| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup Convos Convos
- * @ingroup DolphinModules
- *
- * @{
- */
- bx_import ('BxBaseModTextModule');
- define('BX_CNV_FOLDER_INBOX', 1);
- define('BX_CNV_FOLDER_DRAFTS', 2);
- define('BX_CNV_FOLDER_SPAM', 3);
- define('BX_CNV_FOLDER_TRASH', 4);
- /**
- * Conversations module
- */
- class BxCnvModule extends BxBaseModTextModule
- {
- function __construct(&$aModule)
- {
- parent::__construct($aModule);
- }
- public function sortCollaborators ($aCollaborators, $iProfileIdLastComment, $iProfileIdAuthor, $iProfileIdCurrent = 0)
- {
- if (!$iProfileIdCurrent)
- $iProfileIdCurrent = bx_get_logged_profile_id();
- $aMoveUp = array($iProfileIdCurrent, $iProfileIdLastComment, $iProfileIdAuthor);
- asort($aCollaborators, SORT_NUMERIC);
- foreach ($aMoveUp as $iProfileId) {
- if (!isset($aCollaborators[$iProfileId]))
- continue;
- $a = array($iProfileId => $aCollaborators[$iProfileId]);
- unset($aCollaborators[$iProfileId]);
- $aCollaborators = $a + $aCollaborators;
- }
- return $aCollaborators;
- }
- public function setModuleSubmenu ($iCurrentFolderId = 0)
- {
- $CNF = &$this->_oConfig->CNF;
- $aMapFolderId2MenuName = array (
- BX_CNV_FOLDER_INBOX => 'convos-folder-inbox',
- BX_CNV_FOLDER_DRAFTS => 'convos-drafts',
- BX_CNV_FOLDER_SPAM => 'convos-spam',
- BX_CNV_FOLDER_TRASH => 'convos-trash',
- );
- bx_import('BxDolMenu');
- $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
- if (!$oMenuSubmenu)
- return;
- $oMenuSubmenu->setObjectSubmenu($CNF['OBJECT_MENU_SUBMENU'], array (
- 'title' => _t('_bx_cnv'),
- 'link' => BX_DOL_URL_ROOT . $CNF['URL_HOME'],
- 'icon' => '',
- ));
- $oMenuModule = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU']);
- if ($oMenuModule && isset($aMapFolderId2MenuName[$iCurrentFolderId]))
- $oMenuModule->setSelected($this->_aModule['name'], $aMapFolderId2MenuName[$iCurrentFolderId]);
- }
- /**
- * Mark conversation as unread for the current user
- * @return error string on error, or empty string on success
- */
- public function markUnread ($iContentId)
- {
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if (!$aContentInfo)
- return _t('_sys_request_page_not_found_cpt');
- if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aContentInfo)))
- return $sMsg;
- if (!$this->_oDb->updateReadComments(bx_get_logged_profile_id(), (int)$iContentId, -1))
- return _t('_error occured');
- return '';
- }
- /**
- * Delete conversation for current user by content id
- * @return error string on error, or empty string on success
- */
- public function deleteConvo ($iContentId)
- {
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if (!$aContentInfo)
- return _t('_sys_request_page_not_found_cpt');
- if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedDelete($aContentInfo)))
- return $sMsg;
- if (!$this->_oDb->moveConvo((int)$iContentId, bx_get_logged_profile_id(), BX_CNV_FOLDER_TRASH))
- return _t('_error occured');
- return '';
- }
- public function actionMarkUnread($iContentId)
- {
- header('Content-Type:text/plain; charset=utf-8');
- if ($s = $this->markUnread ($iContentId)) {
- echo $s;
- exit;
- }
- echo BX_DOL_URL_ROOT . $this->_oConfig->CNF['URL_HOME'];
- exit;
- }
- public function actionDelete($iContentId)
- {
- header('Content-Type:text/plain; charset=utf-8');
- if ($s = $this->deleteConvo ($iContentId)) {
- echo $s;
- exit;
- }
- echo BX_DOL_URL_ROOT . $this->_oConfig->CNF['URL_HOME'];
- exit;
- }
- /**
- * Display convos in folder
- */
- public function actionFolder ($iFolderId)
- {
- bx_import('BxDolGrid');
- $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID']);
- if (!$oGrid){
- $this->_oTemplate->displayErrorOccured();
- exit;
- }
- $aFolder = $this->_oDb->getFolder((int)$iFolderId);
- if (!$aFolder) {
- $this->_oTemplate->displayPageNotFound();
- exit;
- }
- $this->setModuleSubmenu ((int)$iFolderId);
- // TODO: incorporate markers into custom class, so replace will work in search and so on
- $oGrid->addMarkers(array(
- 'folder_id' => (int)$iFolderId,
- 'profile_id' => bx_get_logged_profile_id(),
- ));
- // TODO: refactor below
- $oTemplate = BxDolTemplate::getInstance();
- $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
- $oTemplate->setPageHeader (str_replace('{folder}', _t($aFolder['name']), _t('_bx_cnv_page_title_folder')));
- $oTemplate->setPageContent ('page_main_code', $oGrid->getCode());
- $oTemplate->getPageCode();
- }
- /**
- * Get possible recipients for start conversation form
- */
- public function actionAjaxGetRecipients ()
- {
- $sTerm = bx_get('term');
- $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
-
- header('Content-Type:text/javascript; charset=utf-8');
- echo(json_encode($a));
- }
- /**
- * Get number of unread messages for spme profile
- * @param $iProfileId - profile to get unread messages for, if omitted then currently logged is profile is used
- * @return integer
- */
- public function serviceGetUnreadMessagesNum ($iProfileId = 0)
- {
- if (!$iProfileId)
- $iProfileId = bx_get_logged_profile_id();
- return $this->_oDb->getUnreadMessagesNum((int)$iProfileId);
- }
- /**
- * Update last comment time and author
- */
- public function serviceTriggerCommentPost ($iContentId, $iProfileId, $iTimestamp = 0)
- {
- if (!(int)$iContentId)
- return false;
- $aContentInfo = $this->_oDb->getContentInfoById((int)$iContentId);
- if (!$aContentInfo)
- return false;
-
- if (!$iTimestamp)
- $iTimestamp = time();
- if ($iProfileId == bx_get_logged_profile_id())
- $this->_oDb->updateReadComments($iProfileId, $aContentInfo[$this->_oConfig->CNF['FIELD_ID']], $aContentInfo[$this->_oConfig->CNF['FIELD_COMMENTS']]);
- return $this->_oDb->updateLastCommentTimeProfile((int)$iContentId, (int)$iProfileId, $iTimestamp);
- }
- /**
- * Entry collaborators block
- */
- public function serviceEntityCollaborators ($iContentId = 0)
- {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if (!$aContentInfo)
- return false;
-
- return $this->_oTemplate->entryCollaborators ($aContentInfo, 5, 'right');
- }
- /**
- * No moderators for personal convos
- */
- protected function _isModerator ($isPerformAction = false)
- {
- return false;
- }
- /**
- * No thumbs for convos
- */
- public function checkAllowedSetThumb ()
- {
- return _t('_sys_txt_access_denied');
- }
- /**
- * Only collaborators can view convo
- */
- public function checkAllowedView ($aDataEntry, $isPerformAction = false)
- {
- if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = parent::checkAllowedView ($aDataEntry, $isPerformAction)))
- return $sMsg;
- $aCollaborators = $this->_oDb->getCollaborators($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]);
- return isset($aCollaborators[bx_get_logged_profile_id()]) ? CHECK_ACTION_RESULT_ALLOWED : _t('_sys_txt_access_denied');
- }
- }
- /** @} */
|