BxBaseModGeneralModule.php 60 KB

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