1
0

BxBaseModGeneralModule.php 144 KB

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