X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=showmore%2Fshowmore.php;h=c0f581ec724a6d8afd0c8b940401df4e5f5fbb82;hb=9e025b4771629487d9db91e32bf2a31b80eb93da;hp=a7b5979b8a219c0b634444ab2843eff22779a5f7;hpb=d836593a3b54a30f961fc17c4e48c622f1e0b8e7;p=friendica-addons.git diff --git a/showmore/showmore.php b/showmore/showmore.php index a7b5979b..c0f581ec 100644 --- a/showmore/showmore.php +++ b/showmore/showmore.php @@ -7,23 +7,15 @@ * based upon NSFW from Mike Macgirvin * */ -use Friendica\Core\Addon; -use Friendica\Core\L10n; -use Friendica\Core\PConfig; +use Friendica\Core\Hook; +use Friendica\DI; use Friendica\Util\Strings; 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() -{ - 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'); + Hook::register('prepare_body', 'addon/showmore/showmore.php', 'showmore_prepare_body'); + Hook::register('addon_settings', 'addon/showmore/showmore.php', 'showmore_addon_settings'); + Hook::register('addon_settings_post', 'addon/showmore/showmore.php', 'showmore_addon_settings_post'); } function showmore_addon_settings(&$a, &$s) @@ -34,30 +26,30 @@ function showmore_addon_settings(&$a, &$s) /* Add our stylesheet to the page so we can make our settings look nice */ - $a->page['htmlhead'] .= ''."\r\n"; + DI::page()['htmlhead'] .= ''."\r\n"; - $enable_checked = (intval(PConfig::get(local_user(), 'showmore', 'disable')) ? '' : ' checked="checked"'); - $chars = PConfig::get(local_user(), 'showmore', 'chars', 1100); + $enable_checked = (intval(DI::pConfig()->get(local_user(), 'showmore', 'disable')) ? '' : ' checked="checked"'); + $chars = DI::pConfig()->get(local_user(), 'showmore', 'chars', 1100); $s .= ''; - $s .= '

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

'; + $s .= '

' . DI::l10n()->t('"Show more" Settings').'

'; $s .= '
'; $s .= ''; return; @@ -70,11 +62,10 @@ function showmore_addon_settings_post(&$a, &$b) } if (!empty($_POST['showmore-submit'])) { - PConfig::set(local_user(), 'showmore', 'chars', trim($_POST['showmore-chars'])); + DI::pConfig()->set(local_user(), 'showmore', 'chars', trim($_POST['showmore-chars'])); $enable = (!empty($_POST['showmore-enable']) ? intval($_POST['showmore-enable']) : 0); $disable = 1-$enable; - PConfig::set(local_user(), 'showmore', 'disable', $disable); - info(L10n::t('Show More Settings saved.') . EOL); + DI::pConfig()->set(local_user(), 'showmore', 'disable', $disable); } } @@ -90,8 +81,9 @@ function get_body_length($body) // We need to get rid of hidden tags (display: none) // Get rid of the warning. It would be better to have some valid html as input - $dom = @DomDocument::loadHTML($body); - $xpath = new DOMXPath($dom); + $doc = new DOMDocument(); + @$doc->loadHTML($body); + $xpath = new DOMXPath($doc); /* * Checking any possible syntax of the style attribute with xpath is impossible @@ -105,7 +97,7 @@ function get_body_length($body) } } // Now we can get the body of our HTML DomDocument, it contains only what is visible - $string = $dom->saveHTML(); + $string = $doc->saveHTML(); $string = strip_tags($string); return strlen($string); @@ -118,11 +110,11 @@ function showmore_prepare_body(\Friendica\App $a, &$hook_data) return; } - if (PConfig::get(local_user(), 'showmore', 'disable')) { + if (DI::pConfig()->get(local_user(), 'showmore', 'disable')) { return; } - $chars = (int) PConfig::get(local_user(), 'showmore', 'chars', 1100); + $chars = (int) DI::pConfig()->get(local_user(), 'showmore', 'chars', 1100); if (get_body_length($hook_data['html']) > $chars) { $found = true; @@ -133,9 +125,9 @@ function showmore_prepare_body(\Friendica\App $a, &$hook_data) if ($found) { $rnd = Strings::getRandomHex(8); - $hook_data['html'] = '' . $shortened . " " . - '' . L10n::t('show more') . '' . - ''; + $hook_data['html'] = '' . + ''; } }