BxBaseModGeneralModule.php 51 KB

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