BxBaseModGeneralModule.php 44 KB

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