1
0

BxBaseModGeneralModule.php 186 KB

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