BxTimelineModule.php 250 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361
  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 Timeline Timeline
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. bx_import('BxBaseModNotificationsModule');
  13. /**
  14. * SLTMODE - Silent mode:
  15. * It is needed for alert sending module to tell that the alert should be ignored
  16. * with Timeline module completely or partially. Available values:
  17. * 1. disabled (global, value = 0) - all events are registered;
  18. * 2. absolute (global, value = 1) - alert isn't registered which means that event won't appear in timelines at all;
  19. * 3. absolute (for Timeline only, value = 21) - the same as global absolute.
  20. * 4. partial registration might be added in the future versions.
  21. *
  22. * @see BxBaseModNotificationsModule and BxTimelineResponse::response - 'silent_mode' parameter in Alerts Extras array.
  23. */
  24. define('BX_TIMELINE_SLTMODE_ABSOLUTE', 21);
  25. define('BX_TIMELINE_NAME_VIEWS_DB', 'views_db'); //--- Dynamic browsing feeds.
  26. define('BX_TIMELINE_TYPE_ITEM', 'view_item');
  27. define('BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS', 'owner_and_connections');
  28. define('BX_TIMELINE_TYPE_CONNECTED_CONTEXTS', 'connected_contexts'); //--- Followed contexts by type (groups, events, spaces, etc) only.
  29. define('BX_TIMELINE_TYPE_CHANNELS', 'channels'); //--- Followed channels only.
  30. define('BX_TIMELINE_TYPE_FEED', 'feed'); //--- Owner and followed contexts excluding channels.
  31. define('BX_TIMELINE_TYPE_HOT', 'hot'); //--- Aggrigated hot content.
  32. define('BX_TIMELINE_TYPE_FOR_YOU', 'feed_and_hot'); //--- Aggrigated from different timelines.
  33. define('BX_TIMELINE_TYPE_DEFAULT', BX_BASE_MOD_NTFS_TYPE_OWNER);
  34. define('BX_TIMELINE_VIEW_ITEM', 'item');
  35. define('BX_TIMELINE_VIEW_TIMELINE', 'timeline');
  36. define('BX_TIMELINE_VIEW_OUTLINE', 'outline');
  37. define('BX_TIMELINE_VIEW_SEARCH', 'search');
  38. define('BX_TIMELINE_VIEW_DEFAULT', BX_TIMELINE_VIEW_OUTLINE);
  39. define('BX_TIMELINE_FILTER_ALL', 'all');
  40. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  41. define('BX_TIMELINE_FILTER_OTHER', 'other');
  42. define('BX_TIMELINE_FILTER_OTHER_VIEWER', 'other_viewer');
  43. define('BX_TIMELINE_PARSE_TYPE_POST', 'post');
  44. define('BX_TIMELINE_PARSE_TYPE_REPOST', 'repost');
  45. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_POST);
  46. define('BX_TIMELINE_STATUS_ACTIVE', 'active');
  47. define('BX_TIMELINE_STATUS_PENDING', 'pending');
  48. define('BX_TIMELINE_STATUS_AWAITING', 'awaiting');
  49. define('BX_TIMELINE_STATUS_FAILED', 'failed');
  50. define('BX_TIMELINE_STATUS_HIDDEN', 'hidden');
  51. define('BX_TIMELINE_STATUS_DELETED', 'deleted');
  52. //--- Video Auto Play
  53. define('BX_TIMELINE_VAP_OFF', 'off');
  54. define('BX_TIMELINE_VAP_ON_MUTE', 'on_mute');
  55. define('BX_TIMELINE_VAP_ON', 'on');
  56. //--- Media Layouts
  57. define('BX_TIMELINE_ML_SINGLE', 'single');
  58. define('BX_TIMELINE_ML_GALLERY', 'gallery');
  59. define('BX_TIMELINE_ML_SHOWCASE', 'showcase');
  60. //--- Default Attachments Media Layout
  61. define('BX_TIMELINE_AML_DEFAULT', BX_TIMELINE_ML_GALLERY);
  62. //--- Hot Feed sources
  63. define('BX_TIMELINE_HFS_CONTENT', 'content');
  64. define('BX_TIMELINE_HFS_COMMENT', 'comment');
  65. define('BX_TIMELINE_HFS_VOTE', 'vote');
  66. //--- For You Feed sources
  67. define('BX_TIMELINE_FYFS_FEED', 'feed');
  68. define('BX_TIMELINE_FYFS_CHANNELS', 'channels');
  69. define('BX_TIMELINE_FYFS_HOT', 'hot');
  70. define('BX_TIMELINE_FYFS_RECOM_FRIENDS', 'recom_friends');
  71. define('BX_TIMELINE_FYFS_RECOM_SUBSCRIPTIONS', 'recom_subscriptions');
  72. class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolContentInfoService
  73. {
  74. protected $_sJsPostObject;
  75. protected $_sJsViewObject;
  76. protected $_aPostElements;
  77. protected $_sJsOutlineObject;
  78. protected $_sDividerTemplate;
  79. protected $_sBalloonTemplate;
  80. protected $_sCmtPostTemplate;
  81. protected $_sCmtViewTemplate;
  82. protected $_sCmtTemplate;
  83. /**
  84. * Constructor
  85. */
  86. function __construct($aModule)
  87. {
  88. parent::__construct($aModule);
  89. }
  90. /**
  91. * ACTION METHODS
  92. */
  93. public function actionGetContexts($iLimit = 20)
  94. {
  95. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  96. if(!$oConnection)
  97. return echoJson(array());
  98. $iProfileId = bx_get_logged_profile_id();
  99. $aConnected = $oConnection->getConnectedContent($iProfileId);
  100. $sTerm = bx_get('term');
  101. if(!$sTerm)
  102. return array_slice($aConnected, 0, $iLimit);
  103. $aResults = array();
  104. $aModules = bx_srv('system', 'get_profiles_modules', array(false), 'TemplServiceProfiles');
  105. foreach($aModules as $aModule) {
  106. if(!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  107. continue;
  108. $aContexts = bx_srv($aModule['name'], 'profiles_search', array($sTerm, PHP_INT_MAX));
  109. foreach($aContexts as $aContext) {
  110. if(!in_array($aContext['value'], $aConnected))
  111. continue;
  112. $aResults[] = $aContext;
  113. }
  114. }
  115. usort($aResults, function($r1, $r2) {
  116. return strcmp($r1['label'], $r2['label']);
  117. });
  118. echoJson(array_slice($aResults, 0, $iLimit));
  119. }
  120. public function actionVideo($iEventId, $iVideoId)
  121. {
  122. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEventId));
  123. if(empty($aEvent) || !is_array($aEvent))
  124. return;
  125. $aData = $this->_oTemplate->getDataCached($aEvent);
  126. if($aData === false || !isset($aData['content']['videos'][$iVideoId]))
  127. return;
  128. $oTemplate = BxDolTemplate::getInstance();
  129. $oTemplate->addJs(array(
  130. 'embedly-player.min.js'
  131. ));
  132. $oTemplate->setPageNameIndex (BX_PAGE_EMBED);
  133. $oTemplate->setPageContent ('page_main_code', $this->_oTemplate->getVideo($aEvent, $aData['content']['videos'][$iVideoId]));
  134. $oTemplate->getPageCode();
  135. }
  136. public function actionPost()
  137. {
  138. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  139. $mixedAllowed = $this->isAllowedPost(true);
  140. if($mixedAllowed !== true)
  141. return echoJson(array('message' => strip_tags($mixedAllowed)));
  142. if (!bx_is_api())
  143. echoJson($this->getFormPost());
  144. else
  145. $this->getFormPost();
  146. }
  147. public function actionEdit($iId)
  148. {
  149. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  150. $aParams = [
  151. 'type' => BX_TIMELINE_TYPE_DEFAULT,
  152. 'dynamic_mode' => true
  153. ];
  154. $aBrowseParams = [];
  155. if(bx_get('bp') !== false) {
  156. $aBrowseParams = $this->_oConfig->getBrowseParams(bx_process_input(bx_get('bp')));
  157. $aBrowseParams = $this->_prepareParamsGet($aBrowseParams);
  158. $aParams['type'] = $aBrowseParams['type'];
  159. }
  160. $mixedAllowed = $this->isAllowedPost(true);
  161. if($mixedAllowed !== true)
  162. return echoJson(array('message' => strip_tags($mixedAllowed)));
  163. echoJson($this->getFormEdit($iId, $aParams, $aBrowseParams));
  164. }
  165. function actionPin()
  166. {
  167. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  168. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  169. if(empty($aEvent) || !is_array($aEvent))
  170. return echoJson(array('code' => 1));
  171. $aParams = $this->_prepareParamsGet();
  172. $this->_iOwnerId = $aParams['owner_id'];
  173. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['pinned'] == 0 ? 'Pin' : 'Unpin')}($aEvent, true);
  174. if($mixedAllowed !== true)
  175. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  176. $aEvent['pinned'] = (int)$aEvent['pinned'] == 0 ? time() : 0;
  177. if(!$this->_oDb->updateEvent(array('pinned' => $aEvent['pinned']), array('id' => $iId)))
  178. return echoJson(array('code' => 3));
  179. $this->rebuildSlice();
  180. echoJson(array(
  181. 'code' => 0,
  182. 'id' => $iId,
  183. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onPinPost(oData)'
  184. ));
  185. }
  186. function actionStick()
  187. {
  188. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  189. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  190. if(empty($aEvent) || !is_array($aEvent))
  191. return echoJson(array('code' => 1));
  192. $aParams = $this->_prepareParamsGet();
  193. $this->_iOwnerId = $aParams['owner_id'];
  194. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['sticked'] == 0 ? 'Stick' : 'Unstick')}($aEvent, true);
  195. if($mixedAllowed !== true)
  196. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  197. $aEvent['sticked'] = (int)$aEvent['sticked'] == 0 ? time() : 0;
  198. if(!$this->_oDb->updateEvent(array('sticked' => $aEvent['sticked']), array('id' => $iId)))
  199. return echoJson(array('code' => 3));
  200. $this->rebuildSlice();
  201. bx_audit(
  202. $iId,
  203. $this->getName(),
  204. '_sys_audit_action_' . ((int)$aEvent['sticked'] == 0 ? 'stick' : 'unstick'),
  205. $this->_prepareAuditParams($aEvent, false)
  206. );
  207. echoJson(array(
  208. 'code' => 0,
  209. 'id' => $iId,
  210. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onStickPost(oData)'
  211. ));
  212. }
  213. function actionPromote()
  214. {
  215. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  216. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  217. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  218. $sAction = (int)$aEvent['promoted'] == 0 ? 'promote' : 'unpromote';
  219. $mixedAllowed = $this->{'isAllowed' . ucfirst($sAction)}($aEvent, true);
  220. if($mixedAllowed !== true)
  221. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  222. $aEvent['promoted'] = (int)$aEvent['promoted'] == 0 ? time() : 0;
  223. if(!$this->_oDb->updateEvent(array('promoted' => $aEvent['promoted']), array('id' => $iId)))
  224. return echoJson(array('code' => 2));
  225. $this->rebuildSlice();
  226. /**
  227. * @hooks
  228. * @hookdef hook-bx_timeline-promoted 'bx_timeline', 'promoted' - hook after an event was promoted
  229. * - $unit_name - equals `bx_timeline`
  230. * - $action - equals `promoted`
  231. * - $object_id - event id
  232. * - $sender_id - performer profile id
  233. * - $extra_params - array of additional params with the following array keys:
  234. * - `owner_id` - [int] owner profile id
  235. * - `object_id` - [int] object id
  236. * - `object_author_id` - [int] object author profile id
  237. * @hook @ref hook-bx_timeline-promoted
  238. */
  239. /**
  240. * @hooks
  241. * @hookdef hook-bx_timeline-unpromoted 'bx_timeline', 'unpromoted' - hook after an event was unpromoted
  242. * It's equivalent to @ref hook-bx_timeline-promoted
  243. * @hook @ref hook-bx_timeline-unpromoted
  244. */
  245. bx_alert($this->_oConfig->getObject('alert'), $sAction . 'd', $iId, (int)$this->getUserId(), [
  246. 'owner_id' => $aEvent['owner_id'],
  247. 'object_id' => $aEvent['object_id'],
  248. 'object_author_id' => $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['owner_id'] : $aEvent['object_id']
  249. ]);
  250. bx_audit(
  251. $iId,
  252. $this->getName(),
  253. '_sys_audit_action_' . ((int)$aEvent['promoted'] == 0 ? 'promote' : 'unpromote'),
  254. $this->_prepareAuditParams($aEvent, false)
  255. );
  256. echoJson(array(
  257. 'code' => 0,
  258. 'message' => _t('_bx_timeline_txt_msg_performed_action')
  259. ));
  260. }
  261. function actionMarkAsRead()
  262. {
  263. $aParams = $this->_prepareParamsGet();
  264. $mixedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  265. if(!is_array($mixedId))
  266. $mixedId = [$mixedId];
  267. $iProcessed = 0;
  268. foreach($mixedId as $iId) {
  269. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iId]);
  270. if(empty($aEvent) || !is_array($aEvent))
  271. continue;
  272. if(!$this->_oDb->markAsRead($aParams['viewer_id'], $iId))
  273. continue;
  274. $iProcessed++;
  275. }
  276. return echoJson($iProcessed != count($mixedId) ? ['code' => 1] : [
  277. 'code' => 0,
  278. 'id' => $mixedId
  279. ]);
  280. }
  281. function actionMute()
  282. {
  283. $CNF = &$this->_oConfig->CNF;
  284. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  285. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  286. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  287. $mixedAllowed = $this->isAllowedMute($aEvent, true);
  288. if($mixedAllowed !== true)
  289. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  290. $iAuthor = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  291. if(!$this->_oConfig->isSystem($aEvent['type'], $aEvent['action']))
  292. $iAuthor = (int)$aEvent[$CNF['FIELD_OBJECT_ID']];
  293. if(!$this->getConnectionMuteObject()->addConnection($this->_iProfileId, $iAuthor))
  294. return echoJson(array('code' => 2));
  295. /**
  296. * @hooks
  297. * @hookdef hook-bx_timeline-muted 'bx_timeline', 'muted' - hook after an event author was muted
  298. * - $unit_name - equals `bx_timeline`
  299. * - $action - equals `muted`
  300. * - $object_id - event author profile id
  301. * - $sender_id - performer profile id
  302. * - $extra_params - array of additional params with the following array keys:
  303. * - `owner_id` - [int] owner profile id
  304. * - `object_id` - [int] object id
  305. * - `object_author_id` - [int] object author profile id
  306. * @hook @ref hook-bx_timeline-muted
  307. */
  308. bx_alert($this->_oConfig->getObject('alert'), 'muted', $iAuthor, $this->_iProfileId, [
  309. 'owner_id' => $aEvent['owner_id'],
  310. 'object_id' => $aEvent['object_id'],
  311. 'object_author_id' => $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['owner_id'] : $aEvent['object_id']
  312. ]);
  313. echoJson(array('code' => 0, 'message' => _t('_bx_timeline_txt_msg_performed_action'), 'reload' => 1));
  314. }
  315. function actionDelete()
  316. {
  317. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  318. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  319. if(empty($aEvent) || !is_array($aEvent))
  320. return echoJson(array('code' => 1));
  321. $aParams = $this->_prepareParamsGet();
  322. $this->_iOwnerId = $aParams['owner_id'];
  323. $mixedAllowed = $this->isAllowedDelete($aEvent, true);
  324. if($mixedAllowed !== true)
  325. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  326. if(!$this->{$this->_oConfig->isHideUponDelete() ? 'hideEvent' : 'deleteEvent'}($aEvent))
  327. return echoJson(array('code' => 3));
  328. echoJson(array(
  329. 'code' => 0,
  330. 'id' => $aEvent['id'],
  331. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onDeletePost(oData)'
  332. ));
  333. }
  334. public function actionRepost()
  335. {
  336. $iAuthorId = $this->getUserId();
  337. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  338. $sType = bx_process_input(bx_get('type'), BX_DATA_TEXT);
  339. $sAction = bx_process_input(bx_get('action'), BX_DATA_TEXT);
  340. $iObjectId = bx_process_input(bx_get('object_id'), BX_DATA_INT);
  341. $aResult = $this->repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId);
  342. if(!empty($aResult) && is_array($aResult))
  343. return echoJson($aResult);
  344. $aParams = $this->_oConfig->getRepostDefaults();
  345. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  346. echoJson([
  347. 'code' => 0,
  348. 'message' => _t('_bx_timeline_txt_msg_success_repost'),
  349. 'count' => $aReposted['reposts'],
  350. 'countf' => (int)$aReposted['reposts'] > 0 ? $this->_oTemplate->getRepostCounterLabel($aReposted['reposts'], $aParams) : '',
  351. 'counter' => $this->_oTemplate->getRepostCounter($aReposted, $aParams),
  352. 'disabled' => true
  353. ]);
  354. }
  355. public function actionRepostWith()
  356. {
  357. if(($iReposterId = bx_get('reposter_id')) !== false)
  358. $iReposterId = bx_process_input($iReposterId, BX_DATA_INT);
  359. $iUserId = $this->getUserId();
  360. if(!$iReposterId || $iReposterId != $iUserId)
  361. $iReposterId = $iUserId;
  362. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  363. $sType = bx_process_input(bx_get('type'), BX_DATA_TEXT);
  364. $sAction = bx_process_input(bx_get('action'), BX_DATA_TEXT);
  365. $iObjectId = bx_process_input(bx_get('object_id'), BX_DATA_INT);
  366. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_repost'), $this->_oConfig->getObject('form_display_repost_with'));
  367. $oForm->initChecker(array(
  368. 'reposter_id' => $iReposterId,
  369. 'owner_id' => $iOwnerId,
  370. 'type' => $sType,
  371. 'action' => $sAction,
  372. 'object_id' => $iObjectId
  373. ));
  374. if($oForm->isSubmitted()) {
  375. if(!$oForm->isValid())
  376. return echoJson(array('popup' => array(
  377. 'html' => BxTemplFunctions::getInstance()->transBox($this->_oConfig->getHtmlIds('repost', 'with_popup'), $this->_oTemplate->getRepostWith($oForm)),
  378. 'options' => array('closeOnOuterClick' => false, 'removeOnClose' => true)
  379. )));
  380. $this->repost($iReposterId, $iOwnerId, $sType, $sAction, $iObjectId, ['text' => $oForm->getCleanValue('text')]);
  381. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  382. $sCounter = $this->_oTemplate->getRepostCounter($aReposted);
  383. return echoJson(array(
  384. 'code' => 0,
  385. 'message' => _t('_bx_timeline_txt_msg_success_repost'),
  386. 'count' => $aReposted['reposts'],
  387. 'countf' => (int)$aReposted['reposts'] > 0 ? $this->_oTemplate->getRepostCounterLabel($aReposted['reposts']) : '',
  388. 'counter' => $sCounter,
  389. ));
  390. }
  391. echo $this->_oTemplate->getRepostTo($oForm);
  392. }
  393. public function actionRepostTo()
  394. {
  395. $iReposterId = bx_process_input(bx_get('reposter_id'), BX_DATA_INT);
  396. if($iReposterId != $this->getUserId())
  397. return;
  398. $sType = bx_process_input(bx_get('type'), BX_DATA_TEXT);
  399. $sAction = bx_process_input(bx_get('action'), BX_DATA_TEXT);
  400. $iObjectId = bx_process_input(bx_get('object_id'), BX_DATA_INT);
  401. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_repost'), $this->_oConfig->getObject('form_display_repost_to'));
  402. $oForm->initChecker(array(
  403. 'reposter_id' => $iReposterId,
  404. 'type' => $sType,
  405. 'action' => $sAction,
  406. 'object_id' => $iObjectId
  407. ));
  408. if($oForm->isSubmitted()) {
  409. if(!$oForm->isValid())
  410. return echoJson(array('popup' => array(
  411. 'html' => BxTemplFunctions::getInstance()->transBox($this->_oConfig->getHtmlIds('repost', 'to_popup'), $this->_oTemplate->getRepostTo($oForm)),
  412. 'options' => array('closeOnOuterClick' => false, 'removeOnClose' => true)
  413. )));
  414. $aContexts = array();
  415. if(($aContextsSearch = $oForm->getCleanValue('search')) !== false)
  416. $aContexts = array_merge($aContexts, $aContextsSearch);
  417. if(($aContextsList = $oForm->getCleanValue('list')) !== false)
  418. $aContexts = array_merge($aContexts, $aContextsList);
  419. $aContexts = array_unique($aContexts);
  420. if(empty($aContexts) || !is_array($aContexts))
  421. return echoJson(array());
  422. foreach($aContexts as $iContextId)
  423. $this->repost($iReposterId, $iContextId, $sType, $sAction, $iObjectId);
  424. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  425. $sCounter = $this->_oTemplate->getRepostCounter($aReposted);
  426. return echoJson(array(
  427. 'code' => 0,
  428. 'message' => _t('_bx_timeline_txt_msg_success_repost'),
  429. 'count' => $aReposted['reposts'],
  430. 'countf' => (int)$aReposted['reposts'] > 0 ? $this->_oTemplate->getRepostCounterLabel($aReposted['reposts']) : '',
  431. 'counter' => $sCounter,
  432. ));
  433. }
  434. echo $this->_oTemplate->getRepostTo($oForm);
  435. }
  436. function actionGetView()
  437. {
  438. $aParams = $this->_prepareParamsGet();
  439. $this->_iOwnerId = $aParams['owner_id'];
  440. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  441. if(!$oProfileOwner)
  442. return echoJson([]);
  443. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  444. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  445. return echoJson(['code' => 1, 'msg' => $mixedResult]);
  446. $sContent = $this->_oTemplate->getViewBlock($aParams);
  447. if(empty($sContent))
  448. return echoJson([]);
  449. if(!empty($aParams['type']))
  450. $this->_oConfig->setUserChoice(['type' => $aParams['type']]);
  451. echoJson([
  452. 'code' => 0,
  453. 'content' => $sContent,
  454. ]);
  455. }
  456. function actionGetViewFilters()
  457. {
  458. $aParams = $this->_prepareParamsGet();
  459. $sContent = $this->_oTemplate->getViewFilters($aParams);
  460. if(empty($sContent))
  461. return echoJson([]);
  462. echoJson([
  463. 'code' => 0,
  464. 'popup' => [
  465. 'html' => $sContent,
  466. 'options' => [
  467. 'closeOnOuterClick' => true,
  468. 'removeOnClose' => false,
  469. ]
  470. ],
  471. ]);
  472. }
  473. function actionGetPost()
  474. {
  475. $aParams = $this->_prepareParamsGet();
  476. $aParams['dynamic_mode'] = true;
  477. $this->_iOwnerId = $aParams['owner_id'];
  478. $sJsObject = '';
  479. if(bx_get('js_object') !== false)
  480. $sJsObject = $this->_oConfig->prepareParam('js_object');
  481. if(empty($sJsObject))
  482. $sJsObject = $this->_oConfig->getJsObject('post');
  483. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => (int)bx_get('id')]);
  484. if(empty($aEvent) || !is_array($aEvent))
  485. return echoJson([]);
  486. /**
  487. * Note. Disabled for now, because Own posts on Timelines of Following members
  488. * became visible on posts' author Dashboard Timeline.
  489. *
  490. $bAfpsLoading = (int)bx_get('afps_loading') === 1;
  491. if($bAfpsLoading && $this->_iOwnerId != $aEvent['owner_id'])
  492. return echoJson(array('message' => _t('_bx_timeline_txt_msg_posted')));
  493. *
  494. */
  495. $aResult = [
  496. 'id' => (int)$aEvent['id'],
  497. 'name' => $aParams['name'],
  498. 'view' => $aParams['view'],
  499. 'type' => $aParams['type'],
  500. 'item' => $this->_oTemplate->getPost($aEvent, $aParams),
  501. 'eval' => $sJsObject . "._onGetPost(oData)"
  502. ];
  503. /**
  504. * @hooks
  505. * @hookdef hook-bx_timeline-on_get_post 'bx_timeline', 'on_get_post' - hook to override just created direct post (update)
  506. * - $unit_name - equals `bx_timeline`
  507. * - $action - equals `on_get_post`
  508. * - $object_id - event author profile id
  509. * - $sender_id - performer profile id
  510. * - $extra_params - array of additional params with the following array keys:
  511. * - `params` - [array] browse params array as key&value pairs
  512. * - `override_result` - [array] by ref, result array as key&value pairs, can be overridden in hook processing
  513. * @hook @ref hook-bx_timeline-on_get_post
  514. */
  515. bx_alert($this->getName(), 'on_get_post', 0, 0, [
  516. 'params' => $aParams,
  517. 'override_result' => &$aResult,
  518. ]);
  519. echoJson($aResult);
  520. }
  521. function actionGetPosts()
  522. {
  523. $aParams = $this->_prepareParamsGet();
  524. list($sItems, $sLoadMore, $sBack, $sEmpty, $iEvent, $bEventsToLoad) = $this->_oTemplate->getPosts($aParams);
  525. echoJson(array(
  526. 'view' => $aParams['view'],
  527. 'items' => $sItems,
  528. 'load_more' => $sLoadMore,
  529. 'back' => $sBack,
  530. 'empty' => $sEmpty,
  531. 'events_to_load' => $bEventsToLoad,
  532. 'eval' => $this->_oConfig->getJsObjectView($aParams) . "._onGetPosts(oData)"
  533. ));
  534. }
  535. /**
  536. * @page service Service Calls
  537. * @section bx_timeline Timeline
  538. * @subsection bx_timeline-other Other
  539. * @subsubsection bx_timeline-get_posts get_posts
  540. *
  541. * @code bx_srv('bx_timeline', 'get_posts', [...]); @endcode
  542. *
  543. * Get a posts list for API.
  544. *
  545. * @return an array
  546. *
  547. * @see BxTimelineModule::serviceGetPosts
  548. */
  549. /**
  550. * @ref bx_timeline-get_posts "get_posts"
  551. * @api @ref bx_timeline-get_posts "get_posts"
  552. */
  553. function serviceGetPosts($aParams)
  554. {
  555. if(is_string($aParams)){
  556. $aParams = json_decode($aParams, true);
  557. }
  558. return $this->_serviceGetBlockViewByType($aParams['params']);
  559. }
  560. public function actionGetPostForm()
  561. {
  562. $CNF = &$this->_oConfig->CNF;
  563. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  564. $sType = bx_process_input(bx_get('type'));
  565. $aResult = $this->getFormPost([
  566. 'type' => $sType,
  567. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  568. ]);
  569. if($this->_oConfig->isEditorAutoattach() && !empty($aResult['form_object'])) {
  570. $aUploadersInfo = $aResult['form_object']->getUploadersInfo($CNF['FIELD_PHOTO']);
  571. if(!empty($aUploadersInfo) && is_array($aUploadersInfo))
  572. $aResult = array_merge($aResult, ['options' => [
  573. 'sAutoUploader' => $aUploadersInfo['name'],
  574. 'sAutoUploaderId' => $aUploadersInfo['id']
  575. ]]);
  576. unset($aResult['form_object']);
  577. }
  578. echoJson($aResult);
  579. }
  580. public function actionGetEditForm($iId)
  581. {
  582. $aBrowseParams = $this->_prepareParamsGet();
  583. $this->_iOwnerId = $aBrowseParams['owner_id'];
  584. echoJson($this->getFormEdit($iId, [
  585. 'type' => $aBrowseParams['type'],
  586. 'dynamic_mode' => true
  587. ], $aBrowseParams));
  588. }
  589. public function serviceGetEditForm($iId)
  590. {
  591. $aFrm = $this->getFormEdit($iId)['form'];
  592. $aFrm['inputs']['tlb_do_submit'] = $aFrm['inputs']['controls'][0];
  593. unset($aForm['inputs']['controls']);
  594. $aRv['form'] = ['id' => 'bx_timeline', 'type' => 'form', 'name' => 'feed_edit', 'data' => $aFrm, 'request' => ['immutable' => true]];
  595. $aItemData = $this->getItemData($iId);
  596. if(is_array($aItemData) && !empty($aItemData['event']))
  597. $aRv['item'] = $this->_oTemplate->getPostApi($aItemData['event']);
  598. return $aRv;
  599. }
  600. public function actionGetComments()
  601. {
  602. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  603. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  604. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  605. $sComments = $this->_oTemplate->getComments($sSystem, $iId, array('dynamic_mode' => true));
  606. echoJson(array('content' => $sComments));
  607. }
  608. public function actionDeleteAttachLinks()
  609. {
  610. $iUserId = $this->getUserId();
  611. $iEventId = bx_process_input(bx_get('event_id'), BX_DATA_INT);
  612. $aParams = $iEventId > 0 ? ['type' => 'event_id', 'event_id' => $iEventId] : ['type' => 'unused', 'profile_id' => $iUserId];
  613. $aLinks = $this->_oDb->getLinksBy($aParams);
  614. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  615. $aUrls = [];
  616. foreach($aLinks as $aLink) {
  617. $aUrls[] = $aLink['url'];
  618. if(!empty($aLink['media_id']))
  619. $oStorage->deleteFile($aLink['media_id']);
  620. $this->_oDb->deleteLink($aLink['id']);
  621. }
  622. echoJson(['code' => 0, 'urls' => $aUrls]);
  623. }
  624. public function actionAutoAttachInsertion()
  625. {
  626. $sTxtError = _t('_bx_timeline_txt_err_cannot_perform_insertion');
  627. $sUploader = bx_process_input(bx_get('u'));
  628. $sResultContainerId = bx_process_input(bx_get('uid'));
  629. $sStorage = $this->_oConfig->getObject('storage_photos');
  630. $oUploader = BxDolUploader::getObjectInstance($sUploader, $sStorage, $sResultContainerId, $this->_oTemplate);
  631. if(!$oUploader)
  632. return echoJson(['code' => 1, 'msg' => $sTxtError]);
  633. ob_start();
  634. $oUploader->handleUploads(bx_get_logged_profile_id(), isset($_FILES['file']) ? $_FILES['file'] : null, true, false, false);
  635. ob_end_clean();
  636. $sError = $oUploader->getUploadErrorMessages();
  637. if(!empty($sError))
  638. return echoJson(['code' => 2, 'msg' => $sError]);
  639. return echoJson(['code' => 0, 'eval' => $oUploader->getNameJsInstanceUploader() . '.restoreGhosts()']);
  640. }
  641. public function actionGetRepostedBy()
  642. {
  643. $iRepostedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  644. echo $this->_oTemplate->getRepostedBy($iRepostedId);
  645. }
  646. public function actionGetItemBrief()
  647. {
  648. $aParams = $this->_prepareParamsGet();
  649. $iEvent = bx_process_input(bx_get('id'), BX_DATA_INT);
  650. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEvent));
  651. if(empty($aEvent) || !is_array($aEvent)) {
  652. echo MsgBox(_t('_Empty'));
  653. return;
  654. }
  655. if(!$this->isAllowedView($aEvent)) {
  656. echo MsgBox(_t('_sys_access_denied_to_private_content'));
  657. return;
  658. }
  659. $sName = $this->_oConfig->getHtmlIdView('item_popup', $aParams, array('whole' => false, 'hash' => false)) . $iEvent;
  660. $sTitle = _t('_bx_timeline_page_title_item_brief');
  661. $sContent = BxDolPage::getObjectInstance($this->_oConfig->getObject('page_item_brief'), $this->_oTemplate)->getCodeDynamic();
  662. echo PopupBox($sName, $sTitle, $sContent, true);
  663. }
  664. public function actionGetJumpTo()
  665. {
  666. $aParams = $this->_prepareParamsGet();
  667. $this->_iOwnerId = $aParams['owner_id'];
  668. $sJsObjectView = $this->_oConfig->getJsObjectView($aParams);
  669. echoJson(array(
  670. 'content' => $this->_oTemplate->getJumpTo($aParams),
  671. 'eval' => $sJsObjectView . '.onGetJumpTo(oData)'
  672. ));
  673. }
  674. public function actionResumeLiveUpdate()
  675. {
  676. $aParams = $this->_prepareParamsGet();
  677. $sKey = $this->_oConfig->getLiveUpdateKey($aParams);
  678. bx_import('BxDolSession');
  679. BxDolSession::getInstance()->unsetValue($sKey);
  680. }
  681. public function actionPauseLiveUpdate()
  682. {
  683. $aParams = $this->_prepareParamsGet();
  684. $sKey = $this->_oConfig->getLiveUpdateKey($aParams);
  685. bx_import('BxDolSession');
  686. BxDolSession::getInstance()->setValue($sKey, 1);
  687. }
  688. function actionRss()
  689. {
  690. $CNF = &$this->_oConfig->CNF;
  691. $iLength = $this->_oConfig->getRssLength();
  692. if(!$iLength)
  693. return;
  694. $iOwnerId = 0;
  695. $aArgs = func_get_args();
  696. $sType = $this->_oConfig->processParam(array_shift($aArgs));
  697. switch($sType) {
  698. case BX_BASE_MOD_NTFS_TYPE_OWNER:
  699. $iOwnerId = (int)array_shift($aArgs);
  700. $sOwnerName = $this->getObjectUser($iOwnerId)->getDisplayName();
  701. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sOwnerName);
  702. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  703. break;
  704. default:
  705. $sRssCaption = _t('_bx_timeline_page_title_view_home');
  706. $sRssLink = $this->_oConfig->getHomeViewUrl();
  707. break;
  708. }
  709. $aParams = $this->_prepareParams(array(
  710. 'view' => BX_TIMELINE_VIEW_DEFAULT,
  711. 'type' => $sType,
  712. 'owner_id' => $iOwnerId,
  713. 'start' => 0,
  714. 'per_page' => $iLength,
  715. 'timeline' => 0,
  716. 'filter' => '',
  717. 'modules' => array()
  718. ));
  719. $aEvents = $this->_oDb->getEvents($aParams);
  720. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  721. $aRssData = array();
  722. foreach($aEvents as $aEvent) {
  723. if(empty($aEvent['title']))
  724. continue;
  725. $iEventId = (int)$aEvent[$CNF['FIELD_ID']];
  726. $sEventFieldAuthor = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id';
  727. if($oPrivacy) {
  728. $oPrivacy->setTableFieldAuthor($sEventFieldAuthor);
  729. if(!$oPrivacy->check($iEventId))
  730. continue;
  731. }
  732. $iOwner = $aEvent[$sEventFieldAuthor];
  733. $oOwner = BxDolProfile::getInstanceMagic($iOwner);
  734. $aRssData[$iEventId] = array(
  735. 'UnitID' => $iEventId,
  736. 'UnitTitle' => $aEvent['title'],
  737. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  738. 'UnitDesc' => bx_replace_markers($aEvent['description'], array(
  739. 'profile_name' => $oOwner->getDisplayName()
  740. )),
  741. 'UnitDateTimeUTS' => $aEvent['date'],
  742. );
  743. }
  744. $oRss = new BxDolRssFactory();
  745. header('Content-Type: application/xml; charset=utf-8');
  746. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  747. }
  748. /**
  749. * SERVICE METHODS
  750. */
  751. public function serviceGetSafeServices()
  752. {
  753. $a = parent::serviceGetSafeServices();
  754. return array_merge($a, array (
  755. 'GetCreatePostForm' => '',
  756. 'GetSearchResultUnit' => '',
  757. 'GetBlockPost' => '',
  758. 'GetBlockPostProfile' => '',
  759. 'GetBlockPostHome' => '',
  760. 'GetBlockPostAccount' => '',
  761. 'GetBlockView' => '',
  762. 'GetBlockViewOutline' => '',
  763. 'GetBlockViewProfile' => '',
  764. 'GetBlockViewProfileOutline' => '',
  765. 'GetBlockViewsTimeline' => '',
  766. 'GetBlockViewsOutline' => '',
  767. 'GetBlockViewHome' => '',
  768. 'GetBlockViewHomeOutline' => '',
  769. 'GetBlockViewHot' => '',
  770. 'GetBlockViewHotOutline' => '',
  771. 'GetBlockViewAccount' => '',
  772. 'GetBlockViewAccountOutline' => '',
  773. 'GetBlockItem' => '',
  774. 'GetPosts' => '',
  775. 'Get' => '',
  776. 'Repost' => '',
  777. 'Delete' => '',
  778. 'GetEditForm' => '',
  779. 'GetLiveUpdate' => ''
  780. ));
  781. }
  782. /**
  783. * @page service Service Calls
  784. * @section bx_timeline Timeline
  785. * @subsection bx_timeline-other Other
  786. * @subsubsection bx_timeline-get_hot_sources_checklist get_hot_sources_checklist
  787. *
  788. * @code bx_srv('bx_timeline', 'get_hot_sources_checklist', [...]); @endcode
  789. *
  790. * Get a list of available sources for Hot feed. Is used in module settings in Studio.
  791. *
  792. * @return an array with available sources represented as key => value pairs.
  793. *
  794. * @see BxTimelineModule::serviceGetHotSourcesChecklist
  795. */
  796. /**
  797. * @ref bx_timeline-get_hot_sources_checklist "get_hot_sources_checklist"
  798. */
  799. function serviceGetHotSourcesChecklist()
  800. {
  801. $CNF = &$this->_oConfig->CNF;
  802. $aSources = $this->_oConfig->getHotSourcesList();
  803. $aResults = [];
  804. foreach($aSources as $sSource)
  805. $aResults[$sSource] = _t($CNF['T']['option_hfs_' . $sSource]);
  806. return $aResults;
  807. }
  808. /**
  809. * @page service Service Calls
  810. * @section bx_timeline Timeline
  811. * @subsection bx_timeline-other Other
  812. * @subsubsection bx_timeline-get_for_you_sources_checklist get_for_you_sources_checklist
  813. *
  814. * @code bx_srv('bx_timeline', 'get_for_you_sources_checklist', [...]); @endcode
  815. *
  816. * Get a list of available sources for 'For You' feed. Is used in module settings in Studio.
  817. *
  818. * @return an array with available sources represented as key => value pairs.
  819. *
  820. * @see BxTimelineModule::serviceGetForYouSourcesChecklist
  821. */
  822. /**
  823. * @ref bx_timeline-get_for_you_sources_checklist "get_for_you_sources_checklist"
  824. */
  825. function serviceGetForYouSourcesChecklist()
  826. {
  827. $CNF = &$this->_oConfig->CNF;
  828. $aSources = $this->_oConfig->getForYouSourcesList();
  829. $aResults = [];
  830. foreach($aSources as $sSource)
  831. $aResults[$sSource] = _t($CNF['T']['option_fyfs_' . $sSource]);
  832. return $aResults;
  833. }
  834. public function serviceManageTools($sType = 'common')
  835. {
  836. $sResult = parent::serviceManageTools($sType);
  837. if(!empty($sResult))
  838. $this->_oTemplate->addJsSystem(['modules/base/text/js/|manage_tools.js']);
  839. return $sResult;
  840. }
  841. public function serviceFeedsMenuAdd($mixedModule = false)
  842. {
  843. $sSetName = $this->_oConfig->getObject('menu_set_feeds');
  844. $iOrder = $this->_oDb->getMenuItemMaxOrder($sSetName);
  845. $aModules = !empty($mixedModule) ? [$this->_oDb->getModuleByName($mixedModule)] : bx_srv('system', 'get_modules_by_type', ['context']);
  846. foreach($aModules as $aModule) {
  847. $sModuleName = $aModule['name'];
  848. $sModuleUri = $aModule['uri'];
  849. if($sModuleName == 'system' && $sModuleUri == 'system')
  850. continue;
  851. $iMenuItem = $this->_oDb->getMenuItemId($sSetName, $sModuleUri);
  852. if(!empty($iMenuItem))
  853. continue;
  854. $sTitleKey = '_' . $sModuleName;
  855. if(strcmp($sTitleKey, _t($sTitleKey)) == 0)
  856. $sTitleKey = $aModule['title'];
  857. $this->_oDb->insertMenuItem($sSetName, $sModuleName, $sModuleUri, $sTitleKey, ++$iOrder);
  858. }
  859. return true;
  860. }
  861. public function serviceFeedsMenuDelete($mixedModule = false)
  862. {
  863. $sSetName = $this->_oConfig->getObject('menu_set_feeds');
  864. $aModules = !empty($mixedModule) ? [$this->_oDb->getModuleByName($mixedModule)] : bx_srv('system', 'get_modules_by_type', ['context']);
  865. foreach($aModules as $aModule)
  866. $this->_oDb->deleteMenuItem($sSetName, $aModule['uri']);
  867. return true;
  868. }
  869. /**
  870. * @page service Service Calls
  871. * @section bx_timeline Timeline
  872. * @subsection bx_timeline-other Other
  873. * @subsubsection bx_timeline-get_content_owner_profile_id get_content_owner_profile_id
  874. *
  875. * @code bx_srv('bx_timeline', 'get_content_owner_profile_id', [...]); @endcode
  876. *
  877. * Get event's owner profile id.
  878. *
  879. * @param $mixedEvent integer value with event ID or an array with event info.
  880. * @return event's owner profile id.
  881. *
  882. * @see BxTimelineModule::serviceGetContentOwnerProfileId
  883. */
  884. /**
  885. * @ref bx_timeline-get_content_owner_profile_id "get_content_owner_profile_id"
  886. */
  887. public function serviceGetContentOwnerProfileId($mixedEvent)
  888. {
  889. $CNF = &$this->_oConfig->CNF;
  890. $iProfile = (int)bx_get_logged_profile_id();
  891. if(empty($mixedEvent))
  892. return $iProfile;
  893. if(!is_array($mixedEvent))
  894. $mixedEvent = $this->_oDb->getContentInfoById((int)$mixedEvent);
  895. if(empty($mixedEvent) || !is_array($mixedEvent) || !isset($mixedEvent[$CNF['FIELD_SYSTEM']]))
  896. return $iProfile;
  897. if((int)$mixedEvent[$CNF['FIELD_SYSTEM']] == 0)
  898. return (int)$mixedEvent[$CNF['FIELD_OBJECT_ID']];
  899. if(!empty($mixedEvent['object_owner_id']))
  900. return (int)$mixedEvent['object_owner_id'];
  901. if(!empty($mixedEvent['content'])) {
  902. $aContent = unserialize($mixedEvent['content']);
  903. if(!empty($aContent) && is_array($aContent) && !empty($aContent['object_author_id']))
  904. return (int)$aContent['object_author_id'];
  905. }
  906. $aEventData = $this->_oTemplate->getData($mixedEvent);
  907. if(!empty($aEventData) && is_array($aEventData) && !empty($aEventData['object_owner_id']))
  908. return (int)$aEventData['object_owner_id'];
  909. return $iProfile;
  910. }
  911. /**
  912. * @page service Service Calls
  913. * @section bx_timeline Timeline
  914. * @subsection bx_timeline-other Other
  915. * @subsubsection bx_timeline-get_create_post_form get_create_post_form
  916. *
  917. * @code bx_srv('bx_timeline', 'get_create_post_form', [...]); @endcode
  918. *
  919. * Get form code for add content. Is needed for United Post Form.
  920. *
  921. * @param $aParams optional array with parameters(display name, etc)
  922. * @return form code or error
  923. *
  924. * @see BxTimelineModule::serviceGetCreatePostForm
  925. */
  926. /**
  927. * @ref bx_timeline-get_create_post_form "get_create_post_form"
  928. */
  929. public function serviceGetCreatePostForm($aParams = array())
  930. {
  931. $CNF = &$this->_oConfig->CNF;
  932. $aParams = array_merge($this->_aFormParams, $aParams);
  933. $bContext = $aParams['context_id'] !== false;
  934. $this->_iOwnerId = $bContext ? abs($aParams['context_id']) : 0;
  935. $oForm = $this->serviceGetObjectForm('add', $aParams);
  936. if(!$oForm)
  937. return '';
  938. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  939. $aParams['form_display'] = 'form_display_post_add_public';
  940. if($bContext) {
  941. if($aParams['context_id'] < 0) {
  942. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_OWNER;
  943. $aParams['form_display'] = 'form_display_post_add_profile';
  944. }
  945. else {
  946. $aParams['type'] = BX_TIMELINE_TYPE_FEED;
  947. $aParams['form_display'] = 'form_display_post_add';
  948. }
  949. }
  950. if(!empty($aParams['display']))
  951. $aParams['form_display'] = $aParams['display'];
  952. $aResult = $this->getFormPost($aParams);
  953. if(!empty($aResult['form'])) {
  954. $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'];
  955. if($this->_oConfig->isEditorAutoattach() && !empty($aResult['form_object'])) {
  956. $aUploadersInfo = $aResult['form_object']->getUploadersInfo($CNF['FIELD_PHOTO']);
  957. if(!empty($aUploadersInfo) && is_array($aUploadersInfo))
  958. $aParams = [
  959. 'gparams' => ['sAutoUploader' => $aUploadersInfo['name'], 'sAutoUploaderId' => $aUploadersInfo['id']],
  960. 'rparams' => $aParams
  961. ];
  962. }
  963. $sCode = '';
  964. $sCode .= $this->_oTemplate->getJsCodePost($this->_iOwnerId, $aParams, true, $bDynamicMode);
  965. $sCode .= $aResult['form'];
  966. return $sCode;
  967. }
  968. if(!empty($aResult['message']))
  969. return $aResult['message'];
  970. return '';
  971. }
  972. /**
  973. * @page service Service Calls
  974. * @section bx_timeline Timeline
  975. * @subsection bx_timeline-other Other
  976. * @subsubsection bx_timeline-get_object_form get_object_form
  977. *
  978. * @code bx_srv('bx_timeline', 'get_object_form', [...]); @endcode
  979. *
  980. * Get form object for add, edit, view or delete the content.
  981. *
  982. * @param $sType 'add' is supported only
  983. * @param $aParams optional array with parameters(display name, etc)
  984. * @return form object or false on error
  985. *
  986. * @see BxTimelineModule::serviceGetObjectForm
  987. */
  988. /**
  989. * @ref bx_timeline-get_object_form "get_object_form"
  990. */
  991. public function serviceGetObjectForm ($sType, $aParams = array())
  992. {
  993. if(!in_array($sType, array('add')))
  994. return false;
  995. $bContext = $aParams['context_id'] !== false;
  996. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($aParams['context_id']))) !== false)
  997. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  998. return false;
  999. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  1000. $aParams['form_display'] = 'form_display_post_add_public';
  1001. if($bContext) {
  1002. if($aParams['context_id'] < 0) {
  1003. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_OWNER;
  1004. $aParams['form_display'] = 'form_display_post_add_profile';
  1005. }
  1006. else {
  1007. $aParams['type'] = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  1008. $aParams['form_display'] = 'form_display_post_add';
  1009. }
  1010. }
  1011. if(!empty($aParams['display']))
  1012. $aParams['form_display'] = $aParams['display'];
  1013. $oForm = $this->getFormPostObject($aParams);
  1014. /**
  1015. * @hooks
  1016. * @hookdef hook-system-get_object_form 'system', 'get_object_form' - hook to override an object of create content form, @see BxDolForm
  1017. * - $unit_name - equals `system`
  1018. * - $action - equals `get_object_form`
  1019. * - $object_id - not used
  1020. * - $sender_id - not used
  1021. * - $extra_params - array of additional params with the following array keys:
  1022. * - `module` - [string] module name
  1023. * - `type` - [string] 'add', 'edit', 'view' or 'delete' form display type
  1024. * - `params` - [array] form params array as key&value pairs
  1025. * - `form` - [object] by ref, an object of create content form, @see BxDolForm, can be overridden in hook processing
  1026. * @hook @ref hook-system-get_object_form
  1027. */
  1028. bx_alert('system', 'get_object_form', 0, 0, array(
  1029. 'module' => $this->_oConfig->getName(),
  1030. 'type' => $sType,
  1031. 'params' => $aParams,
  1032. 'form' => &$oForm
  1033. ));
  1034. return $oForm;
  1035. }
  1036. /**
  1037. * @page service Service Calls
  1038. * @section bx_timeline Timeline
  1039. * @subsection get_timeline_post
  1040. * @see BxTimelineModule::serviceGetTimelinePost
  1041. *
  1042. * Get Timeline post. It's needed for Timeline module.
  1043. *
  1044. * @param $aEvent timeline event array from Timeline module
  1045. * @return array in special format which is needed specifically for Timeline module to display the data.
  1046. */
  1047. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  1048. {
  1049. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1050. if(empty($aContentInfo) || !is_array($aContentInfo))
  1051. return false;
  1052. $aEvent = array_merge($aEvent, array(
  1053. 'owner_id' => $aContentInfo['owner_id'],
  1054. 'object_privacy_view' => $aContentInfo['object_privacy_view']
  1055. ));
  1056. /*
  1057. * Note. For 'Direct Timeline Posts' FIELD_OBJECT_ID contains post's author profile ID.
  1058. */
  1059. $this->_oConfig->CNF['FIELD_AUTHOR'] = $this->_oConfig->CNF['FIELD_OBJECT_ID'];
  1060. return parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  1061. }
  1062. /**
  1063. * @page service Service Calls
  1064. * @section bx_timeline Timeline
  1065. * @subsection get_timeline_post
  1066. * @see BxTimelineModule::serviceGetTimelinePostAllowedView
  1067. *
  1068. * Check Timeline post's visibility. It's needed for Timeline module, when its events
  1069. * are accessed and checked from outside. For example, when they are referenced
  1070. * from Channels module.
  1071. *
  1072. * @param $aEvent timeline event array from Timeline module
  1073. * @return mixed value: CHECK_ACTION_RESULT_ALLOWED or text of some error message.
  1074. */
  1075. public function serviceGetTimelinePostAllowedView($aEvent)
  1076. {
  1077. $CNF = &$this->_oConfig->CNF;
  1078. $iOwnerId = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  1079. if($iOwnerId == 0)
  1080. return CHECK_ACTION_RESULT_ALLOWED;
  1081. $oOwner = BxDolProfile::getInstance($iOwnerId);
  1082. if(!$oOwner)
  1083. return CHECK_ACTION_RESULT_ALLOWED;
  1084. $sModule = $oOwner->getModule();
  1085. $aOwnerInfo = BxDolService::call($sModule, 'get_info', array($oOwner->getContentId(), false));
  1086. if(empty($aOwnerInfo) || !is_array($aOwnerInfo))
  1087. return CHECK_ACTION_RESULT_ALLOWED;
  1088. return BxDolService::call($sModule, 'check_allowed_view_for_profile', array($aOwnerInfo));
  1089. }
  1090. /**
  1091. * @page service Service Calls
  1092. * @section bx_timeline Timeline
  1093. * @subsection bx_timeline-other Other
  1094. * @subsubsection bx_timeline-get_author get_author
  1095. *
  1096. * @code bx_srv('bx_timeline', 'get_author', [...]); @endcode
  1097. *
  1098. * Get author ID from content info by content ID. Is used in "Content Info Objects" system.
  1099. *
  1100. * @param $iContentId integer value with content ID.
  1101. * @return integer value with author ID.
  1102. *
  1103. * @see BxTimelineModule::serviceGetAuthor
  1104. */
  1105. /**
  1106. * @ref bx_timeline-get_author "get_author"
  1107. */
  1108. public function serviceGetAuthor ($iContentId)
  1109. {
  1110. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  1111. if(empty($aEvent) || !is_array($aEvent))
  1112. return 0;
  1113. return $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? (int)$aEvent['owner_id'] : (int)$aEvent['object_id'];
  1114. }
  1115. /**
  1116. * @page service Service Calls
  1117. * @section bx_timeline Timeline
  1118. * @subsection bx_timeline-other Other
  1119. * @subsubsection bx_timeline-get_date_changed get_date_changed
  1120. *
  1121. * @code bx_srv('bx_timeline', 'get_date_changed', [...]); @endcode
  1122. *
  1123. * Get date when the content was changed last time. Is used in "Content Info Objects" system.
  1124. * Note. In case of Timeline event 0 is returned everytime.
  1125. *
  1126. * @param $iContentId integer value with content ID.
  1127. * @return integer value with changing date.
  1128. *
  1129. * @see BxTimelineModule::serviceGetDateChanged
  1130. */
  1131. /**
  1132. * @ref bx_timeline-get_date_changed "get_date_changed"
  1133. */
  1134. public function serviceGetDateChanged ($iContentId)
  1135. {
  1136. return 0;
  1137. }
  1138. /**
  1139. * @page service Service Calls
  1140. * @section bx_timeline Timeline
  1141. * @subsection bx_timeline-other Other
  1142. * @subsubsection bx_timeline-get_link get_link
  1143. *
  1144. * @code bx_srv('bx_timeline', 'get_link', [...]); @endcode
  1145. *
  1146. * Get content view page link. Is used in "Content Info Objects" system.
  1147. *
  1148. * @param $iContentId integer value with content ID.
  1149. * @return string value with view page link.
  1150. *
  1151. * @see BxTimelineModule::serviceGetLink
  1152. */
  1153. /**
  1154. * @ref bx_timeline-get_link "get_link"
  1155. */
  1156. public function serviceGetLink ($iContentId)
  1157. {
  1158. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  1159. if(empty($aEvent) || !is_array($aEvent))
  1160. return '';
  1161. return $this->_oConfig->getItemViewUrl($aEvent);
  1162. }
  1163. /**
  1164. * @page service Service Calls
  1165. * @section bx_timeline Timeline
  1166. * @subsection bx_timeline-other Other
  1167. * @subsubsection bx_timeline-get_thumb get_thumb
  1168. *
  1169. * @code bx_srv('bx_timeline', 'get_thumb', [...]); @endcode
  1170. *
  1171. * Get content thumbnail link. Is used in "Content Info Objects" system.
  1172. * Note. In case of Timeline event an empty string is returned everytime.
  1173. *
  1174. * @param $iContentId integer value with content ID.
  1175. * @param $sTranscoder (optional) string value with transcoder name which should be applied to thumbnail image.
  1176. * @return string value with thumbnail link.
  1177. *
  1178. * @see BxTimelineModule::serviceGetThumb
  1179. */
  1180. /**
  1181. * @ref bx_timeline-get_thumb "get_thumb"
  1182. */
  1183. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  1184. {
  1185. return '';
  1186. }
  1187. /**
  1188. * @page service Service Calls
  1189. * @section bx_timeline Timeline
  1190. * @subsection bx_timeline-other Other
  1191. * @subsubsection bx_timeline-get_info get_info
  1192. *
  1193. * @code bx_srv('bx_timeline', 'get_info', [...]); @endcode
  1194. *
  1195. * Get content info by content ID. Is used in "Content Info Objects" system.
  1196. *
  1197. * @param $iContentId integer value with content ID.
  1198. * @param $bSearchableFieldsOnly (optional) boolean value determining all info or "searchable fields" only will be returned.
  1199. * @return an array with content info. Empty array is returned if something is wrong.
  1200. *
  1201. * @see BxTimelineModule::serviceGetInfo
  1202. */
  1203. /**
  1204. * @ref bx_timeline-get_info "get_info"
  1205. */
  1206. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  1207. {
  1208. $aContentInfo = $this->_oDb->getEvents(array(
  1209. 'browse' => 'id',
  1210. 'value' => $iContentId)
  1211. );
  1212. return BxDolContentInfo::formatFields($aContentInfo);
  1213. }
  1214. /**
  1215. * @page service Service Calls
  1216. * @section bx_timeline Timeline
  1217. * @subsection bx_timeline-other Other
  1218. * @subsubsection bx_timeline-get_title get_title
  1219. *
  1220. * @code bx_srv('bx_timeline', 'get_title', [...]); @endcode
  1221. *
  1222. * Get content title by content ID. Is used in "Content Info Objects" system.
  1223. *
  1224. * @param $iContentId integer value with content ID.
  1225. * @return an array with content info. Empty array is returned if something is wrong.
  1226. *
  1227. * @see BxTimelineModule::serviceGetTitle
  1228. */
  1229. /**
  1230. * @ref bx_timeline-get_title "get_title"
  1231. */
  1232. public function serviceGetTitle ($iContentId)
  1233. {
  1234. $sResult = parent::serviceGetTitle($iContentId);
  1235. if($sResult != '' && get_mb_substr($sResult, 0, 1) == '_')
  1236. $sResult = _t($sResult);
  1237. return $sResult;
  1238. }
  1239. /**
  1240. * @page service Service Calls
  1241. * @section bx_timeline Timeline
  1242. * @subsection bx_timeline-other Other
  1243. * @subsubsection bx_timeline-get_text get_text
  1244. *
  1245. * @code bx_srv('bx_timeline', 'get_text', [...]); @endcode
  1246. *
  1247. * Get content text by content ID. Is used in "Content Info Objects" system.
  1248. *
  1249. * @param $iContentId integer value with content ID.
  1250. * @return an array with content info. Empty array is returned if something is wrong.
  1251. *
  1252. * @see BxTimelineModule::serviceGetText
  1253. */
  1254. /**
  1255. * @ref bx_timeline-get_text "get_text"
  1256. */
  1257. public function serviceGetText ($iContentId)
  1258. {
  1259. $sResult = parent::serviceGetText($iContentId);
  1260. if(!$sResult)
  1261. return $sResult;
  1262. return $this->_oConfig->getDescription($sResult, $this->_getFieldValue('FIELD_OBJECT_OWNER_ID', $iContentId), '');
  1263. }
  1264. /**
  1265. * @page service Service Calls
  1266. * @section bx_timeline Timeline
  1267. * @subsection bx_timeline-other Other
  1268. * @subsubsection bx_timeline-get_search_result_unit get_search_result_unit
  1269. *
  1270. * @code bx_srv('bx_timeline', 'get_search_result_unit', [...]); @endcode
  1271. *
  1272. * Get search result unit by content ID. Is used in "Content Info Objects" system.
  1273. *
  1274. * @param $iContentId integer value with content ID.
  1275. * @param $sUnitTemplate (optional) string value with template name.
  1276. * @return HTML string with search result unit. Empty string is returned if something is wrong.
  1277. *
  1278. * @see BxTimelineModule::serviceGetSearchResultUnit
  1279. */
  1280. /**
  1281. * @ref bx_timeline-get_search_result_unit "get_search_result_unit"
  1282. */
  1283. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  1284. {
  1285. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  1286. if(empty($aEvent) || !is_array($aEvent))
  1287. return '';
  1288. if(empty($sUnitTemplate))
  1289. $sUnitTemplate = 'unit.html';
  1290. return $this->_oTemplate->unit($aEvent, true, $sUnitTemplate);
  1291. }
  1292. public function serviceGetSearchableFields ($aInputsAdd = [])
  1293. {
  1294. $CNF = $this->_oConfig->CNF;
  1295. foreach(['PUBLIC', 'PROFILE'] as $sDisplay) {
  1296. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD_' . $sDisplay], $this->_oTemplate);
  1297. if(!$oForm || empty($oForm->aInputs))
  1298. continue;
  1299. $aInputsAdd = array_merge($aInputsAdd, $oForm->aInputs);
  1300. }
  1301. $aResult = parent::serviceGetSearchableFields($aInputsAdd);
  1302. if(isset($aResult['text']))
  1303. unset($aResult['text']);
  1304. return array_merge($aResult, [
  1305. $CNF['FIELD_TITLE'] => _t('_bx_timeline_txt_title'),
  1306. $CNF['FIELD_TEXT'] => _t('_bx_timeline_txt_description'),
  1307. ]);
  1308. }
  1309. /**
  1310. * @page service Service Calls
  1311. * @section bx_timeline Timeline
  1312. * @subsection bx_timeline-page_blocks Page Blocks
  1313. * @subsubsection bx_timeline-get_block_post get_block_post
  1314. *
  1315. * @code bx_srv('bx_timeline', 'get_block_post', [...]); @endcode
  1316. *
  1317. * Get Post block for a separate page.
  1318. *
  1319. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1320. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1321. *
  1322. * @see BxTimelineModule::serviceGetBlockPost
  1323. */
  1324. /**
  1325. * @ref bx_timeline-get_block_post "get_block_post"
  1326. */
  1327. public function serviceGetBlockPost($iProfileId = 0)
  1328. {
  1329. if(empty($iProfileId) && bx_get('profile_id') !== false)
  1330. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1331. if(empty($iProfileId) && isLogged())
  1332. $iProfileId = bx_get_logged_profile_id();
  1333. if(!$iProfileId)
  1334. return array();
  1335. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  1336. return $this->_getBlockPost($iProfileId, array(
  1337. 'type' => $sType,
  1338. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  1339. ));
  1340. }
  1341. /**
  1342. * @page service Service Calls
  1343. * @section bx_timeline Timeline
  1344. * @subsection bx_timeline-page_blocks Page Blocks
  1345. * @subsubsection bx_timeline-get_block_post_profile get_block_post_profile
  1346. *
  1347. * @code bx_srv('bx_timeline', 'get_block_post_profile', [...]); @endcode
  1348. *
  1349. * Get Post block for the Profile page.
  1350. *
  1351. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  1352. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1353. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1354. *
  1355. * @see BxTimelineModule::serviceGetBlockPostProfile
  1356. */
  1357. /**
  1358. * @ref bx_timeline-get_block_post_profile "get_block_post_profile"
  1359. */
  1360. public function serviceGetBlockPostProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0)
  1361. {
  1362. if(empty($sProfileModule))
  1363. return array();
  1364. if(empty($iProfileContentId) && bx_get('id') !== false)
  1365. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1366. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  1367. if(empty($oProfile))
  1368. return array();
  1369. $iProfileId = $oProfile->id();
  1370. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  1371. return $this->_getBlockPost($iProfileId, array(
  1372. 'type' => $sType,
  1373. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  1374. ));
  1375. }
  1376. /**
  1377. * @page service Service Calls
  1378. * @section bx_timeline Timeline
  1379. * @subsection bx_timeline-page_blocks Page Blocks
  1380. * @subsubsection bx_timeline-get_block_post_home get_block_post_home
  1381. *
  1382. * @code bx_srv('bx_timeline', 'get_block_post_home', [...]); @endcode
  1383. *
  1384. * Get Post block for site's Home page.
  1385. *
  1386. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1387. *
  1388. * @see BxTimelineModule::serviceGetBlockPostHome
  1389. */
  1390. /**
  1391. * @ref bx_timeline-get_block_post_home "get_block_post_home"
  1392. */
  1393. public function serviceGetBlockPostHome()
  1394. {
  1395. $iProfileId = 0;
  1396. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  1397. return $this->_getBlockPost($iProfileId, array(
  1398. 'type' => $sType,
  1399. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  1400. ));
  1401. }
  1402. /**
  1403. * @page service Service Calls
  1404. * @section bx_timeline Timeline
  1405. * @subsection bx_timeline-page_blocks Page Blocks
  1406. * @subsubsection bx_timeline-get_block_post_account get_block_post_account
  1407. *
  1408. * @code bx_srv('bx_timeline', 'get_block_post_account', [...]); @endcode
  1409. *
  1410. * Get Post block for the Dashboard page.
  1411. *
  1412. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1413. *
  1414. * @see BxTimelineModule::serviceGetBlockPostAccount
  1415. */
  1416. /**
  1417. * @ref bx_timeline-get_block_post_account "get_block_post_account"
  1418. */
  1419. public function serviceGetBlockPostAccount()
  1420. {
  1421. if(!isLogged())
  1422. return '';
  1423. $iProfileId = $this->getProfileId();
  1424. $sType = BX_TIMELINE_TYPE_FEED;
  1425. return $this->_getBlockPost($iProfileId, array(
  1426. 'type' => $sType,
  1427. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  1428. ));
  1429. }
  1430. /**
  1431. * @page service Service Calls
  1432. * @section bx_timeline Timeline
  1433. * @subsection bx_timeline-page_blocks Page Blocks
  1434. * @subsubsection bx_timeline-get_block_post_custom get_block_post_custom
  1435. *
  1436. * @code bx_srv('bx_timeline', 'get_block_post_custom', [...]); @endcode
  1437. *
  1438. * Get Post block for the Custom timeline.
  1439. *
  1440. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1441. *
  1442. * @see BxTimelineModule::serviceGetBlockPostCustom
  1443. */
  1444. /**
  1445. * @ref bx_timeline-get_block_post_custom "get_block_post_custom"
  1446. */
  1447. public function serviceGetBlockPostCustom($aParams)
  1448. {
  1449. if(!isLogged())
  1450. return '';
  1451. $iProfileId = $this->getProfileId();
  1452. if (!isset($aParams['form_display']))
  1453. $aParams['form_display'] = $this->_oConfig->getPostFormDisplay($aParams['type']);
  1454. return $this->_getBlockPost($iProfileId, $aParams);
  1455. }
  1456. /**
  1457. * @page service Service Calls
  1458. * @section bx_timeline Timeline
  1459. * @subsection bx_timeline-page_blocks Page Blocks
  1460. * @subsubsection bx_timeline-get_block_view get_block_view
  1461. *
  1462. * @code bx_srv('bx_timeline', 'get_block_view', [...]); @endcode
  1463. *
  1464. * Get Timeline View block for a separate page.
  1465. *
  1466. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1467. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1468. *
  1469. * @see BxTimelineModule::serviceGetBlockView
  1470. */
  1471. /**
  1472. * @ref bx_timeline-get_block_view "get_block_view"
  1473. */
  1474. public function serviceGetBlockView($iProfileId = 0)
  1475. {
  1476. return $this->_serviceGetBlockView($iProfileId, array(
  1477. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1478. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1479. 'start' => -1,
  1480. 'per_page' => -1,
  1481. 'per_page_default' => $this->_oConfig->getPerPage(BX_BASE_MOD_NTFS_TYPE_OWNER),
  1482. 'timeline' => -1,
  1483. 'filter' => '',
  1484. 'modules' => array()
  1485. ));
  1486. }
  1487. /**
  1488. * @page service Service Calls
  1489. * @section bx_timeline Timeline
  1490. * @subsection bx_timeline-page_blocks Page Blocks
  1491. * @subsubsection bx_timeline-get_block_view_outline get_block_view_outline
  1492. *
  1493. * @code bx_srv('bx_timeline', 'get_block_view_outline', [...]); @endcode
  1494. *
  1495. * Get Outline View block for a separate page.
  1496. *
  1497. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1498. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1499. *
  1500. * @see BxTimelineModule::serviceGetBlockViewOutline
  1501. */
  1502. /**
  1503. * @ref bx_timeline-get_block_view_outline "get_block_view_outline"
  1504. */
  1505. public function serviceGetBlockViewOutline($iProfileId = 0)
  1506. {
  1507. return $this->_serviceGetBlockView($iProfileId, array(
  1508. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1509. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1510. 'start' => -1,
  1511. 'per_page' => -1,
  1512. 'per_page_default' => $this->_oConfig->getPerPage(BX_BASE_MOD_NTFS_TYPE_OWNER),
  1513. 'timeline' => -1,
  1514. 'filter' => '',
  1515. 'modules' => array()
  1516. ));
  1517. }
  1518. /**
  1519. * @page service Service Calls
  1520. * @section bx_timeline Timeline
  1521. * @subsection bx_timeline-page_blocks Page Blocks
  1522. * @subsubsection bx_timeline-get_block_view_profile get_block_view_profile
  1523. *
  1524. * @code bx_srv('bx_timeline', 'get_block_view_profile', [...]); @endcode
  1525. *
  1526. * Get Timeline View block for the Profile page.
  1527. *
  1528. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  1529. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1530. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1531. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1532. * @param $sFilter (optional) string value with filter name.
  1533. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1534. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1535. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1536. *
  1537. * @see BxTimelineModule::serviceGetBlockViewProfile
  1538. */
  1539. /**
  1540. * @ref bx_timeline-get_block_view_profile "get_block_view_profile"
  1541. */
  1542. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1543. {
  1544. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, array(
  1545. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1546. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1547. 'start' => $iStart,
  1548. 'per_page' => $iPerPage,
  1549. 'per_page_default' => $this->_oConfig->getPerPage(BX_BASE_MOD_NTFS_TYPE_OWNER),
  1550. 'timeline' => $iTimeline,
  1551. 'filter' => $sFilter,
  1552. 'modules' => $aModules
  1553. ));
  1554. }
  1555. /**
  1556. * @page service Service Calls
  1557. * @section bx_timeline Timeline
  1558. * @subsection bx_timeline-page_blocks Page Blocks
  1559. * @subsubsection bx_timeline-get_block_view_profile_outline get_block_view_profile_outline
  1560. *
  1561. * @code bx_srv('bx_timeline', 'get_block_view_profile_outline', [...]); @endcode
  1562. *
  1563. * Get Outline View block for the Profile page.
  1564. *
  1565. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  1566. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  1567. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1568. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1569. * @param $sFilter (optional) string value with filter name.
  1570. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1571. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1572. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1573. *
  1574. * @see BxTimelineModule::serviceGetBlockViewProfileOutline
  1575. */
  1576. /**
  1577. * @ref bx_timeline-get_block_view_profile_outline "get_block_view_profile_outline"
  1578. */
  1579. public function serviceGetBlockViewProfileOutline($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1580. {
  1581. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, array(
  1582. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1583. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1584. 'start' => $iStart,
  1585. 'per_page' => $iPerPage,
  1586. 'per_page_default' => $this->_oConfig->getPerPage(BX_BASE_MOD_NTFS_TYPE_OWNER),
  1587. 'timeline' => $iTimeline,
  1588. 'filter' => $sFilter,
  1589. 'modules' => $aModules
  1590. ));
  1591. }
  1592. public function serviceGetBlockViewsCustom($aParams = array())
  1593. {
  1594. $aParams = array_merge(array(
  1595. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1596. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  1597. 'owner_id' => 0,
  1598. ), $aParams);
  1599. return $this->_serviceGetBlockViews($aParams);
  1600. }
  1601. public function serviceGetBlockViewsTimeline($sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1602. {
  1603. return $this->_serviceGetBlockViews(array(
  1604. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1605. 'type' => $sType,
  1606. 'owner_id' => $iProfileId,
  1607. 'start' => $iStart,
  1608. 'per_page' => $iPerPage,
  1609. 'per_page_default' => $this->_oConfig->getPerPage($sType),
  1610. 'timeline' => $iTimeline,
  1611. 'filter' => $sFilter,
  1612. 'modules' => $aModules
  1613. ));
  1614. }
  1615. public function serviceGetBlockViewsOutline($sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1616. {
  1617. return $this->_serviceGetBlockViews(array(
  1618. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1619. 'type' => $sType,
  1620. 'owner_id' => $iProfileId,
  1621. 'start' => $iStart,
  1622. 'per_page' => $iPerPage,
  1623. 'per_page_default' => $this->_oConfig->getPerPage($sType),
  1624. 'timeline' => $iTimeline,
  1625. 'filter' => $sFilter,
  1626. 'modules' => $aModules
  1627. ));
  1628. }
  1629. /**
  1630. * @page service Service Calls
  1631. * @section bx_timeline Timeline
  1632. * @subsection bx_timeline-page_blocks Page Blocks
  1633. * @subsubsection bx_timeline-get_block_view_home get_block_view_home
  1634. *
  1635. * @code bx_srv('bx_timeline', 'get_block_view_home', [...]); @endcode
  1636. *
  1637. * Get Timeline View block for site's Home page.
  1638. *
  1639. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1640. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1641. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1642. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1643. * @param $sFilter (optional) string value with filter name.
  1644. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1645. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1646. *
  1647. * @see BxTimelineModule::serviceGetBlockViewHome
  1648. */
  1649. /**
  1650. * @ref bx_timeline-get_block_view_home "get_block_view_home"
  1651. */
  1652. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1653. {
  1654. return $this->_serviceGetBlockViewHome(array(
  1655. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1656. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  1657. 'owner_id' => $iProfileId,
  1658. 'start' => $iStart,
  1659. 'per_page' => $iPerPage,
  1660. 'per_page_default' => $this->_oConfig->getPerPage(BX_BASE_MOD_NTFS_TYPE_PUBLIC),
  1661. 'timeline' => $iTimeline,
  1662. 'filter' => $sFilter,
  1663. 'modules' => $aModules
  1664. ));
  1665. }
  1666. /**
  1667. * @page service Service Calls
  1668. * @section bx_timeline Timeline
  1669. * @subsection bx_timeline-page_blocks Page Blocks
  1670. * @subsubsection bx_timeline-get_block_view_home_outline get_block_view_home_outline
  1671. *
  1672. * @code bx_srv('bx_timeline', 'get_block_view_home_outline', [...]); @endcode
  1673. *
  1674. * Get Outline View block for site's Home page.
  1675. *
  1676. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1677. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1678. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1679. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1680. * @param $sFilter (optional) string value with filter name.
  1681. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1682. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1683. *
  1684. * @see BxTimelineModule::serviceGetBlockViewHomeOutline
  1685. */
  1686. /**
  1687. * @ref bx_timeline-get_block_view_home_outline "get_block_view_home_outline"
  1688. */
  1689. public function serviceGetBlockViewHomeOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1690. {
  1691. return $this->_serviceGetBlockViewHome(array(
  1692. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1693. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  1694. 'owner_id' => $iProfileId,
  1695. 'start' => $iStart,
  1696. 'per_page' => $iPerPage,
  1697. 'per_page_default' => $this->_oConfig->getPerPage(BX_BASE_MOD_NTFS_TYPE_PUBLIC),
  1698. 'timeline' => $iTimeline,
  1699. 'filter' => $sFilter,
  1700. 'modules' => $aModules
  1701. ));
  1702. }
  1703. /**
  1704. * @page service Service Calls
  1705. * @section bx_timeline Timeline
  1706. * @subsection bx_timeline-page_blocks Page Blocks
  1707. * @subsubsection bx_timeline-get_block_view_hot get_block_view_hot
  1708. *
  1709. * @code bx_srv('bx_timeline', 'get_block_view_hot', [...]); @endcode
  1710. *
  1711. * Get Timeline View block with Hot public events.
  1712. *
  1713. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1714. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1715. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1716. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1717. * @param $sFilter (optional) string value with filter name.
  1718. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1719. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1720. *
  1721. * @see BxTimelineModule::serviceGetBlockViewHot
  1722. */
  1723. /**
  1724. * @ref bx_timeline-get_block_view_hot "get_block_view_hot"
  1725. */
  1726. public function serviceGetBlockViewHot($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1727. {
  1728. return $this->_serviceGetBlockViewHot(array(
  1729. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1730. 'type' => BX_TIMELINE_TYPE_HOT,
  1731. 'owner_id' => $iProfileId,
  1732. 'start' => $iStart,
  1733. 'per_page' => $iPerPage,
  1734. 'per_page_default' => $this->_oConfig->getPerPage(BX_TIMELINE_TYPE_HOT),
  1735. 'timeline' => $iTimeline,
  1736. 'filter' => $sFilter,
  1737. 'modules' => $aModules
  1738. ));
  1739. }
  1740. /**
  1741. * @page service Service Calls
  1742. * @section bx_timeline Timeline
  1743. * @subsection bx_timeline-page_blocks Page Blocks
  1744. * @subsubsection bx_timeline-get_block_view_hot_outline get_block_view_hot_outline
  1745. *
  1746. * @code bx_srv('bx_timeline', 'get_block_view_hot_outline', [...]); @endcode
  1747. *
  1748. * Get Outline View block with Hot public events.
  1749. *
  1750. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1751. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1752. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1753. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1754. * @param $sFilter (optional) string value with filter name.
  1755. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1756. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1757. *
  1758. * @see BxTimelineModule::serviceGetBlockViewHotOutline
  1759. */
  1760. /**
  1761. * @ref bx_timeline-get_block_view_hot_outline "get_block_view_hot_outline"
  1762. */
  1763. public function serviceGetBlockViewHotOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1764. {
  1765. return $this->_serviceGetBlockViewHot(array(
  1766. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1767. 'type' => BX_TIMELINE_TYPE_HOT,
  1768. 'owner_id' => $iProfileId,
  1769. 'start' => $iStart,
  1770. 'per_page' => $iPerPage,
  1771. 'per_page_default' => $this->_oConfig->getPerPage(BX_TIMELINE_TYPE_HOT),
  1772. 'timeline' => $iTimeline,
  1773. 'filter' => $sFilter,
  1774. 'modules' => $aModules
  1775. ));
  1776. }
  1777. /**
  1778. * @page service Service Calls
  1779. * @section bx_timeline Timeline
  1780. * @subsection bx_timeline-page_blocks Page Blocks
  1781. * @subsubsection bx_timeline-get_block_view_account get_block_view_account
  1782. *
  1783. * @code bx_srv('bx_timeline', 'get_block_view_account', [...]); @endcode
  1784. *
  1785. * Get Timeline View block for the Dashboard page.
  1786. *
  1787. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1788. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1789. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1790. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1791. * @param $sFilter (optional) string value with filter name.
  1792. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1793. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1794. *
  1795. * @see BxTimelineModule::serviceGetBlockViewAccount
  1796. */
  1797. /**
  1798. * @ref bx_timeline-get_block_view_account "get_block_view_account"
  1799. */
  1800. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1801. {
  1802. if(!isLogged())
  1803. return '';
  1804. return $this->_serviceGetBlockViewByType(array(
  1805. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1806. 'type' => BX_TIMELINE_TYPE_FEED,
  1807. 'owner_id' => $iProfileId,
  1808. 'start' => $iStart,
  1809. 'per_page' => $iPerPage,
  1810. 'per_page_default' => $this->_oConfig->getPerPage(BX_TIMELINE_TYPE_FEED),
  1811. 'timeline' => $iTimeline,
  1812. 'filter' => $sFilter,
  1813. 'modules' => $aModules
  1814. ));
  1815. }
  1816. /**
  1817. * @page service Service Calls
  1818. * @section bx_timeline Timeline
  1819. * @subsection bx_timeline-page_blocks Page Blocks
  1820. * @subsubsection bx_timeline-get_block_view_account_outline get_block_view_account_outline
  1821. *
  1822. * @code bx_srv('bx_timeline', 'get_block_view_account_outline', [...]); @endcode
  1823. *
  1824. * Get Outline View block for the Dashboard page.
  1825. *
  1826. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1827. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1828. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1829. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1830. * @param $sFilter (optional) string value with filter name.
  1831. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1832. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1833. *
  1834. * @see BxTimelineModule::serviceGetBlockViewAccountOutline
  1835. */
  1836. /**
  1837. * @ref bx_timeline-get_block_view_account_outline "get_block_view_account_outline"
  1838. */
  1839. public function serviceGetBlockViewAccountOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1840. {
  1841. if(!isLogged())
  1842. return '';
  1843. return $this->_serviceGetBlockViewByType(array(
  1844. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1845. 'type' => BX_TIMELINE_TYPE_FEED,
  1846. 'owner_id' => $iProfileId,
  1847. 'start' => $iStart,
  1848. 'per_page' => $iPerPage,
  1849. 'per_page_default' => $this->_oConfig->getPerPage(BX_TIMELINE_TYPE_FEED),
  1850. 'timeline' => $iTimeline,
  1851. 'filter' => $sFilter,
  1852. 'modules' => $aModules
  1853. ));
  1854. }
  1855. /**
  1856. * @page service Service Calls
  1857. * @section bx_timeline Timeline
  1858. * @subsection bx_timeline-page_blocks Page Blocks
  1859. * @subsubsection bx_timeline-get_block_view_custom get_block_view_custom
  1860. *
  1861. * @code bx_srv('bx_timeline', 'get_block_view_custom', [...]); @endcode
  1862. *
  1863. * Get custom Timeline View block.
  1864. *
  1865. * @param $aParams (optional) an array with block parameneters.
  1866. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1867. *
  1868. * @see BxTimelineModule::serviceGetBlockViewCustom
  1869. *
  1870. * @example Events from followed contexts by type (groups, events, spaces, etc). Groups in this example.
  1871. * array ('module' => 'bx_timeline', 'method' => 'get_block_view_custom', 'params' => array (0 => array ('view' => 'timeline', 'type' => 'connected_contexts', 'context' => 'bx_groups')))
  1872. *
  1873. * @example Events from "For You" (Feed + Hot) feed.
  1874. * array ('module' => 'bx_timeline', 'method' => 'get_block_view_custom', 'params' => array (0 => array ('view' => 'timeline', 'type' => 'feed_and_hot')))
  1875. */
  1876. /**
  1877. * @ref bx_timeline-get_block_view_custom "get_block_view_custom"
  1878. */
  1879. public function serviceGetBlockViewCustom($aParams = [])
  1880. {
  1881. return $this->_serviceGetBlockViewByType($aParams);
  1882. }
  1883. public function serviceGetBlockMenuDb($aParams = [])
  1884. {
  1885. $aParams = $this->_prepareParams(array_merge([
  1886. 'name' => BX_TIMELINE_NAME_VIEWS_DB,
  1887. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1888. 'type' => BX_TIMELINE_TYPE_FEED,
  1889. 'owner_id' => $this->getProfileId()
  1890. ], $aParams));
  1891. if(($sType = $this->_oConfig->getUserChoice('type')) !== false)
  1892. $this->_setParamsType($sType, $aParams);
  1893. $sMenu = $this->_oConfig->getObject('menu_feeds');
  1894. if(isset($aParams['menu_feeds'])) {
  1895. $sMenu = $aParams['menu_feeds'];
  1896. unset($aParams['menu_feeds']);
  1897. }
  1898. $oMenu = BxDolMenu::getObjectInstance($sMenu);
  1899. if(!$oMenu)
  1900. return '';
  1901. $sSelectedModule = $this->getName();
  1902. $sSelectedName = $aParams['type'];
  1903. if(($aModule = $this->_oDb->getModuleByName($aParams['type']))) {
  1904. $sSelectedModule = $aModule['name'];
  1905. $sSelectedName = $aModule['uri'];
  1906. }
  1907. $oMenu->setSelected($sSelectedModule, $sSelectedName);
  1908. $oMenu->setBrowseParams($aParams);
  1909. return $oMenu->getCode();
  1910. }
  1911. public function serviceGetBlockViewsDb($aParams = [])
  1912. {
  1913. $iProfileId = $this->getProfileId();
  1914. $aParams = $this->_prepareParams(array_merge([
  1915. 'name' => BX_TIMELINE_NAME_VIEWS_DB,
  1916. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1917. 'type' => BX_TIMELINE_TYPE_FEED,
  1918. 'viewer_id' => $iProfileId,
  1919. 'owner_id' => $iProfileId
  1920. ], $aParams));
  1921. if(($sType = $this->_oConfig->getUserChoice('type', $aParams['viewer_id'])) !== false)
  1922. $this->_setParamsType($sType, $aParams);
  1923. $this->_iOwnerId = $aParams['owner_id'];
  1924. return $this->_oTemplate->getViewsDbBlock($aParams);
  1925. }
  1926. /**
  1927. * @page service Service Calls
  1928. * @section bx_timeline Timeline
  1929. * @subsection bx_timeline-page_blocks Page Blocks
  1930. * @subsubsection bx_timeline-get_block_item get_block_item
  1931. *
  1932. * @code bx_srv('bx_timeline', 'get_block_item', [...]); @endcode
  1933. *
  1934. * Get View Item block.
  1935. *
  1936. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1937. *
  1938. * @see BxTimelineModule::serviceGetBlockItem
  1939. */
  1940. /**
  1941. * @ref bx_timeline-get_block_item "get_block_item"
  1942. */
  1943. public function serviceGetBlockItem()
  1944. {
  1945. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1946. if(!$iItemId)
  1947. return array();
  1948. $aParams = $this->_prepareParams(array(
  1949. 'view' => BX_TIMELINE_VIEW_ITEM,
  1950. 'type' => BX_TIMELINE_TYPE_ITEM
  1951. ));
  1952. $aItemData = $this->getItemData($iItemId, $aParams);
  1953. if (bx_is_api()){
  1954. $aItemData['event'] = $this->_oTemplate->getPostApi($aItemData['event'], $aParams);
  1955. return [bx_api_get_block('feed_item', $aItemData)];
  1956. }
  1957. return $this->_oTemplate->getItemBlock($aItemData, $aParams);
  1958. }
  1959. public function serviceGetBlockItemContent()
  1960. {
  1961. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1962. $sMode = bx_process_input(bx_get('mode'));
  1963. if(!$iItemId || !$sMode)
  1964. return '';
  1965. return $this->_oTemplate->getItemBlockContent($iItemId, $sMode);
  1966. }
  1967. public function serviceGetBlockItemInfo()
  1968. {
  1969. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1970. if(!$iItemId)
  1971. return '';
  1972. return $this->_oTemplate->getItemBlockInfo($iItemId);
  1973. }
  1974. public function serviceGetBlockItemComments()
  1975. {
  1976. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1977. if(!$iItemId)
  1978. return '';
  1979. return $this->_oTemplate->getItemBlockComments($iItemId);
  1980. }
  1981. public function serviceGetBlockMuted($iProfileId = 0)
  1982. {
  1983. if(!isLogged())
  1984. return MsgBox(_t('_Access denied'));
  1985. if($iProfileId == 0)
  1986. $iProfileId = $this->_iProfileId;
  1987. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getObject('grid_mute'));
  1988. if(!$oGrid)
  1989. return MsgBox('_Empty');
  1990. $oGrid->setProfile($iProfileId);
  1991. return $oGrid->getCode();
  1992. }
  1993. public function serviceGetPost($mixedEvent, $aParams = [])
  1994. {
  1995. if(!empty($mixedEvent) && !is_array($mixedEvent))
  1996. $mixedEvent = $this->_oDb->getContentInfoById((int)$mixedEvent);
  1997. if(empty($mixedEvent) || !is_array($mixedEvent))
  1998. return '';
  1999. $sPost = $this->_oTemplate->getPost($mixedEvent, $this->_prepareParams(array_merge([
  2000. 'view' => BX_TIMELINE_VIEW_ITEM,
  2001. 'type' => BX_TIMELINE_TYPE_ITEM
  2002. ], $aParams)));
  2003. if(empty($sPost))
  2004. return '';
  2005. return isset($aParams['return_data_type']) && $aParams['return_data_type'] == 'array' ? $mixedEvent : $sPost;
  2006. }
  2007. public function serviceGetTimelineRepostAllowedView($aEvent)
  2008. {
  2009. return isset($aEvent['content']['allowed_view']) ? $aEvent['content']['allowed_view'] : CHECK_ACTION_RESULT_ALLOWED;
  2010. }
  2011. /**
  2012. * @page service Service Calls
  2013. * @section bx_timeline Timeline
  2014. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2015. * @subsubsection bx_timeline-get_notifications_data get_notifications_data
  2016. *
  2017. * @code bx_srv('bx_timeline', 'get_notifications_data', [...]); @endcode
  2018. *
  2019. * Data for Notifications module.
  2020. *
  2021. * @return an array with special format.
  2022. *
  2023. * @see BxTimelineModule::serviceGetNotificationsData
  2024. */
  2025. /**
  2026. * @ref bx_timeline-get_notifications_data "get_notifications_data"
  2027. */
  2028. public function serviceGetNotificationsData()
  2029. {
  2030. $sModule = $this->_aModule['name'];
  2031. return array(
  2032. 'handlers' => array(
  2033. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  2034. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  2035. array('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'),
  2036. array('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'),
  2037. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  2038. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  2039. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  2040. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  2041. array('group' => $sModule . '_reply', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'replyPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_reply', 'module_class' => 'Module'),
  2042. array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
  2043. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  2044. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  2045. array('group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_reaction', 'module_class' => 'Module'),
  2046. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  2047. array('group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module'),
  2048. array('group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module'),
  2049. ),
  2050. 'settings' => array(
  2051. array('group' => 'content', 'unit' => $sModule, 'action' => 'post_common', 'types' => array('personal', 'follow_member', 'follow_context')),
  2052. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => array('personal')),
  2053. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => array('personal')),
  2054. array('group' => 'content', 'unit' => $sModule, 'action' => 'repost', 'types' => array('personal', 'follow_member', 'follow_context')),
  2055. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  2056. array('group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => array('personal')),
  2057. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  2058. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  2059. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  2060. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  2061. ),
  2062. 'alerts' => array(
  2063. array('unit' => $sModule, 'action' => 'post_common'),
  2064. array('unit' => $sModule, 'action' => 'publish_failed'),
  2065. array('unit' => $sModule, 'action' => 'publish_succeeded'),
  2066. array('unit' => $sModule, 'action' => 'delete'),
  2067. array('unit' => $sModule, 'action' => 'repost'),
  2068. array('unit' => $sModule, 'action' => 'delete_repost'),
  2069. array('unit' => $sModule, 'action' => 'commentPost'),
  2070. array('unit' => $sModule, 'action' => 'commentRemoved'),
  2071. array('unit' => $sModule, 'action' => 'replyPost'),
  2072. array('unit' => $sModule, 'action' => 'replyRemoved'),
  2073. array('unit' => $sModule, 'action' => 'doVote'),
  2074. array('unit' => $sModule, 'action' => 'undoVote'),
  2075. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  2076. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  2077. array('unit' => $sModule, 'action' => 'doVoteUp'),
  2078. array('unit' => $sModule, 'action' => 'doVoteDown'),
  2079. )
  2080. );
  2081. }
  2082. /**
  2083. * @page service Service Calls
  2084. * @section bx_timeline Timeline
  2085. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2086. * @subsubsection bx_timeline-get_notifications_repost get_notifications_repost
  2087. *
  2088. * @code bx_srv('bx_timeline', 'get_notifications_repost', [...]); @endcode
  2089. *
  2090. * Get data for Repost event to display in Notifications module.
  2091. *
  2092. * @param $aEvent an array with event description.
  2093. * @return an array with special format.
  2094. *
  2095. * @see BxTimelineModule::serviceGetNotificationsRepost
  2096. */
  2097. /**
  2098. * @ref bx_timeline-get_notifications_repost "get_notifications_repost"
  2099. */
  2100. public function serviceGetNotificationsRepost($aEvent)
  2101. {
  2102. $aResult = $this->serviceGetNotificationsPost($aEvent);
  2103. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  2104. return $aResult;
  2105. }
  2106. /**
  2107. * @page service Service Calls
  2108. * @section bx_timeline Timeline
  2109. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2110. * @subsubsection bx_timeline-get_notifications_post get_notifications_post
  2111. *
  2112. * @code bx_srv('bx_timeline', 'get_notifications_post', [...]); @endcode
  2113. *
  2114. * Get data for Post event to display in Notifications module.
  2115. *
  2116. * @param $aEvent an array with event description.
  2117. * @return an array with special format.
  2118. *
  2119. * @see BxTimelineModule::serviceGetNotificationsPost
  2120. */
  2121. /**
  2122. * @ref bx_timeline-get_notifications_post "get_notifications_post"
  2123. */
  2124. public function serviceGetNotificationsPost($aEvent)
  2125. {
  2126. $CNF = &$this->_oConfig->CNF;
  2127. $iContent = (int)$aEvent['object_id'];
  2128. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  2129. if(empty($aContent) || !is_array($aContent))
  2130. return [];
  2131. if($this->_oConfig->isSystem($aContent['type'], $aContent['action']))
  2132. $iEntryAuthor = (int)$aContent['owner_id'];
  2133. else
  2134. $iEntryAuthor = (int)$aContent['object_id'];
  2135. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  2136. $sEntrySummary = $this->_oConfig->getTitle($aContent['description'], $aContent['object_id'], false);
  2137. return [
  2138. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  2139. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2140. 'entry_caption' => $sEntryCaption,
  2141. 'entry_summary' => $sEntrySummary,
  2142. 'entry_author' => $iEntryAuthor,
  2143. 'lang_key' => '' //may be empty or not specified. In this case the default one from Notification module will be used.
  2144. ];
  2145. }
  2146. /**
  2147. * @page service Service Calls
  2148. * @section bx_timeline Timeline
  2149. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2150. * @subsubsection bx_timeline-get_notifications_comment get_notifications_comment
  2151. *
  2152. * @code bx_srv('bx_timeline', 'get_notifications_comment', [...]); @endcode
  2153. *
  2154. * Get data for Post Comment event to display in Notifications module.
  2155. *
  2156. * @param $aEvent an array with event description.
  2157. * @return an array with special format.
  2158. *
  2159. * @see BxTimelineModule::serviceGetNotificationsComment
  2160. */
  2161. /**
  2162. * @ref bx_timeline-get_notifications_comment "get_notifications_comment"
  2163. */
  2164. public function serviceGetNotificationsComment($aEvent)
  2165. {
  2166. $CNF = &$this->_oConfig->CNF;
  2167. $iContent = (int)$aEvent['object_id'];
  2168. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  2169. if(empty($aContent) || !is_array($aContent))
  2170. return [];
  2171. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  2172. if(!$oComment || !$oComment->isEnabled())
  2173. return [];
  2174. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  2175. $sEntrySummary = $this->_oConfig->getTitle($aContent['description'], $aContent['object_id'], false);
  2176. $iCommentId = (int)$aEvent['subobject_id'];
  2177. return [
  2178. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2179. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2180. 'entry_caption' => $sEntryCaption,
  2181. 'entry_summary' => $sEntrySummary,
  2182. 'entry_author' => $aContent['owner_id'],
  2183. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  2184. 'subentry_url' => bx_absolute_url($oComment->getViewUrl($iCommentId, false), '{bx_url_root}'),
  2185. 'subentry_summary' => $oComment->getViewText($iCommentId),
  2186. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2187. ];
  2188. }
  2189. /**
  2190. * @page service Service Calls
  2191. * @section bx_timeline Timeline
  2192. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2193. * @subsubsection bx_timeline-get_notifications_reply get_notifications_reply
  2194. *
  2195. * @code bx_srv('bx_timeline', 'get_notifications_reply', [...]); @endcode
  2196. *
  2197. * Get data for Reply to Comment event to display in Notifications module.
  2198. *
  2199. * @param $aEvent an array with event description.
  2200. * @return an array with special format.
  2201. *
  2202. * @see BxTimelineModule::serviceGetNotificationsReply
  2203. */
  2204. /**
  2205. * @ref bx_timeline-get_notifications_reply "get_notifications_reply"
  2206. */
  2207. public function serviceGetNotificationsReply($aEvent)
  2208. {
  2209. $CNF = &$this->_oConfig->CNF;
  2210. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  2211. if(!$oComment || !$oComment->isEnabled())
  2212. return [];
  2213. $iParentId = (int)$aEvent['object_id'];
  2214. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  2215. if(empty($aParentInfo) || !is_array($aParentInfo))
  2216. return [];
  2217. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  2218. $oComment->init($iObjectId);
  2219. $iCommentId = (int)$aEvent['subobject_id'];
  2220. return [
  2221. 'object_id' => $iObjectId,
  2222. 'entry_sample' => '_cmt_txt_sample_comment_single',
  2223. 'entry_url' => bx_absolute_url($oComment->getViewUrl($iParentId, false), '{bx_url_root}'),
  2224. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  2225. 'entry_summary' => $oComment->getViewText($iParentId),
  2226. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  2227. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  2228. 'subentry_url' => bx_absolute_url($oComment->getViewUrl($iCommentId, false), '{bx_url_root}'),
  2229. 'subentry_summary' => $oComment->getViewText($iCommentId),
  2230. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2231. ];
  2232. }
  2233. /**
  2234. * @page service Service Calls
  2235. * @section bx_timeline Timeline
  2236. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2237. * @subsubsection bx_timeline-get_notifications_vote get_notifications_vote
  2238. *
  2239. * @code bx_srv('bx_timeline', 'get_notifications_vote', [...]); @endcode
  2240. *
  2241. * Get data for Vote event to display in Notifications module.
  2242. *
  2243. * @param $aEvent an array with event description.
  2244. * @return an array with special format.
  2245. *
  2246. * @see BxTimelineModule::serviceGetNotificationsVote
  2247. */
  2248. /**
  2249. * @ref bx_timeline-get_notifications_vote "get_notifications_vote"
  2250. */
  2251. public function serviceGetNotificationsVote($aEvent)
  2252. {
  2253. $CNF = &$this->_oConfig->CNF;
  2254. $iContent = (int)$aEvent['object_id'];
  2255. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  2256. if(empty($aContent) || !is_array($aContent))
  2257. return [];
  2258. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  2259. if(!$oVote || !$oVote->isEnabled())
  2260. return [];
  2261. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  2262. $sEntrySummary = $this->_oConfig->getTitle($aContent['description'], $aContent['object_id'], false);
  2263. return [
  2264. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2265. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2266. 'entry_caption' => $sEntryCaption,
  2267. 'entry_summary' => $sEntrySummary,
  2268. 'entry_author' => $aContent['owner_id'],
  2269. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  2270. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2271. ];
  2272. }
  2273. /**
  2274. * Entry post vote for Notifications module
  2275. */
  2276. public function serviceGetNotificationsReaction($aEvent)
  2277. {
  2278. $CNF = &$this->_oConfig->CNF;
  2279. $iContent = (int)$aEvent['object_id'];
  2280. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  2281. if(empty($aContent) || !is_array($aContent))
  2282. return [];
  2283. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContent);
  2284. if(!$oReaction || !$oReaction->isEnabled())
  2285. return [];
  2286. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  2287. if(empty($aSubentry) || !is_array($aSubentry))
  2288. return [];
  2289. $aSubentrySampleParams = array();
  2290. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  2291. if(!empty($aReaction['title']))
  2292. $aSubentrySampleParams[] = $aReaction['title'];
  2293. else
  2294. $aSubentrySampleParams[] = '_undefined';
  2295. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  2296. $sEntrySummary = $this->_oConfig->getTitle($aContent['description'], $aContent['object_id'], false);
  2297. return [
  2298. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2299. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2300. 'entry_caption' => $sEntryCaption,
  2301. 'entry_summary' => $sEntrySummary,
  2302. 'entry_author' => $aContent['owner_id'],
  2303. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  2304. 'subentry_sample_params' => $aSubentrySampleParams,
  2305. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2306. ];
  2307. }
  2308. /**
  2309. * @page service Service Calls
  2310. * @section bx_timeline Timeline
  2311. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2312. * @subsubsection bx_timeline-get_notifications_score_up get_notifications_score_up
  2313. *
  2314. * @code bx_srv('bx_timeline', 'get_notifications_score_up', [...]); @endcode
  2315. *
  2316. * Get data for Score Up Vote event to display in Notifications module.
  2317. *
  2318. * @param $aEvent an array with event description.
  2319. * @return an array with special format.
  2320. *
  2321. * @see BxTimelineModule::serviceGetNotificationsScoreUp
  2322. */
  2323. /**
  2324. * @ref bx_timeline-get_notifications_score_up "get_notifications_score_up"
  2325. */
  2326. public function serviceGetNotificationsScoreUp($aEvent)
  2327. {
  2328. return $this->_serviceGetNotificationsScore('up', $aEvent);
  2329. }
  2330. /**
  2331. * @page service Service Calls
  2332. * @section bx_timeline Timeline
  2333. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2334. * @subsubsection bx_timeline-get_notifications_score_down get_notifications_score_down
  2335. *
  2336. * @code bx_srv('bx_timeline', 'get_notifications_score_down', [...]); @endcode
  2337. *
  2338. * Get data for Score Down Vote event to display in Notifications module.
  2339. *
  2340. * @param $aEvent an array with event description.
  2341. * @return an array with special format.
  2342. *
  2343. * @see BxTimelineModule::serviceGetNotificationsScoreDown
  2344. */
  2345. /**
  2346. * @ref bx_timeline-get_notifications_score_down "get_notifications_score_down"
  2347. */
  2348. public function serviceGetNotificationsScoreDown($aEvent)
  2349. {
  2350. return $this->_serviceGetNotificationsScore('down', $aEvent);
  2351. }
  2352. protected function _serviceGetNotificationsScore($sType, $aEvent)
  2353. {
  2354. $CNF = &$this->_oConfig->CNF;
  2355. $iContent = (int)$aEvent['object_id'];
  2356. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  2357. if(empty($aContent) || !is_array($aContent))
  2358. return [];
  2359. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContent);
  2360. if(!$oScore || !$oScore->isEnabled())
  2361. return [];
  2362. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  2363. $sEntrySummary = $this->_oConfig->getTitle($aContent['description'], $aContent['object_id'], false);
  2364. return [
  2365. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2366. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2367. 'entry_caption' => $sEntryCaption,
  2368. 'entry_summary' => $sEntrySummary,
  2369. 'entry_author' => $aContent['owner_id'],
  2370. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  2371. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2372. ];
  2373. }
  2374. /**
  2375. * @page service Service Calls
  2376. * @section bx_timeline Timeline
  2377. * @subsection bx_timeline-repost Repost
  2378. * @subsubsection bx_timeline-get_repost_element_block get_repost_element_block
  2379. *
  2380. * @code bx_srv('bx_timeline', 'get_repost_element_block', [...]); @endcode
  2381. *
  2382. * Get repost element for content based modules.
  2383. *
  2384. * @param $iOwnerId integer value with owner profile ID.
  2385. * @param $sType string value with type (module name).
  2386. * @param $sAction string value with action (module action).
  2387. * @param $iObjectId integer value with object ID to be reposted.
  2388. * @param $aParams (optional) an array with additional params.
  2389. * @return HTML string with repost element to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  2390. *
  2391. * @see BxTimelineModule::serviceGetRepostElementBlock
  2392. */
  2393. /**
  2394. * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
  2395. */
  2396. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = [])
  2397. {
  2398. if(!$this->isEnabled())
  2399. return '';
  2400. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  2401. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  2402. }
  2403. /**
  2404. * @page service Service Calls
  2405. * @section bx_timeline Timeline
  2406. * @subsection bx_timeline-repost Repost
  2407. * @subsubsection bx_timeline-get_repost_element_block_api get_repost_element_block_api
  2408. *
  2409. * @code bx_srv('bx_timeline', 'get_repost_element_block_api', [...]); @endcode
  2410. *
  2411. * Get repost element for content based modules.
  2412. * Note. Response is formated to be used in API calls.
  2413. *
  2414. * @param $iOwnerId integer value with owner profile ID.
  2415. * @param $sType string value with type (module name).
  2416. * @param $sAction string value with action (module action).
  2417. * @param $iObjectId integer value with object ID to be reposted.
  2418. * @param $aParams (optional) an array with additional params.
  2419. * @return HTML string with repost element to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  2420. *
  2421. * @see BxTimelineModule::serviceGetRepostElementBlockApi
  2422. */
  2423. /**
  2424. * @ref bx_timeline-get_repost_element_block_api "get_repost_element_block_api"
  2425. * @api @ref bx_timeline-get_repost_element_block_api "get_repost_element_block_api"
  2426. */
  2427. public function serviceGetRepostElementBlockApi($iOwnerId, $sType, $sAction, $iObjectId, $aParams = [])
  2428. {
  2429. if(!$this->_bIsApi || !$this->isEnabled())
  2430. return [];
  2431. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2432. if(empty($aReposted) || !is_array($aReposted))
  2433. return [];
  2434. $aParams = array_merge($this->_oConfig->getRepostDefaults(true), $aParams);
  2435. $bPerformed = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $this->getUserId());
  2436. $bDisabled = $this->isAllowedRepost($aReposted) !== true;
  2437. $sDo = isset($aParams['do']) ? $aParams['do'] : 'repost';
  2438. $sDataType = $sType;
  2439. $sDataAction = $sAction;
  2440. $iDataObjectId = $iObjectId;
  2441. if(($sCommonPrefix = $this->_oConfig->getPrefix('common_post')) && str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  2442. $aRepostedData = unserialize($aReposted['content']);
  2443. $sDataType = $aRepostedData['type'];
  2444. $sDataAction = $aRepostedData['action'];
  2445. $iDataObjectId = $aRepostedData['object_id'];
  2446. }
  2447. return [
  2448. 'type' => 'reposts',
  2449. 'system' => $sType . (!empty($sAction) ? '_' . $sAction : ''),
  2450. 'object_id' => $iObjectId,
  2451. 'params' => array_intersect_key($aParams, array_flip($this->_oConfig->getRepostParams(true))),
  2452. 'action' => [
  2453. 'is_undo' => false,
  2454. 'is_performed' => $bPerformed,
  2455. 'is_disabled' => $bDisabled || $bPerformed,
  2456. 'title' => _t($aParams['text_do_' . $sDo]),
  2457. 'data' => [
  2458. 'author_id' => $iOwnerId,
  2459. 'owner_id' => $iOwnerId,
  2460. 'type' => $sDataType,
  2461. 'action' => $sDataAction,
  2462. 'object_id' => $iDataObjectId
  2463. ]
  2464. ],
  2465. 'counter' => []
  2466. ];
  2467. }
  2468. /**
  2469. * @page service Service Calls
  2470. * @section bx_timeline Timeline
  2471. * @subsection bx_timeline-repost Repost
  2472. * @subsubsection bx_timeline-get_repost_counter get_repost_counter
  2473. *
  2474. * @code bx_srv('bx_timeline', 'get_repost_counter', [...]); @endcode
  2475. *
  2476. * Get repost counter.
  2477. *
  2478. * @param $sType string value with type (module name).
  2479. * @param $sAction string value with action (module action).
  2480. * @param $iObjectId integer value with object ID to be reposted.
  2481. * @return HTML string with repost counter to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  2482. *
  2483. * @see BxTimelineModule::serviceGetRepostCounter
  2484. */
  2485. /**
  2486. * @ref bx_timeline-get_repost_counter "get_repost_counter"
  2487. */
  2488. public function serviceGetRepostCounter($sType, $sAction, $iObjectId, $aParams = [])
  2489. {
  2490. if(!$this->isEnabled())
  2491. return '';
  2492. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2493. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  2494. return $this->_oTemplate->getRepostCounter($aReposted, $aParams);
  2495. }
  2496. /**
  2497. * @page service Service Calls
  2498. * @section bx_timeline Timeline
  2499. * @subsection bx_timeline-repost Repost
  2500. * @subsubsection bx_timeline-get_repost_js_script get_repost_js_script
  2501. *
  2502. * @code bx_srv('bx_timeline', 'get_repost_js_script', [...]); @endcode
  2503. *
  2504. * Get repost JavaScript code.
  2505. *
  2506. * @return HTML string with JavaScript code to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  2507. *
  2508. * @see BxTimelineModule::serviceGetRepostJsScript
  2509. */
  2510. /**
  2511. * @ref bx_timeline-get_repost_js_script "get_repost_js_script"
  2512. */
  2513. public function serviceGetRepostJsScript()
  2514. {
  2515. if(!$this->isEnabled())
  2516. return '';
  2517. return $this->_oTemplate->getRepostJsScript();
  2518. }
  2519. /**
  2520. * @page service Service Calls
  2521. * @section bx_timeline Timeline
  2522. * @subsection bx_timeline-repost Repost
  2523. * @subsubsection bx_timeline-get_repost_js_click get_repost_js_click
  2524. *
  2525. * @code bx_srv('bx_timeline', 'get_repost_js_click', [...]); @endcode
  2526. *
  2527. * Get repost JavaScript code for OnClick event.
  2528. *
  2529. * @param $iOwnerId integer value with owner profile ID.
  2530. * @param $sType string value with type (module name).
  2531. * @param $sAction string value with action (module action).
  2532. * @param $iObjectId integer value with object ID to be reposted.
  2533. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  2534. *
  2535. * @see BxTimelineModule::serviceGetRepostJsClick
  2536. */
  2537. /**
  2538. * @ref bx_timeline-get_repost_js_click "get_repost_js_click"
  2539. */
  2540. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  2541. {
  2542. if(!$this->isEnabled())
  2543. return '';
  2544. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  2545. }
  2546. /**
  2547. * @page service Service Calls
  2548. * @section bx_timeline Timeline
  2549. * @subsection bx_timeline-repost Repost
  2550. * @subsubsection bx_timeline-get_repost_with_js_click get_repost_with_js_click
  2551. *
  2552. * @code bx_srv('bx_timeline', 'get_repost_with_js_click', [...]); @endcode
  2553. *
  2554. * Get 'repost with' JavaScript code for OnClick event.
  2555. *
  2556. * @param $iReposterId integer value with reposter profile ID.
  2557. * @param $sType string value with type (module name).
  2558. * @param $sAction string value with action (module action).
  2559. * @param $iObjectId integer value with object ID to be reposted.
  2560. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  2561. *
  2562. * @see BxTimelineModule::serviceGetRepostWithJsClick
  2563. */
  2564. /**
  2565. * @ref bx_timeline-get_repost_with_js_click "get_repost_with_js_click"
  2566. */
  2567. public function serviceGetRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId)
  2568. {
  2569. if(!$this->isEnabled())
  2570. return '';
  2571. return $this->_oTemplate->getRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId);
  2572. }
  2573. /**
  2574. * @page service Service Calls
  2575. * @section bx_timeline Timeline
  2576. * @subsection bx_timeline-repost Repost
  2577. * @subsubsection bx_timeline-get_repost_to_js_click get_repost_to_js_click
  2578. *
  2579. * @code bx_srv('bx_timeline', 'get_repost_to_js_click', [...]); @endcode
  2580. *
  2581. * Get 'repost to' JavaScript code for OnClick event.
  2582. *
  2583. * @param $iReposterId integer value with reposter profile ID.
  2584. * @param $sType string value with type (module name).
  2585. * @param $sAction string value with action (module action).
  2586. * @param $iObjectId integer value with object ID to be reposted.
  2587. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  2588. *
  2589. * @see BxTimelineModule::serviceGetRepostToJsClick
  2590. */
  2591. /**
  2592. * @ref bx_timeline-get_repost_to_js_click "get_repost_to_js_click"
  2593. */
  2594. public function serviceGetRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId)
  2595. {
  2596. if(!$this->isEnabled())
  2597. return '';
  2598. return $this->_oTemplate->getRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId);
  2599. }
  2600. /**
  2601. * @page service Service Calls
  2602. * @section bx_timeline Timeline
  2603. * @subsection bx_timeline-repost Repost
  2604. * @subsubsection bx_timeline-repost repost
  2605. *
  2606. * @code bx_srv('bx_timeline', 'repost', [...]); @endcode
  2607. *
  2608. * Perform repost action.
  2609. *
  2610. * @param $iAuthorId integer value with performer profile ID.
  2611. * @param $iOwnerId integer value with repost event owner profile ID.
  2612. * @param $sType string value with type (module name).
  2613. * @param $sAction string value with action (module action).
  2614. * @param $iObjectId integer value with object ID to be reposted.
  2615. * @parem $bForce boolean value force reposting without ACL check.
  2616. * @return an array with error (code and message) or integer with newly created repost event ID.
  2617. *
  2618. * @see BxTimelineModule::serviceRepost
  2619. */
  2620. /**
  2621. * @ref bx_timeline-repost "repost"
  2622. * @api @ref bx_timeline-repost "repost"
  2623. */
  2624. public function serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce = false)
  2625. {
  2626. $mixedResult = $this->repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, false, $bForce);
  2627. if($this->_bIsApi && !is_array($mixedResult))
  2628. $mixedResult = [
  2629. 'code' => 0,
  2630. 'id' => $mixedResult,
  2631. 'performer_id' => $iAuthorId,
  2632. 'is_performed' => true,
  2633. 'is_disabled' => true,
  2634. 'counter' => []
  2635. ];
  2636. return $mixedResult;
  2637. }
  2638. /**
  2639. * @page service Service Calls
  2640. * @section bx_timeline Timeline
  2641. * @subsection bx_timeline-repost Repost
  2642. * @subsubsection bx_timeline-repost_with repost_with
  2643. *
  2644. * @code bx_srv('bx_timeline', 'repost_with', [...]); @endcode
  2645. *
  2646. * Perform repost action passing additional data.
  2647. *
  2648. * @param $iAuthorId integer value with performer profile ID.
  2649. * @param $iOwnerId integer value with repost event owner profile ID.
  2650. * @param $sType string value with type (module name).
  2651. * @param $sAction string value with action (module action).
  2652. * @param $iObjectId integer value with object ID to be reposted.
  2653. * @param $mixedData array with some data to attach to repost event or false.
  2654. * @parem $bForce boolean value force reposting without ACL check.
  2655. * @return an array with error (code and message) or integer with newly created repost event ID.
  2656. *
  2657. * @see BxTimelineModule::serviceRepostWith
  2658. */
  2659. /**
  2660. * @ref bx_timeline-repost_with "repost_with"
  2661. */
  2662. public function serviceRepostWith($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $mixedData = false, $bForce = false)
  2663. {
  2664. return $this->repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $mixedData, $bForce);
  2665. }
  2666. /**
  2667. * @page service Service Calls
  2668. * @section bx_timeline Timeline
  2669. * @subsection bx_timeline-repost Repost
  2670. * @subsubsection bx_timeline-repost_by_id repost_by_id
  2671. *
  2672. * @code bx_srv('bx_timeline', 'repost_by_id', [...]); @endcode
  2673. *
  2674. * Perform repost action by Timeline event ID.
  2675. *
  2676. * @param $iAuthorId integer value with performer profile ID.
  2677. * @param $iOwnerId integer value with repost event owner profile ID.
  2678. * @param $iEventId integer value with event ID which will be reposted.
  2679. * @parem $bForce boolean value force reposting without ACL check.
  2680. * @return an array with error (code and message) or integer with newly created repost event ID.
  2681. *
  2682. * @see BxTimelineModule::serviceRepostById
  2683. */
  2684. /**
  2685. * @ref bx_timeline-repost_by_id "repost_by_id"
  2686. */
  2687. public function serviceRepostById($iAuthorId, $iOwnerId, $iEventId, $bForce = false)
  2688. {
  2689. $aEvent = $this->_oDb->getEntriesBy(array('type' => 'id', 'id' => $iEventId));
  2690. if(empty($aEvent) || !is_array($aEvent))
  2691. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2692. $sType = $aEvent['type'];
  2693. $sAction = $aEvent['action'];
  2694. $iObjectId = $this->_oConfig->isSystem($sType, $sAction) ? $aEvent['object_id'] : $aEvent['id'];
  2695. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  2696. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  2697. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2698. if(empty($aReposted) || !is_array($aReposted))
  2699. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2700. $aRepostedData = unserialize($aEvent['content']);
  2701. $sType = $aRepostedData['type'];
  2702. $sAction = $aRepostedData['action'];
  2703. $iObjectId = $aRepostedData['object_id'];
  2704. }
  2705. return $this->repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, false, $bForce);
  2706. }
  2707. public function isReposted($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId)
  2708. {
  2709. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2710. if(empty($aReposted) || !is_array($aReposted))
  2711. return false;
  2712. if(str_replace($this->_oConfig->getPrefix('common_post'), '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  2713. $aRepostedData = unserialize($aReposted['content']);
  2714. $aReposted = $this->_oDb->getReposted($aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
  2715. if(empty($aReposted) || !is_array($aReposted))
  2716. return false;
  2717. }
  2718. return $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  2719. }
  2720. public function repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $mixedData = false, $bForce = false)
  2721. {
  2722. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2723. if(empty($aReposted) || !is_array($aReposted))
  2724. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2725. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  2726. if(!$bForce && $mixedAllowed !== true)
  2727. return array('code' => 2, 'message' => strip_tags($mixedAllowed));
  2728. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  2729. if($bReposted)
  2730. return array('code' => 3, 'message' => _t('_bx_timeline_txt_err_already_reposted'));
  2731. $iDate = time();
  2732. $iId = $this->_oDb->insertEvent([
  2733. 'owner_id' => $iOwnerId,
  2734. 'system' => 0,
  2735. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  2736. 'action' => '',
  2737. 'object_id' => $iAuthorId,
  2738. 'object_owner_id' => $iAuthorId,
  2739. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  2740. 'content' => serialize([
  2741. 'type' => $sType,
  2742. 'action' => $sAction,
  2743. 'object_id' => $iObjectId,
  2744. 'rdata' => $mixedData
  2745. ]),
  2746. 'title' => '',
  2747. 'description' => '',
  2748. 'date' => $iDate,
  2749. 'reacted' => $iDate,
  2750. 'status_admin' => $this->getStatusAdmin()
  2751. ]);
  2752. if(empty($iId))
  2753. return array('code' => 4, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2754. $this->_oDb->updateEvent([
  2755. 'source' => $this->getName() . '_' . $iAuthorId . '_' . $iId
  2756. ], ['id' => $iId]);
  2757. $this->onRepost($iId, $aReposted);
  2758. return $iId;
  2759. }
  2760. /**
  2761. * @page service Service Calls
  2762. * @section bx_timeline Timeline
  2763. * @subsection bx_timeline-other Other
  2764. * @subsubsection bx_timeline-update update
  2765. *
  2766. * @code bx_srv('bx_timeline', 'update', [...]); @endcode
  2767. *
  2768. * Update timeline event by ID.
  2769. *
  2770. * @param $iEventId integer value with event ID.
  2771. * @param $aSet an array with key=>value pairs for fields which should be updated.
  2772. * @return boolean value with the result of operation.
  2773. *
  2774. * @see BxTimelineModule::serviceUpdate
  2775. */
  2776. /**
  2777. * @ref bx_timeline-update "update"
  2778. */
  2779. public function serviceUpdate($iEventId, $aSet)
  2780. {
  2781. if(empty($iEventId))
  2782. return false;
  2783. return (int)$this->_oDb->updateEvent($aSet, array('id' => $iEventId)) > 0;
  2784. }
  2785. /**
  2786. * @page service Service Calls
  2787. * @section bx_timeline Timeline
  2788. * @subsection bx_timeline-other Other
  2789. * @subsubsection bx_timeline-delete delete
  2790. *
  2791. * @code bx_srv('bx_timeline', 'delete', [...]); @endcode
  2792. *
  2793. * Delete timeline event by ID.
  2794. *
  2795. * @param $iId integer value with event ID.
  2796. * @return boolean value with the result of operation.
  2797. *
  2798. * @see BxTimelineModule::serviceDelete
  2799. */
  2800. /**
  2801. * @ref bx_timeline-delete "delete"
  2802. */
  2803. public function serviceDelete($iId)
  2804. {
  2805. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2806. if(empty($aEvent) || !is_array($aEvent))
  2807. return true;
  2808. if($this->isAllowedDelete($aEvent, true) !== true || !$this->deleteEvent($aEvent))
  2809. return false;
  2810. return true;
  2811. }
  2812. /**
  2813. * @page service Service Calls
  2814. * @section bx_timeline Timeline
  2815. * @subsection bx_timeline-other Other
  2816. * @subsubsection bx_timeline-get_menu_item_addon_comment get_menu_item_addon_comment
  2817. *
  2818. * @code bx_srv('bx_timeline', 'get_menu_item_addon_comment', [...]); @endcode
  2819. *
  2820. * Get addon for Comment menu item.
  2821. * NOTE. The service isn't used for now because comment functionality in card was updated.
  2822. *
  2823. * @param $sSystem string value with comments engine system.
  2824. * @param $iObjectId integer value with object ID.
  2825. * @return HTML string to display in menu item.
  2826. *
  2827. * @see BxTimelineModule::serviceGetMenuItemAddonComment
  2828. */
  2829. /**
  2830. * @ref bx_timeline-get_menu_item_addon_comment "get_menu_item_addon_comment"
  2831. */
  2832. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId, $aBrowseParams = array())
  2833. {
  2834. if(empty($sSystem) || empty($iObjectId))
  2835. return '';
  2836. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  2837. if($oCmts === false)
  2838. return '';
  2839. $iCounter = (int)$oCmts->getCommentsCount();
  2840. if(empty($iCounter))
  2841. return '';
  2842. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter, array(
  2843. 'class' => 'bx-menu-item-addon',
  2844. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  2845. 'onclick' => "javascript:" . $this->_oConfig->getJsObjectView($aBrowseParams) . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  2846. ));
  2847. }
  2848. /**
  2849. * @page service Service Calls
  2850. * @section bx_timeline Timeline
  2851. * @subsection bx_timeline-other Other
  2852. * @subsubsection bx_timeline-get_settings_checker_helper get_settings_checker_helper
  2853. *
  2854. * @code bx_srv('bx_timeline', 'get_settings_checker_helper', [...]); @endcode
  2855. *
  2856. * Get Checker Helper class name for Forms engine.
  2857. *
  2858. * @return string with Checker Helper class name.
  2859. *
  2860. * @see BxTimelineModule::serviceGetSettingsCheckerHelper
  2861. */
  2862. /**
  2863. * @ref bx_timeline-get_settings_checker_helper "get_settings_checker_helper"
  2864. */
  2865. public function serviceGetSettingsCheckerHelper()
  2866. {
  2867. bx_import('FormCheckerHelper', $this->_aModule);
  2868. return 'BxTimelineFormCheckerHelper';
  2869. }
  2870. /**
  2871. * @page service Service Calls
  2872. * @section bx_timeline Timeline
  2873. * @subsection bx_timeline-other Other
  2874. * @subsubsection bx_timeline-get_options_videos_preload get_options_videos_preload
  2875. *
  2876. * @code bx_srv('bx_timeline', 'get_options_videos_preload', [...]); @endcode
  2877. *
  2878. * Get an array with available options for 'Videos preload in Timeline' setting.
  2879. *
  2880. * @return an array with available options represented as key => value pairs.
  2881. *
  2882. * @see BxTimelineModule::serviceGetOptionsVideosPreload
  2883. */
  2884. /**
  2885. * @ref bx_timeline-get_options_videos_preload "get_options_videos_preload"
  2886. */
  2887. public function serviceGetOptionsVideosPreload()
  2888. {
  2889. $CNF = &$this->_oConfig->CNF;
  2890. $aOptions = array('auto', 'metadata', 'none');
  2891. $aResult = array();
  2892. foreach($aOptions as $sOption)
  2893. $aResult[] = array(
  2894. 'key' => $sOption,
  2895. 'value' => _t($CNF['T']['option_vp_' . $sOption])
  2896. );
  2897. return $aResult;
  2898. }
  2899. /**
  2900. * @page service Service Calls
  2901. * @section bx_timeline Timeline
  2902. * @subsection bx_timeline-other Other
  2903. * @subsubsection bx_timeline-get_options_videos_autoplay get_options_videos_autoplay
  2904. *
  2905. * @code bx_srv('bx_timeline', 'get_options_videos_autoplay', [...]); @endcode
  2906. *
  2907. * Get an array with available options for 'Videos autoplay in Timeline' setting.
  2908. *
  2909. * @return an array with available options represented as key => value pairs.
  2910. *
  2911. * @see BxTimelineModule::serviceGetOptionsVideosAutoplay
  2912. */
  2913. /**
  2914. * @ref bx_timeline-get_options_videos_autoplay "get_options_videos_autoplay"
  2915. */
  2916. public function serviceGetOptionsVideosAutoplay()
  2917. {
  2918. $CNF = &$this->_oConfig->CNF;
  2919. $aOptions = array(BX_TIMELINE_VAP_OFF, BX_TIMELINE_VAP_ON_MUTE, BX_TIMELINE_VAP_ON);
  2920. $aResult = array();
  2921. foreach($aOptions as $sOption)
  2922. $aResult[] = array(
  2923. 'key' => $sOption,
  2924. 'value' => _t($CNF['T']['option_vap_' . $sOption])
  2925. );
  2926. return $aResult;
  2927. }
  2928. /**
  2929. * @page service Service Calls
  2930. * @section bx_timeline Timeline
  2931. * @subsection bx_timeline-other Other
  2932. * @subsubsection bx_timeline-get_options_attachments_layout get_options_attachments_layout
  2933. *
  2934. * @code bx_srv('bx_timeline', 'get_options_attachments_layout', [...]); @endcode
  2935. *
  2936. * Get an array with available options for 'Show attachments as' setting.
  2937. *
  2938. * @return an array with available options represented as key => value pairs.
  2939. *
  2940. * @see BxTimelineModule::serviceGetOptionsAttachmentsLayout
  2941. */
  2942. /**
  2943. * @ref bx_timeline-get_options_attachments_layout "get_options_attachments_layout"
  2944. */
  2945. public function serviceGetOptionsAttachmentsLayout()
  2946. {
  2947. $CNF = &$this->_oConfig->CNF;
  2948. $aOptions = array(BX_TIMELINE_ML_GALLERY, BX_TIMELINE_ML_SHOWCASE);
  2949. $aResult = array();
  2950. foreach($aOptions as $sOption)
  2951. $aResult[] = array(
  2952. 'key' => $sOption,
  2953. 'value' => _t($CNF['T']['option_al_' . $sOption])
  2954. );
  2955. return $aResult;
  2956. }
  2957. /**
  2958. * @page service Service Calls
  2959. * @section bx_timeline Timeline
  2960. * @subsection bx_timeline-other Other
  2961. * @subsubsection bx_timeline-get_live_update get_live_update
  2962. *
  2963. * @code bx_srv('bx_timeline', 'get_live_update', [...]); @endcode
  2964. *
  2965. * Get an array with actual Live Update info. Only one live update notification for all new events.
  2966. *
  2967. * @return an array with Live Update info.
  2968. *
  2969. * @see BxTimelineModule::serviceGetLiveUpdate
  2970. */
  2971. /**
  2972. * @ref bx_timeline-get_live_update "get_live_update"
  2973. */
  2974. public function serviceGetLiveUpdate($aBrowseParams, $iProfileId, $iValue = 0, $iInit = 0)
  2975. {
  2976. $CNF = &$this->_oConfig->CNF;
  2977. if (!is_array($aBrowseParams)){
  2978. $aTmp = json_decode($aBrowseParams, true);
  2979. $aBrowseParams = $aTmp['params'];
  2980. }
  2981. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  2982. bx_import('BxDolSession');
  2983. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  2984. return false;
  2985. $aParams = $this->_prepareParams($aBrowseParams);
  2986. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  2987. if(($iLiveUpdateLength = $this->_oConfig->getLiveUpdateLength()) != 0)
  2988. $aParams['per_page'] = $iLiveUpdateLength;
  2989. $aEvents = $this->_oDb->getEvents($aParams);
  2990. if(empty($aEvents) || !is_array($aEvents))
  2991. return false;
  2992. $iValueNew = 0;
  2993. foreach($aEvents as $aEvent) {
  2994. if((int)$aEvent[$CNF['FIELD_STICKED']] != 0)
  2995. continue;
  2996. $sContent = $this->_oTemplate->getPost($aEvent, $aParams);
  2997. if(empty($sContent))
  2998. continue;
  2999. $iValueNew = $aEvent['id'];
  3000. break;
  3001. }
  3002. if($iValueNew == $iValue)
  3003. return false;
  3004. if($this->_bIsApi)
  3005. return $iValueNew;
  3006. if((int)$iInit != 0)
  3007. return array('count' => $iValueNew);
  3008. return array(
  3009. 'count' => $iValueNew, // required (for initialization and visualization)
  3010. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdate(oData)', // required (for visualization)
  3011. 'data' => array(
  3012. 'code' => $this->_oTemplate->getLiveUpdate($aBrowseParams, $iProfileId, $iValue, $iValueNew)
  3013. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  3014. );
  3015. }
  3016. /**
  3017. * @page service Service Calls
  3018. * @section bx_timeline Timeline
  3019. * @subsection bx_timeline-other Other
  3020. * @subsubsection bx_timeline-get_live_updates get_live_updates
  3021. *
  3022. * @code bx_srv('bx_timeline', 'get_live_updates', [...]); @endcode
  3023. *
  3024. * Get an array with actual Live Update info. Separate live update notification for each new Event.
  3025. * Note. This method isn't used for now. @see BxTimelineModule::serviceGetLiveUpdate method instead.
  3026. *
  3027. * Note. This way to display live update notifications isn't used for now.
  3028. * See BxTimelineModule::serviceGetLiveUpdate method instead.
  3029. *
  3030. * @return an array with Live Update info.
  3031. *
  3032. * @see BxTimelineModule::serviceGetLiveUpdates
  3033. */
  3034. /**
  3035. * @ref bx_timeline-get_live_updates "get_live_updates"
  3036. */
  3037. public function serviceGetLiveUpdates($aBrowseParams, $iProfileId, $iCount = 0, $iInit = 0)
  3038. {
  3039. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  3040. bx_import('BxDolSession');
  3041. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  3042. return false;
  3043. $aParams = $this->_prepareParams($aBrowseParams);
  3044. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  3045. $aParams['count'] = true;
  3046. $iCountNew = $this->_oDb->getEvents($aParams);
  3047. if($iCountNew == $iCount)
  3048. return false;
  3049. if((int)$iInit != 0)
  3050. return array('count' => $iCountNew);
  3051. return array(
  3052. 'count' => $iCountNew, // required (for initialization and visualization)
  3053. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdates(oData)', // required (for visualization)
  3054. 'data' => array(
  3055. 'code' => $this->_oTemplate->getLiveUpdates($aBrowseParams, $iProfileId, $iCount, $iCountNew)
  3056. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  3057. );
  3058. }
  3059. /**
  3060. * @page service Service Calls
  3061. * @section bx_timeline Accounts
  3062. * @subsection bx_timeline-other Other
  3063. * @subsubsection bx_timeline-get_menu_addon_manage_tools get_menu_addon_manage_tools
  3064. *
  3065. * @code bx_srv('bx_timeline', 'get_menu_addon_manage_tools', [...]); @endcode
  3066. *
  3067. * Get number of 'hidden' events for User End -> Dasboard page -> Manage block.
  3068. *
  3069. * @return integer number of 'hidden' events
  3070. *
  3071. * @see BxTimelineModule::serviceGetMenuAddonManageTools
  3072. */
  3073. /**
  3074. * @ref bx_timeline-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
  3075. */
  3076. public function serviceGetMenuAddonManageTools()
  3077. {
  3078. $iNum1 = $this->_oDb->getEntriesNumByParams([
  3079. [
  3080. 'key' => 'status',
  3081. 'value' => BX_TIMELINE_STATUS_HIDDEN,
  3082. 'operator' => '='
  3083. ]
  3084. ]);
  3085. $iNum2 = $this->_oDb->getEntriesNumByParams([
  3086. [
  3087. 'key' => 'reports',
  3088. 'value' => '0',
  3089. 'operator' => '>'
  3090. ]
  3091. ]);
  3092. return array(
  3093. 'counter1_value' => $iNum1,
  3094. 'counter2_value' => $iNum2,
  3095. 'counter3_value' => 0
  3096. );
  3097. }
  3098. /**
  3099. * @page service Service Calls
  3100. * @section bx_timeline Accounts
  3101. * @subsection bx_timeline-other Other
  3102. * @subsubsection bx_timeline-get_menu_addon_profile_stats get_menu_addon_profile_stats
  3103. *
  3104. * @code bx_srv('bx_timeline', 'get_menu_addon_profile_stats', [...]); @endcode
  3105. *
  3106. * Get number of 'muted' events for currently logged in user. User End -> Profile Stats.
  3107. *
  3108. * @return integer number of 'muted' events
  3109. *
  3110. * @see BxTimelineModule::serviceGetMenuAddonProfileStats
  3111. */
  3112. /**
  3113. * @ref bx_timeline-get_menu_addon_profile_stats "get_menu_addon_profile_stats"
  3114. */
  3115. public function serviceGetMenuAddonProfileStats($iProfileId = 0)
  3116. {
  3117. if(empty($iProfileId))
  3118. $iProfileId = $this->_iProfileId;
  3119. return $this->getConnectionMuteObject()->getConnectedContentCount($iProfileId);
  3120. }
  3121. public function serviceGet($aParams)
  3122. {
  3123. if($this->_bIsApi && is_string($aParams))
  3124. $aParams = bx_api_get_browse_params($aParams, true);
  3125. $aParams = $this->_prepareParams($aParams);
  3126. $aParams['return_data_type'] = 'array';
  3127. return $this->_oTemplate->getPosts($aParams);
  3128. }
  3129. public function serviceAdd($aValues)
  3130. {
  3131. return $this->getFormPost(array(
  3132. 'values' => $aValues
  3133. ));
  3134. }
  3135. public function serviceEdit($iId, $aValues)
  3136. {
  3137. return $this->getFormEdit($iId, array(
  3138. 'values' => $aValues
  3139. ));
  3140. }
  3141. /**
  3142. * Delete content entry
  3143. * @param $iContentId content id
  3144. * @return error message or empty string on success
  3145. */
  3146. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  3147. {
  3148. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3149. if(empty($aEvent) || !is_array($aEvent))
  3150. return _t('_Empty');
  3151. if(!$this->deleteEvent($aEvent))
  3152. return _t('_bx_timeline_txt_err_cannot_perform_action');
  3153. return '';
  3154. }
  3155. public function serviceGetEvents($aParams = [])
  3156. {
  3157. return $this->_oDb->getEvents($aParams);
  3158. }
  3159. public function serviceGetEventsByDescriptor($sType, $sAction, $iObjectId)
  3160. {
  3161. return $this->_oDb->getEvents([
  3162. 'browse' => 'descriptor',
  3163. 'type' => $sType,
  3164. 'action' => $sAction,
  3165. 'object_id' => $iObjectId
  3166. ]);
  3167. }
  3168. /*
  3169. * COMMON METHODS
  3170. */
  3171. public function getStatusAdmin()
  3172. {
  3173. return $this->isModerator() || $this->_oConfig->isAutoApproveEnabled() ? BX_TIMELINE_STATUS_ACTIVE : BX_TIMELINE_STATUS_PENDING;
  3174. }
  3175. public function getItemData($iId, $aParams = array())
  3176. {
  3177. $CNF = &$this->_oConfig->CNF;
  3178. if(empty($aParams))
  3179. $aParams = $this->_prepareParams(array(
  3180. 'view' => BX_TIMELINE_VIEW_ITEM,
  3181. 'type' => BX_TIMELINE_TYPE_ITEM
  3182. ));
  3183. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  3184. if(empty($aEvent))
  3185. return array('code' => 1, 'content' => _t('_Empty'));
  3186. $iProfile = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  3187. if(!empty($iProfile)) {
  3188. $oProfile = BxDolProfile::getInstance($iProfile);
  3189. if(!$oProfile)
  3190. return array('code' => 1, 'content' => _t('_Empty'));
  3191. $mixedResult = $oProfile->checkAllowedProfileView();
  3192. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  3193. return array('code' => 2, 'content' => $mixedResult);
  3194. }
  3195. $sContent = $this->_oTemplate->getPost($aEvent, $aParams);
  3196. if(empty($sContent))
  3197. return array('code' => 2, 'content' => _t('_Access denied'));
  3198. $sKey = 'allowed_view';
  3199. if(isset($aEvent[$sKey]) && $aEvent[$sKey] !== CHECK_ACTION_RESULT_ALLOWED)
  3200. return array('code' => 2, 'content' => $aEvent[$sKey]);
  3201. if($this->isAllowedView($aEvent) !== true)
  3202. return array('code' => 2, 'content' => _t('_Access denied'));
  3203. return array('code' => 0, 'content' => $sContent, 'event' => $aEvent);
  3204. }
  3205. public function hideEvent($aEvent)
  3206. {
  3207. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->updateEvent(['status' => 'hidden'], ['id' => (int)$aEvent['id']]))
  3208. return false;
  3209. $this->onHide($aEvent);
  3210. return true;
  3211. }
  3212. public function deleteEvent($aEvent)
  3213. {
  3214. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  3215. return false;
  3216. $this->onDelete($aEvent);
  3217. return true;
  3218. }
  3219. public function getFormPost($aParams = [])
  3220. {
  3221. $CNF = &$this->_oConfig->CNF;
  3222. $iUserId = $this->getUserId();
  3223. $oForm = $this->getFormPostObject($aParams);
  3224. $aFormInitCheckerParams = [];
  3225. $bValues = !empty($aParams['values']) && is_array($aParams['values']);
  3226. if($bValues) {
  3227. $this->_prepareFormForAutoSubmit($oForm, $aParams['values']);
  3228. $aFormInitCheckerParams = [[], $aParams['values']];
  3229. unset($aParams['values']);
  3230. }
  3231. call_user_func_array([$oForm, 'initChecker'], $aFormInitCheckerParams);
  3232. $bAjaxMode = $oForm->isAjaxMode();
  3233. $bDynamicMode = $bAjaxMode;
  3234. if($oForm->isSubmittedAndValid()) {
  3235. $sType = $oForm->getCleanValue('type');
  3236. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  3237. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  3238. $aContent = [];
  3239. //--- Process Text ---//
  3240. $sText = $oForm->getCleanValue('text');
  3241. $sText = $this->_prepareTextForSave($sText);
  3242. $bText = !empty($sText);
  3243. if($bText)
  3244. $aContent['text'] = $sText;
  3245. //--- Process Context and Privacy ---//
  3246. $iOwnerId = (int)$oForm->getCleanValue('owner_id');
  3247. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  3248. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  3249. if(empty($iObjectPrivacyView))
  3250. $iObjectPrivacyView = $iObjectPrivacyViewDefault;
  3251. else if($iObjectPrivacyView < 0)
  3252. $iOwnerId = abs($iObjectPrivacyView);
  3253. //--- Process Link ---//
  3254. $aLinkIds = $oForm->getCleanValue($CNF['FIELD_LINK']);
  3255. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  3256. //--- Process Photos ---//
  3257. $aPhotoIds = $oForm->getCleanValue($CNF['FIELD_PHOTO']);
  3258. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  3259. //--- Process Videos ---//
  3260. $aVideoIds = $oForm->getCleanValue($CNF['FIELD_VIDEO']);
  3261. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  3262. //--- Process Files ---//
  3263. $aFileIds = $oForm->getCleanValue($CNF['FIELD_FILE']);
  3264. $bFileIds = !empty($aFileIds) && is_array($aFileIds);
  3265. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds && !$bFileIds) {
  3266. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  3267. $oForm->setValid(false);
  3268. if(bx_is_api())
  3269. return ['form_object' => $oForm];
  3270. return $this->_prepareResponse([
  3271. 'form' => $oForm->getCode($bDynamicMode),
  3272. 'form_id' => $oForm->id
  3273. ], $bAjaxMode);
  3274. }
  3275. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $this->_oConfig->getTitleDefault($bLinkIds, $bPhotoIds, $bVideoIds, $bFileIds);
  3276. $sDescription = _t('_bx_timeline_txt_user_added_sample', '{profile_name}', _t('_bx_timeline_txt_sample_with_article'));
  3277. /**
  3278. * Unset 'text' input because its data was already processed
  3279. * and will be saved via additional values which were passed
  3280. * to BxDolForm::insert method.
  3281. */
  3282. unset($oForm->aInputs['text']['db']);
  3283. $oForm->aInputs['text']['value'] = '';
  3284. $iId = $oForm->insert([
  3285. 'owner_id' => $iOwnerId,
  3286. 'object_id' => $iUserId,
  3287. 'object_owner_id' => $iUserId,
  3288. 'object_privacy_view' => $iObjectPrivacyView,
  3289. 'content' => serialize($aContent),
  3290. 'title' => $sTitle,
  3291. 'description' => $sDescription,
  3292. 'status_admin' => $this->getStatusAdmin()
  3293. ]);
  3294. if(!empty($iId)) {
  3295. $this->isAllowedPost(true);
  3296. $sSource = $this->getName() . '_' . $iUserId . '_' . $iId;
  3297. $aContent = array_merge($aContent, [
  3298. 'timeline_group' => [
  3299. 'by' => $sSource,
  3300. 'field' => 'owner_id'
  3301. ]
  3302. ]);
  3303. $this->_oDb->updateEvent(['content' => serialize($aContent), 'source' => $sSource], ['id' => $iId]);
  3304. //--- Process Meta ---//
  3305. $this->_processMetas($iId, $sText);
  3306. //--- Process Link ---//
  3307. if($bLinkIds)
  3308. foreach($aLinkIds as $iLinkId)
  3309. $this->_oDb->saveLink($iId, $iLinkId);
  3310. //--- Process Media ---//
  3311. $this->_saveMedia($CNF['FIELD_PHOTO'], $iId, $aPhotoIds, $iUserId, true);
  3312. $this->_saveMedia($CNF['FIELD_VIDEO'], $iId, $aVideoIds, $iUserId, true);
  3313. $this->_saveMedia($CNF['FIELD_FILE'], $iId, $aFileIds, $iUserId, true);
  3314. $this->onPost($iId);
  3315. if(bx_is_api())
  3316. return ['form_object' => $oForm, 'id' => $iId];
  3317. return $this->_prepareResponse(['id' => $iId], $bAjaxMode, [
  3318. 'redirect' => $this->_oConfig->getItemViewUrl(['id' => $iId])
  3319. ]);
  3320. }
  3321. return $this->_prepareResponse(['message' => _t('_bx_timeline_txt_err_cannot_perform_action')], $bAjaxMode);
  3322. }
  3323. if(bx_is_api())
  3324. return ['form_object' => $oForm];
  3325. $mixedResult = $this->_prepareResponse([
  3326. 'form' => $oForm->getCode($bDynamicMode),
  3327. 'form_id' => $oForm->id
  3328. ], $bAjaxMode && $oForm->isSubmitted());
  3329. if(is_array($mixedResult))
  3330. $mixedResult['form_object'] = $oForm;
  3331. return $mixedResult;
  3332. }
  3333. public function getFormEdit($iId, $aParams = [], $aBrowseParams = [])
  3334. {
  3335. $CNF = &$this->_oConfig->CNF;
  3336. $sJsObjectView = $this->_oConfig->getJsObjectView($aBrowseParams);
  3337. $iUserId = $this->getUserId();
  3338. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iId]);
  3339. if(empty($aEvent) || !is_array($aEvent))
  3340. return [];
  3341. if(($mixedCheck = $this->isAllowedEdit($aEvent)) !== true)
  3342. return $this->_bIsApi ? bx_api_get_msg($mixedCheck !== false ? $mixedCheck : _t('_sys_txt_access_denied')) : ['message' => $mixedCheck !== false ? $mixedCheck : _t('_sys_txt_access_denied')];
  3343. $aContent = unserialize($aEvent['content']);
  3344. if(is_array($aContent) && !empty($aContent['text']))
  3345. $aEvent['text'] = $aContent['text'];
  3346. if(empty($aParams['form_object']))
  3347. $aParams['form_object'] = 'form_post';
  3348. if(empty($aParams['form_display']))
  3349. $aParams['form_display'] = 'form_display_post_edit';
  3350. $oForm = $this->getFormPostObject($aParams);
  3351. $oForm->setId($this->_oConfig->getHtmlIds('view', 'edit_form') . $iId);
  3352. $aFormInitCheckerParams = [];
  3353. $bValues = !empty($aParams['values']) && is_array($aParams['values']);
  3354. if($bValues) {
  3355. $this->_prepareFormForAutoSubmit($oForm, $aParams['values']);
  3356. $aFormInitCheckerParams = [[], array_merge($aEvent, $aParams['values'])];
  3357. unset($aParams['values']);
  3358. }
  3359. else {
  3360. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit/' . $iId ;
  3361. if(!empty($aBrowseParams) && is_array($aBrowseParams))
  3362. $oForm->aFormAttrs['action'] = $this->_oConfig->addBrowseParams($oForm->aFormAttrs['action'], $aBrowseParams);
  3363. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  3364. if(!is_numeric($mixedIndex))
  3365. continue;
  3366. $oForm->aInputs[$CNF['FIELD_CONTROLS']][$mixedIndex]['attrs'] = bx_replace_markers($aInput['attrs'], [
  3367. 'js_object_view' => $sJsObjectView,
  3368. 'content_id' => $iId
  3369. ]);
  3370. }
  3371. $aFormInitCheckerParams = [$aEvent];
  3372. }
  3373. call_user_func_array([$oForm, 'initChecker'], $aFormInitCheckerParams);
  3374. $bAjaxMode = $oForm->isAjaxMode();
  3375. $bDynamicMode = $bAjaxMode || bx_is_dynamic_request();
  3376. $sCodeAdd = '';
  3377. if($bDynamicMode) {
  3378. $sCodeAdd .= $this->_oTemplate->getAddedJs('post', $bDynamicMode);
  3379. $sCodeAdd .= $this->_oTemplate->getJsCode('post', [], true, $bDynamicMode);
  3380. }
  3381. if($oForm->isSubmittedAndValid()) {
  3382. $aContent = unserialize($aEvent['content']);
  3383. //--- Process Text ---//
  3384. $sText = $oForm->getCleanValue('text');
  3385. $sText = $this->_prepareTextForSave($sText);
  3386. $bText = !empty($sText);
  3387. unset($oForm->aInputs['text']);
  3388. if($bText)
  3389. $aContent['text'] = $sText;
  3390. $aValsToAdd = [
  3391. 'content' => serialize($aContent),
  3392. 'status_admin' => $this->getStatusAdmin()
  3393. ];
  3394. //--- Process Privacy ---//
  3395. if(isset($oForm->aInputs[$CNF['FIELD_OBJECT_PRIVACY_VIEW']])) {
  3396. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  3397. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  3398. if(empty($iObjectPrivacyView))
  3399. $aValsToAdd = array_merge($aValsToAdd, [
  3400. 'object_privacy_view' => $iObjectPrivacyViewDefault
  3401. ]);
  3402. else if($iObjectPrivacyView < 0)
  3403. $aValsToAdd = array_merge($aValsToAdd, [
  3404. 'owner_id' => abs($iObjectPrivacyView)
  3405. ]);
  3406. }
  3407. //--- Process Link ---//
  3408. $aLinkIds = $oForm->getCleanValue($CNF['FIELD_LINK']);
  3409. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  3410. //--- Process Media ---//
  3411. $aPhotoIds = $oForm->getCleanValue($CNF['FIELD_PHOTO']);
  3412. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  3413. $aVideoIds = $oForm->getCleanValue($CNF['FIELD_VIDEO']);
  3414. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  3415. if($bVideoIds && ($mixedCheckResult = $this->_checkMedia($CNF['FIELD_VIDEO'], $iId, $aVideoIds, $iUserId)) !== false) {
  3416. list($bHasImage, $bHasVideo, $bIsVideoProcessed) = $mixedCheckResult;
  3417. if($bHasVideo && !$bIsVideoProcessed)
  3418. $aValsToAdd[$CNF['FIELD_STATUS']] = 'awaiting';
  3419. }
  3420. $aFileIds = $oForm->getCleanValue($CNF['FIELD_FILE']);
  3421. $bFileIds = !empty($aFileIds) && is_array($aFileIds);
  3422. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds && !$bFileIds) {
  3423. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  3424. $oForm->setValid(false);
  3425. return $this->_bIsApi ? ['form' => $oForm->getCodeAPI()] : $this->_prepareResponse([
  3426. 'form' => $sCodeAdd . $oForm->getCode($bDynamicMode),
  3427. 'form_id' => $oForm->id
  3428. ], $bAjaxMode);
  3429. }
  3430. if($oForm->update($iId, $aValsToAdd) === false)
  3431. return $this->_bIsApi ? bx_api_get_msg(_t('_bx_timeline_txt_err_cannot_perform_action')) : ['message' => _t('_bx_timeline_txt_err_cannot_perform_action')];
  3432. $this->isAllowedEdit($aEvent, true);
  3433. //--- Process Meta ---//
  3434. $this->_processMetas($iId, $sText);
  3435. //--- Process Link ---//
  3436. if($bLinkIds)
  3437. foreach($aLinkIds as $iLinkId)
  3438. $this->_oDb->saveLink($iId, $iLinkId);
  3439. //--- Process Media ---//
  3440. $this->_saveMedia($CNF['FIELD_PHOTO'], $iId, $aPhotoIds, $iUserId);
  3441. $this->_saveMedia($CNF['FIELD_VIDEO'], $iId, $aVideoIds, $iUserId);
  3442. $this->_saveMedia($CNF['FIELD_FILE'], $iId, $aFileIds, $iUserId);
  3443. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iId);
  3444. $this->onEdit($iId);
  3445. return $this->_bIsApi ? [ 'id' => $iId ] : [ 'id' => $iId ];
  3446. }
  3447. return $this->_bIsApi ? ['form' => $oForm->getCodeAPI()] : [
  3448. 'id' => $iId,
  3449. 'form' => $sCodeAdd . $oForm->getCode($bDynamicMode),
  3450. 'form_id' => $oForm->id,
  3451. 'eval' => $sJsObjectView . '.onEditPost(oData)'
  3452. ];
  3453. }
  3454. public function getFormPostObject($aParams)
  3455. {
  3456. $CNF = &$this->_oConfig->CNF;
  3457. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  3458. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  3459. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  3460. $oForm->aFormAttrs = bx_replace_markers($oForm->aFormAttrs, [
  3461. 'js_object_post' => $this->_oConfig->getJsObject('post')
  3462. ]);
  3463. $sParamsKey = 'type';
  3464. if(!empty($aParams[$sParamsKey]))
  3465. $oForm->setType($aParams[$sParamsKey]);
  3466. /**
  3467. * Note. 'ajax_mode' parameter isn't checked because
  3468. * timeline post form works as Ajax form by default.
  3469. */
  3470. $sParamsKey = 'visibility_autoselect';
  3471. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  3472. $oForm->setVisibilityAutoselect((bool)$aParams[$sParamsKey]);
  3473. $sKey = 'FIELD_LABELS';
  3474. if(isset($oForm->aInputs[$CNF[$sKey]], $aParams['type']) && empty($oForm->aInputs[$CNF[$sKey]]['value']) && $aParams['type'] == BX_BASE_MOD_NTFS_TYPE_OWNER) {
  3475. $iContextProfileId = !empty($aParams['context_id']) ? abs($aParams['context_id']) : $this->_iOwnerId;
  3476. if(($oContextProfile = BxDolProfile::getInstance($iContextProfileId)) !== false) {
  3477. $sMethod = 'is_fan';
  3478. $sModule = $oContextProfile->getModule();
  3479. if(bx_is_srv($sModule, $sMethod) && bx_srv($sModule, $sMethod, [$iContextProfileId, (int)bx_get_logged_profile_id()])) {
  3480. $aContextInfo = bx_srv($sModule, 'get_content_info_by_profile_id', [$iContextProfileId]);
  3481. if(!empty($aContextInfo['hashtag']))
  3482. $oForm->aInputs[$CNF[$sKey]]['value'] = [$aContextInfo['hashtag']];
  3483. }
  3484. }
  3485. }
  3486. $oForm->init();
  3487. return $oForm;
  3488. }
  3489. public function getCmtsObject($sSystem, $iId)
  3490. {
  3491. if(empty($sSystem) || (int)$iId == 0)
  3492. return false;
  3493. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3494. if(!$oCmts || !$oCmts->isEnabled())
  3495. return false;
  3496. return $oCmts;
  3497. }
  3498. public function getViewObject($sSystem, $iId)
  3499. {
  3500. if(empty($sSystem) || (int)$iId == 0)
  3501. return false;
  3502. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3503. if(!$oView || !$oView->isEnabled())
  3504. return false;
  3505. return $oView;
  3506. }
  3507. public function getVoteObject($sSystem, $iId)
  3508. {
  3509. if(empty($sSystem) || (int)$iId == 0)
  3510. return false;
  3511. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3512. if(!$oVote || !$oVote->isEnabled())
  3513. return false;
  3514. return $oVote;
  3515. }
  3516. public function getReactionObject($sSystem, $iId)
  3517. {
  3518. if(empty($sSystem) || (int)$iId == 0)
  3519. return false;
  3520. $oReaction = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3521. if(!$oReaction || !$oReaction->isEnabled())
  3522. return false;
  3523. return $oReaction;
  3524. }
  3525. public function getScoreObject($sSystem, $iId)
  3526. {
  3527. if(empty($sSystem) || (int)$iId == 0)
  3528. return false;
  3529. $oScore = BxDolScore::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3530. if(!$oScore || !$oScore->isEnabled())
  3531. return false;
  3532. return $oScore;
  3533. }
  3534. public function getReportObject($sSystem, $iId)
  3535. {
  3536. if(empty($sSystem) || (int)$iId == 0)
  3537. return false;
  3538. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3539. if(!$oReport || !$oReport->isEnabled())
  3540. return false;
  3541. return $oReport;
  3542. }
  3543. public function getAttachmentsMenuObject()
  3544. {
  3545. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  3546. }
  3547. public function getManageMenuObject()
  3548. {
  3549. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  3550. }
  3551. public function getCacheItemObject()
  3552. {
  3553. $oCacheEngine = bx_instance('BxDolCache' . $this->_oConfig->getCacheItemEngine());
  3554. if(!$oCacheEngine->isAvailable())
  3555. $oCacheEngine = bx_instance('BxDolCacheFile');
  3556. return $oCacheEngine;
  3557. }
  3558. public function getConnectionMuteObject()
  3559. {
  3560. return BxDolConnection::getObjectInstance($this->_oConfig->getObject('connection_mute'));
  3561. }
  3562. //--- Check permissions methods ---//
  3563. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  3564. {
  3565. if(!$iProfileId)
  3566. $iProfileId = $this->_iProfileId;
  3567. $CNF = &$this->_oConfig->CNF;
  3568. // moderator and owner always have access
  3569. $iOwnerId = (int)$aDataEntry['owner_id'];
  3570. if(!empty($iProfileId) && (abs($iOwnerId) == (int)$iProfileId || $this->isModerator()))
  3571. return CHECK_ACTION_RESULT_ALLOWED;
  3572. // check ACL
  3573. if($iOwnerId != 0 && ($oOwner = BxDolProfile::getInstanceMagic($iOwnerId)) !== false && !($oOwner instanceof BxDolProfileUndefined)) {
  3574. $mixedCheckResult = bx_srv($oOwner->getModule(), 'check_allowed_with_content_for_profile', ['view', $oOwner->getContentId(), $iProfileId]);
  3575. if($mixedCheckResult !== CHECK_ACTION_RESULT_ALLOWED)
  3576. return $mixedCheckResult;
  3577. }
  3578. // check privacy
  3579. if(!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  3580. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  3581. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  3582. return _t('_sys_access_denied_to_private_content');
  3583. }
  3584. // check alert to allow custom checks
  3585. $mixedResult = null;
  3586. /**
  3587. * @hooks
  3588. * @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
  3589. * - $unit_name - equals `system`
  3590. * - $action - equals `check_allowed_view`
  3591. * - $object_id - not used
  3592. * - $sender_id - not used
  3593. * - $extra_params - array of additional params with the following array keys:
  3594. * - `module` - [string] module name
  3595. * - `content_info` - [array] content info array as key&value pairs
  3596. * - `profile_id` - [boolean] or [int] profile id to be checked the availability of the action to
  3597. * - `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
  3598. * @hook @ref hook-system-check_allowed_view
  3599. */
  3600. bx_alert('system', 'check_allowed_view', 0, 0, [
  3601. 'module' => $this->getName(),
  3602. 'content_info' => $aDataEntry,
  3603. 'profile_id' => $iProfileId,
  3604. 'override_result' => &$mixedResult
  3605. ]);
  3606. if($mixedResult !== null)
  3607. return $mixedResult;
  3608. return CHECK_ACTION_RESULT_ALLOWED;
  3609. }
  3610. public function isModerator()
  3611. {
  3612. return $this->isModeratorForProfile((int)$this->getUserId());
  3613. }
  3614. public function isModeratorForProfile($iUserId)
  3615. {
  3616. if($this->checkAllowedEditAnyEntryForProfile(false, $iUserId) === CHECK_ACTION_RESULT_ALLOWED)
  3617. return true;
  3618. if($this->checkAllowedDeleteAnyEntryForProfile(false, $iUserId) === CHECK_ACTION_RESULT_ALLOWED)
  3619. return true;
  3620. return false;
  3621. }
  3622. public function isAllowedPost($bPerform = false)
  3623. {
  3624. if(isAdmin())
  3625. return true;
  3626. $iUserId = $this->getUserId();
  3627. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  3628. if($aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  3629. return $aCheckResult[CHECK_ACTION_MESSAGE];
  3630. if(!empty($this->_iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId)) !== false) {
  3631. if($oProfileOwner->checkAllowedPostInProfile($this->_iOwnerId, $this->getName()) !== CHECK_ACTION_RESULT_ALLOWED)
  3632. return _t('_sys_txt_access_denied');
  3633. /**
  3634. * @hooks
  3635. * @hookdef hook-bx_base_profile-timeline_post '{profile_module_name}', 'timeline_post' - hook to override the result of checking whether 'post in profile' action is allowed or not
  3636. * - $unit_name - profile module name
  3637. * - $action - equals `timeline_post`
  3638. * - $object_id - timeline owner profile id
  3639. * - $sender_id - performer profile id
  3640. * - $extra_params - array of additional params with the following array keys:
  3641. * - `check_result` - [array] by ref, check action result, can be overridden in hook processing.
  3642. * @hook @ref hook-bx_base_profile-timeline_post
  3643. */
  3644. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, [
  3645. 'check_result' => &$aCheckResult
  3646. ]);
  3647. }
  3648. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3649. }
  3650. public function isAllowedView($aEvent, $bPerform = false)
  3651. {
  3652. $CNF = $this->_oConfig->CNF;
  3653. if((int)$aEvent[$CNF['FIELD_OWNER_ID']] == 0)
  3654. return true;
  3655. $oProfileOwner = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']]);
  3656. if($oProfileOwner && $oProfileOwner->checkAllowedProfileView() !== CHECK_ACTION_RESULT_ALLOWED)
  3657. return false;
  3658. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  3659. if(!$oPrivacy)
  3660. return true;
  3661. $oPrivacy->setTableFieldAuthor($this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id');
  3662. return $oPrivacy->check($aEvent[$CNF['FIELD_ID']]);
  3663. }
  3664. public function isAllowedEdit($aEvent, $bPerform = false)
  3665. {
  3666. if(!isLogged())
  3667. return false;
  3668. //--- System posts and Reposts cannot be edited at all.
  3669. if(!$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) || $aEvent['type'] == $this->_oConfig->getPrefix('common_post') . 'repost')
  3670. return false;
  3671. if(isAdmin())
  3672. return true;
  3673. $iUserId = (int)$this->getUserId();
  3674. $iOwnerId = (int)$aEvent['owner_id'];
  3675. $iObjectId = abs((int)$aEvent['object_id']);
  3676. if($iObjectId == $iUserId && $this->_oConfig->isAllowEdit())
  3677. return true;
  3678. $aCheckResult = checkActionModule($iUserId, 'edit', $this->getName(), $bPerform);
  3679. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false) {
  3680. if(BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'edit_any')) === CHECK_ACTION_RESULT_ALLOWED)
  3681. return true;
  3682. /**
  3683. * @hooks
  3684. * @hookdef hook-bx_base_profile-timeline_edit '{profile_module_name}', 'timeline_edit' - hook to override the result of checking whether 'edit' action is allowed or not
  3685. * It's equivalent to @ref hook-bx_base_profile-timeline_post
  3686. * @hook @ref hook-bx_base_profile-timeline_edit
  3687. */
  3688. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_edit', $oProfileOwner->id(), $iUserId, [
  3689. 'check_result' => &$aCheckResult
  3690. ]);
  3691. }
  3692. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3693. }
  3694. public function isAllowedDelete($aEvent, $bPerform = false)
  3695. {
  3696. if(!isLogged())
  3697. return false;
  3698. if(isAdmin())
  3699. return true;
  3700. $iUserId = (int)$this->getUserId();
  3701. $iOwnerId = (int)$aEvent['owner_id'];
  3702. $iObjectId = abs((int)$aEvent['object_id']);
  3703. if((($iOwnerId == $iUserId && $this->_oConfig->isAllowDelete()) || ($this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)))
  3704. return true;
  3705. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  3706. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false) {
  3707. if(BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'delete_any')) === CHECK_ACTION_RESULT_ALLOWED)
  3708. return true;
  3709. /**
  3710. * @hooks
  3711. * @hookdef hook-bx_base_profile-timeline_delete '{profile_module_name}', 'timeline_delete' - hook to override the result of checking whether 'delete' action is allowed or not
  3712. * It's equivalent to @ref hook-bx_base_profile-timeline_post
  3713. * @hook @ref hook-bx_base_profile-timeline_delete
  3714. */
  3715. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, [
  3716. 'check_result' => &$aCheckResult
  3717. ]);
  3718. }
  3719. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3720. }
  3721. public function isAllowedComment($aEvent, $bPerform = false)
  3722. {
  3723. $mixedComments = $this->getCommentsData($aEvent['comments']);
  3724. if($mixedComments === false)
  3725. return false;
  3726. list($sSystem, $iObjectId, $iCount) = $mixedComments;
  3727. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  3728. if($oCmts->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED || ($iCount == 0 && !$oCmts->isPostAllowed()))
  3729. return false;
  3730. $oCmts->addCssJs();
  3731. return true;
  3732. }
  3733. public function isAllowedViewCounter($aEvent, $bPerform = false)
  3734. {
  3735. $mixedViews = $this->getViewsData($aEvent['views']);
  3736. if($mixedViews === false)
  3737. return false;
  3738. list($sSystem, $iObjectId) = $mixedViews;
  3739. $oView = $this->getViewObject($sSystem, $iObjectId);
  3740. if(!$oView->isAllowedViewView($bPerform))
  3741. return false;
  3742. $bResult = true;
  3743. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3744. /**
  3745. * @hooks
  3746. * @hookdef hook-bx_base_profile-timeline_view_counter '{profile_module_name}', 'timeline_view_counter' - hook to override the result of checking whether 'view counter' action is allowed or not
  3747. * - $unit_name - profile module name
  3748. * - $action - equals `timeline_view_counter`
  3749. * - $object_id - timeline owner profile id
  3750. * - $sender_id - performer profile id
  3751. * - $extra_params - array of additional params with the following array keys:
  3752. * - `result` - [boolean] by ref, check action result, can be overridden in hook processing.
  3753. * @hook @ref hook-bx_base_profile-timeline_view_counter
  3754. */
  3755. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), [
  3756. 'result' => &$bResult
  3757. ]);
  3758. return $bResult;
  3759. }
  3760. public function isAllowedVote($aEvent, $bPerform = false)
  3761. {
  3762. $mixedVotes = $this->getVotesData($aEvent['votes']);
  3763. if($mixedVotes === false)
  3764. return false;
  3765. list($sSystem, $iObjectId) = $mixedVotes;
  3766. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  3767. if(!$oVote->isAllowedVote($bPerform))
  3768. return false;
  3769. $bResult = true;
  3770. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3771. /**
  3772. * @hooks
  3773. * @hookdef hook-bx_base_profile-timeline_vote '{profile_module_name}', 'timeline_vote' - hook to override the result of checking whether 'vote' action is allowed or not
  3774. * It's equivalent to @ref hook-bx_base_profile-timeline_view_counter
  3775. * @hook @ref hook-bx_base_profile-timeline_vote
  3776. */
  3777. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), [
  3778. 'result' => &$bResult
  3779. ]);
  3780. return $bResult;
  3781. }
  3782. public function isAllowedVoteView($aEvent, $bPerform = false)
  3783. {
  3784. $mixedVotes = $this->getVotesData($aEvent['votes']);
  3785. if($mixedVotes === false)
  3786. return false;
  3787. list($sSystem, $iObjectId) = $mixedVotes;
  3788. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  3789. if(!$oVote->isAllowedVoteView($bPerform))
  3790. return false;
  3791. $bResult = true;
  3792. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3793. /**
  3794. * @hooks
  3795. * @hookdef hook-bx_base_profile-timeline_vote_view '{profile_module_name}', 'timeline_vote_view' - hook to override the result of checking whether 'vote' action is allowed or not
  3796. * It's equivalent to @ref hook-bx_base_profile-timeline_view_counter
  3797. * @hook @ref hook-bx_base_profile-timeline_vote_view
  3798. */
  3799. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote_view', $oProfileOwner->id(), (int)$this->getUserId(), [
  3800. 'result' => &$bResult
  3801. ]);
  3802. return $bResult;
  3803. }
  3804. public function isAllowedReaction($aEvent, $bPerform = false)
  3805. {
  3806. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  3807. if($mixedReactions === false)
  3808. return false;
  3809. list($sSystem, $iObjectId) = $mixedReactions;
  3810. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  3811. if(!$oReaction->isAllowedVote($bPerform))
  3812. return false;
  3813. $bResult = true;
  3814. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3815. /**
  3816. * @hooks
  3817. * @hookdef hook-bx_base_profile-timeline_reaction '{profile_module_name}', 'timeline_reaction' - hook to override the result of checking whether 'give reaction vote' action is allowed or not
  3818. * It's equivalent to @ref hook-bx_base_profile-timeline_view_counter
  3819. * @hook @ref hook-bx_base_profile-timeline_reaction
  3820. */
  3821. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction', $oProfileOwner->id(), (int)$this->getUserId(), [
  3822. 'result' => &$bResult
  3823. ]);
  3824. return $bResult;
  3825. }
  3826. public function isAllowedReactionView($aEvent, $bPerform = false)
  3827. {
  3828. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  3829. if($mixedReactions === false)
  3830. return false;
  3831. list($sSystem, $iObjectId) = $mixedReactions;
  3832. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  3833. if(!$oReaction->isAllowedVoteView($bPerform))
  3834. return false;
  3835. $bResult = true;
  3836. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3837. /**
  3838. * @hooks
  3839. * @hookdef hook-bx_base_profile-timeline_reaction_view '{profile_module_name}', 'timeline_reaction_view' - hook to override the result of checking whether 'view reactions' action is allowed or not
  3840. * It's equivalent to @ref hook-bx_base_profile-timeline_view_counter
  3841. * @hook @ref hook-bx_base_profile-timeline_reaction_view
  3842. */
  3843. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction_view', $oProfileOwner->id(), (int)$this->getUserId(), [
  3844. 'result' => &$bResult
  3845. ]);
  3846. return $bResult;
  3847. }
  3848. public function isAllowedScore($aEvent, $bPerform = false)
  3849. {
  3850. $mixedScores = $this->getScoresData($aEvent['scores']);
  3851. if($mixedScores === false)
  3852. return false;
  3853. list($sSystem, $iObjectId) = $mixedScores;
  3854. $oScore = $this->getScoreObject($sSystem, $iObjectId);
  3855. if(!$oScore->isAllowedVote($bPerform))
  3856. return false;
  3857. $bResult = true;
  3858. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3859. /**
  3860. * @hooks
  3861. * @hookdef hook-bx_base_profile-timeline_score '{profile_module_name}', 'timeline_score' - hook to override the result of checking whether 'give score vote' action is allowed or not
  3862. * It's equivalent to @ref hook-bx_base_profile-timeline_view_counter
  3863. * @hook @ref hook-bx_base_profile-timeline_score
  3864. */
  3865. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_score', $oProfileOwner->id(), (int)$this->getUserId(), [
  3866. 'result' => &$bResult
  3867. ]);
  3868. return $bResult;
  3869. }
  3870. public function isAllowedReport($aEvent, $bPerform = false)
  3871. {
  3872. $mixedReports = $this->getReportsData($aEvent['reports']);
  3873. if($mixedReports === false)
  3874. return false;
  3875. list($sSystem, $iObjectId) = $mixedReports;
  3876. $oReport = $this->getReportObject($sSystem, $iObjectId);
  3877. if(!$oReport->isAllowedReport($bPerform))
  3878. return false;
  3879. $bResult = true;
  3880. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3881. /**
  3882. * @hooks
  3883. * @hookdef hook-bx_base_profile-timeline_report '{profile_module_name}', 'timeline_report' - hook to override the result of checking whether 'give score vote' action is allowed or not
  3884. * It's equivalent to @ref hook-bx_base_profile-timeline_view_counter
  3885. * @hook @ref hook-bx_base_profile-timeline_report
  3886. */
  3887. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), [
  3888. 'result' => &$bResult
  3889. ]);
  3890. return $bResult;
  3891. }
  3892. public function isAllowedRepost($aEvent, $bPerform = false)
  3893. {
  3894. $mixedResult = $this->_isAllowedRepost($aEvent, $bPerform);
  3895. /**
  3896. * @hooks
  3897. * @hookdef hook-bx_timeline-is_allowed_repost 'bx_timeline', 'is_allowed_repost' - hook to override the result of checking whether 'repost' action is allowed or not
  3898. * - $unit_name - equals `bx_timeline`
  3899. * - $action - equals `is_allowed_repost`
  3900. * - $object_id - not used
  3901. * - $sender_id - not used
  3902. * - $extra_params - array of additional params with the following array keys:
  3903. * - `content_info` - [array] content info array as key&value pairs
  3904. * - `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
  3905. * @hook @ref hook-bx_timeline-is_allowed_repost
  3906. */
  3907. bx_alert($this->getName(), 'is_allowed_repost', 0, 0, [
  3908. 'content_info' => $aEvent,
  3909. 'override_result' => &$mixedResult
  3910. ]);
  3911. return $mixedResult;
  3912. }
  3913. public function isAllowedSend($aEvent, $bPerform = false)
  3914. {
  3915. if(!$this->_oDb->isEnabledByName('bx_convos'))
  3916. return false;
  3917. if(isAdmin())
  3918. return true;
  3919. $iUserId = (int)$this->getUserId();
  3920. if($iUserId == 0)
  3921. return false;
  3922. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  3923. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3924. /**
  3925. * @hooks
  3926. * @hookdef hook-bx_base_profile-timeline_send '{profile_module_name}', 'timeline_send' - hook to override the result of checking whether 'send' action is allowed or not
  3927. * It's equivalent to @ref hook-bx_base_profile-timeline_post
  3928. * @hook @ref hook-bx_base_profile-timeline_send
  3929. */
  3930. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, [
  3931. 'check_result' => &$aCheckResult
  3932. ]);
  3933. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3934. }
  3935. public function isAllowedMute($aEvent, $bPerform = false)
  3936. {
  3937. $CNF = &$this->_oConfig->CNF;
  3938. if(!empty($aEvent[$CNF['FIELD_OWNER_ID']]) && $aEvent[$CNF['FIELD_OWNER_ID']] != $this->_iProfileId)
  3939. return false;
  3940. $iAuthor = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  3941. if(!$this->_oConfig->isSystem($aEvent['type'], $aEvent['action']))
  3942. $iAuthor = (int)$aEvent[$CNF['FIELD_OBJECT_ID']];
  3943. if($this->_iProfileId == $iAuthor || $this->getConnectionMuteObject()->isConnected($this->_iProfileId, $iAuthor))
  3944. return false;
  3945. return $this->_isAllowedMute($bPerform);
  3946. }
  3947. public function isAllowedUnmute($iAuthor, $bPerform = false)
  3948. {
  3949. if(!$this->getConnectionMuteObject()->isConnected($this->_iProfileId, $iAuthor))
  3950. return false;
  3951. return $this->_isAllowedMute($bPerform);
  3952. }
  3953. /**
  3954. * Pin - "Pin here" - pin the post on Profile Timeline for profile owner.
  3955. * Can be done by profile owner for himself or by admin for profile owner to see.
  3956. * @param type $aEvent
  3957. * @param type $bPerform
  3958. * @return boolean
  3959. */
  3960. public function isAllowedPin($aEvent, $bPerform = false)
  3961. {
  3962. if((int)$aEvent['pinned'] != 0)
  3963. return false;
  3964. return $this->_isAllowedPin($aEvent, $bPerform);
  3965. }
  3966. public function isAllowedUnpin($aEvent, $bPerform = false)
  3967. {
  3968. if((int)$aEvent['pinned'] == 0)
  3969. return false;
  3970. return $this->_isAllowedPin($aEvent, $bPerform);
  3971. }
  3972. /**
  3973. * Stick - "Pin for All" - pin the post on Public Timeline for everybody to see.
  3974. * Is available for Administrators/Moderators only.
  3975. * @param type $aEvent
  3976. * @param type $bPerform
  3977. * @return boolean
  3978. */
  3979. public function isAllowedStick($aEvent, $bPerform = false)
  3980. {
  3981. if((int)$aEvent['sticked'] != 0)
  3982. return false;
  3983. return $this->_isAllowedStick($aEvent, $bPerform);
  3984. }
  3985. public function isAllowedUnstick($aEvent, $bPerform = false)
  3986. {
  3987. if((int)$aEvent['sticked'] == 0)
  3988. return false;
  3989. return $this->_isAllowedStick($aEvent, $bPerform);
  3990. }
  3991. public function isAllowedPromote($aEvent, $bPerform = false)
  3992. {
  3993. if((int)$aEvent['promoted'] != 0)
  3994. return false;
  3995. return $this->_isAllowedPromote($aEvent, $bPerform);
  3996. }
  3997. public function isAllowedUnpromote($aEvent, $bPerform = false)
  3998. {
  3999. if((int)$aEvent['promoted'] == 0)
  4000. return false;
  4001. return $this->_isAllowedPromote($aEvent, $bPerform);
  4002. }
  4003. public function isAllowedNotes($aEvent, $bPerform = false)
  4004. {
  4005. return $this->isModerator();
  4006. }
  4007. public function isAllowedMore($aEvent, $bPerform = false)
  4008. {
  4009. $oMoreMenu = $this->getManageMenuObject();
  4010. if(!$oMoreMenu)
  4011. return false;
  4012. $oMoreMenu->setEvent($aEvent);
  4013. return $oMoreMenu->isVisible();
  4014. }
  4015. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  4016. {
  4017. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  4018. return _t('_sys_txt_access_denied');
  4019. return CHECK_ACTION_RESULT_ALLOWED;
  4020. }
  4021. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  4022. {
  4023. if(($mixedResult = $this->isAllowedDelete($aDataEntry, $isPerformAction)) !== true)
  4024. return is_string($mixedResult) ? $mixedResult : _t('_sys_txt_access_denied');
  4025. return CHECK_ACTION_RESULT_ALLOWED;
  4026. }
  4027. /**
  4028. * Checks if it's allowed to view a comment by checking the availability to view the content which was commented.
  4029. * Note. Don't check the related comments object for view action accessibility because this method is called from there.
  4030. */
  4031. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  4032. {
  4033. $CNF = $this->_oConfig->CNF;
  4034. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  4035. if($iOwner == 0) //--- in case of Public Timeline.
  4036. return CHECK_ACTION_RESULT_ALLOWED;
  4037. $oOwner = BxDolProfile::getInstance($iOwner);
  4038. if(!$oOwner) //--- in case of non-existed Timeline owner.
  4039. return _t('_sys_txt_access_denied');
  4040. $mixedResult = $oOwner->checkAllowedProfileView();
  4041. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  4042. return $mixedResult;
  4043. return $this->checkAllowedView($aContentInfo, $isPerformAction);
  4044. }
  4045. /**
  4046. * Checks if it's allowed to post a comment by checking the availability to post anything in the context.
  4047. * Note. Don't check the related comments object for post action accessibility because this method is called from there.
  4048. */
  4049. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  4050. {
  4051. $CNF = $this->_oConfig->CNF;
  4052. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  4053. if($iOwner == 0) //--- in case of Public Timeline.
  4054. return CHECK_ACTION_RESULT_ALLOWED;
  4055. $oOwner = BxDolProfile::getInstance($iOwner);
  4056. if(!$oOwner) //--- in case of non-existed Timeline owner.
  4057. return _t('_sys_txt_access_denied');
  4058. /*
  4059. * Disabled in accordance with #4238 ticket.
  4060. *
  4061. if(($mixedResult = $oOwner->checkAllowedPostInProfile()) !== CHECK_ACTION_RESULT_ALLOWED)
  4062. return $mixedResult;
  4063. */
  4064. return CHECK_ACTION_RESULT_ALLOWED;
  4065. }
  4066. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  4067. {
  4068. if(!$iProfileId)
  4069. $iProfileId = $this->_iProfileId;
  4070. $aCheck = checkActionModule($iProfileId, 'edit', $this->getName(), $isPerformAction);
  4071. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  4072. return CHECK_ACTION_RESULT_ALLOWED;
  4073. return _t('_sys_txt_access_denied');
  4074. }
  4075. public function checkAllowedDeleteAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  4076. {
  4077. if(!$iProfileId)
  4078. $iProfileId = $this->_iProfileId;
  4079. $aCheck = checkActionModule($iProfileId, 'delete', $this->getName(), $isPerformAction);
  4080. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  4081. return CHECK_ACTION_RESULT_ALLOWED;
  4082. return _t('_sys_txt_access_denied');
  4083. }
  4084. public function onPost($iContentId)
  4085. {
  4086. $CNF = &$this->_oConfig->CNF;
  4087. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iContentId]);
  4088. if($this->_oConfig->isSystem($aEvent[$CNF['FIELD_TYPE']], $aEvent[$CNF['FIELD_ACTION']])) {
  4089. //--- Request event's data from content module and update it in the Timeline DB.
  4090. $this->_oTemplate->getDataCached($aEvent);
  4091. $sPostType = 'system';
  4092. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  4093. }
  4094. else {
  4095. $sPostType = 'common';
  4096. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  4097. }
  4098. $this->rebuildSlice();
  4099. $sAction = ($aEvent[$CNF['FIELD_STATUS']] == BX_TIMELINE_STATUS_AWAITING ? 'defer' : 'post') . '_' . $sPostType;
  4100. /**
  4101. * @hooks
  4102. * @hookdef hook-bx_timeline-post_system 'bx_timeline', 'post_system' - hook after system post was added and published
  4103. * - $unit_name - equals `bx_timeline`
  4104. * - $action - equals `post_system`
  4105. * - $object_id - content id
  4106. * - $sender_id - content author profile id
  4107. * - $extra_params - array of additional params with the following array keys:
  4108. * - `source` - [string] unique source
  4109. * - `owner_id` - [int] owner profile id
  4110. * - `object_author_id` - [int] object author profile id
  4111. * - `privacy_view` - [int] or [string] privacy for view content action, @see BxDolPrivacy
  4112. * @hook @ref hook-bx_timeline-post_system
  4113. */
  4114. /**
  4115. * @hooks
  4116. * @hookdef hook-bx_timeline-post_common 'bx_timeline', 'post_common' - hook after common post was added and published
  4117. * It's equivalent to @ref hook-bx_timeline-post_system
  4118. * @hook @ref hook-bx_timeline-post_common
  4119. */
  4120. /**
  4121. * @hooks
  4122. * @hookdef hook-bx_timeline-defer_system 'bx_timeline', 'defer_system' - hook after system post was added
  4123. * It's equivalent to @ref hook-bx_timeline-post_system
  4124. * @hook @ref hook-bx_timeline-defer_system
  4125. */
  4126. /**
  4127. * @hooks
  4128. * @hookdef hook-bx_timeline-defer_common 'bx_timeline', 'defer_common' - hook after common post was added
  4129. * It's equivalent to @ref hook-bx_timeline-post_system
  4130. * @hook @ref hook-bx_timeline-defer_common
  4131. */
  4132. bx_alert($this->_oConfig->getObject('alert'), $sAction, $iContentId, $iSenderId, [
  4133. 'source' => $aEvent[$CNF['FIELD_SOURCE']],
  4134. 'owner_id' => $aEvent[$CNF['FIELD_OWNER_ID']],
  4135. 'object_author_id' => $iObjectAuthorId,
  4136. 'privacy_view' => $aEvent[$CNF['FIELD_OBJECT_PRIVACY_VIEW']],
  4137. ]);
  4138. /**
  4139. * Note. 0 is used as $iContentId to allow to subscribe on all events at once.
  4140. */
  4141. if(($oSockets = BxDolSockets::getInstance()) && $oSockets->isEnabled())
  4142. $oSockets->sendEvent($this->_oConfig->getSocketName(), 0, 'added', json_encode([
  4143. 'id' => $aEvent[$CNF['FIELD_ID']],
  4144. 'author_id' => $aEvent[$CNF['FIELD_OBJECT_OWNER_ID']],
  4145. 'peformer_id' => $iSenderId
  4146. ]));
  4147. }
  4148. public function onEdit($iContentId)
  4149. {
  4150. $CNF = &$this->_oConfig->CNF;
  4151. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iContentId]);
  4152. $iSenderId = $this->_oConfig->isSystem($aEvent[$CNF['FIELD_TYPE']], $aEvent[$CNF['FIELD_ACTION']]) ? $aEvent['owner_id'] : $aEvent['object_id'];
  4153. if(($oSockets = BxDolSockets::getInstance()) && $oSockets->isEnabled())
  4154. $oSockets->sendEvent($this->_oConfig->getSocketName(), 0, 'edited', json_encode([
  4155. 'id' => $aEvent[$CNF['FIELD_ID']],
  4156. 'author_id' => $aEvent[$CNF['FIELD_OBJECT_OWNER_ID']],
  4157. 'peformer_id' => $iSenderId
  4158. ]));
  4159. }
  4160. public function onPublished($iContentId)
  4161. {
  4162. //--- Clear Item cache
  4163. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  4164. $this->onPost($iContentId);
  4165. }
  4166. public function onFailed($iContentId)
  4167. {
  4168. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  4169. //--- Clear Item cache
  4170. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  4171. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  4172. //--- Request event's data from content module and update it in the Timeline DB.
  4173. $this->_oTemplate->getDataCached($aEvent);
  4174. $sPostType = 'system';
  4175. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  4176. }
  4177. else {
  4178. $sPostType = 'common';
  4179. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  4180. }
  4181. /**
  4182. * @hooks
  4183. * @hookdef hook-bx_timeline-fail_system 'bx_timeline', 'fail_system' - hook after system post failed to publish
  4184. * It's equivalent to @ref hook-bx_timeline-post_system
  4185. * @hook @ref hook-bx_timeline-fail_system
  4186. */
  4187. /**
  4188. * @hooks
  4189. * @hookdef hook-bx_timeline-fail_common 'bx_timeline', 'fail_common' - hook after common post failed to publish
  4190. * It's equivalent to @ref hook-bx_timeline-post_system
  4191. * @hook @ref hook-bx_timeline-fail_common
  4192. */
  4193. bx_alert($this->_oConfig->getObject('alert'), 'fail_' . $sPostType, $iContentId, $iSenderId, [
  4194. 'source' => $this->_oConfig->getName() . '_' . $iContentId,
  4195. 'owner_id' => $aEvent['owner_id'],
  4196. 'object_author_id' => $iObjectAuthorId,
  4197. 'privacy_view' => $aEvent['object_privacy_view'],
  4198. ]);
  4199. }
  4200. public function onRepost($iContentId, $aReposted = array())
  4201. {
  4202. $CNF = &$this->_oConfig->CNF;
  4203. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  4204. if(empty($aReposted)) {
  4205. $aContent = unserialize($aEvent['content']);
  4206. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  4207. if(empty($aReposted) || !is_array($aReposted))
  4208. return;
  4209. }
  4210. $iUserId = (int)$aEvent[$CNF['FIELD_OBJECT_OWNER_ID']];
  4211. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  4212. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  4213. $this->rebuildSlice();
  4214. /**
  4215. * @hooks
  4216. * @hookdef hook-bx_timeline-repost 'bx_timeline', 'repost' - hook after repost was added (published)
  4217. * - $unit_name - equals `bx_timeline`
  4218. * - $action - equals `repost`
  4219. * - $object_id - reposted content id
  4220. * - $sender_id - performer profile id
  4221. * - $extra_params - array of additional params with the following array keys:
  4222. * - `repost_id` - [int] repost id
  4223. * - `object_author_id` - [int] reposted content author profile id
  4224. * - `privacy_view` - [int] or [string] privacy for view content action, @see BxDolPrivacy
  4225. * @hook @ref hook-bx_timeline-repost
  4226. */
  4227. bx_alert($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, [
  4228. 'repost_id' => $iContentId,
  4229. 'object_author_id' => $aReposted['owner_id'],
  4230. 'privacy_view' => $aEvent['object_privacy_view'],
  4231. ]);
  4232. }
  4233. public function onHide($aEvent)
  4234. {
  4235. $CNF = &$this->_oConfig->CNF;
  4236. $iUserId = $this->getUserId();
  4237. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  4238. //--- Update parent event when repost event was deactivated.
  4239. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  4240. if($bRepost) {
  4241. $this->_oDb->updateRepostTrack(['active' => 0], ['event_id' => $aEvent[$CNF['FIELD_ID']]]);
  4242. $aContent = unserialize($aEvent['content']);
  4243. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  4244. if(!empty($aReposted) && is_array($aReposted))
  4245. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  4246. }
  4247. //--- Find and hide repost events when parent event was deactivated.
  4248. $aRepostEvents = $this->_oDb->getEvents(['browse' => 'reposted_by_track', 'value' => $aEvent[$CNF['FIELD_ID']]]);
  4249. foreach($aRepostEvents as $aRepostEvent) {
  4250. if((int)$this->_oDb->updateEvent(['active' => 0], ['id' => (int)$aRepostEvent[$CNF['FIELD_ID']]]) == 0)
  4251. continue;
  4252. $this->_oDb->updateRepostTrack(['active' => 0], ['event_id' => $aRepostEvent[$CNF['FIELD_ID']]]);
  4253. /**
  4254. * @hooks
  4255. * @hookdef hook-bx_timeline-hide_repost 'bx_timeline', 'hide_repost' - hook after repost was hidden
  4256. * - $unit_name - equals `bx_timeline`
  4257. * - $action - equals `hide_repost`
  4258. * - $object_id - content id
  4259. * - $sender_id - performer profile id
  4260. * - $extra_params - array of additional params with the following array keys:
  4261. * - `repost_id` - [int] repost id
  4262. * @hook @ref hook-bx_timeline-hide_repost
  4263. */
  4264. bx_alert($this->_oConfig->getObject('alert'), 'hide_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, [
  4265. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  4266. ]);
  4267. }
  4268. //--- Delete associated meta for Common events.
  4269. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  4270. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  4271. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  4272. }
  4273. //--- Delete item cache.
  4274. $this->deleteCacheItem($aEvent[$CNF['FIELD_ID']]);
  4275. //--- Rebuild cache table.
  4276. $this->rebuildSlice();
  4277. //--- Event -> Hide for Alerts Engine ---//
  4278. if($bRepost)
  4279. /**
  4280. * @hooks
  4281. * @hookdef hook-bx_timeline-hide_repost 'bx_timeline', 'hide_repost' - hook after repost was hidden
  4282. * - $unit_name - equals `bx_timeline`
  4283. * - $action - equals `hide_repost`
  4284. * - $object_id - content id
  4285. * - $sender_id - performer profile id
  4286. * - $extra_params - array of additional params with the following array keys:
  4287. * - `repost_id` - [int] repost id
  4288. * @hook @ref hook-bx_timeline-hide_repost
  4289. */
  4290. bx_alert($this->_oConfig->getObject('alert'), 'hide_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, [
  4291. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  4292. ]);
  4293. else
  4294. /**
  4295. * @hooks
  4296. * @hookdef hook-bx_timeline-hide 'bx_timeline', 'hide' - hook after post (event) was hidden
  4297. * - $unit_name - equals `bx_timeline`
  4298. * - $action - equals `hide`
  4299. * - $object_id - content id
  4300. * - $sender_id - performer profile id
  4301. * - $extra_params - not used
  4302. * @hook @ref hook-bx_timeline-hide
  4303. */
  4304. bx_alert($this->_oConfig->getObject('alert'), 'hide', $aEvent[$CNF['FIELD_ID']], $iUserId);
  4305. }
  4306. public function onUnhide($aEvent)
  4307. {
  4308. $CNF = &$this->_oConfig->CNF;
  4309. $iUserId = $this->getUserId();
  4310. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  4311. //--- Update parent event when repost event was activated back.
  4312. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  4313. if($bRepost) {
  4314. $this->_oDb->updateRepostTrack(['active' => 1], ['event_id' => $aEvent[$CNF['FIELD_ID']]]);
  4315. $aContent = unserialize($aEvent['content']);
  4316. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  4317. if(!empty($aReposted) && is_array($aReposted))
  4318. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], 1);
  4319. }
  4320. //--- Find and hide repost events when parent event was activated back.
  4321. $aRepostEvents = $this->_oDb->getEvents(['browse' => 'reposted_by_track', 'value' => $aEvent[$CNF['FIELD_ID']]]);
  4322. foreach($aRepostEvents as $aRepostEvent) {
  4323. if((int)$this->_oDb->updateEvent(['active' => 1], ['id' => (int)$aRepostEvent[$CNF['FIELD_ID']]]) == 0)
  4324. continue;
  4325. $this->_oDb->updateRepostTrack(['active' => 1], ['event_id' => $aRepostEvent[$CNF['FIELD_ID']]]);
  4326. /**
  4327. * @hooks
  4328. * @hookdef hook-bx_timeline-unhide_repost 'bx_timeline', 'unhide_repost' - hook after repost was unhidden
  4329. * It's equivalent to @ref hook-bx_timeline-hide_repost
  4330. * @hook @ref hook-bx_timeline-unhide_repost
  4331. */
  4332. bx_alert($this->_oConfig->getObject('alert'), 'unhide_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, [
  4333. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  4334. ]);
  4335. }
  4336. //--- Process meta for Common events.
  4337. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  4338. $aContent = unserialize($aEvent['content']);
  4339. $this->_processMetas($aEvent[$CNF['FIELD_ID']], $aContent['text']);
  4340. }
  4341. //--- Rebuild cache table.
  4342. $this->rebuildSlice();
  4343. if($bRepost)
  4344. /**
  4345. * @hooks
  4346. * @hookdef hook-bx_timeline-unhide_repost 'bx_timeline', 'unhide_repost' - hook after repost was unhidden
  4347. * It's equivalent to @ref hook-bx_timeline-hide_repost
  4348. * @hook @ref hook-bx_timeline-unhide_repost
  4349. */
  4350. bx_alert($this->_oConfig->getObject('alert'), 'unhide_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, [
  4351. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  4352. ]);
  4353. else
  4354. /**
  4355. * @hooks
  4356. * @hookdef hook-bx_timeline-unhide 'bx_timeline', 'unhide' - hook after post (event) was unhidden
  4357. * It's equivalent to @ref hook-bx_timeline-hide
  4358. * @hook @ref hook-bx_timeline-unhide
  4359. */
  4360. bx_alert($this->_oConfig->getObject('alert'), 'unhide', $aEvent[$CNF['FIELD_ID']], $iUserId);
  4361. }
  4362. public function onDelete($aEvent)
  4363. {
  4364. $CNF = &$this->_oConfig->CNF;
  4365. $iUserId = $this->getUserId();
  4366. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  4367. $sCommonPostComment = $this->_oConfig->getObject('comment');
  4368. //--- Delete related flags.
  4369. $this->_oDb->deleteEventFlags($aEvent[$CNF['FIELD_ID']]);
  4370. //--- Delete comments for Common posts.
  4371. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  4372. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent[$CNF['FIELD_ID']]);
  4373. if($oComments !== false)
  4374. $oComments->onObjectDelete($aEvent[$CNF['FIELD_ID']]);
  4375. }
  4376. //--- Delete attached photos, videos and links when common event was deleted.
  4377. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  4378. $this->_deleteMedia($CNF['FIELD_PHOTO'], $aEvent[$CNF['FIELD_ID']]);
  4379. $this->_deleteMedia($CNF['FIELD_VIDEO'], $aEvent[$CNF['FIELD_ID']]);
  4380. $this->_deleteMedia($CNF['FIELD_FILE'], $aEvent[$CNF['FIELD_ID']]);
  4381. $this->_deleteLinks($aEvent[$CNF['FIELD_ID']]);
  4382. }
  4383. //--- Update parent event when repost event was deleted.
  4384. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  4385. if($bRepost) {
  4386. $this->_oDb->deleteRepostTrack($aEvent[$CNF['FIELD_ID']]);
  4387. $aContent = unserialize($aEvent['content']);
  4388. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  4389. if(!empty($aReposted) && is_array($aReposted))
  4390. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  4391. }
  4392. //--- Find and delete repost events when parent event was deleted.
  4393. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_track', 'value' => $aEvent[$CNF['FIELD_ID']]));
  4394. foreach($aRepostEvents as $aRepostEvent) {
  4395. if((int)$this->_oDb->deleteEvent(array('id' => (int)$aRepostEvent[$CNF['FIELD_ID']])) == 0)
  4396. continue;
  4397. $this->_oDb->deleteRepostTrack($aRepostEvent[$CNF['FIELD_ID']]);
  4398. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent[$CNF['FIELD_ID']]);
  4399. if($oComments !== false)
  4400. $oComments->onObjectDelete($aRepostEvent[$CNF['FIELD_ID']]);
  4401. /**
  4402. * @hooks
  4403. * @hookdef hook-bx_timeline-delete_repost 'bx_timeline', 'delete_repost' - hook after repost was deleted
  4404. * It's equivalent to @ref hook-bx_timeline-hide_repost
  4405. * @hook @ref hook-bx_timeline-delete_repost
  4406. */
  4407. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, [
  4408. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  4409. ]);
  4410. }
  4411. //--- Delete associated meta for Common events.
  4412. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  4413. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  4414. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  4415. }
  4416. //--- Delete item cache.
  4417. $this->deleteCacheItem($aEvent[$CNF['FIELD_ID']]);
  4418. //--- Rebuild cache table.
  4419. $this->rebuildSlice();
  4420. if($bRepost)
  4421. /**
  4422. * @hooks
  4423. * @hookdef hook-bx_timeline-delete_repost 'bx_timeline', 'delete_repost' - hook after repost was deleted
  4424. * It's equivalent to @ref hook-bx_timeline-hide_repost
  4425. * @hook @ref hook-bx_timeline-delete_repost
  4426. */
  4427. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, [
  4428. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  4429. ]);
  4430. else
  4431. /**
  4432. * @hooks
  4433. * @hookdef hook-bx_timeline-delete 'bx_timeline', 'delete' - hook after post (event) was deleted
  4434. * It's equivalent to @ref hook-bx_timeline-hide
  4435. * @hook @ref hook-bx_timeline-delete
  4436. */
  4437. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent[$CNF['FIELD_ID']], $iUserId);
  4438. //--- Event -> Delete for Alerts Engine ---//
  4439. if(($oSockets = BxDolSockets::getInstance()) && $oSockets->isEnabled())
  4440. $oSockets->sendEvent($this->_oConfig->getSocketName(), 0, 'deleted', json_encode([
  4441. 'id' => $aEvent[$CNF['FIELD_ID']],
  4442. 'author_id' => $aEvent[$CNF['FIELD_OBJECT_OWNER_ID']],
  4443. 'peformer_id' => $iUserId
  4444. ]));
  4445. }
  4446. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0)
  4447. {
  4448. return $this->_prepareParams(array(
  4449. 'view' => $sView,
  4450. 'type' => $sType,
  4451. 'owner_id' => $iOwnerId,
  4452. 'start' => $iStart,
  4453. 'per_page' => $iPerPage,
  4454. 'timeline' => $iTimeline,
  4455. 'filter' => $sFilter,
  4456. 'modules' => $aModules
  4457. ));
  4458. }
  4459. public function getParamsExt($aParams = array())
  4460. {
  4461. return $this->_prepareParams($aParams);
  4462. }
  4463. public function getViewsData(&$aViews)
  4464. {
  4465. if(empty($aViews) || !is_array($aViews))
  4466. return false;
  4467. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  4468. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  4469. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  4470. if($sSystem == '' || $iObjectId == 0)
  4471. return false;
  4472. return array($sSystem, $iObjectId, $iCount);
  4473. }
  4474. public function getVotesData(&$aVotes)
  4475. {
  4476. if(empty($aVotes) || !is_array($aVotes))
  4477. return false;
  4478. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  4479. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  4480. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  4481. if($sSystem == '' || $iObjectId == 0)
  4482. return false;
  4483. return array($sSystem, $iObjectId, $iCount);
  4484. }
  4485. public function getReactionsData(&$aReactions)
  4486. {
  4487. if(empty($aReactions) || !is_array($aReactions))
  4488. return false;
  4489. $sSystem = isset($aReactions['system']) ? $aReactions['system'] : '';
  4490. $iObjectId = isset($aReactions['object_id']) ? (int)$aReactions['object_id'] : 0;
  4491. $iCount = isset($aReactions['count']) ? (int)$aReactions['count'] : 0;
  4492. if($sSystem == '' || $iObjectId == 0)
  4493. return false;
  4494. return array($sSystem, $iObjectId, $iCount);
  4495. }
  4496. public function getScoresData(&$aScores)
  4497. {
  4498. if(empty($aScores) || !is_array($aScores))
  4499. return false;
  4500. $sSystem = isset($aScores['system']) ? $aScores['system'] : '';
  4501. $iObjectId = isset($aScores['object_id']) ? (int)$aScores['object_id'] : 0;
  4502. $iScore = isset($aScores['score']) ? (int)$aScores['score'] : 0;
  4503. if($sSystem == '' || $iObjectId == 0)
  4504. return false;
  4505. return array($sSystem, $iObjectId, $iScore);
  4506. }
  4507. public function getReportsData(&$aReports)
  4508. {
  4509. if(empty($aReports) || !is_array($aReports))
  4510. return false;
  4511. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  4512. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  4513. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  4514. if($sSystem == '' || $iObjectId == 0)
  4515. return false;
  4516. return array($sSystem, $iObjectId, $iCount);
  4517. }
  4518. public function getCommentsData(&$aComments)
  4519. {
  4520. if(empty($aComments) || !is_array($aComments))
  4521. return false;
  4522. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  4523. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  4524. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  4525. if($sSystem == '' || $iObjectId == 0)
  4526. return false;
  4527. return [$sSystem, $iObjectId, $iCount];
  4528. }
  4529. public function getEventLinks($iEventId)
  4530. {
  4531. $aLinks = $this->_oDb->getLinks($iEventId);
  4532. if(empty($aLinks) || !is_array($aLinks))
  4533. return array();
  4534. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_preview'));
  4535. $aResult = array();
  4536. foreach($aLinks as $aLink)
  4537. $aResult[] = array(
  4538. 'url' => $aLink['url'],
  4539. 'title' => $aLink['title'],
  4540. 'text' => $aLink['text'],
  4541. 'thumbnail' => (int)$aLink['media_id'] != 0 ? $oTranscoder->getFileUrl($aLink['media_id']) : ''
  4542. );
  4543. return $aResult;
  4544. }
  4545. public function getEventImages($iEventId)
  4546. {
  4547. $CNF = &$this->_oConfig->CNF;
  4548. $aPhotos = $this->_oDb->getMedia($CNF['FIELD_PHOTO'], $iEventId);
  4549. if(empty($aPhotos) || !is_array($aPhotos))
  4550. return [];
  4551. $sStorage = $this->_oConfig->getObject('storage_photos');
  4552. $oTranscoderSm = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_view'));
  4553. $oTranscoderMd = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_medium'));
  4554. $oTranscoderLg = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_big'));
  4555. $aResult = [];
  4556. foreach($aPhotos as $iPhotoId) {
  4557. if($this->_bIsApi) {
  4558. $aResult[] = bx_api_get_image($sStorage, $iPhotoId);
  4559. continue;
  4560. }
  4561. $sPhotoSrcMd = $oTranscoderMd->getFileUrl($iPhotoId);
  4562. if(empty($sPhotoSrcMd))
  4563. continue;
  4564. $sPhotoSrcSm = $oTranscoderSm->getFileUrl($iPhotoId);
  4565. if(empty($sPhotoSrcSm))
  4566. $sPhotoSrcSm = $sPhotoSrcMd;
  4567. $sPhotoSrcLg = $oTranscoderLg->getFileUrl($iPhotoId);
  4568. if(empty($sPhotoSrcLg))
  4569. $sPhotoSrcLg = $sPhotoSrcMd;
  4570. $aResult[] = [
  4571. 'id' => $iPhotoId,
  4572. 'src' => $sPhotoSrcMd,
  4573. 'src_small' => $sPhotoSrcSm,
  4574. 'src_medium' => $sPhotoSrcMd,
  4575. 'src_orig' => $sPhotoSrcLg,
  4576. ];
  4577. }
  4578. return $aResult;
  4579. }
  4580. public function getEventVideos($iEventId)
  4581. {
  4582. $CNF = &$this->_oConfig->CNF;
  4583. $aMediaIds = $this->_oDb->getMedia($CNF['FIELD_VIDEO'], $iEventId);
  4584. if(empty($aMediaIds) || !is_array($aMediaIds))
  4585. return [];
  4586. $sStorage = $this->_oConfig->getObject('storage_videos');
  4587. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  4588. $oTranscoderPoster = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_poster'));
  4589. $oTranscoderMp4 = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4'));
  4590. $oTranscoderMp4Hd = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4_hd'));
  4591. $oTranscoderPhoto = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_videos_photo_view'));
  4592. $oTranscoderPhotoBig = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_videos_photo_big'));
  4593. $aResult = [];
  4594. foreach($aMediaIds as $iMediaId) {
  4595. $aMediaFile = $oStorage->getFile($iMediaId);
  4596. $bVideoFile = strncmp('video/', $aMediaFile['mime_type'], 6) === 0 && $oTranscoderPoster->isMimeTypeSupported($aMediaFile['mime_type']);
  4597. if($bVideoFile) {
  4598. $sVideoUrlHd = '';
  4599. if (!empty($aMediaFile['dimensions']) && $oTranscoderMp4Hd->isProcessHD($aMediaFile['dimensions']))
  4600. $sVideoUrlHd = $oTranscoderMp4Hd->getFileUrl($iMediaId);
  4601. $aResult[$iMediaId] = [
  4602. 'id' => $iMediaId,
  4603. 'src_poster' => $oTranscoderPoster->getFileUrl($iMediaId),
  4604. 'src_mp4' => $oTranscoderMp4->getFileUrl($iMediaId),
  4605. 'src_mp4_hd' => $sVideoUrlHd,
  4606. ];
  4607. }
  4608. $bImageFile = strncmp('image/', $aMediaFile['mime_type'], 6) === 0 && $oTranscoderPhoto->isMimeTypeSupported($aMediaFile['mime_type']);
  4609. if($bImageFile) {
  4610. if($this->_bIsApi) {
  4611. $aResult[] = bx_api_get_image($sStorage, $iMediaId);
  4612. continue;
  4613. }
  4614. $sPhotoSrc = $oTranscoderPhoto->getFileUrl($iMediaId);
  4615. $sPhotoSrcBig = $oTranscoderPhotoBig->getFileUrl($iMediaId);
  4616. if(empty($sPhotoSrcBig) && !empty($sPhotoSrc))
  4617. $sPhotoSrcBig = $sPhotoSrc;
  4618. $aResult[$iMediaId] = [
  4619. 'id' => $iMediaId,
  4620. 'src' => $sPhotoSrc,
  4621. 'src_orig' => $sPhotoSrcBig,
  4622. ];
  4623. }
  4624. }
  4625. return $aResult;
  4626. }
  4627. public function getEventFiles($iEventId)
  4628. {
  4629. $CNF = &$this->_oConfig->CNF;
  4630. $aFiles = $this->_oDb->getMedia($CNF['FIELD_FILE'], $iEventId);
  4631. if(empty($aFiles) || !is_array($aFiles))
  4632. return [];
  4633. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_files'));
  4634. $aResult = [];
  4635. foreach($aFiles as $iFileId) {
  4636. $sFileUrl = $oStorage->getFileUrlById($iFileId);
  4637. $aFileFile = $oStorage->getFile($iFileId);
  4638. $aResult[$iFileId] = [
  4639. 'id' => $iFileId,
  4640. 'src' => $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFileFile['file_name'])),
  4641. 'src_medium' => '',
  4642. 'src_orig' => '',
  4643. 'url' => $sFileUrl,
  4644. 'title' => $aFileFile['file_name']
  4645. ];
  4646. }
  4647. return $aResult;
  4648. }
  4649. public function hasMedia($iEventId, $iProfileId = 0)
  4650. {
  4651. $CNF = &$this->_oConfig->CNF;
  4652. if(!empty($iEventId))
  4653. return $this->_oDb->hasMedia($iEventId);
  4654. if(empty($iProfileId))
  4655. $iProfileId = $this->_iProfileId;
  4656. $aTypes = [
  4657. $CNF['FIELD_PHOTO'],
  4658. $CNF['FIELD_VIDEO'],
  4659. $CNF['FIELD_FILE']
  4660. ];
  4661. $bResult = false;
  4662. foreach($aTypes as $sType) {
  4663. $sStorage = $this->_oConfig->getObject('storage_' . strtolower($sType) . 's');
  4664. if(($oStorage = BxDolStorage::getObjectInstance($sStorage)) !== false) {
  4665. $aGhosts = $oStorage->getGhosts($iProfileId, 0);
  4666. if(!empty($aGhosts) && is_array($aGhosts)) {
  4667. $bResult = true;
  4668. break;
  4669. }
  4670. }
  4671. }
  4672. return $bResult;
  4673. }
  4674. public function deleteLinksUnused($iProfileId)
  4675. {
  4676. $aLinks = $this->_oDb->getUnusedLinks($iProfileId);
  4677. if(empty($aLinks) || !is_array($aLinks))
  4678. return;
  4679. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  4680. foreach($aLinks as $aLink)
  4681. if(!empty($aLink['media_id']))
  4682. $oStorage->deleteFile($aLink['media_id']);
  4683. $this->_oDb->deleteUnusedLinks($iProfileId);
  4684. }
  4685. public function deleteCacheItem($iEventId)
  4686. {
  4687. //--- Delete own item cache.
  4688. $oCacheItem = $this->getCacheItemObject();
  4689. $aCacheKeys = $this->_oConfig->getCacheItemKeys($iEventId);
  4690. foreach($aCacheKeys as $sCacheKey)
  4691. $oCacheItem->delData($sCacheKey);
  4692. //--- Delete item cache for reposts.
  4693. $aReposts = $this->_oDb->getReposts($iEventId);
  4694. foreach($aReposts as $aRepost)
  4695. $this->deleteCacheItem($aRepost['event_id']);
  4696. }
  4697. public function rebuildSlice()
  4698. {
  4699. if(!$this->_oConfig->isCacheTable())
  4700. return;
  4701. $this->_oDb->rebuildSlice();
  4702. }
  4703. /**
  4704. * Protected Methods
  4705. */
  4706. protected function _serviceGetBlockView($iProfileId = 0, $aBrowseParams = array())
  4707. {
  4708. if(empty($iProfileId) && bx_get('profile_id') !== false)
  4709. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  4710. if(empty($iProfileId) && isLogged())
  4711. $iProfileId = bx_get_logged_profile_id();
  4712. $aBrowseParams['owner_id'] = $iProfileId;
  4713. $aBlock = $this->_getBlockView($aBrowseParams);
  4714. if(!empty($aBlock))
  4715. return $aBlock;
  4716. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  4717. }
  4718. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $aBrowseParams = array())
  4719. {
  4720. if(empty($sProfileModule))
  4721. return array();
  4722. if(empty($iProfileContentId) && bx_get('id') !== false)
  4723. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  4724. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  4725. if(empty($oProfile))
  4726. return array();
  4727. $aBrowseParams['owner_id'] = $oProfile->id();
  4728. return $this->_getBlockView($aBrowseParams);
  4729. }
  4730. protected function _serviceGetBlockViews($aBrowseParams = [])
  4731. {
  4732. $aParams = $this->_prepareParams($aBrowseParams);
  4733. if(($sType = $this->_oConfig->getUserChoice('type')) !== false)
  4734. $this->_setParamsType($sType, $aParams);
  4735. $this->_iOwnerId = $aParams['owner_id'];
  4736. return $this->_oTemplate->getViewsBlock($aParams);
  4737. }
  4738. protected function _serviceGetBlockViewHome($aBrowseParams = array())
  4739. {
  4740. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  4741. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  4742. return $this->_serviceGetBlockViewByType($aBrowseParams);
  4743. }
  4744. protected function _serviceGetBlockViewHot($aBrowseParams = array())
  4745. {
  4746. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  4747. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_hot'), $sRssUrl);
  4748. return $this->_serviceGetBlockViewByType($aBrowseParams);
  4749. }
  4750. protected function _serviceGetBlockViewByType($aBrowseParams = array())
  4751. {
  4752. $aParams = $this->_prepareParams($aBrowseParams);
  4753. $this->_iOwnerId = $aParams['owner_id'];
  4754. if(isset($aParams['validate']) && is_array($aParams['validate'])) {
  4755. $iSlice = count($aParams['validate']);
  4756. $aEventsIds = $this->_oDb->getEvents(array_merge($aParams, [
  4757. 'start' => 0,
  4758. 'per_page' => 2 * $iSlice,
  4759. 'from_cache' => $this->_oConfig->isCacheTable()
  4760. ]));
  4761. $iIds = 0;
  4762. $aIds = [];
  4763. foreach($aEventsIds as $aEventId) {
  4764. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => (int)$aEventId['id']]);
  4765. if(empty($aEvent) || !is_array($aEvent))
  4766. continue;
  4767. $sEvent = $this->_oTemplate->getPost($aEvent, $aParams);
  4768. if(empty($sEvent))
  4769. continue;
  4770. $aIds[] = $aEvent['id'];
  4771. if(++$iIds == $iSlice)
  4772. break;
  4773. }
  4774. sort($aIds);
  4775. sort($aParams['validate']);
  4776. $aResult = $aIds == $aParams['validate'] ? 'valid' : 'invalid';
  4777. }
  4778. else
  4779. $aResult = $this->_oTemplate->getViewBlock($aParams);
  4780. return $this->_bIsApi ? [bx_api_get_block('browse', [
  4781. 'unit' => 'feed',
  4782. 'request_url' => '/api.php?r=bx_timeline/get_posts/&params[]=',
  4783. 'params' => $aParams,
  4784. 'data' => $aResult
  4785. ])] : ['content' => $aResult];
  4786. }
  4787. protected function _getBlockPost($iProfileId, $aParams = array())
  4788. {
  4789. $this->_iOwnerId = $iProfileId;
  4790. if($this->isAllowedPost() !== true)
  4791. return [];
  4792. $mixedResult = $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams);
  4793. /*if (bx_is_api()){
  4794. $this->actionPost();
  4795. }
  4796. */
  4797. return bx_is_api() ? $mixedResult : [
  4798. 'content' => $mixedResult
  4799. ];
  4800. }
  4801. protected function _getBlockView($aBrowseParams = array())
  4802. {
  4803. if(empty($aBrowseParams['owner_id']))
  4804. return array();
  4805. $aParams = $this->_prepareParams($aBrowseParams);
  4806. if(empty($aParams['per_page']))
  4807. $aParams['per_page'] = $this->_oConfig->getPerPage('profile');
  4808. $this->_iOwnerId = $aParams['owner_id'];
  4809. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  4810. if(!$oProfileOwner)
  4811. return array();
  4812. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  4813. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED) {
  4814. if(!$this->_bIsApi) {
  4815. $this->_oTemplate->displayAccessDenied($mixedResult);
  4816. exit;
  4817. }
  4818. else
  4819. return [bx_api_get_msg($mixedResult, ['ext' => ['msg_type' => 'result']])];
  4820. }
  4821. $sUserName = $this->getObjectUser($aParams['owner_id'])->getDisplayName();
  4822. $sView = $aParams['view'];
  4823. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $this->_iOwnerId . '/';
  4824. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  4825. $aMenu = array(
  4826. array('id' => $sView . '-view-all', 'name' => $sView . '-view-all', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_all'), 'active' => 1),
  4827. array('id' => $sView . '-view-owner', 'name' => $sView . '-view-owner', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_owner', $sUserName)),
  4828. array('id' => $sView . '-view-other', 'name' => $sView . '-view-other', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_other')),
  4829. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'onclick' => '', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  4830. );
  4831. $sContent = '';
  4832. /**
  4833. * @hooks
  4834. * @hookdef hook-bx_base_profile-timeline_view '{profile_module_name}', 'timeline_view' - hook to override view timeline block
  4835. * - $unit_name - profile module name
  4836. * - $action - equals `timeline_view`
  4837. * - $object_id - timeline owner profile id
  4838. * - $sender_id - currently logged in profile id
  4839. * - $extra_params - array of additional params with the following array keys:
  4840. * - `params` - [array] browsing params array as key&value pairs
  4841. * - `menu` - [array] block submenu items array
  4842. * - `override_content` - [string] by ref, block content, can be overridden in hook processing
  4843. * @hook @ref hook-bx_base_profile-timeline_view
  4844. */
  4845. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), [
  4846. 'params' => &$aParams,
  4847. 'menu' => &$aMenu,
  4848. 'override_content' => &$sContent,
  4849. ]);
  4850. $oMenu = new BxTemplMenuInteractive(['template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu]);
  4851. $oMenu->setSelected('', $sView . '-view-all');
  4852. if (!$sContent)
  4853. $sContent = $this->_oTemplate->getViewBlock($aParams);
  4854. if($this->_bIsApi)
  4855. return [bx_api_get_block('browse', [
  4856. 'unit' => 'feed',
  4857. 'request_url' => '/api.php?r=bx_timeline/get_posts/&params[]=',
  4858. 'params' => $aParams,
  4859. 'data' => $sContent
  4860. ])];
  4861. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  4862. return array('content' => $sContent, 'menu' => $oMenu);
  4863. }
  4864. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  4865. {
  4866. $CNF = &$this->_oConfig->CNF;
  4867. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  4868. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iId));
  4869. $sText = '';
  4870. if(isset($aContentInfo['content'])){
  4871. $aTmp = unserialize($aContentInfo['content']);
  4872. if(isset($aTmp['text']))
  4873. $sText = $aTmp['text'];
  4874. }
  4875. if(empty($sText) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  4876. $sText = $aContentInfo[$CNF['FIELD_TITLE']];
  4877. if(!empty($CNF['OBJECT_METATAGS']) && !empty($sText)) {
  4878. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  4879. $sText = $oMetatags->metaParse($iId, $sText);
  4880. }
  4881. return array(
  4882. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  4883. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  4884. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  4885. 'url' => $sUrl,
  4886. 'title' => '',
  4887. 'text' => $sText,
  4888. 'links' => $this->getEventLinks($iId),
  4889. 'images' => array(),
  4890. 'images_attach' => $this->getEventImages($iId),
  4891. 'videos' => array(),
  4892. 'videos_attach' => $this->getEventVideos($iId),
  4893. 'files' => array(),
  4894. 'files_attach' => $this->getEventFiles($iId)
  4895. );
  4896. }
  4897. protected function _isAllowedRepost($aEvent, $bPerform = false)
  4898. {
  4899. $iUserId = (int)$this->getUserId();
  4900. if($iUserId == 0)
  4901. return false;
  4902. $iPrivacy = (int)$aEvent['object_privacy_view'];
  4903. if($iPrivacy >= 0 && !in_array($iPrivacy, [BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS]))
  4904. return false;
  4905. if(isAdmin())
  4906. return true;
  4907. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  4908. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  4909. /**
  4910. * @hooks
  4911. * @hookdef hook-bx_base_profile-timeline_repost '{profile_module_name}', 'timeline_repost' - hook to override the result of checking whether 'repost' action is allowed or not
  4912. * It's equivalent to @ref hook-bx_base_profile-timeline_post
  4913. * @hook @ref hook-bx_base_profile-timeline_repost
  4914. */
  4915. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, [
  4916. 'check_result' => &$aCheckResult
  4917. ]);
  4918. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4919. }
  4920. protected function _isAllowedMute($bPerform = false)
  4921. {
  4922. if($this->_iProfileId == 0)
  4923. return false;
  4924. if(isAdmin())
  4925. return true;
  4926. $aCheckResult = checkActionModule($this->_iProfileId, 'mute', $this->getName(), $bPerform);
  4927. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4928. }
  4929. protected function _isAllowedPin($aEvent, $bPerform = false)
  4930. {
  4931. $iUserId = (int)$this->getUserId();
  4932. if($iUserId == 0)
  4933. return false;
  4934. if(isAdmin() || (int)$aEvent['owner_id'] == $iUserId || ((int)$aEvent['owner_id'] == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && (int)$aEvent['object_id'] == $iUserId))
  4935. return true;
  4936. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  4937. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false) {
  4938. if(bx_srv($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'pin')) === CHECK_ACTION_RESULT_ALLOWED)
  4939. return true;
  4940. /**
  4941. * @hooks
  4942. * @hookdef hook-bx_base_profile-timeline_pin '{profile_module_name}', 'timeline_pin' - hook to override the result of checking whether 'pin' action is allowed or not
  4943. * It's equivalent to @ref hook-bx_base_profile-timeline_post
  4944. * @hook @ref hook-bx_base_profile-timeline_pin
  4945. */
  4946. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, [
  4947. 'check_result' => &$aCheckResult
  4948. ]);
  4949. }
  4950. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4951. }
  4952. protected function _isAllowedStick($aEvent, $bPerform = false)
  4953. {
  4954. $iUserId = (int)$this->getUserId();
  4955. if($iUserId == 0)
  4956. return false;
  4957. if(isAdmin())
  4958. return true;
  4959. $aCheckResult = checkActionModule($iUserId, 'stick', $this->getName(), $bPerform);
  4960. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  4961. /**
  4962. * @hooks
  4963. * @hookdef hook-bx_base_profile-timeline_stick '{profile_module_name}', 'timeline_stick' - hook to override the result of checking whether 'stick' action is allowed or not
  4964. * It's equivalent to @ref hook-bx_base_profile-timeline_post
  4965. * @hook @ref hook-bx_base_profile-timeline_stick
  4966. */
  4967. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_stick', $oProfileOwner->id(), $iUserId, [
  4968. 'check_result' => &$aCheckResult
  4969. ]);
  4970. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4971. }
  4972. protected function _isAllowedPromote($aEvent, $bPerform = false)
  4973. {
  4974. if(isAdmin())
  4975. return true;
  4976. $iUserId = (int)$this->getUserId();
  4977. if($iUserId == 0)
  4978. return false;
  4979. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  4980. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  4981. /**
  4982. * @hooks
  4983. * @hookdef hook-bx_base_profile-timeline_promote '{profile_module_name}', 'timeline_promote' - hook to override the result of checking whether 'promote' action is allowed or not
  4984. * It's equivalent to @ref hook-bx_base_profile-timeline_post
  4985. * @hook @ref hook-bx_base_profile-timeline_promote
  4986. */
  4987. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, [
  4988. 'check_result' => &$aCheckResult
  4989. ]);
  4990. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4991. }
  4992. protected function _deleteLinks($iId)
  4993. {
  4994. $aLinks = $this->_oDb->getLinks($iId);
  4995. if(empty($aLinks) || !is_array($aLinks))
  4996. return;
  4997. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  4998. foreach($aLinks as $aLink)
  4999. if(!empty($aLink['media_id']))
  5000. $oStorage->deleteFile($aLink['media_id']);
  5001. $this->_oDb->deleteLinks($iId);
  5002. }
  5003. protected function _processMetas($iId, $sText)
  5004. {
  5005. $CNF = &$this->_oConfig->CNF;
  5006. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  5007. if(!empty($sText)) {
  5008. $oMetatags->metaAdd($iId, $sText);
  5009. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iId]);
  5010. if($oMetatags->keywordsIsEnabled() && !empty($aEvent[$CNF['FIELD_LABELS']])) {
  5011. $aLabels = unserialize($aEvent[$CNF['FIELD_LABELS']]);
  5012. if(!empty($aLabels) && is_array($aLabels))
  5013. foreach ($aLabels as $sLabel) {
  5014. if(!preg_match("/(\pL[\pL\pN_]+)/u", $sLabel))
  5015. continue;
  5016. $oMetatags->keywordsAddOne($iId, $sLabel, false);
  5017. }
  5018. }
  5019. }
  5020. $oMetatags->locationsAddFromForm($iId, $CNF['FIELD_LOCATION_PREFIX']);
  5021. }
  5022. /**
  5023. * Check attached media for content type (photo, video).
  5024. */
  5025. protected function _checkMedia($sType, $iContentId, $aItemIds, $iProfileId = 0)
  5026. {
  5027. if(empty($iContentId) || empty($aItemIds) || !is_array($aItemIds))
  5028. return false;
  5029. if(empty($iProfileId))
  5030. $iProfileId = $this->_iProfileId;
  5031. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  5032. $aGhostFiles = $oStorage->getGhosts ($iProfileId, $iContentId, true, $this->_isModerator());
  5033. if(empty($aGhostFiles) || !is_array($aGhostFiles))
  5034. return false;
  5035. $oTranscoder = BxDolTranscoder::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4'));
  5036. $bHasImage = $bHasVideo = false;
  5037. $bIsVideoProcessed = true;
  5038. foreach($aGhostFiles as $aFile) {
  5039. if(is_array($aItemIds) && !in_array($aFile['id'], $aItemIds))
  5040. continue;
  5041. if(strncmp('image/', $aFile['mime_type'], 6) === 0) {
  5042. $bHasImage = true;
  5043. continue;
  5044. }
  5045. if(strncmp('video/', $aFile['mime_type'], 6) === 0) {
  5046. $bHasVideo = true;
  5047. if($oTranscoder && !$oTranscoder->isFileReady((int)$aFile['id']))
  5048. $bIsVideoProcessed = false;
  5049. continue;
  5050. }
  5051. }
  5052. return [$bHasImage, $bHasVideo, $bIsVideoProcessed];
  5053. }
  5054. protected function _saveMedia($sType, $iContentId, $aItemIds, $iProfileId = 0, $isAssociateWithContent = false)
  5055. {
  5056. if(empty($iContentId))
  5057. return;
  5058. if(!$isAssociateWithContent)
  5059. $this->_oDb->deleteMedia($sType, $iContentId);
  5060. if(empty($aItemIds) || !is_array($aItemIds))
  5061. return;
  5062. if(empty($iProfileId))
  5063. $iProfileId = $this->_iProfileId;
  5064. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  5065. $aGhostFiles = $oStorage->getGhosts ($iProfileId, !$isAssociateWithContent ? $iContentId : 0, true, $this->_isModerator());
  5066. if(empty($aGhostFiles) || !is_array($aGhostFiles))
  5067. return;
  5068. foreach($aGhostFiles as $aFile) {
  5069. if(is_array($aItemIds) && !in_array($aFile['id'], $aItemIds))
  5070. continue;
  5071. $iFileId = (int)$aFile['id'];
  5072. if($aFile['private'])
  5073. $oStorage->setFilePrivate($iFileId, 1);
  5074. $oStorage->updateGhostsContentId($iFileId, $iProfileId, $iContentId, $this->_isModerator());
  5075. $this->_oDb->saveMedia($sType, $iContentId, $iFileId);
  5076. }
  5077. }
  5078. protected function _deleteMedia($sType, $iContentId)
  5079. {
  5080. $aItems = $this->_oDb->getMedia($sType, $iContentId);
  5081. if(empty($aItems) || !is_array($aItems))
  5082. return;
  5083. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  5084. foreach($aItems as $iItemId)
  5085. $oStorage->deleteFile($iItemId);
  5086. $this->_oDb->deleteMedia($sType, $iContentId);
  5087. }
  5088. protected function _setParamsType($sType, &$aParams)
  5089. {
  5090. if(isset($aParams['type']) && $aParams['type'] == $sType)
  5091. return;
  5092. $iPerPage = $this->_oConfig->getPerPage($sType);
  5093. $aParams = array_merge($aParams, [
  5094. 'type' => $sType,
  5095. 'per_page' => $iPerPage,
  5096. 'per_page_default' => $iPerPage
  5097. ]);
  5098. }
  5099. protected function _prepareParams($aParams)
  5100. {
  5101. if(empty($aParams['name']))
  5102. $aParams['name'] = '';
  5103. if(empty($aParams['browse']))
  5104. $aParams['browse'] = 'list';
  5105. if(empty($aParams['view']))
  5106. $aParams['view'] = BX_TIMELINE_VIEW_DEFAULT;
  5107. if(empty($aParams['type']))
  5108. $aParams['type'] = BX_TIMELINE_TYPE_DEFAULT;
  5109. if(empty($aParams['owner_id']))
  5110. $aParams['owner_id'] = $this->getUserId();
  5111. if(!isset($aParams['start']) || (int)$aParams['start'] < 0)
  5112. $aParams['start'] = 0;
  5113. if(!isset($aParams['per_page_default']) || (int)$aParams['per_page_default'] <= 0)
  5114. $aParams['per_page_default'] = $this->_oConfig->getPerPage($aParams['type']);
  5115. if(!isset($aParams['per_page']) || (int)$aParams['per_page'] <= 0)
  5116. $aParams['per_page'] = $aParams['per_page_default'];
  5117. if(empty($aParams['timeline']) || (int)$aParams['timeline'] < 0)
  5118. $aParams['timeline'] = 0;
  5119. if(empty($aParams['filter']))
  5120. $aParams['filter'] = BX_TIMELINE_FILTER_ALL;
  5121. if(empty($aParams['modules']) || !is_array($aParams['modules']))
  5122. $aParams['modules'] = array();
  5123. if(empty($aParams['media']))
  5124. $aParams['media'] = '';
  5125. if(empty($aParams['context']))
  5126. $aParams['context'] = '';
  5127. if(empty($aParams['blink']) || !is_array($aParams['blink']))
  5128. $aParams['blink'] = array();
  5129. $iViewerId = $this->getUserId();
  5130. if(empty($aParams['viewer_id']) || (int)$aParams['viewer_id'] != $iViewerId)
  5131. $aParams['viewer_id'] = $iViewerId;
  5132. if(isset($aParams['validate']) && !is_array($aParams['validate']))
  5133. $aParams['validate'] = !empty($aParams['validate']) ? explode(',', $aParams['validate']) : [];
  5134. if(empty($aParams['status']))
  5135. $aParams['status'] = BX_TIMELINE_STATUS_ACTIVE;
  5136. if(empty($aParams['moderator']))
  5137. $aParams['moderator'] = $this->isModeratorForProfile($aParams['viewer_id']);
  5138. if(empty($aParams['dynamic_mode']))
  5139. $aParams['dynamic_mode'] = false;
  5140. return $aParams;
  5141. }
  5142. protected function _prepareParamsGet($mParams = false)
  5143. {
  5144. $aKeys = ['name', 'view', 'type', 'owner_id', 'start', 'per_page', 'per_page_default', 'timeline', 'filter', 'modules', 'media', 'context', 'blink', 'viewer_id', 'validate'];
  5145. $aParams = [];
  5146. if(!empty($mParams) && is_array($mParams))
  5147. foreach($aKeys as $sKey)
  5148. $aParams[$sKey] = isset($mParams[$sKey]) ? $mParams[$sKey] : false;
  5149. else
  5150. foreach($aKeys as $sKey)
  5151. $aParams[$sKey] = bx_get($sKey);
  5152. $aParams['name'] = $this->_oConfig->processParam($aParams['name']);
  5153. $aParams['view'] = $this->_oConfig->processParamWithDefault($aParams['view'], BX_TIMELINE_VIEW_DEFAULT);
  5154. $aParams['type'] = $this->_oConfig->processParamWithDefault($aParams['type'], BX_TIMELINE_TYPE_DEFAULT);
  5155. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  5156. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  5157. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage($aParams['type']);
  5158. $aParams['per_page_default'] = $aParams['per_page_default'] !== false ? bx_process_input($aParams['per_page_default'], BX_DATA_INT) : $this->_oConfig->getPerPage($aParams['type']);
  5159. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline']) : '';
  5160. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  5161. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : [];
  5162. $aParams['media'] = $aParams['media'] !== false ? $this->_oConfig->processParam($aParams['media']) : '';
  5163. $aParams['context'] = $aParams['context'] !== false ? $this->_oConfig->processParam($aParams['context']) : '';
  5164. if($aParams['blink'] !== false)
  5165. $aParams['blink'] = bx_process_input(is_string($aParams['blink']) ? explode(',', $aParams['blink']) : $aParams['blink'], BX_DATA_TEXT);
  5166. else
  5167. $aParams['blink'] = [];
  5168. $iViewerId = $this->getUserId();
  5169. if($aParams['viewer_id'] !== false)
  5170. $aParams['viewer_id'] = bx_process_input($aParams['viewer_id'], BX_DATA_INT);
  5171. if(!$aParams['viewer_id'] || $aParams['viewer_id'] != $iViewerId)
  5172. $aParams['viewer_id'] = $iViewerId;
  5173. if(isset($aParams['validate']) && !is_array($aParams['validate']))
  5174. $aParams['validate'] = !empty($aParams['validate']) ? explode(',', $aParams['validate']) : [];
  5175. $aParams = array_merge($aParams, [
  5176. 'browse' => 'list',
  5177. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  5178. 'moderator' => $this->isModeratorForProfile($aParams['viewer_id']),
  5179. 'dynamic_mode' => true,
  5180. ]);
  5181. return $aParams;
  5182. }
  5183. protected function _prepareTextForSave($s)
  5184. {
  5185. return bx_process_input($s, BX_DATA_HTML);
  5186. }
  5187. protected function _prepareFormForAutoSubmit(&$oForm, &$aValues)
  5188. {
  5189. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  5190. $oForm->aParams['csrf']['disable'] = true;
  5191. if(!empty($oForm->aParams['db']['submit_name'])) {
  5192. $sSubmitName = $sSubmitValue = false;
  5193. if(is_array($oForm->aParams['db']['submit_name'])) {
  5194. foreach ($oForm->aParams['db']['submit_name'] as $sName) {
  5195. if(isset($oForm->aInputs[$sName])) {
  5196. $sSubmitName = $sName;
  5197. $sSubmitValue = $oForm->aInputs[$sName]['value'];
  5198. break;
  5199. }
  5200. else if(isset($oForm->aInputs['controls']))
  5201. foreach($oForm->aInputs['controls'] as $mixedKey => $mixedInput)
  5202. if(is_numeric($mixedKey) && isset($mixedInput['name']) && $mixedInput['name'] == $sName) {
  5203. $sSubmitName = $sName;
  5204. $sSubmitValue = $mixedInput['value'];
  5205. break 2;
  5206. }
  5207. }
  5208. }
  5209. else {
  5210. $sName = $oForm->aParams['db']['submit_name'];
  5211. if(isset($oForm->aInputs[$sName])) {
  5212. $sSubmitName = $sName;
  5213. $sSubmitValue = $oForm->aInputs[$sName]['value'];
  5214. }
  5215. else if(isset($oForm->aInputs['controls']))
  5216. foreach($oForm->aInputs['controls'] as $mixedKey => $mixedInput)
  5217. if(is_numeric($mixedKey) && isset($mixedInput['name']) && $mixedInput['name'] == $sName) {
  5218. $sSubmitName = $sName;
  5219. $sSubmitValue = $mixedInput['value'];
  5220. break;
  5221. }
  5222. }
  5223. if($sSubmitName && $sSubmitValue)
  5224. $aValues[$sSubmitName] = $sSubmitValue;
  5225. }
  5226. }
  5227. protected function _getFieldValue($sField, $iContentId)
  5228. {
  5229. $CNF = &$this->_oConfig->CNF;
  5230. if(empty($CNF[$sField]))
  5231. return false;
  5232. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  5233. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  5234. return false;
  5235. return $aEvent[$CNF[$sField]];
  5236. }
  5237. /**
  5238. * Returns records for React Jot using OAuth2
  5239. * @param int $iProfileId
  5240. * @param string $sPage
  5241. * @param string $sTab
  5242. * @param int $iStart
  5243. * @param int $iPerPage
  5244. * @return array
  5245. */
  5246. public function serviceGetUserPosts($iProfileId = 0, $sPage = 'home', $sTab = 'hot', $iStart = 0, $iPerPage = 0)
  5247. {
  5248. $iProfileId = (int)$iProfileId ? (int)$iProfileId : bx_get_logged_profile_id();
  5249. if(empty($iProfileId))
  5250. return array(
  5251. 'code' => 1,
  5252. 'result' => array(),
  5253. 'message' => _t('_bx_timeline_txt_msg_no_profile_id'),
  5254. 'page' => $sPage,
  5255. 'tab' => $sTab
  5256. );
  5257. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  5258. $sView = BX_TIMELINE_VIEW_DEFAULT;
  5259. $sFilter = BX_TIMELINE_FILTER_ALL;
  5260. $aModules = array();
  5261. switch($sPage){
  5262. case 'profile':
  5263. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  5264. $sFilter = BX_TIMELINE_FILTER_OWNER;
  5265. break;
  5266. default:
  5267. if ($this -> _oDb -> isModuleByName($sPage))
  5268. $aModules = array($sPage);
  5269. }
  5270. switch($sTab)
  5271. {
  5272. case 'latest':
  5273. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  5274. break;
  5275. case 'popular':
  5276. $sType = BX_TIMELINE_TYPE_HOT;
  5277. break;
  5278. case 'feed':
  5279. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  5280. break;
  5281. default:
  5282. if ($this -> _oDb -> isModuleByName($sTab))
  5283. $aModules = array($sTab);
  5284. }
  5285. $aParams = $this->getParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules);
  5286. $aEvents = $this->_oDb->getEvents($aParams);
  5287. $iCount = $this->_oDb->getEvents(array_merge($aParams, array('count' => true)));
  5288. if(empty($aEvents) || !is_array($aEvents))
  5289. return array(
  5290. 'code' => 0,
  5291. 'result' => array(),
  5292. 'message' => _t('_bx_timeline_txt_msg_no_results'),
  5293. 'page' => $sPage,
  5294. 'tab' => $sTab
  5295. );
  5296. $aBrowseParams = array();
  5297. $aItems = array();
  5298. foreach($aEvents as $aEvent) {
  5299. $aResult = $this->_oTemplate->getData($aEvent, $aBrowseParams);
  5300. if($aResult === false)
  5301. continue;
  5302. $oOwnerProfile = BxDolProfile::getInstance($aResult['owner_id']);
  5303. $aFiles = array();
  5304. $aContent = &$aResult['content'];
  5305. if (!empty($aContent['image']))
  5306. $aFiles['images'] = array_values($aContent['images']);
  5307. if (!empty($aContent['images_attach']))
  5308. $aFiles['images'] = array_values($aContent['images_attach']);
  5309. if (!empty($aContent['videos']))
  5310. $aFiles['videos'] = array_values($aContent['videos']);
  5311. else
  5312. if (!empty($aContent['videos_attach']))
  5313. $aFiles['videos'] = array_values($aContent['videos_attach']);
  5314. if (!empty($aContent['files']))
  5315. $aFiles['files'] = array_values($aContent['files']);
  5316. else
  5317. if (!empty($aContent['files_attach']))
  5318. $aFiles['files'] = array_values($aContent['files_attach']);
  5319. $aItems[$aEvent['id']] = array_merge(array(
  5320. 'owner' => array(
  5321. 'icon' => $oOwnerProfile -> getThumb(),
  5322. 'name' => $oOwnerProfile -> getDisplayName(),
  5323. 'url' => $oOwnerProfile -> getUrl()
  5324. ),
  5325. 'sample' => !empty($aResult['sample']) ? _t($aResult['sample']) : _t('_bx_timeline_txt_sample'),
  5326. 'sample_action' => !empty($aResult['sample_action']) ? _t($aResult['sample_action']) : _t('_bx_timeline_txt_added_sample'),
  5327. 'url' => isset($aResult['url']) ? $aResult['url'] : '',
  5328. 'raw' => isset($aContent['raw']) ? strip_tags($aContent['raw']) : '',
  5329. 'text' => isset($aContent['text']) ? strip_tags($aContent['text']) : '',
  5330. 'views' => isset($aResult['views']['count']) ? (int)$aResult['views']['count'] : 0,
  5331. 'votes' => isset($aResult['votes']['count']) ? (int)$aResult['votes']['count'] : 0,
  5332. 'reactions' => isset($aResult['reactions']['count']) ? (int)$aResult['reactions']['count'] : 0,
  5333. 'scores' => isset($aResult['scores']['count']) ? (int)$aResult['scores']['count'] : 0,
  5334. 'reports' => isset($aResult['reports']['count']) ? (int)$aResult['reports']['count'] : 0,
  5335. 'comments' => isset($aResult['comments']['count']) ? (int)$aResult['comments']['count'] : 0,
  5336. 'date' => isset($aResult['date']) ? $aResult['date'] : $aEvent['date'],
  5337. 'type' => stripos($aEvent['type'], 'timeline') !== false ? 'bx_timeline' : $aEvent['type'],
  5338. 'event_type' => $aEvent['type'],
  5339. 'id' => $aEvent['id'],
  5340. 'content' => $aResult['content'],
  5341. 'title' => isset($aResult['title']) ? _t($aResult['title']) : '',
  5342. 'description' => isset($aResult['description']) ? $aResult['description'] : ''
  5343. ), $aFiles);
  5344. }
  5345. return array(
  5346. 'result' => $aItems,
  5347. 'code' => 0,
  5348. 'message' => '',
  5349. 'page' => $sPage,
  5350. 'tab' => $sTab,
  5351. 'total' => $iCount,
  5352. 'start' => (int)$iStart
  5353. );
  5354. }
  5355. }
  5356. /** @} */