From ed45145415b2789f06632a9b75b53aa87c5e377e Mon Sep 17 00:00:00 2001 From: Christian Wiwie Date: Sat, 14 Mar 2020 22:09:30 +0100 Subject: [PATCH] #8374: Making postLimitHeight an addon parameter --- showmore_dyn/showmore_dyn.css | 5 ---- showmore_dyn/showmore_dyn.js | 6 ++++- showmore_dyn/showmore_dyn.php | 50 +++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/showmore_dyn/showmore_dyn.css b/showmore_dyn/showmore_dyn.css index 6f9d59bc..76bb7555 100644 --- a/showmore_dyn/showmore_dyn.css +++ b/showmore_dyn/showmore_dyn.css @@ -1,8 +1,3 @@ -.limit-height { - max-height: 250px; - overflow: hidden; -} - .wall-item-body-toggle { width: 100%; text-align: center; diff --git a/showmore_dyn/showmore_dyn.js b/showmore_dyn/showmore_dyn.js index 7d91c337..d60529d9 100644 --- a/showmore_dyn/showmore_dyn.js +++ b/showmore_dyn/showmore_dyn.js @@ -1,4 +1,8 @@ $(document).ready(function(){ + $("head").append(''); + var newStyleElement = $("head").children(':last'); + newStyleElement.html('.limit-height{max-height: ' + postLimitHeight + 'px; overflow: hidden;}'); + handleNewWallItemBodies(); document.addEventListener("postprocess_liveupdate", function() { @@ -60,7 +64,7 @@ function processHeightLimit($item) { var itemId = $item.data("item-id"); var $toggle = $("#wall-item-body-toggle-" + itemId); - if ($item.height() < 250) { + if ($item.height() < postLimitHeight) { $item.removeClass("limit-height"); $toggle.hide(); return false; diff --git a/showmore_dyn/showmore_dyn.php b/showmore_dyn/showmore_dyn.php index 4840201d..b38231fa 100644 --- a/showmore_dyn/showmore_dyn.php +++ b/showmore_dyn/showmore_dyn.php @@ -9,17 +9,27 @@ use Friendica\App; use Friendica\Core\Hook; +use Friendica\Core\L10n; +use Friendica\Core\Logger; +use Friendica\Core\Renderer; +use Friendica\Database\DBA; use Friendica\DI; function showmore_dyn_install() { + Hook::register('page_end', 'addon/showmore_dyn.php/showmore_dyn.php', 'showmore_dyn_script'); Hook::register('head' , __FILE__, 'showmore_dyn_head'); 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'); } function showmore_dyn_uninstall() { + Hook::unregister('page_end', 'addon/jappixmini/jappixmini.php', 'jappixmini_script'); Hook::unregister('head' , __FILE__, 'showmore_dyn_head'); 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'); } function showmore_dyn_head(App $a, &$b) @@ -32,3 +42,43 @@ function showmore_dyn_footer(App $a, &$b) DI::page()->registerFooterScript(__DIR__ . '/showmore_dyn.js'); } +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); + +/* + $str=file_get_contents('addon/showmore_dyn/showmore_dyn.css'); + $str=preg_replace("/(max-height: )\d+(px;)/i", "max-height: " . $limitHeight . "px;" ,$str); + file_put_contents('addon/showmore_dyn/showmore_dyn.css', $str); + + $str=file_get_contents('addon/showmore_dyn/showmore_dyn.js'); + $str=preg_replace('/if \(\$item.height\(\) \< \d+\) \{/i', 'if ($item.height() < ' . $limitHeight . ') {' ,$str); + file_put_contents('addon/showmore_dyn/showmore_dyn2.js', $str);*/ + } +} + +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' ); + DI::page()['htmlhead'] .= ''; +}