]> git.mxchange.org Git - friendica.git/blobdiff - include/notifier.php
Merge pull request #2685 from annando/1607-poller-information
[friendica.git] / include / notifier.php
index 45ccf5e40fb39ecea5e8748a4e263a7d3110aa53..446824a26ae065164374d23b599b8bba464a4dee 100644 (file)
@@ -132,18 +132,25 @@ function notifier_run(&$argv, &$argc){
                $recipients[] = $suggest[0]['cid'];
                $item = $suggest[0];
        } elseif($cmd === 'removeme') {
-               $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($item_id));
-               if (! $r)
+               $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`,
+                               `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`,
+                               `user`.`page-flags`, `user`.`prvnets`, `user`.`guid`
+                       FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
+                               WHERE `contact`.`uid` = %d AND `contact`.`self` LIMIT 1",
+                               intval($item_id));
+               if (!$r)
                        return;
 
                $user = $r[0];
-               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($item_id));
-               if (! $r)
+
+               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($item_id));
+               if (!$r)
                        return;
 
                $self = $r[0];
-               $r = q("SELECT * FROM `contact` WHERE `self` = 0 AND `uid` = %d", intval($item_id));
-               if(! $r)
+
+               $r = q("SELECT * FROM `contact` WHERE NOT `self` AND `uid` = %d", intval($item_id));
+               if(!$r)
                        return;
 
                require_once('include/Contact.php');
@@ -223,13 +230,13 @@ function notifier_run(&$argv, &$argc){
 
        if(! ($mail || $fsuggest || $relocate)) {
 
-               $slap = ostatus_salmon($target_item,$owner);
+               $slap = ostatus::salmon($target_item,$owner);
 
                require_once('include/group.php');
 
                $parent = $items[0];
 
-               $thr_parent = q("SELECT `network` FROM `item` WHERE `uri` = '%s' AND `uid` = %d",
+               $thr_parent = q("SELECT `network`, `author-link`, `owner-link` FROM `item` WHERE `uri` = '%s' AND `uid` = %d",
                        dbesc($target_item["thr-parent"]), intval($target_item["uid"]));
 
                logger('Parent is '.$parent['network'].'. Thread parent is '.$thr_parent[0]['network'], LOGGER_DEBUG);
@@ -310,7 +317,7 @@ function notifier_run(&$argv, &$argc){
                                if ($parent["network"] == NETWORK_OSTATUS) {
                                        // Distribute the message to the DFRN contacts as if this wasn't a followup since OStatus can't relay comments
                                        // Currently it is work at progress
-                                       $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `network` = '%s' AND NOT `blocked` AND NOT `pending`",
+                                       $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `network` = '%s' AND NOT `blocked` AND NOT `pending` AND NOT `archive`",
                                                intval($uid),
                                                dbesc(NETWORK_DFRN)
                                        );
@@ -388,7 +395,34 @@ function notifier_run(&$argv, &$argc){
                // We have not only to look at the parent, since it could be a Friendica thread.
                if (($thr_parent AND ($thr_parent[0]['network'] == NETWORK_OSTATUS)) OR ($parent['network'] == NETWORK_OSTATUS)) {
 
-                       logger('Some parent is OStatus for '.$target_item["guid"], LOGGER_DEBUG);
+                       logger('Some parent is OStatus for '.$target_item["guid"]." - Author: ".$thr_parent[0]['author-link']." - Owner: ".$thr_parent[0]['owner-link'], LOGGER_DEBUG);
+
+                       // Send a salmon to the parent author
+                       $r = q("SELECT `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''",
+                               dbesc(normalise_link($thr_parent[0]['author-link'])),
+                               intval($uid));
+                       if ($r)
+                               $probed_contact = $r[0];
+                       else
+                               $probed_contact = probe_url($thr_parent[0]['author-link']);
+
+                       if ($probed_contact["notify"] != "") {
+                               logger('Notify parent author '.$probed_contact["url"].': '.$probed_contact["notify"]);
+                               $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
+                       }
+
+                       // Send a salmon to the parent owner
+                       $r = q("SELECT `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''",
+                               dbesc(normalise_link($thr_parent[0]['owner-link'])),
+                               intval($uid));
+                       if ($r)
+                               $probed_contact = $r[0];
+                       else
+                               $probed_contact = probe_url($thr_parent[0]['owner-link']);
+                       if ($probed_contact["notify"] != "") {
+                               logger('Notify parent owner '.$probed_contact["url"].': '.$probed_contact["notify"]);
+                               $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
+                       }
 
                        // Send a salmon notification to every person we mentioned in the post
                        $arr = explode(',',$target_item['tag']);
