BxBaseModGeneralModule.php 151 KB

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