BxBaseModGeneralModule.php 146 KB

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