]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #4166 from MrPetovan/task/fix-scrutinizer-issues
authorMichael Vogel <icarus@dabo.de>
Thu, 4 Jan 2018 19:59:07 +0000 (20:59 +0100)
committerGitHub <noreply@github.com>
Thu, 4 Jan 2018 19:59:07 +0000 (20:59 +0100)
[Scrutinizer] Fix unused code issues in boot and include

1  2 
doc/htconfig.md
include/items.php
include/network.php
include/plaintext.php

diff --combined doc/htconfig.md
index c2c2f536bcf02de5b83bef32c49f4a5beac4935f,a39bf0aadecdc091311e941e05de14753dc08e89..f601bdca9ed40ae6997541672b21fb9804d6d199
@@@ -25,7 -25,6 +25,6 @@@ Example: To set the directory value ple
  
  * **allowed_link_protocols** (Array) - Allowed protocols in links URLs, add at your own risk. http is always allowed.
  * **always_show_preview** (Boolean) - Only show small preview picures. Default value is false.
- * **birthday_input_format** - Default value is "ymd".
  * **block_local_dir** (Boolean) - Blocks the access to the directory of the local users.
  * **auth_cookie_lifetime** (Integer) - Number of days that should pass without any activity before a user who chose "Remember me" when logging in is considered logged out. Defaults to 7.
  * **curl_range_bytes** - Maximum number of bytes that should be fetched. Default is 0, which mean "no limit".
@@@ -43,7 -42,6 +42,6 @@@
  * **disable_email_validation** (Boolean) - Disables the check if a mail address is in a valid format and can be resolved via DNS.
  * **disable_url_validation** (Boolean) - Disables the DNS lookup of an URL.
  * **dlogfile - location of the developer log file
- * **event_input_format** - Default value is "ymd".
  * **frontend_worker_timeout** - Value in minutes after we think that a frontend task was killed by the webserver. Default value is 10.
  * **hsts** (Boolean) - Enables the sending of HTTP Strict Transport Security headers
  * **ignore_cache** (Boolean) - For development only. Disables the item cache.
@@@ -65,6 -63,7 +63,6 @@@
  * **memcache_port** - Portnumber of the memcache daemon. Default is 11211.
  * **no_count** (Boolean) - Don't do count calculations (currently only when showing albums)
  * **no_oembed** (Boolean) - Don't use OEmbed to fetch more information about a link.
 -* **no_oembed_rich_content** (Boolean) - Don't show the rich content (e.g. embedded PDF).
  * **no_smilies** (Boolean) - Don't show smilies.
  * **no_view_full_size** (Boolean) - Don't add the link "View full size" under a resized image.
  * **optimize_items** (Boolean) - Triggers an SQL command to optimize the item table before expiring items.
diff --combined include/items.php
index 4bb00cdddd34f0b0927821576215629e8a73537f,1ac8e96965b02fa35e1b164e339cfc32ea4c420e..9e7a4621af9ba966b9ed4fa3757af8bc6532b95f
@@@ -3,6 -3,7 +3,6 @@@
   * @file include/items.php
   */
  use Friendica\App;
 -use Friendica\ParseUrl;
  use Friendica\Content\Feature;
  use Friendica\Core\Config;
  use Friendica\Core\PConfig;
@@@ -17,7 -18,6 +17,7 @@@ use Friendica\Object\Image
  use Friendica\Protocol\DFRN;
  use Friendica\Protocol\OStatus;
  use Friendica\Protocol\Feed;
 +use Friendica\Util\ParseUrl;
  
  require_once 'include/bbcode.php';
  require_once 'include/tags.php';
@@@ -37,13 -37,20 +37,20 @@@ function construct_verb($item) 
  
  /* limit_body_size()
   *
-  *            The purpose of this function is to apply system message length limits to
-  *            imported messages without including any embedded photos in the length
+  *
+  *
   */
