X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fnotifier.php;h=9e1450ba2b5004a676f62375aab0f686290f3c23;hb=c0cc65304b06b027219a9f162deaab90fe2a0487;hp=a46744f0701a0c33b7ca3f3a6898332397d4f857;hpb=ec90a9e6ad1b2d424f7c72410d4a5a6cec2aad9b;p=friendica.git diff --git a/include/notifier.php b/include/notifier.php index a46744f070..9e1450ba2b 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -16,7 +16,7 @@ require_once('include/salmon.php'); /* * The notifier is typically called with: * - * proc_run('php', "include/notifier.php", COMMAND, ITEM_ID); + * proc_run(PRIORITY_HIGH, "include/notifier.php", COMMAND, ITEM_ID); * * where COMMAND is one of the following: * @@ -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`.`account-type`, `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'); @@ -163,7 +170,7 @@ function notifier_run(&$argv, &$argc){ intval($item_id) ); - if((! count($r)) || (! intval($r[0]['parent']))) { + if((! dbm::is_result($r)) || (! intval($r[0]['parent']))) { return; } @@ -197,14 +204,15 @@ function notifier_run(&$argv, &$argc){ $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`.`page-flags`, `user`.`prvnets`, `user`.`account-type` FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1", intval($uid) ); - if(! count($r)) + if (! dbm::is_result($r)) { return; + } $owner = $r[0]; @@ -223,13 +231,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); @@ -314,7 +322,7 @@ function notifier_run(&$argv, &$argc){ intval($uid), dbesc(NETWORK_DFRN) ); - if(count($r)) + if (dbm::is_result($r)) foreach($r as $rr) $recipients_followup[] = $rr['id']; } @@ -348,7 +356,7 @@ function notifier_run(&$argv, &$argc){ // a delivery fork. private groups (forum_mode == 2) do not uplink if((intval($parent['forum_mode']) == 1) && (! $top_level) && ($cmd !== 'uplink')) { - proc_run('php','include/notifier.php','uplink',$item_id); + proc_run(PRIORITY_HIGH,'include/notifier.php','uplink',$item_id); } $conversants = array(); @@ -388,7 +396,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']); @@ -411,7 +446,7 @@ function notifier_run(&$argv, &$argc){ $r = q("SELECT * FROM `contact` WHERE `id` IN ($conversant_str) AND NOT `blocked` AND NOT `pending` AND NOT `archive`".$sql_extra); - if(count($r)) + if (dbm::is_result($r)) $contacts = $r; } else @@ -429,7 +464,7 @@ function notifier_run(&$argv, &$argc){ intval($uid), dbesc(NETWORK_MAIL) ); - if(count($r)) { + if (dbm::is_result($r)) { foreach($r as $rr) $recipients[] = $rr['id']; } @@ -457,7 +492,7 @@ function notifier_run(&$argv, &$argc){ // delivery loop - if(count($r)) { + if (dbm::is_result($r)) { foreach($r as $contact) { if(!$contact['self']) { @@ -504,7 +539,7 @@ function notifier_run(&$argv, &$argc){ $this_batch[] = $contact['id']; if(count($this_batch) >= $deliveries_per_process) { - proc_run('php','include/delivery.php',$cmd,$item_id,$this_batch); + proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$this_batch); $this_batch = array(); if($interval) @time_sleep_until(microtime(true) + (float) $interval); @@ -514,7 +549,7 @@ function notifier_run(&$argv, &$argc){ // be sure to pick up any stragglers if(count($this_batch)) - proc_run('php','include/delivery.php',$cmd,$item_id,$this_batch); + proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$this_batch); } // send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts @@ -523,7 +558,7 @@ function notifier_run(&$argv, &$argc){ if($slap && count($url_recipients) && ($public_message || $push_notify) && $normal_mode) { if(!get_config('system','dfrn_only')) { foreach($url_recipients as $url) { - if($url) { + 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 @@ -535,7 +570,7 @@ function notifier_run(&$argv, &$argc){ if($public_message) { - if (!$followup AND $top_level) + if (!$followup) $r0 = diaspora::relay_list(); else $r0 = array(); @@ -558,17 +593,17 @@ function notifier_run(&$argv, &$argc){ $r = array_merge($r2,$r1,$r0); - if(count($r)) { + if (dbm::is_result($r)) { logger('pubdeliver '.$target_item["guid"].': '.print_r($r,true), LOGGER_DEBUG); // throw everything into the queue in case we get killed foreach($r as $rr) { if((! $mail) && (! $fsuggest) && (! $followup)) { - q("insert into deliverq ( `cmd`,`item`,`contact` ) values ('%s', %d, %d )", - dbesc($cmd), - intval($item_id), - intval($rr['id']) + q("INSERT INTO `deliverq` (`cmd`,`item`,`contact`) VALUES ('%s', %d, %d) + ON DUPLICATE KEY UPDATE `cmd` = '%s', `item` = %d, `contact` = %d", + dbesc($cmd), intval($item_id), intval($rr['id']), + dbesc($cmd), intval($item_id), intval($rr['id']) ); } } @@ -585,7 +620,7 @@ function notifier_run(&$argv, &$argc){ if((! $mail) && (! $fsuggest) && (! $followup)) { logger('notifier: delivery agent: '.$rr['name'].' '.$rr['id'].' '.$rr['network'].' '.$target_item["guid"]); - proc_run('php','include/delivery.php',$cmd,$item_id,$rr['id']); + proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$rr['id']); if($interval) @time_sleep_until(microtime(true) + (float) $interval); } @@ -608,14 +643,14 @@ function notifier_run(&$argv, &$argc){ if ($h === '[internal]') { // Set push flag for PuSH subscribers to this topic, // they will be notified in queue.php - q("UPDATE `push_subscriber` SET `push` = 1 " . - "WHERE `nickname` = '%s'", dbesc($owner['nickname'])); + q("UPDATE `push_subscriber` SET `push` = 1 ". + "WHERE `nickname` = '%s' AND `push` = 0", dbesc($owner['nickname'])); logger('Activating internal PuSH for item '.$item_id, LOGGER_DEBUG); } else { - $params = 'hub.mode=publish&hub.url=' . urlencode( $a->get_baseurl() . '/dfrn_poll/' . $owner['nickname'] ); + $params = 'hub.mode=publish&hub.url=' . urlencode( App::get_baseurl() . '/dfrn_poll/' . $owner['nickname'] ); post_url($h,$params); logger('publish for item '.$item_id.' ' . $h . ' ' . $params . ' returned ' . $a->get_curl_code()); } @@ -625,7 +660,7 @@ function notifier_run(&$argv, &$argc){ } // Handling the pubsubhubbub requests - proc_run('php','include/pubsubpublish.php'); + proc_run(PRIORITY_HIGH,'include/pubsubpublish.php'); } logger('notifier: calling hooks', LOGGER_DEBUG);