BxMsgModule.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Messages Messages
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import ('BxBaseModTextModule');
  12. define('BX_MSG_FOLDER_INBOX', 1);
  13. define('BX_MSG_FOLDER_SENT', 2);
  14. define('BX_MSG_FOLDER_DRAFTS', 3);
  15. define('BX_MSG_FOLDER_SPAM', 4);
  16. define('BX_MSG_FOLDER_TRASH', 5);
  17. /**
  18. * Messages module
  19. */
  20. class BxMsgModule extends BxBaseModTextModule
  21. {
  22. function __construct(&$aModule)
  23. {
  24. parent::__construct($aModule);
  25. }
  26. public function sortCollaborators ($aCollaborators, $iProfileIdLastComment, $iProfileIdAuthor, $iProfileIdCurrent = 0)
  27. {
  28. if (!$iProfileIdCurrent)
  29. $iProfileIdCurrent = bx_get_logged_profile_id();
  30. $aMoveUp = array($iProfileIdCurrent, $iProfileIdLastComment, $iProfileIdAuthor);
  31. asort($aCollaborators, SORT_NUMERIC);
  32. foreach ($aMoveUp as $iProfileId) {
  33. if (!isset($aCollaborators[$iProfileId]))
  34. continue;
  35. $a = array($iProfileId => $aCollaborators[$iProfileId]);
  36. unset($aCollaborators[$iProfileId]);
  37. $aCollaborators = $a + $aCollaborators;
  38. }
  39. return $aCollaborators;
  40. }
  41. public function setModuleSubmenu ()
  42. {
  43. bx_import('BxDolMenu');
  44. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  45. if ($oMenuSubmenu)
  46. $oMenuSubmenu->setObjectSubmenu($this->_oConfig->CNF['OBJECT_MENU_SUBMENU'], array (
  47. 'title' => 'Messages',
  48. 'link' => 'javascript:void(0);',
  49. 'icon' => '',
  50. ));
  51. }
  52. /**
  53. * Display messages in folder
  54. */
  55. public function actionFolder ($iFolderId)
  56. {
  57. $this->setModuleSubmenu ();
  58. bx_import('BxDolGrid');
  59. $oGrid = BxDolGrid::getObjectInstance('bx_messages');
  60. if (!$oGrid){
  61. $this->_oTemplate->displayErrorOccured();
  62. exit;
  63. }
  64. // TODO: incorporate markers into custom class, so replace will work in search and so on
  65. $oGrid->addMarkers(array(
  66. 'folder_id' => (int)$iFolderId,
  67. 'profile_id' => bx_get_logged_profile_id(),
  68. ));
  69. // TODO: refactor below
  70. $oTemplate = BxDolTemplate::getInstance();
  71. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  72. $oTemplate->setPageContent ('page_main_code', $oGrid->getCode());
  73. $oTemplate->getPageCode();
  74. }
  75. /**
  76. * Get possible recipients for message compose form
  77. */
  78. public function actionAjaxGetRecipients ()
  79. {
  80. $sTerm = bx_get('term');
  81. $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  82. header('Content-Type:text/javascript; charset=utf-8');
  83. echo(json_encode($a));
  84. }
  85. /**
  86. * Update last comment time and author
  87. */
  88. public function serviceTriggerCommentPost ($iContentId, $iProfileId, $iTimestamp = 0)
  89. {
  90. if (!(int)$iContentId)
  91. return false;
  92. $aContentInfo = $this->_oDb->getContentInfoById((int)$iContentId);
  93. if (!$aContentInfo)
  94. return false;
  95. if (!$iTimestamp)
  96. $iTimestamp = time();
  97. if ($iProfileId == bx_get_logged_profile_id())
  98. $this->_oDb->updateReadComments($iProfileId, $aContentInfo[$this->_oConfig->CNF['FIELD_ID']], $aContentInfo[$this->_oConfig->CNF['FIELD_COMMENTS']]);
  99. return $this->_oDb->updateLastCommentTimeProfile((int)$iContentId, (int)$iProfileId, $iTimestamp);
  100. }
  101. /**
  102. * Entry collaborators block
  103. */
  104. public function serviceEntityCollaborators ($iContentId = 0)
  105. {
  106. if (!$iContentId)
  107. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  108. if (!$iContentId)
  109. return false;
  110. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  111. if (!$aContentInfo)
  112. return false;
  113. return $this->_oTemplate->entryCollaborators ($aContentInfo, 5, 'right');
  114. }
  115. /**
  116. * No moderators for personal messages
  117. */
  118. protected function _isModerator ($isPerformAction = false)
  119. {
  120. return false;
  121. }
  122. /**
  123. * No thumbs for messages
  124. */
  125. public function checkAllowedSetThumb ()
  126. {
  127. return _t('_sys_txt_access_denied');
  128. }
  129. /**
  130. * Only collaborators can view message
  131. */
  132. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  133. {
  134. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = parent::checkAllowedView ($aDataEntry, $isPerformAction)))
  135. return $sMsg;
  136. $aCollaborators = $this->_oDb->getCollaborators($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]);
  137. return isset($aCollaborators[bx_get_logged_profile_id()]) ? CHECK_ACTION_RESULT_ALLOWED : _t('_sys_txt_access_denied');
  138. }
  139. }
  140. /** @} */