| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481 |
- <?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 Notes Notes
- * @ingroup DolphinModules
- *
- * @{
- */
- bx_import ('BxDolModule');
- bx_import ('BxDolAcl');
- /**
- * Notes module
- */
- class BxNotesModule extends BxDolModule
- {
- protected $_iProfileId;
- function __construct(&$aModule)
- {
- parent::__construct($aModule);
- $this->_iProfileId = bx_get_logged_profile_id();
- }
- // ====== SERVICE METHODS
- /**
- * Display pablic entries
- * @return HTML string
- */
- public function serviceBrowsePublic ()
- {
- return $this->_serviceBrowse ('public');
- }
- /**
- * Display featured entries
- * @return HTML string
- */
- public function serviceBrowseFeatured ()
- {
- return $this->_serviceBrowse ('public');
- }
- /**
- * Display entries of the author
- * @return HTML string
- */
- public function serviceBrowseAuthor ($iProfileId = 0)
- {
- if (!$iProfileId)
- $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
- if (!$iProfileId)
- return '';
- return $this->_serviceBrowse ('author', array('author' => $iProfileId));
- }
- /**
- * Add entry form
- * @return HTML string
- */
- public function serviceEntityCreate ()
- {
- bx_import('FormsEntryHelper', $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
- $oFormsHelper = new $sClass($this);
- return $oFormsHelper->addDataForm();
- }
- /**
- * Edit entry form
- * @return HTML string
- */
- public function serviceEntityEdit ($iContentId = 0)
- {
- return $this->_serviceEntityForm ('editDataForm', $iContentId);
- }
- /**
- * Delete entry form
- * @return HTML string
- */
- public function serviceEntityDelete ($iContentId = 0)
- {
- return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
- }
- /**
- * Entry text with some additional controls
- */
- public function serviceEntityTextBlock ($iContentId = 0)
- {
- return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
- }
- /**
- * Additional entry info
- */
- public function serviceEntityInfo ($iContentId = 0)
- {
- return $this->_serviceEntityForm ('viewDataForm', $iContentId);
- }
- /**
- * Entry social sharing block
- */
- public function serviceEntitySocialSharing ($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;
- $CNF = &$this->_oConfig->CNF;
- bx_import('BxDolPermalinks');
- $sUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
- $aCustomParams = false;
- if ($aContentInfo[$CNF['FIELD_THUMB']]) {
- bx_import('BxDolStorage');
- $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
- if ($oStorage && ($sImgUrl = $oStorage->getFileUrlById($aContentInfo[$CNF['FIELD_THUMB']]))) {
- $aCustomParams = array (
- 'img_url' => $sImgUrl,
- 'img_url_encoded' => rawurlencode($sImgUrl),
- );
- }
- }
- //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
- $sVotes = '';
- bx_import('BxDolVote');
- $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]);
- if ($oVotes)
- $sVotes = $oVotes->getElementBlock(array('show_do_vote_as_button' => true));
- $sShare = '';
- if (BxDolRequest::serviceExists('bx_timeline', 'get_share_element_block'))
- $sShare = BxDolService::call('bx_timeline', 'get_share_element_block', array(bx_get_logged_profile_id(), $this->_aModule['name'], 'added', $aContentInfo[$CNF['FIELD_ID']], array('show_do_share_as_button' => true)));
- bx_import('BxTemplSocialSharing');
- $sSocial = BxTemplSocialSharing::getInstance()->getCode($iContentId, $this->_aModule['name'], BX_DOL_URL_ROOT . $sUrl, $aContentInfo[$CNF['FIELD_TITLE']], $aCustomParams);
- return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
- 'vote' => $sVotes,
- 'share' => $sShare,
- 'social' => $sSocial,
- ));
- //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
- }
- /**
- * Entry comments
- */
- public function serviceEntityComments ($iContentId = 0)
- {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- bx_import('BxDolCmts');
- $oCmts = BxDolCmts::getObjectInstance($this->_oConfig->CNF['OBJECT_COMMENTS'], $iContentId);
- if(!$oCmts->isEnabled())
- return false;
- return $oCmts->getCommentsBlock(0, 0, false);
- }
- /**
- * Entry author block
- */
- public function serviceEntityAuthor ($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;
- $oProfile = BxDolProfile::getInstance($aContentInfo[$this->_oConfig->CNF['FIELD_AUTHOR']]);
- if (!$oProfile) {
- bx_import('BxDolProfileUndefined');
- $oProfile = BxDolProfileUndefined::getInstance();
- }
- return $this->_oTemplate->entryAuthor ($aContentInfo, $oProfile);
- }
- /**
- * Entry actions block
- */
- public function serviceEntityActions ($iContentId = 0)
- {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- bx_import('BxTemplMenu');
- $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
- return $oMenu ? $oMenu->getCode() : false;
- }
- /**
- * My entries actions block
- */
- public function serviceMyEntriesActions ($iProfileId = 0)
- {
- if (!$iProfileId)
- $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
- if (!$iProfileId || $iProfileId != $this->_iProfileId)
- return false;
- bx_import('BxTemplMenu');
- $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
- return $oMenu ? $oMenu->getCode() : false;
- }
- /**
- * Data for Timeline
- */
- public function serviceGetTimelineData()
- {
- return array(
- 'handlers' => array(
- array('type' => 'insert', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'added', 'module_name' => $this->_aModule['name'], 'module_method' => 'get_timeline_post', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
- array('type' => 'update', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'edited'),
- array('type' => 'delete', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'deleted')
- ),
- 'alerts' => array(
- array('unit' => $this->_aModule['name'], 'action' => 'added'),
- array('unit' => $this->_aModule['name'], 'action' => 'edited'),
- array('unit' => $this->_aModule['name'], 'action' => 'deleted'),
- )
- );
- }
- /**
- * Entry post for Timeline
- */
- public function serviceGetTimelinePost($aEvent)
- {
- $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
- if(empty($aContentInfo) || !is_array($aContentInfo))
- return '';
- $CNF = &$this->_oConfig->CNF;
- bx_import('BxDolPermalinks');
- $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
- //--- Image(s)
- $sImage = '';
- if($aContentInfo[$CNF['FIELD_THUMB']]) {
- bx_import('BxDolStorage');
- $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
- if($oStorage)
- $sImage = $oStorage->getFileUrlById($aContentInfo[$CNF['FIELD_THUMB']]);
- }
- //--- Votes
- bx_import('BxDolVote');
- $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aEvent['object_id']);
- $aVotes = array();
- if ($oVotes && $oVotes->isEnabled())
- $aVotes = array(
- 'system' => $CNF['OBJECT_VOTES'],
- 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
- 'count' => $aContentInfo['votes']
- );
- //--- Comments
- bx_import('BxDolCmts');
- $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']);
- $aComments = array();
- if($oCmts->isEnabled())
- $aComments = array(
- 'system' => $CNF['OBJECT_COMMENTS'],
- 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
- 'count' => $aContentInfo['comments']
- );
- return array(
- 'owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
- 'content' => array(
- 'sample' => _t('_bx_notes_txt_sample_single'),
- 'url' => $sUrl,
- 'title' => $aContentInfo[$CNF['FIELD_TITLE']],
- 'text' => $aContentInfo[$CNF['FIELD_TEXT']],
- 'images' => array(
- array(
- 'url' => $sUrl,
- 'src' => $sImage
- )
- )
- ), //a string to display or array to parse default template before displaying.
- 'votes' => $aVotes,
- 'comments' => $aComments,
- 'title' => '', //may be empty.
- 'description' => '' //may be empty.
- );
- }
- // ====== ACTION METHODS
- function actionBrowse ($sMode = '')
- {
- $sMode = bx_process_input($sMode);
- if (CHECK_ACTION_RESULT_ALLOWED !== $this->isAllowedBrowse()) {
- $this->_oTemplate->displayAccessDenied ();
- return;
- }
- bx_import ('SearchResult', $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
- $o = new $sClass($sMode);
- if ($o->isError) {
- $this->_oTemplate->displayPageNotFound ();
- return;
- }
- if (bx_get('rss')) {
- echo $o->rss();
- exit;
- }
- if (!($s = $o->processing())) {
- $this->_oTemplate->displayNoData ();
- return;
- }
- // TODO: remake to use "pages"
- $this->_oTemplate->addCss ('main.css');
- $oTemplate = BxDolTemplate::getInstance();
- $oTemplate->setPageHeader ($o->aCurrent['title']);
- $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
- $oTemplate->setPageContent ('page_main_code', $s);
- $oTemplate->getPageCode();
- }
- // ====== PERMISSION METHODS
- function _checkModeratorAccess ($isPerformAction = false)
- {
- // check moderator ACL
- $aCheck = checkActionModule($this->_iProfileId, 'edit any note', $this->getName(), $isPerformAction);
- return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
- */
- function isAllowedView ($aDataEntry, $isPerformAction = false)
- {
- $CNF = &$this->_oConfig->CNF;
- // moderator and owner always have access
- if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
- return CHECK_ACTION_RESULT_ALLOWED;
- // check ACL
- $aCheck = checkActionModule($this->_iProfileId, 'view note', $this->getName(), $isPerformAction);
- if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
- return $aCheck[CHECK_ACTION_MESSAGE];
- // check privacy
- bx_import('BxDolPrivacy');
- $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
- if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]))
- return _t('_sys_access_denied_to_private_content');
- return CHECK_ACTION_RESULT_ALLOWED;
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
- */
- function isAllowedBrowse ()
- {
- return CHECK_ACTION_RESULT_ALLOWED;
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- function isAllowedAdd ($isPerformAction = false)
- {
- // check ACL
- $aCheck = checkActionModule($this->_iProfileId, 'create note', $this->getName(), $isPerformAction);
- if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
- return $aCheck[CHECK_ACTION_MESSAGE];
- return CHECK_ACTION_RESULT_ALLOWED;
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- function isAllowedEdit ($aDataEntry, $isPerformAction = false)
- {
- // moderator and owner always have access
- if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
- return CHECK_ACTION_RESULT_ALLOWED;
- return _t('_sys_txt_access_denied');
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- function isAllowedDelete (&$aDataEntry, $isPerformAction = false)
- {
- // moderator always has access
- if ($this->_checkModeratorAccess($isPerformAction))
- return CHECK_ACTION_RESULT_ALLOWED;
- // check ACL
- $aCheck = checkActionModule($this->_iProfileId, 'delete note', $this->getName(), $isPerformAction);
- if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
- return CHECK_ACTION_RESULT_ALLOWED;
- return _t('_sys_txt_access_denied');
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- function isAllowedSetThumb ()
- {
- // check ACL
- $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
- if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
- return $aCheck[CHECK_ACTION_MESSAGE];
- return CHECK_ACTION_RESULT_ALLOWED;
- }
- protected function _serviceBrowse ($sMode, $aParams = false)
- {
- $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
- bx_import('SearchResult', $this->_aModule);
- $o = new $sClass($sMode, $aParams);
-
- $o->setDisplayEmptyMsg(true);
- if ($o->isError)
- return false;
- if ($s = $o->processing())
- return $s;
- else
- return false;
- }
- public function _serviceEntityForm ($sFormMethod, $iContentId = 0)
- {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- bx_import('FormsEntryHelper', $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
- $oFormsHelper = new $sClass($this);
- return $oFormsHelper->$sFormMethod((int)$iContentId);
- }
- }
- /** @} */
|