Allow smarty directory customization
authorJean-Michel Vourgère <jvourger@greenpeace.org>
Mon, 27 Feb 2017 15:46:18 +0000 (15:46 +0000)
committerJean-Michel Vourgère <jvourger@greenpeace.org>
Thu, 9 Mar 2017 18:06:30 +0000 (18:06 +0000)
config.php.example
index.php
squasher.class.php
squasher.php

index 20976e3e3f03adef8e15fcaf89db0ecb09dd6693..17c01862773102c2f771c8328a7a86643324d01a 100644 (file)
@@ -8,7 +8,17 @@ DEFINE('SQUASHER_DB_DATABASE', 'squasher'); // Mysql database name
 // Location of the smarty library
 // Use 'smarty/Smarty.class.php' for relative directory 'smarty/'
 // Use 'smarty3/Smarty.class.php' if you installed package smarty3
-DEFINE('SQUASHER_SMARTY', 'smarty3/Smarty.class.php');
+DEFINE('SQUASHER_SMARTY_SOURCE', 'smarty3/Smarty.class.php');
+
+// Location of the smarty templates
+DEFINE('SQUASHER_SMARTY_TEMPLATES', './templates');
+
+// Location of the smarty compiled templates
+DEFINE('SQUASHER_SMARTY_TEMPLATES_C', './templates_c');
+
+// Location of the smarty cache
+DEFINE('SQUASHER_SMARTY_CACHE', './cache');
+
 
 // start session
 session_start();
index dfcc4689205efd4de0a1b232a728ce76c849793a..372fcd7117b0371b904b6a6959ff2ad232bcdd23 100644 (file)
--- a/index.php
+++ b/index.php
@@ -23,9 +23,7 @@ if ($_SESSION['creds']['validated'] || @$_GET['f']) {
 } else {
        //show login
 
-       require_once(SQUASHER_SMARTY); // See config.php
-
-       $smarty = new Smarty;
+       $smarty = get_smarty();
 
        $smarty->assign('salt', $salt);
        $smarty->assign('debug', @$_GET['debug']);
index 0b132b306ee534af586d2a25f7ad1285c53494b3..42af06c8ebc670da992d36341af6a8965ebc6ec0 100644 (file)
@@ -42,6 +42,17 @@ function validate_user($username, $password, $salt) {
 }
 
 
+function get_smarty() {
+       require_once(SQUASHER_SMARTY_SOURCE); // See config.php
+
+       $smarty = new Smarty;
+       $smarty->setTemplateDir(SQUASHER_SMARTY_TEMPLATES)
+              ->setCompileDir(SQUASHER_SMARTY_TEMPLATES_C)
+              ->setCacheDir(SQUASHER_SMARTY_CACHE);
+
+       return $smarty;
+}
+
 
 class squashweb {
 
index 61d350dae4546a43ef27d04662025c62d5b271b1..7bf49acfd3e28019b75ed2a489709a41178143e2 100644 (file)
@@ -131,9 +131,7 @@ if (@$_GET['f']) {
        
 } elseif (@$_GET['tools']=='access' && $_SESSION['creds']['user_level'] > 100) {
 
-       require_once(SQUASHER_SMARTY);
-
-       $smarty = new Smarty;
+       $smarty = get_smarty();
 
        $smarty->assign('user_level', $_SESSION['creds']['user_level']);
        $smarty->assign('user_name', $_SESSION['creds']['user_name']);
@@ -161,9 +159,7 @@ if (@$_GET['f']) {
                $squashweb->remove_users($_POST['u']);
        if ($type=="new")
                $squashweb->insert_users($_POST['u'], $_SESSION['creds']['user_level']);
-       require_once(SQUASHER_SMARTY);
-
-       $smarty = new Smarty;
+       $smarty = get_smarty();
 
        $smarty->assign('user_level', $_SESSION['creds']['user_level']);
        $smarty->assign('user_name', $_SESSION['creds']['user_name']);
@@ -182,9 +178,8 @@ if (@$_GET['f']) {
        $logtype=@$_GET['logtype'];
        if (!$logtype)
                $logtype = 'all';
-       require_once(SQUASHER_SMARTY);
 
-       $smarty = new Smarty;
+       $smarty = get_smarty();
 
        $smarty->assign('user_level', $_SESSION['creds']['user_level']);
        $smarty->assign('user_name', $_SESSION['creds']['user_name']);
@@ -197,10 +192,7 @@ if (@$_GET['f']) {
 } else {
        //show overview
 
-       require_once(SQUASHER_SMARTY);
-
-       $smarty = new Smarty;
-
+       $smarty = get_smarty();
        /***
        *       $config:: array
        *       [0]     ->      versioncode