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\Core\Hook ;
2020-03-14 21:09:30 +00:00
use Friendica\Core\Renderer ;
2020-03-12 22:24:54 +00:00
use Friendica\DI ;
2020-03-15 12:34:51 +00:00
function showmore_dyn_install ()
2020-03-12 22:24:54 +00:00
{
2020-03-15 12:34:51 +00: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 22:24:54 +00:00
}
2023-01-14 02:16:09 +00:00
function showmore_dyn_head ( string & $body )
2020-03-12 22:24:54 +00:00
{
2020-03-13 21:09:21 +00:00
DI :: page () -> registerStylesheet ( __DIR__ . '/showmore_dyn.css' );
2020-03-12 22:24:54 +00:00
}
2023-01-14 02:16:09 +00:00
function showmore_dyn_footer ( string & $body )
2020-03-12 22:24:54 +00:00
{
2020-03-13 21:09:21 +00:00
DI :: page () -> registerFooterScript ( __DIR__ . '/showmore_dyn.js' );
2020-03-12 22:24:54 +00:00
}
2020-03-15 12:34:51 +00:00
function showmore_dyn_settings_post ()
{
2022-10-20 21:51:49 +00:00
if ( ! DI :: userSession () -> getLocalUserId ()) {
2020-03-15 12:34:51 +00:00
return ;
}
if ( isset ( $_POST [ 'showmore_dyn-submit' ])) {
2022-10-20 21:51:49 +00:00
DI :: pConfig () -> set ( DI :: userSession () -> getLocalUserId (), 'showmore_dyn' , 'limitHeight' , $_POST [ 'limitHeight' ] ? ? 0 );
2020-03-15 12:34:51 +00:00
}
2020-03-14 21:09:30 +00:00
}
2023-01-14 02:16:09 +00:00
function showmore_dyn_settings ( array & $data )
2020-03-15 12:34:51 +00:00
{
2022-10-20 21:51:49 +00:00
if ( ! DI :: userSession () -> getLocalUserId ()) {
2020-03-15 12:34:51 +00:00
return ;
}
2020-03-14 21:09:30 +00:00
2022-10-20 21:51:49 +00:00
$limitHeight = DI :: pConfig () -> get ( DI :: userSession () -> getLocalUserId (), 'showmore_dyn' , 'limitHeight' , 250 );
DI :: pConfig () -> set ( DI :: userSession () -> getLocalUserId (), 'showmore_dyn' , 'limitHeight' , $limitHeight );
2020-03-14 21:09:30 +00:00
2020-03-15 12:34:51 +00:00
$t = Renderer :: getMarkupTemplate ( 'settings.tpl' , 'addon/showmore_dyn/' );
2021-11-20 09:56:55 +00:00
$html = Renderer :: replaceMacros ( $t , [
2020-12-31 14:16:52 +00:00
'$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' ],
2020-03-15 12:34:51 +00:00
]);
2020-03-14 21:09:30 +00:00
2021-11-20 09:56:55 +00:00
$data = [
'addon' => 'showmore_dyn' ,
'title' => DI :: l10n () -> t ( 'Show More Dynamic' ),
'html' => $html ,
];
2020-03-14 21:09:30 +00:00
}
2020-03-15 12:34:51 +00:00
function showmore_dyn_script ()
{
2022-10-20 21:51:49 +00:00
$limitHeight = intval ( DI :: pConfig () -> get ( DI :: userSession () -> getLocalUserId (), 'showmore_dyn' , 'limitHeight' , 250 ));
2020-12-31 14:16:52 +00:00
$showmore_dyn_showmore_linktext = DI :: l10n () -> t ( 'Show more...' );
2020-03-15 12:34:51 +00:00
DI :: page ()[ 'htmlhead' ] .= <<< EOT
< script >
var postLimitHeight = $limitHeight ;
var showmore_dyn_showmore_linktext = " $showmore_dyn_showmore_linktext " ;
</ script >
EOT ;
2020-03-14 21:09:30 +00:00
}