]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #7256 from MrPetovan/bug/7249-remote-logout
authorPhilipp <admin+Github@philipp.info>
Wed, 12 Jun 2019 05:37:42 +0000 (07:37 +0200)
committerGitHub <noreply@github.com>
Wed, 12 Jun 2019 05:37:42 +0000 (07:37 +0200)
Fix remote logout

42 files changed:
composer.json
composer.lock
mod/dfrn_confirm.php
mod/events.php
mod/fsuggest.php
mod/item.php
mod/parse_url.php
mod/settings.php
mod/tagger.php
src/Content/OEmbed.php
src/Content/Text/BBCode.php
src/Core/Config/Cache/ConfigCache.php
src/Core/Config/Configuration.php
src/Core/Search.php
src/Core/UserImport.php
src/Core/Worker.php
src/Factory/DBFactory.php
src/Model/APContact.php
src/Model/Contact.php
src/Model/Item.php
src/Model/Mail.php
src/Model/Photo.php
src/Model/User.php
src/Module/Admin/Site.php
src/Module/Magic.php
src/Network/Probe.php
src/Object/Image.php
src/Protocol/ActivityPub.php
src/Protocol/ActivityPub/Transmitter.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Protocol/OStatus.php
src/Protocol/PortableContact.php
src/Util/HTTPSignature.php
src/Util/Network.php
src/Util/Security.php
src/Worker/APDelivery.php
src/Worker/Delivery.php
src/Worker/Notifier.php
src/Worker/OnePoll.php
tests/src/Core/Config/Cache/ConfigCacheTest.php
update.php

index a8b4a20d28fc4463c1c677cef0bae3a60cfe463f..aac5c10bc6e3fa88582ab7563b8661f62cefac33 100644 (file)
@@ -37,6 +37,7 @@
                "mobiledetect/mobiledetectlib": "2.8.*",
                "monolog/monolog": "^1.24",
                "nikic/fast-route": "^1.3",
+               "paragonie/hidden-string": "^1.0",
                "pear/text_languagedetect": "1.*",
                "pragmarx/google2fa": "^5.0",
                "pragmarx/recovery": "^0.1.0",
index 75c10b78f026eaea9b8c83d3a73c828ff90932e7..af51b6dfe7ef7c9ca4ba2de0e4cad4ea3501ae96 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": "67821d2270bdf8cdd24e7a047b9544e7",
+    "content-hash": "eb985236d64ed0b0fe1fc2e4ac6616e2",
     "packages": [
         {
             "name": "asika/simple-console",
         },
         {
             "name": "paragonie/constant_time_encoding",
-            "version": "v1.0.4",
+            "version": "v2.2.3",
             "source": {
                 "type": "git",
                 "url": "https://github.com/paragonie/constant_time_encoding.git",
-                "reference": "2132f0f293d856026d7d11bd81b9f4a23a1dc1f6"
+                "reference": "55af0dc01992b4d0da7f6372e2eac097bbbaffdb"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/2132f0f293d856026d7d11bd81b9f4a23a1dc1f6",
-                "reference": "2132f0f293d856026d7d11bd81b9f4a23a1dc1f6",
+                "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/55af0dc01992b4d0da7f6372e2eac097bbbaffdb",
+                "reference": "55af0dc01992b4d0da7f6372e2eac097bbbaffdb",
                 "shasum": ""
             },
             "require": {
-                "php": "^5.3|^7"
+                "php": "^7"
             },
             "require-dev": {
-                "paragonie/random_compat": "^1.4|^2",
-                "phpunit/phpunit": "4.*|5.*",
-                "vimeo/psalm": "^0.3|^1"
+                "phpunit/phpunit": "^6|^7",
+                "vimeo/psalm": "^1|^2"
             },
             "type": "library",
             "autoload": {
                 "hex2bin",
                 "rfc4648"
             ],
-            "time": "2018-04-30T17:57:16+00:00"
+            "time": "2019-01-03T20:26:31+00:00"
+        },
+        {
+            "name": "paragonie/hidden-string",
+            "version": "v1.0.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/paragonie/hidden-string.git",
+                "reference": "0bbb00be0e33b8e1d48fa79ea35cd42d3091a936"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/paragonie/hidden-string/zipball/0bbb00be0e33b8e1d48fa79ea35cd42d3091a936",
+                "reference": "0bbb00be0e33b8e1d48fa79ea35cd42d3091a936",
+                "shasum": ""
+            },
+            "require": {
+                "paragonie/constant_time_encoding": "^2",
+                "paragonie/sodium_compat": "^1.6",
+                "php": "^7"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^6|^7",
+                "vimeo/psalm": "^1"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "ParagonIE\\HiddenString\\": "./src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MPL-2.0"
+            ],
+            "authors": [
+                {
+                    "name": "Paragon Initiative Enterprises",
+                    "email": "info@paragonie.com",
+                    "homepage": "https://paragonie.com"
+                }
+            ],
+            "description": "Encapsulate strings in an object to hide them from stack traces",
+            "homepage": "https://github.com/paragonie/hidden-string",
+            "keywords": [
+                "hidden",
+                "stack trace",
+                "string"
+            ],
+            "time": "2018-05-07T20:28:06+00:00"
         },
         {
             "name": "paragonie/random_compat",
             "version": "v1.6.5",
             "source": {
                 "type": "git",
-                "url": "https://github.com/mikey179/vfsStream.git",
+                "url": "https://github.com/bovigo/vfsStream.git",
                 "reference": "d5fec95f541d4d71c4823bb5e30cf9b9e5b96145"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/mikey179/vfsStream/zipball/d5fec95f541d4d71c4823bb5e30cf9b9e5b96145",
+                "url": "https://api.github.com/repos/bovigo/vfsStream/zipball/d5fec95f541d4d71c4823bb5e30cf9b9e5b96145",
                 "reference": "d5fec95f541d4d71c4823bb5e30cf9b9e5b96145",
                 "shasum": ""
             },
                 }
             ],
             "description": "Provides the functionality to compare PHP values for equality",
-            "homepage": "http://www.github.com/sebastianbergmann/comparator",
+            "homepage": "https://github.com/sebastianbergmann/comparator",
             "keywords": [
                 "comparator",
                 "compare",
                 }
             ],
             "description": "Provides functionality to handle HHVM/PHP environments",
-            "homepage": "http://www.github.com/sebastianbergmann/environment",
+            "homepage": "https://github.com/sebastianbergmann/environment",
             "keywords": [
                 "Xdebug",
                 "environment",
                 }
             ],
             "description": "Provides the functionality to export PHP variables for visualization",
-            "homepage": "http://www.github.com/sebastianbergmann/exporter",
+            "homepage": "https://github.com/sebastianbergmann/exporter",
             "keywords": [
                 "export",
                 "exporter"
                 }
             ],
             "description": "Snapshotting of global state",
-            "homepage": "http://www.github.com/sebastianbergmann/global-state",
+            "homepage": "https://github.com/sebastianbergmann/global-state",
             "keywords": [
                 "global state"
             ],
                 }
             ],
             "description": "Provides functionality to recursively process PHP variables",
-            "homepage": "http://www.github.com/sebastianbergmann/recursion-context",
+            "homepage": "https://github.com/sebastianbergmann/recursion-context",
             "time": "2016-11-19T07:33:16+00:00"
         },
         {
                 },
                 {
                     "name": "Gert de Pagter",
-                    "email": "backendtea@gmail.com"
+                    "email": "BackEndTea@gmail.com"
                 }
             ],
             "description": "Symfony polyfill for ctype functions",
index 7b1171ba41b9a5571ae6f7ddc4e94271fcf05efc..9f9684e0936e9b40ede108ac7a00b7903d4d78c6 100644 (file)
@@ -209,7 +209,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
                 *
                 */
 
