1
0

BxBaseModGeneralModule.php 50 KB

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