[blockem] Cleanups: (#655)

* [blockem] Cleanups:
- used `use Friendica\App;`
- used proper type-hints
- added spaces and curly braces for better readability

* [blockem] Moved open curly braces to new line

* [blockem]:
- changed checking condition (CR request)
- added/removed more spaces

* [blockem]: converted 4 spaces -> tab
This commit is contained in:
Roland Häder 2018-07-21 03:51:15 +02:00 committed by Hypolite Petovan
parent 81e57250e8
commit aaab504eb2

View file

@ -4,8 +4,10 @@
* Description: Allows users to hide content by collapsing posts and replies. * Description: Allows users to hide content by collapsing posts and replies.
* Version: 1.0 * Version: 1.0
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike> * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
* * Author: Roland Haeder <https://f.haeder.net/roland>
*/ */
use Friendica\App;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
@ -13,40 +15,40 @@ use Friendica\Core\PConfig;
function blockem_install() function blockem_install()
{ {
Addon::registerHook('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter'); Addon::registerHook('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter');
Addon::registerHook('display_item', 'addon/blockem/blockem.php', 'blockem_display_item'); Addon::registerHook('display_item' , 'addon/blockem/blockem.php', 'blockem_display_item');
Addon::registerHook('addon_settings', 'addon/blockem/blockem.php', 'blockem_addon_settings'); Addon::registerHook('addon_settings' , 'addon/blockem/blockem.php', 'blockem_addon_settings');
Addon::registerHook('addon_settings_post', 'addon/blockem/blockem.php', 'blockem_addon_settings_post'); Addon::registerHook('addon_settings_post' , 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
Addon::registerHook('conversation_start', 'addon/blockem/blockem.php', 'blockem_conversation_start'); Addon::registerHook('conversation_start' , 'addon/blockem/blockem.php', 'blockem_conversation_start');
Addon::registerHook('item_photo_menu', 'addon/blockem/blockem.php', 'blockem_item_photo_menu'); Addon::registerHook('item_photo_menu' , 'addon/blockem/blockem.php', 'blockem_item_photo_menu');
Addon::registerHook('enotify_store', 'addon/blockem/blockem.php', 'blockem_enotify_store'); Addon::registerHook('enotify_store' , 'addon/blockem/blockem.php', 'blockem_enotify_store');
} }
function blockem_uninstall() function blockem_uninstall()
{ {
Addon::unregisterHook('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter'); Addon::unregisterHook('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter');
Addon::unregisterHook('prepare_body', 'addon/blockem/blockem.php', 'blockem_prepare_body'); Addon::unregisterHook('prepare_body' , 'addon/blockem/blockem.php', 'blockem_prepare_body');
Addon::unregisterHook('display_item', 'addon/blockem/blockem.php', 'blockem_display_item'); Addon::unregisterHook('display_item' , 'addon/blockem/blockem.php', 'blockem_display_item');
Addon::unregisterHook('addon_settings', 'addon/blockem/blockem.php', 'blockem_addon_settings'); Addon::unregisterHook('addon_settings' , 'addon/blockem/blockem.php', 'blockem_addon_settings');
Addon::unregisterHook('addon_settings_post', 'addon/blockem/blockem.php', 'blockem_addon_settings_post'); Addon::unregisterHook('addon_settings_post' , 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
Addon::unregisterHook('conversation_start', 'addon/blockem/blockem.php', 'blockem_conversation_start'); Addon::unregisterHook('conversation_start' , 'addon/blockem/blockem.php', 'blockem_conversation_start');
Addon::unregisterHook('item_photo_menu', 'addon/blockem/blockem.php', 'blockem_item_photo_menu'); Addon::unregisterHook('item_photo_menu' , 'addon/blockem/blockem.php', 'blockem_item_photo_menu');
Addon::unregisterHook('enotify_store', 'addon/blockem/blockem.php', 'blockem_enotify_store'); Addon::unregisterHook('enotify_store' , 'addon/blockem/blockem.php', 'blockem_enotify_store');
} }
function blockem_addon_settings(&$a, &$s) function blockem_addon_settings (App $a, &$s)
{ {
if (! local_user()) {
if(! local_user())
return; return;
}
/* Add our stylesheet to the page so we can make our settings look nice */ /* Add our stylesheet to the page so we can make our settings look nice */
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/blockem/blockem.css' . '" media="all" />' . "\r\n"; $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/blockem/blockem.css' . '" media="all" />' . "\r\n";
$words = PConfig::get(local_user(), 'blockem', 'words'); $words = PConfig::get(local_user(), 'blockem', 'words');
if(! $words)
if (! $words) {
$words = ''; $words = '';
}
$s .= '<span id="settings_blockem_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_blockem_expanded\'); openClose(\'settings_blockem_inflated\');">'; $s .= '<span id="settings_blockem_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_blockem_expanded\'); openClose(\'settings_blockem_inflated\');">';
$s .= '<h3>' . L10n::t('"Blockem"') . '</h3>'; $s .= '<h3>' . L10n::t('"Blockem"') . '</h3>';
@ -68,52 +70,56 @@ function blockem_addon_settings(&$a, &$s)
} }
function blockem_addon_settings_post(&$a,&$b) { function blockem_addon_settings_post(App $a, array &$b)
{
if(! local_user()) if (! local_user()) {
return; return;
}
if($_POST['blockem-submit']) { if ($_POST['blockem-submit']) {
PConfig::set(local_user(),'blockem','words',trim($_POST['blockem-words'])); PConfig::set(local_user(), 'blockem', 'words', trim($_POST['blockem-words']));
info(L10n::t('BLOCKEM Settings saved.') . EOL); info(L10n::t('BLOCKEM Settings saved.') . EOL);
} }
} }
function blockem_enotify_store(&$a,&$b) { function blockem_enotify_store(App $a, array &$b)
{
$words = PConfig::get($b['uid'], 'blockem', 'words');
$words = PConfig::get($b['uid'],'blockem','words'); if ($words) {
if($words) { $arr = explode(',', $words);
$arr = explode(',',$words); } else {
}
else {
return; return;
} }
$found = false; $found = false;
if(count($arr)) {
foreach($arr as $word) { if (count($arr)) {
if(! strlen(trim($word))) { foreach ($arr as $word) {
if (!strlen(trim($word))) {
continue; continue;
} }
if(link_compare($b['url'],$word)) { if (link_compare($b['url'], $word)) {
$found = true; $found = true;
break; break;
} }
} }
} }
if($found) {
if ($found) {
$b['abort'] = true; $b['abort'] = true;
} }
} }
function blockem_prepare_body_content_filter(\Friendica\App $a, &$hook_data) function blockem_prepare_body_content_filter(App $a, array &$hook_data)
{ {
if (!local_user()) { if (!local_user()) {
return; return;
} }
$profiles_string = null; $profiles_string = null;
if (local_user()) { if (local_user()) {
$profiles_string = PConfig::get(local_user(), 'blockem', 'words'); $profiles_string = PConfig::get(local_user(), 'blockem', 'words');
} }
@ -125,6 +131,7 @@ function blockem_prepare_body_content_filter(\Friendica\App $a, &$hook_data)
} }
$found = false; $found = false;
foreach ($profiles_array as $word) { foreach ($profiles_array as $word) {
if (link_compare($hook_data['item']['author-link'], trim($word))) { if (link_compare($hook_data['item']['author-link'], trim($word))) {
$found = true; $found = true;
@ -137,24 +144,25 @@ function blockem_prepare_body_content_filter(\Friendica\App $a, &$hook_data)
} }
} }
function blockem_display_item(&$a,&$b) { function blockem_display_item(App $a, array &$b = null)
if (empty($b['output']['body'])) { {
return; if (!empty($b['output']['body']) && strstr($b['output']['body'], 'id="blockem-wrap-')) {
}
if(strstr($b['output']['body'],'id="blockem-wrap-'))
$b['output']['thumb'] = $a->get_baseurl() . "/images/person-80.jpg"; $b['output']['thumb'] = $a->get_baseurl() . "/images/person-80.jpg";
}
} }
function blockem_conversation_start(&$a,&$b) { function blockem_conversation_start(App $a, array &$b)
{
if(! local_user()) if (! local_user()) {
return; return;
$words = PConfig::get(local_user(),'blockem','words');
if($words) {
$a->data['blockem'] = explode(',',$words);
} }
$words = PConfig::get(local_user(), 'blockem', 'words');
if ($words) {
$a->data['blockem'] = explode(',', $words);
}
$a->page['htmlhead'] .= <<< EOT $a->page['htmlhead'] .= <<< EOT
<script> <script>
@ -171,59 +179,68 @@ function blockemUnblock(author) {
</script> </script>
EOT; EOT;
} }
function blockem_item_photo_menu(&$a,&$b) { function blockem_item_photo_menu(App $a, array &$b)
{
if((! local_user()) || ($b['item']['self'])) if ((! local_user()) || ($b['item']['self'])) {
return; return;
}
$blocked = false; $blocked = false;
$author = $b['item']['author-link']; $author = $b['item']['author-link'];
if(!empty($a->data['blockem'])) {
if (!empty($a->data['blockem'])) {
foreach($a->data['blockem'] as $bloke) { foreach($a->data['blockem'] as $bloke) {
if(link_compare($bloke,$author)) { if (link_compare($bloke,$author)) {
$blocked = true; $blocked = true;
break; break;
} }
} }
} }
if($blocked) if ($blocked) {
$b['menu'][L10n::t('Unblock Author')] = 'javascript:blockemUnblock(\'' . $author . '\');'; $b['menu'][L10n::t('Unblock Author')] = 'javascript:blockemUnblock(\'' . $author . '\');';
else } else {
$b['menu'][L10n::t('Block Author')] = 'javascript:blockemBlock(\'' . $author . '\');'; $b['menu'][L10n::t('Block Author')] = 'javascript:blockemBlock(\'' . $author . '\');';
}
} }
function blockem_module() {} function blockem_module()
{
}
function blockem_init(App $a)
function blockem_init(&$a) { {
if (! local_user()) {
if(! local_user())
return; return;
}
$words = PConfig::get(local_user(),'blockem','words'); $words = PConfig::get(local_user(), 'blockem', 'words');
if(array_key_exists('block',$_GET) && $_GET['block']) { if (array_key_exists('block', $_GET) && $_GET['block']) {
if(strlen($words)) if (strlen($words)) {
$words .= ','; $words .= ',';
}
$words .= trim($_GET['block']); $words .= trim($_GET['block']);
} }
if(array_key_exists('unblock',$_GET) && $_GET['unblock']) {
if (array_key_exists('unblock', $_GET) && $_GET['unblock']) {
$arr = explode(',',$words); $arr = explode(',',$words);
$newarr = []; $newarr = [];
if(count($arr)) { if (count($arr)) {
foreach($arr as $x) { foreach ($arr as $x) {
if(! link_compare(trim($x),trim($_GET['unblock']))) if (!link_compare(trim($x), trim($_GET['unblock']))) {
$newarr[] = $x; $newarr[] = $x;
} }
} }
$words = implode(',',$newarr);
} }
PConfig::set(local_user(),'blockem','words',$words); $words = implode(',', $newarr);
}
PConfig::set(local_user(), 'blockem', 'words', $words);
info(L10n::t('blockem settings updated') . EOL ); info(L10n::t('blockem settings updated') . EOL );
killme(); killme();
} }