1
0

BxBaseModGeneralModule.php 187 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861
  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. bx_import($sClassSearchResult, $this->_aModule);
  1086. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1087. return new $sClass($sMode, array_merge(['mode' => $sMode], $aParams));
  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. 'object' => &$oObject
  1427. ]);
  1428. if($oObject !== null)
  1429. return $oObject;
  1430. bx_import($sClass, $this->_aModule);
  1431. $sClass = $this->_aModule['class_prefix'] . $sClass;
  1432. return new $sClass($this);
  1433. }
  1434. public function serviceFormsHelper()
  1435. {
  1436. return $this->getFormsHelper();
  1437. }
  1438. /**
  1439. * Add entry using provided fields' values.
  1440. * @return array with result:
  1441. * 'code' is 0 on success or non-zero on error,
  1442. * 'message' is error message in case of error,
  1443. * 'content' is content info array in case of success
  1444. */
  1445. public function serviceEntityAdd($iProfile, $aValues, $sDisplay = false)
  1446. {
  1447. $oFormsHelper = $this->getFormsHelper();
  1448. return $oFormsHelper->addData($iProfile, $aValues, $sDisplay);
  1449. }
  1450. public function serviceEntityAddForcedly($iProfile, $aValues, $sDisplay = false)
  1451. {
  1452. $oFormsHelper = $this->getFormsHelper();
  1453. $oFormsHelper->setValidMode(true);
  1454. return $oFormsHelper->addData($iProfile, $aValues, $sDisplay);
  1455. }
  1456. /**
  1457. * Perform redirect after content creation
  1458. * @return nothing, rediret header is sent
  1459. */
  1460. public function serviceRedirectAfterAdd($aContentInfo)
  1461. {
  1462. $oFormsHelper = $this->getFormsHelper();
  1463. $oFormsHelper->redirectAfterAdd($aContentInfo);
  1464. }
  1465. /**
  1466. * Get form object for add, edit, view or delete the content
  1467. * @param $sType 'add', 'edit', 'view' or 'delete'
  1468. * @param $aParams optional array with parameters(display name, etc)
  1469. * @return form object or false on error
  1470. */
  1471. public function serviceGetObjectForm ($sType, $aParams = array())
  1472. {
  1473. if(!in_array($sType, array('add', 'edit', 'view', 'delete')))
  1474. return false;
  1475. $iLoggedId = (int)bx_get_logged_profile_id();
  1476. $mixedContextId = isset($aParams['context_id']) ? $aParams['context_id'] : false;
  1477. $oContextProfile = false;
  1478. $bContext = $mixedContextId !== false;
  1479. if($bContext) {
  1480. $oContextProfile = BxDolProfile::getInstance(abs($mixedContextId));
  1481. $bContext = $oContextProfile !== false;
  1482. if($bContext && $oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  1483. return false;
  1484. }
  1485. $CNF = &$this->_oConfig->CNF;
  1486. $oFormsHelper = $this->getFormsHelper();
  1487. $sParamsKey = 'ajax_mode';
  1488. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  1489. $oFormsHelper->setAjaxMode((bool)$aParams[$sParamsKey]);
  1490. $sParamsKey = 'absolute_action_url';
  1491. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  1492. $oFormsHelper->setAbsoluteActionUrl((bool)$aParams[$sParamsKey]);
  1493. if($bContext)
  1494. $oFormsHelper->setContextId($mixedContextId);
  1495. $sDisplay = !empty($aParams['display']) ? $aParams['display'] : false;
  1496. $sFunc = 'getObjectForm' . ucfirst($sType);
  1497. $oForm = $oFormsHelper->$sFunc($sDisplay);
  1498. $sKey = 'FIELD_ALLOW_VIEW_TO';
  1499. if(!empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]]) && (!$bContext || $mixedContextId < 0)) {
  1500. $bContextOwner = $bContext && abs($mixedContextId) == $iLoggedId;
  1501. if(!$bContext || $bContextOwner) {
  1502. $iGc = 0;
  1503. $iKeyGh = false;
  1504. foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $iKey => $aValue) {
  1505. if(isset($aValue['type']) && in_array($aValue['type'], array('group_header', 'group_end'))) {
  1506. if($iKeyGh !== false && $iGc == 0) {
  1507. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKeyGh]);
  1508. $iKeyGh = false;
  1509. if($aValue['type'] == 'group_end')
  1510. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  1511. }
  1512. if($aValue['type'] == 'group_header') {
  1513. $iGc = 0;
  1514. $iKeyGh = $iKey;
  1515. }
  1516. continue;
  1517. }
  1518. //--- Show 'Public' privacy group only in Public post form.
  1519. if(!$bContext && $aValue['key'] == BX_DOL_PG_ALL) {
  1520. $iGc += 1;
  1521. continue;
  1522. }
  1523. //--- Show a default privacy groups in Profile (for Owner) post form.
  1524. if($bContextOwner && ((int)$aValue['key'] >= 0 || $mixedContextId == $aValue['key'])) {
  1525. $iGc += 1;
  1526. continue;
  1527. }
  1528. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  1529. }
  1530. }
  1531. else {
  1532. $oForm->aInputs[$CNF[$sKey]]['value'] = $mixedContextId;
  1533. $oForm->aInputs[$CNF[$sKey]]['type'] = 'hidden';
  1534. }
  1535. }
  1536. $sKey = 'FIELD_LABELS';
  1537. if(!empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]]) && empty($oForm->aInputs[$CNF[$sKey]]['value']) && $bContext) {
  1538. $iContextProfileId = $oContextProfile->id();
  1539. $sContextModule = $oContextProfile->getModule();
  1540. if(bx_srv($sContextModule, 'is_fan', [$iContextProfileId, $iLoggedId])) {
  1541. $aContextInfo = bx_srv($sContextModule, 'get_content_info_by_profile_id', [$iContextProfileId]);
  1542. if(!empty($aContextInfo['hashtag']))
  1543. $oForm->aInputs[$CNF[$sKey]]['value'] = [$aContextInfo['hashtag']];
  1544. }
  1545. }
  1546. /**
  1547. * @hooks
  1548. * @hookdef hook-system-get_object_form 'system', 'get_object_form' - hook to override an object of create content form, @see BxDolForm
  1549. * - $unit_name - equals `system`
  1550. * - $action - equals `get_object_form`
  1551. * - $object_id - not used
  1552. * - $sender_id - not used
  1553. * - $extra_params - array of additional params with the following array keys:
  1554. * - `module` - [string] module name
  1555. * - `type` - [string] 'add', 'edit', 'view' or 'delete' form display type
  1556. * - `params` - [array] form params array as key&value pairs
  1557. * - `form` - [object] by ref, an object of create content form, @see BxDolForm, can be overridden in hook processing
  1558. * @hook @ref hook-system-get_object_form
  1559. */
  1560. bx_alert('system', 'get_object_form', 0, 0, [
  1561. 'module' => $this->_oConfig->getName(),
  1562. 'type' => $sType,
  1563. 'params' => $aParams,
  1564. 'form' => &$oForm
  1565. ]);
  1566. return $oForm;
  1567. }
  1568. /**
  1569. *
  1570. *
  1571. * Create entry form
  1572. * @return HTML string
  1573. */
  1574. public function serviceEntityCreate ($sParams = false)
  1575. {
  1576. if($this->_bIsApi && ($aParams = bx_api_get_browse_params($sParams))) {
  1577. if(($aKeys = ['context_pid', 'context_nid', 'context_usage']) && ($aParamsContext = array_intersect_key($aParams, array_flip($aKeys)))) {
  1578. $_GET = array_merge($_GET, $aParamsContext);
  1579. $sParams = array_diff_key($aParams, array_flip($aKeys));
  1580. }
  1581. }
  1582. $bParamsArray = is_array($sParams);
  1583. $sDisplay = is_string($sParams) ? $sParams : false;
  1584. if($bParamsArray && !empty($sParams['display']))
  1585. $sDisplay = $sParams['display'];
  1586. $oFormsHelper = $this->getFormsHelper();
  1587. if($bParamsArray && isset($sParams['dynamic_mode']))
  1588. $oFormsHelper->setDynamicMode($sParams['dynamic_mode']);
  1589. $mixedResult = $oFormsHelper->addDataForm($sDisplay);
  1590. if($this->_bIsApi)
  1591. return $mixedResult;
  1592. if(isset($mixedResult['_dt']) && $mixedResult['_dt'] == 'json') {
  1593. echoJson($mixedResult);
  1594. exit;
  1595. }
  1596. return $mixedResult;
  1597. }
  1598. /**
  1599. * @page service Service Calls
  1600. * @section bx_base_general Base General
  1601. * @subsection bx_base_general-forms Forms
  1602. * @subsubsection bx_base_general-get_create_post_form get_create_post_form
  1603. *
  1604. * @code bx_srv('bx_posts', 'get_create_post_form'); @endcode
  1605. *
  1606. * Get content creation form
  1607. * @param $aParams additional parameters array:
  1608. * context_id, ajax_mode, absolute_action_url, displays
  1609. *
  1610. * @see BxBaseModGeneralModule::serviceGetCreatePostForm
  1611. */
  1612. /**
  1613. * @ref bx_base_general-get_create_post_form "get_create_post_form"
  1614. */
  1615. public function serviceGetCreatePostForm($aParams = [])
  1616. {
  1617. $aParams = array_merge($this->_aFormParams, $aParams);
  1618. if($aParams['context_id'] !== false && ($aContextInfo = BxDolProfileQuery::getInstance()->getInfoById(abs($aParams['context_id']))))
  1619. if(bx_srv($aContextInfo['type'], 'check_allowed_post_in_profile', [$aContextInfo['content_id'], $this->getName()]) !== CHECK_ACTION_RESULT_ALLOWED)
  1620. return '';
  1621. $oForm = $this->serviceGetObjectForm('add', $aParams);
  1622. if(!$oForm)
  1623. return '';
  1624. return $this->serviceEntityCreate($aParams);
  1625. }
  1626. /**
  1627. * @page service Service Calls
  1628. * @section bx_base_general Base General
  1629. * @subsection bx_base_general-forms Forms
  1630. * @subsubsection bx_base_general-entity_edit entity_edit
  1631. *
  1632. * @code bx_srv('bx_posts', 'entity_edit', [...]); @endcode
  1633. *
  1634. * Get content edit form
  1635. * @param $iContentId content ID
  1636. * @param $sDisplay optional form display name
  1637. *
  1638. * @see BxBaseModGeneralModule::serviceEntityEdit
  1639. */
  1640. /**
  1641. * @ref bx_base_general-entity_edit "entity_edit"
  1642. */
  1643. public function serviceEntityEdit ($iContentId = 0, $sDisplay = false)
  1644. {
  1645. return $this->_serviceEntityForm ('editDataForm', $iContentId, $sDisplay);
  1646. }
  1647. /**
  1648. * @page service Service Calls
  1649. * @section bx_base_general Base General
  1650. * @subsection bx_base_general-forms Forms
  1651. * @subsubsection bx_base_general-entity_delete entity_delete
  1652. *
  1653. * @code bx_srv('bx_posts', 'entity_delete', [...]); @endcode
  1654. *
  1655. * Get content delete form
  1656. * @param $iContentId content ID
  1657. *
  1658. * @see BxBaseModGeneralModule::serviceEntityDelete
  1659. */
  1660. /**
  1661. * @ref bx_base_general-entity_delete "entity_delete"
  1662. */
  1663. public function serviceEntityDelete ($iContentId = 0)
  1664. {
  1665. $mixedResult = $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  1666. if(!bx_is_api())
  1667. return $mixedResult;
  1668. $aResult = [];
  1669. if(is_a($mixedResult, 'BxTemplFormView')){
  1670. $iContentId = $this->_getContent($iContentId, false);
  1671. $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]]]);
  1672. }
  1673. else
  1674. $aResult = $mixedResult;
  1675. return [
  1676. $aResult
  1677. ];
  1678. }
  1679. /**
  1680. * @page service Service Calls
  1681. * @section bx_base_general Base General
  1682. * @subsection bx_base_general-page_blocks Page Blocks
  1683. * @subsubsection bx_base_general-entity_text_block entity_text_block
  1684. *
  1685. * @code bx_srv('bx_posts', 'entity_text_block', [...]); @endcode
  1686. *
  1687. * Get content text/description
  1688. * @param $iContentId content ID
  1689. *
  1690. * @see BxBaseModGeneralModule::serviceEntityTextBlock
  1691. */
  1692. /**
  1693. * @ref bx_base_general-entity_text_block "entity_text_block"
  1694. */
  1695. public function serviceEntityTextBlock ($iContentId = 0)
  1696. {
  1697. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  1698. }
  1699. /**
  1700. * @page service Service Calls
  1701. * @section bx_base_general Base General
  1702. * @subsection bx_base_general-page_blocks Page Blocks
  1703. * @subsubsection bx_base_general-entity_info entity_info
  1704. *
  1705. * @code bx_srv('bx_posts', 'entity_info', [...]); @endcode
  1706. *
  1707. * Get content info
  1708. * @param $iContentId content ID
  1709. *
  1710. * @see BxBaseModGeneralModule::serviceEntityInfo
  1711. */
  1712. /**
  1713. * @ref bx_base_general-entity_info "entity_info"
  1714. */
  1715. public function serviceEntityInfo ($iContentId = 0, $sDisplay = false)
  1716. {
  1717. return $this->_serviceEntityForm ('viewDataForm', $iContentId, $sDisplay);
  1718. }
  1719. /**
  1720. * @page service Service Calls
  1721. * @section bx_base_general Base General
  1722. * @subsection bx_base_general-page_blocks Page Blocks
  1723. * @subsubsection bx_base_general-entity_info_full entity_info_full
  1724. *
  1725. * @code bx_srv('bx_posts', 'entity_info_full', [...]); @endcode
  1726. *
  1727. * Get full content info
  1728. * @param $iContentId content ID
  1729. *
  1730. * @see BxBaseModGeneralModule::serviceEntityInfoFull
  1731. */
  1732. /**
  1733. * @ref bx_base_general-entity_info_full "entity_info_full"
  1734. */
  1735. public function serviceEntityInfoFull ($iContentId = 0)
  1736. {
  1737. $CNF = &$this->_oConfig->CNF;
  1738. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  1739. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  1740. }
  1741. /**
  1742. * @page service Service Calls
  1743. * @section bx_base_general Base General
  1744. * @subsection bx_base_general-page_blocks Page Blocks
  1745. * @subsubsection bx_base_general-entity_info_extended entity_info_extended
  1746. *
  1747. * @code bx_srv('bx_posts', 'entity_info_extended', [...]); @endcode
  1748. *
  1749. * Get extended content info
  1750. * @param $iContentId content ID
  1751. *
  1752. * @see BxBaseModGeneralModule::serviceEntityInfoExtended
  1753. */
  1754. /**
  1755. * @ref bx_base_general-entity_info_extended "entity_info_extended"
  1756. */
  1757. public function serviceEntityInfoExtended ($iContentId = 0)
  1758. {
  1759. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  1760. }
  1761. /**
  1762. * @page service Service Calls
  1763. * @section bx_base_general Base General
  1764. * @subsection bx_base_general-page_blocks Page Blocks
  1765. * @subsubsection bx_base_general-entity_location entity_location
  1766. *
  1767. * @code bx_srv('bx_posts', 'entity_location', [...]); @endcode
  1768. *
  1769. * Get content location
  1770. * @param $iContentId content ID
  1771. *
  1772. * @see BxBaseModGeneralModule::serviceEntityLocation
  1773. */
  1774. /**
  1775. * @ref bx_base_general-entity_location "entity_location"
  1776. */
  1777. public function serviceEntityLocation ($iContentId = 0)
  1778. {
  1779. $CNF = &$this->_oConfig->CNF;
  1780. $mixedContent = $this->_getContent($iContentId);
  1781. if($mixedContent === false)
  1782. return false;
  1783. list($iContentId, $aContentInfo) = $mixedContent;
  1784. $oFormsHelper = $this->getFormsHelper();
  1785. $oFormView = $oFormsHelper->getObjectFormView();
  1786. if(!$oFormView)
  1787. return false;
  1788. $oFormView->initChecker($aContentInfo);
  1789. if(empty($CNF['FIELD_LOCATION']) || !$oFormView->isInputVisible($CNF['FIELD_LOCATION']))
  1790. return false;
  1791. return $this->_oTemplate->entryLocation ($iContentId);
  1792. }
  1793. /**
  1794. * @page service Service Calls
  1795. * @section bx_base_general Base General
  1796. * @subsection bx_base_general-page_blocks Page Blocks
  1797. * @subsubsection bx_base_general-entity_comments entity_comments
  1798. *
  1799. * @code bx_srv('bx_posts', 'entity_comments', [...]); @endcode
  1800. *
  1801. * Get content comments
  1802. * @param $iContentId content ID
  1803. *
  1804. * @see BxBaseModGeneralModule::serviceEntityComments
  1805. */
  1806. /**
  1807. * @ref bx_base_general-entity_comments "entity_comments"
  1808. */
  1809. public function serviceEntityComments ($iContentId = 0)
  1810. {
  1811. $CNF = &$this->_oConfig->CNF;
  1812. if(empty($CNF['OBJECT_COMMENTS']))
  1813. return '';
  1814. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
  1815. }
  1816. /**
  1817. * @page service Service Calls
  1818. * @section bx_base_general Base General
  1819. * @subsection bx_base_general-page_blocks Page Blocks
  1820. * @subsubsection bx_base_general-entity_attachments entity_attachments
  1821. *
  1822. * @code bx_srv('bx_posts', 'entity_attachments', [...]); @endcode
  1823. *
  1824. * Get content attachments
  1825. * @param $iContentId content ID
  1826. *
  1827. * @see BxBaseModGeneralModule::serviceEntityAttachments
  1828. */
  1829. /**
  1830. * @ref bx_base_general-entity_attachments "entity_attachments"
  1831. */
  1832. public function serviceEntityAttachments ($iContentId = 0)
  1833. {
  1834. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  1835. }
  1836. /**
  1837. * @page service Service Calls
  1838. * @section bx_base_general Base General
  1839. * @subsection bx_base_general-page_blocks Page Blocks
  1840. * @subsubsection bx_base_general-entity_polls entity_polls
  1841. *
  1842. * @code bx_srv('bx_posts', 'entity_polls', [...]); @endcode
  1843. *
  1844. * Display polls for the specified post
  1845. * @param $iContentId content ID
  1846. *
  1847. * @see BxBaseModGeneralModule::serviceEntityPolls
  1848. */
  1849. /**
  1850. * @ref bx_base_general-entity_polls "entity_polls"
  1851. */
  1852. public function serviceEntityPolls ($iContentId = 0)
  1853. {
  1854. return $this->_serviceTemplateFunc ('entryPolls', $iContentId);
  1855. }
  1856. /**
  1857. * Delete content entry
  1858. * @param $iContentId content id
  1859. * @return error message or empty string on success
  1860. */
  1861. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  1862. {
  1863. $oFormsHelper = $this->getFormsHelper();
  1864. return $oFormsHelper->$sFuncDelete($iContentId);
  1865. }
  1866. /**
  1867. * Edit content entry
  1868. * @param $iContentId content id
  1869. * @param $aValues key value pairs to update
  1870. * @return error message or empty string on success
  1871. */
  1872. public function serviceEditEntity ($iContentId, $aValues, $sDisplay = false)
  1873. {
  1874. $oFormsHelper = $this->getFormsHelper();
  1875. return $oFormsHelper->editData($iContentId, $aValues, $sDisplay);
  1876. }
  1877. /**
  1878. * @page service Service Calls
  1879. * @section bx_base_general Base General
  1880. * @subsection bx_base_general-menu Menu
  1881. * @subsubsection bx_base_general-my_entries_actions my_entries_actions
  1882. *
  1883. * @code bx_srv('bx_posts', 'my_entries_actions', [...]); @endcode
  1884. *
  1885. * My entries actions menu
  1886. * @param $iProfileId profiles ID,
  1887. * if omitted it try to get it from 'profile_id' GET param
  1888. *
  1889. * @see BxBaseModGeneralModule::serviceMyEntriesActions
  1890. */
  1891. /**
  1892. * @ref bx_base_general-my_entries_actions "my_entries_actions"
  1893. */
  1894. public function serviceMyEntriesActions ($iProfileId = 0)
  1895. {
  1896. $CNF = &$this->_oConfig->CNF;
  1897. if(empty($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']))
  1898. return false;
  1899. if (!$iProfileId)
  1900. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1901. if (!$iProfileId || !($oProfile = BxDolProfile::getInstance($iProfileId)))
  1902. return false;
  1903. if ($iProfileId != $this->_iProfileId)
  1904. return false;
  1905. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  1906. return $oMenu ? $oMenu->getCode() : false;
  1907. }
  1908. /**
  1909. * @page service Service Calls
  1910. * @section bx_base_general Base General
  1911. * @subsection bx_base_general-menu Menu
  1912. * @subsubsection bx_base_general-entity_all_actions entity_all_actions
  1913. *
  1914. * @code bx_srv('bx_posts', 'entity_all_actions', [...]); @endcode
  1915. *
  1916. * Entry actions and social sharing actions
  1917. * @param $mixedContent content ID
  1918. * @param $aParams additional params
  1919. *
  1920. * @see BxBaseModGeneralModule::serviceEntityAllActions
  1921. */
  1922. /**
  1923. * @ref bx_base_general-entity_all_actions "entity_all_actions"
  1924. */
  1925. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  1926. {
  1927. $mixedResult = $this->getEntryAllActions($mixedContent, $aParams);
  1928. if(bx_is_api())
  1929. return [bx_api_get_block('entity_actions', $mixedResult)];
  1930. else
  1931. return $this->_oTemplate->entryAllActions($mixedResult);
  1932. }
  1933. /**
  1934. * @page service Service Calls
  1935. * @section bx_base_general Base General
  1936. * @subsection bx_base_general-menu Menu
  1937. * @subsubsection bx_base_general-entity_actions entity_actions
  1938. *
  1939. * @code bx_srv('bx_posts', 'entity_actions', [...]); @endcode
  1940. *
  1941. * Entry actions, without social sharing actions
  1942. * @param $iContentId content ID
  1943. *
  1944. * @see BxBaseModGeneralModule::serviceEntityActions
  1945. */
  1946. /**
  1947. * @ref bx_base_general-entity_actions "entity_actions"
  1948. */
  1949. public function serviceEntityActions ($iContentId = 0)
  1950. {
  1951. $iContentId = $this->_getContent($iContentId, false);
  1952. if($iContentId === false)
  1953. return false;
  1954. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  1955. return $oMenu ? $oMenu->getCode() : false;
  1956. }
  1957. /**
  1958. * @page service Service Calls
  1959. * @section bx_base_general Base General
  1960. * @subsection bx_base_general-page_blocks Page Blocks
  1961. * @subsubsection bx_base_general-entity_reports entity_reports
  1962. *
  1963. * @code bx_srv('bx_posts', 'entity_reports', [...]); @endcode
  1964. *
  1965. * Get content reports
  1966. * @param $iContentId content ID
  1967. *
  1968. * @see BxBaseModGeneralModule::serviceEntityReports
  1969. */
  1970. /**
  1971. * @ref bx_base_general-entity_reports "entity_reports"
  1972. */
  1973. public function serviceEntityReports ($iContentId = 0)
  1974. {
  1975. $mixedContent = $this->_getContent($iContentId);
  1976. list($iContentId, $aContentInfo) = $mixedContent;
  1977. if($iContentId === false)
  1978. return false;
  1979. $CNF = &$this->_oConfig->CNF;
  1980. if (!isset($CNF['OBJECT_REPORTS']) || !isset($CNF['OBJECT_NOTES']))
  1981. return false;
  1982. if(!$aContentInfo || !(BxDolAcl::getInstance()->isMemberLevelInSet(192) || (isset($CNF['FIELD_AUTHOR']) && bx_get_logged_profile_id() == $aContentInfo[$CNF['FIELD_AUTHOR']])))
  1983. return false;
  1984. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $iContentId, true);
  1985. if(!$oReport)
  1986. return false;
  1987. return $oReport->getReportedByWithComments($CNF['OBJECT_NOTES']);
  1988. }
  1989. /**
  1990. * @page service Service Calls
  1991. * @section bx_base_general Base General
  1992. * @subsection bx_base_general-page_blocks Page Blocks
  1993. * @subsubsection bx_base_general-reports_count_by_status reports_count_by_status
  1994. *
  1995. * @code bx_srv('bx_posts', 'reports_count_by_status', [...]); @endcode
  1996. *
  1997. * Get number of reports with specified status
  1998. * @param $iStatus status ID
  1999. *
  2000. * @see BxBaseModGeneralModule::serviceReportsCountByStatus
  2001. */
  2002. /**
  2003. * @ref bx_base_general-entity_reports "entity_reports"
  2004. */
  2005. public function serviceReportsCountByStatus ($iStatus)
  2006. {
  2007. $CNF = &$this->_oConfig->CNF;
  2008. if (!isset($CNF['OBJECT_REPORTS']) || !isset($CNF['OBJECT_NOTES']))
  2009. return false;
  2010. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], 0, false);
  2011. return $oReport->getCountByStatus($iStatus);
  2012. }
  2013. /**
  2014. * @page service Service Calls
  2015. * @section bx_base_general Base General
  2016. * @subsection bx_base_general-menu Menu
  2017. * @subsubsection bx_base_general-entity_social_sharing entity_social_sharing
  2018. *
  2019. * @code bx_srv('bx_posts', 'entity_social_sharing', [...]); @endcode
  2020. *
  2021. * Entry social sharing actions
  2022. * @param $mixedContent content ID or array with integer content ID and
  2023. * array with content info, or false
  2024. * @param $aParams array with additional custom params
  2025. * which may overwrite some default values
  2026. *
  2027. * @see BxBaseModGeneralModule::serviceEntitySocialSharing
  2028. */
  2029. /**
  2030. * @ref bx_base_general-entity_social_sharing "entity_social_sharing"
  2031. */
  2032. public function serviceEntitySocialSharing($mixedContent = false, $aParams = array())
  2033. {
  2034. if(!empty($mixedContent)) {
  2035. if(!is_array($mixedContent))
  2036. $mixedContent = array((int)$mixedContent, array());
  2037. }
  2038. else {
  2039. $mixedContent = $this->_getContent();
  2040. if($mixedContent === false)
  2041. return false;
  2042. }
  2043. list($iContentId, $aContentInfo) = $mixedContent;
  2044. $CNF = &$this->_oConfig->CNF;
  2045. $sUri = !empty($aParams['uri']) ? $aParams['uri'] : '';
  2046. if(empty($sUri) && !empty($CNF['URI_VIEW_ENTRY']))
  2047. $sUri = $CNF['URI_VIEW_ENTRY'];
  2048. $sUrl = !empty($sUri) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $iContentId) : '';
  2049. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  2050. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  2051. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  2052. $aMarkers = array(
  2053. 'id' => $iContentId,
  2054. 'module' => $this->_aModule['name'],
  2055. 'url' => bx_absolute_url($sUrl),
  2056. 'title' => $sTitle,
  2057. );
  2058. $iIdThumb = !empty($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  2059. if(empty($iIdThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  2060. $iIdThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  2061. if ($iIdThumb) {
  2062. $sTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : '';
  2063. $sStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : '';
  2064. if(empty($sStorage) && !empty($CNF['OBJECT_STORAGE']))
  2065. $sStorage = $CNF['OBJECT_STORAGE'];
  2066. if(!empty($sTranscoder))
  2067. $o = BxDolTranscoder::getObjectInstance($sTranscoder);
  2068. else if(!empty($sStorage))
  2069. $o = BxDolStorage::getObjectInstance($sStorage);
  2070. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  2071. if($sImgUrl)
  2072. $aMarkers['img_url'] = $sImgUrl;
  2073. }
  2074. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  2075. $oMenu->addMarkers($aMarkers);
  2076. $sMenu = $oMenu->getCode();
  2077. if(empty($sMenu))
  2078. return '';
  2079. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  2080. 'menu' => $sMenu
  2081. ));
  2082. }
  2083. /**
  2084. * Entry context block
  2085. */
  2086. public function serviceEntityContext ($iContentId = 0)
  2087. {
  2088. return $this->_serviceTemplateFunc ('entryContext', $iContentId);
  2089. }
  2090. /**
  2091. * Blocks for lables tree browsing
  2092. */
  2093. public function serviceGetLablesTree()
  2094. {
  2095. $aBreadcrumbs = array();
  2096. $this->_getLablesBreadcrumbsArray(bx_get('label'), $aBreadcrumbs);
  2097. return $this->_getLablesTreeLevel($aBreadcrumbs);
  2098. }
  2099. public function serviceGetLablesBreadcrumbs()
  2100. {
  2101. if (bx_get('label')){
  2102. $aBreadcrumbs = array();
  2103. $this->_getLablesBreadcrumbsArray(bx_process_input(bx_get('label'), BX_DATA_INT), $aBreadcrumbs);
  2104. $aLabels = array();
  2105. foreach (array_reverse($aBreadcrumbs) as $aLabel){
  2106. $aLabels[] = array(
  2107. 'value' => $aLabel['value'],
  2108. 'url' => $this->_getLablesBrowseUrl($aLabel['id'])
  2109. );
  2110. }
  2111. return $this->_oTemplate->parseHtmlByName('labels_breadcrumbs.html', array('bx_repeat:items' => $aLabels));
  2112. }
  2113. return '';
  2114. }
  2115. public function serviceBrowseByLabel()
  2116. {
  2117. $CNF = &$this->_oConfig->CNF;
  2118. if (empty($CNF['OBJECT_METATAGS']))
  2119. return '';
  2120. $sMode = 'recent';
  2121. if(bx_srv('system', 'is_module_content', [$this->_aModule['name']]))
  2122. $sMode = 'public';
  2123. $sClassSearchResult ='SearchResult';
  2124. bx_import($sClassSearchResult, $this->_aModule['name']);
  2125. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  2126. $o = new $sClass($sMode, false);
  2127. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  2128. $o->setDisplayEmptyMsg(true);
  2129. $o->setAjaxPaginate(false);
  2130. $o->setUnitParams(array('context' => $sMode));
  2131. if (bx_get('label')){
  2132. $iLabelId = (int)bx_get('label');
  2133. $oLabel = BxDolLabel::getInstance();
  2134. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  2135. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2136. $sTmp =$oMetatags->keywordsSetSearchCondition($o, $aLabel['value']);
  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. $CNF = &$this->_oConfig->CNF;
  2148. $sClassSearchResult ='SearchResult';
  2149. bx_import($sClassSearchResult, $this->_aModule['name']);
  2150. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  2151. $o = new $sClass($sMode, array('unit_view' => $sUnitView, 'paginate' => array('perPage' => 10, 'start' => 0, 'num' => 11)));
  2152. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  2153. $o->setAjaxPaginate($bAjaxPaginate);
  2154. $o->setCategoryObject('multi');
  2155. $aCategoriesOutput = array();
  2156. $aCategories = BxDolCategories::getInstance()->getData(array('type' => 'by_module_with_num', 'module' => $this->_aModule['name']));
  2157. foreach($aCategories as $aCategory){
  2158. if ($aCategory['num'] > 0){
  2159. $o->setCustomSearchCondition(array('keyword' => $aCategory['value']));
  2160. $o->setPaginatePerPage(2);
  2161. if (!$o->isError){
  2162. $aResult = $o->processing();
  2163. if ($aResult && $aResult['content'] != '')
  2164. $aCategoriesOutput[] = array('name' => _t($aCategory['value']), 'url' => '', 'content' => $aResult['content']);
  2165. }
  2166. }
  2167. }
  2168. return $this->_oTemplate->parseHtmlByName('browse_by_categories.html', array(
  2169. 'bx_repeat:categories' => $aCategoriesOutput,
  2170. ));
  2171. }
  2172. /**
  2173. * @page service Service Calls
  2174. * @section bx_base_general Base General
  2175. * @subsection bx_base_general-polls Polls Blocks
  2176. * @subsubsection bx_base_general-get_block_poll_answers get_block_poll_answers
  2177. *
  2178. * @code bx_srv('bx_posts', 'get_block_poll_answers', [...]); @endcode
  2179. *
  2180. * Get block with poll answers
  2181. * @param $iPollId poll ID
  2182. *
  2183. * @see BxBaseModGeneralModule::serviceGetBlockPollAnswers
  2184. */
  2185. /**
  2186. * @ref bx_base_general-get_block_poll_answers "get_block_poll_answers"
  2187. */
  2188. public function serviceGetBlockPollAnswers($iPollId, $bForceDisplay = false)
  2189. {
  2190. if(!$iPollId)
  2191. return false;
  2192. if(!$bForceDisplay && $this->isPollPerformed($iPollId))
  2193. return $this->serviceGetBlockPollResults($iPollId);
  2194. return $this->_serviceTemplateFunc('entryPollAnswers', $iPollId, 'getPollInfoById');
  2195. }
  2196. /**
  2197. * @page service Service Calls
  2198. * @section bx_base_general Base General
  2199. * @subsection bx_base_general-polls Polls Blocks
  2200. * @subsubsection bx_base_general-get_block_poll_results get_block_poll_results
  2201. *
  2202. * @code bx_srv('bx_posts', 'get_block_poll_results', [...]); @endcode
  2203. *
  2204. * Get block with poll results
  2205. * @param $iPollId poll ID
  2206. *
  2207. * @see BxBaseModGeneralModule::serviceGetBlockPollResults
  2208. */
  2209. /**
  2210. * @ref bx_base_general-get_block_poll_results "get_block_poll_results"
  2211. */
  2212. public function serviceGetBlockPollResults($iPollId)
  2213. {
  2214. return $this->_serviceTemplateFunc('entryPollResults', $iPollId, 'getPollInfoById');
  2215. }
  2216. /**
  2217. * Data for Notifications module
  2218. */
  2219. public function serviceGetNotificationsData()
  2220. {
  2221. $sModule = $this->_aModule['name'];
  2222. $sEventPrivacy = $sModule . '_allow_view_event_to';
  2223. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  2224. $sEventPrivacy = '';
  2225. $aResult = [
  2226. 'handlers' => [
  2227. ['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],
  2228. ['group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'],
  2229. ['group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'],
  2230. ['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],
  2231. ['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],
  2232. ['group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'],
  2233. ['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],
  2234. ['group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'],
  2235. ['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],
  2236. ['group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'],
  2237. ['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],
  2238. ['group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'],
  2239. ['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],
  2240. ['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],
  2241. //--- Moderation related: For 'admins'.
  2242. ['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],
  2243. ['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],
  2244. ],
  2245. 'settings' => [
  2246. ['group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => ['follow_member', 'follow_context']],
  2247. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'approved', 'types' => ['personal']],
  2248. ['group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => ['personal', 'follow_member', 'follow_context']],
  2249. ['group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => ['personal']],
  2250. ['group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => ['personal', 'follow_member', 'follow_context']],
  2251. ['group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => ['personal', 'follow_member', 'follow_context']],
  2252. ['group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => ['personal', 'follow_member', 'follow_context']],
  2253. ['group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => ['personal', 'follow_member', 'follow_context']],
  2254. //--- Moderation related: For 'admins'.
  2255. ['group' => 'action_required', 'unit' => $sModule, 'action' => 'pending_approval', 'types' => ['personal']],
  2256. ['group' => 'action_required', 'unit' => $sModule, 'action' => 'reported_content', 'types' => ['personal']],
  2257. ],
  2258. 'alerts' => [
  2259. ['unit' => $sModule, 'action' => 'added'],
  2260. ['unit' => $sModule, 'action' => 'edited'],
  2261. ['unit' => $sModule, 'action' => 'deleted'],
  2262. ['unit' => $sModule, 'action' => 'approved'],
  2263. ['unit' => $sModule, 'action' => 'commentPost'],
  2264. ['unit' => $sModule, 'action' => 'commentRemoved'],
  2265. ['unit' => $sModule, 'action' => 'replyPost'],
  2266. ['unit' => $sModule, 'action' => 'replyRemoved'],
  2267. ['unit' => $sModule, 'action' => 'doVote'],
  2268. ['unit' => $sModule, 'action' => 'undoVote'],
  2269. ['unit' => $sModule . '_reactions', 'action' => 'doVote'],
  2270. ['unit' => $sModule . '_reactions', 'action' => 'undoVote'],
  2271. ['unit' => $sModule, 'action' => 'doVoteUp'],
  2272. ['unit' => $sModule, 'action' => 'doVoteDown'],
  2273. //--- Moderation related: For 'admins'.
  2274. ['unit' => $sModule, 'action' => 'pending_approval'],
  2275. ['unit' => $sModule, 'action' => 'reported_content'],
  2276. ]
  2277. ];
  2278. if(!empty($this->_oConfig->CNF['FIELDS_DELAYED_PROCESSING'])) {
  2279. $aResult['handlers'] = array_merge($aResult['handlers'], [
  2280. ['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' => ''],
  2281. ['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' => ''],
  2282. ]);
  2283. $aResult['settings'] = array_merge($aResult['settings'], [
  2284. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => ['personal']],
  2285. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => ['personal']],
  2286. ]);
  2287. $aResult['alerts'] = array_merge($aResult['alerts'], [
  2288. ['unit' => $sModule, 'action' => 'publish_failed'],
  2289. ['unit' => $sModule, 'action' => 'publish_succeeded'],
  2290. ]);
  2291. }
  2292. return $aResult;
  2293. }
  2294. /**
  2295. * Entry post for Notifications module
  2296. */
  2297. public function serviceGetNotificationsPost($aEvent)
  2298. {
  2299. $CNF = &$this->_oConfig->CNF;
  2300. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  2301. if(empty($aContentInfo) || !is_array($aContentInfo))
  2302. return [];
  2303. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  2304. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2305. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2306. return [
  2307. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2308. 'entry_url' => $sEntryUrl,
  2309. 'entry_caption' => $sEntryCaption,
  2310. 'entry_summary' => $sEntrySummary,
  2311. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  2312. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  2313. '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.
  2314. /*
  2315. * Custom settings for email and/or push notifications can be provided here.
  2316. * Only necessary parts of 'settings' array can be used.
  2317. *
  2318. 'settings' => array(
  2319. 'email' => array(
  2320. 'template' => '', //--- custom email template
  2321. 'markers' => '', //--- markers to parse email parts (subject, body) with
  2322. 'subject' => '' //--- custom email subject
  2323. ),
  2324. 'push' => array(
  2325. 'subject' => '' //--- custom push notification subject
  2326. )
  2327. )
  2328. */
  2329. ];
  2330. }
  2331. public function serviceGetNotificationsPostPendingApproval($aEvent)
  2332. {
  2333. return $this->serviceGetNotificationsPostForModeration($aEvent);
  2334. }
  2335. public function serviceGetNotificationsPostReported($aEvent)
  2336. {
  2337. return $this->serviceGetNotificationsPostForModeration($aEvent);
  2338. }
  2339. public function serviceGetNotificationsPostForModeration($aEvent)
  2340. {
  2341. $aResult = $this->serviceGetNotificationsPost($aEvent);
  2342. /**
  2343. * Unset Entry Author because the notification is addressed to 'admins'.
  2344. */
  2345. if(isset($aResult['entry_author']))
  2346. unset($aResult['entry_author']);
  2347. return $aResult;
  2348. }
  2349. public function serviceGetNotificationsPostApproved($aEvent)
  2350. {
  2351. return $this->serviceGetNotificationsPost($aEvent);
  2352. }
  2353. public function serviceGetNotificationsPostPublishFailed($aEvent)
  2354. {
  2355. return $this->serviceGetNotificationsPost($aEvent);
  2356. }
  2357. public function serviceGetNotificationsPostPublishSucceeded($aEvent)
  2358. {
  2359. return $this->serviceGetNotificationsPost($aEvent);
  2360. }
  2361. /**
  2362. * Entry post comment for Notifications module
  2363. */
  2364. public function serviceGetNotificationsComment($aEvent)
  2365. {
  2366. $CNF = &$this->_oConfig->CNF;
  2367. $iContentId = (int)$aEvent['object_id'];
  2368. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2369. if(empty($aContentInfo) || !is_array($aContentInfo))
  2370. return [];
  2371. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  2372. if(!$oComment || !$oComment->isEnabled())
  2373. return [];
  2374. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  2375. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2376. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2377. $iCommentId = (int)$aEvent['subobject_id'];
  2378. return [
  2379. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2380. 'entry_url' => $sEntryUrl,
  2381. 'entry_caption' => $sEntryCaption,
  2382. 'entry_summary' => $sEntrySummary,
  2383. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  2384. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  2385. 'subentry_url' => $oComment->getItemUrl($iCommentId, '{bx_url_root}'),
  2386. 'subentry_url_api' => $oComment->getItemUrlApi($iCommentId, '{bx_url_root}'),
  2387. 'subentry_summary' => $oComment->getViewText($iCommentId),
  2388. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2389. ];
  2390. }
  2391. /**
  2392. * Entry post reply for Notifications module
  2393. */
  2394. public function serviceGetNotificationsReply($aEvent)
  2395. {
  2396. $CNF = &$this->_oConfig->CNF;
  2397. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  2398. if(!$oComment || !$oComment->isEnabled())
  2399. return [];
  2400. $iParentId = (int)$aEvent['object_id'];
  2401. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(['type' => 'id', 'id' => $iParentId]);
  2402. if(empty($aParentInfo) || !is_array($aParentInfo))
  2403. return [];
  2404. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  2405. $oComment->init($iObjectId);
  2406. $iCommentId = (int)$aEvent['subobject_id'];
  2407. return [
  2408. 'object_id' => $iObjectId,
  2409. 'entry_sample' => '_cmt_txt_sample_comment_single',
  2410. 'entry_url' => $oComment->getItemUrl($iParentId, '{bx_url_root}'),
  2411. 'entry_url_api' => $oComment->getItemUrlApi($iParentId, '{bx_url_root}'),
  2412. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  2413. 'entry_summary' => $oComment->getViewText($iParentId),
  2414. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  2415. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  2416. 'subentry_url' => $oComment->getItemUrl($iCommentId, '{bx_url_root}'),
  2417. 'subentry_url_api' => $oComment->getItemUrlApi($iCommentId, '{bx_url_root}'),
  2418. 'subentry_summary' => $oComment->getViewText($iCommentId),
  2419. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2420. ];
  2421. }
  2422. /**
  2423. * Entry post vote for Notifications module
  2424. */
  2425. public function serviceGetNotificationsVote($aEvent)
  2426. {
  2427. $CNF = &$this->_oConfig->CNF;
  2428. $iContentId = (int)$aEvent['object_id'];
  2429. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2430. if(empty($aContentInfo) || !is_array($aContentInfo))
  2431. return [];
  2432. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  2433. if(!$oVote || !$oVote->isEnabled())
  2434. return [];
  2435. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  2436. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2437. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2438. return [
  2439. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2440. 'entry_url' => $sEntryUrl,
  2441. 'entry_caption' => $sEntryCaption,
  2442. 'entry_summary' => $sEntrySummary,
  2443. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  2444. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  2445. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2446. ];
  2447. }
  2448. /**
  2449. * Entry post vote for Notifications module
  2450. */
  2451. public function serviceGetNotificationsReaction($aEvent)
  2452. {
  2453. $CNF = &$this->_oConfig->CNF;
  2454. $iContentId = (int)$aEvent['object_id'];
  2455. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2456. if(empty($aContentInfo) || !is_array($aContentInfo))
  2457. return [];
  2458. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContentId);
  2459. if(!$oReaction || !$oReaction->isEnabled())
  2460. return [];
  2461. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  2462. if(empty($aSubentry) || !is_array($aSubentry))
  2463. return [];
  2464. $aSubentrySampleParams = array();
  2465. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  2466. if(!empty($aReaction['title']))
  2467. $aSubentrySampleParams[] = $aReaction['title'];
  2468. else
  2469. $aSubentrySampleParams[] = '_undefined';
  2470. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  2471. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2472. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2473. return [
  2474. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2475. 'entry_url' => $sEntryUrl,
  2476. 'entry_caption' => $sEntryCaption,
  2477. 'entry_summary' => $sEntrySummary,
  2478. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  2479. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  2480. 'subentry_sample_params' => $aSubentrySampleParams,
  2481. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2482. ];
  2483. }
  2484. /**
  2485. * Entry post score -> vote up for Notifications module
  2486. */
  2487. public function serviceGetNotificationsScoreUp($aEvent)
  2488. {
  2489. return $this->_serviceGetNotificationsScore('up', $aEvent);
  2490. }
  2491. /**
  2492. * Entry post score -> vote up for Notifications module
  2493. */
  2494. public function serviceGetNotificationsScoreDown($aEvent)
  2495. {
  2496. return $this->_serviceGetNotificationsScore('down', $aEvent);
  2497. }
  2498. protected function _serviceGetNotificationsScore($sType, $aEvent)
  2499. {
  2500. $CNF = &$this->_oConfig->CNF;
  2501. $iContentId = (int)$aEvent['object_id'];
  2502. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2503. if(empty($aContentInfo) || !is_array($aContentInfo))
  2504. return array();
  2505. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  2506. if(!$oScore || !$oScore->isEnabled())
  2507. return array();
  2508. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]), '{bx_url_root}');
  2509. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2510. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2511. return [
  2512. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2513. 'entry_url' => $sEntryUrl,
  2514. 'entry_caption' => $sEntryCaption,
  2515. 'entry_summary' => $sEntrySummary,
  2516. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  2517. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  2518. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2519. ];
  2520. }
  2521. /**
  2522. * Data for Reputation module
  2523. */
  2524. public function serviceGetReputationData()
  2525. {
  2526. $sModule = $this->_aModule['name'];
  2527. $aResult = [
  2528. 'handlers' => [
  2529. ['group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'points_active' => 3, 'points_passive' => 0],
  2530. ['group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted', 'points_active' => -3, 'points_passive' => 0],
  2531. ['group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'points_active' => 2, 'points_passive' => 1],
  2532. ['group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved', 'points_active' => -2, 'points_passive' => -1],
  2533. ['group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'points_active' => 1, 'points_passive' => 1],
  2534. ['group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote', 'points_active' => -1, 'points_passive' => -1],
  2535. ['group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'points_active' => 1, 'points_passive' => 1],
  2536. ['group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote', 'points_active' => -1, 'points_passive' => -1],
  2537. ['group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'points_active' => 1, 'points_passive' => 1],
  2538. ['group' => $sModule . '_score_up', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVoteUp', 'points_active' => -1, 'points_passive' => -1],
  2539. ['group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'points_active' => 1, 'points_passive' => -1],
  2540. ['group' => $sModule . '_score_down', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVoteDown', 'points_active' => -1, 'points_passive' => 1],
  2541. ],
  2542. 'alerts' => [
  2543. ['unit' => $sModule, 'action' => 'added'],
  2544. ['unit' => $sModule, 'action' => 'deleted'],
  2545. ['unit' => $sModule, 'action' => 'commentPost'],
  2546. ['unit' => $sModule, 'action' => 'commentRemoved'],
  2547. ['unit' => $sModule, 'action' => 'doVote'],
  2548. ['unit' => $sModule, 'action' => 'undoVote'],
  2549. ['unit' => $sModule . '_reactions', 'action' => 'doVote'],
  2550. ['unit' => $sModule . '_reactions', 'action' => 'undoVote'],
  2551. ['unit' => $sModule, 'action' => 'doVoteUp'],
  2552. ['unit' => $sModule, 'action' => 'undoVoteUp'],
  2553. ['unit' => $sModule, 'action' => 'doVoteDown'],
  2554. ['unit' => $sModule, 'action' => 'undoVoteDown'],
  2555. ]
  2556. ];
  2557. return $aResult;
  2558. }
  2559. /**
  2560. * Data for Timeline module
  2561. */
  2562. public function serviceGetTimelineData()
  2563. {
  2564. $sModule = $this->_aModule['name'];
  2565. return array(
  2566. 'handlers' => array(
  2567. 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' => ''),
  2568. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  2569. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  2570. ),
  2571. 'alerts' => array(
  2572. array('unit' => $sModule, 'action' => 'added'),
  2573. array('unit' => $sModule, 'action' => 'edited'),
  2574. array('unit' => $sModule, 'action' => 'deleted'),
  2575. )
  2576. );
  2577. }
  2578. /**
  2579. * Entry post for Timeline module
  2580. */
  2581. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  2582. {
  2583. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  2584. if(empty($aContentInfo) || !is_array($aContentInfo))
  2585. return false;
  2586. $CNF = &$this->_oConfig->CNF;
  2587. if((!empty($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active') || (!empty($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active'))
  2588. return false;
  2589. $bCache = true;
  2590. $iUserId = $this->getUserId();
  2591. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  2592. $iAuthorIdAbs = abs($iAuthorId);
  2593. /**
  2594. * Don't show anonymous posts on the post's owner timeline
  2595. * and don't cache them when they're viewed by their authors.
  2596. */
  2597. if($iAuthorId < 0 && ((is_numeric($aEvent['owner_id']) && $iAuthorIdAbs == (int)$aEvent['owner_id']) || (is_array($aEvent['owner_id']) && in_array($iAuthorIdAbs, $aEvent['owner_id'])))) {
  2598. if($iAuthorIdAbs != $iUserId)
  2599. return false;
  2600. $bCache = false;
  2601. }
  2602. //--- Views
  2603. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2604. $aViews = array();
  2605. if ($oViews && $oViews->isEnabled())
  2606. $aViews = array(
  2607. 'system' => $CNF['OBJECT_VIEWS'],
  2608. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2609. 'count' => $aContentInfo['views']
  2610. );
  2611. //--- Votes
  2612. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2613. $aVotes = array();
  2614. if ($oVotes && $oVotes->isEnabled())
  2615. $aVotes = array(
  2616. 'system' => $CNF['OBJECT_VOTES'],
  2617. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2618. 'count' => $aContentInfo['votes']
  2619. );
  2620. //--- Reactions
  2621. $oReactions = isset($CNF['OBJECT_REACTIONS']) ? BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2622. $aReactions = array();
  2623. if ($oReactions && $oReactions->isEnabled())
  2624. $aReactions = array(
  2625. 'system' => $CNF['OBJECT_REACTIONS'],
  2626. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2627. 'count' => $aContentInfo['rvotes']
  2628. );
  2629. //--- Scores
  2630. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2631. $aScores = array();
  2632. if ($oScores && $oScores->isEnabled())
  2633. $aScores = array(
  2634. 'system' => $CNF['OBJECT_SCORES'],
  2635. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2636. 'score' => $aContentInfo['score']
  2637. );
  2638. //--- Reports
  2639. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2640. $aReports = array();
  2641. if ($oReports && $oReports->isEnabled())
  2642. $aReports = array(
  2643. 'system' => $CNF['OBJECT_REPORTS'],
  2644. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2645. 'count' => $aContentInfo['reports']
  2646. );
  2647. //--- Comments
  2648. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  2649. $aComments = array();
  2650. if($oCmts && $oCmts->isEnabled())
  2651. $aComments = array(
  2652. 'system' => $CNF['OBJECT_COMMENTS'],
  2653. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  2654. 'count' => $aContentInfo['comments']
  2655. );
  2656. //--- Title & Description
  2657. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  2658. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  2659. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  2660. $iOwnerId = $iAuthorIdAbs;
  2661. if(isset($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0)
  2662. $iOwnerId = abs($aEvent['object_privacy_view']);
  2663. $aContent = $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  2664. if(isset($aContent['_cache'])) {
  2665. if($bCache)
  2666. $bCache = (bool)$aContent['_cache'];
  2667. unset($aContent['_cache']);
  2668. }
  2669. return [
  2670. '_cache' => $bCache,
  2671. 'owner_id' => $iOwnerId,
  2672. 'object_owner_id' => $iAuthorId,
  2673. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  2674. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  2675. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  2676. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  2677. 'url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']])),
  2678. 'content' => $aContent, //a string to display or array to parse default template before displaying.
  2679. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  2680. 'views' => $aViews,
  2681. 'votes' => $aVotes,
  2682. 'reactions' => $aReactions,
  2683. 'scores' => $aScores,
  2684. 'reports' => $aReports,
  2685. 'comments' => $aComments,
  2686. 'title' => $sTitle, //may be empty.
  2687. 'description' => '' //may be empty.
  2688. ];
  2689. }
  2690. public function serviceGetTimelinePostAllowedView($aEvent)
  2691. {
  2692. $iContentId = (int)$aEvent['object_id'];
  2693. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2694. if(empty($aContentInfo) || !is_array($aContentInfo))
  2695. return _t('_sys_txt_access_denied');
  2696. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  2697. }
  2698. /**
  2699. * Check particular action permission without content
  2700. * @param $sAction action to check, for example: Browse, Add
  2701. * @param $iContentId content ID
  2702. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  2703. */
  2704. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  2705. {
  2706. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  2707. if (!method_exists($this, $sMethod))
  2708. return _t('_sys_request_method_not_found_cpt');
  2709. return $this->$sMethod($isPerformAction);
  2710. }
  2711. /**
  2712. * Check particular action permission with content
  2713. * @param $sAction action to check, for example: View, Edit
  2714. * @param $iContentId content ID
  2715. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  2716. */
  2717. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  2718. {
  2719. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  2720. return _t('_sys_request_page_not_found_cpt');
  2721. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  2722. if (!method_exists($this, $sMethod))
  2723. return _t('_sys_request_method_not_found_cpt');
  2724. return $this->$sMethod($aContentInfo, $isPerformAction);
  2725. }
  2726. /**
  2727. * Check particular action permission with content for specified profile
  2728. * @param $sAction action to check, for example: View, Edit
  2729. * @param $iContentId content ID
  2730. * @param $iProfileId profile ID which the permissions to be cheked for
  2731. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  2732. */
  2733. public function serviceCheckAllowedWithContentForProfile($sAction, $iContentId, $iProfileId, $isPerformAction = false)
  2734. {
  2735. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  2736. return _t('_sys_request_page_not_found_cpt');
  2737. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction) . 'ForProfile';
  2738. if (!method_exists($this, $sMethod))
  2739. return _t('_sys_request_method_not_found_cpt');
  2740. return $this->$sMethod($aContentInfo, $iProfileId, $isPerformAction);
  2741. }
  2742. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  2743. {
  2744. //negative id used in comments for reports
  2745. if ($iContentId < 0)
  2746. return CHECK_ACTION_RESULT_ALLOWED;
  2747. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  2748. }
  2749. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  2750. {
  2751. //negative id used in comments for reports
  2752. if ($iContentId < 0)
  2753. return CHECK_ACTION_RESULT_ALLOWED;
  2754. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  2755. }
  2756. public function serviceGetContentOwnerProfileId ($iContentId)
  2757. {
  2758. $CNF = &$this->_oConfig->CNF;
  2759. // file owner must be author of the content or profile itself in case of profile based module
  2760. if ($iContentId) {
  2761. $sModule = $this->getName();
  2762. if ($this instanceof iBxDolProfileService && BxDolService::call($sModule, 'act_as_profile')) {
  2763. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  2764. }
  2765. else {
  2766. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2767. $iContentAuthor = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  2768. if($iContentAuthor < 0)
  2769. $iContentAuthor = abs($iContentAuthor);
  2770. $oProfile = $aContentInfo ? BxDolProfile::getInstance($iContentAuthor) : null;
  2771. }
  2772. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  2773. }
  2774. else
  2775. $iProfileId = bx_get_logged_profile_id();
  2776. return $iProfileId;
  2777. }
  2778. public function serviceGetBadges($iContentId, $bIsSingle = false, $bIsCompact = false)
  2779. {
  2780. $sModule = $this->getName();
  2781. $oBadges = BxDolBadges::getInstance();
  2782. $aBadges = $oBadges->getData(array(
  2783. 'type' => ($bIsSingle ? 'by_module&object2_single' : 'by_module&object2'),
  2784. 'module' => $sModule,
  2785. 'object_id' => $iContentId
  2786. ));
  2787. $sResult = false;
  2788. /**
  2789. * @hooks
  2790. * @hookdef hook-system-get_badges 'system', 'get_badges' - hook to override bages assigned to an entry (content)
  2791. * - $unit_name - equals `system`
  2792. * - $action - equals `get_badges`
  2793. * - $object_id - not used
  2794. * - $sender_id - not used
  2795. * - $extra_params - array of additional params with the following array keys:
  2796. * - `module` - [string] module name
  2797. * - `content_id` - [int] content id
  2798. * - `is_single` - [boolean] only one badge can be used or not
  2799. * - `is_compact` - [boolean] badge in compact mode or not
  2800. * - `badges` - [array] a list of all badges assigned to the content
  2801. * - `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
  2802. * @hook @ref hook-system-get_badges
  2803. */
  2804. bx_alert('system', 'get_badges', 0, 0, [
  2805. 'module' => $sModule,
  2806. 'content_id' => $iContentId,
  2807. 'is_single' => $bIsSingle,
  2808. 'is_compact' => $bIsCompact,
  2809. 'badges' => $aBadges,
  2810. 'override_result' => &$sResult
  2811. ]);
  2812. if($sResult !== false)
  2813. return $sResult;
  2814. if(empty($aBadges) || !is_array($aBadges))
  2815. return $this->_bIsApi ? [] : '';
  2816. if($this->_bIsApi) {
  2817. foreach($aBadges as &$aBadge)
  2818. if(($mixedIcon = $aBadge['icon']) && is_numeric($mixedIcon) && (int)$mixedIcon > 0)
  2819. $aBadge['icon_url'] = $this->_oTemplate->getIcon($aBadge['icon'], ['wrap_in_tag' => false]);
  2820. else
  2821. $aBadge['icon'] = $mixedIcon;
  2822. return $aBadges;
  2823. }
  2824. if($bIsSingle)
  2825. return BxDolService::call('system', 'get_badge', array($aBadges[0], $bIsCompact), 'TemplServices');
  2826. $aBadgesOutput = array();
  2827. foreach($aBadges as $aBadge)
  2828. $aBadgesOutput[] = array('badge' => BxDolService::call('system', 'get_badge', array($aBadge, $bIsCompact), 'TemplServices'));
  2829. return $this->_oTemplate->parseHtmlByName('badges.html', array(
  2830. 'bx_repeat:items' => $aBadgesOutput,
  2831. ));
  2832. }
  2833. /**
  2834. * @page service Service Calls
  2835. * @section bx_base_general Base General
  2836. * @subsection bx_base_general-page_blocks Page Blocks
  2837. * @subsubsection bx_base_general-categories_multi_list categories_multi_list
  2838. *
  2839. * @code bx_srv('bx_posts', 'categories_multi_list', [...]); @endcode
  2840. *
  2841. * Display multi-categorories block with number of posts in each category
  2842. * @param $bAsArray boolean reature as array or not.
  2843. *
  2844. * @see BxBaseModGeneralModule::serviceCategoriesMultiList
  2845. */
  2846. /**
  2847. * @ref bx_base_general-categories_multi_list "categories_multi_list"
  2848. */
  2849. public function serviceCategoriesMultiList($bAsArray = false)
  2850. {
  2851. $oCategories = BxDolCategories::getInstance();
  2852. $oCategories->setModule($this->getName());
  2853. $mixedResult = $oCategories->getCategoriesList($bAsArray || $this->_bIsApi);
  2854. return !$this->_bIsApi ? $mixedResult : [bx_api_get_block('categories_list', $mixedResult)];
  2855. }
  2856. /**
  2857. * ======
  2858. * PERMISSION METHODS
  2859. * ======
  2860. */
  2861. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  2862. {
  2863. $mixedResult = $this->_serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  2864. /**
  2865. * @hooks
  2866. * @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
  2867. * - $unit_name - equals `system`
  2868. * - $action - equals `check_allowed_view`
  2869. * - $object_id - not used
  2870. * - $sender_id - not used
  2871. * - $extra_params - array of additional params with the following array keys:
  2872. * - `module` - [string] module name
  2873. * - `content_info` - [array] content info array as key&value pairs
  2874. * - `profile_id` - [boolean] or [int] profile id to be checked the availability of the action to
  2875. * - `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
  2876. * @hook @ref hook-system-check_allowed_view
  2877. */
  2878. bx_alert('system', 'check_allowed_view', 0, 0, [
  2879. 'module' => $this->getName(),
  2880. 'content_info' => $aDataEntry,
  2881. 'profile_id' => $iProfileId,
  2882. 'override_result' => &$mixedResult
  2883. ]);
  2884. return $mixedResult;
  2885. }
  2886. public function checkAllowedSetThumb ($iContentId = 0)
  2887. {
  2888. return CHECK_ACTION_RESULT_ALLOWED;
  2889. }
  2890. /**
  2891. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2892. */
  2893. public function checkAllowedBrowse ()
  2894. {
  2895. $mixedResult = null;
  2896. /**
  2897. * @hooks
  2898. * @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
  2899. * It's equivalent to @ref hook-system-check_allowed_view
  2900. * except `content_info` parameter in $extra_params is missing
  2901. * @hook @ref hook-system-check_allowed_browse
  2902. */
  2903. bx_alert('system', 'check_allowed_browse', 0, 0, [
  2904. 'module' => $this->getName(),
  2905. 'profile_id' => $this->_iProfileId,
  2906. 'override_result' => &$mixedResult
  2907. ]);
  2908. if($mixedResult !== null)
  2909. return $mixedResult;
  2910. return CHECK_ACTION_RESULT_ALLOWED;
  2911. }
  2912. /**
  2913. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2914. */
  2915. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  2916. {
  2917. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  2918. }
  2919. /**
  2920. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2921. */
  2922. public function checkAllowedViewForProfile ($aDataEntry, $iProfileId, $isPerformAction = false)
  2923. {
  2924. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  2925. }
  2926. /**
  2927. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2928. */
  2929. public function checkAllowedAdd ($isPerformAction = false)
  2930. {
  2931. // check ACL
  2932. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  2933. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2934. return $aCheck[CHECK_ACTION_MESSAGE];
  2935. return CHECK_ACTION_RESULT_ALLOWED;
  2936. }
  2937. public function serviceCheckAllowedAddInContext($sContextModule)
  2938. {
  2939. $CNF = &$this->_oConfig->CNF;
  2940. if(($sKey = 'OBJECT_PRIVACY_VIEW') && !empty($CNF[$sKey]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF[$sKey])) !== false && !$oPrivacy->isAllowedAddInContext($sContextModule))
  2941. return _t('_sys_txt_access_denied');
  2942. return CHECK_ACTION_RESULT_ALLOWED;
  2943. }
  2944. /**
  2945. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2946. */
  2947. public function checkAllowedApprove ($aDataEntry, $isPerformAction = false)
  2948. {
  2949. $CNF = &$this->_oConfig->CNF;
  2950. $sError = '_sys_txt_access_denied';
  2951. if($this->_oConfig->isAutoApproveEnabled())
  2952. return _t($sError);
  2953. if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_GENERAL_STATUS_PENDING)
  2954. return _t($sError);
  2955. // moderator always have access
  2956. if ($this->_isModerator($isPerformAction))
  2957. return CHECK_ACTION_RESULT_ALLOWED;
  2958. // check for context's admins
  2959. if (!empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  2960. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]);
  2961. if ($oProfile){
  2962. $sModule = $oProfile->getModule();
  2963. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  2964. $oModule = BxDolModule::getInstance($sModule);
  2965. // check for context's extra roles with rights
  2966. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  2967. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  2968. if ($bResult !== NULL) return $bResult;
  2969. }
  2970. // if allowed edit a group then allowed to edit anything inside its context
  2971. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  2972. return CHECK_ACTION_RESULT_ALLOWED;
  2973. }
  2974. }
  2975. }
  2976. return _t($sError);
  2977. }
  2978. /**
  2979. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2980. */
  2981. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  2982. {
  2983. // moderator and owner always have access
  2984. if ($this->isEntryAuthor($aDataEntry, $this->_iProfileId) || $this->_isModerator($isPerformAction))
  2985. return CHECK_ACTION_RESULT_ALLOWED;
  2986. // check for context's admins
  2987. if (!empty($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  2988. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  2989. if ($oProfile){
  2990. $sModule = $oProfile->getModule();
  2991. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  2992. $oModule = BxDolModule::getInstance($sModule);
  2993. // check for context's extra roles with rights
  2994. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  2995. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  2996. if ($bResult !== NULL) return $bResult;
  2997. }
  2998. // if allowed edit a group then allowed to edit anything inside its context
  2999. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  3000. return CHECK_ACTION_RESULT_ALLOWED;
  3001. }
  3002. }
  3003. }
  3004. return _t('_sys_txt_access_denied');
  3005. }
  3006. /**
  3007. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3008. */
  3009. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  3010. {
  3011. // moderator always has access
  3012. if ($this->_isAdministrator($isPerformAction))
  3013. return CHECK_ACTION_RESULT_ALLOWED;
  3014. // check ACL
  3015. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  3016. if ($this->isEntryAuthor($aDataEntry, $this->_iProfileId) && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  3017. return CHECK_ACTION_RESULT_ALLOWED;
  3018. // check for context's admins
  3019. if (isset($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0){
  3020. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  3021. if ($oProfile){
  3022. $sModule = $oProfile->getModule();
  3023. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  3024. $oModule = BxDolModule::getInstance($sModule);
  3025. // check for context's extra roles with rights
  3026. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  3027. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'delete_any');
  3028. if ($bResult !== NULL) return $bResult;
  3029. }
  3030. // if allowed delete a group then allowed to delete anything inside its context
  3031. if(isset($aEntity) && $oModule->checkAllowedDelete($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  3032. return CHECK_ACTION_RESULT_ALLOWED;
  3033. }
  3034. }
  3035. }
  3036. return _t('_sys_txt_access_denied');
  3037. }
  3038. /**
  3039. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3040. */
  3041. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  3042. {
  3043. // admin always has access
  3044. if (isAdmin())
  3045. return CHECK_ACTION_RESULT_ALLOWED;
  3046. // check ACL
  3047. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  3048. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  3049. return $aCheck[CHECK_ACTION_MESSAGE];
  3050. return CHECK_ACTION_RESULT_ALLOWED;
  3051. }
  3052. /**
  3053. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3054. */
  3055. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  3056. {
  3057. return $this->checkAllowedEditAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  3058. }
  3059. /**
  3060. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3061. */
  3062. public function checkAllowedDeleteAnyEntry ($isPerformAction = false)
  3063. {
  3064. return $this->checkAllowedDeleteAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  3065. }
  3066. /**
  3067. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3068. */
  3069. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  3070. {
  3071. if(!$iProfileId)
  3072. $iProfileId = $this->_iProfileId;
  3073. $aCheck = checkActionModule($iProfileId, MEMBERSHIP_ACTION_EDIT_ANY_ENTRY, $this->getName(), $isPerformAction);
  3074. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  3075. return CHECK_ACTION_RESULT_ALLOWED;
  3076. return _t('_sys_txt_access_denied');
  3077. }
  3078. /**
  3079. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  3080. */
  3081. public function checkAllowedDeleteAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  3082. {
  3083. if(!$iProfileId)
  3084. $iProfileId = $this->_iProfileId;
  3085. $aCheck = checkActionModule($iProfileId, MEMBERSHIP_ACTION_DELETE_ANY_ENTRY, $this->getName(), $isPerformAction);
  3086. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  3087. return CHECK_ACTION_RESULT_ALLOWED;
  3088. return _t('_sys_txt_access_denied');
  3089. }
  3090. /**
  3091. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  3092. */
  3093. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  3094. {
  3095. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  3096. }
  3097. /**
  3098. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  3099. */
  3100. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  3101. {
  3102. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  3103. }
  3104. protected function _serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId)
  3105. {
  3106. $CNF = &$this->_oConfig->CNF;
  3107. if(!$iProfileId)
  3108. $iProfileId = $this->_iProfileId;
  3109. if(empty($aDataEntry) || !is_array($aDataEntry))
  3110. return _t('_sys_txt_not_found');
  3111. if(!empty($iProfileId) && abs($aDataEntry[$CNF['FIELD_AUTHOR']]) == (int)$iProfileId)
  3112. return CHECK_ACTION_RESULT_ALLOWED;
  3113. // below goes mem cached response for current page load
  3114. $sCacheKey = $this->getName() . ':' . __CLASS__ . ':_checkAllowedViewForProfile:' . $aDataEntry[$CNF['FIELD_ID']] . ':' . $iProfileId;
  3115. $mixedRet = bx_mem_cache_get($sCacheKey);
  3116. if (null !== $mixedRet)
  3117. return $mixedRet;
  3118. $mixedRet = CHECK_ACTION_RESULT_ALLOWED;
  3119. if (empty($iProfileId) || !$this->_isModeratorForProfile($isPerformAction, $iProfileId)) { // skip checking if moderator
  3120. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  3121. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED) { // check ACL
  3122. $mixedRet = $aCheck[CHECK_ACTION_MESSAGE];
  3123. } elseif(!empty($CNF['OBJECT_PRIVACY_VIEW'])) { // check privacy
  3124. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  3125. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  3126. $mixedRet = _t('_sys_access_denied_to_private_content');
  3127. }
  3128. }
  3129. bx_mem_cache_set($sCacheKey, $mixedRet);
  3130. return $mixedRet;
  3131. }
  3132. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  3133. {
  3134. if(CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  3135. return $this->_bIsApi ? [bx_api_get_msg($sMsg)] : MsgBox($sMsg);
  3136. bx_import($sClassSearchResult, $this->_aModule);
  3137. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  3138. $o = new $sClass($sMode, $aParams);
  3139. $o->setDesignBoxTemplateId($iDesignBox);
  3140. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  3141. $o->setAjaxPaginate($bAjaxPaginate);
  3142. $o->setUnitParams(array('context' => $sMode));
  3143. if(isset($aParams['condition']) && is_array($aParams['condition']))
  3144. $o->setCustomCurrentCondition($aParams['condition']);
  3145. if($o->isError)
  3146. return '';
  3147. if($this->_bIsApi) {
  3148. $aBlock = BxDolPage::getBlockProcessing();
  3149. $sContentType = 'browse';
  3150. if(($sK = 'config_api') && $aBlock[$sK] && is_array($aBlock[$sK]))
  3151. $sContentType = $aBlock[$sK]['content_type'] ?? $sContentType;
  3152. $bBrowseSimple = $sContentType == 'browse_simple';
  3153. $a = $o->processingAPI($bBrowseSimple);
  3154. return !$bBrowseSimple || $a['data'] ? [bx_api_get_block($sContentType, $a)] : [];
  3155. }
  3156. else
  3157. return ($s = $o->processing()) ? $s : '';
  3158. }
  3159. /**
  3160. * Shows a list of profiles.
  3161. */
  3162. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4, $aAdditionalParams = [])
  3163. {
  3164. return bx_srv('system', 'browse_quick', [$aProfiles, $iStart, $iLimit, ['additional_params' => $aAdditionalParams]], 'TemplServiceProfiles');
  3165. }
  3166. // ====== COMMON METHODS
  3167. public function isPollPerformed($iObjectId, $iAuthorId = 0, $iAuthorIp = 0)
  3168. {
  3169. if(empty($iAuthorId)) {
  3170. $iAuthorId = bx_get_logged_profile_id();
  3171. $iAuthorIp = bx_get_ip_hash(getVisitorIP());
  3172. }
  3173. return $this->_oDb->isPollPerformed($iObjectId, $iAuthorId, $iAuthorIp);
  3174. }
  3175. public function getPollPerformedValue($iObjectId, $iAuthorId = 0)
  3176. {
  3177. if(empty($iAuthorId))
  3178. $iAuthorId = bx_get_logged_profile_id();
  3179. return $this->_oDb->getPollPerformedValue($iObjectId, $iAuthorId);
  3180. }
  3181. public function onPublished($iContentId)
  3182. {
  3183. $CNF = &$this->_oConfig->CNF;
  3184. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  3185. if(!$aContentInfo)
  3186. return;
  3187. /*
  3188. * Process metas.
  3189. * Note. It's essential to process metas a the very end,
  3190. * because all data related to an entry should be already
  3191. * processed and are ready to be passed to alert.
  3192. */
  3193. $this->processMetasAdd($iContentId);
  3194. $this->alertAfterAdd($aContentInfo);
  3195. }
  3196. public function onFailed($iContentId)
  3197. {
  3198. $CNF = &$this->_oConfig->CNF;
  3199. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  3200. if(!$aContentInfo)
  3201. return;
  3202. /**
  3203. * @hooks
  3204. * @hookdef hook-bx_base_general-failed '{module_name}', 'failed' - hook after content creation when publishing was failed
  3205. * - $unit_name - module name
  3206. * - $action - equals `failed`
  3207. * - $object_id - content id
  3208. * - $sender_id - content author profile id
  3209. * - $extra_params - array of additional params with the following array keys:
  3210. * - `object_author_id` - [int] content author profile id
  3211. * @hook @ref hook-bx_base_general-failed
  3212. */
  3213. bx_alert($this->getName(), 'failed', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], [
  3214. 'object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]
  3215. ]);
  3216. }
  3217. public function onApprove($mixedContent)
  3218. {
  3219. $CNF = &$this->_oConfig->CNF;
  3220. if(!is_array($mixedContent))
  3221. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  3222. $this->alertAfterApprove($mixedContent);
  3223. $this->onPublished($mixedContent[$CNF['FIELD_ID']]);
  3224. }
  3225. public function onUpdateImage($iContentId, $sFiledName, $sFiledValue, $iProfileId = 0) {}
  3226. public function alertAfterAdd($aContentInfo) {}
  3227. public function alertAfterEdit($aContentInfo) {}
  3228. public function alertAfterApprove($aContentInfo)
  3229. {
  3230. $CNF = &$this->_oConfig->CNF;
  3231. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  3232. $sModule = $this->getName();
  3233. $aParams = $this->_alertParams($aContentInfo);
  3234. /**
  3235. * @hooks
  3236. * @hookdef hook-bx_base_general-approved '{module_name}', 'approved' - hook when module content has been approved
  3237. * - $unit_name - module name
  3238. * - $action - equals `approved`
  3239. * - $object_id - content id
  3240. * - $sender_id - not used, always `false`
  3241. * - $extra_params - array of additional params with the following array keys:
  3242. * - `source` - [string] uniq string for particular content in the following format `{module}_{content}`
  3243. * - `object_author_id` - [int] content author profile id
  3244. * @hook @ref hook-bx_base_general-approved
  3245. */
  3246. bx_alert($sModule, 'approved', $iId, false, $aParams);
  3247. }
  3248. /**
  3249. * Get array of params to be passed in Add/Edit Alert.
  3250. */
  3251. protected function _alertParams($aContentInfo)
  3252. {
  3253. $CNF = &$this->_oConfig->CNF;
  3254. return [
  3255. 'source' => $this->_oConfig->getName() . '_' . (int)$aContentInfo[$CNF['FIELD_ID']],
  3256. 'object_author_id' => (int)$aContentInfo[$CNF['FIELD_AUTHOR']]
  3257. ];
  3258. }
  3259. public function processMetasAdd($iContentId)
  3260. {
  3261. return $this->processMetas('add', $iContentId);
  3262. }
  3263. public function processMetasEdit($iContentId, $oForm)
  3264. {
  3265. return $this->processMetas('edit', $iContentId, $oForm);
  3266. }
  3267. public function processMetas($aAction, $iContentId, $oForm = false)
  3268. {
  3269. $CNF = &$this->_oConfig->CNF;
  3270. if(empty($CNF['OBJECT_METATAGS']))
  3271. return false;
  3272. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  3273. $bFldStatus = !empty($CNF['FIELD_STATUS']);
  3274. $bFldStatusAdmin = !empty($CNF['FIELD_STATUS_ADMIN']);
  3275. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  3276. if(!$bContentInfo)
  3277. return false;
  3278. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  3279. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_' . strtoupper($aAction)]);
  3280. if($oMetatags->locationsIsEnabled() && ($sKey = 'FIELD_LOCATION') && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  3281. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  3282. if(!empty($aLocation) && is_array($aLocation))
  3283. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  3284. }
  3285. if($oMetatags->keywordsIsEnabled() && ($sKey = 'FIELD_LABELS') && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  3286. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  3287. if(!empty($aLabels) && is_array($aLabels))
  3288. foreach ($aLabels as $sLabel) {
  3289. if(!preg_match("/(\pL[\pL\pN_]+)/u", $sLabel))
  3290. continue;
  3291. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  3292. }
  3293. }
  3294. return true;
  3295. }
  3296. public function addAttachLink($aValues, $sDisplay = false)
  3297. {
  3298. $CNF = &$this->_oConfig->CNF;
  3299. if(!$sDisplay)
  3300. $sDisplay = $CNF['OBJECT_FORM_ATTACH_LINK_DISPLAY_ADD'];
  3301. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ATTACH_LINK'], $sDisplay, $this->_oTemplate);
  3302. if(!$oForm)
  3303. return array('message' => '_sys_txt_error_occured');
  3304. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  3305. $oForm->aParams['csrf']['disable'] = true;
  3306. if(!empty($oForm->aParams['db']['submit_name'])) {
  3307. $sSubmitName = $oForm->aParams['db']['submit_name'];
  3308. if(!isset($oForm->aInputs[$sSubmitName])) {
  3309. if(isset($oForm->aInputs[$CNF['FIELD_ATTACH_LINK_CONTROLS']]))
  3310. foreach($oForm->aInputs[$CNF['FIELD_ATTACH_LINK_CONTROLS']] as $mixedIndex => $aInput) {
  3311. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  3312. continue;
  3313. $aValues[$sSubmitName] = $aInput['value'];
  3314. }
  3315. }
  3316. else
  3317. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  3318. }
  3319. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  3320. $oForm->initChecker(array(), $aValues);
  3321. if(!$oForm->isSubmittedAndValid())
  3322. return array('message' => '_sys_txt_error_occured');
  3323. return $this->_addLink($oForm);
  3324. }
  3325. public function getFormAttachLink($iContentId = 0)
  3326. {
  3327. $CNF = &$this->_oConfig->CNF;
  3328. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ATTACH_LINK'], $CNF['OBJECT_FORM_ATTACH_LINK_DISPLAY_ADD'], $this->_oTemplate);
  3329. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  3330. $oForm->aInputs[$CNF['FIELD_ATTACH_LINK_CONTENT_ID']]['value'] = $iContentId;
  3331. $oForm->aInputs[$CNF['FIELD_ATTACH_LINK_URL']]['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  3332. $oForm->initChecker();
  3333. if($oForm->isSubmittedAndValid())
  3334. return $this->_addLink($oForm);
  3335. return ['form' => $oForm->getCode(), 'form_id' => $oForm->id];
  3336. }
  3337. protected function _addLink(&$oForm)
  3338. {
  3339. $CNF = &$this->_oConfig->CNF;
  3340. $iUserId = $this->getUserId();
  3341. $iContentId = (int)$oForm->getCleanValue($CNF['FIELD_ATTACH_LINK_CONTENT_ID']);
  3342. $sLink = rtrim($oForm->getCleanValue('url'), '/');
  3343. $sHost = parse_url($sLink, PHP_URL_HOST);
  3344. if($sHost && is_private_ip(gethostbyname($sHost)))
  3345. return ['message' => _t('_sys_txt_error_occured')];
  3346. $aMatches = [];
  3347. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  3348. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  3349. $aSiteInfo = bx_get_site_info($sLink, [
  3350. 'thumbnailUrl' => ['tag' => 'link', 'content_attr' => 'href'],
  3351. 'OGImage' => ['name_attr' => 'property', 'name' => 'og:image'],
  3352. ]);
  3353. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : $sHost;
  3354. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : '';
  3355. $sMediaUrl = '';
  3356. if(!empty($aSiteInfo['thumbnailUrl']))
  3357. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  3358. else if(!empty($aSiteInfo['OGImage']))
  3359. $sMediaUrl = $aSiteInfo['OGImage'];
  3360. $iMediaId = 0;
  3361. $oStorage = null;
  3362. if(!empty($sMediaUrl)) {
  3363. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  3364. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  3365. }
  3366. $iId = (int)$oForm->insert(['profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()]);
  3367. if(!empty($iId)) {
  3368. if(!empty($oStorage) && !empty($iMediaId))
  3369. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  3370. return [
  3371. 'id' => $iId,
  3372. $CNF['FIELD_ATTACH_LINK_CONTENT_ID'] => $iContentId,
  3373. 'url' => $sLink,
  3374. 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId)
  3375. ];
  3376. }
  3377. return ['message' => _t('_bx_timeline_txt_err_cannot_perform_action')];
  3378. }
  3379. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  3380. {
  3381. if(empty($aTranscoders))
  3382. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  3383. $CNF = &$this->_oConfig->CNF;
  3384. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  3385. return false;
  3386. $iId = (int)$aContentInfo[$CNF[$sField]];
  3387. $aFile = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE'])->getFile($iId);
  3388. if(!empty($aFile) && is_array($aFile) && strpos($aFile['mime_type'], 'svg') !== false)
  3389. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  3390. foreach($aTranscoders as $sTranscoder)
  3391. if(!empty($CNF[$sTranscoder]))
  3392. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  3393. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  3394. }
  3395. public function getEntryAllActions ($mixedContent = false, $aParams = [])
  3396. {
  3397. $CNF = &$this->_oConfig->CNF;
  3398. if(!empty($mixedContent)) {
  3399. if(!is_array($mixedContent))
  3400. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  3401. }
  3402. else {
  3403. $mixedContent = $this->_getContent();
  3404. if($mixedContent === false)
  3405. return false;
  3406. }
  3407. list($iContentId, $aContentInfo) = $mixedContent;
  3408. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  3409. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  3410. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL'];
  3411. if(empty($sObjectMenu))
  3412. return false;
  3413. $sEntryTitle = !empty($aParams['entry_title']) ? $aParams['entry_title'] : '';
  3414. if(empty($sEntryTitle) && !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  3415. $sEntryTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  3416. $sEntryUrl = !empty($aParams['entry_url']) ? $aParams['entry_url'] : '';
  3417. if(empty($sEntryUrl) && !empty($CNF['URI_VIEW_ENTRY']))
  3418. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId));
  3419. $iEntryThumb = !empty($aParams['entry_thumb']) ? (int)$aParams['entry_thumb'] : 0;
  3420. if(empty($iEntryThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  3421. $iEntryThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  3422. $sObjectStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : false;
  3423. if(empty($sObjectStorage) && !empty($CNF['OBJECT_STORAGE']))
  3424. $sObjectStorage = $CNF['OBJECT_STORAGE'];
  3425. $sObjectTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : false;
  3426. $aMarkers = [
  3427. 'id' => $iContentId,
  3428. 'module' => $this->_oConfig->getName(),
  3429. 'title' => !empty($sEntryTitle) ? $sEntryTitle : '',
  3430. 'url' => !empty($sEntryUrl) ? $sEntryUrl : '',
  3431. 'img_url' => ''
  3432. ];
  3433. if(!empty($iEntryThumb)) {
  3434. if(!empty($sObjectTranscoder))
  3435. $o = BxDolTranscoder::getObjectInstance($sObjectTranscoder);
  3436. else if(!empty($sObjectStorage))
  3437. $o = BxDolStorage::getObjectInstance($sObjectStorage);
  3438. $sImageUrl = $o ? $o->getFileUrlById($iEntryThumb) : '';
  3439. if(!empty($sImageUrl))
  3440. $aMarkers['img_url'] = $sImageUrl;
  3441. }
  3442. $oActions = BxDolMenu::getObjectInstance($sObjectMenu, $this->_oTemplate);
  3443. if(!$oActions)
  3444. return false;
  3445. $oActions->setContentId($iContentId);
  3446. $oActions->addMarkers($aMarkers);
  3447. return $oActions->{bx_is_api() ? 'getCodeAPI' : 'getCode'}();
  3448. }
  3449. public function getProfileId()
  3450. {
  3451. return bx_get_logged_profile_id();
  3452. }
  3453. public function getProfileInfo($iUserId = false)
  3454. {
  3455. $oProfile = $this->getObjectUser($iUserId);
  3456. $oAccount = null;
  3457. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  3458. $oAccount = $oProfile->getAccountObject();
  3459. $bAccount = !empty($oAccount);
  3460. if(!$bAccount)
  3461. $oProfile = BxDolProfileUndefined::getInstance();
  3462. return array(
  3463. 'id' => $oProfile->id(),
  3464. 'name' => $oProfile->getDisplayName(),
  3465. 'email' => $bAccount ? $oAccount->getEmail() : '',
  3466. 'link' => $oProfile->getUrl(),
  3467. 'icon' => $oProfile->getIcon(),
  3468. 'thumb' => $oProfile->getThumb(),
  3469. 'avatar' => $oProfile->getAvatar(),
  3470. 'active' => $oProfile->isActive(),
  3471. );
  3472. }
  3473. public function getObjectUser($iUserId = false)
  3474. {
  3475. bx_import('BxDolProfile');
  3476. return BxDolProfile::getInstanceMagic($iUserId);
  3477. }
  3478. public function getObjectFavorite($sSystem = '', $iId = 0)
  3479. {
  3480. $CNF = &$this->_oConfig->CNF;
  3481. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  3482. $sSystem = $CNF['OBJECT_FAVORITES'];
  3483. if(empty($sSystem))
  3484. return false;
  3485. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3486. if(!$oFavorite || !$oFavorite->isEnabled())
  3487. return false;
  3488. return $oFavorite;
  3489. }
  3490. public function getUserId()
  3491. {
  3492. return isLogged() ? bx_get_logged_profile_id() : 0;
  3493. }
  3494. public function getUserIp()
  3495. {
  3496. return getVisitorIP();
  3497. }
  3498. public function getUserInfo($iUserId = 0)
  3499. {
  3500. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  3501. return array(
  3502. $oProfile->getDisplayName(),
  3503. $oProfile->getUrl(),
  3504. $oProfile->getThumb(),
  3505. $oProfile->getUnit(),
  3506. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  3507. );
  3508. }
  3509. public function getUserInfoWithBadges($iUserId = 0)
  3510. {
  3511. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  3512. return array(
  3513. $oProfile->getDisplayName(),
  3514. $oProfile->getUrl(),
  3515. $oProfile->getThumb(),
  3516. $oProfile->getUnit(),
  3517. $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  3518. $oProfile->getBadges()
  3519. );
  3520. }
  3521. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  3522. {
  3523. $CNF = &$this->_oConfig->CNF;
  3524. // default visible settings
  3525. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  3526. return false;
  3527. if (!empty($aItem['visibility_custom'])) {
  3528. $oMenu = BxDolMenu::getObjectInstance($sObject);
  3529. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $oMenu->getMarkers()))
  3530. return false;
  3531. }
  3532. // get custom function name to check menu item visibility
  3533. $sFuncCheckAccess = false;
  3534. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  3535. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  3536. // check custom visibility settings defined in module config class
  3537. if(!isset($aContentInfo))
  3538. $aContentInfo = array();
  3539. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), array(&$aContentInfo)))
  3540. return false;
  3541. return true;
  3542. }
  3543. public function getModerators($mixedContentInfo)
  3544. {
  3545. $CNF = &$this->_oConfig->CNF;
  3546. $sModule = $this->_oConfig->getName();
  3547. if(!is_array($mixedContentInfo))
  3548. $mixedContentInfo = $this->_oDb->getContentInfoById((int)$mixedContentInfo);
  3549. $aModerators = [];
  3550. 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) {
  3551. $iContextProfileId = abs((int)$mixedContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  3552. $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
  3553. $aModerators = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
  3554. }
  3555. if(empty($aModerators))
  3556. $aModerators = BxDolAclQuery::getInstance()->getProfilesByAction([
  3557. MEMBERSHIP_ACTION_EDIT_ANY_ENTRY,
  3558. MEMBERSHIP_ACTION_DELETE_ANY_ENTRY
  3559. ], [
  3560. 'module' => $sModule,
  3561. 'ids_only' => true
  3562. ]);
  3563. return $aModerators;
  3564. }
  3565. public function _isModerator ($isPerformAction = false)
  3566. {
  3567. return $this->_isModeratorForProfile($isPerformAction, $this->_iProfileId);
  3568. }
  3569. public function _isModeratorForProfile($isPerformAction = false, $iProfileId = false)
  3570. {
  3571. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntryForProfile ($isPerformAction, $iProfileId);
  3572. }
  3573. public function _isAdministrator ($isPerformAction = false)
  3574. {
  3575. return $this->_isAdministratorForProfile($isPerformAction, $this->_iProfileId);
  3576. }
  3577. public function _isAdministratorForProfile($isPerformAction = false, $iProfileId = false)
  3578. {
  3579. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedDeleteAnyEntryForProfile ($isPerformAction, $iProfileId);
  3580. }
  3581. public function _prepareAuditParams($aContentInfo, $bIsSaveData = true, $aOverrideAuditParams = array())
  3582. {
  3583. $CNF = &$this->_oConfig->CNF;
  3584. $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;
  3585. $AuditParams = array(
  3586. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  3587. 'context_profile_id' => $iContextId,
  3588. 'content_info_object' => isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
  3589. 'data' => ($bIsSaveData ? $aContentInfo : array())
  3590. );
  3591. if ($iContextId > 0)
  3592. $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
  3593. $AuditParams = array_merge($AuditParams, $aOverrideAuditParams);
  3594. return $AuditParams;
  3595. }
  3596. public function _getFavoriteListUrl ($iListId, $iProfileId)
  3597. {
  3598. $CNF = &$this->_oConfig->CNF;
  3599. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_FAVORITES_LIST'] . '&profile_id=' . $iProfileId . '&list_id=' . $iListId));
  3600. }
  3601. public function getDataAPI($aData, $aParams = [])
  3602. {
  3603. $aDataApi = $this->decodeDataAPI($aData, $aParams);
  3604. $sModule = $this->getName();
  3605. $aExtras = [
  3606. 'module' => $sModule,
  3607. 'data' => $aData,
  3608. 'params' => $aParams,
  3609. 'data_api' => &$aDataApi,
  3610. ];
  3611. /**
  3612. * @hooks
  3613. * @hookdef hook-system-decode_data_api 'system', 'decode_data_api' - hook to override content data prepared for sending in API response
  3614. * - $unit_name - equals `system`
  3615. * - $action - equals `decode_data_api`
  3616. * - $object_id - not used
  3617. * - $sender_id - not used
  3618. * - $extra_params - array of additional params with the following array keys:
  3619. * - `module` - [string] module name
  3620. * - `data` - [array] content info array as key&value pairs
  3621. * - `params` - [array] params array as key&value pairs
  3622. * - `data_api` - [array] by ref, content data prepared for sending in API response, can be overridden in hook processing
  3623. * @hook @ref hook-system-decode_data_api
  3624. */
  3625. bx_alert('system', 'decode_data_api', 0, 0, $aExtras);
  3626. /**
  3627. * @hooks
  3628. * @hookdef hook-bx_base_general-decode_data_api '{module_name}', 'decode_data_api' - hook to override content data prepared for sending in API response
  3629. * It's equivalent to @ref hook-system-decode_data_api
  3630. * @hook @ref hook-bx_base_general-decode_data_api
  3631. */
  3632. bx_alert($sModule, 'decode_data_api', 0, 0, $aExtras);
  3633. return $aDataApi;
  3634. }
  3635. public function decodeDataAPI($aData, $aParams = [])
  3636. {
  3637. return $aData;
  3638. }
  3639. // ====== PROTECTED METHODS
  3640. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  3641. {
  3642. $iContentId = $this->_getContent($iContentId, false);
  3643. if($iContentId === false)
  3644. return false;
  3645. $oFormsHelper = $this->getFormsHelper();
  3646. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  3647. }
  3648. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  3649. {
  3650. return $this->_serviceTemplateFuncEx($sFunc, $iContentId, array('function_get_content' => $sFuncGetContent));
  3651. }
  3652. protected function _serviceTemplateFuncEx ($sFunc, $iContentId, $aParams = array())
  3653. {
  3654. if (!isset($aParams['function_get_content']))
  3655. $aParams['function_get_content'] = 'getContentInfoById';
  3656. $mixedContent = $this->_getContent($iContentId, $aParams['function_get_content']);
  3657. if($mixedContent === false)
  3658. return false;
  3659. list($iContentId, $aContentInfo) = $mixedContent;
  3660. unset($aParams['function_get_content']);
  3661. if (!empty($aParams))
  3662. return $this->_oTemplate->$sFunc($aContentInfo, $aParams);
  3663. else
  3664. return $this->_oTemplate->$sFunc($aContentInfo);
  3665. }
  3666. protected function _getApproveForm($iContentId, $aContentInfo)
  3667. {
  3668. $CNF = &$this->_oConfig->CNF;
  3669. $sForm = 'sys_manage';
  3670. if(!empty($CNF['OBJECT_FORM_MANAGE']))
  3671. $sForm = $CNF['OBJECT_FORM_MANAGE'];
  3672. $sFormDisplay = 'sys_manage_approve';
  3673. if(!empty($CNF['OBJECT_FORM_MANAGE_APPROVE']))
  3674. $sFormDisplay = $CNF['OBJECT_FORM_MANAGE_APPROVE'];
  3675. $oForm = BxTemplFormView::getObjectInstance($sForm, $sFormDisplay);
  3676. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'approve';
  3677. $oForm->aInputs['content_id']['value'] = $iContentId;
  3678. foreach($oForm->aInputs['controls'] as $iKey => $mixedValue)
  3679. if(is_numeric($iKey) && isset($mixedValue['name']) && $mixedValue['name'] == 'do_submit')
  3680. $oForm->aInputs['controls'][$iKey]['value'] = _t('_sys_form_manage_input_do_submit_approve');
  3681. /**
  3682. * @hooks
  3683. * @hookdef hook-bx_base_general-get_approve_form '{module_name}', 'get_approve_form' - hook to override approve content form
  3684. * - $unit_name - module name
  3685. * - $action - equals `get_approve_form`
  3686. * - $object_id - not used
  3687. * - $sender_id - not used
  3688. * - $extra_params - array of additional params with the following array keys:
  3689. * - `content_id` - [int] content id
  3690. * - `content_info` - [array] content info array as key&value pairs
  3691. * - `override_result` - [object] by ref, an instance of approve content form, @see BxDolForm, can be overridden in hook processing
  3692. * @hook @ref hook-bx_base_general-get_approve_form
  3693. */
  3694. bx_alert($this->_oConfig->getName(), 'get_approve_form', 0, 0, [
  3695. 'content_id' => $iContentId,
  3696. 'content_info' => $aContentInfo,
  3697. 'override_result' => &$oForm
  3698. ]);
  3699. return $oForm;
  3700. }
  3701. protected function _sendApproveMessage($iContentId, $aContentInfo, &$oForm)
  3702. {
  3703. $CNF = &$this->_oConfig->CNF;
  3704. $sETemplate = 't_ManageApprove';
  3705. if(!empty($CNF['ETEMPLATE_MANAGE_APPROVE']))
  3706. $sETemplate = $CNF['ETEMPLATE_MANAGE_APPROVE'];
  3707. $aEParams = array(
  3708. 'content_title' => !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  3709. 'notes' => $oForm->getCleanValue('notes'),
  3710. );
  3711. /**
  3712. * @hooks
  3713. * @hookdef hook-bx_base_general-get_approve_message '{module_name}', 'get_approve_form' - hook to override approve content message
  3714. * - $unit_name - module name
  3715. * - $action - equals `get_approve_message`
  3716. * - $object_id - not used
  3717. * - $sender_id - not used
  3718. * - $extra_params - array of additional params with the following array keys:
  3719. * - `content_id` - [int] content id
  3720. * - `content_info` - [array] content info array as key&value pairs
  3721. * - `form` - [object] an instance of approve content form
  3722. * - `email_template` - [string] by ref, email template name, @see BxDolEmailTemplates, can be overridden in hook processing
  3723. * - `email_params` - [array] by ref, email template params, can be overridden in hook processing
  3724. * @hook @ref hook-bx_base_general-get_approve_message
  3725. */
  3726. bx_alert($this->_oConfig->getName(), 'get_approve_message', 0, 0, [
  3727. 'content_id' => $iContentId,
  3728. 'content_info' => $aContentInfo,
  3729. 'form' => $oForm,
  3730. 'email_template' => &$sETemplate,
  3731. 'email_params' => &$aEParams
  3732. ]);
  3733. return sendMailTemplate($sETemplate, 0, $aContentInfo[$CNF['FIELD_AUTHOR']], $aEParams);
  3734. }
  3735. protected function _processModerationNotifications($aContentInfo)
  3736. {
  3737. $CNF = &$this->_oConfig->CNF;
  3738. if(empty($CNF['PARAM_AUTO_APPROVE']) || getParam($CNF['PARAM_AUTO_APPROVE']) == 'on')
  3739. return;
  3740. $aRecipients = $this->getModerators($aContentInfo);
  3741. if(empty($aRecipients))
  3742. return;
  3743. foreach($aRecipients as $iRecipientId)
  3744. /**
  3745. * @hooks
  3746. * @hookdef hook-bx_base_general-pending_approval '{module_name}', 'pending_approval' - hook to notify admins/moderators about new pending approval content
  3747. * - $unit_name - module name
  3748. * - $action - equals `pending_approval`
  3749. * - $object_id - content id
  3750. * - $sender_id - content author profile id
  3751. * - $extra_params - array of additional params with the following array keys:
  3752. * - `object_author_id` - [int] admin/moderator profile id
  3753. * @hook @ref hook-bx_base_general-pending_approval
  3754. */
  3755. bx_alert($sModule, 'pending_approval', $aContentInfo[$CNF['FIELD_ID']], $aContentInfo[$CNF['FIELD_AUTHOR']], [
  3756. 'object_author_id' => (int)$iRecipientId
  3757. ]);
  3758. }
  3759. protected function _rss ($aArgs, $sClass = 'SearchResult')
  3760. {
  3761. $sMode = array_shift($aArgs);
  3762. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  3763. $this->_oTemplate->displayAccessDenied ($sMsg);
  3764. exit;
  3765. }
  3766. $aParams = $this->_buildRssParams($sMode, $aArgs);
  3767. bx_import ($sClass, $this->_aModule);
  3768. $sClass = $this->_aModule['class_prefix'] . $sClass;
  3769. $o = new $sClass($sMode, $aParams);
  3770. if ($o->isError)
  3771. $this->_oTemplate->displayPageNotFound ();
  3772. else
  3773. $o->outputRSS();
  3774. exit;
  3775. }
  3776. protected function _getContent($iContentId = 0, $sFuncGetContent = true)
  3777. {
  3778. if(!$iContentId)
  3779. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  3780. if(!$iContentId)
  3781. return false;
  3782. if($sFuncGetContent === true)
  3783. $sFuncGetContent = 'getContentInfoById';
  3784. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  3785. return $iContentId;
  3786. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  3787. if(!$aContentInfo)
  3788. return false;
  3789. return array($iContentId, $aContentInfo);
  3790. }
  3791. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  3792. {
  3793. $CNF = &$this->_oConfig->CNF;
  3794. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  3795. //--- Image(s)
  3796. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3797. $aImagesAttach = $this->_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3798. //--- Video(s)
  3799. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3800. $aVideosAttach = $this->_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3801. //--- Files(s)
  3802. $aFiles = $this->_getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3803. $aFilesAttach = $this->_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  3804. if($this->_bIsApi && getParam('sys_api_extended_units') != 'on') {
  3805. $sTitle = '';
  3806. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  3807. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  3808. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  3809. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  3810. $sAbstract = isset($CNF['FIELD_ABSTRACT']) && isset($aContentInfo[$CNF['FIELD_ABSTRACT']]) ? $aContentInfo[$CNF['FIELD_ABSTRACT']] : '';
  3811. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  3812. $sText = BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sText), 240);
  3813. $aResults = [
  3814. 'url' => $sUrl,
  3815. 'title' => $sTitle,
  3816. 'abstract' => $sAbstract,
  3817. 'text' => $sText
  3818. ];
  3819. if(!empty($aImages) && is_array($aImages))
  3820. $aResults['images'] = $aImages;
  3821. if(!empty($aVideos) && is_array($aVideos))
  3822. $aResults['videos'] = $aVideos;
  3823. if(!empty($aFiles) && is_array($aFiles))
  3824. $aResults['files'] = $aFiles;
  3825. return $aResults;
  3826. }
  3827. //--- Title
  3828. $sTitle = '';
  3829. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  3830. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  3831. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  3832. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  3833. //--- Text
  3834. $sText = '';
  3835. if(isset($CNF['FIELD_ABSTRACT']) && isset($aContentInfo[$CNF['FIELD_ABSTRACT']]))
  3836. $sText = $aContentInfo[$CNF['FIELD_ABSTRACT']];
  3837. if(empty($sText) && isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  3838. $sText = $aContentInfo[$CNF['FIELD_TEXT']];
  3839. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  3840. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  3841. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  3842. }
  3843. $sCategory = '';
  3844. if (isset($CNF['OBJECT_CATEGORY']) && isset($CNF['OBJECT_CATEGORY']) && isset($aContentInfo[$CNF['FIELD_CATEGORY']])){
  3845. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  3846. if ($oCategory)
  3847. $sCategory = $oCategory->getCategoryTitle($aContentInfo[$CNF['FIELD_CATEGORY']]);
  3848. }
  3849. $aResult = [
  3850. 'title' => $sTitle,
  3851. 'text' => $sText,
  3852. 'images' => $aImages,
  3853. 'images_attach' => $aImagesAttach,
  3854. 'videos' => $aVideos,
  3855. 'videos_attach' => $aVideosAttach,
  3856. 'files' => $aFiles,
  3857. 'files_attach' => $aFilesAttach
  3858. ];
  3859. return $this->_bIsApi ? $aResult : array_merge($aResult, [
  3860. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  3861. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  3862. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  3863. 'url' => $sUrl,
  3864. 'category' => $sCategory,
  3865. ]);
  3866. }
  3867. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  3868. {
  3869. $CNF = &$this->_oConfig->CNF;
  3870. if (bx_is_api()){
  3871. $aResult = [];
  3872. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']])) {
  3873. $aResult[] = bx_api_get_image($CNF['OBJECT_STORAGE'], (int)$aContentInfo[$CNF['FIELD_COVER']]);
  3874. }
  3875. if(isset($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']])) {
  3876. $aResult[] = bx_api_get_image($CNF['OBJECT_STORAGE'], (int)$aContentInfo[$CNF['FIELD_THUMB']]);
  3877. }
  3878. return $aResult;
  3879. }
  3880. else{
  3881. $iImageId = 0;
  3882. $sImageSm = $sImageMd = $sImageXl = '';
  3883. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']])) {
  3884. $iImageId = (int)$aContentInfo[$CNF['FIELD_COVER']];
  3885. $sImageSm = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_MINIATURE', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  3886. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  3887. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  3888. }
  3889. if($sImageMd == '' && isset($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']])) {
  3890. $iImageId = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  3891. $sImageSm = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_MINIATURE', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  3892. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB']);
  3893. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  3894. }
  3895. if(empty($sImageMd))
  3896. return [];
  3897. if($sImageSm == '')
  3898. $sImageSm = $sImageMd;
  3899. if($sImageXl == '')
  3900. $sImageXl = $sImageMd;
  3901. return [[
  3902. 'id' => $iImageId,
  3903. 'url' => $sUrl,
  3904. 'src' => $sImageMd,
  3905. 'src_small' => $sImageSm,
  3906. 'src_medium' => $sImageMd,
  3907. 'src_orig' => $sImageXl
  3908. ]];
  3909. }
  3910. }
  3911. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  3912. {
  3913. return array();
  3914. }
  3915. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  3916. {
  3917. return array();
  3918. }
  3919. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  3920. {
  3921. return array();
  3922. }
  3923. protected function _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  3924. {
  3925. return array();
  3926. }
  3927. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  3928. {
  3929. return array();
  3930. }
  3931. protected function _entityComments ($sObject, $iId = 0)
  3932. {
  3933. if (!$iId)
  3934. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  3935. if (!$iId)
  3936. return false;
  3937. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  3938. if (!$oCmts || !$oCmts->isEnabled())
  3939. return false;
  3940. if (bx_is_api()){
  3941. return [bx_srv('system', 'get_data_api', [['module' => $sObject, 'object_id' => $iId]], 'TemplCmtsServices')];
  3942. }
  3943. return $oCmts->getCommentsBlock([], ['in_designbox' => false, 'show_empty' => false]);
  3944. }
  3945. protected function _getFields($iContentId)
  3946. {
  3947. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  3948. if(empty($aContentInfo))
  3949. return array();
  3950. return BxDolContentInfo::formatFields($aContentInfo);
  3951. }
  3952. protected function _getFieldValue($sField, $iContentId)
  3953. {
  3954. $CNF = &$this->_oConfig->CNF;
  3955. if(empty($CNF[$sField]))
  3956. return false;
  3957. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  3958. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  3959. return false;
  3960. return $aContentInfo[$CNF[$sField]];
  3961. }
  3962. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  3963. {
  3964. $CNF = &$this->_oConfig->CNF;
  3965. if(empty($sTranscoder) || empty($CNF[$sField]))
  3966. return false;
  3967. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  3968. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  3969. return false;
  3970. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  3971. if(!$oImagesTranscoder)
  3972. return false;
  3973. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  3974. }
  3975. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  3976. {
  3977. if(!$bAsJson)
  3978. return $aResponse;
  3979. if(!empty($aAdditional) && is_array($aAdditional))
  3980. $aResponse = array_merge($aResponse, $aAdditional);
  3981. echoJson($aResponse);
  3982. exit;
  3983. }
  3984. /**
  3985. * Blocks for lables tree browsing private functions
  3986. */
  3987. private function _getLablesBreadcrumbsArray($iLabelId, &$aBreadcrumbs)
  3988. {
  3989. $oLabel = BxDolLabel::getInstance();
  3990. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  3991. if ($aLabel){
  3992. $aBreadcrumbs[$aLabel['id']] = array('id' => $aLabel['id'], 'value' => $aLabel['value']);
  3993. $this->_getLablesBreadcrumbsArray($aLabel['parent'], $aBreadcrumbs);
  3994. }
  3995. }
  3996. private function _getLablesBrowseUrl($iLabelId)
  3997. {
  3998. list($sPageLink, $aPageParams) = bx_get_base_url_inline();
  3999. return BxDolPermalinks::getInstance()->permalink(bx_append_url_params($sPageLink, array_merge($aPageParams, array('label' => $iLabelId))));
  4000. }
  4001. private function _getLablesTreeLevel($aBreadcrumbs, $iParent = 0)
  4002. {
  4003. $oLabel = BxDolLabel::getInstance();
  4004. $aLabelsOutput = array();
  4005. $aLabels = $oLabel->getLabels(array('type' => 'parent', 'parent' => $iParent));
  4006. if (count($aLabels) > 0){
  4007. foreach($aLabels as $aLabel) {
  4008. $sChild = $this->_getLablesTreeLevel($aBreadcrumbs, $aLabel['id']);
  4009. $bChildPresent = $sChild != '' ? true : false;
  4010. $bIsOpen = array_key_exists($aLabel['id'], $aBreadcrumbs) ? true : false;
  4011. if (!$bIsOpen){
  4012. $sChild = '';
  4013. }
  4014. $aLabelsOutput[] = array(
  4015. 'value' => $aLabel['value'],
  4016. 'url' => $this->_getLablesBrowseUrl($aLabel['id']),
  4017. 'child' => $sChild,
  4018. 'selected' => bx_process_input(bx_get('label'), BX_DATA_INT) == $aLabel['id'] ? 'selected' : ''.$aLabel['id'],
  4019. 'bx_if:open' => array(
  4020. 'condition' => $bChildPresent && $bIsOpen,
  4021. 'content' => array()
  4022. ),
  4023. 'bx_if:can_open' => array(
  4024. 'condition' => $bChildPresent && !$bIsOpen,
  4025. 'content' => array()
  4026. )
  4027. );
  4028. }
  4029. return $this->_oTemplate->parseHtmlByName('labels_tree.html',
  4030. array(
  4031. 'bx_repeat:items' => $aLabelsOutput,
  4032. 'parent' => $iParent,
  4033. )
  4034. );
  4035. }
  4036. return '';
  4037. }
  4038. }
  4039. /** @} */