-               $res = Network::post($dfrn_confirm, $params, null, $redirects, 120)->getBody();
+               $res = Network::post($dfrn_confirm, $params, [], 120)->getBody();
 
                Logger::log(' Confirm: received data: ' . $res, Logger::DATA);
 
index 8e9606b203cb8e15b236a6c45f28e494ab409635..86cec9a7d4130edfdafb31a6bd66f10e594bf6b0 100644 (file)
@@ -21,6 +21,7 @@ use Friendica\Module\Login;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
+use Friendica\Worker\Delivery;
 
 function events_init(App $a)
 {
@@ -195,7 +196,7 @@ function events_post(App $a)
        $item_id = Event::store($datarray);
 
        if (!$cid) {
-               Worker::add(PRIORITY_HIGH, "Notifier", "event", $item_id);
+               Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $item_id);
        }
 
        $a->internalRedirect('events');
index 2cede5685215abe6ad0bbf8bbddaa90b42efd86e..2bddf48133103510becfb1c90290c86a2c820059 100644 (file)
@@ -10,6 +10,7 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
+use Friendica\Worker\Delivery;
 
 function fsuggest_post(App $a)
 {
@@ -51,7 +52,7 @@ function fsuggest_post(App $a)
                'photo' => $contact['avatar'], 'note' => $note, 'created' => DateTimeFormat::utcNow()];
        DBA::insert('fsuggest', $fields);
 
-       Worker::add(PRIORITY_HIGH, 'Notifier', 'suggest', DBA::lastInsertId());
+       Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::SUGGESTION, DBA::lastInsertId());
 
        info(L10n::t('Friend suggestion sent.') . EOL);
 }
index 1fccbca4d6b85fa072729b6bad8005027998c26d..20dc9dfdae892a94a22da257dff8f9b235d28f60 100644 (file)
@@ -604,8 +604,6 @@ function item_post(App $a) {
                $origin = $_REQUEST['origin'];
        }
 
-       $notify_type = ($toplevel_item_id ? Delivery::COMMENT : Delivery::POST);
-
        $uri = ($message_id ? $message_id : Item::newURI($api_source ? $profile_uid : $uid, $guid));
 
        // Fallback so that we alway have a parent uri
@@ -870,7 +868,7 @@ function item_post(App $a) {
        // When we are doing some forum posting via ! we have to start the notifier manually.
        // These kind of posts don't initiate the notifier call in the item class.
        if ($only_to_forum) {
-               Worker::add(PRIORITY_HIGH, "Notifier", $notify_type, $post_id);
+               Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post_id);
        }
 
        Logger::log('post_complete');
index 7631a5a710b62d07d0f349b2b3b17914debb81a6..6b393932ebc8aa73e176670d6889329a70320fb7 100644 (file)
@@ -70,9 +70,8 @@ function parse_url_content(App $a)
 
        // Check if the URL is an image, video or audio file. If so format
        // the URL with the corresponding BBCode media tag
-       $redirects = 0;
        // Fetch the header of the URL
-       $curlResponse = Network::curl($url, false, $redirects, ['novalidate' => true, 'nobody' => true]);
+       $curlResponse = Network::curl($url, false, ['novalidate' => true, 'nobody' => true]);
 
        if ($curlResponse->isSuccess()) {
                // Convert the header fields into an array
index 45f11cdb6c3f3ff89e69ad9899b986ca1e74bcb5..ab7586733adfe3bd014157181a226388f28950e8 100644 (file)
@@ -27,6 +27,7 @@ use Friendica\Protocol\Email;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
+use Friendica\Worker\Delivery;
 
 function get_theme_config_file($theme)
 {
@@ -389,7 +390,7 @@ function settings_post(App $a)
        BaseModule::checkFormSecurityTokenRedirectOnError('/settings', 'settings');
 
        if (!empty($_POST['resend_relocate'])) {
-               Worker::add(PRIORITY_HIGH, 'Notifier', 'relocate', local_user());
+               Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, local_user());
                info(L10n::t("Relocate message has been send to your contacts"));
                $a->internalRedirect('settings');
        }
index 5d3d1923e4425958b4d53a00e3ea436cd8553c76..2c15cdd28c68d62f4d836b905713d1c30b435fa7 100644 (file)
@@ -12,6 +12,7 @@ use Friendica\Database\DBA;
 use Friendica\Model\Item;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
+use Friendica\Worker\Delivery;
 
 function tagger_content(App $a) {
 
@@ -194,7 +195,7 @@ EOT;
 
        Hook::callAll('post_local_end', $arr);
 
-       Worker::add(PRIORITY_HIGH, "Notifier", "tag", $post_id);
+       Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post_id);
 
        exit();
 }
