Cheetah
ChShoutBoxModule.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbModuleDb');
9 ch_import('ChWsbModule');
10 
47 {
49 
50  // contain some module information ;
52 
53  // contain path for current module;
55 
56  // contain logged member's Id;
58 
59  // contain all used templates
60  var $aUsedTemplates = array();
61 
62  // shoutbox objects
63  var $_aObjects = array();
64 
78  function __construct(&$aModule)
79  {
80  parent::__construct($aModule);
81 
82  // prepare the location link ;
83  $this->sPathToModule = CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri();
84  $this->sModuleName = 'ch_' . $aModule['uri'];
85  $this->aModuleInfo = $aModule;
86  $this->iMemberId = getLoggedId();
87  $this->_aObjects = $this->_oDb->getShoutboxObjects();
88  }
89 
97  function actionWriteMessage($sObject, $iHandler)
98  {
99  if ($this->_checkObjectAndHandler($sObject, $iHandler) && $this->isShoutBoxAllowed($sObject, $iHandler,
100  $this->iMemberId, true)
101  ) {
102 
103  $sMessage = isset($_POST['message'])
104  ? htmlentities($_POST['message'], ENT_COMPAT, 'UTF-8', false)
105  : '';
106 
107  if ($sMessage) {
108  // create new message;
109  $iMessage = $this->_oDb->writeMessage($sObject, $iHandler, $sMessage, $this->iMemberId, sprintf("%u", ip2long(getVisitorIP())));
110  if($iMessage !== false) {
111  $oAlert = new ChWsbAlerts($this -> sModuleName, 'add', $iMessage, $this -> iMemberId, array('Object' => $sObject, 'Message' => $sMessage));
112  $oAlert->alert();
113  }
114 
115  if (1 == rand(1, 10) && $this->_oConfig->iAllowedMessagesCount) { // "sometimes" delete old messages
116  // delete superfluous messages;
117  $iMessagesCount = $this->_oDb->getMessagesCount($sObject, $iHandler);
118  if ($iMessagesCount > $this->_oConfig->iAllowedMessagesCount) {
119  $this->_oDb->deleteMessages($sObject, $iHandler,
120  $iMessagesCount - $this->_oConfig->iAllowedMessagesCount);
121  }
122  }
123  } else {
124  echo _t('_ch_shoutbox_message_empty');
125  }
126  } else {
127  echo _t('_ch_shoutbox_access_denied');
128  }
129  }
130 
139  function actionBlockMessage($sObject, $iHandler, $iMessageId = 0)
140  {
141  $sCallBackMessage = '';
142  $iMessageId = (int)$iMessageId;
143 
144  //check membership level
145  if ($this->_checkObjectAndHandler($sObject, $iHandler) && $this->isShoutBoxBlockIpAllowed($sObject, $iHandler,
146  $this->iMemberId) && $iMessageId > 0
147  ) {
148  //get message info
149  $aMessageInfo = $this->_oDb->getMessageInfo($sObject, $iHandler, $iMessageId);
150  if (!$aMessageInfo) {
151  $sCallBackMessage = _t('_Error Occured');
152  } else {
153  //block user IP
154  ch_block_ip((int)$aMessageInfo['IP'], $this->_oConfig->iBlockExpirationSec,
155  _t('_ch_shoutbox_ip_blocked'));
156 
157  $this->_oDb->deleteMessagesByIp($sObject, $iHandler, $aMessageInfo['IP']);
158  }
159  } else {
160  $sCallBackMessage = _t('_ch_shoutbox_access_denied');
161  }
162 
163  echo $sCallBackMessage;
164  }
165 
174  function actionDeleteMessage($sObject, $iHandler, $iMessageId = 0)
175  {
176  $sCallBackMessage = '';
177  $iMessageId = (int)$iMessageId;
178 
179  //check membership level
180  if ($this->_checkObjectAndHandler($sObject, $iHandler) && $this->isShoutBoxDeleteAllowed($sObject, $iHandler,
181  $this->iMemberId) && $iMessageId > 0
182  ) {
183  if ($this->_oDb->deleteMessage($sObject, $iHandler, $iMessageId)) {
184  $this->isShoutBoxDeleteAllowed($sObject, $iHandler, $this->iMemberId, true);
185  } else {
186  $sCallBackMessage = _t('_Error Occured');
187  }
188  } else {
189  $sCallBackMessage = _t('_ch_shoutbox_access_denied');
190  }
191 
192  echo $sCallBackMessage;
193  }
194 
203  function actionGetMessages($sObject, $iHandler, $iLastMessageId = 0)
204  {
205  $iLastMessageId = (int)$iLastMessageId;
206  $aRetArray = array();
207 
208  if ($this->_checkObjectAndHandler($sObject, $iHandler)) {
209  $sMessages = $this->_getLastMessages($sObject, $iHandler, $iLastMessageId);
210  $iLastMessageId = $this->_oDb->getLastMessageId($sObject, $iHandler);
211 
212  $aRetArray = array(
213  'messages' => $sMessages,
214  'last_message_id' => $iLastMessageId,
215  );
216  }
217 
218  echo json_encode($aRetArray);
219  }
220 
227  {
228  $GLOBALS['iAdminPage'] = 1;
229 
230  if (!isAdmin()) {
231  header('location: ' . CH_WSB_URL_ROOT);
232  }
233 
234  $aLanguageKeys = array(
235  'settings' => _t('_ch_shoutbox_settings'),
236  );
237 
238  // try to define globals category number;
239  $iId = $this->_oDb->getSettingsCategory('shoutbox_update_time');
240  if (!$iId) {
241  $sContent = MsgBox(_t('_Empty'));
242  } else {
243  ch_import('ChWsbAdminSettings');
244 
245  $mixedResult = '';
246  if (isset($_POST['save']) && isset($_POST['cat'])) {
248  $mixedResult = $oSettings->saveChanges($_POST);
249  }
250 
252  $sResult = $oSettings->getForm();
253 
254  if ($mixedResult !== true && !empty($mixedResult)) {
255  $sResult = $mixedResult . $sResult;
256  }
257 
258  $sContent = $GLOBALS['oAdmTemplate']
259  ->parseHtmlByName('design_box_content.html', array('content' => $sResult));
260  }
261 
262  $this->_oTemplate->pageCodeAdminStart();
263  echo $this->_oTemplate->adminBlock($sContent, $aLanguageKeys['settings']);
264  $this->_oTemplate->pageCodeAdmin(_t('_ch_shoutbox_module'));
265  }
266 
273  function serviceGetShoutBox($sObject = 'ch_shoutbox', $iHandler = 0)
274  {
275  if (!$this->_checkObjectAndHandler($sObject, $iHandler)) {
276  $sObject = 'ch_shoutbox';
277  }
278 
279  echo $this->_oTemplate->getShoutboxWindow($sObject, $iHandler, $this->sPathToModule
280  , $this->_oDb->getLastMessageId($sObject, $iHandler), $this->_getLastMessages($sObject, $iHandler));
281  }
282 
290  {
291  if (!($iProfileId = (int)$oAlert->iObject)) {
292  return false;
293  }
294 
295  $this->_oDb->deleteMessagesByProfile((int)$iProfileId);
296 
297  return true;
298  }
299 
303  function serviceUpdateObjects($sModuleUri = 'all', $bInstall = true)
304  {
305  $aModules = $sModuleUri == 'all' ? $this->_oDb->getModules() : array($this->_oDb->getModuleByUri($sModuleUri));
306 
307  foreach ($aModules as $aModule) {
308  if (!ChWsbRequest::serviceExists($aModule, 'get_shoutbox_data')) {
309  continue;
310  }
311 
312  if (!($aData = ChWsbService::call($aModule['uri'], 'get_shoutbox_data'))) {
313  continue;
314  }
315 
316  if ($bInstall) {
317  $this->_oDb->insertData($aData);
318  } else {
319  $this->_oDb->deleteData($aData);
320  }
321  }
322 
323  $this->_oDb->clearShoutboxObjectsCache();
324  }
325 
334  function _getLastMessages($sObject, $iHandler, $iLastId = 0)
335  {
336  return $this->_oTemplate->getProcessedMessages($this->_oDb->getMessages($sObject, $iHandler, $iLastId)
337  , $this->isShoutBoxDeleteAllowed($sObject, $iHandler, $this->iMemberId)
338  , $this->isShoutBoxBlockIpAllowed($sObject, $iHandler, $this->iMemberId));
339  }
340 
346  function _defineActions()
347  {
349  array('shoutbox use', 'shoutbox delete messages', 'shoutbox block by ip')
350  );
351  }
352 
360  function isShoutBoxAllowed($sObject, $iHandler, $iMemberId, $isPerformAction = false)
361  {
362  if (isAdmin()) {
363  return true;
364  }
365 
366  if ($this->_aObjects[$sObject]['code_allow_use']) {
367  return $this->_runCheckAllowedCustom($sObject, $iHandler, $iMemberId, $isPerformAction,
368  $this->_aObjects[$sObject]['code_allow_use']);
369  }
370 
371  if (!defined('CH_SHOUTBOX_USE')) {
372  $this->_defineActions();
373  }
374 
375  $aCheck = checkAction($iMemberId, CH_SHOUTBOX_USE, $isPerformAction);
376 
378  }
379 
387  function isShoutBoxDeleteAllowed($sObject, $iHandler, $iMemberId, $isPerformAction = false)
388  {
389  if (isAdmin()) {
390  return true;
391  }
392 
393  if ($this->_aObjects[$sObject]['code_allow_delete']) {
394  return $this->_runCheckAllowedCustom($sObject, $iHandler, $iMemberId, $isPerformAction,
395  $this->_aObjects[$sObject]['code_allow_delete']);
396  }
397 
398  if (!defined('CH_SHOUTBOX_DELETE_MESSAGES')) {
399  $this->_defineActions();
400  }
401 
402  $aCheck = checkAction($iMemberId, CH_SHOUTBOX_DELETE_MESSAGES, $isPerformAction);
403 
405  }
406 
414  function isShoutBoxBlockIpAllowed($sObject, $iHandler, $iMemberId, $isPerformAction = false)
415  {
416  if (isAdmin()) {
417  return true;
418  }
419 
420  if ($this->_aObjects[$sObject]['code_allow_block']) {
421  return $this->_runCheckAllowedCustom($sObject, $iHandler, $iMemberId, $isPerformAction,
422  $this->_aObjects[$sObject]['code_allow_block']);
423  }
424 
425 
426  if (!defined('CH_SHOUTBOX_BLOCK_BY_IP')) {
427  $this->_defineActions();
428  }
429 
430  $aCheck = checkAction($iMemberId, CH_SHOUTBOX_BLOCK_BY_IP, $isPerformAction);
431 
433  }
434 
435  function _checkObjectAndHandler($sObject, &$iHandler)
436  {
437  $iHandler = (int)$iHandler;
438 
439  return isset($this->_aObjects[$sObject]);
440  }
441 
442  function _runCheckAllowedCustom($sObject, $iHandler, $iMemberId, $isPerformAction, $sCode)
443  {
444  return eval($sCode);
445  }
446 }
header
</code > Be careful enabling this directive if you have a redirector script that does not use the< code > Location</code > HTTP header
Definition: URI.MungeResources.txt:10
$oSettings
$oSettings
Definition: advanced_settings.php:20
ChShoutBoxModule
Definition: ChShoutBoxModule.php:47
getVisitorIP
getVisitorIP($isProxyCheck=true)
Definition: utils.inc.php:643
$sMessage
$sMessage
Definition: actions.inc.php:17
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
ChShoutBoxModule\actionWriteMessage
actionWriteMessage($sObject, $iHandler)
Definition: ChShoutBoxModule.php:97
ChShoutBoxModule\actionAdministration
actionAdministration()
Definition: ChShoutBoxModule.php:226
ChWsbRequest\serviceExists
static serviceExists($mixedModule, $sMethod, $sClass="Module")
Definition: ChWsbRequest.php:70
ChShoutBoxModule\actionBlockMessage
actionBlockMessage($sObject, $iHandler, $iMessageId=0)
Definition: ChShoutBoxModule.php:139
$sCode
$sCode
Definition: explanation.php:19
CHECK_ACTION_RESULT_ALLOWED
const CHECK_ACTION_RESULT_ALLOWED
Definition: membership_levels.inc.php:60
$sResult
$sResult
Definition: advanced_settings.php:26
ChShoutBoxModule\_runCheckAllowedCustom
_runCheckAllowedCustom($sObject, $iHandler, $iMemberId, $isPerformAction, $sCode)
Definition: ChShoutBoxModule.php:442
ChShoutBoxModule\isShoutBoxBlockIpAllowed
isShoutBoxBlockIpAllowed($sObject, $iHandler, $iMemberId, $isPerformAction=false)
Definition: ChShoutBoxModule.php:414
$aModule
$aModule
Definition: classifieds.php:21
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
ChShoutBoxModule\serviceGetShoutBox
serviceGetShoutBox($sObject='ch_shoutbox', $iHandler=0)
Definition: ChShoutBoxModule.php:273
$oAlert
$oAlert
Definition: embed.php:15
CHECK_ACTION_RESULT
const CHECK_ACTION_RESULT
Definition: membership_levels.inc.php:54
ChShoutBoxModule\_checkObjectAndHandler
_checkObjectAndHandler($sObject, &$iHandler)
Definition: ChShoutBoxModule.php:435
php
$iId
$iId
Definition: license.php:15
ChShoutBoxModule\actionDeleteMessage
actionDeleteMessage($sObject, $iHandler, $iMessageId=0)
Definition: ChShoutBoxModule.php:174
ChShoutBoxModule\_defineActions
_defineActions()
Definition: ChShoutBoxModule.php:346
ChShoutBoxModule\$sModuleName
$sModuleName
Definition: ChShoutBoxModule.php:48
ChShoutBoxModule\_getLastMessages
_getLastMessages($sObject, $iHandler, $iLastId=0)
Definition: ChShoutBoxModule.php:334
isAdmin
isAdmin()
Definition: index.php:649
ChShoutBoxModule\serviceResponseProfileDelete
serviceResponseProfileDelete($oAlert)
Definition: ChShoutBoxModule.php:289
ChWsbAlerts
Definition: ChWsbAlerts.php:39
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
ChShoutBoxModule\$aModuleInfo
$aModuleInfo
Definition: ChShoutBoxModule.php:51
ChWsbModule
Definition: ChWsbModule.php:41
$sContent
$sContent
Definition: bottom_menu_compose.php:169
ChShoutBoxModule\serviceUpdateObjects
serviceUpdateObjects($sModuleUri='all', $bInstall=true)
Definition: ChShoutBoxModule.php:303
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
ChShoutBoxModule\actionGetMessages
actionGetMessages($sObject, $iHandler, $iLastMessageId=0)
Definition: ChShoutBoxModule.php:203
ChWsbAdminSettings
Definition: ChWsbAdminSettings.php:35
checkAction
checkAction($iMemberId, $actionID, $performAction=false, $iForcedProfID=0, $isCheckMemberStatus=true)
Definition: membership_levels.inc.php:313
ChShoutBoxModule\$_aObjects
$_aObjects
Definition: ChShoutBoxModule.php:63
defineMembershipActions
defineMembershipActions($aActionsAll, $sPrefix='CH_')
Definition: membership_levels.inc.php:744
$aModules
$aModules
Definition: constants.inc.php:29
ChShoutBoxModule\$iMemberId
$iMemberId
Definition: ChShoutBoxModule.php:57
ChShoutBoxModule\$sPathToModule
$sPathToModule
Definition: ChShoutBoxModule.php:54
ChShoutBoxModule\isShoutBoxAllowed
isShoutBoxAllowed($sObject, $iHandler, $iMemberId, $isPerformAction=false)
Definition: ChShoutBoxModule.php:360
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChWsbService\call
static call($mixed, $sMethod, $aParams=array(), $sClass='Module')
Definition: ChWsbService.php:32
ChShoutBoxModule\__construct
__construct(&$aModule)
Definition: ChShoutBoxModule.php:78
ChShoutBoxModule\isShoutBoxDeleteAllowed
isShoutBoxDeleteAllowed($sObject, $iHandler, $iMemberId, $isPerformAction=false)
Definition: ChShoutBoxModule.php:387
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChShoutBoxModule\$aUsedTemplates
$aUsedTemplates
Definition: ChShoutBoxModule.php:60
ch_block_ip
ch_block_ip($mixedIP, $iExpirationInSec=86400, $sComment='')
Definition: utils.inc.php:977
$iProfileId
if( $sMembersList) $iProfileId
Definition: communicator.php:29
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10