Merge pull request #691 from annando/more-notices

some more notices and some code beautification
This commit is contained in:
Tobias Diekershoff 2018-08-08 09:29:32 +02:00 committed by GitHub
commit 347e4eff14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 105 additions and 107 deletions

View file

@ -76,7 +76,7 @@ function blockem_addon_settings_post(App $a, array &$b)
return; return;
} }
if ($_POST['blockem-submit']) { if (!empty($_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);
} }
@ -183,7 +183,7 @@ EOT;
function blockem_item_photo_menu(App $a, array &$b) function blockem_item_photo_menu(App $a, array &$b)
{ {
if ((! local_user()) || ($b['item']['self'])) { if (!local_user() || $b['item']['self']) {
return; return;
} }

View file

@ -76,9 +76,9 @@ function langfilter_addon_settings_post(App $a, &$b)
return; return;
} }
if ($_POST['langfilter-settings-submit']) { if (!empty($_POST['langfilter-settings-submit'])) {
PConfig::set(local_user(), 'langfilter', 'languages', trim($_POST['langfilter_languages'])); 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; $disable = 1 - $enable;
PConfig::set(local_user(), 'langfilter', 'disable', $disable); PConfig::set(local_user(), 'langfilter', 'disable', $disable);
$minconfidence = 0 + $_POST['langfilter_minconfidence']; $minconfidence = 0 + $_POST['langfilter_minconfidence'];

View file

@ -101,7 +101,7 @@ function nsfw_addon_settings_post(&$a, &$b)
return; return;
} }
if ($_POST['nsfw-submit']) { if (!empty($_POST['nsfw-submit'])) {
PConfig::set(local_user(), 'nsfw', 'words', trim($_POST['nsfw-words'])); PConfig::set(local_user(), 'nsfw', 'words', trim($_POST['nsfw-words']));
$enable = (x($_POST, 'nsfw-enable') ? intval($_POST['nsfw-enable']) : 0); $enable = (x($_POST, 'nsfw-enable') ? intval($_POST['nsfw-enable']) : 0);
$disable = 1 - $enable; $disable = 1 - $enable;

View file

@ -11,31 +11,32 @@ use Friendica\Core\Addon;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
function showmore_install() { function showmore_install()
{
Addon::registerHook('prepare_body', 'addon/showmore/showmore.php', 'showmore_prepare_body'); 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', 'addon/showmore/showmore.php', 'showmore_addon_settings');
Addon::registerHook('addon_settings_post', 'addon/showmore/showmore.php', 'showmore_addon_settings_post'); 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('prepare_body', 'addon/showmore/showmore.php', 'showmore_prepare_body');
Addon::unregisterHook('addon_settings', 'addon/showmore/showmore.php', 'showmore_addon_settings'); Addon::unregisterHook('addon_settings', 'addon/showmore/showmore.php', 'showmore_addon_settings');
Addon::unregisterHook('addon_settings_post', 'addon/showmore/showmore.php', 'showmore_addon_settings_post'); Addon::unregisterHook('addon_settings_post', 'addon/showmore/showmore.php', 'showmore_addon_settings_post');
} }
function showmore_addon_settings(&$a,&$s) { function showmore_addon_settings(&$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/showmore/showmore.css'.'" media="all"/>'."\r\n"; $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'.$a->get_baseurl().'/addon/showmore/showmore.css'.'" media="all"/>'."\r\n";
$enable_checked = (intval(PConfig::get(local_user(), 'showmore', 'disable')) ? '' : ' checked="checked"'); $enable_checked = (intval(PConfig::get(local_user(), 'showmore', 'disable')) ? '' : ' checked="checked"');
$chars = PConfig::get(local_user(),'showmore','chars'); $chars = PConfig::get(local_user(), 'showmore', 'chars', 1100);
if(!$chars)
$chars = '1100';
$s .= '<span id="settings_showmore_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_showmore_expanded\'); openClose(\'settings_showmore_inflated\');">'; $s .= '<span id="settings_showmore_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_showmore_expanded\'); openClose(\'settings_showmore_inflated\');">';
$s .= '<h3>' . L10n::t('"Show more" Settings').'</h3>'; $s .= '<h3>' . L10n::t('"Show more" Settings').'</h3>';
@ -61,21 +62,23 @@ function showmore_addon_settings(&$a,&$s) {
return; return;
} }
function showmore_addon_settings_post(&$a,&$b) { function showmore_addon_settings_post(&$a, &$b)
{
if(! local_user()) if (!local_user()) {
return; return;
}
if($_POST['showmore-submit']) { if (!empty($_POST['showmore-submit'])) {
PConfig::set(local_user(), 'showmore', 'chars', trim($_POST['showmore-chars'])); PConfig::set(local_user(), 'showmore', 'chars', trim($_POST['showmore-chars']));
$enable = ((x($_POST,'showmore-enable')) ? intval($_POST['showmore-enable']) : 0); $enable = (x($_POST, 'showmore-enable') ? intval($_POST['showmore-enable']) : 0);
$disable = 1-$enable; $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); info(L10n::t('Show More Settings saved.') . EOL);
} }
} }
function get_body_length($body) { function get_body_length($body)
{
$string = trim($body); $string = trim($body);
// DomDocument doesn't like empty strings // DomDocument doesn't like empty strings
@ -118,10 +121,7 @@ function showmore_prepare_body(\Friendica\App $a, &$hook_data)
return; return;
} }
$chars = (int) PConfig::get(local_user(), 'showmore', 'chars'); $chars = (int) PConfig::get(local_user(), 'showmore', 'chars', 1100);
if (!$chars) {
$chars = 1100;
}
if (get_body_length($hook_data['html']) > $chars) { if (get_body_length($hook_data['html']) > $chars) {
$found = true; $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 = trim($text);
$text = mb_convert_encoding($text, 'HTML-ENTITIES', "UTF-8"); $text = mb_convert_encoding($text, 'HTML-ENTITIES', "UTF-8");
@ -167,5 +168,5 @@ function showmore_cutitem($text, $limit) {
$text = $doc->saveHTML(); $text = $doc->saveHTML();
$text = str_replace(["<html><body>", "</body></html>", $doctype], ["", "", ""], $text); $text = str_replace(["<html><body>", "</body></html>", $doctype], ["", "", ""], $text);
return($text); return $text;
} }

View file

@ -16,18 +16,18 @@ function startpage_install() {
Addon::registerHook('addon_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post'); 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('home_init', 'addon/startpage/startpage.php', 'startpage_home_init');
Addon::unregisterHook('addon_settings', 'addon/startpage/startpage.php', 'startpage_settings'); Addon::unregisterHook('addon_settings', 'addon/startpage/startpage.php', 'startpage_settings');
Addon::unregisterHook('addon_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post'); Addon::unregisterHook('addon_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post');
} }
function startpage_home_init($a, $b)
{
function startpage_home_init($a, $b) { if (!local_user()) {
if(! local_user())
return; return;
}
$page = PConfig::get(local_user(), 'startpage', 'startpage'); $page = PConfig::get(local_user(), 'startpage', 'startpage');
if (strlen($page)) { if (strlen($page)) {
@ -45,12 +45,16 @@ function startpage_home_init($a, $b) {
* *
*/ */
function startpage_settings_post($a,$post) { function startpage_settings_post($a, $post)
if(! local_user()) {
if (!local_user()) {
return; return;
if($_POST['startpage-submit']) }
if (!empty($_POST['startpage-submit'])) {
PConfig::set(local_user(), 'startpage', 'startpage', strip_tags(trim($_POST['startpage']))); 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. * Add our own settings info to the page.
* *
*/ */
function startpage_settings(&$a,&$s) { function startpage_settings(&$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 */
@ -71,7 +76,6 @@ function startpage_settings(&$a,&$s) {
$page = PConfig::get(local_user(), 'startpage', 'startpage'); $page = PConfig::get(local_user(), 'startpage', 'startpage');
/* Add some HTML to the existing form */ /* Add some HTML to the existing form */
$s .= '<span id="settings_startpage_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_startpage_expanded\'); openClose(\'settings_startpage_inflated\');">'; $s .= '<span id="settings_startpage_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_startpage_expanded\'); openClose(\'settings_startpage_inflated\');">';
@ -90,5 +94,4 @@ function startpage_settings(&$a,&$s) {
/* provide a submit button */ /* provide a submit button */
$s .= '<div class="settings-submit-wrapper" ><input type="submit" name="startpage-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>'; $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="startpage-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
} }

View file

@ -1,6 +1,4 @@
<?php <?php
/** /**
* Name: superblock * Name: superblock
* Description: block people * Description: block people
@ -12,33 +10,26 @@ use Friendica\Core\Addon;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
function superblock_install() { function superblock_install()
{
Addon::registerHook('addon_settings', 'addon/superblock/superblock.php', 'superblock_addon_settings'); Addon::registerHook('addon_settings', 'addon/superblock/superblock.php', 'superblock_addon_settings');
Addon::registerHook('addon_settings_post', 'addon/superblock/superblock.php', 'superblock_addon_settings_post'); Addon::registerHook('addon_settings_post', 'addon/superblock/superblock.php', 'superblock_addon_settings_post');
Addon::registerHook('conversation_start', 'addon/superblock/superblock.php', 'superblock_conversation_start'); Addon::registerHook('conversation_start', 'addon/superblock/superblock.php', 'superblock_conversation_start');
Addon::registerHook('item_photo_menu', 'addon/superblock/superblock.php', 'superblock_item_photo_menu'); Addon::registerHook('item_photo_menu', 'addon/superblock/superblock.php', 'superblock_item_photo_menu');
Addon::registerHook('enotify_store', 'addon/superblock/superblock.php', 'superblock_enotify_store'); Addon::registerHook('enotify_store', 'addon/superblock/superblock.php', 'superblock_enotify_store');
} }
function superblock_uninstall()
function superblock_uninstall() { {
Addon::unregisterHook('addon_settings', 'addon/superblock/superblock.php', 'superblock_addon_settings'); Addon::unregisterHook('addon_settings', 'addon/superblock/superblock.php', 'superblock_addon_settings');
Addon::unregisterHook('addon_settings_post', 'addon/superblock/superblock.php', 'superblock_addon_settings_post'); Addon::unregisterHook('addon_settings_post', 'addon/superblock/superblock.php', 'superblock_addon_settings_post');
Addon::unregisterHook('conversation_start', 'addon/superblock/superblock.php', 'superblock_conversation_start'); Addon::unregisterHook('conversation_start', 'addon/superblock/superblock.php', 'superblock_conversation_start');
Addon::unregisterHook('item_photo_menu', 'addon/superblock/superblock.php', 'superblock_item_photo_menu'); Addon::unregisterHook('item_photo_menu', 'addon/superblock/superblock.php', 'superblock_item_photo_menu');
Addon::unregisterHook('enotify_store', 'addon/superblock/superblock.php', 'superblock_enotify_store'); Addon::unregisterHook('enotify_store', 'addon/superblock/superblock.php', 'superblock_enotify_store');
} }
function superblock_addon_settings(&$a, &$s)
{
function superblock_addon_settings(&$a,&$s) {
if (!local_user()) { if (!local_user()) {
return; return;
} }
@ -69,12 +60,13 @@ function superblock_addon_settings(&$a,&$s) {
return; return;
} }
function superblock_addon_settings_post(&$a,&$b) { function superblock_addon_settings_post(&$a, &$b)
{
if(! local_user()) if (!local_user()) {
return; return;
}
if($_POST['superblock-submit']) { if (!empty($_POST['superblock-submit'])) {
PConfig::set(local_user(), 'system', 'blocked',trim($_POST['superblock-words'])); PConfig::set(local_user(), 'system', 'blocked',trim($_POST['superblock-words']));
info(L10n::t('SUPERBLOCK Settings saved.') . EOL); info(L10n::t('SUPERBLOCK Settings saved.') . EOL);
} }
@ -85,8 +77,7 @@ function superblock_enotify_store(&$a,&$b) {
$words = PConfig::get($b['uid'], 'system', 'blocked'); $words = PConfig::get($b['uid'], 'system', 'blocked');
if ($words) { if ($words) {
$arr = explode(',', $words); $arr = explode(',', $words);
} } else {
else {
return; return;
} }
@ -109,10 +100,11 @@ function superblock_enotify_store(&$a,&$b) {
} }
function superblock_conversation_start(&$a,&$b) { function superblock_conversation_start(&$a, &$b)
{
if(! local_user()) if (!local_user()) {
return; return;
}
$words = PConfig::get(local_user(), 'system', 'blocked'); $words = PConfig::get(local_user(), 'system', 'blocked');
if ($words) { if ($words) {
@ -132,10 +124,11 @@ EOT;
} }
function superblock_item_photo_menu(&$a,&$b) { function superblock_item_photo_menu(&$a, &$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'];
@ -154,10 +147,11 @@ function superblock_item_photo_menu(&$a,&$b) {
function superblock_module() {} function superblock_module() {}
function superblock_init(&$a) { function superblock_init(&$a)
{
if(! local_user()) if (!local_user()) {
return; return;
}
$words = PConfig::get(local_user(), 'system', 'blocked'); $words = PConfig::get(local_user(), 'system', 'blocked');