BxBaseModGeneralModule.php 188 KB

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