BxBaseModGeneralModule.php 176 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521
  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 $_bIsApi;
  21. protected $_iProfileId;
  22. protected $_aSearchableNamesExcept;
  23. protected $_aFormParams;
  24. protected $_aBrowsingFiltersKeys;
  25. function __construct(&$aModule)
  26. {
  27. parent::__construct($aModule);
  28. $this->_bIsApi = bx_is_api();
  29. $this->_iProfileId = bx_get_logged_profile_id();
  30. $this->_aSearchableNamesExcept = array(
  31. 'allow_view_to'
  32. );
  33. $this->_aFormParams = array(
  34. 'display' => false,
  35. 'dynamic_mode' => false,
  36. 'ajax_mode' => false,
  37. 'absolute_action_url' => false,
  38. 'visibility_autoselect' => false,
  39. 'context_id' => 0,
  40. 'custom' => array()
  41. );
  42. $this->_aBrowsingFiltersKeys = ['mode'];
  43. }
  44. // ====== ACTIONS METHODS
  45. public function isEntryActive($aContentInfo)
  46. {
  47. $CNF = &$this->_oConfig->CNF;
  48. $iProfileId = bx_get_logged_profile_id();
  49. $bModerator = $this->_isModerator();
  50. $mixedResult = null;
  51. /**
  52. * @hooks
  53. * @hookdef hook-bx_base_general-is_entry_active '{module_name}', 'is_entry_active' - hook to override whether an entry (content) active or not
  54. * - $unit_name - module name
  55. * - $action - equals `is_entry_active`
  56. * - $object_id - not used
  57. * - $sender_id - not used
  58. * - $extra_params - array of additional params with the following array keys:
  59. * - `viewer_id` - [int] viewer profile id
  60. * - `is_moderator` - [boolean] is viewer has moderator status or not
  61. * - `content_info` - [array] content info array as key&value pairs
  62. * - `override_result` - [boolean] by ref, boolean value which determines whether entry (content) active or not, can be overridden in hook processing
  63. * @hook @ref hook-bx_base_general-is_entry_active
  64. */
  65. bx_alert($this->getName(), 'is_entry_active', 0, 0, [
  66. 'viewer_id' => $iProfileId,
  67. 'is_moderator' => $bModerator,
  68. 'content_info' => $aContentInfo,
  69. 'override_result' => &$mixedResult
  70. ]);
  71. if($mixedResult !== null)
  72. return $mixedResult;
  73. if($this->isEntryAuthor($aContentInfo, $iProfileId) || $bModerator)
  74. return true;
  75. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  76. $iContextProfileId = abs((int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  77. $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
  78. $aAdmins = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
  79. if(!empty($aAdmins) && in_array($iProfileId, $aAdmins))
  80. return true;
  81. }
  82. if(isset($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active')
  83. return false;
  84. if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active')
  85. return false;
  86. return true;
  87. }
  88. public function isEntryAuthor($aContentInfo, $iProfileId = 0)
  89. {
  90. $CNF = &$this->_oConfig->CNF;
  91. if(!$iProfileId)
  92. $iProfileId = bx_get_logged_profile_id();
  93. $mixedResult = null;
  94. /**
  95. * @hooks
  96. * @hookdef hook-bx_base_general-is_entry_author '{module_name}', 'is_entry_author' - hook to check if a viewer is an author of viewed entry (content) or not
  97. * - $unit_name - module name
  98. * - $action - equals `is_entry_author`
  99. * - $object_id - not used
  100. * - $sender_id - not used
  101. * - $extra_params - array of additional params with the following array keys:
  102. * - `viewer_id` - [int] viewer profile id
  103. * - `content_info` - [array] content info array as key&value pairs
  104. * - `override_result` - [boolean] by ref, boolean value which determines whether the viewer is an author of viewed entry (content) or not, can be overridden in hook processing
  105. * @hook @ref hook-bx_base_general-is_entry_author
  106. */
  107. bx_alert($this->getName(), 'is_entry_author', 0, 0, [
  108. 'viewer_id' => $iProfileId,
  109. 'content_info' => $aContentInfo,
  110. 'override_result' => &$mixedResult
  111. ]);
  112. if($mixedResult !== null)
  113. return $mixedResult;
  114. return abs($aContentInfo[$CNF['FIELD_AUTHOR']]) == $iProfileId;
  115. }
  116. public function actionUpdateImage($sFiledName, $iContentId, $sValue)
  117. {
  118. $mixedResult = $this->serviceUpdateImage($sFiledName, $iContentId, $sValue);
  119. if($mixedResult !== false)
  120. echo $mixedResult;
  121. }
  122. public function actionUpdateImagePosition($iContentId, $sFiledName, $sH, $sV)
  123. {
  124. $this->serviceUpdateImagePosition($iContentId, $sFiledName, $sH, $sV);
  125. }
  126. public function actionApprove()
  127. {
  128. $CNF = &$this->_oConfig->CNF;
  129. if(!isset($CNF['FIELD_STATUS_ADMIN']))
  130. return echoJson([]);
  131. $iContentId = (int)bx_get('content_id');
  132. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  133. if(empty($aContentInfo) || !is_array($aContentInfo) || $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_GENERAL_STATUS_PENDING)
  134. return echoJson([]);
  135. if(($mixedCheckResult = $this->checkAllowedApprove($aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
  136. return echoJson(['msg' => $mixedCheckResult]);
  137. $oForm = $this->_getApproveForm($iContentId, $aContentInfo);
  138. $oForm->initChecker();
  139. if(!$oForm->isSubmitted() || !$oForm->isValid()) {
  140. $sPopupId = $this->getName() . '_approve_' . $iContentId;
  141. $sPopupTitle = '_sys_manage_popup_approve_title';
  142. if(!empty($CNF['T']['txt_approve_popup_title']))
  143. $sPopupTitle = $CNF['T']['txt_approve_popup_title'];
  144. return echoJson(['popup' => BxTemplFunctions::getInstance()->popupBox($sPopupId, _t($sPopupTitle), $oForm->getCode(true))]);
  145. }
  146. if($oForm->getCleanValue('do_send')) {
  147. $aResult = [];
  148. if($this->_sendApproveMessage($iContentId, $aContentInfo, $oForm))
  149. $aResult = ['msg' => _t('_sys_manage_txt_sent')];
  150. else
  151. $aResult = ['msg' => _t('_sys_manage_err_cannot_perform_action')];
  152. return echoJson($aResult);
  153. }
  154. if($oForm->getCleanValue('do_submit')) {
  155. $aResult = [];
  156. if($this->_oDb->updateEntriesBy([$CNF['FIELD_STATUS_ADMIN'] => BX_BASE_MOD_GENERAL_STATUS_ACTIVE], [$CNF['FIELD_ID'] => $iContentId])) {
  157. $this->checkAllowedApprove($aContentInfo, true);
  158. $this->onApprove($aContentInfo);
  159. /*
  160. * Process metas.
  161. * Note. It's essential to process metas a the very end,
  162. * because all data related to an entry should be already
  163. * processed and are ready to be passed to alert.
  164. */
  165. $this->processMetasAdd($iContentId);
  166. $aResult = ['msg' => _t('_sys_manage_txt_approved'), 'reload' => 1];
  167. }
  168. else
  169. $aResult = ['msg' => _t('_sys_manage_err_cannot_perform_action')];
  170. return echoJson($aResult);
  171. }
  172. }
  173. public function serviceSetStatus($iId, $sValue, $sStatus = '')
  174. {
  175. $CNF = &$this->_oConfig->CNF;
  176. if(!$sStatus && !empty($CNF['FIELD_STATUS_ADMIN']))
  177. $sStatus = $CNF['FIELD_STATUS_ADMIN'];
  178. $aStatuses = [];
  179. if(!empty($CNF['FIELD_STATUS_ADMIN']))
  180. $aStatuses[] = $CNF['FIELD_STATUS_ADMIN'];
  181. if(!empty($CNF['FIELD_STATUS']))
  182. $aStatuses[] = $CNF['FIELD_STATUS'];
  183. if(!in_array($sStatus, $aStatuses))
  184. return false;
  185. if((int)$this->_oDb->updateEntriesBy([$sStatus => $sValue], [$CNF['FIELD_ID'] => $iId]) == 0)
  186. return false;
  187. if($sValue == BX_BASE_MOD_GENERAL_STATUS_ACTIVE)
  188. $this->onPublished($iId);
  189. }
  190. public function actionRss ()
  191. {
  192. $aArgs = func_get_args();
  193. $this->_rss($aArgs);
  194. }
  195. public function actionGetAttachLinkForm()
  196. {
  197. $CNF = &$this->_oConfig->CNF;
  198. $iContentId = ($iContentId = bx_get($CNF['FIELD_ATTACH_LINK_CONTENT_ID'])) !== false ? (int)$iContentId : 0;
  199. echo $this->_oTemplate->getAttachLinkForm($iContentId);
  200. }
  201. public function actionSubmitAttachLinkForm()
  202. {
  203. echoJson($this->getFormAttachLink());
  204. }
  205. public function actionAddAttachLink()
  206. {
  207. $CNF = &$this->_oConfig->CNF;
  208. $sUrl = bx_process_input(bx_get($CNF['FIELD_ATTACH_LINK_URL']));
  209. if(empty($sUrl))
  210. return echoJson([]);
  211. $sUrl = htmlspecialchars_decode($sUrl);
  212. $oStreamContext = stream_context_create([
  213. 'http' => [
  214. 'timeout' => getParam('sys_default_socket_timeout'),
  215. ]
  216. ]);
  217. $sHeader = 'Content-Type';
  218. $aHeaders = @get_headers($sUrl, 1, $oStreamContext);
  219. if(!empty($aHeaders) && is_array($aHeaders) && !empty($aHeaders[$sHeader])) {
  220. $mixedContentType = $aHeaders[$sHeader];
  221. if(!is_array($mixedContentType))
  222. $mixedContentType = [$mixedContentType];
  223. foreach($mixedContentType as $sContentType)
  224. if(strpos($sContentType, 'image') !== false)
  225. return echoJson([]);
  226. }
  227. echoJson($this->addAttachLink([
  228. $CNF['FIELD_ATTACH_LINK_CONTENT_ID'] => ($iContentId = bx_get($CNF['FIELD_ATTACH_LINK_CONTENT_ID'])) !== false ? (int)$iContentId : 0,
  229. $CNF['FIELD_ATTACH_LINK_URL'] => $sUrl
  230. ]));
  231. }
  232. public function actionDeleteAttachLink()
  233. {
  234. $CNF = &$this->_oConfig->CNF;
  235. $iUserId = $this->getUserId();
  236. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  237. if(empty($iLinkId))
  238. return echoJson([]);
  239. $aLink = $this->_oDb->getLinksBy(['type' => 'id', 'id' => $iLinkId, 'profile_id' => $iUserId]);
  240. if(empty($aLink) || !is_array($aLink))
  241. return echoJson([]);
  242. if(!empty($aLink['media_id']))
  243. BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS'])->deleteFile($aLink['media_id']);
  244. $aResult = [];
  245. if($this->_oDb->deleteLink($iLinkId))
  246. $aResult = ['code' => 0, 'url' => $aLink['url']];
  247. else
  248. $aResult = ['code' => 1, 'message' => _t(!empty($CNF['txt_link_form_err_delete']) ? $CNF['txt_link_form_err_delete'] : $this->getName() . '_form_post_input_link_err_delete')];
  249. echoJson($aResult);
  250. }
  251. public function actionGetCreatePostForm()
  252. {
  253. $sName = $this->_oConfig->getName();
  254. $aParams = bx_process_input(array_intersect_key($_GET, $this->_aFormParams));
  255. $aParams = array_merge($this->_aFormParams, $aParams);
  256. $aParams['context_id'] = (bool)$aParams['context_id'] ? (int)$aParams['context_id'] : false;
  257. $mixedResponse = $this->serviceGetCreatePostForm($aParams);
  258. if(empty($mixedResponse))
  259. return echoJson(array());
  260. else if(is_array($mixedResponse)) {
  261. $mixedResponse['module'] = $sName;
  262. return echoJson($mixedResponse);
  263. }
  264. return echoJson(array(
  265. 'module' => $sName,
  266. 'content' => $mixedResponse
  267. ));
  268. }
  269. public function actionGetNotes()
  270. {
  271. $CNF = &$this->_oConfig->CNF;
  272. if(empty($CNF['OBJECT_NOTES']))
  273. return echoJson([]);
  274. $iContentId = (int)bx_get('content_id');
  275. $oCmtsNotes = BxDolCmts::getObjectInstance($CNF['OBJECT_NOTES'], $iContentId, true, $this->_oTemplate);
  276. $aCmtsNotes = $oCmtsNotes->getCommentsBlock([], ['in_designbox' => false]);
  277. if(empty($aCmtsNotes) || !is_array($aCmtsNotes))
  278. return echoJson([]);
  279. $sPostfix = $iContentId < 0 ? '_rc' : '';
  280. $sPopupId = $this->getName() . '_notes_' . $iContentId;
  281. $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;
  282. echoJson(['popup' => BxTemplFunctions::getInstance()->popupBox($sPopupId, _t($sPopupTitle), $aCmtsNotes['content'])]);
  283. }
  284. public function actionNested()
  285. {
  286. $sAction = bx_get('a');
  287. $sMethodName = 'subaction' . ucfirst($sAction);
  288. if (!method_exists($this, $sMethodName)) {
  289. return;
  290. }
  291. $this->$sMethodName();
  292. }
  293. public function actionEmbed($iContentId, $sUnitTemplate = '', $sAddCode = '')
  294. {
  295. $oTemplate = BxDolTemplate::getInstance();
  296. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  297. if(empty($aContentInfo))
  298. $oTemplate->getEmbed(false);
  299. if(empty($sUnitTemplate))
  300. $sUnitTemplate = 'unit_gallery.html';
  301. $CNF = &$this->_oConfig->CNF;
  302. if(!empty($CNF['OBJECT_VIEWS'])) {
  303. $oView = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId);
  304. if($oView && $oView->isEnabled())
  305. $oView->doView();
  306. }
  307. $oTemplate->getEmbed($this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate) . $sAddCode);
  308. }
  309. public function subactionDelete()
  310. {
  311. header('Content-type: text/html; charset=utf-8');
  312. $iNestedId = (int)bx_get('id');
  313. $sNestedForm = bx_get('s');
  314. $oForm = BxDolForm::getObjectInstance($sNestedForm, $sNestedForm);
  315. if (!$oForm){
  316. echo _t('_sys_request_page_not_found_cpt');
  317. return;
  318. }
  319. $aNested = $this->_oDb->getNestedBy(array('type' => 'id', 'id' => $iNestedId, 'key_name' => $oForm->aParams['db']['key']), $oForm->aParams['db']['table']);
  320. if (empty($aNested)){
  321. echo _t('_sys_request_page_not_found_cpt');
  322. return;
  323. }
  324. $aContentInfo = $this->_oDb->getContentInfoById ($aNested['content_id']);
  325. if (!$aContentInfo){
  326. echo _t('_sys_request_page_not_found_cpt');
  327. return;
  328. }
  329. elseif (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedEdit ($aContentInfo))) {
  330. echo $sMsg;
  331. }
  332. elseif (!$this->_oDb->deleteNestedById($iNestedId, $oForm->aParams['db']['key'], $oForm->aParams['db']['table'])) {
  333. echo _t('_sys_txt_error_occured');
  334. }
  335. else {
  336. echo 'ok';
  337. }
  338. }
  339. /**
  340. * Get possible recipients for start conversation form
  341. */
  342. public function actionAjaxGetProfiles ()
  343. {
  344. $sTerm = bx_get('term');
  345. $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  346. header('Content-Type:text/javascript; charset=utf-8');
  347. echo(json_encode($a));
  348. }
  349. public function serviceGetProfiles ($sParams)
  350. {
  351. $aOptions = json_decode($sParams, true);
  352. if (!$sParams || !isset($aOptions['term']))
  353. return [];
  354. return BxDolService::call('system', 'profiles_search', array($aOptions['term']), 'TemplServiceProfiles');
  355. }
  356. public function actionGetBrowsingFilters()
  357. {
  358. $aParams = $this->_prepareBrowsingFiltersParamsGet();
  359. $sContent = $this->_oTemplate->getBrowsingFilters($aParams);
  360. if(empty($sContent))
  361. return echoJson([]);
  362. echoJson([
  363. 'code' => 0,
  364. 'popup' => [
  365. 'html' => $sContent,
  366. 'options' => [
  367. 'closeOnOuterClick' => false,
  368. 'removeOnClose' => false,
  369. ]
  370. ],
  371. ]);
  372. }
  373. public function actionApplyBrowsingFilters()
  374. {
  375. $aParams = $this->_prepareBrowsingFiltersParamsGet();
  376. $aBrowseParams = ['mode' => $aParams['mode'], 'empty_message' => true];
  377. unset($aParams['mode']);
  378. $aBrowseParams['params'] = $aParams;
  379. $mixedResult = $this->serviceBrowse($aBrowseParams);
  380. if(empty($mixedResult))
  381. return echoJson([]);
  382. if(is_array($mixedResult) && isset($mixedResult['content']))
  383. $mixedResult = $mixedResult['content'];
  384. return echoJson([
  385. 'code' => 0,
  386. 'content' => $mixedResult,
  387. 'eval' => $this->_oConfig->getJsObject('main') . '.onApplyBrowsingFilter(oData)'
  388. ]);
  389. }
  390. protected function _prepareBrowsingFiltersParamsGet($mParams = false)
  391. {
  392. $aParams = [];
  393. $bParams = !empty($mParams) && is_array($mParams);
  394. foreach($this->_aBrowsingFiltersKeys as $sKey)
  395. if($bParams) {
  396. if(isset($mParams[$sKey]))
  397. $aParams[$sKey] = $mParams[$sKey];
  398. }
  399. else {
  400. if(($sValue = bx_get($sKey)) !== false)
  401. $aParams[$sKey] = $sValue;
  402. }
  403. return $aParams;
  404. }
  405. // ====== SERVICE METHODS
  406. public function serviceIsAllowedAddContentToContext($iContextPid)
  407. {
  408. $oContext = false;
  409. if(!$iContextPid || !($oContext = BxDolProfile::getInstance((int)$iContextPid)))
  410. return false;
  411. if($iContextPid == bx_get_logged_profile_id())
  412. return true;
  413. return bx_srv($oContext->getModule(), 'check_allowed_post_in_profile', [$oContext->getContentId(), $this->getName()]) === CHECK_ACTION_RESULT_ALLOWED;
  414. }
  415. public function serviceIsBadgesAvaliable()
  416. {
  417. if(!isAdmin() && !$this->_isAdministrator())
  418. return false;
  419. $aBadges = BxDolBadges::getInstance()->getData([
  420. 'type' => 'by_module&object',
  421. 'object_id' => 0,
  422. 'module' => $this->getName()
  423. ]);
  424. return count($aBadges) > 0 ? true : false;
  425. }
  426. public function serviceGetSafeServices()
  427. {
  428. return array(
  429. // other
  430. 'ModuleIcon' => '',
  431. 'GetLink' => '',
  432. // browse
  433. 'GetSearchResultUnit' => '',
  434. 'Browse' => '',
  435. 'BrowseFeatured' => '',
  436. 'BrowseFavorite' => '',
  437. // forms
  438. 'GetCreatePostForm' => '',
  439. 'EntityCreate' => '',
  440. 'EntityEdit' => '',
  441. 'EntityDelete' => '',
  442. 'UpdateImage' => '',
  443. // page blocks
  444. 'EntityTextBlock' => '',
  445. 'EntityInfo' => '',
  446. 'EntityInfoFull' => '',
  447. 'EntityInfoExtended' => '',
  448. 'EntityLocation' => '',
  449. 'EntityComments' => '',
  450. 'EntityAttachments' => '',
  451. 'CategoriesMultiList' => '',
  452. // menu
  453. 'EntityAllActions' => '',
  454. 'EntityActions' => '',
  455. 'EntitySocialSharing' => '',
  456. 'MyEntriesActions' => '',
  457. 'GetProfiles' => '',
  458. );
  459. }
  460. /**
  461. * @page service Service Calls
  462. * @section bx_base_general Base General
  463. * @subsection bx_base_general-other Other
  464. * @subsubsection bx_base_general-module_icon module_icon
  465. *
  466. * @code bx_srv('bx_posts', 'module_icon', [...]); @endcode
  467. *
  468. * Get module icon as CSS class name with FontAwesome icon name class and color class
  469. *
  470. * @see BxBaseModGeneralModule::serviceModuleIcon
  471. */
  472. /**
  473. * @ref bx_base_general-module_icon "module_icon"
  474. */
  475. public function serviceModuleIcon ()
  476. {
  477. return isset($this->_oConfig->CNF['ICON']) ? $this->_oConfig->CNF['ICON'] : '';
  478. }
  479. public function serviceGetAuthor ($iContentId)
  480. {
  481. $mixedResult = $this->_getFieldValue('FIELD_AUTHOR', $iContentId);
  482. return $mixedResult !== false ? (int)$mixedResult : 0;
  483. }
  484. public function serviceGetPrivacyView ($iContentId)
  485. {
  486. return $this->_getFieldValue('FIELD_ALLOW_VIEW_TO', $iContentId);
  487. }
  488. public function serviceGetDateAdded ($iContentId)
  489. {
  490. $mixedResult = $this->_getFieldValue('FIELD_ADDED', $iContentId);
  491. return $mixedResult !== false ? (int)$mixedResult : 0;
  492. }
  493. public function serviceGetDateChanged ($iContentId)
  494. {
  495. $mixedResult = $this->_getFieldValue('FIELD_CHANGED', $iContentId);
  496. return $mixedResult !== false ? (int)$mixedResult : 0;
  497. }
  498. /**
  499. * @page service Service Calls
  500. * @section bx_base_general Base General
  501. * @subsection bx_base_general-other Other
  502. * @subsubsection bx_base_general-get_link get_link
  503. *
  504. * @code bx_srv('bx_posts', 'get_link', [...]); @endcode
  505. *
  506. * Get URL for the specified content.
  507. * @param $iContentId content id
  508. *
  509. * @see BxBaseModGeneralModule::serviceGetLink
  510. */
  511. /**
  512. * @ref bx_base_general-get_link "get_link"
  513. */
  514. public function serviceGetLink ($iContentId)
  515. {
  516. $CNF = &$this->_oConfig->CNF;
  517. if(empty($CNF['URI_VIEW_ENTRY']))
  518. return '';
  519. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  520. if(empty($aContentInfo))
  521. return '';
  522. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  523. }
  524. public function serviceGetTitle ($iContentId)
  525. {
  526. $mixedResult = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  527. return $mixedResult !== false ? $mixedResult : '';
  528. }
  529. public function serviceGetText ($iContentId)
  530. {
  531. $mixedResult = $this->_getFieldValue('FIELD_TEXT', $iContentId);
  532. if (false === $mixedResult)
  533. return '';
  534. $CNF = &$this->_oConfig->CNF;
  535. if (!empty($CNF['OBJECT_METATAGS']) && is_string($mixedResult)) {
  536. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  537. $mixedResult = $oMetatags->metaParse($iContentId, $mixedResult);
  538. }
  539. return $mixedResult;
  540. }
  541. public function serviceGetLocation ($iContentId)
  542. {
  543. $CNF = &$this->_oConfig->CNF;
  544. if(empty($CNF['OBJECT_METATAGS']))
  545. return [];
  546. $mixedResult = $this->_getFieldValue('FIELD_LOCATION', $iContentId);
  547. if(false === $mixedResult)
  548. return [];
  549. $oMeta = false;
  550. if(!($oMeta = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) || !$oMeta->locationsIsEnabled())
  551. return false;
  552. $aLocation = $oMeta->locationGet($iContentId);
  553. if(empty($aLocation) || !is_array($aLocation))
  554. return false;
  555. return array_values(array_slice($aLocation, 1));
  556. }
  557. public function serviceGetEmbed ($iContentId)
  558. {
  559. $sTitle = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  560. return $this->_oTemplate->parseHtmlByName('embed.html', [
  561. 'title' => $sTitle,
  562. 'url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'embed/' . $iContentId . '/'
  563. ]);
  564. }
  565. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  566. {
  567. $CNF = &$this->_oConfig->CNF;
  568. $aContentInfo = $this->_getFields($iContentId);
  569. if(empty($aContentInfo))
  570. return array();
  571. if(!$bSearchableFieldsOnly)
  572. return $aContentInfo;
  573. if(empty($CNF['PARAM_SEARCHABLE_FIELDS']))
  574. return array();
  575. $aFields = explode(',', getParam($CNF['PARAM_SEARCHABLE_FIELDS']));
  576. if(empty($aFields))
  577. return array();
  578. $aResult = array();
  579. foreach($aFields as $sField)
  580. if(isset($aContentInfo[$sField]))
  581. $aResult[$sField] = $aContentInfo[$sField];
  582. return $aResult;
  583. }
  584. public function serviceGetInfoApi ($iContentId, $bExtendedUnits = false)
  585. {
  586. $aData = $this->serviceGetInfo($iContentId, false);
  587. if($aData)
  588. $aData = $this->getDataAPI($aData, ['extended' => $bExtendedUnits]);
  589. return $aData;
  590. }
  591. /**
  592. * @page service Service Calls
  593. * @section bx_base_general Base General
  594. * @subsection bx_base_general-browsing Browsing
  595. * @subsubsection bx_base_general-get_search_result_unit get_search_result_unit
  596. *
  597. * @code bx_srv('bx_posts', 'get_search_result_unit', [3,"unit_gallery.html"]); @endcode
  598. *
  599. * Get browsing unit for the specified content
  600. * @param $iContentId content id
  601. * @param $sUnitTemplate unit template, such as: unit_full.html, unit_gallery.html, unit_live_search.html
  602. *
  603. * @see BxBaseModGeneralModule::serviceGetSearchResultUnit
  604. */
  605. /**
  606. * @ref bx_base_general-get_search_result_unit "get_search_result_unit"
  607. */
  608. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  609. {
  610. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  611. if($this->_bIsApi)
  612. return $this->getDataAPI($aContentInfo);
  613. if(empty($aContentInfo))
  614. return '';
  615. if(empty($sUnitTemplate))
  616. $sUnitTemplate = 'unit.html';
  617. return $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
  618. }
  619. /**
  620. * @page service Service Calls
  621. * @section bx_base_general Base General
  622. * @subsection bx_base_general-browsing Browsing
  623. * @subsubsection bx_base_general-get_view get_view
  624. *
  625. * @code bx_srv('bx_posts', 'get_view', [3]); @endcode
  626. *
  627. * Get view for the specified content
  628. * @param $iContentId content id
  629. *
  630. * @see BxBaseModGeneralModule::serviceGetView
  631. */
  632. /**
  633. * @ref bx_base_general-get_view "get_view"
  634. */
  635. public function serviceGetView ($iContentId)
  636. {
  637. return $this->serviceEntityTextBlock($iContentId);
  638. }
  639. public function serviceGetAll ($aParams = array())
  640. {
  641. if(empty($aParams) || !is_array($aParams))
  642. $aParams = array('type' => 'all');
  643. return $this->_oDb->getEntriesBy($aParams);
  644. }
  645. public function serviceGetAllByAuthor ($iProfileId)
  646. {
  647. return $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  648. }
  649. public function serviceGetSortableFieldsExtended($aInputsAdd = array())
  650. {
  651. $CNF = &$this->_oConfig->CNF;
  652. if(empty($CNF['OBJECT_FORM_ENTRY']))
  653. return array();
  654. $aResult = array();
  655. $aSortableFields = [];
  656. $aDisplays = [];
  657. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
  658. $aDisplays[] = $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'];
  659. }
  660. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
  661. $aDisplays[] = $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'];
  662. }
  663. $aInputsAll = BxDolFormQuery::getFormInputs($CNF['OBJECT_FORM_ENTRY']);
  664. foreach($aInputsAll as $aInput){
  665. $aInputsAll[$aInput['name']] = $aInput;
  666. }
  667. $aInputs = BxDolFormQuery::getFormInputs($CNF['OBJECT_FORM_ENTRY'], $aDisplays);
  668. foreach($aInputs as $aInput){
  669. $aInputs[$aInput['name']] = $aInput;
  670. if ($aInput['type'] == 'text'){
  671. $aSortableFields[] = $aInput['name'];
  672. }
  673. }
  674. if(!empty($CNF['FIELD_ADDED']) && isset($aInputsAll[$CNF['FIELD_ADDED']])){
  675. $aSortableFields[] = $CNF['FIELD_ADDED'];
  676. }
  677. if(!empty($CNF['FIELD_CHANGED']) && isset($aInputsAll[$CNF['FIELD_CHANGED']])){
  678. $aSortableFields[] = $CNF['FIELD_CHANGED'];
  679. }
  680. foreach($aSortableFields as $sSortableField){
  681. $aResult[$sSortableField . '_asc'] = [
  682. 'name' => $sSortableField,
  683. 'caption' => $aInputsAll[$sSortableField]['caption'],
  684. 'direction' => 'asc'
  685. ];
  686. $aResult[$sSortableField . '_desc'] = [
  687. 'name' => $sSortableField,
  688. 'caption' => $aInputsAll[$sSortableField]['caption'],
  689. 'direction' => 'desc'
  690. ];
  691. }
  692. /**
  693. * @hooks
  694. * @hookdef hook-bx_base_general-get_sortable_fields '{module_name}', 'get_sortable_fields' - hook to override a list of sortable fields
  695. * - $unit_name - module name
  696. * - $action - equals `get_sortable_fields`
  697. * - $object_id - not used
  698. * - $sender_id - not used
  699. * - $extra_params - array of additional params with the following array keys:
  700. * - `override_result` - [array] a list of searchable fields, can be overridden in hook processing
  701. * @hook @ref hook-bx_base_general-get_sortable_fields
  702. */
  703. bx_alert($this->getName(), 'get_sortable_fields', 0, 0, [
  704. 'extended' => true,
  705. 'override_result' => &$aResult
  706. ]);
  707. return $aResult;
  708. }
  709. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  710. {
  711. $CNF = &$this->_oConfig->CNF;
  712. if(empty($CNF['OBJECT_FORM_ENTRY']))
  713. return array();
  714. $aResult = array();
  715. if(!empty($CNF['FIELD_AUTHOR']) && !in_array($CNF['FIELD_AUTHOR'], $this->_aSearchableNamesExcept))
  716. $aResult[$CNF['FIELD_AUTHOR']] = array(
  717. 'type' => 'text_auto',
  718. 'caption' => $CNF['T']['form_field_author'],
  719. 'info' => '',
  720. 'value' => '',
  721. 'values' => '',
  722. 'pass' => ''
  723. );
  724. if(!empty($CNF['FIELD_LABELS']) && !in_array($CNF['FIELD_LABELS'], $this->_aSearchableNamesExcept))
  725. $aResult[$CNF['FIELD_LABELS']] = array(
  726. 'type' => 'checkbox_set',
  727. 'caption' => isset($CNF['T']['form_field_labels']) ? $CNF['T']['form_field_author'] : '_sys_form_input_labels',
  728. 'info' => '',
  729. 'value' => '',
  730. 'values' => '',
  731. 'pass' => '',
  732. 'search_operator' => 'like'
  733. );
  734. $aInputs = array();
  735. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
  736. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  737. $aInputs = array_merge($aInputs, $oForm->aInputs);
  738. }
  739. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
  740. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'], $this->_oTemplate);
  741. $aInputs = array_merge($aInputs, $oForm->aInputs);
  742. }
  743. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  744. $aInputs = array_merge($aInputs, $aInputsAdd);
  745. foreach($aInputs as $aInput){
  746. if(in_array($aInput['type'], BxDolSearchExtended::$SEARCHABLE_TYPES) && !in_array($aInput['name'], $this->_aSearchableNamesExcept)) {
  747. $aField = array(
  748. 'type' => $aInput['type'],
  749. 'caption_system' => $aInput['caption_system_src'],
  750. 'caption' => $aInput['caption_src'],
  751. 'info' => $aInput['info_src'],
  752. 'value' => !empty($aInput['value']) ? $aInput['value'] : '',
  753. 'values' => !empty($aInput['values_src']) ? $aInput['values_src'] : '',
  754. 'pass' => !empty($aInput['db']['pass']) ? $aInput['db']['pass'] : '',
  755. );
  756. if(isset($aInput['search_type']))
  757. $aField['search_type'] = $aInput['search_type'];
  758. if(isset($aInput['search_operator']))
  759. $aField['search_operator'] = $aInput['search_operator'];
  760. $aResult[$aInput['name']] = $aField;
  761. }
  762. }
  763. /**
  764. * @hooks
  765. * @hookdef hook-bx_base_general-get_searchable_fields '{module_name}', 'get_searchable_fields' - hook to override a list of searchable fields
  766. * - $unit_name - module name
  767. * - $action - equals `get_searchable_fields`
  768. * - $object_id - not used
  769. * - $sender_id - not used
  770. * - $extra_params - array of additional params with the following array keys:
  771. * - `override_result` - [array] a list of searchable fields, can be overridden in hook processing
  772. * @hook @ref hook-bx_base_general-get_searchable_fields
  773. */
  774. bx_alert($this->getName(), 'get_searchable_fields', 0, 0, [
  775. 'extended' => true,
  776. 'override_result' => &$aResult
  777. ]);
  778. return $aResult;
  779. }
  780. public function serviceGetSearchResultExtended($aParams, $iStart = 0, $iPerPage = 0, $bFilterMode = false)
  781. {
  782. if((empty($aParams) || !is_array($aParams)) && !$bFilterMode)
  783. return array();
  784. return $this->_oDb->getEntriesBy(array('type' => 'search_ids', 'search_params' => $aParams, 'start' => $iStart, 'per_page' => $iPerPage));
  785. }
  786. public function serviceGetSearchableFields ($aInputsAdd = array())
  787. {
  788. $CNF = $this->_oConfig->CNF;
  789. if(!isset($CNF['PARAM_SEARCHABLE_FIELDS']) || !isset($CNF['OBJECT_FORM_ENTRY']) || !isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
  790. return array();
  791. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  792. if(!$oForm)
  793. return array();
  794. $aInputs = $oForm->aInputs;
  795. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  796. $aInputs = array_merge($aInputs, $aInputsAdd);
  797. $aTextTypes = array('text', 'textarea');
  798. $aTextFields = array();
  799. foreach($aInputs as $r)
  800. if(in_array($r['type'], $aTextTypes))
  801. $aTextFields[$r['name']] = $r['caption'];
  802. return $aTextFields;
  803. }
  804. public function serviceUpdateImage($sFiledName, $iContentId, $sValue)
  805. {
  806. $CNF = &$this->_oConfig->CNF;
  807. $aData = $this->_oDb->getContentInfoById($iContentId);
  808. if(empty($aData) || !is_array($aData))
  809. return false;
  810. if($this->checkAllowedEdit($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  811. return false;
  812. //TODO add transcoder settings
  813. $oImgStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  814. if(!$oImgStorage)
  815. return false;
  816. $this->_oDb->updateEntriesBy([$sFiledName => $sValue], [$CNF['FIELD_ID'] => $iContentId]);
  817. $this->serviceUpdateImagePosition($iContentId, $sFiledName, '', '');
  818. $this->onUpdateImage($iContentId, $sFiledName, $sValue);
  819. return $oImgStorage->getFileUrlById($sValue);
  820. }
  821. public function serviceUpdateImagePosition($iContentId, $sFiledName, $sH, $sV)
  822. {
  823. $CNF = &$this->_oConfig->CNF;
  824. $sFieldNamePos = 'FIELD_' . strtoupper($sFiledName) . '_POSITION';
  825. if(!isset($CNF[$sFieldNamePos]))
  826. return false;
  827. $sValue = '';
  828. if($sH != '' || $sV != '')
  829. $sValue = json_encode(['x' => $sH, 'y' => $sV]);
  830. $this->_oDb->updateEntriesBy([$CNF[$sFieldNamePos] => $sValue], [$CNF['FIELD_ID'] => $iContentId]);
  831. return true;
  832. }
  833. public function serviceManageTools($sType = 'common')
  834. {
  835. if(!isLogged())
  836. return '';
  837. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
  838. if(!$oGrid)
  839. return '';
  840. if($this->_bIsApi)
  841. return [
  842. bx_api_get_block('grid', $oGrid->getCodeAPI())
  843. ];
  844. $CNF = &$this->_oConfig->CNF;
  845. $mixedMenu = '';
  846. if(BxDolAcl::getInstance()->isMemberLevelInSet(192)) {
  847. $oPermalink = BxDolPermalinks::getInstance();
  848. $aMenuItems = array();
  849. if(!empty($CNF['OBJECT_GRID_COMMON']) && !empty($CNF['T']['menu_item_manage_my']))
  850. $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);
  851. if(!empty($CNF['OBJECT_GRID_ADMINISTRATION']) && !empty($CNF['T']['menu_item_manage_all']))
  852. $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);
  853. if(count($aMenuItems) > 1) {
  854. $mixedMenu = new BxTemplMenu(array(
  855. 'template' => 'menu_block_submenu_ver.html',
  856. 'menu_items' => $aMenuItems
  857. ), $this->_oTemplate);
  858. $mixedMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
  859. }
  860. }
  861. if(!empty($CNF['OBJECT_MENU_SUBMENU']) && isset($CNF['URI_MANAGE_COMMON']) && ($oSubmenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])) !== false)
  862. $oSubmenu->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
  863. $this->_oTemplate->addCss(array('manage_tools.css'));
  864. $this->_oTemplate->addJs(array('manage_tools.js'));
  865. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  866. return array(
  867. 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
  868. 'menu' => $mixedMenu
  869. );
  870. }
  871. public function serviceGetMenuAddonManageTools()
  872. {
  873. return 0;
  874. }
  875. public function serviceGetMenuAddonManageToolsProfileStats($iProfileId = 0)
  876. {
  877. return 0;
  878. }
  879. /**
  880. * @page service Service Calls
  881. * @section bx_base_general Base General
  882. * @subsection bx_base_general-browsing Browsing
  883. * @subsubsection bx_base_general-browse browse
  884. *
  885. * @code bx_srv('bx_posts', 'browse', [...]); @endcode
  886. * @code {{~bx_posts:browse[{"mode":"author", "params":{"author":"10"}}]~}} @endcode
  887. *
  888. * Universal browse method.
  889. * @param $aParams custom browse params, possible params are the following:
  890. * - mode - browse mode, such as 'recent', 'featured', etc
  891. * - params - custom params to browse method, for example 'unit_view' can be passed here
  892. * - design_box - design box style, @see BxBaseFunctions::DesignBoxContent
  893. * - empty_message - display or not "empty" message when there is no content
  894. * - ajax_paginate - use AJAX paginate or not
  895. *
  896. * @see BxBaseModGeneralModule::serviceBrowse
  897. */
  898. /**
  899. * @ref bx_base_general-browse "browse"
  900. */
  901. public function serviceBrowse ($aParams = array())
  902. {
  903. if($this->_bIsApi && is_string($aParams)){
  904. $aParams = json_decode($aParams, true);
  905. if (isset($aParams['params'])) {
  906. if(isset($aParams['params']['type']))
  907. $aParams['mode'] = $aParams['params']['type'];
  908. if(isset($aParams['params']['filters'])) {
  909. foreach($aParams['params']['filters'] as $sKey => $sValue)
  910. $aParams['params'][$sKey] = $sValue;
  911. $aParams['params']['filters'] = [
  912. 'values' => $aParams['params']['filters']
  913. ];
  914. }
  915. if(isset($aParams['params']['validate']) && !is_array($aParams['params']['validate']))
  916. $aParams['params']['validate'] = !empty($aParams['params']['validate']) ? explode(',', $aParams['params']['validate']) : [];
  917. }
  918. }
  919. if (isset($aParams['params']['condition']))
  920. unset($aParams['params']['condition']);
  921. return $this->serviceBrowseWithCondition ($aParams);
  922. }
  923. public function serviceBrowseWithCondition ($aParams = array())
  924. {
  925. $aDefaults = array (
  926. 'mode' => 'recent',
  927. 'params' => false,
  928. 'design_box' => BX_DB_PADDING_DEF,
  929. 'empty_message' => false,
  930. 'ajax_paginate' => true,
  931. 'class_search_result' => 'SearchResult'
  932. );
  933. $aParams = array_merge($aDefaults, $aParams);
  934. return $this->_serviceBrowse ($aParams['mode'], $aParams['params'], $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate'], $aParams['class_search_result']);
  935. }
  936. /**
  937. * @page service Service Calls
  938. * @section bx_base_general Base General
  939. * @subsection bx_base_general-browsing Browsing
  940. * @subsubsection bx_base_general-browse_featured browse_featured
  941. *
  942. * @code bx_srv('bx_posts', 'browse_featured', [...]); @endcode
  943. *
  944. * Display featured entries
  945. * @param $sUnitView browsing unity view,
  946. * such as: full, extended, gallery, showcase
  947. * @param $bEmptyMessage display or not "empty" message when there is no content
  948. * @param $bAjaxPaginate use AJAX paginate or not
  949. *
  950. * @see BxBaseModGeneralModule::serviceBrowseFeatured
  951. */
  952. /**
  953. * @ref bx_base_general-browse_featured "browse_featured"
  954. */
  955. public function serviceBrowseFeatured ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  956. {
  957. return $this->_serviceBrowse ('featured', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  958. }
  959. /**
  960. * @page service Service Calls
  961. * @section bx_base_general Base General
  962. * @subsection bx_base_general-browsing Browsing
  963. * @subsubsection bx_base_general-browse_favorite browse_favorite
  964. *
  965. * @code bx_srv('bx_posts', 'browse_favorite', [...]); @endcode
  966. *
  967. * Display entries which were added to favorite list by some member
  968. * @param $iProfileId profile ID
  969. * @param $aParams additional browse params, see BxBaseModGeneralModule::serviceBrowse
  970. *
  971. * @see BxBaseModGeneralModule::serviceBrowseFavorite BxBaseModGeneralModule::serviceBrowse
  972. */
  973. /**
  974. * @ref bx_base_general-browse_favorite "browse_favorite"
  975. */
  976. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  977. {
  978. $CNF = &$this->_oConfig->CNF;
  979. $oProfile = null;
  980. if((int)$iProfileId)
  981. $oProfile = BxDolProfile::getInstance($iProfileId);
  982. if(!$oProfile && bx_get('profile_id') !== false)
  983. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  984. if(!$oProfile)
  985. $oProfile = BxDolProfile::getInstance();
  986. if(!$oProfile)
  987. return '';
  988. $bEmptyMessage = true;
  989. if(isset($aParams['empty_message'])) {
  990. $bEmptyMessage = (bool)$aParams['empty_message'];
  991. unset($aParams['empty_message']);
  992. }
  993. if(bx_get('list_id') !== false && !isset($aParams['list_id']))
  994. $aParams['list_id'] = (int) bx_get('list_id');
  995. $aBlock = $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage);
  996. if(!$aBlock)
  997. return $aBlock;
  998. $sTitle = _t('_sys_txt_default_favorite_list');
  999. if(!empty($aParams['list_id']) && ($oFavorite = BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], 0, true))) {
  1000. $aList = $oFavorite->getQueryObject()->getList(['type' => 'id', 'list_id' => $aParams['list_id']]);
  1001. if(!empty($aList) && is_array($aList))
  1002. $sTitle = $aList['title'];
  1003. }
  1004. return array_merge($aBlock, ['markers' => [
  1005. 'title' => $sTitle
  1006. ]]);
  1007. }
  1008. /**
  1009. * @page service Service Calls
  1010. * @section bx_base_general Base General
  1011. * @subsection bx_base_general-browsing Browsing
  1012. * @subsubsection bx_base_general-browse_favorite_lists browse_favorite_lists
  1013. *
  1014. * @code bx_srv('bx_posts', 'browse_favorite_lists', [...]); @endcode
  1015. *
  1016. * Display entries which were added to favorite lists grouped by lists by some member
  1017. * @param $iProfileId profile ID
  1018. * @param $aParams additional browse params, see BxBaseModGeneralModule::serviceBrowse
  1019. *
  1020. * @see BxBaseModGeneralModule::serviceBrowseFavoriteLists BxBaseModGeneralModule::serviceBrowse
  1021. */
  1022. /**
  1023. * @ref bx_base_general-browse_favorite_lists "browse_favorite_lists"
  1024. */
  1025. public function serviceBrowseFavoriteLists ($iProfileId = 0, $aParams = array())
  1026. {
  1027. $CNF = &$this->_oConfig->CNF;
  1028. $oProfile = null;
  1029. if((int)$iProfileId)
  1030. $oProfile = BxDolProfile::getInstance($iProfileId);
  1031. if(!$oProfile && bx_get('profile_id') !== false)
  1032. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  1033. if(!$oProfile)
  1034. $oProfile = BxDolProfile::getInstance();
  1035. if(!$oProfile)
  1036. return '';
  1037. $iStart = (bx_get('list_start') !== false ? (int)bx_get('list_start') : 0);
  1038. $iPerPage = (int)getParam($CNF['PARAM_PER_PAGE_FOR_FAVORITES_LISTS']);
  1039. return $this->_oTemplate->getFavoriteList($oProfile, $iStart, $iPerPage, $aParams);
  1040. }
  1041. /**
  1042. * @page service Service Calls
  1043. * @section bx_base_general Base General
  1044. * @subsection bx_base_general-browsing Browsing
  1045. * @subsubsection bx_base_general-browse_by_category category
  1046. *
  1047. * @code bx_srv('bx_posts', 'browse_by_category', [...]); @endcode
  1048. *
  1049. * Display entries in category
  1050. * @param $sUnitView browsing unity view,
  1051. * such as: full, extended, gallery, showcase
  1052. * @param $bEmptyMessage display or not "empty" message when there is no content
  1053. * @param $bAjaxPaginate use AJAX paginate or not
  1054. *
  1055. * @see BxBaseModGeneralModule::serviceBrowseByCategory BxBaseModGeneralModule::serviceBrowse
  1056. */
  1057. /**
  1058. * @ref bx_base_general-browse_by_category "browse_by_category"
  1059. */
  1060. public function serviceBrowseCategory($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $aParams = [])
  1061. {
  1062. $sType = 'category';
  1063. $aParams = array_merge(['category' => bx_process_input(bx_get('category'), BX_DATA_INT)], $aParams);
  1064. if($sUnitView)
  1065. $aParams['unit_view'] = $sUnitView;
  1066. return $this->_serviceBrowse($sType, $aParams, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  1067. }
  1068. /**
  1069. * @page service Service Calls
  1070. * @section bx_base_general Base General
  1071. * @subsection bx_base_general-browsing Browsing
  1072. * @subsubsection bx_base_general-browse_favorite_list_actions browse_favorite_list_actions
  1073. *
  1074. * @code bx_srv('bx_posts', 'browse_favorite_list_actions', [...]); @endcode
  1075. *
  1076. * Display menu actions for favorite lists
  1077. *
  1078. * @see BxBaseModGeneralModule::serviceFavoritesListActions
  1079. */
  1080. /**
  1081. * @ref bx_base_general-browse_favorite_list_actions "browse_favorite_list_actions"
  1082. */
  1083. public function serviceFavoritesListActions()
  1084. {
  1085. $iListId = 0;
  1086. if(bx_get('list_id') !== false)
  1087. $iListId = (int) bx_get('list_id');
  1088. $oProfile = null;
  1089. if(bx_get('profile_id') !== false)
  1090. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  1091. if(!$oProfile)
  1092. return false;
  1093. $CNF = &$this->_oConfig->CNF;
  1094. $oFavorite = BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], 0, true);
  1095. $aList = $oFavorite->getQueryObject()->getList(array('type' => 'id', 'list_id' => $iListId));
  1096. if($iListId != 0 && (empty($aList) || !is_array($aList)))
  1097. return false;
  1098. $sRv = '';
  1099. if (!empty($aList) && $oFavorite->isAllowedEditList($aList['author_id'])){
  1100. $aMarkers = array(
  1101. 'js_object' => $oFavorite->getJsObjectName(),
  1102. 'list_id' => $iListId,
  1103. );
  1104. $oMenu = BxDolMenu::getObjectInstance('sys_favorite_list');
  1105. $oMenu->addMarkers($aMarkers);
  1106. $sMenu = $oMenu->getCode();
  1107. $sRv .= $sMenu . $oFavorite->getJsScript();
  1108. }
  1109. $aMarkers = array(
  1110. 'id' => $iListId,
  1111. 'module' => $this->_aModule['name'],
  1112. 'url' => $this->_getFavoriteListUrl($iListId, $oProfile->id()),
  1113. 'title' => $iListId > 0 ? $aList['title'] : _t('_sys_txt_default_favorite_list')
  1114. );
  1115. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  1116. $oMenu->addMarkers($aMarkers);
  1117. $sRv .= $sMenu = $oMenu->getCode();
  1118. return $sRv;
  1119. }
  1120. /**
  1121. * @page service Service Calls
  1122. * @section bx_base_general Base General
  1123. * @subsection bx_base_general-menu Menu
  1124. * @subsubsection bx_base_general-favorites_list_info favorites_list_info
  1125. *
  1126. * @code bx_srv('bx_posts', 'favorites_list_info', [...]); @endcode
  1127. *
  1128. * Favorites list info
  1129. * @param $aParams array with additional custom params
  1130. * which may overwrite some default values
  1131. *
  1132. * @see BxBaseModGeneralModule::serviceFavoritesListInfo
  1133. */
  1134. /**
  1135. * @ref bx_base_general-favorites_list_info "favorites_list_info"
  1136. */
  1137. public function serviceFavoritesListInfo($aParams = array())
  1138. {
  1139. $CNF = &$this->_oConfig->CNF;
  1140. $iListId = 0;
  1141. if(bx_get('list_id') !== false)
  1142. $iListId = (int) bx_get('list_id');
  1143. $oFavorite = BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], 0, true);
  1144. $aList = $oFavorite->getQueryObject()->getList(array('type' => 'id', 'list_id' => $iListId));
  1145. if($iListId != 0 && (empty($aList) || !is_array($aList)))
  1146. return false;
  1147. $oProfile = null;
  1148. if(bx_get('profile_id') !== false)
  1149. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  1150. if(!$oProfile)
  1151. return false;
  1152. return $this->_oTemplate->getFavoritesListInfo($aList, $oProfile);
  1153. }
  1154. /**
  1155. * Display entries posted into particular context
  1156. * @return HTML string
  1157. */
  1158. public function serviceBrowseContext ($iProfileId = 0, $aParams = array())
  1159. {
  1160. return $this->_serviceBrowseWithParam ('context', 'profile_id', $iProfileId, $aParams);
  1161. }
  1162. public function _serviceBrowseWithParam ($sParamName, $sParamGet, $sParamVal, $aParams = array())
  1163. {
  1164. if(!$sParamVal)
  1165. $sParamVal = bx_process_input(bx_get($sParamGet), BX_DATA_INT);
  1166. if(!$sParamVal)
  1167. return '';
  1168. $bEmptyMessage = true;
  1169. if(isset($aParams['empty_message'])) {
  1170. $bEmptyMessage = (bool)$aParams['empty_message'];
  1171. unset($aParams['empty_message']);
  1172. }
  1173. $bAjaxPaginate = true;
  1174. if(isset($aParams['ajax_paginate'])) {
  1175. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  1176. unset($aParams['ajax_paginate']);
  1177. }
  1178. return $this->_serviceBrowse ($sParamName, array_merge(array($sParamName => $sParamVal), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  1179. }
  1180. public function getFormsHelper ()
  1181. {
  1182. $sClass = 'FormsEntryHelper';
  1183. $oObject = null;
  1184. bx_alert('system', 'get_forms_helper', 0, 0, [
  1185. 'class' => &$sClass,
  1186. 'object' => &$oObject
  1187. ]);
  1188. if($oObject !== null)
  1189. return $oObject;
  1190. bx_import($sClass, $this->_aModule);
  1191. $sClass = $this->_aModule['class_prefix'] . $sClass;
  1192. return new $sClass($this);
  1193. }
  1194. public function serviceFormsHelper ()
  1195. {
  1196. return $this->getFormsHelper();
  1197. }
  1198. /**
  1199. * Add entry using provided fields' values.
  1200. * @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
  1201. */
  1202. public function serviceEntityAdd ($iProfile, $aValues, $sDisplay = false)
  1203. {
  1204. $oFormsHelper = $this->getFormsHelper();
  1205. return $oFormsHelper->addData($iProfile, $aValues, $sDisplay);
  1206. }
  1207. /**
  1208. * Perform redirect after content creation
  1209. * @return nothing, rediret header is sent
  1210. */
  1211. public function serviceRedirectAfterAdd($aContentInfo)
  1212. {
  1213. $oFormsHelper = $this->getFormsHelper();
  1214. $oFormsHelper->redirectAfterAdd($aContentInfo);
  1215. }
  1216. /**
  1217. * Get form object for add, edit, view or delete the content
  1218. * @param $sType 'add', 'edit', 'view' or 'delete'
  1219. * @param $aParams optional array with parameters(display name, etc)
  1220. * @return form object or false on error
  1221. */
  1222. public function serviceGetObjectForm ($sType, $aParams = array())
  1223. {
  1224. if(!in_array($sType, array('add', 'edit', 'view', 'delete')))
  1225. return false;
  1226. $iLoggedId = (int)bx_get_logged_profile_id();
  1227. $mixedContextId = isset($aParams['context_id']) ? $aParams['context_id'] : false;
  1228. $oContextProfile = false;
  1229. $bContext = $mixedContextId !== false;
  1230. if($bContext) {
  1231. $oContextProfile = BxDolProfile::getInstance(abs($mixedContextId));
  1232. $bContext = $oContextProfile !== false;
  1233. if($bContext && $oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  1234. return false;
  1235. }
  1236. $CNF = &$this->_oConfig->CNF;
  1237. $oFormsHelper = $this->getFormsHelper();
  1238. $sParamsKey = 'ajax_mode';
  1239. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  1240. $oFormsHelper->setAjaxMode((bool)$aParams[$sParamsKey]);
  1241. $sParamsKey = 'absolute_action_url';
  1242. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  1243. $oFormsHelper->setAbsoluteActionUrl((bool)$aParams[$sParamsKey]);
  1244. if($bContext)
  1245. $oFormsHelper->setContextId($mixedContextId);
  1246. $sDisplay = !empty($aParams['display']) ? $aParams['display'] : false;
  1247. $sFunc = 'getObjectForm' . ucfirst($sType);
  1248. $oForm = $oFormsHelper->$sFunc($sDisplay);
  1249. $sKey = 'FIELD_ALLOW_VIEW_TO';
  1250. if(!empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]]) && (!$bContext || $mixedContextId < 0)) {
  1251. $bContextOwner = $bContext && abs($mixedContextId) == $iLoggedId;
  1252. if(!$bContext || $bContextOwner) {
  1253. $iGc = 0;
  1254. $iKeyGh = false;
  1255. foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $iKey => $aValue) {
  1256. if(isset($aValue['type']) && in_array($aValue['type'], array('group_header', 'group_end'))) {
  1257. if($iKeyGh !== false && $iGc == 0) {
  1258. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKeyGh]);
  1259. $iKeyGh = false;
  1260. if($aValue['type'] == 'group_end')
  1261. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  1262. }
  1263. if($aValue['type'] == 'group_header') {
  1264. $iGc = 0;
  1265. $iKeyGh = $iKey;
  1266. }
  1267. continue;
  1268. }
  1269. //--- Show 'Public' privacy group only in Public post form.
  1270. if(!$bContext && $aValue['key'] == BX_DOL_PG_ALL) {
  1271. $iGc += 1;
  1272. continue;
  1273. }
  1274. //--- Show a default privacy groups in Profile (for Owner) post form.
  1275. if($bContextOwner && ((int)$aValue['key'] >= 0 || $mixedContextId == $aValue['key'])) {
  1276. $iGc += 1;
  1277. continue;
  1278. }
  1279. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  1280. }
  1281. }
  1282. else {
  1283. $oForm->aInputs[$CNF[$sKey]]['value'] = $mixedContextId;
  1284. $oForm->aInputs[$CNF[$sKey]]['type'] = 'hidden';
  1285. }
  1286. }
  1287. $sKey = 'FIELD_LABELS';
  1288. if(!empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]]) && empty($oForm->aInputs[$CNF[$sKey]]['value']) && $bContext) {
  1289. $iContextProfileId = $oContextProfile->id();
  1290. $sContextModule = $oContextProfile->getModule();
  1291. if(bx_srv($sContextModule, 'is_fan', [$iContextProfileId, $iLoggedId])) {
  1292. $aContextInfo = bx_srv($sContextModule, 'get_content_info_by_profile_id', [$iContextProfileId]);
  1293. if(!empty($aContextInfo['hashtag']))
  1294. $oForm->aInputs[$CNF[$sKey]]['value'] = [$aContextInfo['hashtag']];
  1295. }
  1296. }
  1297. /**
  1298. * @hooks
  1299. * @hookdef hook-system-get_object_form 'system', 'get_object_form' - hook to override an object of create content form, @see BxDolForm
  1300. * - $unit_name - equals `system`
  1301. * - $action - equals `get_object_form`
  1302. * - $object_id - not used
  1303. * - $sender_id - not used
  1304. * - $extra_params - array of additional params with the following array keys:
  1305. * - `module` - [string] module name
  1306. * - `type` - [string] 'add', 'edit', 'view' or 'delete' form display type
  1307. * - `params` - [array] form params array as key&value pairs
  1308. * - `form` - [object] by ref, an object of create content form, @see BxDolForm, can be overridden in hook processing
  1309. * @hook @ref hook-system-get_object_form
  1310. */
  1311. bx_alert('system', 'get_object_form', 0, 0, [
  1312. 'module' => $this->_oConfig->getName(),
  1313. 'type' => $sType,
  1314. 'params' => $aParams,
  1315. 'form' => &$oForm
  1316. ]);
  1317. return $oForm;
  1318. }
  1319. /**
  1320. *
  1321. *
  1322. * Create entry form
  1323. * @return HTML string
  1324. */
  1325. public function serviceEntityCreate ($sParams = false)
  1326. {
  1327. if($this->_bIsApi && ($aParams = bx_api_get_browse_params($sParams))) {
  1328. if(($aKeys = ['context_pid', 'context_nid', 'context_usage']) && ($aParamsContext = array_intersect_key($aParams, array_flip($aKeys)))) {
  1329. $_GET = array_merge($_GET, $aParamsContext);
  1330. $sParams = array_diff_key($aParams, array_flip($aKeys));
  1331. }
  1332. }
  1333. $bParamsArray = is_array($sParams);
  1334. $sDisplay = is_string($sParams) ? $sParams : false;
  1335. if($bParamsArray && !empty($sParams['display']))
  1336. $sDisplay = $sParams['display'];
  1337. $oFormsHelper = $this->getFormsHelper();
  1338. if($bParamsArray && isset($sParams['dynamic_mode']))
  1339. $oFormsHelper->setDynamicMode($sParams['dynamic_mode']);
  1340. $mixedResult = $oFormsHelper->addDataForm($sDisplay);
  1341. if($this->_bIsApi)
  1342. return $mixedResult;
  1343. if(isset($mixedResult['_dt']) && $mixedResult['_dt'] == 'json') {
  1344. echoJson($mixedResult);
  1345. exit;
  1346. }
  1347. return $mixedResult;
  1348. }
  1349. /**
  1350. * @page service Service Calls
  1351. * @section bx_base_general Base General
  1352. * @subsection bx_base_general-forms Forms
  1353. * @subsubsection bx_base_general-get_create_post_form get_create_post_form
  1354. *
  1355. * @code bx_srv('bx_posts', 'get_create_post_form'); @endcode
  1356. *
  1357. * Get content creation form
  1358. * @param $aParams additional parameters array:
  1359. * context_id, ajax_mode, absolute_action_url, displays
  1360. *
  1361. * @see BxBaseModGeneralModule::serviceGetCreatePostForm
  1362. */
  1363. /**
  1364. * @ref bx_base_general-get_create_post_form "get_create_post_form"
  1365. */
  1366. public function serviceGetCreatePostForm($aParams = [])
  1367. {
  1368. $aParams = array_merge($this->_aFormParams, $aParams);
  1369. if($aParams['context_id'] !== false && ($aContextInfo = BxDolProfileQuery::getInstance()->getInfoById(abs($aParams['context_id']))))
  1370. if(bx_srv($aContextInfo['type'], 'check_allowed_post_in_profile', [$aContextInfo['content_id'], $this->getName()]) !== CHECK_ACTION_RESULT_ALLOWED)
  1371. return '';
  1372. $oForm = $this->serviceGetObjectForm('add', $aParams);
  1373. if(!$oForm)
  1374. return '';
  1375. return $this->serviceEntityCreate($aParams);
  1376. }
  1377. /**
  1378. * @page service Service Calls
  1379. * @section bx_base_general Base General
  1380. * @subsection bx_base_general-forms Forms
  1381. * @subsubsection bx_base_general-entity_edit entity_edit
  1382. *
  1383. * @code bx_srv('bx_posts', 'entity_edit', [...]); @endcode
  1384. *
  1385. * Get content edit form
  1386. * @param $iContentId content ID
  1387. * @param $sDisplay optional form display name
  1388. *
  1389. * @see BxBaseModGeneralModule::serviceEntityEdit
  1390. */
  1391. /**
  1392. * @ref bx_base_general-entity_edit "entity_edit"
  1393. */
  1394. public function serviceEntityEdit ($iContentId = 0, $sDisplay = false)
  1395. {
  1396. return $this->_serviceEntityForm ('editDataForm', $iContentId, $sDisplay);
  1397. }
  1398. /**
  1399. * @page service Service Calls
  1400. * @section bx_base_general Base General
  1401. * @subsection bx_base_general-forms Forms
  1402. * @subsubsection bx_base_general-entity_delete entity_delete
  1403. *
  1404. * @code bx_srv('bx_posts', 'entity_delete', [...]); @endcode
  1405. *
  1406. * Get content delete form
  1407. * @param $iContentId content ID
  1408. *
  1409. * @see BxBaseModGeneralModule::serviceEntityDelete
  1410. */
  1411. /**
  1412. * @ref bx_base_general-entity_delete "entity_delete"
  1413. */
  1414. public function serviceEntityDelete ($iContentId = 0)
  1415. {
  1416. $mixedResult = $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  1417. if(!bx_is_api())
  1418. return $mixedResult;
  1419. $aResult = [];
  1420. if(is_a($mixedResult, 'BxTemplFormView')){
  1421. $iContentId = $this->_getContent($iContentId, false);
  1422. $aResult = bx_api_get_block('form', $mixedResult->getCodeAPI(), ['ext' => ['name' => $this->getName(), 'request' => ['url' => '/api.php?r=' . $this->_aModule['name'] . '/entity_delete&params[]=' . $iContentId . '&params[]=' . $mixedResult->aParams['display'], 'immutable' => true]]]);
  1423. }
  1424. else
  1425. $aResult = $mixedResult;
  1426. return [
  1427. $aResult
  1428. ];
  1429. }
  1430. /**
  1431. * @page service Service Calls
  1432. * @section bx_base_general Base General
  1433. * @subsection bx_base_general-page_blocks Page Blocks
  1434. * @subsubsection bx_base_general-entity_text_block entity_text_block
  1435. *
  1436. * @code bx_srv('bx_posts', 'entity_text_block', [...]); @endcode
  1437. *
  1438. * Get content text/description
  1439. * @param $iContentId content ID
  1440. *
  1441. * @see BxBaseModGeneralModule::serviceEntityTextBlock
  1442. */
  1443. /**
  1444. * @ref bx_base_general-entity_text_block "entity_text_block"
  1445. */
  1446. public function serviceEntityTextBlock ($iContentId = 0)
  1447. {
  1448. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  1449. }
  1450. /**
  1451. * @page service Service Calls
  1452. * @section bx_base_general Base General
  1453. * @subsection bx_base_general-page_blocks Page Blocks
  1454. * @subsubsection bx_base_general-entity_info entity_info
  1455. *
  1456. * @code bx_srv('bx_posts', 'entity_info', [...]); @endcode
  1457. *
  1458. * Get content info
  1459. * @param $iContentId content ID
  1460. *
  1461. * @see BxBaseModGeneralModule::serviceEntityInfo
  1462. */
  1463. /**
  1464. * @ref bx_base_general-entity_info "entity_info"
  1465. */
  1466. public function serviceEntityInfo ($iContentId = 0, $sDisplay = false)
  1467. {
  1468. return $this->_serviceEntityForm ('viewDataForm', $iContentId, $sDisplay);
  1469. }
  1470. /**
  1471. * @page service Service Calls
  1472. * @section bx_base_general Base General
  1473. * @subsection bx_base_general-page_blocks Page Blocks
  1474. * @subsubsection bx_base_general-entity_info_full entity_info_full
  1475. *
  1476. * @code bx_srv('bx_posts', 'entity_info_full', [...]); @endcode
  1477. *
  1478. * Get full content info
  1479. * @param $iContentId content ID
  1480. *
  1481. * @see BxBaseModGeneralModule::serviceEntityInfoFull
  1482. */
  1483. /**
  1484. * @ref bx_base_general-entity_info_full "entity_info_full"
  1485. */
  1486. public function serviceEntityInfoFull ($iContentId = 0)
  1487. {
  1488. $CNF = &$this->_oConfig->CNF;
  1489. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  1490. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  1491. }
  1492. /**
  1493. * @page service Service Calls
  1494. * @section bx_base_general Base General
  1495. * @subsection bx_base_general-page_blocks Page Blocks
  1496. * @subsubsection bx_base_general-entity_info_extended entity_info_extended
  1497. *
  1498. * @code bx_srv('bx_posts', 'entity_info_extended', [...]); @endcode
  1499. *
  1500. * Get extended content info
  1501. * @param $iContentId content ID
  1502. *
  1503. * @see BxBaseModGeneralModule::serviceEntityInfoExtended
  1504. */
  1505. /**
  1506. * @ref bx_base_general-entity_info_extended "entity_info_extended"
  1507. */
  1508. public function serviceEntityInfoExtended ($iContentId = 0)
  1509. {
  1510. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  1511. }
  1512. /**
  1513. * @page service Service Calls
  1514. * @section bx_base_general Base General
  1515. * @subsection bx_base_general-page_blocks Page Blocks
  1516. * @subsubsection bx_base_general-entity_location entity_location
  1517. *
  1518. * @code bx_srv('bx_posts', 'entity_location', [...]); @endcode
  1519. *
  1520. * Get content location
  1521. * @param $iContentId content ID
  1522. *
  1523. * @see BxBaseModGeneralModule::serviceEntityLocation
  1524. */
  1525. /**
  1526. * @ref bx_base_general-entity_location "entity_location"
  1527. */
  1528. public function serviceEntityLocation ($iContentId = 0)
  1529. {
  1530. $CNF = &$this->_oConfig->CNF;
  1531. $mixedContent = $this->_getContent($iContentId);
  1532. if($mixedContent === false)
  1533. return false;
  1534. list($iContentId, $aContentInfo) = $mixedContent;
  1535. $oFormsHelper = $this->getFormsHelper();
  1536. $oFormView = $oFormsHelper->getObjectFormView();
  1537. if(!$oFormView)
  1538. return false;
  1539. $oFormView->initChecker($aContentInfo);
  1540. if(empty($CNF['FIELD_LOCATION']) || !$oFormView->isInputVisible($CNF['FIELD_LOCATION']))
  1541. return false;
  1542. return $this->_oTemplate->entryLocation ($iContentId);
  1543. }
  1544. /**
  1545. * @page service Service Calls
  1546. * @section bx_base_general Base General
  1547. * @subsection bx_base_general-page_blocks Page Blocks
  1548. * @subsubsection bx_base_general-entity_comments entity_comments
  1549. *
  1550. * @code bx_srv('bx_posts', 'entity_comments', [...]); @endcode
  1551. *
  1552. * Get content comments
  1553. * @param $iContentId content ID
  1554. *
  1555. * @see BxBaseModGeneralModule::serviceEntityComments
  1556. */
  1557. /**
  1558. * @ref bx_base_general-entity_comments "entity_comments"
  1559. */
  1560. public function serviceEntityComments ($iContentId = 0)
  1561. {
  1562. $CNF = &$this->_oConfig->CNF;
  1563. if(empty($CNF['OBJECT_COMMENTS']))
  1564. return '';
  1565. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
  1566. }
  1567. /**
  1568. * @page service Service Calls
  1569. * @section bx_base_general Base General
  1570. * @subsection bx_base_general-page_blocks Page Blocks
  1571. * @subsubsection bx_base_general-entity_attachments entity_attachments
  1572. *
  1573. * @code bx_srv('bx_posts', 'entity_attachments', [...]); @endcode
  1574. *
  1575. * Get content attachments
  1576. * @param $iContentId content ID
  1577. *
  1578. * @see BxBaseModGeneralModule::serviceEntityAttachments
  1579. */
  1580. /**
  1581. * @ref bx_base_general-entity_attachments "entity_attachments"
  1582. */
  1583. public function serviceEntityAttachments ($iContentId = 0)
  1584. {
  1585. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  1586. }
  1587. /**
  1588. * Delete content entry
  1589. * @param $iContentId content id
  1590. * @return error message or empty string on success
  1591. */
  1592. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  1593. {
  1594. $oFormsHelper = $this->getFormsHelper();
  1595. return $oFormsHelper->$sFuncDelete($iContentId);
  1596. }
  1597. /**
  1598. * Edit content entry
  1599. * @param $iContentId content id
  1600. * @param $aValues key value pairs to update
  1601. * @return error message or empty string on success
  1602. */
  1603. public function serviceEditEntity ($iContentId, $aValues)
  1604. {
  1605. $oFormsHelper = $this->getFormsHelper();
  1606. return $oFormsHelper->editData($iContentId, $aValues);
  1607. }
  1608. /**
  1609. * @page service Service Calls
  1610. * @section bx_base_general Base General
  1611. * @subsection bx_base_general-menu Menu
  1612. * @subsubsection bx_base_general-my_entries_actions my_entries_actions
  1613. *
  1614. * @code bx_srv('bx_posts', 'my_entries_actions', [...]); @endcode
  1615. *
  1616. * My entries actions menu
  1617. * @param $iProfileId profiles ID,
  1618. * if omitted it try to get it from 'profile_id' GET param
  1619. *
  1620. * @see BxBaseModGeneralModule::serviceMyEntriesActions
  1621. */
  1622. /**
  1623. * @ref bx_base_general-my_entries_actions "my_entries_actions"
  1624. */
  1625. public function serviceMyEntriesActions ($iProfileId = 0)
  1626. {
  1627. $CNF = &$this->_oConfig->CNF;
  1628. if(empty($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']))
  1629. return false;
  1630. if (!$iProfileId)
  1631. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1632. if (!$iProfileId || !($oProfile = BxDolProfile::getInstance($iProfileId)))
  1633. return false;
  1634. if ($iProfileId != $this->_iProfileId)
  1635. return false;
  1636. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  1637. return $oMenu ? $oMenu->getCode() : false;
  1638. }
  1639. /**
  1640. * @page service Service Calls
  1641. * @section bx_base_general Base General
  1642. * @subsection bx_base_general-menu Menu
  1643. * @subsubsection bx_base_general-entity_all_actions entity_all_actions
  1644. *
  1645. * @code bx_srv('bx_posts', 'entity_all_actions', [...]); @endcode
  1646. *
  1647. * Entry actions and social sharing actions
  1648. * @param $mixedContent content ID
  1649. * @param $aParams additional params
  1650. *
  1651. * @see BxBaseModGeneralModule::serviceEntityAllActions
  1652. */
  1653. /**
  1654. * @ref bx_base_general-entity_all_actions "entity_all_actions"
  1655. */
  1656. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  1657. {
  1658. $mixedResult = $this->getEntryAllActions($mixedContent, $aParams);
  1659. if(bx_is_api())
  1660. return [bx_api_get_block('entity_actions', $mixedResult)];
  1661. else
  1662. return $this->_oTemplate->entryAllActions($mixedResult);
  1663. }
  1664. /**
  1665. * @page service Service Calls
  1666. * @section bx_base_general Base General
  1667. * @subsection bx_base_general-menu Menu
  1668. * @subsubsection bx_base_general-entity_actions entity_actions
  1669. *
  1670. * @code bx_srv('bx_posts', 'entity_actions', [...]); @endcode
  1671. *
  1672. * Entry actions, without social sharing actions
  1673. * @param $iContentId content ID
  1674. *
  1675. * @see BxBaseModGeneralModule::serviceEntityActions
  1676. */
  1677. /**
  1678. * @ref bx_base_general-entity_actions "entity_actions"
  1679. */
  1680. public function serviceEntityActions ($iContentId = 0)
  1681. {
  1682. $iContentId = $this->_getContent($iContentId, false);
  1683. if($iContentId === false)
  1684. return false;
  1685. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  1686. return $oMenu ? $oMenu->getCode() : false;
  1687. }
  1688. /**
  1689. * @page service Service Calls
  1690. * @section bx_base_general Base General
  1691. * @subsection bx_base_general-page_blocks Page Blocks
  1692. * @subsubsection bx_base_general-entity_reports entity_reports
  1693. *
  1694. * @code bx_srv('bx_posts', 'entity_reports', [...]); @endcode
  1695. *
  1696. * Get content reports
  1697. * @param $iContentId content ID
  1698. *
  1699. * @see BxBaseModGeneralModule::serviceEntityReports
  1700. */
  1701. /**
  1702. * @ref bx_base_general-entity_reports "entity_reports"
  1703. */
  1704. public function serviceEntityReports ($iContentId = 0)
  1705. {
  1706. $mixedContent = $this->_getContent($iContentId);
  1707. list($iContentId, $aContentInfo) = $mixedContent;
  1708. if($iContentId === false)
  1709. return false;
  1710. $CNF = &$this->_oConfig->CNF;
  1711. if (!isset($CNF['OBJECT_REPORTS']) || !isset($CNF['OBJECT_NOTES']))
  1712. return false;
  1713. if(!$aContentInfo || !(BxDolAcl::getInstance()->isMemberLevelInSet(192) || (isset($CNF['FIELD_AUTHOR']) && bx_get_logged_profile_id() == $aContentInfo[$CNF['FIELD_AUTHOR']])))
  1714. return false;
  1715. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $iContentId, true);
  1716. if(!$oReport)
  1717. return false;
  1718. return $oReport->getReportedByWithComments($CNF['OBJECT_NOTES']);
  1719. }
  1720. /**
  1721. * @page service Service Calls
  1722. * @section bx_base_general Base General
  1723. * @subsection bx_base_general-page_blocks Page Blocks
  1724. * @subsubsection bx_base_general-reports_count_by_status reports_count_by_status
  1725. *
  1726. * @code bx_srv('bx_posts', 'reports_count_by_status', [...]); @endcode
  1727. *
  1728. * Get number of reports with specified status
  1729. * @param $iStatus status ID
  1730. *
  1731. * @see BxBaseModGeneralModule::serviceReportsCountByStatus
  1732. */
  1733. /**
  1734. * @ref bx_base_general-entity_reports "entity_reports"
  1735. */
  1736. public function serviceReportsCountByStatus ($iStatus)
  1737. {
  1738. $CNF = &$this->_oConfig->CNF;
  1739. if (!isset($CNF['OBJECT_REPORTS']) || !isset($CNF['OBJECT_NOTES']))
  1740. return false;
  1741. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], 0, false);
  1742. return $oReport->getCountByStatus($iStatus);
  1743. }
  1744. /**
  1745. * @page service Service Calls
  1746. * @section bx_base_general Base General
  1747. * @subsection bx_base_general-menu Menu
  1748. * @subsubsection bx_base_general-entity_social_sharing entity_social_sharing
  1749. *
  1750. * @code bx_srv('bx_posts', 'entity_social_sharing', [...]); @endcode
  1751. *
  1752. * Entry social sharing actions
  1753. * @param $mixedContent content ID or array with integer content ID and
  1754. * array with content info, or false
  1755. * @param $aParams array with additional custom params
  1756. * which may overwrite some default values
  1757. *
  1758. * @see BxBaseModGeneralModule::serviceEntitySocialSharing
  1759. */
  1760. /**
  1761. * @ref bx_base_general-entity_social_sharing "entity_social_sharing"
  1762. */
  1763. public function serviceEntitySocialSharing($mixedContent = false, $aParams = array())
  1764. {
  1765. if(!empty($mixedContent)) {
  1766. if(!is_array($mixedContent))
  1767. $mixedContent = array((int)$mixedContent, array());
  1768. }
  1769. else {
  1770. $mixedContent = $this->_getContent();
  1771. if($mixedContent === false)
  1772. return false;
  1773. }
  1774. list($iContentId, $aContentInfo) = $mixedContent;
  1775. $CNF = &$this->_oConfig->CNF;
  1776. $sUri = !empty($aParams['uri']) ? $aParams['uri'] : '';
  1777. if(empty($sUri) && !empty($CNF['URI_VIEW_ENTRY']))
  1778. $sUri = $CNF['URI_VIEW_ENTRY'];
  1779. $sUrl = !empty($sUri) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $iContentId) : '';
  1780. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  1781. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  1782. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  1783. $aMarkers = array(
  1784. 'id' => $iContentId,
  1785. 'module' => $this->_aModule['name'],
  1786. 'url' => bx_absolute_url($sUrl),
  1787. 'title' => $sTitle,
  1788. );
  1789. $iIdThumb = !empty($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  1790. if(empty($iIdThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  1791. $iIdThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  1792. if ($iIdThumb) {
  1793. $sTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : '';
  1794. $sStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : '';
  1795. if(empty($sStorage) && !empty($CNF['OBJECT_STORAGE']))
  1796. $sStorage = $CNF['OBJECT_STORAGE'];
  1797. if(!empty($sTranscoder))
  1798. $o = BxDolTranscoder::getObjectInstance($sTranscoder);
  1799. else if(!empty($sStorage))
  1800. $o = BxDolStorage::getObjectInstance($sStorage);
  1801. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  1802. if($sImgUrl)
  1803. $aMarkers['img_url'] = $sImgUrl;
  1804. }
  1805. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  1806. $oMenu->addMarkers($aMarkers);
  1807. $sMenu = $oMenu->getCode();
  1808. if(empty($sMenu))
  1809. return '';
  1810. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  1811. 'menu' => $sMenu
  1812. ));
  1813. }
  1814. /**
  1815. * Entry context block
  1816. */
  1817. public function serviceEntityContext ($iContentId = 0)
  1818. {
  1819. return $this->_serviceTemplateFunc ('entryContext', $iContentId);
  1820. }
  1821. /**
  1822. * Blocks for lables tree browsing
  1823. */
  1824. public function serviceGetLablesTree()
  1825. {
  1826. $aBreadcrumbs = array();
  1827. $this->_getLablesBreadcrumbsArray(bx_get('label'), $aBreadcrumbs);
  1828. return $this->_getLablesTreeLevel($aBreadcrumbs);
  1829. }
  1830. public function serviceGetLablesBreadcrumbs()
  1831. {
  1832. if (bx_get('label')){
  1833. $aBreadcrumbs = array();
  1834. $this->_getLablesBreadcrumbsArray(bx_process_input(bx_get('label'), BX_DATA_INT), $aBreadcrumbs);
  1835. $aLabels = array();
  1836. foreach (array_reverse($aBreadcrumbs) as $aLabel){
  1837. $aLabels[] = array(
  1838. 'value' => $aLabel['value'],
  1839. 'url' => $this->_getLablesBrowseUrl($aLabel['id'])
  1840. );
  1841. }
  1842. return $this->_oTemplate->parseHtmlByName('labels_breadcrumbs.html', array('bx_repeat:items' => $aLabels));
  1843. }
  1844. return '';
  1845. }
  1846. public function serviceBrowseByLabel()
  1847. {
  1848. $CNF = &$this->_oConfig->CNF;
  1849. if (empty($CNF['OBJECT_METATAGS']))
  1850. return '';
  1851. $sMode = 'recent';
  1852. if(bx_srv('system', 'is_module_content', [$this->_aModule['name']]))
  1853. $sMode = 'public';
  1854. $sClassSearchResult ='SearchResult';
  1855. bx_import($sClassSearchResult, $this->_aModule['name']);
  1856. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1857. $o = new $sClass($sMode, false);
  1858. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  1859. $o->setDisplayEmptyMsg(true);
  1860. $o->setAjaxPaginate(false);
  1861. $o->setUnitParams(array('context' => $sMode));
  1862. if (bx_get('label')){
  1863. $iLabelId = (int)bx_get('label');
  1864. $oLabel = BxDolLabel::getInstance();
  1865. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  1866. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1867. $sTmp =$oMetatags->keywordsSetSearchCondition($o, $aLabel['value']);
  1868. }
  1869. if ($o->isError)
  1870. return '';
  1871. if ($s = $o->processing())
  1872. return $s;
  1873. else
  1874. return '';
  1875. }
  1876. public function serviceBrowseByCategories($sUnitView, $bEmptyMessage, $bAjaxPaginate, $sMode, $iPerPage)
  1877. {
  1878. $CNF = &$this->_oConfig->CNF;
  1879. $sClassSearchResult ='SearchResult';
  1880. bx_import($sClassSearchResult, $this->_aModule['name']);
  1881. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1882. $o = new $sClass($sMode, array('unit_view' => $sUnitView, 'paginate' => array('perPage' => 10, 'start' => 0, 'num' => 11)));
  1883. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  1884. $o->setAjaxPaginate($bAjaxPaginate);
  1885. $o->setCategoryObject('multi');
  1886. $aCategoriesOutput = array();
  1887. $aCategories = BxDolCategories::getInstance()->getData(array('type' => 'by_module_with_num', 'module' => $this->_aModule['name']));
  1888. foreach($aCategories as $aCategory){
  1889. if ($aCategory['num'] > 0){
  1890. $o->setCustomSearchCondition(array('keyword' => $aCategory['value']));
  1891. $o->setPaginatePerPage(2);
  1892. if (!$o->isError){
  1893. $aResult = $o->processing();
  1894. if ($aResult && $aResult['content'] != '')
  1895. $aCategoriesOutput[] = array('name' => _t($aCategory['value']), 'url' => '', 'content' => $aResult['content']);
  1896. }
  1897. }
  1898. }
  1899. return $this->_oTemplate->parseHtmlByName('browse_by_categories.html', array(
  1900. 'bx_repeat:categories' => $aCategoriesOutput,
  1901. ));
  1902. }
  1903. /**
  1904. * Data for Notifications module
  1905. */
  1906. public function serviceGetNotificationsData()
  1907. {
  1908. $sModule = $this->_aModule['name'];
  1909. $sEventPrivacy = $sModule . '_allow_view_event_to';
  1910. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  1911. $sEventPrivacy = '';
  1912. $aResult = [
  1913. 'handlers' => [
  1914. ['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],
  1915. ['group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'],
  1916. ['group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'],
  1917. ['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],
  1918. ['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],
  1919. ['group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'],
  1920. ['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],
  1921. ['group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'],
  1922. ['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],
  1923. ['group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'],
  1924. ['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],
  1925. ['group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'],
  1926. ['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],
  1927. ['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],
  1928. //--- Moderation related: For 'admins'.
  1929. ['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],
  1930. ],
  1931. 'settings' => [
  1932. ['group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => ['follow_member', 'follow_context']],
  1933. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'approved', 'types' => ['personal']],
  1934. ['group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => ['personal', 'follow_member', 'follow_context']],
  1935. ['group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => ['personal']],
  1936. ['group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => ['personal', 'follow_member', 'follow_context']],
  1937. ['group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => ['personal', 'follow_member', 'follow_context']],
  1938. ['group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => ['personal', 'follow_member', 'follow_context']],
  1939. ['group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => ['personal', 'follow_member', 'follow_context']],
  1940. //--- Moderation related: For 'admins'.
  1941. ['group' => 'action_required', 'unit' => $sModule, 'action' => 'pending_approval', 'types' => ['personal']],
  1942. ],
  1943. 'alerts' => [
  1944. ['unit' => $sModule, 'action' => 'added'],
  1945. ['unit' => $sModule, 'action' => 'edited'],
  1946. ['unit' => $sModule, 'action' => 'deleted'],
  1947. ['unit' => $sModule, 'action' => 'approved'],
  1948. ['unit' => $sModule, 'action' => 'commentPost'],
  1949. ['unit' => $sModule, 'action' => 'commentRemoved'],
  1950. ['unit' => $sModule, 'action' => 'replyPost'],
  1951. ['unit' => $sModule, 'action' => 'replyRemoved'],
  1952. ['unit' => $sModule, 'action' => 'doVote'],
  1953. ['unit' => $sModule, 'action' => 'undoVote'],
  1954. ['unit' => $sModule . '_reactions', 'action' => 'doVote'],
  1955. ['unit' => $sModule . '_reactions', 'action' => 'undoVote'],
  1956. ['unit' => $sModule, 'action' => 'doVoteUp'],
  1957. ['unit' => $sModule, 'action' => 'doVoteDown'],
  1958. //--- Moderation related: For 'admins'.
  1959. ['unit' => $sModule, 'action' => 'pending_approval'],
  1960. ]
  1961. ];
  1962. if(!empty($this->_oConfig->CNF['FIELDS_DELAYED_PROCESSING'])) {
  1963. $aResult['handlers'] = array_merge($aResult['handlers'], [
  1964. ['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' => ''],
  1965. ['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' => ''],
  1966. ]);
  1967. $aResult['settings'] = array_merge($aResult['settings'], [
  1968. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => ['personal']],
  1969. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => ['personal']],
  1970. ]);
  1971. $aResult['alerts'] = array_merge($aResult['alerts'], [
  1972. ['unit' => $sModule, 'action' => 'publish_failed'],
  1973. ['unit' => $sModule, 'action' => 'publish_succeeded'],
  1974. ]);
  1975. }
  1976. return $aResult;
  1977. }
  1978. /**
  1979. * Entry post for Notifications module
  1980. */
  1981. public function serviceGetNotificationsPost($aEvent)
  1982. {
  1983. $CNF = &$this->_oConfig->CNF;
  1984. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1985. if(empty($aContentInfo) || !is_array($aContentInfo))
  1986. return [];
  1987. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  1988. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1989. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  1990. return [
  1991. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1992. 'entry_url' => $sEntryUrl,
  1993. 'entry_caption' => $sEntryCaption,
  1994. 'entry_summary' => $sEntrySummary,
  1995. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1996. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  1997. '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.
  1998. /*
  1999. * Custom settings for email and/or push notifications can be provided here.
  2000. * Only necessary parts of 'settings' array can be used.
  2001. *
  2002. 'settings' => array(
  2003. 'email' => array(
  2004. 'template' => '', //--- custom email template
  2005. 'markers' => '', //--- markers to parse email parts (subject, body) with
  2006. 'subject' => '' //--- custom email subject
  2007. ),
  2008. 'push' => array(
  2009. 'subject' => '' //--- custom push notification subject
  2010. )
  2011. )
  2012. */
  2013. ];
  2014. }
  2015. public function serviceGetNotificationsPostPendingApproval($aEvent)
  2016. {
  2017. $aResult = $this->serviceGetNotificationsPost($aEvent);
  2018. /**
  2019. * Unset Entry Author because the notification is addressed to 'admins'.
  2020. */
  2021. if(isset($aResult['entry_author']))
  2022. unset($aResult['entry_author']);
  2023. return $aResult;
  2024. }
  2025. public function serviceGetNotificationsPostApproved($aEvent)
  2026. {
  2027. return $this->serviceGetNotificationsPost($aEvent);
  2028. }
  2029. public function serviceGetNotificationsPostPublishFailed($aEvent)
  2030. {
  2031. return $this->serviceGetNotificationsPost($aEvent);
  2032. }
  2033. public function serviceGetNotificationsPostPublishSucceeded($aEvent)
  2034. {
  2035. return $this->serviceGetNotificationsPost($aEvent);
  2036. }
  2037. /**
  2038. * Entry post comment for Notifications module
  2039. */
  2040. public function serviceGetNotificationsComment($aEvent)
  2041. {
  2042. $CNF = &$this->_oConfig->CNF;
  2043. $iContentId = (int)$aEvent['object_id'];
  2044. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2045. if(empty($aContentInfo) || !is_array($aContentInfo))
  2046. return [];
  2047. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  2048. if(!$oComment || !$oComment->isEnabled())
  2049. return [];
  2050. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  2051. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2052. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2053. $iCommentId = (int)$aEvent['subobject_id'];
  2054. return [
  2055. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2056. 'entry_url' => $sEntryUrl,
  2057. 'entry_caption' => $sEntryCaption,
  2058. 'entry_summary' => $sEntrySummary,
  2059. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  2060. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  2061. 'subentry_url' => bx_absolute_url($oComment->getViewUrl($iCommentId, false), '{bx_url_root}'),
  2062. 'subentry_summary' => $oComment->getViewText($iCommentId),
  2063. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2064. ];
  2065. }
  2066. /**
  2067. * Entry post reply for Notifications module
  2068. */
  2069. public function serviceGetNotificationsReply($aEvent)
  2070. {
  2071. $CNF = &$this->_oConfig->CNF;
  2072. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  2073. if(!$oComment || !$oComment->isEnabled())
  2074. return [];
  2075. $iParentId = (int)$aEvent['object_id'];
  2076. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  2077. if(empty($aParentInfo) || !is_array($aParentInfo))
  2078. return [];
  2079. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  2080. $oComment->init($iObjectId);
  2081. $iCommentId = (int)$aEvent['subobject_id'];
  2082. return [
  2083. 'object_id' => $iObjectId,
  2084. 'entry_sample' => '_cmt_txt_sample_comment_single',
  2085. 'entry_url' => bx_absolute_url($oComment->getViewUrl($iParentId, false), '{bx_url_root}'),
  2086. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  2087. 'entry_summary' => $oComment->getViewText($iParentId),
  2088. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  2089. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  2090. 'subentry_url' => bx_absolute_url($oComment->getViewUrl($iCommentId, false), '{bx_url_root}'),
  2091. 'subentry_summary' => $oComment->getViewText($iCommentId),
  2092. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2093. ];
  2094. }
  2095. /**
  2096. * Entry post vote for Notifications module
  2097. */
  2098. public function serviceGetNotificationsVote($aEvent)
  2099. {
  2100. $CNF = &$this->_oConfig->CNF;
  2101. $iContentId = (int)$aEvent['object_id'];
  2102. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2103. if(empty($aContentInfo) || !is_array($aContentInfo))
  2104. return [];
  2105. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  2106. if(!$oVote || !$oVote->isEnabled())
  2107. return [];
  2108. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  2109. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2110. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2111. return [
  2112. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2113. 'entry_url' => $sEntryUrl,
  2114. 'entry_caption' => $sEntryCaption,
  2115. 'entry_summary' => $sEntrySummary,
  2116. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  2117. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  2118. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2119. ];
  2120. }
  2121. /**
  2122. * Entry post vote for Notifications module
  2123. */
  2124. public function serviceGetNotificationsReaction($aEvent)
  2125. {
  2126. $CNF = &$this->_oConfig->CNF;
  2127. $iContentId = (int)$aEvent['object_id'];
  2128. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2129. if(empty($aContentInfo) || !is_array($aContentInfo))
  2130. return [];
  2131. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContentId);
  2132. if(!$oReaction || !$oReaction->isEnabled())
  2133. return [];
  2134. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  2135. if(empty($aSubentry) || !is_array($aSubentry))
  2136. return [];
  2137. $aSubentrySampleParams = array();
  2138. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  2139. if(!empty($aReaction['title']))
  2140. $aSubentrySampleParams[] = $aReaction['title'];
  2141. else
  2142. $aSubentrySampleParams[] = '_undefined';
  2143. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  2144. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2145. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2146. return [
  2147. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2148. 'entry_url' => $sEntryUrl,
  2149. 'entry_caption' => $sEntryCaption,
  2150. 'entry_summary' => $sEntrySummary,
  2151. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  2152. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  2153. 'subentry_sample_params' => $aSubentrySampleParams,
  2154. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2155. ];
  2156. }
  2157. /**
  2158. * Entry post score -> vote up for Notifications module
  2159. */
  2160. public function serviceGetNotificationsScoreUp($aEvent)
  2161. {
  2162. return $this->_serviceGetNotificationsScore('up', $aEvent);
  2163. }
  2164. /**
  2165. * Entry post score -> vote up for Notifications module
  2166. */
  2167. public function serviceGetNotificationsScoreDown($aEvent)
  2168. {
  2169. return $this->_serviceGetNotificationsScore('down', $aEvent);
  2170. }
  2171. protected function _serviceGetNotificationsScore($sType, $aEvent)
  2172. {
  2173. $CNF = &$this->_oConfig->CNF;
  2174. $iContentId = (int)$aEvent['object_id'];
  2175. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2176. if(empty($aContentInfo) || !is_array($aContentInfo))
  2177. return array();
  2178. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  2179. if(!$oScore || !$oScore->isEnabled())
  2180. return array();
  2181. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  2182. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2183. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2184. return [
  2185. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2186. 'entry_url' => $sEntryUrl,
  2187. 'entry_caption' => $sEntryCaption,
  2188. 'entry_summary' => $sEntrySummary,
  2189. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  2190. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  2191. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2192. ];
  2193. }
  2194. /**
  2195. * Data for Reputation module
  2196. */
  2197. public function serviceGetReputationData()
  2198. {
  2199. $sModule = $this->_aModule['name'];
  2200. $aResult = [
  2201. 'handlers' => [
  2202. ['group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'points_active' => 3, 'points_passive' => 0],
  2203. ['group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted', 'points_active' => -3, 'points_passive' => 0],
  2204. ['group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'points_active' => 2, 'points_passive' => 1],
  2205. ['group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved', 'points_active' => -2, 'points_passive' => -1],
  2206. ['group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'points_active' => 1, 'points_passive' => 1],
  2207. ['group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote', 'points_active' => -1, 'points_passive' => -1],
  2208. ['group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'points_active' => 1, 'points_passive' => 1],
  2209. ['group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote', 'points_active' => -1, 'points_passive' => -1],
  2210. ['group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'points_active' => 1, 'points_passive' => 1],
  2211. ['group' => $sModule . '_score_up', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVoteUp', 'points_active' => -1, 'points_passive' => -1],
  2212. ['group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'points_active' => 1, 'points_passive' => -1],
  2213. ['group' => $sModule . '_score_down', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVoteDown', 'points_active' => -1, 'points_passive' => 1],
  2214. ],
  2215. 'alerts' => [
  2216. ['unit' => $sModule, 'action' => 'added'],
  2217. ['unit' => $sModule, 'action' => 'deleted'],
  2218. ['unit' => $sModule, 'action' => 'commentPost'],
  2219. ['unit' => $sModule, 'action' => 'commentRemoved'],
  2220. ['unit' => $sModule, 'action' => 'doVote'],
  2221. ['unit' => $sModule, 'action' => 'undoVote'],
  2222. ['unit' => $sModule . '_reactions', 'action' => 'doVote'],
  2223. ['unit' => $sModule . '_reactions', 'action' => 'undoVote'],
  2224. ['unit' => $sModule, 'action' => 'doVoteUp'],
  2225. ['unit' => $sModule, 'action' => 'undoVoteUp'],
  2226. ['unit' => $sModule, 'action' => 'doVoteDown'],
  2227. ['unit' => $sModule, 'action' => 'undoVoteDown'],
  2228. ]
  2229. ];
  2230. return $aResult;
  2231. }
  2232. /**
  2233. * Data for Timeline module
  2234. */
  2235. public function serviceGetTimelineData()
  2236. {
  2237. $sModule = $this->_aModule['name'];
  2238. return array(
  2239. 'handlers' => array(
  2240. 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' => ''),
  2241. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  2242. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  2243. ),
  2244. 'alerts' => array(
  2245. array('unit' => $sModule, 'action' => 'added'),
  2246. array('unit' => $sModule, 'action' => 'edited'),
  2247. array('unit' => $sModule, 'action' => 'deleted'),
  2248. )
  2249. );
  2250. }
  2251. /**
  2252. * Entry post for Timeline module
  2253. */
  2254. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  2255. {
  2256. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  2257. if(empty($aContentInfo) || !is_array($aContentInfo))
  2258. return false;
  2259. $CNF = &$this->_oConfig->CNF;
  2260. if((!empty($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active') || (!empty($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active'))
  2261. return false;
  2262. $bCache = true;
  2263. $iUserId = $this->getUserId();
  2264. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  2265. $iAuthorIdAbs = abs($iAuthorId);
  2266. /**
  2267. * Don't show anonymous posts on the post's owner timeline
  2268. * and don't cache them when they're viewed by their authors.
  2269. */
  2270. if($iAuthorId < 0 && ((is_numeric($aEvent['owner_id']) && $iAuthorIdAbs == (int)$aEvent['owner_id']) || (is_array($aEvent['owner_id']) && in_array($iAuthorIdAbs, $aEvent['owner_id'])))) {
  2271. if($iAuthorIdAbs != $iUserId)
  2272. return false;
  2273. $bCache = false;
  2274. }
  2275. //--- Views
  2276. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2277. $aViews = array();
  2278. if ($oViews && $oViews->isEnabled())
  2279. $aViews = array(
  2280. 'system' => $CNF['OBJECT_VIEWS'],
  2281. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2282. 'count' => $aContentInfo['views']
  2283. );
  2284. //--- Votes
  2285. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2286. $aVotes = array();
  2287. if ($oVotes && $oVotes->isEnabled())
  2288. $aVotes = array(
  2289. 'system' => $CNF['OBJECT_VOTES'],
  2290. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2291. 'count' => $aContentInfo['votes']
  2292. );
  2293. //--- Reactions
  2294. $oReactions = isset($CNF['OBJECT_REACTIONS']) ? BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2295. $aReactions = array();
  2296. if ($oReactions && $oReactions->isEnabled())
  2297. $aReactions = array(
  2298. 'system' => $CNF['OBJECT_REACTIONS'],
  2299. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2300. 'count' => $aContentInfo['rvotes']
  2301. );
  2302. //--- Scores
  2303. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2304. $aScores = array();
  2305. if ($oScores && $oScores->isEnabled())
  2306. $aScores = array(
  2307. 'system' => $CNF['OBJECT_SCORES'],
  2308. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2309. 'score' => $aContentInfo['score']
  2310. );
  2311. //--- Reports
  2312. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2313. $aReports = array();
  2314. if ($oReports && $oReports->isEnabled())
  2315. $aReports = array(
  2316. 'system' => $CNF['OBJECT_REPORTS'],
  2317. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2318. 'count' => $aContentInfo['reports']
  2319. );
  2320. //--- Comments
  2321. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2322. $aComments = array();
  2323. if($oCmts && $oCmts->isEnabled())
  2324. $aComments = array(
  2325. 'system' => $CNF['OBJECT_COMMENTS'],
  2326. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2327. 'count' => $aContentInfo['comments']
  2328. );
  2329. //--- Title & Description
  2330. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  2331. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  2332. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  2333. $iOwnerId = $iAuthorIdAbs;
  2334. if(isset($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0)
  2335. $iOwnerId = abs($aEvent['object_privacy_view']);
  2336. $aContent = $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  2337. if(isset($aContent['_cache'])) {
  2338. if($bCache)
  2339. $bCache = (bool)$aContent['_cache'];
  2340. unset($aContent['_cache']);
  2341. }
  2342. return [
  2343. '_cache' => $bCache,
  2344. 'owner_id' => $iOwnerId,
  2345. 'object_owner_id' => $iAuthorId,
  2346. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  2347. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  2348. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  2349. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  2350. 'url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']])),
  2351. 'content' => $aContent, //a string to display or array to parse default template before displaying.
  2352. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  2353. 'views' => $aViews,
  2354. 'votes' => $aVotes,
  2355. 'reactions' => $aReactions,
  2356. 'scores' => $aScores,
  2357. 'reports' => $aReports,
  2358. 'comments' => $aComments,
  2359. 'title' => $sTitle, //may be empty.
  2360. 'description' => '' //may be empty.
  2361. ];
  2362. }
  2363. public function serviceGetTimelinePostAllowedView($aEvent)
  2364. {
  2365. $iContentId = (int)$aEvent['object_id'];
  2366. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2367. if(empty($aContentInfo) || !is_array($aContentInfo))
  2368. return _t('_sys_txt_access_denied');
  2369. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  2370. }
  2371. /**
  2372. * Check particular action permission without content
  2373. * @param $sAction action to check, for example: Browse, Add
  2374. * @param $iContentId content ID
  2375. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  2376. */
  2377. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  2378. {
  2379. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  2380. if (!method_exists($this, $sMethod))
  2381. return _t('_sys_request_method_not_found_cpt');
  2382. return $this->$sMethod($isPerformAction);
  2383. }
  2384. /**
  2385. * Check particular action permission with content
  2386. * @param $sAction action to check, for example: View, Edit
  2387. * @param $iContentId content ID
  2388. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  2389. */
  2390. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  2391. {
  2392. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  2393. return _t('_sys_request_page_not_found_cpt');
  2394. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  2395. if (!method_exists($this, $sMethod))
  2396. return _t('_sys_request_method_not_found_cpt');
  2397. return $this->$sMethod($aContentInfo, $isPerformAction);
  2398. }
  2399. /**
  2400. * Check particular action permission with content for specified profile
  2401. * @param $sAction action to check, for example: View, Edit
  2402. * @param $iContentId content ID
  2403. * @param $iProfileId profile ID which the permissions to be cheked for
  2404. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  2405. */
  2406. public function serviceCheckAllowedWithContentForProfile($sAction, $iContentId, $iProfileId, $isPerformAction = false)
  2407. {
  2408. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  2409. return _t('_sys_request_page_not_found_cpt');
  2410. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction) . 'ForProfile';
  2411. if (!method_exists($this, $sMethod))
  2412. return _t('_sys_request_method_not_found_cpt');
  2413. return $this->$sMethod($aContentInfo, $iProfileId, $isPerformAction);
  2414. }
  2415. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  2416. {
  2417. //negative id used in comments for reports
  2418. if ($iContentId < 0)
  2419. return CHECK_ACTION_RESULT_ALLOWED;
  2420. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  2421. }
  2422. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  2423. {
  2424. //negative id used in comments for reports
  2425. if ($iContentId < 0)
  2426. return CHECK_ACTION_RESULT_ALLOWED;
  2427. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  2428. }
  2429. public function serviceGetContentOwnerProfileId ($iContentId)
  2430. {
  2431. $CNF = &$this->_oConfig->CNF;
  2432. // file owner must be author of the content or profile itself in case of profile based module
  2433. if ($iContentId) {
  2434. $sModule = $this->getName();
  2435. if ($this instanceof iBxDolProfileService && BxDolService::call($sModule, 'act_as_profile')) {
  2436. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  2437. }
  2438. else {
  2439. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2440. $iContentAuthor = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  2441. if($iContentAuthor < 0)
  2442. $iContentAuthor = abs($iContentAuthor);
  2443. $oProfile = $aContentInfo ? BxDolProfile::getInstance($iContentAuthor) : null;
  2444. }
  2445. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  2446. }
  2447. else
  2448. $iProfileId = bx_get_logged_profile_id();
  2449. return $iProfileId;
  2450. }
  2451. public function serviceGetBadges($iContentId, $bIsSingle = false, $bIsCompact = false)
  2452. {
  2453. $sModule = $this->getName();
  2454. $oBadges = BxDolBadges::getInstance();
  2455. $aBadges = $oBadges->getData(array(
  2456. 'type' => ($bIsSingle ? 'by_module&object2_single' : 'by_module&object2'),
  2457. 'module' => $sModule,
  2458. 'object_id' => $iContentId
  2459. ));
  2460. $sResult = false;
  2461. /**
  2462. * @hooks
  2463. * @hookdef hook-system-get_badges 'system', 'get_badges' - hook to override bages assigned to an entry (content)
  2464. * - $unit_name - equals `system`
  2465. * - $action - equals `get_badges`
  2466. * - $object_id - not used
  2467. * - $sender_id - not used
  2468. * - $extra_params - array of additional params with the following array keys:
  2469. * - `module` - [string] module name
  2470. * - `content_id` - [int] content id
  2471. * - `is_single` - [boolean] only one badge can be used or not
  2472. * - `is_compact` - [boolean] badge in compact mode or not
  2473. * - `badges` - [array] a list of all badges assigned to the content
  2474. * - `override_result` - [string] or [boolean] by ref, if string is returned then it will be used as resulting badges code, can be overridden in hook processing
  2475. * @hook @ref hook-system-get_badges
  2476. */
  2477. bx_alert('system', 'get_badges', 0, 0, [
  2478. 'module' => $sModule,
  2479. 'content_id' => $iContentId,
  2480. 'is_single' => $bIsSingle,
  2481. 'is_compact' => $bIsCompact,
  2482. 'badges' => $aBadges,
  2483. 'override_result' => &$sResult
  2484. ]);
  2485. if($sResult !== false)
  2486. return $sResult;
  2487. if(empty($aBadges) || !is_array($aBadges))
  2488. return '';
  2489. if (bx_is_api()){
  2490. return $aBadges;
  2491. }
  2492. if($bIsSingle)
  2493. return BxDolService::call('system', 'get_badge', array($aBadges[0], $bIsCompact), 'TemplServices');
  2494. $aBadgesOutput = array();
  2495. foreach($aBadges as $aBadge)
  2496. $aBadgesOutput[] = array('badge' => BxDolService::call('system', 'get_badge', array($aBadge, $bIsCompact), 'TemplServices'));
  2497. return $this->_oTemplate->parseHtmlByName('badges.html', array(
  2498. 'bx_repeat:items' => $aBadgesOutput,
  2499. ));
  2500. }
  2501. /**
  2502. * @page service Service Calls
  2503. * @section bx_base_general Base General
  2504. * @subsection bx_base_general-page_blocks Page Blocks
  2505. * @subsubsection bx_base_general-categories_multi_list categories_multi_list
  2506. *
  2507. * @code bx_srv('bx_posts', 'categories_multi_list', [...]); @endcode
  2508. *
  2509. * Display multi-categorories block with number of posts in each category
  2510. * @param $bDisplayEmptyCats display empty categories
  2511. *
  2512. * @see BxBaseModGeneralModule::serviceCategoriesMultiList
  2513. */
  2514. /**
  2515. * @ref bx_base_general-categories_multi_list "categories_multi_list"
  2516. */
  2517. public function serviceCategoriesMultiList($bDisplayEmptyCats = true)
  2518. {
  2519. $aContextInfo = bx_get_page_info();
  2520. $mProfileContextId = false;
  2521. if ($aContextInfo !== false)
  2522. $mProfileContextId = $aContextInfo['context_profile_id'];
  2523. $oCategories = BxDolCategories::getInstance();
  2524. if ($mProfileContextId)
  2525. $aCats = $oCategories->getData([
  2526. 'type' => 'by_module&context_with_num',
  2527. 'module' => $this->getName(),
  2528. 'context_id' => $mProfileContextId
  2529. ]);
  2530. else{
  2531. $aCats = $oCategories->getData([
  2532. 'type' => 'by_module_with_num',
  2533. 'module' => $this->getName()
  2534. ]);
  2535. }
  2536. $aVars = array('bx_repeat:cats' => array());
  2537. foreach ($aCats as $oCat) {
  2538. $sValue = $oCat['value'];
  2539. $iNum = $oCat['num'];
  2540. $aVars['bx_repeat:cats'][] = array(
  2541. 'url' => $oCategories->getUrl($this->getName(), $sValue, $mProfileContextId ? '&context_id=' . $mProfileContextId : ''),
  2542. 'name' => _t($sValue),
  2543. 'value' => $sValue,
  2544. 'num' => $iNum,
  2545. );
  2546. }
  2547. if (!$aVars['bx_repeat:cats'])
  2548. return '';
  2549. return $this->_oTemplate->parseHtmlByName('category_list_multi.html', $aVars);
  2550. }
  2551. /**
  2552. * ======
  2553. * PERMISSION METHODS
  2554. * ======
  2555. */
  2556. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  2557. {
  2558. $mixedResult = $this->_serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  2559. /**
  2560. * @hooks
  2561. * @hookdef hook-system-check_allowed_view 'system', 'check_allowed_view' - hook to override the result of checking whether 'view' action is allowed or not to specified profile
  2562. * - $unit_name - equals `system`
  2563. * - $action - equals `check_allowed_view`
  2564. * - $object_id - not used
  2565. * - $sender_id - not used
  2566. * - $extra_params - array of additional params with the following array keys:
  2567. * - `module` - [string] module name
  2568. * - `content_info` - [array] content info array as key&value pairs
  2569. * - `profile_id` - [boolean] or [int] profile id to be checked the availability of the action to
  2570. * - `override_result` - [string] or [int] by ref, check action result, can be overridden in hook processing. Return string with an error if action isn't allowed or CHECK_ACTION_RESULT_ALLOWED, @see BxDolAcl
  2571. * @hook @ref hook-system-check_allowed_view
  2572. */
  2573. bx_alert('system', 'check_allowed_view', 0, 0, [
  2574. 'module' => $this->getName(),
  2575. 'content_info' => $aDataEntry,
  2576. 'profile_id' => $iProfileId,
  2577. 'override_result' => &$mixedResult
  2578. ]);
  2579. return $mixedResult;
  2580. }
  2581. public function checkAllowedSetThumb ($iContentId = 0)
  2582. {
  2583. return CHECK_ACTION_RESULT_ALLOWED;
  2584. }
  2585. /**
  2586. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2587. */
  2588. public function checkAllowedBrowse ()
  2589. {
  2590. $mixedResult = null;
  2591. /**
  2592. * @hooks
  2593. * @hookdef hook-system-check_allowed_browse 'system', 'check_allowed_browse' - hook to override the result of checking whether 'browse' action is allowed or not to currently logged in profile
  2594. * It's equivalent to @ref hook-system-check_allowed_view
  2595. * except `content_info` parameter in $extra_params is missing
  2596. * @hook @ref hook-system-check_allowed_browse
  2597. */
  2598. bx_alert('system', 'check_allowed_browse', 0, 0, [
  2599. 'module' => $this->getName(),
  2600. 'profile_id' => $this->_iProfileId,
  2601. 'override_result' => &$mixedResult
  2602. ]);
  2603. if($mixedResult !== null)
  2604. return $mixedResult;
  2605. return CHECK_ACTION_RESULT_ALLOWED;
  2606. }
  2607. /**
  2608. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2609. */
  2610. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  2611. {
  2612. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  2613. }
  2614. /**
  2615. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2616. */
  2617. public function checkAllowedViewForProfile ($aDataEntry, $iProfileId, $isPerformAction = false)
  2618. {
  2619. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  2620. }
  2621. /**
  2622. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2623. */
  2624. public function checkAllowedAdd ($isPerformAction = false)
  2625. {
  2626. // check ACL
  2627. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  2628. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2629. return $aCheck[CHECK_ACTION_MESSAGE];
  2630. return CHECK_ACTION_RESULT_ALLOWED;
  2631. }
  2632. /**
  2633. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2634. */
  2635. public function checkAllowedApprove ($aDataEntry, $isPerformAction = false)
  2636. {
  2637. $CNF = &$this->_oConfig->CNF;
  2638. $sError = '_sys_txt_access_denied';
  2639. if($this->_oConfig->isAutoApproveEnabled())
  2640. return _t($sError);
  2641. if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_GENERAL_STATUS_PENDING)
  2642. return _t($sError);
  2643. // moderator always have access
  2644. if ($this->_isModerator($isPerformAction))
  2645. return CHECK_ACTION_RESULT_ALLOWED;
  2646. // check for context's admins
  2647. if (!empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  2648. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]);
  2649. if ($oProfile){
  2650. $sModule = $oProfile->getModule();
  2651. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  2652. $oModule = BxDolModule::getInstance($sModule);
  2653. // check for context's extra roles with rights
  2654. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  2655. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  2656. if ($bResult !== NULL) return $bResult;
  2657. }
  2658. // if allowed edit a group then allowed to edit anything inside its context
  2659. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  2660. return CHECK_ACTION_RESULT_ALLOWED;
  2661. }
  2662. }
  2663. }
  2664. return _t($sError);
  2665. }
  2666. /**
  2667. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2668. */
  2669. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  2670. {
  2671. // moderator and owner always have access
  2672. if ($this->isEntryAuthor($aDataEntry, $this->_iProfileId) || $this->_isModerator($isPerformAction))
  2673. return CHECK_ACTION_RESULT_ALLOWED;
  2674. // check for context's admins
  2675. if (!empty($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  2676. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  2677. if ($oProfile){
  2678. $sModule = $oProfile->getModule();
  2679. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  2680. $oModule = BxDolModule::getInstance($sModule);
  2681. // check for context's extra roles with rights
  2682. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  2683. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  2684. if ($bResult !== NULL) return $bResult;
  2685. }
  2686. // if allowed edit a group then allowed to edit anything inside its context
  2687. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  2688. return CHECK_ACTION_RESULT_ALLOWED;
  2689. }
  2690. }
  2691. }
  2692. return _t('_sys_txt_access_denied');
  2693. }
  2694. /**
  2695. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2696. */
  2697. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  2698. {
  2699. // moderator always has access
  2700. if ($this->_isAdministrator($isPerformAction))
  2701. return CHECK_ACTION_RESULT_ALLOWED;
  2702. // check ACL
  2703. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  2704. if ($this->isEntryAuthor($aDataEntry, $this->_iProfileId) && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2705. return CHECK_ACTION_RESULT_ALLOWED;
  2706. // check for context's admins
  2707. if (isset($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0){
  2708. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  2709. if ($oProfile){
  2710. $sModule = $oProfile->getModule();
  2711. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  2712. $oModule = BxDolModule::getInstance($sModule);
  2713. // check for context's extra roles with rights
  2714. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  2715. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'delete_any');
  2716. if ($bResult !== NULL) return $bResult;
  2717. }
  2718. // if allowed delete a group then allowed to delete anything inside its context
  2719. if(isset($aEntity) && $oModule->checkAllowedDelete($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  2720. return CHECK_ACTION_RESULT_ALLOWED;
  2721. }
  2722. }
  2723. }
  2724. return _t('_sys_txt_access_denied');
  2725. }
  2726. /**
  2727. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2728. */
  2729. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  2730. {
  2731. // admin always has access
  2732. if (isAdmin())
  2733. return CHECK_ACTION_RESULT_ALLOWED;
  2734. // check ACL
  2735. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  2736. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2737. return $aCheck[CHECK_ACTION_MESSAGE];
  2738. return CHECK_ACTION_RESULT_ALLOWED;
  2739. }
  2740. /**
  2741. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2742. */
  2743. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  2744. {
  2745. return $this->checkAllowedEditAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  2746. }
  2747. /**
  2748. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2749. */
  2750. public function checkAllowedDeleteAnyEntry ($isPerformAction = false)
  2751. {
  2752. return $this->checkAllowedDeleteAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  2753. }
  2754. /**
  2755. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2756. */
  2757. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  2758. {
  2759. if(!$iProfileId)
  2760. $iProfileId = $this->_iProfileId;
  2761. $aCheck = checkActionModule($iProfileId, MEMBERSHIP_ACTION_EDIT_ANY_ENTRY, $this->getName(), $isPerformAction);
  2762. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2763. return CHECK_ACTION_RESULT_ALLOWED;
  2764. return _t('_sys_txt_access_denied');
  2765. }
  2766. /**
  2767. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2768. */
  2769. public function checkAllowedDeleteAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  2770. {
  2771. if(!$iProfileId)
  2772. $iProfileId = $this->_iProfileId;
  2773. $aCheck = checkActionModule($iProfileId, MEMBERSHIP_ACTION_DELETE_ANY_ENTRY, $this->getName(), $isPerformAction);
  2774. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2775. return CHECK_ACTION_RESULT_ALLOWED;
  2776. return _t('_sys_txt_access_denied');
  2777. }
  2778. /**
  2779. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2780. */
  2781. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  2782. {
  2783. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  2784. }
  2785. /**
  2786. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2787. */
  2788. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  2789. {
  2790. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  2791. }
  2792. protected function _serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId)
  2793. {
  2794. $CNF = &$this->_oConfig->CNF;
  2795. if(!$iProfileId)
  2796. $iProfileId = $this->_iProfileId;
  2797. if(empty($aDataEntry) || !is_array($aDataEntry))
  2798. return _t('_sys_txt_not_found');
  2799. // moderator and owner always have access
  2800. if(!empty($iProfileId) && (abs($aDataEntry[$CNF['FIELD_AUTHOR']]) == (int)$iProfileId || $this->_isModeratorForProfile($isPerformAction, $iProfileId)))
  2801. return CHECK_ACTION_RESULT_ALLOWED;
  2802. // check ACL
  2803. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  2804. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2805. return $aCheck[CHECK_ACTION_MESSAGE];
  2806. // check privacy
  2807. if(!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  2808. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  2809. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  2810. return _t('_sys_access_denied_to_private_content');
  2811. }
  2812. return CHECK_ACTION_RESULT_ALLOWED;
  2813. }
  2814. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  2815. {
  2816. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  2817. return bx_is_api() ? [bx_api_get_msg($sMsg)] : MsgBox($sMsg);
  2818. bx_import($sClassSearchResult, $this->_aModule);
  2819. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  2820. $o = new $sClass($sMode, $aParams);
  2821. $o->setDesignBoxTemplateId($iDesignBox);
  2822. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  2823. $o->setAjaxPaginate($bAjaxPaginate);
  2824. $o->setUnitParams(array('context' => $sMode));
  2825. if (isset($aParams['condition']) && is_array($aParams['condition']))
  2826. $o->setCustomCurrentCondition($aParams['condition']);
  2827. if ($o->isError)
  2828. return '';
  2829. if ($s = $o->processing())
  2830. return bx_is_api() ? [bx_api_get_block('browse', $s)] : $s;
  2831. else
  2832. return '';
  2833. }
  2834. /**
  2835. * Shows a list of profiles.
  2836. */
  2837. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4, $aAdditionalParams = array())
  2838. {
  2839. // get paginate object
  2840. $oPaginate = new BxTemplPaginate(array(
  2841. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . bx_js_string(json_encode($aAdditionalParams)) . ");",
  2842. 'num' => count($aProfiles),
  2843. 'per_page' => $iLimit,
  2844. 'start' => $iStart,
  2845. ));
  2846. // remove last item from connection array, because we've got one more item for pagination calculations only
  2847. if (count($aProfiles) > $iLimit)
  2848. array_pop($aProfiles);
  2849. // get profiles HTML
  2850. $s = '';
  2851. foreach ($aProfiles as $mixedProfile) {
  2852. $bProfile = is_array($mixedProfile);
  2853. $oProfile = BxDolProfile::getInstance($bProfile ? (int)$mixedProfile['id'] : (int)$mixedProfile);
  2854. if(!$oProfile)
  2855. continue;
  2856. $aUnitParams = array('template' => array('name' => 'unit', 'size' => 'thumb'));
  2857. if(BxDolModule::getInstance($oProfile->getModule()) instanceof BxBaseModGroupsModule)
  2858. $aUnitParams['template']['name'] = 'unit_wo_cover';
  2859. if($bProfile && is_array($mixedProfile['info']))
  2860. $aUnitParams['template']['vars'] = $mixedProfile['info'];
  2861. $s .= $oProfile->getUnit(0, $aUnitParams);
  2862. }
  2863. $aTmplVarsPaginate = [];
  2864. if($iStart || $oPaginate->getNum() > $iLimit)
  2865. $aTmplVarsPaginate = ['paginate' => $oPaginate->getSimplePaginate()];
  2866. return $this->_oTemplate->parseHtmlByName('browse_quick.html', array(
  2867. 'code' => $s,
  2868. 'bx_if:show_paginate' => [
  2869. 'condition' => !empty($aTmplVarsPaginate),
  2870. 'content' => $aTmplVarsPaginate
  2871. ]
  2872. ));
  2873. }
  2874. // ====== COMMON METHODS
  2875. public function onPublished($iContentId)
  2876. {
  2877. $CNF = &$this->_oConfig->CNF;
  2878. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2879. if(!$aContentInfo)
  2880. return;
  2881. /*
  2882. * Process metas.
  2883. * Note. It's essential to process metas a the very end,
  2884. * because all data related to an entry should be already
  2885. * processed and are ready to be passed to alert.
  2886. */
  2887. $this->processMetasAdd($iContentId);
  2888. $this->alertAfterAdd($aContentInfo);
  2889. }
  2890. public function onFailed($iContentId)
  2891. {
  2892. $CNF = &$this->_oConfig->CNF;
  2893. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2894. if(!$aContentInfo)
  2895. return;
  2896. /**
  2897. * @hooks
  2898. * @hookdef hook-bx_base_general-failed '{module_name}', 'failed' - hook after content creation when publishing was failed
  2899. * - $unit_name - module name
  2900. * - $action - equals `failed`
  2901. * - $object_id - content id
  2902. * - $sender_id - content author profile id
  2903. * - $extra_params - array of additional params with the following array keys:
  2904. * - `object_author_id` - [int] content author profile id
  2905. * @hook @ref hook-bx_base_general-failed
  2906. */
  2907. bx_alert($this->getName(), 'failed', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], [
  2908. 'object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]
  2909. ]);
  2910. }
  2911. public function onApprove($mixedContent)
  2912. {
  2913. $CNF = &$this->_oConfig->CNF;
  2914. if(!is_array($mixedContent))
  2915. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  2916. $this->alertAfterApprove($mixedContent);
  2917. $this->onPublished($mixedContent[$CNF['FIELD_ID']]);
  2918. }
  2919. public function onUpdateImage($iContentId, $sFiledName, $sFiledValue, $iProfileId = 0) {}
  2920. public function alertAfterAdd($aContentInfo) {}
  2921. public function alertAfterEdit($aContentInfo) {}
  2922. public function alertAfterApprove($aContentInfo)
  2923. {
  2924. $CNF = &$this->_oConfig->CNF;
  2925. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  2926. $sModule = $this->getName();
  2927. $aParams = $this->_alertParams($aContentInfo);
  2928. /**
  2929. * @hooks
  2930. * @hookdef hook-bx_base_general-approved '{module_name}', 'approved' - hook when module content has been approved
  2931. * - $unit_name - module name
  2932. * - $action - equals `approved`
  2933. * - $object_id - content id
  2934. * - $sender_id - not used, always `false`
  2935. * - $extra_params - array of additional params with the following array keys:
  2936. * - `source` - [string] uniq string for particular content in the following format `{module}_{content}`
  2937. * - `object_author_id` - [int] content author profile id
  2938. * @hook @ref hook-bx_base_general-approved
  2939. */
  2940. bx_alert($sModule, 'approved', $iId, false, $aParams);
  2941. }
  2942. /**
  2943. * Get array of params to be passed in Add/Edit Alert.
  2944. */
  2945. protected function _alertParams($aContentInfo)
  2946. {
  2947. $CNF = &$this->_oConfig->CNF;
  2948. return [
  2949. 'source' => $this->_oConfig->getName() . '_' . (int)$aContentInfo[$CNF['FIELD_ID']],
  2950. 'object_author_id' => (int)$aContentInfo[$CNF['FIELD_AUTHOR']]
  2951. ];
  2952. }
  2953. public function processMetasAdd($iContentId)
  2954. {
  2955. $CNF = &$this->_oConfig->CNF;
  2956. if(empty($CNF['OBJECT_METATAGS']))
  2957. return false;
  2958. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2959. $bFldStatus = !empty($CNF['FIELD_STATUS']);
  2960. $bFldStatusAdmin = !empty($CNF['FIELD_STATUS_ADMIN']);
  2961. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  2962. if(!$bContentInfo)
  2963. return false;
  2964. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2965. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  2966. $sKey = 'FIELD_LOCATION';
  2967. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2968. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  2969. if(!empty($aLocation) && is_array($aLocation))
  2970. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  2971. }
  2972. $sKey = 'FIELD_LABELS';
  2973. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2974. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  2975. if(!empty($aLabels) && is_array($aLabels))
  2976. foreach ($aLabels as $sLabel) {
  2977. if(!preg_match("/(\pL[\pL\pN_]+)/u", $sLabel))
  2978. continue;
  2979. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  2980. }
  2981. }
  2982. return true;
  2983. }
  2984. public function processMetasEdit($iContentId, $oForm)
  2985. {
  2986. $CNF = &$this->_oConfig->CNF;
  2987. if(empty($CNF['OBJECT_METATAGS']))
  2988. return false;
  2989. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2990. $bFldStatus = isset($CNF['FIELD_STATUS']);
  2991. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  2992. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  2993. if(!$bContentInfo)
  2994. return false;
  2995. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2996. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']);
  2997. $sKey = 'FIELD_LOCATION';
  2998. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2999. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  3000. if(!empty($aLocation) && is_array($aLocation))
  3001. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  3002. }
  3003. $sKey = 'FIELD_LABELS';
  3004. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  3005. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  3006. if(!empty($aLabels) && is_array($aLabels))
  3007. foreach ($aLabels as $sLabel) {
  3008. if(!preg_match("/(\pL[\pL\pN_]+)/u", $sLabel))
  3009. continue;
  3010. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  3011. }
  3012. }
  3013. return true;
  3014. }
  3015. public function addAttachLink($aValues, $sDisplay = false)
  3016. {
  3017. $CNF = &$this->_oConfig->CNF;
  3018. if(!$sDisplay)
  3019. $sDisplay = $CNF['OBJECT_FORM_ATTACH_LINK_DISPLAY_ADD'];
  3020. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ATTACH_LINK'], $sDisplay, $this->_oTemplate);
  3021. if(!$oForm)
  3022. return array('message' => '_sys_txt_error_occured');
  3023. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  3024. $oForm->aParams['csrf']['disable'] = true;
  3025. if(!empty($oForm->aParams['db']['submit_name'])) {
  3026. $sSubmitName = $oForm->aParams['db']['submit_name'];
  3027. if(!isset($oForm->aInputs[$sSubmitName])) {
  3028. if(isset($oForm->aInputs[$CNF['FIELD_ATTACH_LINK_CONTROLS']]))
  3029. foreach($oForm->aInputs[$CNF['FIELD_ATTACH_LINK_CONTROLS']] as $mixedIndex => $aInput) {
  3030. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  3031. continue;
  3032. $aValues[$sSubmitName] = $aInput['value'];
  3033. }
  3034. }
  3035. else
  3036. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  3037. }
  3038. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  3039. $oForm->initChecker(array(), $aValues);
  3040. if(!$oForm->isSubmittedAndValid())
  3041. return array('message' => '_sys_txt_error_occured');
  3042. return $this->_addLink($oForm);
  3043. }
  3044. public function getFormAttachLink($iContentId = 0)
  3045. {
  3046. $CNF = &$this->_oConfig->CNF;
  3047. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ATTACH_LINK'], $CNF['OBJECT_FORM_ATTACH_LINK_DISPLAY_ADD'], $this->_oTemplate);
  3048. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  3049. $oForm->aInputs[$CNF['FIELD_ATTACH_LINK_CONTENT_ID']]['value'] = $iContentId;
  3050. $oForm->aInputs[$CNF['FIELD_ATTACH_LINK_URL']]['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  3051. $oForm->initChecker();
  3052. if($oForm->isSubmittedAndValid())
  3053. return $this->_addLink($oForm);
  3054. return ['form' => $oForm->getCode(), 'form_id' => $oForm->id];
  3055. }
  3056. protected function _addLink(&$oForm)
  3057. {
  3058. $CNF = &$this->_oConfig->CNF;
  3059. $iUserId = $this->getUserId();
  3060. $iContentId = (int)$oForm->getCleanValue($CNF['FIELD_ATTACH_LINK_CONTENT_ID']);
  3061. $sLink = rtrim($oForm->getCleanValue('url'), '/');
  3062. $sHost = parse_url($sLink, PHP_URL_HOST);
  3063. if($sHost && is_private_ip(gethostbyname($sHost)))
  3064. return ['message' => _t('_sys_txt_error_occured')];
  3065. $aMatches = [];
  3066. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  3067. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  3068. $aSiteInfo = bx_get_site_info($sLink, [
  3069. 'thumbnailUrl' => ['tag' => 'link', 'content_attr' => 'href'],
  3070. 'OGImage' => ['name_attr' => 'property', 'name' => 'og:image'],
  3071. ]);
  3072. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : $sHost;
  3073. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : '';
  3074. $sMediaUrl = '';
  3075. if(!empty($aSiteInfo['thumbnailUrl']))
  3076. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  3077. else if(!empty($aSiteInfo['OGImage']))
  3078. $sMediaUrl = $aSiteInfo['OGImage'];
  3079. $iMediaId = 0;
  3080. $oStorage = null;
  3081. if(!empty($sMediaUrl)) {
  3082. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  3083. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  3084. }
  3085. $iId = (int)$oForm->insert(['profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()]);
  3086. if(!empty($iId)) {
  3087. if(!empty($oStorage) && !empty($iMediaId))
  3088. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  3089. return [
  3090. 'id' => $iId,
  3091. $CNF['FIELD_ATTACH_LINK_CONTENT_ID'] => $iContentId,
  3092. 'url' => $sLink,
  3093. 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId)
  3094. ];
  3095. }
  3096. return ['message' => _t('_bx_timeline_txt_err_cannot_perform_action')];
  3097. }
  3098. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  3099. {
  3100. if(empty($aTranscoders))
  3101. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  3102. $CNF = &$this->_oConfig->CNF;
  3103. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  3104. return false;
  3105. $iId = (int)$aContentInfo[$CNF[$sField]];
  3106. $aFile = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE'])->getFile($iId);
  3107. if(!empty($aFile) && is_array($aFile) && strpos($aFile['mime_type'], 'svg') !== false)
  3108. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  3109. foreach($aTranscoders as $sTranscoder)
  3110. if(!empty($CNF[$sTranscoder]))
  3111. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  3112. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  3113. }
  3114. public function getEntryAllActions ($mixedContent = false, $aParams = [])
  3115. {
  3116. $CNF = &$this->_oConfig->CNF;
  3117. if(!empty($mixedContent)) {
  3118. if(!is_array($mixedContent))
  3119. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  3120. }
  3121. else {
  3122. $mixedContent = $this->_getContent();
  3123. if($mixedContent === false)
  3124. return false;
  3125. }
  3126. list($iContentId, $aContentInfo) = $mixedContent;
  3127. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  3128. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  3129. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL'];
  3130. if(empty($sObjectMenu))
  3131. return false;
  3132. $sEntryTitle = !empty($aParams['entry_title']) ? $aParams['entry_title'] : '';
  3133. if(empty($sEntryTitle) && !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  3134. $sEntryTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  3135. $sEntryUrl = !empty($aParams['entry_url']) ? $aParams['entry_url'] : '';
  3136. if(empty($sEntryUrl) && !empty($CNF['URI_VIEW_ENTRY']))
  3137. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId));
  3138. $iEntryThumb = !empty($aParams['entry_thumb']) ? (int)$aParams['entry_thumb'] : 0;
  3139. if(empty($iEntryThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  3140. $iEntryThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  3141. $sObjectStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : false;
  3142. if(empty($sObjectStorage) && !empty($CNF['OBJECT_STORAGE']))
  3143. $sObjectStorage = $CNF['OBJECT_STORAGE'];
  3144. $sObjectTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : false;
  3145. $aMarkers = [
  3146. 'id' => $iContentId,
  3147. 'module' => $this->_oConfig->getName(),
  3148. 'title' => !empty($sEntryTitle) ? $sEntryTitle : '',
  3149. 'url' => !empty($sEntryUrl) ? $sEntryUrl : '',
  3150. 'img_url' => ''
  3151. ];
  3152. if(!empty($iEntryThumb)) {
  3153. if(!empty($sObjectTranscoder))
  3154. $o = BxDolTranscoder::getObjectInstance($sObjectTranscoder);
  3155. else if(!empty($sObjectStorage))
  3156. $o = BxDolStorage::getObjectInstance($sObjectStorage);
  3157. $sImageUrl = $o ? $o->getFileUrlById($iEntryThumb) : '';
  3158. if(!empty($sImageUrl))
  3159. $aMarkers['img_url'] = $sImageUrl;
  3160. }
  3161. $oActions = BxDolMenu::getObjectInstance($sObjectMenu, $this->_oTemplate);
  3162. if(!$oActions)
  3163. return false;
  3164. $oActions->setContentId($iContentId);
  3165. $oActions->addMarkers($aMarkers);
  3166. return $oActions->{bx_is_api() ? 'getCodeAPI' : 'getCode'}();
  3167. }
  3168. public function getProfileId()
  3169. {
  3170. return bx_get_logged_profile_id();
  3171. }
  3172. public function getProfileInfo($iUserId = false)
  3173. {
  3174. $oProfile = $this->getObjectUser($iUserId);
  3175. $oAccount = null;
  3176. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  3177. $oAccount = $oProfile->getAccountObject();
  3178. $bAccount = !empty($oAccount);
  3179. if(!$bAccount)
  3180. $oProfile = BxDolProfileUndefined::getInstance();
  3181. return array(
  3182. 'id' => $oProfile->id(),
  3183. 'name' => $oProfile->getDisplayName(),
  3184. 'email' => $bAccount ? $oAccount->getEmail() : '',
  3185. 'link' => $oProfile->getUrl(),
  3186. 'icon' => $oProfile->getIcon(),
  3187. 'thumb' => $oProfile->getThumb(),
  3188. 'avatar' => $oProfile->getAvatar(),
  3189. 'active' => $oProfile->isActive(),
  3190. );
  3191. }
  3192. public function getObjectUser($iUserId = false)
  3193. {
  3194. bx_import('BxDolProfile');
  3195. return BxDolProfile::getInstanceMagic($iUserId);
  3196. }
  3197. public function getObjectFavorite($sSystem = '', $iId = 0)
  3198. {
  3199. $CNF = &$this->_oConfig->CNF;
  3200. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  3201. $sSystem = $CNF['OBJECT_FAVORITES'];
  3202. if(empty($sSystem))
  3203. return false;
  3204. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3205. if(!$oFavorite || !$oFavorite->isEnabled())
  3206. return false;
  3207. return $oFavorite;
  3208. }
  3209. public function getUserId()
  3210. {
  3211. return isLogged() ? bx_get_logged_profile_id() : 0;
  3212. }
  3213. public function getUserIp()
  3214. {
  3215. return getVisitorIP();
  3216. }
  3217. public function getUserInfo($iUserId = 0)
  3218. {
  3219. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  3220. return array(
  3221. $oProfile->getDisplayName(),
  3222. $oProfile->getUrl(),
  3223. $oProfile->getThumb(),
  3224. $oProfile->getUnit(),
  3225. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  3226. );
  3227. }
  3228. public function getUserInfoWithBadges($iUserId = 0)
  3229. {
  3230. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  3231. return array(
  3232. $oProfile->getDisplayName(),
  3233. $oProfile->getUrl(),
  3234. $oProfile->getThumb(),
  3235. $oProfile->getUnit(),
  3236. $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  3237. $oProfile->getBadges()
  3238. );
  3239. }
  3240. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  3241. {
  3242. $CNF = &$this->_oConfig->CNF;
  3243. // default visible settings
  3244. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  3245. return false;
  3246. if (!empty($aItem['visibility_custom'])) {
  3247. $oMenu = BxDolMenu::getObjectInstance($sObject);
  3248. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $oMenu->getMarkers()))
  3249. return false;
  3250. }
  3251. // get custom function name to check menu item visibility
  3252. $sFuncCheckAccess = false;
  3253. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  3254. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  3255. // check custom visibility settings defined in module config class
  3256. if(!isset($aContentInfo))
  3257. $aContentInfo = array();
  3258. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), array(&$aContentInfo)))
  3259. return false;
  3260. return true;
  3261. }
  3262. public function _isModerator ($isPerformAction = false)
  3263. {
  3264. return $this->_isModeratorForProfile($isPerformAction, $this->_iProfileId);
  3265. }
  3266. public function _isModeratorForProfile($isPerformAction = false, $iProfileId = false)
  3267. {
  3268. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntryForProfile ($isPerformAction, $iProfileId);
  3269. }
  3270. public function _isAdministrator ($isPerformAction = false)
  3271. {
  3272. return $this->_isAdministratorForProfile($isPerformAction, $this->_iProfileId);
  3273. }
  3274. public function _isAdministratorForProfile($isPerformAction = false, $iProfileId = false)
  3275. {
  3276. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedDeleteAnyEntryForProfile ($isPerformAction, $iProfileId);
  3277. }
  3278. public function _prepareAuditParams($aContentInfo, $bIsSaveData = true, $aOverrideAuditParams = array())
  3279. {
  3280. $CNF = &$this->_oConfig->CNF;
  3281. $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;
  3282. $AuditParams = array(
  3283. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  3284. 'context_profile_id' => $iContextId,
  3285. 'content_info_object' => isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
  3286. 'data' => ($bIsSaveData ? $aContentInfo : array())
  3287. );
  3288. if ($iContextId > 0)
  3289. $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
  3290. $AuditParams = array_merge($AuditParams, $aOverrideAuditParams);
  3291. return $AuditParams;
  3292. }
  3293. public function _getFavoriteListUrl ($iListId, $iProfileId)
  3294. {
  3295. $CNF = &$this->_oConfig->CNF;
  3296. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_FAVORITES_LIST'] . '&profile_id=' . $iProfileId . '&list_id=' . $iListId));
  3297. }
  3298. public function getDataAPI($aData, $aParams = [])
  3299. {
  3300. $aDataApi = $this->decodeDataAPI($aData, $aParams);
  3301. $sModule = $this->getName();
  3302. $aExtras = [
  3303. 'module' => $sModule,
  3304. 'data' => $aData,
  3305. 'params' => $aParams,
  3306. 'data_api' => &$aDataApi,
  3307. ];
  3308. /**
  3309. * @hooks
  3310. * @hookdef hook-system-decode_data_api 'system', 'decode_data_api' - hook to override content data prepared for sending in API response
  3311. * - $unit_name - equals `system`
  3312. * - $action - equals `decode_data_api`
  3313. * - $object_id - not used
  3314. * - $sender_id - not used
  3315. * - $extra_params - array of additional params with the following array keys:
  3316. * - `module` - [string] module name
  3317. * - `data` - [array] content info array as key&value pairs
  3318. * - `params` - [array] params array as key&value pairs
  3319. * - `data_api` - [array] by ref, content data prepared for sending in API response, can be overridden in hook processing
  3320. * @hook @ref hook-system-decode_data_api
  3321. */
  3322. bx_alert('system', 'decode_data_api', 0, 0, $aExtras);
  3323. /**
  3324. * @hooks
  3325. * @hookdef hook-bx_base_general-decode_data_api '{module_name}', 'decode_data_api' - hook to override content data prepared for sending in API response
  3326. * It's equivalent to @ref hook-system-decode_data_api
  3327. * @hook @ref hook-bx_base_general-decode_data_api
  3328. */
  3329. bx_alert($sModule, 'decode_data_api', 0, 0, $aExtras);
  3330. return $aDataApi;
  3331. }
  3332. public function decodeDataAPI($aData, $aParams = [])
  3333. {
  3334. return $aData;
  3335. }
  3336. // ====== PROTECTED METHODS
  3337. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  3338. {
  3339. $iContentId = $this->_getContent($iContentId, false);
  3340. if($iContentId === false)
  3341. return false;
  3342. $oFormsHelper = $this->getFormsHelper();
  3343. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  3344. }
  3345. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  3346. {
  3347. return $this->_serviceTemplateFuncEx($sFunc, $iContentId, array('function_get_content' => $sFuncGetContent));
  3348. }
  3349. protected function _serviceTemplateFuncEx ($sFunc, $iContentId, $aParams = array())
  3350. {
  3351. if (!isset($aParams['function_get_content']))
  3352. $aParams['function_get_content'] = 'getContentInfoById';
  3353. $mixedContent = $this->_getContent($iContentId, $aParams['function_get_content']);
  3354. if($mixedContent === false)
  3355. return false;
  3356. list($iContentId, $aContentInfo) = $mixedContent;
  3357. unset($aParams['function_get_content']);
  3358. if (!empty($aParams))
  3359. return $this->_oTemplate->$sFunc($aContentInfo, $aParams);
  3360. else
  3361. return $this->_oTemplate->$sFunc($aContentInfo);
  3362. }
  3363. protected function _getApproveForm($iContentId, $aContentInfo)
  3364. {
  3365. $CNF = &$this->_oConfig->CNF;
  3366. $sForm = 'sys_manage';
  3367. if(!empty($CNF['OBJECT_FORM_MANAGE']))
  3368. $sForm = $CNF['OBJECT_FORM_MANAGE'];
  3369. $sFormDisplay = 'sys_manage_approve';
  3370. if(!empty($CNF['OBJECT_FORM_MANAGE_APPROVE']))
  3371. $sFormDisplay = $CNF['OBJECT_FORM_MANAGE_APPROVE'];
  3372. $oForm = BxTemplFormView::getObjectInstance($sForm, $sFormDisplay);
  3373. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'approve';
  3374. $oForm->aInputs['content_id']['value'] = $iContentId;
  3375. foreach($oForm->aInputs['controls'] as $iKey => $mixedValue)
  3376. if(is_numeric($iKey) && isset($mixedValue['name']) && $mixedValue['name'] == 'do_submit')
  3377. $oForm->aInputs['controls'][$iKey]['value'] = _t('_sys_form_manage_input_do_submit_approve');
  3378. /**
  3379. * @hooks
  3380. * @hookdef hook-bx_base_general-get_approve_form '{module_name}', 'get_approve_form' - hook to override approve content form
  3381. * - $unit_name - module name
  3382. * - $action - equals `get_approve_form`
  3383. * - $object_id - not used
  3384. * - $sender_id - not used
  3385. * - $extra_params - array of additional params with the following array keys:
  3386. * - `content_id` - [int] content id
  3387. * - `content_info` - [array] content info array as key&value pairs
  3388. * - `override_result` - [object] by ref, an instance of approve content form, @see BxDolForm, can be overridden in hook processing
  3389. * @hook @ref hook-bx_base_general-get_approve_form
  3390. */
  3391. bx_alert($this->_oConfig->getName(), 'get_approve_form', 0, 0, [
  3392. 'content_id' => $iContentId,
  3393. 'content_info' => $aContentInfo,
  3394. 'override_result' => &$oForm
  3395. ]);
  3396. return $oForm;
  3397. }
  3398. protected function _sendApproveMessage($iContentId, $aContentInfo, &$oForm)
  3399. {
  3400. $CNF = &$this->_oConfig->CNF;
  3401. $sETemplate = 't_ManageApprove';
  3402. if(!empty($CNF['ETEMPLATE_MANAGE_APPROVE']))
  3403. $sETemplate = $CNF['ETEMPLATE_MANAGE_APPROVE'];
  3404. $aEParams = array(
  3405. 'content_title' => !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  3406. 'notes' => $oForm->getCleanValue('notes'),
  3407. );
  3408. /**
  3409. * @hooks
  3410. * @hookdef hook-bx_base_general-get_approve_message '{module_name}', 'get_approve_form' - hook to override approve content message
  3411. * - $unit_name - module name
  3412. * - $action - equals `get_approve_message`
  3413. * - $object_id - not used
  3414. * - $sender_id - not used
  3415. * - $extra_params - array of additional params with the following array keys:
  3416. * - `content_id` - [int] content id
  3417. * - `content_info` - [array] content info array as key&value pairs
  3418. * - `form` - [object] an instance of approve content form
  3419. * - `email_template` - [string] by ref, email template name, @see BxDolEmailTemplates, can be overridden in hook processing
  3420. * - `email_params` - [array] by ref, email template params, can be overridden in hook processing
  3421. * @hook @ref hook-bx_base_general-get_approve_message
  3422. */
  3423. bx_alert($this->_oConfig->getName(), 'get_approve_message', 0, 0, [
  3424. 'content_id' => $iContentId,
  3425. 'content_info' => $aContentInfo,
  3426. 'form' => $oForm,
  3427. 'email_template' => &$sETemplate,
  3428. 'email_params' => &$aEParams
  3429. ]);
  3430. return sendMailTemplate($sETemplate, 0, $aContentInfo[$CNF['FIELD_AUTHOR']], $aEParams);
  3431. }
  3432. protected function _processModerationNotifications($aContentInfo)
  3433. {
  3434. $CNF = &$this->_oConfig->CNF;
  3435. if(empty($CNF['PARAM_AUTO_APPROVE']) || getParam($CNF['PARAM_AUTO_APPROVE']) == 'on')
  3436. return;
  3437. $aRecipients = [];
  3438. 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) {
  3439. $iContextProfileId = abs((int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  3440. $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
  3441. $aRecipients = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
  3442. }
  3443. $sModule = $this->getName();
  3444. if(empty($aRecipients))
  3445. $aRecipients = BxDolAclQuery::getInstance()->getProfilesByAction([
  3446. MEMBERSHIP_ACTION_EDIT_ANY_ENTRY,
  3447. MEMBERSHIP_ACTION_DELETE_ANY_ENTRY
  3448. ], [
  3449. 'module' => $sModule,
  3450. 'ids_only' => true
  3451. ]);
  3452. if(empty($aRecipients))
  3453. return;
  3454. foreach($aRecipients as $iRecipientId)
  3455. /**
  3456. * @hooks
  3457. * @hookdef hook-bx_base_general-pending_approval '{module_name}', 'pending_approval' - hook to notify admins/moderators about new pending approval content
  3458. * - $unit_name - module name
  3459. * - $action - equals `pending_approval`
  3460. * - $object_id - content id
  3461. * - $sender_id - content author profile id
  3462. * - $extra_params - array of additional params with the following array keys:
  3463. * - `object_author_id` - [int] admin/moderator profile id
  3464. * @hook @ref hook-bx_base_general-pending_approval
  3465. */
  3466. bx_alert($sModule, 'pending_approval', $aContentInfo[$CNF['FIELD_ID']], $aContentInfo[$CNF['FIELD_AUTHOR']], [
  3467. 'object_author_id' => (int)$iRecipientId
  3468. ]);
  3469. }
  3470. protected function _rss ($aArgs, $sClass = 'SearchResult')
  3471. {
  3472. $sMode = array_shift($aArgs);
  3473. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  3474. $this->_oTemplate->displayAccessDenied ($sMsg);
  3475. exit;
  3476. }
  3477. $aParams = $this->_buildRssParams($sMode, $aArgs);
  3478. bx_import ($sClass, $this->_aModule);
  3479. $sClass = $this->_aModule['class_prefix'] . $sClass;
  3480. $o = new $sClass($sMode, $aParams);
  3481. if ($o->isError)
  3482. $this->_oTemplate->displayPageNotFound ();
  3483. else
  3484. $o->outputRSS();
  3485. exit;
  3486. }
  3487. protected function _getContent($iContentId = 0, $sFuncGetContent = true)
  3488. {
  3489. if(!$iContentId)
  3490. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  3491. if(!$iContentId)
  3492. return false;
  3493. if($sFuncGetContent === true)
  3494. $sFuncGetContent = 'getContentInfoById';
  3495. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  3496. return $iContentId;
  3497. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  3498. if(!$aContentInfo)
  3499. return false;
  3500. return array($iContentId, $aContentInfo);
  3501. }
  3502. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  3503. {
  3504. $CNF = &$this->_oConfig->CNF;
  3505. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  3506. //--- Image(s)
  3507. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3508. $aImagesAttach = $this->_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3509. //--- Video(s)
  3510. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3511. $aVideosAttach = $this->_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3512. //--- Files(s)
  3513. $aFiles = $this->_getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3514. $aFilesAttach = $this->_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3515. if($this->_bIsApi && getParam('sys_api_extended_units') != 'on') {
  3516. $sTitle = '';
  3517. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  3518. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  3519. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  3520. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  3521. $sAbstract = isset($CNF['FIELD_ABSTRACT']) && isset($aContentInfo[$CNF['FIELD_ABSTRACT']]) ? $aContentInfo[$CNF['FIELD_ABSTRACT']] : '';
  3522. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  3523. $sText = BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sText), 240);
  3524. $aResults = [
  3525. 'url' => $sUrl,
  3526. 'title' => $sTitle,
  3527. 'abstract' => $sAbstract,
  3528. 'text' => $sText
  3529. ];
  3530. if(!empty($aImages) && is_array($aImages))
  3531. $aResults['images'] = $aImages;
  3532. if(!empty($aVideos) && is_array($aVideos))
  3533. $aResults['videos'] = $aVideos;
  3534. if(!empty($aFiles) && is_array($aFiles))
  3535. $aResults['files'] = $aFiles;
  3536. return $aResults;
  3537. }
  3538. //--- Title
  3539. $sTitle = '';
  3540. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  3541. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  3542. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  3543. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  3544. //--- Text
  3545. $sText = '';
  3546. if(isset($CNF['FIELD_ABSTRACT']) && isset($aContentInfo[$CNF['FIELD_ABSTRACT']]))
  3547. $sText = $aContentInfo[$CNF['FIELD_ABSTRACT']];
  3548. if(empty($sText) && isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  3549. $sText = $aContentInfo[$CNF['FIELD_TEXT']];
  3550. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  3551. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  3552. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  3553. }
  3554. $sCategory = '';
  3555. if (isset($CNF['OBJECT_CATEGORY']) && isset($CNF['OBJECT_CATEGORY']) && isset($aContentInfo[$CNF['FIELD_CATEGORY']])){
  3556. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  3557. if ($oCategory)
  3558. $sCategory = $oCategory->getCategoryTitle($aContentInfo[$CNF['FIELD_CATEGORY']]);
  3559. }
  3560. $aResult = [
  3561. 'title' => $sTitle,
  3562. 'text' => $sText,
  3563. 'images' => $aImages,
  3564. 'images_attach' => $aImagesAttach,
  3565. 'videos' => $aVideos,
  3566. 'videos_attach' => $aVideosAttach,
  3567. 'files' => $aFiles,
  3568. 'files_attach' => $aFilesAttach
  3569. ];
  3570. return $this->_bIsApi ? $aResult : array_merge($aResult, [
  3571. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  3572. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  3573. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  3574. 'url' => $sUrl,
  3575. 'category' => $sCategory,
  3576. ]);
  3577. }
  3578. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  3579. {
  3580. $CNF = &$this->_oConfig->CNF;
  3581. if (bx_is_api()){
  3582. $aResult = [];
  3583. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']])) {
  3584. $aResult[] = bx_api_get_image($CNF['OBJECT_STORAGE'], (int)$aContentInfo[$CNF['FIELD_COVER']]);
  3585. }
  3586. if(isset($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']])) {
  3587. $aResult[] = bx_api_get_image($CNF['OBJECT_STORAGE'], (int)$aContentInfo[$CNF['FIELD_THUMB']]);
  3588. }
  3589. return $aResult;
  3590. }
  3591. else{
  3592. $iImageId = 0;
  3593. $sImageSm = $sImageMd = $sImageXl = '';
  3594. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']])) {
  3595. $iImageId = (int)$aContentInfo[$CNF['FIELD_COVER']];
  3596. $sImageSm = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_MINIATURE', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  3597. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  3598. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  3599. }
  3600. if($sImageMd == '' && isset($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']])) {
  3601. $iImageId = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  3602. $sImageSm = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_MINIATURE', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  3603. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  3604. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  3605. }
  3606. if(empty($sImageMd))
  3607. return [];
  3608. if($sImageSm == '')
  3609. $sImageSm = $sImageMd;
  3610. if($sImageXl == '')
  3611. $sImageXl = $sImageMd;
  3612. return [[
  3613. 'id' => $iImageId,
  3614. 'url' => $sUrl,
  3615. 'src' => $sImageMd,
  3616. 'src_small' => $sImageSm,
  3617. 'src_medium' => $sImageMd,
  3618. 'src_orig' => $sImageXl
  3619. ]];
  3620. }
  3621. }
  3622. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  3623. {
  3624. return array();
  3625. }
  3626. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  3627. {
  3628. return array();
  3629. }
  3630. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  3631. {
  3632. return array();
  3633. }
  3634. protected function _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  3635. {
  3636. return array();
  3637. }
  3638. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  3639. {
  3640. return array();
  3641. }
  3642. protected function _entityComments ($sObject, $iId = 0)
  3643. {
  3644. if (!$iId)
  3645. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  3646. if (!$iId)
  3647. return false;
  3648. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  3649. if (!$oCmts || !$oCmts->isEnabled())
  3650. return false;
  3651. if (bx_is_api()){
  3652. return [bx_srv('system', 'get_data_api', [['module' => $sObject, 'object_id' => $iId]], 'TemplCmtsServices')];
  3653. }
  3654. return $oCmts->getCommentsBlock([], ['in_designbox' => false, 'show_empty' => false]);
  3655. }
  3656. protected function _getFields($iContentId)
  3657. {
  3658. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  3659. if(empty($aContentInfo))
  3660. return array();
  3661. return BxDolContentInfo::formatFields($aContentInfo);
  3662. }
  3663. protected function _getFieldValue($sField, $iContentId)
  3664. {
  3665. $CNF = &$this->_oConfig->CNF;
  3666. if(empty($CNF[$sField]))
  3667. return false;
  3668. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  3669. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  3670. return false;
  3671. return $aContentInfo[$CNF[$sField]];
  3672. }
  3673. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  3674. {
  3675. $CNF = &$this->_oConfig->CNF;
  3676. if(empty($sTranscoder) || empty($CNF[$sField]))
  3677. return false;
  3678. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  3679. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  3680. return false;
  3681. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  3682. if(!$oImagesTranscoder)
  3683. return false;
  3684. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  3685. }
  3686. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  3687. {
  3688. if(!$bAsJson)
  3689. return $aResponse;
  3690. if(!empty($aAdditional) && is_array($aAdditional))
  3691. $aResponse = array_merge($aResponse, $aAdditional);
  3692. echoJson($aResponse);
  3693. exit;
  3694. }
  3695. /**
  3696. * Blocks for lables tree browsing private functions
  3697. */
  3698. private function _getLablesBreadcrumbsArray($iLabelId, &$aBreadcrumbs)
  3699. {
  3700. $oLabel = BxDolLabel::getInstance();
  3701. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  3702. if ($aLabel){
  3703. $aBreadcrumbs[$aLabel['id']] = array('id' => $aLabel['id'], 'value' => $aLabel['value']);
  3704. $this->_getLablesBreadcrumbsArray($aLabel['parent'], $aBreadcrumbs);
  3705. }
  3706. }
  3707. private function _getLablesBrowseUrl($iLabelId)
  3708. {
  3709. list($sPageLink, $aPageParams) = bx_get_base_url_inline();
  3710. return BxDolPermalinks::getInstance()->permalink(bx_append_url_params($sPageLink, array_merge($aPageParams, array('label' => $iLabelId))));
  3711. }
  3712. private function _getLablesTreeLevel($aBreadcrumbs, $iParent = 0)
  3713. {
  3714. $oLabel = BxDolLabel::getInstance();
  3715. $aLabelsOutput = array();
  3716. $aLabels = $oLabel->getLabels(array('type' => 'parent', 'parent' => $iParent));
  3717. if (count($aLabels) > 0){
  3718. foreach($aLabels as $aLabel) {
  3719. $sChild = $this->_getLablesTreeLevel($aBreadcrumbs, $aLabel['id']);
  3720. $bChildPresent = $sChild != '' ? true : false;
  3721. $bIsOpen = array_key_exists($aLabel['id'], $aBreadcrumbs) ? true : false;
  3722. if (!$bIsOpen){
  3723. $sChild = '';
  3724. }
  3725. $aLabelsOutput[] = array(
  3726. 'value' => $aLabel['value'],
  3727. 'url' => $this->_getLablesBrowseUrl($aLabel['id']),
  3728. 'child' => $sChild,
  3729. 'selected' => bx_process_input(bx_get('label'), BX_DATA_INT) == $aLabel['id'] ? 'selected' : ''.$aLabel['id'],
  3730. 'bx_if:open' => array(
  3731. 'condition' => $bChildPresent && $bIsOpen,
  3732. 'content' => array()
  3733. ),
  3734. 'bx_if:can_open' => array(
  3735. 'condition' => $bChildPresent && !$bIsOpen,
  3736. 'content' => array()
  3737. )
  3738. );
  3739. }
  3740. return $this->_oTemplate->parseHtmlByName('labels_tree.html',
  3741. array(
  3742. 'bx_repeat:items' => $aLabelsOutput,
  3743. 'parent' => $iParent,
  3744. )
  3745. );
  3746. }
  3747. return '';
  3748. }
  3749. }
  3750. /** @} */