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
This commit is contained in:
Hypolite Petovan 2018-01-01 15:51:02 -05:00
parent 861c4c7474
commit 9f04017e27
9 changed files with 41 additions and 35 deletions

View 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); 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. * 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. * This means that wall posts, repeated posts, etc. should have the gcontact id of the owner.

View file

@ -994,7 +994,7 @@ function contact_block() {
function micropro($contact, $redirect = false, $class = '', $textmode = false) { function micropro($contact, $redirect = false, $class = '', $textmode = false) {
// Use the contact URL if no address is available // Use the contact URL if no address is available
if ($contact["addr"] == "") { if (!x($contact, "addr")) {
$contact["addr"] = $contact["url"]; $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( 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, '$class' => $class,
'$url' => $url, '$url' => $url,
'$photo' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB), '$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) { function put_item_in_cache(&$item, $update = false)
{
if (($item["rendered-hash"] != hash("md5", $item["body"])) || ($item["rendered-hash"] == "") || $rendered_hash = defaults($item, 'rendered-hash', '');
($item["rendered-html"] == "") || Config::get("system", "ignore_cache")) {
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. // The function "redir_private_images" changes the body.
// I'm not sure if we should store it permanently, so we save the old value. // I'm not sure if we should store it permanently, so we save the old value.
$body = $item["body"]; $body = $item["body"];
@ -2026,7 +2030,7 @@ function deindent($text, $chr = "[\t ]", $count = NULL) {
} }
function formatBytes($bytes, $precision = 2) { function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB'); $units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0); $bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = floor(($bytes ? log($bytes) : 0) / log(1024));

View file

@ -201,8 +201,9 @@ function display_content(App $a, $update = false, $update_uid = 0) {
if ($update) { if ($update) {
$item_id = $_REQUEST['item_id']; $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'])); $a->profile = array('uid' => intval($item['uid']), 'profile_uid' => intval($item['uid']));
$item_parent = $item['parent'];
} else { } else {
$item_id = (($a->argc > 2) ? $a->argv[2] : 0); $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; $contact_id = 0;
if (is_array($_SESSION['remote'])) { if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) {
foreach ($_SESSION['remote'] as $v) { foreach ($_SESSION['remote'] as $v) {
if ($v['uid'] == $a->profile['uid']) { if ($v['uid'] == $a->profile['uid']) {
$contact_id = $v['cid']; $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); $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); notice(t('Access to this profile has been restricted.') . EOL);
return; return;
} }

View file

@ -41,28 +41,25 @@ function nogroup_content(App $a)
$contact_details = Contact::getDetailsByURL($rr['url'], local_user(), $rr); $contact_details = Contact::getDetailsByURL($rr['url'], local_user(), $rr);
$contacts[] = array( $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'), 'edit_hover' => t('Edit contact'),
'photo_menu' => Contact::photoMenu($rr), 'photo_menu' => Contact::photoMenu($rr),
'id' => $rr['id'], 'id' => $rr['id'],
'alt_text' => $alt_text,
'dir_icon' => $dir_icon,
'thumb' => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB), 'thumb' => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
'name' => $contact_details['name'], 'name' => $contact_details['name'],
'username' => $contact_details['name'], 'username' => $contact_details['name'],
'details' => $contact_details['location'], 'details' => $contact_details['location'],
'tags' => $contact_details['keywords'], 'tags' => $contact_details['keywords'],
'about' => $contact_details['about'], 'about' => $contact_details['about'],
'sparkle' => $sparkle,
'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']), 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
'url' => $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"); $tpl = get_markup_template("nogroup-template.tpl");
$o .= replace_macros( $o = replace_macros(
$tpl, $tpl,
array( array(
'$header' => t('Contacts who are not members of a group'), '$header' => t('Contacts who are not members of a group'),

View file

@ -164,8 +164,8 @@ function ping_init(App $a)
if (intval(Feature::isEnabled(local_user(), 'forumlist_widget'))) { if (intval(Feature::isEnabled(local_user(), 'forumlist_widget'))) {
$forum_counts = ForumManager::countUnseenItems(); $forum_counts = ForumManager::countUnseenItems();
if (DBM::is_result($forums_counts)) { if (DBM::is_result($forum_counts)) {
foreach ($forums_counts as $forum_count) { foreach ($forum_counts as $forum_count) {
if ($forum_count['count'] > 0) { if ($forum_count['count'] > 0) {
$forums_unseen[] = $forum_count; $forums_unseen[] = $forum_count;
} }
@ -490,8 +490,10 @@ function ping_get_notifications($uid)
$notification["href"] = System::baseUrl() . "/notify/view/" . $notification["id"]; $notification["href"] = System::baseUrl() . "/notify/view/" . $notification["id"];
if ($notification["visible"] && !$notification["spam"] if ($notification["visible"]
&& !$notification["deleted"] && !is_array($result[$notification["parent"]]) && !$notification["spam"]
&& !$notification["deleted"]
&& !(x($result, $notification["parent"]) && is_array($result[$notification["parent"]]))
) { ) {
// Should we condense the notifications or show them all? // Should we condense the notifications or show them all?
if (PConfig::get(local_user(), 'system', 'detailed_notif')) { if (PConfig::get(local_user(), 'system', 'detailed_notif')) {

View file

@ -7,11 +7,11 @@ use Friendica\Core\Worker;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
require_once('include/items.php'); require_once 'include/items.php';
require_once('include/acl_selectors.php'); require_once 'include/acl_selectors.php';
require_once('include/bbcode.php'); require_once 'include/bbcode.php';
require_once('include/security.php'); require_once 'include/security.php';
require_once('include/redir.php'); require_once 'include/redir.php';
function videos_init(App $a) { function videos_init(App $a) {
@ -44,12 +44,12 @@ function videos_init(App $a) {
$tpl = get_markup_template("vcard-widget.tpl"); $tpl = get_markup_template("vcard-widget.tpl");
$vcard_widget .= replace_macros($tpl, array( $vcard_widget = replace_macros($tpl, array(
'$name' => $profile['name'], '$name' => $profile['name'],
'$photo' => $profile['photo'], '$photo' => $profile['photo'],
'$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""), '$addr' => defaults($profile, 'addr', ''),
'$account_type' => $account_type, '$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)) { if(remote_user() && (! $visitor)) {
$contact_id = 0; $contact_id = 0;
if(is_array($_SESSION['remote'])) { if(is_array($_SESSION['remote'])) {
@ -317,7 +318,7 @@ function videos_content(App $a) {
return; return;
} }
$sql_extra = permissions_sql($owner_uid,$remote_contact,$groups); $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
$o = ""; $o = "";

View file

@ -606,6 +606,7 @@ class Worker
$exponent = 3; $exponent = 3;
$slope = $maxworkers / pow($maxsysload, $exponent); $slope = $maxworkers / pow($maxsysload, $exponent);
$queues = ceil($slope * pow(max(0, $maxsysload - $load), $exponent)); $queues = ceil($slope * pow(max(0, $maxsysload - $load), $exponent));
$processlist = '';
if (Config::get('system', 'worker_debug')) { if (Config::get('system', 'worker_debug')) {
// Create a list of queue entries grouped by their priority // Create a list of queue entries grouped by their priority

View file

@ -662,7 +662,7 @@ class Contact extends BaseObject
if (!DBM::is_result($contact)) { if (!DBM::is_result($contact)) {
// The link could be provided as http although we stored it as https // The link could be provided as http although we stored it as https
$ssl_url = str_replace('http://', 'https://', $url); $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); $contact = dba::fetch($r);
dba::close($r); dba::close($r);
} }
@ -674,7 +674,7 @@ class Contact extends BaseObject
$update_contact = ($contact['avatar-date'] < datetime_convert('', '', 'now -7 days')); $update_contact = ($contact['avatar-date'] < datetime_convert('', '', 'now -7 days'));
// We force the update if the avatar is empty // We force the update if the avatar is empty
if ($contact['avatar'] == '') { if (!x($contact, 'avatar')) {
$update_contact = true; $update_contact = true;
} }

View file

@ -330,7 +330,7 @@ class Probe
$data["url"] = $uri; $data["url"] = $uri;
} }
if ($data["photo"] != "") { if (x($data, "photo")) {
$data["baseurl"] = matching_url(normalise_link($data["baseurl"]), normalise_link($data["photo"])); $data["baseurl"] = matching_url(normalise_link($data["baseurl"]), normalise_link($data["photo"]));
} else { } else {
$data["photo"] = System::baseUrl().'/images/person-175.jpg'; $data["photo"] = System::baseUrl().'/images/person-175.jpg';
@ -341,7 +341,7 @@ class Probe
$data["name"] = $data["nick"]; $data["name"] = $data["nick"];
} }
if ($data["name"] == "") { if (!x($data, "name")) {
$data["name"] = $data["url"]; $data["name"] = $data["url"];
} }
} }