X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=showmore%2Fshowmore.php;h=8e85925aec8e5f19fa0884af4e587f868bfd4b48;hb=3f2cc739369597b2199a5801397443ba03dbfcdc;hp=7583fd33dfd9bb4cbb0e8ed1afcc9b9a65baa125;hpb=203672cf27fc45e264dd0d6dd507ffc4da837e4d;p=friendica-addons.git diff --git a/showmore/showmore.php b/showmore/showmore.php index 7583fd33..8e85925a 100644 --- a/showmore/showmore.php +++ b/showmore/showmore.php @@ -7,7 +7,10 @@ * based upon NSFW from Mike Macgirvin * */ + +use Friendica\App; use Friendica\Core\Hook; +use Friendica\Core\Renderer; use Friendica\DI; use Friendica\Util\Strings; @@ -18,54 +21,41 @@ function showmore_install() Hook::register('addon_settings_post', 'addon/showmore/showmore.php', 'showmore_addon_settings_post'); } -function showmore_addon_settings(&$a, &$s) +function showmore_addon_settings(array &$data) { - if (!local_user()) { + if (!DI::userSession()->getLocalUserId()) { return; } - /* Add our stylesheet to the page so we can make our settings look nice */ - - DI::page()['htmlhead'] .= ''."\r\n"; - - $enable_checked = (intval(DI::pConfig()->get(local_user(), 'showmore', 'disable')) ? '' : ' checked="checked"'); - $chars = DI::pConfig()->get(local_user(), 'showmore', 'chars', 1100); + DI::page()->registerStylesheet(__DIR__ . '/showmore.css', 'all'); - $s .= ''; - $s .= '

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

'; - $s .= '
'; - $s .= ''; - - return; + $data = [ + 'addon' => 'showmore', + 'title' => DI::l10n()->t('"Show more" Settings'), + 'html' => $html, + ]; } -function showmore_addon_settings_post(&$a, &$b) +function showmore_addon_settings_post(array &$b) { - if (!local_user()) { + if (!DI::userSession()->getLocalUserId()) { return; } if (!empty($_POST['showmore-submit'])) { - DI::pConfig()->set(local_user(), 'showmore', 'chars', trim($_POST['showmore-chars'])); + DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'showmore', 'chars', trim($_POST['showmore-chars'])); $enable = (!empty($_POST['showmore-enable']) ? intval($_POST['showmore-enable']) : 0); $disable = 1-$enable; - DI::pConfig()->set(local_user(), 'showmore', 'disable', $disable); + DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'showmore', 'disable', $disable); } } @@ -81,8 +71,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 @@ -96,24 +87,24 @@ 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); } -function showmore_prepare_body(\Friendica\App $a, &$hook_data) +function showmore_prepare_body(&$hook_data) { // No combination with content filters if (!empty($hook_data['filter_reasons'])) { return; } - if (DI::pConfig()->get(local_user(), 'showmore', 'disable')) { + if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'showmore', 'disable')) { return; } - $chars = (int) DI::pConfig()->get(local_user(), 'showmore', 'chars', 1100); + $chars = (int) DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'showmore', 'chars', 1100); if (get_body_length($hook_data['html']) > $chars) { $found = true; @@ -124,9 +115,9 @@ function showmore_prepare_body(\Friendica\App $a, &$hook_data) if ($found) { $rnd = Strings::getRandomHex(8); - $hook_data['html'] = '' . - ''; + $hook_data['html'] = '' . + ''; } }