BxBaseModGeneralModule.php 55 KB

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