1
0

BxBaseModGeneralModule.php 136 KB

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