]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
empty is better than isset
[friendica.git] / src / Protocol / Diaspora.php
index beaf42c6c11db13e30a42e06b682b23e2185dfa0..77ad0170442359a5cac8a6bf3dc27898f194d7e7 100644 (file)
@@ -10,6 +10,7 @@
 
 namespace Friendica\Protocol;
 
+use Friendica\Content\Feature;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\Markdown;
 use Friendica\Core\Cache;
@@ -648,15 +649,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 +759,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 +1078,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
         */
@@ -3666,6 +3667,20 @@ class Diaspora
                return $msg;
        }
 
+       private static function prependParentAuthorMention($body, $profile_url)
+       {
+               $profile = Contact::getDetailsByURL($profile_url);
+               if (!empty($profile['addr'])
+                       && $profile['contact-type'] != Contact::TYPE_COMMUNITY
+                       && !strstr($body, $profile['addr'])
+                       && !strstr($body, $profile_url)
+               ) {
+                       $body = '@[url=' . $profile_url . ']' . $profile['nick'] . '[/url] ' . $body;
+               }
+
+               return $body;
+       }
+
        /**
         * @brief Sends a post
         *
@@ -3773,12 +3788,18 @@ class Diaspora
                        return $result;
                }
 
-               $parent = Item::selectFirst(['guid'], ['id' => $item["parent"], 'parent' => $item["parent"]]);
+               $parent = Item::selectFirst(['guid', 'author-link'], ['id' => $item["parent"], 'parent' => $item["parent"]]);
                if (!DBA::isResult($parent)) {
                        return false;
                }
 
-               $text = html_entity_decode(BBCode::toMarkdown($item["body"]));
+               $body = $item["body"];
+
+               if (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) {
+                       $body = self::prependParentAuthorMention($body, $parent['author-link']);
+               }
+
+               $text = html_entity_decode(BBCode::toMarkdown($body));
                $created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
 
                $comment = ["author" => self::myHandle($owner),
@@ -4133,7 +4154,7 @@ class Diaspora
                        if ($profile['pub_keywords']) {
                                $kw = str_replace(',', ' ', $profile['pub_keywords']);
                                $kw = str_replace('  ', ' ', $kw);
-                               $arr = explode(' ', $profile['pub_keywords']);
+                               $arr = explode(' ', $kw);
                                if (count($arr)) {
                                        for ($x = 0; $x < 5; $x ++) {
                                                if (!empty($arr[$x])) {