1
0

BxBaseModGeneralModule.php 45 KB

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