1
0

BxBaseModGeneralModule.php 50 KB

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