BxNewCommentsAlertsResponse.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup NewComments New Comments
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxNewCommentsAlertsResponse extends BxDolAlertsResponse
  12. {
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. }
  17. public function response($oAlert)
  18. {
  19. if ($oAlert->sAction == 'menu_custom_item'){
  20. if($oAlert->aExtras['item']['module'] == 'bx_new_comments' && $oAlert->aExtras['item']['name'] == 'new-comment'){
  21. if ($oAlert->aExtras['content_data']['cmt_time'] > $this->getPrevSession()){
  22. $oModule = BxDolModule::getInstance('bx_new_comments');
  23. $oAlert->aExtras['res'] = $oModule->_oTemplate->parseHtmlByName('label.html', array('title' => _t('_bx_new_comments_txt_new')));
  24. }
  25. else{
  26. $oAlert->aExtras['res'] = '';
  27. }
  28. $this->setLastVisit();
  29. }
  30. }
  31. }
  32. private function setLastVisit()
  33. {
  34. $iCookieTime = time() + 24 * 3600;
  35. $iLastVistit = time();
  36. if ($iLastVistit - $this->getPrevSession() > 60 * getParam('bx_new_comments_session_interval')){
  37. bx_setcookie("bxNewCommentsPrevSession", $iLastVistit, $iCookieTime);
  38. }
  39. bx_setcookie("bxNewCommentsCurrentSession", $iLastVistit, $iCookieTime);
  40. }
  41. private function getPrevSession()
  42. {
  43. $iLastVistit = isset($_COOKIE['bxNewCommentsPrevSession']) ? $_COOKIE['bxNewCommentsPrevSession'] : 0;
  44. return $iLastVistit;
  45. }
  46. }
  47. /** @} */