]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #7578 from annando/archive
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 28 Aug 2019 15:12:00 +0000 (11:12 -0400)
committerGitHub <noreply@github.com>
Wed, 28 Aug 2019 15:12:00 +0000 (11:12 -0400)
Don't transmit content to already archived contacts

include/conversation.php
src/Content/ContactSelector.php
src/Content/Text/BBCode.php
src/Database/Database.php
src/Model/Contact.php
src/Object/Post.php
src/Util/Crypto.php
view/theme/frio/templates/search_item.tpl
view/theme/frio/templates/wall_thread.tpl

index 798a224016c911bf72d8284ad5a053ce8a6ee9db..66b6d2a11cc48cb6de5862c534f34406b706c8ec 100644 (file)
@@ -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),
index 2b86a6e75df663291b5f6bbd1fdaa7fac437928f..478cfdbbe8da6c5e623d40263cde2b6b2c0bf64f 100644 (file)
@@ -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'], ['uid' => 0, '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,58 @@ 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', // There is no generic OStatus icon
+                       Protocol::FEED      =>   'rss',
+                       Protocol::MAIL      =>   'file-text-o', /// @todo
+                       Protocol::DIASPORA  =>   'diaspora',
+                       Protocol::ZOT       =>   'hubzilla',
+                       Protocol::LINKEDIN  =>   'linkedin',
+                       Protocol::XMPP      =>   'xmpp',
+                       Protocol::MYSPACE   =>   'file-text-o', /// @todo
+                       Protocol::GPLUS     =>   'google-plus',
+                       Protocol::PUMPIO    =>   'file-text-o', /// @todo
+                       Protocol::TWITTER   =>   'twitter',
+                       Protocol::DIASPORA2 =>   'diaspora',
+                       Protocol::STATUSNET =>   'gnu-social',
+                       Protocol::ACTIVITYPUB => 'activitypub',
+                       Protocol::PNUT      =>   'file-text-o', /// @todo
+               ];
+
+               $platform_icons = ['diaspora' => 'diaspora', 'friendica' => 'friendica', 'friendika' => 'friendica',
+                       'GNU Social' => 'gnu-social', 'gnusocial' => 'gnu-social', 'hubzilla' => 'hubzilla',
+                       'mastodon' => 'mastodon', 'peertube' => 'peertube', 'pixelfed' => 'pixelfed',
+                       'pleroma' => 'pleroma', 'red' => 'hubzilla', 'redmatrix' => 'hubzilla',
+                       'socialhome' => 'social-home', 'wordpress' => 'wordpress'];
+
+               $search  = array_keys($nets);
+               $replace = array_values($nets);
+
+               $network_icon = 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'])) {
+                               $network_icon = $platform_icons[strtolower($gserver['platform'])] ?? $network_icon;
+                       }
+               }
+
+               return $network_icon;
+       }
+
        /**
         * @param string $current optional, default empty
         * @param string $suffix  optionsl, default empty
index c16041e2207df7fe929a8cb040afd91e067f61c0..a60e17c90eeb787e76349349546d00e38f44210d 100644 (file)
@@ -120,7 +120,15 @@ class BBCode extends BaseObject
         */
        public static function getAttachmentData($body)
        {
-               $data = [];
+               $data = [
+                       'type'        => '',
+                       'text'        => '',
+                       'after'       => '',
+                       'image'       => null,
+                       'url'         => '',
+                       'title'       => '',
+                       'description' => '',
+               ];
 
                if (!preg_match("/(.*)\[attachment(.*?)\](.*?)\[\/attachment\](.*)/ism", $body, $match)) {
                        return self::getOldAttachmentData($body);
index d3ec4d585a1f71a3606d47c2af9036723be74fad..d13b52848d311ff0c49e305bd482c7937e3f0ebb 100644 (file)
@@ -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"
index 6887b9d0a40c949641c5f33315ee989697f0c181..fdcef6f36a40aceaeddc39520d3177f3eb6eedbd 100644 (file)
@@ -1838,13 +1838,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)) {
@@ -1857,6 +1863,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'])) {
index 7f9f84b546c678c274db0a76f1ffa0620b271af8..36be9c4e6b8577cb90b5838cd62bcfa01f0aa11d 100644 (file)
@@ -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'],
index 78f7c349a71eb855e2f05ebb3d8c528b4adcc83e..a45fdf9faac6732768577c9d86123acaa6ac4294 100644 (file)
@@ -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);
+               }
        }
 
        /**
index 3b3f64a0d4f6b95d33f9f3f91a72719a498e8c94..7f3c0936d1e2fc9baa786ef8b967bce1ce364b1c 100644 (file)
                        {{* Put additional actions in a top-right dropdown menu *}}
 
                        <ul class="nav nav-pills preferences">
+                               {{if $item.network_icon != ""}}
+                               <li><span class="wall-item-network"><i class="fa fa-{{$item.network_icon}}" title="{{$item.network_name}}" aria-hidden="true"></i></span></li>
+                               {{else}}
                                <li><span class="wall-item-network" title="{{$item.app}}">{{$item.network_name}}</span></li>
+                               {{/if}}
 
                                {{if $item.plink || $item.star || $item.drop.dropping || $item.edpost || $item.subthread}}
                                <li class="dropdown">
index 21923737c03d2523a79010ec32b667296a33a399..5a10a025521874e5bc66e75e3b3fbac6d3a91fc4 100644 (file)
@@ -84,8 +84,11 @@ as the value of $top_child_total (this is done at the end of this file)
                {{* Put addional actions in a top-right dropdown menu *}}
 
                <ul class="nav nav-pills preferences">
+                       {{if $item.network_icon != ""}}
+                        <li><span class="wall-item-network"><i class="fa fa-{{$item.network_icon}}" title="{{$item.network_name}}" aria-hidden="true"></i></span></li>
+                       {{else}}
                        <li><span class="wall-item-network" title="{{$item.app}}">{{$item.network_name}}</span></li>
-
+                       {{/if}}
                        {{if $item.plink || $item.drop.dropping || $item.edpost || $item.ignore || $item.tagger || $item.star || $item.filer || $item.subthread}}
                        <li class="dropdown">
                                <button type="button" class="btn-link dropdown-toggle" data-toggle="dropdown" id="dropdownMenuTools-{{$item.id}}" aria-haspopup="true" aria-expanded="false"><i class="fa fa-angle-down" aria-hidden="true"></i></button>