BxBaseModGeneralModule.php 74 KB

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