From f7a02601290ff37a5081af30c3571ee0df4fa79a Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:27:38 +0100 Subject: [PATCH 01/17] 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 02/17] 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 03/17] 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 04/17] 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 05/17] 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 06/17] 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 07/17] 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 08/17]
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 1f2bf81844f5a319c74d2566eb92e281001dffa7 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 1 Mar 2016 14:27:38 +0100 Subject: [PATCH 09/17] 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 10/17] 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 11/17] 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 12/17] 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 13/17] 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 14/17] 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 15/17] 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 16/17] 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 17/17] 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:'),