BxBaseModGeneralModule.php 99 KB

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