[phpMP-CVS] CVS: phpMP/includes core.php,1.49,1.50 functions.php,1.28,1.29 language.php,1.10,1.11 se
Status: Pre-Alpha
Brought to you by:
heimidal
From: Brian R. <hei...@us...> - 2003-05-09 08:07:42
|
Update of /cvsroot/phpmp/phpMP/includes In directory sc8-pr-cvs1:/tmp/cvs-serv26421/includes Modified Files: core.php functions.php language.php session.php template.php user.php Log Message: Huge update to variable storage system. See the Changelong. Index: core.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/core.php,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -r1.49 -r1.50 *** core.php 9 May 2003 04:46:48 -0000 1.49 --- core.php 9 May 2003 08:07:39 -0000 1.50 *************** *** 64,76 **** define("DB_TEMPLATE_VARS_TABLE", DB_NAME . '.' . DB_TABLE_PREFIX . 'template_vars'); ! $result = $DB->query( "SELECT * FROM " . DB_CONFIG_TABLE ); ! ! // Loop through all config values from DB. ! // Define each key as its respective value. ! while( $row = $DB->fetchArray( $result ) ) ! { ! $Config; ! $Config[$row['config_key']] = $row['config_value']; ! } include_once(PHPMP_ROOT . 'includes/constants.php'); --- 64,68 ---- define("DB_TEMPLATE_VARS_TABLE", DB_NAME . '.' . DB_TABLE_PREFIX . 'template_vars'); ! $Config = new Config(); include_once(PHPMP_ROOT . 'includes/constants.php'); *************** *** 112,115 **** --- 104,151 ---- $DB->close(); } + } + + class Config + { + var $_cfgvars; + + function Config() + { + global $DB; + + $result = $DB->query( "SELECT * FROM " . DB_CONFIG_TABLE ); + + // Loop through all config values from DB. + // Define each key as its respective value. + while( $row = $DB->fetchArray( $result ) ) + { + $this->_cfgvars[$row['config_key']] = $row['config_value']; + } + } + + function set($cfgkey, $cfgval) + { + if( (!empty($cfgkey)) && (eregi('^[a-z]+[_a-z0-9-]*$', $cfgkey)) && (!empty($cfgval)) ) + { + $this->_cfgvars[strtolower($cfgkey)] = $cfgval; + return true; + } + else + { + return false; + } + } + + function get($cfgkey) + { + if( !empty($this->_cfgvars[strtolower($cfgkey)]) ) + { + return $this->_cfgvars[strtolower($cfgkey)]; + } + else + { + return false; + } + } } Index: functions.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/functions.php,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -r1.28 -r1.29 *** functions.php 2 May 2003 04:52:57 -0000 1.28 --- functions.php 9 May 2003 08:07:39 -0000 1.29 *************** *** 9,14 **** global $Config, $User; ! ( $User->data['date_format'] != '' ) ? ($Config['date_format'] = $User->data['date_format']) : ($Config['date_format'] = $Config['default_date_format']); ! $Config['time_now'] = date( $Config['date_format'] ); // This is here...for now. } --- 9,14 ---- global $Config, $User; ! ( $User->get('date_format') != '' ) ? ($Config->set('date_format', $User->get('date_format'))) : ($Config->set('date_format', $Config->get('default_date_format'))); ! $Config->set('time_now', date( $Config->get('date_format') ) ); // This is here...for now. } Index: language.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/language.php,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -r1.10 -r1.11 *** language.php 23 Apr 2003 07:21:03 -0000 1.10 --- language.php 9 May 2003 08:07:39 -0000 1.11 *************** *** 7,13 **** { global $Config, $User, $Local; ! ($User->data['language'] != '') ? ($Config['language'] = $User->data['language']) : ($Config['language'] = $Config['default_lang']); ! include_once( PHPMP_ROOT . 'languages/' . $Config['language'] . '/lang_main.php' ); $Local = new Localization(); --- 7,13 ---- { global $Config, $User, $Local; ! ($User->get('language') != '') ? ($Config->set('language', $User->get('language'))) : ($Config->set('language', $Config->get('default_lang'))); ! include_once( PHPMP_ROOT . 'languages/' . $Config->get('language') . '/lang_main.php' ); $Local = new Localization(); Index: session.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/session.php,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** session.php 9 May 2003 04:46:48 -0000 1.7 --- session.php 9 May 2003 08:07:39 -0000 1.8 *************** *** 29,33 **** global $DB, $Config, $SID; ! $exp_time = time() + $Config['session_length']; $this->page = basename($_SERVER['REQUEST_URI']); --- 29,33 ---- global $DB, $Config, $SID; ! $exp_time = time() + $Config->get('session_length'); $this->page = basename($_SERVER['REQUEST_URI']); *************** *** 43,48 **** $DB->query($sql); ! setcookie($Config['cookie_name'] . '_auto', '', time() - 31536000, $Config['cookie_path'], $Config['cookie_domain'], $Config['cookie_secure']); ! setcookie($Config['cookie_name'] . '_data', '', time() - 31536000, $Config['cookie_path'], $Config['cookie_domain'], $Config['cookie_secure']); } --- 43,48 ---- $DB->query($sql); ! setcookie($Config->get('cookie_name') . '_auto', '', time() - 31536000, $Config->get('cookie_path'), $Config->get('cookie_domain'), $Config->get('cookie_secure')); ! setcookie($Config->get('cookie_name') . '_data', '', time() - 31536000, $Config->get('cookie_path'), $Config->get('cookie_domain'), $Config->get('cookie_secure')); } *************** *** 67,72 **** if( $num_rows == 1 ) // We have a user! { ! $User->data = $DB->fetchAssoc($result); ! $this->session_user_id = $User->data['user_id']; $this->is_logged_in = true; --- 67,72 ---- if( $num_rows == 1 ) // We have a user! { ! $User->set( $DB->fetchAssoc($result) ); ! $this->session_user_id = $User->get('user_id'); $this->is_logged_in = true; *************** *** 74,78 **** { $auto_cookie_data = urlencode( $this->session_user_id . ':' . $passwd_enc ); ! setcookie($Config['cookie_name'] . '_auto', $auto_cookie_data, time() + 31536000, $Config['cookie_path'], $Config['cookie_domain'], $Config['cookie_secure']); } } --- 74,78 ---- { $auto_cookie_data = urlencode( $this->session_user_id . ':' . $passwd_enc ); ! setcookie($Config->get('cookie_name') . '_auto', $auto_cookie_data, time() + 31536000, $Config->get('cookie_path'), $Config->get('cookie_domain'), $Config->get('cookie_secure')); } } *************** *** 104,108 **** $cur_time = time(); // Time as of right now. ! $exp_time = $cur_time + $Config['session_length']; // Time at which this session will become invalid. $this->ip = $User->getIPEncoded(); // Gets the user's IP address. --- 104,108 ---- $cur_time = time(); // Time as of right now. ! $exp_time = $cur_time + $Config->get('session_length'); // Time at which this session will become invalid. $this->ip = $User->getIPEncoded(); // Gets the user's IP address. *************** *** 170,178 **** $result = $DB->query($sql); ! $User->data = $DB->fetchAssoc($result); } $cookie_data = urlencode( $this->session_user_id . ':' . $this->session_key ); ! (setcookie($Config['cookie_name'] . '_data', $cookie_data, $cur_time + $Config['session_length'], $Config['cookie_path'], $Config['cookie_domain'], $Config['cookie_secure'])) ? ($SID = "?sid=") : ($SID = "?sid=" . $this->session_key); $this->clean(); } --- 170,178 ---- $result = $DB->query($sql); ! $User->set( $DB->fetchAssoc($result) ); } $cookie_data = urlencode( $this->session_user_id . ':' . $this->session_key ); ! (setcookie($Config->get('cookie_name') . '_data', $cookie_data, $cur_time + $Config->get('session_length'), $Config->get('cookie_path'), $Config->get('cookie_domain'), $Config->get('cookie_secure'))) ? ($SID = "?sid=") : ($SID = "?sid=" . $this->session_key); $this->clean(); } *************** *** 203,209 **** // Let's see if we have a standard cookie available. ! if(!empty($_COOKIE[$Config['cookie_name'] . '_data'])) { ! $cookie_data = $_COOKIE[$Config['cookie_name'] . '_data']; $cookie_array = explode(':', urldecode( $cookie_data ) ); --- 203,209 ---- // Let's see if we have a standard cookie available. ! if(!empty($_COOKIE[$Config->get('cookie_name') . '_data'])) { ! $cookie_data = $_COOKIE[$Config->get('cookie_name') . '_data']; $cookie_array = explode(':', urldecode( $cookie_data ) ); *************** *** 230,236 **** if( ($this->session_user_id == ANONYMOUS) || empty($this->session_user_id) ) { ! if( !empty( $_COOKIE[$Config['cookie_name'] . '_auto'] ) ) // We have an autologin cookie set. { ! $auto_cookie_data = $_COOKIE[$Config['cookie_name'] . '_auto']; $auto_cookie_array = explode(':', urldecode( $auto_cookie_data ) ); --- 230,236 ---- if( ($this->session_user_id == ANONYMOUS) || empty($this->session_user_id) ) { ! if( !empty( $_COOKIE[$Config->get('cookie_name') . '_auto'] ) ) // We have an autologin cookie set. { ! $auto_cookie_data = $_COOKIE[$Config->get('cookie_name') . '_auto']; $auto_cookie_array = explode(':', urldecode( $auto_cookie_data ) ); *************** *** 244,248 **** if( $num_rows == 1 ) // This cookie is valid. { ! $User->data = $DB->fetchAssoc($result); $this->session_user_id = $auto_cookie_array[0]; $this->is_logged_in = true; --- 244,248 ---- if( $num_rows == 1 ) // This cookie is valid. { ! $User->set( $DB->fetchAssoc($result) ); $this->session_user_id = $auto_cookie_array[0]; $this->is_logged_in = true; *************** *** 251,255 **** { // We'll unset the cookie and continue on like nothing ever happened. ! setcookie($Config['cookie_name'] . '_auto', '', time() - 31536000, $Config['cookie_path'], $Config['cookie_domain'], $Config['cookie_secure']); return false; $this->session_user_id = ANONYMOUS; --- 251,255 ---- { // We'll unset the cookie and continue on like nothing ever happened. ! setcookie($Config->get('cookie_name') . '_auto', '', time() - 31536000, $Config->get('cookie_path'), $Config->get('cookie_domain'), $Config->get('cookie_secure')); return false; $this->session_user_id = ANONYMOUS; Index: template.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/template.php,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -r1.31 -r1.32 *** template.php 9 May 2003 04:46:48 -0000 1.31 --- template.php 9 May 2003 08:07:39 -0000 1.32 *************** *** 7,11 **** { var $tplname; ! var $tplvars = array(); /** --- 7,11 ---- { var $tplname; ! var $_tplvars = array(); /** *************** *** 28,32 **** $this->tplname = $tplname; ! $this->tplvars = $DB->fetchArray($query); } --- 28,32 ---- $this->tplname = $tplname; ! $this->_tplvars = $DB->fetchArray($query); } *************** *** 63,79 **** { // 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; } } --- 63,79 ---- { // 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; } } Index: user.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/user.php,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -r1.19 -r1.20 *** user.php 29 Apr 2003 08:40:54 -0000 1.19 --- user.php 9 May 2003 08:07:39 -0000 1.20 *************** *** 4,8 **** { ! var $data; // Taken from phpBB2. Fetches the IP in a hex form. --- 4,43 ---- { ! var $_data; ! ! function set($userkey, $userval = false) ! { ! if(is_array( $userkey )) ! { ! foreach( $userkey as $key => $val ) ! { ! if(eregi('^[a-z]+[_a-z0-9-]*$', $key)) ! { ! $this->_data[strtolower($key)] = $val; ! } ! } ! } ! elseif( (!empty($userkey)) && (eregi('^[a-z]+[_a-z0-9-]*$', $userkey)) && (!empty($userval)) ) ! { ! $this->_data[strtolower($userkey)] = $userval; ! return true; ! } ! else ! { ! return false; ! } ! } ! ! function get($userkey) ! { ! if( !empty($this->_data[strtolower($userkey)]) ) ! { ! return $this->_data[strtolower($userkey)]; ! } ! else ! { ! return false; ! } ! } // Taken from phpBB2. Fetches the IP in a hex form. |