-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathshowmore_dyn.php
75 lines (64 loc) · 2.16 KB
/
showmore_dyn.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Name: Showmore Dynamic
* Description: Dynamically limits height of posts
* Version: 1.0
* Author: Christian Wiwie
*
*/
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\DI;
function showmore_dyn_install()
{
Hook::register('page_end', __FILE__, 'showmore_dyn_script');
Hook::register('head', __FILE__, 'showmore_dyn_head');
Hook::register('footer', __FILE__, 'showmore_dyn_footer');
Hook::register('addon_settings', __FILE__, 'showmore_dyn_settings');
Hook::register('addon_settings_post', __FILE__, 'showmore_dyn_settings_post');
}
function showmore_dyn_head(string &$body)
{
DI::page()->registerStylesheet(__DIR__ . '/showmore_dyn.css');
}
function showmore_dyn_footer(string &$body)
{
DI::page()->registerFooterScript(__DIR__ . '/showmore_dyn.js');
}
function showmore_dyn_settings_post()
{
if(!DI::userSession()->getLocalUserId()) {
return;
}
if (isset($_POST['showmore_dyn-submit'])) {
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'showmore_dyn', 'limitHeight', $_POST['limitHeight'] ?? 0);
}
}
function showmore_dyn_settings(array &$data)
{
if(!DI::userSession()->getLocalUserId()) {
return;
}
$limitHeight = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'showmore_dyn', 'limitHeight', 250);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'showmore_dyn', 'limitHeight', $limitHeight);
$t = Renderer::getMarkupTemplate('settings.tpl', 'addon/showmore_dyn/');
$html = Renderer::replaceMacros($t, [
'$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'],
]);
$data = [
'addon' => 'showmore_dyn',
'title' => DI::l10n()->t('Show More Dynamic'),
'html' => $html,
];
}
function showmore_dyn_script()
{
$limitHeight = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'showmore_dyn', 'limitHeight', 250));
$showmore_dyn_showmore_linktext = DI::l10n()->t('Show more...');
DI::page()['htmlhead'] .= <<<EOT
<script>
var postLimitHeight = $limitHeight;
var showmore_dyn_showmore_linktext = "$showmore_dyn_showmore_linktext";
</script>
EOT;
}