Cheetah
functions.inc.php
Go to the documentation of this file.
1 <?php
2 
12 function getBoards($sMode = 'new', $sId = "")
13 {
18 
19  $iCurrentTime = time();
20  $iUpdateInterval = (int)getSettingValue($sModule, "updateInterval");
21  $iNewTime = $iUpdateInterval * 2;
22  $iIdleTime = $iUpdateInterval * 3;
23  $iDeleteTime = $iUpdateInterval * 6;
24  $sBoards = "";
25  switch ($sMode) {
26  case 'update':
27  getResult("UPDATE `" . MODULE_DB_PREFIX . "Boards` SET `When`='" . $iCurrentTime . "', `Status`='" . BOARD_STATUS_NORMAL . "' WHERE `OwnerID`='" . $sId . "' AND (`Status`='" . BOARD_STATUS_NORMAL . "' OR (`Status`='" . BOARD_STATUS_NEW . "' AND `When`<='" . ($iCurrentTime - $iNewTime) . "'))");
28 
29  //--- delete old boards ---//
30  $rFiles = getResult("SELECT `ID` FROM `" . MODULE_DB_PREFIX . "Boards` WHERE `Status`='" . BOARD_STATUS_DELETE . "' AND `When`<=(" . ($iCurrentTime - $iDeleteTime) . ")");
31  while($aFile = $rFiles->fetch()) @unlink($sFilesPath . $aFile['ID'] . $sFileExtension);
32  getResult("DELETE FROM `" . MODULE_DB_PREFIX . "Boards`, `" . MODULE_DB_PREFIX . "Users` USING `" . MODULE_DB_PREFIX . "Boards` LEFT JOIN `" . MODULE_DB_PREFIX . "Users` ON `" . MODULE_DB_PREFIX . "Boards`.`ID`=`" . MODULE_DB_PREFIX . "Users`.`Board` WHERE `" . MODULE_DB_PREFIX . "Boards`.`Status`='" . BOARD_STATUS_DELETE . "' AND `" . MODULE_DB_PREFIX . "Boards`.`When`<=(" . ($iCurrentTime - $iDeleteTime) . ")");
33 
34  getResult("UPDATE `" . MODULE_DB_PREFIX . "Boards` SET `Status`='" . BOARD_STATUS_DELETE . "' WHERE `When`<'" . ($iCurrentTime - $iIdleTime) . "' AND `Status`<>'" . BOARD_STATUS_DELETE . "'");
35 
36  $rResult = getResult("SELECT * FROM `" . MODULE_DB_PREFIX . "Boards` WHERE `OwnerID`<>'" . $sId . "' AND `Status`<>'" . BOARD_STATUS_NORMAL . "'");
37  while($aBoard = $rResult->fetch())
38  switch($aBoard['Status']) {
39  case BOARD_STATUS_DELETE:
40  $sBoards .= parseXml($aXmlTemplates['board'], $aBoard['ID'], BOARD_STATUS_DELETE);
41  break;
42  case BOARD_STATUS_NEW:
43  $sBoards .= parseXml($aXmlTemplates['board'], $aBoard['ID'], BOARD_STATUS_NORMAL, $aBoard['OwnerID'], empty($aBoard['Password']) ? FALSE_VAL : TRUE_VAL, stripslashes($aBoard['Name']));
44  break;
45  }
46 
47  $rResult = getResult("SELECT `boards`.`ID` FROM `" . MODULE_DB_PREFIX . "Boards` AS `boards` INNER JOIN `" . MODULE_DB_PREFIX . "Users` AS `users` ON `boards`.`ID`=`users`.`Board` WHERE `boards`.`OwnerID`<>'" . $sId . "'");
48  while($aBoard = $rResult->fetch()) {
49  $sFile = $sFilesPath . $aBoard['ID'] . $sFileExtension;
50  if(!file_exists($sFile)) continue;
51  $iModifiedTime = filemtime($sFile);
52  if($iModifiedTime >= ($iCurrentTime - $iUpdateInterval))
53  $sBoards .= parseXml($aXmlTemplates['board'], $aBoard['ID'], BOARD_STATUS_UPDATED);
54  }
55  break;
56 
57  case 'updateUsers':
58  $sSql = "SELECT `r`.`ID` AS `BoardID`, GROUP_CONCAT(DISTINCT IF(`ru`.`Status`<>'" . BOARD_STATUS_DELETE . "',`ru`.`User`,'') SEPARATOR ',') AS `In`, GROUP_CONCAT(DISTINCT IF(`ru`.`Status`='" . BOARD_STATUS_DELETE . "',`ru`.`User`,'') SEPARATOR ',') AS `Out` FROM `" . MODULE_DB_PREFIX . "Boards` AS `r` INNER JOIN `" . MODULE_DB_PREFIX . "Users` AS `ru` WHERE `r`.`ID`=`ru`.`Board` AND `r`.`Status`='" . BOARD_STATUS_NORMAL . "' AND `ru`.`When`>=" . ($iCurrentTime - $iUpdateInterval) . " GROUP BY `r`.`ID`";
59  $rResult = getResult($sSql);
60  while($aBoard = $rResult->fetch())
61  $sBoards .= parseXml($aXmlTemplates['board'], $aBoard['BoardID'], $aBoard['In'], $aBoard['Out']);
62  break;
63 
64  case 'all':
65  $iRunTime = isset($_REQUEST['_t']) ? floor($_REQUEST['_t']/1000) : 0;
66  $iCurrentTime -= $iRunTime;
67  $rResult = getResult("SELECT `ID` FROM `" . MODULE_DB_PREFIX . "Users`");
68  if($rResult->rowCount() == 0) getResult("TRUNCATE TABLE `" . MODULE_DB_PREFIX . "Users`");
69  $iBoardsCount = getValue("SELECT COUNT(`ID`) FROM `" . MODULE_DB_PREFIX . "Boards`");
70 
71  $sSql = "SELECT `r`.`ID` AS `BoardID`, `r`.*, GROUP_CONCAT(DISTINCT IF(`ru`.`Status`='" . BOARD_STATUS_NORMAL . "' AND `ru`.`User`<>'" . $sId . "',`ru`.`User`,'') SEPARATOR ',') AS `In`, GROUP_CONCAT(DISTINCT IF(`ru`.`Status`='" . BOARD_STATUS_DELETE . "' AND `ru`.`User`<>'" . $sId . "',`ru`.`User`,'') SEPARATOR ',') AS `Out` FROM `" . MODULE_DB_PREFIX . "Boards` AS `r` LEFT JOIN `" . MODULE_DB_PREFIX . "Users` AS `ru` ON `r`.`ID`=`ru`.`Board` GROUP BY `r`.`ID` ORDER BY `r`.`ID`";
72  $rResult = getResult($sSql);
73  while($aBoard = $rResult->fetch()) {
74  $sBoards .= parseXml($aXmlTemplates['board'], $aBoard['BoardID'], BOARD_STATUS_NORMAL, $aBoard['OwnerID'], empty($aBoard['Password']) ? FALSE_VAL : TRUE_VAL, $aBoard['In'], stripslashes($aBoard['Name']));
75  }
76  if($rResult->rowCount() === 0) {
77  getResult("TRUNCATE TABLE `" . MODULE_DB_PREFIX . "Boards`");
78  getResult("TRUNCATE TABLE `" . MODULE_DB_PREFIX . "Users`");
79  }
80  break;
81  }
82  return $sBoards;
83 }
84 
88 function doBoard($sSwitch, $sUserId = "", $iBoardId = 0, $sTitle = "", $sPassword = "")
89 {
90  $iCurrentTime = time();
91  switch ($sSwitch) {
92  case 'insert':
93  $iBoardId = getValue("SELECT `ID` FROM `" . MODULE_DB_PREFIX . "Boards` WHERE `Name`='" . $sTitle . "' AND `OwnerID`='" . $sUserId . "'");
94  if(empty($iBoardId)) {
95  getResult("INSERT INTO `" . MODULE_DB_PREFIX . "Boards` (`ID`, `Name`, `Password`, `OwnerID`, `When`) VALUES ('" . $iBoardId . "', '" . $sTitle . "', '" . $sPassword . "', '" . $sUserId . "', '" . $iCurrentTime . "')");
97  }
98  return $iBoardId;
99  break;
100 
101  case 'update':
102  getResult("UPDATE `" . MODULE_DB_PREFIX . "Boards` SET `Name`='" . $sTitle . "', `Password`='" . $sPassword . "', `When`='" . $iCurrentTime . "', `Status`='" . BOARD_STATUS_NEW . "' WHERE `ID`='" . $iBoardId . "'");
103  break;
104 
105  case 'delete':
106  getResult("UPDATE `" . MODULE_DB_PREFIX . "Boards` SET `When`='" . $iCurrentTime . "', `Status`='" . BOARD_STATUS_DELETE . "' WHERE `ID` = '" . $iBoardId . "'");
107  break;
108 
109  case 'enter':
110  $sId = getValue("SELECT `ID` FROM `" . MODULE_DB_PREFIX . "Users` WHERE `Board`='" . $iBoardId . "' AND `User`='" . $sUserId . "' LIMIT 1");
111  if(empty($sId)) getResult("INSERT INTO `" . MODULE_DB_PREFIX . "Users`(`Board`, `User`, `When`) VALUES('" . $iBoardId . "', '" . $sUserId . "', '" . $iCurrentTime . "')");
112  else getResult("UPDATE `" . MODULE_DB_PREFIX . "Users` SET `When`='" . $iCurrentTime . "', `Status`='" . BOARD_STATUS_NORMAL . "' WHERE `ID`='" . $sId . "'");
113  break;
114 
115  case 'exit':
116  getResult("UPDATE `" . MODULE_DB_PREFIX . "Users` SET `When`='" . $iCurrentTime . "', `Status`='" . BOARD_STATUS_DELETE . "' WHERE `Board`='" . $iBoardId . "' AND `User`='" . $sUserId . "' LIMIT 1");
117  break;
118  }
119 }
120 
126 function refreshUsersInfo($sId = "", $sMode = 'all')
127 {
132 
133  $iUpdateInterval = (int)getSettingValue($sModule, "updateInterval");
134  $iIdleTime = $iUpdateInterval * 3;
135  $iDeleteTime = $iUpdateInterval * 6;
136 
137  $iCurrentTime = time();
138  //--- refresh current user's track ---//
139  getResult("UPDATE `" . MODULE_DB_PREFIX . "CurrentUsers` SET `Status`='" . USER_STATUS_OLD . "', `When`='" . $iCurrentTime . "' WHERE `ID`='" . $sId . "' AND (`Status`<>'" . USER_STATUS_NEW . "' || (" . $iCurrentTime . "-`When`)>" . $iUpdateInterval . ") LIMIT 1");
140 
141  //--- refresh other users' states ---//
142  getResult("UPDATE `" . MODULE_DB_PREFIX . "CurrentUsers` SET `When`=" . $iCurrentTime . ", `Status`='" . USER_STATUS_IDLE . "' WHERE `Status`<>'" . USER_STATUS_IDLE . "' AND `When`<=(" . ($iCurrentTime - $iIdleTime) . ")");
143  getResult("DELETE FROM `" . MODULE_DB_PREFIX . "Users` WHERE `Status`='" . BOARD_STATUS_DELETE . "' AND `When`<=(" . ($iCurrentTime - $iDeleteTime) . ")");
144 
145  //--- delete idle users, whose track was not refreshed more than delete time ---//
146  getResult("DELETE FROM `" . MODULE_DB_PREFIX . "CurrentUsers`, `" . MODULE_DB_PREFIX . "Users` USING `" . MODULE_DB_PREFIX . "CurrentUsers` LEFT JOIN `" . MODULE_DB_PREFIX . "Users` ON `" . MODULE_DB_PREFIX . "CurrentUsers`.`ID`=`" . MODULE_DB_PREFIX . "Users`.`User` WHERE `" . MODULE_DB_PREFIX . "CurrentUsers`.`Status`='" . USER_STATUS_IDLE . "' AND `" . MODULE_DB_PREFIX . "CurrentUsers`.`When`<=" . ($iCurrentTime - $iDeleteTime));
147 
148  //--- Get information about users in the chat ---//
149  switch($sMode) {
150  case 'update':
151  $rRes = getResult("SELECT * FROM `" . MODULE_DB_PREFIX . "CurrentUsers` ORDER BY `When`");
152  while($aUser = $rRes->fetch()) {
153  switch($aUser['Status']) {
154  case USER_STATUS_NEW:
155  $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], $aUser['Status'], $aUser['Nick'], $aUser['Sex'], $aUser['Age'], $aUser['Photo'], $aUser['Profile'], $aUser['Desc']);
156  break;
157  case USER_STATUS_IDLE:
158  $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], $aUser['Status']);
159  break;
160  }
161  }
162  break;
163 
164  case 'all':
165  $iRunTime = isset($_REQUEST['_t']) ? floor($_REQUEST['_t']/1000) : 0;
166  $iCurrentTime -= $iRunTime;
167  $rRes = getResult("SELECT * FROM `" . MODULE_DB_PREFIX . "CurrentUsers` WHERE `Status`<>'" . USER_STATUS_IDLE . "' ORDER BY `When`");
168  while($aUser = $rRes->fetch())
169  $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], USER_STATUS_NEW, $aUser['Nick'], $aUser['Sex'], $aUser['Age'], $aUser['Photo'], $aUser['Profile'], $aUser['Desc']);
170  break;
171  }
172  return makeGroup($sContent, "users");
173 }
getLastInsertId
getLastInsertId()
Definition: db.inc.php:66
$sMode
else $sMode
Definition: antispam.php:362
refreshUsersInfo
refreshUsersInfo($sId="", $sMode='all')
Definition: functions.inc.php:126
php
getBoards
getBoards($sMode='new', $sId="")
Definition: functions.inc.php:12
getValue
getValue($sQuery)
Definition: db.inc.php:59
$sModule
if(!file_exists($sRayHeaderPath)) $sModule
Definition: index.php:14
doBoard
doBoard($sSwitch, $sUserId="", $iBoardId=0, $sTitle="", $sPassword="")
Definition: functions.inc.php:88
$sPassword
$sPassword
Definition: actions.inc.php:10
$sFile
$sFile
Definition: index.php:20
$iBoardId
$iBoardId
Definition: actions.inc.php:12
$sTitle
$sTitle
Definition: actions.inc.php:13
$_REQUEST
$_REQUEST['action']
Definition: cmd.php:11
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
$sContent
$sContent
Definition: bottom_menu_compose.php:169
$sFileExtension
$sFileExtension
Definition: header.inc.php:9
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
parseXml
parseXml($aXmlTemplates)
Definition: apiFunctions.inc.php:15
makeGroup
makeGroup($sXmlContent, $sXmlGroup="ray")
Definition: apiFunctions.inc.php:32
$aUser
$aUser
Definition: profiles.inc.php:74
$aXmlTemplates
$aXmlTemplates
Definition: xmlTemplates.inc.php:8
$sId
$sId
Definition: actions.inc.php:8
getSettingValue
getSettingValue($sWidget, $sSettingKey, $sFile="config", $bFullReturn=false, $sFolder="xml")
Definition: apiFunctions.inc.php:82
$sFilesPath
$sFilesPath
Definition: header.inc.php:10
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
getResult
getResult($sQuery)
Definition: db.inc.php:45