]> git.mxchange.org Git - friendica.git/blobdiff - include/notifier.php
Fix #8 \"recycle symbol getting mangled from status.net retweets\"
[friendica.git] / include / notifier.php
index 8442349cfdcfe83ebc574c5f43ea150be096f21a..648a07062c02aa0104ffd6571fc4c76f2ea1cbe4 100644 (file)
@@ -2,18 +2,18 @@
 require_once("boot.php");
 
 function notifier_run($argv, $argc){
-  global $a, $db;
+       global $a, $db;
 
-  if(is_null($a)){
-    $a = new App;
-  }
+       if(is_null($a)){
+               $a = new App;
+       }
   
-  if(is_null($db)){
-    @include(".htconfig.php");
-    require_once("dba.php");
-    $db = new dba($db_host, $db_user, $db_pass, $db_data);
-    unset($db_host, $db_user, $db_pass, $db_data);
-  };
+       if(is_null($db)) {
+               @include(".htconfig.php");
+               require_once("dba.php");
+               $db = new dba($db_host, $db_user, $db_pass, $db_data);
+                       unset($db_host, $db_user, $db_pass, $db_data);
+       }
 
        require_once("session.php");
        require_once("datetime.php");
@@ -40,6 +40,7 @@ function notifier_run($argv, $argc){
                        break;
        }
 
+       $top_level = false;
        $recipients = array();
        $url_recipients = array();
 
@@ -62,11 +63,12 @@ function notifier_run($argv, $argc){
                $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
                        intval($item_id)
                );
-               if(! count($r)){
+
+               if((! count($r)) || (! intval($r[0]['parent']))) {
                        return;
                }
-  
-               $parent_id = $r[0]['parent'];
+
+               $parent_id = intval($r[0]['parent']);
                $uid = $r[0]['uid'];
                $updated = $r[0]['edited'];
 
@@ -77,9 +79,20 @@ function notifier_run($argv, $argc){
                if(! count($items)){
                        return;
                }
+
+
+               // avoid race condition with deleting entries
+
+               if($items[0]['deleted']) {
+                       foreach($items as $item)
+                               $item['deleted'] = 1;
+               }
+
+               if(count($items) == 1 && $items[0]['uri'] === $items[0]['parent-uri'])
+                       $top_level = true;
        }
 
-       $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)
@@ -122,8 +135,8 @@ function notifier_run($argv, $argc){
 
                        $allow_people = expand_acl($parent['allow_cid']);
                        $allow_groups = expand_groups(expand_acl($parent['allow_gid']));
-                       $deny_people = expand_acl($parent['deny_cid']);
-                       $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
+                       $deny_people  = expand_acl($parent['deny_cid']);
+                       $deny_groups  = expand_groups(expand_acl($parent['deny_gid']));
 
                        $conversants = array();
 
@@ -159,9 +172,6 @@ function notifier_run($argv, $argc){
 
                $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0");
 
-//             if( ! count($r)){
-//                     return;
-//             }
 
                if(count($r))
                        $contacts = $r;
@@ -171,20 +181,14 @@ 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 .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
-                       }
-               }
-       }
+       $hubxml = feed_hublinks();
+
+       $birthday = feed_birthday($owner['uid'],$owner['timezone']);
+
+       if(strlen($birthday))
+               $birthday = '<dfrn:birthday>' . xmlify($birthday) . '</dfrn:birthday>';
 
        $atom .= replace_macros($feed_template, array(
                        '$version'      => xmlify(FRIENDIKA_VERSION),
@@ -200,7 +204,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') {
@@ -220,6 +224,8 @@ function notifier_run($argv, $argc){
        else {
                if($followup) {
                        foreach($items as $item) {  // there is only one item
+                               if(! $item['parent'])
+                                       continue;
                                if($item['id'] == $item_id) {
                                        logger('notifier: followup: item: ' . print_r($item,true), LOGGER_DATA);
                                        $slap  = atom_entry($item,'html',$owner,$owner,false);
@@ -229,18 +235,17 @@ function notifier_run($argv, $argc){
                }
                else {
                        foreach($items as $item) {
+                               if(! $item['parent'])
+                                       continue;
+
                                $contact = get_item_contact($item,$contacts);
                                if(! $contact)
                                        continue;
 
                                $atom   .= atom_entry($item,'text',$contact,$owner,true);
 
-                               // There's a problem here - we *were* going to use salmon to provide semi-authenticated
-                               // communication to OStatus, but unless we're the item author they won't verify.
-                               // commented out for now, though we'll still send local replies (and any mentions 
-                               // that they contain) upstream. Rethinking the problem space.
-//                             $slaps[] = atom_entry($item,'html',$contact,$owner,true);
+                               if(($top_level) && ($notify_hub) && ($item['author-link'] === $item['owner-link'])) 
+                                       $slaps[] = atom_entry($item,'html',$contact,$owner,true);
                        }
                }
        }
@@ -248,7 +253,7 @@ function notifier_run($argv, $argc){
 
        logger('notifier: ' . $atom, LOGGER_DATA);
 
-//     logger('notifier: slaps: ' . print_r($slaps,true), LOGGER_DATA);
+       logger('notifier: slaps: ' . print_r($slaps,true), LOGGER_DATA);
 
        if($followup)
                $recip_str = $parent['contact-id'];
@@ -381,7 +386,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')));
                                
                /**
                 *