]> git.mxchange.org Git - friendica.git/commitdiff
Quick fix PHP notices in various files
authorHypolite Petovan <mrpetovan@gmail.com>
Mon, 1 Jan 2018 20:51:02 +0000 (15:51 -0500)
committerHypolite Petovan <mrpetovan@gmail.com>
Tue, 2 Jan 2018 13:11:14 +0000 (08:11 -0500)
- Remove unused variables
- Fix variable name typos
- Use x() and defaults() to fix undefined index
- Add back uninitialized variables

include/items.php
include/text.php
mod/display.php
mod/nogroup.php
mod/ping.php
mod/videos.php
src/Core/Worker.php
src/Model/Contact.php
src/Network/Probe.php

index 4d495d35151b7c184d1c27ebe9b6c04e45f102d6..9bb5ceb79ca4e4f922edd9996467c84ff1a6d9e2 100644 (file)
@@ -733,7 +733,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
                logger("Contact-id was missing for post ".$arr["guid"]." from user id ".$uid." - now set to ".$arr["contact-id"], LOGGER_DEBUG);
        }
 
-       if ($arr["gcontact-id"] == 0) {
+       if (defaults($arr, "gcontact-id", 0) === 0) {
                /*
                 * The gcontact should mostly behave like the contact. But is is supposed to be global for the system.
                 * This means that wall posts, repeated posts, etc. should have the gcontact id of the owner.
index cbba8d0c5b501065c3ff451e14706be4ec9704a9..5a24c68ed3b1fe562dae509c4d62a8072135d7d7 100644 (file)
@@ -994,7 +994,7 @@ function contact_block() {
 function micropro($contact, $redirect = false, $class = '', $textmode = false) {
 
        // Use the contact URL if no address is available
-       if ($contact["addr"] == "") {
+       if (!x($contact, "addr")) {
                $contact["addr"] = $contact["url"];
        }
 
@@ -1020,7 +1020,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) {
        }
 
        return replace_macros(get_markup_template(($textmode)?'micropro_txt.tpl':'micropro_img.tpl'),array(
-               '$click' => (($contact['click']) ? $contact['click'] : ''),
+               '$click' => defaults($contact, 'click', ''),
                '$class' => $class,
                '$url' => $url,
                '$photo' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB),
@@ -1202,11 +1202,15 @@ function redir_private_images($a, &$item)
        }
 }
 
-function put_item_in_cache(&$item, $update = false) {
-
-       if (($item["rendered-hash"] != hash("md5", $item["body"])) || ($item["rendered-hash"] == "") ||
-               ($item["rendered-html"] == "") || Config::get("system", "ignore_cache")) {
+function put_item_in_cache(&$item, $update = false)
+{
+       $rendered_hash = defaults($item, 'rendered-hash', '');
 
+       if ($rendered_hash == ''
+               || $item["rendered-html"] == ""
+               || $rendered_hash != hash("md5", $item["body"])
+               || Config::get("system", "ignore_cache")
+       ) {
                // The function "redir_private_images" changes the body.
                // I'm not sure if we should store it permanently, so we save the old value.
                $body = $item["body"];
@@ -2026,7 +2030,7 @@ function deindent($text, $chr = "[\t ]", $count = NULL) {
 }
 
 function formatBytes($bytes, $precision = 2) {
-        $units = array('B', 'KB', 'MB', 'GB', 'TB');
+       $units = array('B', 'KB', 'MB', 'GB', 'TB');
 
        $bytes = max($bytes, 0);
        $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
index 12b10f36f85d96e222a38c336753482ad219ebd1..c124f48bb5e7d58622f1e3bb2fc80452cbf8163b 100644 (file)
@@ -201,8 +201,9 @@ function display_content(App $a, $update = false, $update_uid = 0) {
 
        if ($update) {
                $item_id = $_REQUEST['item_id'];
-               $item = dba::select('item', ['uid'], ['id' => $item_id], ['limit' => 1]);
+               $item = dba::select('item', ['uid', 'parent'], ['id' => $item_id], ['limit' => 1]);
                $a->profile = array('uid' => intval($item['uid']), 'profile_uid' => intval($item['uid']));
+               $item_parent = $item['parent'];
        } else {
                $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
 
@@ -260,7 +261,7 @@ function display_content(App $a, $update = false, $update_uid = 0) {
 
        $contact_id = 0;
 
-       if (is_array($_SESSION['remote'])) {
+       if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) {
                foreach ($_SESSION['remote'] as $v) {
                        if ($v['uid'] == $a->profile['uid']) {
                                $contact_id = $v['cid'];
@@ -294,7 +295,7 @@ function display_content(App $a, $update = false, $update_uid = 0) {
        }
        $is_owner = (local_user() && (in_array($a->profile['profile_uid'], [local_user(), 0])) ? true : false);
 
-       if ($a->profile['hidewall'] && !$is_owner && !$remote_contact) {
+       if (x($a->profile, 'hidewall') && !$is_owner && !$remote_contact) {
                notice(t('Access to this profile has been restricted.') . EOL);
                return;
        }
index d80b6d3dbd3a9584681d4bf15da81a7e0e110579..9f5425d9eb7c36604432d2106b895cd8ef75b723 100644 (file)
@@ -41,28 +41,25 @@ function nogroup_content(App $a)
                        $contact_details = Contact::getDetailsByURL($rr['url'], local_user(), $rr);
 
                        $contacts[] = array(
-                               'img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $contact_details['name'], $rr['url']),
+                               'img_hover' => t('Visit %s\'s profile [%s]', $contact_details['name'], $rr['url']),
                                'edit_hover' => t('Edit contact'),
                                'photo_menu' => Contact::photoMenu($rr),
                                'id' => $rr['id'],
-                               'alt_text' => $alt_text,
-                               'dir_icon' => $dir_icon,
                                'thumb' => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
                                'name' => $contact_details['name'],
                                'username' => $contact_details['name'],
                                'details'       => $contact_details['location'],
                                'tags'          => $contact_details['keywords'],
                                'about'         => $contact_details['about'],
-                               'sparkle' => $sparkle,
                                'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
                                'url' => $rr['url'],
-                               'network' => network_to_name($rr['network'], $url),
+                               'network' => network_to_name($rr['network'], $rr['url']),
                        );
                }
        }
 
        $tpl = get_markup_template("nogroup-template.tpl");
-       $o .= replace_macros(
+       $o = replace_macros(
                $tpl,
                array(
                '$header' => t('Contacts who are not members of a group'),
index 930ed54ff9de977e046755044fd71f127bb7828e..d8eaa8126fd03f0aad9b5a079db905dab216b2c5 100644 (file)
@@ -164,8 +164,8 @@ function ping_init(App $a)
 
                        if (intval(Feature::isEnabled(local_user(), 'forumlist_widget'))) {
                                $forum_counts = ForumManager::countUnseenItems();
-                               if (DBM::is_result($forums_counts)) {
-                                       foreach ($forums_counts as $forum_count) {
+                               if (DBM::is_result($forum_counts)) {
+                                       foreach ($forum_counts as $forum_count) {
                                                if ($forum_count['count'] > 0) {
                                                        $forums_unseen[] = $forum_count;
                                                }
@@ -490,8 +490,10 @@ function ping_get_notifications($uid)
 
                        $notification["href"] = System::baseUrl() . "/notify/view/" . $notification["id"];
 
-                       if ($notification["visible"] && !$notification["spam"]
-                               && !$notification["deleted"] && !is_array($result[$notification["parent"]])
+                       if ($notification["visible"]
+                               && !$notification["spam"]
+                               && !$notification["deleted"]
+                               && !(x($result, $notification["parent"]) && is_array($result[$notification["parent"]]))
                        ) {
                                // Should we condense the notifications or show them all?
                                if (PConfig::get(local_user(), 'system', 'detailed_notif')) {
index bb0e0c237fd432aff144e5cd804dcdf853432ab5..c4e5d0aaa410882caf4eb97430cf310c3fe60948 100644 (file)
@@ -7,11 +7,11 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 
-require_once('include/items.php');
-require_once('include/acl_selectors.php');
-require_once('include/bbcode.php');
-require_once('include/security.php');
-require_once('include/redir.php');
+require_once 'include/items.php';
+require_once 'include/acl_selectors.php';
+require_once 'include/bbcode.php';
+require_once 'include/security.php';
+require_once 'include/redir.php';
 
 function videos_init(App $a) {
 
@@ -44,12 +44,12 @@ function videos_init(App $a) {
 
                $tpl = get_markup_template("vcard-widget.tpl");
 
-               $vcard_widget .= replace_macros($tpl, array(
+               $vcard_widget = replace_macros($tpl, array(
                        '$name' => $profile['name'],
                        '$photo' => $profile['photo'],
-                       '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""),
+                       '$addr' => defaults($profile, 'addr', ''),
                        '$account_type' => $account_type,
-                       '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
+                       '$pdesc' => defaults($profile, 'pdesc', ''),
                ));
 
 
@@ -280,8 +280,9 @@ function videos_content(App $a) {
                }
        }
 
-       // perhaps they're visiting - but not a community page, so they wouldn't have write access
+       $groups = [];
 
+       // perhaps they're visiting - but not a community page, so they wouldn't have write access
        if(remote_user() && (! $visitor)) {
                $contact_id = 0;
                if(is_array($_SESSION['remote'])) {
@@ -317,7 +318,7 @@ function videos_content(App $a) {
                return;
        }
 
-       $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
+       $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
 
        $o = "";
 
index 760b40b1d30eb19adb742d85b8077fe385d5e730..55e2b33a047ee9c9a52c5fce5dcc0f0e0f9ba5fe 100644 (file)
@@ -606,6 +606,7 @@ class Worker
                        $exponent = 3;
                        $slope = $maxworkers / pow($maxsysload, $exponent);
                        $queues = ceil($slope * pow(max(0, $maxsysload - $load), $exponent));
+                       $processlist = '';
 
                        if (Config::get('system', 'worker_debug')) {
                                // Create a list of queue entries grouped by their priority
index 1b15f1c76d89faafa38bae7187a7184552962ecd..067a2fda7f104e44680937d287696b04d1c2100a 100644 (file)
@@ -662,7 +662,7 @@ class Contact extends BaseObject
                if (!DBM::is_result($contact)) {
                        // The link could be provided as http although we stored it as https
                        $ssl_url = str_replace('http://', 'https://', $url);
-                       $r = dba::select('contact', array('id', 'avatar-date'), array('`alias` IN (?, ?, ?) AND `uid` = ?', $url, normalise_link($url), $ssl_url, $uid), array('limit' => 1));
+                       $r = dba::select('contact', array('id', 'avatar', 'avatar-date'), array('`alias` IN (?, ?, ?) AND `uid` = ?', $url, normalise_link($url), $ssl_url, $uid), array('limit' => 1));
                        $contact = dba::fetch($r);
                        dba::close($r);
                }
@@ -674,7 +674,7 @@ class Contact extends BaseObject
                        $update_contact = ($contact['avatar-date'] < datetime_convert('', '', 'now -7 days'));
 
                        // We force the update if the avatar is empty
-                       if ($contact['avatar'] == '') {
+                       if (!x($contact, 'avatar')) {
                                $update_contact = true;
                        }
 
index 539803b6e4d93acfc56ea918f5c2bc59f3ff75f4..8912088cbb003a967b771da5988d53eddd38d04d 100644 (file)
@@ -330,7 +330,7 @@ class Probe
                        $data["url"] = $uri;
                }
 
-               if ($data["photo"] != "") {
+               if (x($data, "photo")) {
                        $data["baseurl"] = matching_url(normalise_link($data["baseurl"]), normalise_link($data["photo"]));
                } else {
                        $data["photo"] = System::baseUrl().'/images/person-175.jpg';
@@ -341,7 +341,7 @@ class Probe
                                $data["name"] = $data["nick"];
                        }
 
-                       if ($data["name"] == "") {
+                       if (!x($data, "name")) {
                                $data["name"] = $data["url"];
                        }
                }