@@ -409,7 +443,7 @@ function notifier_run(&$argv, &$argc){
                } else
                        $sql_extra = " AND `network` IN ('".NETWORK_OSTATUS."', '".NETWORK_DFRN."', '".NETWORK_DIASPORA."', '".NETWORK_MAIL."', '".NETWORK_MAIL2."')";
 
-               $r = q("SELECT * FROM `contact` WHERE `id` IN ($conversant_str) AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0".$sql_extra);
+               $r = q("SELECT * FROM `contact` WHERE `id` IN ($conversant_str) AND NOT `blocked` AND NOT `pending` AND NOT `archive`".$sql_extra);
 
                if(count($r))
                        $contacts = $r;
@@ -444,7 +478,7 @@ function notifier_run(&$argv, &$argc){
        if ($relocate)
                $r = $recipients_relocate;
        else
-               $r = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND NOT `blocked` AND NOT `pending`",
+               $r = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND NOT `blocked` AND NOT `pending` AND NOT `archive`",
                        dbesc($recip_str)
                );
 
@@ -526,7 +560,7 @@ function notifier_run(&$argv, &$argc){
                                if($url) {
                                        logger('notifier: urldelivery: ' . $url);
                                        $deliver_status = slapper($owner,$url,$slap);
-                                       // TODO: redeliver/queue these items on failure, though there is no contact record
+                                       /// @TODO Redeliver/queue these items on failure, though there is no contact record
                                }
                        }
                }
@@ -536,7 +570,7 @@ function notifier_run(&$argv, &$argc){
        if($public_message) {
 
                if (!$followup)
-                       $r0 = diaspora_fetch_relay();
+                       $r0 = diaspora::relay_list();
                else
                        $r0 = array();
 
@@ -548,7 +582,7 @@ function notifier_run(&$argv, &$argc){
                );
 
                $r2 = q("SELECT `id`, `name`,`network` FROM `contact`
-                       WHERE `network` in ( '%s', '%s')  AND `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
+                       WHERE `network` in ( '%s', '%s')  AND `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `archive`
                        AND `rel` != %d order by rand() ",
                        dbesc(NETWORK_DFRN),
                        dbesc(NETWORK_MAIL2),
@@ -559,7 +593,7 @@ function notifier_run(&$argv, &$argc){
                $r = array_merge($r2,$r1,$r0);
 
                if(count($r)) {
-                       logger('pubdeliver: ' . print_r($r,true), LOGGER_DEBUG);
+                       logger('pubdeliver '.$target_item["guid"].': '.print_r($r,true), LOGGER_DEBUG);
 
                        // throw everything into the queue in case we get killed
 
@@ -584,7 +618,7 @@ function notifier_run(&$argv, &$argc){
                                }
 
                                if((! $mail) && (! $fsuggest) && (! $followup)) {
-                                       logger('notifier: delivery agent: ' . $rr['name'] . ' ' . $rr['id']);
+                                       logger('notifier: delivery agent: '.$rr['name'].' '.$rr['id'].' '.$rr['network'].' '.$target_item["guid"]);
                                        proc_run('php','include/delivery.php',$cmd,$item_id,$rr['id']);
                                        if($interval)
                                                @time_sleep_until(microtime(true) + (float) $interval);
@@ -628,13 +662,6 @@ function notifier_run(&$argv, &$argc){
                proc_run('php','include/pubsubpublish.php');
        }
 
-       // If the item was deleted, clean up the `sign` table
-       if($target_item['deleted']) {
-               $r = q("DELETE FROM sign where `retract_iid` = %d",
-                       intval($target_item['id'])
-               );
-       }
-
        logger('notifier: calling hooks', LOGGER_DEBUG);
 
        if($normal_mode)