]> git.mxchange.org Git - friendica.git/blobdiff - include/delivery.php
Merge pull request #3868 from rabuzarus/20171104_-_use_best_link_url_for_events
[friendica.git] / include / delivery.php
index 5000a1edb908a77e9fbcc6053cbb8921c40ba4c2..cddc9cb004006eb15d17c3bc0241734de6e1315a 100644 (file)
@@ -1,45 +1,28 @@
 <?php
 
-use \Friendica\Core\Config;
+use Friendica\App;
+use Friendica\Core\System;
+use Friendica\Core\Config;
 
-require_once("boot.php");
-require_once('include/queue_fn.php');
-require_once('include/html2plain.php');
-require_once("include/Scrape.php");
-require_once('include/diaspora.php');
-require_once("include/ostatus.php");
-require_once("include/dfrn.php");
+require_once 'include/queue_fn.php';
+require_once 'include/html2plain.php';
+require_once 'include/probe.php';
+require_once 'include/diaspora.php';
+require_once 'include/ostatus.php';
+require_once 'include/dfrn.php';
 
 function delivery_run(&$argv, &$argc){
-       global $a, $db;
+       global $a;
 
-       if (is_null($a)) {
-               $a = new App;
-       }
-
-       if (is_null($db)) {
-               @include(".htconfig.php");
-               require_once("include/dba.php");
-               $db = new dba($db_host, $db_user, $db_pass, $db_data);
-               unset($db_host, $db_user, $db_pass, $db_data);
-       }
-
-       require_once("include/session.php");
-       require_once("include/datetime.php");
-       require_once('include/items.php');
-       require_once('include/bbcode.php');
-       require_once('include/email.php');
-
-       Config::load();
-
-       load_hooks();
+       require_once 'include/datetime.php';
+       require_once 'include/items.php';
+       require_once 'include/bbcode.php';
+       require_once 'include/email.php';
 
        if ($argc < 3) {
                return;
        }
 
-       $a->set_baseurl(get_config('system','url'));
-
        logger('delivery: invoked: '. print_r($argv,true), LOGGER_DEBUG);
 
        $cmd        = $argv[1];
@@ -49,30 +32,6 @@ function delivery_run(&$argv, &$argc){
 
                $contact_id = intval($argv[$x]);
 
-               /// @todo When switching completely to the worker we won't need this anymore
-               // Some other process may have delivered this item already.
-
-               $r = q("SELECT * FROM `deliverq` WHERE `cmd` = '%s' AND `item` = %d AND `contact` = %d LIMIT 1",
-                       dbesc($cmd),
-                       dbesc($item_id),
-                       dbesc($contact_id)
-               );
-               if (!dbm::is_result($r)) {
-                       continue;
-               }
-
-               if ($a->maxload_reached()) {
-                       return;
-               }
-
-               // It's ours to deliver. Remove it from the queue.
-
-               q("DELETE FROM `deliverq` WHERE `cmd` = '%s' AND `item` = %d AND `contact` = %d",
-                       dbesc($cmd),
-                       dbesc($item_id),
-                       dbesc($contact_id)
-               );
-
                if (!$item_id || !$contact_id) {
                        continue;
                }
@@ -133,7 +92,7 @@ function delivery_run(&$argv, &$argc){
                        $uid = $item_id;
                } else {
                        // find ancestors
-                       $r = q("SELECT * FROM `item` WHERE `id` = %d and visible = 1 and moderated = 0 LIMIT 1",
+                       $r = q("SELECT * FROM `item` WHERE `id` = %d AND visible = 1 AND moderated = 0 LIMIT 1",
                                intval($item_id)
                        );
 
@@ -147,7 +106,7 @@ function delivery_run(&$argv, &$argc){
                        $updated = $r[0]['edited'];
 
                        $items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer`
-                               FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d and visible = 1 and moderated = 0 ORDER BY `id` ASC",
+                               FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d AND visible = 1 AND moderated = 0 ORDER BY `id` ASC",
                                intval($parent_id)
                        );
 
@@ -208,7 +167,7 @@ function delivery_run(&$argv, &$argc){
                $public_message = true;
 
                if (!($mail || $fsuggest || $relocate)) {
-                       require_once('include/group.php');
+                       require_once 'include/group.php';
 
                        $parent = $items[0];
 
@@ -341,7 +300,7 @@ function delivery_run(&$argv, &$argc){
 
                                // perform local delivery if we are on the same site
 
-                               if (link_compare($basepath,App::get_baseurl())) {
+                               if (link_compare($basepath,System::baseUrl())) {
 
                                        $nickname = basename($contact['url']);
                                        if ($contact['issued-id']) {
@@ -381,7 +340,7 @@ function delivery_run(&$argv, &$argc){
 
                                                // If we are setup as a soapbox we aren't accepting top level posts from this person
 
-                                               if (($x[0]['page-flags'] == PAGE_SOAPBOX) AND $top_level) {
+                                               if (($x[0]['page-flags'] == PAGE_SOAPBOX) && $top_level) {
                                                        break;
                                                }
                                                logger('mod-delivery: local delivery');
@@ -398,7 +357,7 @@ function delivery_run(&$argv, &$argc){
 
                                logger('notifier: dfrn_delivery to '.$contact["url"].' with guid '.$target_item["guid"].' returns '.$deliver_status);
 
-                               if ($deliver_status == (-1)) {
+                               if ($deliver_status < 0) {
                                        logger('notifier: delivery failed: queuing message');
                                        add_to_queue($contact['id'],NETWORK_DFRN,$atom);
 
@@ -495,7 +454,7 @@ function delivery_run(&$argv, &$argc){
                                                $headers .= "References: <".iri2msgid($it["parent-uri"]).">";
 
                                                // If Threading is enabled, write down the correct parent
-                                               if (($it["thr-parent"] != "") and ($it["thr-parent"] != $it["parent-uri"]))
+                                               if (($it["thr-parent"] != "") && ($it["thr-parent"] != $it["parent-uri"]))
                                                        $headers .= " <".iri2msgid($it["thr-parent"]).">";
                                                $headers .= "\n";
 
@@ -504,14 +463,14 @@ function delivery_run(&$argv, &$argc){
                                                                dbesc($it['parent-uri']),
                                                                intval($uid));
 
-                                                       if (dbm::is_result($r) AND ($r[0]['title'] != '')) {
+                                                       if (dbm::is_result($r) && ($r[0]['title'] != '')) {
                                                                $subject = $r[0]['title'];
                                                        } else {
                                                                $r = q("SELECT `title` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d LIMIT 1",
                                                                        dbesc($it['parent-uri']),
                                                                        intval($uid));
 
-                                                               if (dbm::is_result($r) AND ($r[0]['title'] != ''))
+                                                               if (dbm::is_result($r) && ($r[0]['title'] != ''))
                                                                        $subject = $r[0]['title'];
                                                        }
                                                }
@@ -549,6 +508,9 @@ function delivery_run(&$argv, &$argc){
                                        logger('diaspora retract: '.$loc);
                                        Diaspora::send_retraction($target_item,$owner,$contact,$public_message);
                                        break;
+                               } elseif ($relocate) {
+                                       Diaspora::sendAccountMigration($owner, $contact, $uid);
+                                       break;
                                } elseif ($followup) {
                                        // send comments and likes to owner to relay
                                        logger('diaspora followup: '.$loc);
@@ -577,8 +539,3 @@ function delivery_run(&$argv, &$argc){
 
        return;
 }
-
-if (array_search(__file__,get_included_files())===0){
-  delivery_run($_SERVER["argv"],$_SERVER["argc"]);
-  killme();
-}