[Owp-cvs] owp/inc/classes tmain.class,NONE,1.1 tusersession.class,NONE,1.1
Status: Inactive
Brought to you by:
scader
From: <owp...@li...> - 2006-04-25 22:27:16
|
Update of /cvsroot/owp/owp/inc/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8738/classes Added Files: tmain.class tusersession.class Log Message: integrated main class with everything we need for work --- NEW FILE: tmain.class --- <?php /* Copyright (c) 2006, 2realities Group All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the 2realities Group nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /**Main class, contains everything we need to work * @package owp * @author Artem Sidorenko <ar...@2r...> * @version $Id: tmain.class,v 1.1 2006/04/25 22:27:07 scader Exp $ * @copyright (c) 2004-2006 2realities Group (www.2realities.com) */ /**Max length of GET string*/ @ define('security_get_max_length',150); /**we need some functions for parsing*/ include_once 'incoming_data_functions.inc'; /**Class for working with session and cookies*/ include_once 'tusersession.class'; class tmain{ /**Contains all input data, added only for compatibility and is deprecated, please don't use in anymore *@var array */ var $input = array(); /**Contains all unsafe input data, added only for compatibility and is deprecated, please don't use in anymore *@var array */ var $input_unsafe = array(); /**Contains save GET data *@var array */ var $get = array(); /**Contains save POST data *@var array */ var $post = array(); /**Contains unsafe GET data *@var array */ var $get_unsafe = array(); /**Contains unsafe POST data *@var array */ var $post_unsafe = array(); /**Contains save FILES data *@var array */ var $files = array(); /**Contains unsafe FILES data *@var array */ var $files_unsafe = array(); /**Object for working with cookies and session *@var tusersession */ var $usersession = false; /**Constructor */ function tmain(){ //processing GET data $get = substr(getenv ('QUERY_STRING') ,0,security_get_max_length); if(strpos($get,'?')!==false){//if we have GET data $get = ereg_replace(".*\\?","",$get); parse_str($get,$this->get_unsafe); $this->get_unsafe = strip_magic_quotes($this->get_unsafe); $this->get = parse_incoming_data($this->get_unsafe); }//\\if //processing POST data $this->post_unsafe = strip_magic_quotes($_POST); $this->post = parse_incoming_data($this->post_unsafe); //processing FILES data /**/ //meging our data, order GET,POST,FILES #unsafe data $this->input_unsafe = array_merge($this->get_unsafe,$this->post_unsafe,$this->files_unsafe); #save data $this->input = array_merge($this->get,$this->post,$this->files); //creating usersession object $this->usersession = &new tusersession(); }//\\tmain }//\\tmain ?> --- NEW FILE: tusersession.class --- <?php /* Copyright (c) 2006, 2realities Group All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the 2realities Group nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /**Class for working with user sessions and cookies * @package owp * @author Artem Sidorenko <ar...@2r...> * @version $Id: tusersession.class,v 1.1 2006/04/25 22:27:07 scader Exp $ * @copyright (c) 2004-2006 2realities Group (www.2realities.com) */ /**constant to define cookies in methods of tusersession*/ define('USER_COOKIES',1); /**constant to define session in methods of tusersession*/ define('USER_SESSION',2); /**name of test cookie*/ @ define('usersession_test_cookie_name','test_cookie'); /**name of var with first call data*/ @ define('usersession_first_call_session_var','usersession_first_call'); /**name of var with cookies data, in case if cookies are disabled*/ @ define('usersession_cookies_session_var','usersession_cookies'); /**name of var with cookie status data, internal use only*/ @ define('usersession_cookies_processed','usersession_cookies_processed'); /**we need some functions for parsing*/ include_once 'incoming_data_functions.inc'; class tusersession{ /**array with cookies, readonly *@var array */ var $cookies = array(); /**array with session data, readwrite, but it's recommended to use methods *@var array */ var $session = array(); /**status of cookies *@var bool */ var $cookies_enabled = false; /**constructor*/ function tusersession(){ //start session session_start(); //linking our property $this->session = &$_SESSION; //init cookies $this->session[usersession_cookies_session_var] = array(); //first call? if(!$this->get_data(usersession_first_call_session_var)){//sending test cookie setcookie(usersession_test_cookie_name,1); $this->edit_data(usersession_first_call_session_var,1); }//\\if elseif(isset($_COOKIE[usersession_test_cookie_name])){ $this->cookies_enabled = true; //checking if existing cookies already processed if(!$this->get_data(usersession_cookies_processed)){ $this->edit_data(usersession_cookies_processed,1); foreach($this->session[usersession_cookies_session_var] as $k=>$v){ setcookie($k,$v); $_COOKIE[$k]=$v; }//\\foreach }//\\if //processing our cookies $this->cookies = strip_magic_quotes($_COOKIE); //it must be safe! $this->cookies = parse_incoming_data($this->cookies); }//\\if else $this->cookies = $this->session[usersession_cookies_session_var] ; }//\\tusersession /**Edit or add data *@param string $name name *@param mixed $value value *@param integer $type type of var: USER_COOKIES or USER_SESSION. These are constants */ function edit_data($name,$value,$type=USER_SESSION){ if($type==USER_SESSION) $this->session[$name]=$value; elseif($type==USER_COOKIES){ if($this->cookies_enabled) setcookie($name,$value); else $this->sesson[usersession_cookies_session_var][$name]=$value; }//\\elseif else return false; }//\\edit_data /**Remove data *@param string $name name *@param integer $type type of var: USER_COOKIES or USER_SESSION. These are constants */ function remove_data($name,$type=USER_SESSION){ if($type==USER_SESSION) unset($this->session[$name]); elseif($type==USER_COOKIES){ if($this->cookies_enabled) setcookie($name,''); else unset($this->sesson[usersession_cookies_session_var][$name]); }//\\elseif else return false; }//\\remove_data /**returns requered data, or false if not defined *@param string $name name of var *@param integer $type type of var: USER_COOKIES or USER_SESSION. These are constants *@return bool value or bool false */ function get_data($name,$type=USER_SESSION){ if($type==USER_SESSION){ if(!isset($this->session[$name]))//doesn't exists return false; return $this->session[$name];//OK }//\\if elseif($type==USER_COOKIES){ if(isset($this->cookies[$name])) return $this->cookies[$name]; }//\\elseif else return false; }//\\get_data }//\\tusersession ?> |