| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- <?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 BaseText Base classes for text modules
- * @ingroup TridentModules
- *
- * @{
- */
- bx_import ('BxBaseModGeneralModule');
- bx_import ('BxDolAcl');
- /**
- * Base module class for text based modules
- */
- class BxBaseModTextModule extends BxBaseModGeneralModule
- {
- function __construct(&$aModule)
- {
- parent::__construct($aModule);
- }
- // ====== SERVICE METHODS
- public function serviceGetMenuAddonManageTools()
- {
- bx_import('SearchResult', $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
- $o = new $sClass();
- $o->fillFilters(array(
- 'status' => 'hidden'
- ));
- $o->unsetPaginate();
- return $o->getNum();
- }
- public function serviceGetMenuAddonManageToolsProfileStats()
- {
- bx_import('SearchResult', $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
- $o = new $sClass();
- $o->fillFilters(array(
- 'author' => bx_get_logged_profile_id()
- ));
- $o->unsetPaginate();
- return $o->getNum();
- }
- /**
- * Display public entries
- * @return HTML string
- */
- public function serviceBrowsePublic ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
- {
- return $this->_serviceBrowse ('public', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
- }
- /**
- * Display featured entries
- * @return HTML string
- */
- public function serviceBrowsePopular ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
- {
- return $this->_serviceBrowse ('popular', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
- }
- /**
- * Display entries of the author
- * @return HTML string
- */
- public function serviceBrowseAuthor ($iProfileId = 0, $sUnitView = false)
- {
- if (!$iProfileId)
- $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
- if (!$iProfileId)
- return '';
- return $this->_serviceBrowse ('author', array('author' => $iProfileId, 'unit_view' => $sUnitView ? $sUnitView : ''), BX_DB_PADDING_DEF, true);
- }
- /**
- * 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 text with some additional controls
- */
- public function serviceEntityTextBlock ($iContentId = 0)
- {
- return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
- }
- /**
- * Entry location info
- */
- public function serviceEntityLocation ($iContentId = 0)
- {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- return $this->_oTemplate->entryLocation ($iContentId);
- }
- /**
- * 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 || !$oCmts->isEnabled())
- return false;
- return $oCmts->getCommentsBlock(0, 0, false);
- }
- /**
- * Entry author block
- */
- public function serviceEntityAuthor ($iContentId = 0)
- {
- return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
- }
- /**
- * Entry attachments block
- */
- public function serviceEntityAttachments ($iContentId = 0)
- {
- return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
- }
- /**
- * 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;
- }
- /**
- * Delete all content by profile
- * @param $iProfileId profile id
- * @return number of deleted items
- */
- public function serviceDeleteEntitiesByAuthor ($iProfileId)
- {
- $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
- if (!$a)
- return 0;
- $iCount = 0;
- foreach ($a as $aContentInfo)
- $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
- return $iCount;
- }
- /**
- * Data for Notification
- */
- public function serviceGetNotificationsData()
- {
- return array(
- 'handlers' => array(
- array('type' => 'insert', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'added', 'module_name' => $this->_aModule['name'], 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
- 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 serviceGetNotificationsPost($aEvent)
- {
- $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
- if(empty($aContentInfo) || !is_array($aContentInfo))
- return array();
- $CNF = &$this->_oConfig->CNF;
- bx_import('BxDolPermalinks');
- $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
- $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
- return array(
- 'entry_sample' => _t($CNF['T']['txt_sample_single']),
- 'entry_url' => $sEntryUrl,
- 'entry_caption' => $sEntryCaption,
- 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
- );
- }
- /**
- * 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 (isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']]) {
- bx_import('BxDolStorage');
- $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
- if($oStorage)
- $sImage = $oStorage->getFileUrlById($aContentInfo[$CNF['FIELD_THUMB']]);
- }
- $aImages = array();
- if(!empty($sImage))
- $aImages = array(
- array('url' => $sUrl, 'src' => $sImage)
- );
- //--- 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 && $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($CNF['T']['txt_sample_single']),
- 'url' => $sUrl,
- 'title' => isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...'),
- 'text' => $aContentInfo[$CNF['FIELD_TEXT']],
- 'images' => $aImages,
- ), //a string to display or array to parse default template before displaying.
- 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
- 'votes' => $aVotes,
- 'comments' => $aComments,
- 'title' => '', //may be empty.
- 'description' => '' //may be empty.
- );
- }
- // ====== PERMISSION METHODS
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
- */
- public function checkAllowedSetThumb ()
- {
- // 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 METHODS
- protected function _buildRssParams($sMode, $aArgs)
- {
- $aParams = array ();
- $sMode = bx_process_input($sMode);
- switch ($sMode) {
- case 'author':
- $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
- break;
- }
- return $aParams;
- }
- }
- /** @} */
|