BxBaseModGeneralModule.php 62 KB

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