1
0

BxBaseModGeneralModule.php 140 KB

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