1
0

BxBaseModGeneralModule.php 59 KB

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