Cheetah
ChWsbSession.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbSessionQuery');
9 
10 define('CH_WSB_SESSION_LIFETIME', 3600);
11 define('CH_WSB_SESSION_COOKIE', 'memberSession');
12 
14 {
15  var $oDb;
16  var $sId;
17  var $iUserId;
18  var $aData;
19 
20  public function __construct()
21  {
22  $this->oDb = new ChWsbSessionQuery();
23  $this->sId = '';
24  $this->iUserId = 0;
25  $this->aData = array();
26  }
27 
28  public static function getInstance()
29  {
30  if(!isset($GLOBALS['chWsbClasses']['ChWsbSession']))
31  $GLOBALS['chWsbClasses']['ChWsbSession'] = new ChWsbSession();
32 
33  if(!$GLOBALS['chWsbClasses']['ChWsbSession']->getId())
34  $GLOBALS['chWsbClasses']['ChWsbSession']->start();
35 
36  return $GLOBALS['chWsbClasses']['ChWsbSession'];
37  }
38 
39  public function start()
40  {
41  if (defined('CH_WSB_CRON_EXECUTE'))
42  return true;
43 
44  if($this->exists($this->sId))
45  return true;
46 
47  $this->sId = genRndPwd(32, true);
48 
49  $aUrl = parse_url($GLOBALS['site']['url']);
50  $sPath = isset($aUrl['path']) && !empty($aUrl['path']) ? $aUrl['path'] : '/';
51  setcookie(CH_WSB_SESSION_COOKIE, $this->sId, 0, $sPath, '', false, true);
52 
53  $this->save();
54  return true;
55  }
56 
57  public function destroy()
58  {
59  $aUrl = parse_url($GLOBALS['site']['url']);
60  $sPath = isset($aUrl['path']) && !empty($aUrl['path']) ? $aUrl['path'] : '/';
61  setcookie(CH_WSB_SESSION_COOKIE, '', time() - 86400, $sPath, '', false, true);
62  unset($_COOKIE[CH_WSB_SESSION_COOKIE]);
63 
64  $this->oDb->delete($this->sId);
65 
66  $this->sId = '';
67  $this->iUserId = 0;
68  $this->aData = array();
69  }
70 
71  public function exists($sId = '')
72  {
73  if(empty($sId) && isset($_COOKIE[CH_WSB_SESSION_COOKIE]))
75 
76  $mixedSession = array();
77  if(($mixedSession = $this->oDb->exists($sId)) !== false) {
78  $this->sId = $mixedSession['id'];
79  $this->iUserId = (int)$mixedSession['user_id'];
80  $this->aData = unserialize($mixedSession['data']);
81  return true;
82  } else
83  return false;
84  }
85 
86  public function getId()
87  {
88  return $this->sId;
89  }
90 
91  public function setValue($sKey, $mixedValue)
92  {
93  if(empty($this->sId))
94  $this->start();
95 
96  $this->aData[$sKey] = $mixedValue;
97  $this->save();
98  }
99 
100  public function unsetValue($sKey)
101  {
102  if(empty($this->sId))
103  $this->start();
104 
105  unset($this->aData[$sKey]);
106 
107  if(!empty($this->aData))
108  $this->save();
109  else
110  $this->destroy();
111  }
112 
113  public function getValue($sKey)
114  {
115  if(empty($this->sId))
116  $this->start();
117 
118  return isset($this->aData[$sKey]) ? $this->aData[$sKey] : false;
119  }
120 
121  private function save()
122  {
123  if($this->iUserId == 0)
124  $this->iUserId = getLoggedId();
125 
126  $this->oDb->save($this->sId, array(
127  'user_id' => $this->iUserId,
128  'data' => serialize($this->aData)
129  ));
130  }
131 }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
ChWsbSession\unsetValue
unsetValue($sKey)
Definition: ChWsbSession.php:100
ChWsbSession\$iUserId
$iUserId
Definition: ChWsbSession.php:17
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
php
ChWsbSession\$aData
$aData
Definition: ChWsbSession.php:18
ChWsbSession\getValue
getValue($sKey)
Definition: ChWsbSession.php:113
ChWsbSession\destroy
destroy()
Definition: ChWsbSession.php:57
ChWsbSession\getId
getId()
Definition: ChWsbSession.php:86
CH_WSB_SESSION_COOKIE
const CH_WSB_SESSION_COOKIE
Definition: ChWsbSession.php:11
ChWsbSession
Definition: ChWsbSession.php:14
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
ChWsbSession\$sId
$sId
Definition: ChWsbSession.php:16
ChWsbSession\setValue
setValue($sKey, $mixedValue)
Definition: ChWsbSession.php:91
genRndPwd
genRndPwd($iLength=8, $bSpecialCharacters=true)
Definition: utils.inc.php:1618
ChWsbSession\__construct
__construct()
Definition: ChWsbSession.php:20
time
that in the case of a Adaptation or at a minimum such credit will if a credit for all contributing authors of the Adaptation or Collection then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors For the avoidance of You may only use the credit required by this Section for the purpose of attribution in the manner set out above by exercising Your rights under this You may not implicitly or explicitly assert or imply any connection sponsorship or endorsement by the Original Licensor and or Attribution as of You or Your use of the without the express prior written permission of the Original Licensor and or Attribution Parties Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable if You Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or You must not modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author s honor or reputation Licensor agrees that in those in which any exercise of the right granted in modification or other derogatory action prejudicial to the Original Author s honor and the Licensor will waive or not as this to the fullest extent permitted by the applicable national to enable You to reasonably exercise Your right under Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN LICENSOR OFFERS THE WORK AS IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE STATUTORY OR WITHOUT WARRANTIES OF FITNESS FOR A PARTICULAR OR THE ABSENCE OF LATENT OR OTHER OR THE PRESENCE OF ABSENCE OF WHETHER OR NOT DISCOVERABLE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED SO SUCH EXCLUSION MAY NOT APPLY TO YOU Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License Individuals or entities who have received Adaptations or Collections from You under this will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses and will survive any termination of this License Subject to the above terms and the license granted here is Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time
Definition: license.txt:56
ChWsbSession\$oDb
$oDb
Definition: ChWsbSession.php:15
ChWsbSession\getInstance
static getInstance()
Definition: ChWsbSession.php:28
CH_TAGS_STRIP
const CH_TAGS_STRIP
Definition: utils.inc.php:22
ChWsbSession\start
start()
Definition: ChWsbSession.php:39
ChWsbSessionQuery
Definition: ChWsbSessionQuery.php:14
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChWsbSession\exists
exists($sId='')
Definition: ChWsbSession.php:71
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10