]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #6110 from annando/issue-6100
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 11 Nov 2018 01:57:07 +0000 (20:57 -0500)
committerGitHub <noreply@github.com>
Sun, 11 Nov 2018 01:57:07 +0000 (20:57 -0500)
Issue 6100: The AS object should be fetchable for every original post

14 files changed:
composer.json
composer.lock
doc/Addons.md
mod/follow.php
mod/removeme.php
phpunit.xml
src/App.php
src/Core/Hook.php
src/Core/Logger.php
src/Model/Contact.php
src/Network/Probe.php
src/Protocol/Feed.php
tests/src/Core/Cache/CacheTest.php
tests/src/Core/Lock/LockTest.php

index 5df9a5355b866d4fdc1a259024d9e9e09617b55a..339211f6f0e5718cd8496a06c0ba58716a915ac1 100644 (file)
@@ -76,7 +76,8 @@
                "phpdocumentor/reflection-docblock": "^3.0.2",
                "phpunit/php-token-stream": "^1.4.2",
                "mikey179/vfsStream": "^1.6",
-               "mockery/mockery": "^1.2"
+               "mockery/mockery": "^1.2",
+               "johnkary/phpunit-speedtrap": "1.1"
        },
        "scripts": {
                "test": "phpunit"
index 9230bb4db93c59e4efc260483ba603fa2cdd2ef3..16b9e50b5265fc1891c9fac777955c69a1a65e1d 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "9f0dbeccbae197460a0ce74a940177cd",
+    "content-hash": "ee7a6d8a1a9df21b46478dd91c1b73b7",
     "packages": [
         {
             "name": "asika/simple-console",
             ],
             "time": "2016-01-20T08:20:44+00:00"
         },
+        {
+            "name": "johnkary/phpunit-speedtrap",
+            "version": "v1.1.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/johnkary/phpunit-speedtrap.git",
+                "reference": "f7cfe17c5a7076ed0ccca5450fe3bb981ec56361"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/johnkary/phpunit-speedtrap/zipball/f7cfe17c5a7076ed0ccca5450fe3bb981ec56361",
+                "reference": "f7cfe17c5a7076ed0ccca5450fe3bb981ec56361",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.6",
+                "phpunit/phpunit": ">=4.7,<6.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.1-dev"
+                }
+            },
+            "autoload": {
+                "psr-0": {
+                    "JohnKary": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "John Kary",
+                    "email": "john@johnkary.net"
+                }
+            ],
+            "description": "Find slow tests in your PHPUnit test suite",
+            "homepage": "https://github.com/johnkary/phpunit-speedtrap",
+            "keywords": [
+                "phpunit",
+                "profile",
+                "slow"
+            ],
+            "time": "2017-03-25T17:14:26+00:00"
+        },
         {
             "name": "mikey179/vfsStream",
             "version": "v1.6.5",
index 50febf7214abde7abcd9dbc1550604a82004875b..bf139aea7f1e831084646558d3528332d81848a0 100644 (file)
@@ -693,6 +693,9 @@ Here is a complete list of all hook callbacks with file locations (as of 24-Sep-
 
     Addon::callHooks('logged_in', $a->user);
 
+### src/Core/Hook.php
+
+    self::callSingle(self::getApp(), 'hook_fork', $fork_hook, $hookdata);
 
 ### src/Core/Worker.php
 
index 08f664d39301e23e0ecf09218d837cb63296e47e..b92424c2083730c339c248dc93e1111190104b6c 100644 (file)
@@ -27,7 +27,7 @@ function follow_post(App $a)
 
        $uid = local_user();
        $url = Strings::escapeTags(trim($_REQUEST['url']));
-       $return_path = 'contacts';
+       $return_path = 'follow?url=' . urlencode($url);
 
        // Makes the connection request for friendica contacts easier
        // This is just a precaution if maybe this page is called somewhere directly via POST
index 44671ef073abae8abb27ddfae953c352b367c01b..49b8f6d5345d4478ecb83582c02f3b989ea9cec2 100644 (file)
@@ -10,6 +10,7 @@ use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\User;
+use Friendica\Util\Strings;
 
 require_once 'include/enotify.php';
 
index 9ed293b6314c4e2da2f1b30f0d3330477aca5a68..0209ce6aa2102adec5cbcce93cd5f7791947e321 100644 (file)
@@ -26,4 +26,7 @@
        <logging>
                <log type="coverage-clover" target="clover.xml" />
        </logging>
+       <listeners>
+               <listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
+       </listeners>
 </phpunit>
index 12f302f06ee0b68cae010fcfb2277f4aa1bf1c16..445101309384a2f651b46fd69f78b507835538a4 100644 (file)
@@ -787,9 +787,9 @@ class App
                 */
                if ($this->is_mobile || $this->is_tablet) {
                        if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
-                               $link = 'toggle_mobile?address=' . curPageURL();
+                               $link = 'toggle_mobile?address=' . urlencode(curPageURL());
                        } else {
-                               $link = 'toggle_mobile?off=1&address=' . curPageURL();
+                               $link = 'toggle_mobile?off=1&address=' . urlencode(curPageURL());
                        }
                        $this->page['footer'] .= Core\Renderer::replaceMacros(Core\Renderer::getMarkupTemplate("toggle_mobile_footer.tpl"), [
                                '$toggle_link' => $link,
index a0200a7db36934506b51fc59cf75d5e03f59cff3..2d6c945067965263e45f6a2b879602615e76facd 100644 (file)
@@ -136,6 +136,22 @@ class Hook extends BaseObject
        {
                if (array_key_exists($name, self::$hooks)) {
                        foreach (self::$hooks[$name] as $hook) {
+                               // Call a hook to check if this hook call needs to be forked
+                               if (array_key_exists('hook_fork', self::$hooks)) {
+                                       $hookdata = ['name' => $name, 'data' => $data, 'execute' => true];
+
+                                       foreach (self::$hooks['hook_fork'] as $fork_hook) {
+                                               if ($hook[0] != $fork_hook[0]) {
+                                                       continue;
+                                               }
+                                               self::callSingle(self::getApp(), 'hook_fork', $fork_hook, $hookdata);
+                                       }
+
+                                       if (!$hookdata['execute']) {
+                                               continue;
+                                       }
+                               }
+
                                Worker::add($priority, 'ForkHook', $name, $hook, $data);
                        }
                }
index c9253a83e913ea92f03e5e06c1b3f8dea6eddc04..f9cb8cde01f254d6e5ee0d540f7cb5ac0892cd9b 100644 (file)
@@ -115,6 +115,10 @@ class Logger extends BaseObject
             $processId = $a->process_id;
         }
 
+        if (!is_string($msg)) {
+               $msg = var_export($msg, true);
+        }
+
         $callers = debug_backtrace();
         $logline = sprintf("%s@\t%s:\t%s:\t%s\t%s\t%s\n",
                 DateTimeFormat::utcNow(),
index 8e150b50652b8cbca8c7765ac44836473c16939a..1c90d0c815e0eedbd7fd048ccd2ead5797630175 100644 (file)
@@ -8,13 +8,13 @@ use Friendica\BaseObject;
 use Friendica\Content\Pager;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
+use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
-use Friendica\Model\Profile;
 use Friendica\Network\Probe;
 use Friendica\Object\Image;
 use Friendica\Protocol\ActivityPub;
@@ -1606,7 +1606,7 @@ class Contact extends BaseObject
 
                $arr = ['url' => $url, 'contact' => []];
 
-               Addon::callHooks('follow', $arr);
+               Hook::callAll('follow', $arr);
 
                if (empty($arr)) {
                        $result['message'] = L10n::t('The contact could not be added. Please check the relevant network credentials in your Settings -> Social Networks page.');
index d870e06f9711f1e90a6bf01aa21bdfe418cfd2f7..9c57d624f89356d670c7e4f202d740282110ac95 100644 (file)
@@ -318,10 +318,10 @@ class Probe
         *
         * @return array uri data
         */
-       public static function uri($uri, $network = "", $uid = -1, $cache = true)
+       public static function uri($uri, $network = '', $uid = -1, $cache = true)
        {
                if ($cache) {
-                       $result = Cache::get("Probe::uri:".$network.":".$uri);
+                       $result = Cache::get('Probe::uri:' . $network . ':' . $uri);
                        if (!is_null($result)) {
                                return $result;
                        }
@@ -343,28 +343,28 @@ class Probe
                        $data = $ap_profile;
                }
 
-               if (!isset($data["url"])) {
-                       $data["url"] = $uri;
+               if (!isset($data['url'])) {
+                       $data['url'] = $uri;
                }
 
-               if (x($data, "photo")) {
-                       $data["baseurl"] = Network::getUrlMatch(Strings::normaliseLink(defaults($data, "baseurl", "")), Strings::normaliseLink($data["photo"]));
+               if (x($data, 'photo')) {
+                       $data['baseurl'] = Network::getUrlMatch(Strings::normaliseLink(defaults($data, 'baseurl', '')), Strings::normaliseLink($data['photo']));
                } else {
-                       $data["photo"] = System::baseUrl().'/images/person-300.jpg';
+                       $data['photo'] = System::baseUrl() . '/images/person-300.jpg';
                }
 
-               if (empty($data["name"])) {
-                       if (!empty($data["nick"])) {
-                               $data["name"] = $data["nick"];
+               if (empty($data['name'])) {
+                       if (!empty($data['nick'])) {
+                               $data['name'] = $data['nick'];
                        }
 
-                       if (!x($data, "name")) {
-                               $data["name"] = $data["url"];
+                       if (!x($data, 'name')) {
+                               $data['name'] = $data['url'];
                        }
                }
 
-               if (empty($data["nick"])) {
-                       $data["nick"] = strtolower($data["name"]);
+               if (empty($data['nick'])) {
+                       $data['nick'] = strtolower($data['name']);
 
                        if (strpos($data['nick'], ' ')) {
                                $data['nick'] = trim(substr($data['nick'], 0, strpos($data['nick'], ' ')));
@@ -372,42 +372,44 @@ class Probe
                }
 
                if (!empty(self::$baseurl)) {
-                       $data["baseurl"] = self::$baseurl;
+                       $data['baseurl'] = self::$baseurl;
                }
 
-               if (empty($data["network"])) {
-                       $data["network"] = Protocol::PHANTOM;
+               if (empty($data['network'])) {
+                       $data['network'] = Protocol::PHANTOM;
                }
 
                $data = self::rearrangeData($data);
 
                // Only store into the cache if the value seems to be valid
                if (!in_array($data['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
-                       Cache::set("Probe::uri:".$network.":".$uri, $data, Cache::DAY);
+                       Cache::set('Probe::uri:' . $network . ':' . $uri, $data, Cache::DAY);
 
                        /// @todo temporary fix - we need a real contact update function that updates only changing fields
                        /// The biggest problem is the avatar picture that could have a reduced image size.
                        /// It should only be updated if the existing picture isn't existing anymore.
                        /// We only update the contact when it is no probing for a specific network.
                        if (($data['network'] != Protocol::FEED)
-                               && ($network == "")
-                               && $data["name"]
-                               && $data["nick"]
-                               && $data["url"]
-                               && $data["addr"]
-                               && $data["poll"]
+                               && ($network == '')
+                               && $data['name']
+                               && $data['nick']
+                               && $data['url']
+                               && $data['addr']
+                               && $data['poll']
                        ) {
-                               $fields = ['name' => $data['name'],
-                                               'nick' => $data['nick'],
-                                               'url' => $data['url'],
-                                               'addr' => $data['addr'],
-                                               'photo' => $data['photo'],
-                                               'keywords' => $data['keywords'],
-                                               'location' => $data['location'],
-                                               'about' => $data['about'],
-                                               'notify' => $data['notify'],
-                                               'network' => $data['network'],
-                                               'server_url' => $data['baseurl']];
+                               $fields = [
+                                       'name' => $data['name'],
+                                       'nick' => $data['nick'],
+                                       'url' => $data['url'],
+                                       'addr' => $data['addr'],
+                                       'photo' => $data['photo'],
+                                       'keywords' => $data['keywords'],
+                                       'location' => $data['location'],
+                                       'about' => $data['about'],
+                                       'notify' => $data['notify'],
+                                       'network' => $data['network'],
+                                       'server_url' => $data['baseurl']
+                               ];
 
                                // This doesn't cover the case when a community isn't a community anymore
                                if (!empty($data['community']) && $data['community']) {
@@ -427,7 +429,7 @@ class Probe
 
                                $fields['updated'] = DateTimeFormat::utcNow();
 
-                               $condition = ['nurl' => Strings::normaliseLink($data["url"])];
+                               $condition = ['nurl' => Strings::normaliseLink($data['url'])];
 
                                $old_fields = DBA::selectFirst('gcontact', $fieldnames, $condition);
 
@@ -444,25 +446,27 @@ class Probe
 
                                DBA::update('gcontact', $fields, $condition, $old_fields);
 
-                               $fields = ['name' => $data['name'],
-                                               'nick' => $data['nick'],
-                                               'url' => $data['url'],
-                                               'addr' => $data['addr'],
-                                               'alias' => $data['alias'],
-                                               'keywords' => $data['keywords'],
-                                               'location' => $data['location'],
-                                               'about' => $data['about'],
-                                               'batch' => $data['batch'],
-                                               'notify' => $data['notify'],
-                                               'poll' => $data['poll'],
-                                               'request' => $data['request'],
-                                               'confirm' => $data['confirm'],
-                                               'poco' => $data['poco'],
-                                               'network' => $data['network'],
-                                               'pubkey' => $data['pubkey'],
-                                               'priority' => $data['priority'],
-                                               'writable' => true,
-                                               'rel' => Contact::SHARING];
+                               $fields = [
+                                       'name' => $data['name'],
+                                       'nick' => $data['nick'],
+                                       'url' => $data['url'],
+                                       'addr' => $data['addr'],
+                                       'alias' => $data['alias'],
+                                       'keywords' => $data['keywords'],
+                                       'location' => $data['location'],
+                                       'about' => $data['about'],
+                                       'batch' => $data['batch'],
+                                       'notify' => $data['notify'],
+                                       'poll' => $data['poll'],
+                                       'request' => $data['request'],
+                                       'confirm' => $data['confirm'],
+                                       'poco' => $data['poco'],
+                                       'network' => $data['network'],
+                                       'pubkey' => $data['pubkey'],
+                                       'priority' => $data['priority'],
+                                       'writable' => true,
+                                       'rel' => Contact::SHARING
+                               ];
 
                                $fieldnames = [];
 
@@ -474,7 +478,7 @@ class Probe
                                        }
                                }
 
-                               $condition = ['nurl' => Strings::normaliseLink($data["url"]), 'self' => false, 'uid' => 0];
+                               $condition = ['nurl' => Strings::normaliseLink($data['url']), 'self' => false, 'uid' => 0];
 
                                // "$old_fields" will return a "false" when the contact doesn't exist.
                                // This won't trigger an insert. This is intended, since we only need
@@ -575,7 +579,7 @@ class Probe
        {
                $parts = parse_url($uri);
 
-               if (!empty($parts["scheme"]) && !empty($parts["host"]) && !empty($parts["path"])) {
+               if (!empty($parts["scheme"]) && !empty($parts["host"])) {
                        $host = $parts["host"];
                        if (!empty($parts["port"])) {
                                $host .= ':'.$parts["port"];
@@ -590,7 +594,7 @@ class Probe
                                return [];
                        }
 
-                       $path_parts = explode("/", trim($parts["path"], "/"));
+                       $path_parts = explode("/", trim(defaults($parts, 'path', ''), "/"));
 
                        while (!$lrdd && (sizeof($path_parts) > 1)) {
                                $host .= "/".array_shift($path_parts);
@@ -979,7 +983,9 @@ class Probe
        {
                $hcard_url = "";
                $data = [];
-               foreach ($webfinger["links"] as $link) {
+               // The array is reversed to take into account the order of preference for same-rel links
+               // See: https://tools.ietf.org/html/rfc7033#section-4.4.4
+               foreach (array_reverse($webfinger["links"]) as $link) {
                        if (($link["rel"] == NAMESPACE_DFRN) && !empty($link["href"])) {
                                $data["network"] = Protocol::DFRN;
                        } elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
@@ -1182,7 +1188,9 @@ class Probe
        {
                $hcard_url = "";
                $data = [];
-               foreach ($webfinger["links"] as $link) {
+               // The array is reversed to take into account the order of preference for same-rel links
+               // See: https://tools.ietf.org/html/rfc7033#section-4.4.4
+               foreach (array_reverse($webfinger["links"]) as $link) {
                        if (($link["rel"] == "http://microformats.org/profile/hcard") && !empty($link["href"])) {
                                $hcard_url = $link["href"];
                        } elseif (($link["rel"] == "http://joindiaspora.com/seed_location") && !empty($link["href"])) {
@@ -1283,7 +1291,9 @@ class Probe
 
                $pubkey = "";
                if (is_array($webfinger["links"])) {
-                       foreach ($webfinger["links"] as $link) {
+                       // The array is reversed to take into account the order of preference for same-rel links
+                       // See: https://tools.ietf.org/html/rfc7033#section-4.4.4
+                       foreach (array_reverse($webfinger["links"]) as $link) {
                                if (($link["rel"] == "http://webfinger.net/rel/profile-page")
                                        && (defaults($link, "type", "") == "text/html")
                                        && ($link["href"] != "")
@@ -1447,7 +1457,9 @@ class Probe
        private static function pumpio($webfinger, $addr)
        {
                $data = [];
-               foreach ($webfinger["links"] as $link) {
+               // The array is reversed to take into account the order of preference for same-rel links
+               // See: https://tools.ietf.org/html/rfc7033#section-4.4.4
+               foreach (array_reverse($webfinger["links"]) as $link) {
                        if (($link["rel"] == "http://webfinger.net/rel/profile-page")
                                && (defaults($link, "type", "") == "text/html")
                                && ($link["href"] != "")
index 71ebe5506b9dadd78587e6123646af464d9c2d5f..d63b57b8c9522bd6a21d9387b1c7e0c93a217e50 100644 (file)
@@ -123,7 +123,13 @@ class Feed {
                                $author["author-name"] = $value;
                        }
                        if ($simulate) {
-                               $author["author-id"] = XML::getFirstNodeValue($xpath, '/atom:feed/atom:author/atom:uri/text()');
+                               $author["author-id"] = XML::getFirstNodeValue($xpath, '/atom:feed/atom:author/atom:id/text()');
+
+                               // See https://tools.ietf.org/html/rfc4287#section-3.2.2
+                               $value = XML::getFirstNodeValue($xpath, 'atom:author/atom:uri/text()');
+                               if ($value != "") {
+                                       $author["author-link"] = $value;
+                               }
 
                                $value = XML::getFirstNodeValue($xpath, 'atom:author/poco:preferredUsername/text()');
                                if ($value != "") {
index 86bf5e7f01fa2a1e115db8aaee1aa9a15dba6dc4..e51ce745f0c72638c41ab960b30673c34ec40c61 100644 (file)
@@ -123,6 +123,8 @@ abstract class CacheTest extends DatabaseTest
         * @medium
         */
        function testTTL() {
+               $this->markTestSkipped('taking too much time without mocking');
+
                $this->assertNull($this->instance->get('value1'));
 
                $value = 'foobar';
index a7bbea265f1a9fb9caf8e80ab3cc01b215864cb5..78f2271e54016bd581b74c542794d7c3b5b03a39 100644 (file)
@@ -116,6 +116,8 @@ abstract class LockTest extends DatabaseTest
         * @medium
         */
        function testLockTTL() {
+               $this->markTestSkipped('taking too much time without mocking');
+
                $this->assertFalse($this->instance->isLocked('foo'));
                $this->assertFalse($this->instance->isLocked('bar'));