1
0

BxBaseModGeneralModule.php 69 KB

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