BxBaseModGeneralModule.php 187 KB

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