1
0

BxBaseModGeneralModule.php 58 KB

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