1
0

BxBaseModGeneralModule.php 148 KB

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