index 7190f1ce0ed39cc8b8433b1497947074e566cd6e..94e95e5f51d234e04b3be242159c4b68cc894158 100644 (file)
@@ -83,8 +83,7 @@ class OEmbed
 
                        if (!in_array($ext, $noexts)) {
                                // try oembed autodiscovery
-                               $redirects = 0;
-                               $html_text = Network::fetchUrl($embedurl, false, $redirects, 15, 'text/*');
+                               $html_text = Network::fetchUrl($embedurl, false, 15, 'text/*');
                                if ($html_text) {
                                        $dom = @DOMDocument::loadHTML($html_text);
                                        if ($dom) {
index 6805369d083d4bc7a8c6d53e4288228ce98a1280..146dedf470144de402be3bd64b1f7ac2fc4f7df1 100644 (file)
@@ -251,8 +251,14 @@ class BBCode extends BaseObject
 
                        if (preg_match_all("(\[url=([$URLSearchString]*)\]\s*\[img\]([$URLSearchString]*)\[\/img\]\s*\[\/url\])ism", $body, $pictures, PREG_SET_ORDER)) {
                                if ((count($pictures) == 1) && !$has_title) {
-                                       // Checking, if the link goes to a picture
-                                       $data = ParseUrl::getSiteinfoCached($pictures[0][1], true);
+                                       if (!empty($item['object-type']) && ($item['object-type'] == ACTIVITY_OBJ_IMAGE)) {
+                                               // Replace the preview picture with the real picture
+                                               $url = str_replace('-1.', '-0.', $pictures[0][2]);
+                                               $data = ['url' => $url, 'type' => 'photo'];
+                                       } else {
+                                               // Checking, if the link goes to a picture
+                                               $data = ParseUrl::getSiteinfoCached($pictures[0][1], true);
+                                       }
 
                                        // Workaround:
                                        // Sometimes photo posts to the own album are not detected at the start.
@@ -271,14 +277,14 @@ class BBCode extends BaseObject
                                                }
 
                                                $post["preview"] = $pictures[0][2];
-                                               $post["text"] = str_replace($pictures[0][0], "", $body);
+                                               $post["text"] = trim(str_replace($pictures[0][0], "", $body));
                                        } else {
                                                $imgdata = Image::getInfoFromURL($pictures[0][1]);
                                                if ($imgdata && substr($imgdata["mime"], 0, 6) == "image/") {
                                                        $post["type"] = "photo";
                                                        $post["image"] = $pictures[0][1];
                                                        $post["preview"] = $pictures[0][2];
-                                                       $post["text"] = str_replace($pictures[0][0], "", $body);
+                                                       $post["text"] = trim(str_replace($pictures[0][0], "", $body));
                                                }
                                        }
                                } elseif (count($pictures) > 0) {
@@ -563,7 +569,7 @@ class BBCode extends BaseObject
                }
 
                $return = '';
-               if ($simplehtml == 7) {
+               if (in_array($simplehtml, [7, 9])) {
                        $return = self::convertUrlForOStatus($data["url"]);
                } elseif (($simplehtml != 4) && ($simplehtml != 0)) {
                        $return = sprintf('<a href="%s" target="_blank">%s</a><br>', $data["url"], $data["title"]);
@@ -979,16 +985,9 @@ class BBCode extends BaseObject
                                $text = ($is_quote_share? '<br />' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ': </p>' . "\n" . $content;
                                break;
                        case 7: // statusnet/GNU Social
+                       case 9: // ActivityPub
                                $text = ($is_quote_share? '<br />' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' @' . $author_contact['addr'] . ': ' . $content . '</p>' . "\n";
                                break;
-                       case 9: // Google+
-                               $text = ($is_quote_share? '<br />' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ': </p>' . "\n";
-                               $text .= '<p>' . $content . '</p>' . "\n";
-
-                               if ($attributes['link'] != '') {
-                                       $text .= '<p>' . $attributes['link'] . '</p>';
-                               }
-                               break;
                        default:
                                // Transforms quoted tweets in rich attachments to avoid nested tweets
                                if (stripos(Strings::normaliseLink($attributes['link']), 'http://twitter.com/') === 0 && OEmbed::isAllowedURL($attributes['link'])) {
@@ -1140,13 +1139,14 @@ class BBCode extends BaseObject
         * Simple HTML values meaning:
         * - 0: Friendica display
         * - 1: Unused
-        * - 2: Used for Google+, Windows Phone push, Friendica API
+        * - 2: Used for Windows Phone push, Friendica API
         * - 3: Used before converting to Markdown in bb2diaspora.php
         * - 4: Used for WordPress, Libertree (before Markdown), pump.io and tumblr
         * - 5: Unused
         * - 6: Unused
         * - 7: Used for dfrn, OStatus
         * - 8: Used for WP backlink text setting
+        * - 9: ActivityPub
         *
         * @param string $text
         * @param bool   $try_oembed
@@ -1292,7 +1292,7 @@ class BBCode extends BaseObject
                // if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text
                if (!$for_plaintext) {
                        $text = preg_replace(Strings::autoLinkRegEx(), '[url]$1[/url]', $text);
-                       if ($simple_html == 7) {
+                       if (in_array($simple_html, [7, 9])) {
                                $text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text);
                                $text = preg_replace_callback("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text);
                        }
@@ -1304,14 +1304,14 @@ class BBCode extends BaseObject
                $text = str_replace(["\r","\n"], ['<br />', '<br />'], $text);
 
                // Remove all hashtag addresses
-               if ((!$try_oembed || $simple_html) && !in_array($simple_html, [3, 7])) {
+               if ((!$try_oembed || $simple_html) && !in_array($simple_html, [3, 7, 9])) {
                        $text = preg_replace("/([#@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $text);
                } elseif ($simple_html == 3) {
                        // The ! is converted to @ since Diaspora only understands the @
                        $text = preg_replace("/([@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
                                '@<a href="$2">$3</a>',
                                $text);
-               } elseif ($simple_html == 7) {
+               } elseif (in_array($simple_html, [7, 9])) {
                        $text = preg_replace("/([@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
                                '$1<span class="vcard"><a href="$2" class="url u-url mention" title="$3"><span class="fn nickname mention">$3</span></a></span>',
                                $text);
@@ -1327,7 +1327,7 @@ class BBCode extends BaseObject
                $text = preg_replace("/#\[url\=[$URLSearchString]*\]\^\[\/url\]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/i",
                                        "[bookmark=$1]$2[/bookmark]", $text);
 
-               if (in_array($simple_html, [2, 6, 7, 8, 9])) {
+               if (in_array($simple_html, [2, 6, 7, 8])) {
                        $text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", "self::expandLinksCallback", $text);
                        //$Text = preg_replace("/[^#@!]\[url\=([^\]]*)\](.*?)\[\/url\]/ism", ' $2 [url]$1[/url]', $Text);
                        $text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", ' $2 [url]$1[/url]',$text);
index 3314e184f3519cf5f4a7ee388e37da8ce949fc41..441cdee811cc550c3e0bb748c8fdb26887b0dc59 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace Friendica\Core\Config\Cache;
 
+use ParagonIE\HiddenString\HiddenString;
+
 /**
  * The Friendica config cache for the application
  * Initial, all *.config.php files are loaded into this cache with the
@@ -14,11 +16,18 @@ class ConfigCache implements IConfigCache, IPConfigCache
         */
        private $config;
 
+       /**
+        * @var bool
+        */
+       private $hidePasswordOutput;
+
        /**
         * @param array $config    A initial config array
+        * @param bool  $hidePasswordOutput True, if cache variables should take extra care of password values
         */
-       public function __construct(array $config = [])
+       public function __construct(array $config = [], $hidePasswordOutput = true)
        {
+               $this->hidePasswordOutput = $hidePasswordOutput;
                $this->load($config);
        }
 
@@ -84,8 +93,13 @@ class ConfigCache implements IConfigCache, IPConfigCache
                        $this->config[$cat] = [];
                }
 
-               $this->config[$cat][$key] = $value;
-
+               if ($this->hidePasswordOutput &&
+                   $key == 'password' &&
+                   !empty($value) && is_string($value)) {
+                       $this->config[$cat][$key] = new HiddenString((string) $value);
+               } else {
+                       $this->config[$cat][$key] = $value;
+               }
                return true;
        }
 
index 532ed982a9d46498d3de738e741f58db33b26cbc..18191d0429c45bfd2fb5fc9f860fb71eaca2b008 100644 (file)
@@ -88,7 +88,7 @@ class Configuration
 
                        if (isset($dbvalue)) {
                                $this->configCache->set($cat, $key, $dbvalue);
-                               return $dbvalue;
+                               unset($dbvalue);
                        }
                }
 
index 48231f08247a94c1206e8c8f62a774dbc8253f53..e26cc0edc3a55792b682ad397cac11e4d87fafb7 100644 (file)
@@ -107,8 +107,7 @@ class Search extends BaseObject
                        $searchUrl .= '&page=' . $page;
                }
 
-               $red        = 0;
-               $resultJson = Network::fetchUrl($searchUrl, false, $red, 0, 'application/json');
+               $resultJson = Network::fetchUrl($searchUrl, false, 0, 'application/json');
 
                $results = json_decode($resultJson, true);
 
index 97a6e6028e3b4905e341506a5f4d540ccbbd219d..71767e8cef788be4cfa1f90b7c189d7dac63ad13 100644 (file)
@@ -10,6 +10,7 @@ use Friendica\Database\DBStructure;
 use Friendica\Model\Photo;
 use Friendica\Object\Image;
 use Friendica\Util\Strings;
+use Friendica\Worker\Delivery;
 
 /**
  * @brief UserImport class
@@ -278,7 +279,7 @@ class UserImport
                }
 
                // send relocate messages
-               Worker::add(PRIORITY_HIGH, 'Notifier', 'relocate', $newuid);
+               Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, $newuid);
 
                info(L10n::t("Done. You can now login with your username and password"));
                $a->internalRedirect('login');
index 0f4a527f6bd21aa95cb9f387ba1f29e5264aab73..8fdd60c2a74db95549ec4d3766b631b3f1020358 100644 (file)
@@ -983,7 +983,7 @@ class Worker
                }
 
                $url = System::baseUrl()."/worker";
-               Network::fetchUrl($url, false, $redirects, 1);
+               Network::fetchUrl($url, false, 1);
        }
 
        /**
@@ -1100,7 +1100,7 @@ class Worker
         * @param (integer|array) priority or parameter array, strings are deprecated and are ignored
         *
         * next args are passed as $cmd command line
-        * or: Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
+        * or: Worker::add(PRIORITY_HIGH, "Notifier", Delivery::DELETION, $drop_id);
         * or: Worker::add(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "CreateShadowEntry", $post_id);
         *
         * @return boolean "false" if proc_run couldn't be executed
index 1c01f733192d6604940415c77b7ddf394d358e22..7caa63ec46755d8e74abdb11736fc9d784be9171 100644 (file)
@@ -6,6 +6,7 @@ use Friendica\Core\Config\Cache;
 use Friendica\Database;
 use Friendica\Util\Logger\VoidLogger;
 use Friendica\Util\Profiler;
+use ParagonIE\HiddenString\HiddenString;
 
 class DBFactory
 {
@@ -45,7 +46,7 @@ class DBFactory
                        } else {
                                $db_user = $server['MYSQL_USER'];
                        }
-                       $db_pass = (string) $server['MYSQL_PASSWORD'];
+                       $db_pass = new HiddenString((string) $server['MYSQL_PASSWORD']);
                        $db_data = $server['MYSQL_DATABASE'];
                }
 
index cf1f9b72313c44baee97083b4b91a3b76255017e..c308da3889cec771e62cb66516a45d3c3fafc350 100644 (file)
@@ -34,7 +34,7 @@ class APContact extends BaseObject
 
                $webfinger = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr);
 
-               $curlResult = Network::curl($webfinger, false, $redirects, ['accept_content' => 'application/jrd+json,application/json']);
+               $curlResult = Network::curl($webfinger, false, ['accept_content' => 'application/jrd+json,application/json']);
                if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
                        return false;
                }
@@ -152,7 +152,13 @@ class APContact extends BaseObject
                        $apcontact['alias'] = JsonLD::fetchElement($compacted['as:url'], 'as:href', '@id');
                }
 
-               if (empty($apcontact['url']) || empty($apcontact['inbox'])) {
+               // Quit if none of the basic values are set
+               if (empty($apcontact['url']) || empty($apcontact['inbox']) || empty($apcontact['type'])) {
+                       return false;
+               }
+
+               // Quit if this doesn't seem to be an account at all
+               if (!in_array($apcontact['type'], ActivityPub::ACCOUNT_TYPES)) {
                        return false;
                }
 
@@ -228,11 +234,13 @@ class APContact extends BaseObject
 
                DBA::update('contact', $contact_fields, ['nurl' => Strings::normaliseLink($url)]);
 
-               $contacts = DBA::select('contact', ['uid', 'id'], ['nurl' => Strings::normaliseLink($url)]);
-               while ($contact = DBA::fetch($contacts)) {
-                       Contact::updateAvatar($apcontact['photo'], $contact['uid'], $contact['id']);
+               if (!empty($apcontact['photo'])) {
+                       $contacts = DBA::select('contact', ['uid', 'id'], ['nurl' => Strings::normaliseLink($url)]);
+                       while ($contact = DBA::fetch($contacts)) {
+                               Contact::updateAvatar($apcontact['photo'], $contact['uid'], $contact['id']);
+                       }
+                       DBA::close($contacts);
                }
-               DBA::close($contacts);
 
                // Update the gcontact table
                // These two fields don't exist in the gcontact table
index a0bbdd10499f43abbf6138d976c7a145e6d66402..7e1d8c2ba5d9a174534df794fd619ff454dcb4d4 100644 (file)
@@ -2157,7 +2157,8 @@ class Contact extends BaseObject
 
                if (!empty($contact)) {
             // Contact is blocked at user-level
-                   if (self::isBlockedByUser($contact['id'], $importer['id'])) {
+                   if (!empty($contact['id']) && !empty($importer['id']) &&
+                       self::isBlockedByUser($contact['id'], $importer['id'])) {
                        return false;
             }
 
index e57b3cbd3c740649234a4c11fc12373da26822bb..4dc1be648aea7c455cf20958cae6512b69da744c 100644 (file)
@@ -926,7 +926,7 @@ class Item extends BaseObject
                        // We only need to notfiy others when it is an original entry from us.
                        // Only call the notifier when the item has some content relevant change.
                        if ($item['origin'] && in_array('edited', array_keys($fields))) {
-                               Worker::add(PRIORITY_HIGH, "Notifier", 'edit_post', $item['id']);
+                               Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $item['id']);
                        }
                }
 
@@ -1096,7 +1096,7 @@ class Item extends BaseObject
                        self::delete(['uri' => $item['uri'], 'deleted' => false], $priority);
 
                        // send the notification upstream/downstream
-                       Worker::add(['priority' => $priority, 'dont_fork' => true], "Notifier", "drop", intval($item['id']));
+                       Worker::add(['priority' => $priority, 'dont_fork' => true], "Notifier", Delivery::DELETION, intval($item['id']));
                } elseif ($item['uid'] != 0) {
 
                        // When we delete just our local user copy of an item, we have to set a marker to hide it
@@ -1509,7 +1509,7 @@ class Item extends BaseObject
 
                $item['thr-parent'] = $item['parent-uri'];
 
-               $notify_type = '';
+               $notify_type = Delivery::POST;
                $allow_cid = '';
                $allow_gid = '';
                $deny_cid  = '';
@@ -1522,7 +1522,6 @@ class Item extends BaseObject
                        $allow_gid = $item['allow_gid'];
                        $deny_cid  = $item['deny_cid'];
                        $deny_gid  = $item['deny_gid'];
-                       $notify_type = Delivery::POST;
                } else {
                        // find the parent and snarf the item id and ACLs
                        // and anything else we need to inherit
@@ -1560,7 +1559,6 @@ class Item extends BaseObject
                                $deny_cid       = $parent['deny_cid'];
                                $deny_gid       = $parent['deny_gid'];
                                $item['wall']   = $parent['wall'];
-                               $notify_type    = Delivery::COMMENT;
 
                                /*
                                 * If the parent is private, force privacy for the entire conversation
@@ -1882,20 +1880,8 @@ class Item extends BaseObject
 
                check_user_notification($current_post);
 
-               if ($notify) {
+               if ($notify || ($item['visible'] && ((!empty($parent) && $parent['origin']) || $item['origin']))) {
                        Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $notify_type, $current_post);
-               } elseif ($item['visible'] && ((!empty($parent) && $parent['origin']) || $item['origin'])) {
-                       if ($item['gravity'] == GRAVITY_ACTIVITY) {
-                               $cmd = $item['origin'] ? Delivery::ACTIVITY : 'activity-import';
-                       } elseif ($item['gravity'] == GRAVITY_COMMENT) {
-                               $cmd = $item['origin'] ? Delivery::COMMENT : 'comment-import';
-                       } elseif (!empty($notify_type)) {
-                               $cmd = $notify_type;
-                       } else {
-                               $cmd = Delivery::POST;
-                       }
-
-                       Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $cmd, $current_post);
                }
 
                return $current_post;
@@ -2611,7 +2597,7 @@ class Item extends BaseObject
 
                self::updateThread($item_id);
 
-               Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', 'tgroup', $item_id);
+               Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', Delivery::POST, $item_id);
        }
 
        public static function isRemoteSelf($contact, &$datarray)
index 9bdb6e1a10bdd91895dd6fcdf91f020b71e248f9..30191edae62b4122337e3e29cdcd4e2d527d53fa 100644 (file)
@@ -13,6 +13,7 @@ use Friendica\Model\Item;
 use Friendica\Database\DBA;
 use Friendica\Network\Probe;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Worker\Delivery;
 
 /**
  * Class to handle private messages
@@ -218,7 +219,7 @@ class Mail
                }
 
                if ($post_id) {
-                       Worker::add(PRIORITY_HIGH, "Notifier", "mail", $post_id);
+                       Worker::add(PRIORITY_HIGH, "Notifier", Delivery::MAIL, $post_id);
                        return intval($post_id);
                } else {
                        return -3;
index 8ad7f3145f3d8c30d593c3b1b34c24999774171a..2d740e137858c9e4d47059eb8d75818d3be032ad 100644 (file)
@@ -413,7 +413,11 @@ class Photo extends BaseObject
                $photo_failure = false;
 
                $filename = basename($image_url);
-               $img_str = Network::fetchUrl($image_url, true);
+               if (!empty($image_url)) {
+                       $img_str = Network::fetchUrl($image_url, true);
+               } else {
+                       $img_str = '';
+               }
 
                if ($quit_on_error && ($img_str == "")) {
                        return false;
index 64253946fd71207f0c54b50b58c4ad76ed5ecaf5..b73356306e465720f15aec64601dbe5045603c68 100644 (file)
@@ -21,6 +21,7 @@ use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
+use Friendica\Worker\Delivery;
 use LightOpenID;
 
 /**
@@ -912,7 +913,7 @@ class User
 
                // The user and related data will be deleted in "cron_expire_and_remove_users" (cronjobs.php)
                DBA::update('user', ['account_removed' => true, 'account_expires_on' => DateTimeFormat::utc('now + 7 day')], ['uid' => $uid]);
-               Worker::add(PRIORITY_HIGH, 'Notifier', 'removeme', $uid);
+               Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::REMOVAL, $uid);
 
                // Send an update to the directory
                $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
index 5d2004ca5fbf988961e51671f9dc973671792450..78576efe3bce0f710a926fc9074a729f8f6616b8 100644 (file)
@@ -16,6 +16,7 @@ use Friendica\Protocol\PortableContact;
 use Friendica\Util\BasePath;
 use Friendica\Util\BaseURL;
 use Friendica\Util\Strings;
+use Friendica\Worker\Delivery;
 
 require_once __DIR__ . '/../../../boot.php';
 
@@ -99,7 +100,7 @@ class Site extends BaseAdminModule
                        // send relocate
                        $usersStmt = DBA::select('user', ['uid'], ['account_removed' => false, 'account_expired' => false]);
                        while ($user = DBA::fetch($usersStmt)) {
-                               Worker::add(PRIORITY_HIGH, 'Notifier', 'relocate', $user['uid']);
+                               Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, $user['uid']);
                        }
 
                        info("Relocation started. Could take a while to complete.");
index 491ed31cbd4a4bd0c24036ea45a398325d078251..441fe7f157a33c61609744422dd94385a2cbb3ae 100644 (file)
@@ -85,7 +85,7 @@ class Magic extends BaseModule
                                );
 
                                // Try to get an authentication token from the other instance.
-                               $curlResult = Network::curl($basepath . '/owa', false, $redirects, ['headers' => $headers]);
+                               $curlResult = Network::curl($basepath . '/owa', false, ['headers' => $headers]);
 
                                if ($curlResult->isSuccess()) {
                                        $j = json_decode($curlResult->getBody(), true);
index b0d2630103beaed42328d4aa61cee75a08a3d57f..00c38a4c12c16b383234beb6583bcea71c532c80 100644 (file)
@@ -109,12 +109,11 @@ class Probe
                $url = "http://".$host."/.well-known/host-meta";
 
                $xrd_timeout = Config::get('system', 'xrd_timeout', 20);
-               $redirects = 0;
 
                Logger::log("Probing for ".$host, Logger::DEBUG);
                $xrd = null;
 
-               $curlResult = Network::curl($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
+               $curlResult = Network::curl($ssl_url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
                if ($curlResult->isSuccess()) {
                        $xml = $curlResult->getBody();
                        $xrd = XML::parseString($xml, false);
@@ -122,7 +121,7 @@ class Probe
                }
 
                if (!is_object($xrd)) {
-                       $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
+                       $curlResult = Network::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
                        if ($curlResult->isTimeout()) {
                                Logger::log("Probing timeout for " . $url, Logger::DEBUG);
                                self::$istimeout = true;
@@ -738,9 +737,8 @@ class Probe
        private static function webfinger($url, $type)
        {
                $xrd_timeout = Config::get('system', 'xrd_timeout', 20);
-               $redirects = 0;
 
-               $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
+               $curlResult = Network::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
                if ($curlResult->isTimeout()) {
                        self::$istimeout = true;
                        return false;
index 67413e3c0d1e7c5f13d7ae07287f4827ad9c4973..803aa08b38f58b7e28da83ce0506769aea38f766 100644 (file)
@@ -781,7 +781,7 @@ class Image
                $data = Cache::get($url);
 
                if (is_null($data) || !$data || !is_array($data)) {
-                       $img_str = Network::fetchUrl($url, true, $redirects, 4);
+                       $img_str = Network::fetchUrl($url, true, 4);
 
                        if (!$img_str) {
                                return false;
index fa63c44d574bcb9b8f2f6af54707f3cd721f6229..8caf7ac64c97bb8bd88510d8a93f414a03459030 100644 (file)
@@ -74,7 +74,7 @@ class ActivityPub
                        return HTTPSignature::fetch($url, $uid);
                }
 
-               $curlResult = Network::curl($url, false, $redirects, ['accept_content' => 'application/activity+json, application/ld+json']);
+               $curlResult = Network::curl($url, false, ['accept_content' => 'application/activity+json, application/ld+json']);
                if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
                        return false;
                }
index 06dbaee71f81f1c619a9e857dde8dd80c465cb01..81b8bc1de310a98d6020adc559de339423868926 100644 (file)
@@ -436,7 +436,7 @@ class Transmitter
                                                                $data['to'][] = $profile['url'];
                                                        } else {
                                                                $data['cc'][] = $profile['url'];
-                                                               if (!$item['private']) {
+                                                               if (!$item['private'] && !empty($actor_profile['followers'])) {
                                                                        $data['cc'][] = $actor_profile['followers'];
                                                                }
                                                        }
@@ -1141,7 +1141,7 @@ class Transmitter
        {
                $event = [];
                $event['name'] = $item['event-summary'];
-               $event['content'] = BBCode::convert($item['event-desc'], false, 7);
+               $event['content'] = BBCode::convert($item['event-desc'], false, 9);
                $event['startTime'] = DateTimeFormat::utc($item['event-start'] . '+00:00', DateTimeFormat::ATOM);
 
                if (!$item['event-nofinish']) {
@@ -1231,7 +1231,7 @@ class Transmitter
                        $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
                        $body = preg_replace_callback($regexp, ['self', 'mentionCallback'], $body);
 
-                       $data['content'] = BBCode::convert($body, false, 7);
+                       $data['content'] = BBCode::convert($body, false, 9);
                }
 
                $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"];
index fe2a608ec6fd0358fd94757e08ae0f6e471dfe81..ec4557e8221a70f833b090d2da98f32f8cb78b2b 100644 (file)
@@ -2216,11 +2216,10 @@ class DFRN
        {
                Logger::log("Process verb ".$item["verb"]." and object-type ".$item["object-type"]." for entrytype ".$entrytype, Logger::DEBUG);
 
-               if (($entrytype == DFRN::TOP_LEVEL)) {
+               if (($entrytype == DFRN::TOP_LEVEL) && !empty($importer['id'])) {
                        // The filling of the the "contact" variable is done for legcy reasons
                        // The functions below are partly used by ostatus.php as well - where we have this variable
-                       $r = q("SELECT * FROM `contact` WHERE `id` = %d", intval($importer["id"]));
-                       $contact = $r[0];
+                       $contact = Contact::select([], ['id' => $importer['id']]);
 
                        // Big question: Do we need these functions? They were part of the "consume_feed" function.
                        // This function once was responsible for DFRN and OStatus.
index ac1cf9c38d469793b7d7179de1cca1a0707167b0..751033e9600c6dc5fb4453e95562177a732f2dcb 100644 (file)
@@ -2148,13 +2148,9 @@ class Diaspora
                        if ($comment['id'] == $comment['parent']) {
                                continue;
                        }
-                       if ($comment['verb'] == ACTIVITY_POST) {
-                               $cmd = $comment['self'] ? Delivery::COMMENT : 'comment-import';
-                       } else {
-                               $cmd = $comment['self'] ? Delivery::ACTIVITY : 'activity-import';
-                       }
-                       Logger::log("Send ".$cmd." for item ".$comment['id']." to contact ".$contact_id, Logger::DEBUG);
-                       Worker::add(PRIORITY_HIGH, 'Delivery', $cmd, $comment['id'], $contact_id);
+
+                       Logger::info('Deliver participation', ['item' => $comment['id'], 'contact' => $contact_id]);
+                       Worker::add(PRIORITY_HIGH, 'Delivery', Delivery::POST, $comment['id'], $contact_id);
                }
                DBA::close($comments);
 
index 81e5c19db8cc42d73eaf2c5e7adc2f2f74c2cb53..9fa0ff43af73e9120122178142dba54257ee03e4 100644 (file)
@@ -738,7 +738,7 @@ class OStatus
 
                self::$conv_list[$conversation] = true;
 
-               $curlResult = Network::curl($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
+               $curlResult = Network::curl($conversation, false, ['accept_content' => 'application/atom+xml, text/html']);
 
                if (!$curlResult->isSuccess()) {
                        return;
@@ -931,7 +931,7 @@ class OStatus
                }
 
                $stored = false;
-               $curlResult = Network::curl($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
+               $curlResult = Network::curl($related, false, ['accept_content' => 'application/atom+xml, text/html']);
 
                if (!$curlResult->isSuccess()) {
                        return;
index 5345cb22fce2ae182c6f155ab93e518138c08790..60bb844226038c951a01d50f8709e363c2fbc0e7 100644 (file)
@@ -1004,7 +1004,7 @@ class PortableContact
                $server_url = str_replace("http://", "https://", $server_url);
 
                // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital
-               $curlResult = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]);
+               $curlResult = Network::curl($server_url."/.well-known/host-meta", false, ['timeout' => 20]);
 
                // Quit if there is a timeout.
                // But we want to make sure to only quit if we are mostly sure that this server url fits.
@@ -1021,7 +1021,7 @@ class PortableContact
                        $server_url = str_replace("https://", "http://", $server_url);
 
                        // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital
-                       $curlResult = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]);
+                       $curlResult = Network::curl($server_url."/.well-known/host-meta", false, ['timeout' => 20]);
 
                        // Quit if there is a timeout
                        if ($curlResult->isTimeout()) {
@@ -1624,7 +1624,7 @@ class PortableContact
                        if (!empty($accesstoken)) {
                                $api = 'https://instances.social/api/1.0/instances/list?count=0';
                                $header = ['Authorization: Bearer '.$accesstoken];
-                               $curlResult = Network::curl($api, false, $redirects, ['headers' => $header]);
+                               $curlResult = Network::curl($api, false, ['headers' => $header]);
 
                                if ($curlResult->isSuccess()) {
                                        $servers = json_decode($curlResult->getBody(), true);
index e002d5981cb54f3b78961adc05057df49db0328d..8a058c3b5c7e45d15bd4737daf29dc41b76b5890 100644 (file)
@@ -455,7 +455,7 @@ class HTTPSignature
                $curl_opts = $opts;
                $curl_opts['header'] = $headers;
 
-               $curlResult = Network::curl($request, false, $redirects, $curl_opts);
+               $curlResult = Network::curl($request, false, $curl_opts);
                $return_code = $curlResult->getReturnCode();
 
                Logger::log('Fetched for user ' . $uid . ' from ' . $request . ' returned ' . $return_code, Logger::DEBUG);
index e4e9c5af5bb5a75673017425b6cc298057fa74ac..92265e30e6116a8721d8f2b1f4d9db3524e1439f 100644 (file)
@@ -23,19 +23,19 @@ class Network
         *
         * @brief Curl wrapper
         * @param string  $url            URL to fetch
-        * @param boolean $binary         default false
+        * @param bool    $binary         default false
         *                                TRUE if asked to return binary results (file download)
-        * @param integer $redirects      The recursion counter for internal use - default 0
-        * @param integer $timeout        Timeout in seconds, default system config value or 60 seconds
+        * @param int     $timeout        Timeout in seconds, default system config value or 60 seconds
         * @param string  $accept_content supply Accept: header with 'accept_content' as the value
         * @param string  $cookiejar      Path to cookie jar file
+        * @param int     $redirects      The recursion counter for internal use - default 0
         *
         * @return string The fetched content
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function fetchUrl($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = '')
+       public static function fetchUrl(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0)
        {
-               $ret = self::fetchUrlFull($url, $binary, $redirects, $timeout, $accept_content, $cookiejar);
+               $ret = self::fetchUrlFull($url, $binary, $timeout, $accept_content, $cookiejar, $redirects);
 
                return $ret->getBody();
        }
@@ -48,26 +48,27 @@ class Network
         *
         * @brief Curl wrapper with array of return values.
         * @param string  $url            URL to fetch
-        * @param boolean $binary         default false
+        * @param bool    $binary         default false
         *                                TRUE if asked to return binary results (file download)
-        * @param integer $redirects      The recursion counter for internal use - default 0
-        * @param integer $timeout        Timeout in seconds, default system config value or 60 seconds
+        * @param int     $timeout        Timeout in seconds, default system config value or 60 seconds
         * @param string  $accept_content supply Accept: header with 'accept_content' as the value
         * @param string  $cookiejar      Path to cookie jar file
+        * @param int     $redirects      The recursion counter for internal use - default 0
         *
         * @return CurlResult With all relevant information, 'body' contains the actual fetched content.
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function fetchUrlFull($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = '')
+       public static function fetchUrlFull(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0)
        {
                return self::curl(
                        $url,
                        $binary,
-                       $redirects,
-                       ['timeout'=>$timeout,
-                       'accept_content'=>$accept_content,
-                       'cookiejar'=>$cookiejar
-                       ]
+                       [
+                               'timeout'        => $timeout,
+                               'accept_content' => $accept_content,
+                               'cookiejar'      => $cookiejar
+                       ],
+                       $redirects
                );
        }
 
@@ -75,9 +76,8 @@ class Network
         * @brief fetches an URL.
         *
         * @param string  $url       URL to fetch
-        * @param boolean $binary    default false
+        * @param bool    $binary    default false
         *                           TRUE if asked to return binary results (file download)
-        * @param int     $redirects The recursion counter for internal use - default 0
         * @param array   $opts      (optional parameters) assoziative array with:
         *                           'accept_content' => supply Accept: header with 'accept_content' as the value
         *                           'timeout' => int Timeout in seconds, default system config value or 60 seconds
@@ -86,11 +86,12 @@ class Network
         *                           'nobody' => only return the header
         *                           'cookiejar' => path to cookie jar file
         *                           'header' => header array
+        * @param int     $redirects The recursion counter for internal use - default 0
         *
         * @return CurlResult
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function curl($url, $binary = false, &$redirects = 0, $opts = [])
+       public static function curl(string $url, bool $binary = false, array $opts = [], int &$redirects = 0)
        {
                $stamp1 = microtime(true);
 
@@ -227,7 +228,7 @@ class Network
                        $redirects++;
                        Logger::log('curl: redirect ' . $url . ' to ' . $curlResponse->getRedirectUrl());
                        @curl_close($ch);
-                       return self::curl($curlResponse->getRedirectUrl(), $binary, $redirects, $opts);
+                       return self::curl($curlResponse->getRedirectUrl(), $binary, $opts, $redirects);
                }
 
                @curl_close($ch);
@@ -242,14 +243,14 @@ class Network
         *
         * @param string  $url       URL to post
         * @param mixed   $params    array of POST variables
-        * @param string  $headers   HTTP headers
-        * @param integer $redirects Recursion counter for internal use - default = 0
-        * @param integer $timeout   The timeout in seconds, default system config value or 60 seconds
+        * @param array   $headers   HTTP headers
+        * @param int     $redirects Recursion counter for internal use - default = 0
+        * @param int     $timeout   The timeout in seconds, default system config value or 60 seconds
         *
         * @return CurlResult The content
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function post($url, $params, $headers = null, &$redirects = 0, $timeout = 0)
+       public static function post(string $url, $params, array $headers = [], int $timeout = 0, int &$redirects = 0)
        {
                $stamp1 = microtime(true);
 
@@ -285,7 +286,7 @@ class Network
                }
 
                if (defined('LIGHTTPD')) {
-                       if (!is_array($headers)) {
+                       if (empty($headers)) {
                                $headers = ['Expect:'];
                        } else {
                                if (!in_array('Expect:', $headers)) {
@@ -294,7 +295,7 @@ class Network
                        }
                }
 
-               if ($headers) {
+               if (!empty($headers)) {
                        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                }
 
@@ -351,7 +352,7 @@ class Network
         * @return string|boolean The actual working URL, false else
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function isUrlValid($url)
+       public static function isUrlValid(string $url)
        {
                if (Config::get('system', 'disable_url_validation')) {
                        return $url;
@@ -381,9 +382,8 @@ class Network
         *
         * @param string $addr The email address
         * @return boolean True if it's a valid email address, false if it's not
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function isEmailDomainValid($addr)
+       public static function isEmailDomainValid(string $addr)
        {
                if (Config::get('system', 'disable_email_validation')) {
                        return true;
@@ -413,9 +413,8 @@ class Network
         *
         * @param string $url URL which get tested
         * @return boolean True if url is allowed otherwise return false
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function isUrlAllowed($url)
+       public static function isUrlAllowed(string $url)
        {
                $h = @parse_url($url);
 
@@ -460,7 +459,7 @@ class Network
         *
         * @return boolean
         */
-       public static function isUrlBlocked($url)
+       public static function isUrlBlocked(string $url)
        {
                $host = @parse_url($url, PHP_URL_HOST);
                if (!$host) {
@@ -491,7 +490,7 @@ class Network
         *                       or if allowed list is not configured
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function isEmailDomainAllowed($email)
+       public static function isEmailDomainAllowed(string $email)
        {
                $domain = strtolower(substr($email, strpos($email, '@') + 1));
                if (!$domain) {
@@ -516,7 +515,7 @@ class Network
         * @param array  $domain_list
         * @return boolean
         */
-       public static function isDomainAllowed($domain, array $domain_list)
+       public static function isDomainAllowed(string $domain, array $domain_list)
        {
                $found = false;
 
@@ -531,7 +530,7 @@ class Network
                return $found;
        }
 
-       public static function lookupAvatarByEmail($email)
+       public static function lookupAvatarByEmail(string $email)
        {
                $avatar['size'] = 300;
                $avatar['email'] = $email;
@@ -554,7 +553,7 @@ class Network
         * @param string $url Any user-submitted URL that may contain tracking params
         * @return string The same URL stripped of tracking parameters
         */
-       public static function stripTrackingQueryParams($url)
+       public static function stripTrackingQueryParams(string $url)
        {
                $urldata = parse_url($url);
                if (!empty($urldata["query"])) {
@@ -613,7 +612,7 @@ class Network
         * @return string A canonical URL
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function finalUrl($url, $depth = 1, $fetchbody = false)
+       public static function finalUrl(string $url, int $depth = 1, bool $fetchbody = false)
        {
                $a = \get_app();
 
@@ -724,7 +723,7 @@ class Network
         * @param string $url2
         * @return string The matching part
         */
-       public static function getUrlMatch($url1, $url2)
+       public static function getUrlMatch(string $url1, string $url2)
        {
                if (($url1 == "") || ($url2 == "")) {
                        return "";
@@ -812,7 +811,7 @@ class Network
         *
         * @return string The glued URL
         */
-       public static function unparseURL($parsed)
+       public static function unparseURL(array $parsed)
        {
                $get = function ($key) use ($parsed) {
                        return isset($parsed[$key]) ? $parsed[$key] : null;
@@ -844,7 +843,7 @@ class Network
         *
         * @return string switched URL
         */
-       public static function switchScheme($url)
+       public static function switchScheme(string $url)
        {
                $scheme = parse_url($url, PHP_URL_SCHEME);
                if (empty($scheme)) {
index d1e668e0d8ce80a46ec101630d5a1fb4a88db9ce..1c934d6fe617c741d9d6b47316570ea2ebe7b74b 100644 (file)
@@ -120,9 +120,18 @@ class Security extends BaseObject
                         */
 
                        if (!$remote_verified) {
-                               if (DBA::exists('contact', ['id' => $remote_user, 'uid' => $owner_id, 'blocked' => false])) {
+                               $cid = 0;
+
+                               foreach (\Friendica\Core\Session::get('remote', []) as $visitor) {
+                                       if ($visitor['uid'] == $owner_id) {
+                                               $cid = $visitor['cid'];
+                                               break;
+                                       }
+                               }
+
+                               if ($cid && DBA::exists('contact', ['id' => $cid, 'uid' => $owner_id, 'blocked' => false])) {
                                        $remote_verified = true;
-                                       $groups = Group::getIdsByContactId($remote_user);
+                                       $groups = Group::getIdsByContactId($cid);
                                }
                        }
 
@@ -140,9 +149,9 @@ class Security extends BaseObject
                                          AND ( allow_cid REGEXP '<%d>' OR allow_gid REGEXP '%s' OR ( allow_cid = '' AND allow_gid = '') )
                                          )
                                        ",
-                                       intval($remote_user),
+                                       intval($cid),
                                        DBA::escape($gs),
-                                       intval($remote_user),
+                                       intval($cid),
                                        DBA::escape($gs)
                                );
                        }
index 632f6cffc5dae09736391dafa11befa0ae6d7993..fcd4a76725f65dd4881a3f956fb14bf9da653b13 100644 (file)
@@ -48,7 +48,7 @@ class APDelivery extends BaseObject
                        $data = ActivityPub\Transmitter::createCachedActivityFromItem($target_id);
                        if (!empty($data)) {
                                $success = HTTPSignature::transmit($data, $inbox, $uid);
-                               if ($success && in_array($cmd, [Delivery::POST, Delivery::COMMENT])) {
+                               if ($success && in_array($cmd, [Delivery::POST])) {
                                        ItemDeliveryData::incrementQueueDone($target_id);
                                }
                        }
index 97bc58ef67411fd52345cd85e74790c7105798d2..ad6bb75c03af95055ecd2944c0dc1eea3633e373 100644 (file)
@@ -27,8 +27,7 @@ class Delivery extends BaseObject
        const DELETION      = 'drop';
        const POST          = 'wall-new';
        const POKE          = 'poke';
-       const COMMENT       = 'comment-new';
-       const ACTIVITY      = 'activity-new';
+       const UPLINK        = 'uplink';
        const REMOVAL       = 'removeme';
        const PROFILEUPDATE = 'profileupdate';
 
@@ -319,7 +318,7 @@ class Delivery extends BaseObject
                        // We successfully delivered a message, the contact is alive
                        Model\Contact::unmarkForArchival($contact);
 
-                       if (in_array($cmd, [Delivery::POST, Delivery::COMMENT])) {
+                       if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
                                Model\ItemDeliveryData::incrementQueueDone($target_item['id']);
                        }
                } else {
@@ -400,7 +399,7 @@ class Delivery extends BaseObject
                        // We successfully delivered a message, the contact is alive
                        Model\Contact::unmarkForArchival($contact);
 
-                       if (in_array($cmd, [Delivery::POST, Delivery::COMMENT])) {
+                       if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
                                Model\ItemDeliveryData::incrementQueueDone($target_item['id']);
                        }
                } else {
@@ -411,7 +410,7 @@ class Delivery extends BaseObject
                                Logger::info('Delivery failed: defer message', ['id' => defaults($target_item, 'guid', $target_item['id'])]);
                                // defer message for redelivery
                                Worker::defer();
-                       } elseif (in_array($cmd, [Delivery::POST, Delivery::COMMENT])) {
+                       } elseif (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
                                Model\ItemDeliveryData::incrementQueueDone($target_item['id']);
                        }
                }
@@ -439,7 +438,7 @@ class Delivery extends BaseObject
                        return;
                }
 
-               if (!in_array($cmd, [self::POST, self::COMMENT])) {
+               if (!in_array($cmd, [self::POST, self::POKE])) {
                        return;
                }
 
index c2f61c55a426325ef97734ee1ae39d1bade45e0d..36c6e92a04d9a20ff7dd4cc589f365c7d9b8e621 100644 (file)
@@ -32,23 +32,7 @@ require_once 'include/items.php';
  *
  *             Worker::add(PRIORITY_HIGH, "Notifier", COMMAND, ITEM_ID);
  *
- * where COMMAND is one of the following:
- *
- *             activity                                (in diaspora.php, dfrn_confirm.php, profiles.php)
- *             comment-import                  (in diaspora.php, items.php)
- *             comment-new                             (in item.php)
- *             drop                                    (in diaspora.php, items.php, photos.php)
- *             edit_post                               (in item.php)
- *             event                                   (in events.php)
- *             like                                    (in like.php, poke.php)
- *             mail                                    (in message.php)
- *             suggest                                 (in fsuggest.php)
- *             tag                                             (in photos.php, poke.php, tagger.php)
- *             tgroup                                  (in items.php)
- *             wall-new                                (in photos.php, item.php)
- *             removeme                                (in Contact.php)
- *             relocate                                (in uimport.php)
- *
+ * where COMMAND is one of the constants that are defined in Worker/Delivery.php
  * and ITEM_ID is the id of the item in the database that needs to be sent to others.
  */
 
@@ -199,7 +183,7 @@ class Notifier
                        }
 
 
-                       if (($cmd === 'uplink') && (intval($parent['forum_mode']) == 1) && !$top_level) {
+                       if (($cmd === Delivery::UPLINK) && (intval($parent['forum_mode']) == 1) && !$top_level) {
                                $relay_to_owner = true;
                        }
 
@@ -287,8 +271,8 @@ class Notifier
                                // if our parent is a public forum (forum_mode == 1), uplink to the origional author causing
                                // a delivery fork. private groups (forum_mode == 2) do not uplink
 
-                               if ((intval($parent['forum_mode']) == 1) && !$top_level && ($cmd !== 'uplink')) {
-                                       Worker::add($a->queue['priority'], 'Notifier', 'uplink', $target_id);
+                               if ((intval($parent['forum_mode']) == 1) && !$top_level && ($cmd !== Delivery::UPLINK)) {
+                                       Worker::add($a->queue['priority'], 'Notifier', Delivery::UPLINK, $target_id);
                                }
 
                                foreach ($items as $item) {
@@ -545,13 +529,19 @@ class Notifier
                if (!empty($target_item)) {
                        Logger::log('Calling hooks for ' . $cmd . ' ' . $target_id, Logger::DEBUG);
 
-                       if (in_array($cmd, [Delivery::POST, Delivery::COMMENT])) {
-                               ItemDeliveryData::update($target_item['id'], ['queue_count' => $delivery_queue_count]);
-                       }
-
                        Hook::fork($a->queue['priority'], 'notifier_normal', $target_item);
 
                        Hook::callAll('notifier_end', $target_item);
+
+                       // Workaround for pure connector posts
+                       if ($delivery_queue_count == 0) {
+                               ItemDeliveryData::incrementQueueDone($target_item['id']);
+                               $delivery_queue_count = 1;
+                       }
+
+                       if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
+                               ItemDeliveryData::update($target_item['id'], ['queue_count' => $delivery_queue_count]);
+                       }
                }
 
                return;
index 8f494af53a9afc4130251c0603f06bb9dc52d0ff..a605ee92ed593b4bde77e8b3b4a68da4eccfcd36 100644 (file)
@@ -371,7 +371,7 @@ class OnePoll
                        }
 
                        $cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-');
-                       $curlResult = Network::curl($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]);
+                       $curlResult = Network::curl($contact['poll'], false, ['cookiejar' => $cookiejar]);
                        unlink($cookiejar);
 
                        if ($curlResult->isTimeout()) {
index e6ac8255e9f7b3b454aced052381a62e71a44c04..f8f81f9ee721c8193bfbe656d3ad9279efb2bdbf 100644 (file)
@@ -275,4 +275,77 @@ class ConfigCacheTest extends MockedTest
 
                $this->assertEmpty($configCache->keyDiff($diffConfig));
        }
+
+       /**
+        * Test the default hiding of passwords inside the cache
+        */
+       public function testPasswordHide()
+       {
+               $configCache = new ConfigCache([
+                       'database' => [
+                               'password' => 'supersecure',
+                               'username' => 'notsecured',
+                       ],
+               ]);
+
+               $this->assertEquals('supersecure', $configCache->get('database', 'password'));
+               $this->assertNotEquals('supersecure', print_r($configCache->get('database', 'password'), true));
+               $this->assertEquals('notsecured', print_r($configCache->get('database', 'username'), true));
+       }
+
+       /**
+        * Test disabling the hiding of passwords inside the cache
+        */
+       public function testPasswordShow()
+       {
+               $configCache = new ConfigCache([
+                       'database' => [
+                               'password' => 'supersecure',
+                               'username' => 'notsecured',
+                       ],
+               ], false);
+
+               $this->assertEquals('supersecure', $configCache->get('database', 'password'));
+               $this->assertEquals('supersecure', print_r($configCache->get('database', 'password'), true));
+               $this->assertEquals('notsecured', print_r($configCache->get('database', 'username'), true));
+       }
+
+       /**
+        * Test a empty password
+        */
+       public function testEmptyPassword()
+       {
+               $configCache = new ConfigCache([
+                       'database' => [
+                               'password' => '',
+                               'username' => '',
+                       ]
+               ]);
+
+               $this->assertEmpty($configCache->get('database', 'password'));
+               $this->assertEmpty($configCache->get('database', 'username'));
+       }
+
+       public function testWrongTypePassword()
+       {
+               $configCache = new ConfigCache([
+                       'database' => [
+                               'password' => new \stdClass(),
+                               'username' => '',
+                       ]
+               ]);
+
+               $this->assertNotEmpty($configCache->get('database', 'password'));
+               $this->assertEmpty($configCache->get('database', 'username'));
+
+               $configCache = new ConfigCache([
+                       'database' => [
+                               'password' => 23,
+                               'username' => '',
+                       ]
+               ]);
+
+               $this->assertEquals(23, $configCache->get('database', 'password'));
+               $this->assertEmpty($configCache->get('database', 'username'));
+       }
 }
index 40a3e8ff0d22ee39328b8eddcd39621144af1e00..077a56e66e795252e8027ab6b1f73caa1ad338f3 100644 (file)
@@ -362,14 +362,8 @@ function update_1309()
                        continue;
                }
 
-               if ($item['gravity'] == GRAVITY_PARENT) {
-                       $cmd = Delivery::POST;
-               } else {
-                       $cmd = Delivery::COMMENT;
-               }
-
                $deliver_options = ['priority' => PRIORITY_MEDIUM, 'dont_fork' => true];
-               Worker::add($deliver_options, 'Delivery', $cmd, $item['id'], $entry['cid']);
+               Worker::add($deliver_options, 'Delivery', Delivery::POST, $item['id'], $entry['cid']);
                Logger::info('Added delivery worker', ['command' => $cmd, 'item' => $item['id'], 'contact' => $entry['cid']]);
                DBA::delete('queue', ['id' => $entry['id']]);
        }