BxBaseModGeneralModule.php 57 KB

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