1
0

BxBaseModGeneralModule.php 66 KB

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