BxBaseModGeneralModule.php 44 KB

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