1
0

BxBaseModGeneralModule.php 185 KB

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