BxBaseModGeneralModule.php 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522
  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. $aParams['context_id'] = (bool)$aParams['context_id'] ? (int)$aParams['context_id'] : false;
  49. $mixedResponse = $this->serviceGetCreatePostForm($aParams);
  50. if(empty($mixedResponse))
  51. return echoJson(array());
  52. else if(is_array($mixedResponse)) {
  53. $mixedResponse['module'] = $sName;
  54. return echoJson($mixedResponse);
  55. }
  56. return echoJson(array(
  57. 'module' => $sName,
  58. 'content' => $mixedResponse
  59. ));
  60. }
  61. // ====== SERVICE METHODS
  62. public function serviceIsSafeService($s)
  63. {
  64. $sService = bx_gen_method_name($s);
  65. $aSafeServices = $this->serviceGetSafeServices();
  66. return isset($aSafeServices[$sService]);
  67. }
  68. public function serviceIsBadgesAvaliable()
  69. {
  70. $oBadges = BxDolBadges::getInstance();
  71. $aBadges = $oBadges->getData(array('type' => 'by_module&object', 'object_id' => 0, 'module' => $this->_oConfig->getName()));
  72. return count($aBadges) > 0 ? true : false;
  73. }
  74. public function serviceGetSafeServices()
  75. {
  76. return array(
  77. // other
  78. 'ModuleIcon' => '',
  79. 'GetLink' => '',
  80. // browse
  81. 'GetSearchResultUnit' => '',
  82. 'Browse' => '',
  83. 'BrowseFeatured' => '',
  84. 'BrowseFavorite' => '',
  85. // forms
  86. 'GetCreatePostForm' => '',
  87. 'EntityEdit' => '',
  88. 'EntityDelete' => '',
  89. // page blocks
  90. 'EntityTextBlock' => '',
  91. 'EntityInfo' => '',
  92. 'EntityInfoFull' => '',
  93. 'EntityInfoExtended' => '',
  94. 'EntityLocation' => '',
  95. 'EntityComments' => '',
  96. 'EntityAttachments' => '',
  97. // menu
  98. 'EntityAllActions' => '',
  99. 'EntityActions' => '',
  100. 'EntitySocialSharing' => '',
  101. 'MyEntriesActions' => '',
  102. );
  103. }
  104. /**
  105. * @page service Service Calls
  106. * @section bx_base_general Base General
  107. * @subsection bx_base_general-other Other
  108. * @subsubsection bx_base_general-module_icon module_icon
  109. *
  110. * @code bx_srv('bx_posts', 'module_icon', [...]); @endcode
  111. *
  112. * Get module icon as CSS class name with FontAwesome icon name class and color class
  113. *
  114. * @see BxBaseModGeneralModule::serviceModuleIcon
  115. */
  116. /**
  117. * @ref bx_base_general-module_icon "module_icon"
  118. */
  119. public function serviceModuleIcon ()
  120. {
  121. return isset($this->_oConfig->CNF['ICON']) ? $this->_oConfig->CNF['ICON'] : '';
  122. }
  123. public function serviceGetAuthor ($iContentId)
  124. {
  125. $mixedResult = $this->_getFieldValue('FIELD_AUTHOR', $iContentId);
  126. return $mixedResult !== false ? (int)$mixedResult : 0;
  127. }
  128. public function serviceGetPrivacyView ($iContentId)
  129. {
  130. return $this->_getFieldValue('FIELD_ALLOW_VIEW_TO', $iContentId);
  131. }
  132. public function serviceGetDateAdded ($iContentId)
  133. {
  134. $mixedResult = $this->_getFieldValue('FIELD_ADDED', $iContentId);
  135. return $mixedResult !== false ? (int)$mixedResult : 0;
  136. }
  137. public function serviceGetDateChanged ($iContentId)
  138. {
  139. $mixedResult = $this->_getFieldValue('FIELD_CHANGED', $iContentId);
  140. return $mixedResult !== false ? (int)$mixedResult : 0;
  141. }
  142. /**
  143. * @page service Service Calls
  144. * @section bx_base_general Base General
  145. * @subsection bx_base_general-other Other
  146. * @subsubsection bx_base_general-get_link get_link
  147. *
  148. * @code bx_srv('bx_posts', 'get_link', [...]); @endcode
  149. *
  150. * Get URL for the specified content.
  151. * @param $iContentId content id
  152. *
  153. * @see BxBaseModGeneralModule::serviceGetLink
  154. */
  155. /**
  156. * @ref bx_base_general-get_link "get_link"
  157. */
  158. public function serviceGetLink ($iContentId)
  159. {
  160. $CNF = &$this->_oConfig->CNF;
  161. if(empty($CNF['URI_VIEW_ENTRY']))
  162. return '';
  163. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  164. if(empty($aContentInfo))
  165. return '';
  166. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  167. }
  168. public function serviceGetTitle ($iContentId)
  169. {
  170. $mixedResult = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  171. return $mixedResult !== false ? $mixedResult : '';
  172. }
  173. public function serviceGetText ($iContentId)
  174. {
  175. $mixedResult = $this->_getFieldValue('FIELD_TEXT', $iContentId);
  176. if (false === $mixedResult)
  177. return '';
  178. $CNF = &$this->_oConfig->CNF;
  179. if (!empty($CNF['OBJECT_METATAGS']) && is_string($mixedResult)) {
  180. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  181. $mixedResult = $oMetatags->metaParse($iContentId, $mixedResult);
  182. }
  183. return $mixedResult;
  184. }
  185. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  186. {
  187. $CNF = &$this->_oConfig->CNF;
  188. $aContentInfo = $this->_getFields($iContentId);
  189. if(empty($aContentInfo))
  190. return array();
  191. if(!$bSearchableFieldsOnly)
  192. return $aContentInfo;
  193. if(empty($CNF['PARAM_SEARCHABLE_FIELDS']))
  194. return array();
  195. $aFields = explode(',', getParam($CNF['PARAM_SEARCHABLE_FIELDS']));
  196. if(empty($aFields))
  197. return array();
  198. $aResult = array();
  199. foreach($aFields as $sField)
  200. if(isset($aContentInfo[$sField]))
  201. $aResult[$sField] = $aContentInfo[$sField];
  202. return $aResult;
  203. }
  204. /**
  205. * @page service Service Calls
  206. * @section bx_base_general Base General
  207. * @subsection bx_base_general-browsing Browsing
  208. * @subsubsection bx_base_general-get_search_result_unit get_search_result_unit
  209. *
  210. * @code bx_srv('bx_posts', 'get_search_result_unit', [3,"unit_gallery.html"]); @endcode
  211. *
  212. * Get browsing unit for the specified content
  213. * @param $iContentId content id
  214. * @param $sUnitTemplate unit template, such as: unit_full.html, unit_gallery.html, unit_live_search.html
  215. *
  216. * @see BxBaseModGeneralModule::serviceGetSearchResultUnit
  217. */
  218. /**
  219. * @ref bx_base_general-get_search_result_unit "get_search_result_unit"
  220. */
  221. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  222. {
  223. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  224. if(empty($aContentInfo))
  225. return '';
  226. if(empty($sUnitTemplate))
  227. $sUnitTemplate = 'unit.html';
  228. return $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
  229. }
  230. public function serviceGetAll ($aParams = array())
  231. {
  232. if(empty($aParams) || !is_array($aParams))
  233. $aParams = array('type' => 'all');
  234. return $this->_oDb->getEntriesBy($aParams);
  235. }
  236. public function serviceGetAllByAuthor ($iProfileId)
  237. {
  238. return $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  239. }
  240. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  241. {
  242. $CNF = &$this->_oConfig->CNF;
  243. if(empty($CNF['OBJECT_FORM_ENTRY']))
  244. return array();
  245. $aResult = array();
  246. if(!empty($CNF['FIELD_AUTHOR']) && !in_array($CNF['FIELD_AUTHOR'], $this->_aSearchableNamesExcept))
  247. $aResult[$CNF['FIELD_AUTHOR']] = array(
  248. 'type' => 'text_auto',
  249. 'caption' => $CNF['T']['form_field_author'],
  250. 'info' => '',
  251. 'value' => '',
  252. 'values' => '',
  253. 'pass' => ''
  254. );
  255. $aInputs = array();
  256. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
  257. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  258. $aInputs = array_merge($aInputs, $oForm->aInputs);
  259. }
  260. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
  261. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'], $this->_oTemplate);
  262. $aInputs = array_merge($aInputs, $oForm->aInputs);
  263. }
  264. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  265. $aInputs = array_merge($aInputs, $aInputsAdd);
  266. foreach($aInputs as $aInput){
  267. if(in_array($aInput['type'], BxDolSearchExtended::$SEARCHABLE_TYPES) && !in_array($aInput['name'], $this->_aSearchableNamesExcept)) {
  268. $aField = array(
  269. 'type' => $aInput['type'],
  270. 'caption_system' => $aInput['caption_system_src'],
  271. 'caption' => $aInput['caption_src'],
  272. 'info' => $aInput['info_src'],
  273. 'value' => !empty($aInput['value']) ? $aInput['value'] : '',
  274. 'values' => !empty($aInput['values_src']) ? $aInput['values_src'] : '',
  275. 'pass' => !empty($aInput['db']['pass']) ? $aInput['db']['pass'] : '',
  276. );
  277. if(isset($aInput['search_type']))
  278. $aField['search_type'] = $aInput['search_type'];
  279. $aResult[$aInput['name']] = $aField;
  280. }
  281. }
  282. return $aResult;
  283. }
  284. public function serviceGetSearchResultExtended($aParams, $iStart = 0, $iPerPage = 0)
  285. {
  286. if(empty($aParams) || !is_array($aParams))
  287. return array();
  288. return $this->_oDb->getEntriesBy(array('type' => 'search_ids', 'search_params' => $aParams, 'start' => $iStart, 'per_page' => $iPerPage));
  289. }
  290. public function serviceGetSearchableFields ($aInputsAdd = array())
  291. {
  292. $CNF = $this->_oConfig->CNF;
  293. if(!isset($CNF['PARAM_SEARCHABLE_FIELDS']) || !isset($CNF['OBJECT_FORM_ENTRY']) || !isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
  294. return array();
  295. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  296. if(!$oForm)
  297. return array();
  298. $aInputs = $oForm->aInputs;
  299. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  300. $aInputs = array_merge($aInputs, $aInputsAdd);
  301. $aTextTypes = array('text', 'textarea');
  302. $aTextFields = array();
  303. foreach($aInputs as $r)
  304. if(in_array($r['type'], $aTextTypes))
  305. $aTextFields[$r['name']] = $r['caption'];
  306. return $aTextFields;
  307. }
  308. public function serviceManageTools($sType = 'common')
  309. {
  310. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
  311. if(!$oGrid)
  312. return '';
  313. $CNF = &$this->_oConfig->CNF;
  314. $sMenu = '';
  315. if(BxDolAcl::getInstance()->isMemberLevelInSet(192)) {
  316. $oPermalink = BxDolPermalinks::getInstance();
  317. $aMenuItems = array();
  318. if(!empty($CNF['OBJECT_GRID_COMMON']) && !empty($CNF['T']['menu_item_manage_my']))
  319. $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);
  320. if(!empty($CNF['OBJECT_GRID_ADMINISTRATION']) && !empty($CNF['T']['menu_item_manage_all']))
  321. $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);
  322. if(count($aMenuItems) > 1) {
  323. $oMenu = new BxTemplMenu(array(
  324. 'template' => 'menu_vertical.html',
  325. 'menu_items' => $aMenuItems
  326. ), $this->_oTemplate);
  327. $oMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
  328. $sMenu = $oMenu->getCode();
  329. }
  330. }
  331. if(!empty($CNF['OBJECT_MENU_SUBMENU']) && isset($CNF['URI_MANAGE_COMMON'])) {
  332. BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
  333. }
  334. $this->_oTemplate->addCss(array('manage_tools.css'));
  335. $this->_oTemplate->addJs(array('manage_tools.js'));
  336. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  337. return array(
  338. 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
  339. 'menu' => $sMenu
  340. );
  341. }
  342. public function serviceGetMenuAddonManageTools()
  343. {
  344. return 0;
  345. }
  346. public function serviceGetMenuAddonManageToolsProfileStats()
  347. {
  348. return 0;
  349. }
  350. /**
  351. * @page service Service Calls
  352. * @section bx_base_general Base General
  353. * @subsection bx_base_general-browsing Browsing
  354. * @subsubsection bx_base_general-browse browse
  355. *
  356. * @code bx_srv('bx_posts', 'browse', [...]); @endcode
  357. *
  358. * Universal browse method.
  359. * @param $aParams custom browse params, possible params are the following:
  360. * - mode - browse mode, such as 'recent', 'featured', etc
  361. * - params - custom params to browse method, for example 'unit_view' can be passed here
  362. * - design_box - design box style, @see BxBaseFunctions::DesignBoxContent
  363. * - empty_message - display or not "empty" message when there is no content
  364. * - ajax_paginate - use AJAX paginate or not
  365. *
  366. * @see BxBaseModGeneralModule::serviceBrowse
  367. */
  368. /**
  369. * @ref bx_base_general-browse "browse"
  370. */
  371. public function serviceBrowse ($aParams = array())
  372. {
  373. $aDefaults = array (
  374. 'mode' => 'recent',
  375. 'params' => false,
  376. 'design_box' => BX_DB_PADDING_DEF,
  377. 'empty_message' => false,
  378. 'ajax_paginate' => true,
  379. 'class_search_result' => 'SearchResult'
  380. );
  381. $aParams = array_merge($aDefaults, $aParams);
  382. return $this->_serviceBrowse ($aParams['mode'], $aParams['params'], $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate'], $aParams['class_search_result']);
  383. }
  384. /**
  385. * @page service Service Calls
  386. * @section bx_base_general Base General
  387. * @subsection bx_base_general-browsing Browsing
  388. * @subsubsection bx_base_general-browse_featured browse_featured
  389. *
  390. * @code bx_srv('bx_posts', 'browse_featured', [...]); @endcode
  391. *
  392. * Display featured entries
  393. * @param $sUnitView browsing unity view,
  394. * such as: full, extended, gallery, showcase
  395. * @param $bEmptyMessage display or not "empty" message when there is no content
  396. * @param $bAjaxPaginate use AJAX paginate or not
  397. *
  398. * @see BxBaseModGeneralModule::serviceBrowseFeatured
  399. */
  400. /**
  401. * @ref bx_base_general-browse_featured "browse_featured"
  402. */
  403. public function serviceBrowseFeatured ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  404. {
  405. return $this->_serviceBrowse ('featured', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  406. }
  407. /**
  408. * @page service Service Calls
  409. * @section bx_base_general Base General
  410. * @subsection bx_base_general-browsing Browsing
  411. * @subsubsection bx_base_general-browse_favorite browse_favorite
  412. *
  413. * @code bx_srv('bx_posts', 'browse_favorite', [...]); @endcode
  414. *
  415. * Display entries whoch were added to favorite list by some member
  416. * @param $iProfileId profile ID
  417. * @param $aParams additional browse params, see BxBaseModGeneralModule::serviceBrowse
  418. *
  419. * @see BxBaseModGeneralModule::serviceBrowseFavorite BxBaseModGeneralModule::serviceBrowse
  420. */
  421. /**
  422. * @ref bx_base_general-browse_favorite "browse_favorite"
  423. */
  424. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  425. {
  426. $oProfile = null;
  427. if((int)$iProfileId)
  428. $oProfile = BxDolProfile::getInstance($iProfileId);
  429. if(!$oProfile && bx_get('profile_id') !== false)
  430. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  431. if(!$oProfile)
  432. $oProfile = BxDolProfile::getInstance();
  433. if(!$oProfile)
  434. return '';
  435. $bEmptyMessage = false;
  436. if(isset($aParams['empty_message'])) {
  437. $bEmptyMessage = (bool)$aParams['empty_message'];
  438. unset($aParams['empty_message']);
  439. }
  440. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage);
  441. }
  442. /**
  443. * Display entries posted into particular context
  444. * @return HTML string
  445. */
  446. public function serviceBrowseContext ($iProfileId = 0, $aParams = array())
  447. {
  448. return $this->_serviceBrowseWithParam ('context', 'profile_id', $iProfileId, $aParams);
  449. }
  450. public function _serviceBrowseWithParam ($sParamName, $sParamGet, $sParamVal, $aParams = array())
  451. {
  452. if(!$sParamVal)
  453. $sParamVal = bx_process_input(bx_get($sParamGet), BX_DATA_INT);
  454. if(!$sParamVal)
  455. return '';
  456. $bEmptyMessage = true;
  457. if(isset($aParams['empty_message'])) {
  458. $bEmptyMessage = (bool)$aParams['empty_message'];
  459. unset($aParams['empty_message']);
  460. }
  461. $bAjaxPaginate = true;
  462. if(isset($aParams['ajax_paginate'])) {
  463. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  464. unset($aParams['ajax_paginate']);
  465. }
  466. return $this->_serviceBrowse ($sParamName, array_merge(array($sParamName => $sParamVal), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  467. }
  468. public function serviceFormsHelper ()
  469. {
  470. bx_import('FormsEntryHelper', $this->_aModule);
  471. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  472. return new $sClass($this);
  473. }
  474. /**
  475. * Add entry using provided fields' values.
  476. * @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
  477. */
  478. public function serviceEntityAdd ($iProfile, $aValues)
  479. {
  480. bx_import('FormsEntryHelper', $this->_aModule);
  481. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  482. $oFormsHelper = new $sClass($this);
  483. return $oFormsHelper->addData($iProfile, $aValues);
  484. }
  485. /**
  486. * Perform redirect after content creation
  487. * @return nothing, rediret header is sent
  488. */
  489. public function serviceRedirectAfterAdd($aContentInfo)
  490. {
  491. bx_import('FormsEntryHelper', $this->_aModule);
  492. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  493. $oFormsHelper = new $sClass($this);
  494. $oFormsHelper->redirectAfterAdd($aContentInfo);
  495. }
  496. /**
  497. * Get form object for add, edit, view or delete the content
  498. * @param $sType 'add', 'edit', 'view' or 'delete'
  499. * @param $aParams optional array with parameters(display name, etc)
  500. * @return form object or false on error
  501. */
  502. public function serviceGetObjectForm ($sType, $aParams = array())
  503. {
  504. if(!in_array($sType, array('add', 'edit', 'view', 'delete')))
  505. return false;
  506. $mixedContextId = isset($aParams['context_id']) ? $aParams['context_id'] : false;
  507. $bContext = $mixedContextId !== false;
  508. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  509. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  510. return false;
  511. $CNF = &$this->_oConfig->CNF;
  512. bx_import('FormsEntryHelper', $this->_aModule);
  513. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  514. $oFormsHelper = new $sClass($this);
  515. $sParamsKey = 'ajax_mode';
  516. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  517. $oFormsHelper->setAjaxMode((bool)$aParams[$sParamsKey]);
  518. $sParamsKey = 'absolute_action_url';
  519. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  520. $oFormsHelper->setAbsoluteActionUrl((bool)$aParams[$sParamsKey]);
  521. $sDisplay = !empty($aParams['display']) ? $aParams['display'] : false;
  522. $sFunc = 'getObjectForm' . ucfirst($sType);
  523. $oForm = $oFormsHelper->$sFunc($sDisplay);
  524. $sKey = 'FIELD_ALLOW_VIEW_TO';
  525. if(!empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]]) && (!$bContext || $mixedContextId < 0)) {
  526. $bContextOwner = $bContext && abs($mixedContextId) == (int)bx_get_logged_profile_id();
  527. if(!$bContext || $bContextOwner) {
  528. $iGc = 0;
  529. $iKeyGh = false;
  530. foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $iKey => $aValue) {
  531. if(isset($aValue['type']) && in_array($aValue['type'], array('group_header', 'group_end'))) {
  532. if($iKeyGh !== false && $iGc == 0) {
  533. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKeyGh]);
  534. $iKeyGh = false;
  535. if($aValue['type'] == 'group_end')
  536. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  537. }
  538. if($aValue['type'] == 'group_header') {
  539. $iGc = 0;
  540. $iKeyGh = $iKey;
  541. }
  542. continue;
  543. }
  544. //--- Show 'Public' privacy group only in Public post form.
  545. if(!$bContext && $aValue['key'] == BX_DOL_PG_ALL) {
  546. $iGc += 1;
  547. continue;
  548. }
  549. //--- Show a default privacy groups in Profile (for Owner) post form.
  550. if($bContextOwner && (int)$aValue['key'] >= 0) {
  551. $iGc += 1;
  552. continue;
  553. }
  554. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  555. }
  556. }
  557. else {
  558. $oForm->aInputs[$CNF[$sKey]]['value'] = $mixedContextId;
  559. $oForm->aInputs[$CNF[$sKey]]['type'] = 'hidden';
  560. }
  561. }
  562. bx_alert('system', 'get_object_form', 0, 0, array(
  563. 'module' => $this->_oConfig->getName(),
  564. 'type' => $sType,
  565. 'params' => $aParams,
  566. 'form' => &$oForm
  567. ));
  568. return $oForm;
  569. }
  570. /**
  571. * Create entry form
  572. * @return HTML string
  573. */
  574. public function serviceEntityCreate ($sParams = false)
  575. {
  576. $bParamsArray = is_array($sParams);
  577. $sDisplay = is_string($sParams) ? $sParams : false;
  578. if($bParamsArray && !empty($sParams['display']))
  579. $sDisplay = $sParams['display'];
  580. bx_import('FormsEntryHelper', $this->_aModule);
  581. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  582. $oFormsHelper = new $sClass($this);
  583. if($bParamsArray && isset($sParams['dynamic_mode']))
  584. $oFormsHelper->setDynamicMode($sParams['dynamic_mode']);
  585. $mixedResult = $oFormsHelper->addDataForm($sDisplay);
  586. if(isset($mixedResult['_dt']) && $mixedResult['_dt'] == 'json') {
  587. echoJson($mixedResult);
  588. exit;
  589. }
  590. return $mixedResult;
  591. }
  592. /**
  593. * @page service Service Calls
  594. * @section bx_base_general Base General
  595. * @subsection bx_base_general-forms Forms
  596. * @subsubsection bx_base_general-get_create_post_form get_create_post_form
  597. *
  598. * @code bx_srv('bx_posts', 'get_create_post_form'); @endcode
  599. *
  600. * Get content creation form
  601. * @param $aParams additional parameters array:
  602. * context_id, ajax_mode, absolute_action_url, displays
  603. *
  604. * @see BxBaseModGeneralModule::serviceGetCreatePostForm
  605. */
  606. /**
  607. * @ref bx_base_general-get_create_post_form "get_create_post_form"
  608. */
  609. public function serviceGetCreatePostForm($aParams = array())
  610. {
  611. $aParams = array_merge($this->_aFormParams, $aParams);
  612. $oForm = $this->serviceGetObjectForm('add', $aParams);
  613. if(!$oForm)
  614. return '';
  615. return $this->serviceEntityCreate($aParams);
  616. }
  617. /**
  618. * @page service Service Calls
  619. * @section bx_base_general Base General
  620. * @subsection bx_base_general-forms Forms
  621. * @subsubsection bx_base_general-entity_edit entity_edit
  622. *
  623. * @code bx_srv('bx_posts', 'entity_edit', [...]); @endcode
  624. *
  625. * Get content edit form
  626. * @param $iContentId content ID
  627. * @param $sDisplay optional form display name
  628. *
  629. * @see BxBaseModGeneralModule::serviceEntityEdit
  630. */
  631. /**
  632. * @ref bx_base_general-entity_edit "entity_edit"
  633. */
  634. public function serviceEntityEdit ($iContentId = 0, $sDisplay = false)
  635. {
  636. return $this->_serviceEntityForm ('editDataForm', $iContentId, $sDisplay);
  637. }
  638. /**
  639. * @page service Service Calls
  640. * @section bx_base_general Base General
  641. * @subsection bx_base_general-forms Forms
  642. * @subsubsection bx_base_general-entity_delete entity_delete
  643. *
  644. * @code bx_srv('bx_posts', 'entity_delete', [...]); @endcode
  645. *
  646. * Get content delete form
  647. * @param $iContentId content ID
  648. *
  649. * @see BxBaseModGeneralModule::serviceEntityDelete
  650. */
  651. /**
  652. * @ref bx_base_general-entity_delete "entity_delete"
  653. */
  654. public function serviceEntityDelete ($iContentId = 0)
  655. {
  656. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  657. }
  658. /**
  659. * @page service Service Calls
  660. * @section bx_base_general Base General
  661. * @subsection bx_base_general-page_blocks Page Blocks
  662. * @subsubsection bx_base_general-entity_text_block entity_text_block
  663. *
  664. * @code bx_srv('bx_posts', 'entity_text_block', [...]); @endcode
  665. *
  666. * Get content text/description
  667. * @param $iContentId content ID
  668. *
  669. * @see BxBaseModGeneralModule::serviceEntityTextBlock
  670. */
  671. /**
  672. * @ref bx_base_general-entity_text_block "entity_text_block"
  673. */
  674. public function serviceEntityTextBlock ($iContentId = 0)
  675. {
  676. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  677. }
  678. /**
  679. * @page service Service Calls
  680. * @section bx_base_general Base General
  681. * @subsection bx_base_general-page_blocks Page Blocks
  682. * @subsubsection bx_base_general-entity_info entity_info
  683. *
  684. * @code bx_srv('bx_posts', 'entity_info', [...]); @endcode
  685. *
  686. * Get content info
  687. * @param $iContentId content ID
  688. *
  689. * @see BxBaseModGeneralModule::serviceEntityInfo
  690. */
  691. /**
  692. * @ref bx_base_general-entity_info "entity_info"
  693. */
  694. public function serviceEntityInfo ($iContentId = 0, $sDisplay = false)
  695. {
  696. return $this->_serviceEntityForm ('viewDataForm', $iContentId, $sDisplay);
  697. }
  698. /**
  699. * @page service Service Calls
  700. * @section bx_base_general Base General
  701. * @subsection bx_base_general-page_blocks Page Blocks
  702. * @subsubsection bx_base_general-entity_info_full entity_info_full
  703. *
  704. * @code bx_srv('bx_posts', 'entity_info_full', [...]); @endcode
  705. *
  706. * Get full content info
  707. * @param $iContentId content ID
  708. *
  709. * @see BxBaseModGeneralModule::serviceEntityInfoFull
  710. */
  711. /**
  712. * @ref bx_base_general-entity_info_full "entity_info_full"
  713. */
  714. public function serviceEntityInfoFull ($iContentId = 0)
  715. {
  716. $CNF = &$this->_oConfig->CNF;
  717. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  718. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  719. }
  720. /**
  721. * @page service Service Calls
  722. * @section bx_base_general Base General
  723. * @subsection bx_base_general-page_blocks Page Blocks
  724. * @subsubsection bx_base_general-entity_info_extended entity_info_extended
  725. *
  726. * @code bx_srv('bx_posts', 'entity_info_extended', [...]); @endcode
  727. *
  728. * Get extended content info
  729. * @param $iContentId content ID
  730. *
  731. * @see BxBaseModGeneralModule::serviceEntityInfoExtended
  732. */
  733. /**
  734. * @ref bx_base_general-entity_info_extended "entity_info_extended"
  735. */
  736. public function serviceEntityInfoExtended ($iContentId = 0)
  737. {
  738. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  739. }
  740. /**
  741. * @page service Service Calls
  742. * @section bx_base_general Base General
  743. * @subsection bx_base_general-page_blocks Page Blocks
  744. * @subsubsection bx_base_general-entity_location entity_location
  745. *
  746. * @code bx_srv('bx_posts', 'entity_location', [...]); @endcode
  747. *
  748. * Get content location
  749. * @param $iContentId content ID
  750. *
  751. * @see BxBaseModGeneralModule::serviceEntityLocation
  752. */
  753. /**
  754. * @ref bx_base_general-entity_location "entity_location"
  755. */
  756. public function serviceEntityLocation ($iContentId = 0)
  757. {
  758. $iContentId = $this->_getContent($iContentId, false);
  759. if($iContentId === false)
  760. return false;
  761. return $this->_oTemplate->entryLocation ($iContentId);
  762. }
  763. /**
  764. * @page service Service Calls
  765. * @section bx_base_general Base General
  766. * @subsection bx_base_general-page_blocks Page Blocks
  767. * @subsubsection bx_base_general-entity_comments entity_comments
  768. *
  769. * @code bx_srv('bx_posts', 'entity_comments', [...]); @endcode
  770. *
  771. * Get content comments
  772. * @param $iContentId content ID
  773. *
  774. * @see BxBaseModGeneralModule::serviceEntityComments
  775. */
  776. /**
  777. * @ref bx_base_general-entity_comments "entity_comments"
  778. */
  779. public function serviceEntityComments ($iContentId = 0)
  780. {
  781. $CNF = &$this->_oConfig->CNF;
  782. if(empty($CNF['OBJECT_COMMENTS']))
  783. return '';
  784. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
  785. }
  786. /**
  787. * @page service Service Calls
  788. * @section bx_base_general Base General
  789. * @subsection bx_base_general-page_blocks Page Blocks
  790. * @subsubsection bx_base_general-entity_attachments entity_attachments
  791. *
  792. * @code bx_srv('bx_posts', 'entity_attachments', [...]); @endcode
  793. *
  794. * Get content attachments
  795. * @param $iContentId content ID
  796. *
  797. * @see BxBaseModGeneralModule::serviceEntityAttachments
  798. */
  799. /**
  800. * @ref bx_base_general-entity_attachments "entity_attachments"
  801. */
  802. public function serviceEntityAttachments ($iContentId = 0)
  803. {
  804. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  805. }
  806. /**
  807. * Delete content entry
  808. * @param $iContentId content id
  809. * @return error message or empty string on success
  810. */
  811. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  812. {
  813. bx_import('FormsEntryHelper', $this->_aModule);
  814. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  815. $oFormsHelper = new $sClass($this);
  816. return $oFormsHelper->$sFuncDelete($iContentId);
  817. }
  818. /**
  819. * @page service Service Calls
  820. * @section bx_base_general Base General
  821. * @subsection bx_base_general-menu Menu
  822. * @subsubsection bx_base_general-my_entries_actions my_entries_actions
  823. *
  824. * @code bx_srv('bx_posts', 'my_entries_actions', [...]); @endcode
  825. *
  826. * My entries actions menu
  827. * @param $iProfileId profiles ID,
  828. * if omitted it try to get it from 'profile_id' GET param
  829. *
  830. * @see BxBaseModGeneralModule::serviceMyEntriesActions
  831. */
  832. /**
  833. * @ref bx_base_general-my_entries_actions "my_entries_actions"
  834. */
  835. public function serviceMyEntriesActions ($iProfileId = 0)
  836. {
  837. $CNF = &$this->_oConfig->CNF;
  838. if(empty($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']))
  839. return false;
  840. if (!$iProfileId)
  841. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  842. if (!$iProfileId || !($oProfile = BxDolProfile::getInstance($iProfileId)))
  843. return false;
  844. if ($iProfileId != $this->_iProfileId)
  845. return false;
  846. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  847. return $oMenu ? $oMenu->getCode() : false;
  848. }
  849. /**
  850. * @page service Service Calls
  851. * @section bx_base_general Base General
  852. * @subsection bx_base_general-menu Menu
  853. * @subsubsection bx_base_general-entity_all_actions entity_all_actions
  854. *
  855. * @code bx_srv('bx_posts', 'entity_all_actions', [...]); @endcode
  856. *
  857. * Entry actions and social sharing actions
  858. * @param $mixedContent content ID
  859. * @param $aParams additional params
  860. *
  861. * @see BxBaseModGeneralModule::serviceEntityAllActions
  862. */
  863. /**
  864. * @ref bx_base_general-entity_all_actions "entity_all_actions"
  865. */
  866. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  867. {
  868. $CNF = &$this->_oConfig->CNF;
  869. if(!empty($mixedContent)) {
  870. if(!is_array($mixedContent))
  871. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  872. }
  873. else {
  874. $mixedContent = $this->_getContent();
  875. if($mixedContent === false)
  876. return false;
  877. }
  878. list($iContentId, $aContentInfo) = $mixedContent;
  879. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  880. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  881. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL'];
  882. if(empty($sObjectMenu))
  883. return false;
  884. $sEntryTitle = !empty($aParams['entry_title']) ? $aParams['entry_title'] : '';
  885. if(empty($sEntryTitle) && !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  886. $sEntryTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  887. $sEntryUrl = !empty($aParams['entry_url']) ? $aParams['entry_url'] : '';
  888. if(empty($sEntryUrl) && !empty($CNF['URI_VIEW_ENTRY']))
  889. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  890. $iEntryThumb = !empty($aParams['entry_thumb']) ? (int)$aParams['entry_thumb'] : 0;
  891. if(empty($iEntryThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  892. $iEntryThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  893. $sObjectStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : false;
  894. if(empty($sObjectStorage) && !empty($CNF['OBJECT_STORAGE']))
  895. $sObjectStorage = $CNF['OBJECT_STORAGE'];
  896. $sObjectTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : false;
  897. $aMarkers = array(
  898. 'id' => $iContentId,
  899. 'module' => $this->_oConfig->getName(),
  900. 'title' => !empty($sEntryTitle) ? $sEntryTitle : '',
  901. 'url' => !empty($sEntryUrl) ? $sEntryUrl : '',
  902. 'img_url' => ''
  903. );
  904. if(!empty($iEntryThumb)) {
  905. if(!empty($sObjectTranscoder))
  906. $o = BxDolTranscoder::getObjectInstance($sObjectTranscoder);
  907. else if(!empty($sObjectStorage))
  908. $o = BxDolStorage::getObjectInstance($sObjectStorage);
  909. $sImageUrl = $o ? $o->getFileUrlById($iEntryThumb) : '';
  910. if(!empty($sImageUrl))
  911. $aMarkers['img_url'] = $sImageUrl;
  912. }
  913. $oActions = BxDolMenu::getObjectInstance($sObjectMenu);
  914. if(!$oActions)
  915. return false;
  916. $oActions->setContentId($iContentId);
  917. $oActions->addMarkers($aMarkers);
  918. return $this->_oTemplate->entryAllActions($oActions->getCode());
  919. }
  920. /**
  921. * @page service Service Calls
  922. * @section bx_base_general Base General
  923. * @subsection bx_base_general-menu Menu
  924. * @subsubsection bx_base_general-entity_actions entity_actions
  925. *
  926. * @code bx_srv('bx_posts', 'entity_actions', [...]); @endcode
  927. *
  928. * Entry actions, without social sharing actions
  929. * @param $iContentId content ID
  930. *
  931. * @see BxBaseModGeneralModule::serviceEntityActions
  932. */
  933. /**
  934. * @ref bx_base_general-entity_actions "entity_actions"
  935. */
  936. public function serviceEntityActions ($iContentId = 0)
  937. {
  938. $iContentId = $this->_getContent($iContentId, false);
  939. if($iContentId === false)
  940. return false;
  941. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  942. return $oMenu ? $oMenu->getCode() : false;
  943. }
  944. /**
  945. * @page service Service Calls
  946. * @section bx_base_general Base General
  947. * @subsection bx_base_general-menu Menu
  948. * @subsubsection bx_base_general-entity_social_sharing entity_social_sharing
  949. *
  950. * @code bx_srv('bx_posts', 'entity_social_sharing', [...]); @endcode
  951. *
  952. * Entry social sharing actions
  953. * @param $mixedContent content ID or array with integer content ID and
  954. * array with content info, or false
  955. * @param $aParams array with additional custom params
  956. * which may overwrite some default values
  957. *
  958. * @see BxBaseModGeneralModule::serviceEntitySocialSharing
  959. */
  960. /**
  961. * @ref bx_base_general-entity_social_sharing "entity_social_sharing"
  962. */
  963. public function serviceEntitySocialSharing($mixedContent = false, $aParams = array())
  964. {
  965. if(!empty($mixedContent)) {
  966. if(!is_array($mixedContent))
  967. $mixedContent = array((int)$mixedContent, array());
  968. }
  969. else {
  970. $mixedContent = $this->_getContent();
  971. if($mixedContent === false)
  972. return false;
  973. }
  974. list($iContentId, $aContentInfo) = $mixedContent;
  975. $CNF = &$this->_oConfig->CNF;
  976. $sUri = !empty($aParams['uri']) ? $aParams['uri'] : '';
  977. if(empty($sUri) && !empty($CNF['URI_VIEW_ENTRY']))
  978. $sUri = $CNF['URI_VIEW_ENTRY'];
  979. $sUrl = !empty($sUri) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $iContentId) : '';
  980. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  981. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  982. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  983. $aMarkers = array(
  984. 'id' => $iContentId,
  985. 'module' => $this->_aModule['name'],
  986. 'url' => BX_DOL_URL_ROOT . $sUrl,
  987. 'title' => $sTitle,
  988. );
  989. $iIdThumb = !empty($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  990. if(empty($iIdThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  991. $iIdThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  992. if ($iIdThumb) {
  993. $sTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : '';
  994. $sStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : '';
  995. if(empty($sStorage) && !empty($CNF['OBJECT_STORAGE']))
  996. $sStorage = $CNF['OBJECT_STORAGE'];
  997. if(!empty($sTranscoder))
  998. $o = BxDolTranscoder::getObjectInstance($sTranscoder);
  999. else if(!empty($sStorage))
  1000. $o = BxDolStorage::getObjectInstance($sStorage);
  1001. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  1002. if($sImgUrl)
  1003. $aMarkers['img_url'] = $sImgUrl;
  1004. }
  1005. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  1006. $oMenu->addMarkers($aMarkers);
  1007. $sMenu = $oMenu->getCode();
  1008. if(empty($sMenu))
  1009. return '';
  1010. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  1011. 'menu' => $sMenu
  1012. ));
  1013. }
  1014. /**
  1015. * Entry context block
  1016. */
  1017. public function serviceEntityContext ($iContentId = 0)
  1018. {
  1019. return $this->_serviceTemplateFunc ('entryContext', $iContentId);
  1020. }
  1021. /**
  1022. * Blocks for lables tree browsing
  1023. */
  1024. public function serviceGetLablesTree()
  1025. {
  1026. $aBreadcrumbs = array();
  1027. $this->_getLablesBreadcrumbsArray(bx_get('label'), $aBreadcrumbs);
  1028. return $this->_getLablesTreeLevel($aBreadcrumbs);
  1029. }
  1030. public function serviceGetLablesBreadcrumbs()
  1031. {
  1032. if (bx_get('label')){
  1033. $aBreadcrumbs = array();
  1034. $this->_getLablesBreadcrumbsArray(bx_process_input(bx_get('label'), BX_DATA_INT), $aBreadcrumbs);
  1035. $aLabels = array();
  1036. foreach (array_reverse($aBreadcrumbs) as $aLabel){
  1037. $aLabels[] = array(
  1038. 'value' => $aLabel['value'],
  1039. 'url' => $this->_getLablesBrowseUrl($aLabel['id'])
  1040. );
  1041. }
  1042. return $this->_oTemplate->parseHtmlByName('labels_breadcrumbs.html', array('bx_repeat:items' => $aLabels));
  1043. }
  1044. return '';
  1045. }
  1046. public function serviceBrowseByLabel()
  1047. {
  1048. $CNF = &$this->_oConfig->CNF;
  1049. if (empty($CNF['OBJECT_METATAGS']))
  1050. return '';
  1051. $sMode = 'recent';
  1052. $sClassSearchResult ='SearchResult';
  1053. bx_import($sClassSearchResult, $this->_aModule['name']);
  1054. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1055. $o = new $sClass($sMode, false);
  1056. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  1057. $o->setDisplayEmptyMsg(true);
  1058. $o->setAjaxPaginate(false);
  1059. $o->setUnitParams(array('context' => $sMode));
  1060. if (bx_get('label')){
  1061. $iLabelId = (int)bx_get('label');
  1062. $oLabel = BxDolLabel::getInstance();
  1063. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  1064. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1065. $sTmp =$oMetatags->keywordsSetSearchCondition($o, $aLabel['value']);
  1066. }
  1067. if ($o->isError)
  1068. return '';
  1069. if ($s = $o->processing())
  1070. return $s;
  1071. else
  1072. return '';
  1073. }
  1074. /**
  1075. * Data for Notifications module
  1076. */
  1077. public function serviceGetNotificationsData()
  1078. {
  1079. $sModule = $this->_aModule['name'];
  1080. $sEventPrivacy = $sModule . '_allow_view_event_to';
  1081. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  1082. $sEventPrivacy = '';
  1083. $aResult = array(
  1084. 'handlers' => array(
  1085. 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),
  1086. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  1087. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  1088. 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),
  1089. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  1090. 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),
  1091. array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
  1092. 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),
  1093. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  1094. array('group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_reaction', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  1095. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  1096. array('group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  1097. array('group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  1098. ),
  1099. 'settings' => array(
  1100. array('group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => array('follow_member', 'follow_context')),
  1101. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  1102. array('group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => array('personal')),
  1103. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1104. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1105. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  1106. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  1107. ),
  1108. 'alerts' => array(
  1109. array('unit' => $sModule, 'action' => 'added'),
  1110. array('unit' => $sModule, 'action' => 'edited'),
  1111. array('unit' => $sModule, 'action' => 'deleted'),
  1112. array('unit' => $sModule, 'action' => 'commentPost'),
  1113. array('unit' => $sModule, 'action' => 'commentRemoved'),
  1114. array('unit' => $sModule, 'action' => 'replyPost'),
  1115. array('unit' => $sModule, 'action' => 'replyRemoved'),
  1116. array('unit' => $sModule, 'action' => 'doVote'),
  1117. array('unit' => $sModule, 'action' => 'undoVote'),
  1118. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  1119. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  1120. array('unit' => $sModule, 'action' => 'doVoteUp'),
  1121. array('unit' => $sModule, 'action' => 'doVoteDown'),
  1122. )
  1123. );
  1124. if(!empty($this->_oConfig->CNF['FIELDS_DELAYED_PROCESSING'])) {
  1125. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  1126. array('group' => $sModule . '_object_publish_failed', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'publish_failed', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_publish_failed', 'module_class' => 'Module', 'module_event_privacy' => ''),
  1127. array('group' => $sModule . '_object_publish_succeeded', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'publish_succeeded', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_publish_succeeded', 'module_class' => 'Module', 'module_event_privacy' => ''),
  1128. ));
  1129. $aResult['settings'] = array_merge($aResult['settings'], array(
  1130. array('group' => 'content_publish_failed', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => array('personal')),
  1131. array('group' => 'content_publish_succeeded', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => array('personal')),
  1132. ));
  1133. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  1134. array('unit' => $sModule, 'action' => 'publish_failed'),
  1135. array('unit' => $sModule, 'action' => 'publish_succeeded'),
  1136. ));
  1137. }
  1138. return $aResult;
  1139. }
  1140. /**
  1141. * Entry post for Notifications module
  1142. */
  1143. public function serviceGetNotificationsPost($aEvent)
  1144. {
  1145. $CNF = &$this->_oConfig->CNF;
  1146. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1147. if(empty($aContentInfo) || !is_array($aContentInfo))
  1148. return array();
  1149. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1150. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1151. return array(
  1152. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1153. 'entry_url' => $sEntryUrl,
  1154. 'entry_caption' => $sEntryCaption,
  1155. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1156. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  1157. 'lang_key' => '', //may be empty or not specified, or a string, or an array('site' => '...', 'email' => '...', 'push' => '...'). In this case of empty/not specified the default one from Notification module will be used.
  1158. /*
  1159. * Custom settings for email and/or push notifications can be provided here.
  1160. * Only necessary parts of 'settings' array can be used.
  1161. *
  1162. 'settings' => array(
  1163. 'email' => array(
  1164. 'template' => '', //--- custom email template
  1165. 'markers' => '', //--- markers to parse email parts (subject, body) with
  1166. 'subject' => '' //--- custom email subject
  1167. ),
  1168. 'push' => array(
  1169. 'subject' => '' //--- custom push notification subject
  1170. )
  1171. )
  1172. */
  1173. );
  1174. }
  1175. public function serviceGetNotificationsPostPublishFailed($aEvent)
  1176. {
  1177. return $this->serviceGetNotificationsPost($aEvent);
  1178. }
  1179. public function serviceGetNotificationsPostPublishSucceeded($aEvent)
  1180. {
  1181. return $this->serviceGetNotificationsPost($aEvent);
  1182. }
  1183. /**
  1184. * Entry post comment for Notifications module
  1185. */
  1186. public function serviceGetNotificationsComment($aEvent)
  1187. {
  1188. $CNF = &$this->_oConfig->CNF;
  1189. $iContentId = (int)$aEvent['object_id'];
  1190. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1191. if(empty($aContentInfo) || !is_array($aContentInfo))
  1192. return array();
  1193. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  1194. if(!$oComment || !$oComment->isEnabled())
  1195. return array();
  1196. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1197. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1198. return array(
  1199. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1200. 'entry_url' => $sEntryUrl,
  1201. 'entry_caption' => $sEntryCaption,
  1202. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1203. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1204. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1205. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1206. );
  1207. }
  1208. /**
  1209. * Entry post reply for Notifications module
  1210. */
  1211. public function serviceGetNotificationsReply($aEvent)
  1212. {
  1213. $CNF = &$this->_oConfig->CNF;
  1214. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  1215. if(!$oComment || !$oComment->isEnabled())
  1216. return array();
  1217. $iParentId = (int)$aEvent['object_id'];
  1218. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  1219. if(empty($aParentInfo) || !is_array($aParentInfo))
  1220. return array();
  1221. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  1222. $oComment->init($iObjectId);
  1223. return array(
  1224. 'object_id' => $iObjectId,
  1225. 'entry_sample' => '_cmt_txt_sample_comment_single',
  1226. 'entry_url' => $oComment->getViewUrl($iParentId),
  1227. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  1228. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  1229. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  1230. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1231. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1232. );
  1233. }
  1234. /**
  1235. * Entry post vote for Notifications module
  1236. */
  1237. public function serviceGetNotificationsVote($aEvent)
  1238. {
  1239. $CNF = &$this->_oConfig->CNF;
  1240. $iContentId = (int)$aEvent['object_id'];
  1241. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1242. if(empty($aContentInfo) || !is_array($aContentInfo))
  1243. return array();
  1244. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  1245. if(!$oVote || !$oVote->isEnabled())
  1246. return array();
  1247. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1248. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1249. return array(
  1250. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1251. 'entry_url' => $sEntryUrl,
  1252. 'entry_caption' => $sEntryCaption,
  1253. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1254. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1255. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1256. );
  1257. }
  1258. /**
  1259. * Entry post vote for Notifications module
  1260. */
  1261. public function serviceGetNotificationsReaction($aEvent)
  1262. {
  1263. $CNF = &$this->_oConfig->CNF;
  1264. $iContentId = (int)$aEvent['object_id'];
  1265. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1266. if(empty($aContentInfo) || !is_array($aContentInfo))
  1267. return array();
  1268. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContentId);
  1269. if(!$oReaction || !$oReaction->isEnabled())
  1270. return array();
  1271. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  1272. if(empty($aSubentry) || !is_array($aSubentry))
  1273. return array();
  1274. $aSubentrySampleParams = array();
  1275. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  1276. if(!empty($aReaction['title']))
  1277. $aSubentrySampleParams[] = $aReaction['title'];
  1278. else
  1279. $aSubentrySampleParams[] = '_undefined';
  1280. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1281. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1282. return array(
  1283. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1284. 'entry_url' => $sEntryUrl,
  1285. 'entry_caption' => $sEntryCaption,
  1286. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1287. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  1288. 'subentry_sample_params' => $aSubentrySampleParams,
  1289. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1290. );
  1291. }
  1292. /**
  1293. * Entry post score -> vote up for Notifications module
  1294. */
  1295. public function serviceGetNotificationsScoreUp($aEvent)
  1296. {
  1297. return $this->_serviceGetNotificationsScore('up', $aEvent);
  1298. }
  1299. /**
  1300. * Entry post score -> vote up for Notifications module
  1301. */
  1302. public function serviceGetNotificationsScoreDown($aEvent)
  1303. {
  1304. return $this->_serviceGetNotificationsScore('down', $aEvent);
  1305. }
  1306. protected function _serviceGetNotificationsScore($sType, $aEvent)
  1307. {
  1308. $CNF = &$this->_oConfig->CNF;
  1309. $iContentId = (int)$aEvent['object_id'];
  1310. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1311. if(empty($aContentInfo) || !is_array($aContentInfo))
  1312. return array();
  1313. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  1314. if(!$oScore || !$oScore->isEnabled())
  1315. return array();
  1316. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1317. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1318. return array(
  1319. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1320. 'entry_url' => $sEntryUrl,
  1321. 'entry_caption' => $sEntryCaption,
  1322. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1323. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  1324. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1325. );
  1326. }
  1327. /**
  1328. * Data for Timeline module
  1329. */
  1330. public function serviceGetTimelineData()
  1331. {
  1332. $sModule = $this->_aModule['name'];
  1333. return array(
  1334. 'handlers' => array(
  1335. 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' => ''),
  1336. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  1337. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  1338. ),
  1339. 'alerts' => array(
  1340. array('unit' => $sModule, 'action' => 'added'),
  1341. array('unit' => $sModule, 'action' => 'edited'),
  1342. array('unit' => $sModule, 'action' => 'deleted'),
  1343. )
  1344. );
  1345. }
  1346. /**
  1347. * Entry post for Timeline module
  1348. */
  1349. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  1350. {
  1351. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1352. if(empty($aContentInfo) || !is_array($aContentInfo))
  1353. return false;
  1354. $CNF = &$this->_oConfig->CNF;
  1355. if((!empty($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active') || (!empty($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active'))
  1356. return false;
  1357. $iUserId = $this->getUserId();
  1358. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1359. $iAuthorIdAbs = abs($iAuthorId);
  1360. if($iAuthorId < 0 && ((is_numeric($aEvent['owner_id']) && $iAuthorIdAbs == (int)$aEvent['owner_id']) || (is_array($aEvent['owner_id']) && in_array($iAuthorIdAbs, $aEvent['owner_id']))) && $iAuthorIdAbs != $iUserId)
  1361. return false;
  1362. //--- Views
  1363. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1364. $aViews = array();
  1365. if ($oViews && $oViews->isEnabled())
  1366. $aViews = array(
  1367. 'system' => $CNF['OBJECT_VIEWS'],
  1368. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1369. 'count' => $aContentInfo['views']
  1370. );
  1371. //--- Votes
  1372. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1373. $aVotes = array();
  1374. if ($oVotes && $oVotes->isEnabled())
  1375. $aVotes = array(
  1376. 'system' => $CNF['OBJECT_VOTES'],
  1377. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1378. 'count' => $aContentInfo['votes']
  1379. );
  1380. //--- Reactions
  1381. $oReactions = isset($CNF['OBJECT_REACTIONS']) ? BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1382. $aReactions = array();
  1383. if ($oReactions && $oReactions->isEnabled())
  1384. $aReactions = array(
  1385. 'system' => $CNF['OBJECT_REACTIONS'],
  1386. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1387. 'count' => $aContentInfo['rvotes']
  1388. );
  1389. //--- Scores
  1390. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1391. $aScores = array();
  1392. if ($oScores && $oScores->isEnabled())
  1393. $aScores = array(
  1394. 'system' => $CNF['OBJECT_SCORES'],
  1395. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1396. 'score' => $aContentInfo['score']
  1397. );
  1398. //--- Reports
  1399. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1400. $aReports = array();
  1401. if ($oReports && $oReports->isEnabled())
  1402. $aReports = array(
  1403. 'system' => $CNF['OBJECT_REPORTS'],
  1404. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1405. 'count' => $aContentInfo['reports']
  1406. );
  1407. //--- Comments
  1408. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1409. $aComments = array();
  1410. if($oCmts && $oCmts->isEnabled())
  1411. $aComments = array(
  1412. 'system' => $CNF['OBJECT_COMMENTS'],
  1413. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1414. 'count' => $aContentInfo['comments']
  1415. );
  1416. //--- Title & Description
  1417. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  1418. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  1419. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  1420. $iOwnerId = $iAuthorIdAbs;
  1421. if(isset($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0)
  1422. $iOwnerId = abs($aEvent['object_privacy_view']);
  1423. $bCache = true;
  1424. $aContent = $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  1425. if(isset($aContent['_cache'])) {
  1426. $bCache = (bool)$aContent['_cache'];
  1427. unset($aContent['_cache']);
  1428. }
  1429. return array(
  1430. '_cache' => $bCache,
  1431. 'owner_id' => $iOwnerId,
  1432. 'object_owner_id' => $iAuthorId,
  1433. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  1434. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1435. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1436. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1437. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  1438. 'content' => $aContent, //a string to display or array to parse default template before displaying.
  1439. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  1440. 'views' => $aViews,
  1441. 'votes' => $aVotes,
  1442. 'reactions' => $aReactions,
  1443. 'scores' => $aScores,
  1444. 'reports' => $aReports,
  1445. 'comments' => $aComments,
  1446. 'title' => $sTitle, //may be empty.
  1447. 'description' => '' //may be empty.
  1448. );
  1449. }
  1450. public function serviceGetTimelinePostAllowedView($aEvent)
  1451. {
  1452. $iContentId = (int)$aEvent['object_id'];
  1453. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1454. if(empty($aContentInfo) || !is_array($aContentInfo))
  1455. return _t('_sys_txt_access_denied');
  1456. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  1457. }
  1458. /**
  1459. * Check particular action permission without content
  1460. * @param $sAction action to check, for example: Browse, Add
  1461. * @param $iContentId content ID
  1462. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1463. */
  1464. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  1465. {
  1466. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1467. if (!method_exists($this, $sMethod))
  1468. return _t('_sys_request_method_not_found_cpt');
  1469. return $this->$sMethod($isPerformAction);
  1470. }
  1471. /**
  1472. * Check particular action permission with content
  1473. * @param $sAction action to check, for example: View, Edit
  1474. * @param $iContentId content ID
  1475. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1476. */
  1477. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  1478. {
  1479. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1480. return _t('_sys_request_page_not_found_cpt');
  1481. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1482. if (!method_exists($this, $sMethod))
  1483. return _t('_sys_request_method_not_found_cpt');
  1484. return $this->$sMethod($aContentInfo, $isPerformAction);
  1485. }
  1486. /**
  1487. * Check particular action permission with content for specified profile
  1488. * @param $sAction action to check, for example: View, Edit
  1489. * @param $iContentId content ID
  1490. * @param $iProfileId profile ID which the permissions to be cheked for
  1491. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1492. */
  1493. public function serviceCheckAllowedWithContentForProfile($sAction, $iContentId, $iProfileId, $isPerformAction = false)
  1494. {
  1495. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1496. return _t('_sys_request_page_not_found_cpt');
  1497. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction) . 'ForProfile';
  1498. if (!method_exists($this, $sMethod))
  1499. return _t('_sys_request_method_not_found_cpt');
  1500. return $this->$sMethod($aContentInfo, $iProfileId, $isPerformAction);
  1501. }
  1502. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  1503. {
  1504. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  1505. }
  1506. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  1507. {
  1508. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  1509. }
  1510. public function serviceGetContentOwnerProfileId ($iContentId)
  1511. {
  1512. $CNF = &$this->_oConfig->CNF;
  1513. // file owner must be author of the content or profile itself in case of profile based module
  1514. if ($iContentId) {
  1515. $sModule = $this->getName();
  1516. if ($this instanceof iBxDolProfileService && BxDolService::call($sModule, 'act_as_profile')) {
  1517. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1518. }
  1519. else {
  1520. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1521. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  1522. }
  1523. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  1524. }
  1525. else {
  1526. $iProfileId = bx_get_logged_profile_id();
  1527. }
  1528. return $iProfileId;
  1529. }
  1530. public function serviceGetBadges($iContentId, $bIsSingle = false, $bIsCompact = false)
  1531. {
  1532. $oBadges = BxDolBadges::getInstance();
  1533. $aBadges = $oBadges->getData(
  1534. array(
  1535. 'type' => ($bIsSingle ? 'by_module&object2_single' : 'by_module&object2'),
  1536. 'module' => $this->_aModule['name'],
  1537. 'object_id' => $iContentId
  1538. )
  1539. );
  1540. if ($bIsSingle && count($aBadges) > 0)
  1541. return BxDolService::call('system', 'get_badge', array($aBadges[0], $bIsCompact), 'TemplServices');
  1542. $aBadgesOutput = array();
  1543. foreach($aBadges as $aBadge) {
  1544. $aBadgesOutput[] = array('badge' => BxDolService::call('system', 'get_badge', array($aBadge, $bIsCompact), 'TemplServices'));
  1545. }
  1546. return $this->_oTemplate->parseHtmlByName('badges.html',
  1547. array(
  1548. 'bx_repeat:items' => $aBadgesOutput,
  1549. )
  1550. );
  1551. }
  1552. // ====== PERMISSION METHODS
  1553. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1554. {
  1555. if (!$iProfileId)
  1556. $iProfileId = $this->_iProfileId;
  1557. $CNF = &$this->_oConfig->CNF;
  1558. // moderator and owner always have access
  1559. if (!empty($iProfileId) && (abs($aDataEntry[$CNF['FIELD_AUTHOR']]) == (int)$iProfileId || $this->_isModerator($isPerformAction)))
  1560. return CHECK_ACTION_RESULT_ALLOWED;
  1561. // check ACL
  1562. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  1563. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1564. return $aCheck[CHECK_ACTION_MESSAGE];
  1565. // check privacy
  1566. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  1567. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  1568. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1569. return _t('_sys_access_denied_to_private_content');
  1570. }
  1571. // check alert to allow custom checks
  1572. $mixedResult = null;
  1573. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  1574. if($mixedResult !== null)
  1575. return $mixedResult;
  1576. return CHECK_ACTION_RESULT_ALLOWED;
  1577. }
  1578. public function checkAllowedSetThumb ($iContentId = 0)
  1579. {
  1580. return CHECK_ACTION_RESULT_ALLOWED;
  1581. }
  1582. /**
  1583. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1584. */
  1585. public function checkAllowedBrowse ()
  1586. {
  1587. // check alert to allow custom checks
  1588. $mixedResult = null;
  1589. bx_alert('system', 'check_allowed_browse', 0, 0, array('module' => $this->getName(), 'profile_id' => $this->_iProfileId, 'override_result' => &$mixedResult));
  1590. if($mixedResult !== null)
  1591. return $mixedResult;
  1592. return CHECK_ACTION_RESULT_ALLOWED;
  1593. }
  1594. /**
  1595. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1596. */
  1597. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1598. {
  1599. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  1600. }
  1601. /**
  1602. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1603. */
  1604. public function checkAllowedViewForProfile ($aDataEntry, $iProfileId, $isPerformAction = false)
  1605. {
  1606. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  1607. }
  1608. /**
  1609. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1610. */
  1611. public function checkAllowedAdd ($isPerformAction = false)
  1612. {
  1613. // check ACL
  1614. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  1615. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1616. return $aCheck[CHECK_ACTION_MESSAGE];
  1617. return CHECK_ACTION_RESULT_ALLOWED;
  1618. }
  1619. /**
  1620. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1621. */
  1622. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  1623. {
  1624. // moderator and owner always have access
  1625. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  1626. return CHECK_ACTION_RESULT_ALLOWED;
  1627. return _t('_sys_txt_access_denied');
  1628. }
  1629. /**
  1630. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1631. */
  1632. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  1633. {
  1634. // moderator always has access
  1635. if ($this->_isModerator($isPerformAction))
  1636. return CHECK_ACTION_RESULT_ALLOWED;
  1637. // check ACL
  1638. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  1639. 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)
  1640. return CHECK_ACTION_RESULT_ALLOWED;
  1641. return _t('_sys_txt_access_denied');
  1642. }
  1643. /**
  1644. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1645. */
  1646. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  1647. {
  1648. // admin always has access
  1649. if (isAdmin())
  1650. return CHECK_ACTION_RESULT_ALLOWED;
  1651. // check ACL
  1652. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  1653. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1654. return $aCheck[CHECK_ACTION_MESSAGE];
  1655. return CHECK_ACTION_RESULT_ALLOWED;
  1656. }
  1657. /**
  1658. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1659. */
  1660. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  1661. {
  1662. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  1663. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  1664. return CHECK_ACTION_RESULT_ALLOWED;
  1665. return _t('_sys_txt_access_denied');
  1666. }
  1667. /**
  1668. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1669. */
  1670. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  1671. {
  1672. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  1673. }
  1674. /**
  1675. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1676. */
  1677. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  1678. {
  1679. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  1680. }
  1681. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  1682. {
  1683. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  1684. return MsgBox($sMsg);
  1685. bx_import($sClassSearchResult, $this->_aModule);
  1686. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1687. $o = new $sClass($sMode, $aParams);
  1688. $o->setDesignBoxTemplateId($iDesignBox);
  1689. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  1690. $o->setAjaxPaginate($bAjaxPaginate);
  1691. $o->setUnitParams(array('context' => $sMode));
  1692. if ($o->isError)
  1693. return '';
  1694. if ($s = $o->processing())
  1695. return $s;
  1696. else
  1697. return '';
  1698. }
  1699. // ====== COMMON METHODS
  1700. public function alertAfterAdd($aContentInfo) {}
  1701. public function alertAfterEdit($aContentInfo) {}
  1702. public function onPublished($iContentId) {}
  1703. public function onFailed($iContentId) {}
  1704. public function processMetasAdd($iContentId)
  1705. {
  1706. $CNF = &$this->_oConfig->CNF;
  1707. if(empty($CNF['OBJECT_METATAGS']))
  1708. return;
  1709. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1710. $bFldStatus = isset($CNF['FIELD_STATUS']);
  1711. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  1712. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  1713. if(!$bContentInfo)
  1714. return;
  1715. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1716. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  1717. $sKey = 'FIELD_LOCATION';
  1718. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1719. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  1720. if(!empty($aLocation) && is_array($aLocation))
  1721. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  1722. }
  1723. $sKey = 'FIELD_LABELS';
  1724. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1725. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  1726. if(!empty($aLabels) && is_array($aLabels))
  1727. foreach ($aLabels as $sLabel)
  1728. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  1729. }
  1730. }
  1731. public function processMetasEdit($iContentId, $oForm)
  1732. {
  1733. $CNF = &$this->_oConfig->CNF;
  1734. if(empty($CNF['OBJECT_METATAGS']))
  1735. return;
  1736. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1737. $bFldStatus = isset($CNF['FIELD_STATUS']);
  1738. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  1739. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  1740. if(!$bContentInfo)
  1741. return;
  1742. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1743. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']);
  1744. $sKey = 'FIELD_LOCATION';
  1745. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1746. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  1747. if(!empty($aLocation) && is_array($aLocation))
  1748. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  1749. }
  1750. $sKey = 'FIELD_LABELS';
  1751. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1752. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  1753. if(!empty($aLabels) && is_array($aLabels))
  1754. foreach ($aLabels as $sLabel)
  1755. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  1756. }
  1757. }
  1758. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  1759. {
  1760. if(empty($aTranscoders))
  1761. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  1762. $CNF = &$this->_oConfig->CNF;
  1763. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  1764. return false;
  1765. $iId = (int)$aContentInfo[$CNF[$sField]];
  1766. foreach($aTranscoders as $sTranscoder)
  1767. if(!empty($CNF[$sTranscoder]))
  1768. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  1769. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  1770. }
  1771. public function getProfileId()
  1772. {
  1773. return bx_get_logged_profile_id();
  1774. }
  1775. public function getProfileInfo($iUserId = 0)
  1776. {
  1777. $oProfile = $this->getObjectUser($iUserId);
  1778. $oAccount = null;
  1779. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  1780. $oAccount = $oProfile->getAccountObject();
  1781. $bAccount = !empty($oAccount);
  1782. return array(
  1783. 'id' => $oProfile->id(),
  1784. 'name' => $oProfile->getDisplayName(),
  1785. 'email' => $bAccount ? $oAccount->getEmail() : '',
  1786. 'link' => $oProfile->getUrl(),
  1787. 'icon' => $oProfile->getIcon(),
  1788. 'thumb' => $oProfile->getThumb(),
  1789. 'avatar' => $oProfile->getAvatar(),
  1790. 'unit' => $oProfile->getUnit(),
  1791. 'active' => $oProfile->isActive(),
  1792. );
  1793. }
  1794. public function getObjectUser($iUserId = 0)
  1795. {
  1796. bx_import('BxDolProfile');
  1797. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1798. return $oProfile;
  1799. }
  1800. public function getObjectFavorite($sSystem = '', $iId = 0)
  1801. {
  1802. $CNF = &$this->_oConfig->CNF;
  1803. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  1804. $sSystem = $CNF['OBJECT_FAVORITES'];
  1805. if(empty($sSystem))
  1806. return false;
  1807. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1808. if(!$oFavorite || !$oFavorite->isEnabled())
  1809. return false;
  1810. return $oFavorite;
  1811. }
  1812. public function getUserId()
  1813. {
  1814. return isLogged() ? bx_get_logged_profile_id() : 0;
  1815. }
  1816. public function getUserIp()
  1817. {
  1818. return getVisitorIP();
  1819. }
  1820. public function getUserInfo($iUserId = 0)
  1821. {
  1822. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1823. return array(
  1824. $oProfile->getDisplayName(),
  1825. $oProfile->getUrl(),
  1826. $oProfile->getThumb(),
  1827. $oProfile->getUnit(),
  1828. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  1829. );
  1830. }
  1831. public function getUserInfoWithBadges($iUserId = 0)
  1832. {
  1833. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1834. return array(
  1835. $oProfile->getDisplayName(),
  1836. $oProfile->getUrl(),
  1837. $oProfile->getThumb(),
  1838. $oProfile->getUnit(),
  1839. $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  1840. $oProfile->getBadges()
  1841. );
  1842. }
  1843. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  1844. {
  1845. $CNF = &$this->_oConfig->CNF;
  1846. // default visible settings
  1847. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  1848. return false;
  1849. if (!empty($aItem['visibility_custom'])) {
  1850. $oMenu = BxDolMenu::getObjectInstance($sObject);
  1851. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $oMenu->getMarkers()))
  1852. return false;
  1853. }
  1854. // get custom function name to check menu item visibility
  1855. $sFuncCheckAccess = false;
  1856. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  1857. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  1858. // check custom visibility settings defined in module config class
  1859. if(!isset($aContentInfo))
  1860. $aContentInfo = array();
  1861. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), array(&$aContentInfo)))
  1862. return false;
  1863. return true;
  1864. }
  1865. public function _isModerator ($isPerformAction = false)
  1866. {
  1867. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
  1868. }
  1869. public function _prepareAuditParams($aContentInfo, $bIsSaveData = true, $aOverrideAuditParams = array())
  1870. {
  1871. $CNF = &$this->_oConfig->CNF;
  1872. $iContextId = isset($CNF['FIELD_ALLOW_VIEW_TO']) && (!empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) ? - $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] : 0;
  1873. $AuditParams = array(
  1874. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  1875. 'context_profile_id' => $iContextId,
  1876. 'content_info_object' => isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
  1877. 'data' => ($bIsSaveData ? $aContentInfo : array())
  1878. );
  1879. if ($iContextId > 0)
  1880. $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
  1881. $AuditParams = array_merge($AuditParams, $aOverrideAuditParams);
  1882. return $AuditParams;
  1883. }
  1884. // ====== PROTECTED METHODS
  1885. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  1886. {
  1887. $iContentId = $this->_getContent($iContentId, false);
  1888. if($iContentId === false)
  1889. return false;
  1890. bx_import('FormsEntryHelper', $this->_aModule);
  1891. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  1892. $oFormsHelper = new $sClass($this);
  1893. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  1894. }
  1895. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  1896. {
  1897. $mixedContent = $this->_getContent($iContentId, $sFuncGetContent);
  1898. if($mixedContent === false)
  1899. return false;
  1900. list($iContentId, $aContentInfo) = $mixedContent;
  1901. return $this->_oTemplate->$sFunc($aContentInfo);
  1902. }
  1903. protected function _rss ($aArgs, $sClass = 'SearchResult')
  1904. {
  1905. $sMode = array_shift($aArgs);
  1906. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  1907. $this->_oTemplate->displayAccessDenied ($sMsg);
  1908. exit;
  1909. }
  1910. $aParams = $this->_buildRssParams($sMode, $aArgs);
  1911. bx_import ($sClass, $this->_aModule);
  1912. $sClass = $this->_aModule['class_prefix'] . $sClass;
  1913. $o = new $sClass($sMode, $aParams);
  1914. if ($o->isError)
  1915. $this->_oTemplate->displayPageNotFound ();
  1916. else
  1917. $o->outputRSS();
  1918. exit;
  1919. }
  1920. protected function _getContent($iContentId = 0, $sFuncGetContent = true)
  1921. {
  1922. if(!$iContentId)
  1923. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1924. if(!$iContentId)
  1925. return false;
  1926. if($sFuncGetContent === true)
  1927. $sFuncGetContent = 'getContentInfoById';
  1928. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  1929. return $iContentId;
  1930. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  1931. if(!$aContentInfo)
  1932. return false;
  1933. return array($iContentId, $aContentInfo);
  1934. }
  1935. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  1936. {
  1937. $CNF = &$this->_oConfig->CNF;
  1938. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1939. //--- Image(s)
  1940. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1941. $aImagesAttach = $this->_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1942. //--- Video(s)
  1943. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1944. $aVideosAttach = $this->_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1945. //--- Files(s)
  1946. $aFiles = $this->_getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1947. $aFilesAttach = $this->_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1948. //--- Title
  1949. $sTitle = '';
  1950. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  1951. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  1952. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  1953. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1954. //--- Text
  1955. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  1956. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  1957. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1958. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  1959. }
  1960. return array(
  1961. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1962. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1963. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1964. 'url' => $sUrl,
  1965. 'title' => $sTitle,
  1966. 'text' => $sText,
  1967. 'images' => $aImages,
  1968. 'images_attach' => $aImagesAttach,
  1969. 'videos' => $aVideos,
  1970. 'videos_attach' => $aVideosAttach,
  1971. 'files' => $aFiles,
  1972. 'files_attach' => $aFilesAttach
  1973. );
  1974. }
  1975. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1976. {
  1977. $CNF = &$this->_oConfig->CNF;
  1978. $sImage = $sImageOrig = '';
  1979. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
  1980. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  1981. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  1982. }
  1983. $bImageThumb = isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']];
  1984. if($sImage == '' && $bImageThumb)
  1985. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  1986. if($sImageOrig == '' && $bImageThumb)
  1987. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  1988. if(empty($sImage))
  1989. return array();
  1990. if($sImageOrig == '')
  1991. $sImageOrig = $sImage;
  1992. return array(
  1993. array('id' => $aContentInfo[$CNF['FIELD_THUMB']], 'url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
  1994. );
  1995. }
  1996. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1997. {
  1998. return array();
  1999. }
  2000. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2001. {
  2002. return array();
  2003. }
  2004. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2005. {
  2006. return array();
  2007. }
  2008. protected function _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2009. {
  2010. return array();
  2011. }
  2012. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2013. {
  2014. return array();
  2015. }
  2016. protected function _entityComments ($sObject, $iId = 0)
  2017. {
  2018. if (!$iId)
  2019. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2020. if (!$iId)
  2021. return false;
  2022. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  2023. if (!$oCmts || !$oCmts->isEnabled())
  2024. return false;
  2025. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  2026. }
  2027. protected function _getFields($iContentId)
  2028. {
  2029. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2030. if(empty($aContentInfo))
  2031. return array();
  2032. return BxDolContentInfo::formatFields($aContentInfo);
  2033. }
  2034. protected function _getFieldValue($sField, $iContentId)
  2035. {
  2036. $CNF = &$this->_oConfig->CNF;
  2037. if(empty($CNF[$sField]))
  2038. return false;
  2039. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2040. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  2041. return false;
  2042. return $aContentInfo[$CNF[$sField]];
  2043. }
  2044. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  2045. {
  2046. $CNF = &$this->_oConfig->CNF;
  2047. if(empty($sTranscoder) || empty($CNF[$sField]))
  2048. return false;
  2049. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2050. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  2051. return false;
  2052. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  2053. if(!$oImagesTranscoder)
  2054. return false;
  2055. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  2056. }
  2057. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  2058. {
  2059. if(!$bAsJson)
  2060. return $aResponse;
  2061. if(!empty($aAdditional) && is_array($aAdditional))
  2062. $aResponse = array_merge($aResponse, $aAdditional);
  2063. echoJson($aResponse);
  2064. exit;
  2065. }
  2066. /**
  2067. * Blocks for lables tree browsing private functions
  2068. */
  2069. private function _getLablesBreadcrumbsArray($iLabelId, &$aBreadcrumbs)
  2070. {
  2071. $oLabel = BxDolLabel::getInstance();
  2072. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  2073. if ($aLabel){
  2074. $aBreadcrumbs[$aLabel['id']] = array('id' => $aLabel['id'], 'value' => $aLabel['value']);
  2075. $this->_getLablesBreadcrumbsArray($aLabel['parent'], $aBreadcrumbs);
  2076. }
  2077. }
  2078. private function _getLablesBrowseUrl($iLabelId)
  2079. {
  2080. list($sPageLink, $aPageParams) = bx_get_base_url_inline();
  2081. return BxDolPermalinks::getInstance()->permalink(bx_append_url_params($sPageLink, array_merge($aPageParams, array('label' => $iLabelId))));
  2082. }
  2083. private function _getLablesTreeLevel($aBreadcrumbs, $iParent = 0)
  2084. {
  2085. $oLabel = BxDolLabel::getInstance();
  2086. $aLabelsOutput = array();
  2087. $aLabels = $oLabel->getLabels(array('type' => 'parent', 'parent' => $iParent));
  2088. if (count($aLabels) > 0){
  2089. foreach($aLabels as $aLabel) {
  2090. $sChild = $this->_getLablesTreeLevel($aBreadcrumbs, $aLabel['id']);
  2091. $bChildPresent = $sChild != '' ? true : false;
  2092. $bIsOpen = array_key_exists($aLabel['id'], $aBreadcrumbs) ? true : false;
  2093. if (!$bIsOpen){
  2094. $sChild = '';
  2095. }
  2096. $aLabelsOutput[] = array(
  2097. 'value' => $aLabel['value'],
  2098. 'url' => $this->_getLablesBrowseUrl($aLabel['id']),
  2099. 'child' => $sChild,
  2100. 'selected' => bx_process_input(bx_get('label'), BX_DATA_INT) == $aLabel['id'] ? 'selected' : ''.$aLabel['id'],
  2101. 'bx_if:open' => array(
  2102. 'condition' => $bChildPresent && $bIsOpen,
  2103. 'content' => array()
  2104. ),
  2105. 'bx_if:can_open' => array(
  2106. 'condition' => $bChildPresent && !$bIsOpen,
  2107. 'content' => array()
  2108. )
  2109. );
  2110. }
  2111. return $this->_oTemplate->parseHtmlByName('labels_tree.html',
  2112. array(
  2113. 'bx_repeat:items' => $aLabelsOutput,
  2114. 'parent' => $iParent,
  2115. )
  2116. );
  2117. }
  2118. return '';
  2119. }
  2120. }
  2121. /** @} */