Cheetah
ChShoutBoxDb.php
Go to the documentation of this file.
1 <?php
2 
8 require_once(CH_DIRECTORY_PATH_CLASSES . 'ChWsbModuleDb.php');
9 
11 {
12  var $_oConfig;
13 
14  var $_aObjects = array();
15 
19  function __construct(&$oConfig)
20  {
21  parent::__construct();
22 
23  $this->_oConfig = $oConfig;
24  $this->_aObjects = $this->getShoutboxObjects();
25  }
26 
27  function getShoutboxObjects()
28  {
29  if (!isset($GLOBALS['ch_dol_shoutbox_objects'])) {
30  $GLOBALS['ch_dol_shoutbox_objects'] = $GLOBALS['MySQL']->fromCache('ch_shoutbox_objects', 'getAllWithKey',
31  'SELECT * FROM `ch_shoutbox_objects`', 'name');
32  }
33 
34  return $GLOBALS['ch_dol_shoutbox_objects'];
35  }
36 
38  {
39  $this->cleanCache('ch_shoutbox_objects');
40  }
41 
52  function writeMessage($sObject, $iHandler, $sMessage, $iOwnerId = 0, $iIP = 0)
53  {
54  if (!isset($this->_aObjects[$sObject])) {
55  return false;
56  }
57 
59  $iOwnerId = (int)$iOwnerId;
60  if (!preg_match('/^[0-9]+$/', $iIP)) {
61  $iIP = 0;
62  }
63 
64  $sQuery =
65  "
66  INSERT INTO
67  `{$this -> _aObjects[$sObject]['table']}`
68  SET
69  `HandlerID` = {$iHandler},
70  `OwnerID` = {$iOwnerId},
71  `Message` = '{$sMessage}',
72  `Date` = TIMESTAMP( NOW() ),
73  `IP` = {$iIP}
74  ";
75 
76  return (int)$this->query($sQuery) > 0 ? $this->lastId() : false;
77  }
78 
86  function getLastMessageId($sObject, $iHandler)
87  {
88  if (!isset($this->_aObjects[$sObject])) {
89  return false;
90  }
91 
92  $sQuery = "SELECT `ID` FROM `{$this -> _aObjects[$sObject]['table']}` WHERE `HandlerID` = '{$iHandler}' ORDER BY `ID` DESC LIMIT 1";
93  $iLastId = $this->getOne($sQuery);
94 
95  return ($iLastId) ? $iLastId : 0;
96  }
97 
109  function getMessages($sObject, $iHandler, $iLastId)
110  {
111  if (!isset($this->_aObjects[$sObject])) {
112  return false;
113  }
114 
115  $iLastId = (int)$iLastId;
116  $sQuery = "SELECT *, UNIX_TIMESTAMP(`Date`) AS `DateTS` FROM `{$this -> _aObjects[$sObject]['table']}` WHERE `HandlerID` = '{$iHandler}' AND `ID` > " . (int)$iLastId . " ORDER BY `ID`";
117 
118  return $this->getAll($sQuery);
119  }
120 
128  function getMessagesCount($sObject, $iHandler)
129  {
130  if (!isset($this->_aObjects[$sObject])) {
131  return false;
132  }
133 
134  $sQuery = "SELECT COUNT(*) FROM `{$this -> _aObjects[$sObject]['table']}` WHERE `HandlerID` = '{$iHandler}'";
135 
136  return $this->getOne($sQuery);
137  }
138 
147  function getMessageInfo($sObject, $iHandler, $iMessageId)
148  {
149  if (!isset($this->_aObjects[$sObject])) {
150  return array();
151  }
152 
153  $iMessageId = (int)$iMessageId;
154  $sQuery = "SELECT * FROM `{$this -> _aObjects[$sObject]['table']}` WHERE `HandlerID` = '{$iHandler}' AND `ID` = {$iMessageId}";
155  $aInfo = $this->getAll($sQuery);
156 
157  return $aInfo ? array_shift($aInfo) : array();
158  }
159 
166  function deleteMessages($sObject, $iHandler, $iLimit)
167  {
168  if (!isset($this->_aObjects[$sObject])) {
169  return false;
170  }
171 
172  $iLimit = (int)$iLimit;
173  $sQuery = "DELETE FROM `{$this -> _aObjects[$sObject]['table']}` WHERE `HandlerID` = {$iHandler} ORDER BY `ID` LIMIT {$iLimit}";
174  $this->query($sQuery);
175  }
176 
185  function deleteMessage($sObject, $iHandler, $iMessageId)
186  {
187  if (!isset($this->_aObjects[$sObject])) {
188  return false;
189  }
190 
191  $iMessageId = (int)$iMessageId;
192  $sQuery = "DELETE FROM `{$this -> _aObjects[$sObject]['table']}` WHERE `HandlerID` = {$iHandler} AND `ID` = {$iMessageId}";
193 
194  return $this->query($sQuery);
195  }
196 
205  function deleteMessagesByIp($sObject, $iHandler, $iIp)
206  {
207  if (!isset($this->_aObjects[$sObject])) {
208  return false;
209  }
210 
211  $iIp = (int)$iIp;
212 
213  foreach ($this->_aObjects as $a) {
214  $sQuery = "DELETE FROM `{$a['table']}` WHERE `IP` = {$iIp}";
215  $this->query($sQuery);
216  }
217  }
218 
226  {
227  $iProfileId = (int)$iProfileId;
228  foreach ($this->_aObjects as $a) {
229  $sQuery = "DELETE FROM `{$a['table']}` WHERE `OwnerID` = {$iProfileId}";
230  $this->query($sQuery);
231  }
232  }
233 
240  function deleteOldMessages($iLifeTime)
241  {
242  if (!is_numeric($iLifeTime)) {
243  return;
244  }
245 
246  foreach ($this->_aObjects as $a) {
247  $sQuery = "DELETE FROM `{$a['table']}` WHERE FROM_UNIXTIME( UNIX_TIMESTAMP() - {$iLifeTime} ) >= `Date`";
248  db_res($sQuery);
249  }
250  }
251 
258  {
259  return $this->getOne("SELECT `kateg` FROM `sys_options` WHERE `Name` = ?", [$sName]);
260  }
261 
262  function insertData($aData)
263  {
264  foreach ($aData as $a) {
265  $this->query("INSERT INTO `ch_shoutbox_objects` (`name`, `title`, `table`, `code_allow_use`, `code_allow_delete`, `code_allow_block`) VALUES (?, ?, ?, ?, ?, ?)",
266  [
267  $a['name'],
268  $a['title'],
269  $a['table'],
270  $a['code_allow_use'],
271  $a['code_allow_delete'],
272  $a['code_allow_block']
273  ]);
274  }
275  }
276 
277  function deleteData($aData)
278  {
279  foreach ($aData as $a) {
280  $this->query("DELETE FROM `ch_shoutbox_objects` WHERE `name` = ?", [$a['name']]);
281  }
282  }
283 
284 }
ChShoutBoxDb\deleteMessages
deleteMessages($sObject, $iHandler, $iLimit)
Definition: ChShoutBoxDb.php:166
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
ChShoutBoxDb\writeMessage
writeMessage($sObject, $iHandler, $sMessage, $iOwnerId=0, $iIP=0)
Definition: ChShoutBoxDb.php:52
$sMessage
$sMessage
Definition: actions.inc.php:17
ChShoutBoxDb\getMessagesCount
getMessagesCount($sObject, $iHandler)
Definition: ChShoutBoxDb.php:128
ChShoutBoxDb\deleteData
deleteData($aData)
Definition: ChShoutBoxDb.php:277
ChShoutBoxDb\__construct
__construct(&$oConfig)
Definition: ChShoutBoxDb.php:19
ChShoutBoxDb\$_oConfig
$_oConfig
Definition: ChShoutBoxDb.php:12
ChShoutBoxDb\insertData
insertData($aData)
Definition: ChShoutBoxDb.php:262
php
ChShoutBoxDb\clearShoutboxObjectsCache
clearShoutboxObjectsCache()
Definition: ChShoutBoxDb.php:37
ChWsbModuleDb
Definition: ChWsbModuleDb.php:12
ChWsbDb\getAll
getAll($sQuery, $aBindings=[], $iFetchType=PDO::FETCH_ASSOC)
Definition: ChWsbDb.php:206
$aInfo
$aInfo
Definition: constants.inc.php:21
ChWsbDb\query
query($sQuery, $aBindings=[])
Definition: ChWsbDb.php:386
ChShoutBoxDb\getShoutboxObjects
getShoutboxObjects()
Definition: ChShoutBoxDb.php:27
ChShoutBoxDb\deleteMessagesByIp
deleteMessagesByIp($sObject, $iHandler, $iIp)
Definition: ChShoutBoxDb.php:205
ChWsbDb\getOne
getOne($sQuery, $aBindings=[], $iIndex=0)
Definition: ChWsbDb.php:263
ChShoutBoxDb\getLastMessageId
getLastMessageId($sObject, $iHandler)
Definition: ChShoutBoxDb.php:86
ChShoutBoxDb\getMessages
getMessages($sObject, $iHandler, $iLastId)
Definition: ChShoutBoxDb.php:109
ChShoutBoxDb
Definition: ChShoutBoxDb.php:11
db_res
db_res($query, $bindings=[])
Definition: db.inc.php:39
ChShoutBoxDb\getMessageInfo
getMessageInfo($sObject, $iHandler, $iMessageId)
Definition: ChShoutBoxDb.php:147
ChShoutBoxDb\deleteOldMessages
deleteOldMessages($iLifeTime)
Definition: ChShoutBoxDb.php:240
ChShoutBoxDb\getSettingsCategory
getSettingsCategory($sName)
Definition: ChShoutBoxDb.php:257
ChWsbDb\cleanCache
cleanCache($sName)
Definition: ChWsbDb.php:565
ChShoutBoxDb\$_aObjects
$_aObjects
Definition: ChShoutBoxDb.php:14
ChWsbDb\lastId
lastId()
Definition: ChWsbDb.php:449
ChShoutBoxDb\deleteMessagesByProfile
deleteMessagesByProfile($iProfileId)
Definition: ChShoutBoxDb.php:225
CH_SLASHES_AUTO
const CH_SLASHES_AUTO
Definition: utils.inc.php:27
ChShoutBoxDb\deleteMessage
deleteMessage($sObject, $iHandler, $iMessageId)
Definition: ChShoutBoxDb.php:185
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$sName
$sName
Definition: ChWsbAdminTools.php:853
$iProfileId
if( $sMembersList) $iProfileId
Definition: communicator.php:29
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10