| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup BaseGeneral Base classes for modules
- * @ingroup UnaModules
- *
- * @{
- */
- bx_import('BxDolAcl');
- /**
- * Base module class.
- */
- class BxBaseModGeneralModule extends BxDolModule
- {
- protected $_iProfileId;
- function __construct(&$aModule)
- {
- parent::__construct($aModule);
- $this->_iProfileId = bx_get_logged_profile_id();
- }
- // ====== ACTIONS METHODS
- public function actionRss ()
- {
- $aArgs = func_get_args();
- $this->_rss($aArgs);
- }
- // ====== SERVICE METHODS
- public function serviceModuleIcon ()
- {
- return isset($this->_oConfig->CNF['ICON']) ? $this->_oConfig->CNF['ICON'] : '';
- }
- public function serviceGetSearchableFields ()
- {
- $CNF = $this->_oConfig->CNF;
- if (!isset($CNF['PARAM_SEARCHABLE_FIELDS']) || !isset($CNF['OBJECT_FORM_ENTRY']) || !isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
- return array();
- $aTextTypes = array('text', 'textarea');
- $aTextFields = array();
- $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
- foreach ($oForm->aInputs as $r) {
- if (in_array($r['type'], $aTextTypes))
- $aTextFields[$r['name']] = $r['caption'];
- }
- return $aTextFields;
- }
-
- public function serviceManageTools($sType = 'common')
- {
- $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
- if(!$oGrid)
- return '';
- $CNF = &$this->_oConfig->CNF;
- $sMenu = '';
- if(BxDolAcl::getInstance()->isMemberLevelInSet(192)) {
- $oPermalink = BxDolPermalinks::getInstance();
- $aMenuItems = array();
- if(!empty($CNF['OBJECT_GRID_COMMON']) && !empty($CNF['T']['menu_item_manage_my']))
- $aMenuItems[] = array('id' => 'manage-common', 'name' => 'manage-common', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_MANAGE_COMMON']), 'target' => '_self', 'title' => _t($CNF['T']['menu_item_manage_my']), 'active' => 1);
- if(!empty($CNF['OBJECT_GRID_ADMINISTRATION']) && !empty($CNF['T']['menu_item_manage_all']))
- $aMenuItems[] = array('id' => 'manage-administration', 'name' => 'manage-administration', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_MANAGE_ADMINISTRATION']), 'target' => '_self', 'title' => _t($CNF['T']['menu_item_manage_all']), 'active' => 1);
- if(count($aMenuItems) > 1) {
- $oMenu = new BxTemplMenu(array(
- 'template' => 'menu_vertical.html',
- 'menu_items' => $aMenuItems
- ), $this->_oTemplate);
- $oMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
- $sMenu = $oMenu->getCode();
- }
- }
- if(!empty($CNF['OBJECT_MENU_SUBMENU'])) {
- BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
- }
- $this->_oTemplate->addCss(array('manage_tools.css'));
- $this->_oTemplate->addJs(array('manage_tools.js'));
- $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
- return array(
- 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
- 'menu' => $sMenu
- );
- }
- public function serviceGetMenuAddonManageTools()
- {
- return 0;
- }
-
- public function serviceGetMenuAddonManageToolsProfileStats()
- {
- return 0;
- }
- /**
- * Display entries favored by a member
- * @return HTML string
- */
- public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
- {
- $oProfile = null;
- if((int)$iProfileId)
- $oProfile = BxDolProfile::getInstance($iProfileId);
- if(!$oProfile && bx_get('profile_id') !== false)
- $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
- if(!$oProfile)
- $oProfile = BxDolProfile::getInstance();
- if(!$oProfile)
- return '';
- return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, true);
- }
- public function serviceFormsHelper ()
- {
- bx_import('FormsEntryHelper', $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
- return new $sClass($this);
- }
- /**
- * 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();
- }
- public function serviceEntityEdit ($iContentId = 0)
- {
- return $this->_serviceEntityForm ('editDataForm', $iContentId);
- }
- public function serviceEntityDelete ($iContentId = 0)
- {
- return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
- }
- public function serviceEntityTextBlock ($iContentId = 0)
- {
- return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
- }
- public function serviceEntityInfo ($iContentId = 0)
- {
- return $this->_serviceEntityForm ('viewDataForm', $iContentId);
- }
- public function serviceEntityInfoFull ($iContentId = 0)
- {
- $CNF = &$this->_oConfig->CNF;
- $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
- return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
- }
- public function serviceEntityInfoExtended ($iContentId = 0)
- {
- return $this->_serviceTemplateFunc ('entryInfo', $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);
- }
-
- /**
- * Delete content entry
- * @param $iContentId content id
- * @return error message or empty string on success
- */
- public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
- {
- bx_import('FormsEntryHelper', $this->_aModule);
- $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
- $oFormsHelper = new $sClass($this);
- return $oFormsHelper->$sFuncDelete($iContentId);
- }
- /**
- * Entry actions and social sharing block
- */
- public function serviceEntityAllActions ($iContentId = 0)
- {
- return $this->_oTemplate->entryAllActions('', $this->serviceEntitySocialSharing($iContentId));
- }
- /**
- * Entry actions block
- */
- public function serviceEntityActions ($iContentId = 0)
- {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
- return $oMenu ? $oMenu->getCode() : false;
- }
- /**
- * 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;
- return $this->_entitySocialSharing ($iContentId, array(
- 'id_timeline' => $iContentId,
- 'id_thumb' => !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : '',
- 'title' => !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
- 'object_storage' => !empty($CNF['OBJECT_STORAGE']) ? $CNF['OBJECT_STORAGE'] : '',
- 'object_transcoder' => false,
- 'object_vote' => !empty($CNF['OBJECT_VOTES']) ? $CNF['OBJECT_VOTES'] : '',
- 'object_favorite' => !empty($CNF['OBJECT_FAVORITES']) ? $CNF['OBJECT_FAVORITES'] : '',
- 'object_report' => !empty($CNF['OBJECT_REPORTS']) ? $CNF['OBJECT_REPORTS'] : '',
- 'uri_view_entry' => !empty($CNF['URI_VIEW_ENTRY']) ? $CNF['URI_VIEW_ENTRY'] : '',
- ));
- }
- /**
- * Data for Notifications module
- */
- public function serviceGetNotificationsData()
- {
- $sModule = $this->_aModule['name'];
- $sEventPrivacy = $sModule . '_allow_view_event_to';
- if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
- $sEventPrivacy = '';
- return array(
- 'handlers' => array(
- array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
- array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
- array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
-
- array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
- array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
-
- array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
- array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
- ),
- 'alerts' => array(
- array('unit' => $sModule, 'action' => 'added'),
- array('unit' => $sModule, 'action' => 'edited'),
- array('unit' => $sModule, 'action' => 'deleted'),
- array('unit' => $sModule, 'action' => 'commentPost'),
- array('unit' => $sModule, 'action' => 'commentRemoved'),
-
- array('unit' => $sModule, 'action' => 'doVote'),
- array('unit' => $sModule, 'action' => 'undoVote'),
- )
- );
- }
- /**
- * Entry post for Notifications module
- */
- public function serviceGetNotificationsPost($aEvent)
- {
- $CNF = &$this->_oConfig->CNF;
- $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
- if(empty($aContentInfo) || !is_array($aContentInfo))
- return array();
- $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' => $CNF['T']['txt_sample_single'],
- 'entry_url' => $sEntryUrl,
- 'entry_caption' => $sEntryCaption,
- 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
- 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
- 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
- );
- }
- /**
- * Entry post comment for Notifications module
- */
- public function serviceGetNotificationsComment($aEvent)
- {
- $CNF = &$this->_oConfig->CNF;
- $iContentId = (int)$aEvent['object_id'];
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if(empty($aContentInfo) || !is_array($aContentInfo))
- return array();
- $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
- if(!$oComment || !$oComment->isEnabled())
- return array();
- $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' => $CNF['T']['txt_sample_single'],
- 'entry_url' => $sEntryUrl,
- 'entry_caption' => $sEntryCaption,
- 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
- 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
- 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
- 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
- );
- }
- /**
- * Entry post vote for Notifications module
- */
- public function serviceGetNotificationsVote($aEvent)
- {
- $CNF = &$this->_oConfig->CNF;
- $iContentId = (int)$aEvent['object_id'];
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if(empty($aContentInfo) || !is_array($aContentInfo))
- return array();
- $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
- if(!$oVote || !$oVote->isEnabled())
- return array();
- $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' => $CNF['T']['txt_sample_single'],
- 'entry_url' => $sEntryUrl,
- 'entry_caption' => $sEntryCaption,
- 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
- 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
- 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
- );
- }
- public function _serviceGetNotification($aEvent, $sLangKey)
- {
- $CNF = &$this->_oConfig->CNF;
- $iContentId = (int)$aEvent['object_id'];
- $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
- if (!$oGroupProfile)
- return false;
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if(empty($aContentInfo) || !is_array($aContentInfo))
- return array();
-
- $oProfile = BxDolProfile::getInstance((int)$aEvent['subobject_id']);
- if (!$oProfile)
- return false;
- return array(
- 'entry_sample' => $CNF['T']['txt_sample_single'],
- 'entry_url' => $oGroupProfile->getUrl(),
- 'entry_caption' => $oGroupProfile->getDisplayName(),
- 'entry_author' => $oGroupProfile->id(),
- 'subentry_sample' => $oProfile->getDisplayName(),
- 'subentry_url' => $oProfile->getUrl(),
- 'lang_key' => $sLangKey,
- );
- }
-
- /**
- * Data for Timeline module
- */
- public function serviceGetTimelineData()
- {
- $sModule = $this->_aModule['name'];
- return array(
- 'handlers' => array(
- array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'module_name' => $sModule, 'module_method' => 'get_timeline_post', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
- array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
- array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
- ),
- 'alerts' => array(
- array('unit' => $sModule, 'action' => 'added'),
- array('unit' => $sModule, 'action' => 'edited'),
- array('unit' => $sModule, 'action' => 'deleted'),
- )
- );
- }
- /**
- * Entry post for Timeline module
- */
- public function serviceGetTimelinePost($aEvent)
- {
- $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
- if(empty($aContentInfo) || !is_array($aContentInfo))
- return '';
- $CNF = &$this->_oConfig->CNF;
- //--- Votes
- $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aEvent['object_id']) : null;
- $aVotes = array();
- if ($oVotes && $oVotes->isEnabled())
- $aVotes = array(
- 'system' => $CNF['OBJECT_VOTES'],
- 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
- 'count' => $aContentInfo['votes']
- );
- //--- Reports
- $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aEvent['object_id']) : null;
- $aReports = array();
- if ($oReports && $oReports->isEnabled())
- $aReports = array(
- 'system' => $CNF['OBJECT_REPORTS'],
- 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
- 'count' => $aContentInfo['reports']
- );
- //--- Comments
- $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']) : null;
- $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' => $this->_getContentForTimelinePost($aEvent, $aContentInfo), //a string to display or array to parse default template before displaying.
- 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
- 'votes' => $aVotes,
- 'reports' => $aReports,
- '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 "true === " checking.
- */
- public function checkAllowedBrowse ()
- {
- 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 strict(===) checking.
- */
- public function checkAllowedView ($aDataEntry, $isPerformAction = false)
- {
- $CNF = &$this->_oConfig->CNF;
- // moderator and owner always have access
- if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
- return CHECK_ACTION_RESULT_ALLOWED;
- // check ACL
- $aCheck = checkActionModule($this->_iProfileId, 'view entry', $this->getName(), $isPerformAction);
- if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
- return $aCheck[CHECK_ACTION_MESSAGE];
- // check privacy
- if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
- $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 strict(===) checking.
- */
- public function checkAllowedAdd ($isPerformAction = false)
- {
- // check ACL
- $aCheck = checkActionModule($this->_iProfileId, 'create entry', $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. So make sure to make strict(===) checking.
- */
- public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
- {
- // moderator and owner always have access
- if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($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. So make sure to make strict(===) checking.
- */
- public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
- {
- // moderator always has access
- if ($this->_isModerator($isPerformAction))
- return CHECK_ACTION_RESULT_ALLOWED;
- // check ACL
- $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $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. So make sure to make strict(===) checking.
- */
- public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
- {
- // admin always has access
- if (isAdmin())
- return CHECK_ACTION_RESULT_ALLOWED;
- // check ACL
- $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $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. So make sure to make strict(===) checking.
- */
- public function checkAllowedEditAnyEntry ($isPerformAction = false)
- {
- $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
- if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
- return CHECK_ACTION_RESULT_ALLOWED;
- return _t('_sys_txt_access_denied');
- }
- public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
- {
- if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
- return MsgBox($sMsg);
- bx_import($sClassSearchResult, $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
- $o = new $sClass($sMode, $aParams);
- $o->setDesignBoxTemplateId($iDesignBox);
- $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
- $o->setAjaxPaginate($bAjaxPaginate);
- $o->setUnitParams(array('context' => $sMode));
- if ($o->isError)
- return '';
- if ($s = $o->processing())
- return $s;
- else
- return '';
- }
- // ====== COMMON METHODS
- public function getProfileId()
- {
- return bx_get_logged_profile_id();
- }
- public function getProfileInfo($iUserId = 0)
- {
- $oProfile = $this->getObjectUser($iUserId);
- $oAccount = $oProfile->getAccountObject();
- return array(
- 'id' => $oProfile->id(),
- 'name' => $oProfile->getDisplayName(),
- 'email' => $oAccount->getEmail(),
- 'link' => $oProfile->getUrl(),
- 'icon' => $oProfile->getIcon(),
- 'unit' => $oProfile->getUnit(),
- 'active' => $oProfile->isActive(),
- );
- }
-
- public function getObjectUser($iUserId = 0)
- {
- bx_import('BxDolProfile');
- $oProfile = BxDolProfile::getInstance($iUserId);
- if (!$oProfile) {
- bx_import('BxDolProfileUndefined');
- $oProfile = BxDolProfileUndefined::getInstance();
- }
- return $oProfile;
- }
- public function getObjectFavorite($sSystem = '', $iId = 0)
- {
- $CNF = &$this->_oConfig->CNF;
- if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
- $sSystem = $CNF['OBJECT_FAVORITES'];
- if(empty($sSystem))
- return false;
- $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
- if(!$oFavorite->isEnabled())
- return false;
- return $oFavorite;
- }
- // ====== PROTECTED METHODS
- protected function _isModerator ($isPerformAction = false)
- {
- return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
- }
- protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false)
- {
- 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, $sDisplay);
- }
- protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
- {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
- if (!$aContentInfo)
- return false;
- return $this->_oTemplate->$sFunc($aContentInfo);
- }
- protected function _rss ($aArgs, $sClass = 'SearchResult')
- {
- $sMode = array_shift($aArgs);
- if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
- $this->_oTemplate->displayAccessDenied ($sMsg);
- exit;
- }
- $aParams = $this->_buildRssParams($sMode, $aArgs);
- bx_import ($sClass, $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . $sClass;
- $o = new $sClass($sMode, $aParams);
- if ($o->isError)
- $this->_oTemplate->displayPageNotFound ();
- else
- $o->outputRSS();
- exit;
- }
- protected function _getContentForTimelinePost($aEvent, $aContentInfo)
- {
- $CNF = &$this->_oConfig->CNF;
- $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
- //--- Image(s)
- $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl);
- return array(
- 'sample' => _t($CNF['T']['txt_sample_single']),
- 'url' => $sUrl,
- 'title' => isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] :
- (isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...') : ''),
- 'text' => isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '',
- 'images' => $aImages,
- );
- }
- protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl)
- {
- $CNF = &$this->_oConfig->CNF;
- $sImage = '';
- if (isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']]) {
-
- $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
- if($oTranscoder)
- $sImage = $oTranscoder->getFileUrl($aContentInfo[$CNF['FIELD_THUMB']]);
- }
- if (empty($sImage))
- return array();
- return array(
- array('url' => $sUrl, 'src' => $sImage),
- );
- }
- protected function _entitySocialSharing ($iId, $aParams = array())
- {
- $sUrl = !empty($aParams['uri_view_entry']) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $aParams['uri_view_entry'] . '&id=' . $iId) : '';
- $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
- //--- Comments
- $sComments = '';
- $oComments = !empty($aParams['object_comments']) ? BxTemplCmts::getObjectInstance($aParams['object_comments'], $iId) : false;
- if ($oComments) {
- $iNum = $oComments->getCommentsCountAll();
- $sComments = $this->_oTemplate->parseHtmlByName('comments-item.html', array (
- 'url' => $sUrl . '#' . $oComments->getListAnchor(),
- 'bx_if:comments' => array (
- 'condition' => $iNum,
- 'content' => array (
- 'num' => $iNum,
- ),
- ),
- ));
- }
- $aCustomParams = false;
- $iIdThumb = isset($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
- $bSocialSharing = isset($aParams['social_sharing']) ? (bool)$aParams['social_sharing'] : true;
- if ($iIdThumb && $bSocialSharing) {
- if(!empty($aParams['object_transcoder']))
- $o = BxDolTranscoder::getObjectInstance($aParams['object_transcoder']);
- else if(!empty($aParams['object_storage']))
- $o = BxDolStorage::getObjectInstance($aParams['object_storage']);
- $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
- if($sImgUrl)
- $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.
- //--- Votes
- $sVotes = '';
- $oVotes = !empty($aParams['object_vote']) ? BxDolVote::getObjectInstance($aParams['object_vote'], $iId) : false;
- if ($oVotes)
- $sVotes = $oVotes->getElementBlock(array('show_do_vote_as_button' => true));
- //--- Favorite
- $sFavorites = '';
- $oFavorites = !empty($aParams['object_favorite']) ? BxDolFavorite::getObjectInstance($aParams['object_favorite'], $iId) : false;
- if ($oFavorites)
- $sFavorites = $oFavorites->getElementBlock(array('show_do_favorite_as_button' => true));
- //--- Timeline Repost (Internal Share)
- $sShare = '';
- $iIdTimeline = isset($aParams['id_timeline']) ? (int)$aParams['id_timeline'] : $iId;
- if ($iIdTimeline && 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', $iIdTimeline, array('show_do_share_as_button' => true)));
- //--- Report
- $sReport = '';
- $oReport = !empty($aParams['object_report']) ? BxDolReport::getObjectInstance($aParams['object_report'], $iId) : false;
- if ($oReport)
- $sReport = $oReport->getElementBlock(array('show_do_report_as_button' => true));
- $sSocial = $bSocialSharing ? BxTemplSocialSharing::getInstance()->getCode($iId, $this->_aModule['name'], BX_DOL_URL_ROOT . $sUrl, $sTitle, $aCustomParams) : '';
- if(empty($sComments) && empty($sVotes) && empty($sFavorites) && empty($sShare) && empty($sReport) && empty($sSocial))
- return '';
- return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
- 'comments' => $sComments,
- 'vote' => $sVotes,
- 'favorite' => $sFavorites,
- 'share' => $sShare,
- 'report' => $sReport,
- 'social' => $sSocial,
- ));
- //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
- }
- }
- /** @} */
|