3 * Name: Showmore Dynamic
4 * Description: Dynamically limits height of posts
6 * Author: Christian Wiwie
11 use Friendica\Core\Hook;
12 use Friendica\Core\L10n;
13 use Friendica\Core\Logger;
14 use Friendica\Core\Renderer;
15 use Friendica\Core\Session;
16 use Friendica\Database\DBA;
19 function showmore_dyn_install()
21 Hook::register('page_end', __FILE__, 'showmore_dyn_script');
22 Hook::register('head', __FILE__, 'showmore_dyn_head');
23 Hook::register('footer', __FILE__, 'showmore_dyn_footer');
24 Hook::register('addon_settings', __FILE__, 'showmore_dyn_settings');
25 Hook::register('addon_settings_post', __FILE__, 'showmore_dyn_settings_post');
28 function showmore_dyn_head(App $a, string &$body)
30 DI::page()->registerStylesheet(__DIR__ . '/showmore_dyn.css');
33 function showmore_dyn_footer(App $a, string &$body)
35 DI::page()->registerFooterScript(__DIR__ . '/showmore_dyn.js');
38 function showmore_dyn_settings_post()
40 if(!Session::getLocalUser()) {
44 if (isset($_POST['showmore_dyn-submit'])) {
45 DI::pConfig()->set(Session::getLocalUser(), 'showmore_dyn', 'limitHeight', $_POST['limitHeight'] ?? 0);
49 function showmore_dyn_settings(App &$a, array &$data)
51 if(!Session::getLocalUser()) {
55 $limitHeight = DI::pConfig()->get(Session::getLocalUser(), 'showmore_dyn', 'limitHeight', 250);
56 DI::pConfig()->set(Session::getLocalUser(), 'showmore_dyn', 'limitHeight', $limitHeight);
58 $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/showmore_dyn/');
59 $html = Renderer::replaceMacros($t, [
60 '$limitHeight' => ['limitHeight', DI::l10n()->t('Limit Height'), $limitHeight, DI::l10n()->t('The maximal pixel height of posts before the Show More link is added, 0 to disable'), '', '', 'number'],
64 'addon' => 'showmore_dyn',
65 'title' => DI::l10n()->t('Show More Dynamic'),
70 function showmore_dyn_script()
72 $limitHeight = intval(DI::pConfig()->get(Session::getLocalUser(), 'showmore_dyn', 'limitHeight', 250));
73 $showmore_dyn_showmore_linktext = DI::l10n()->t('Show more...');
74 DI::page()['htmlhead'] .= <<<EOT
76 var postLimitHeight = $limitHeight;
77 var showmore_dyn_showmore_linktext = "$showmore_dyn_showmore_linktext";