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\Database\DBA;
18 function showmore_dyn_install()
20 Hook::register('page_end', __FILE__, 'showmore_dyn_script');
21 Hook::register('head', __FILE__, 'showmore_dyn_head');
22 Hook::register('footer', __FILE__, 'showmore_dyn_footer');
23 Hook::register('addon_settings', __FILE__, 'showmore_dyn_settings');
24 Hook::register('addon_settings_post', __FILE__, 'showmore_dyn_settings_post');
27 function showmore_dyn_head(App $a, &$b)
29 DI::page()->registerStylesheet(__DIR__ . '/showmore_dyn.css');
32 function showmore_dyn_footer(App $a, &$b)
34 DI::page()->registerFooterScript(__DIR__ . '/showmore_dyn.js');
37 function showmore_dyn_settings_post()
43 if (isset($_POST['showmore_dyn-submit'])) {
44 $limitHeight = $_POST['limitHeight'];
45 if ($limitHeight && is_numeric($limitHeight)) {
46 DI::pConfig()->set(local_user(), 'showmore_dyn', 'limitHeight', $limitHeight);
51 function showmore_dyn_settings(App &$a, &$o)
57 $limitHeight = DI::pConfig()->get(local_user(), 'showmore_dyn', 'limitHeight', 250);
58 DI::pConfig()->set(local_user(), 'showmore_dyn', 'limitHeight', $limitHeight);
60 $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/showmore_dyn/');
61 $o .= Renderer::replaceMacros($t, [
62 '$submit' => DI::l10n()->t('Save Settings'),
63 '$title' => 'Showmore Dynamic',
64 '$limitHeight' => ['limitHeight', DI::l10n()->t('Limit Height'), $limitHeight, 'The maximal height of posts when collapsed', '', '', 'number'],
69 function showmore_dyn_script()
71 $limitHeight = DI::pConfig()->get(local_user(), 'showmore_dyn', 'limitHeight', 250);
72 $showmore_dyn_showmore_linktext = DI::l10n()->t('Show more ...');
73 DI::page()['htmlhead'] .= <<<EOT
75 var postLimitHeight = $limitHeight;
76 var showmore_dyn_showmore_linktext = "$showmore_dyn_showmore_linktext";