From 8a51e29824fc2569ac1d0def3070bee7c0552231 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Fri, 2 Mar 2012 17:22:16 +0100 Subject: [PATCH 1/2] template proc: add variable filters --- include/template_processor.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/include/template_processor.php b/include/template_processor.php index 111fc5849a..90c6b2e650 100755 --- a/include/template_processor.php +++ b/include/template_processor.php @@ -160,15 +160,25 @@ private function var_replace($s){ $m = array(); - if (preg_match_all('/\$\[{0,1}([a-zA-Z0-9-_]+\.*)+\]{0,1}/', $s,$m)){ - foreach($m[0] as $var){ - $varn = str_replace(array("[","]"), array("",""), $var); - $val = $this->_get_var($varn, true); + if (preg_match_all('/(\$\[{0,1}([a-zA-Z0-9-_]+\.*)+)(\|[a-zA-Z0-9-_]+)*\]{0,1}/', $s,$m)){ + foreach($m[1] as $id=>$var){ + $var = str_replace("[", "", $var); + $val = $this->_get_var($var, true); + + // apply filters + if ($m[3][$id]!=""){ + $filters = explode("|",trim($m[3][$id],"|")); + foreach($filters as $filter) + if (function_exists($filter)) + $val=$filter($val); + } if ($val!=KEY_NOT_EXISTS) - $s = str_replace($var, $val, $s); + $s = str_replace($m[0][$id], $val, $s); } } + + return $s; } From 607ee1ff9c08a38fb938955bda5fd8aa8776ecbc Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Tue, 6 Mar 2012 09:50:18 +0100 Subject: [PATCH 2/2] quattro: theme settings (a bit hackish) --- view/theme/quattro/theme.php | 46 +++++++++++++++++++++++++++ view/theme/quattro/theme_settings.tpl | 11 +++++++ 2 files changed, 57 insertions(+) create mode 100644 view/theme/quattro/theme.php create mode 100644 view/theme/quattro/theme_settings.tpl diff --git a/view/theme/quattro/theme.php b/view/theme/quattro/theme.php new file mode 100644 index 0000000000..7e5ab1e62e --- /dev/null +++ b/view/theme/quattro/theme.php @@ -0,0 +1,46 @@ +hooks[] = array('plugin_settings', 'view/theme/quattro/theme.php', 'quattro_settings'); +$a->hooks[] = array('plugin_settings_post', 'view/theme/quattro/theme.php', 'quattro_settings_post'); + + +function quattro_settings(&$a, &$o){ + if(!local_user()) + return; + + $align = get_pconfig(local_user(), 'quattro', 'align' ); + + $t = file_get_contents( dirname(__file__). "/theme_settings.tpl" ); + $o .= replace_macros($t, array( + '$submit' => t('Submit'), + '$baseurl' => $a->get_baseurl(), + '$title' => t("Theme settings"), + '$align' => array('quattro_align', t('Alignment'), $align, '', array('left'=>t('Left'), 'center'=>t('Center'))), + )); +} + +function quattro_settings_post(&$a){ + if(! local_user()) + return; + if (isset($_POST['quattro-settings-submit'])){ + set_pconfig(local_user(), 'quattro', 'align', $_POST['quattro_align']); + } + goaway($a->get_baseurl()."/settings/addon"); +} + + +$quattro_align = get_pconfig(local_user(), 'quattro', 'align' ); + +if(local_user() && $quattro_align=="center"){ + + $a->page['htmlhead'].=" + + "; + +} diff --git a/view/theme/quattro/theme_settings.tpl b/view/theme/quattro/theme_settings.tpl new file mode 100644 index 0000000000..25af042530 --- /dev/null +++ b/view/theme/quattro/theme_settings.tpl @@ -0,0 +1,11 @@ +
+

$title

+ + {{inc field_select.tpl with $field=$align}}{{endinc}} + +
+ +
+ + +