BxBaseModGeneralModule.php 163 KB

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