- function limit_body_size($body) {
- //    logger('limit_body_size: start', LOGGER_DEBUG);
  
+ /**
+  * The purpose of this function is to apply system message length limits to
+  * imported messages without including any embedded photos in the length
+  *
+  * @brief Truncates imported message body string length to max_import_size
+  * @param string $body
+  * @return string
+  */
+ function limit_body_size($body)
+ {
        $maxlen = get_max_import_size();
  
        // If the length of the body, including the embedded images, is smaller
@@@ -55,7 -62,6 +62,6 @@@
                $orig_body = $body;
                $new_body = '';
                $textlen = 0;
-               $max_found = false;
  
                $img_start = strpos($orig_body, '[img');
                $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
                        if ($textlen < $maxlen) {
                                logger('limit_body_size: the limit happens after the end of the last image', LOGGER_DEBUG);
                                $new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
-                               $textlen = $maxlen;
                        }
                } else {
                        logger('limit_body_size: the text size with embedded images extracted did not violate the limit', LOGGER_DEBUG);
                        $new_body = $new_body . $orig_body;
-                       $textlen += strlen($orig_body);
                }
  
                return $new_body;
@@@ -169,12 -173,6 +173,6 @@@ function add_page_info_data($data) 
                return "";
        }
  
-       if (sizeof($data["images"]) > 0) {
-               $preview = $data["images"][0];
-       } else {
-               $preview = "";
-       }
        // Escape some bad characters
        $data["url"] = str_replace(array("[", "]"), array("&#91;", "&#93;"), htmlentities($data["url"], ENT_QUOTES, 'UTF-8', false));
        $data["title"] = str_replace(array("[", "]"), array("&#91;", "&#93;"), htmlentities($data["title"], ENT_QUOTES, 'UTF-8', false));
