From 7a29893ecb79f55a01b3655b64371ef8bcc4a806 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 8 Aug 2018 06:24:47 +0000 Subject: [PATCH] some more notices and some code beautification --- blockem/blockem.php | 16 +++---- langfilter/langfilter.php | 4 +- nsfw/nsfw.php | 2 +- showmore/showmore.php | 53 ++++++++++----------- startpage/startpage.php | 39 +++++++++------- superblock/superblock.php | 98 ++++++++++++++++++--------------------- 6 files changed, 105 insertions(+), 107 deletions(-) diff --git a/blockem/blockem.php b/blockem/blockem.php index 364156ee..8263fb10 100644 --- a/blockem/blockem.php +++ b/blockem/blockem.php @@ -37,7 +37,7 @@ function blockem_uninstall() function blockem_addon_settings (App $a, &$s) { - if (! local_user()) { + if (!local_user()) { return; } @@ -46,7 +46,7 @@ function blockem_addon_settings (App $a, &$s) $words = PConfig::get(local_user(), 'blockem', 'words'); - if (! $words) { + if (!$words) { $words = ''; } @@ -72,11 +72,11 @@ function blockem_addon_settings (App $a, &$s) function blockem_addon_settings_post(App $a, array &$b) { - if (! local_user()) { + if (!local_user()) { return; } - if ($_POST['blockem-submit']) { + if (!empty($_POST['blockem-submit'])) { PConfig::set(local_user(), 'blockem', 'words', trim($_POST['blockem-words'])); info(L10n::t('BLOCKEM Settings saved.') . EOL); } @@ -153,7 +153,7 @@ function blockem_display_item(App $a, array &$b = null) function blockem_conversation_start(App $a, array &$b) { - if (! local_user()) { + if (!local_user()) { return; } @@ -183,7 +183,7 @@ EOT; function blockem_item_photo_menu(App $a, array &$b) { - if ((! local_user()) || ($b['item']['self'])) { + if (!local_user() || $b['item']['self']) { return; } @@ -211,7 +211,7 @@ function blockem_module() function blockem_init(App $a) { - if (! local_user()) { + if (!local_user()) { return; } @@ -241,6 +241,6 @@ function blockem_init(App $a) } PConfig::set(local_user(), 'blockem', 'words', $words); - info(L10n::t('blockem settings updated') . EOL ); + info(L10n::t('blockem settings updated') . EOL); killme(); } diff --git a/langfilter/langfilter.php b/langfilter/langfilter.php index f22034e2..1f23ceda 100644 --- a/langfilter/langfilter.php +++ b/langfilter/langfilter.php @@ -76,9 +76,9 @@ function langfilter_addon_settings_post(App $a, &$b) return; } - if ($_POST['langfilter-settings-submit']) { + if (!empty($_POST['langfilter-settings-submit'])) { PConfig::set(local_user(), 'langfilter', 'languages', trim($_POST['langfilter_languages'])); - $enable = ((x($_POST, 'langfilter_enable')) ? intval($_POST['langfilter_enable']) : 0); + $enable = (x($_POST, 'langfilter_enable') ? intval($_POST['langfilter_enable']) : 0); $disable = 1 - $enable; PConfig::set(local_user(), 'langfilter', 'disable', $disable); $minconfidence = 0 + $_POST['langfilter_minconfidence']; diff --git a/nsfw/nsfw.php b/nsfw/nsfw.php index 2ea20b4a..bb093249 100644 --- a/nsfw/nsfw.php +++ b/nsfw/nsfw.php @@ -101,7 +101,7 @@ function nsfw_addon_settings_post(&$a, &$b) return; } - if ($_POST['nsfw-submit']) { + if (!empty($_POST['nsfw-submit'])) { PConfig::set(local_user(), 'nsfw', 'words', trim($_POST['nsfw-words'])); $enable = (x($_POST, 'nsfw-enable') ? intval($_POST['nsfw-enable']) : 0); $disable = 1 - $enable; diff --git a/showmore/showmore.php b/showmore/showmore.php index 3673c956..e7140d19 100644 --- a/showmore/showmore.php +++ b/showmore/showmore.php @@ -11,31 +11,32 @@ use Friendica\Core\Addon; use Friendica\Core\L10n; use Friendica\Core\PConfig; -function showmore_install() { +function showmore_install() +{ Addon::registerHook('prepare_body', 'addon/showmore/showmore.php', 'showmore_prepare_body'); Addon::registerHook('addon_settings', 'addon/showmore/showmore.php', 'showmore_addon_settings'); Addon::registerHook('addon_settings_post', 'addon/showmore/showmore.php', 'showmore_addon_settings_post'); } -function showmore_uninstall() { +function showmore_uninstall() +{ Addon::unregisterHook('prepare_body', 'addon/showmore/showmore.php', 'showmore_prepare_body'); Addon::unregisterHook('addon_settings', 'addon/showmore/showmore.php', 'showmore_addon_settings'); Addon::unregisterHook('addon_settings_post', 'addon/showmore/showmore.php', 'showmore_addon_settings_post'); } -function showmore_addon_settings(&$a,&$s) { - - if(! local_user()) +function showmore_addon_settings(&$a, &$s) +{ + if (!local_user()) { return; + } /* Add our stylesheet to the page so we can make our settings look nice */ $a->page['htmlhead'] .= ''."\r\n"; - $enable_checked = (intval(PConfig::get(local_user(),'showmore','disable')) ? '' : ' checked="checked"'); - $chars = PConfig::get(local_user(),'showmore','chars'); - if(!$chars) - $chars = '1100'; + $enable_checked = (intval(PConfig::get(local_user(), 'showmore', 'disable')) ? '' : ' checked="checked"'); + $chars = PConfig::get(local_user(), 'showmore', 'chars', 1100); $s .= ''; $s .= '

' . L10n::t('"Show more" Settings').'

'; @@ -61,25 +62,27 @@ function showmore_addon_settings(&$a,&$s) { return; } -function showmore_addon_settings_post(&$a,&$b) { - - if(! local_user()) +function showmore_addon_settings_post(&$a, &$b) +{ + if (!local_user()) { return; + } - if($_POST['showmore-submit']) { - PConfig::set(local_user(),'showmore','chars',trim($_POST['showmore-chars'])); - $enable = ((x($_POST,'showmore-enable')) ? intval($_POST['showmore-enable']) : 0); + if (!empty($_POST['showmore-submit'])) { + PConfig::set(local_user(), 'showmore', 'chars', trim($_POST['showmore-chars'])); + $enable = (x($_POST, 'showmore-enable') ? intval($_POST['showmore-enable']) : 0); $disable = 1-$enable; - PConfig::set(local_user(),'showmore','disable', $disable); + PConfig::set(local_user(), 'showmore', 'disable', $disable); info(L10n::t('Show More Settings saved.') . EOL); } } -function get_body_length($body) { +function get_body_length($body) +{ $string = trim($body); // DomDocument doesn't like empty strings - if(! strlen($string)) { + if (!strlen($string)) { return 0; } @@ -94,8 +97,8 @@ function get_body_length($body) { * So we just get any element with a style attribute, and check them with a regexp */ $xr = $xpath->query('//*[@style]'); - foreach($xr as $node) { - if(preg_match('/.*display: *none *;.*/',$node->getAttribute('style'))) { + foreach ($xr as $node) { + if (preg_match('/.*display: *none *;.*/',$node->getAttribute('style'))) { // Hidden, remove it from its parent $node->parentNode->removeChild($node); } @@ -118,10 +121,7 @@ function showmore_prepare_body(\Friendica\App $a, &$hook_data) return; } - $chars = (int) PConfig::get(local_user(), 'showmore', 'chars'); - if (!$chars) { - $chars = 1100; - } + $chars = (int) PConfig::get(local_user(), 'showmore', 'chars', 1100); if (get_body_length($hook_data['html']) > $chars) { $found = true; @@ -138,7 +138,8 @@ function showmore_prepare_body(\Friendica\App $a, &$hook_data) } } -function showmore_cutitem($text, $limit) { +function showmore_cutitem($text, $limit) +{ $text = trim($text); $text = mb_convert_encoding($text, 'HTML-ENTITIES', "UTF-8"); @@ -167,5 +168,5 @@ function showmore_cutitem($text, $limit) { $text = $doc->saveHTML(); $text = str_replace(["", "", $doctype], ["", "", ""], $text); - return($text); + return $text; } diff --git a/startpage/startpage.php b/startpage/startpage.php index 840b547e..00079f9c 100644 --- a/startpage/startpage.php +++ b/startpage/startpage.php @@ -16,21 +16,21 @@ function startpage_install() { Addon::registerHook('addon_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post'); } - -function startpage_uninstall() { +function startpage_uninstall() +{ Addon::unregisterHook('home_init', 'addon/startpage/startpage.php', 'startpage_home_init'); Addon::unregisterHook('addon_settings', 'addon/startpage/startpage.php', 'startpage_settings'); Addon::unregisterHook('addon_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post'); } - - -function startpage_home_init($a, $b) { - if(! local_user()) +function startpage_home_init($a, $b) +{ + if (!local_user()) { return; + } - $page = PConfig::get(local_user(),'startpage','startpage'); - if(strlen($page)) { + $page = PConfig::get(local_user(), 'startpage', 'startpage'); + if (strlen($page)) { goaway($page); } return; @@ -45,11 +45,15 @@ function startpage_home_init($a, $b) { * */ -function startpage_settings_post($a,$post) { - if(! local_user()) +function startpage_settings_post($a, $post) +{ + if (!local_user()) { return; - if($_POST['startpage-submit']) - PConfig::set(local_user(),'startpage','startpage',strip_tags(trim($_POST['startpage']))); + } + + if (!empty($_POST['startpage-submit'])) { + PConfig::set(local_user(), 'startpage', 'startpage', strip_tags(trim($_POST['startpage']))); + } } /** @@ -58,10 +62,11 @@ function startpage_settings_post($a,$post) { * Add our own settings info to the page. * */ -function startpage_settings(&$a,&$s) { - - if(! local_user()) +function startpage_settings(&$a, &$s) +{ + if (!local_user()) { return; + } /* Add our stylesheet to the page so we can make our settings look nice */ @@ -69,8 +74,7 @@ function startpage_settings(&$a,&$s) { /* Get the current state of our config variable */ - $page = PConfig::get(local_user(),'startpage','startpage'); - + $page = PConfig::get(local_user(), 'startpage', 'startpage'); /* Add some HTML to the existing form */ @@ -90,5 +94,4 @@ function startpage_settings(&$a,&$s) { /* provide a submit button */ $s .= '
'; - } diff --git a/superblock/superblock.php b/superblock/superblock.php index 96529df8..7a701e7c 100644 --- a/superblock/superblock.php +++ b/superblock/superblock.php @@ -1,6 +1,4 @@ page['htmlhead'] .= '' . "\r\n"; - $words = PConfig::get(local_user(),'system','blocked'); - if(! $words) { + $words = PConfig::get(local_user(), 'system', 'blocked'); + if (!$words) { $words = ''; } @@ -69,54 +60,55 @@ function superblock_addon_settings(&$a,&$s) { return; } -function superblock_addon_settings_post(&$a,&$b) { - - if(! local_user()) +function superblock_addon_settings_post(&$a, &$b) +{ + if (!local_user()) { return; + } - if($_POST['superblock-submit']) { - PConfig::set(local_user(),'system','blocked',trim($_POST['superblock-words'])); + if (!empty($_POST['superblock-submit'])) { + PConfig::set(local_user(), 'system', 'blocked',trim($_POST['superblock-words'])); info(L10n::t('SUPERBLOCK Settings saved.') . EOL); } } function superblock_enotify_store(&$a,&$b) { - $words = PConfig::get($b['uid'],'system','blocked'); - if($words) { - $arr = explode(',',$words); - } - else { + $words = PConfig::get($b['uid'], 'system', 'blocked'); + if ($words) { + $arr = explode(',', $words); + } else { return; } $found = false; - if(count($arr)) { - foreach($arr as $word) { - if(! strlen(trim($word))) { + if (count($arr)) { + foreach ($arr as $word) { + if (!strlen(trim($word))) { continue; } - if(link_compare($b['url'],$word)) { + if (link_compare($b['url'], $word)) { $found = true; break; } } } - if($found) { + if ($found) { $b['abort'] = true; } } -function superblock_conversation_start(&$a,&$b) { - - if(! local_user()) +function superblock_conversation_start(&$a, &$b) +{ + if (!local_user()) { return; + } - $words = PConfig::get(local_user(),'system','blocked'); - if($words) { - $a->data['superblock'] = explode(',',$words); + $words = PConfig::get(local_user(), 'system', 'blocked'); + if ($words) { + $a->data['superblock'] = explode(',', $words); } $a->page['htmlhead'] .= <<< EOT @@ -132,16 +124,17 @@ EOT; } -function superblock_item_photo_menu(&$a,&$b) { - - if((! local_user()) || ($b['item']['self'])) +function superblock_item_photo_menu(&$a, &$b) +{ + if (!local_user() || $b['item']['self']) { return; + } $blocked = false; $author = $b['item']['author-link']; - if(!empty($a->data['superblock'])) { - foreach($a->data['superblock'] as $bloke) { - if(link_compare($bloke,$author)) { + if (!empty($a->data['superblock'])) { + foreach ($a->data['superblock'] as $bloke) { + if (link_compare($bloke, $author)) { $blocked = true; break; } @@ -154,20 +147,21 @@ function superblock_item_photo_menu(&$a,&$b) { function superblock_module() {} -function superblock_init(&$a) { - - if(! local_user()) +function superblock_init(&$a) +{ + if (!local_user()) { return; + } - $words = PConfig::get(local_user(),'system','blocked'); + $words = PConfig::get(local_user(), 'system', 'blocked'); - if(array_key_exists('block',$_GET) && $_GET['block']) { - if(strlen($words)) + if (array_key_exists('block', $_GET) && $_GET['block']) { + if (strlen($words)) $words .= ','; $words .= trim($_GET['block']); } - PConfig::set(local_user(),'system','blocked',$words); + PConfig::set(local_user(), 'system', 'blocked', $words); info(L10n::t('superblock settings updated') . EOL ); killme(); }