From: Hypolite Petovan Date: Mon, 1 Jan 2018 20:51:02 +0000 (-0500) Subject: Quick fix PHP notices in various files X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9f04017e278e84638af0f35b08433d6289eacf45;p=friendica.git Quick fix PHP notices in various files - Remove unused variables - Fix variable name typos - Use x() and defaults() to fix undefined index - Add back uninitialized variables --- diff --git a/include/items.php b/include/items.php index 4d495d3515..9bb5ceb79c 100644 --- a/include/items.php +++ b/include/items.php @@ -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. diff --git a/include/text.php b/include/text.php index cbba8d0c5b..5a24c68ed3 100644 --- a/include/text.php +++ b/include/text.php @@ -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)); diff --git a/mod/display.php b/mod/display.php index 12b10f36f8..c124f48bb5 100644 --- a/mod/display.php +++ b/mod/display.php @@ -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; } diff --git a/mod/nogroup.php b/mod/nogroup.php index d80b6d3dbd..9f5425d9eb 100644 --- a/mod/nogroup.php +++ b/mod/nogroup.php @@ -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'), diff --git a/mod/ping.php b/mod/ping.php index 930ed54ff9..d8eaa8126f 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -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')) { diff --git a/mod/videos.php b/mod/videos.php index bb0e0c237f..c4e5d0aaa4 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -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 = ""; diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 760b40b1d3..55e2b33a04 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -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 diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 1b15f1c76d..067a2fda7f 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -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; } diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 539803b6e4..8912088cbb 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -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"]; } }