1
0

BxBaseModGeneralModule.php 190 KB

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