BxBaseModGeneralModule.php 172 KB

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