| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445 |
- <?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;
- protected $_aSearchableNamesExcept;
- protected $_aFormParams;
- function __construct(&$aModule)
- {
- parent::__construct($aModule);
- $this->_iProfileId = bx_get_logged_profile_id();
- $this->_aSearchableNamesExcept = array(
- 'allow_view_to'
- );
-
- $this->_aFormParams = array(
- 'display' => false,
- 'dynamic_mode' => false,
- 'ajax_mode' => false,
- 'absolute_action_url' => false
- );
- }
- // ====== ACTIONS METHODS
- public function actionRss ()
- {
- $aArgs = func_get_args();
- $this->_rss($aArgs);
- }
-
- public function actionGetCreatePostForm()
- {
- $aParams = bx_process_input(array_intersect_key($_GET, $this->_aFormParams));
- $aParams = array_merge($this->_aFormParams, $aParams);
- $sForm = $this->serviceGetCreatePostForm($aParams);
- if(empty($sForm))
- return echoJson(array());
- return echoJson(array(
- 'module' => $this->_oConfig->getName(),
- 'content' => $sForm
- ));
- }
- // ====== SERVICE METHODS
- public function serviceGetCreatePostForm($aParams = array())
- {
- $aParams = array_merge($this->_aFormParams, $aParams);
- $oForm = $this->serviceGetObjectForm('add', $aParams);
- if(!$oForm)
- return '';
- return $this->serviceEntityCreate($aParams);
- }
- public function serviceGetAuthor ($iContentId)
- {
- $mixedResult = $this->_getFieldValue('FIELD_AUTHOR', $iContentId);
- return $mixedResult !== false ? (int)$mixedResult : 0;
- }
- public function serviceGetDateAdded ($iContentId)
- {
- $mixedResult = $this->_getFieldValue('FIELD_ADDED', $iContentId);
- return $mixedResult !== false ? (int)$mixedResult : 0;
- }
- public function serviceGetDateChanged ($iContentId)
- {
- $mixedResult = $this->_getFieldValue('FIELD_CHANGED', $iContentId);
- return $mixedResult !== false ? (int)$mixedResult : 0;
- }
- public function serviceGetLink ($iContentId)
- {
- $CNF = &$this->_oConfig->CNF;
- if(empty($CNF['URI_VIEW_ENTRY']))
- return '';
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if(empty($aContentInfo))
- return '';
- return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
- }
- public function serviceGetTitle ($iContentId)
- {
- $mixedResult = $this->_getFieldValue('FIELD_TITLE', $iContentId);
- return $mixedResult !== false ? $mixedResult : '';
- }
- public function serviceGetText ($iContentId)
- {
- $mixedResult = $this->_getFieldValue('FIELD_TEXT', $iContentId);
- return $mixedResult !== false ? $mixedResult : '';
- }
- public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
- {
- $CNF = &$this->_oConfig->CNF;
- $aContentInfo = $this->_getFields($iContentId);
- if(empty($aContentInfo))
- return array();
- if(!$bSearchableFieldsOnly)
- return $aContentInfo;
- if(empty($CNF['PARAM_SEARCHABLE_FIELDS']))
- return array();
- $aFields = explode(',', getParam($CNF['PARAM_SEARCHABLE_FIELDS']));
- if(empty($aFields))
- return array();
- $aResult = array();
- foreach($aFields as $sField)
- if(isset($aContentInfo[$sField]))
- $aResult[$sField] = $aContentInfo[$sField];
- return $aResult;
- }
- public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
- {
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if(empty($aContentInfo))
- return '';
- if(empty($sUnitTemplate))
- $sUnitTemplate = 'unit.html';
- return $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
- }
- public function serviceGetAll ($aParams = array())
- {
- if(empty($aParams) || !is_array($aParams))
- $aParams = array('type' => 'all');
- return $this->_oDb->getEntriesBy($aParams);
- }
- public function serviceGetAllByAuthor ($iProfileId)
- {
- return $this->_oDb->getEntriesByAuthor((int)$iProfileId);
- }
- public function serviceGetSearchableFieldsExtended()
- {
- $CNF = &$this->_oConfig->CNF;
- if(empty($CNF['OBJECT_FORM_ENTRY']))
- return array();
- $aResult = array();
- if(!empty($CNF['FIELD_AUTHOR']) && !in_array($CNF['FIELD_AUTHOR'], $this->_aSearchableNamesExcept))
- $aResult[$CNF['FIELD_AUTHOR']] = array(
- 'type' => 'text_auto',
- 'caption' => $CNF['T']['form_field_author'],
- 'info' => '',
- 'value' => '',
- 'values' => '',
- 'pass' => ''
- );
- $aInputs = array();
- if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
- $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
- $aInputs = array_merge($aInputs, $oForm->aInputs);
- }
- if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
- $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'], $this->_oTemplate);
- $aInputs = array_merge($aInputs, $oForm->aInputs);
- }
- foreach($aInputs as $aInput)
- if(in_array($aInput['type'], BxDolSearchExtended::$SEARCHABLE_TYPES) && !in_array($aInput['name'], $this->_aSearchableNamesExcept))
- $aResult[$aInput['name']] = array(
- 'type' => $aInput['type'],
- 'caption' => $aInput['caption_src'],
- 'info' => $aInput['info_src'],
- 'value' => !empty($aInput['value']) ? $aInput['value'] : '',
- 'values' => !empty($aInput['values_src']) ? $aInput['values_src'] : '',
- 'pass' => !empty($aInput['db']['pass']) ? $aInput['db']['pass'] : '',
- );
- return $aResult;
- }
- public function serviceGetSearchResultExtended($aParams, $iStart = 0, $iPerPage = 0)
- {
- if(empty($aParams) || !is_array($aParams))
- return array();
- return $this->_oDb->getEntriesBy(array('type' => 'search_ids', 'search_params' => $aParams, 'start' => $iStart, 'per_page' => $iPerPage));
- }
- 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;
- }
- /**
- * My entries actions block
- */
- public function serviceMyEntriesActions ($iProfileId = 0)
- {
- $CNF = &$this->_oConfig->CNF;
- if(empty($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']))
- return false;
- if (!$iProfileId)
- $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
- if (!$iProfileId || !($oProfile = BxDolProfile::getInstance($iProfileId)))
- return false;
- if ($iProfileId != $this->_iProfileId)
- return false;
- $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
- return $oMenu ? $oMenu->getCode() : false;
- }
- /**
- * Display featured entries
- * @return HTML string
- */
- public function serviceBrowseFeatured ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
- {
- return $this->_serviceBrowse ('featured', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
- }
-
- /**
- * 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 '';
- $bEmptyMessage = false;
- if(isset($aParams['empty_message'])) {
- $bEmptyMessage = (bool)$aParams['empty_message'];
- unset($aParams['empty_message']);
- }
- return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage);
- }
- public function serviceFormsHelper ()
- {
- bx_import('FormsEntryHelper', $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
- return new $sClass($this);
- }
- /**
- * Add entry using provided fields' values.
- * @return HTML string
- */
- public function serviceEntityAdd ($iProfile, $aValues)
- {
- bx_import('FormsEntryHelper', $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
- $oFormsHelper = new $sClass($this);
- return $oFormsHelper->addData($iProfile, $aValues);
- }
- /**
- * Perform redirect after content creation
- * @return nothing, rediret header is sent
- */
- public function serviceRedirectAfterAdd($aContentInfo)
- {
- bx_import('FormsEntryHelper', $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
- $oFormsHelper = new $sClass($this);
- $oFormsHelper->redirectAfterAdd($aContentInfo);
- }
- /**
- * Get form object for add, edit, view or delete the content
- * @param $sType 'add', 'edit', 'view' or 'delete'
- * @param $aParams optional array with parameters(display name, etc)
- * @return form object or false on error
- */
- public function serviceGetObjectForm ($sType, $aParams = array())
- {
- if (!in_array($sType, array('add', 'edit', 'view', 'delete')))
- return false;
- bx_import('FormsEntryHelper', $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
- $oFormsHelper = new $sClass($this);
- $sDisplay = !empty($aParams['display']) ? $aParams['display'] : false;
- $sFunc = 'getObjectForm' . ucfirst($sType);
- $oForm = $oFormsHelper->$sFunc($sDisplay);
- $sParamsKey = 'absolute_action_url';
- if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true) {
- $sKeyUri = 'URI_' . strtoupper($sType) . '_ENTRY';
- if(!empty($this->_oConfig->CNF[$sKeyUri]))
- $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF[$sKeyUri]);
- }
- $sParamsKey = 'ajax_mode';
- if(isset($aParams[$sParamsKey]) && is_bool($aParams[$sParamsKey]))
- $oForm->setAjaxMode((bool)$aParams[$sParamsKey]);
- return $oForm;
- }
- /**
- * Create entry form
- * @return HTML string
- */
- public function serviceEntityCreate ($sParams = false)
- {
- $bParamsArray = is_array($sParams);
- $sDisplay = is_string($sParams) ? $sParams : false;
- if($bParamsArray && !empty($sParams['display']))
- $sDisplay = $sParams['display'];
- bx_import('FormsEntryHelper', $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
- $oFormsHelper = new $sClass($this);
- if($bParamsArray && isset($sParams['dynamic_mode']))
- $oFormsHelper->setDynamicMode($sParams['dynamic_mode']);
- return $oFormsHelper->addDataForm($sDisplay);
- }
- public function serviceEntityEdit ($iContentId = 0, $sDisplay = false)
- {
- return $this->_serviceEntityForm ('editDataForm', $iContentId, $sDisplay);
- }
- 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, $sDisplay = false)
- {
- return $this->_serviceEntityForm ('viewDataForm', $iContentId, $sDisplay);
- }
- 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)
- {
- $iContentId = $this->_getContent($iContentId, false);
- if($iContentId === false)
- return false;
- return $this->_oTemplate->entryLocation ($iContentId);
- }
- /**
- * Entry comments
- */
- public function serviceEntityComments ($iContentId = 0)
- {
- $CNF = &$this->_oConfig->CNF;
- if(empty($CNF['OBJECT_COMMENTS']))
- return '';
- return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
- }
- /**
- * Entry attachments block
- */
- public function serviceEntityAttachments ($iContentId = 0)
- {
- return $this->_serviceTemplateFunc ('entryAttachments', $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)
- {
- $iContentId = $this->_getContent($iContentId, false);
- if($iContentId === false)
- 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)
- {
- $mixedContent = $this->_getContent($iContentId);
- if($mixedContent === false)
- return false;
- list($iContentId, $aContentInfo) = $mixedContent;
- $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_view' => !empty($CNF['OBJECT_VIEWS']) ? $CNF['OBJECT_VIEWS'] : '',
- 'object_vote' => !empty($CNF['OBJECT_VOTES']) ? $CNF['OBJECT_VOTES'] : '',
- 'object_score' => !empty($CNF['OBJECT_SCORES']) ? $CNF['OBJECT_SCORES'] : '',
- 'object_favorite' => !empty($CNF['OBJECT_FAVORITES']) ? $CNF['OBJECT_FAVORITES'] : '',
- 'object_feature' => !empty($CNF['OBJECT_FEATURED']) ? $CNF['OBJECT_FEATURED'] : '',
- '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 . '_reply', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'replyPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_reply', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
- array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
- 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' => 'replyPost'),
- array('unit' => $sModule, 'action' => 'replyRemoved'),
- 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 reply for Notifications module
- */
- public function serviceGetNotificationsReply($aEvent)
- {
- $CNF = &$this->_oConfig->CNF;
- $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
- if(!$oComment || !$oComment->isEnabled())
- return array();
- $iParentId = (int)$aEvent['object_id'];
- $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
- if(empty($aParentInfo) || !is_array($aParentInfo))
- return array();
- $iObjectId = (int)$aParentInfo['cmt_object_id'];
- $oComment->init($iObjectId);
- return array(
- 'object_id' => $iObjectId,
- 'entry_sample' => '_cmt_txt_sample_comment_single',
- 'entry_url' => $oComment->getViewUrl($iParentId),
- 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
- 'entry_author' => (int)$aParentInfo['cmt_author_id'],
- 'subentry_sample' => '_cmt_txt_sample_reply_to',
- '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.
- );
- }
- /**
- * 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, $aBrowseParams = array())
- {
- $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
- if(empty($aContentInfo) || !is_array($aContentInfo))
- return '';
- $CNF = &$this->_oConfig->CNF;
-
- //--- Views
- $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aEvent['object_id']) : null;
- $aViews = array();
- if ($oViews && $oViews->isEnabled())
- $aViews = array(
- 'system' => $CNF['OBJECT_VIEWS'],
- 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
- 'count' => $aContentInfo['views']
- );
- //--- 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']
- );
- //--- Scores
- $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aEvent['object_id']) : null;
- $aScores = array();
- if ($oScores && $oScores->isEnabled())
- $aScores = array(
- 'system' => $CNF['OBJECT_SCORES'],
- 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
- 'score' => $aContentInfo['score']
- );
- //--- 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']
- );
- //--- Title & Description
- $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
- if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
- $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
- return array(
- 'owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
- 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
- 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
- 'sample_wo_article' => $CNF['T']['txt_sample_single'],
- 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
- 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
- 'content' => $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams), //a string to display or array to parse default template before displaying.
- 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
- 'views' => $aViews,
- 'votes' => $aVotes,
- 'scores' => $aScores,
- 'reports' => $aReports,
- 'comments' => $aComments,
- 'title' => $sTitle, //may be empty.
- 'description' => '' //may be empty.
- );
- }
- /**
- * Check particular action permission without content
- * @param $sAction action to check, for example: Browse, Add
- * @param $iContentId content ID
- * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
- */
- public function serviceCheckAllowed($sAction, $isPerformAction = false)
- {
- $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
- if (!method_exists($this, $sMethod))
- return _t('_sys_request_method_not_found_cpt');
- return $this->$sMethod($isPerformAction);
- }
-
- /**
- * Check particular action permission with content
- * @param $sAction action to check, for example: View, Edit
- * @param $iContentId content ID
- * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
- */
- public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
- {
- if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
- return _t('_sys_request_page_not_found_cpt');
- $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
- if (!method_exists($this, $sMethod))
- return _t('_sys_request_method_not_found_cpt');
- return $this->$sMethod($aContentInfo, $isPerformAction);
- }
-
- public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
- {
- return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
- }
-
- public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
- {
- return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
- }
- public function serviceGetContentOwnerProfileId ($iContentId)
- {
- $CNF = &$this->_oConfig->CNF;
- // file owner must be author of the content or profile itself in case of profile based module
- if ($iContentId) {
- if ($this instanceof iBxDolProfileService) {
- $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
- }
- else {
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
- }
- $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
- }
- else {
- $iProfileId = bx_get_logged_profile_id();
- }
- return $iProfileId;
- }
-
- // ====== PERMISSION METHODS
- public function checkAllowedSetThumb ($iContentId = 0)
- {
- 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.
- */
- 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)
- {
- return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
- }
- public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
- {
- if (!$iProfileId)
- $iProfileId = $this->_iProfileId;
- $CNF = &$this->_oConfig->CNF;
- // moderator and owner always have access
- if (!empty($iProfileId) && ((int)$aDataEntry[$CNF['FIELD_AUTHOR']] == (int)$iProfileId || $this->_isModerator($isPerformAction)))
- return CHECK_ACTION_RESULT_ALLOWED;
- // check ACL
- $aCheck = checkActionModule($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']], $iProfileId))
- 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');
- }
- /**
- * @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 checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
- {
- return $this->checkAllowedView ($aContentInfo, $isPerformAction);
- }
- /**
- * @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 checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
- {
- return $this->checkAllowedView ($aContentInfo, $isPerformAction);
- }
- 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 = null;
- if($oProfile && !($oProfile instanceof BxDolProfileUndefined))
- $oAccount = $oProfile->getAccountObject();
- $bAccount = !empty($oAccount);
- return array(
- 'id' => $oProfile->id(),
- 'name' => $oProfile->getDisplayName(),
- 'email' => $bAccount ? $oAccount->getEmail() : '',
- 'link' => $oProfile->getUrl(),
- 'icon' => $oProfile->getIcon(),
- 'thumb' => $oProfile->getThumb(),
- 'avatar' => $oProfile->getAvatar(),
- '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;
- }
- public function getUserId()
- {
- return isLogged() ? bx_get_logged_profile_id() : 0;
- }
- public function getUserIp()
- {
- return getVisitorIP();
- }
- public function getUserInfo($iUserId = 0)
- {
- $oProfile = BxDolProfile::getInstance($iUserId);
- if (!$oProfile)
- $oProfile = BxDolProfileUndefined::getInstance();
- return array(
- $oProfile->getDisplayName(),
- $oProfile->getUrl(),
- $oProfile->getThumb(),
- $oProfile->getUnit(),
- $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
- );
- }
- public function _isModerator ($isPerformAction = false)
- {
- return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
- }
- // ====== PROTECTED METHODS
- protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
- {
- $iContentId = $this->_getContent($iContentId, false);
- if($iContentId === false)
- return false;
- bx_import('FormsEntryHelper', $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
- $oFormsHelper = new $sClass($this);
- return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
- }
- protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
- {
- $mixedContent = $this->_getContent($iContentId, $sFuncGetContent);
- if($mixedContent === false)
- return false;
- list($iContentId, $aContentInfo) = $mixedContent;
- 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 _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
- {
- if(!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if(!$iContentId)
- return false;
- if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
- return $iContentId;
- $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
- if(!$aContentInfo)
- return false;
- return array($iContentId, $aContentInfo);
- }
- protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
- {
- $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, $aBrowseParams);
- //--- Video(s)
- $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
- return array(
- 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
- 'sample_wo_article' => $CNF['T']['txt_sample_single'],
- 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
- '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,
- 'videos' => $aVideos
- );
- }
- protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
- {
- $CNF = &$this->_oConfig->CNF;
- $sImage = $sImageOrig = '';
- if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
- $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
- $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
- }
- $bImageThumb = isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']];
- if($sImage == '' && $bImageThumb)
- $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
- if($sImageOrig == '' && $bImageThumb)
- $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
- if(empty($sImage))
- return array();
- if($sImageOrig == '')
- $sImageOrig = $sImage;
- return array(
- array('url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
- );
- }
- protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
- {
- return array();
- }
- protected function _entityComments ($sObject, $iId = 0)
- {
- if (!$iId)
- $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iId)
- return false;
- $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
- if (!$oCmts || !$oCmts->isEnabled())
- return false;
- return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
- }
- protected function _entitySocialSharing ($iId, $aParams = array())
- {
- $bShowAsButton = !isset($aParams['show_as_button']) || $aParams['show_as_button'] === true;
- $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 (
- 'class' => 'bx-base-general-comments-' . ($bShowAsButton ? 'button' : 'link'),
- 'class_do' => $bShowAsButton ? ' bx-btn' : '',
- 'class_counter' => $bShowAsButton ? ' bx-btn-height' : '',
- 'url' => $sUrl . $oComments->getListAnchor(true),
- 'bx_if:comments' => array (
- 'condition' => $iNum,
- 'content' => array (
- 'num' => $iNum,
- ),
- ),
- ));
- }
- $aCustomParams = array();
- $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.
- //--- Views
- $sViews = '';
- $oViews = !empty($aParams['object_view']) ? BxDolView::getObjectInstance($aParams['object_view'], $iId) : false;
- if ($oViews && $oViews->isEnabled())
- $sViews = $oViews->getElementBlock(array('show_do_view_as_button' => $bShowAsButton));
- //--- Votes
- $sVotes = '';
- $oVotes = !empty($aParams['object_vote']) ? BxDolVote::getObjectInstance($aParams['object_vote'], $iId) : false;
- if ($oVotes && $oVotes->isEnabled())
- $sVotes = $oVotes->getElementBlock(array('show_do_vote_as_button' => $bShowAsButton));
- //--- Scores
- $sScores = '';
- $oScores = !empty($aParams['object_score']) ? BxDolScore::getObjectInstance($aParams['object_score'], $iId) : false;
- if ($oScores && $oScores->isEnabled())
- $sScores = $oScores->getElementBlock(array('show_do_vote_as_button' => $bShowAsButton));
- //--- Favorite
- $sFavorites = '';
- $oFavorites = !empty($aParams['object_favorite']) ? BxDolFavorite::getObjectInstance($aParams['object_favorite'], $iId) : false;
- if ($oFavorites && $oFavorites->isEnabled())
- $sFavorites = $oFavorites->getElementBlock(array('show_do_favorite_as_button' => $bShowAsButton));
- //--- Featured
- $sFeatured = '';
- $oFeatured = !empty($aParams['object_feature']) ? BxDolFeature::getObjectInstance($aParams['object_feature'], $iId) : false;
- if ($oFeatured && $oFeatured->isEnabled())
- $sFeatured = $oFeatured->getElementBlock(array('show_do_feature_as_button' => $bShowAsButton));
- //--- Timeline Repost
- $sRepost = '';
- $iIdTimeline = isset($aParams['id_timeline']) ? (int)$aParams['id_timeline'] : $iId;
- if ($iIdTimeline && BxDolRequest::serviceExists('bx_timeline', 'get_repost_element_block'))
- $sRepost = BxDolService::call('bx_timeline', 'get_repost_element_block', array(bx_get_logged_profile_id(), $this->_aModule['name'], 'added', $iIdTimeline, array('show_do_repost_as_button' => $bShowAsButton)));
- //--- 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' => $bShowAsButton));
- $sSocial = '';
- if($bSocialSharing) {
- $oSocial = BxDolMenu::getObjectInstance('sys_social_sharing');
- $oSocial->addMarkers(array_merge(array(
- 'id' => $iId,
- 'module' => $this->_aModule['name'],
- 'url' => BX_DOL_URL_ROOT . $sUrl,
- 'title' => $sTitle,
- ), $aCustomParams));
- $sSocial = $oSocial->getCode();
- }
- if(empty($sComments) && empty($sViews) && empty($sVotes) && empty($sScores) && empty($sFavorites) && empty($sFeatured) && empty($sRepost) && empty($sReport) && empty($sSocial))
- return '';
- return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
- 'comments' => $sComments,
- 'view' => $sViews,
- 'vote' => $sVotes,
- 'score' => $sScores,
- 'favorite' => $sFavorites,
- 'feature' => $sFeatured,
- 'repost' => $sRepost,
- 'report' => $sReport,
- 'social' => $sSocial,
- ));
- //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Repost, etc.
- }
- protected function _getFields($iContentId)
- {
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if(empty($aContentInfo))
- return array();
- return BxDolContentInfo::formatFields($aContentInfo);
- }
- protected function _getFieldValue($sField, $iContentId)
- {
- $CNF = &$this->_oConfig->CNF;
- if(empty($CNF[$sField]))
- return false;
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
- return false;
- return $aContentInfo[$CNF[$sField]];
- }
- protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
- {
- $CNF = &$this->_oConfig->CNF;
- if(empty($sTranscoder) || empty($CNF[$sField]))
- return false;
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
- return false;
- $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
- if(!$oImagesTranscoder)
- return false;
- return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
- }
- protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
- {
- if(!$bAsJson)
- return $aResponse;
- if(!empty($aAdditional) && is_array($aAdditional))
- $aResponse = array_merge($aResponse, $aAdditional);
- echoJson($aResponse);
- exit;
- }
- }
- /** @} */
|