BxBaseModGeneralModule.php 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. /**
  13. * Base module class.
  14. */
  15. class BxBaseModGeneralModule extends BxDolModule
  16. {
  17. protected $_iProfileId;
  18. protected $_aSearchableNamesExcept;
  19. protected $_aFormParams;
  20. function __construct(&$aModule)
  21. {
  22. parent::__construct($aModule);
  23. $this->_iProfileId = bx_get_logged_profile_id();
  24. $this->_aSearchableNamesExcept = array(
  25. 'allow_view_to'
  26. );
  27. $this->_aFormParams = array(
  28. 'display' => false,
  29. 'dynamic_mode' => false,
  30. 'ajax_mode' => false,
  31. 'absolute_action_url' => false,
  32. 'visibility_autoselect' => false,
  33. 'context_id' => 0,
  34. );
  35. }
  36. // ====== ACTIONS METHODS
  37. public function actionRss ()
  38. {
  39. $aArgs = func_get_args();
  40. $this->_rss($aArgs);
  41. }
  42. public function actionGetCreatePostForm()
  43. {
  44. $aParams = bx_process_input(array_intersect_key($_GET, $this->_aFormParams));
  45. $aParams = array_merge($this->_aFormParams, $aParams);
  46. $sForm = $this->serviceGetCreatePostForm($aParams);
  47. if(empty($sForm))
  48. return echoJson(array());
  49. return echoJson(array(
  50. 'module' => $this->_oConfig->getName(),
  51. 'content' => $sForm
  52. ));
  53. }
  54. // ====== SERVICE METHODS
  55. public function serviceGetCreatePostForm($aParams = array())
  56. {
  57. $aParams = array_merge($this->_aFormParams, $aParams);
  58. $oForm = $this->serviceGetObjectForm('add', $aParams);
  59. if(!$oForm)
  60. return '';
  61. return $this->serviceEntityCreate($aParams);
  62. }
  63. public function serviceGetAuthor ($iContentId)
  64. {
  65. $mixedResult = $this->_getFieldValue('FIELD_AUTHOR', $iContentId);
  66. return $mixedResult !== false ? (int)$mixedResult : 0;
  67. }
  68. public function serviceGetDateAdded ($iContentId)
  69. {
  70. $mixedResult = $this->_getFieldValue('FIELD_ADDED', $iContentId);
  71. return $mixedResult !== false ? (int)$mixedResult : 0;
  72. }
  73. public function serviceGetDateChanged ($iContentId)
  74. {
  75. $mixedResult = $this->_getFieldValue('FIELD_CHANGED', $iContentId);
  76. return $mixedResult !== false ? (int)$mixedResult : 0;
  77. }
  78. public function serviceGetLink ($iContentId)
  79. {
  80. $CNF = &$this->_oConfig->CNF;
  81. if(empty($CNF['URI_VIEW_ENTRY']))
  82. return '';
  83. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  84. if(empty($aContentInfo))
  85. return '';
  86. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  87. }
  88. public function serviceGetTitle ($iContentId)
  89. {
  90. $mixedResult = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  91. return $mixedResult !== false ? $mixedResult : '';
  92. }
  93. public function serviceGetText ($iContentId)
  94. {
  95. $mixedResult = $this->_getFieldValue('FIELD_TEXT', $iContentId);
  96. if (false === $mixedResult)
  97. return '';
  98. $CNF = &$this->_oConfig->CNF;
  99. if (!empty($CNF['OBJECT_METATAGS']) && is_string($mixedResult)) {
  100. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  101. $mixedResult = $oMetatags->metaParse($iContentId, $mixedResult);
  102. }
  103. return $mixedResult;
  104. }
  105. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  106. {
  107. $CNF = &$this->_oConfig->CNF;
  108. $aContentInfo = $this->_getFields($iContentId);
  109. if(empty($aContentInfo))
  110. return array();
  111. if(!$bSearchableFieldsOnly)
  112. return $aContentInfo;
  113. if(empty($CNF['PARAM_SEARCHABLE_FIELDS']))
  114. return array();
  115. $aFields = explode(',', getParam($CNF['PARAM_SEARCHABLE_FIELDS']));
  116. if(empty($aFields))
  117. return array();
  118. $aResult = array();
  119. foreach($aFields as $sField)
  120. if(isset($aContentInfo[$sField]))
  121. $aResult[$sField] = $aContentInfo[$sField];
  122. return $aResult;
  123. }
  124. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  125. {
  126. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  127. if(empty($aContentInfo))
  128. return '';
  129. if(empty($sUnitTemplate))
  130. $sUnitTemplate = 'unit.html';
  131. return $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
  132. }
  133. public function serviceGetAll ($aParams = array())
  134. {
  135. if(empty($aParams) || !is_array($aParams))
  136. $aParams = array('type' => 'all');
  137. return $this->_oDb->getEntriesBy($aParams);
  138. }
  139. public function serviceGetAllByAuthor ($iProfileId)
  140. {
  141. return $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  142. }
  143. public function serviceGetSearchableFieldsExtended()
  144. {
  145. $CNF = &$this->_oConfig->CNF;
  146. if(empty($CNF['OBJECT_FORM_ENTRY']))
  147. return array();
  148. $aResult = array();
  149. if(!empty($CNF['FIELD_AUTHOR']) && !in_array($CNF['FIELD_AUTHOR'], $this->_aSearchableNamesExcept))
  150. $aResult[$CNF['FIELD_AUTHOR']] = array(
  151. 'type' => 'text_auto',
  152. 'caption' => $CNF['T']['form_field_author'],
  153. 'info' => '',
  154. 'value' => '',
  155. 'values' => '',
  156. 'pass' => ''
  157. );
  158. $aInputs = array();
  159. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
  160. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  161. $aInputs = array_merge($aInputs, $oForm->aInputs);
  162. }
  163. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
  164. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'], $this->_oTemplate);
  165. $aInputs = array_merge($aInputs, $oForm->aInputs);
  166. }
  167. foreach($aInputs as $aInput)
  168. if(in_array($aInput['type'], BxDolSearchExtended::$SEARCHABLE_TYPES) && !in_array($aInput['name'], $this->_aSearchableNamesExcept))
  169. $aResult[$aInput['name']] = array(
  170. 'type' => $aInput['type'],
  171. 'caption_system' => $aInput['caption_system_src'],
  172. 'caption' => $aInput['caption_src'],
  173. 'info' => $aInput['info_src'],
  174. 'value' => !empty($aInput['value']) ? $aInput['value'] : '',
  175. 'values' => !empty($aInput['values_src']) ? $aInput['values_src'] : '',
  176. 'pass' => !empty($aInput['db']['pass']) ? $aInput['db']['pass'] : '',
  177. );
  178. return $aResult;
  179. }
  180. public function serviceGetSearchResultExtended($aParams, $iStart = 0, $iPerPage = 0)
  181. {
  182. if(empty($aParams) || !is_array($aParams))
  183. return array();
  184. return $this->_oDb->getEntriesBy(array('type' => 'search_ids', 'search_params' => $aParams, 'start' => $iStart, 'per_page' => $iPerPage));
  185. }
  186. public function serviceModuleIcon ()
  187. {
  188. return isset($this->_oConfig->CNF['ICON']) ? $this->_oConfig->CNF['ICON'] : '';
  189. }
  190. public function serviceGetSearchableFields ()
  191. {
  192. $CNF = $this->_oConfig->CNF;
  193. if (!isset($CNF['PARAM_SEARCHABLE_FIELDS']) || !isset($CNF['OBJECT_FORM_ENTRY']) || !isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
  194. return array();
  195. $aTextTypes = array('text', 'textarea');
  196. $aTextFields = array();
  197. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  198. foreach ($oForm->aInputs as $r) {
  199. if (in_array($r['type'], $aTextTypes))
  200. $aTextFields[$r['name']] = $r['caption'];
  201. }
  202. return $aTextFields;
  203. }
  204. public function serviceManageTools($sType = 'common')
  205. {
  206. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
  207. if(!$oGrid)
  208. return '';
  209. $CNF = &$this->_oConfig->CNF;
  210. $sMenu = '';
  211. if(BxDolAcl::getInstance()->isMemberLevelInSet(192)) {
  212. $oPermalink = BxDolPermalinks::getInstance();
  213. $aMenuItems = array();
  214. if(!empty($CNF['OBJECT_GRID_COMMON']) && !empty($CNF['T']['menu_item_manage_my']))
  215. $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);
  216. if(!empty($CNF['OBJECT_GRID_ADMINISTRATION']) && !empty($CNF['T']['menu_item_manage_all']))
  217. $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);
  218. if(count($aMenuItems) > 1) {
  219. $oMenu = new BxTemplMenu(array(
  220. 'template' => 'menu_vertical.html',
  221. 'menu_items' => $aMenuItems
  222. ), $this->_oTemplate);
  223. $oMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
  224. $sMenu = $oMenu->getCode();
  225. }
  226. }
  227. if(!empty($CNF['OBJECT_MENU_SUBMENU']) && isset($CNF['URI_MANAGE_COMMON'])) {
  228. BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
  229. }
  230. $this->_oTemplate->addCss(array('manage_tools.css'));
  231. $this->_oTemplate->addJs(array('manage_tools.js'));
  232. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  233. return array(
  234. 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
  235. 'menu' => $sMenu
  236. );
  237. }
  238. public function serviceGetMenuAddonManageTools()
  239. {
  240. return 0;
  241. }
  242. public function serviceGetMenuAddonManageToolsProfileStats()
  243. {
  244. return 0;
  245. }
  246. /**
  247. * My entries actions block
  248. */
  249. public function serviceMyEntriesActions ($iProfileId = 0)
  250. {
  251. $CNF = &$this->_oConfig->CNF;
  252. if(empty($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']))
  253. return false;
  254. if (!$iProfileId)
  255. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  256. if (!$iProfileId || !($oProfile = BxDolProfile::getInstance($iProfileId)))
  257. return false;
  258. if ($iProfileId != $this->_iProfileId)
  259. return false;
  260. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  261. return $oMenu ? $oMenu->getCode() : false;
  262. }
  263. /**
  264. * Universal browse method
  265. * @param $aParams custom browse params, possible params are the following:
  266. * - mode - browse mode, such as 'recent', 'featured', etc
  267. * - params - custom params to browse method, for example 'unit_view' can be passed here
  268. * - design_box - design box style, @see BxBaseFunctions::DesignBoxContent
  269. * - empty_message - display or not "empty" message when there is no content
  270. * - ajax_paginate - use AJAX paginate or not
  271. * @return HTML string
  272. */
  273. public function serviceBrowse ($aParams = array())
  274. {
  275. $aDefaults = array (
  276. 'mode' => 'recent',
  277. 'params' => false,
  278. 'design_box' => BX_DB_PADDING_DEF,
  279. 'empty_message' => false,
  280. 'ajax_paginate' => true,
  281. );
  282. $aParams = array_merge($aDefaults, $aParams);
  283. return $this->_serviceBrowse ($aParams['mode'], $aParams['params'], $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  284. }
  285. /**
  286. * Display featured entries
  287. * @return HTML string
  288. */
  289. public function serviceBrowseFeatured ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  290. {
  291. return $this->_serviceBrowse ('featured', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  292. }
  293. /**
  294. * Display entries favored by a member
  295. * @return HTML string
  296. */
  297. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  298. {
  299. $oProfile = null;
  300. if((int)$iProfileId)
  301. $oProfile = BxDolProfile::getInstance($iProfileId);
  302. if(!$oProfile && bx_get('profile_id') !== false)
  303. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  304. if(!$oProfile)
  305. $oProfile = BxDolProfile::getInstance();
  306. if(!$oProfile)
  307. return '';
  308. $bEmptyMessage = false;
  309. if(isset($aParams['empty_message'])) {
  310. $bEmptyMessage = (bool)$aParams['empty_message'];
  311. unset($aParams['empty_message']);
  312. }
  313. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage);
  314. }
  315. public function serviceFormsHelper ()
  316. {
  317. bx_import('FormsEntryHelper', $this->_aModule);
  318. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  319. return new $sClass($this);
  320. }
  321. /**
  322. * Add entry using provided fields' values.
  323. * @return HTML string
  324. */
  325. public function serviceEntityAdd ($iProfile, $aValues)
  326. {
  327. bx_import('FormsEntryHelper', $this->_aModule);
  328. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  329. $oFormsHelper = new $sClass($this);
  330. return $oFormsHelper->addData($iProfile, $aValues);
  331. }
  332. /**
  333. * Perform redirect after content creation
  334. * @return nothing, rediret header is sent
  335. */
  336. public function serviceRedirectAfterAdd($aContentInfo)
  337. {
  338. bx_import('FormsEntryHelper', $this->_aModule);
  339. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  340. $oFormsHelper = new $sClass($this);
  341. $oFormsHelper->redirectAfterAdd($aContentInfo);
  342. }
  343. /**
  344. * Get form object for add, edit, view or delete the content
  345. * @param $sType 'add', 'edit', 'view' or 'delete'
  346. * @param $aParams optional array with parameters(display name, etc)
  347. * @return form object or false on error
  348. */
  349. public function serviceGetObjectForm ($sType, $aParams = array())
  350. {
  351. if (!in_array($sType, array('add', 'edit', 'view', 'delete')))
  352. return false;
  353. $CNF = &$this->_oConfig->CNF;
  354. bx_import('FormsEntryHelper', $this->_aModule);
  355. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  356. $oFormsHelper = new $sClass($this);
  357. $sDisplay = !empty($aParams['display']) ? $aParams['display'] : false;
  358. $sFunc = 'getObjectForm' . ucfirst($sType);
  359. $oForm = $oFormsHelper->$sFunc($sDisplay);
  360. $sParamsKey = 'absolute_action_url';
  361. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true) {
  362. $sKeyUri = 'URI_' . strtoupper($sType) . '_ENTRY';
  363. if(!empty($this->_oConfig->CNF[$sKeyUri]))
  364. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF[$sKeyUri]);
  365. }
  366. $sParamsKey = 'ajax_mode';
  367. if(isset($aParams[$sParamsKey]) && is_bool($aParams[$sParamsKey]))
  368. $oForm->setAjaxMode((bool)$aParams[$sParamsKey]);
  369. $sKey = 'FIELD_ALLOW_VIEW_TO';
  370. if(!empty($aParams['context_id']) && !empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]])) {
  371. foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $aValue)
  372. if(isset($aValue['key']) && (int)$aValue['key'] == -(int)$aParams['context_id']) {
  373. $oForm->aInputs[$CNF[$sKey]]['value'] = -(int)$aParams['context_id'];
  374. $oForm->aInputs[$CNF[$sKey]]['type'] = 'hidden';
  375. break;
  376. }
  377. }
  378. return $oForm;
  379. }
  380. /**
  381. * Create entry form
  382. * @return HTML string
  383. */
  384. public function serviceEntityCreate ($sParams = false)
  385. {
  386. $bParamsArray = is_array($sParams);
  387. $sDisplay = is_string($sParams) ? $sParams : false;
  388. if($bParamsArray && !empty($sParams['display']))
  389. $sDisplay = $sParams['display'];
  390. bx_import('FormsEntryHelper', $this->_aModule);
  391. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  392. $oFormsHelper = new $sClass($this);
  393. if($bParamsArray && isset($sParams['dynamic_mode']))
  394. $oFormsHelper->setDynamicMode($sParams['dynamic_mode']);
  395. return $oFormsHelper->addDataForm($sDisplay);
  396. }
  397. public function serviceEntityEdit ($iContentId = 0, $sDisplay = false)
  398. {
  399. return $this->_serviceEntityForm ('editDataForm', $iContentId, $sDisplay);
  400. }
  401. public function serviceEntityDelete ($iContentId = 0)
  402. {
  403. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  404. }
  405. public function serviceEntityTextBlock ($iContentId = 0)
  406. {
  407. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  408. }
  409. public function serviceEntityInfo ($iContentId = 0, $sDisplay = false)
  410. {
  411. return $this->_serviceEntityForm ('viewDataForm', $iContentId, $sDisplay);
  412. }
  413. public function serviceEntityInfoFull ($iContentId = 0)
  414. {
  415. $CNF = &$this->_oConfig->CNF;
  416. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  417. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  418. }
  419. public function serviceEntityInfoExtended ($iContentId = 0)
  420. {
  421. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  422. }
  423. /**
  424. * Entry location info
  425. */
  426. public function serviceEntityLocation ($iContentId = 0)
  427. {
  428. $iContentId = $this->_getContent($iContentId, false);
  429. if($iContentId === false)
  430. return false;
  431. return $this->_oTemplate->entryLocation ($iContentId);
  432. }
  433. /**
  434. * Entry comments
  435. */
  436. public function serviceEntityComments ($iContentId = 0)
  437. {
  438. $CNF = &$this->_oConfig->CNF;
  439. if(empty($CNF['OBJECT_COMMENTS']))
  440. return '';
  441. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
  442. }
  443. /**
  444. * Entry attachments block
  445. */
  446. public function serviceEntityAttachments ($iContentId = 0)
  447. {
  448. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  449. }
  450. /**
  451. * Delete content entry
  452. * @param $iContentId content id
  453. * @return error message or empty string on success
  454. */
  455. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  456. {
  457. bx_import('FormsEntryHelper', $this->_aModule);
  458. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  459. $oFormsHelper = new $sClass($this);
  460. return $oFormsHelper->$sFuncDelete($iContentId);
  461. }
  462. /**
  463. * Entry actions and social sharing block
  464. */
  465. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  466. {
  467. $CNF = &$this->_oConfig->CNF;
  468. if(!empty($mixedContent)) {
  469. if(!is_array($mixedContent))
  470. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  471. }
  472. else {
  473. $mixedContent = $this->_getContent();
  474. if($mixedContent === false)
  475. return false;
  476. }
  477. list($iContentId, $aContentInfo) = $mixedContent;
  478. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  479. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  480. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL'];
  481. if(empty($sObjectMenu))
  482. return false;
  483. $sEntryTitle = !empty($aParams['entry_title']) ? $aParams['entry_title'] : '';
  484. if(empty($sEntryTitle) && !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  485. $sEntryTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  486. $sEntryUrl = !empty($aParams['entry_url']) ? $aParams['entry_url'] : '';
  487. if(empty($sEntryUrl) && !empty($CNF['URI_VIEW_ENTRY']))
  488. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  489. $iEntryThumb = !empty($aParams['entry_thumb']) ? (int)$aParams['entry_thumb'] : 0;
  490. if(empty($iEntryThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  491. $iEntryThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  492. $sObjectStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : false;
  493. if(empty($sObjectStorage) && !empty($CNF['OBJECT_STORAGE']))
  494. $sObjectStorage = $CNF['OBJECT_STORAGE'];
  495. $sObjectTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : false;
  496. $aMarkers = array(
  497. 'id' => $iContentId,
  498. 'module' => $this->_oConfig->getName(),
  499. 'title' => !empty($sEntryTitle) ? $sEntryTitle : '',
  500. 'url' => !empty($sEntryUrl) ? $sEntryUrl : '',
  501. 'img_url' => ''
  502. );
  503. if(!empty($iEntryThumb)) {
  504. if(!empty($sObjectTranscoder))
  505. $o = BxDolTranscoder::getObjectInstance($sObjectTranscoder);
  506. else if(!empty($sObjectStorage))
  507. $o = BxDolStorage::getObjectInstance($sObjectStorage);
  508. $sImageUrl = $o ? $o->getFileUrlById($iEntryThumb) : '';
  509. if(!empty($sImageUrl))
  510. $aMarkers['img_url'] = $sImageUrl;
  511. }
  512. $oActions = BxDolMenu::getObjectInstance($sObjectMenu);
  513. if(!$oActions)
  514. return false;
  515. $oActions->setContentId($iContentId);
  516. $oActions->addMarkers($aMarkers);
  517. return $this->_oTemplate->entryAllActions($oActions->getCode());
  518. }
  519. /**
  520. * Entry actions block
  521. */
  522. public function serviceEntityActions ($iContentId = 0)
  523. {
  524. $iContentId = $this->_getContent($iContentId, false);
  525. if($iContentId === false)
  526. return false;
  527. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  528. return $oMenu ? $oMenu->getCode() : false;
  529. }
  530. /**
  531. * Entry social sharing block.
  532. * @param type $mixedContent integer content ID or array with integer content ID and array with content info, or false.
  533. * @param type $aParams array with additional custom params which may overwrite some default values.
  534. * @return boolean|string string with block content or false if something went wrong.
  535. */
  536. public function serviceEntitySocialSharing($mixedContent = false, $aParams = array())
  537. {
  538. if(!empty($mixedContent)) {
  539. if(!is_array($mixedContent))
  540. $mixedContent = array((int)$mixedContent, array());
  541. }
  542. else {
  543. $mixedContent = $this->_getContent();
  544. if($mixedContent === false)
  545. return false;
  546. }
  547. list($iContentId, $aContentInfo) = $mixedContent;
  548. $CNF = &$this->_oConfig->CNF;
  549. $sUri = !empty($aParams['uri']) ? $aParams['uri'] : '';
  550. if(empty($sUri) && !empty($CNF['URI_VIEW_ENTRY']))
  551. $sUri = $CNF['URI_VIEW_ENTRY'];
  552. $sUrl = !empty($sUri) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $iContentId) : '';
  553. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  554. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  555. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  556. $aMarkers = array(
  557. 'id' => $iContentId,
  558. 'module' => $this->_aModule['name'],
  559. 'url' => BX_DOL_URL_ROOT . $sUrl,
  560. 'title' => $sTitle,
  561. );
  562. $iIdThumb = !empty($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  563. if(empty($iIdThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  564. $iIdThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  565. if ($iIdThumb) {
  566. $sTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : '';
  567. $sStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : '';
  568. if(empty($sStorage) && !empty($CNF['OBJECT_STORAGE']))
  569. $sStorage = $CNF['OBJECT_STORAGE'];
  570. if(!empty($sTranscoder))
  571. $o = BxDolTranscoder::getObjectInstance($sTranscoder);
  572. else if(!empty($sStorage))
  573. $o = BxDolStorage::getObjectInstance($sStorage);
  574. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  575. if($sImgUrl)
  576. $aMarkers['img_url'] = $sImgUrl;
  577. }
  578. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  579. $oMenu->addMarkers($aMarkers);
  580. $sMenu = $oMenu->getCode();
  581. if(empty($sMenu))
  582. return '';
  583. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  584. 'menu' => $sMenu
  585. ));
  586. }
  587. /**
  588. * Data for Notifications module
  589. */
  590. public function serviceGetNotificationsData()
  591. {
  592. $sModule = $this->_aModule['name'];
  593. $sEventPrivacy = $sModule . '_allow_view_event_to';
  594. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  595. $sEventPrivacy = '';
  596. return array(
  597. 'handlers' => array(
  598. 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),
  599. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  600. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  601. 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),
  602. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  603. 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),
  604. array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
  605. 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),
  606. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  607. ),
  608. 'settings' => array(
  609. array('group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => array('follow_member', 'follow_context')),
  610. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  611. array('group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => array('personal')),
  612. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context'))
  613. ),
  614. 'alerts' => array(
  615. array('unit' => $sModule, 'action' => 'added'),
  616. array('unit' => $sModule, 'action' => 'edited'),
  617. array('unit' => $sModule, 'action' => 'deleted'),
  618. array('unit' => $sModule, 'action' => 'commentPost'),
  619. array('unit' => $sModule, 'action' => 'commentRemoved'),
  620. array('unit' => $sModule, 'action' => 'replyPost'),
  621. array('unit' => $sModule, 'action' => 'replyRemoved'),
  622. array('unit' => $sModule, 'action' => 'doVote'),
  623. array('unit' => $sModule, 'action' => 'undoVote'),
  624. )
  625. );
  626. }
  627. /**
  628. * Entry post for Notifications module
  629. */
  630. public function serviceGetNotificationsPost($aEvent)
  631. {
  632. $CNF = &$this->_oConfig->CNF;
  633. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  634. if(empty($aContentInfo) || !is_array($aContentInfo))
  635. return array();
  636. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  637. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  638. return array(
  639. 'entry_sample' => $CNF['T']['txt_sample_single'],
  640. 'entry_url' => $sEntryUrl,
  641. 'entry_caption' => $sEntryCaption,
  642. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  643. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  644. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  645. );
  646. }
  647. /**
  648. * Entry post comment for Notifications module
  649. */
  650. public function serviceGetNotificationsComment($aEvent)
  651. {
  652. $CNF = &$this->_oConfig->CNF;
  653. $iContentId = (int)$aEvent['object_id'];
  654. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  655. if(empty($aContentInfo) || !is_array($aContentInfo))
  656. return array();
  657. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  658. if(!$oComment || !$oComment->isEnabled())
  659. return array();
  660. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  661. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  662. return array(
  663. 'entry_sample' => $CNF['T']['txt_sample_single'],
  664. 'entry_url' => $sEntryUrl,
  665. 'entry_caption' => $sEntryCaption,
  666. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  667. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  668. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  669. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  670. );
  671. }
  672. /**
  673. * Entry post reply for Notifications module
  674. */
  675. public function serviceGetNotificationsReply($aEvent)
  676. {
  677. $CNF = &$this->_oConfig->CNF;
  678. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  679. if(!$oComment || !$oComment->isEnabled())
  680. return array();
  681. $iParentId = (int)$aEvent['object_id'];
  682. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  683. if(empty($aParentInfo) || !is_array($aParentInfo))
  684. return array();
  685. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  686. $oComment->init($iObjectId);
  687. return array(
  688. 'object_id' => $iObjectId,
  689. 'entry_sample' => '_cmt_txt_sample_comment_single',
  690. 'entry_url' => $oComment->getViewUrl($iParentId),
  691. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  692. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  693. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  694. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  695. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  696. );
  697. }
  698. /**
  699. * Entry post vote for Notifications module
  700. */
  701. public function serviceGetNotificationsVote($aEvent)
  702. {
  703. $CNF = &$this->_oConfig->CNF;
  704. $iContentId = (int)$aEvent['object_id'];
  705. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  706. if(empty($aContentInfo) || !is_array($aContentInfo))
  707. return array();
  708. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  709. if(!$oVote || !$oVote->isEnabled())
  710. return array();
  711. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  712. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  713. return array(
  714. 'entry_sample' => $CNF['T']['txt_sample_single'],
  715. 'entry_url' => $sEntryUrl,
  716. 'entry_caption' => $sEntryCaption,
  717. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  718. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  719. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  720. );
  721. }
  722. /**
  723. * Data for Timeline module
  724. */
  725. public function serviceGetTimelineData()
  726. {
  727. $sModule = $this->_aModule['name'];
  728. return array(
  729. 'handlers' => array(
  730. 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' => ''),
  731. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  732. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  733. ),
  734. 'alerts' => array(
  735. array('unit' => $sModule, 'action' => 'added'),
  736. array('unit' => $sModule, 'action' => 'edited'),
  737. array('unit' => $sModule, 'action' => 'deleted'),
  738. )
  739. );
  740. }
  741. /**
  742. * Entry post for Timeline module
  743. */
  744. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  745. {
  746. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  747. if(empty($aContentInfo) || !is_array($aContentInfo))
  748. return false;
  749. $CNF = &$this->_oConfig->CNF;
  750. $iUserId = $this->getUserId();
  751. $iAuthorId = $aContentInfo[$CNF['FIELD_AUTHOR']];
  752. if($iAuthorId < 0 && abs($iAuthorId) != $iUserId)
  753. return false;
  754. //--- Views
  755. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aEvent['object_id']) : null;
  756. $aViews = array();
  757. if ($oViews && $oViews->isEnabled())
  758. $aViews = array(
  759. 'system' => $CNF['OBJECT_VIEWS'],
  760. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  761. 'count' => $aContentInfo['views']
  762. );
  763. //--- Votes
  764. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aEvent['object_id']) : null;
  765. $aVotes = array();
  766. if ($oVotes && $oVotes->isEnabled())
  767. $aVotes = array(
  768. 'system' => $CNF['OBJECT_VOTES'],
  769. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  770. 'count' => $aContentInfo['votes']
  771. );
  772. //--- Scores
  773. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aEvent['object_id']) : null;
  774. $aScores = array();
  775. if ($oScores && $oScores->isEnabled())
  776. $aScores = array(
  777. 'system' => $CNF['OBJECT_SCORES'],
  778. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  779. 'score' => $aContentInfo['score']
  780. );
  781. //--- Reports
  782. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aEvent['object_id']) : null;
  783. $aReports = array();
  784. if ($oReports && $oReports->isEnabled())
  785. $aReports = array(
  786. 'system' => $CNF['OBJECT_REPORTS'],
  787. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  788. 'count' => $aContentInfo['reports']
  789. );
  790. //--- Comments
  791. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']) : null;
  792. $aComments = array();
  793. if($oCmts && $oCmts->isEnabled())
  794. $aComments = array(
  795. 'system' => $CNF['OBJECT_COMMENTS'],
  796. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  797. 'count' => $aContentInfo['comments']
  798. );
  799. //--- Title & Description
  800. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  801. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  802. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  803. return array(
  804. 'owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  805. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  806. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  807. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  808. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  809. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  810. 'content' => $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams), //a string to display or array to parse default template before displaying.
  811. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  812. 'views' => $aViews,
  813. 'votes' => $aVotes,
  814. 'scores' => $aScores,
  815. 'reports' => $aReports,
  816. 'comments' => $aComments,
  817. 'title' => $sTitle, //may be empty.
  818. 'description' => '' //may be empty.
  819. );
  820. }
  821. /**
  822. * Check particular action permission without content
  823. * @param $sAction action to check, for example: Browse, Add
  824. * @param $iContentId content ID
  825. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  826. */
  827. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  828. {
  829. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  830. if (!method_exists($this, $sMethod))
  831. return _t('_sys_request_method_not_found_cpt');
  832. return $this->$sMethod($isPerformAction);
  833. }
  834. /**
  835. * Check particular action permission with content
  836. * @param $sAction action to check, for example: View, Edit
  837. * @param $iContentId content ID
  838. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  839. */
  840. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  841. {
  842. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  843. return _t('_sys_request_page_not_found_cpt');
  844. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  845. if (!method_exists($this, $sMethod))
  846. return _t('_sys_request_method_not_found_cpt');
  847. return $this->$sMethod($aContentInfo, $isPerformAction);
  848. }
  849. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  850. {
  851. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  852. }
  853. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  854. {
  855. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  856. }
  857. public function serviceGetContentOwnerProfileId ($iContentId)
  858. {
  859. $CNF = &$this->_oConfig->CNF;
  860. // file owner must be author of the content or profile itself in case of profile based module
  861. if ($iContentId) {
  862. if ($this instanceof iBxDolProfileService) {
  863. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  864. }
  865. else {
  866. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  867. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  868. }
  869. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  870. }
  871. else {
  872. $iProfileId = bx_get_logged_profile_id();
  873. }
  874. return $iProfileId;
  875. }
  876. // ====== PERMISSION METHODS
  877. public function checkAllowedSetThumb ($iContentId = 0)
  878. {
  879. return CHECK_ACTION_RESULT_ALLOWED;
  880. }
  881. /**
  882. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  883. */
  884. public function checkAllowedBrowse ()
  885. {
  886. return CHECK_ACTION_RESULT_ALLOWED;
  887. }
  888. /**
  889. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  890. */
  891. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  892. {
  893. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  894. }
  895. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  896. {
  897. if (!$iProfileId)
  898. $iProfileId = $this->_iProfileId;
  899. $CNF = &$this->_oConfig->CNF;
  900. // moderator and owner always have access
  901. if (!empty($iProfileId) && ((int)$aDataEntry[$CNF['FIELD_AUTHOR']] == (int)$iProfileId || $this->_isModerator($isPerformAction)))
  902. return CHECK_ACTION_RESULT_ALLOWED;
  903. // check ACL
  904. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  905. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  906. return $aCheck[CHECK_ACTION_MESSAGE];
  907. // check privacy
  908. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  909. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  910. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  911. return _t('_sys_access_denied_to_private_content');
  912. }
  913. return CHECK_ACTION_RESULT_ALLOWED;
  914. }
  915. /**
  916. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  917. */
  918. public function checkAllowedAdd ($isPerformAction = false)
  919. {
  920. // check ACL
  921. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  922. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  923. return $aCheck[CHECK_ACTION_MESSAGE];
  924. return CHECK_ACTION_RESULT_ALLOWED;
  925. }
  926. /**
  927. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  928. */
  929. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  930. {
  931. // moderator and owner always have access
  932. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  933. return CHECK_ACTION_RESULT_ALLOWED;
  934. return _t('_sys_txt_access_denied');
  935. }
  936. /**
  937. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  938. */
  939. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  940. {
  941. // moderator always has access
  942. if ($this->_isModerator($isPerformAction))
  943. return CHECK_ACTION_RESULT_ALLOWED;
  944. // check ACL
  945. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  946. if (($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId) && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  947. return CHECK_ACTION_RESULT_ALLOWED;
  948. return _t('_sys_txt_access_denied');
  949. }
  950. /**
  951. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  952. */
  953. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  954. {
  955. // admin always has access
  956. if (isAdmin())
  957. return CHECK_ACTION_RESULT_ALLOWED;
  958. // check ACL
  959. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  960. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  961. return $aCheck[CHECK_ACTION_MESSAGE];
  962. return CHECK_ACTION_RESULT_ALLOWED;
  963. }
  964. /**
  965. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  966. */
  967. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  968. {
  969. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  970. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  971. return CHECK_ACTION_RESULT_ALLOWED;
  972. return _t('_sys_txt_access_denied');
  973. }
  974. /**
  975. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  976. */
  977. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  978. {
  979. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  980. }
  981. /**
  982. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  983. */
  984. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  985. {
  986. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  987. }
  988. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  989. {
  990. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  991. return MsgBox($sMsg);
  992. bx_import($sClassSearchResult, $this->_aModule);
  993. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  994. $o = new $sClass($sMode, $aParams);
  995. $o->setDesignBoxTemplateId($iDesignBox);
  996. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  997. $o->setAjaxPaginate($bAjaxPaginate);
  998. $o->setUnitParams(array('context' => $sMode));
  999. if ($o->isError)
  1000. return '';
  1001. if ($s = $o->processing())
  1002. return $s;
  1003. else
  1004. return '';
  1005. }
  1006. // ====== COMMON METHODS
  1007. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  1008. {
  1009. if(empty($aTranscoders))
  1010. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  1011. $CNF = &$this->_oConfig->CNF;
  1012. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  1013. return false;
  1014. $iId = (int)$aContentInfo[$CNF[$sField]];
  1015. foreach($aTranscoders as $sTranscoder)
  1016. if(!empty($CNF[$sTranscoder]))
  1017. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  1018. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  1019. }
  1020. public function getProfileId()
  1021. {
  1022. return bx_get_logged_profile_id();
  1023. }
  1024. public function getProfileInfo($iUserId = 0)
  1025. {
  1026. $oProfile = $this->getObjectUser($iUserId);
  1027. $oAccount = null;
  1028. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  1029. $oAccount = $oProfile->getAccountObject();
  1030. $bAccount = !empty($oAccount);
  1031. return array(
  1032. 'id' => $oProfile->id(),
  1033. 'name' => $oProfile->getDisplayName(),
  1034. 'email' => $bAccount ? $oAccount->getEmail() : '',
  1035. 'link' => $oProfile->getUrl(),
  1036. 'icon' => $oProfile->getIcon(),
  1037. 'thumb' => $oProfile->getThumb(),
  1038. 'avatar' => $oProfile->getAvatar(),
  1039. 'unit' => $oProfile->getUnit(),
  1040. 'active' => $oProfile->isActive(),
  1041. );
  1042. }
  1043. public function getObjectUser($iUserId = 0)
  1044. {
  1045. bx_import('BxDolProfile');
  1046. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1047. return $oProfile;
  1048. }
  1049. public function getObjectFavorite($sSystem = '', $iId = 0)
  1050. {
  1051. $CNF = &$this->_oConfig->CNF;
  1052. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  1053. $sSystem = $CNF['OBJECT_FAVORITES'];
  1054. if(empty($sSystem))
  1055. return false;
  1056. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1057. if(!$oFavorite->isEnabled())
  1058. return false;
  1059. return $oFavorite;
  1060. }
  1061. public function getUserId()
  1062. {
  1063. return isLogged() ? bx_get_logged_profile_id() : 0;
  1064. }
  1065. public function getUserIp()
  1066. {
  1067. return getVisitorIP();
  1068. }
  1069. public function getUserInfo($iUserId = 0)
  1070. {
  1071. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1072. return array(
  1073. $oProfile->getDisplayName(),
  1074. $oProfile->getUrl(),
  1075. $oProfile->getThumb(),
  1076. $oProfile->getUnit(),
  1077. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  1078. );
  1079. }
  1080. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  1081. {
  1082. $CNF = &$this->_oConfig->CNF;
  1083. // default visible settings
  1084. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  1085. return false;
  1086. if (!empty($aItem['visibility_custom'])) {
  1087. $oMenu = BxDolMenu::getObjectInstance($sObject);
  1088. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $this->_aMarkers))
  1089. return false;
  1090. }
  1091. // get custom function name to check menu item visibility
  1092. $sFuncCheckAccess = false;
  1093. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  1094. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  1095. // check custom visibility settings defined in module config class
  1096. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), isset($aContentInfo) ? array(&$aContentInfo) : array()))
  1097. return false;
  1098. return true;
  1099. }
  1100. public function _isModerator ($isPerformAction = false)
  1101. {
  1102. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
  1103. }
  1104. // ====== PROTECTED METHODS
  1105. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  1106. {
  1107. $iContentId = $this->_getContent($iContentId, false);
  1108. if($iContentId === false)
  1109. return false;
  1110. bx_import('FormsEntryHelper', $this->_aModule);
  1111. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  1112. $oFormsHelper = new $sClass($this);
  1113. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  1114. }
  1115. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  1116. {
  1117. $mixedContent = $this->_getContent($iContentId, $sFuncGetContent);
  1118. if($mixedContent === false)
  1119. return false;
  1120. list($iContentId, $aContentInfo) = $mixedContent;
  1121. return $this->_oTemplate->$sFunc($aContentInfo);
  1122. }
  1123. protected function _rss ($aArgs, $sClass = 'SearchResult')
  1124. {
  1125. $sMode = array_shift($aArgs);
  1126. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  1127. $this->_oTemplate->displayAccessDenied ($sMsg);
  1128. exit;
  1129. }
  1130. $aParams = $this->_buildRssParams($sMode, $aArgs);
  1131. bx_import ($sClass, $this->_aModule);
  1132. $sClass = $this->_aModule['class_prefix'] . $sClass;
  1133. $o = new $sClass($sMode, $aParams);
  1134. if ($o->isError)
  1135. $this->_oTemplate->displayPageNotFound ();
  1136. else
  1137. $o->outputRSS();
  1138. exit;
  1139. }
  1140. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  1141. {
  1142. if(!$iContentId)
  1143. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1144. if(!$iContentId)
  1145. return false;
  1146. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  1147. return $iContentId;
  1148. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  1149. if(!$aContentInfo)
  1150. return false;
  1151. return array($iContentId, $aContentInfo);
  1152. }
  1153. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  1154. {
  1155. $CNF = &$this->_oConfig->CNF;
  1156. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1157. //--- Image(s)
  1158. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1159. //--- Video(s)
  1160. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1161. //--- Text
  1162. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  1163. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  1164. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1165. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  1166. }
  1167. return array(
  1168. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1169. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1170. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1171. 'url' => $sUrl,
  1172. 'title' => isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] :
  1173. (isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...') : ''),
  1174. 'text' => $sText,
  1175. 'images' => $aImages,
  1176. 'videos' => $aVideos
  1177. );
  1178. }
  1179. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1180. {
  1181. $CNF = &$this->_oConfig->CNF;
  1182. $sImage = $sImageOrig = '';
  1183. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
  1184. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  1185. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  1186. }
  1187. $bImageThumb = isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']];
  1188. if($sImage == '' && $bImageThumb)
  1189. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  1190. if($sImageOrig == '' && $bImageThumb)
  1191. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  1192. if(empty($sImage))
  1193. return array();
  1194. if($sImageOrig == '')
  1195. $sImageOrig = $sImage;
  1196. return array(
  1197. array('url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
  1198. );
  1199. }
  1200. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1201. {
  1202. return array();
  1203. }
  1204. protected function _entityComments ($sObject, $iId = 0)
  1205. {
  1206. if (!$iId)
  1207. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1208. if (!$iId)
  1209. return false;
  1210. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  1211. if (!$oCmts || !$oCmts->isEnabled())
  1212. return false;
  1213. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  1214. }
  1215. protected function _getFields($iContentId)
  1216. {
  1217. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1218. if(empty($aContentInfo))
  1219. return array();
  1220. return BxDolContentInfo::formatFields($aContentInfo);
  1221. }
  1222. protected function _getFieldValue($sField, $iContentId)
  1223. {
  1224. $CNF = &$this->_oConfig->CNF;
  1225. if(empty($CNF[$sField]))
  1226. return false;
  1227. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1228. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1229. return false;
  1230. return $aContentInfo[$CNF[$sField]];
  1231. }
  1232. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  1233. {
  1234. $CNF = &$this->_oConfig->CNF;
  1235. if(empty($sTranscoder) || empty($CNF[$sField]))
  1236. return false;
  1237. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1238. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1239. return false;
  1240. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  1241. if(!$oImagesTranscoder)
  1242. return false;
  1243. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  1244. }
  1245. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  1246. {
  1247. if(!$bAsJson)
  1248. return $aResponse;
  1249. if(!empty($aAdditional) && is_array($aAdditional))
  1250. $aResponse = array_merge($aResponse, $aAdditional);
  1251. echoJson($aResponse);
  1252. exit;
  1253. }
  1254. }
  1255. /** @} */