forked from kerphi/phpfreechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpfcuserconfig.class.php
140 lines (119 loc) · 3.45 KB
/
pfcuserconfig.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
require_once dirname(__FILE__)."/pfcglobalconfig.class.php";
class pfcUserConfig
{
var $nick;
var $channels;
var $privmsg;
var $active;
var $timeout;
var $nickid;
var $serverid;
// var $is_init = false; // used internaly to know if the chat config is initialized
// var $errors = array();
function pfcUserConfig()
{
$c =& pfcGlobalConfig::Instance();
// start the session : session is used for locking purpose and cache purpose
if(session_id() == "") session_start();
// the nickid is a public identifier shared between all the chatters
// this is why the session_id must not be assigned directly to the nickid
$this->nickid = sha1(session_id());
// user parameters are cached in sessions
$this->_getParam("nick");
if (!isset($this->nick)) $this->_setParam("nick",""); // setup a blank nick if it is not yet in session
$this->_getParam("active");
if (!isset($this->active)) $this->_setParam("active",false);
$this->_getParam("channels");
if (!isset($this->channels)) $this->_setParam("channels",array());
$this->_getParam("privmsg");
if (!isset($this->privmsg)) $this->_setParam("privmsg",array());
$this->_getParam("serverid");
if (!isset($this->serverid)) $this->_setParam("serverid",$c->serverid);
}
static function &Instance()
{
static $i;
if (!isset($i))
{
$i = new pfcUserConfig();
}
return $i;
}
function &_getParam($p)
{
if (!isset($this->$p))
{
$c =& pfcGlobalConfig::Instance();
$nickid = 'pfcuserconfig_'.$c->getId().'_'.$this->nickid;
$nickid_param = $nickid."_".$p;
if (isset($_SESSION[$nickid_param]))
$this->$p = $_SESSION[$nickid_param];
}
return $this->$p;
}
function _setParam($p, $v)
{
$c =& pfcGlobalConfig::Instance();
$nickid_param = 'pfcuserconfig_'.$c->getId().'_'.$this->nickid.'_'.$p;
$_SESSION[$nickid_param] = $v;
$this->$p = $v;
}
function _rmParam($p)
{
$c =& pfcGlobalConfig::Instance();
$nickid_param = 'pfcuserconfig_'.$c->getId().'_'.$this->nickid.'_'.$p;
unset($_SESSION[$nickid_param]);
unset($this->$p);
if ($p == 'active') $this->active = false;
}
function destroy()
{
$this->_rmParam("nick");
$this->_rmParam("active");
$this->_rmParam("channels");
$this->_rmParam("privmsg");
$this->_rmParam("serverid");
}
function saveInCache()
{
// echo "saveInCache()<br>";
$c =& pfcGlobalConfig::Instance();
// do not save anything as long as nickname is not assigned
//if ($this->active && $this->nick != "")
{
$this->_setParam("nick", $this->nick);
$this->_setParam("active", $this->active);
$this->_setParam("channels", $this->channels);
$this->_setParam("privmsg", $this->privmsg);
$this->_setParam("serverid", $this->serverid);
}
}
function isOnline()
{
$ct =& pfcContainer::Instance();
$online = $ct->isNickOnline(NULL, $this->nickid);
return $online;
}
function getNickname()
{
if ($this->nick != '') return $this->nick;
$ct =& pfcContainer::Instance();
return $ct->getNickname($this->nickid);
}
function getChannelNames()
{
$list = array();
foreach( $this->channels as $v )
$list[] = $v["name"];
return $list;
}
function getPrivMsgNames()
{
$list = array();
foreach( $this->privmsg as $v )
$list[] = $v["name"];
return $list;
}
}
?>