]> git.mxchange.org Git - friendica.git/commitdiff
PortableContact created
authorAdam Magness <adam.magness@gmail.com>
Wed, 15 Nov 2017 15:53:16 +0000 (10:53 -0500)
committerAdam Magness <adam.magness@gmail.com>
Wed, 15 Nov 2017 15:53:16 +0000 (10:53 -0500)
Create PortableContact and remove socgraph, update references, and calls

26 files changed:
include/cronjobs.php
include/discover_poco.php
include/follow.php
include/gprobe.php
include/items.php
include/ostatus.php
include/pubsubpublish.php
include/queue.php
include/update_gcontact.php
mod/allfriends.php
mod/contacts.php
mod/dirfind.php
mod/hovercard.php
mod/item.php
mod/match.php
mod/nogroup.php
mod/poco.php
mod/profiles.php
mod/settings.php
mod/suggest.php
src/Model/GlobalContact.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Protocol/PortableContact.php
src/Worker/OnePoll.php
view/theme/vier/theme.php

index 0b0aa7f3300591a8ae1361e0c611689e052d7e65..2f6ade9c9692e30aa16da4392448ffe169416736 100644 (file)
@@ -8,6 +8,7 @@ use Friendica\Core\Config;
 use Friendica\Database\DBM;
 use Friendica\Model\GlobalContact;
 use Friendica\Network\Probe;
