1
0

BxBaseModGeneralModule.php 189 KB

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