BxBaseModGeneralModule.php 117 KB

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