@@@ -854,7 -852,6 +852,6 @@@ function item_store($arr, $force_paren
                        logger("item_store: Checking if parent ".$parent_id." has to be tagged as mention for user ".$arr['uid'], LOGGER_DEBUG);
                        $u = q("SELECT `nickname` FROM `user` WHERE `uid` = %d", intval($arr['uid']));
                        if (DBM::is_result($u)) {
-                               $a = get_app();
                                $self = normalise_link(System::baseUrl() . '/profile/' . $u[0]['nickname']);
                                logger("item_store: 'myself' is ".$self." for parent ".$parent_id." checking against ".$arr['author-link']." and ".$arr['owner-link'], LOGGER_DEBUG);
                                if ((normalise_link($arr['author-link']) == $self) || (normalise_link($arr['owner-link']) == $self)) {
        }
  
        // Set parent id
-       $r = dba::update('item', array('parent' => $parent_id), array('id' => $current_post));
+       dba::update('item', array('parent' => $parent_id), array('id' => $current_post));
  
        $arr['id'] = $current_post;
        $arr['parent'] = $parent_id;
         * It is done after the transaction to avoid dead locks.
         */
        if ($arr['last-child']) {
-               $r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d AND `id` != %d",
+               q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d AND `id` != %d",
                        dbesc($arr['uri']),
                        intval($arr['uid']),
                        intval($current_post)
@@@ -1205,8 -1202,6 +1202,6 @@@ function item_body_set_hashtags(&$item
        // Otherwise there could be problems with hashtags like #test and #test2
        rsort($tags);
  
-       $a = get_app();
        $URLSearchString = "^\[\]";
  
        // All hashtags should point to the home server if "local_tags" is activated
@@@ -1315,7 -1310,6 +1310,6 @@@ function get_item_contact($item, $conta
        foreach ($contacts as $contact) {
                if ($contact['id'] == $item['contact-id']) {
                        return $contact;
-                       break; // NOTREACHED
                }
        }
        return false;
   * @param int $item_id
   * @return bool true if item was deleted, else false
   */
- function tag_deliver($uid, $item_id) {
-       $a = get_app();
+ function tag_deliver($uid, $item_id)
+ {
        $mention = false;
  
        $u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
                intval($uid)
        );
        if (! DBM::is_result($u)) {
                return;
        }
        $community_page = (($u[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
        $prvgroup = (($u[0]['page-flags'] == PAGE_PRVGROUP) ? true : false);
  
        $i = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                intval($item_id),
                intval($uid)
@@@ -1674,15 -1664,13 +1664,13 @@@ function new_follower($importer, $conta
        if (is_array($contact)) {
                if (($contact['network'] == NETWORK_OSTATUS && $contact['rel'] == CONTACT_IS_SHARING)
                        || ($sharing && $contact['rel'] == CONTACT_IS_FOLLOWER)) {
-                       $r = dba::update('contact', array('rel' => CONTACT_IS_FRIEND, 'writable' => true),
+                       dba::update('contact', array('rel' => CONTACT_IS_FRIEND, 'writable' => true),
                                        array('id' => $contact['id'], 'uid' => $importer['uid']));
                }
                // send email notification to owner?
        } else {
                // create contact record
-               $r = q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `name`, `nick`, `photo`, `network`, `rel`,
+               q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `name`, `nick`, `photo`, `network`, `rel`,
                        `blocked`, `readonly`, `pending`, `writable`)
                        VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 0, 1, 1)",
                        intval($importer['uid']),
                        dbesc(NETWORK_OSTATUS),
                        intval(CONTACT_IS_FOLLOWER)
                );
                $r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `pending` = 1 LIMIT 1",
                                intval($importer['uid']),
                                dbesc($url)
                $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
                        intval($importer['uid'])
                );
                if (DBM::is_result($r) && !in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY))) {
                        // create notification
                        $hash = random_string();
  
  
                        }
                } elseif (DBM::is_result($r) && in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY))) {
-                       $r = q("UPDATE `contact` SET `pending` = 0 WHERE `uid` = %d AND `url` = '%s' AND `pending` LIMIT 1",
+                       q("UPDATE `contact` SET `pending` = 0 WHERE `uid` = %d AND `url` = '%s' AND `pending` LIMIT 1",
                                        intval($importer['uid']),
                                        dbesc($url)
                        );
@@@ -1798,7 -1785,7 +1785,7 @@@ function subscribe_to_hub($url, $import
        logger('subscribe_to_hub: ' . $hubmode . ' ' . $contact['name'] . ' to hub ' . $url . ' endpoint: '  . $push_url . ' with verifier ' . $verify_token);
  
        if (!strlen($contact['hub-verify']) || ($contact['hub-verify'] != $verify_token)) {
-               $r = dba::update('contact', array('hub-verify' => $verify_token), array('id' => $contact['id']));
+               dba::update('contact', array('hub-verify' => $verify_token), array('id' => $contact['id']));
        }
  
        post_url($url, $params);
  
  }
  
- function fix_private_photos($s, $uid, $item = null, $cid = 0) {
-       if (Config::get('system','disable_embedded')) {
+ /**
+  *
+  * @param string $s
+  * @param int    $uid
+  * @param array  $item
+  * @param int    $cid
+  * @return string
+  */
+ function fix_private_photos($s, $uid, $item = null, $cid = 0)
+ {
+       if (Config::get('system', 'disable_embedded')) {
                return $s;
        }
  
-       $a = get_app();
        logger('fix_private_photos: check for photos', LOGGER_DEBUG);
-       $site = substr(System::baseUrl(),strpos(System::baseUrl(),'://'));
+       $site = substr(System::baseUrl(), strpos(System::baseUrl(), '://'));
  
        $orig_body = $s;
        $new_body = '';
        $img_start = strpos($orig_body, '[img');
        $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
        $img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false);
-       while ( ($img_st_close !== false) && ($img_len !== false) ) {
  
+       while (($img_st_close !== false) && ($img_len !== false)) {
                $img_st_close++; // make it point to AFTER the closing bracket
                $image = substr($orig_body, $img_start + $img_st_close, $img_len);
  
                logger('fix_private_photos: found photo ' . $image, LOGGER_DEBUG);
  
-               if (stristr($image , $site . '/photo/')) {
+               if (stristr($image, $site . '/photo/')) {
                        // Only embed locally hosted photos
                        $replace = false;
                        $i = basename($image);
-                       $i = str_replace(array('.jpg', '.png', '.gif'),array('', '',''), $i);
+                       $i = str_replace(array('.jpg', '.png', '.gif'), array('', '', ''), $i);
                        $x = strpos($i, '-');
  
                        if ($x) {
                                        dbesc($i),
                                        intval($res),
                                        intval($uid)
                                );
                                if (DBM::is_result($r)) {
                                        /*
@@@ -2161,7 -2152,7 +2152,7 @@@ function drop_item($id, $interactive = 
                logger('delete item: ' . $item['id'], LOGGER_DEBUG);
  
                // delete the item
-               $r = dba::update('item', array('deleted' => true, 'title' => '', 'body' => '',
+               dba::update('item', array('deleted' => true, 'title' => '', 'body' => '',
                                        'edited' => datetime_convert(), 'changed' => datetime_convert()),
                                array('id' => $item['id']));
  
  
                // Now delete them
                if ($parentid != "") {
-                       $r = q("DELETE FROM `sign` WHERE `iid` IN (%s)", dbesc($parentid));
+                       q("DELETE FROM `sign` WHERE `iid` IN (%s)", dbesc($parentid));
                }
  
                // If it's the parent of a comment thread, kill all the kids
                if ($item['uri'] == $item['parent-uri']) {
-                       $r = dba::update('item', array('deleted' => true, 'title' => '', 'body' => '',
+                       dba::update('item', array('deleted' => true, 'title' => '', 'body' => '',
                                        'edited' => datetime_convert(), 'changed' => datetime_convert()),
                                array('parent-uri' => $item['parent-uri'], 'uid' => $item['uid']));
  
diff --combined include/network.php
index bd64ab3508c45c2bb1222a6897907fa990c78483,3e5e15d282f39206f9a60ecbecf0d0006466a32f..561c7aa9489a6305009f250bf23f6e38d525e6e3
@@@ -232,8 -232,6 +232,6 @@@ function z_fetch_url($url, $binary = fa
        $a->set_curl_code($http_code);
        $a->set_curl_content_type($curl_info['content_type']);
  
-       $body = substr($s, strlen($header));
        $rc = intval($http_code);
        $ret['return_code'] = $rc;
        $ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false);
@@@ -615,37 -613,24 +613,37 @@@ function allowed_email($email
                return false;
        }
  
 -      $str_allowed = Config::get('system', 'allowed_email');
 -      if (! $str_allowed) {
 -              return true;
 -      }
 +      $str_allowed = Config::get('system', 'allowed_email', '');
 +      $allowed = explode(',', $str_allowed);
  
 -      $found = false;
 +      return allowed_domain($domain, $allowed);
 +}
  
 -      $fnmatch = function_exists('fnmatch');
 -      $allowed = explode(',', $str_allowed);
 +/**
 + * Checks for the existence of a domain in a domain list
 + *
 + * If strict is not set, an empty domain list counts as found
 + *
 + * @brief Checks for the existence of a domain in a domain list
 + * @param string $domain
 + * @param array $domain_list
 + * @param bool   $strict
 + * @return boolean
 + */
 +function allowed_domain($domain, array $domain_list, $strict = false)
 +{
 +      $found = false;
  
 -      if (count($allowed)) {
 -              foreach ($allowed as $a) {
 -                      $pat = strtolower(trim($a));
 -                      if (($fnmatch && fnmatch($pat, $domain)) || ($pat == $domain)) {
 +      if (count($domain_list)) {
 +              foreach ($domain_list as $item) {
 +                      $pat = strtolower(trim($item));
 +                      if (fnmatch($pat, $domain) || ($pat == $domain)) {
                                $found = true;
                                break;
                        }
                }
 +      } elseif(!$strict) {
 +              $found = true;
        }
        return $found;
  }
@@@ -693,8 -678,6 +691,6 @@@ function scale_external_images($srctext
                $include_link = false;
        }
  
-       $a = get_app();
        // Picture addresses can contain special characters
        $s = htmlspecialchars_decode($srctext);
  
@@@ -868,7 -851,6 +864,6 @@@ function original_url($url, $depth = 1
  
        $stamp1 = microtime(true);
  
-       $siteinfo = array();
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
  
-       $header = curl_exec($ch);
+       curl_exec($ch);
        $curl_info = @curl_getinfo($ch);
        $http_code = $curl_info['http_code'];
        curl_close($ch);
                if (@$attr["http-equiv"] == 'refresh') {
                        $path = $attr["content"];
                        $pathinfo = explode(";", $path);
-                       $content = "";
                        foreach ($pathinfo as $value) {
                                if (substr(strtolower($value), 0, 4) == "url=") {
                                        return(original_url(substr($value, 4), ++$depth));
                }
        }
  
-       return($url);
+       return $url;
  }
  
  function short_link($url)
diff --combined include/plaintext.php
index 5931cba5737ca158c1340b97009216a76eee9f18,acc35869eea668d86e7fd178e78adb5c104f7358..86acad6cfe730209cce2c3070ac4bb02c526ac69
@@@ -3,9 -3,9 +3,9 @@@
   * @file include/plaintext.php
   */
  use Friendica\App;
 -use Friendica\ParseUrl;
  use Friendica\Core\PConfig;
  use Friendica\Object\Image;
 +use Friendica\Util\ParseUrl;
  
  require_once "include/bbcode.php";
  require_once "include/html2plain.php";
@@@ -292,30 -292,38 +292,38 @@@ function get_attached_data($body, $ite
        return $post;
  }
  
- function shortenmsg($msg, $limit, $twitter = false) {
-       /// @TODO
-       /// For Twitter URLs aren't shortened, but they have to be calculated as if.
+ /**
+  * Shortens message
+  *
+  * @param type $msg
+  * @param type $limit
+  * @return type
+  *
+  * @todo For Twitter URLs aren't shortened, but they have to be calculated as if.
+  */
+ function shortenmsg($msg, $limit)
+ {
        $lines = explode("\n", $msg);
        $msg = "";
        $recycle = html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8');
        $ellipsis = html_entity_decode("&#x2026;", ENT_QUOTES, 'UTF-8');
-       foreach ($lines AS $row=>$line) {
-               if (iconv_strlen(trim($msg."\n".$line), "UTF-8") <= $limit)
-                       $msg = trim($msg."\n".$line);
-               // Is the new message empty by now or is it a reshared message?
-               elseif (($msg == "") || (($row == 1) && (substr($msg, 0, 4) == $recycle)))
-                       $msg = iconv_substr(iconv_substr(trim($msg."\n".$line), 0, $limit, "UTF-8"), 0, -3, "UTF-8").$ellipsis;
-               else
+       foreach ($lines AS $row => $line) {
+               if (iconv_strlen(trim($msg . "\n" . $line), "UTF-8") <= $limit) {
+                       $msg = trim($msg . "\n" . $line);
+               } elseif (($msg == "") || (($row == 1) && (substr($msg, 0, 4) == $recycle))) {
+                       // Is the new message empty by now or is it a reshared message?
+                       $msg = iconv_substr(iconv_substr(trim($msg . "\n" . $line), 0, $limit, "UTF-8"), 0, -3, "UTF-8") . $ellipsis;
+               } else {
                        break;
+               }
        }
-       return($msg);
+       return $msg;
  }
  
  /**
   * @brief Convert a message into plaintext for connectors to other networks
   *
-  * @param App $a The application class
   * @param array $b The message array that is about to be posted
   * @param int $limit The maximum number of characters when posting to that network
   * @param bool $includedlinks Has an attached link to be included into the message?
   *
   * @return string The converted message
   */
- function plaintext(App $a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2, $target_network = "") {
+ function plaintext($b, $limit = 0, $includedlinks = false, $htmlmode = 2, $target_network = "") {
  
        // Remove the hash tags
        $URLSearchString = "^\[\]";