[phpMP-CVS] CVS: phpMP/includes template.php,1.32,1.33
Status: Pre-Alpha
Brought to you by:
heimidal
From: Brian R. <hei...@us...> - 2003-05-17 07:56:09
|
Update of /cvsroot/phpmp/phpMP/includes In directory sc8-pr-cvs1:/tmp/cvs-serv31035/includes Modified Files: template.php Log Message: Oops, missed one. Index: template.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/template.php,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -r1.32 -r1.33 *** template.php 9 May 2003 08:07:39 -0000 1.32 --- template.php 17 May 2003 07:56:05 -0000 1.33 *************** *** 1,82 **** ! <?php ! ! // Contains the Template class. ! // This will utilize a flat-file template system. ! ! class Template ! { ! var $tplname; ! var $_tplvars = array(); ! ! /** ! * Template::Template() ! * ! * Initializes the template system ! * Default Constructor ! * ! * @param $tplname, $tplsub ! * @return ! * ! * $tpl_sub will contain the called division of a page i.e. modules.php?m=news&sub=read would yield ! * Template('news', 'read') so that the correct template is displayed for underlying divisions of mods ! * and such. ! **/ ! function Template($tplname, $tplsub = '') ! { ! global $DB; ! $query = $DB->query("SELECT * FROM " . DB_TEMPLATE_VARS_TABLE . " WHERE tpl_name='$tplname'"); ! ! $this->tplname = $tplname; ! $this->_tplvars = $DB->fetchArray($query); ! } ! ! /** ! * Template::assign() ! * ! * Allows for the assignment of template variables. ! * ! * @param $new_tpl_var ! * @return ! * ! * Note that this function can accept two forms of variables in order to assign them; ! * you may specify an associative array of keys and values or call call the function ! * with a single key and value. ! * ! * For instance, the following is entirely valid: ! * ! * $Template->assign( array( ! * 'Google' => 'http://www.google.com', ! * 'Excite' => 'http://www.excite.com', ! * 'Altavista' => 'http://www.altavista.com' ! * ) ); ! * ! * The following is also valid: ! * ! * $Template->assign('Google', 'http://www.google.com'); ! * ! * Lastly, keep in mind that, in order to make things a little cohesive and standardized, ! * your template variable names may only contains characters A-Z, a-z, 0-9, (_), and (-). ! **/ ! function assign($new_tpl_var, $new_tpl_val = false) ! { ! if( is_array( $new_tpl_var ) ) ! { ! // Assign an array to the template vars hash. ! foreach( $new_tpl_var as $key => $val ) ! { ! if(eregi('^[a-z]+[_a-z0-9-]*$', $key)) ! { ! $this->_tplvars[$key] = $val; ! } ! // If the regex doesn't validate to A-z0-9_-, we won't do anything and ignore the fault. ! } ! } ! elseif((!empty( $new_tpl_var )) && (eregi('^[a-z]+[_a-z0-9-]*$', $new_tpl_var)) && ($new_tpl_val != false)) ! { ! // Assign one single var to the template vars hash. ! $this->_tplvars[$new_tpl_var] = $new_tpl_val; ! } ! } ! } ! ?> --- 1,104 ---- ! <?php ! ! /* ! * phpMP - The PHP Modular Portal System ! * Copyright (C) 2002-2003 Brian Rose and the phpMP group ! * ! * This program is free software; you can redistribute it and/or modify ! * it under the terms of the GNU General Public License as published by ! * the Free Software Foundation; either version 2 of the License, or ! * (at your option) any later version. ! * ! * This program is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! * GNU General Public License for more details. ! * ! * You should have received a copy of the GNU General Public License ! * along with this program; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! * ! * $Id$ ! * ! */ ! ! // Contains the Template class. ! // This will utilize a flat-file template system. ! ! class Template ! { ! var $tplname; ! var $_tplvars = array(); ! ! /** ! * Template::Template() ! * ! * Initializes the template system ! * Default Constructor ! * ! * @param $tplname, $tplsub ! * @return ! * ! * $tpl_sub will contain the called division of a page i.e. modules.php?m=news&sub=read would yield ! * Template('news', 'read') so that the correct template is displayed for underlying divisions of mods ! * and such. ! **/ ! function Template($tplname, $tplsub = '') ! { ! global $DB; ! $query = $DB->query("SELECT * FROM " . DB_TEMPLATE_VARS_TABLE . " WHERE tpl_name='$tplname'"); ! ! $this->tplname = $tplname; ! $this->_tplvars = $DB->fetchArray($query); ! } ! ! /** ! * Template::assign() ! * ! * Allows for the assignment of template variables. ! * ! * @param $new_tpl_var ! * @return ! * ! * Note that this function can accept two forms of variables in order to assign them; ! * you may specify an associative array of keys and values or call call the function ! * with a single key and value. ! * ! * For instance, the following is entirely valid: ! * ! * $Template->assign( array( ! * 'Google' => 'http://www.google.com', ! * 'Excite' => 'http://www.excite.com', ! * 'Altavista' => 'http://www.altavista.com' ! * ) ); ! * ! * The following is also valid: ! * ! * $Template->assign('Google', 'http://www.google.com'); ! * ! * Lastly, keep in mind that, in order to make things a little cohesive and standardized, ! * your template variable names may only contains characters A-Z, a-z, 0-9, (_), and (-). ! **/ ! function assign($new_tpl_var, $new_tpl_val = false) ! { ! if( is_array( $new_tpl_var ) ) ! { ! // Assign an array to the template vars hash. ! foreach( $new_tpl_var as $key => $val ) ! { ! if(eregi('^[a-z]+[_a-z0-9-]*$', $key)) ! { ! $this->_tplvars[$key] = $val; ! } ! // If the regex doesn't validate to A-z0-9_-, we won't do anything and ignore the fault. ! } ! } ! elseif((!empty( $new_tpl_var )) && (eregi('^[a-z]+[_a-z0-9-]*$', $new_tpl_var)) && ($new_tpl_val != false)) ! { ! // Assign one single var to the template vars hash. ! $this->_tplvars[$new_tpl_var] = $new_tpl_val; ! } ! } ! } ! ?> |