BxBaseModGeneralModule.php 185 KB

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