BxBaseModGeneralModule.php 60 KB

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