+use Friendica\Protocol\PortableContact;
 
 function cronjobs_run(&$argv, &$argc){
        global $a;
@@ -17,7 +18,6 @@ function cronjobs_run(&$argv, &$argc){
        require_once 'mod/nodeinfo.php';
        require_once 'include/photos.php';
        require_once 'include/user.php';
-       require_once 'include/socgraph.php';
 
        // No parameter set? So return
        if ($argc <= 1) {
@@ -226,7 +226,7 @@ function cron_repair_diaspora(App $a) {
                        return;
                }
 
-               if (!poco_reachable($contact["url"])) {
+               if (!PortableContact::reachable($contact["url"])) {
                        continue;
                }
 
index 90d55075f8c28c34e68920ce5e573bc0c77f6b06..3e374de9433e215da1b933ffbdff9f654ff75e46 100644 (file)
@@ -55,7 +55,7 @@ function discover_poco_run(&$argv, &$argc)
 
        if ($mode == 8) {
                if ($argv[2] != "") {
-                       poco_last_updated($argv[2], true);
+                       PortableContact::lastUpdated($argv[2], true);
                }
        } elseif ($mode == 7) {
                if ($argc == 6) {
@@ -65,7 +65,7 @@ function discover_poco_run(&$argv, &$argc)
                }
                PortableContact::load(intval($argv[2]), intval($argv[3]), intval($argv[4]), $url);
        } elseif ($mode == 6) {
-               poco_discover_single_server(intval($argv[2]));
+               PortableContact::discoverSingleServer(intval($argv[2]));
        } elseif ($mode == 5) {
                update_server();
        } elseif ($mode == 4) {
@@ -78,7 +78,7 @@ function discover_poco_run(&$argv, &$argc)
                        return;
                }
                $result = "Checking server ".$server_url." - ";
-               $ret = poco_check_server($server_url);
+               $ret = PortableContact::checkServer($server_url);
                if ($ret) {
                        $result .= "success";
                } else {
@@ -94,11 +94,12 @@ function discover_poco_run(&$argv, &$argc)
                gs_search_user($search);
        } elseif (($mode == 0) && ($search == "") && (Config::get('system', 'poco_discovery') > 0)) {
                // Query Friendica and Hubzilla servers for their users
-               poco_discover();
+               PortableContact::discover();
 
                // Query GNU Social servers for their users ("statistics" addon has to be enabled on the GS server)
-               if (!Config::get('system', 'ostatus_disabled'))
+               if (!Config::get('system', 'ostatus_disabled')) {
                        GlobalContact::gsDiscover();
+               }
        }
 
        logger('end '.$search);
@@ -120,7 +121,7 @@ function update_server() {
        $updated = 0;
 
        foreach ($r AS $server) {
-               if (!poco_do_update($server["created"], "", $server["last_failure"], $server["last_contact"])) {
+               if (!PortableContact::updateNeeded($server["created"], "", $server["last_failure"], $server["last_contact"])) {
                        continue;
                }
                logger('Update server status for server '.$server["url"], LOGGER_DEBUG);
@@ -172,7 +173,7 @@ function discover_users() {
                        continue;
                }
 
-               $server_url = poco_detect_server($user["url"]);
+               $server_url = PortableContact::detectServer($user["url"]);
                $force_update = false;
 
                if ($user["server_url"] != "") {
@@ -182,7 +183,7 @@ function discover_users() {
                        $server_url = $user["server_url"];
                }
 
-               if ((($server_url == "") && ($user["network"] == NETWORK_FEED)) || $force_update || poco_check_server($server_url, $user["network"])) {
+               if ((($server_url == "") && ($user["network"] == NETWORK_FEED)) || $force_update || PortableContact::checkServer($server_url, $user["network"])) {
                        logger('Check profile '.$user["url"]);
                        Worker::add(PRIORITY_LOW, "discover_poco", "check_profile", $user["url"]);
 
@@ -227,13 +228,13 @@ function discover_directory($search) {
                                        continue;
                                }
                                // Update the contact
-                               poco_last_updated($jj->url);
+                               PortableContact::lastUpdated($jj->url);
                                continue;
                        }
 
-                       $server_url = poco_detect_server($jj->url);
+                       $server_url = PortableContact::detectServer($jj->url);
                        if ($server_url != '') {
-                               if (!poco_check_server($server_url)) {
+                               if (!PortableContact::checkServer($server_url)) {
                                        logger("Friendica server ".$server_url." doesn't answer.", LOGGER_DEBUG);
                                        continue;
                                }
index 7dced715679f976ddd9b3f7cf99f6fb7641715c8..0f52a5bd8e2d4ef3f87bd9a9c08e9be23436ee82 100644 (file)
@@ -1,5 +1,7 @@
 <?php
-
+/**
+ * @file include/follow.php
+ */
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\System;
@@ -7,8 +9,8 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBM;
 use Friendica\Network\Probe;
 use Friendica\Protocol\Diaspora;
+use Friendica\Protocol\PortableContact;
 
-require_once 'include/socgraph.php';
 require_once 'include/group.php';
 require_once 'include/salmon.php';
 require_once 'include/ostatus.php';
@@ -57,7 +59,7 @@ function update_contact($id) {
        );
 
        // Update the corresponding gcontact entry
-       poco_last_updated($ret["url"]);
+       PortableContact::lastUpdated($ret["url"]);
 
        return true;
 }
index 30c81aa81e1ff64a180f6cbce94a059d1c97bd00..a6b46afc563d02cbf29550cc9a85d355dfff383a 100644 (file)
@@ -54,7 +54,7 @@ function gprobe_run(&$argv, &$argc)
        }
        if (DBM::is_result($r)) {
                // Check for accessibility and do a poco discovery
-               if (poco_last_updated($r[0]['url'], true) && ($r[0]["network"] == NETWORK_DFRN)) {
+               if (PortableContact::lastUpdated($r[0]['url'], true) && ($r[0]["network"] == NETWORK_DFRN)) {
                        PortableContact::loadWorker(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
                }
        }
index 675f33f40f945c977b3285e82f5d7adb71594d7f..1e6ef7d22539cc01d5626af882673a0263deb728 100644 (file)
@@ -5,15 +5,15 @@
  */
 
 use Friendica\App;
-use Friendica\Core\System;
 use Friendica\ParseUrl;
-use Friendica\Util\Lock;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
 use Friendica\Core\Worker;
+use Friendica\Core\System;
 use Friendica\Database\DBM;
 use Friendica\Model\GlobalContact;
 use Friendica\Protocol\DFRN;
+use Friendica\Util\Lock;
 
 require_once 'include/bbcode.php';
 require_once 'include/oembed.php';
@@ -25,7 +25,6 @@ require_once 'include/files.php';
 require_once 'include/text.php';
 require_once 'include/email.php';
 require_once 'include/threads.php';
-require_once 'include/socgraph.php';
 require_once 'include/plaintext.php';
 require_once 'include/ostatus.php';
 require_once 'include/feed.php';
index 091b3e80da0ac80828afd49381ddbc24d6beaa03..5df956b2c9c93e63a69a0cef83bf7f1279ccdd9a 100644 (file)
@@ -5,8 +5,8 @@
 
 use Friendica\App;
 use Friendica\Core\Cache;
-use Friendica\Core\System;
 use Friendica\Core\Config;
+use Friendica\Core\System;
 use Friendica\Database\DBM;
 use Friendica\Model\GlobalContact;
 use Friendica\Network\Probe;
@@ -20,7 +20,6 @@ require_once 'include/bbcode.php';
 require_once 'include/items.php';
 require_once 'mod/share.php';
 require_once 'include/enotify.php';
-require_once 'include/socgraph.php';
 require_once 'include/Photo.php';
 require_once 'include/follow.php';
 require_once 'include/api.php';
index 52a707b8bcdff5ef7d83244c00e82469f6f896fa..a283c685963b2603fb376aade0a4ab795e6fd216 100644 (file)
@@ -41,7 +41,7 @@ function handle_pubsubhubbub($id) {
 
        $rr = $r[0];
 
-       /// @todo Check server status with poco_check_server()
+       /// @todo Check server status with PortableContact::checkServer()
        // Before this can be done we need a way to safely detect the server url.
 
        logger("Generate feed of user ".$rr['nickname']." to ".$rr['callback_url']." - last updated ".$rr['last_update'], LOGGER_DEBUG);
index a56c41d97a9c19ad785a95c70f5a24ffd82c79b2..8a6564ce456947c43aa95ec63ba41508ac27c35c 100644 (file)
@@ -8,12 +8,12 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBM;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\DFRN;
+use Friendica\Protocol\PortableContact;
 
 require_once 'include/queue_fn.php';
 require_once 'include/datetime.php';
 require_once 'include/items.php';
 require_once 'include/bbcode.php';
-require_once 'include/socgraph.php';
 
 function queue_run(&$argv, &$argc)
 {
@@ -99,7 +99,7 @@ function queue_run(&$argv, &$argc)
                return;
        }
 
-       $server = poco_detect_server($c[0]['url']);
+       $server = PortableContact::detectServer($c[0]['url']);
 
        if ($server != "") {
                $vital = Cache::get($cachekey_server.$server);
@@ -107,7 +107,7 @@ function queue_run(&$argv, &$argc)
                if (is_null($vital)) {
                        logger("Check server ".$server." (".$c[0]["network"].")");
 
-                       $vital = poco_check_server($server, $c[0]["network"], true);
+                       $vital = PortableContact::checkServer($server, $c[0]["network"], true);
                        Cache::set($cachekey_server.$server, $vital, CACHE_QUARTER_HOUR);
                }
 
index cd7a9366fbc94790967b9113f71e1e976f952208..953778786e94108f6ec1034d64dad8cda5a10187 100644 (file)
@@ -1,14 +1,15 @@
 <?php
-
+/**
+ * @file include/update_gcontact.php
+ */
 use Friendica\Core\Config;
-use Friendica\Network\Probe;
 use Friendica\Database\DBM;
+use Friendica\Network\Probe;
+use Friendica\Protocol\PortableContact;
 
 function update_gcontact_run(&$argv, &$argc) {
        global $a;
 
-       require_once 'include/socgraph.php';
-
        logger('update_gcontact: start');
 
        if (($argc > 1) && (intval($argv[1]))) {
@@ -34,7 +35,7 @@ function update_gcontact_run(&$argv, &$argc) {
 
        if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
                if ($r[0]["server_url"] != "")
-                       poco_check_server($r[0]["server_url"], $r[0]["network"]);
+                       PortableContact::checkServer($r[0]["server_url"], $r[0]["network"]);
 
                q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d",
                        dbesc(datetime_convert()), intval($contact_id));
index 360c7d3c9e95896e0e0b42993c22cd9b4662a879..0a6989e4d01ea9a85b6e88fa887d02483c5f8b5b 100644 (file)
@@ -7,7 +7,6 @@ use Friendica\Core\System;
 use Friendica\Database\DBM;
 use Friendica\Model\GlobalContact;
 
-require_once 'include/socgraph.php';
 require_once 'include/Contact.php';
 require_once 'include/contact_selectors.php';
 require_once 'mod/contacts.php';
index 8da40152e228d7ea6bb07dd8b18dac3112e00cdf..10a4f6b1b852cf8b1aecabbd23a49568e5e1bf80 100644 (file)
@@ -8,7 +8,6 @@ use Friendica\Model\GlobalContact;
 use Friendica\Network\Probe;
 
 require_once 'include/Contact.php';
-require_once 'include/socgraph.php';
 require_once 'include/contact_selectors.php';
 require_once 'mod/proxy.php';
 require_once 'include/Photo.php';
index e4e611699d35032eb9797e90a44646e8125d88b6..84fe6f0ff49de8f23af517de565282f7f1161e29 100644 (file)
@@ -1,14 +1,16 @@
 <?php
-
+/**
+ * @file mod/dirfind.php
+ */
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Model\GlobalContact;
 use Friendica\Network\Probe;
+use Friendica\Protocol\PortableContact;
 
 require_once 'include/contact_widgets.php';
-require_once 'include/socgraph.php';
 require_once 'include/Contact.php';
 require_once 'include/contact_selectors.php';
 require_once 'mod/contacts.php';
@@ -143,7 +145,7 @@ function dirfind_content(App $a, $prefix = "") {
                        $j->items_page = $perpage;
                        $j->page = $a->pager['page'];
                        foreach ($results AS $result) {
-                               if (poco_alternate_ostatus_url($result["url"])) {
+                               if (PortableContact::alternateOStatusUrl($result["url"])) {
                                        continue;
                                }
 
index f21db31f886f88578de3cf96640354b2d1ec3af8..a5a41e26357756b6c0bf9e389fffb436ee5def2a 100644 (file)
@@ -12,7 +12,6 @@ use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Model\GlobalContact;
 
-require_once "include/socgraph.php";
 require_once "include/Contact.php";
 
 function hovercard_init(App $a) {
index 9a725bae440a6d8905d87bc78c668588cc0f9bfe..400acfc971a3c5bad9ba6e3efdfe1bcb7a80b442 100644 (file)
@@ -1133,9 +1133,8 @@ function item_content(App $a) {
  *
  * @return boolean true if replaced, false if not replaced
  */
-function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "") {
-       require_once 'include/socgraph.php';
-
+function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "")
+{
        $replaced = false;
        $r = null;
        $tag_type = '@';
index 2824e6b71dfdc8bdbf30ac31ecf2e52cb0279067..7258fd9c70d9697d6b5924a8c0e0565353941be8 100644 (file)
@@ -1,14 +1,15 @@
 <?php
-
+/**
+ * @file mod/match.php
+ */
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
 
-require_once('include/text.php');
-require_once('include/socgraph.php');
-require_once('include/contact_widgets.php');
-require_once('mod/proxy.php');
+require_once 'include/text.php';
+require_once 'include/contact_widgets.php';
+require_once 'mod/proxy.php';
 
 /**
  * @brief Controller for /match.
@@ -16,11 +17,12 @@ require_once('mod/proxy.php');
  * It takes keywords from your profile and queries the directory server for
  * matching keywords from other profiles.
  *
- * @param App $a
+ * @param App $a App
+ *
  * @return void|string
  */
-function match_content(App $a) {
-
+function match_content(App $a)
+{
        $o = '';
        if (! local_user()) {
                return;
@@ -31,46 +33,50 @@ function match_content(App $a) {
 
        $_SESSION['return_url'] = System::baseUrl() . '/' . $a->cmd;
 
-       $r = q("SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
+       $r = q(
+               "SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
                intval(local_user())
        );
        if (! DBM::is_result($r)) {
                return;
        }
-       if(! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) {
-               notice( t('No keywords to match. Please add keywords to your default profile.') . EOL);
+       if (! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) {
+               notice(t('No keywords to match. Please add keywords to your default profile.') . EOL);
                return;
        }
 
        $params = array();
        $tags = trim($r[0]['pub_keywords'] . ' ' . $r[0]['prv_keywords']);
 
-       if($tags) {
+       if ($tags) {
                $params['s'] = $tags;
-               if($a->pager['page'] != 1)
+               if ($a->pager['page'] != 1) {
                        $params['p'] = $a->pager['page'];
+               }
 
-               if(strlen(Config::get('system','directory')))
+               if (strlen(Config::get('system', 'directory'))) {
                        $x = post_url(get_server().'/msearch', $params);
-               else
+               } else {
                        $x = post_url(System::baseUrl() . '/msearch', $params);
+               }
 
                $j = json_decode($x);
 
-               if($j->total) {
+               if ($j->total) {
                        $a->set_pager_total($j->total);
                        $a->set_pager_itemspage($j->items_page);
                }
 
-               if(count($j->results)) {
-
+               if (count($j->results)) {
                        $id = 0;
 
-                       foreach($j->results as $jj) {
+                       foreach ($j->results as $jj) {
                                $match_nurl = normalise_link($jj->url);
-                               $match = q("SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1",
+                               $match = q(
+                                       "SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1",
                                        intval(local_user()),
-                                       dbesc($match_nurl));
+                                       dbesc($match_nurl)
+                               );
 
                                if (!count($match)) {
                                        $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
@@ -102,19 +108,18 @@ function match_content(App $a) {
                                }
                        }
 
-               $tpl = get_markup_template('viewcontact_template.tpl');
-
-               $o .= replace_macros($tpl,array(
-                       '$title' => t('Profile Match'),
-                       '$contacts' => $entries,
-                       '$paginate' => paginate($a),
-               ));
-
-               }
-               else {
-                       info( t('No matches') . EOL);
+                       $tpl = get_markup_template('viewcontact_template.tpl');
+
+                       $o .= replace_macros(
+                               $tpl,
+                               array(
+                               '$title' => t('Profile Match'),
+                               '$contacts' => $entries,
+                               '$paginate' => paginate($a))
+                       );
+               else {
+                       info(t('No matches') . EOL);
                }
-
        }
 
        return $o;
index 04866632824ff38345d267ac506ad6c16c4b84b4..e212b30dc16265bd4d00db73c9ba4511d23db0c9 100644 (file)
@@ -1,45 +1,44 @@
 <?php
-
+/**
+ * @file mod/nogroup.php
+ */
 use Friendica\App;
 use Friendica\Database\DBM;
 
-require_once('include/Contact.php');
-require_once('include/socgraph.php');
-require_once('include/contact_selectors.php');
-
-function nogroup_init(App $a) {
+require_once 'include/Contact.php';
+require_once 'include/contact_selectors.php';
 
+function nogroup_init(App $a)
+{
        if (! local_user()) {
                return;
        }
 
-       require_once('include/group.php');
-       require_once('include/contact_widgets.php');
+       require_once 'include/group.php';
+       require_once 'include/contact_widgets.php';
 
-       if (! x($a->page,'aside')) {
+       if (! x($a->page, 'aside')) {
                $a->page['aside'] = '';
        }
 
-       $a->page['aside'] .= group_side('contacts','group','extended',0,$contact_id);
+       $a->page['aside'] .= group_side('contacts', 'group', 'extended', 0, $contact_id);
 }
 
-
-function nogroup_content(App $a) {
-
+function nogroup_content(App $a)
+{
        if (! local_user()) {
-               notice( t('Permission denied.') . EOL);
+               notice(t('Permission denied.') . EOL);
                return '';
        }
 
-       require_once('include/Contact.php');
+       require_once 'include/Contact.php';
        $r = contacts_not_grouped(local_user());
        if (DBM::is_result($r)) {
                $a->set_pager_total($r[0]['total']);
        }
-       $r = contacts_not_grouped(local_user(),$a->pager['start'],$a->pager['itemspage']);
+       $r = contacts_not_grouped(local_user(), $a->pager['start'], $a->pager['itemspage']);
        if (DBM::is_result($r)) {
                foreach ($r as $rr) {
-
                        $contact_details = get_contact_details_by_url($rr['url'], local_user(), $rr);
 
                        $contacts[] = array(
@@ -64,12 +63,13 @@ function nogroup_content(App $a) {
        }
 
        $tpl = get_markup_template("nogroup-template.tpl");
-       $o .= replace_macros($tpl, array(
+       $o .= replace_macros(
+               $tpl,
+               array(
                '$header' => t('Contacts who are not members of a group'),
                '$contacts' => $contacts,
-               '$paginate' => paginate($a),
-       ));
+               '$paginate' => paginate($a))
+       );
 
        return $o;
-
 }
index a32972f9ee158b6e4cabd63ea0348007065dee79..2e2791fc1ee6b763c008d79364dfb4192a59d36d 100644 (file)
@@ -7,6 +7,7 @@ use Friendica\App;
 use Friendica\Core\Cache;
 use Friendica\Core\Config;
 use Friendica\Database\DBM;
+use Friendica\Protocol\PortableContact;
 
 function poco_init(App $a) {
        $system_mode = false;
@@ -32,9 +33,8 @@ function poco_init(App $a) {
        $global = false;
 
        if ($a->argc > 1 && $a->argv[1] === '@server') {
-               require_once 'include/socgraph.php';
                // List of all servers that this server knows
-               $ret = poco_serverlist();
+               $ret = PortableContact::serverlist();
                header('Content-type: application/json');
                echo json_encode($ret);
                killme();
index f3e71491f7aa448dc54f406a4c0ec1ab7b444f2b..4263897d0b19cbbac30704d8c1bd368c68cf8b9b 100644 (file)
@@ -12,7 +12,6 @@ use Friendica\Model\GlobalContact;
 use Friendica\Network\Probe;
 
 require_once 'include/Contact.php';
-require_once 'include/socgraph.php';
 
 function profiles_init(App $a) {
 
@@ -755,7 +754,6 @@ function profiles_content(App $a) {
 
                return $o;
        } else {
-
                // If we don't support multi profiles, don't display this list.
                if (!feature_enabled(local_user(), 'multi_profiles')) {
                        $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1",
index 296e8684ca0bf98da8a363a50c9420d530ee3163..e693f775958d9db5e14f832f9924c7601ed77a09 100644 (file)
@@ -1,14 +1,16 @@
 <?php
-
+/**
+ * @file mod/settings.php
+ */
 use Friendica\App;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
 use Friendica\Database\DBM;
+use Friendica\Model\GlobalContact;
 
-require_once('include/group.php');
-require_once('include/socgraph.php');
+require_once 'include/group.php';
 
 function get_theme_config_file($theme) {
        $a = get_app();
index 8451173a5fe6f7f0a61e30243097f3e5135d8442..bb23fc8cba71ae1d26d2de67455e39b7c3a31f66 100644 (file)
@@ -7,7 +7,6 @@ use Friendica\Core\System;
 use Friendica\Database\DBM;
 use Friendica\Model\GlobalContact;
 
-require_once 'include/socgraph.php';
 require_once 'include/contact_widgets.php';
 
 function suggest_init(App $a) {
index dc62024bc4095120ca6f24aa11bb33bdc6c100bc..21ac0d60e7da00c66abb80e2fea889f02d1fc591 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /**
  * @file src/Model/GlobalContact.php
  * @brief This file includes the GlobalContact class with directory related functions
@@ -169,7 +168,7 @@ class GlobalContact
                        $gcontact['url'] = self::cleanContactUrl($gcontact['url']);
                }
 
-               $alternate = poco_alternate_ostatus_url($gcontact['url']);
+               $alternate = PortableContact::alternateOStatusUrl($gcontact['url']);
 
                // The global contacts should contain the original picture, not the cached one
                if (($gcontact['generation'] != 1) && stristr(normalise_link($gcontact['photo']), normalise_link(System::baseUrl()."/photo/"))) {
@@ -223,7 +222,7 @@ class GlobalContact
                }
 
                if ((!isset($gcontact['network']) || !isset($gcontact['name']) || !isset($gcontact['addr']) || !isset($gcontact['photo']) || !isset($gcontact['server_url']) || $alternate)
-                       && poco_reachable($gcontact['url'], $gcontact['server_url'], $gcontact['network'], false)
+                       && PortableContact::reachable($gcontact['url'], $gcontact['server_url'], $gcontact['network'], false)
                ) {
                        $data = Probe::uri($gcontact['url']);
 
@@ -257,7 +256,7 @@ class GlobalContact
 
                if (!isset($gcontact['server_url'])) {
                        // We check the server url to be sure that it is a real one
-                       $server_url = poco_detect_server($gcontact['url']);
+                       $server_url = PortableContact::detectServer($gcontact['url']);
 
                        // We are now sure that it is a correct URL. So we use it in the future
                        if ($server_url != "") {
@@ -266,7 +265,7 @@ class GlobalContact
                }
 
                // The server URL doesn't seem to be valid, so we don't store it.
-               if (!poco_check_server($gcontact['server_url'], $gcontact['network'])) {
+               if (!PortableContact::checkServer($gcontact['server_url'], $gcontact['network'])) {
                        $gcontact['server_url'] = "";
                }
 
@@ -524,7 +523,7 @@ class GlobalContact
                                $j = json_decode($x);
                                if ($j->entries) {
                                        foreach ($j->entries as $entry) {
-                                               poco_check_server($entry->url);
+                                               PortableContact::checkServer($entry->url);
 
                                                $url = $entry->url . '/poco';
                                                if (! in_array($url, $done)) {
@@ -591,7 +590,7 @@ class GlobalContact
         */
        public static function fixAlternateContactAddress(&$contact)
        {
-               if (($contact["network"] == NETWORK_OSTATUS) && poco_alternate_ostatus_url($contact["url"])) {
+               if (($contact["network"] == NETWORK_OSTATUS) && PortableContact::alternateOStatusUrl($contact["url"])) {
                        $data = Probe::uri($contact["url"]);
                        if ($contact["network"] == NETWORK_OSTATUS) {
                                logger("Fix primary url from ".$contact["url"]." to ".$data["url"]." - Called by: ".System::callstack(), LOGGER_DEBUG);
index 0788d36f4ee5836ef301e10678be0c9feb3d9208..86f009f31ae80c310a9a262bc37fda2025c0a6b3 100644 (file)
@@ -24,7 +24,6 @@ use ostatus;
 require_once "include/Contact.php";
 require_once "include/enotify.php";
 require_once "include/threads.php";
-require_once "include/socgraph.php";
 require_once "include/items.php";
 require_once "include/tags.php";
 require_once "include/files.php";
index 758a23db887259f8097c3a32930089b34e38aa28..0c0c3bb2fa1bb32e671065cbbc073d448ca688f1 100644 (file)
@@ -27,7 +27,6 @@ require_once 'include/items.php';
 require_once 'include/bb2diaspora.php';
 require_once 'include/Contact.php';
 require_once 'include/Photo.php';
-require_once 'include/socgraph.php';
 require_once 'include/group.php';
 require_once 'include/datetime.php';
 require_once 'include/queue_fn.php';
index f884b0f283a641926f04b83da647b63f6a632990..f4f20dc0866ff2c8fb3b0b83f81d158bcfef4ad6 100644 (file)
@@ -17,6 +17,10 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBM;
 use Friendica\Model\GlobalContact;
 use Friendica\Network\Probe;
+use dba;
+use DOMDocument;
+use DomXPath;
+use Exception;
 
 require_once 'include/datetime.php';
 require_once 'include/network.php';
@@ -210,21 +214,21 @@ class PortableContact
                );
        }
 
-       function poco_reachable($profile, $server = "", $network = "", $force = false) {
-
+       public static function reachable($profile, $server = "", $network = "", $force = false)
+       {
                if ($server == "") {
-                       $server = poco_detect_server($profile);
+                       $server = self::detectServer($profile);
                }
 
                if ($server == "") {
                        return true;
                }
 
-               return poco_check_server($server, $network, $force);
+               return self::checkServer($server, $network, $force);
        }
 
-       function poco_detect_server($profile) {
-
+       public static function detectServer($profile)
+       {
                // Try to detect the server path based upon some known standard paths
                $server_url = "";
 
@@ -283,8 +287,11 @@ class PortableContact
                        return "";
                }
 
-               $r = q("SELECT `id` FROM `gserver` WHERE `nurl` = '%s' AND `last_contact` > `last_failure`",
-                       dbesc(normalise_link($server_url)));
+               $r = q(
+                       "SELECT `id` FROM `gserver` WHERE `nurl` = '%s' AND `last_contact` > `last_failure`",
+                       dbesc(normalise_link($server_url))
+               );
+
                if (DBM::is_result($r)) {
                        return $server_url;
                }
@@ -298,14 +305,17 @@ class PortableContact
                return $server_url;
        }
 
-       function poco_alternate_ostatus_url($url) {
+       public static function alternateOStatusUrl($url)
+       {
                return(preg_match("=https?://.+/user/\d+=ism", $url, $matches));
        }
 
-       function poco_last_updated($profile, $force = false) {
-
-               $gcontacts = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'",
-                               dbesc(normalise_link($profile)));
+       public static function lastUpdated($profile, $force = false)
+       {
+               $gcontacts = q(
+                       "SELECT * FROM `gcontact` WHERE `nurl` = '%s'",
+                       dbesc(normalise_link($profile))
+               );
 
                if (!DBM::is_result($gcontacts)) {
                        return false;
@@ -318,7 +328,7 @@ class PortableContact
                }
 
                if ($force) {
-                       $server_url = normalise_link(poco_detect_server($profile));
+                       $server_url = normalise_link(self::detectServer($profile));
                }
 
                if (($server_url == '') && ($gcontacts[0]["server_url"] != "")) {
@@ -326,7 +336,7 @@ class PortableContact
                }
 
                if (!$force && (($server_url == '') || ($gcontacts[0]["server_url"] == $gcontacts[0]["nurl"]))) {
-                       $server_url = normalise_link(poco_detect_server($profile));
+                       $server_url = normalise_link(self::detectServer($profile));
                }
 
                if (!in_array($gcontacts[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_FEED, NETWORK_OSTATUS, ""))) {
@@ -335,10 +345,13 @@ class PortableContact
                }
 
                if ($server_url != "") {
-                       if (!poco_check_server($server_url, $gcontacts[0]["network"], $force)) {
+                       if (!self::checkServer($server_url, $gcontacts[0]["network"], $force)) {
                                if ($force) {
-                                       q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'",
-                                               dbesc(datetime_convert()), dbesc(normalise_link($profile)));
+                                       q(
+                                               "UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'",
+                                               dbesc(datetime_convert()),
+                                               dbesc(normalise_link($profile))
+                                       );
                                }
 
                                logger("Profile ".$profile.": Server ".$server_url." wasn't reachable.", LOGGER_DEBUG);
@@ -348,8 +361,10 @@ class PortableContact
                }
 
                if (in_array($gcontacts[0]["network"], array("", NETWORK_FEED))) {
-                       $server = q("SELECT `network` FROM `gserver` WHERE `nurl` = '%s' AND `network` != ''",
-                               dbesc(normalise_link($server_url)));
+                       $server = q(
+                               "SELECT `network` FROM `gserver` WHERE `nurl` = '%s' AND `network` != ''",
+                               dbesc(normalise_link($server_url))
+                       );
 
                        if ($server) {
                                $contact['network'] = $server[0]["network"];
@@ -360,7 +375,6 @@ class PortableContact
 
                // noscrape is really fast so we don't cache the call.
                if (($server_url != "") && ($gcontacts[0]["nick"] != "")) {
-
                        //  Use noscrape if possible
                        $server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($server_url)));
 
@@ -368,7 +382,6 @@ class PortableContact
                                $noscraperet = z_fetch_url($server[0]["noscrape"]."/".$gcontacts[0]["nick"]);
 
                                if ($noscraperet["success"] && ($noscraperet["body"] != "")) {
-
                                        $noscrape = json_decode($noscraperet["body"], true);
 
                                        if (is_array($noscrape)) {
@@ -418,8 +431,11 @@ class PortableContact
                                                GlobalContact::update($contact);
 
                                                if (trim($noscrape["updated"]) != "") {
-                                                       q("UPDATE `gcontact` SET `last_contact` = '%s' WHERE `nurl` = '%s'",
-                                                               dbesc(datetime_convert()), dbesc(normalise_link($profile)));
+                                                       q(
+                                                               "UPDATE `gcontact` SET `last_contact` = '%s' WHERE `nurl` = '%s'",
+                                                               dbesc(datetime_convert()),
+                                                               dbesc(normalise_link($profile))
+                                                       );
 
                                                        logger("Profile ".$profile." was last updated at ".$noscrape["updated"]." (noscrape)", LOGGER_DEBUG);
 
@@ -431,7 +447,7 @@ class PortableContact
                }
 
                // If we only can poll the feed, then we only do this once a while
-               if (!$force && !poco_do_update($gcontacts[0]["created"], $gcontacts[0]["updated"], $gcontacts[0]["last_failure"], $gcontacts[0]["last_contact"])) {
+               if (!$force && !self::updateNeeded($gcontacts[0]["created"], $gcontacts[0]["updated"], $gcontacts[0]["last_failure"], $gcontacts[0]["last_contact"])) {
                        logger("Profile ".$profile." was last updated at ".$gcontacts[0]["updated"]." (cached)", LOGGER_DEBUG);
 
                        GlobalContact::update($contact);
@@ -442,7 +458,7 @@ class PortableContact
 
                // Is the profile link the alternate OStatus link notation? (http://domain.tld/user/4711)
                // Then check the other link and delete this one
-               if (($data["network"] == NETWORK_OSTATUS) && poco_alternate_ostatus_url($profile)
+               if (($data["network"] == NETWORK_OSTATUS) && self::alternateOStatusUrl($profile)
                        && (normalise_link($profile) == normalise_link($data["alias"]))
                        && (normalise_link($profile) != normalise_link($data["url"]))
                ) {
@@ -458,7 +474,7 @@ class PortableContact
                                $gcontact = GlobalContact::sanitize($gcontact);
                                GlobalContact::update($gcontact);
 
-                               poco_last_updated($data["url"], $force);
+                               self::lastUpdated($data["url"], $force);
                        } catch (Exception $e) {
                                logger($e->getMessage(), LOGGER_DEBUG);
                        }
@@ -468,8 +484,11 @@ class PortableContact
                }
 
                if (($data["poll"] == "") || (in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
-                       q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'",
-                               dbesc(datetime_convert()), dbesc(normalise_link($profile)));
+                       q(
+                               "UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'",
+                               dbesc(datetime_convert()),
+                               dbesc(normalise_link($profile))
+                       );
 
                        logger("Profile ".$profile." wasn't reachable (profile)", LOGGER_DEBUG);
                        return false;
@@ -484,8 +503,11 @@ class PortableContact
                $feedret = z_fetch_url($data["poll"]);
 
                if (!$feedret["success"]) {
-                       q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'",
-                               dbesc(datetime_convert()), dbesc(normalise_link($profile)));
+                       q(
+                               "UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'",
+                               dbesc(datetime_convert()),
+                               dbesc(normalise_link($profile))
+                       );
 
                        logger("Profile ".$profile." wasn't reachable (no feed)", LOGGER_DEBUG);
                        return false;
@@ -518,12 +540,18 @@ class PortableContact
                                $last_updated = NULL_DATE;
                        }
                }
-               q("UPDATE `gcontact` SET `updated` = '%s', `last_contact` = '%s' WHERE `nurl` = '%s'",
-                       dbesc(DBM::date($last_updated)), dbesc(DBM::date()), dbesc(normalise_link($profile)));
+               q(
+                       "UPDATE `gcontact` SET `updated` = '%s', `last_contact` = '%s' WHERE `nurl` = '%s'",
+                       dbesc(DBM::date($last_updated)),
+                       dbesc(DBM::date()),
+                       dbesc(normalise_link($profile))
+               );
 
                if (($gcontacts[0]["generation"] == 0)) {
-                       q("UPDATE `gcontact` SET `generation` = 9 WHERE `nurl` = '%s'",
-                               dbesc(normalise_link($profile)));
+                       q(
+                               "UPDATE `gcontact` SET `generation` = 9 WHERE `nurl` = '%s'",
+                               dbesc(normalise_link($profile))
+                       );
                }
 
                logger("Profile ".$profile." was last updated at ".$last_updated, LOGGER_DEBUG);
@@ -531,7 +559,8 @@ class PortableContact
                return($last_updated);
        }
 
-       function poco_do_update($created, $updated, $last_failure, $last_contact) {
+       public static function updateNeeded($created, $updated, $last_failure, $last_contact)
+       {
                $now = strtotime(datetime_convert());
 
                if ($updated > $last_contact) {
@@ -575,7 +604,8 @@ class PortableContact
                return true;
        }
 
-       function poco_to_boolean($val) {
+       public static function toBoolean($val)
+       {
                if (($val == "true") || ($val == 1)) {
                        return true;
                } elseif (($val == "false") || ($val == 0)) {
@@ -591,7 +621,8 @@ class PortableContact
         * @param object $data POCO data
         * @return array Server data
         */
-       function poco_detect_poco_data($data) {
+       public static function detectPocoData($data)
+       {
                $server = false;
 
                if (!isset($data->entry)) {
@@ -627,7 +658,8 @@ class PortableContact
         * @param string $server_url address of the server
         * @return array Server data
         */
-       function poco_fetch_nodeinfo($server_url) {
+       public static function fetchNodeinfo($server_url)
+       {
                $serverret = z_fetch_url($server_url."/.well-known/nodeinfo");
                if (!$serverret["success"]) {
                        return false;
@@ -734,7 +766,8 @@ class PortableContact
         * @param string $body Front page of the server
         * @return array Server data
         */
-       function poco_detect_server_type($body) {
+       public static function detectServerType($body)
+       {
                $server = false;
 
                $doc = new DOMDocument();
@@ -790,8 +823,8 @@ class PortableContact
                return $server;
        }
 
-       function poco_check_server($server_url, $network = "", $force = false) {
-
+       public static function checkServer($server_url, $network = "", $force = false)
+       {
                // Unify the server address
                $server_url = trim($server_url, "/");
                $server_url = str_replace("/index.php", "", $server_url);
@@ -802,10 +835,12 @@ class PortableContact
 
                $servers = q("SELECT * FROM `gserver` WHERE `nurl` = '%s'", dbesc(normalise_link($server_url)));
                if (DBM::is_result($servers)) {
-
                        if ($servers[0]["created"] <= NULL_DATE) {
-                               q("UPDATE `gserver` SET `created` = '%s' WHERE `nurl` = '%s'",
-                                       dbesc(datetime_convert()), dbesc(normalise_link($server_url)));
+                               q(
+                                       "UPDATE `gserver` SET `created` = '%s' WHERE `nurl` = '%s'",
+                                       dbesc(datetime_convert()),
+                                       dbesc(normalise_link($server_url))
+                               );
                        }
                        $poco = $servers[0]["poco"];
                        $noscrape = $servers[0]["noscrape"];
@@ -822,7 +857,7 @@ class PortableContact
                        $info = $servers[0]["info"];
                        $register_policy = $servers[0]["register_policy"];
 
-                       if (!$force && !poco_do_update($servers[0]["created"], "", $last_failure, $last_contact)) {
+                       if (!$force && !self::updateNeeded($servers[0]["created"], "", $last_failure, $last_contact)) {
                                logger("Use cached data for server ".$server_url, LOGGER_DEBUG);
                                return ($last_contact >= $last_failure);
                        }
@@ -862,7 +897,7 @@ class PortableContact
                }
 
                // Maybe the page is unencrypted only?
-               $xmlobj = @simplexml_load_string($serverret["body"],'SimpleXMLElement',0, "http://docs.oasis-open.org/ns/xri/xrd-1.0");
+               $xmlobj = @simplexml_load_string($serverret["body"], 'SimpleXMLElement', 0, "http://docs.oasis-open.org/ns/xri/xrd-1.0");
                if (!$serverret["success"] || ($serverret["body"] == "") || (@sizeof($xmlobj) == 0) || !is_object($xmlobj)) {
                        $server_url = str_replace("https://", "http://", $server_url);
 
@@ -876,7 +911,7 @@ class PortableContact
                                return false;
                        }
 
-                       $xmlobj = @simplexml_load_string($serverret["body"],'SimpleXMLElement',0, "http://docs.oasis-open.org/ns/xri/xrd-1.0");
+                       $xmlobj = @simplexml_load_string($serverret["body"], 'SimpleXMLElement', 0, "http://docs.oasis-open.org/ns/xri/xrd-1.0");
                }
 
                if (!$serverret["success"] || ($serverret["body"] == "") || (sizeof($xmlobj) == 0) || !is_object($xmlobj)) {
@@ -903,7 +938,7 @@ class PortableContact
                                $data = json_decode($serverret["body"]);
                                if (isset($data->totalResults)) {
                                        $poco = $server_url."/poco";
-                                       $server = poco_detect_poco_data($data);
+                                       $server = self::detectPocoData($data);
                                        if ($server) {
                                                $platform = $server['platform'];
                                                $network = $server['network'];
@@ -921,7 +956,7 @@ class PortableContact
                        if (!$serverret["success"] || ($serverret["body"] == "")) {
                                $failure = true;
                        } else {
-                               $server = poco_detect_server_type($serverret["body"]);
+                               $server = self::detectServerType($serverret["body"]);
                                if ($server) {
                                        $platform = $server['platform'];
                                        $network = $server['network'];
@@ -929,11 +964,11 @@ class PortableContact
                                        $site_name = $server['site_name'];
                                }
 
-                               $lines = explode("\n",$serverret["header"]);
+                               $lines = explode("\n", $serverret["header"]);
                                if (count($lines)) {
-                                       foreach($lines as $line) {
+                                       foreach ($lines as $line) {
                                                $line = trim($line);
-                                               if (stristr($line,'X-Diaspora-Version:')) {
+                                               if (stristr($line, 'X-Diaspora-Version:')) {
                                                        $platform = "Diaspora";
                                                        $version = trim(str_replace("X-Diaspora-Version:", "", $line));
                                                        $version = trim(str_replace("x-diaspora-version:", "", $version));
@@ -942,7 +977,7 @@ class PortableContact
                                                        $version = $versionparts[0];
                                                }
 
-                                               if (stristr($line,'Server: Mastodon')) {
+                                               if (stristr($line, 'Server: Mastodon')) {
                                                        $platform = "Mastodon";
                                                        $network = NETWORK_OSTATUS;
                                                }
@@ -1059,9 +1094,9 @@ class PortableContact
 
                                                $site_name = $data->site->name;
 
-                                               $data->site->closed = poco_to_boolean($data->site->closed);
-                                               $data->site->private = poco_to_boolean($data->site->private);
-                                               $data->site->inviteonly = poco_to_boolean($data->site->inviteonly);
+                                               $data->site->closed = self::toBoolean($data->site->closed);
+                                               $data->site->private = self::toBoolean($data->site->private);
+                                               $data->site->inviteonly = self::toBoolean($data->site->inviteonly);
 
                                                if (!$data->site->closed && !$data->site->private and $data->site->inviteonly) {
                                                        $register_policy = REGISTER_APPROVE;
@@ -1109,7 +1144,7 @@ class PortableContact
 
                // Query nodeinfo. Working for (at least) Diaspora and Friendica.
                if (!$failure) {
-                       $server = poco_fetch_nodeinfo($server_url);
+                       $server = self::fetchNodeinfo($server_url);
                        if ($server) {
                                $register_policy = $server['register_policy'];
 
@@ -1195,7 +1230,8 @@ class PortableContact
                $platform = strip_tags($platform);
 
                if ($servers) {
-                       q("UPDATE `gserver` SET `url` = '%s', `version` = '%s', `site_name` = '%s', `info` = '%s', `register_policy` = %d, `poco` = '%s', `noscrape` = '%s',
+                       q(
+                               "UPDATE `gserver` SET `url` = '%s', `version` = '%s', `site_name` = '%s', `info` = '%s', `register_policy` = %d, `poco` = '%s', `noscrape` = '%s',
                                `network` = '%s', `platform` = '%s', `last_contact` = '%s', `last_failure` = '%s' WHERE `nurl` = '%s'",
                                dbesc($server_url),
                                dbesc($version),
@@ -1211,22 +1247,23 @@ class PortableContact
                                dbesc(normalise_link($server_url))
                        );
                } elseif (!$failure) {
-                       q("INSERT INTO `gserver` (`url`, `nurl`, `version`, `site_name`, `info`, `register_policy`, `poco`, `noscrape`, `network`, `platform`, `created`, `last_contact`, `last_failure`)
+                       q(
+                               "INSERT INTO `gserver` (`url`, `nurl`, `version`, `site_name`, `info`, `register_policy`, `poco`, `noscrape`, `network`, `platform`, `created`, `last_contact`, `last_failure`)
                                                VALUES ('%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
-                                       dbesc($server_url),
-                                       dbesc(normalise_link($server_url)),
-                                       dbesc($version),
-                                       dbesc($site_name),
-                                       dbesc($info),
-                                       intval($register_policy),
-                                       dbesc($poco),
-                                       dbesc($noscrape),
-                                       dbesc($network),
-                                       dbesc($platform),
-                                       dbesc(datetime_convert()),
-                                       dbesc($last_contact),
-                                       dbesc($last_failure),
-                                       dbesc(datetime_convert())
+                               dbesc($server_url),
+                               dbesc(normalise_link($server_url)),
+                               dbesc($version),
+                               dbesc($site_name),
+                               dbesc($info),
+                               intval($register_policy),
+                               dbesc($poco),
+                               dbesc($noscrape),
+                               dbesc($network),
+                               dbesc($platform),
+                               dbesc(datetime_convert()),
+                               dbesc($last_contact),
+                               dbesc($last_failure),
+                               dbesc(datetime_convert())
                        );
                }
                logger("End discovery for server " . $server_url, LOGGER_DEBUG);
@@ -1238,12 +1275,18 @@ class PortableContact
         * @brief Returns a list of all known servers
         * @return array List of server urls
         */
-       function poco_serverlist() {
-               $r = q("SELECT `url`, `site_name` AS `displayName`, `network`, `platform`, `version` FROM `gserver`
+       public static function serverlist()
+       {
+               $r = q(
+                       "SELECT `url`, `site_name` AS `displayName`, `network`, `platform`, `version` FROM `gserver`
                        WHERE `network` IN ('%s', '%s', '%s') AND `last_contact` > `last_failure`
                        ORDER BY `last_contact`
                        LIMIT 1000",
-                       dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
+                       dbesc(NETWORK_DFRN),
+                       dbesc(NETWORK_DIASPORA),
+                       dbesc(NETWORK_OSTATUS)
+               );
+
                if (!DBM::is_result($r)) {
                        return false;
                }
@@ -1256,7 +1299,8 @@ class PortableContact
         *
         * @param string $poco URL to the POCO endpoint
         */
-       function poco_fetch_serverlist($poco) {
+       public static function fetchServerlist($poco)
+       {
                $serverret = z_fetch_url($poco."/@server");
                if (!$serverret["success"]) {
                        return;
@@ -1278,8 +1322,9 @@ class PortableContact
                }
        }
 
-       function poco_discover_federation() {
-               $last = Config::get('poco','last_federation_discovery');
+       public static function discoverFederation()
+       {
+               $last = Config::get('poco', 'last_federation_discovery');
 
                if ($last) {
                        $next = $last + (24 * 60 * 60);
@@ -1300,7 +1345,7 @@ class PortableContact
                }
 
                // Disvover Mastodon servers
-               if (!Config::get('system','ostatus_disabled')) {
+               if (!Config::get('system', 'ostatus_disabled')) {
                        $serverdata = fetch_url("https://instances.mastodon.xyz/instances.json");
 
                        if ($serverdata) {
@@ -1324,14 +1369,15 @@ class PortableContact
                //              $servers = json_decode($result["body"]);
 
                //              foreach($servers->data as $server)
-               //                      poco_check_server($server->instance_address);
+               //                      self::checkServer($server->instance_address);
                //      }
                //}
 
-               Config::set('poco','last_federation_discovery', time());
+               Config::set('poco', 'last_federation_discovery', time());
        }
 
-       function poco_discover_single_server($id) {
+       public static function discoverSingleServer($id)
+       {
                $r = q("SELECT `poco`, `nurl`, `url`, `network` FROM `gserver` WHERE `id` = %d", intval($id));
                if (!DBM::is_result($r)) {
                        return false;
@@ -1340,7 +1386,7 @@ class PortableContact
                $server = $r[0];
 
                // Discover new servers out there (Works from Friendica version 3.5.2)
-               poco_fetch_serverlist($server["poco"]);
+               self::fetchServerlist($server["poco"]);
 
                // Fetch all users from the other server
                $url = $server["poco"]."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";
@@ -1351,11 +1397,10 @@ class PortableContact
                if ($retdata["success"]) {
                        $data = json_decode($retdata["body"]);
 
-                       poco_discover_server($data, 2);
+                       self::discoverServer($data, 2);
 
-                       if (Config::get('system','poco_discovery') > 1) {
-
-                               $timeframe = Config::get('system','poco_discovery_since');
+                       if (Config::get('system', 'poco_discovery') > 1) {
+                               $timeframe = Config::get('system', 'poco_discovery_since');
                                if ($timeframe == 0) {
                                        $timeframe = 30;
                                }
@@ -1370,12 +1415,12 @@ class PortableContact
                                $retdata = z_fetch_url($url);
                                if ($retdata["success"]) {
                                        logger("Fetch all global contacts from the server ".$server["nurl"], LOGGER_DEBUG);
-                                       $success = poco_discover_server(json_decode($retdata["body"]));
+                                       $success = self::discoverServer(json_decode($retdata["body"]));
                                }
 
-                               if (!$success && (Config::get('system','poco_discovery') > 2)) {
+                               if (!$success && (Config::get('system', 'poco_discovery') > 2)) {
                                        logger("Fetch contacts from users of the server ".$server["nurl"], LOGGER_DEBUG);
-                                       poco_discover_server_users($data, $server);
+                                       self::discoverServerUsers($data, $server);
                                }
                        }
 
@@ -1384,7 +1429,7 @@ class PortableContact
                        return true;
                } else {
                        // If the server hadn't replied correctly, then force a sanity check
-                       poco_check_server($server["url"], $server["network"], true);
+                       self::checkServer($server["url"], $server["network"], true);
 
                        // If we couldn't reach the server, we will try it some time later
                        q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
@@ -1393,10 +1438,10 @@ class PortableContact
                }
        }
 
-       function poco_discover($complete = false) {
-
+       public static function discover($complete = false)
+       {
                // Update the server list
-               poco_discover_federation();
+               self::discoverFederation();
 
                $no_of_queries = 5;
 
@@ -1410,8 +1455,7 @@ class PortableContact
                $r = q("SELECT `id`, `url`, `network` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `poco` != '' AND `last_poco_query` < '%s' ORDER BY RAND()", dbesc($last_update));
                if (DBM::is_result($r)) {
                        foreach ($r as $server) {
-
-                               if (!poco_check_server($server["url"], $server["network"])) {
+                               if (!self::checkServer($server["url"], $server["network"])) {
                                        // The server is not reachable? Okay, then we will try it later
                                        q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
                                        continue;
@@ -1427,8 +1471,8 @@ class PortableContact
                }
        }
 
-       function poco_discover_server_users($data, $server) {
-
+       public static function discoverServerUsers($data, $server)
+       {
                if (!isset($data->entry)) {
                        return;
                }
@@ -1452,14 +1496,14 @@ class PortableContact
 
                                $retdata = z_fetch_url($url);
                                if ($retdata["success"]) {
-                                       poco_discover_server(json_decode($retdata["body"]), 3);
+                                       self::discoverServer(json_decode($retdata["body"]), 3);
                                }
                        }
                }
        }
 
-       function poco_discover_server($data, $default_generation = 0) {
-
+       public static function discoverServer($data, $default_generation = 0)
+       {
                if (!isset($data->entry) || !count($data->entry)) {
                        return false;
                }
@@ -1524,11 +1568,11 @@ class PortableContact
                                $gender = $entry->gender;
                        }
 
-                       if(isset($entry->generation) && ($entry->generation > 0)) {
+                       if (isset($entry->generation) && ($entry->generation > 0)) {
                                $generation = ++$entry->generation;
                        }
 
-                       if(isset($entry->contactType) && ($entry->contactType >= 0)) {
+                       if (isset($entry->contactType) && ($entry->contactType >= 0)) {
                                $contact_type = $entry->contactType;
                        }
 
index e4d58f66aad37df7d64e7ea1254efb41ac3a44f4..11e7d30c3f9dbe608c377f1a688e308fe144ae95 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+/**
+ * @file src/Worker/OnePoll.php
+ */
 namespace Friendica\Worker;
 
 use Friendica\Core\Config;
@@ -81,8 +84,8 @@ Class OnePoll
                /// @TODO Check why we don't poll the Diaspora feed at the moment (some guid problem in the items?)
                /// @TODO Check whether this is possible with Redmatrix
                if ($contact["network"] == NETWORK_DIASPORA) {
-                       if (poco_do_update($contact["created"], $contact["last-item"], $contact["failure_update"], $contact["success_update"])) {
-                               $last_updated = poco_last_updated($contact["url"]);
+                       if (PortableContact::updateNeeded($contact["created"], $contact["last-item"], $contact["failure_update"], $contact["success_update"])) {
+                               $last_updated = PortableContact::lastUpdated($contact["url"]);
                                $updated = datetime_convert();
                                if ($last_updated) {
                                        $fields = array('last-item' => $last_updated, 'last-update' => $updated, 'success_update' => $updated);
@@ -117,7 +120,7 @@ Class OnePoll
 
                // Update the contact entry
                if (($contact['network'] === NETWORK_OSTATUS) || ($contact['network'] === NETWORK_DIASPORA) || ($contact['network'] === NETWORK_DFRN)) {
-                       if (!poco_reachable($contact['url'])) {
+                       if (!PortableContact::reachable($contact['url'])) {
                                logger("Skipping probably dead contact ".$contact['url']);
                                return;
                        }
index 525bbe9d9918a7027c91b94609c1b2e53ebb6597..40d4d9c734abba44579855313b027d428cc33b53 100644 (file)
@@ -17,7 +17,6 @@ use Friendica\Database\DBM;
 use Friendica\Model\GlobalContact;
 
 require_once "include/plugin.php";
-require_once "include/socgraph.php";
 require_once "mod/proxy.php";
 
 function vier_init(App $a) {