1
0

BxBaseModGeneralModule.php 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621
  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. /*
  658. * Custom settings for email and/or push notifications can be provided here.
  659. * Only necessary parts of 'settings' array can be used.
  660. *
  661. 'settings' => array(
  662. 'email' => array(
  663. 'template' => '', //--- custom email template
  664. 'markers' => '', //--- markers to parse email parts (subject, body) with
  665. 'subject' => '' //--- custom email subject
  666. ),
  667. 'push' => array(
  668. 'subject' => '' //--- custom push notification subject
  669. )
  670. )
  671. */
  672. );
  673. }
  674. /**
  675. * Entry post comment for Notifications module
  676. */
  677. public function serviceGetNotificationsComment($aEvent)
  678. {
  679. $CNF = &$this->_oConfig->CNF;
  680. $iContentId = (int)$aEvent['object_id'];
  681. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  682. if(empty($aContentInfo) || !is_array($aContentInfo))
  683. return array();
  684. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  685. if(!$oComment || !$oComment->isEnabled())
  686. return array();
  687. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  688. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  689. return array(
  690. 'entry_sample' => $CNF['T']['txt_sample_single'],
  691. 'entry_url' => $sEntryUrl,
  692. 'entry_caption' => $sEntryCaption,
  693. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  694. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  695. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  696. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  697. );
  698. }
  699. /**
  700. * Entry post reply for Notifications module
  701. */
  702. public function serviceGetNotificationsReply($aEvent)
  703. {
  704. $CNF = &$this->_oConfig->CNF;
  705. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  706. if(!$oComment || !$oComment->isEnabled())
  707. return array();
  708. $iParentId = (int)$aEvent['object_id'];
  709. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  710. if(empty($aParentInfo) || !is_array($aParentInfo))
  711. return array();
  712. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  713. $oComment->init($iObjectId);
  714. return array(
  715. 'object_id' => $iObjectId,
  716. 'entry_sample' => '_cmt_txt_sample_comment_single',
  717. 'entry_url' => $oComment->getViewUrl($iParentId),
  718. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  719. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  720. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  721. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  722. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  723. );
  724. }
  725. /**
  726. * Entry post vote for Notifications module
  727. */
  728. public function serviceGetNotificationsVote($aEvent)
  729. {
  730. $CNF = &$this->_oConfig->CNF;
  731. $iContentId = (int)$aEvent['object_id'];
  732. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  733. if(empty($aContentInfo) || !is_array($aContentInfo))
  734. return array();
  735. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  736. if(!$oVote || !$oVote->isEnabled())
  737. return array();
  738. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  739. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  740. return array(
  741. 'entry_sample' => $CNF['T']['txt_sample_single'],
  742. 'entry_url' => $sEntryUrl,
  743. 'entry_caption' => $sEntryCaption,
  744. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  745. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  746. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  747. );
  748. }
  749. /**
  750. * Data for Timeline module
  751. */
  752. public function serviceGetTimelineData()
  753. {
  754. $sModule = $this->_aModule['name'];
  755. return array(
  756. 'handlers' => array(
  757. 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' => ''),
  758. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  759. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  760. ),
  761. 'alerts' => array(
  762. array('unit' => $sModule, 'action' => 'added'),
  763. array('unit' => $sModule, 'action' => 'edited'),
  764. array('unit' => $sModule, 'action' => 'deleted'),
  765. )
  766. );
  767. }
  768. /**
  769. * Entry post for Timeline module
  770. */
  771. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  772. {
  773. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  774. if(empty($aContentInfo) || !is_array($aContentInfo))
  775. return false;
  776. $CNF = &$this->_oConfig->CNF;
  777. $iUserId = $this->getUserId();
  778. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  779. $iAuthorIdAbs = abs($iAuthorId);
  780. if($iAuthorId < 0 && $iAuthorIdAbs == (int)$aEvent['owner_id'] && $iAuthorIdAbs != $iUserId)
  781. return false;
  782. //--- Views
  783. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aEvent['object_id']) : null;
  784. $aViews = array();
  785. if ($oViews && $oViews->isEnabled())
  786. $aViews = array(
  787. 'system' => $CNF['OBJECT_VIEWS'],
  788. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  789. 'count' => $aContentInfo['views']
  790. );
  791. //--- Votes
  792. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aEvent['object_id']) : null;
  793. $aVotes = array();
  794. if ($oVotes && $oVotes->isEnabled())
  795. $aVotes = array(
  796. 'system' => $CNF['OBJECT_VOTES'],
  797. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  798. 'count' => $aContentInfo['votes']
  799. );
  800. //--- Scores
  801. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aEvent['object_id']) : null;
  802. $aScores = array();
  803. if ($oScores && $oScores->isEnabled())
  804. $aScores = array(
  805. 'system' => $CNF['OBJECT_SCORES'],
  806. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  807. 'score' => $aContentInfo['score']
  808. );
  809. //--- Reports
  810. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aEvent['object_id']) : null;
  811. $aReports = array();
  812. if ($oReports && $oReports->isEnabled())
  813. $aReports = array(
  814. 'system' => $CNF['OBJECT_REPORTS'],
  815. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  816. 'count' => $aContentInfo['reports']
  817. );
  818. //--- Comments
  819. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']) : null;
  820. $aComments = array();
  821. if($oCmts && $oCmts->isEnabled())
  822. $aComments = array(
  823. 'system' => $CNF['OBJECT_COMMENTS'],
  824. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  825. 'count' => $aContentInfo['comments']
  826. );
  827. //--- Title & Description
  828. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  829. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  830. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  831. return array(
  832. 'owner_id' => $aEvent['owner_id'],
  833. 'object_owner_id' => $iAuthorId,
  834. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  835. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  836. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  837. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  838. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  839. 'content' => $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams), //a string to display or array to parse default template before displaying.
  840. 'allowed_view' => method_exists($this, 'checkAllowedView') ? $this->checkAllowedView($aContentInfo) : CHECK_ACTION_RESULT_ALLOWED,
  841. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  842. 'views' => $aViews,
  843. 'votes' => $aVotes,
  844. 'scores' => $aScores,
  845. 'reports' => $aReports,
  846. 'comments' => $aComments,
  847. 'title' => $sTitle, //may be empty.
  848. 'description' => '' //may be empty.
  849. );
  850. }
  851. /**
  852. * Check particular action permission without content
  853. * @param $sAction action to check, for example: Browse, Add
  854. * @param $iContentId content ID
  855. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  856. */
  857. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  858. {
  859. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  860. if (!method_exists($this, $sMethod))
  861. return _t('_sys_request_method_not_found_cpt');
  862. return $this->$sMethod($isPerformAction);
  863. }
  864. /**
  865. * Check particular action permission with content
  866. * @param $sAction action to check, for example: View, Edit
  867. * @param $iContentId content ID
  868. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  869. */
  870. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  871. {
  872. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  873. return _t('_sys_request_page_not_found_cpt');
  874. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  875. if (!method_exists($this, $sMethod))
  876. return _t('_sys_request_method_not_found_cpt');
  877. return $this->$sMethod($aContentInfo, $isPerformAction);
  878. }
  879. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  880. {
  881. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  882. }
  883. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  884. {
  885. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  886. }
  887. public function serviceGetContentOwnerProfileId ($iContentId)
  888. {
  889. $CNF = &$this->_oConfig->CNF;
  890. // file owner must be author of the content or profile itself in case of profile based module
  891. if ($iContentId) {
  892. if ($this instanceof iBxDolProfileService) {
  893. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  894. }
  895. else {
  896. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  897. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  898. }
  899. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  900. }
  901. else {
  902. $iProfileId = bx_get_logged_profile_id();
  903. }
  904. return $iProfileId;
  905. }
  906. // ====== PERMISSION METHODS
  907. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  908. {
  909. if (!$iProfileId)
  910. $iProfileId = $this->_iProfileId;
  911. $CNF = &$this->_oConfig->CNF;
  912. // moderator and owner always have access
  913. if (!empty($iProfileId) && (abs($aDataEntry[$CNF['FIELD_AUTHOR']]) == (int)$iProfileId || $this->_isModerator($isPerformAction)))
  914. return CHECK_ACTION_RESULT_ALLOWED;
  915. // check ACL
  916. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  917. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  918. return $aCheck[CHECK_ACTION_MESSAGE];
  919. // check privacy
  920. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  921. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  922. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  923. return _t('_sys_access_denied_to_private_content');
  924. }
  925. // check alert to allow custom checks
  926. $mixedResult = null;
  927. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  928. if($mixedResult !== null)
  929. return $mixedResult;
  930. return CHECK_ACTION_RESULT_ALLOWED;
  931. }
  932. public function checkAllowedSetThumb ($iContentId = 0)
  933. {
  934. return CHECK_ACTION_RESULT_ALLOWED;
  935. }
  936. /**
  937. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  938. */
  939. public function checkAllowedBrowse ()
  940. {
  941. // check alert to allow custom checks
  942. $mixedResult = null;
  943. bx_alert('system', 'check_allowed_browse', 0, 0, array('module' => $this->getName(), 'profile_id' => $this->_iProfileId, 'override_result' => &$mixedResult));
  944. if($mixedResult !== null)
  945. return $mixedResult;
  946. return CHECK_ACTION_RESULT_ALLOWED;
  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 checkAllowedView ($aDataEntry, $isPerformAction = false)
  952. {
  953. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  954. }
  955. /**
  956. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  957. */
  958. public function checkAllowedAdd ($isPerformAction = false)
  959. {
  960. // check ACL
  961. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  962. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  963. return $aCheck[CHECK_ACTION_MESSAGE];
  964. return CHECK_ACTION_RESULT_ALLOWED;
  965. }
  966. /**
  967. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  968. */
  969. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  970. {
  971. // moderator and owner always have access
  972. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  973. return CHECK_ACTION_RESULT_ALLOWED;
  974. return _t('_sys_txt_access_denied');
  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 checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  980. {
  981. // moderator always has access
  982. if ($this->_isModerator($isPerformAction))
  983. return CHECK_ACTION_RESULT_ALLOWED;
  984. // check ACL
  985. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  986. 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)
  987. return CHECK_ACTION_RESULT_ALLOWED;
  988. return _t('_sys_txt_access_denied');
  989. }
  990. /**
  991. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  992. */
  993. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  994. {
  995. // admin always has access
  996. if (isAdmin())
  997. return CHECK_ACTION_RESULT_ALLOWED;
  998. // check ACL
  999. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  1000. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1001. return $aCheck[CHECK_ACTION_MESSAGE];
  1002. return CHECK_ACTION_RESULT_ALLOWED;
  1003. }
  1004. /**
  1005. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1006. */
  1007. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  1008. {
  1009. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  1010. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  1011. return CHECK_ACTION_RESULT_ALLOWED;
  1012. return _t('_sys_txt_access_denied');
  1013. }
  1014. /**
  1015. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1016. */
  1017. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  1018. {
  1019. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  1020. }
  1021. /**
  1022. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1023. */
  1024. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  1025. {
  1026. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  1027. }
  1028. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  1029. {
  1030. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  1031. return MsgBox($sMsg);
  1032. bx_import($sClassSearchResult, $this->_aModule);
  1033. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1034. $o = new $sClass($sMode, $aParams);
  1035. $o->setDesignBoxTemplateId($iDesignBox);
  1036. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  1037. $o->setAjaxPaginate($bAjaxPaginate);
  1038. $o->setUnitParams(array('context' => $sMode));
  1039. if ($o->isError)
  1040. return '';
  1041. if ($s = $o->processing())
  1042. return $s;
  1043. else
  1044. return '';
  1045. }
  1046. // ====== COMMON METHODS
  1047. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  1048. {
  1049. if(empty($aTranscoders))
  1050. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  1051. $CNF = &$this->_oConfig->CNF;
  1052. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  1053. return false;
  1054. $iId = (int)$aContentInfo[$CNF[$sField]];
  1055. foreach($aTranscoders as $sTranscoder)
  1056. if(!empty($CNF[$sTranscoder]))
  1057. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  1058. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  1059. }
  1060. public function getProfileId()
  1061. {
  1062. return bx_get_logged_profile_id();
  1063. }
  1064. public function getProfileInfo($iUserId = 0)
  1065. {
  1066. $oProfile = $this->getObjectUser($iUserId);
  1067. $oAccount = null;
  1068. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  1069. $oAccount = $oProfile->getAccountObject();
  1070. $bAccount = !empty($oAccount);
  1071. return array(
  1072. 'id' => $oProfile->id(),
  1073. 'name' => $oProfile->getDisplayName(),
  1074. 'email' => $bAccount ? $oAccount->getEmail() : '',
  1075. 'link' => $oProfile->getUrl(),
  1076. 'icon' => $oProfile->getIcon(),
  1077. 'thumb' => $oProfile->getThumb(),
  1078. 'avatar' => $oProfile->getAvatar(),
  1079. 'unit' => $oProfile->getUnit(),
  1080. 'active' => $oProfile->isActive(),
  1081. );
  1082. }
  1083. public function getObjectUser($iUserId = 0)
  1084. {
  1085. bx_import('BxDolProfile');
  1086. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1087. return $oProfile;
  1088. }
  1089. public function getObjectFavorite($sSystem = '', $iId = 0)
  1090. {
  1091. $CNF = &$this->_oConfig->CNF;
  1092. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  1093. $sSystem = $CNF['OBJECT_FAVORITES'];
  1094. if(empty($sSystem))
  1095. return false;
  1096. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1097. if(!$oFavorite->isEnabled())
  1098. return false;
  1099. return $oFavorite;
  1100. }
  1101. public function getUserId()
  1102. {
  1103. return isLogged() ? bx_get_logged_profile_id() : 0;
  1104. }
  1105. public function getUserIp()
  1106. {
  1107. return getVisitorIP();
  1108. }
  1109. public function getUserInfo($iUserId = 0)
  1110. {
  1111. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1112. return array(
  1113. $oProfile->getDisplayName(),
  1114. $oProfile->getUrl(),
  1115. $oProfile->getThumb(),
  1116. $oProfile->getUnit(),
  1117. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  1118. );
  1119. }
  1120. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  1121. {
  1122. $CNF = &$this->_oConfig->CNF;
  1123. // default visible settings
  1124. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  1125. return false;
  1126. if (!empty($aItem['visibility_custom'])) {
  1127. $oMenu = BxDolMenu::getObjectInstance($sObject);
  1128. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $oMenu->getMarkers()))
  1129. return false;
  1130. }
  1131. // get custom function name to check menu item visibility
  1132. $sFuncCheckAccess = false;
  1133. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  1134. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  1135. // check custom visibility settings defined in module config class
  1136. if(!isset($aContentInfo))
  1137. $aContentInfo = array();
  1138. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), array(&$aContentInfo)))
  1139. return false;
  1140. return true;
  1141. }
  1142. public function _isModerator ($isPerformAction = false)
  1143. {
  1144. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
  1145. }
  1146. // ====== PROTECTED METHODS
  1147. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  1148. {
  1149. $iContentId = $this->_getContent($iContentId, false);
  1150. if($iContentId === false)
  1151. return false;
  1152. bx_import('FormsEntryHelper', $this->_aModule);
  1153. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  1154. $oFormsHelper = new $sClass($this);
  1155. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  1156. }
  1157. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  1158. {
  1159. $mixedContent = $this->_getContent($iContentId, $sFuncGetContent);
  1160. if($mixedContent === false)
  1161. return false;
  1162. list($iContentId, $aContentInfo) = $mixedContent;
  1163. return $this->_oTemplate->$sFunc($aContentInfo);
  1164. }
  1165. protected function _rss ($aArgs, $sClass = 'SearchResult')
  1166. {
  1167. $sMode = array_shift($aArgs);
  1168. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  1169. $this->_oTemplate->displayAccessDenied ($sMsg);
  1170. exit;
  1171. }
  1172. $aParams = $this->_buildRssParams($sMode, $aArgs);
  1173. bx_import ($sClass, $this->_aModule);
  1174. $sClass = $this->_aModule['class_prefix'] . $sClass;
  1175. $o = new $sClass($sMode, $aParams);
  1176. if ($o->isError)
  1177. $this->_oTemplate->displayPageNotFound ();
  1178. else
  1179. $o->outputRSS();
  1180. exit;
  1181. }
  1182. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  1183. {
  1184. if(!$iContentId)
  1185. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1186. if(!$iContentId)
  1187. return false;
  1188. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  1189. return $iContentId;
  1190. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  1191. if(!$aContentInfo)
  1192. return false;
  1193. return array($iContentId, $aContentInfo);
  1194. }
  1195. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  1196. {
  1197. $CNF = &$this->_oConfig->CNF;
  1198. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1199. //--- Image(s)
  1200. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1201. $aImagesAttach = $this->_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1202. //--- Video(s)
  1203. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1204. $aVideosAttach = $this->_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1205. //--- Files(s)
  1206. $aFiles = $this->_getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1207. $aFilesAttach = $this->_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1208. //--- Title
  1209. $sTitle = '';
  1210. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  1211. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  1212. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  1213. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1214. //--- Text
  1215. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  1216. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  1217. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1218. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  1219. }
  1220. return array(
  1221. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1222. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1223. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1224. 'url' => $sUrl,
  1225. 'title' => $sTitle,
  1226. 'text' => $sText,
  1227. 'images' => $aImages,
  1228. 'images_attach' => $aImagesAttach,
  1229. 'videos' => $aVideos,
  1230. 'videos_attach' => $aVideosAttach,
  1231. 'files' => $aFiles,
  1232. 'files_attach' => $aFilesAttach
  1233. );
  1234. }
  1235. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1236. {
  1237. $CNF = &$this->_oConfig->CNF;
  1238. $sImage = $sImageOrig = '';
  1239. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
  1240. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  1241. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  1242. }
  1243. $bImageThumb = isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']];
  1244. if($sImage == '' && $bImageThumb)
  1245. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  1246. if($sImageOrig == '' && $bImageThumb)
  1247. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  1248. if(empty($sImage))
  1249. return array();
  1250. if($sImageOrig == '')
  1251. $sImageOrig = $sImage;
  1252. return array(
  1253. array('url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
  1254. );
  1255. }
  1256. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1257. {
  1258. return array();
  1259. }
  1260. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1261. {
  1262. return array();
  1263. }
  1264. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1265. {
  1266. return array();
  1267. }
  1268. protected function _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1269. {
  1270. return array();
  1271. }
  1272. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1273. {
  1274. return array();
  1275. }
  1276. protected function _entityComments ($sObject, $iId = 0)
  1277. {
  1278. if (!$iId)
  1279. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1280. if (!$iId)
  1281. return false;
  1282. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  1283. if (!$oCmts || !$oCmts->isEnabled())
  1284. return false;
  1285. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  1286. }
  1287. protected function _getFields($iContentId)
  1288. {
  1289. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1290. if(empty($aContentInfo))
  1291. return array();
  1292. return BxDolContentInfo::formatFields($aContentInfo);
  1293. }
  1294. protected function _getFieldValue($sField, $iContentId)
  1295. {
  1296. $CNF = &$this->_oConfig->CNF;
  1297. if(empty($CNF[$sField]))
  1298. return false;
  1299. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1300. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1301. return false;
  1302. return $aContentInfo[$CNF[$sField]];
  1303. }
  1304. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  1305. {
  1306. $CNF = &$this->_oConfig->CNF;
  1307. if(empty($sTranscoder) || empty($CNF[$sField]))
  1308. return false;
  1309. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1310. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1311. return false;
  1312. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  1313. if(!$oImagesTranscoder)
  1314. return false;
  1315. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  1316. }
  1317. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  1318. {
  1319. if(!$bAsJson)
  1320. return $aResponse;
  1321. if(!empty($aAdditional) && is_array($aAdditional))
  1322. $aResponse = array_merge($aResponse, $aAdditional);
  1323. echoJson($aResponse);
  1324. exit;
  1325. }
  1326. }
  1327. /** @} */