Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

703 lines
22 KiB

  1. <?php
  2. use \Friendica\Core\Config;
  3. require_once("boot.php");
  4. require_once('include/queue_fn.php');
  5. require_once('include/html2plain.php');
  6. require_once("include/Scrape.php");
  7. require_once('include/diaspora.php');
  8. require_once("include/ostatus.php");
  9. require_once('include/salmon.php');
  10. /*
  11. * This file was at one time responsible for doing all deliveries, but this caused
  12. * big problems when the process was killed or stalled during the delivery process.
  13. * It now invokes separate queues that are delivering via delivery.php and pubsubpublish.php.
  14. */
  15. /*
  16. * The notifier is typically called with:
  17. *
  18. * proc_run(PRIORITY_HIGH, "include/notifier.php", COMMAND, ITEM_ID);
  19. *
  20. * where COMMAND is one of the following:
  21. *
  22. * activity (in diaspora.php, dfrn_confirm.php, profiles.php)
  23. * comment-import (in diaspora.php, items.php)
  24. * comment-new (in item.php)
  25. * drop (in diaspora.php, items.php, photos.php)
  26. * edit_post (in item.php)
  27. * event (in events.php)
  28. * expire (in items.php)
  29. * like (in like.php, poke.php)
  30. * mail (in message.php)
  31. * suggest (in fsuggest.php)
  32. * tag (in photos.php, poke.php, tagger.php)
  33. * tgroup (in items.php)
  34. * wall-new (in photos.php, item.php)
  35. * removeme (in Contact.php)
  36. * relocate (in uimport.php)
  37. *
  38. * and ITEM_ID is the id of the item in the database that needs to be sent to others.
  39. */
  40. function notifier_run(&$argv, &$argc){
  41. global $a, $db;
  42. if (is_null($a)) {
  43. $a = new App;
  44. }
  45. if (is_null($db)) {
  46. @include(".htconfig.php");
  47. require_once("include/dba.php");
  48. $db = new dba($db_host, $db_user, $db_pass, $db_data);
  49. unset($db_host, $db_user, $db_pass, $db_data);
  50. }
  51. require_once("include/session.php");
  52. require_once("include/datetime.php");
  53. require_once('include/items.php');
  54. require_once('include/bbcode.php');
  55. require_once('include/email.php');
  56. Config::load();
  57. load_hooks();
  58. if ($argc < 3) {
  59. return;
  60. }
  61. $a->set_baseurl(get_config('system','url'));
  62. logger('notifier: invoked: ' . print_r($argv,true), LOGGER_DEBUG);
  63. $cmd = $argv[1];
  64. switch($cmd) {
  65. case 'mail':
  66. default:
  67. $item_id = intval($argv[2]);
  68. if (! $item_id) {
  69. return;
  70. }
  71. break;
  72. }
  73. $expire = false;
  74. $mail = false;
  75. $fsuggest = false;
  76. $relocate = false;
  77. $top_level = false;
  78. $recipients = array();
  79. $url_recipients = array();
  80. $normal_mode = true;
  81. if ($cmd === 'mail') {
  82. $normal_mode = false;
  83. $mail = true;
  84. $message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1",
  85. intval($item_id)
  86. );
  87. if (! count($message)) {
  88. return;
  89. }
  90. $uid = $message[0]['uid'];
  91. $recipients[] = $message[0]['contact-id'];
  92. $item = $message[0];
  93. } elseif ($cmd === 'expire') {
  94. $normal_mode = false;
  95. $expire = true;
  96. $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1
  97. AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP() - INTERVAL 10 MINUTE",
  98. intval($item_id)
  99. );
  100. $uid = $item_id;
  101. $item_id = 0;
  102. if (! count($items)) {
  103. return;
  104. }
  105. } elseif ($cmd === 'suggest') {
  106. $normal_mode = false;
  107. $fsuggest = true;
  108. $suggest = q("SELECT * FROM `fsuggest` WHERE `id` = %d LIMIT 1",
  109. intval($item_id)
  110. );
  111. if (! count($suggest)) {
  112. return;
  113. }
  114. $uid = $suggest[0]['uid'];
  115. $recipients[] = $suggest[0]['cid'];
  116. $item = $suggest[0];
  117. } elseif ($cmd === 'removeme') {
  118. $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`,
  119. `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`,
  120. `user`.`page-flags`, `user`.`prvnets`, `user`.`account-type`, `user`.`guid`
  121. FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
  122. WHERE `contact`.`uid` = %d AND `contact`.`self` LIMIT 1",
  123. intval($item_id));
  124. if (!$r)
  125. return;
  126. $user = $r[0];
  127. $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($item_id));
  128. if (!$r)
  129. return;
  130. $self = $r[0];
  131. $r = q("SELECT * FROM `contact` WHERE NOT `self` AND `uid` = %d", intval($item_id));
  132. if (!$r) {
  133. return;
  134. }
  135. require_once('include/Contact.php');
  136. foreach ($r as $contact) {
  137. terminate_friendship($user, $self, $contact);
  138. }
  139. return;
  140. } elseif ($cmd === 'relocate') {
  141. $normal_mode = false;
  142. $relocate = true;
  143. $uid = $item_id;
  144. $recipients_relocate = q("SELECT * FROM contact WHERE uid = %d AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN);
  145. } else {
  146. // find ancestors
  147. $r = q("SELECT * FROM `item` WHERE `id` = %d and visible = 1 and moderated = 0 LIMIT 1",
  148. intval($item_id)
  149. );
  150. if ((! dbm::is_result($r)) || (! intval($r[0]['parent']))) {
  151. return;
  152. }
  153. $target_item = $r[0];
  154. $parent_id = intval($r[0]['parent']);
  155. $uid = $r[0]['uid'];
  156. $updated = $r[0]['edited'];
  157. $items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer`
  158. FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d and visible = 1 and moderated = 0 ORDER BY `id` ASC",
  159. intval($parent_id)
  160. );
  161. if (! count($items)) {
  162. return;
  163. }
  164. // avoid race condition with deleting entries
  165. if ($items[0]['deleted']) {
  166. foreach ($items as $item) {
  167. $item['deleted'] = 1;
  168. }
  169. }
  170. if ((count($items) == 1) && ($items[0]['id'] === $target_item['id']) && ($items[0]['uri'] === $items[0]['parent-uri'])) {
  171. logger('notifier: top level post');
  172. $top_level = true;
  173. }
  174. }
  175. $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`,
  176. `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`,
  177. `user`.`page-flags`, `user`.`prvnets`, `user`.`account-type`
  178. FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
  179. WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
  180. intval($uid)
  181. );
  182. if (! dbm::is_result($r)) {
  183. return;
  184. }
  185. $owner = $r[0];
  186. $walltowall = ((($top_level) && ($owner['id'] != $items[0]['contact-id'])) ? true : false);
  187. $hub = get_config('system','huburl');
  188. // Should the post be transmitted to Diaspora?
  189. $diaspora_delivery = true;
  190. // If this is a public conversation, notify the feed hub
  191. $public_message = true;
  192. // Do a PuSH
  193. $push_notify = false;
  194. // fill this in with a single salmon slap if applicable
  195. $slap = '';
  196. if (! ($mail || $fsuggest || $relocate)) {
  197. $slap = ostatus::salmon($target_item,$owner);
  198. require_once('include/group.php');
  199. $parent = $items[0];
  200. $thr_parent = q("SELECT `network`, `author-link`, `owner-link` FROM `item` WHERE `uri` = '%s' AND `uid` = %d",
  201. dbesc($target_item["thr-parent"]), intval($target_item["uid"]));
  202. logger('GUID: '.$target_item["guid"].': Parent is '.$parent['network'].'. Thread parent is '.$thr_parent[0]['network'], LOGGER_DEBUG);
  203. // This is IMPORTANT!!!!
  204. // We will only send a "notify owner to relay" or followup message if the referenced post
  205. // originated on our system by virtue of having our hostname somewhere
  206. // in the URI, AND it was a comment (not top_level) AND the parent originated elsewhere.
  207. // if $parent['wall'] == 1 we will already have the parent message in our array
  208. // and we will relay the whole lot.
  209. // expire sends an entire group of expire messages and cannot be forwarded.
  210. // However the conversation owner will be a part of the conversation and will
  211. // be notified during this run.
  212. // Other DFRN conversation members will be alerted during polled updates.
  213. // Diaspora members currently are not notified of expirations, and other networks have
  214. // either limited or no ability to process deletions. We should at least fix Diaspora
  215. // by stringing togther an array of retractions and sending them onward.
  216. $localhost = str_replace('www.','',$a->get_hostname());
  217. if (strpos($localhost,':')) {
  218. $localhost = substr($localhost,0,strpos($localhost,':'));
  219. }
  220. /**
  221. *
  222. * Be VERY CAREFUL if you make any changes to the following several lines. Seemingly innocuous changes
  223. * have been known to cause runaway conditions which affected several servers, along with
  224. * permissions issues.
  225. *
  226. */
  227. $relay_to_owner = false;
  228. if (!$top_level && ($parent['wall'] == 0) && !$expire && (stristr($target_item['uri'],$localhost))) {
  229. $relay_to_owner = true;
  230. }
  231. if (($cmd === 'uplink') && (intval($parent['forum_mode']) == 1) && !$top_level) {
  232. $relay_to_owner = true;
  233. }
  234. // until the 'origin' flag has been in use for several months
  235. // we will just use it as a fallback test
  236. // later we will be able to use it as the primary test of whether or not to relay.
  237. if (! $target_item['origin']) {
  238. $relay_to_owner = false;
  239. }
  240. if ($parent['origin']) {
  241. $relay_to_owner = false;
  242. }
  243. if ($relay_to_owner) {
  244. logger('notifier: followup '.$target_item["guid"], LOGGER_DEBUG);
  245. // local followup to remote post
  246. $followup = true;
  247. $public_message = false; // not public
  248. $conversant_str = dbesc($parent['contact-id']);
  249. $recipients = array($parent['contact-id']);
  250. $recipients_followup = array($parent['contact-id']);
  251. //if (!$target_item['private'] AND $target_item['wall'] AND
  252. if (!$target_item['private'] AND
  253. (strlen($target_item['allow_cid'].$target_item['allow_gid'].
  254. $target_item['deny_cid'].$target_item['deny_gid']) == 0))
  255. $push_notify = true;
  256. if (($thr_parent AND ($thr_parent[0]['network'] == NETWORK_OSTATUS)) OR ($parent['network'] == NETWORK_OSTATUS)) {
  257. $push_notify = true;
  258. if ($parent["network"] == NETWORK_OSTATUS) {
  259. // Distribute the message to the DFRN contacts as if this wasn't a followup since OStatus can't relay comments
  260. // Currently it is work at progress
  261. $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `network` = '%s' AND NOT `blocked` AND NOT `pending` AND NOT `archive`",
  262. intval($uid),
  263. dbesc(NETWORK_DFRN)
  264. );
  265. if (dbm::is_result($r)) {
  266. foreach ($r as $rr) {
  267. $recipients_followup[] = $rr['id'];
  268. }
  269. }
  270. }
  271. }
  272. logger("Notify ".$target_item["guid"]." via PuSH: ".($push_notify?"Yes":"No"), LOGGER_DEBUG);
  273. } else {
  274. $followup = false;
  275. logger('Distributing directly '.$target_item["guid"], LOGGER_DEBUG);
  276. // don't send deletions onward for other people's stuff
  277. if ($target_item['deleted'] && (! intval($target_item['wall']))) {
  278. logger('notifier: ignoring delete notification for non-wall item');
  279. return;
  280. }
  281. if ((strlen($parent['allow_cid']))
  282. || (strlen($parent['allow_gid']))
  283. || (strlen($parent['deny_cid']))
  284. || (strlen($parent['deny_gid']))) {
  285. $public_message = false; // private recipients, not public
  286. }
  287. $allow_people = expand_acl($parent['allow_cid']);
  288. $allow_groups = expand_groups(expand_acl($parent['allow_gid']),true);
  289. $deny_people = expand_acl($parent['deny_cid']);
  290. $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
  291. // if our parent is a public forum (forum_mode == 1), uplink to the origional author causing
  292. // a delivery fork. private groups (forum_mode == 2) do not uplink
  293. if ((intval($parent['forum_mode']) == 1) && (! $top_level) && ($cmd !== 'uplink')) {
  294. proc_run(PRIORITY_HIGH,'include/notifier.php','uplink',$item_id);
  295. }
  296. $conversants = array();
  297. foreach ($items as $item) {
  298. $recipients[] = $item['contact-id'];
  299. $conversants[] = $item['contact-id'];
  300. // pull out additional tagged people to notify (if public message)
  301. if ($public_message && strlen($item['inform'])) {
  302. $people = explode(',',$item['inform']);
  303. foreach ($people as $person) {
  304. if (substr($person,0,4) === 'cid:') {
  305. $recipients[] = intval(substr($person,4));
  306. $conversants[] = intval(substr($person,4));
  307. } else {
  308. $url_recipients[] = substr($person,4);
  309. }
  310. }
  311. }
  312. }
  313. if (count($url_recipients))
  314. logger('notifier: '.$target_item["guid"].' url_recipients ' . print_r($url_recipients,true));
  315. $conversants = array_unique($conversants);
  316. $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups));
  317. $deny = array_unique(array_merge($deny_people,$deny_groups));
  318. $recipients = array_diff($recipients,$deny);
  319. $conversant_str = dbesc(implode(', ',$conversants));
  320. }
  321. // If the thread parent is OStatus then do some magic to distribute the messages.
  322. // We have not only to look at the parent, since it could be a Friendica thread.
  323. if (($thr_parent AND ($thr_parent[0]['network'] == NETWORK_OSTATUS)) OR ($parent['network'] == NETWORK_OSTATUS)) {
  324. $diaspora_delivery = false;
  325. logger('Some parent is OStatus for '.$target_item["guid"]." - Author: ".$thr_parent[0]['author-link']." - Owner: ".$thr_parent[0]['owner-link'], LOGGER_DEBUG);
  326. // Send a salmon to the parent author
  327. $r = q("SELECT `url`, `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''",
  328. dbesc(normalise_link($thr_parent[0]['author-link'])),
  329. intval($uid));
  330. if (dbm::is_result($r)) {
  331. $probed_contact = $r[0];
  332. } else {
  333. $probed_contact = probe_url($thr_parent[0]['author-link']);
  334. }
  335. if ($probed_contact["notify"] != "") {
  336. logger('Notify parent author '.$probed_contact["url"].': '.$probed_contact["notify"]);
  337. $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
  338. }
  339. // Send a salmon to the parent owner
  340. $r = q("SELECT `url`, `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''",
  341. dbesc(normalise_link($thr_parent[0]['owner-link'])),
  342. intval($uid));
  343. if (dbm::is_result($r)) {
  344. $probed_contact = $r[0];
  345. } else {
  346. $probed_contact = probe_url($thr_parent[0]['owner-link']);
  347. }
  348. if ($probed_contact["notify"] != "") {
  349. logger('Notify parent owner '.$probed_contact["url"].': '.$probed_contact["notify"]);
  350. $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
  351. }
  352. // Send a salmon notification to every person we mentioned in the post
  353. $arr = explode(',',$target_item['tag']);
  354. foreach ($arr as $x) {
  355. //logger('Checking tag '.$x, LOGGER_DEBUG);
  356. $matches = null;
  357. if (preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) {
  358. $probed_contact = probe_url($matches[1]);
  359. if ($probed_contact["notify"] != "") {
  360. logger('Notify mentioned user '.$probed_contact["url"].': '.$probed_contact["notify"]);
  361. $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
  362. }
  363. }
  364. }
  365. // It only makes sense to distribute answers to OStatus messages to Friendica and OStatus - but not Diaspora
  366. $sql_extra = " AND `network` IN ('".NETWORK_OSTATUS."', '".NETWORK_DFRN."')";
  367. } else {
  368. $sql_extra = " AND `network` IN ('".NETWORK_OSTATUS."', '".NETWORK_DFRN."', '".NETWORK_DIASPORA."', '".NETWORK_MAIL."', '".NETWORK_MAIL2."')";
  369. }
  370. } else {
  371. $public_message = false;
  372. }
  373. // If this is a public message and pubmail is set on the parent, include all your email contacts
  374. $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
  375. if (! $mail_disabled) {
  376. if ((! strlen($target_item['allow_cid'])) && (! strlen($target_item['allow_gid']))
  377. && (! strlen($target_item['deny_cid'])) && (! strlen($target_item['deny_gid']))
  378. && (intval($target_item['pubmail']))) {
  379. $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `network` = '%s'",
  380. intval($uid),
  381. dbesc(NETWORK_MAIL)
  382. );
  383. if (dbm::is_result($r)) {
  384. foreach ($r as $rr) {
  385. $recipients[] = $rr['id'];
  386. }
  387. }
  388. }
  389. }
  390. if ($followup) {
  391. $recip_str = implode(', ', $recipients_followup);
  392. } else {
  393. $recip_str = implode(', ', $recipients);
  394. }
  395. if ($relocate) {
  396. $r = $recipients_relocate;
  397. } else {
  398. $r = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND NOT `blocked` AND NOT `pending` AND NOT `archive`".$sql_extra,
  399. dbesc($recip_str)
  400. );
  401. }
  402. $interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval')));
  403. // If we are using the worker we don't need a delivery interval
  404. if (get_config("system", "worker")) {
  405. $interval = false;
  406. }
  407. // delivery loop
  408. if (dbm::is_result($r)) {
  409. foreach ($r as $contact) {
  410. if (!$contact['self']) {
  411. if (($contact['network'] === NETWORK_DIASPORA) && ($public_message)) {
  412. continue;
  413. }
  414. q("INSERT INTO `deliverq` (`cmd`,`item`,`contact`) VALUES ('%s', %d, %d)",
  415. dbesc($cmd),
  416. intval($item_id),
  417. intval($contact['id'])
  418. );
  419. }
  420. }
  421. // This controls the number of deliveries to execute with each separate delivery process.
  422. // By default we'll perform one delivery per process. Assuming a hostile shared hosting
  423. // provider, this provides the greatest chance of deliveries if processes start getting
  424. // killed. We can also space them out with the delivery_interval to also help avoid them
  425. // getting whacked.
  426. // If $deliveries_per_process > 1, we will chain this number of multiple deliveries
  427. // together into a single process. This will reduce the overall number of processes
  428. // spawned for each delivery, but they will run longer.
  429. // When using the workerqueue, we don't need this functionality.
  430. $deliveries_per_process = intval(get_config('system','delivery_batch_count'));
  431. if (($deliveries_per_process <= 0) OR get_config("system", "worker")) {
  432. $deliveries_per_process = 1;
  433. }
  434. $this_batch = array();
  435. for ($x = 0; $x < count($r); $x ++) {
  436. $contact = $r[$x];
  437. if ($contact['self']) {
  438. continue;
  439. }
  440. logger("Deliver ".$target_item["guid"]." to ".$contact['url']." via network ".$contact['network'], LOGGER_DEBUG);
  441. // potentially more than one recipient. Start a new process and space them out a bit.
  442. // we will deliver single recipient types of message and email recipients here.
  443. $this_batch[] = $contact['id'];
  444. if (count($this_batch) >= $deliveries_per_process) {
  445. proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$this_batch);
  446. $this_batch = array();
  447. if ($interval) {
  448. @time_sleep_until(microtime(true) + (float) $interval);
  449. }
  450. }
  451. continue;
  452. }
  453. // be sure to pick up any stragglers
  454. if (count($this_batch)) {
  455. proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$this_batch);
  456. }
  457. }
  458. // send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts
  459. // They are especially used for notifications to OStatus users that don't follow us.
  460. if ($slap && count($url_recipients) && ($public_message || $push_notify) && $normal_mode) {
  461. if (!get_config('system','dfrn_only')) {
  462. foreach ($url_recipients as $url) {
  463. if ($url) {
  464. logger('notifier: urldelivery: ' . $url);
  465. $deliver_status = slapper($owner,$url,$slap);
  466. /// @TODO Redeliver/queue these items on failure, though there is no contact record
  467. }
  468. }
  469. }
  470. }
  471. if ($public_message) {
  472. $r0 = array();
  473. $r1 = array();
  474. if ($diaspora_delivery) {
  475. if (!$followup) {
  476. $r0 = Diaspora::relay_list();
  477. }
  478. $r1 = q("SELECT DISTINCT(`batch`), `id`, `name`,`network` FROM `contact` WHERE `network` = '%s'
  479. AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch` ORDER BY rand()",
  480. dbesc(NETWORK_DIASPORA),
  481. intval($owner['uid']),
  482. intval(CONTACT_IS_SHARING)
  483. );
  484. }
  485. $r2 = q("SELECT `id`, `name`,`network` FROM `contact`
  486. WHERE `network` in ( '%s', '%s') AND `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `archive`
  487. AND `rel` != %d order by rand() ",
  488. dbesc(NETWORK_DFRN),
  489. dbesc(NETWORK_MAIL2),
  490. intval($owner['uid']),
  491. intval(CONTACT_IS_SHARING)
  492. );
  493. $r = array_merge($r2,$r1,$r0);
  494. if (dbm::is_result($r)) {
  495. logger('pubdeliver '.$target_item["guid"].': '.print_r($r,true), LOGGER_DEBUG);
  496. // throw everything into the queue in case we get killed
  497. foreach ($r as $rr) {
  498. if ((! $mail) && (! $fsuggest) && (! $followup)) {
  499. q("INSERT INTO `deliverq` (`cmd`,`item`,`contact`) VALUES ('%s', %d, %d)
  500. ON DUPLICATE KEY UPDATE `cmd` = '%s', `item` = %d, `contact` = %d",
  501. dbesc($cmd), intval($item_id), intval($rr['id']),
  502. dbesc($cmd), intval($item_id), intval($rr['id'])
  503. );
  504. }
  505. }
  506. foreach ($r as $rr) {
  507. // except for Diaspora batch jobs
  508. // Don't deliver to folks who have already been delivered to
  509. if (($rr['network'] !== NETWORK_DIASPORA) && (in_array($rr['id'],$conversants))) {
  510. logger('notifier: already delivered id=' . $rr['id']);
  511. continue;
  512. }
  513. if ((! $mail) && (! $fsuggest) && (! $followup)) {
  514. logger('notifier: delivery agent: '.$rr['name'].' '.$rr['id'].' '.$rr['network'].' '.$target_item["guid"]);
  515. proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$rr['id']);
  516. if ($interval) {
  517. @time_sleep_until(microtime(true) + (float) $interval);
  518. }
  519. }
  520. }
  521. }
  522. $push_notify = true;
  523. }
  524. // Notify PuSH subscribers (Used for OStatus distribution of regular posts)
  525. if ($push_notify AND strlen($hub)) {
  526. $hubs = explode(',', $hub);
  527. if (count($hubs)) {
  528. foreach ($hubs as $h) {
  529. $h = trim($h);
  530. if (! strlen($h)) {
  531. continue;
  532. }
  533. if ($h === '[internal]') {
  534. // Set push flag for PuSH subscribers to this topic,
  535. // they will be notified in queue.php
  536. q("UPDATE `push_subscriber` SET `push` = 1 ".
  537. "WHERE `nickname` = '%s' AND `push` = 0", dbesc($owner['nickname']));
  538. logger('Activating internal PuSH for item '.$item_id, LOGGER_DEBUG);
  539. } else {
  540. $params = 'hub.mode=publish&hub.url=' . urlencode( App::get_baseurl() . '/dfrn_poll/' . $owner['nickname'] );
  541. post_url($h,$params);
  542. logger('publish for item '.$item_id.' ' . $h . ' ' . $params . ' returned ' . $a->get_curl_code());
  543. }
  544. if (count($hubs) > 1) {
  545. sleep(7); // try and avoid multiple hubs responding at precisely the same time
  546. }
  547. }
  548. }
  549. // Handling the pubsubhubbub requests
  550. proc_run(PRIORITY_HIGH,'include/pubsubpublish.php');
  551. }
  552. logger('notifier: calling hooks', LOGGER_DEBUG);
  553. if ($normal_mode) {
  554. call_hooks('notifier_normal',$target_item);
  555. }
  556. call_hooks('notifier_end',$target_item);
  557. return;
  558. }
  559. if (array_search(__file__,get_included_files())===0){
  560. notifier_run($_SERVER["argv"],$_SERVER["argc"]);
  561. killme();
  562. }