BxBaseModGeneralModule.php 72 KB

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