[phpMP-CVS] CVS: phpMP/includes core.php,1.48,1.49 session.php,1.6,1.7 template.php,1.30,1.31
Status: Pre-Alpha
Brought to you by:
heimidal
From: Brian R. <hei...@us...> - 2003-05-09 04:46:51
|
Update of /cvsroot/phpmp/phpMP/includes In directory sc8-pr-cvs1:/tmp/cvs-serv30808/includes Modified Files: core.php session.php template.php Log Message: Continued work on the template system. Index: core.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/core.php,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -r1.48 -r1.49 *** core.php 4 May 2003 21:12:06 -0000 1.48 --- core.php 9 May 2003 04:46:48 -0000 1.49 *************** *** 9,15 **** { if (is_array($v)) ! { $arr[$k] = strip_magic_quotes($v); } else ! { $arr[$k] = stripslashes($v); } } --- 9,19 ---- { if (is_array($v)) ! { ! $arr[$k] = strip_magic_quotes($v); ! } else ! { ! $arr[$k] = stripslashes($v); ! } } *************** *** 76,79 **** --- 80,85 ---- include_once(PHPMP_ROOT . 'includes/user.php'); $User = new User(); // Create an instance of User. + + createVars(); include_once(PHPMP_ROOT . 'includes/session.php'); *************** *** 86,91 **** $Language = new Language(); - createVars(); - include_once(PHPMP_ROOT . 'includes/mpcode.php'); --- 92,95 ---- *************** *** 104,108 **** //include_once(PHPMP_ROOT . 'includes/Smarty.class.php'); include_once(PHPMP_ROOT . 'includes/template.php'); ! $Template = new Template('index'); // Create an instance of Template. $DB->close(); --- 108,112 ---- //include_once(PHPMP_ROOT . 'includes/Smarty.class.php'); include_once(PHPMP_ROOT . 'includes/template.php'); ! $Template = new Template($Session->page); // Create an instance of Template. $DB->close(); Index: session.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/session.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** session.php 4 May 2003 21:12:06 -0000 1.6 --- session.php 9 May 2003 04:46:48 -0000 1.7 *************** *** 12,15 **** --- 12,16 ---- var $session_user_id; var $ip; + var $page; // Starts the session. Must be called. *************** *** 29,33 **** $exp_time = time() + $Config['session_length']; ! $page = basename($_SERVER['REQUEST_URI']); $SID = "?sid="; --- 30,34 ---- $exp_time = time() + $Config['session_length']; ! $this->page = basename($_SERVER['REQUEST_URI']); $SID = "?sid="; *************** *** 36,40 **** $sql = "UPDATE " . DB_SESSIONS_TABLE . " SET session_exp_time=" . $exp_time . " ! AND session_page='" . $page . "' AND session_user_id=" . ANONYMOUS . " WHERE session_key='" . $this->session_key . "'"; --- 37,41 ---- $sql = "UPDATE " . DB_SESSIONS_TABLE . " SET session_exp_time=" . $exp_time . " ! AND session_page='" . $this->page . "' AND session_user_id=" . ANONYMOUS . " WHERE session_key='" . $this->session_key . "'"; *************** *** 100,104 **** // Capture the page we're at. ! $page = basename($_SERVER['REQUEST_URI']); $cur_time = time(); // Time as of right now. --- 101,105 ---- // Capture the page we're at. ! $this->page = basename($_SERVER['REQUEST_URI']); $cur_time = time(); // Time as of right now. *************** *** 138,142 **** { $sql = "UPDATE " . DB_SESSIONS_TABLE . " ! SET session_exp_time=" . $exp_time . ", session_page='" . addslashes($page) . "', session_user_id=" . $this->session_user_id . " WHERE session_key='" . $this->session_key . "'"; } --- 139,143 ---- { $sql = "UPDATE " . DB_SESSIONS_TABLE . " ! SET session_exp_time=" . $exp_time . ", session_page='" . addslashes($this->page) . "', session_user_id=" . $this->session_user_id . " WHERE session_key='" . $this->session_key . "'"; } *************** *** 144,148 **** { $sql = "UPDATE " . DB_SESSIONS_TABLE . " ! SET session_exp_time=" . $exp_time . ", session_page='" . addslashes($page) . "' WHERE session_key='" . $this->session_key . "'"; } --- 145,149 ---- { $sql = "UPDATE " . DB_SESSIONS_TABLE . " ! SET session_exp_time=" . $exp_time . ", session_page='" . addslashes($this->page) . "' WHERE session_key='" . $this->session_key . "'"; } *************** *** 157,161 **** $sql = 'INSERT INTO ' . DB_SESSIONS_TABLE . ' (session_key, session_user_id, session_start_time, session_exp_time, session_page, session_ip) ! VALUES(\'' . $this->session_key . '\', ' . $this->session_user_id . ', ' . $cur_time . ', ' . $exp_time . ', \'' . addslashes($page) . '\', \'' . $this->ip . '\')'; } --- 158,162 ---- $sql = 'INSERT INTO ' . DB_SESSIONS_TABLE . ' (session_key, session_user_id, session_start_time, session_exp_time, session_page, session_ip) ! VALUES(\'' . $this->session_key . '\', ' . $this->session_user_id . ', ' . $cur_time . ', ' . $exp_time . ', \'' . addslashes($this->page) . '\', \'' . $this->ip . '\')'; } Index: template.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/template.php,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -r1.30 -r1.31 *** template.php 4 May 2003 21:12:06 -0000 1.30 --- template.php 9 May 2003 04:46:48 -0000 1.31 *************** *** 4,8 **** // This will utilize a flat-file template system. ! class template { var $tplname; --- 4,8 ---- // This will utilize a flat-file template system. ! class Template { var $tplname; *************** *** 10,22 **** /** ! * template::template() * * Initializes the template system * Default Constructor * ! * @param $tplname * @return **/ ! function template($tplname) { global $DB; --- 10,26 ---- /** ! * 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; *************** *** 25,28 **** --- 29,80 ---- $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( $arr as $key => $val ) + { + if(preg_match('^A-z0-9_-', $key)) + { + $Template->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 )) && (preg_match('^A-z0-9_-', $new_tpl_var)) && ($new_tpl_val != false)) + { + // Assign one single var to the template vars hash. + $Template->tplvars[$new_tpl_var] = $new_tpl_val; + } } } |