BxBaseModGeneralModule.php 161 KB

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