From aa548be3b95f1a4292f51e0758e80d759a9b14d1 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:33:54 +0100 Subject: [PATCH 01/30] Introduced is_filled_array() + added some missing array initialization Signed-off-by: Roland Haeder --- boot.php | 4 ++++ mod/message.php | 10 ++++++---- mod/ping.php | 25 +++++++++++++------------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/boot.php b/boot.php index d82669f231..bf98cf5c3a 100644 --- a/boot.php +++ b/boot.php @@ -2138,3 +2138,7 @@ function argv($x) { return ''; } + +function is_filled_array ($array) { + return (is_array($array) && count($array) > 0); +} diff --git a/mod/message.php b/mod/message.php index 734bf34710..6e176f7123 100644 --- a/mod/message.php +++ b/mod/message.php @@ -8,7 +8,7 @@ function message_init(&$a) { $tabs = ''; if ($a->argc >1 && is_numeric($a->argv[1])) { - $tabs = render_messages(get_messages(local_user(),0,5), 'mail_list.tpl'); + $tabs = render_messages(get_messages(local_user(),0,5), 'mail_list.tpl'); } $new = array( @@ -360,11 +360,13 @@ function message_content(&$a) { dbesc($myprofile) ); - if(count($r)) $a->set_pager_total($r[0]['total']); + if (is_filled_array($r)) { + $a->set_pager_total($r[0]['total']); + } $r = get_messages(local_user(), $a->pager['start'], $a->pager['itemspage']); - if(! count($r)) { + if(! is_filled_array($r)) { info( t('No messages.') . EOL); return $o; } @@ -542,7 +544,7 @@ function get_messages($user, $lstart, $lend) { ); } -function render_messages($msg, $t) { +function render_messages(array $msg, $t) { $a = get_app(); diff --git a/mod/ping.php b/mod/ping.php index 2eb94576b3..8deab28ed2 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -32,6 +32,8 @@ function ping_init(&$a) { $dislikes = array(); $friends = array(); $posts = array(); + $regs = array(); + $mails = array(); $home = 0; $network = 0; @@ -49,7 +51,7 @@ function ping_init(&$a) { intval(local_user()), intval(local_user()) ); - if(count($r)) { + if(is_filled_array($r)) { $arr = array('items' => $r); call_hooks('network_ping', $arr); @@ -116,8 +118,6 @@ function ping_init(&$a) { $intro = count($intros1) + count($intros2); $intros = $intros1+$intros2; - - $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ; $mails = q("SELECT * FROM `mail` WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ", @@ -150,7 +150,7 @@ function ping_init(&$a) { dbesc(datetime_convert('UTC','UTC','now')) ); - if($ev && count($ev)) { + if(is_filled_array($ev)) { $all_events = intval($ev[0]['total']); if($all_events) { @@ -219,7 +219,7 @@ function ping_init(&$a) { $home\r\n"; if ($register!=0) echo "$register"; - if (count($groups_unseen)) { + if ( is_filled_array($groups_unseen) ) { echo ''; foreach ($groups_unseen as $it) if ($it['count'] > 0) @@ -228,7 +228,7 @@ function ping_init(&$a) { echo ""; } - if (count($forums_unseen)) { + if ( is_filled_array($forums_unseen) ) { echo ''; foreach ($forums_unseen as $it) if ($it['count'] > 0) @@ -245,8 +245,8 @@ function ping_init(&$a) { $birthdays_today\r\n"; - if(count($notifs) && (! $sysnotify)) { - foreach($notifs as $zz) { + if (is_filled_array($notifs) && (! $sysnotify)) { + foreach ($notifs as $zz) { if($zz['seen'] == 0) $sysnotify ++; } @@ -255,7 +255,7 @@ function ping_init(&$a) { echo ' '; // merge all notification types in one array - if ($intro>0){ + if ( is_filled_array($intros) ) { foreach ($intros as $i) { $n = array( 'href' => $a->get_baseurl().'/notifications/intros/'.$i['id'], @@ -270,7 +270,7 @@ function ping_init(&$a) { } } - if ($mail>0){ + if ( is_filled_array($mails) ) { foreach ($mails as $i) { $n = array( 'href' => $a->get_baseurl().'/message/'.$i['id'], @@ -285,7 +285,7 @@ function ping_init(&$a) { } } - if ($register>0){ + if ( is_filled_array($regs) ) { foreach ($regs as $i) { $n = array( 'href' => $a->get_baseurl().'/admin/users/', @@ -299,6 +299,7 @@ function ping_init(&$a) { $notifs[] = $n; } } + // sort notifications by $[]['date'] $sort_function = function($a, $b) { $adate = date($a['date']); @@ -310,7 +311,7 @@ function ping_init(&$a) { }; usort($notifs, $sort_function); - if(count($notifs)) { + if( is_filled_array($notifs) ) { foreach($notifs as $n) { echo xmlize($n); } From 78e6569b27260b6cf156c372f22e90f6f122dd67 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:38:02 +0100 Subject: [PATCH 02/30] Also use is_filled_array() here, too. if $contacts is FALSE count() issues are E_WARNING Signed-off-by: Roland Haeder --- include/ForumManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ForumManager.php b/include/ForumManager.php index 6fede0204d..bbf881c9d0 100644 --- a/include/ForumManager.php +++ b/include/ForumManager.php @@ -86,7 +86,7 @@ class ForumManager { $total = count($contacts); $visible_forums = 10; - if(count($contacts)) { + if(is_filled_array($contacts)) { $id = 0; From f7a02601290ff37a5081af30c3571ee0df4fa79a Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:27:38 +0100 Subject: [PATCH 03/30] No need to set $a->theme_info = array() everywhere if you can define it in App itself. Signed-off-by: Roland Haeder --- boot.php | 5 +++-- view/theme/decaf-mobile/theme.php | 1 - view/theme/duepuntozero/theme.php | 1 - view/theme/facepark/theme.php | 1 - view/theme/frost-mobile/theme.php | 1 - view/theme/frost/theme.php | 1 - view/theme/quattro/theme.php | 2 -- view/theme/smoothly/theme.php | 1 - view/theme/vier/theme.php | 2 -- 9 files changed, 3 insertions(+), 12 deletions(-) diff --git a/boot.php b/boot.php index d82669f231..4b2e83f18a 100644 --- a/boot.php +++ b/boot.php @@ -465,11 +465,12 @@ class App { public $plugins; public $apps = array(); public $identities; - public $is_mobile; - public $is_tablet; + public $is_mobile = false; + public $is_tablet = false; public $is_friendica_app; public $performance = array(); public $callstack = array(); + public $theme_info = array(); public $nav_sel; diff --git a/view/theme/decaf-mobile/theme.php b/view/theme/decaf-mobile/theme.php index 1a32fb724d..9b1c1daa61 100644 --- a/view/theme/decaf-mobile/theme.php +++ b/view/theme/decaf-mobile/theme.php @@ -10,7 +10,6 @@ */ function decaf_mobile_init(&$a) { - $a->theme_info = array(); $a->sourcename = 'Friendica mobile web'; $a->videowidth = 250; $a->videoheight = 200; diff --git a/view/theme/duepuntozero/theme.php b/view/theme/duepuntozero/theme.php index ba3f25d3e2..50d57f91e5 100644 --- a/view/theme/duepuntozero/theme.php +++ b/view/theme/duepuntozero/theme.php @@ -2,7 +2,6 @@ function duepuntozero_init(&$a) { -$a->theme_info = array(); set_template_engine($a, 'smarty3'); $colorset = get_pconfig( local_user(), 'duepuntozero','colorset'); diff --git a/view/theme/facepark/theme.php b/view/theme/facepark/theme.php index e7203c6641..e6255f118a 100644 --- a/view/theme/facepark/theme.php +++ b/view/theme/facepark/theme.php @@ -1,7 +1,6 @@ theme_info = array(); set_template_engine($a, 'smarty3'); $a->page['htmlhead'] .= <<< EOT diff --git a/view/theme/frost-mobile/theme.php b/view/theme/frost-mobile/theme.php index beec924934..29a990f7b8 100644 --- a/view/theme/frost-mobile/theme.php +++ b/view/theme/frost-mobile/theme.php @@ -10,7 +10,6 @@ */ function frost_mobile_init(&$a) { - $a->theme_info = array(); $a->sourcename = 'Friendica mobile web'; $a->videowidth = 250; $a->videoheight = 200; diff --git a/view/theme/frost/theme.php b/view/theme/frost/theme.php index 868a840dee..1093a04729 100644 --- a/view/theme/frost/theme.php +++ b/view/theme/frost/theme.php @@ -10,7 +10,6 @@ */ function frost_init(&$a) { - $a->theme_info = array(); $a->videowidth = 400; $a->videoheight = 330; $a->theme_thread_allow = false; diff --git a/view/theme/quattro/theme.php b/view/theme/quattro/theme.php index a1cd29ee72..0b67c6b49a 100644 --- a/view/theme/quattro/theme.php +++ b/view/theme/quattro/theme.php @@ -8,8 +8,6 @@ */ function quattro_init(&$a) { - $a->theme_info = array(); - $a->page['htmlhead'] .= ''; $a->page['htmlhead'] .= '';; } diff --git a/view/theme/smoothly/theme.php b/view/theme/smoothly/theme.php index d3ebbc1d15..0dae3a6e47 100644 --- a/view/theme/smoothly/theme.php +++ b/view/theme/smoothly/theme.php @@ -11,7 +11,6 @@ */ function smoothly_init(&$a) { - $a->theme_info = array(); set_template_engine($a, 'smarty3'); $cssFile = null; diff --git a/view/theme/vier/theme.php b/view/theme/vier/theme.php index 7f6ead079f..925ac76a1f 100644 --- a/view/theme/vier/theme.php +++ b/view/theme/vier/theme.php @@ -19,8 +19,6 @@ function vier_init(&$a) { set_template_engine($a, 'smarty3'); - $a->theme_info = array(); - if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()) { vier_community_info(); From c54e38fddb9e0132124094bd7848157af943f1ea Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:32:19 +0100 Subject: [PATCH 04/30] Prevent some E_NOTICE in boot.php Signed-off-by: Roland Haeder --- boot.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/boot.php b/boot.php index 4b2e83f18a..0a2f5c50cd 100644 --- a/boot.php +++ b/boot.php @@ -1047,11 +1047,21 @@ class App { function save_timestamp($stamp, $value) { $duration = (float)(microtime(true)-$stamp); + if (!isset($this->performance[$value])) { + // Prevent ugly E_NOTICE + $this->performance[$value] = 0; + } + $this->performance[$value] += (float)$duration; $this->performance["marktime"] += (float)$duration; $callstack = $this->callstack(); + if (!isset($this->callstack[$value][$callstack])) { + // Prevent ugly E_NOTICE + $this->callstack[$value][$callstack] = 0; + } + $this->callstack[$value][$callstack] += (float)$duration; } From 2c37eab808bb18c929a861b9cad54df865a95322 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:33:54 +0100 Subject: [PATCH 05/30] Introduced is_filled_array() + added some missing array initialization Signed-off-by: Roland Haeder --- boot.php | 4 ++++ mod/message.php | 10 ++++++---- mod/ping.php | 25 +++++++++++++------------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/boot.php b/boot.php index 0a2f5c50cd..a1f29398f6 100644 --- a/boot.php +++ b/boot.php @@ -2149,3 +2149,7 @@ function argv($x) { return ''; } + +function is_filled_array ($array) { + return (is_array($array) && count($array) > 0); +} diff --git a/mod/message.php b/mod/message.php index 734bf34710..6e176f7123 100644 --- a/mod/message.php +++ b/mod/message.php @@ -8,7 +8,7 @@ function message_init(&$a) { $tabs = ''; if ($a->argc >1 && is_numeric($a->argv[1])) { - $tabs = render_messages(get_messages(local_user(),0,5), 'mail_list.tpl'); + $tabs = render_messages(get_messages(local_user(),0,5), 'mail_list.tpl'); } $new = array( @@ -360,11 +360,13 @@ function message_content(&$a) { dbesc($myprofile) ); - if(count($r)) $a->set_pager_total($r[0]['total']); + if (is_filled_array($r)) { + $a->set_pager_total($r[0]['total']); + } $r = get_messages(local_user(), $a->pager['start'], $a->pager['itemspage']); - if(! count($r)) { + if(! is_filled_array($r)) { info( t('No messages.') . EOL); return $o; } @@ -542,7 +544,7 @@ function get_messages($user, $lstart, $lend) { ); } -function render_messages($msg, $t) { +function render_messages(array $msg, $t) { $a = get_app(); diff --git a/mod/ping.php b/mod/ping.php index 2eb94576b3..8deab28ed2 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -32,6 +32,8 @@ function ping_init(&$a) { $dislikes = array(); $friends = array(); $posts = array(); + $regs = array(); + $mails = array(); $home = 0; $network = 0; @@ -49,7 +51,7 @@ function ping_init(&$a) { intval(local_user()), intval(local_user()) ); - if(count($r)) { + if(is_filled_array($r)) { $arr = array('items' => $r); call_hooks('network_ping', $arr); @@ -116,8 +118,6 @@ function ping_init(&$a) { $intro = count($intros1) + count($intros2); $intros = $intros1+$intros2; - - $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ; $mails = q("SELECT * FROM `mail` WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ", @@ -150,7 +150,7 @@ function ping_init(&$a) { dbesc(datetime_convert('UTC','UTC','now')) ); - if($ev && count($ev)) { + if(is_filled_array($ev)) { $all_events = intval($ev[0]['total']); if($all_events) { @@ -219,7 +219,7 @@ function ping_init(&$a) { $home\r\n"; if ($register!=0) echo "$register"; - if (count($groups_unseen)) { + if ( is_filled_array($groups_unseen) ) { echo ''; foreach ($groups_unseen as $it) if ($it['count'] > 0) @@ -228,7 +228,7 @@ function ping_init(&$a) { echo ""; } - if (count($forums_unseen)) { + if ( is_filled_array($forums_unseen) ) { echo ''; foreach ($forums_unseen as $it) if ($it['count'] > 0) @@ -245,8 +245,8 @@ function ping_init(&$a) { $birthdays_today\r\n"; - if(count($notifs) && (! $sysnotify)) { - foreach($notifs as $zz) { + if (is_filled_array($notifs) && (! $sysnotify)) { + foreach ($notifs as $zz) { if($zz['seen'] == 0) $sysnotify ++; } @@ -255,7 +255,7 @@ function ping_init(&$a) { echo ' '; // merge all notification types in one array - if ($intro>0){ + if ( is_filled_array($intros) ) { foreach ($intros as $i) { $n = array( 'href' => $a->get_baseurl().'/notifications/intros/'.$i['id'], @@ -270,7 +270,7 @@ function ping_init(&$a) { } } - if ($mail>0){ + if ( is_filled_array($mails) ) { foreach ($mails as $i) { $n = array( 'href' => $a->get_baseurl().'/message/'.$i['id'], @@ -285,7 +285,7 @@ function ping_init(&$a) { } } - if ($register>0){ + if ( is_filled_array($regs) ) { foreach ($regs as $i) { $n = array( 'href' => $a->get_baseurl().'/admin/users/', @@ -299,6 +299,7 @@ function ping_init(&$a) { $notifs[] = $n; } } + // sort notifications by $[]['date'] $sort_function = function($a, $b) { $adate = date($a['date']); @@ -310,7 +311,7 @@ function ping_init(&$a) { }; usort($notifs, $sort_function); - if(count($notifs)) { + if( is_filled_array($notifs) ) { foreach($notifs as $n) { echo xmlize($n); } From 962536330a145cacddf4794eb4ba16ea20402daf Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:36:23 +0100 Subject: [PATCH 06/30] Prevent some E_NOTICE in identity.php Signed-off-by: Roland Haeder --- include/identity.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/identity.php b/include/identity.php index aba69bae49..888a09ee6f 100644 --- a/include/identity.php +++ b/include/identity.php @@ -237,6 +237,7 @@ function profile_sidebar($profile, $block = 0) { if ($connect AND ($profile['network'] != NETWORK_DFRN) AND !isset($profile['remoteconnect'])) $connect = false; + $remoteconnect = NULL; if (isset($profile['remoteconnect'])) $remoteconnect = $profile['remoteconnect']; @@ -292,9 +293,9 @@ function profile_sidebar($profile, $block = 0) { // check if profile is a forum if((intval($profile['page-flags']) == PAGE_COMMUNITY) || (intval($profile['page-flags']) == PAGE_PRVGROUP) - || (intval($profile['forum'])) - || (intval($profile['prv'])) - || (intval($profile['community']))) + || (isset($profile['forum']) && intval($profile['forum'])) + || (isset($profile['prv']) && intval($profile['prv'])) + || (isset($profile['community']) && intval($profile['community']))) $account_type = t('Forum'); else $account_type = ""; From f53af9732c18fb81f7c3eb95b3e3d2356f840d87 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:38:02 +0100 Subject: [PATCH 07/30] Also use is_filled_array() here, too. if $contacts is FALSE count() issues are E_WARNING Signed-off-by: Roland Haeder --- include/ForumManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ForumManager.php b/include/ForumManager.php index 6fede0204d..bbf881c9d0 100644 --- a/include/ForumManager.php +++ b/include/ForumManager.php @@ -86,7 +86,7 @@ class ForumManager { $total = count($contacts); $visible_forums = 10; - if(count($contacts)) { + if(is_filled_array($contacts)) { $id = 0; From 438026aafdad8be1d449369055a26cd8d9e862df Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:42:55 +0100 Subject: [PATCH 08/30] More logging in case of errors + logged network type + added TODO (for ugly E_NOTICE). Signed-off-by: Roland Haeder --- mod/dfrn_request.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 2741ad59b4..82886a6efa 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -42,8 +42,10 @@ function dfrn_request_init(&$a) { if(! function_exists('dfrn_request_post')) { function dfrn_request_post(&$a) { - if(($a->argc != 2) || (! count($a->profile))) + if(($a->argc != 2) || (! count($a->profile))) { + logger('Wrong count of argc or profiles: argc=' . $a->argc . ',profile()=' . count($a->profile)); return; + } if(x($_POST, 'cancel')) { @@ -461,7 +463,7 @@ function dfrn_request_post(&$a) { $network = NETWORK_DFRN; } - logger('dfrn_request: url: ' . $url); + logger('dfrn_request: url: ' . $url . ',network=' . $network, LOGGER_DEBUG); if($network === NETWORK_DFRN) { $ret = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `self` = 0 LIMIT 1", @@ -825,6 +827,7 @@ function dfrn_request_content(&$a) { else $tpl = get_markup_template('auto_request.tpl'); + // TODO This .= triggers an E_NOTICE, really needed? $page_desc .= t("Please enter your 'Identity Address' from one of the following supported communications networks:"); // see if we are allowed to have NETWORK_MAIL2 contacts @@ -850,6 +853,7 @@ function dfrn_request_content(&$a) { get_server() ); + // TODO This .= triggers an E_NOTICE, really needed? $o .= replace_macros($tpl,array( '$header' => t('Friend/Connection Request'), '$desc' => t('Examples: jojo@demo.friendica.com, http://demo.friendica.com/profile/jojo, testuser@identi.ca'), From 262618201651aac7c971dfd526edcc35fa9c784a Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:49:07 +0100 Subject: [PATCH 09/30] Don't miss to add exit() after header('Location: bla') as header() does *NOT* exit the script quickly enough. Always use an explicit exit() or you get real trouble. Signed-off-by: Roland Haeder --- index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index e364389b2c..625c2d82dc 100644 --- a/index.php +++ b/index.php @@ -72,7 +72,8 @@ if(!$install) { (intval(get_config('system','ssl_policy')) == SSL_POLICY_FULL) AND (substr($a->get_baseurl(), 0, 8) == "https://")) { header("HTTP/1.1 302 Moved Temporarily"); - header("location: ".$a->get_baseurl()."/".$a->query_string); + header("Location: ".$a->get_baseurl()."/".$a->query_string); + exit(); } require_once("include/session.php"); From 7e485f25ab0fee428f159d91f2b958173d02f26c Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:49:56 +0100 Subject: [PATCH 10/30]
and or are not self-closing tags. Signed-off-by: Roland Haeder --- view/templates/dfrn_request.tpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/view/templates/dfrn_request.tpl b/view/templates/dfrn_request.tpl index 3b96d3eefd..5225bd60b2 100644 --- a/view/templates/dfrn_request.tpl +++ b/view/templates/dfrn_request.tpl @@ -18,13 +18,13 @@ {{/if}} {{if $request}} - + {{else}} - + {{/if}} {{if $photo}} - + {{/if}} {{if $url}}
{{$url_label}}
{{$url}}
{{/if}} From 858438daec44cad20153b4160f7d1c9ddeac7484 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 16:00:55 +0100 Subject: [PATCH 11/30] More calls replaced with is_filled_array(), ticket #2390 Signed-off-by: Roland Haeder --- boot.php | 10 +++++----- index.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/boot.php b/boot.php index bf98cf5c3a..b049099ea8 100644 --- a/boot.php +++ b/boot.php @@ -926,7 +926,7 @@ class App { } else { $r = q("SELECT `contact`.`avatar-date` AS picdate FROM `contact` WHERE `contact`.`thumb` like '%%/%s'", $common_filename); - if(! count($r)){ + if(! is_filled_array($r)){ $this->cached_profile_image[$avatar_image] = $avatar_image; } else { $this->cached_profile_picdate[$common_filename] = "?rev=".urlencode($r[0]['picdate']); @@ -1352,7 +1352,7 @@ function run_update_function($x) { function check_plugins(&$a) { $r = q("SELECT * FROM `addon` WHERE `installed` = 1"); - if(count($r)) + if(is_filled_array($r)) $installed = $r; else $installed = array(); @@ -1680,7 +1680,7 @@ function current_theme(){ $r = q("select theme from user where uid = %d limit 1", intval($a->profile_uid) ); - if($r) + if(is_filled_array($r)) $page_theme = $r[0]['theme']; } @@ -1793,7 +1793,7 @@ function feed_birthday($uid,$tz) { intval($uid) ); - if($p && count($p)) { + if(is_filled_array($p)) { $tmp_dob = substr($p[0]['dob'],5); if(intval($tmp_dob)) { $y = datetime_convert($tz,$tz,'now','Y'); @@ -1838,7 +1838,7 @@ function load_contact_links($uid) { $r = q("SELECT `id`,`network`,`url`,`thumb`, `rel` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `thumb` != ''", intval($uid) ); - if(count($r)) { + if(is_filled_array($r)) { foreach($r as $rr){ $url = normalise_link($rr['url']); $ret[$url] = $rr; diff --git a/index.php b/index.php index e364389b2c..e03d38a0c2 100644 --- a/index.php +++ b/index.php @@ -107,7 +107,7 @@ if (x($_SESSION,'authenticated') && !x($_SESSION,'language')) { // we didn't loaded user data yet, but we need user language $r = q("SELECT language FROM user WHERE uid=%d", intval($_SESSION['uid'])); $_SESSION['language'] = $lang; - if (count($r)>0) $_SESSION['language'] = $r[0]['language']; + if (is_filled_array($r)) $_SESSION['language'] = $r[0]['language']; } if((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) { From 1f2bf81844f5a319c74d2566eb92e281001dffa7 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:27:38 +0100 Subject: [PATCH 12/30] No need to set $a->theme_info = array() everywhere if you can define it in App itself. Signed-off-by: Roland Haeder --- boot.php | 5 +++-- view/theme/decaf-mobile/theme.php | 1 - view/theme/duepuntozero/theme.php | 1 - view/theme/facepark/theme.php | 1 - view/theme/frost-mobile/theme.php | 1 - view/theme/frost/theme.php | 1 - view/theme/quattro/theme.php | 2 -- view/theme/smoothly/theme.php | 1 - view/theme/vier/theme.php | 2 -- 9 files changed, 3 insertions(+), 12 deletions(-) diff --git a/boot.php b/boot.php index d82669f231..4b2e83f18a 100644 --- a/boot.php +++ b/boot.php @@ -465,11 +465,12 @@ class App { public $plugins; public $apps = array(); public $identities; - public $is_mobile; - public $is_tablet; + public $is_mobile = false; + public $is_tablet = false; public $is_friendica_app; public $performance = array(); public $callstack = array(); + public $theme_info = array(); public $nav_sel; diff --git a/view/theme/decaf-mobile/theme.php b/view/theme/decaf-mobile/theme.php index 1a32fb724d..9b1c1daa61 100644 --- a/view/theme/decaf-mobile/theme.php +++ b/view/theme/decaf-mobile/theme.php @@ -10,7 +10,6 @@ */ function decaf_mobile_init(&$a) { - $a->theme_info = array(); $a->sourcename = 'Friendica mobile web'; $a->videowidth = 250; $a->videoheight = 200; diff --git a/view/theme/duepuntozero/theme.php b/view/theme/duepuntozero/theme.php index ba3f25d3e2..50d57f91e5 100644 --- a/view/theme/duepuntozero/theme.php +++ b/view/theme/duepuntozero/theme.php @@ -2,7 +2,6 @@ function duepuntozero_init(&$a) { -$a->theme_info = array(); set_template_engine($a, 'smarty3'); $colorset = get_pconfig( local_user(), 'duepuntozero','colorset'); diff --git a/view/theme/facepark/theme.php b/view/theme/facepark/theme.php index e7203c6641..e6255f118a 100644 --- a/view/theme/facepark/theme.php +++ b/view/theme/facepark/theme.php @@ -1,7 +1,6 @@ theme_info = array(); set_template_engine($a, 'smarty3'); $a->page['htmlhead'] .= <<< EOT diff --git a/view/theme/frost-mobile/theme.php b/view/theme/frost-mobile/theme.php index beec924934..29a990f7b8 100644 --- a/view/theme/frost-mobile/theme.php +++ b/view/theme/frost-mobile/theme.php @@ -10,7 +10,6 @@ */ function frost_mobile_init(&$a) { - $a->theme_info = array(); $a->sourcename = 'Friendica mobile web'; $a->videowidth = 250; $a->videoheight = 200; diff --git a/view/theme/frost/theme.php b/view/theme/frost/theme.php index 868a840dee..1093a04729 100644 --- a/view/theme/frost/theme.php +++ b/view/theme/frost/theme.php @@ -10,7 +10,6 @@ */ function frost_init(&$a) { - $a->theme_info = array(); $a->videowidth = 400; $a->videoheight = 330; $a->theme_thread_allow = false; diff --git a/view/theme/quattro/theme.php b/view/theme/quattro/theme.php index a1cd29ee72..0b67c6b49a 100644 --- a/view/theme/quattro/theme.php +++ b/view/theme/quattro/theme.php @@ -8,8 +8,6 @@ */ function quattro_init(&$a) { - $a->theme_info = array(); - $a->page['htmlhead'] .= ''; $a->page['htmlhead'] .= '';; } diff --git a/view/theme/smoothly/theme.php b/view/theme/smoothly/theme.php index d3ebbc1d15..0dae3a6e47 100644 --- a/view/theme/smoothly/theme.php +++ b/view/theme/smoothly/theme.php @@ -11,7 +11,6 @@ */ function smoothly_init(&$a) { - $a->theme_info = array(); set_template_engine($a, 'smarty3'); $cssFile = null; diff --git a/view/theme/vier/theme.php b/view/theme/vier/theme.php index 7f6ead079f..925ac76a1f 100644 --- a/view/theme/vier/theme.php +++ b/view/theme/vier/theme.php @@ -19,8 +19,6 @@ function vier_init(&$a) { set_template_engine($a, 'smarty3'); - $a->theme_info = array(); - if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()) { vier_community_info(); From 0142ff7f0f93b5120daf7b0f60a11b1717f711c2 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:32:19 +0100 Subject: [PATCH 13/30] Prevent some E_NOTICE in boot.php Signed-off-by: Roland Haeder --- boot.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/boot.php b/boot.php index 4b2e83f18a..0a2f5c50cd 100644 --- a/boot.php +++ b/boot.php @@ -1047,11 +1047,21 @@ class App { function save_timestamp($stamp, $value) { $duration = (float)(microtime(true)-$stamp); + if (!isset($this->performance[$value])) { + // Prevent ugly E_NOTICE + $this->performance[$value] = 0; + } + $this->performance[$value] += (float)$duration; $this->performance["marktime"] += (float)$duration; $callstack = $this->callstack(); + if (!isset($this->callstack[$value][$callstack])) { + // Prevent ugly E_NOTICE + $this->callstack[$value][$callstack] = 0; + } + $this->callstack[$value][$callstack] += (float)$duration; } From 118d4280135755d6054295ea89467975be9cae07 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:36:23 +0100 Subject: [PATCH 14/30] Prevent some E_NOTICE in identity.php Signed-off-by: Roland Haeder --- include/identity.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/identity.php b/include/identity.php index aba69bae49..888a09ee6f 100644 --- a/include/identity.php +++ b/include/identity.php @@ -237,6 +237,7 @@ function profile_sidebar($profile, $block = 0) { if ($connect AND ($profile['network'] != NETWORK_DFRN) AND !isset($profile['remoteconnect'])) $connect = false; + $remoteconnect = NULL; if (isset($profile['remoteconnect'])) $remoteconnect = $profile['remoteconnect']; @@ -292,9 +293,9 @@ function profile_sidebar($profile, $block = 0) { // check if profile is a forum if((intval($profile['page-flags']) == PAGE_COMMUNITY) || (intval($profile['page-flags']) == PAGE_PRVGROUP) - || (intval($profile['forum'])) - || (intval($profile['prv'])) - || (intval($profile['community']))) + || (isset($profile['forum']) && intval($profile['forum'])) + || (isset($profile['prv']) && intval($profile['prv'])) + || (isset($profile['community']) && intval($profile['community']))) $account_type = t('Forum'); else $account_type = ""; From cf50bb34710de6845ab0a5fa6b289de7dee8d630 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:42:55 +0100 Subject: [PATCH 15/30] More logging in case of errors + logged network type + added TODO (for ugly E_NOTICE). Signed-off-by: Roland Haeder --- mod/dfrn_request.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 2741ad59b4..82886a6efa 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -42,8 +42,10 @@ function dfrn_request_init(&$a) { if(! function_exists('dfrn_request_post')) { function dfrn_request_post(&$a) { - if(($a->argc != 2) || (! count($a->profile))) + if(($a->argc != 2) || (! count($a->profile))) { + logger('Wrong count of argc or profiles: argc=' . $a->argc . ',profile()=' . count($a->profile)); return; + } if(x($_POST, 'cancel')) { @@ -461,7 +463,7 @@ function dfrn_request_post(&$a) { $network = NETWORK_DFRN; } - logger('dfrn_request: url: ' . $url); + logger('dfrn_request: url: ' . $url . ',network=' . $network, LOGGER_DEBUG); if($network === NETWORK_DFRN) { $ret = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `self` = 0 LIMIT 1", @@ -825,6 +827,7 @@ function dfrn_request_content(&$a) { else $tpl = get_markup_template('auto_request.tpl'); + // TODO This .= triggers an E_NOTICE, really needed? $page_desc .= t("Please enter your 'Identity Address' from one of the following supported communications networks:"); // see if we are allowed to have NETWORK_MAIL2 contacts @@ -850,6 +853,7 @@ function dfrn_request_content(&$a) { get_server() ); + // TODO This .= triggers an E_NOTICE, really needed? $o .= replace_macros($tpl,array( '$header' => t('Friend/Connection Request'), '$desc' => t('Examples: jojo@demo.friendica.com, http://demo.friendica.com/profile/jojo, testuser@identi.ca'), From 2247d85b28e681ba4dd0f1f9de6179e019c9733e Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:49:07 +0100 Subject: [PATCH 16/30] Don't miss to add exit() after header('Location: bla') as header() does *NOT* exit the script quickly enough. Always use an explicit exit() or you get real trouble. Signed-off-by: Roland Haeder --- index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index e364389b2c..625c2d82dc 100644 --- a/index.php +++ b/index.php @@ -72,7 +72,8 @@ if(!$install) { (intval(get_config('system','ssl_policy')) == SSL_POLICY_FULL) AND (substr($a->get_baseurl(), 0, 8) == "https://")) { header("HTTP/1.1 302 Moved Temporarily"); - header("location: ".$a->get_baseurl()."/".$a->query_string); + header("Location: ".$a->get_baseurl()."/".$a->query_string); + exit(); } require_once("include/session.php"); From 0510b31b7b933293396b6d1611a2712c39183ef4 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:49:56 +0100 Subject: [PATCH 17/30] and or are not self-closing tags. Signed-off-by: Roland Haeder --- view/templates/dfrn_request.tpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/view/templates/dfrn_request.tpl b/view/templates/dfrn_request.tpl index 3b96d3eefd..5225bd60b2 100644 --- a/view/templates/dfrn_request.tpl +++ b/view/templates/dfrn_request.tpl @@ -18,13 +18,13 @@ {{/if}} {{if $request}} - + {{else}} - + {{/if}} {{if $photo}} - + {{/if}} {{if $url}}
{{$url_label}}
{{$url}}
{{/if}} From 0c1cc0d32f949d566820a243eb2ebb3d622fc994 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:33:54 +0100 Subject: [PATCH 18/30] Introduced is_filled_array() + added some missing array initialization Signed-off-by: Roland Haeder --- boot.php | 4 ++++ mod/message.php | 10 ++++++---- mod/ping.php | 25 +++++++++++++------------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/boot.php b/boot.php index 0a2f5c50cd..a1f29398f6 100644 --- a/boot.php +++ b/boot.php @@ -2149,3 +2149,7 @@ function argv($x) { return ''; } + +function is_filled_array ($array) { + return (is_array($array) && count($array) > 0); +} diff --git a/mod/message.php b/mod/message.php index 734bf34710..6e176f7123 100644 --- a/mod/message.php +++ b/mod/message.php @@ -8,7 +8,7 @@ function message_init(&$a) { $tabs = ''; if ($a->argc >1 && is_numeric($a->argv[1])) { - $tabs = render_messages(get_messages(local_user(),0,5), 'mail_list.tpl'); + $tabs = render_messages(get_messages(local_user(),0,5), 'mail_list.tpl'); } $new = array( @@ -360,11 +360,13 @@ function message_content(&$a) { dbesc($myprofile) ); - if(count($r)) $a->set_pager_total($r[0]['total']); + if (is_filled_array($r)) { + $a->set_pager_total($r[0]['total']); + } $r = get_messages(local_user(), $a->pager['start'], $a->pager['itemspage']); - if(! count($r)) { + if(! is_filled_array($r)) { info( t('No messages.') . EOL); return $o; } @@ -542,7 +544,7 @@ function get_messages($user, $lstart, $lend) { ); } -function render_messages($msg, $t) { +function render_messages(array $msg, $t) { $a = get_app(); diff --git a/mod/ping.php b/mod/ping.php index 2eb94576b3..8deab28ed2 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -32,6 +32,8 @@ function ping_init(&$a) { $dislikes = array(); $friends = array(); $posts = array(); + $regs = array(); + $mails = array(); $home = 0; $network = 0; @@ -49,7 +51,7 @@ function ping_init(&$a) { intval(local_user()), intval(local_user()) ); - if(count($r)) { + if(is_filled_array($r)) { $arr = array('items' => $r); call_hooks('network_ping', $arr); @@ -116,8 +118,6 @@ function ping_init(&$a) { $intro = count($intros1) + count($intros2); $intros = $intros1+$intros2; - - $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ; $mails = q("SELECT * FROM `mail` WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ", @@ -150,7 +150,7 @@ function ping_init(&$a) { dbesc(datetime_convert('UTC','UTC','now')) ); - if($ev && count($ev)) { + if(is_filled_array($ev)) { $all_events = intval($ev[0]['total']); if($all_events) { @@ -219,7 +219,7 @@ function ping_init(&$a) { $home\r\n"; if ($register!=0) echo "$register"; - if (count($groups_unseen)) { + if ( is_filled_array($groups_unseen) ) { echo ''; foreach ($groups_unseen as $it) if ($it['count'] > 0) @@ -228,7 +228,7 @@ function ping_init(&$a) { echo ""; } - if (count($forums_unseen)) { + if ( is_filled_array($forums_unseen) ) { echo ''; foreach ($forums_unseen as $it) if ($it['count'] > 0) @@ -245,8 +245,8 @@ function ping_init(&$a) { $birthdays_today\r\n"; - if(count($notifs) && (! $sysnotify)) { - foreach($notifs as $zz) { + if (is_filled_array($notifs) && (! $sysnotify)) { + foreach ($notifs as $zz) { if($zz['seen'] == 0) $sysnotify ++; } @@ -255,7 +255,7 @@ function ping_init(&$a) { echo ' '; // merge all notification types in one array - if ($intro>0){ + if ( is_filled_array($intros) ) { foreach ($intros as $i) { $n = array( 'href' => $a->get_baseurl().'/notifications/intros/'.$i['id'], @@ -270,7 +270,7 @@ function ping_init(&$a) { } } - if ($mail>0){ + if ( is_filled_array($mails) ) { foreach ($mails as $i) { $n = array( 'href' => $a->get_baseurl().'/message/'.$i['id'], @@ -285,7 +285,7 @@ function ping_init(&$a) { } } - if ($register>0){ + if ( is_filled_array($regs) ) { foreach ($regs as $i) { $n = array( 'href' => $a->get_baseurl().'/admin/users/', @@ -299,6 +299,7 @@ function ping_init(&$a) { $notifs[] = $n; } } + // sort notifications by $[]['date'] $sort_function = function($a, $b) { $adate = date($a['date']); @@ -310,7 +311,7 @@ function ping_init(&$a) { }; usort($notifs, $sort_function); - if(count($notifs)) { + if( is_filled_array($notifs) ) { foreach($notifs as $n) { echo xmlize($n); } From f05c1e82f0b3c43ece556d86a024147363497397 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:38:02 +0100 Subject: [PATCH 19/30] Also use is_filled_array() here, too. if $contacts is FALSE count() issues are E_WARNING Signed-off-by: Roland Haeder --- include/ForumManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ForumManager.php b/include/ForumManager.php index 6fede0204d..bbf881c9d0 100644 --- a/include/ForumManager.php +++ b/include/ForumManager.php @@ -86,7 +86,7 @@ class ForumManager { $total = count($contacts); $visible_forums = 10; - if(count($contacts)) { + if(is_filled_array($contacts)) { $id = 0; From 51a2d31f545122afa2500b936efdb53c22c0b442 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 18:28:06 +0100 Subject: [PATCH 20/30] Closed TODO: no .= needed here. #2392 Signed-off-by: Roland Haeder --- mod/dfrn_request.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 82886a6efa..5455996069 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -827,8 +827,7 @@ function dfrn_request_content(&$a) { else $tpl = get_markup_template('auto_request.tpl'); - // TODO This .= triggers an E_NOTICE, really needed? - $page_desc .= t("Please enter your 'Identity Address' from one of the following supported communications networks:"); + $page_desc = t("Please enter your 'Identity Address' from one of the following supported communications networks:"); // see if we are allowed to have NETWORK_MAIL2 contacts @@ -853,8 +852,7 @@ function dfrn_request_content(&$a) { get_server() ); - // TODO This .= triggers an E_NOTICE, really needed? - $o .= replace_macros($tpl,array( + $o = replace_macros($tpl,array( '$header' => t('Friend/Connection Request'), '$desc' => t('Examples: jojo@demo.friendica.com, http://demo.friendica.com/profile/jojo, testuser@identi.ca'), '$pls_answer' => t('Please answer the following:'), From 4ec377008db92033c117a66140879f6b1c75afd8 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:33:54 +0100 Subject: [PATCH 21/30] Introduced is_filled_array() + added some missing array initialization Signed-off-by: Roland Haeder --- boot.php | 4 ++++ mod/message.php | 10 ++++++---- mod/ping.php | 25 +++++++++++++------------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/boot.php b/boot.php index 0a2f5c50cd..a1f29398f6 100644 --- a/boot.php +++ b/boot.php @@ -2149,3 +2149,7 @@ function argv($x) { return ''; } + +function is_filled_array ($array) { + return (is_array($array) && count($array) > 0); +} diff --git a/mod/message.php b/mod/message.php index 734bf34710..6e176f7123 100644 --- a/mod/message.php +++ b/mod/message.php @@ -8,7 +8,7 @@ function message_init(&$a) { $tabs = ''; if ($a->argc >1 && is_numeric($a->argv[1])) { - $tabs = render_messages(get_messages(local_user(),0,5), 'mail_list.tpl'); + $tabs = render_messages(get_messages(local_user(),0,5), 'mail_list.tpl'); } $new = array( @@ -360,11 +360,13 @@ function message_content(&$a) { dbesc($myprofile) ); - if(count($r)) $a->set_pager_total($r[0]['total']); + if (is_filled_array($r)) { + $a->set_pager_total($r[0]['total']); + } $r = get_messages(local_user(), $a->pager['start'], $a->pager['itemspage']); - if(! count($r)) { + if(! is_filled_array($r)) { info( t('No messages.') . EOL); return $o; } @@ -542,7 +544,7 @@ function get_messages($user, $lstart, $lend) { ); } -function render_messages($msg, $t) { +function render_messages(array $msg, $t) { $a = get_app(); diff --git a/mod/ping.php b/mod/ping.php index 2eb94576b3..8deab28ed2 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -32,6 +32,8 @@ function ping_init(&$a) { $dislikes = array(); $friends = array(); $posts = array(); + $regs = array(); + $mails = array(); $home = 0; $network = 0; @@ -49,7 +51,7 @@ function ping_init(&$a) { intval(local_user()), intval(local_user()) ); - if(count($r)) { + if(is_filled_array($r)) { $arr = array('items' => $r); call_hooks('network_ping', $arr); @@ -116,8 +118,6 @@ function ping_init(&$a) { $intro = count($intros1) + count($intros2); $intros = $intros1+$intros2; - - $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'] ; $mails = q("SELECT * FROM `mail` WHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ", @@ -150,7 +150,7 @@ function ping_init(&$a) { dbesc(datetime_convert('UTC','UTC','now')) ); - if($ev && count($ev)) { + if(is_filled_array($ev)) { $all_events = intval($ev[0]['total']); if($all_events) { @@ -219,7 +219,7 @@ function ping_init(&$a) { $home\r\n"; if ($register!=0) echo "$register"; - if (count($groups_unseen)) { + if ( is_filled_array($groups_unseen) ) { echo ''; foreach ($groups_unseen as $it) if ($it['count'] > 0) @@ -228,7 +228,7 @@ function ping_init(&$a) { echo ""; } - if (count($forums_unseen)) { + if ( is_filled_array($forums_unseen) ) { echo ''; foreach ($forums_unseen as $it) if ($it['count'] > 0) @@ -245,8 +245,8 @@ function ping_init(&$a) { $birthdays_today\r\n"; - if(count($notifs) && (! $sysnotify)) { - foreach($notifs as $zz) { + if (is_filled_array($notifs) && (! $sysnotify)) { + foreach ($notifs as $zz) { if($zz['seen'] == 0) $sysnotify ++; } @@ -255,7 +255,7 @@ function ping_init(&$a) { echo ' '; // merge all notification types in one array - if ($intro>0){ + if ( is_filled_array($intros) ) { foreach ($intros as $i) { $n = array( 'href' => $a->get_baseurl().'/notifications/intros/'.$i['id'], @@ -270,7 +270,7 @@ function ping_init(&$a) { } } - if ($mail>0){ + if ( is_filled_array($mails) ) { foreach ($mails as $i) { $n = array( 'href' => $a->get_baseurl().'/message/'.$i['id'], @@ -285,7 +285,7 @@ function ping_init(&$a) { } } - if ($register>0){ + if ( is_filled_array($regs) ) { foreach ($regs as $i) { $n = array( 'href' => $a->get_baseurl().'/admin/users/', @@ -299,6 +299,7 @@ function ping_init(&$a) { $notifs[] = $n; } } + // sort notifications by $[]['date'] $sort_function = function($a, $b) { $adate = date($a['date']); @@ -310,7 +311,7 @@ function ping_init(&$a) { }; usort($notifs, $sort_function); - if(count($notifs)) { + if( is_filled_array($notifs) ) { foreach($notifs as $n) { echo xmlize($n); } From 24cbac1a5b6b10882238253822794efca1fb2be3 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:38:02 +0100 Subject: [PATCH 22/30] Also use is_filled_array() here, too. if $contacts is FALSE count() issues are E_WARNING Signed-off-by: Roland Haeder --- include/ForumManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ForumManager.php b/include/ForumManager.php index 6fede0204d..bbf881c9d0 100644 --- a/include/ForumManager.php +++ b/include/ForumManager.php @@ -86,7 +86,7 @@ class ForumManager { $total = count($contacts); $visible_forums = 10; - if(count($contacts)) { + if(is_filled_array($contacts)) { $id = 0; From 8cb011a07ed947a01e34590cf1ea3fe4ee7f3043 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:42:55 +0100 Subject: [PATCH 23/30] More logging in case of errors + logged network type + added TODO (for ugly E_NOTICE). Signed-off-by: Roland Haeder --- mod/dfrn_request.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 2741ad59b4..82886a6efa 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -42,8 +42,10 @@ function dfrn_request_init(&$a) { if(! function_exists('dfrn_request_post')) { function dfrn_request_post(&$a) { - if(($a->argc != 2) || (! count($a->profile))) + if(($a->argc != 2) || (! count($a->profile))) { + logger('Wrong count of argc or profiles: argc=' . $a->argc . ',profile()=' . count($a->profile)); return; + } if(x($_POST, 'cancel')) { @@ -461,7 +463,7 @@ function dfrn_request_post(&$a) { $network = NETWORK_DFRN; } - logger('dfrn_request: url: ' . $url); + logger('dfrn_request: url: ' . $url . ',network=' . $network, LOGGER_DEBUG); if($network === NETWORK_DFRN) { $ret = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `self` = 0 LIMIT 1", @@ -825,6 +827,7 @@ function dfrn_request_content(&$a) { else $tpl = get_markup_template('auto_request.tpl'); + // TODO This .= triggers an E_NOTICE, really needed? $page_desc .= t("Please enter your 'Identity Address' from one of the following supported communications networks:"); // see if we are allowed to have NETWORK_MAIL2 contacts @@ -850,6 +853,7 @@ function dfrn_request_content(&$a) { get_server() ); + // TODO This .= triggers an E_NOTICE, really needed? $o .= replace_macros($tpl,array( '$header' => t('Friend/Connection Request'), '$desc' => t('Examples: jojo@demo.friendica.com, http://demo.friendica.com/profile/jojo, testuser@identi.ca'), From 2d154ae72fef27c846c570fd0f362376dd5e10b1 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 18:28:06 +0100 Subject: [PATCH 24/30] Closed TODO: no .= needed here. #2392 Signed-off-by: Roland Haeder --- mod/dfrn_request.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 82886a6efa..5455996069 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -827,8 +827,7 @@ function dfrn_request_content(&$a) { else $tpl = get_markup_template('auto_request.tpl'); - // TODO This .= triggers an E_NOTICE, really needed? - $page_desc .= t("Please enter your 'Identity Address' from one of the following supported communications networks:"); + $page_desc = t("Please enter your 'Identity Address' from one of the following supported communications networks:"); // see if we are allowed to have NETWORK_MAIL2 contacts @@ -853,8 +852,7 @@ function dfrn_request_content(&$a) { get_server() ); - // TODO This .= triggers an E_NOTICE, really needed? - $o .= replace_macros($tpl,array( + $o = replace_macros($tpl,array( '$header' => t('Friend/Connection Request'), '$desc' => t('Examples: jojo@demo.friendica.com, http://demo.friendica.com/profile/jojo, testuser@identi.ca'), '$pls_answer' => t('Please answer the following:'), From d88606321dd9c8d2f43d8f24789bfaad9f9b346d Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 4 Mar 2016 22:39:08 +0100 Subject: [PATCH 25/30] Just easier code ... Signed-off-by: Roland Haeder --- include/poller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/poller.php b/include/poller.php index 755862eb6b..558eda25ff 100644 --- a/include/poller.php +++ b/include/poller.php @@ -206,7 +206,7 @@ function poller_max_connections_reached() { function poller_kill_stale_workers() { $r = q("SELECT `pid`, `executed` FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'"); - if (!is_array($r) || count($r) == 0) { + if (!is_filled_array($r)) { // No processing here needed return; } From 5a439a31f3ef58b826ffe21c8972d6373165b8bb Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 4 Mar 2016 22:46:30 +0100 Subject: [PATCH 26/30] Fixes E_WARNING from foreach() because count() seem to return TRUE even when $r is no array ?! Signed-off-by: Roland Haeder --- boot.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/boot.php b/boot.php index a1f29398f6..fdf0fa3aa7 100644 --- a/boot.php +++ b/boot.php @@ -1849,7 +1849,8 @@ function load_contact_links($uid) { $r = q("SELECT `id`,`network`,`url`,`thumb`, `rel` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `thumb` != ''", intval($uid) ); - if(count($r)) { + + if(is_filled_array($r)) { foreach($r as $rr){ $url = normalise_link($rr['url']); $ret[$url] = $rr; From b56a9bfaccbd22a632f71af96120b35fb3246547 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 4 Mar 2016 22:46:30 +0100 Subject: [PATCH 27/30] Fixes E_WARNING from foreach() because count() seem to return TRUE even when $r is no array ?! Signed-off-by: Roland Haeder --- boot.php | 1 + 1 file changed, 1 insertion(+) diff --git a/boot.php b/boot.php index b049099ea8..ea9f7f9e0c 100644 --- a/boot.php +++ b/boot.php @@ -1838,6 +1838,7 @@ function load_contact_links($uid) { $r = q("SELECT `id`,`network`,`url`,`thumb`, `rel` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `thumb` != ''", intval($uid) ); + if(is_filled_array($r)) { foreach($r as $rr){ $url = normalise_link($rr['url']); From 9cfc249b12b3d8b756cc914b0a03a17957e49a77 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 12 Mar 2016 18:54:55 +0100 Subject: [PATCH 28/30] Moved is_filled_array() to both dba classes and named it is_result(). Please see ticket #2390 for full discussion. Signed-off-by: Roland Haeder --- boot.php | 14 +++++--------- include/ForumManager.php | 2 +- include/dba.php | 11 ++++++++++- include/dba_pdo.php | 10 ++++++++++ include/poller.php | 2 +- index.php | 2 +- mod/message.php | 4 ++-- mod/ping.php | 18 +++++++++--------- 8 files changed, 39 insertions(+), 24 deletions(-) diff --git a/boot.php b/boot.php index 72d34229e5..a9ff0c30c3 100644 --- a/boot.php +++ b/boot.php @@ -927,7 +927,7 @@ class App { } else { $r = q("SELECT `contact`.`avatar-date` AS picdate FROM `contact` WHERE `contact`.`thumb` like '%%/%s'", $common_filename); - if(! is_filled_array($r)){ + if(! dba::is_result($r)){ $this->cached_profile_image[$avatar_image] = $avatar_image; } else { $this->cached_profile_picdate[$common_filename] = "?rev=".urlencode($r[0]['picdate']); @@ -1412,7 +1412,7 @@ function run_update_function($x) { function check_plugins(&$a) { $r = q("SELECT * FROM `addon` WHERE `installed` = 1"); - if(is_filled_array($r)) + if(dba::is_result($r)) $installed = $r; else $installed = array(); @@ -1743,7 +1743,7 @@ function current_theme(){ $r = q("select theme from user where uid = %d limit 1", intval($a->profile_uid) ); - if(is_filled_array($r)) + if(dba::is_result($r)) $page_theme = $r[0]['theme']; } @@ -1856,7 +1856,7 @@ function feed_birthday($uid,$tz) { intval($uid) ); - if(is_filled_array($p)) { + if(dba::is_result($p)) { $tmp_dob = substr($p[0]['dob'],5); if(intval($tmp_dob)) { $y = datetime_convert($tz,$tz,'now','Y'); @@ -1902,7 +1902,7 @@ function load_contact_links($uid) { intval($uid) ); - if(is_filled_array($r)) { + if(dba::is_result($r)) { foreach($r as $rr){ $url = normalise_link($rr['url']); $ret[$url] = $rr; @@ -2202,7 +2202,3 @@ function argv($x) { return ''; } - -function is_filled_array ($array) { - return (is_array($array) && count($array) > 0); -} diff --git a/include/ForumManager.php b/include/ForumManager.php index bbf881c9d0..99a78be71e 100644 --- a/include/ForumManager.php +++ b/include/ForumManager.php @@ -86,7 +86,7 @@ class ForumManager { $total = count($contacts); $visible_forums = 10; - if(is_filled_array($contacts)) { + if(dba::is_result($contacts)) { $id = 0; diff --git a/include/dba.php b/include/dba.php index cae045d874..3a16c187c7 100644 --- a/include/dba.php +++ b/include/dba.php @@ -230,6 +230,16 @@ class dba { } } + /** + * Checks if $array is a filled array with at least one entry. + * + * @param $array mixed A filled array with at least one entry + * @return Whether $array is a filled array + */ + public function is_result ($array) { + return (is_array($array) && count($array) > 0); + } + function __destruct() { if ($this->db) if($this->mysqli) @@ -340,4 +350,3 @@ function dbesc_array(&$arr) { function dba_timer() { return microtime(true); } - diff --git a/include/dba_pdo.php b/include/dba_pdo.php index 7b720fb6c1..b48aba4487 100644 --- a/include/dba_pdo.php +++ b/include/dba_pdo.php @@ -232,6 +232,16 @@ class dba { } } + /** + * Checks if $array is a filled array with at least one entry. + * + * @param $array mixed A filled array with at least one entry + * @return Whether $array is a filled array + */ + public function is_result ($array) { + return (is_array($array) && count($array) > 0); + } + function __destruct() { if ($this->db) \DDDBL\disconnect(); diff --git a/include/poller.php b/include/poller.php index 0b3d89ab3d..b0e88f73dd 100644 --- a/include/poller.php +++ b/include/poller.php @@ -197,7 +197,7 @@ function poller_max_connections_reached() { function poller_kill_stale_workers() { $r = q("SELECT `pid`, `executed` FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'"); - if (!is_filled_array($r)) { + if (!dba::is_result($r)) { // No processing here needed return; } diff --git a/index.php b/index.php index 841eede0ab..484c276343 100644 --- a/index.php +++ b/index.php @@ -108,7 +108,7 @@ if (x($_SESSION,'authenticated') && !x($_SESSION,'language')) { // we didn't loaded user data yet, but we need user language $r = q("SELECT language FROM user WHERE uid=%d", intval($_SESSION['uid'])); $_SESSION['language'] = $lang; - if (is_filled_array($r)) $_SESSION['language'] = $r[0]['language']; + if (dba::is_result($r)) $_SESSION['language'] = $r[0]['language']; } if((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) { diff --git a/mod/message.php b/mod/message.php index 6e176f7123..b6981cc88c 100644 --- a/mod/message.php +++ b/mod/message.php @@ -360,13 +360,13 @@ function message_content(&$a) { dbesc($myprofile) ); - if (is_filled_array($r)) { + if (dba::is_result($r)) { $a->set_pager_total($r[0]['total']); } $r = get_messages(local_user(), $a->pager['start'], $a->pager['itemspage']); - if(! is_filled_array($r)) { + if(! dba::is_result($r)) { info( t('No messages.') . EOL); return $o; } diff --git a/mod/ping.php b/mod/ping.php index f572b430e8..9338b8b686 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -51,7 +51,7 @@ function ping_init(&$a) { intval(local_user()), intval(local_user()) ); - if(is_filled_array($r)) { + if(dba::is_result($r)) { $arr = array('items' => $r); call_hooks('network_ping', $arr); @@ -150,7 +150,7 @@ function ping_init(&$a) { dbesc(datetime_convert('UTC','UTC','now')) ); - if(is_filled_array($ev)) { + if(dba::is_result($ev)) { $all_events = intval($ev[0]['total']); if($all_events) { @@ -219,7 +219,7 @@ function ping_init(&$a) { $home\r\n"; if ($register!=0) echo "$register"; - if ( is_filled_array($groups_unseen) ) { + if ( dba::is_result($groups_unseen) ) { echo ''; foreach ($groups_unseen as $it) if ($it['count'] > 0) @@ -228,7 +228,7 @@ function ping_init(&$a) { echo ""; } - if ( is_filled_array($forums_unseen) ) { + if ( dba::is_result($forums_unseen) ) { echo ''; foreach ($forums_unseen as $it) if ($it['count'] > 0) @@ -245,7 +245,7 @@ function ping_init(&$a) { $birthdays_today\r\n"; - if (is_filled_array($notifs) && (! $sysnotify)) { + if (dba::is_result($notifs) && (! $sysnotify)) { foreach ($notifs as $zz) { if($zz['seen'] == 0) $sysnotify ++; @@ -255,7 +255,7 @@ function ping_init(&$a) { echo ' '; // merge all notification types in one array - if ( is_filled_array($intros) ) { + if ( dba::is_result($intros) ) { foreach ($intros as $i) { $n = array( 'href' => $a->get_baseurl().'/notifications/intros/'.$i['id'], @@ -270,7 +270,7 @@ function ping_init(&$a) { } } - if ( is_filled_array($mails) ) { + if ( dba::is_result($mails) ) { foreach ($mails as $i) { $n = array( 'href' => $a->get_baseurl().'/message/'.$i['id'], @@ -285,7 +285,7 @@ function ping_init(&$a) { } } - if ( is_filled_array($regs) ) { + if ( dba::is_result($regs) ) { foreach ($regs as $i) { $n = array( 'href' => $a->get_baseurl().'/admin/users/', @@ -311,7 +311,7 @@ function ping_init(&$a) { }; usort($notifs, $sort_function); - if( is_filled_array($notifs) ) { + if( dba::is_result($notifs) ) { foreach($notifs as $n) { echo xmlize($n); } From 7f0ae9843f2e2e1268e6f1913949c7912ce9b534 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 12 Mar 2016 22:54:06 +0100 Subject: [PATCH 29/30] count() didn't notice about FALSE ... #2390 Signed-off-by: Roland Haeder --- mod/profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/profile.php b/mod/profile.php index 26bd395230..c3f58ab528 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -300,7 +300,7 @@ function profile_content(&$a, $update = 0) { $parents_arr = array(); $parents_str = ''; - if(count($r)) { + if (dba::is_result($r)) { foreach($r as $rr) $parents_arr[] = $rr['item_id']; $parents_str = implode(', ', $parents_arr); From 47b591c09a7773ff3eeaa60e53d3508d79bcc129 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 12 Mar 2016 23:02:42 +0100 Subject: [PATCH 30/30] Fixes another warning because of count()'s lazyness. #2390 Signed-off-by: Roland Haeder --- mod/network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/network.php b/mod/network.php index a9f369a894..202be047ea 100644 --- a/mod/network.php +++ b/mod/network.php @@ -792,7 +792,7 @@ function network_content(&$a, $update = 0) { $parents_str = ''; $date_offset = ""; - if(count($r)) { + if(dba::is_result($r)) { foreach($r as $rr) if(! in_array($rr['item_id'],$parents_arr)) $parents_arr[] = $rr['item_id'];