From df7ec0cdf7fdaf75a5897016f69254a97066f429 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Tue, 27 Aug 2019 08:27:07 +0200 Subject: [PATCH 01/11] php notice fixings addons: - bufferapp (missing errorcode) - twitter (wrong field name 'nickname') core: - bbcode (incomplete attachementdata) - crypto (uninitialized key) --- src/Content/Text/BBCode.php | 11 ++++++++++- src/Util/Crypto.php | 10 ++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index c16041e22..bd4fc73c1 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -120,7 +120,16 @@ class BBCode extends BaseObject */ public static function getAttachmentData($body) { - $data = []; + // Initialize empty data array + $data = [ + 'type' => '', + 'text' => '', + 'after' => '', + 'image' => null, + 'url' => '', + 'title' => '', + 'description' => '', + ]; if (!preg_match("/(.*)\[attachment(.*?)\](.*?)\[\/attachment\](.*)/ism", $body, $match)) { return self::getOldAttachmentData($body); diff --git a/src/Util/Crypto.php b/src/Util/Crypto.php index 78f7c349a..a45fdf9fa 100644 --- a/src/Util/Crypto.php +++ b/src/Util/Crypto.php @@ -4,12 +4,12 @@ */ namespace Friendica\Util; +use ASN_BASE; +use ASNValue; use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\System; -use ASN_BASE; -use ASNValue; /** * @brief Crypto class @@ -209,8 +209,10 @@ class Crypto $r = ASN_BASE::parseASNString($x); - $m = Strings::base64UrlDecode($r[0]->asnData[1]->asnData[0]->asnData[0]->asnData); - $e = Strings::base64UrlDecode($r[0]->asnData[1]->asnData[0]->asnData[1]->asnData); + if (isset($r[0])) { + $m = Strings::base64UrlDecode($r[0]->asnData[1]->asnData[0]->asnData[0]->asnData); + $e = Strings::base64UrlDecode($r[0]->asnData[1]->asnData[0]->asnData[1]->asnData); + } } /** From 8688053a08dc9beffd0f3c315ec6fe910d374e39 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Wed, 28 Aug 2019 01:02:23 +0200 Subject: [PATCH 02/11] remove superfluous comment --- src/Content/Text/BBCode.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index bd4fc73c1..a60e17c90 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -120,7 +120,6 @@ class BBCode extends BaseObject */ public static function getAttachmentData($body) { - // Initialize empty data array $data = [ 'type' => '', 'text' => '', From 4733b1e5e0c3039277ed38eadd8a9621d76fa7de Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Wed, 28 Aug 2019 01:22:09 +0200 Subject: [PATCH 03/11] Fixing PHP Fatal Error for Model\Contact (usage of non available contact) --- src/Model/Contact.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 6f9ee4cdb..14f970e59 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1795,13 +1795,19 @@ class Contact extends BaseObject /** * @brief Helper function for "updateFromProbe". Updates personal and public contact * - * @param array $contact The personal contact entry - * @param array $fields The fields that are updated + * @param integer $id contact id + * @param integer $uid user id + * @param string $url The profile URL of the contact + * @param array $fields The fields that are updated + * * @throws \Exception */ private static function updateContact($id, $uid, $url, array $fields) { - DBA::update('contact', $fields, ['id' => $id]); + if (!DBA::update('contact', $fields, ['id' => $id])) { + Logger::info('Couldn\'t update contact.', ['id' => $id, 'fields' => $fields]); + return; + } // Search for duplicated contacts and get rid of them if (self::handleDuplicates(Strings::normaliseLink($url), $uid, $id) || ($uid != 0)) { @@ -1814,6 +1820,11 @@ class Contact extends BaseObject // Archive or unarchive the contact. We only need to do this for the public contact. // The archive/unarchive function will update the personal contacts by themselves. $contact = DBA::selectFirst('contact', [], ['id' => $id]); + if (!DBA::isResult($contact)) { + Logger::info('Couldn\'t select contact for archival.', ['id' => $id]); + return; + } + if (!empty($fields['success_update'])) { self::unmarkForArchival($contact); } elseif (!empty($fields['failure_update'])) { From 4b4dbd38d9db220e519a0722f0d852ecca19f2ab Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Wed, 28 Aug 2019 01:40:02 +0200 Subject: [PATCH 04/11] Fixing PHP Fatal Error for Database-Reconnects with PDO --- src/Database/Database.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index d3ec4d585..d13b52848 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -4,6 +4,7 @@ namespace Friendica\Database; use Friendica\Core\Config\Cache\ConfigCache; use Friendica\Core\System; +use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Util\DateTimeFormat; use Friendica\Util\Profiler; use mysqli; @@ -126,7 +127,7 @@ class Database $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $this->connected = true; } catch (PDOException $e) { - /// @TODO At least log exception, don't ignore it! + $this->connected = false; } } @@ -484,6 +485,10 @@ class Database // We are having an own error logging in the function "e" $called_from_e = ($called_from['function'] == 'e'); + if (!isset($this->connection)) { + throw new InternalServerErrorException('The Connection is empty, although connected is set true.'); + } + switch ($this->driver) { case 'pdo': // If there are no arguments we use "query" From 9cbf320c86baecc5aa3f72106dfef0e7df925ef9 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 28 Aug 2019 06:38:35 +0000 Subject: [PATCH 05/11] Issue 7563: Use icons instead of names on posts --- include/conversation.php | 1 + src/Content/ContactSelector.php | 107 ++++++++++++++++++++-- src/Object/Post.php | 1 + view/theme/frio/templates/search_item.tpl | 5 + view/theme/frio/templates/wall_thread.tpl | 5 +- 5 files changed, 108 insertions(+), 11 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 798a22401..66b6d2a11 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -677,6 +677,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ 'guid' => ($preview ? 'Q0' : $item['guid']), 'network' => $item['network'], 'network_name' => ContactSelector::networkToName($item['network'], $item['author-link']), + 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link']), 'linktitle' => L10n::t('View %s\'s profile @ %s', $profile_name, $item['author-link']), 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), diff --git a/src/Content/ContactSelector.php b/src/Content/ContactSelector.php index 2b86a6e75..2f6677aba 100644 --- a/src/Content/ContactSelector.php +++ b/src/Content/ContactSelector.php @@ -71,6 +71,39 @@ class ContactSelector return $o; } + /** + * @param string $profile Profile URL + * @return string Server URL + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + private static function getServerURLForProfile($profile) + { + $server_url = ''; + + // Fetch the server url from the contact table + $contact = DBA::selectFirst('contact', ['baseurl'], ['nurl' => Strings::normaliseLink($profile)]); + if (DBA::isResult($contact) && !empty($contact['baseurl'])) { + $server_url = Strings::normaliseLink($contact['baseurl']); + } + + if (empty($server_url)) { + // Fetch the server url from the gcontact table + $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($profile)]); + if (!empty($gcontact) && !empty($gcontact['server_url'])) { + $server_url = Strings::normaliseLink($gcontact['server_url']); + } + } + + if (empty($server_url)) { + // Create the server url out of the profile url + $parts = parse_url($profile); + unset($parts['path']); + $server_url = Strings::normaliseLink(Network::unparseURL($parts)); + } + + return $server_url; + } + /** * @param string $network network * @param string $profile optional, default empty @@ -106,16 +139,7 @@ class ContactSelector $networkname = str_replace($search, $replace, $network); if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) { - // Create the server url out of the profile url - $parts = parse_url($profile); - unset($parts['path']); - $server_url = [Strings::normaliseLink(Network::unparseURL($parts))]; - - // Fetch the server url - $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($profile)]); - if (!empty($gcontact) && !empty($gcontact['server_url'])) { - $server_url[] = Strings::normaliseLink($gcontact['server_url']); - } + $server_url = self::getServerURLForProfile($profile); // Now query the GServer for the platform name $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]); @@ -140,6 +164,69 @@ class ContactSelector return $networkname; } + /** + * @param string $network network + * @param string $profile optional, default empty + * @return string + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public static function networkToIcon($network, $profile = "") + { + $nets = [ + Protocol::DFRN => 'friendica', + Protocol::OSTATUS => 'gnu-social', + Protocol::FEED => 'rss', + Protocol::MAIL => '', + Protocol::DIASPORA => 'diaspora', + Protocol::ZOT => 'hubzilla', + Protocol::LINKEDIN => 'linkedin', + Protocol::XMPP => 'xmpp', + Protocol::MYSPACE => '', + Protocol::GPLUS => 'google-plus', + Protocol::PUMPIO => '', + Protocol::TWITTER => 'twitter', + Protocol::DIASPORA2 => 'diaspora', + Protocol::STATUSNET => 'gnu-social', + Protocol::ACTIVITYPUB => 'activitypub', + Protocol::PNUT => '', + ]; + + $search = array_keys($nets); + $replace = array_values($nets); + + $networkicon = str_replace($search, $replace, $network); + + if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) { + $server_url = self::getServerURLForProfile($profile); + + // Now query the GServer for the platform name + $gserver = DBA::selectFirst('gserver', ['platform'], ['nurl' => $server_url]); + + if (DBA::isResult($gserver) && !empty($gserver['platform'])) { + switch (strtolower($gserver['platform'])) { + case 'friendica': + $networkicon = 'friendica'; + break; + case 'hubzilla': + $networkicon = 'hubzilla'; + break; + case 'mastodon': + $networkicon = 'mastodon'; + break; + case 'pleroma': + $networkicon = 'pleroma'; + break; + } + } + } + + if (empty($networkicon)) { + $networkicon = 'file-text-o'; + } + + return $networkicon; + } + /** * @param string $current optional, default empty * @param string $suffix optionsl, default empty diff --git a/src/Object/Post.php b/src/Object/Post.php index 7f9f84b54..36be9c4e6 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -426,6 +426,7 @@ class Post extends BaseObject 'edited' => $edited, 'network' => $item["network"], 'network_name' => ContactSelector::networkToName($item['network'], $item['author-link']), + 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link']), 'received' => $item['received'], 'commented' => $item['commented'], 'created_date' => $item['created'], diff --git a/view/theme/frio/templates/search_item.tpl b/view/theme/frio/templates/search_item.tpl index 3b3f64a0d..3b56621ef 100644 --- a/view/theme/frio/templates/search_item.tpl +++ b/view/theme/frio/templates/search_item.tpl @@ -12,7 +12,12 @@ {{* Put additional actions in a top-right dropdown menu *}}