Falko Timme
2013-10-18 2d2fd172e1548dd24e1719accd0b856cff6a31a0
interface/lib/classes/tpl.inc.php
@@ -22,12 +22,12 @@
//
// $Id: class.tpl.inc.php,v 1.1 2003/07/08 12:31:10 platinum Exp $
//** check to avoid multiple including of class
//** check and avoid multiple loading of class
if (!defined('vlibTemplateClassLoaded')) {
    define('vlibTemplateClassLoaded', 1);
    global $conf;
      include_once ($conf['classpath'].'/tpl_error.inc.php');
      include_once ($conf['classpath'].'/tpl_ini.inc.php');
      include_once (ISPC_CLASS_PATH.'/tpl_error.inc.php');
      include_once (ISPC_CLASS_PATH.'/tpl_ini.inc.php');
    class tpl{
    
@@ -157,7 +157,9 @@
         */
        public function newTemplate($tmplfile)
        {
            if (!$tfile = $this->_fileSearch($tmplfile)) vlibTemplateError::raiseError('VT_ERROR_NOFILE',KILL,$tmplfile);
            if (!$tfile = $this->_fileSearch($tmplfile)){
                vlibTemplateError::raiseError('VT_ERROR_NOFILE', KILL, $tmplfile);
            }
            //* make sure that any parsing vars are cleared for the new template
            $this->_tmplfile = null;
@@ -169,8 +171,9 @@
            $this->_totalparsetime = null;
            //* reset debug module
            if ($this->_debug) $this->_debugReset();
            if ($this->_debug){
                $this->_debugReset();
            }
            $this->_tmplfilename = $tfile;
            return true;
        }
@@ -189,12 +192,12 @@
            if (is_array($k)) {
                foreach($k as $key => $value){
                    $key = ($this->OPTIONS['CASELESS']) ? strtolower(trim($key)) : trim($key);
                    if (preg_match('/^[A-Za-z_]+[A-Za-z0-9_]*$/', $key) && $value !== null ) {
                    if (preg_match('/^[A-Za-z]+[A-Za-z0-9_]*$/', $key) && $value !== null ) {
                        $this->_vars[$key] = $value;
                    }
                }
            } else {
                if (preg_match('/^[A-Za-z_]+[A-Za-z0-9_]*$/', $k) && $v !== null) {
                if (preg_match('/^[A-Za-z]+[A-Za-z0-9_]*$/', $k) && $v !== null) {
                    if ($this->OPTIONS['CASELESS']) $k = strtolower($k);
                    $this->_vars[trim($k)] = $v;
                } else {
@@ -240,7 +243,7 @@
            for ($i = 0; $i < $num_args; $i++) {
                $var = func_get_arg($i);
                if ($this->OPTIONS['CASELESS']) $var = strtolower($var);
                if (!preg_match('/^[A-Za-z_]+[A-Za-z0-9_]*$/', $var)) continue;
                if (!preg_match('/^[A-Za-z]+[A-Za-z0-9_]*$/', $var)) continue;
                unset($this->_vars[$var]);
            }
            return true;
@@ -253,8 +256,7 @@
         */
        public function getVars()
        {
            if (empty($this->_vars)) return false;
            return $this->_vars;
            return empty($this->_vars) ? false : $this->_vars;
        }
        /**
@@ -265,8 +267,7 @@
        public function getVar($var)
        {
            if ($this->OPTIONS['CASELESS']) $var = strtolower($var);
            if (empty($var) || !isset($this->_vars[$var])) return false;
            return $this->_vars[$var];
            return (empty($var) || !isset($this->_vars[$var])) ? false : $this->_vars[$var];
        }
        /**
@@ -299,12 +300,14 @@
         */
        public function setLoop($k, $v)
        {
            if (is_array($v) && preg_match('/^[A-Za-z_]+[A-Za-z0-9_]*$/', $k)) {
            if (is_array($v) && preg_match('/^[A-Za-z]+[A-Za-z0-9_]*$/', $k)) {
                $k = ($this->OPTIONS['CASELESS']) ? strtolower(trim($k)) : trim($k);
                $this->_arrvars[$k] = array();
                if ($this->OPTIONS['SET_LOOP_VAR'] && !empty($v)) $this->setvar($k, 1);
                if (($this->_arrvars[$k] = $this->_arrayBuild($v)) == false) {
                    vlibTemplateError::raiseError('VT_WARNING_INVALID_ARR',WARNING,$k);
                    vlibTemplateError::raiseError('VT_WARNING_INVALID_ARR', WARNING, $k);
                } else {
                    $this->vars['_'.$k.'_num'] = count($v);
                }
            }
            return true;
@@ -321,18 +324,20 @@
         */
        public function setDbLoop($loopname, $result, $db_type = 'MYSQL')
        {
            $db_type = strtoupper($db_type);
            /*
         $db_type = strtoupper($db_type);
            if (!in_array($db_type, $this->allowed_loop_dbs)) {
                vlibTemplateError::raiseError('VT_WARNING_INVALID_LOOP_DB',WARNING, $db_type);
                vlibTemplateError::raiseError('VT_WARNING_INVALID_LOOP_DB', WARNING, $db_type);
                return false;
            }
            $loop_arr = array();
            // TODO: Are all these necessary as were onyl using mysql and possible postgres ? - pedro
            switch ($db_type) {
                case 'MYSQL':
                    if (get_resource_type($result) != 'mysql result') {
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE',WARNING, $db_type);
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE', WARNING, $db_type);
                        return false;
                    }
                    while($r = mysql_fetch_assoc($result)) {
@@ -342,7 +347,7 @@
                case 'POSTGRESQL':
                    if (get_resource_type($result) != 'pgsql result') {
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE',WARNING, $db_type);
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE', WARNING, $db_type);
                        return false;
                    }
@@ -355,7 +360,7 @@
                case 'INFORMIX':
                    if (!$result) {
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE',WARNING, $db_type);
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE', WARNING, $db_type);
                        return false;
                    }
                    while($r = ifx_fetch_row($result, 'NEXT')) {
@@ -365,7 +370,7 @@
                case 'INTERBASE':
                    if (get_resource_type($result) != 'interbase result') {
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE',WARNING, $db_type);
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE', WARNING, $db_type);
                        return false;
                    }
                    while($r = ibase_fetch_row($result)) {
@@ -375,7 +380,7 @@
                case 'INGRES':
                    if (!$result) {
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE',WARNING, $db_type);
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE', WARNING, $db_type);
                        return false;
                    }
                    while($r = ingres_fetch_array(INGRES_ASSOC, $result)) {
@@ -385,7 +390,7 @@
                case 'MSSQL':
                    if (get_resource_type($result) != 'mssql result') {
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE',WARNING, $db_type);
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE', WARNING, $db_type);
                        return false;
                    }
                    while($r = mssql_fetch_array($result)) {
@@ -395,7 +400,7 @@
                case 'MSQL':
                    if (get_resource_type($result) != 'msql result') {
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE',WARNING, $db_type);
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE', WARNING, $db_type);
                        return false;
                    }
                    while($r = msql_fetch_array($result, MSQL_ASSOC)) {
@@ -405,7 +410,7 @@
                case 'OCI8':
                    if (get_resource_type($result) != 'oci8 statement') {
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE',WARNING, $db_type);
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE', WARNING, $db_type);
                        return false;
                    }
                    while(OCIFetchInto($result, &$r, OCI_ASSOC+OCI_RETURN_LOBS)) {
@@ -415,7 +420,7 @@
                case 'ORACLE':
                    if (get_resource_type($result) != 'oracle Cursor') {
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE',WARNING, $db_type);
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE', WARNING, $db_type);
                        return false;
                    }
                    while(ora_fetch_into($result, &$r, ORA_FETCHINTO_ASSOC)) {
@@ -425,7 +430,7 @@
                case 'OVRIMOS':
                    if (!$result) {
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE',WARNING, $db_type);
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE', WARNING, $db_type);
                        return false;
                    }
                    while(ovrimos_fetch_into($result, &$r, 'NEXT')) {
@@ -435,7 +440,7 @@
                case 'SYBASE':
                    if (get_resource_type($result) != 'sybase-db result') {
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE',WARNING, $db_type);
                        vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE', WARNING, $db_type);
                        return false;
                    }
@@ -446,6 +451,7 @@
            }
            $this->setLoop($loopname, $loop_arr);
            return true;
         */
        }
        /**
@@ -477,7 +483,7 @@
            if (!$loopname) $loopname = $this->_currloopname[(count($this->_currloopname)-1)];
            if (!isset($this->_currloop[$loopname]) || empty($this->_currloopname)) {
                vlibTemplateError::raiseError('VT_WARNING_LOOP_NOT_SET',WARNING);
                vlibTemplateError::raiseError('VT_WARNING_LOOP_NOT_SET', WARNING);
                return false;
            }
            if (is_array($row)) {
@@ -795,7 +801,9 @@
            if ($this->_includedepth > $this->OPTIONS['MAX_INCLUDES'] || $tmplfile == false) {
                return;
            } else {
                if ($this->_debug) array_push ($this->_debugIncludedfiles, $tmplfile);
                if ($this->_debug){
                    array_push ($this->_debugIncludedfiles, $tmplfile);
                }
                if ($do_eval) {
                    array_push($this->_currentincludedir, dirname($tmplfile));
                    $this->_includedepth++;
@@ -843,8 +851,8 @@
                $regex.=    '[\"\']?';
                $regex.= ')?\s*';
                $regex.= '(?:>|\/>|}|-->){1}';
                $regex.= '([\r\n|\n|\r])?/ie';
                $data = preg_replace($regex,"\$this->_parseTag(array('\\0','\\1','\\2','\\3','\\4','\\5','\\6','\\7','\\8','\\9'));",$data);
                $regex.= '([\r\n|\n|\r])?/i';
                $data = preg_replace_callback($regex, array($this, _parseTag), $data);
                if ($this->_cache) { // add cache if need be
                    $this->_createCache($data);
@@ -872,8 +880,15 @@
         */
        private function _fileSearch($file) 
        {
            $filename = basename($file);
         $filename = basename($file);
            $filepath = dirname($file);
         if(isset($_SESSION['s']['module']['name']) && isset($_SESSION['s']['theme'])) {
            if(is_file(ISPC_THEMES_PATH.'/'.$_SESSION['s']['theme'].'/templates/'.$_SESSION['s']['module']['name'].'/'.$filename)) {
               return ISPC_THEMES_PATH.'/'.$_SESSION['s']['theme'].'/templates/'.$_SESSION['s']['module']['name'].'/'.$filename;
            }
         }
            //* check fullpath first..
            $fullpath = $filepath.'/'.$filename;
@@ -1091,7 +1106,7 @@
            switch (strtolower($this->OPTIONS['UNKNOWNS'])) {
                case 'comment':
                    $comment = addcslashes('<!-- unknown variable '.ereg_replace('<!--|-->', '', $wholetag).'//-->', '"');
                    $comment = addcslashes('<!-- unknown variable '.preg_replace('/<!--|-->/', '', $wholetag).'//-->', '"');
                    $retstr .= ' else { print("'.$comment.'"); $this->_setUnknown("'.$varname.'"); }';
                    return $retstr;
@@ -1220,10 +1235,10 @@
         */
        private function _intParse ()
        {
            $mqrt = get_magic_quotes_runtime();
            set_magic_quotes_runtime(0);
            //$mqrt = get_magic_quotes_runtime();
            //set_magic_quotes_runtime(0);
            $this->_tmplfilep = '?>'.$this->_getData($this->_tmplfilename).'<?php return true;';
            set_magic_quotes_runtime($mqrt);
            //set_magic_quotes_runtime($mqrt);
            return true;
        }
@@ -1361,8 +1376,8 @@
        function setCacheExtension() {vlibTemplateError::raiseError('VT_WARNING_NOT_CACHE_OBJ', WARNING, 'setCacheExtension()');}
    } // << end class Def
    //include_once ($conf['classpath'].'/vlibTemplate/debug.php');
    include_once ($conf['classpath'].'/tpl_cache.inc.php');
    //include_once (ISPC_CLASS_PATH.'/vlibTemplate/debug.php');
    include_once (ISPC_CLASS_PATH.'/tpl_cache.inc.php');
} // << end if(!defined())..
?>