]> git.mxchange.org Git - friendica.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 10 May 2018 12:48:27 +0000 (14:48 +0200)
committerRoland Häder <roland@mxchange.org>
Mon, 14 May 2018 20:50:05 +0000 (22:50 +0200)
- avoided else() block which reduces code complexibility
- used more x()
- added curly braces
- added known type-hints

Signed-off-by: Roland Häder <roland@mxchange.org>
include/conversation.php
mod/admin.php
mod/subthread.php
mod/tagger.php
src/Model/Event.php
src/Model/Item.php
src/Protocol/DFRN.php
src/Protocol/OStatus.php

index de3b2aaf450cb8068fc5be8a73a52950181dc52e..e617eebf387210fdcbe7f50befb755dca5c79fec 100644 (file)
@@ -1120,7 +1120,7 @@ function builtin_activity_puller($item, &$conv_responses) {
 
                        $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
 
-                       if (!$item['thr-parent']) {
+                       if (!x($item, 'thr-parent')) {
                                $item['thr-parent'] = $item['parent-uri'];
                        }
 
index d195128a39d74b455b531522a50f7b3933960a31..fd7558a8d42ae06ffcaf01a4533b3e7f35dfbb1a 100644 (file)
@@ -1770,8 +1770,8 @@ function admin_page_users(App $a)
                $e['page-flags-raw'] = $e['page-flags'];
                $e['page-flags'] = $page_types[$e['page-flags']];
 
-               $e['account-type-raw'] = ($e['page_flags_raw']==0) ? $e['account-type'] : -1;
-               $e['account-type'] = ($e['page_flags_raw']==0) ? $account_types[$e['account-type']] : "";
+               $e['account-type-raw'] = ($e['page_flags_raw'] == 0) ? $e['account-type'] : -1;
+               $e['account-type'] = ($e['page_flags_raw'] == 0) ? $account_types[$e['account-type']] : "";
 
                $e['register_date'] = Temporal::getRelativeDate($e['register_date']);
                $e['login_date'] = Temporal::getRelativeDate($e['login_date']);
index c858f2d1fa3a3c847ea132b823605d33b31496ce..df44df6efa893331ba525d29de6ee2573a80ea95 100644 (file)
@@ -63,17 +63,19 @@ function subthread_content(App $a) {
                WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
                intval($owner_uid)
        );
-       if (DBM::is_result($r))
+
+       if (DBM::is_result($r)) {
                $owner = $r[0];
+       }
 
        if (! $owner) {
                logger('like: no owner');
                return;
        }
 
-       if (! $remote_owner)
+       if (! $remote_owner) {
                $remote_owner = $owner;
-
+       }
 
        $contact = null;
        // This represents the person posting
@@ -85,8 +87,10 @@ function subthread_content(App $a) {
                        intval($_SESSION['visitor_id']),
                        intval($owner_uid)
                );
-               if (DBM::is_result($r))
+
+               if (DBM::is_result($r)) {
                        $contact = $r[0];
+               }
        }
        if (! $contact) {
                return;
index 16195cc339d2f02f4c04eb719f7e7b04484e1e98..211e2ffa1fe6c94bb63eac0c84ebc7447ade683a 100644 (file)
@@ -159,11 +159,13 @@ EOT;
        }
 
        $term_objtype = ($item['resource-id'] ? TERM_OBJ_PHOTO : TERM_OBJ_POST);
-        $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
-                intval($item['id']),
-                dbesc($term)
-        );
-       if((! $blocktags) && $t[0]['tcount']==0 ) {
+
+       $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
+               intval($item['id']),
+               dbesc($term)
+       );
+
+       if ((!$blocktags) && $t[0]['tcount'] == 0 ) {
                q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
                   intval($item['id']),
                   $term_objtype,
@@ -176,26 +178,28 @@ EOT;
 
        // if the original post is on this site, update it.
 
-       $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1",
+       $r = q("SELECT `tag`,`id`,`uid` FROM `item` WHERE `origin`=1 AND `uri`='%s' LIMIT 1",
                dbesc($item['uri'])
        );
+
        if (DBM::is_result($r)) {
-               $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1",
+               $x = q("SELECT `blocktags` FROM `user` WHERE `uid`=%d LIMIT 1",
                        intval($r[0]['uid'])
                );
-               $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
+               $t = q("SELECT COUNT(`tid`) AS `tcount` FROM `term` WHERE `oid`=%d AND `term`='%s'",
                        intval($r[0]['id']),
                        dbesc($term)
                );
-               if(count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){
-                       q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
-                          intval($r[0]['id']),
-                          $term_objtype,
-                          TERM_HASHTAG,
-                          dbesc($term),
-                          dbesc(System::baseUrl() . '/search?tag=' . $term),
-                          intval($owner_uid)
-                       );
+
+               if (DBM::is_result($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
+                       q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
+                               intval($r[0]['id']),
+                               $term_objtype,
+                               TERM_HASHTAG,
+                               dbesc($term),
+                               dbesc(System::baseUrl() . '/search?tag=' . $term),
+                               intval($owner_uid)
+                       );
                }
        }
 
index e65e61ee58367a4e3e6005217a36a5a29af1b860..db9e2b93034127cc85e1036571a8a3caea20899a 100644 (file)
@@ -803,10 +803,10 @@ class Event extends BaseObject
        /**
         * @brief Format an item array with event data to HTML.
         *
-        * @param arr $item Array with item and event data.
+        * @param array $item Array with item and event data.
         * @return string HTML output.
         */
-       public static function getItemHTML($item) {
+       public static function getItemHTML(array $item) {
                $same_date = false;
                $finish    = false;
 
index 425f71822ae1ab6b717777a1568c03f02db1c35c..bf1193d7096996a6b0c92e52043c884edbfc431d 100644 (file)
@@ -1032,8 +1032,9 @@ class Item extends BaseObject
                }
 
                // Is this a shadow entry?
-               if ($item['uid'] == 0)
+               if ($item['uid'] == 0) {
                        return;
+               }
 
                // Is there a shadow parent?
                if (!dba::exists('item', ['uri' => $item['parent-uri'], 'uid' => 0])) {
@@ -1073,10 +1074,8 @@ class Item extends BaseObject
 
                // If this was a comment to a Diaspora post we don't get our comment back.
                // This means that we have to distribute the comment by ourselves.
-               if ($origin) {
-                       if (dba::exists('item', ['id' => $parent, 'network' => NETWORK_DIASPORA])) {
-                               self::distribute($public_shadow);
-                       }
+               if ($origin && dba::exists('item', ['id' => $parent, 'network' => NETWORK_DIASPORA])) {
+                       self::distribute($public_shadow);
                }
        }
 
@@ -1087,14 +1086,14 @@ class Item extends BaseObject
         */
        private static function addLanguageInPostopts(&$item)
        {
+               $postopts = "";
+
                if (!empty($item['postopts'])) {
                        if (strstr($item['postopts'], 'lang=')) {
                                // do not override
                                return;
                        }
                        $postopts = $item['postopts'];
-               } else {
-                       $postopts = "";
                }
 
                $naked_body = Text\BBCode::toPlaintext($item['body'], false);
index 5b748e10dca5b75b6b51e47741113bc4914793cf..d738adecb8b2d95f245f8371abbcdaf2e7aa96a8 100644 (file)
@@ -892,7 +892,7 @@ class DFRN
         * @return object XML entry object
         * @todo Find proper type-hints
         */
-       private static function entry($doc, $type, $item, $owner, $comment = false, $cid = 0, $single = false)
+       private static function entry($doc, $type, array $item, array $owner, $comment = false, $cid = 0, $single = false)
        {
                $mentioned = [];
 
index 8b6939214496aa61ff92b5598cc120ed397f4e0c..8dac2b456ce858c9c427319bb1e7d7f4967c59b7 100644 (file)
@@ -1948,7 +1948,7 @@ class OStatus
         * @param bool   $complete default true
         * @return void
         */
-       private static function entryFooter($doc, $entry, $item, $owner, $complete = true)
+       private static function entryFooter($doc, $entry, array $item, array $owner, $complete = true)
        {
                $mentioned = [];
 
@@ -1988,6 +1988,7 @@ class OStatus
 
                        if (isset($parent_item)) {
                                $r = dba::fetch_first("SELECT `conversation-uri`, `conversation-href` FROM `conversation` WHERE `item-uri` = ?", $parent_item);
+
                                if (DBM::is_result($r)) {
                                        if ($r['conversation-uri'] != '') {
                                                $conversation_uri = $r['conversation-uri'];
@@ -2048,9 +2049,11 @@ class OStatus
                }
 
                if ($owner['account-type'] == ACCOUNT_TYPE_COMMUNITY) {
-                       XML::addElement($doc, $entry, "link", "", ["rel" => "mentioned",
-                                                                       "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/group",
-                                                                       "href" => $owner['url']]);
+                       XML::addElement($doc, $entry, "link", "", [
+                               "rel" => "mentioned",
+                               "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/group",
+                               "href" => $owner['url']
+                       ]);
                }
 
                if (!$item["private"]) {