BxBaseModGeneralModule.php 46 KB

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