BxBaseModGeneralModule.php 61 KB

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