1
0

BxBaseModGeneralModule.php 150 KB

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