1
0

BxBaseModGeneralModule.php 97 KB

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