From 0c19c4c75d7ef3d93eddcd09702915c083469c1e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 16:05:03 -0500 Subject: [PATCH 01/15] Fix missing reference to 'data' key in Util\Crypto - Fix doc blocks --- src/Util/Crypto.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Util/Crypto.php b/src/Util/Crypto.php index 4f762964c..2ab97e537 100644 --- a/src/Util/Crypto.php +++ b/src/Util/Crypto.php @@ -423,13 +423,13 @@ class Crypto * * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/include/crypto.php * - * @param string $data + * @param array $data ['iv' => $iv, 'key' => $key, 'alg' => $alg, 'data' => $data] * @param string $prvkey The private key used for decryption. * * @return string|boolean The decrypted string or false on failure. * @throws \Exception */ - public static function unencapsulate($data, $prvkey) + public static function unencapsulate(array $data, $prvkey) { if (!$data) { return; @@ -437,23 +437,23 @@ class Crypto $alg = ((array_key_exists('alg', $data)) ? $data['alg'] : 'aes256cbc'); if ($alg === 'aes256cbc') { - return self::encapsulateAes($data, $prvkey); + return self::encapsulateAes($data['data'], $prvkey); } - return self::encapsulateOther($data, $prvkey, $alg); + return self::encapsulateOther($data['data'], $prvkey, $alg); } /** * * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/include/crypto.php * - * @param string $data + * @param array $data * @param string $prvkey The private key used for decryption. * @param string $alg * * @return string|boolean The decrypted string or false on failure. * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - private static function unencapsulateOther($data, $prvkey, $alg) + private static function unencapsulateOther(array $data, $prvkey, $alg) { $fn = 'decrypt' . strtoupper($alg); From d5ce74672e0886ccceeff25ed6d1a3ad31a50a83 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 16:05:25 -0500 Subject: [PATCH 02/15] Fix method scope in Model\Attach --- src/Model/Attach.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Attach.php b/src/Model/Attach.php index bd4269b9e..3bd77ef9c 100644 --- a/src/Model/Attach.php +++ b/src/Model/Attach.php @@ -176,7 +176,7 @@ class Attach extends BaseObject * @return boolean/integer Row id on success, False on errors * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function store($data, $uid, $filename, $filetype = '' , $filesize = null, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') + public static function store($data, $uid, $filename, $filetype = '' , $filesize = null, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') { if ($filetype === '') { $filetype = Mimetype::getContentType($filename); From 5ea033db33c62562dcd27dd70447a35b3d14326e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 16:05:42 -0500 Subject: [PATCH 03/15] Remove unused variable in Model\Item --- src/Model/Item.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 300e80650..67071db31 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1790,13 +1790,13 @@ class Item extends BaseObject DBA::insert('diaspora-interaction', ['uri-id' => $item['uri-id'], 'interaction' => $diaspora_signed_text], true); } - $deleted = self::tagDeliver($item['uid'], $current_post); + self::tagDeliver($item['uid'], $current_post); /* * current post can be deleted if is for a community page and no mention are * in it. */ - if (!$deleted && !$dontcache) { + if (!$dontcache) { $posted_item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $current_post]); if (DBA::isResult($posted_item)) { if ($notify) { From 64847e7cc8ca8f157cae4994c71b93df28624d6f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 16:51:59 -0500 Subject: [PATCH 04/15] Fix types in doc blocks/prototypes --- src/Content/Widget/TagCloud.php | 2 +- src/Core/Console.php | 1 + src/Core/Renderer.php | 1 + src/Core/StorageManager.php | 3 ++ src/Model/Attach.php | 4 +++ src/Model/Mail.php | 4 +-- src/Model/Photo.php | 6 +++- src/Object/Image.php | 1 + src/Protocol/DFRN.php | 60 ++++++++++++++++----------------- src/Protocol/Diaspora.php | 12 +++---- src/Protocol/Email.php | 26 +++++++------- src/Protocol/OStatus.php | 16 ++++----- src/Util/Temporal.php | 8 ++--- src/Util/XML.php | 24 ++++++------- 14 files changed, 91 insertions(+), 77 deletions(-) diff --git a/src/Content/Widget/TagCloud.php b/src/Content/Widget/TagCloud.php index d775d010a..f2b94b111 100644 --- a/src/Content/Widget/TagCloud.php +++ b/src/Content/Widget/TagCloud.php @@ -113,7 +113,7 @@ class TagCloud * @param array $arr Array of tags/terms with tag/term name and total count of use. * @return array Alphabetical sorted array of used tags/terms of an user. */ - private static function tagCalc($arr) + private static function tagCalc(array $arr) { $tags = []; $min = 1e9; diff --git a/src/Core/Console.php b/src/Core/Console.php index 32e12fa1f..c60f36296 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -121,6 +121,7 @@ HELP; $className = $this->subConsoles[$command]; + /** @var Console $subconsole */ $subconsole = new $className($subargs); foreach ($this->options as $name => $value) { diff --git a/src/Core/Renderer.php b/src/Core/Renderer.php index 9d2a7e22e..67bc5e3ba 100644 --- a/src/Core/Renderer.php +++ b/src/Core/Renderer.php @@ -8,6 +8,7 @@ namespace Friendica\Core; use Exception; use Friendica\BaseObject; use Friendica\Render\FriendicaSmarty; +use Friendica\Render\ITemplateEngine; /** * @brief This class handles Renderer related functions. diff --git a/src/Core/StorageManager.php b/src/Core/StorageManager.php index 415ee522b..cfefa5f35 100644 --- a/src/Core/StorageManager.php +++ b/src/Core/StorageManager.php @@ -3,6 +3,7 @@ namespace Friendica\Core; use Friendica\Database\DBA; +use Friendica\Model\Storage\IStorage; /** @@ -138,6 +139,7 @@ class StorageManager while($r = DBA::fetch($rr)) { $id = $r['id']; $data = $r['data']; + /** @var IStorage $backendClass */ $backendClass = $r['backend-class']; $backendRef = $r['backend-ref']; if (!is_null($backendClass) && $backendClass !== '') { @@ -146,6 +148,7 @@ class StorageManager } Logger::log("save data to new backend " . $dest); + /** @var IStorage $dest */ $ref = $dest::put($data); Logger::log("saved data as " . $ref); diff --git a/src/Model/Attach.php b/src/Model/Attach.php index 3bd77ef9c..7efb56f95 100644 --- a/src/Model/Attach.php +++ b/src/Model/Attach.php @@ -11,6 +11,7 @@ use Friendica\Core\System; use Friendica\Core\StorageManager; use Friendica\Database\DBA; use Friendica\Database\DBStructure; +use Friendica\Model\Storage\IStorage; use Friendica\Object\Image; use Friendica\Util\Security; use Friendica\Util\DateTimeFormat; @@ -186,6 +187,7 @@ class Attach extends BaseObject $filesize = strlen($data); } + /** @var IStorage $backend_class */ $backend_class = StorageManager::getBackend(); $backend_ref = ''; if ($backend_class !== '') { @@ -265,6 +267,7 @@ class Attach extends BaseObject $items = self::select(['backend-class','backend-ref'], $conditions); foreach($items as $item) { + /** @var IStorage $backend_class */ $backend_class = (string)$item['backend-class']; if ($backend_class !== '') { $fields['backend-ref'] = $backend_class::put($img->asString(), $item['backend-ref']); @@ -297,6 +300,7 @@ class Attach extends BaseObject $items = self::select(['backend-class','backend-ref'], $conditions); foreach($items as $item) { + /** @var IStorage $backend_class */ $backend_class = (string)$item['backend-class']; if ($backend_class !== '') { $backend_class::delete($item['backend-ref']); diff --git a/src/Model/Mail.php b/src/Model/Mail.php index b9ed609fa..2d304e55f 100644 --- a/src/Model/Mail.php +++ b/src/Model/Mail.php @@ -157,7 +157,7 @@ class Mail } /** - * @param string $recipient recipient, default empty + * @param array $recipient recipient, default empty * @param string $body message body, default empty * @param string $subject message subject, default empty * @param string $replyto reply to, default empty @@ -165,7 +165,7 @@ class Mail * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function sendWall($recipient = '', $body = '', $subject = '', $replyto = '') + public static function sendWall(array $recipient = [], $body = '', $subject = '', $replyto = '') { if (!$recipient) { return -1; diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 1cee2f633..0778bf419 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -14,6 +14,7 @@ use Friendica\Core\System; use Friendica\Core\StorageManager; use Friendica\Database\DBA; use Friendica\Database\DBStructure; +use Friendica\Model\Storage\IStorage; use Friendica\Object\Image; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; @@ -268,6 +269,7 @@ class Photo extends BaseObject $data = ""; $backend_ref = ""; + /** @var IStorage $backend_class */ if (DBA::isResult($existing_photo)) { $backend_ref = (string)$existing_photo["backend-ref"]; $backend_class = (string)$existing_photo["backend-class"]; @@ -334,6 +336,7 @@ class Photo extends BaseObject $photos = self::select(["backend-class","backend-ref"], $conditions); foreach($photos as $photo) { + /** @var IStorage $backend_class */ $backend_class = (string)$photo["backend-class"]; if ($backend_class !== "") { $backend_class::delete($photo["backend-ref"]); @@ -363,6 +366,7 @@ class Photo extends BaseObject $photos = self::select(["backend-class","backend-ref"], $conditions); foreach($photos as $photo) { + /** @var IStorage $backend_class */ $backend_class = (string)$photo["backend-class"]; if ($backend_class !== "") { $fields["backend-ref"] = $backend_class::put($img->asString(), $photo["backend-ref"]); @@ -479,7 +483,7 @@ class Photo extends BaseObject } /** - * @param string $exifCoord coordinate + * @param array $exifCoord coordinate * @param string $hemi hemi * @return float */ diff --git a/src/Object/Image.php b/src/Object/Image.php index 1fe0a048b..9143c23c1 100644 --- a/src/Object/Image.php +++ b/src/Object/Image.php @@ -23,6 +23,7 @@ use ImagickPixel; */ class Image { + /** @var Imagick|resource */ private $image; /* diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index cf6080c57..e6524de96 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -529,17 +529,17 @@ class DFRN /** * @brief Adds the header elements for the DFRN protocol * - * @param object $doc XML document - * @param array $owner Owner record - * @param string $authorelement Element name for the author - * @param string $alternatelink link to profile or category - * @param bool $public Is it a header for public posts? + * @param DOMDocument $doc XML document + * @param array $owner Owner record + * @param string $authorelement Element name for the author + * @param string $alternatelink link to profile or category + * @param bool $public Is it a header for public posts? * * @return object XML root object * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @todo Find proper type-hints */ - private static function addHeader($doc, $owner, $authorelement, $alternatelink = "", $public = false) + private static function addHeader(DOMDocument $doc, $owner, $authorelement, $alternatelink = "", $public = false) { if ($alternatelink == "") { @@ -607,16 +607,16 @@ class DFRN /** * @brief Adds the author element in the header for the DFRN protocol * - * @param object $doc XML document - * @param array $owner Owner record - * @param string $authorelement Element name for the author - * @param boolean $public boolean + * @param DOMDocument $doc XML document + * @param array $owner Owner record + * @param string $authorelement Element name for the author + * @param boolean $public boolean * - * @return object XML author object + * @return \DOMElement XML author object * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @todo Find proper type-hints */ - private static function addAuthor($doc, $owner, $authorelement, $public) + private static function addAuthor(DOMDocument $doc, array $owner, $authorelement, $public) { // Is the profile hidden or shouldn't be published in the net? Then add the "hide" element $r = q( @@ -752,16 +752,16 @@ class DFRN /** * @brief Adds the author elements in the "entry" elements of the DFRN protocol * - * @param object $doc XML document + * @param DOMDocument $doc XML document * @param string $element Element name for the author * @param string $contact_url Link of the contact * @param array $item Item elements * - * @return object XML author object + * @return \DOMElement XML author object * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @todo Find proper type-hints */ - private static function addEntryAuthor($doc, $element, $contact_url, $item) + private static function addEntryAuthor(DOMDocument $doc, $element, $contact_url, $item) { $contact = Contact::getDetailsByURL($contact_url, $item["uid"]); @@ -795,15 +795,15 @@ class DFRN /** * @brief Adds the activity elements * - * @param object $doc XML document - * @param string $element Element name for the activity - * @param string $activity activity value + * @param DOMDocument $doc XML document + * @param string $element Element name for the activity + * @param string $activity activity value * - * @return object XML activity object + * @return \DOMElement XML activity object * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @todo Find proper type-hints */ - private static function createActivity($doc, $element, $activity) + private static function createActivity(DOMDocument $doc, $element, $activity) { if ($activity) { $entry = $doc->createElement($element); @@ -898,20 +898,20 @@ class DFRN /** * @brief Adds the "entry" elements for the DFRN protocol * - * @param object $doc XML document - * @param string $type "text" or "html" - * @param array $item Item element - * @param array $owner Owner record - * @param bool $comment Trigger the sending of the "comment" element - * @param int $cid Contact ID of the recipient - * @param bool $single If set, the entry is created as an XML document with a single "entry" element + * @param DOMDocument $doc XML document + * @param string $type "text" or "html" + * @param array $item Item element + * @param array $owner Owner record + * @param bool $comment Trigger the sending of the "comment" element + * @param int $cid Contact ID of the recipient + * @param bool $single If set, the entry is created as an XML document with a single "entry" element * - * @return object XML entry object + * @return \DOMElement XML entry object * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException * @todo Find proper type-hints */ - private static function entry($doc, $type, array $item, array $owner, $comment = false, $cid = 0, $single = false) + private static function entry(DOMDocument $doc, $type, array $item, array $owner, $comment = false, $cid = 0, $single = false) { $mentioned = []; @@ -2414,7 +2414,7 @@ class DFRN * @param object $xpath XPath object * @param object $entry entry elements * @param array $importer Record of the importer user mixed with contact of the content - * @param object $xml xml + * @param string $xml xml * @return void * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index e9d3be805..34bdf2e87 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -648,15 +648,15 @@ class Diaspora /** * @brief Dispatches the different message types to the different functions * - * @param array $importer Array of the importer user - * @param array $msg The post that will be dispatched - * @param object $fields SimpleXML object that contains the message + * @param array $importer Array of the importer user + * @param array $msg The post that will be dispatched + * @param SimpleXMLElement $fields SimpleXML object that contains the message * * @return int The message id of the generated message, "true" or "false" if there was an error * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function dispatch(array $importer, $msg, $fields = null) + public static function dispatch(array $importer, $msg, SimpleXMLElement $fields = null) { // The sender is the handle of the contact that sent the message. // This will often be different with relayed messages (for example "like" and "comment") @@ -758,7 +758,7 @@ class Diaspora * * @param array $msg Array with the XML, the sender handle and the sender signature * - * @return bool|array If the posting is valid then an array with an SimpleXML object is returned + * @return bool|SimpleXMLElement If the posting is valid then an array with an SimpleXML object is returned * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ @@ -1077,7 +1077,7 @@ class Diaspora * @param int $uid The user id * @param string $handle The handle in the format user@domain.tld * - * @return int Contact id + * @return array Contact data * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ diff --git a/src/Protocol/Email.php b/src/Protocol/Email.php index 05d59a152..a6090ce91 100644 --- a/src/Protocol/Email.php +++ b/src/Protocol/Email.php @@ -17,7 +17,7 @@ class Email * @param string $mailbox The mailbox name * @param string $username The username * @param string $password The password - * @return object + * @return resource * @throws \Exception */ public static function connect($mailbox, $username, $password) @@ -42,8 +42,8 @@ class Email } /** - * @param object $mbox mailbox - * @param string $email_addr email + * @param resource $mbox mailbox + * @param string $email_addr email * @return array * @throws \Exception */ @@ -92,8 +92,8 @@ class Email } /** - * @param object $mbox mailbox - * @param integer $uid user id + * @param resource $mbox mailbox + * @param integer $uid user id * @return mixed */ public static function messageMeta($mbox, $uid) @@ -103,9 +103,9 @@ class Email } /** - * @param object $mbox mailbox - * @param integer $uid user id - * @param string $reply reply + * @param resource $mbox mailbox + * @param integer $uid user id + * @param string $reply reply * @return array * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ @@ -166,11 +166,11 @@ class Email // At the moment - only return plain/text. // Later we'll repackage inline images as data url's and make the HTML safe /** - * @param object $mbox mailbox - * @param integer $uid user id - * @param object $p parts - * @param integer $partno part number - * @param string $subtype sub type + * @param resource $mbox mailbox + * @param integer $uid user id + * @param object $p parts + * @param integer $partno part number + * @param string $subtype sub type * @return string */ private static function messageGetPart($mbox, $uid, $p, $partno, $subtype) diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index b1cc4f402..b2d0004c0 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -1453,7 +1453,7 @@ class OStatus * @param array $owner Contact data of the poster * @param bool $show_profile Whether to show profile * - * @return object author element + * @return \DOMElement author element * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ private static function addAuthor(DOMDocument $doc, array $owner, $show_profile = true) @@ -1573,7 +1573,7 @@ class OStatus * @param bool $toplevel optional default false * @param bool $feed_mode Behave like a regular feed for users if true * - * @return object Entry element + * @return \DOMElement Entry element * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ @@ -1605,7 +1605,7 @@ class OStatus * @param DOMDocument $doc XML document * @param array $contact Array of the contact that is added * - * @return object Source element + * @return \DOMElement Source element * @throws \Exception */ private static function sourceEntry(DOMDocument $doc, array $contact) @@ -1748,7 +1748,7 @@ class OStatus * @param array $owner Contact data of the poster * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * - * @return object Entry element with "like" + * @return \DOMElement Entry element with "like" * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ @@ -1835,7 +1835,7 @@ class OStatus * @param array $owner Contact data of the poster * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * - * @return object Entry element + * @return \DOMElement Entry element * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ @@ -1900,7 +1900,7 @@ class OStatus * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * @param bool $feed_mode Behave like a regular feed for users if true * - * @return object Entry element + * @return \DOMElement Entry element * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ @@ -1976,7 +1976,7 @@ class OStatus * @brief Adds elements to the XML document * * @param DOMDocument $doc XML document - * @param object $entry Entry element where the content is added + * @param \DOMElement $entry Entry element where the content is added * @param array $item Data of the item that is to be posted * @param array $owner Contact data of the poster * @param string $title Title for the post @@ -1986,7 +1986,7 @@ class OStatus * @return void * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - private static function entryContent(DOMDocument $doc, $entry, array $item, array $owner, $title, $verb = "", $complete = true, $feed_mode = false) + private static function entryContent(DOMDocument $doc, \DOMElement $entry, array $item, array $owner, $title, $verb = "", $complete = true, $feed_mode = false) { if ($verb == "") { $verb = self::constructVerb($item); diff --git a/src/Util/Temporal.php b/src/Util/Temporal.php index 0e9baf249..ec71ab5e9 100644 --- a/src/Util/Temporal.php +++ b/src/Util/Temporal.php @@ -158,10 +158,10 @@ class Temporal /** * @brief Returns a date selector * - * @param string $min Unix timestamp of minimum date - * @param string $max Unix timestap of maximum date - * @param string $default Unix timestamp of default date - * @param string $id ID and name of datetimepicker (defaults to "datetimepicker") + * @param DateTime $min Minimum date + * @param DateTime $max Maximum date + * @param DateTime $default Default date + * @param string $id ID and name of datetimepicker (defaults to "datetimepicker") * * @return string Parsed HTML output. * @throws \Friendica\Network\HTTPException\InternalServerErrorException diff --git a/src/Util/XML.php b/src/Util/XML.php index d56b2311f..ba146ec7b 100644 --- a/src/Util/XML.php +++ b/src/Util/XML.php @@ -135,14 +135,14 @@ class XML /** * @brief Create an XML element * - * @param object $doc XML root - * @param string $element XML element name - * @param string $value XML value - * @param array $attributes array containing the attributes + * @param \DOMDocument $doc XML root + * @param string $element XML element name + * @param string $value XML value + * @param array $attributes array containing the attributes * - * @return object XML element object + * @return \DOMElement XML element object */ - public static function createElement($doc, $element, $value = "", $attributes = []) + public static function createElement(\DOMDocument $doc, $element, $value = "", $attributes = []) { $element = $doc->createElement($element, self::escape($value)); @@ -157,14 +157,14 @@ class XML /** * @brief Create an XML and append it to the parent object * - * @param object $doc XML root + * @param \DOMDocument $doc XML root * @param object $parent parent object * @param string $element XML element name * @param string $value XML value * @param array $attributes array containing the attributes * @return void */ - public static function addElement($doc, $parent, $element, $value = "", $attributes = []) + public static function addElement(\DOMDocument $doc, $parent, $element, $value = "", $attributes = []) { $element = self::createElement($doc, $element, $value, $attributes); $parent->appendChild($element); @@ -402,11 +402,11 @@ class XML /** * @brief Delete a node in a XML object * - * @param object $doc XML document + * @param \DOMDocument $doc XML document * @param string $node Node name * @return void */ - public static function deleteNode(&$doc, $node) + public static function deleteNode(\DOMDocument $doc, $node) { $xpath = new DOMXPath($doc); $list = $xpath->query("//".$node); @@ -431,7 +431,7 @@ class XML return $x; } - public static function getFirstNodeValue($xpath, $element, $context = null) + public static function getFirstNodeValue(DOMXPath $xpath, $element, $context = null) { $result = $xpath->evaluate($element, $context); if (!is_object($result)) { @@ -446,7 +446,7 @@ class XML return $first_item->nodeValue; } - public static function getFirstAttributes($xpath, $element, $context = null) + public static function getFirstAttributes(DOMXPath $xpath, $element, $context = null) { $result = $xpath->query($element, $context); if (!is_object($result)) { From f8c782380fa8acd90090e8f99a1e6eb228183fd5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 16:52:28 -0500 Subject: [PATCH 05/15] Remove unused code/use statements --- src/Content/Text/HTML.php | 3 --- src/Module/Contact.php | 1 - src/Module/Inbox.php | 14 -------------- src/Protocol/ActivityPub/Transmitter.php | 1 - 4 files changed, 19 deletions(-) diff --git a/src/Content/Text/HTML.php b/src/Content/Text/HTML.php index 7976b02e6..47463bdd0 100644 --- a/src/Content/Text/HTML.php +++ b/src/Content/Text/HTML.php @@ -11,10 +11,7 @@ use Friendica\Content\Widget\ContactBlock; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Config; -use Friendica\Core\PConfig; -use Friendica\Core\Protocol; use Friendica\Core\Renderer; -use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Util\Network; use Friendica\Util\Proxy as ProxyUtils; diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 59f2627e3..230ad4b57 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -8,7 +8,6 @@ use Friendica\Content\ContactSelector; use Friendica\Content\Nav; use Friendica\Content\Pager; use Friendica\Content\Text\BBCode; -use Friendica\Content\Text\HTML; use Friendica\Content\Widget; use Friendica\Core\ACL; use Friendica\Core\Hook; diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index 25312bdf3..e955f11a3 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -8,7 +8,6 @@ use Friendica\BaseModule; use Friendica\Protocol\ActivityPub; use Friendica\Core\System; use Friendica\Database\DBA; -use Friendica\Util\HTTPSignature; /** * ActivityPub Inbox @@ -25,19 +24,6 @@ class Inbox extends BaseModule System::httpExit(400); } -// Enable for test purposes -/* - if (HTTPSignature::getSigner($postdata, $_SERVER)) { - $filename = 'signed-activitypub'; - } else { - $filename = 'failed-activitypub'; - } - - $tempfile = tempnam(get_temppath(), $filename); - file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); - - Logger::log('Incoming message stored under ' . $tempfile); -*/ if (!empty($a->argv[1])) { $user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]); if (!DBA::isResult($user)) { diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index a44f5c8b5..05ce13879 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -23,7 +23,6 @@ use Friendica\Util\LDSignature; use Friendica\Model\Profile; use Friendica\Object\Image; use Friendica\Protocol\ActivityPub; -use Friendica\Protocol\Diaspora; use Friendica\Core\Cache; use Friendica\Util\Map; use Friendica\Util\Network; From 49c9b6f9ffc946c2eafe99a9930d30a3d72e6156 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 16:53:03 -0500 Subject: [PATCH 06/15] Fix possibly undefined variables --- src/Content/ForumManager.php | 2 ++ src/Content/Widget/TagCloud.php | 1 + src/Model/Event.php | 6 +++-- src/Model/Term.php | 1 + src/Module/Photo.php | 43 +++++++++++++++++---------------- 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/Content/ForumManager.php b/src/Content/ForumManager.php index d39ea3029..d0aefd306 100644 --- a/src/Content/ForumManager.php +++ b/src/Content/ForumManager.php @@ -105,6 +105,8 @@ class ForumManager if (DBA::isResult($contacts)) { $id = 0; + $entries = []; + foreach ($contacts as $contact) { $selected = (($cid == $contact['id']) ? ' forum-selected' : ''); diff --git a/src/Content/Widget/TagCloud.php b/src/Content/Widget/TagCloud.php index f2b94b111..62301729b 100644 --- a/src/Content/Widget/TagCloud.php +++ b/src/Content/Widget/TagCloud.php @@ -40,6 +40,7 @@ class TagCloud $contact = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]); $url = System::removedBaseUrl($contact['url']); + $tags = []; foreach ($r as $rr) { $tag['level'] = $rr[2]; $tag['url'] = $url . '?tag=' . urlencode($rr[0]); diff --git a/src/Model/Event.php b/src/Model/Event.php index cd08c314a..3ce86017b 100644 --- a/src/Model/Event.php +++ b/src/Model/Event.php @@ -644,15 +644,17 @@ class Event extends BaseObject */ private static function formatListForExport(array $events, $format) { + $o = ''; + if (!count($events)) { - return ''; + return $o; } switch ($format) { // Format the exported data as a CSV file. case "csv": header("Content-type: text/csv"); - $o = '"Subject", "Start Date", "Start Time", "Description", "End Date", "End Time", "Location"' . PHP_EOL; + $o .= '"Subject", "Start Date", "Start Time", "Description", "End Date", "End Time", "Location"' . PHP_EOL; foreach ($events as $event) { /// @todo The time / date entries don't include any information about the diff --git a/src/Model/Term.php b/src/Model/Term.php index 28c28fb1a..6a213d445 100644 --- a/src/Model/Term.php +++ b/src/Model/Term.php @@ -274,6 +274,7 @@ class Term 'network' => $item['author-network'], 'url' => $item['author-link']]; $tag['url'] = Contact::magicLinkByContact($author, $tag['url']); + $prefix = ''; if ($tag['type'] == TERM_HASHTAG) { if ($orig_tag != $tag['url']) { $item['body'] = str_replace($orig_tag, $tag['url'], $item['body']); diff --git a/src/Module/Photo.php b/src/Module/Photo.php index 994d0efa6..15ea261fb 100644 --- a/src/Module/Photo.php +++ b/src/Module/Photo.php @@ -46,28 +46,29 @@ class Photo extends BaseModule } $customsize = 0; + $photo = false; switch($a->argc) { - case 4: - $customsize = intval($a->argv[2]); - $uid = self::stripExtension($a->argv[3]); - $photo = self::getAvatar($uid, $a->argv[1]); - break; - case 3: - $uid = self::stripExtension($a->argv[2]); - $photo = self::getAvatar($uid, $a->argv[1]); - break; - case 2: - $photoid = self::stripExtension($a->argv[1]); - $scale = 0; - if (substr($photoid, -2, 1) == "-") { - $scale = intval(substr($photoid, -1, 1)); - $photoid = substr($photoid, 0, -2); - } - $photo = MPhoto::getPhoto($photoid, $scale); - if ($photo === false) { - $photo = MPhoto::createPhotoForSystemResource("images/nosign.jpg"); - } - break; + case 4: + $customsize = intval($a->argv[2]); + $uid = self::stripExtension($a->argv[3]); + $photo = self::getAvatar($uid, $a->argv[1]); + break; + case 3: + $uid = self::stripExtension($a->argv[2]); + $photo = self::getAvatar($uid, $a->argv[1]); + break; + case 2: + $photoid = self::stripExtension($a->argv[1]); + $scale = 0; + if (substr($photoid, -2, 1) == "-") { + $scale = intval(substr($photoid, -1, 1)); + $photoid = substr($photoid, 0, -2); + } + $photo = MPhoto::getPhoto($photoid, $scale); + if ($photo === false) { + $photo = MPhoto::createPhotoForSystemResource("images/nosign.jpg"); + } + break; } if ($photo === false) { From ddad9721c024523232b944ea24d37ae8c7c69967 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 16:55:35 -0500 Subject: [PATCH 07/15] Fix query return type in Widget\TagCloud --- src/Content/Widget/TagCloud.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Content/Widget/TagCloud.php b/src/Content/Widget/TagCloud.php index 62301729b..8413eccd1 100644 --- a/src/Content/Widget/TagCloud.php +++ b/src/Content/Widget/TagCloud.php @@ -89,7 +89,7 @@ class TagCloud } // Fetch tags - $r = DBA::p("SELECT `term`, COUNT(`term`) AS `total` FROM `term` + $tag_stmt = DBA::p("SELECT `term`, COUNT(`term`) AS `total` FROM `term` LEFT JOIN `item` ON `term`.`oid` = `item`.`id` WHERE `term`.`uid` = ? AND `term`.`type` = ? AND `term`.`otype` = ? @@ -100,10 +100,12 @@ class TagCloud $type, TERM_OBJ_POST ); - if (!DBA::isResult($r)) { + if (!DBA::isResult($tag_stmt)) { return []; } + $r = DBA::toArray($tag_stmt); + return self::tagCalc($r); } From df706484cdf2e7a066ff54ddeacc4175f27db964 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 16:56:15 -0500 Subject: [PATCH 08/15] User DOMDocument object call instead of static in Content\OEmbed --- src/Content/OEmbed.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 0093ba11a..7adff8908 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -86,7 +86,8 @@ class OEmbed $redirects = 0; $html_text = Network::fetchUrl($embedurl, false, $redirects, 15, 'text/*'); if ($html_text) { - $dom = @DOMDocument::loadHTML($html_text); + $dom = new DOMDocument(); + $dom->loadHTML($html_text); if ($dom) { $xpath = new DOMXPath($dom); $entries = $xpath->query("//link[@type='application/json+oembed']"); @@ -274,7 +275,8 @@ class OEmbed $html_text = mb_convert_encoding($text, 'HTML-ENTITIES', mb_detect_encoding($text)); // If it doesn't parse at all, just return the text. - $dom = @DOMDocument::loadHTML($html_text); + $dom = new DOMDocument(); + $dom->loadHTML($html_text); if (!$dom) { return $text; } From a6786ac81402ca58a9deef5719f1b31640fe1eb4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 16:56:35 -0500 Subject: [PATCH 09/15] Update array notation in Protocol\DFRN --- src/Protocol/DFRN.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index e6524de96..5e6c733e2 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -2513,7 +2513,7 @@ class DFRN $notice_info = $xpath->query("statusnet:notice_info", $entry); if ($notice_info && ($notice_info->length > 0)) { - foreach ($notice_info->item(0)->attributes as $attributes) { + foreach ($notice_info->item[0]->attributes as $attributes) { if ($attributes->name == "source") { $item["app"] = strip_tags($attributes->textContent); } @@ -2588,8 +2588,8 @@ class DFRN $item['conversation-uri'] = XML::getFirstNodeValue($xpath, 'ostatus:conversation/text()', $entry); $conv = $xpath->query('ostatus:conversation', $entry); - if (is_object($conv->item(0))) { - foreach ($conv->item(0)->attributes as $attributes) { + if (is_object($conv->item[0])) { + foreach ($conv->item[0]->attributes as $attributes) { if ($attributes->name == "ref") { $item['conversation-uri'] = $attributes->textContent; } @@ -2603,8 +2603,8 @@ class DFRN $item["parent-uri"] = $item["uri"]; $inreplyto = $xpath->query("thr:in-reply-to", $entry); - if (is_object($inreplyto->item(0))) { - foreach ($inreplyto->item(0)->attributes as $attributes) { + if (is_object($inreplyto->item[0])) { + foreach ($inreplyto->item[0]->attributes as $attributes) { if ($attributes->name == "ref") { $item["parent-uri"] = $attributes->textContent; } From c8979695891765a0d2f17b640ddf99cc3a9400e4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 16:56:48 -0500 Subject: [PATCH 10/15] Fix wrong variable name in Worker\Delivery --- src/Worker/Delivery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 18654d5ed..8e9b649c7 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -94,7 +94,7 @@ class Delivery extends BaseObject } elseif (!empty($target_item['uid'])) { $uid = $target_item['uid']; } else { - Logger::log('Only public users for item ' . $item_id, Logger::DEBUG); + Logger::log('Only public users for item ' . $target_id, Logger::DEBUG); return; } From bfc0729752320ddc078fd737ac1f162d7bed0bf7 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 22 Jan 2019 01:30:52 -0500 Subject: [PATCH 11/15] Use new log levels in admin log settings page --- mod/admin.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index 97d7a8bfd..cc2256b73 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -34,6 +34,7 @@ use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; use Friendica\Util\Strings; use Friendica\Util\Temporal; +use Psr\Log\LogLevel; /** * Sets the current theme for theme settings pages. @@ -2497,7 +2498,7 @@ function admin_page_logs_post(App $a) $logfile = (!empty($_POST['logfile']) ? Strings::escapeTags(trim($_POST['logfile'])) : ''); $debugging = !empty($_POST['debugging']); - $loglevel = (!empty($_POST['loglevel']) ? intval(trim($_POST['loglevel'])) : 0); + $loglevel = defaults($_POST, 'loglevel', LogLevel::ERROR); Config::set('system', 'logfile', $logfile); Config::set('system', 'debugging', $debugging); @@ -2529,12 +2530,11 @@ function admin_page_logs_post(App $a) function admin_page_logs(App $a) { $log_choices = [ - Logger::WARNING => 'Warning', - Logger::INFO => 'Info', - Logger::TRACE => 'Trace', - Logger::DEBUG => 'Debug', - Logger::DATA => 'Data', - Logger::ALL => 'All' + LogLevel::ERROR => 'Error', + LogLevel::WARNING => 'Warning', + LogLevel::NOTICE => 'Notice', + LogLevel::INFO => 'Info', + LogLevel::DEBUG => 'Debug', ]; if (ini_get('log_errors')) { From 7720b627998d4cd647bdb09debcf50a7123ac11d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 22 Jan 2019 01:32:55 -0500 Subject: [PATCH 12/15] Change workerqueue.parameter to mediumtext for lisibility --- config/dbstructure.config.php | 4 ++-- database.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/dbstructure.config.php b/config/dbstructure.config.php index a4728c15d..dcacce811 100644 --- a/config/dbstructure.config.php +++ b/config/dbstructure.config.php @@ -34,7 +34,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1299); + define('DB_UPDATE_VERSION', 1300); } return [ @@ -1365,7 +1365,7 @@ return [ "comment" => "Background tasks queue entries", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "Auto incremented worker task id"], - "parameter" => ["type" => "mediumblob", "comment" => "Task command"], + "parameter" => ["type" => "mediumtext", "comment" => "Task command"], "priority" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Task priority"], "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Creation date"], "pid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "Process id of the worker"], diff --git a/database.sql b/database.sql index 7d0db4fa6..2102a9398 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2019.03-dev (The Tazmans Flax-lily) --- DB_UPDATE_VERSION 1299 +-- DB_UPDATE_VERSION 1300 -- ------------------------------------------ @@ -1260,7 +1260,7 @@ CREATE TABLE IF NOT EXISTS `worker-ipc` ( -- CREATE TABLE IF NOT EXISTS `workerqueue` ( `id` int unsigned NOT NULL auto_increment COMMENT 'Auto incremented worker task id', - `parameter` mediumblob COMMENT 'Task command', + `parameter` mediumtext COMMENT 'Task command', `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Task priority', `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date', `pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process id of the worker', From 0d9209a74bffff8f9a025cf7fb03d5265293f0b9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 22 Jan 2019 12:15:42 -0500 Subject: [PATCH 13/15] Add AP Inbox logging back with config --- config/defaults.config.php | 5 +++++ src/Module/Inbox.php | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/config/defaults.config.php b/config/defaults.config.php index 90596a8fe..f16bd664c 100644 --- a/config/defaults.config.php +++ b/config/defaults.config.php @@ -421,4 +421,9 @@ return [ // Must be writable by the ejabberd process. if set then it will prevent the running of multiple processes. 'lockpath' => '', ], + 'debug' => [ + // ap_inbox_log (Boolean) + // Logs every call to /inbox as a JSON file in Friendica's temporary directory + 'ap_inbox_log' => false, + ] ]; diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index e955f11a3..5fc1b15f1 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -8,6 +8,7 @@ use Friendica\BaseModule; use Friendica\Protocol\ActivityPub; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\Util\HTTPSignature; /** * ActivityPub Inbox @@ -24,6 +25,17 @@ class Inbox extends BaseModule System::httpExit(400); } + if (Config::get('debug', 'ap_inbox_log')) { + if (HTTPSignature::getSigner($postdata, $_SERVER)) { + $filename = 'signed-activitypub'; + } else { + $filename = 'failed-activitypub'; + } + $tempfile = tempnam(get_temppath(), $filename); + file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); + Logger::log('Incoming message stored under ' . $tempfile); + } + if (!empty($a->argv[1])) { $user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]); if (!DBA::isResult($user)) { From 004818ca1b37dac574eed7d528f02219b7394c29 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 22 Jan 2019 12:19:15 -0500 Subject: [PATCH 14/15] Fix indentation in Module\Inbox --- src/Module/Inbox.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index 5fc1b15f1..8842c66bc 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -2,6 +2,7 @@ /** * @file src/Module/Inbox.php */ + namespace Friendica\Module; use Friendica\BaseModule; @@ -26,15 +27,15 @@ class Inbox extends BaseModule } if (Config::get('debug', 'ap_inbox_log')) { - if (HTTPSignature::getSigner($postdata, $_SERVER)) { - $filename = 'signed-activitypub'; - } else { - $filename = 'failed-activitypub'; - } - $tempfile = tempnam(get_temppath(), $filename); - file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); - Logger::log('Incoming message stored under ' . $tempfile); - } + if (HTTPSignature::getSigner($postdata, $_SERVER)) { + $filename = 'signed-activitypub'; + } else { + $filename = 'failed-activitypub'; + } + $tempfile = tempnam(get_temppath(), $filename); + file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); + Logger::log('Incoming message stored under ' . $tempfile); + } if (!empty($a->argv[1])) { $user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]); From 41136e53ccbb3ff3524481b9b129dcc2dff90d2d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 22 Jan 2019 22:02:35 -0500 Subject: [PATCH 15/15] [Travis] Update target PHP versions --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f9f9acff1..c66457325 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,10 @@ --- language: php -## Friendica supports PHP version >= 5.6.1 +## Friendica officially supports PHP version >= 7.1 php: - - 5.6 - - 7.0 - 7.1 - 7.2 + - 7.3 services: - mysql