BxBaseModGeneralModule.php 57 KB

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