BxBaseModGeneralModule.php 189 KB

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