1
0

BxBaseModGeneralModule.php 172 KB

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