BxBaseModGeneralModule.php 164 KB

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