1
0

BxBaseModGeneralModule.php 45 KB

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