| | |
| | | // |
| | | // $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{ |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * FUNCTION: newTemplate |
| | | * |
| | | * Usually called by the class constructor. |
| | | * Stores the filename in $this->_tmplfilename. |
| | | * Raises an error if the template file is not found. |
| | | * |
| | | * @param string $tmplfile full path to template file |
| | | * @return boolean true |
| | | * @access public |
| | | */ |
| | | 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; |
| | |
| | | $this->_totalparsetime = null; |
| | | |
| | | //* reset debug module |
| | | if ($this->_debug) $this->_debugReset(); |
| | | |
| | | if ($this->_debug){ |
| | | $this->_debugReset(); |
| | | } |
| | | $this->_tmplfilename = $tfile; |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: setVar |
| | | * |
| | | * Sets variables to be used by the template |
| | | * If $k is an array, then it will treat it as an associative array |
| | | * using the keys as variable names and the values as variable values. |
| | | * |
| | | * @param mixed $k key to define variable name |
| | | * @param mixed $v variable to assign to $k |
| | | * @return boolean true/false |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: setInclude |
| | | * |
| | | * Sets dynamic includes to be used by the template |
| | | * If $k is an array, then it will treat it as an associative array |
| | | * using the keys as variable names and the values as variable values. |
| | | * |
| | | * @param mixed $k key to define variable name |
| | | * @param mixed $v variable to assign to $k |
| | | * @return boolean true/false |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: unsetVar |
| | | * |
| | | * Unsets a variable which has already been set |
| | | * Parse in all vars wanted for deletion in seperate parametres |
| | | * |
| | | * @param string var name to remove use: vlibTemplate::unsetVar(var[, var..]) |
| | | * @return boolean true/false returns true unless called with 0 params |
| | | * @access public |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: getVars |
| | | * |
| | | * Gets all vars currently set in global namespace. |
| | | * |
| | | * @return array |
| | | * @access public |
| | | */ |
| | | public function getVars() |
| | | { |
| | | if (empty($this->_vars)) return false; |
| | | return $this->_vars; |
| | | return empty($this->_vars) ? false : $this->_vars; |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: getVar |
| | | * |
| | | * Gets a single var from the global namespace |
| | | * |
| | | * @return var |
| | | * @access public |
| | | */ |
| | | 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]; |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: setContextVars |
| | | * |
| | | * sets the GLOBAL_CONTEXT_VARS |
| | | * |
| | | * @return true |
| | | * @access public |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: setLoop |
| | | * |
| | | * Builds the loop construct for use with <TMPL_LOOP>. |
| | | * |
| | | * @param string $k string to define loop name |
| | | * @param array $v array to assign to $k |
| | | * @return boolean true/false |
| | |
| | | $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); |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: setDbLoop [** EXPERIMENTAL **] |
| | | * |
| | | * [** EXPERIMENTAL **] |
| | | * Function to create a loop from a Db result resource link. |
| | | * |
| | | * @param string $loopname to commit loop. If not set, will use last loopname set using newLoop() |
| | | * @param string $result link to a Db result resource |
| | | * @param string $db_type, type of db that the result resource belongs to. |
| | |
| | | */ |
| | | 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)) { |
| | |
| | | |
| | | 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; |
| | | } |
| | | |
| | |
| | | |
| | | 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')) { |
| | |
| | | |
| | | 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)) { |
| | |
| | | |
| | | 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)) { |
| | |
| | | |
| | | 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)) { |
| | |
| | | |
| | | 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)) { |
| | |
| | | |
| | | 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)) { |
| | |
| | | |
| | | 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)) { |
| | |
| | | |
| | | 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')) { |
| | |
| | | |
| | | 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; |
| | | } |
| | | |
| | |
| | | } |
| | | $this->setLoop($loopname, $loop_arr); |
| | | return true; |
| | | */ |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: newLoop |
| | | * |
| | | * Sets the name for the curent loop in the 3 step loop process. |
| | | * |
| | | * @param string $name string to define loop name |
| | | * @return boolean true/false |
| | | * @access public |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: addRow |
| | | * |
| | | * Adds a row to the current loop in the 3 step loop process. |
| | | * |
| | | * @param array $row loop row to add to current loop |
| | | * @param string $loopname loop to which you want to add row, if not set will use last loop set using newLoop(). |
| | | * @return boolean true/false |
| | |
| | | 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)) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: addLoop |
| | | * |
| | | * Completes the 3 step loop process. This assigns the rows and resets |
| | | * the variables used. |
| | | * |
| | | * @param string $loopname to commit loop. If not set, will use last loopname set using newLoop() |
| | | * @return boolean true/false |
| | | * @access public |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: unsetLoop |
| | | * |
| | | * Unsets a loop which has already been set. |
| | | * Can only unset top level loops. |
| | | * |
| | | * @param string loop to remove use: vlibTemplate::unsetLoop(loop[, loop..]) |
| | | * @return boolean true/false returns true unless called with 0 params |
| | | * @access public |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: reset |
| | | * |
| | | * Resets the vlibTemplate object. After using vlibTemplate::reset() you must |
| | | * use vlibTemplate::newTemplate(tmpl) to reuse, not passing in the options array. |
| | | * |
| | | * @return boolean true |
| | | * @access public |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: clearVars |
| | | * |
| | | * Unsets all variables in the template |
| | | * |
| | | * @return boolean true |
| | | * @access public |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: clearLoops |
| | | * |
| | | * Unsets all loops in the template |
| | | * |
| | | * @return boolean true |
| | | * @access public |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: clearAll |
| | | * |
| | | * Unsets all variables and loops set using setVar/Loop() |
| | | * |
| | | * @return boolean true |
| | | * @access public |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: unknownsExist |
| | | * |
| | | * Returns true if unknowns were found after parsing. |
| | | * Function MUST be called AFTER one of the parsing functions to have any relevance. |
| | | * |
| | | * @return boolean true/false |
| | | * @access public |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: unknowns |
| | | * |
| | | * Alias for unknownsExist. |
| | | * |
| | | * @access public |
| | | */ |
| | | public function unknowns() |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: getUnknowns |
| | | * |
| | | * Returns an array of all unknown vars found when parsing. |
| | | * This function is only relevant after parsing a document. |
| | | * |
| | | * @return array |
| | | * @access public |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: setUnknowns |
| | | * |
| | | * Sets how you want to handle variables that were found in the |
| | | * Sets how you want to handle variables that were found in the |
| | | * template but not set in vlibTemplate using vlibTemplate::setVar(). |
| | | * |
| | | * @param string $arg ignore, remove, print, leave or comment |
| | | * @return boolean |
| | | * @access public |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: setPath |
| | | * |
| | | * function sets the paths to use when including files. |
| | | * Use of this function: vlibTemplate::setPath(string path [, string path, ..]); |
| | | * i.e. if $tmpl is your template object do: $tmpl->setPath('/web/htdocs/templates','/web/htdocs/www'); |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: getParseTime |
| | | * |
| | | * After using one of the parse functions, this will allow you |
| | | * access the time taken to parse the template. |
| | | * see OPTION 'TIME_PARSE'. |
| | |
| | | |
| | | |
| | | /** |
| | | * FUNCTION: fastPrint |
| | | * |
| | | * Identical to pparse() except that it uses output buffering w/ gz compression thus |
| | | * printing the output directly and compressed if poss. |
| | | * Will possibly if parsing a huge template. |
| | |
| | | |
| | | |
| | | /** |
| | | * FUNCTION: pparse |
| | | * |
| | | * Calls parse, and then prints out $this->_tmploutput |
| | | * |
| | | * @access public |
| | | * @return boolean true/false |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: pprint |
| | | * |
| | | * Alias for pparse() |
| | | * |
| | | * @access public |
| | | */ |
| | | public function pprint() |
| | |
| | | |
| | | |
| | | /** |
| | | * FUNCTION: grab |
| | | * |
| | | * Returns the parsed output, ready for printing, passing to mail() ...etc. |
| | | * Invokes $this->_parse() if template has not yet been parsed. |
| | | * |
| | |
| | | \-----------------------------------------------------------------------------*/ |
| | | |
| | | /** |
| | | * FUNCTION: vlibTemplate |
| | | * |
| | | * vlibTemplate constructor. |
| | | * if $tmplfile has been passed to it, it will send to $this->newTemplate() |
| | | * |
| | | * @param string $tmplfile full path to template file |
| | | * @param array $options see above |
| | | * @return boolean true/false |
| | |
| | | return true; |
| | | } |
| | | |
| | | /** FUNCTION: _getData |
| | | * |
| | | /** |
| | | * function returns the text from the file, or if we're using cache, the text |
| | | * from the cache file. MUST RETURN DATA. |
| | | * @param string tmplfile contains path to template file |
| | |
| | | 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++; |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: _fileSearch |
| | | * |
| | | * Searches for all possible instances of file { $file } |
| | | * |
| | | * @param string $file path of file we're looking for |
| | | * @access private |
| | | * @return mixed fullpath to file or boolean false |
| | | */ |
| | | 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; |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: _arrayBuild |
| | | * |
| | | * Modifies the array $arr to add Template variables, __FIRST__, __LAST__ ..etc |
| | | * if $this->OPTIONS['LOOP_CONTEXT_VARS'] is true. |
| | | * Used by $this->setloop(). |
| | | * |
| | | * @param array $arr |
| | | * @return array new look array |
| | | * @access private |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: _parseIf |
| | | * returns a string used for parsing in tmpl_if statements. |
| | | * |
| | | * @param string $varname |
| | | * @param string $value |
| | | * @param string $op |
| | |
| | | |
| | | |
| | | /** |
| | | * FUNCTION: _parseLoop |
| | | * returns a string used for parsing in tmpl_loop statements. |
| | | * |
| | | * @param string $varname |
| | | * @access private |
| | | * @return string used for eval'ing |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: _parseVar |
| | | * |
| | | * returns a string used for parsing in tmpl_var statements. |
| | | * |
| | | * @param string $wholetag |
| | | * @param string $tag |
| | | * @param string $varname |
| | |
| | | |
| | | 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; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: _parseTag |
| | | * takes values from preg_replace in $this->_intparse() and determines |
| | | * the replace string. |
| | | * |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: _intParse |
| | | * |
| | | * Parses $this->_tmplfile into correct format for eval() to work |
| | | * Called by $this->_parse(), or $this->fastPrint, this replaces all <tmpl_*> references |
| | | * with their correct php representation, i.e. <tmpl_var title> becomes $this->vars['title'] |
| | |
| | | */ |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: _parse |
| | | * |
| | | * Calls _intParse, and eval()s $this->tmplfilep |
| | | * and outputs the results to $this->tmploutput |
| | | * |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: _setOption |
| | | * |
| | | * Sets one or more of the boolean options 1/0, that control certain actions in the template. |
| | | * Use of this function: |
| | | * either: vlibTemplate::_setOptions(string option_name, bool option_val [, string option_name, bool option_val ..]); |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: _setUnknown |
| | | * |
| | | * Used during parsing, this function sets an unknown var checking to see if it |
| | | * has been previously set. |
| | | * |
| | | * @param string var |
| | | * @access private |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: _getMicrotime |
| | | * Returns microtime as a float number |
| | | * |
| | | * @return float microtime |
| | | * @access private |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * FUNCTION: _escape_hex |
| | | * Returns str encoded to hex code. |
| | | * |
| | | * @param string str to be encoded |
| | | * @param bool true/false specify whether to use hex_entity |
| | | * @return string encoded in hex |
| | |
| | | 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()).. |
| | | ?> |