From 0d9ed4873801a669ff9530a5fa434252a1be2a57 Mon Sep 17 00:00:00 2001 From: Friendika Date: Sun, 6 Feb 2011 22:41:07 -0800 Subject: [PATCH 1/8] functionise birthday --- boot.php | 43 +++++++++++++++++++++++++++++++++++++++++++ include/items.php | 39 +-------------------------------------- include/notifier.php | 8 ++++++-- 3 files changed, 50 insertions(+), 40 deletions(-) diff --git a/boot.php b/boot.php index 5327688ddd..4dcd6db660 100644 --- a/boot.php +++ b/boot.php @@ -2323,3 +2323,46 @@ function current_theme_url() { }} +if(! function_exists('feed_birthday')) { +function feed_birthday($uid,$tz) { + + /** + * + * Determine the next birthday, but only if the birthday is published + * in the default profile. We _could_ also look for a private profile that the + * recipient can see, but somebody could get mad at us if they start getting + * public birthday greetings when they haven't made this info public. + * + * Assuming we are able to publish this info, we are then going to convert + * the start time from the owner's timezone to UTC. + * + * This will potentially solve the problem found with some social networks + * where birthdays are converted to the viewer's timezone and salutations from + * elsewhere in the world show up on the wrong day. We will convert it to the + * viewer's timezone also, but first we are going to convert it from the birthday + * person's timezone to GMT - so the viewer may find the birthday starting at + * 6:00PM the day before, but that will correspond to midnight to the birthday person. + * + */ + + $birthday = ''; + + $p = q("SELECT `dob` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1", + intval($uid) + ); + + if($p && count($p)) { + $tmp_dob = substr($p[0]['dob'],5); + if(intval($tmp_dob)) { + $y = datetime_convert($tz,$tz,'now','Y'); + $bd = $y . '-' . $tmp_dob . ' 00:00'; + $t_dob = strtotime($bd); + $now = strtotime(datetime_convert($tz,$tz,'now')); + if($t_dob < $now) + $bd = $y + 1 . '-' . $tmp_dob . ' 00:00'; + $birthday = datetime_convert($tz,'UTC',$bd,ATOM_TIME); + } + } + + return $birthday; +}} \ No newline at end of file diff --git a/include/items.php b/include/items.php index 15fd262f4c..5b99ca1714 100644 --- a/include/items.php +++ b/include/items.php @@ -37,44 +37,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) else killme(); - - /** - * - * Determine the next birthday, but only if the birthday is published - * in the default profile. We _could_ also look for a private profile that the - * recipient can see, but somebody could get mad at us if they start getting - * public birthday greetings when they haven't made this info public. - * - * Assuming we are able to publish this info, we are then going to convert - * the start time from the owner's timezone to UTC. - * - * This will potentially solve the problem found with some social networks - * where birthdays are converted to the viewer's timezone and salutations from - * elsewhere in the world show up on the wrong day. We will convert it to the - * viewer's timezone also, but first we are going to convert it from the birthday - * person's timezone to GMT - so the viewer may find the birthday starting at - * 6:00PM the day before, but that will correspond to midnight to the birthday person. - * - */ - - $birthday = ''; - - $p = q("SELECT `dob` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1", - intval($owner_id) - ); - - if($p && count($p)) { - $tmp_dob = substr($p[0]['dob'],5); - if(intval($tmp_dob)) { - $y = datetime_convert($owner_tz,$owner_tz,'now','Y'); - $bd = $y . '-' . $tmp_dob . ' 00:00'; - $t_dob = strtotime($bd); - $now = strtotime(datetime_convert($owner_tz,$owner_tz,'now')); - if($t_dob < $now) - $bd = $y + 1 . '-' . $tmp_dob . ' 00:00'; - $birthday = datetime_convert($owner_tz,'UTC',$bd,ATOM_TIME); - } - } + $birthday = feed_birthday($owner_id,$owner_tz); if($dfrn_id && $dfrn_id != '*') { diff --git a/include/notifier.php b/include/notifier.php index 07bde7c4d6..ca0aa0df38 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -87,7 +87,7 @@ function notifier_run($argv, $argc){ } } - $r = q("SELECT `contact`.*, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, `user`.`page-flags` + $r = q("SELECT `contact`.*, `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, `user`.`page-flags` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1", intval($uid) @@ -194,6 +194,10 @@ function notifier_run($argv, $argc){ } } + $birthday = feed_birthday($owner['uid'],$owner['timezone']); + if($birthday) + $birthday = '' . xmlify($birthday) . ''; + $atom .= replace_macros($feed_template, array( '$version' => xmlify(FRIENDIKA_VERSION), '$feed_id' => xmlify($a->get_baseurl() . '/profile/' . $owner['nickname'] ), @@ -208,7 +212,7 @@ function notifier_run($argv, $argc){ '$picdate' => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , ATOM_TIME)) , '$uridate' => xmlify(datetime_convert('UTC','UTC',$owner['uri-date'] . '+00:00' , ATOM_TIME)) , '$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , ATOM_TIME)) , - '$birthday' => '' + '$birthday' => $birthday )); if($cmd === 'mail') { From 118f1d7e0a517d5c2734c6c40d6e4c44c09d1cc5 Mon Sep 17 00:00:00 2001 From: Friendika Date: Sun, 6 Feb 2011 23:04:10 -0800 Subject: [PATCH 2/8] don't show logout link on 'home' link if remote_user --- boot.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/boot.php b/boot.php index 4dcd6db660..87ea65b96c 100644 --- a/boot.php +++ b/boot.php @@ -762,7 +762,7 @@ function login($register = false) { $lostpass = t('Forgot your password?'); $lostlink = t('Password Reset'); - if(x($_SESSION,'authenticated')) { + if(local_user())) { $tpl = load_view_file("view/logout.tpl"); } else { @@ -772,12 +772,12 @@ function login($register = false) { $o = replace_macros($tpl,array( '$register_html' => $register_html, - '$classname' => $classname, - '$namelabel' => $namelabel, - '$passlabel' => $passlabel, - '$login' => $login, - '$lostpass' => $lostpass, - '$lostlink' => $lostlink + '$classname' => $classname, + '$namelabel' => $namelabel, + '$passlabel' => $passlabel, + '$login' => $login, + '$lostpass' => $lostpass, + '$lostlink' => $lostlink )); return $o; From 7dd56fa14c784a95695aece6dfe5cac145452ffe Mon Sep 17 00:00:00 2001 From: Friendika Date: Sun, 6 Feb 2011 23:06:50 -0800 Subject: [PATCH 3/8] one less paren --- boot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot.php b/boot.php index 87ea65b96c..509fe22878 100644 --- a/boot.php +++ b/boot.php @@ -762,7 +762,7 @@ function login($register = false) { $lostpass = t('Forgot your password?'); $lostlink = t('Password Reset'); - if(local_user())) { + if(local_user()) { $tpl = load_view_file("view/logout.tpl"); } else { From 18c5d1ff90dd364328032b3f0092ac5176ebc4c5 Mon Sep 17 00:00:00 2001 From: Friendika Date: Mon, 7 Feb 2011 17:06:04 -0800 Subject: [PATCH 4/8] feed cleanup --- boot.php | 43 +++++++++++++++++++++++++- include/items.php | 72 ++++++++++++++------------------------------ include/notifier.php | 18 +++-------- mod/dfrn_poll.php | 2 +- 4 files changed, 70 insertions(+), 65 deletions(-) diff --git a/boot.php b/boot.php index 509fe22878..c8722caa7b 100644 --- a/boot.php +++ b/boot.php @@ -2365,4 +2365,45 @@ function feed_birthday($uid,$tz) { } return $birthday; -}} \ No newline at end of file +}} + +/** + * return atom link elements for all of our hubs + */ + +if(! function_exists('feed_hublinks')) { +function feed_hublinks() { + + $hub = get_config('system','huburl'); + + $hubxml = ''; + if(strlen($hub)) { + $hubs = explode(',', $hub); + if(count($hubs)) { + foreach($hubs as $h) { + $h = trim($h); + if(! strlen($h)) + continue; + $hubxml .= '' . "\n" ; + } + } + } + return $hubxml; +}} + +/* return atom link elements for salmon endpoints */ + +if(! function_exists('feed_salmonlinks')) { +function feed_salmonlinks($nick) { + + $a = get_app(); + + $salmon = '' . "\n" ; + + // old style links that status.net still needed as of 12/2010 + + $salmon .= ' ' . "\n" ; + $salmon .= ' ' . "\n" ; + return $salmon; +}} + diff --git a/include/items.php b/include/items.php index 5b99ca1714..9c29e65586 100644 --- a/include/items.php +++ b/include/items.php @@ -9,37 +9,27 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) // default permissions - anonymous user - $sql_extra = " - AND `allow_cid` = '' - AND `allow_gid` = '' - AND `deny_cid` = '' - AND `deny_gid` = '' - "; - - if(strlen($owner_nick) && ! intval($owner_nick)) { - $r = q("SELECT `uid`, `nickname`, `timezone` FROM `user` WHERE `nickname` = '%s' LIMIT 1", - dbesc($owner_nick) - ); - if(count($r)) { - $owner_id = $r[0]['uid']; - $owner_nick = $r[0]['nickname']; - $owner_tz = $r[0]['timezone']; - } - } - - $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", - intval($owner_id) - ); - if(count($r)) { - $owner = $r[0]; - $owner['nickname'] = $owner_nick; - } - else + if(! strlen($owner_nick)) killme(); - $birthday = feed_birthday($owner_id,$owner_tz); + $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' "; - if($dfrn_id && $dfrn_id != '*') { + $r = q("SELECT `contact`.*, `user`.`uid` AS `user_uid`, `user`.`nickname`, `user`.`timezone` + FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` + WHERE `contact`.`self` = 1 AND `user`.`nickname` = '%s' LIMIT 1", + dbesc($owner_nick) + ); + + if(! count($r)) + killme(); + + $owner = $r[0]; + $owner_id = $owner['user_uid']; + $owner_nick = $owner['nickname']; + + $birthday = feed_birthday($owner_id,$owner['timezone']); + + if(strlen($dfrn_id)) { $sql_extra = ''; switch($direction) { @@ -65,7 +55,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) ); if(! count($r)) - return false; + killme(); $contact = $r[0]; $groups = init_groups_visitor($contact['id']); @@ -119,7 +109,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) ); // Will check further below if this actually returned results. - // We will provide an empty feed in any case. + // We will provide an empty feed if that is the case. $items = $r; @@ -127,25 +117,9 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) $atom = ''; - $hub = get_config('system','huburl'); - - $hubxml = ''; - if(strlen($hub)) { - $hubs = explode(',', $hub); - if(count($hubs)) { - foreach($hubs as $h) { - $h = trim($h); - if(! strlen($h)) - continue; - $hubxml .= '' . "\n" ; - } - } - } - - $salmon = '' . "\n" ; - $salmon .= '' . "\n" ; - $salmon .= '' . "\n" ; + $hubxml = feed_hublinks(); + $salmon = feed_salmonlinks($owner_nick); $atom .= replace_macros($feed_template, array( '$version' => xmlify(FRIENDIKA_VERSION), @@ -178,7 +152,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) // public feeds get html, our own nodes use bbcode - if($dfrn_id === '*') { + if($dfrn_id === '') { $type = 'html'; } else { diff --git a/include/notifier.php b/include/notifier.php index ca0aa0df38..b6c4ca5712 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -179,23 +179,13 @@ function notifier_run($argv, $argc){ $mail_template = load_view_file('view/atom_mail.tpl'); $atom = ''; - $hubxml = ''; $slaps = array(); - if(strlen($hub)) { - $hubs = explode(',', $hub); - if(count($hubs)) { - foreach($hubs as $h) { - $h = trim($h); - if(! strlen($h)) - continue; - $hubxml .= '' . "\n" ; - } - } - } + $hubxml = feed_hublinks(); $birthday = feed_birthday($owner['uid'],$owner['timezone']); - if($birthday) + + if(strlen($birthday)) $birthday = '' . xmlify($birthday) . ''; $atom .= replace_macros($feed_template, array( @@ -398,7 +388,7 @@ function notifier_run($argv, $argc){ * */ - $max_allowed = ((get_config('system','maxpubdeliver') === false) ? 150 : intval(get_config('system','maxdeliver'))); + $max_allowed = ((get_config('system','maxpubdeliver') === false) ? 150 : intval(get_config('system','maxpubdeliver'))); /** * diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 85e7fc0afd..334e103079 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -28,7 +28,7 @@ function dfrn_poll_init(&$a) { if(($dfrn_id === '') && (! x($_POST,'dfrn_id')) && ($a->argc > 1)) { logger('dfrn_poll: public feed request from ' . $_SERVER['REMOTE_ADDR'] ); header("Content-type: application/atom+xml"); - $o = get_feed_for($a, '*', $a->argv[1],$last_update); + $o = get_feed_for($a, '', $a->argv[1],$last_update); echo $o; killme(); } From 9f5d3000c74253a1284abda16006d74df84073fe Mon Sep 17 00:00:00 2001 From: Friendika Date: Mon, 7 Feb 2011 21:16:39 -0800 Subject: [PATCH 5/8] don't change photo visibility if only album name was changed --- include/items.php | 6 +++--- mod/photos.php | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/items.php b/include/items.php index 9c29e65586..5d9eaaaf3f 100644 --- a/include/items.php +++ b/include/items.php @@ -859,12 +859,12 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) { } -/* +/** * * consume_feed - process atom feed and update anything/everything we might need to update * - * $xml = the (atom) feed to consume - no RSS spoken here, it might partially work since simplepie - * handles both, but we don't claim it will work well, and are reasonably certain it won't. + * $xml = the (atom) feed to consume - RSS isn't as fully supported but may work for simple feeds. + * * $importer = the contact_record (joined to user_record) of the local user who owns this relationship. * It is this person's stuff that is going to be updated. * $contact = the person who is sending us stuff. If not set, we MAY be processing a "follow" activity diff --git a/mod/photos.php b/mod/photos.php index 1a1ebaac19..9acde458df 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -268,6 +268,13 @@ foreach($_FILES AS $key => $val) { intval($page_owner_uid) ); } + + /* Don't make the item visible if the only change was the album name */ + + $visibility = 0; + if($p[0]['desc'] !== $desc || strlen($rawtags)) + $visibility = 1; + if(! $item_id) { // Create item container @@ -297,6 +304,7 @@ foreach($_FILES AS $key => $val) { $arr['deny_cid'] = $p[0]['deny_cid']; $arr['deny_gid'] = $p[0]['deny_gid']; $arr['last-child'] = 1; + $arr['visible'] = $visibility; $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]' . '[/url]'; From d37ee1b399c7f03e301b9cb70ed32b95ebaa65b5 Mon Sep 17 00:00:00 2001 From: Friendika Date: Mon, 7 Feb 2011 23:20:38 -0800 Subject: [PATCH 6/8] at least one server is giving CURL a second set of headers (and it isn't a 100 continue which we've already accounted for) --- boot.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/boot.php b/boot.php index c8722caa7b..3714f588b4 100644 --- a/boot.php +++ b/boot.php @@ -626,7 +626,16 @@ function fetch_url($url,$binary = false, &$redirects = 0) { } } $a->set_curl_code($http_code); + $body = substr($s,strlen($header)+4); + + /* one more try to make sure there are no more headers */ + + if(strpos($body,'HTTP/') === 0) { + $header = substr($body,0,strpos($body,"\r\n\r\n")); + $body = substr($body,strlen($header)+4); + } + $a->set_curl_headers($header); curl_close($ch); @@ -690,6 +699,14 @@ function post_url($url,$params, $headers = null, &$redirects = 0) { } $a->set_curl_code($http_code); $body = substr($s,strlen($header)+4); + + /* one more try to make sure there are no more headers */ + + if(strpos($body,'HTTP/') === 0) { + $header = substr($body,0,strpos($body,"\r\n\r\n")); + $body = substr($body,strlen($header)+4); + } + $a->set_curl_headers($header); curl_close($ch); From e06cd399b7d90d0083ef70d0db8d284d22aa3f19 Mon Sep 17 00:00:00 2001 From: Friendika Date: Mon, 7 Feb 2011 23:28:41 -0800 Subject: [PATCH 7/8] close tag on favicon link missing --- view/de/head.tpl | 2 +- view/en/head.tpl | 2 +- view/fr/head.tpl | 2 +- view/it/head.tpl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/view/de/head.tpl b/view/de/head.tpl index 50dd9cab6b..c3ec3d2c9e 100644 --- a/view/de/head.tpl +++ b/view/de/head.tpl @@ -1,7 +1,7 @@ - +