friendica-addons/showmore_dyn/showmore_dyn.php

77 lines
2 KiB
PHP
Raw Normal View History

2020-03-12 23:24:54 +01:00
<?php
/**
* Name: Showmore Dynamic
* Description: Dynamically limits height of posts
* Version: 1.0
* Author: Christian Wiwie
*
*/
use Friendica\App;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
2020-03-12 23:24:54 +01:00
use Friendica\DI;
2020-03-15 13:34:51 +01:00
function showmore_dyn_install()
2020-03-12 23:24:54 +01:00
{
2020-03-15 13:34:51 +01:00
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');
2020-03-12 23:24:54 +01:00
}
function showmore_dyn_head(App $a, &$b)
{
2020-03-13 22:09:21 +01:00
DI::page()->registerStylesheet(__DIR__ . '/showmore_dyn.css');
2020-03-12 23:24:54 +01:00
}
function showmore_dyn_footer(App $a, &$b)
{
2020-03-13 22:09:21 +01:00
DI::page()->registerFooterScript(__DIR__ . '/showmore_dyn.js');
2020-03-12 23:24:54 +01:00
}
2020-03-15 13:34:51 +01:00
function showmore_dyn_settings_post()
{
if(!local_user()) {
return;
}
if (isset($_POST['showmore_dyn-submit'])) {
DI::pConfig()->set(local_user(), 'showmore_dyn', 'limitHeight', $_POST['limitHeight'] ?? 0);
2020-03-15 13:34:51 +01:00
}
}
2020-03-15 13:38:57 +01:00
function showmore_dyn_settings(App &$a, &$o)
2020-03-15 13:34:51 +01:00
{
if(!local_user()) {
return;
}
2020-03-15 13:34:51 +01:00
$limitHeight = DI::pConfig()->get(local_user(), 'showmore_dyn', 'limitHeight', 250);
DI::pConfig()->set(local_user(), 'showmore_dyn', 'limitHeight', $limitHeight);
2020-03-15 13:34:51 +01:00
$t = Renderer::getMarkupTemplate('settings.tpl', 'addon/showmore_dyn/');
$o .= Renderer::replaceMacros($t, [
'$submit' => DI::l10n()->t('Save Settings'),
'$title' => 'Showmore Dynamic',
'$limitHeight' => ['limitHeight', DI::l10n()->t('Limit Height'), $limitHeight, 'The maximal pixel height of posts, 0 to disable', '', '', 'number'],
2020-03-15 13:34:51 +01:00
]);
}
2020-03-15 13:34:51 +01:00
function showmore_dyn_script()
{
$limitHeight = intval(DI::pConfig()->get(local_user(), 'showmore_dyn', 'limitHeight', 250));
2020-03-14 22:29:11 +01:00
$showmore_dyn_showmore_linktext = DI::l10n()->t('Show more ...');
2020-03-15 13:34:51 +01:00
DI::page()['htmlhead'] .= <<<EOT
<script>
var postLimitHeight = $limitHeight;
var showmore_dyn_showmore_linktext = "$showmore_dyn_showmore_linktext";
</script>
EOT;
}