From 9be6dfadba85819aa0dadf7df7082331f14e88d6 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Mon, 23 Oct 2017 15:16:23 +0200 Subject: [PATCH 1/6] frio: use cached css if no settings (or file) have changed --- view/theme/frio/config.php | 90 +++++----- view/theme/frio/style.php | 171 +++++++++++-------- view/theme/frio/templates/theme_settings.tpl | 2 +- view/theme/frio/theme.php | 2 +- 4 files changed, 152 insertions(+), 113 deletions(-) diff --git a/view/theme/frio/config.php b/view/theme/frio/config.php index 6e5aca1bad..e3164697ba 100644 --- a/view/theme/frio/config.php +++ b/view/theme/frio/config.php @@ -1,81 +1,85 @@ " . t("Note: "). "".t("Check image permissions if all users are allowed to visit the image"); - + $background_image_help = "" . t("Note"). ": ".t("Check image permissions if all users are allowed to visit the image"); $t = get_markup_template('theme_settings.tpl'); $o .= replace_macros($t, array( - '$submit' => t('Submit'), - '$baseurl' => System::baseUrl(), - '$title' => t("Theme settings"), - '$schema' => array('frio_schema', t("Select scheme"), $arr["schema"], '', $scheme_choices), - '$nav_bg' => array_key_exists("nav_bg", $disable) ? "" : array('frio_nav_bg', t('Navigation bar background color'), $arr['nav_bg']), - '$nav_icon_color' => array_key_exists("nav_icon_color", $disable) ? "" : array('frio_nav_icon_color', t('Navigation bar icon color '), $arr['nav_icon_color']), - '$link_color' => array_key_exists("link_color", $disable) ? "" : array('frio_link_color', t('Link color'), $arr['link_color'], '', $link_colors), - '$bgcolor' => array_key_exists("bgcolor", $disable) ? "" : array('frio_background_color', t('Set the background color'), $arr['bgcolor']), - '$contentbg_transp' => array_key_exists("contentbg_transp", $disable) ? "" : array('frio_contentbg_transp', t("Content background transparency"), ($arr["contentbg_transp"] ? $arr["contentbg_transp"] : 0 )), - '$background_image' => array_key_exists("background_image", $disable ) ? "" : array('frio_background_image', t('Set the background image'), $arr['background_image'], $background_image_help), - '$bg_image_options' => Image::get_options($arr), + '$submit' => t('Submit'), + '$baseurl' => System::baseUrl(), + '$title' => t("Theme settings"), + '$schema' => array('frio_schema', t("Select scheme"), $arr["schema"], '', $scheme_choices), + '$nav_bg' => array_key_exists("nav_bg", $disable) ? "" : array('frio_nav_bg', t('Navigation bar background color'), $arr['nav_bg']), + '$nav_icon_color' => array_key_exists("nav_icon_color", $disable) ? "" : array('frio_nav_icon_color', t('Navigation bar icon color '), $arr['nav_icon_color']), + '$link_color' => array_key_exists("link_color", $disable) ? "" : array('frio_link_color', t('Link color'), $arr['link_color'], '', $link_colors), + '$bgcolor' => array_key_exists("bgcolor", $disable) ? "" : array('frio_background_color', t('Set the background color'), $arr['bgcolor']), + '$contentbg_transp' => array_key_exists("contentbg_transp", $disable) ? "" : array('frio_contentbg_transp', t("Content background transparency"), ((isset($arr["contentbg_transp"]) && $arr["contentbg_transp"] != "") ? $arr["contentbg_transp"] : 100)), + '$background_image' => array_key_exists("background_image", $disable ) ? "" : array('frio_background_image', t('Set the background image'), $arr['background_image'], $background_image_help), + '$bg_image_options' => Image::get_options($arr), )); return $o; diff --git a/view/theme/frio/style.php b/view/theme/frio/style.php index cc77f8234a..76cbb97776 100644 --- a/view/theme/frio/style.php +++ b/view/theme/frio/style.php @@ -1,40 +1,52 @@ install) { - // Get the UID of the channel owner +$schemecss = ""; +$schemecssfile = false; +$scheme_modified = 0; + +if (! $a->install) { + // Get the UID of the profile owner. $uid = get_theme_uid(); - if($uid) { - load_pconfig($uid,'frio'); + if ($uid) { + PConfig::load($uid, 'frio'); + + // Load the profile owners pconfig. + $schema = PConfig::get($uid, "frio", "schema"); + $nav_bg = PConfig::get($uid, "frio", "nav_bg"); + $nav_icon_color = PConfig::get($uid, "frio", "nav_icon_color"); + $link_color = PConfig::get($uid, "frio", "link_color"); + $bgcolor = PConfig::get($uid, "frio", "background_color"); + $contentbg_transp = PConfig::get($uid, "frio", "contentbg_transp"); + $background_image = PConfig::get($uid, "frio", "background_image"); + $bg_image_option = PConfig::get($uid, "frio", "bg_image_option"); + $modified = PConfig::get($uid, "frio", "css_modified"); + + // There is maybe the case that the user did never modify the theme settings. + // In this case we store the present time. + if (empty($modified)) { + PConfig::set($uid, 'frio', 'css_modified', time()); + } } - // Load the owners pconfig - $schema = get_pconfig($uid, "frio", "schema"); - $nav_bg = get_pconfig($uid, "frio", "nav_bg"); - $nav_icon_color = get_pconfig($uid, "frio", "nav_icon_color"); - $link_color = get_pconfig($uid, "frio", "link_color"); - $bgcolor = get_pconfig($uid, "frio", "background_color"); - $contentbg_transp = get_pconfig($uid, "frio", "contentbg_transp"); - $background_image = get_pconfig($uid, "frio", "background_image"); - $bg_image_option = get_pconfig($uid, "frio", "bg_image_option"); } // Now load the scheme. If a value is changed above, we'll keep the settings // If not, we'll keep those defined by the schema // Setting $schema to '' wasn't working for some reason, so we'll check it's // not --- like the mobile theme does instead. -// Allow layouts to over-ride the schema -if($_REQUEST['schema']) { +// Allow layouts to over-ride the schema. +if ($_REQUEST['schema']) { $schema = $_REQUEST['schema']; } if (($schema) && ($schema != '---')) { - // Check it exists, because this setting gets distributed to clones - if(file_exists('view/theme/frio/schema/' . $schema . '.php')) { + if (file_exists('view/theme/frio/schema/' . $schema . '.php')) { $schemefile = 'view/theme/frio/schema/' . $schema . '.php'; - require_once ($schemefile); + require_once $schemefile; } - if(file_exists('view/theme/frio/schema/' . $schema . '.css')) { - $schemecss = file_get_contents('view/theme/frio/schema/' . $schema . '.css'); + if (file_exists('view/theme/frio/schema/' . $schema . '.css')) { + $schemecssfile = 'view/theme/frio/schema/' . $schema . '.css'; } } @@ -44,57 +56,53 @@ if (($schema) && ($schema != '---')) { if (! $schema) { if(file_exists('view/theme/frio/schema/default.php')) { $schemefile = 'view/theme/frio/schema/default.php'; - require_once ($schemefile); + require_once $schemefile; } if(file_exists('view/theme/frio/schema/default.css')) { - $schemecss = file_get_contents('view/theme/frio/schema/default.css'); + $schemecssfile = 'view/theme/frio/schema/default.css'; } } //Set some defaults - we have to do this after pulling owner settings, and we have to check for each setting //individually. If we don't, we'll have problems if a user has set one, but not all options. -if(! $nav_bg) - $nav_bg = "#708fa0"; -if(! $nav_icon_color) - $nav_icon_color = "#fff"; -if(! $link_color) - $link_color = "#6fdbe8"; -if(! $bgcolor) - $bgcolor = "#ededed"; -if(! $contentbg_transp) - $contentbg_transp = 100; -if(! $background_image) - $background_image =''; +$nav_bg = (empty($nav_bg) ? "#708fa0" : $nav_bg); +$nav_icon_color = (empty($nav_icon_color) ? "#fff" : $nav_icon_color); +$link_color = (empty($link_color) ? "#6fdbe8" : $link_color); +$bgcolor = (empty($bgcolor) ? "#ededed" : $bgcolor); +$background_image = (empty($background_image) ? '' : $background_image); +$modified = (empty($modified) ? time() : $modified); -// Calculate some colors in dependance of existing colors +$contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != "") ? $contentbg_transp : 100); + +// Calculate some colors in dependance of existing colors. // Some colors are calculated to don't have too many selection -// fields in the theme settings -if(! $menu_background_hover_color) { +// fields in the theme settings. +if (! $menu_background_hover_color) { $mbhc = new Color($nav_bg); $mcolor = $mbhc->getHex(); - if($mbhc->isLight($mcolor, 75)) { + if ($mbhc->isLight($mcolor, 75)) { $menu_is = 'light'; $menu_background_hover_color = '#' . $mbhc->darken(5); } else { $menu_is = 'dark'; $menu_background_hover_color = '#' . $mbhc->lighten(5); - //$menu_background_hover_color = "#628394"; } } -if(! $nav_icon_hover_color) { +if (! $nav_icon_hover_color) { $nihc = new Color($nav_bg); - if($nihc->isLight()) + if ($nihc->isLight()) { $nav_icon_hover_color = '#' . $nihc->darken(10); - else + } else { $nav_icon_hover_color = '#' . $nihc->lighten(10); + } } -if(! $link_hover_color) { +if (! $link_hover_color) { $lhc = new Color($link_color); $lcolor = $lhc->getHex(); - if($lhc->isLight($lcolor, 75)) { + if ($lhc->isLight($lcolor, 75)) { $link_hover_color = '#' . $lhc->darken(5); } else { $link_hover_color = '#' . $lhc->lighten(5); @@ -102,7 +110,7 @@ if(! $link_hover_color) { } -// Convert $bg_image_options into css +// Convert $bg_image_options into css. switch ($bg_image_option) { case "stretch": $background_size_img = "100%"; @@ -122,32 +130,59 @@ switch ($bg_image_option) { break; } -// Convert transparency level from percentage to opacity value +// Convert transparency level from percentage to opacity value. $contentbg_transp = $contentbg_transp / 100; +$options = array ( + '$nav_bg' => $nav_bg, + '$nav_icon_color' => $nav_icon_color, + '$nav_icon_hover_color' => $nav_icon_hover_color, + '$link_color' => $link_color, + '$link_hover_color' => $link_hover_color, + '$menu_background_hover_color' => $menu_background_hover_color, + '$btn_primary_color' => $nav_icon_color, + '$btn_primary_hover_color' => $menu_background_hover_color, + '$bgcolor' => $bgcolor, + '$contentbg_transp' => $contentbg_transp, + '$background_image' => $background_image, + '$background_size_img' => $background_size_img, +); -// Apply the settings -if(file_exists('view/theme/frio/css/style.css')) { - $x = file_get_contents('view/theme/frio/css/style.css'); +$css_tpl = file_get_contents('view/theme/frio/css/style.css'); - $options = array ( - '$nav_bg' => $nav_bg, - '$nav_icon_color' => $nav_icon_color, - '$nav_icon_hover_color' => $nav_icon_hover_color, - '$link_color' => $link_color, - '$link_hover_color' => $link_hover_color, - '$menu_background_hover_color' => $menu_background_hover_color, - '$btn_primary_color' => $nav_icon_color, - '$btn_primary_hover_color' => $menu_background_hover_color, - '$bgcolor' => $bgcolor, - '$contentbg_transp' => $contentbg_transp, - '$background_image' => $background_image, - '$background_size_img' => $background_size_img, - ); - - echo str_replace(array_keys($options), array_values($options), $x); +// Get the content of the scheme css file and the time of the last file change. +if ($schemecssfile) { + $css_tpl .= file_get_contents($schemecssfile); + $scheme_modified = filemtime($schemecssfile); } -if($schemecss) { - echo $schemecss; +// We need to check which is the most recent css data. +// We will use this time later to decide if we load the cached or fresh css data. +if ($scheme_modified > $modified) { + $modified = $scheme_modified; } +// Apply the settings to the css template. +$css = str_replace(array_keys($options), array_values($options), $css_tpl); + +$modified = gmdate('r', $modified); + +$etag = md5($css); + +// Set a header for caching. +header('Cache-Control: public'); +header('ETag: "'.$etag.'"'); +header('Last-Modified: '.$modified); + +// Only send the CSS file if it was changed. +if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) { + $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])); + $cached_etag = str_replace(array('"', "-gzip"), array('', ''), + stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])); + + if (($cached_modified == $modified) && ($cached_etag == $etag)) { + header('HTTP/1.1 304 Not Modified'); + exit(); + } +} + +echo $css; diff --git a/view/theme/frio/templates/theme_settings.tpl b/view/theme/frio/templates/theme_settings.tpl index d4438caa8c..cc9d941f05 100644 --- a/view/theme/frio/templates/theme_settings.tpl +++ b/view/theme/frio/templates/theme_settings.tpl @@ -31,7 +31,7 @@ EOT; - } +} if ($style == "") $style = get_config('frio', 'style'); From 1585918f2958399d9958438b09d67feb815b6daf Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Mon, 23 Oct 2017 15:25:09 +0200 Subject: [PATCH 2/6] frio: set a dummy img for background image if no img was set (Otherwise the empty value would be replaced in the browser with a path to the theme and the css would be loaded a second time) --- view/theme/frio/style.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/view/theme/frio/style.php b/view/theme/frio/style.php index 76cbb97776..041f890e29 100644 --- a/view/theme/frio/style.php +++ b/view/theme/frio/style.php @@ -65,12 +65,13 @@ if (! $schema) { //Set some defaults - we have to do this after pulling owner settings, and we have to check for each setting //individually. If we don't, we'll have problems if a user has set one, but not all options. -$nav_bg = (empty($nav_bg) ? "#708fa0" : $nav_bg); -$nav_icon_color = (empty($nav_icon_color) ? "#fff" : $nav_icon_color); -$link_color = (empty($link_color) ? "#6fdbe8" : $link_color); -$bgcolor = (empty($bgcolor) ? "#ededed" : $bgcolor); -$background_image = (empty($background_image) ? '' : $background_image); -$modified = (empty($modified) ? time() : $modified); +$nav_bg = (empty($nav_bg) ? "#708fa0" : $nav_bg); +$nav_icon_color = (empty($nav_icon_color) ? "#fff" : $nav_icon_color); +$link_color = (empty($link_color) ? "#6fdbe8" : $link_color); +$bgcolor = (empty($bgcolor) ? "#ededed" : $bgcolor); +// The background image can not be empty. So we use a dummy jpg if no image was set. +$background_image = (empty($background_image) ? 'img/none.jpg' : $background_image); +$modified = (empty($modified) ? time() :$modified); $contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != "") ? $contentbg_transp : 100); From 6a8969452a4f029df6a56a286b837347150fee7d Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Mon, 23 Oct 2017 20:26:31 +0200 Subject: [PATCH 3/6] frio: add the possibility for the admin to change the colors for non personal pages --- view/theme/frio/config.php | 52 +++++++++++++++++++++++++++++------ view/theme/frio/css/style.css | 8 ++++++ view/theme/frio/style.php | 20 ++++++++++++++ 3 files changed, 72 insertions(+), 8 deletions(-) diff --git a/view/theme/frio/config.php b/view/theme/frio/config.php index e3164697ba..8add86ea05 100644 --- a/view/theme/frio/config.php +++ b/view/theme/frio/config.php @@ -1,6 +1,7 @@ install) { if (empty($modified)) { PConfig::set($uid, 'frio', 'css_modified', time()); } + } else { + Config::load('frio'); + + // Load frios system config. + $schema = Config::get("frio", "schema"); + $nav_bg = Config::get("frio", "nav_bg"); + $nav_icon_color = Config::get("frio", "nav_icon_color"); + $link_color = Config::get("frio", "link_color"); + $bgcolor = Config::get("frio", "background_color"); + $contentbg_transp = Config::get("frio", "contentbg_transp"); + $background_image = Config::get("frio", "background_image"); + $bg_image_option = Config::get("frio", "bg_image_option"); + $modified = Config::get("frio", "css_modified"); + + // There is maybe the case that the user did never modify the theme settings. + // In this case we store the present time. + if (empty($modified)) { + Config::set('frio', 'css_modified', time()); + } } } From 7e273ba51bc1d00f8778a3afc73965b4fc52d284 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Mon, 23 Oct 2017 21:15:46 +0200 Subject: [PATCH 4/6] frio: fix wrong slider position in the theme_settings --- view/theme/frio/templates/theme_settings.tpl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/view/theme/frio/templates/theme_settings.tpl b/view/theme/frio/templates/theme_settings.tpl index cc9d941f05..92b463694f 100644 --- a/view/theme/frio/templates/theme_settings.tpl +++ b/view/theme/frio/templates/theme_settings.tpl @@ -60,6 +60,13 @@ theme: 'theme-frio', }); + // The position of the slider is wrong calculated on hidden elements. + // So set an event listener toggle and update the jRange value. + $(document).on('click', '#custom-settings-title a', function() { + var bgTransp = $('#frio_contentbg_transp').val(); + $('.slider-input').jRange('setValue', bgTransp); + }); + }); From 2687a42e3cbf17b169da3d624c1b2d68d68678ca Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Mon, 23 Oct 2017 22:14:35 +0200 Subject: [PATCH 5/6] frio: sanitise $schema --- view/theme/frio/style.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/view/theme/frio/style.php b/view/theme/frio/style.php index 7b1b8a350d..c227c354f8 100644 --- a/view/theme/frio/style.php +++ b/view/theme/frio/style.php @@ -60,6 +60,9 @@ if (! $a->install) { if ($_REQUEST['schema']) { $schema = $_REQUEST['schema']; } + +$schema = basename($schema); + if (($schema) && ($schema != '---')) { if (file_exists('view/theme/frio/schema/' . $schema . '.php')) { $schemefile = 'view/theme/frio/schema/' . $schema . '.php'; From 578dc6f9672ca81a21ff70363cb16fb7cd0aca7c Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Tue, 24 Oct 2017 14:44:31 +0200 Subject: [PATCH 6/6] frio: sanitize $schema only if the variable is initialized --- view/theme/frio/style.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/view/theme/frio/style.php b/view/theme/frio/style.php index c227c354f8..04379b244e 100644 --- a/view/theme/frio/style.php +++ b/view/theme/frio/style.php @@ -61,7 +61,9 @@ if ($_REQUEST['schema']) { $schema = $_REQUEST['schema']; } -$schema = basename($schema); +// Sanitize the data. +$schema = !empty($schema) ? basename($schema) : ""; + if (($schema) && ($schema != '---')) { if (file_exists('view/theme/frio/schema/' . $schema . '.php')) { @@ -96,7 +98,7 @@ $bgcolor = (empty($bgcolor) ? "#ededed" : $bgcolor); $background_image = (empty($background_image) ? 'img/none.jpg' : $background_image); $modified = (empty($modified) ? time() :$modified); -$contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != "") ? $contentbg_transp : 100); +$contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != "") ? $contentbg_transp : 100); // Calculate some colors in dependance of existing colors. // Some colors are calculated to don't have too many selection