]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/OStatus.php
Merge pull request #4194 from MrPetovan/task/fix-scrutinizer-issues
[friendica.git] / src / Protocol / OStatus.php
index 1b02b313f923cdcd841e220acb99b31177f92fc9..242af46045ec983525035e32f50727f41c2897fe 100644 (file)
@@ -26,7 +26,6 @@ require_once 'include/bbcode.php';
 require_once 'include/items.php';
 require_once 'mod/share.php';
 require_once 'include/enotify.php';
-require_once 'include/follow.php';
 require_once 'include/api.php';
 require_once 'mod/proxy.php';
 
@@ -71,9 +70,9 @@ class OStatus
                $found = false;
 
                if ($aliaslink != '') {
-                       $condition = array("`uid` = ? AND `alias` = ? AND `network` != ?",
-                                       $importer["uid"], $aliaslink, NETWORK_STATUSNET);
-                       $r = dba::select('contact', array(), $condition, array('limit' => 1));
+                       $condition = ["`uid` = ? AND `alias` = ? AND `network` != ?",
+                                       $importer["uid"], $aliaslink, NETWORK_STATUSNET];
+                       $r = dba::selectFirst('contact', [], $condition);
 
                        if (DBM::is_result($r)) {
                                $found = true;
@@ -90,9 +89,9 @@ class OStatus
                                $aliaslink = $author["author-link"];
                        }
 
-                       $condition = array("`uid` = ? AND `nurl` IN (?, ?) AND `network` != ?", $importer["uid"],
-                                       normalise_link($author["author-link"]), normalise_link($aliaslink), NETWORK_STATUSNET);
-                       $r = dba::select('contact', array(), $condition, array('limit' => 1));
+                       $condition = ["`uid` = ? AND `nurl` IN (?, ?) AND `network` != ?", $importer["uid"],
+                                       normalise_link($author["author-link"]), normalise_link($aliaslink), NETWORK_STATUSNET];
+                       $r = dba::selectFirst('contact', [], $condition);
 
                        if (DBM::is_result($r)) {
                                $found = true;
@@ -105,9 +104,9 @@ class OStatus
                }
 
                if (!$found && ($addr != "")) {
-                       $condition = array("`uid` = ? AND `addr` = ? AND `network` != ?",
-                                       $importer["uid"], $addr, NETWORK_STATUSNET);
-                       $r = dba::select('contact', array(), $condition, array('limit' => 1));
+                       $condition = ["`uid` = ? AND `addr` = ? AND `network` != ?",
+                                       $importer["uid"], $addr, NETWORK_STATUSNET];
+                       $r = dba::selectFirst('contact', [], $condition);
 
                        if (DBM::is_result($r)) {
                                $found = true;
@@ -208,8 +207,8 @@ class OStatus
                        $cid = Contact::getIdForURL($aliaslink, 0);
 
                        if ($cid) {
-                               $fields = array('url', 'nurl', 'name', 'nick', 'alias', 'about', 'location');
-                               $old_contact = dba::select('contact', $fields, array('id' => $cid), array('limit' => 1));
+                               $fields = ['url', 'nurl', 'name', 'nick', 'alias', 'about', 'location'];
+                               $old_contact = dba::selectFirst('contact', $fields, ['id' => $cid]);
 
                                // Update it with the current values
                                $fields = array('url' => $author["author-link"], 'name' => $contact["name"],
@@ -542,8 +541,8 @@ class OStatus
         */
        private static function deleteNotice($item)
        {
-               $condition = array('uid' => $item['uid'], 'author-link' => $item['author-link'], 'uri' => $item['uri']);
-               $deleted = dba::select('item', array('id', 'parent-uri'), $condition, array('limit' => 1));
+               $condition = ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'uri' => $item['uri']];
+               $deleted = dba::selectFirst('item', ['id', 'parent-uri'], $condition);
                if (!DBM::is_result($deleted)) {
                        logger('Item from '.$item['author-link'].' with uri '.$item['uri'].' for user '.$item['uid']." wasn't found. We don't delete it. ");
                        return;
@@ -896,8 +895,8 @@ class OStatus
         */
        private static function fetchRelated($related, $related_uri, $importer)
        {
-               $condition = array('`item-uri` = ? AND `protocol` IN (?, ?)', $related_uri, PROTOCOL_DFRN, PROTOCOL_OSTATUS_SALMON);
-               $conversation = dba::select('conversation', array('source', 'protocol'), $condition,  array('limit' => 1));
+               $condition = ['`item-uri` = ? AND `protocol` IN (?, ?)', $related_uri, PROTOCOL_DFRN, PROTOCOL_OSTATUS_SALMON];
+               $conversation = dba::selectFirst('conversation', ['source', 'protocol'], $condition);
                if (DBM::is_result($conversation)) {
                        $stored = true;
                        $xml = $conversation['source'];
@@ -976,8 +975,8 @@ class OStatus
 
                // Finally we take the data that we fetched from "ostatus:conversation"
                if ($xml == '') {
-                       $condition = array('item-uri' => $related_uri, 'protocol' => PROTOCOL_SPLITTED_CONV);
-                       $conversation = dba::select('conversation', array('source'), $condition,  array('limit' => 1));
+                       $condition = ['item-uri' => $related_uri, 'protocol' => PROTOCOL_SPLITTED_CONV];
+                       $conversation = dba::selectFirst('conversation', ['source'], $condition);
                        if (DBM::is_result($conversation)) {
                                $stored = true;
                                logger('Got cached XML from conversation for URI '.$related_uri, LOGGER_DEBUG);
@@ -1235,12 +1234,13 @@ class OStatus
        /**
         * @brief Adds the header elements to the XML document
         *
-        * @param object $doc   XML document
-        * @param array  $owner Contact data of the poster
+        * @param object $doc    XML document
+        * @param array  $owner  Contact data of the poster
+        * @param string $filter The related feed filter (activity, posts or comments)
         *
         * @return object header root element
         */
-       private static function addHeader($doc, $owner, $type)
+       private static function addHeader($doc, $owner, $filter)
        {
                $a = get_app();
 
@@ -1256,7 +1256,7 @@ class OStatus
                $root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
                $root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
 
-               switch ($type) {
+               switch ($filter) {
                        case 'activity': $title = t('%s\'s timeline', $owner['name']); break;
                        case 'posts'   : $title = t('%s\'s posts'   , $owner['name']); break;
                        case 'comments': $title = t('%s\'s comments', $owner['name']); break;
@@ -2088,22 +2088,22 @@ class OStatus
         * @param string  $owner_nick  Nickname of the feed owner
         * @param string  $last_update Date of the last update
         * @param integer $max_items   Number of maximum items to fetch
-        * @param string  $type        Type of feed (posts, comments or activity)
-        * @param boolean $nocache     Wether to bypass the cache
+        * @param string  $filter      Feed items filter (activity, posts or comments)
+        * @param boolean $nocache     Wether to bypass caching
         *
         * @return string XML feed
         */
-       public static function feed($owner_nick, &$last_update, $max_items = 300, $type = 'activity', $nocache = false)
+       public static function feed($owner_nick, &$last_update, $max_items = 300, $filter = 'activity', $nocache = false)
        {
                $stamp = microtime(true);
 
-               $cachekey = "ostatus:feed:" . $owner_nick . ":" . $type . ":" . $last_update;
+               $cachekey = "ostatus:feed:" . $owner_nick . ":" . $filter . ":" . $last_update;
 
                $previous_created = $last_update;
 
                $result = Cache::get($cachekey);
                if (!$nocache && !is_null($result)) {
-                       logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $type . ' - ' . $previous_created . ' (cached)', LOGGER_DEBUG);
+                       logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created . ' (cached)', LOGGER_DEBUG);
                        $last_update = $result['last_update'];
                        return $result['feed'];
                }
@@ -2126,11 +2126,11 @@ class OStatus
                $authorid = Contact::getIdForURL($owner["url"], 0);
 
                $sql_extra = '';
-               if ($type === 'posts') {
+               if ($filter === 'posts') {
                        $sql_extra .= ' AND `item`.`id` = `item`.`parent` ';
                }
 
-               if ($type === 'comments') {
+               if ($filter === 'comments') {
                        $sql_extra .= sprintf(" AND `item`.`object-type` = '%s' ", dbesc(ACTIVITY_OBJ_COMMENT));
                }
 
@@ -2158,7 +2158,7 @@ class OStatus
                $doc = new DOMDocument('1.0', 'utf-8');
                $doc->formatOutput = true;
 
-               $root = self::addHeader($doc, $owner, $type);
+               $root = self::addHeader($doc, $owner, $filter);
 
                foreach ($items as $item) {
                        if (Config::get('system', 'ostatus_debug')) {
@@ -2177,7 +2177,7 @@ class OStatus
                $msg = array('feed' => $feeddata, 'last_update' => $last_update);
                Cache::set($cachekey, $msg, CACHE_QUARTER_HOUR);
 
-               logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $type . ' - ' . $previous_created, LOGGER_DEBUG);
+               logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created, LOGGER_DEBUG);
 
                return $feeddata;
        }