friendica-addons/showmore_dyn/showmore_dyn.php

77 lines
2.7 KiB
PHP
Raw Normal View History

2020-03-12 22:24:54 +00: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 22:24:54 +00:00
use Friendica\DI;
function showmore_dyn_install() {
Hook::register('page_end', 'addon/showmore_dyn.php/showmore_dyn.php', 'showmore_dyn_script');
2020-03-12 22:24:54 +00:00
Hook::register('head' , __FILE__, 'showmore_dyn_head');
2020-03-13 21:09:21 +00:00
Hook::register('footer', __FILE__, 'showmore_dyn_footer');
Hook::register('addon_settings', 'addon/showmore_dyn/showmore_dyn.php', 'showmore_dyn_settings');
Hook::register('addon_settings_post', 'addon/showmore_dyn/showmore_dyn.php', 'showmore_dyn_settings_post');
2020-03-12 22:24:54 +00:00
}
function showmore_dyn_uninstall()
{
Hook::unregister('page_end', 'addon/jappixmini/jappixmini.php', 'jappixmini_script');
2020-03-12 22:24:54 +00:00
Hook::unregister('head' , __FILE__, 'showmore_dyn_head');
2020-03-13 21:09:21 +00:00
Hook::unregister('footer', __FILE__, 'showmore_dyn_footer');
Hook::unregister('addon_settings', 'addon/showmore_dyn/showmore_dyn.php', 'showmore_dyn_settings');
Hook::unregister('addon_settings_post', 'addon/showmore_dyn/showmore_dyn.php', 'showmore_dyn_settings_post');
2020-03-12 22:24:54 +00:00
}
function showmore_dyn_head(App $a, &$b)
{
2020-03-13 21:09:21 +00:00
DI::page()->registerStylesheet(__DIR__ . '/showmore_dyn.css');
2020-03-12 22:24:54 +00:00
}
function showmore_dyn_footer(App $a, &$b)
{
2020-03-13 21:09:21 +00:00
DI::page()->registerFooterScript(__DIR__ . '/showmore_dyn.js');
2020-03-12 22:24:54 +00:00
}
function showmore_dyn_settings_post(){
if(! local_user())
return;
if (isset($_POST['showmore_dyn-submit'])){
$limitHeight = $_POST['showmore_dyn_height'];
DI::pConfig()->set(local_user(), 'showmore_dyn', 'limitHeight', $limitHeight);
}
}
function showmore_dyn_settings(&$a,&$o) {
if(! local_user())
return;
$limitHeight = DI::pConfig()->get(local_user(), 'showmore_dyn', 'limitHeight' );
if ($limitHeight=='') { $limitHeight = 250; DI::pConfig()->set(local_user(), 'showmore_dyn', 'limitHeight', $limitHeight); }
$t = Renderer::getMarkupTemplate("settings.tpl", "addon/showmore_dyn/");
$o .= Renderer::replaceMacros($t, [
'$submit' => DI::l10n()->t('Save Settings'),
'$title' => "Showmore Dynamic",
'$label' => DI::l10n()->t('Limit Height'),
'$limitHeight' => $limitHeight,
]);
}
function showmore_dyn_script() {
$limitHeight = DI::pConfig()->get(local_user(), 'showmore_dyn', 'limitHeight' );
2020-03-14 21:29:11 +00:00
$showmore_dyn_showmore_linktext = DI::l10n()->t('Show more ...');
DI::page()['htmlhead'] .= '<script>var postLimitHeight = ' . intval($limitHeight) . '; var showmore_dyn_showmore_linktext = "' . $showmore_dyn_showmore_linktext . '"</script>';
}