BxMsgModule.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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_PRIMARY', 1);
  13. define('BX_MSG_FOLDER_DRAFTS', 2);
  14. define('BX_MSG_FOLDER_SPAM', 3);
  15. define('BX_MSG_FOLDER_TRASH', 4);
  16. /**
  17. * Messages module
  18. */
  19. class BxMsgModule extends BxBaseModTextModule
  20. {
  21. function __construct(&$aModule)
  22. {
  23. parent::__construct($aModule);
  24. }
  25. public function sortCollaborators ($aCollaborators, $iProfileIdLastComment, $iProfileIdAuthor, $iProfileIdCurrent = 0)
  26. {
  27. if (!$iProfileIdCurrent)
  28. $iProfileIdCurrent = bx_get_logged_profile_id();
  29. $aMoveUp = array($iProfileIdCurrent, $iProfileIdLastComment, $iProfileIdAuthor);
  30. asort($aCollaborators, SORT_NUMERIC);
  31. foreach ($aMoveUp as $iProfileId) {
  32. if (!isset($aCollaborators[$iProfileId]))
  33. continue;
  34. $a = array($iProfileId => $aCollaborators[$iProfileId]);
  35. unset($aCollaborators[$iProfileId]);
  36. $aCollaborators = $a + $aCollaborators;
  37. }
  38. return $aCollaborators;
  39. }
  40. public function setModuleSubmenu ()
  41. {
  42. bx_import('BxDolMenu');
  43. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  44. if ($oMenuSubmenu)
  45. $oMenuSubmenu->setObjectSubmenu($this->_oConfig->CNF['OBJECT_MENU_SUBMENU'], array (
  46. 'title' => _t('_bx_msg'),
  47. 'link' => 'javascript:void(0);',
  48. 'icon' => '',
  49. ));
  50. }
  51. /**
  52. * Delete message for current user by content id
  53. * @return error message on error, or empty message on success
  54. */
  55. public function deleteMessage ($iContentId)
  56. {
  57. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  58. if (!$aContentInfo)
  59. return _t('_sys_request_page_not_found_cpt');
  60. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedDelete($aContentInfo)))
  61. return $sMsg;
  62. if (!$this->_oDb->moveMessage((int)$iContentId, bx_get_logged_profile_id(), BX_MSG_FOLDER_TRASH))
  63. return _t('_error occured');
  64. return '';
  65. }
  66. public function actionDelete($iContentId)
  67. {
  68. header('Content-Type:text/plain; charset=utf-8');
  69. if ($s = $this->deleteMessage ($iContentId)) {
  70. echo $s;
  71. exit;
  72. }
  73. echo BX_DOL_URL_ROOT . $this->_oConfig->CNF['URL_HOME'];
  74. exit;
  75. }
  76. /**
  77. * Display messages in folder
  78. */
  79. public function actionFolder ($iFolderId)
  80. {
  81. $this->setModuleSubmenu ();
  82. bx_import('BxDolGrid');
  83. $oGrid = BxDolGrid::getObjectInstance('bx_messages');
  84. if (!$oGrid){
  85. $this->_oTemplate->displayErrorOccured();
  86. exit;
  87. }
  88. $aFolder = $this->_oDb->getFolder((int)$iFolderId);
  89. if (!$aFolder) {
  90. $this->_oTemplate->displayPageNotFound();
  91. exit;
  92. }
  93. // TODO: incorporate markers into custom class, so replace will work in search and so on
  94. $oGrid->addMarkers(array(
  95. 'folder_id' => (int)$iFolderId,
  96. 'profile_id' => bx_get_logged_profile_id(),
  97. ));
  98. // TODO: refactor below
  99. $oTemplate = BxDolTemplate::getInstance();
  100. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  101. $oTemplate->setPageHeader (str_replace('{folder}', _t($aFolder['name']), _t('_bx_msg_page_title_folder')));
  102. $oTemplate->setPageContent ('page_main_code', $oGrid->getCode());
  103. $oTemplate->getPageCode();
  104. }
  105. /**
  106. * Get possible recipients for message compose form
  107. */
  108. public function actionAjaxGetRecipients ()
  109. {
  110. $sTerm = bx_get('term');
  111. $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  112. header('Content-Type:text/javascript; charset=utf-8');
  113. echo(json_encode($a));
  114. }
  115. /**
  116. * Update last comment time and author
  117. */
  118. public function serviceTriggerCommentPost ($iContentId, $iProfileId, $iTimestamp = 0)
  119. {
  120. if (!(int)$iContentId)
  121. return false;
  122. $aContentInfo = $this->_oDb->getContentInfoById((int)$iContentId);
  123. if (!$aContentInfo)
  124. return false;
  125. if (!$iTimestamp)
  126. $iTimestamp = time();
  127. if ($iProfileId == bx_get_logged_profile_id())
  128. $this->_oDb->updateReadComments($iProfileId, $aContentInfo[$this->_oConfig->CNF['FIELD_ID']], $aContentInfo[$this->_oConfig->CNF['FIELD_COMMENTS']]);
  129. return $this->_oDb->updateLastCommentTimeProfile((int)$iContentId, (int)$iProfileId, $iTimestamp);
  130. }
  131. /**
  132. * Entry collaborators block
  133. */
  134. public function serviceEntityCollaborators ($iContentId = 0)
  135. {
  136. if (!$iContentId)
  137. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  138. if (!$iContentId)
  139. return false;
  140. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  141. if (!$aContentInfo)
  142. return false;
  143. return $this->_oTemplate->entryCollaborators ($aContentInfo, 5, 'right');
  144. }
  145. /**
  146. * No moderators for personal messages
  147. */
  148. protected function _isModerator ($isPerformAction = false)
  149. {
  150. return false;
  151. }
  152. /**
  153. * No thumbs for messages
  154. */
  155. public function checkAllowedSetThumb ()
  156. {
  157. return _t('_sys_txt_access_denied');
  158. }
  159. /**
  160. * Only collaborators can view message
  161. */
  162. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  163. {
  164. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = parent::checkAllowedView ($aDataEntry, $isPerformAction)))
  165. return $sMsg;
  166. $aCollaborators = $this->_oDb->getCollaborators($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]);
  167. return isset($aCollaborators[bx_get_logged_profile_id()]) ? CHECK_ACTION_RESULT_ALLOWED : _t('_sys_txt_access_denied');
  168. }
  169. }
  170. /** @} */