BxTimelineModule.php 251 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412
  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. $aForm = $this->getFormEdit($iId)['form'];
  592. $aForm['inputs']['tlb_do_submit'] = $aForm['inputs']['controls'][0];
  593. unset($aForm['inputs']['controls']);
  594. $aRv['form'] = ['id' => 'bx_timeline', 'type' => 'form', 'name' => 'feed_edit', 'data' => $aForm, '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 serviceGetBlockViewChannels($sView = 'timeline')
  1884. {
  1885. return $this->serviceGetBlockViewCustom([
  1886. 'view' => $sView,
  1887. 'type' => 'channels'
  1888. ]);
  1889. }
  1890. public function serviceGetBlockViewFeedAndHot($sView = 'timeline')
  1891. {
  1892. return $this->serviceGetBlockViewCustom([
  1893. 'view' => $sView,
  1894. 'type' => 'feed_and_hot'
  1895. ]);
  1896. }
  1897. public function serviceGetBlockViewContexts($sView = 'timeline', $sContextModule = 'bx_groups')
  1898. {
  1899. return $this->serviceGetBlockViewCustom([
  1900. 'view' => $sView,
  1901. 'type' => 'connected_contexts',
  1902. 'context' => $sContextModule
  1903. ]);
  1904. }
  1905. public function serviceGetBlockViewMedia($sView = 'timeline', $mixedMedia = ['files', 'images', 'videos'])
  1906. {
  1907. return $this->serviceGetBlockViewCustom([
  1908. 'view' => $sView,
  1909. 'type' => 'feed',
  1910. 'media' => $mixedMedia
  1911. ]);
  1912. }
  1913. public function serviceGetBlockViewMediaFiles($sView = 'timeline')
  1914. {
  1915. return $this->serviceGetBlockViewMedia($sView, 'files');
  1916. }
  1917. public function serviceGetBlockViewMediaImages($sView = 'timeline')
  1918. {
  1919. return $this->serviceGetBlockViewMedia($sView, 'images');
  1920. }
  1921. public function serviceGetBlockViewMediaVideos($sView = 'timeline')
  1922. {
  1923. return $this->serviceGetBlockViewMedia($sView, 'videos');
  1924. }
  1925. public function serviceGetBlockMenuDb($aParams = [])
  1926. {
  1927. $aParams = $this->_prepareParams(array_merge([
  1928. 'name' => BX_TIMELINE_NAME_VIEWS_DB,
  1929. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1930. 'type' => BX_TIMELINE_TYPE_FEED,
  1931. 'owner_id' => $this->getProfileId()
  1932. ], $aParams));
  1933. if(($sType = $this->_oConfig->getUserChoice('type')) !== false)
  1934. $this->_setParamsType($sType, $aParams);
  1935. $sMenu = $this->_oConfig->getObject('menu_feeds');
  1936. if(isset($aParams['menu_feeds'])) {
  1937. $sMenu = $aParams['menu_feeds'];
  1938. unset($aParams['menu_feeds']);
  1939. }
  1940. $oMenu = BxDolMenu::getObjectInstance($sMenu);
  1941. if(!$oMenu)
  1942. return '';
  1943. $sSelectedModule = $this->getName();
  1944. $sSelectedName = $aParams['type'];
  1945. if(($aModule = $this->_oDb->getModuleByName($aParams['type']))) {
  1946. $sSelectedModule = $aModule['name'];
  1947. $sSelectedName = $aModule['uri'];
  1948. }
  1949. $oMenu->setSelected($sSelectedModule, $sSelectedName);
  1950. $oMenu->setBrowseParams($aParams);
  1951. return $oMenu->getCode();
  1952. }
  1953. public function serviceGetBlockViewsDb($aParams = [])
  1954. {
  1955. $iProfileId = $this->getProfileId();
  1956. $aParams = $this->_prepareParams(array_merge([
  1957. 'name' => BX_TIMELINE_NAME_VIEWS_DB,
  1958. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1959. 'type' => BX_TIMELINE_TYPE_FEED,
  1960. 'viewer_id' => $iProfileId,
  1961. 'owner_id' => $iProfileId
  1962. ], $aParams));
  1963. if(($sType = $this->_oConfig->getUserChoice('type', $aParams['viewer_id'])) !== false)
  1964. $this->_setParamsType($sType, $aParams);
  1965. $this->_iOwnerId = $aParams['owner_id'];
  1966. return $this->_oTemplate->getViewsDbBlock($aParams);
  1967. }
  1968. /**
  1969. * @page service Service Calls
  1970. * @section bx_timeline Timeline
  1971. * @subsection bx_timeline-page_blocks Page Blocks
  1972. * @subsubsection bx_timeline-get_block_item get_block_item
  1973. *
  1974. * @code bx_srv('bx_timeline', 'get_block_item', [...]); @endcode
  1975. *
  1976. * Get View Item block.
  1977. *
  1978. * @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.
  1979. *
  1980. * @see BxTimelineModule::serviceGetBlockItem
  1981. */
  1982. /**
  1983. * @ref bx_timeline-get_block_item "get_block_item"
  1984. */
  1985. public function serviceGetBlockItem()
  1986. {
  1987. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1988. if(!$iItemId)
  1989. return array();
  1990. $aParams = $this->_prepareParams(array(
  1991. 'view' => BX_TIMELINE_VIEW_ITEM,
  1992. 'type' => BX_TIMELINE_TYPE_ITEM
  1993. ));
  1994. $aItemData = $this->getItemData($iItemId, $aParams);
  1995. if (bx_is_api()){
  1996. $aItemData['event'] = $this->_oTemplate->getPostApi($aItemData['event'], $aParams);
  1997. return [bx_api_get_block('feed_item', $aItemData)];
  1998. }
  1999. return $this->_oTemplate->getItemBlock($aItemData, $aParams);
  2000. }
  2001. public function serviceGetBlockItemContent()
  2002. {
  2003. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2004. $sMode = bx_process_input(bx_get('mode'));
  2005. if(!$iItemId || !$sMode)
  2006. return '';
  2007. return $this->_oTemplate->getItemBlockContent($iItemId, $sMode);
  2008. }
  2009. public function serviceGetBlockItemInfo()
  2010. {
  2011. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2012. if(!$iItemId)
  2013. return '';
  2014. return $this->_oTemplate->getItemBlockInfo($iItemId);
  2015. }
  2016. public function serviceGetBlockItemComments()
  2017. {
  2018. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2019. if(!$iItemId)
  2020. return '';
  2021. return $this->_oTemplate->getItemBlockComments($iItemId);
  2022. }
  2023. public function serviceGetBlockMuted($iProfileId = 0)
  2024. {
  2025. if(!isLogged())
  2026. return MsgBox(_t('_Access denied'));
  2027. if($iProfileId == 0)
  2028. $iProfileId = $this->_iProfileId;
  2029. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getObject('grid_mute'));
  2030. if(!$oGrid)
  2031. return MsgBox('_Empty');
  2032. $oGrid->setProfile($iProfileId);
  2033. return $oGrid->getCode();
  2034. }
  2035. public function serviceGetPost($mixedEvent, $aParams = [])
  2036. {
  2037. if(!empty($mixedEvent) && !is_array($mixedEvent))
  2038. $mixedEvent = $this->_oDb->getContentInfoById((int)$mixedEvent);
  2039. if(empty($mixedEvent) || !is_array($mixedEvent))
  2040. return '';
  2041. $sPost = $this->_oTemplate->getPost($mixedEvent, $this->_prepareParams(array_merge([
  2042. 'view' => BX_TIMELINE_VIEW_ITEM,
  2043. 'type' => BX_TIMELINE_TYPE_ITEM
  2044. ], $aParams)));
  2045. if(empty($sPost))
  2046. return '';
  2047. return isset($aParams['return_data_type']) && $aParams['return_data_type'] == 'array' ? $mixedEvent : $sPost;
  2048. }
  2049. public function serviceGetTimelineRepostAllowedView($aEvent)
  2050. {
  2051. return isset($aEvent['content']['allowed_view']) ? $aEvent['content']['allowed_view'] : CHECK_ACTION_RESULT_ALLOWED;
  2052. }
  2053. /**
  2054. * @page service Service Calls
  2055. * @section bx_timeline Timeline
  2056. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2057. * @subsubsection bx_timeline-get_notifications_data get_notifications_data
  2058. *
  2059. * @code bx_srv('bx_timeline', 'get_notifications_data', [...]); @endcode
  2060. *
  2061. * Data for Notifications module.
  2062. *
  2063. * @return an array with special format.
  2064. *
  2065. * @see BxTimelineModule::serviceGetNotificationsData
  2066. */
  2067. /**
  2068. * @ref bx_timeline-get_notifications_data "get_notifications_data"
  2069. */
  2070. public function serviceGetNotificationsData()
  2071. {
  2072. $sModule = $this->_aModule['name'];
  2073. return array(
  2074. 'handlers' => array(
  2075. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  2076. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  2077. 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'),
  2078. 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'),
  2079. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  2080. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  2081. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  2082. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  2083. array('group' => $sModule . '_reply', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'replyPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_reply', 'module_class' => 'Module'),
  2084. array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
  2085. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  2086. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  2087. array('group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_reaction', 'module_class' => 'Module'),
  2088. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  2089. 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'),
  2090. 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'),
  2091. ),
  2092. 'settings' => array(
  2093. array('group' => 'content', 'unit' => $sModule, 'action' => 'post_common', 'types' => array('personal', 'follow_member', 'follow_context')),
  2094. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => array('personal')),
  2095. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => array('personal')),
  2096. array('group' => 'content', 'unit' => $sModule, 'action' => 'repost', 'types' => array('personal', 'follow_member', 'follow_context')),
  2097. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  2098. array('group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => array('personal')),
  2099. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  2100. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  2101. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  2102. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  2103. ),
  2104. 'alerts' => array(
  2105. array('unit' => $sModule, 'action' => 'post_common'),
  2106. array('unit' => $sModule, 'action' => 'publish_failed'),
  2107. array('unit' => $sModule, 'action' => 'publish_succeeded'),
  2108. array('unit' => $sModule, 'action' => 'delete'),
  2109. array('unit' => $sModule, 'action' => 'repost'),
  2110. array('unit' => $sModule, 'action' => 'delete_repost'),
  2111. array('unit' => $sModule, 'action' => 'commentPost'),
  2112. array('unit' => $sModule, 'action' => 'commentRemoved'),
  2113. array('unit' => $sModule, 'action' => 'replyPost'),
  2114. array('unit' => $sModule, 'action' => 'replyRemoved'),
  2115. array('unit' => $sModule, 'action' => 'doVote'),
  2116. array('unit' => $sModule, 'action' => 'undoVote'),
  2117. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  2118. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  2119. array('unit' => $sModule, 'action' => 'doVoteUp'),
  2120. array('unit' => $sModule, 'action' => 'doVoteDown'),
  2121. )
  2122. );
  2123. }
  2124. /**
  2125. * @page service Service Calls
  2126. * @section bx_timeline Timeline
  2127. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2128. * @subsubsection bx_timeline-get_notifications_repost get_notifications_repost
  2129. *
  2130. * @code bx_srv('bx_timeline', 'get_notifications_repost', [...]); @endcode
  2131. *
  2132. * Get data for Repost event to display in Notifications module.
  2133. *
  2134. * @param $aEvent an array with event description.
  2135. * @return an array with special format.
  2136. *
  2137. * @see BxTimelineModule::serviceGetNotificationsRepost
  2138. */
  2139. /**
  2140. * @ref bx_timeline-get_notifications_repost "get_notifications_repost"
  2141. */
  2142. public function serviceGetNotificationsRepost($aEvent)
  2143. {
  2144. $aResult = $this->serviceGetNotificationsPost($aEvent);
  2145. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  2146. return $aResult;
  2147. }
  2148. /**
  2149. * @page service Service Calls
  2150. * @section bx_timeline Timeline
  2151. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2152. * @subsubsection bx_timeline-get_notifications_post get_notifications_post
  2153. *
  2154. * @code bx_srv('bx_timeline', 'get_notifications_post', [...]); @endcode
  2155. *
  2156. * Get data for Post event to display in Notifications module.
  2157. *
  2158. * @param $aEvent an array with event description.
  2159. * @return an array with special format.
  2160. *
  2161. * @see BxTimelineModule::serviceGetNotificationsPost
  2162. */
  2163. /**
  2164. * @ref bx_timeline-get_notifications_post "get_notifications_post"
  2165. */
  2166. public function serviceGetNotificationsPost($aEvent)
  2167. {
  2168. $CNF = &$this->_oConfig->CNF;
  2169. $iContent = (int)$aEvent['object_id'];
  2170. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  2171. if(empty($aContent) || !is_array($aContent))
  2172. return [];
  2173. if($this->_oConfig->isSystem($aContent['type'], $aContent['action']))
  2174. $iEntryAuthor = (int)$aContent['owner_id'];
  2175. else
  2176. $iEntryAuthor = (int)$aContent['object_id'];
  2177. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  2178. $sEntrySummary = $this->_oConfig->getTitle($aContent['description'], $aContent['object_id'], false);
  2179. return [
  2180. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  2181. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2182. 'entry_caption' => $sEntryCaption,
  2183. 'entry_summary' => $sEntrySummary,
  2184. 'entry_author' => $iEntryAuthor,
  2185. 'lang_key' => '' //may be empty or not specified. In this case the default one from Notification module will be used.
  2186. ];
  2187. }
  2188. /**
  2189. * @page service Service Calls
  2190. * @section bx_timeline Timeline
  2191. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2192. * @subsubsection bx_timeline-get_notifications_comment get_notifications_comment
  2193. *
  2194. * @code bx_srv('bx_timeline', 'get_notifications_comment', [...]); @endcode
  2195. *
  2196. * Get data for Post Comment event to display in Notifications module.
  2197. *
  2198. * @param $aEvent an array with event description.
  2199. * @return an array with special format.
  2200. *
  2201. * @see BxTimelineModule::serviceGetNotificationsComment
  2202. */
  2203. /**
  2204. * @ref bx_timeline-get_notifications_comment "get_notifications_comment"
  2205. */
  2206. public function serviceGetNotificationsComment($aEvent)
  2207. {
  2208. $CNF = &$this->_oConfig->CNF;
  2209. $iContent = (int)$aEvent['object_id'];
  2210. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  2211. if(empty($aContent) || !is_array($aContent))
  2212. return [];
  2213. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  2214. if(!$oComment || !$oComment->isEnabled())
  2215. return [];
  2216. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  2217. $sEntrySummary = $this->_oConfig->getTitle($aContent['description'], $aContent['object_id'], false);
  2218. $iCommentId = (int)$aEvent['subobject_id'];
  2219. return [
  2220. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2221. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2222. 'entry_caption' => $sEntryCaption,
  2223. 'entry_summary' => $sEntrySummary,
  2224. 'entry_author' => $aContent['owner_id'],
  2225. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  2226. 'subentry_url' => bx_absolute_url($oComment->getViewUrl($iCommentId, false), '{bx_url_root}'),
  2227. 'subentry_summary' => $oComment->getViewText($iCommentId),
  2228. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2229. ];
  2230. }
  2231. /**
  2232. * @page service Service Calls
  2233. * @section bx_timeline Timeline
  2234. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2235. * @subsubsection bx_timeline-get_notifications_reply get_notifications_reply
  2236. *
  2237. * @code bx_srv('bx_timeline', 'get_notifications_reply', [...]); @endcode
  2238. *
  2239. * Get data for Reply to Comment event to display in Notifications module.
  2240. *
  2241. * @param $aEvent an array with event description.
  2242. * @return an array with special format.
  2243. *
  2244. * @see BxTimelineModule::serviceGetNotificationsReply
  2245. */
  2246. /**
  2247. * @ref bx_timeline-get_notifications_reply "get_notifications_reply"
  2248. */
  2249. public function serviceGetNotificationsReply($aEvent)
  2250. {
  2251. $CNF = &$this->_oConfig->CNF;
  2252. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  2253. if(!$oComment || !$oComment->isEnabled())
  2254. return [];
  2255. $iParentId = (int)$aEvent['object_id'];
  2256. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  2257. if(empty($aParentInfo) || !is_array($aParentInfo))
  2258. return [];
  2259. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  2260. $oComment->init($iObjectId);
  2261. $iCommentId = (int)$aEvent['subobject_id'];
  2262. return [
  2263. 'object_id' => $iObjectId,
  2264. 'entry_sample' => '_cmt_txt_sample_comment_single',
  2265. 'entry_url' => bx_absolute_url($oComment->getViewUrl($iParentId, false), '{bx_url_root}'),
  2266. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  2267. 'entry_summary' => $oComment->getViewText($iParentId),
  2268. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  2269. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  2270. 'subentry_url' => bx_absolute_url($oComment->getViewUrl($iCommentId, false), '{bx_url_root}'),
  2271. 'subentry_summary' => $oComment->getViewText($iCommentId),
  2272. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2273. ];
  2274. }
  2275. /**
  2276. * @page service Service Calls
  2277. * @section bx_timeline Timeline
  2278. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2279. * @subsubsection bx_timeline-get_notifications_vote get_notifications_vote
  2280. *
  2281. * @code bx_srv('bx_timeline', 'get_notifications_vote', [...]); @endcode
  2282. *
  2283. * Get data for Vote event to display in Notifications module.
  2284. *
  2285. * @param $aEvent an array with event description.
  2286. * @return an array with special format.
  2287. *
  2288. * @see BxTimelineModule::serviceGetNotificationsVote
  2289. */
  2290. /**
  2291. * @ref bx_timeline-get_notifications_vote "get_notifications_vote"
  2292. */
  2293. public function serviceGetNotificationsVote($aEvent)
  2294. {
  2295. $CNF = &$this->_oConfig->CNF;
  2296. $iContent = (int)$aEvent['object_id'];
  2297. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  2298. if(empty($aContent) || !is_array($aContent))
  2299. return [];
  2300. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  2301. if(!$oVote || !$oVote->isEnabled())
  2302. return [];
  2303. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  2304. $sEntrySummary = $this->_oConfig->getTitle($aContent['description'], $aContent['object_id'], false);
  2305. return [
  2306. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2307. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2308. 'entry_caption' => $sEntryCaption,
  2309. 'entry_summary' => $sEntrySummary,
  2310. 'entry_author' => $aContent['owner_id'],
  2311. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  2312. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2313. ];
  2314. }
  2315. /**
  2316. * Entry post vote for Notifications module
  2317. */
  2318. public function serviceGetNotificationsReaction($aEvent)
  2319. {
  2320. $CNF = &$this->_oConfig->CNF;
  2321. $iContent = (int)$aEvent['object_id'];
  2322. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  2323. if(empty($aContent) || !is_array($aContent))
  2324. return [];
  2325. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContent);
  2326. if(!$oReaction || !$oReaction->isEnabled())
  2327. return [];
  2328. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  2329. if(empty($aSubentry) || !is_array($aSubentry))
  2330. return [];
  2331. $aSubentrySampleParams = array();
  2332. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  2333. if(!empty($aReaction['title']))
  2334. $aSubentrySampleParams[] = $aReaction['title'];
  2335. else
  2336. $aSubentrySampleParams[] = '_undefined';
  2337. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  2338. $sEntrySummary = $this->_oConfig->getTitle($aContent['description'], $aContent['object_id'], false);
  2339. return [
  2340. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2341. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2342. 'entry_caption' => $sEntryCaption,
  2343. 'entry_summary' => $sEntrySummary,
  2344. 'entry_author' => $aContent['owner_id'],
  2345. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  2346. 'subentry_sample_params' => $aSubentrySampleParams,
  2347. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2348. ];
  2349. }
  2350. /**
  2351. * @page service Service Calls
  2352. * @section bx_timeline Timeline
  2353. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2354. * @subsubsection bx_timeline-get_notifications_score_up get_notifications_score_up
  2355. *
  2356. * @code bx_srv('bx_timeline', 'get_notifications_score_up', [...]); @endcode
  2357. *
  2358. * Get data for Score Up Vote event to display in Notifications module.
  2359. *
  2360. * @param $aEvent an array with event description.
  2361. * @return an array with special format.
  2362. *
  2363. * @see BxTimelineModule::serviceGetNotificationsScoreUp
  2364. */
  2365. /**
  2366. * @ref bx_timeline-get_notifications_score_up "get_notifications_score_up"
  2367. */
  2368. public function serviceGetNotificationsScoreUp($aEvent)
  2369. {
  2370. return $this->_serviceGetNotificationsScore('up', $aEvent);
  2371. }
  2372. /**
  2373. * @page service Service Calls
  2374. * @section bx_timeline Timeline
  2375. * @subsection bx_timeline-integration_notifications Integration with Notifications
  2376. * @subsubsection bx_timeline-get_notifications_score_down get_notifications_score_down
  2377. *
  2378. * @code bx_srv('bx_timeline', 'get_notifications_score_down', [...]); @endcode
  2379. *
  2380. * Get data for Score Down Vote event to display in Notifications module.
  2381. *
  2382. * @param $aEvent an array with event description.
  2383. * @return an array with special format.
  2384. *
  2385. * @see BxTimelineModule::serviceGetNotificationsScoreDown
  2386. */
  2387. /**
  2388. * @ref bx_timeline-get_notifications_score_down "get_notifications_score_down"
  2389. */
  2390. public function serviceGetNotificationsScoreDown($aEvent)
  2391. {
  2392. return $this->_serviceGetNotificationsScore('down', $aEvent);
  2393. }
  2394. protected function _serviceGetNotificationsScore($sType, $aEvent)
  2395. {
  2396. $CNF = &$this->_oConfig->CNF;
  2397. $iContent = (int)$aEvent['object_id'];
  2398. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  2399. if(empty($aContent) || !is_array($aContent))
  2400. return [];
  2401. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContent);
  2402. if(!$oScore || !$oScore->isEnabled())
  2403. return [];
  2404. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  2405. $sEntrySummary = $this->_oConfig->getTitle($aContent['description'], $aContent['object_id'], false);
  2406. return [
  2407. 'entry_sample' => $CNF['T']['txt_sample_single'],
  2408. 'entry_url' => bx_absolute_url($this->_oConfig->getItemViewUrl($aContent, false), '{bx_url_root}'),
  2409. 'entry_caption' => $sEntryCaption,
  2410. 'entry_summary' => $sEntrySummary,
  2411. 'entry_author' => $aContent['owner_id'],
  2412. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  2413. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  2414. ];
  2415. }
  2416. /**
  2417. * @page service Service Calls
  2418. * @section bx_timeline Timeline
  2419. * @subsection bx_timeline-repost Repost
  2420. * @subsubsection bx_timeline-get_repost_element_block get_repost_element_block
  2421. *
  2422. * @code bx_srv('bx_timeline', 'get_repost_element_block', [...]); @endcode
  2423. *
  2424. * Get repost element for content based modules.
  2425. *
  2426. * @param $iOwnerId integer value with owner profile ID.
  2427. * @param $sType string value with type (module name).
  2428. * @param $sAction string value with action (module action).
  2429. * @param $iObjectId integer value with object ID to be reposted.
  2430. * @param $aParams (optional) an array with additional params.
  2431. * @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.
  2432. *
  2433. * @see BxTimelineModule::serviceGetRepostElementBlock
  2434. */
  2435. /**
  2436. * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
  2437. */
  2438. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = [])
  2439. {
  2440. if(!$this->isEnabled())
  2441. return '';
  2442. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  2443. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  2444. }
  2445. /**
  2446. * @page service Service Calls
  2447. * @section bx_timeline Timeline
  2448. * @subsection bx_timeline-repost Repost
  2449. * @subsubsection bx_timeline-get_repost_element_block_api get_repost_element_block_api
  2450. *
  2451. * @code bx_srv('bx_timeline', 'get_repost_element_block_api', [...]); @endcode
  2452. *
  2453. * Get repost element for content based modules.
  2454. * Note. Response is formated to be used in API calls.
  2455. *
  2456. * @param $iOwnerId integer value with owner profile ID.
  2457. * @param $sType string value with type (module name).
  2458. * @param $sAction string value with action (module action).
  2459. * @param $iObjectId integer value with object ID to be reposted.
  2460. * @param $aParams (optional) an array with additional params.
  2461. * @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.
  2462. *
  2463. * @see BxTimelineModule::serviceGetRepostElementBlockApi
  2464. */
  2465. /**
  2466. * @ref bx_timeline-get_repost_element_block_api "get_repost_element_block_api"
  2467. * @api @ref bx_timeline-get_repost_element_block_api "get_repost_element_block_api"
  2468. */
  2469. public function serviceGetRepostElementBlockApi($iOwnerId, $sType, $sAction, $iObjectId, $aParams = [])
  2470. {
  2471. if(!$this->_bIsApi || !$this->isEnabled())
  2472. return [];
  2473. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2474. if(empty($aReposted) || !is_array($aReposted))
  2475. return [];
  2476. $aParams = array_merge($this->_oConfig->getRepostDefaults(true), $aParams);
  2477. $bPerformed = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $this->getUserId());
  2478. $bDisabled = $this->isAllowedRepost($aReposted) !== true;
  2479. $sDo = isset($aParams['do']) ? $aParams['do'] : 'repost';
  2480. $sDataType = $sType;
  2481. $sDataAction = $sAction;
  2482. $iDataObjectId = $iObjectId;
  2483. if(($sCommonPrefix = $this->_oConfig->getPrefix('common_post')) && str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  2484. $aRepostedData = unserialize($aReposted['content']);
  2485. $sDataType = $aRepostedData['type'];
  2486. $sDataAction = $aRepostedData['action'];
  2487. $iDataObjectId = $aRepostedData['object_id'];
  2488. }
  2489. return [
  2490. 'type' => 'reposts',
  2491. 'system' => $sType . (!empty($sAction) ? '_' . $sAction : ''),
  2492. 'object_id' => $iObjectId,
  2493. 'params' => array_intersect_key($aParams, array_flip($this->_oConfig->getRepostParams(true))),
  2494. 'action' => [
  2495. 'is_undo' => false,
  2496. 'is_performed' => $bPerformed,
  2497. 'is_disabled' => $bDisabled || $bPerformed,
  2498. 'title' => _t($aParams['text_do_' . $sDo]),
  2499. 'data' => [
  2500. 'author_id' => $iOwnerId,
  2501. 'owner_id' => $iOwnerId,
  2502. 'type' => $sDataType,
  2503. 'action' => $sDataAction,
  2504. 'object_id' => $iDataObjectId
  2505. ]
  2506. ],
  2507. 'counter' => []
  2508. ];
  2509. }
  2510. /**
  2511. * @page service Service Calls
  2512. * @section bx_timeline Timeline
  2513. * @subsection bx_timeline-repost Repost
  2514. * @subsubsection bx_timeline-get_repost_counter get_repost_counter
  2515. *
  2516. * @code bx_srv('bx_timeline', 'get_repost_counter', [...]); @endcode
  2517. *
  2518. * Get repost counter.
  2519. *
  2520. * @param $sType string value with type (module name).
  2521. * @param $sAction string value with action (module action).
  2522. * @param $iObjectId integer value with object ID to be reposted.
  2523. * @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.
  2524. *
  2525. * @see BxTimelineModule::serviceGetRepostCounter
  2526. */
  2527. /**
  2528. * @ref bx_timeline-get_repost_counter "get_repost_counter"
  2529. */
  2530. public function serviceGetRepostCounter($sType, $sAction, $iObjectId, $aParams = [])
  2531. {
  2532. if(!$this->isEnabled())
  2533. return '';
  2534. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2535. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  2536. return $this->_oTemplate->getRepostCounter($aReposted, $aParams);
  2537. }
  2538. /**
  2539. * @page service Service Calls
  2540. * @section bx_timeline Timeline
  2541. * @subsection bx_timeline-repost Repost
  2542. * @subsubsection bx_timeline-get_repost_js_script get_repost_js_script
  2543. *
  2544. * @code bx_srv('bx_timeline', 'get_repost_js_script', [...]); @endcode
  2545. *
  2546. * Get repost JavaScript code.
  2547. *
  2548. * @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.
  2549. *
  2550. * @see BxTimelineModule::serviceGetRepostJsScript
  2551. */
  2552. /**
  2553. * @ref bx_timeline-get_repost_js_script "get_repost_js_script"
  2554. */
  2555. public function serviceGetRepostJsScript()
  2556. {
  2557. if(!$this->isEnabled())
  2558. return '';
  2559. return $this->_oTemplate->getRepostJsScript();
  2560. }
  2561. /**
  2562. * @page service Service Calls
  2563. * @section bx_timeline Timeline
  2564. * @subsection bx_timeline-repost Repost
  2565. * @subsubsection bx_timeline-get_repost_js_click get_repost_js_click
  2566. *
  2567. * @code bx_srv('bx_timeline', 'get_repost_js_click', [...]); @endcode
  2568. *
  2569. * Get repost JavaScript code for OnClick event.
  2570. *
  2571. * @param $iOwnerId integer value with owner profile ID.
  2572. * @param $sType string value with type (module name).
  2573. * @param $sAction string value with action (module action).
  2574. * @param $iObjectId integer value with object ID to be reposted.
  2575. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  2576. *
  2577. * @see BxTimelineModule::serviceGetRepostJsClick
  2578. */
  2579. /**
  2580. * @ref bx_timeline-get_repost_js_click "get_repost_js_click"
  2581. */
  2582. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  2583. {
  2584. if(!$this->isEnabled())
  2585. return '';
  2586. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  2587. }
  2588. /**
  2589. * @page service Service Calls
  2590. * @section bx_timeline Timeline
  2591. * @subsection bx_timeline-repost Repost
  2592. * @subsubsection bx_timeline-get_repost_with_js_click get_repost_with_js_click
  2593. *
  2594. * @code bx_srv('bx_timeline', 'get_repost_with_js_click', [...]); @endcode
  2595. *
  2596. * Get 'repost with' JavaScript code for OnClick event.
  2597. *
  2598. * @param $iReposterId integer value with reposter profile ID.
  2599. * @param $sType string value with type (module name).
  2600. * @param $sAction string value with action (module action).
  2601. * @param $iObjectId integer value with object ID to be reposted.
  2602. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  2603. *
  2604. * @see BxTimelineModule::serviceGetRepostWithJsClick
  2605. */
  2606. /**
  2607. * @ref bx_timeline-get_repost_with_js_click "get_repost_with_js_click"
  2608. */
  2609. public function serviceGetRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId)
  2610. {
  2611. if(!$this->isEnabled())
  2612. return '';
  2613. return $this->_oTemplate->getRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId);
  2614. }
  2615. /**
  2616. * @page service Service Calls
  2617. * @section bx_timeline Timeline
  2618. * @subsection bx_timeline-repost Repost
  2619. * @subsubsection bx_timeline-get_repost_to_js_click get_repost_to_js_click
  2620. *
  2621. * @code bx_srv('bx_timeline', 'get_repost_to_js_click', [...]); @endcode
  2622. *
  2623. * Get 'repost to' JavaScript code for OnClick event.
  2624. *
  2625. * @param $iReposterId integer value with reposter profile ID.
  2626. * @param $sType string value with type (module name).
  2627. * @param $sAction string value with action (module action).
  2628. * @param $iObjectId integer value with object ID to be reposted.
  2629. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  2630. *
  2631. * @see BxTimelineModule::serviceGetRepostToJsClick
  2632. */
  2633. /**
  2634. * @ref bx_timeline-get_repost_to_js_click "get_repost_to_js_click"
  2635. */
  2636. public function serviceGetRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId)
  2637. {
  2638. if(!$this->isEnabled())
  2639. return '';
  2640. return $this->_oTemplate->getRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId);
  2641. }
  2642. /**
  2643. * @page service Service Calls
  2644. * @section bx_timeline Timeline
  2645. * @subsection bx_timeline-repost Repost
  2646. * @subsubsection bx_timeline-repost repost
  2647. *
  2648. * @code bx_srv('bx_timeline', 'repost', [...]); @endcode
  2649. *
  2650. * Perform repost action.
  2651. *
  2652. * @param $iAuthorId integer value with performer profile ID.
  2653. * @param $iOwnerId integer value with repost event owner profile ID.
  2654. * @param $sType string value with type (module name).
  2655. * @param $sAction string value with action (module action).
  2656. * @param $iObjectId integer value with object ID to be reposted.
  2657. * @parem $bForce boolean value force reposting without ACL check.
  2658. * @return an array with error (code and message) or integer with newly created repost event ID.
  2659. *
  2660. * @see BxTimelineModule::serviceRepost
  2661. */
  2662. /**
  2663. * @ref bx_timeline-repost "repost"
  2664. * @api @ref bx_timeline-repost "repost"
  2665. */
  2666. public function serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce = false)
  2667. {
  2668. $mixedResult = $this->repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, false, $bForce);
  2669. if($this->_bIsApi && !is_array($mixedResult))
  2670. $mixedResult = [
  2671. 'code' => 0,
  2672. 'id' => $mixedResult,
  2673. 'performer_id' => $iAuthorId,
  2674. 'is_performed' => true,
  2675. 'is_disabled' => true,
  2676. 'counter' => []
  2677. ];
  2678. return $mixedResult;
  2679. }
  2680. /**
  2681. * @page service Service Calls
  2682. * @section bx_timeline Timeline
  2683. * @subsection bx_timeline-repost Repost
  2684. * @subsubsection bx_timeline-repost_with repost_with
  2685. *
  2686. * @code bx_srv('bx_timeline', 'repost_with', [...]); @endcode
  2687. *
  2688. * Perform repost action passing additional data.
  2689. *
  2690. * @param $iAuthorId integer value with performer profile ID.
  2691. * @param $iOwnerId integer value with repost event owner profile ID.
  2692. * @param $sType string value with type (module name).
  2693. * @param $sAction string value with action (module action).
  2694. * @param $iObjectId integer value with object ID to be reposted.
  2695. * @param $mixedData array with some data to attach to repost event or false.
  2696. * @parem $bForce boolean value force reposting without ACL check.
  2697. * @return an array with error (code and message) or integer with newly created repost event ID.
  2698. *
  2699. * @see BxTimelineModule::serviceRepostWith
  2700. */
  2701. /**
  2702. * @ref bx_timeline-repost_with "repost_with"
  2703. */
  2704. public function serviceRepostWith($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $mixedData = false, $bForce = false)
  2705. {
  2706. return $this->repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $mixedData, $bForce);
  2707. }
  2708. /**
  2709. * @page service Service Calls
  2710. * @section bx_timeline Timeline
  2711. * @subsection bx_timeline-repost Repost
  2712. * @subsubsection bx_timeline-repost_by_id repost_by_id
  2713. *
  2714. * @code bx_srv('bx_timeline', 'repost_by_id', [...]); @endcode
  2715. *
  2716. * Perform repost action by Timeline event ID.
  2717. *
  2718. * @param $iAuthorId integer value with performer profile ID.
  2719. * @param $iOwnerId integer value with repost event owner profile ID.
  2720. * @param $iEventId integer value with event ID which will be reposted.
  2721. * @parem $bForce boolean value force reposting without ACL check.
  2722. * @return an array with error (code and message) or integer with newly created repost event ID.
  2723. *
  2724. * @see BxTimelineModule::serviceRepostById
  2725. */
  2726. /**
  2727. * @ref bx_timeline-repost_by_id "repost_by_id"
  2728. */
  2729. public function serviceRepostById($iAuthorId, $iOwnerId, $iEventId, $bForce = false)
  2730. {
  2731. $aEvent = $this->_oDb->getEntriesBy(array('type' => 'id', 'id' => $iEventId));
  2732. if(empty($aEvent) || !is_array($aEvent))
  2733. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2734. $sType = $aEvent['type'];
  2735. $sAction = $aEvent['action'];
  2736. $iObjectId = $this->_oConfig->isSystem($sType, $sAction) ? $aEvent['object_id'] : $aEvent['id'];
  2737. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  2738. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  2739. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2740. if(empty($aReposted) || !is_array($aReposted))
  2741. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2742. $aRepostedData = unserialize($aEvent['content']);
  2743. $sType = $aRepostedData['type'];
  2744. $sAction = $aRepostedData['action'];
  2745. $iObjectId = $aRepostedData['object_id'];
  2746. }
  2747. return $this->repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, false, $bForce);
  2748. }
  2749. public function isReposted($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId)
  2750. {
  2751. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2752. if(empty($aReposted) || !is_array($aReposted))
  2753. return false;
  2754. if(str_replace($this->_oConfig->getPrefix('common_post'), '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  2755. $aRepostedData = unserialize($aReposted['content']);
  2756. $aReposted = $this->_oDb->getReposted($aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
  2757. if(empty($aReposted) || !is_array($aReposted))
  2758. return false;
  2759. }
  2760. return $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  2761. }
  2762. public function repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $mixedData = false, $bForce = false)
  2763. {
  2764. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  2765. if(empty($aReposted) || !is_array($aReposted))
  2766. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2767. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  2768. if(!$bForce && $mixedAllowed !== true)
  2769. return array('code' => 2, 'message' => strip_tags($mixedAllowed));
  2770. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  2771. if($bReposted)
  2772. return array('code' => 3, 'message' => _t('_bx_timeline_txt_err_already_reposted'));
  2773. $iDate = time();
  2774. $iId = $this->_oDb->insertEvent([
  2775. 'owner_id' => $iOwnerId,
  2776. 'system' => 0,
  2777. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  2778. 'action' => '',
  2779. 'object_id' => $iAuthorId,
  2780. 'object_owner_id' => $iAuthorId,
  2781. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  2782. 'content' => serialize([
  2783. 'type' => $sType,
  2784. 'action' => $sAction,
  2785. 'object_id' => $iObjectId,
  2786. 'rdata' => $mixedData
  2787. ]),
  2788. 'title' => '',
  2789. 'description' => '',
  2790. 'date' => $iDate,
  2791. 'reacted' => $iDate,
  2792. 'status_admin' => $this->getStatusAdmin()
  2793. ]);
  2794. if(empty($iId))
  2795. return array('code' => 4, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  2796. $this->_oDb->updateEvent([
  2797. 'source' => $this->getName() . '_' . $iAuthorId . '_' . $iId
  2798. ], ['id' => $iId]);
  2799. $this->onRepost($iId, $aReposted);
  2800. return $iId;
  2801. }
  2802. /**
  2803. * @page service Service Calls
  2804. * @section bx_timeline Timeline
  2805. * @subsection bx_timeline-other Other
  2806. * @subsubsection bx_timeline-update update
  2807. *
  2808. * @code bx_srv('bx_timeline', 'update', [...]); @endcode
  2809. *
  2810. * Update timeline event by ID.
  2811. *
  2812. * @param $iEventId integer value with event ID.
  2813. * @param $aSet an array with key=>value pairs for fields which should be updated.
  2814. * @return boolean value with the result of operation.
  2815. *
  2816. * @see BxTimelineModule::serviceUpdate
  2817. */
  2818. /**
  2819. * @ref bx_timeline-update "update"
  2820. */
  2821. public function serviceUpdate($iEventId, $aSet)
  2822. {
  2823. if(empty($iEventId))
  2824. return false;
  2825. return (int)$this->_oDb->updateEvent($aSet, array('id' => $iEventId)) > 0;
  2826. }
  2827. /**
  2828. * @page service Service Calls
  2829. * @section bx_timeline Timeline
  2830. * @subsection bx_timeline-other Other
  2831. * @subsubsection bx_timeline-delete delete
  2832. *
  2833. * @code bx_srv('bx_timeline', 'delete', [...]); @endcode
  2834. *
  2835. * Delete timeline event by ID.
  2836. *
  2837. * @param $iId integer value with event ID.
  2838. * @return boolean value with the result of operation.
  2839. *
  2840. * @see BxTimelineModule::serviceDelete
  2841. */
  2842. /**
  2843. * @ref bx_timeline-delete "delete"
  2844. */
  2845. public function serviceDelete($iId)
  2846. {
  2847. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2848. if(empty($aEvent) || !is_array($aEvent))
  2849. return true;
  2850. if($this->isAllowedDelete($aEvent, true) !== true || !$this->deleteEvent($aEvent))
  2851. return false;
  2852. return true;
  2853. }
  2854. /**
  2855. * @page service Service Calls
  2856. * @section bx_timeline Timeline
  2857. * @subsection bx_timeline-other Other
  2858. * @subsubsection bx_timeline-get_menu_item_addon_comment get_menu_item_addon_comment
  2859. *
  2860. * @code bx_srv('bx_timeline', 'get_menu_item_addon_comment', [...]); @endcode
  2861. *
  2862. * Get addon for Comment menu item.
  2863. * NOTE. The service isn't used for now because comment functionality in card was updated.
  2864. *
  2865. * @param $sSystem string value with comments engine system.
  2866. * @param $iObjectId integer value with object ID.
  2867. * @return HTML string to display in menu item.
  2868. *
  2869. * @see BxTimelineModule::serviceGetMenuItemAddonComment
  2870. */
  2871. /**
  2872. * @ref bx_timeline-get_menu_item_addon_comment "get_menu_item_addon_comment"
  2873. */
  2874. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId, $aBrowseParams = array())
  2875. {
  2876. if(empty($sSystem) || empty($iObjectId))
  2877. return '';
  2878. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  2879. if($oCmts === false)
  2880. return '';
  2881. $iCounter = (int)$oCmts->getCommentsCount();
  2882. if(empty($iCounter))
  2883. return '';
  2884. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter, array(
  2885. 'class' => 'bx-menu-item-addon',
  2886. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  2887. 'onclick' => "javascript:" . $this->_oConfig->getJsObjectView($aBrowseParams) . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  2888. ));
  2889. }
  2890. /**
  2891. * @page service Service Calls
  2892. * @section bx_timeline Timeline
  2893. * @subsection bx_timeline-other Other
  2894. * @subsubsection bx_timeline-get_settings_checker_helper get_settings_checker_helper
  2895. *
  2896. * @code bx_srv('bx_timeline', 'get_settings_checker_helper', [...]); @endcode
  2897. *
  2898. * Get Checker Helper class name for Forms engine.
  2899. *
  2900. * @return string with Checker Helper class name.
  2901. *
  2902. * @see BxTimelineModule::serviceGetSettingsCheckerHelper
  2903. */
  2904. /**
  2905. * @ref bx_timeline-get_settings_checker_helper "get_settings_checker_helper"
  2906. */
  2907. public function serviceGetSettingsCheckerHelper()
  2908. {
  2909. bx_import('FormCheckerHelper', $this->_aModule);
  2910. return 'BxTimelineFormCheckerHelper';
  2911. }
  2912. /**
  2913. * @page service Service Calls
  2914. * @section bx_timeline Timeline
  2915. * @subsection bx_timeline-other Other
  2916. * @subsubsection bx_timeline-get_options_videos_preload get_options_videos_preload
  2917. *
  2918. * @code bx_srv('bx_timeline', 'get_options_videos_preload', [...]); @endcode
  2919. *
  2920. * Get an array with available options for 'Videos preload in Timeline' setting.
  2921. *
  2922. * @return an array with available options represented as key => value pairs.
  2923. *
  2924. * @see BxTimelineModule::serviceGetOptionsVideosPreload
  2925. */
  2926. /**
  2927. * @ref bx_timeline-get_options_videos_preload "get_options_videos_preload"
  2928. */
  2929. public function serviceGetOptionsVideosPreload()
  2930. {
  2931. $CNF = &$this->_oConfig->CNF;
  2932. $aOptions = array('auto', 'metadata', 'none');
  2933. $aResult = array();
  2934. foreach($aOptions as $sOption)
  2935. $aResult[] = array(
  2936. 'key' => $sOption,
  2937. 'value' => _t($CNF['T']['option_vp_' . $sOption])
  2938. );
  2939. return $aResult;
  2940. }
  2941. /**
  2942. * @page service Service Calls
  2943. * @section bx_timeline Timeline
  2944. * @subsection bx_timeline-other Other
  2945. * @subsubsection bx_timeline-get_options_videos_autoplay get_options_videos_autoplay
  2946. *
  2947. * @code bx_srv('bx_timeline', 'get_options_videos_autoplay', [...]); @endcode
  2948. *
  2949. * Get an array with available options for 'Videos autoplay in Timeline' setting.
  2950. *
  2951. * @return an array with available options represented as key => value pairs.
  2952. *
  2953. * @see BxTimelineModule::serviceGetOptionsVideosAutoplay
  2954. */
  2955. /**
  2956. * @ref bx_timeline-get_options_videos_autoplay "get_options_videos_autoplay"
  2957. */
  2958. public function serviceGetOptionsVideosAutoplay()
  2959. {
  2960. $CNF = &$this->_oConfig->CNF;
  2961. $aOptions = array(BX_TIMELINE_VAP_OFF, BX_TIMELINE_VAP_ON_MUTE, BX_TIMELINE_VAP_ON);
  2962. $aResult = array();
  2963. foreach($aOptions as $sOption)
  2964. $aResult[] = array(
  2965. 'key' => $sOption,
  2966. 'value' => _t($CNF['T']['option_vap_' . $sOption])
  2967. );
  2968. return $aResult;
  2969. }
  2970. /**
  2971. * @page service Service Calls
  2972. * @section bx_timeline Timeline
  2973. * @subsection bx_timeline-other Other
  2974. * @subsubsection bx_timeline-get_options_attachments_layout get_options_attachments_layout
  2975. *
  2976. * @code bx_srv('bx_timeline', 'get_options_attachments_layout', [...]); @endcode
  2977. *
  2978. * Get an array with available options for 'Show attachments as' setting.
  2979. *
  2980. * @return an array with available options represented as key => value pairs.
  2981. *
  2982. * @see BxTimelineModule::serviceGetOptionsAttachmentsLayout
  2983. */
  2984. /**
  2985. * @ref bx_timeline-get_options_attachments_layout "get_options_attachments_layout"
  2986. */
  2987. public function serviceGetOptionsAttachmentsLayout()
  2988. {
  2989. $CNF = &$this->_oConfig->CNF;
  2990. $aOptions = array(BX_TIMELINE_ML_GALLERY, BX_TIMELINE_ML_SHOWCASE);
  2991. $aResult = array();
  2992. foreach($aOptions as $sOption)
  2993. $aResult[] = array(
  2994. 'key' => $sOption,
  2995. 'value' => _t($CNF['T']['option_al_' . $sOption])
  2996. );
  2997. return $aResult;
  2998. }
  2999. /**
  3000. * @page service Service Calls
  3001. * @section bx_timeline Timeline
  3002. * @subsection bx_timeline-other Other
  3003. * @subsubsection bx_timeline-get_live_update get_live_update
  3004. *
  3005. * @code bx_srv('bx_timeline', 'get_live_update', [...]); @endcode
  3006. *
  3007. * Get an array with actual Live Update info. Only one live update notification for all new events.
  3008. *
  3009. * @return an array with Live Update info.
  3010. *
  3011. * @see BxTimelineModule::serviceGetLiveUpdate
  3012. */
  3013. /**
  3014. * @ref bx_timeline-get_live_update "get_live_update"
  3015. */
  3016. public function serviceGetLiveUpdate($aBrowseParams, $iProfileId, $iValue = 0, $iInit = 0)
  3017. {
  3018. $CNF = &$this->_oConfig->CNF;
  3019. if (!is_array($aBrowseParams)){
  3020. $aTmp = json_decode($aBrowseParams, true);
  3021. $aBrowseParams = $aTmp['params'];
  3022. }
  3023. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  3024. bx_import('BxDolSession');
  3025. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  3026. return false;
  3027. $aParams = $this->_prepareParams($aBrowseParams);
  3028. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  3029. if(($iLiveUpdateLength = $this->_oConfig->getLiveUpdateLength()) != 0)
  3030. $aParams['per_page'] = $iLiveUpdateLength;
  3031. $aEvents = $this->_oDb->getEvents($aParams);
  3032. if(empty($aEvents) || !is_array($aEvents))
  3033. return false;
  3034. $iValueNew = 0;
  3035. foreach($aEvents as $aEvent) {
  3036. if((int)$aEvent[$CNF['FIELD_STICKED']] != 0)
  3037. continue;
  3038. $sContent = $this->_oTemplate->getPost($aEvent, $aParams);
  3039. if(empty($sContent))
  3040. continue;
  3041. $iValueNew = $aEvent['id'];
  3042. break;
  3043. }
  3044. if($iValueNew == $iValue)
  3045. return false;
  3046. if($this->_bIsApi)
  3047. return $iValueNew;
  3048. if((int)$iInit != 0)
  3049. return array('count' => $iValueNew);
  3050. return array(
  3051. 'count' => $iValueNew, // required (for initialization and visualization)
  3052. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdate(oData)', // required (for visualization)
  3053. 'data' => array(
  3054. 'code' => $this->_oTemplate->getLiveUpdate($aBrowseParams, $iProfileId, $iValue, $iValueNew)
  3055. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  3056. );
  3057. }
  3058. /**
  3059. * @page service Service Calls
  3060. * @section bx_timeline Timeline
  3061. * @subsection bx_timeline-other Other
  3062. * @subsubsection bx_timeline-get_live_updates get_live_updates
  3063. *
  3064. * @code bx_srv('bx_timeline', 'get_live_updates', [...]); @endcode
  3065. *
  3066. * Get an array with actual Live Update info. Separate live update notification for each new Event.
  3067. * Note. This method isn't used for now. @see BxTimelineModule::serviceGetLiveUpdate method instead.
  3068. *
  3069. * Note. This way to display live update notifications isn't used for now.
  3070. * See BxTimelineModule::serviceGetLiveUpdate method instead.
  3071. *
  3072. * @return an array with Live Update info.
  3073. *
  3074. * @see BxTimelineModule::serviceGetLiveUpdates
  3075. */
  3076. /**
  3077. * @ref bx_timeline-get_live_updates "get_live_updates"
  3078. */
  3079. public function serviceGetLiveUpdates($aBrowseParams, $iProfileId, $iCount = 0, $iInit = 0)
  3080. {
  3081. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  3082. bx_import('BxDolSession');
  3083. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  3084. return false;
  3085. $aParams = $this->_prepareParams($aBrowseParams);
  3086. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  3087. $aParams['count'] = true;
  3088. $iCountNew = $this->_oDb->getEvents($aParams);
  3089. if($iCountNew == $iCount)
  3090. return false;
  3091. if((int)$iInit != 0)
  3092. return array('count' => $iCountNew);
  3093. return array(
  3094. 'count' => $iCountNew, // required (for initialization and visualization)
  3095. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdates(oData)', // required (for visualization)
  3096. 'data' => array(
  3097. 'code' => $this->_oTemplate->getLiveUpdates($aBrowseParams, $iProfileId, $iCount, $iCountNew)
  3098. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  3099. );
  3100. }
  3101. /**
  3102. * @page service Service Calls
  3103. * @section bx_timeline Accounts
  3104. * @subsection bx_timeline-other Other
  3105. * @subsubsection bx_timeline-get_menu_addon_manage_tools get_menu_addon_manage_tools
  3106. *
  3107. * @code bx_srv('bx_timeline', 'get_menu_addon_manage_tools', [...]); @endcode
  3108. *
  3109. * Get number of 'hidden' events for User End -> Dasboard page -> Manage block.
  3110. *
  3111. * @return integer number of 'hidden' events
  3112. *
  3113. * @see BxTimelineModule::serviceGetMenuAddonManageTools
  3114. */
  3115. /**
  3116. * @ref bx_timeline-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
  3117. */
  3118. public function serviceGetMenuAddonManageTools()
  3119. {
  3120. $iNum1 = $this->_oDb->getEntriesNumByParams([
  3121. [
  3122. 'key' => 'status',
  3123. 'value' => BX_TIMELINE_STATUS_HIDDEN,
  3124. 'operator' => '='
  3125. ]
  3126. ]);
  3127. $iNum2 = $this->_oDb->getEntriesNumByParams([
  3128. [
  3129. 'key' => 'reports',
  3130. 'value' => '0',
  3131. 'operator' => '>'
  3132. ]
  3133. ]);
  3134. return array(
  3135. 'counter1_value' => $iNum1,
  3136. 'counter2_value' => $iNum2,
  3137. 'counter3_value' => 0
  3138. );
  3139. }
  3140. /**
  3141. * @page service Service Calls
  3142. * @section bx_timeline Accounts
  3143. * @subsection bx_timeline-other Other
  3144. * @subsubsection bx_timeline-get_menu_addon_profile_stats get_menu_addon_profile_stats
  3145. *
  3146. * @code bx_srv('bx_timeline', 'get_menu_addon_profile_stats', [...]); @endcode
  3147. *
  3148. * Get number of 'muted' events for currently logged in user. User End -> Profile Stats.
  3149. *
  3150. * @return integer number of 'muted' events
  3151. *
  3152. * @see BxTimelineModule::serviceGetMenuAddonProfileStats
  3153. */
  3154. /**
  3155. * @ref bx_timeline-get_menu_addon_profile_stats "get_menu_addon_profile_stats"
  3156. */
  3157. public function serviceGetMenuAddonProfileStats($iProfileId = 0)
  3158. {
  3159. if(empty($iProfileId))
  3160. $iProfileId = $this->_iProfileId;
  3161. return $this->getConnectionMuteObject()->getConnectedContentCount($iProfileId);
  3162. }
  3163. public function serviceGet($aParams)
  3164. {
  3165. if($this->_bIsApi && is_string($aParams))
  3166. $aParams = bx_api_get_browse_params($aParams, true);
  3167. $aParams = $this->_prepareParams($aParams);
  3168. $aParams['return_data_type'] = 'array';
  3169. return $this->_oTemplate->getPosts($aParams);
  3170. }
  3171. public function serviceAdd($aValues)
  3172. {
  3173. return $this->getFormPost(array(
  3174. 'values' => $aValues
  3175. ));
  3176. }
  3177. public function serviceEdit($iId, $aValues)
  3178. {
  3179. return $this->getFormEdit($iId, array(
  3180. 'values' => $aValues
  3181. ));
  3182. }
  3183. /**
  3184. * Delete content entry
  3185. * @param $iContentId content id
  3186. * @return error message or empty string on success
  3187. */
  3188. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  3189. {
  3190. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3191. if(empty($aEvent) || !is_array($aEvent))
  3192. return _t('_Empty');
  3193. if(!$this->deleteEvent($aEvent))
  3194. return _t('_bx_timeline_txt_err_cannot_perform_action');
  3195. return '';
  3196. }
  3197. public function serviceGetEvents($aParams = [])
  3198. {
  3199. return $this->_oDb->getEvents($aParams);
  3200. }
  3201. public function serviceGetEventsByDescriptor($sType, $sAction, $iObjectId)
  3202. {
  3203. return $this->_oDb->getEvents([
  3204. 'browse' => 'descriptor',
  3205. 'type' => $sType,
  3206. 'action' => $sAction,
  3207. 'object_id' => $iObjectId
  3208. ]);
  3209. }
  3210. /*
  3211. * COMMON METHODS
  3212. */
  3213. public function getStatusAdmin()
  3214. {
  3215. return $this->isModerator() || $this->_oConfig->isAutoApproveEnabled() ? BX_TIMELINE_STATUS_ACTIVE : BX_TIMELINE_STATUS_PENDING;
  3216. }
  3217. public function getItemData($iId, $aParams = array())
  3218. {
  3219. $CNF = &$this->_oConfig->CNF;
  3220. if(empty($aParams))
  3221. $aParams = $this->_prepareParams(array(
  3222. 'view' => BX_TIMELINE_VIEW_ITEM,
  3223. 'type' => BX_TIMELINE_TYPE_ITEM
  3224. ));
  3225. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  3226. if(empty($aEvent))
  3227. return array('code' => 1, 'content' => _t('_Empty'));
  3228. $iProfile = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  3229. if(!empty($iProfile)) {
  3230. $oProfile = BxDolProfile::getInstance($iProfile);
  3231. if(!$oProfile)
  3232. return array('code' => 1, 'content' => _t('_Empty'));
  3233. $mixedResult = $oProfile->checkAllowedProfileView();
  3234. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  3235. return array('code' => 2, 'content' => $mixedResult);
  3236. }
  3237. $sContent = $this->_oTemplate->getPost($aEvent, $aParams);
  3238. if(empty($sContent))
  3239. return array('code' => 2, 'content' => _t('_Access denied'));
  3240. $sKey = 'allowed_view';
  3241. if(isset($aEvent[$sKey]) && $aEvent[$sKey] !== CHECK_ACTION_RESULT_ALLOWED)
  3242. return array('code' => 2, 'content' => $aEvent[$sKey]);
  3243. if($this->isAllowedView($aEvent) !== true)
  3244. return array('code' => 2, 'content' => _t('_Access denied'));
  3245. return array('code' => 0, 'content' => $sContent, 'event' => $aEvent);
  3246. }
  3247. public function hideEvent($aEvent)
  3248. {
  3249. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->updateEvent(['status' => 'hidden'], ['id' => (int)$aEvent['id']]))
  3250. return false;
  3251. $this->onHide($aEvent);
  3252. return true;
  3253. }
  3254. public function deleteEvent($aEvent)
  3255. {
  3256. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  3257. return false;
  3258. $this->onDelete($aEvent);
  3259. return true;
  3260. }
  3261. public function getFormPost($aParams = [])
  3262. {
  3263. $CNF = &$this->_oConfig->CNF;
  3264. $iUserId = $this->getUserId();
  3265. $oForm = $this->getFormPostObject($aParams);
  3266. $aFormInitCheckerParams = [];
  3267. $bValues = !empty($aParams['values']) && is_array($aParams['values']);
  3268. if($bValues) {
  3269. $this->_prepareFormForAutoSubmit($oForm, $aParams['values']);
  3270. $aFormInitCheckerParams = [[], $aParams['values']];
  3271. unset($aParams['values']);
  3272. }
  3273. call_user_func_array([$oForm, 'initChecker'], $aFormInitCheckerParams);
  3274. $bAjaxMode = $oForm->isAjaxMode();
  3275. $bDynamicMode = $bAjaxMode;
  3276. if($oForm->isSubmittedAndValid()) {
  3277. $sType = $oForm->getCleanValue('type');
  3278. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  3279. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  3280. $aContent = [];
  3281. //--- Process Text ---//
  3282. $sText = $oForm->getCleanValue('text');
  3283. $sText = $this->_prepareTextForSave($sText);
  3284. $bText = !empty($sText);
  3285. if($bText)
  3286. $aContent['text'] = $sText;
  3287. //--- Process Context and Privacy ---//
  3288. $iOwnerId = (int)$oForm->getCleanValue('owner_id');
  3289. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  3290. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  3291. if(empty($iObjectPrivacyView))
  3292. $iObjectPrivacyView = $iObjectPrivacyViewDefault;
  3293. else if($iObjectPrivacyView < 0)
  3294. $iOwnerId = abs($iObjectPrivacyView);
  3295. //--- Process Link ---//
  3296. $aLinkIds = $oForm->getCleanValue($CNF['FIELD_LINK']);
  3297. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  3298. //--- Process Photos ---//
  3299. $aPhotoIds = $oForm->getCleanValue($CNF['FIELD_PHOTO']);
  3300. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  3301. //--- Process Videos ---//
  3302. $aVideoIds = $oForm->getCleanValue($CNF['FIELD_VIDEO']);
  3303. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  3304. //--- Process Files ---//
  3305. $aFileIds = $oForm->getCleanValue($CNF['FIELD_FILE']);
  3306. $bFileIds = !empty($aFileIds) && is_array($aFileIds);
  3307. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds && !$bFileIds) {
  3308. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  3309. $oForm->setValid(false);
  3310. if(bx_is_api())
  3311. return ['form_object' => $oForm];
  3312. return $this->_prepareResponse([
  3313. 'form' => $oForm->getCode($bDynamicMode),
  3314. 'form_id' => $oForm->id
  3315. ], $bAjaxMode);
  3316. }
  3317. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $this->_oConfig->getTitleDefault($bLinkIds, $bPhotoIds, $bVideoIds, $bFileIds);
  3318. $sDescription = _t('_bx_timeline_txt_user_added_sample', '{profile_name}', _t('_bx_timeline_txt_sample_with_article'));
  3319. /**
  3320. * Unset 'text' input because its data was already processed
  3321. * and will be saved via additional values which were passed
  3322. * to BxDolForm::insert method.
  3323. */
  3324. unset($oForm->aInputs['text']['db']);
  3325. $oForm->aInputs['text']['value'] = '';
  3326. $iId = $oForm->insert([
  3327. 'owner_id' => $iOwnerId,
  3328. 'object_id' => $iUserId,
  3329. 'object_owner_id' => $iUserId,
  3330. 'object_privacy_view' => $iObjectPrivacyView,
  3331. 'content' => serialize($aContent),
  3332. 'title' => $sTitle,
  3333. 'description' => $sDescription,
  3334. 'status_admin' => $this->getStatusAdmin()
  3335. ]);
  3336. if(!empty($iId)) {
  3337. $this->isAllowedPost(true);
  3338. $sSource = $this->getName() . '_' . $iUserId . '_' . $iId;
  3339. $aContent = array_merge($aContent, [
  3340. 'timeline_group' => [
  3341. 'by' => $sSource,
  3342. 'field' => 'owner_id'
  3343. ]
  3344. ]);
  3345. $this->_oDb->updateEvent(['content' => serialize($aContent), 'source' => $sSource], ['id' => $iId]);
  3346. //--- Process Meta ---//
  3347. $this->_processMetas($iId, $sText);
  3348. //--- Process Link ---//
  3349. if($bLinkIds)
  3350. foreach($aLinkIds as $iLinkId)
  3351. $this->_oDb->saveLink($iId, $iLinkId);
  3352. //--- Process Media ---//
  3353. $this->_saveMedia($CNF['FIELD_PHOTO'], $iId, $aPhotoIds, $iUserId, true);
  3354. $this->_saveMedia($CNF['FIELD_VIDEO'], $iId, $aVideoIds, $iUserId, true);
  3355. $this->_saveMedia($CNF['FIELD_FILE'], $iId, $aFileIds, $iUserId, true);
  3356. $this->onPost($iId);
  3357. if(bx_is_api())
  3358. return ['form_object' => $oForm, 'id' => $iId];
  3359. return $this->_prepareResponse(['id' => $iId], $bAjaxMode, [
  3360. 'redirect' => $this->_oConfig->getItemViewUrl(['id' => $iId])
  3361. ]);
  3362. }
  3363. return $this->_prepareResponse(['message' => _t('_bx_timeline_txt_err_cannot_perform_action')], $bAjaxMode);
  3364. }
  3365. if(bx_is_api())
  3366. return ['form_object' => $oForm];
  3367. $mixedResult = $this->_prepareResponse([
  3368. 'form' => $oForm->getCode($bDynamicMode),
  3369. 'form_id' => $oForm->id
  3370. ], $bAjaxMode && $oForm->isSubmitted());
  3371. if(is_array($mixedResult))
  3372. $mixedResult['form_object'] = $oForm;
  3373. return $mixedResult;
  3374. }
  3375. public function getFormEdit($iId, $aParams = [], $aBrowseParams = [])
  3376. {
  3377. $CNF = &$this->_oConfig->CNF;
  3378. $sJsObjectView = $this->_oConfig->getJsObjectView($aBrowseParams);
  3379. $iUserId = $this->getUserId();
  3380. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iId]);
  3381. if(empty($aEvent) || !is_array($aEvent))
  3382. return [];
  3383. if(($mixedCheck = $this->isAllowedEdit($aEvent)) !== true)
  3384. return $this->_bIsApi ? bx_api_get_msg($mixedCheck !== false ? $mixedCheck : _t('_sys_txt_access_denied')) : ['message' => $mixedCheck !== false ? $mixedCheck : _t('_sys_txt_access_denied')];
  3385. $aContent = unserialize($aEvent['content']);
  3386. if(is_array($aContent) && !empty($aContent['text']))
  3387. $aEvent['text'] = $aContent['text'];
  3388. if(empty($aParams['form_object']))
  3389. $aParams['form_object'] = 'form_post';
  3390. if(empty($aParams['form_display']))
  3391. $aParams['form_display'] = 'form_display_post_edit';
  3392. $oForm = $this->getFormPostObject($aParams);
  3393. $oForm->setId($this->_oConfig->getHtmlIds('view', 'edit_form') . $iId);
  3394. $aFormInitCheckerParams = [];
  3395. $bValues = !empty($aParams['values']) && is_array($aParams['values']);
  3396. if($bValues) {
  3397. $this->_prepareFormForAutoSubmit($oForm, $aParams['values']);
  3398. $aFormInitCheckerParams = [[], array_merge($aEvent, $aParams['values'])];
  3399. unset($aParams['values']);
  3400. }
  3401. else {
  3402. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit/' . $iId ;
  3403. if(!empty($aBrowseParams) && is_array($aBrowseParams))
  3404. $oForm->aFormAttrs['action'] = $this->_oConfig->addBrowseParams($oForm->aFormAttrs['action'], $aBrowseParams);
  3405. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  3406. if(!is_numeric($mixedIndex))
  3407. continue;
  3408. $oForm->aInputs[$CNF['FIELD_CONTROLS']][$mixedIndex]['attrs'] = bx_replace_markers($aInput['attrs'], [
  3409. 'js_object_view' => $sJsObjectView,
  3410. 'content_id' => $iId
  3411. ]);
  3412. }
  3413. $aFormInitCheckerParams = [$aEvent];
  3414. }
  3415. call_user_func_array([$oForm, 'initChecker'], $aFormInitCheckerParams);
  3416. $bAjaxMode = $oForm->isAjaxMode();
  3417. $bDynamicMode = $bAjaxMode || bx_is_dynamic_request();
  3418. $sCodeAdd = '';
  3419. if($bDynamicMode) {
  3420. $sCodeAdd .= $this->_oTemplate->getAddedJs('post', $bDynamicMode);
  3421. $sCodeAdd .= $this->_oTemplate->getJsCode('post', [], true, $bDynamicMode);
  3422. }
  3423. if($oForm->isSubmittedAndValid()) {
  3424. $aContent = unserialize($aEvent['content']);
  3425. //--- Process Text ---//
  3426. $sText = $oForm->getCleanValue('text');
  3427. $sText = $this->_prepareTextForSave($sText);
  3428. $bText = !empty($sText);
  3429. unset($oForm->aInputs['text']);
  3430. if($bText)
  3431. $aContent['text'] = $sText;
  3432. $aValsToAdd = [
  3433. 'content' => serialize($aContent),
  3434. 'status_admin' => $this->getStatusAdmin()
  3435. ];
  3436. //--- Process Privacy ---//
  3437. if(isset($oForm->aInputs[$CNF['FIELD_OBJECT_PRIVACY_VIEW']])) {
  3438. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  3439. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  3440. if(empty($iObjectPrivacyView))
  3441. $aValsToAdd = array_merge($aValsToAdd, [
  3442. 'object_privacy_view' => $iObjectPrivacyViewDefault
  3443. ]);
  3444. else if($iObjectPrivacyView < 0)
  3445. $aValsToAdd = array_merge($aValsToAdd, [
  3446. 'owner_id' => abs($iObjectPrivacyView)
  3447. ]);
  3448. }
  3449. //--- Process Link ---//
  3450. $aLinkIds = $oForm->getCleanValue($CNF['FIELD_LINK']);
  3451. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  3452. //--- Process Media ---//
  3453. $aPhotoIds = $oForm->getCleanValue($CNF['FIELD_PHOTO']);
  3454. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  3455. $aVideoIds = $oForm->getCleanValue($CNF['FIELD_VIDEO']);
  3456. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  3457. if($bVideoIds && ($mixedCheckResult = $this->_checkMedia($CNF['FIELD_VIDEO'], $iId, $aVideoIds, $iUserId)) !== false) {
  3458. list($bHasImage, $bHasVideo, $bIsVideoProcessed) = $mixedCheckResult;
  3459. if($bHasVideo && !$bIsVideoProcessed)
  3460. $aValsToAdd[$CNF['FIELD_STATUS']] = 'awaiting';
  3461. }
  3462. $aFileIds = $oForm->getCleanValue($CNF['FIELD_FILE']);
  3463. $bFileIds = !empty($aFileIds) && is_array($aFileIds);
  3464. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds && !$bFileIds) {
  3465. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  3466. $oForm->setValid(false);
  3467. return $this->_bIsApi ? ['form' => $oForm->getCodeAPI()] : $this->_prepareResponse([
  3468. 'form' => $sCodeAdd . $oForm->getCode($bDynamicMode),
  3469. 'form_id' => $oForm->id
  3470. ], $bAjaxMode);
  3471. }
  3472. if($oForm->update($iId, $aValsToAdd) === false)
  3473. return $this->_bIsApi ? bx_api_get_msg(_t('_bx_timeline_txt_err_cannot_perform_action')) : ['message' => _t('_bx_timeline_txt_err_cannot_perform_action')];
  3474. $this->isAllowedEdit($aEvent, true);
  3475. //--- Process Meta ---//
  3476. $this->_processMetas($iId, $sText);
  3477. //--- Process Link ---//
  3478. if($bLinkIds)
  3479. foreach($aLinkIds as $iLinkId)
  3480. $this->_oDb->saveLink($iId, $iLinkId);
  3481. //--- Process Media ---//
  3482. $this->_saveMedia($CNF['FIELD_PHOTO'], $iId, $aPhotoIds, $iUserId);
  3483. $this->_saveMedia($CNF['FIELD_VIDEO'], $iId, $aVideoIds, $iUserId);
  3484. $this->_saveMedia($CNF['FIELD_FILE'], $iId, $aFileIds, $iUserId);
  3485. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iId);
  3486. $this->onEdit($iId);
  3487. return $this->_bIsApi ? [ 'id' => $iId ] : [ 'id' => $iId ];
  3488. }
  3489. return $this->_bIsApi ? ['form' => $oForm->getCodeAPI()] : [
  3490. 'id' => $iId,
  3491. 'form' => $sCodeAdd . $oForm->getCode($bDynamicMode),
  3492. 'form_id' => $oForm->id,
  3493. 'eval' => $sJsObjectView . '.onEditPost(oData)'
  3494. ];
  3495. }
  3496. public function getFormPostObject($aParams)
  3497. {
  3498. $CNF = &$this->_oConfig->CNF;
  3499. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  3500. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  3501. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  3502. $oForm->aFormAttrs = bx_replace_markers($oForm->aFormAttrs, [
  3503. 'js_object_post' => $this->_oConfig->getJsObject('post')
  3504. ]);
  3505. $sParamsKey = 'type';
  3506. if(!empty($aParams[$sParamsKey]))
  3507. $oForm->setType($aParams[$sParamsKey]);
  3508. /**
  3509. * Note. 'ajax_mode' parameter isn't checked because
  3510. * timeline post form works as Ajax form by default.
  3511. */
  3512. $sParamsKey = 'visibility_autoselect';
  3513. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  3514. $oForm->setVisibilityAutoselect((bool)$aParams[$sParamsKey]);
  3515. $sKey = 'FIELD_LABELS';
  3516. if(isset($oForm->aInputs[$CNF[$sKey]], $aParams['type']) && empty($oForm->aInputs[$CNF[$sKey]]['value']) && $aParams['type'] == BX_BASE_MOD_NTFS_TYPE_OWNER) {
  3517. $iContextProfileId = !empty($aParams['context_id']) ? abs($aParams['context_id']) : $this->_iOwnerId;
  3518. if(($oContextProfile = BxDolProfile::getInstance($iContextProfileId)) !== false) {
  3519. $sMethod = 'is_fan';
  3520. $sModule = $oContextProfile->getModule();
  3521. if(bx_is_srv($sModule, $sMethod) && bx_srv($sModule, $sMethod, [$iContextProfileId, (int)bx_get_logged_profile_id()])) {
  3522. $aContextInfo = bx_srv($sModule, 'get_content_info_by_profile_id', [$iContextProfileId]);
  3523. if(!empty($aContextInfo['hashtag']))
  3524. $oForm->aInputs[$CNF[$sKey]]['value'] = [$aContextInfo['hashtag']];
  3525. }
  3526. }
  3527. }
  3528. $oForm->init();
  3529. return $oForm;
  3530. }
  3531. public function getCmtsObject($sSystem, $iId)
  3532. {
  3533. if(empty($sSystem) || (int)$iId == 0)
  3534. return false;
  3535. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3536. if(!$oCmts || !$oCmts->isEnabled())
  3537. return false;
  3538. return $oCmts;
  3539. }
  3540. public function getViewObject($sSystem, $iId)
  3541. {
  3542. if(empty($sSystem) || (int)$iId == 0)
  3543. return false;
  3544. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3545. if(!$oView || !$oView->isEnabled())
  3546. return false;
  3547. return $oView;
  3548. }
  3549. public function getVoteObject($sSystem, $iId)
  3550. {
  3551. if(empty($sSystem) || (int)$iId == 0)
  3552. return false;
  3553. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3554. if(!$oVote || !$oVote->isEnabled())
  3555. return false;
  3556. return $oVote;
  3557. }
  3558. public function getReactionObject($sSystem, $iId)
  3559. {
  3560. if(empty($sSystem) || (int)$iId == 0)
  3561. return false;
  3562. $oReaction = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3563. if(!$oReaction || !$oReaction->isEnabled())
  3564. return false;
  3565. return $oReaction;
  3566. }
  3567. public function getScoreObject($sSystem, $iId)
  3568. {
  3569. if(empty($sSystem) || (int)$iId == 0)
  3570. return false;
  3571. $oScore = BxDolScore::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3572. if(!$oScore || !$oScore->isEnabled())
  3573. return false;
  3574. return $oScore;
  3575. }
  3576. public function getReportObject($sSystem, $iId)
  3577. {
  3578. if(empty($sSystem) || (int)$iId == 0)
  3579. return false;
  3580. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3581. if(!$oReport || !$oReport->isEnabled())
  3582. return false;
  3583. return $oReport;
  3584. }
  3585. public function getAttachmentsMenuObject()
  3586. {
  3587. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  3588. }
  3589. public function getManageMenuObject()
  3590. {
  3591. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  3592. }
  3593. public function getCacheItemObject()
  3594. {
  3595. $oCacheEngine = bx_instance('BxDolCache' . $this->_oConfig->getCacheItemEngine());
  3596. if(!$oCacheEngine->isAvailable())
  3597. $oCacheEngine = bx_instance('BxDolCacheFile');
  3598. return $oCacheEngine;
  3599. }
  3600. public function getConnectionMuteObject()
  3601. {
  3602. return BxDolConnection::getObjectInstance($this->_oConfig->getObject('connection_mute'));
  3603. }
  3604. //--- Check permissions methods ---//
  3605. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  3606. {
  3607. if(!$iProfileId)
  3608. $iProfileId = $this->_iProfileId;
  3609. $CNF = &$this->_oConfig->CNF;
  3610. // moderator and owner always have access
  3611. $iOwnerId = (int)$aDataEntry['owner_id'];
  3612. if(!empty($iProfileId) && (abs($iOwnerId) == (int)$iProfileId || $this->isModerator()))
  3613. return CHECK_ACTION_RESULT_ALLOWED;
  3614. // check ACL
  3615. if($iOwnerId != 0 && ($oOwner = BxDolProfile::getInstanceMagic($iOwnerId)) !== false && !($oOwner instanceof BxDolProfileUndefined)) {
  3616. $mixedCheckResult = bx_srv($oOwner->getModule(), 'check_allowed_with_content_for_profile', ['view', $oOwner->getContentId(), $iProfileId]);
  3617. if($mixedCheckResult !== CHECK_ACTION_RESULT_ALLOWED)
  3618. return $mixedCheckResult;
  3619. }
  3620. // check privacy
  3621. if(!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  3622. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  3623. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  3624. return _t('_sys_access_denied_to_private_content');
  3625. }
  3626. // check alert to allow custom checks
  3627. $mixedResult = null;
  3628. /**
  3629. * @hooks
  3630. * @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
  3631. * - $unit_name - equals `system`
  3632. * - $action - equals `check_allowed_view`
  3633. * - $object_id - not used
  3634. * - $sender_id - not used
  3635. * - $extra_params - array of additional params with the following array keys:
  3636. * - `module` - [string] module name
  3637. * - `content_info` - [array] content info array as key&value pairs
  3638. * - `profile_id` - [boolean] or [int] profile id to be checked the availability of the action to
  3639. * - `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
  3640. * @hook @ref hook-system-check_allowed_view
  3641. */
  3642. bx_alert('system', 'check_allowed_view', 0, 0, [
  3643. 'module' => $this->getName(),
  3644. 'content_info' => $aDataEntry,
  3645. 'profile_id' => $iProfileId,
  3646. 'override_result' => &$mixedResult
  3647. ]);
  3648. if($mixedResult !== null)
  3649. return $mixedResult;
  3650. return CHECK_ACTION_RESULT_ALLOWED;
  3651. }
  3652. public function isModerator()
  3653. {
  3654. return $this->isModeratorForProfile((int)$this->getUserId());
  3655. }
  3656. public function isModeratorForProfile($iUserId)
  3657. {
  3658. if($this->checkAllowedEditAnyEntryForProfile(false, $iUserId) === CHECK_ACTION_RESULT_ALLOWED)
  3659. return true;
  3660. if($this->checkAllowedDeleteAnyEntryForProfile(false, $iUserId) === CHECK_ACTION_RESULT_ALLOWED)
  3661. return true;
  3662. return false;
  3663. }
  3664. public function isAllowedPost($bPerform = false)
  3665. {
  3666. if(isAdmin())
  3667. return true;
  3668. $iUserId = $this->getUserId();
  3669. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  3670. if($aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  3671. return $aCheckResult[CHECK_ACTION_MESSAGE];
  3672. if(!empty($this->_iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId)) !== false) {
  3673. if($oProfileOwner->checkAllowedPostInProfile($this->_iOwnerId, $this->getName()) !== CHECK_ACTION_RESULT_ALLOWED)
  3674. return _t('_sys_txt_access_denied');
  3675. /**
  3676. * @hooks
  3677. * @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
  3678. * - $unit_name - profile module name
  3679. * - $action - equals `timeline_post`
  3680. * - $object_id - timeline owner profile id
  3681. * - $sender_id - performer profile id
  3682. * - $extra_params - array of additional params with the following array keys:
  3683. * - `check_result` - [array] by ref, check action result, can be overridden in hook processing.
  3684. * @hook @ref hook-bx_base_profile-timeline_post
  3685. */
  3686. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, [
  3687. 'check_result' => &$aCheckResult
  3688. ]);
  3689. }
  3690. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3691. }
  3692. public function isAllowedView($aEvent, $bPerform = false)
  3693. {
  3694. $CNF = $this->_oConfig->CNF;
  3695. if((int)$aEvent[$CNF['FIELD_OWNER_ID']] == 0)
  3696. return true;
  3697. $oProfileOwner = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']]);
  3698. if($oProfileOwner && $oProfileOwner->checkAllowedProfileView() !== CHECK_ACTION_RESULT_ALLOWED)
  3699. return false;
  3700. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  3701. if(!$oPrivacy)
  3702. return true;
  3703. $oPrivacy->setTableFieldAuthor($this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id');
  3704. return $oPrivacy->check($aEvent[$CNF['FIELD_ID']]);
  3705. }
  3706. public function isAllowedEdit($aEvent, $bPerform = false)
  3707. {
  3708. if(!isLogged())
  3709. return false;
  3710. //--- System posts and Reposts cannot be edited at all.
  3711. if(!$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) || $aEvent['type'] == $this->_oConfig->getPrefix('common_post') . 'repost')
  3712. return false;
  3713. if(isAdmin())
  3714. return true;
  3715. $iUserId = (int)$this->getUserId();
  3716. $iOwnerId = (int)$aEvent['owner_id'];
  3717. $iObjectId = abs((int)$aEvent['object_id']);
  3718. if($iObjectId == $iUserId && $this->_oConfig->isAllowEdit())
  3719. return true;
  3720. $aCheckResult = checkActionModule($iUserId, 'edit', $this->getName(), $bPerform);
  3721. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false) {
  3722. if(BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'edit_any')) === CHECK_ACTION_RESULT_ALLOWED)
  3723. return true;
  3724. /**
  3725. * @hooks
  3726. * @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
  3727. * It's equivalent to @ref hook-bx_base_profile-timeline_post
  3728. * @hook @ref hook-bx_base_profile-timeline_edit
  3729. */
  3730. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_edit', $oProfileOwner->id(), $iUserId, [
  3731. 'check_result' => &$aCheckResult
  3732. ]);
  3733. }
  3734. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3735. }
  3736. public function isAllowedDelete($aEvent, $bPerform = false)
  3737. {
  3738. if(!isLogged())
  3739. return false;
  3740. if(isAdmin())
  3741. return true;
  3742. $iUserId = (int)$this->getUserId();
  3743. $iOwnerId = (int)$aEvent['owner_id'];
  3744. $iObjectId = abs((int)$aEvent['object_id']);
  3745. if((($iOwnerId == $iUserId && $this->_oConfig->isAllowDelete()) || ($this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)))
  3746. return true;
  3747. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  3748. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false) {
  3749. if(BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'delete_any')) === CHECK_ACTION_RESULT_ALLOWED)
  3750. return true;
  3751. /**
  3752. * @hooks
  3753. * @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
  3754. * It's equivalent to @ref hook-bx_base_profile-timeline_post
  3755. * @hook @ref hook-bx_base_profile-timeline_delete
  3756. */
  3757. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, [
  3758. 'check_result' => &$aCheckResult
  3759. ]);
  3760. }
  3761. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3762. }
  3763. public function isAllowedComment($aEvent, $bPerform = false)
  3764. {
  3765. $mixedComments = $this->getCommentsData($aEvent['comments']);
  3766. if($mixedComments === false)
  3767. return false;
  3768. list($sSystem, $iObjectId, $iCount) = $mixedComments;
  3769. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  3770. if($oCmts->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED || ($iCount == 0 && !$oCmts->isPostAllowed()))
  3771. return false;
  3772. $oCmts->addCssJs();
  3773. return true;
  3774. }
  3775. public function isAllowedViewCounter($aEvent, $bPerform = false)
  3776. {
  3777. $mixedViews = $this->getViewsData($aEvent['views']);
  3778. if($mixedViews === false)
  3779. return false;
  3780. list($sSystem, $iObjectId) = $mixedViews;
  3781. $oView = $this->getViewObject($sSystem, $iObjectId);
  3782. if(!$oView->isAllowedViewView($bPerform))
  3783. return false;
  3784. $bResult = true;
  3785. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3786. /**
  3787. * @hooks
  3788. * @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
  3789. * - $unit_name - profile module name
  3790. * - $action - equals `timeline_view_counter`
  3791. * - $object_id - timeline owner profile id
  3792. * - $sender_id - performer profile id
  3793. * - $extra_params - array of additional params with the following array keys:
  3794. * - `result` - [boolean] by ref, check action result, can be overridden in hook processing.
  3795. * @hook @ref hook-bx_base_profile-timeline_view_counter
  3796. */
  3797. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), [
  3798. 'result' => &$bResult
  3799. ]);
  3800. return $bResult;
  3801. }
  3802. public function isAllowedVote($aEvent, $bPerform = false)
  3803. {
  3804. $mixedVotes = $this->getVotesData($aEvent['votes']);
  3805. if($mixedVotes === false)
  3806. return false;
  3807. list($sSystem, $iObjectId) = $mixedVotes;
  3808. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  3809. if(!$oVote->isAllowedVote($bPerform))
  3810. return false;
  3811. $bResult = true;
  3812. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3813. /**
  3814. * @hooks
  3815. * @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
  3816. * It's equivalent to @ref hook-bx_base_profile-timeline_view_counter
  3817. * @hook @ref hook-bx_base_profile-timeline_vote
  3818. */
  3819. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), [
  3820. 'result' => &$bResult
  3821. ]);
  3822. return $bResult;
  3823. }
  3824. public function isAllowedVoteView($aEvent, $bPerform = false)
  3825. {
  3826. $mixedVotes = $this->getVotesData($aEvent['votes']);
  3827. if($mixedVotes === false)
  3828. return false;
  3829. list($sSystem, $iObjectId) = $mixedVotes;
  3830. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  3831. if(!$oVote->isAllowedVoteView($bPerform))
  3832. return false;
  3833. $bResult = true;
  3834. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3835. /**
  3836. * @hooks
  3837. * @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
  3838. * It's equivalent to @ref hook-bx_base_profile-timeline_view_counter
  3839. * @hook @ref hook-bx_base_profile-timeline_vote_view
  3840. */
  3841. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote_view', $oProfileOwner->id(), (int)$this->getUserId(), [
  3842. 'result' => &$bResult
  3843. ]);
  3844. return $bResult;
  3845. }
  3846. public function isAllowedReaction($aEvent, $bPerform = false)
  3847. {
  3848. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  3849. if($mixedReactions === false)
  3850. return false;
  3851. list($sSystem, $iObjectId) = $mixedReactions;
  3852. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  3853. if(!$oReaction->isAllowedVote($bPerform))
  3854. return false;
  3855. $bResult = true;
  3856. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3857. /**
  3858. * @hooks
  3859. * @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
  3860. * It's equivalent to @ref hook-bx_base_profile-timeline_view_counter
  3861. * @hook @ref hook-bx_base_profile-timeline_reaction
  3862. */
  3863. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction', $oProfileOwner->id(), (int)$this->getUserId(), [
  3864. 'result' => &$bResult
  3865. ]);
  3866. return $bResult;
  3867. }
  3868. public function isAllowedReactionView($aEvent, $bPerform = false)
  3869. {
  3870. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  3871. if($mixedReactions === false)
  3872. return false;
  3873. list($sSystem, $iObjectId) = $mixedReactions;
  3874. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  3875. if(!$oReaction->isAllowedVoteView($bPerform))
  3876. return false;
  3877. $bResult = true;
  3878. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3879. /**
  3880. * @hooks
  3881. * @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
  3882. * It's equivalent to @ref hook-bx_base_profile-timeline_view_counter
  3883. * @hook @ref hook-bx_base_profile-timeline_reaction_view
  3884. */
  3885. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction_view', $oProfileOwner->id(), (int)$this->getUserId(), [
  3886. 'result' => &$bResult
  3887. ]);
  3888. return $bResult;
  3889. }
  3890. public function isAllowedScore($aEvent, $bPerform = false)
  3891. {
  3892. $mixedScores = $this->getScoresData($aEvent['scores']);
  3893. if($mixedScores === false)
  3894. return false;
  3895. list($sSystem, $iObjectId) = $mixedScores;
  3896. $oScore = $this->getScoreObject($sSystem, $iObjectId);
  3897. if(!$oScore->isAllowedVote($bPerform))
  3898. return false;
  3899. $bResult = true;
  3900. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3901. /**
  3902. * @hooks
  3903. * @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
  3904. * It's equivalent to @ref hook-bx_base_profile-timeline_view_counter
  3905. * @hook @ref hook-bx_base_profile-timeline_score
  3906. */
  3907. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_score', $oProfileOwner->id(), (int)$this->getUserId(), [
  3908. 'result' => &$bResult
  3909. ]);
  3910. return $bResult;
  3911. }
  3912. public function isAllowedReport($aEvent, $bPerform = false)
  3913. {
  3914. $mixedReports = $this->getReportsData($aEvent['reports']);
  3915. if($mixedReports === false)
  3916. return false;
  3917. list($sSystem, $iObjectId) = $mixedReports;
  3918. $oReport = $this->getReportObject($sSystem, $iObjectId);
  3919. if(!$oReport->isAllowedReport($bPerform))
  3920. return false;
  3921. $bResult = true;
  3922. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3923. /**
  3924. * @hooks
  3925. * @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
  3926. * It's equivalent to @ref hook-bx_base_profile-timeline_view_counter
  3927. * @hook @ref hook-bx_base_profile-timeline_report
  3928. */
  3929. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), [
  3930. 'result' => &$bResult
  3931. ]);
  3932. return $bResult;
  3933. }
  3934. public function isAllowedRepost($aEvent, $bPerform = false)
  3935. {
  3936. $mixedResult = $this->_isAllowedRepost($aEvent, $bPerform);
  3937. /**
  3938. * @hooks
  3939. * @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
  3940. * - $unit_name - equals `bx_timeline`
  3941. * - $action - equals `is_allowed_repost`
  3942. * - $object_id - not used
  3943. * - $sender_id - not used
  3944. * - $extra_params - array of additional params with the following array keys:
  3945. * - `content_info` - [array] content info array as key&value pairs
  3946. * - `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
  3947. * @hook @ref hook-bx_timeline-is_allowed_repost
  3948. */
  3949. bx_alert($this->getName(), 'is_allowed_repost', 0, 0, [
  3950. 'content_info' => $aEvent,
  3951. 'override_result' => &$mixedResult
  3952. ]);
  3953. return $mixedResult;
  3954. }
  3955. public function isAllowedSend($aEvent, $bPerform = false)
  3956. {
  3957. if(!$this->_oDb->isEnabledByName('bx_convos'))
  3958. return false;
  3959. if(isAdmin())
  3960. return true;
  3961. $iUserId = (int)$this->getUserId();
  3962. if($iUserId == 0)
  3963. return false;
  3964. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  3965. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3966. /**
  3967. * @hooks
  3968. * @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
  3969. * It's equivalent to @ref hook-bx_base_profile-timeline_post
  3970. * @hook @ref hook-bx_base_profile-timeline_send
  3971. */
  3972. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, [
  3973. 'check_result' => &$aCheckResult
  3974. ]);
  3975. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3976. }
  3977. public function isAllowedMute($aEvent, $bPerform = false)
  3978. {
  3979. $CNF = &$this->_oConfig->CNF;
  3980. if(!empty($aEvent[$CNF['FIELD_OWNER_ID']]) && $aEvent[$CNF['FIELD_OWNER_ID']] != $this->_iProfileId)
  3981. return false;
  3982. $iAuthor = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  3983. if(!$this->_oConfig->isSystem($aEvent['type'], $aEvent['action']))
  3984. $iAuthor = (int)$aEvent[$CNF['FIELD_OBJECT_ID']];
  3985. if($this->_iProfileId == $iAuthor || $this->getConnectionMuteObject()->isConnected($this->_iProfileId, $iAuthor))
  3986. return false;
  3987. return $this->_isAllowedMute($bPerform);
  3988. }
  3989. public function isAllowedUnmute($iAuthor, $bPerform = false)
  3990. {
  3991. if(!$this->getConnectionMuteObject()->isConnected($this->_iProfileId, $iAuthor))
  3992. return false;
  3993. return $this->_isAllowedMute($bPerform);
  3994. }
  3995. /**
  3996. * Pin - "Pin here" - pin the post on Profile Timeline for profile owner.
  3997. * Can be done by profile owner for himself or by admin for profile owner to see.
  3998. * @param type $aEvent
  3999. * @param type $bPerform
  4000. * @return boolean
  4001. */
  4002. public function isAllowedPin($aEvent, $bPerform = false)
  4003. {
  4004. if((int)$aEvent['pinned'] != 0)
  4005. return false;
  4006. return $this->_isAllowedPin($aEvent, $bPerform);
  4007. }
  4008. public function isAllowedUnpin($aEvent, $bPerform = false)
  4009. {
  4010. if((int)$aEvent['pinned'] == 0)
  4011. return false;
  4012. return $this->_isAllowedPin($aEvent, $bPerform);
  4013. }
  4014. /**
  4015. * Stick - "Pin for All" - pin the post on Public Timeline for everybody to see.
  4016. * Is available for Administrators/Moderators only.
  4017. * @param type $aEvent
  4018. * @param type $bPerform
  4019. * @return boolean
  4020. */
  4021. public function isAllowedStick($aEvent, $bPerform = false)
  4022. {
  4023. if((int)$aEvent['sticked'] != 0)
  4024. return false;
  4025. return $this->_isAllowedStick($aEvent, $bPerform);
  4026. }
  4027. public function isAllowedUnstick($aEvent, $bPerform = false)
  4028. {
  4029. if((int)$aEvent['sticked'] == 0)
  4030. return false;
  4031. return $this->_isAllowedStick($aEvent, $bPerform);
  4032. }
  4033. public function isAllowedPromote($aEvent, $bPerform = false)
  4034. {
  4035. if((int)$aEvent['promoted'] != 0)
  4036. return false;
  4037. return $this->_isAllowedPromote($aEvent, $bPerform);
  4038. }
  4039. public function isAllowedUnpromote($aEvent, $bPerform = false)
  4040. {
  4041. if((int)$aEvent['promoted'] == 0)
  4042. return false;
  4043. return $this->_isAllowedPromote($aEvent, $bPerform);
  4044. }
  4045. public function isAllowedNotes($aEvent, $bPerform = false)
  4046. {
  4047. return $this->isModerator();
  4048. }
  4049. public function isAllowedMore($aEvent, $bPerform = false)
  4050. {
  4051. $oMoreMenu = $this->getManageMenuObject();
  4052. if(!$oMoreMenu)
  4053. return false;
  4054. $oMoreMenu->setEvent($aEvent);
  4055. return $oMoreMenu->isVisible();
  4056. }
  4057. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  4058. {
  4059. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  4060. return _t('_sys_txt_access_denied');
  4061. return CHECK_ACTION_RESULT_ALLOWED;
  4062. }
  4063. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  4064. {
  4065. if(($mixedResult = $this->isAllowedDelete($aDataEntry, $isPerformAction)) !== true)
  4066. return is_string($mixedResult) ? $mixedResult : _t('_sys_txt_access_denied');
  4067. return CHECK_ACTION_RESULT_ALLOWED;
  4068. }
  4069. /**
  4070. * Checks if it's allowed to view a comment by checking the availability to view the content which was commented.
  4071. * Note. Don't check the related comments object for view action accessibility because this method is called from there.
  4072. */
  4073. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  4074. {
  4075. $CNF = $this->_oConfig->CNF;
  4076. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  4077. if($iOwner == 0) //--- in case of Public Timeline.
  4078. return CHECK_ACTION_RESULT_ALLOWED;
  4079. $oOwner = BxDolProfile::getInstance($iOwner);
  4080. if(!$oOwner) //--- in case of non-existed Timeline owner.
  4081. return _t('_sys_txt_access_denied');
  4082. $mixedResult = $oOwner->checkAllowedProfileView();
  4083. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  4084. return $mixedResult;
  4085. return $this->checkAllowedView($aContentInfo, $isPerformAction);
  4086. }
  4087. /**
  4088. * Checks if it's allowed to post a comment by checking the availability to post anything in the context.
  4089. * Note. Don't check the related comments object for post action accessibility because this method is called from there.
  4090. */
  4091. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  4092. {
  4093. $CNF = $this->_oConfig->CNF;
  4094. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  4095. if($iOwner == 0) //--- in case of Public Timeline.
  4096. return CHECK_ACTION_RESULT_ALLOWED;
  4097. $oOwner = BxDolProfile::getInstance($iOwner);
  4098. if(!$oOwner) //--- in case of non-existed Timeline owner.
  4099. return _t('_sys_txt_access_denied');
  4100. /*
  4101. * Disabled in accordance with #4238 ticket.
  4102. *
  4103. if(($mixedResult = $oOwner->checkAllowedPostInProfile()) !== CHECK_ACTION_RESULT_ALLOWED)
  4104. return $mixedResult;
  4105. */
  4106. return CHECK_ACTION_RESULT_ALLOWED;
  4107. }
  4108. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  4109. {
  4110. if(!$iProfileId)
  4111. $iProfileId = $this->_iProfileId;
  4112. $aCheck = checkActionModule($iProfileId, 'edit', $this->getName(), $isPerformAction);
  4113. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  4114. return CHECK_ACTION_RESULT_ALLOWED;
  4115. return _t('_sys_txt_access_denied');
  4116. }
  4117. public function checkAllowedDeleteAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  4118. {
  4119. if(!$iProfileId)
  4120. $iProfileId = $this->_iProfileId;
  4121. $aCheck = checkActionModule($iProfileId, 'delete', $this->getName(), $isPerformAction);
  4122. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  4123. return CHECK_ACTION_RESULT_ALLOWED;
  4124. return _t('_sys_txt_access_denied');
  4125. }
  4126. public function onPost($iContentId)
  4127. {
  4128. $CNF = &$this->_oConfig->CNF;
  4129. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iContentId]);
  4130. if($this->_oConfig->isSystem($aEvent[$CNF['FIELD_TYPE']], $aEvent[$CNF['FIELD_ACTION']])) {
  4131. //--- Request event's data from content module and update it in the Timeline DB.
  4132. $this->_oTemplate->getDataCached($aEvent);
  4133. $sPostType = 'system';
  4134. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  4135. }
  4136. else {
  4137. $sPostType = 'common';
  4138. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  4139. }
  4140. $this->rebuildSlice();
  4141. $sAction = ($aEvent[$CNF['FIELD_STATUS']] == BX_TIMELINE_STATUS_AWAITING ? 'defer' : 'post') . '_' . $sPostType;
  4142. /**
  4143. * @hooks
  4144. * @hookdef hook-bx_timeline-post_system 'bx_timeline', 'post_system' - hook after system post was added and published
  4145. * - $unit_name - equals `bx_timeline`
  4146. * - $action - equals `post_system`
  4147. * - $object_id - content id
  4148. * - $sender_id - content author profile id
  4149. * - $extra_params - array of additional params with the following array keys:
  4150. * - `source` - [string] unique source
  4151. * - `owner_id` - [int] owner profile id
  4152. * - `object_author_id` - [int] object author profile id
  4153. * - `privacy_view` - [int] or [string] privacy for view content action, @see BxDolPrivacy
  4154. * @hook @ref hook-bx_timeline-post_system
  4155. */
  4156. /**
  4157. * @hooks
  4158. * @hookdef hook-bx_timeline-post_common 'bx_timeline', 'post_common' - hook after common post was added and published
  4159. * It's equivalent to @ref hook-bx_timeline-post_system
  4160. * @hook @ref hook-bx_timeline-post_common
  4161. */
  4162. /**
  4163. * @hooks
  4164. * @hookdef hook-bx_timeline-defer_system 'bx_timeline', 'defer_system' - hook after system post was added
  4165. * It's equivalent to @ref hook-bx_timeline-post_system
  4166. * @hook @ref hook-bx_timeline-defer_system
  4167. */
  4168. /**
  4169. * @hooks
  4170. * @hookdef hook-bx_timeline-defer_common 'bx_timeline', 'defer_common' - hook after common post was added
  4171. * It's equivalent to @ref hook-bx_timeline-post_system
  4172. * @hook @ref hook-bx_timeline-defer_common
  4173. */
  4174. bx_alert($this->_oConfig->getObject('alert'), $sAction, $iContentId, $iSenderId, [
  4175. 'source' => $aEvent[$CNF['FIELD_SOURCE']],
  4176. 'owner_id' => $aEvent[$CNF['FIELD_OWNER_ID']],
  4177. 'object_author_id' => $iObjectAuthorId,
  4178. 'privacy_view' => $aEvent[$CNF['FIELD_OBJECT_PRIVACY_VIEW']],
  4179. ]);
  4180. /**
  4181. * Note. 0 is used as $iContentId to allow to subscribe on all events at once.
  4182. */
  4183. if(($oSockets = BxDolSockets::getInstance()) && $oSockets->isEnabled())
  4184. $oSockets->sendEvent($this->_oConfig->getSocketName(), 0, 'added', json_encode([
  4185. 'id' => $aEvent[$CNF['FIELD_ID']],
  4186. 'author_id' => $aEvent[$CNF['FIELD_OBJECT_OWNER_ID']],
  4187. 'peformer_id' => $iSenderId
  4188. ]));
  4189. }
  4190. public function onEdit($iContentId)
  4191. {
  4192. $CNF = &$this->_oConfig->CNF;
  4193. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iContentId]);
  4194. $iSenderId = $this->_oConfig->isSystem($aEvent[$CNF['FIELD_TYPE']], $aEvent[$CNF['FIELD_ACTION']]) ? $aEvent['owner_id'] : $aEvent['object_id'];
  4195. if(($oSockets = BxDolSockets::getInstance()) && $oSockets->isEnabled())
  4196. $oSockets->sendEvent($this->_oConfig->getSocketName(), 0, 'edited', json_encode([
  4197. 'id' => $aEvent[$CNF['FIELD_ID']],
  4198. 'author_id' => $aEvent[$CNF['FIELD_OBJECT_OWNER_ID']],
  4199. 'peformer_id' => $iSenderId
  4200. ]));
  4201. }
  4202. public function onPublished($iContentId)
  4203. {
  4204. //--- Clear Item cache
  4205. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  4206. $this->onPost($iContentId);
  4207. }
  4208. public function onFailed($iContentId)
  4209. {
  4210. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  4211. //--- Clear Item cache
  4212. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  4213. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  4214. //--- Request event's data from content module and update it in the Timeline DB.
  4215. $this->_oTemplate->getDataCached($aEvent);
  4216. $sPostType = 'system';
  4217. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  4218. }
  4219. else {
  4220. $sPostType = 'common';
  4221. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  4222. }
  4223. /**
  4224. * @hooks
  4225. * @hookdef hook-bx_timeline-fail_system 'bx_timeline', 'fail_system' - hook after system post failed to publish
  4226. * It's equivalent to @ref hook-bx_timeline-post_system
  4227. * @hook @ref hook-bx_timeline-fail_system
  4228. */
  4229. /**
  4230. * @hooks
  4231. * @hookdef hook-bx_timeline-fail_common 'bx_timeline', 'fail_common' - hook after common post failed to publish
  4232. * It's equivalent to @ref hook-bx_timeline-post_system
  4233. * @hook @ref hook-bx_timeline-fail_common
  4234. */
  4235. bx_alert($this->_oConfig->getObject('alert'), 'fail_' . $sPostType, $iContentId, $iSenderId, [
  4236. 'source' => $this->_oConfig->getName() . '_' . $iContentId,
  4237. 'owner_id' => $aEvent['owner_id'],
  4238. 'object_author_id' => $iObjectAuthorId,
  4239. 'privacy_view' => $aEvent['object_privacy_view'],
  4240. ]);
  4241. }
  4242. public function onRepost($iContentId, $aReposted = array())
  4243. {
  4244. $CNF = &$this->_oConfig->CNF;
  4245. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  4246. if(empty($aReposted)) {
  4247. $aContent = unserialize($aEvent['content']);
  4248. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  4249. if(empty($aReposted) || !is_array($aReposted))
  4250. return;
  4251. }
  4252. $iUserId = (int)$aEvent[$CNF['FIELD_OBJECT_OWNER_ID']];
  4253. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  4254. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  4255. $this->rebuildSlice();
  4256. /**
  4257. * @hooks
  4258. * @hookdef hook-bx_timeline-repost 'bx_timeline', 'repost' - hook after repost was added (published)
  4259. * - $unit_name - equals `bx_timeline`
  4260. * - $action - equals `repost`
  4261. * - $object_id - reposted content id
  4262. * - $sender_id - performer profile id
  4263. * - $extra_params - array of additional params with the following array keys:
  4264. * - `repost_id` - [int] repost id
  4265. * - `object_author_id` - [int] reposted content author profile id
  4266. * - `privacy_view` - [int] or [string] privacy for view content action, @see BxDolPrivacy
  4267. * @hook @ref hook-bx_timeline-repost
  4268. */
  4269. bx_alert($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, [
  4270. 'repost_id' => $iContentId,
  4271. 'object_author_id' => $aReposted['owner_id'],
  4272. 'privacy_view' => $aEvent['object_privacy_view'],
  4273. ]);
  4274. }
  4275. public function onHide($aEvent)
  4276. {
  4277. $CNF = &$this->_oConfig->CNF;
  4278. $iUserId = $this->getUserId();
  4279. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  4280. //--- Update parent event when repost event was deactivated.
  4281. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  4282. if($bRepost) {
  4283. $this->_oDb->updateRepostTrack(['active' => 0], ['event_id' => $aEvent[$CNF['FIELD_ID']]]);
  4284. $aContent = unserialize($aEvent['content']);
  4285. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  4286. if(!empty($aReposted) && is_array($aReposted))
  4287. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  4288. }
  4289. //--- Find and hide repost events when parent event was deactivated.
  4290. $aRepostEvents = $this->_oDb->getEvents(['browse' => 'reposted_by_track', 'value' => $aEvent[$CNF['FIELD_ID']]]);
  4291. foreach($aRepostEvents as $aRepostEvent) {
  4292. if((int)$this->_oDb->updateEvent(['active' => 0], ['id' => (int)$aRepostEvent[$CNF['FIELD_ID']]]) == 0)
  4293. continue;
  4294. $this->_oDb->updateRepostTrack(['active' => 0], ['event_id' => $aRepostEvent[$CNF['FIELD_ID']]]);
  4295. /**
  4296. * @hooks
  4297. * @hookdef hook-bx_timeline-hide_repost 'bx_timeline', 'hide_repost' - hook after repost was hidden
  4298. * - $unit_name - equals `bx_timeline`
  4299. * - $action - equals `hide_repost`
  4300. * - $object_id - content id
  4301. * - $sender_id - performer profile id
  4302. * - $extra_params - array of additional params with the following array keys:
  4303. * - `repost_id` - [int] repost id
  4304. * @hook @ref hook-bx_timeline-hide_repost
  4305. */
  4306. bx_alert($this->_oConfig->getObject('alert'), 'hide_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, [
  4307. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  4308. ]);
  4309. }
  4310. //--- Delete associated meta for Common events.
  4311. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  4312. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  4313. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  4314. }
  4315. //--- Delete item cache.
  4316. $this->deleteCacheItem($aEvent[$CNF['FIELD_ID']]);
  4317. //--- Rebuild cache table.
  4318. $this->rebuildSlice();
  4319. //--- Event -> Hide for Alerts Engine ---//
  4320. if($bRepost)
  4321. /**
  4322. * @hooks
  4323. * @hookdef hook-bx_timeline-hide_repost 'bx_timeline', 'hide_repost' - hook after repost was hidden
  4324. * - $unit_name - equals `bx_timeline`
  4325. * - $action - equals `hide_repost`
  4326. * - $object_id - content id
  4327. * - $sender_id - performer profile id
  4328. * - $extra_params - array of additional params with the following array keys:
  4329. * - `repost_id` - [int] repost id
  4330. * @hook @ref hook-bx_timeline-hide_repost
  4331. */
  4332. bx_alert($this->_oConfig->getObject('alert'), 'hide_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, [
  4333. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  4334. ]);
  4335. else
  4336. /**
  4337. * @hooks
  4338. * @hookdef hook-bx_timeline-hide 'bx_timeline', 'hide' - hook after post (event) was hidden
  4339. * - $unit_name - equals `bx_timeline`
  4340. * - $action - equals `hide`
  4341. * - $object_id - content id
  4342. * - $sender_id - performer profile id
  4343. * - $extra_params - not used
  4344. * @hook @ref hook-bx_timeline-hide
  4345. */
  4346. bx_alert($this->_oConfig->getObject('alert'), 'hide', $aEvent[$CNF['FIELD_ID']], $iUserId);
  4347. }
  4348. public function onUnhide($aEvent)
  4349. {
  4350. $CNF = &$this->_oConfig->CNF;
  4351. $iUserId = $this->getUserId();
  4352. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  4353. //--- Update parent event when repost event was activated back.
  4354. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  4355. if($bRepost) {
  4356. $this->_oDb->updateRepostTrack(['active' => 1], ['event_id' => $aEvent[$CNF['FIELD_ID']]]);
  4357. $aContent = unserialize($aEvent['content']);
  4358. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  4359. if(!empty($aReposted) && is_array($aReposted))
  4360. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], 1);
  4361. }
  4362. //--- Find and hide repost events when parent event was activated back.
  4363. $aRepostEvents = $this->_oDb->getEvents(['browse' => 'reposted_by_track', 'value' => $aEvent[$CNF['FIELD_ID']]]);
  4364. foreach($aRepostEvents as $aRepostEvent) {
  4365. if((int)$this->_oDb->updateEvent(['active' => 1], ['id' => (int)$aRepostEvent[$CNF['FIELD_ID']]]) == 0)
  4366. continue;
  4367. $this->_oDb->updateRepostTrack(['active' => 1], ['event_id' => $aRepostEvent[$CNF['FIELD_ID']]]);
  4368. /**
  4369. * @hooks
  4370. * @hookdef hook-bx_timeline-unhide_repost 'bx_timeline', 'unhide_repost' - hook after repost was unhidden
  4371. * It's equivalent to @ref hook-bx_timeline-hide_repost
  4372. * @hook @ref hook-bx_timeline-unhide_repost
  4373. */
  4374. bx_alert($this->_oConfig->getObject('alert'), 'unhide_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, [
  4375. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  4376. ]);
  4377. }
  4378. //--- Process meta for Common events.
  4379. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  4380. $aContent = unserialize($aEvent['content']);
  4381. $this->_processMetas($aEvent[$CNF['FIELD_ID']], $aContent['text']);
  4382. }
  4383. //--- Rebuild cache table.
  4384. $this->rebuildSlice();
  4385. if($bRepost)
  4386. /**
  4387. * @hooks
  4388. * @hookdef hook-bx_timeline-unhide_repost 'bx_timeline', 'unhide_repost' - hook after repost was unhidden
  4389. * It's equivalent to @ref hook-bx_timeline-hide_repost
  4390. * @hook @ref hook-bx_timeline-unhide_repost
  4391. */
  4392. bx_alert($this->_oConfig->getObject('alert'), 'unhide_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, [
  4393. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  4394. ]);
  4395. else
  4396. /**
  4397. * @hooks
  4398. * @hookdef hook-bx_timeline-unhide 'bx_timeline', 'unhide' - hook after post (event) was unhidden
  4399. * It's equivalent to @ref hook-bx_timeline-hide
  4400. * @hook @ref hook-bx_timeline-unhide
  4401. */
  4402. bx_alert($this->_oConfig->getObject('alert'), 'unhide', $aEvent[$CNF['FIELD_ID']], $iUserId);
  4403. }
  4404. public function onDelete($aEvent)
  4405. {
  4406. $CNF = &$this->_oConfig->CNF;
  4407. $iUserId = $this->getUserId();
  4408. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  4409. $sCommonPostComment = $this->_oConfig->getObject('comment');
  4410. //--- Delete related flags.
  4411. $this->_oDb->deleteEventFlags($aEvent[$CNF['FIELD_ID']]);
  4412. //--- Delete comments for Common posts.
  4413. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  4414. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent[$CNF['FIELD_ID']]);
  4415. if($oComments !== false)
  4416. $oComments->onObjectDelete($aEvent[$CNF['FIELD_ID']]);
  4417. }
  4418. //--- Delete attached photos, videos and links when common event was deleted.
  4419. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  4420. $this->_deleteMedia($CNF['FIELD_PHOTO'], $aEvent[$CNF['FIELD_ID']]);
  4421. $this->_deleteMedia($CNF['FIELD_VIDEO'], $aEvent[$CNF['FIELD_ID']]);
  4422. $this->_deleteMedia($CNF['FIELD_FILE'], $aEvent[$CNF['FIELD_ID']]);
  4423. $this->_deleteLinks($aEvent[$CNF['FIELD_ID']]);
  4424. }
  4425. //--- Update parent event when repost event was deleted.
  4426. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  4427. if($bRepost) {
  4428. $this->_oDb->deleteRepostTrack($aEvent[$CNF['FIELD_ID']]);
  4429. $aContent = unserialize($aEvent['content']);
  4430. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  4431. if(!empty($aReposted) && is_array($aReposted))
  4432. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  4433. }
  4434. //--- Find and delete repost events when parent event was deleted.
  4435. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_track', 'value' => $aEvent[$CNF['FIELD_ID']]));
  4436. foreach($aRepostEvents as $aRepostEvent) {
  4437. if((int)$this->_oDb->deleteEvent(array('id' => (int)$aRepostEvent[$CNF['FIELD_ID']])) == 0)
  4438. continue;
  4439. $this->_oDb->deleteRepostTrack($aRepostEvent[$CNF['FIELD_ID']]);
  4440. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent[$CNF['FIELD_ID']]);
  4441. if($oComments !== false)
  4442. $oComments->onObjectDelete($aRepostEvent[$CNF['FIELD_ID']]);
  4443. /**
  4444. * @hooks
  4445. * @hookdef hook-bx_timeline-delete_repost 'bx_timeline', 'delete_repost' - hook after repost was deleted
  4446. * It's equivalent to @ref hook-bx_timeline-hide_repost
  4447. * @hook @ref hook-bx_timeline-delete_repost
  4448. */
  4449. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, [
  4450. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  4451. ]);
  4452. }
  4453. //--- Delete associated meta for Common events.
  4454. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  4455. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  4456. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  4457. }
  4458. //--- Delete item cache.
  4459. $this->deleteCacheItem($aEvent[$CNF['FIELD_ID']]);
  4460. //--- Rebuild cache table.
  4461. $this->rebuildSlice();
  4462. if($bRepost)
  4463. /**
  4464. * @hooks
  4465. * @hookdef hook-bx_timeline-delete_repost 'bx_timeline', 'delete_repost' - hook after repost was deleted
  4466. * It's equivalent to @ref hook-bx_timeline-hide_repost
  4467. * @hook @ref hook-bx_timeline-delete_repost
  4468. */
  4469. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, [
  4470. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  4471. ]);
  4472. else
  4473. /**
  4474. * @hooks
  4475. * @hookdef hook-bx_timeline-delete 'bx_timeline', 'delete' - hook after post (event) was deleted
  4476. * It's equivalent to @ref hook-bx_timeline-hide
  4477. * @hook @ref hook-bx_timeline-delete
  4478. */
  4479. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent[$CNF['FIELD_ID']], $iUserId);
  4480. //--- Event -> Delete for Alerts Engine ---//
  4481. if(($oSockets = BxDolSockets::getInstance()) && $oSockets->isEnabled())
  4482. $oSockets->sendEvent($this->_oConfig->getSocketName(), 0, 'deleted', json_encode([
  4483. 'id' => $aEvent[$CNF['FIELD_ID']],
  4484. 'author_id' => $aEvent[$CNF['FIELD_OBJECT_OWNER_ID']],
  4485. 'peformer_id' => $iUserId
  4486. ]));
  4487. }
  4488. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0)
  4489. {
  4490. return $this->_prepareParams(array(
  4491. 'view' => $sView,
  4492. 'type' => $sType,
  4493. 'owner_id' => $iOwnerId,
  4494. 'start' => $iStart,
  4495. 'per_page' => $iPerPage,
  4496. 'timeline' => $iTimeline,
  4497. 'filter' => $sFilter,
  4498. 'modules' => $aModules
  4499. ));
  4500. }
  4501. public function getParamsExt($aParams = array())
  4502. {
  4503. return $this->_prepareParams($aParams);
  4504. }
  4505. public function getViewsData(&$aViews)
  4506. {
  4507. if(empty($aViews) || !is_array($aViews))
  4508. return false;
  4509. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  4510. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  4511. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  4512. if($sSystem == '' || $iObjectId == 0)
  4513. return false;
  4514. return array($sSystem, $iObjectId, $iCount);
  4515. }
  4516. public function getVotesData(&$aVotes)
  4517. {
  4518. if(empty($aVotes) || !is_array($aVotes))
  4519. return false;
  4520. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  4521. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  4522. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  4523. if($sSystem == '' || $iObjectId == 0)
  4524. return false;
  4525. return array($sSystem, $iObjectId, $iCount);
  4526. }
  4527. public function getReactionsData(&$aReactions)
  4528. {
  4529. if(empty($aReactions) || !is_array($aReactions))
  4530. return false;
  4531. $sSystem = isset($aReactions['system']) ? $aReactions['system'] : '';
  4532. $iObjectId = isset($aReactions['object_id']) ? (int)$aReactions['object_id'] : 0;
  4533. $iCount = isset($aReactions['count']) ? (int)$aReactions['count'] : 0;
  4534. if($sSystem == '' || $iObjectId == 0)
  4535. return false;
  4536. return array($sSystem, $iObjectId, $iCount);
  4537. }
  4538. public function getScoresData(&$aScores)
  4539. {
  4540. if(empty($aScores) || !is_array($aScores))
  4541. return false;
  4542. $sSystem = isset($aScores['system']) ? $aScores['system'] : '';
  4543. $iObjectId = isset($aScores['object_id']) ? (int)$aScores['object_id'] : 0;
  4544. $iScore = isset($aScores['score']) ? (int)$aScores['score'] : 0;
  4545. if($sSystem == '' || $iObjectId == 0)
  4546. return false;
  4547. return array($sSystem, $iObjectId, $iScore);
  4548. }
  4549. public function getReportsData(&$aReports)
  4550. {
  4551. if(empty($aReports) || !is_array($aReports))
  4552. return false;
  4553. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  4554. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  4555. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  4556. if($sSystem == '' || $iObjectId == 0)
  4557. return false;
  4558. return array($sSystem, $iObjectId, $iCount);
  4559. }
  4560. public function getCommentsData(&$aComments)
  4561. {
  4562. if(empty($aComments) || !is_array($aComments))
  4563. return false;
  4564. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  4565. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  4566. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  4567. if($sSystem == '' || $iObjectId == 0)
  4568. return false;
  4569. return [$sSystem, $iObjectId, $iCount];
  4570. }
  4571. public function getEventLinks($iEventId)
  4572. {
  4573. $aLinks = $this->_oDb->getLinks($iEventId);
  4574. if(empty($aLinks) || !is_array($aLinks))
  4575. return array();
  4576. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_preview'));
  4577. $aResult = array();
  4578. foreach($aLinks as $aLink)
  4579. $aResult[] = array(
  4580. 'url' => $aLink['url'],
  4581. 'title' => $aLink['title'],
  4582. 'text' => $aLink['text'],
  4583. 'thumbnail' => (int)$aLink['media_id'] != 0 ? $oTranscoder->getFileUrl($aLink['media_id']) : ''
  4584. );
  4585. return $aResult;
  4586. }
  4587. public function getEventImages($iEventId)
  4588. {
  4589. $CNF = &$this->_oConfig->CNF;
  4590. $aPhotos = $this->_oDb->getMedia($CNF['FIELD_PHOTO'], $iEventId);
  4591. if(empty($aPhotos) || !is_array($aPhotos))
  4592. return [];
  4593. $sStorage = $this->_oConfig->getObject('storage_photos');
  4594. $oTranscoderSm = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_view'));
  4595. $oTranscoderMd = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_medium'));
  4596. $oTranscoderLg = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_big'));
  4597. $aResult = [];
  4598. foreach($aPhotos as $iPhotoId) {
  4599. if($this->_bIsApi) {
  4600. $aResult[] = bx_api_get_image($sStorage, $iPhotoId);
  4601. continue;
  4602. }
  4603. $sPhotoSrcMd = $oTranscoderMd->getFileUrl($iPhotoId);
  4604. if(empty($sPhotoSrcMd))
  4605. continue;
  4606. $sPhotoSrcSm = $oTranscoderSm->getFileUrl($iPhotoId);
  4607. if(empty($sPhotoSrcSm))
  4608. $sPhotoSrcSm = $sPhotoSrcMd;
  4609. $sPhotoSrcLg = $oTranscoderLg->getFileUrl($iPhotoId);
  4610. if(empty($sPhotoSrcLg))
  4611. $sPhotoSrcLg = $sPhotoSrcMd;
  4612. $aResult[] = [
  4613. 'id' => $iPhotoId,
  4614. 'src' => $sPhotoSrcMd,
  4615. 'src_small' => $sPhotoSrcSm,
  4616. 'src_medium' => $sPhotoSrcMd,
  4617. 'src_orig' => $sPhotoSrcLg,
  4618. ];
  4619. }
  4620. return $aResult;
  4621. }
  4622. public function getEventVideos($iEventId)
  4623. {
  4624. $CNF = &$this->_oConfig->CNF;
  4625. $aMediaIds = $this->_oDb->getMedia($CNF['FIELD_VIDEO'], $iEventId);
  4626. if(empty($aMediaIds) || !is_array($aMediaIds))
  4627. return [];
  4628. $sStorage = $this->_oConfig->getObject('storage_videos');
  4629. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  4630. $oTranscoderPoster = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_poster'));
  4631. $oTranscoderMp4 = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4'));
  4632. $oTranscoderMp4Hd = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4_hd'));
  4633. $oTranscoderPhoto = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_videos_photo_view'));
  4634. $oTranscoderPhotoBig = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_videos_photo_big'));
  4635. $aResult = [];
  4636. foreach($aMediaIds as $iMediaId) {
  4637. $aMediaFile = $oStorage->getFile($iMediaId);
  4638. $bVideoFile = strncmp('video/', $aMediaFile['mime_type'], 6) === 0 && $oTranscoderPoster->isMimeTypeSupported($aMediaFile['mime_type']);
  4639. if($bVideoFile) {
  4640. $sVideoUrlHd = '';
  4641. if (!empty($aMediaFile['dimensions']) && $oTranscoderMp4Hd->isProcessHD($aMediaFile['dimensions']))
  4642. $sVideoUrlHd = $oTranscoderMp4Hd->getFileUrl($iMediaId);
  4643. $aResult[$iMediaId] = [
  4644. 'id' => $iMediaId,
  4645. 'src_poster' => $oTranscoderPoster->getFileUrl($iMediaId),
  4646. 'src_mp4' => $oTranscoderMp4->getFileUrl($iMediaId),
  4647. 'src_mp4_hd' => $sVideoUrlHd,
  4648. ];
  4649. }
  4650. $bImageFile = strncmp('image/', $aMediaFile['mime_type'], 6) === 0 && $oTranscoderPhoto->isMimeTypeSupported($aMediaFile['mime_type']);
  4651. if($bImageFile) {
  4652. if($this->_bIsApi) {
  4653. $aResult[] = bx_api_get_image($sStorage, $iMediaId);
  4654. continue;
  4655. }
  4656. $sPhotoSrc = $oTranscoderPhoto->getFileUrl($iMediaId);
  4657. $sPhotoSrcBig = $oTranscoderPhotoBig->getFileUrl($iMediaId);
  4658. if(empty($sPhotoSrcBig) && !empty($sPhotoSrc))
  4659. $sPhotoSrcBig = $sPhotoSrc;
  4660. $aResult[$iMediaId] = [
  4661. 'id' => $iMediaId,
  4662. 'src' => $sPhotoSrc,
  4663. 'src_orig' => $sPhotoSrcBig,
  4664. ];
  4665. }
  4666. }
  4667. return $aResult;
  4668. }
  4669. public function getEventFiles($iEventId)
  4670. {
  4671. $CNF = &$this->_oConfig->CNF;
  4672. $aFiles = $this->_oDb->getMedia($CNF['FIELD_FILE'], $iEventId);
  4673. if(empty($aFiles) || !is_array($aFiles))
  4674. return [];
  4675. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_files'));
  4676. $aResult = [];
  4677. foreach($aFiles as $iFileId) {
  4678. $sFileUrl = $oStorage->getFileUrlById($iFileId);
  4679. $aFileFile = $oStorage->getFile($iFileId);
  4680. $aResult[$iFileId] = [
  4681. 'id' => $iFileId,
  4682. 'src' => $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFileFile['file_name'])),
  4683. 'src_medium' => '',
  4684. 'src_orig' => '',
  4685. 'url' => $sFileUrl,
  4686. 'title' => $aFileFile['file_name']
  4687. ];
  4688. }
  4689. return $aResult;
  4690. }
  4691. public function hasMedia($iEventId, $iProfileId = 0)
  4692. {
  4693. $CNF = &$this->_oConfig->CNF;
  4694. if(!empty($iEventId))
  4695. return $this->_oDb->hasMedia($iEventId);
  4696. if(empty($iProfileId))
  4697. $iProfileId = $this->_iProfileId;
  4698. $aTypes = [
  4699. $CNF['FIELD_PHOTO'],
  4700. $CNF['FIELD_VIDEO'],
  4701. $CNF['FIELD_FILE']
  4702. ];
  4703. $bResult = false;
  4704. foreach($aTypes as $sType) {
  4705. $sStorage = $this->_oConfig->getObject('storage_' . strtolower($sType) . 's');
  4706. if(($oStorage = BxDolStorage::getObjectInstance($sStorage)) !== false) {
  4707. $aGhosts = $oStorage->getGhosts($iProfileId, 0);
  4708. if(!empty($aGhosts) && is_array($aGhosts)) {
  4709. $bResult = true;
  4710. break;
  4711. }
  4712. }
  4713. }
  4714. return $bResult;
  4715. }
  4716. public function deleteLinksUnused($iProfileId)
  4717. {
  4718. $aLinks = $this->_oDb->getUnusedLinks($iProfileId);
  4719. if(empty($aLinks) || !is_array($aLinks))
  4720. return;
  4721. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  4722. foreach($aLinks as $aLink)
  4723. if(!empty($aLink['media_id']))
  4724. $oStorage->deleteFile($aLink['media_id']);
  4725. $this->_oDb->deleteUnusedLinks($iProfileId);
  4726. }
  4727. public function deleteCacheItem($iEventId)
  4728. {
  4729. //--- Delete own item cache.
  4730. $oCacheItem = $this->getCacheItemObject();
  4731. $aCacheKeys = $this->_oConfig->getCacheItemKeys($iEventId);
  4732. foreach($aCacheKeys as $sCacheKey)
  4733. $oCacheItem->delData($sCacheKey);
  4734. //--- Delete item cache for reposts.
  4735. $aReposts = $this->_oDb->getReposts($iEventId);
  4736. foreach($aReposts as $aRepost)
  4737. $this->deleteCacheItem($aRepost['event_id']);
  4738. }
  4739. public function rebuildSlice()
  4740. {
  4741. if(!$this->_oConfig->isCacheTable())
  4742. return;
  4743. $this->_oDb->rebuildSlice();
  4744. }
  4745. /**
  4746. * Protected Methods
  4747. */
  4748. protected function _serviceGetBlockView($iProfileId = 0, $aBrowseParams = array())
  4749. {
  4750. if(empty($iProfileId) && bx_get('profile_id') !== false)
  4751. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  4752. if(empty($iProfileId) && isLogged())
  4753. $iProfileId = bx_get_logged_profile_id();
  4754. $aBrowseParams['owner_id'] = $iProfileId;
  4755. $aBlock = $this->_getBlockView($aBrowseParams);
  4756. if(!empty($aBlock))
  4757. return $aBlock;
  4758. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  4759. }
  4760. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $aBrowseParams = array())
  4761. {
  4762. if(empty($sProfileModule))
  4763. return array();
  4764. if(empty($iProfileContentId) && bx_get('id') !== false)
  4765. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  4766. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  4767. if(empty($oProfile))
  4768. return array();
  4769. $aBrowseParams['owner_id'] = $oProfile->id();
  4770. return $this->_getBlockView($aBrowseParams);
  4771. }
  4772. protected function _serviceGetBlockViews($aBrowseParams = [])
  4773. {
  4774. $aParams = $this->_prepareParams($aBrowseParams);
  4775. if(($sType = $this->_oConfig->getUserChoice('type')) !== false)
  4776. $this->_setParamsType($sType, $aParams);
  4777. $this->_iOwnerId = $aParams['owner_id'];
  4778. return $this->_oTemplate->getViewsBlock($aParams);
  4779. }
  4780. protected function _serviceGetBlockViewHome($aBrowseParams = array())
  4781. {
  4782. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  4783. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  4784. return $this->_serviceGetBlockViewByType($aBrowseParams);
  4785. }
  4786. protected function _serviceGetBlockViewHot($aBrowseParams = array())
  4787. {
  4788. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  4789. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_hot'), $sRssUrl);
  4790. return $this->_serviceGetBlockViewByType($aBrowseParams);
  4791. }
  4792. protected function _serviceGetBlockViewByType($aBrowseParams = array())
  4793. {
  4794. $aParams = $this->_prepareParams($aBrowseParams);
  4795. $this->_iOwnerId = $aParams['owner_id'];
  4796. if(isset($aParams['validate']) && is_array($aParams['validate'])) {
  4797. $iSlice = count($aParams['validate']);
  4798. $aEventsIds = $this->_oDb->getEvents(array_merge($aParams, [
  4799. 'start' => 0,
  4800. 'per_page' => 2 * $iSlice,
  4801. 'from_cache' => $this->_oConfig->isCacheTable()
  4802. ]));
  4803. $iIds = 0;
  4804. $aIds = [];
  4805. foreach($aEventsIds as $aEventId) {
  4806. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => (int)$aEventId['id']]);
  4807. if(empty($aEvent) || !is_array($aEvent))
  4808. continue;
  4809. $sEvent = $this->_oTemplate->getPost($aEvent, $aParams);
  4810. if(empty($sEvent))
  4811. continue;
  4812. $aIds[] = $aEvent['id'];
  4813. if(++$iIds == $iSlice)
  4814. break;
  4815. }
  4816. sort($aIds);
  4817. sort($aParams['validate']);
  4818. $aResult = $aIds == $aParams['validate'] ? 'valid' : 'invalid';
  4819. }
  4820. else
  4821. $aResult = $this->_oTemplate->getViewBlock($aParams);
  4822. return $this->_bIsApi ? [bx_api_get_block('browse', [
  4823. 'unit' => 'feed',
  4824. 'request_url' => '/api.php?r=bx_timeline/get_posts/&params[]=',
  4825. 'params' => $aParams,
  4826. 'data' => $aResult
  4827. ])] : ['content' => $aResult];
  4828. }
  4829. protected function _getBlockPost($iProfileId, $aParams = array())
  4830. {
  4831. $this->_iOwnerId = $iProfileId;
  4832. if($this->isAllowedPost() !== true)
  4833. return [];
  4834. $mixedResult = $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams);
  4835. /*if (bx_is_api()){
  4836. $this->actionPost();
  4837. }
  4838. */
  4839. return bx_is_api() ? $mixedResult : [
  4840. 'content' => $mixedResult
  4841. ];
  4842. }
  4843. protected function _getBlockView($aBrowseParams = array())
  4844. {
  4845. if(empty($aBrowseParams['owner_id']))
  4846. return array();
  4847. $aParams = $this->_prepareParams($aBrowseParams);
  4848. if(empty($aParams['per_page']))
  4849. $aParams['per_page'] = $this->_oConfig->getPerPage('profile');
  4850. $this->_iOwnerId = $aParams['owner_id'];
  4851. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  4852. if(!$oProfileOwner)
  4853. return array();
  4854. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  4855. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED) {
  4856. if(!$this->_bIsApi) {
  4857. $this->_oTemplate->displayAccessDenied($mixedResult);
  4858. exit;
  4859. }
  4860. else
  4861. return [bx_api_get_msg($mixedResult, ['ext' => ['msg_type' => 'result']])];
  4862. }
  4863. $sUserName = $this->getObjectUser($aParams['owner_id'])->getDisplayName();
  4864. $sView = $aParams['view'];
  4865. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $this->_iOwnerId . '/';
  4866. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  4867. $aMenu = array(
  4868. 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),
  4869. 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)),
  4870. 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')),
  4871. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'onclick' => '', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  4872. );
  4873. $sContent = '';
  4874. /**
  4875. * @hooks
  4876. * @hookdef hook-bx_base_profile-timeline_view '{profile_module_name}', 'timeline_view' - hook to override view timeline block
  4877. * - $unit_name - profile module name
  4878. * - $action - equals `timeline_view`
  4879. * - $object_id - timeline owner profile id
  4880. * - $sender_id - currently logged in profile id
  4881. * - $extra_params - array of additional params with the following array keys:
  4882. * - `params` - [array] browsing params array as key&value pairs
  4883. * - `menu` - [array] block submenu items array
  4884. * - `override_content` - [string] by ref, block content, can be overridden in hook processing
  4885. * @hook @ref hook-bx_base_profile-timeline_view
  4886. */
  4887. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), [
  4888. 'params' => &$aParams,
  4889. 'menu' => &$aMenu,
  4890. 'override_content' => &$sContent,
  4891. ]);
  4892. $oMenu = new BxTemplMenuInteractive(['template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu]);
  4893. $oMenu->setSelected('', $sView . '-view-all');
  4894. if (!$sContent)
  4895. $sContent = $this->_oTemplate->getViewBlock($aParams);
  4896. if($this->_bIsApi)
  4897. return [bx_api_get_block('browse', [
  4898. 'unit' => 'feed',
  4899. 'request_url' => '/api.php?r=bx_timeline/get_posts/&params[]=',
  4900. 'params' => $aParams,
  4901. 'data' => $sContent
  4902. ])];
  4903. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  4904. return array('content' => $sContent, 'menu' => $oMenu);
  4905. }
  4906. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  4907. {
  4908. $CNF = &$this->_oConfig->CNF;
  4909. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  4910. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iId));
  4911. $sText = '';
  4912. if(isset($aContentInfo['content'])){
  4913. $aTmp = unserialize($aContentInfo['content']);
  4914. if(isset($aTmp['text']))
  4915. $sText = $aTmp['text'];
  4916. }
  4917. if(empty($sText) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  4918. $sText = $aContentInfo[$CNF['FIELD_TITLE']];
  4919. if(!empty($CNF['OBJECT_METATAGS']) && !empty($sText)) {
  4920. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  4921. $sText = $oMetatags->metaParse($iId, $sText);
  4922. }
  4923. return array(
  4924. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  4925. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  4926. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  4927. 'url' => $sUrl,
  4928. 'title' => '',
  4929. 'text' => $sText,
  4930. 'links' => $this->getEventLinks($iId),
  4931. 'images' => array(),
  4932. 'images_attach' => $this->getEventImages($iId),
  4933. 'videos' => array(),
  4934. 'videos_attach' => $this->getEventVideos($iId),
  4935. 'files' => array(),
  4936. 'files_attach' => $this->getEventFiles($iId)
  4937. );
  4938. }
  4939. protected function _isAllowedRepost($aEvent, $bPerform = false)
  4940. {
  4941. $iUserId = (int)$this->getUserId();
  4942. if($iUserId == 0)
  4943. return false;
  4944. $iPrivacy = (int)$aEvent['object_privacy_view'];
  4945. if($iPrivacy >= 0 && !in_array($iPrivacy, [BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS]))
  4946. return false;
  4947. if(isAdmin())
  4948. return true;
  4949. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  4950. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  4951. /**
  4952. * @hooks
  4953. * @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
  4954. * It's equivalent to @ref hook-bx_base_profile-timeline_post
  4955. * @hook @ref hook-bx_base_profile-timeline_repost
  4956. */
  4957. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, [
  4958. 'check_result' => &$aCheckResult
  4959. ]);
  4960. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4961. }
  4962. protected function _isAllowedMute($bPerform = false)
  4963. {
  4964. if($this->_iProfileId == 0)
  4965. return false;
  4966. if(isAdmin())
  4967. return true;
  4968. $aCheckResult = checkActionModule($this->_iProfileId, 'mute', $this->getName(), $bPerform);
  4969. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4970. }
  4971. protected function _isAllowedPin($aEvent, $bPerform = false)
  4972. {
  4973. $iUserId = (int)$this->getUserId();
  4974. if($iUserId == 0)
  4975. return false;
  4976. if(isAdmin() || (int)$aEvent['owner_id'] == $iUserId || ((int)$aEvent['owner_id'] == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && (int)$aEvent['object_id'] == $iUserId))
  4977. return true;
  4978. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  4979. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false) {
  4980. if(bx_srv($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'pin')) === CHECK_ACTION_RESULT_ALLOWED)
  4981. return true;
  4982. /**
  4983. * @hooks
  4984. * @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
  4985. * It's equivalent to @ref hook-bx_base_profile-timeline_post
  4986. * @hook @ref hook-bx_base_profile-timeline_pin
  4987. */
  4988. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, [
  4989. 'check_result' => &$aCheckResult
  4990. ]);
  4991. }
  4992. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4993. }
  4994. protected function _isAllowedStick($aEvent, $bPerform = false)
  4995. {
  4996. $iUserId = (int)$this->getUserId();
  4997. if($iUserId == 0)
  4998. return false;
  4999. if(isAdmin())
  5000. return true;
  5001. $aCheckResult = checkActionModule($iUserId, 'stick', $this->getName(), $bPerform);
  5002. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  5003. /**
  5004. * @hooks
  5005. * @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
  5006. * It's equivalent to @ref hook-bx_base_profile-timeline_post
  5007. * @hook @ref hook-bx_base_profile-timeline_stick
  5008. */
  5009. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_stick', $oProfileOwner->id(), $iUserId, [
  5010. 'check_result' => &$aCheckResult
  5011. ]);
  5012. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  5013. }
  5014. protected function _isAllowedPromote($aEvent, $bPerform = false)
  5015. {
  5016. if(isAdmin())
  5017. return true;
  5018. $iUserId = (int)$this->getUserId();
  5019. if($iUserId == 0)
  5020. return false;
  5021. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  5022. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  5023. /**
  5024. * @hooks
  5025. * @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
  5026. * It's equivalent to @ref hook-bx_base_profile-timeline_post
  5027. * @hook @ref hook-bx_base_profile-timeline_promote
  5028. */
  5029. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, [
  5030. 'check_result' => &$aCheckResult
  5031. ]);
  5032. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  5033. }
  5034. protected function _deleteLinks($iId)
  5035. {
  5036. $aLinks = $this->_oDb->getLinks($iId);
  5037. if(empty($aLinks) || !is_array($aLinks))
  5038. return;
  5039. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  5040. foreach($aLinks as $aLink)
  5041. if(!empty($aLink['media_id']))
  5042. $oStorage->deleteFile($aLink['media_id']);
  5043. $this->_oDb->deleteLinks($iId);
  5044. }
  5045. protected function _processMetas($iId, $sText)
  5046. {
  5047. $CNF = &$this->_oConfig->CNF;
  5048. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  5049. if(!empty($sText)) {
  5050. $oMetatags->metaAdd($iId, $sText);
  5051. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iId]);
  5052. if($oMetatags->keywordsIsEnabled() && !empty($aEvent[$CNF['FIELD_LABELS']])) {
  5053. $aLabels = unserialize($aEvent[$CNF['FIELD_LABELS']]);
  5054. if(!empty($aLabels) && is_array($aLabels))
  5055. foreach ($aLabels as $sLabel) {
  5056. if(!preg_match("/(\pL[\pL\pN_]+)/u", $sLabel))
  5057. continue;
  5058. $oMetatags->keywordsAddOne($iId, $sLabel, false);
  5059. }
  5060. }
  5061. }
  5062. $oMetatags->locationsAddFromForm($iId, $CNF['FIELD_LOCATION_PREFIX']);
  5063. }
  5064. /**
  5065. * Check attached media for content type (photo, video).
  5066. */
  5067. protected function _checkMedia($sType, $iContentId, $aItemIds, $iProfileId = 0)
  5068. {
  5069. if(empty($iContentId) || empty($aItemIds) || !is_array($aItemIds))
  5070. return false;
  5071. if(empty($iProfileId))
  5072. $iProfileId = $this->_iProfileId;
  5073. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  5074. $aGhostFiles = $oStorage->getGhosts ($iProfileId, $iContentId, true, $this->_isModerator());
  5075. if(empty($aGhostFiles) || !is_array($aGhostFiles))
  5076. return false;
  5077. $oTranscoder = BxDolTranscoder::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4'));
  5078. $bHasImage = $bHasVideo = false;
  5079. $bIsVideoProcessed = true;
  5080. foreach($aGhostFiles as $aFile) {
  5081. if(is_array($aItemIds) && !in_array($aFile['id'], $aItemIds))
  5082. continue;
  5083. if(strncmp('image/', $aFile['mime_type'], 6) === 0) {
  5084. $bHasImage = true;
  5085. continue;
  5086. }
  5087. if(strncmp('video/', $aFile['mime_type'], 6) === 0) {
  5088. $bHasVideo = true;
  5089. if($oTranscoder && !$oTranscoder->isFileReady((int)$aFile['id']))
  5090. $bIsVideoProcessed = false;
  5091. continue;
  5092. }
  5093. }
  5094. return [$bHasImage, $bHasVideo, $bIsVideoProcessed];
  5095. }
  5096. protected function _saveMedia($sType, $iContentId, $aItemIds, $iProfileId = 0, $isAssociateWithContent = false)
  5097. {
  5098. if(empty($iContentId))
  5099. return;
  5100. if(!$isAssociateWithContent)
  5101. $this->_oDb->deleteMedia($sType, $iContentId);
  5102. if(empty($aItemIds) || !is_array($aItemIds))
  5103. return;
  5104. if(empty($iProfileId))
  5105. $iProfileId = $this->_iProfileId;
  5106. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  5107. $aGhostFiles = $oStorage->getGhosts ($iProfileId, !$isAssociateWithContent ? $iContentId : 0, true, $this->_isModerator());
  5108. if(empty($aGhostFiles) || !is_array($aGhostFiles))
  5109. return;
  5110. foreach($aGhostFiles as $aFile) {
  5111. if(is_array($aItemIds) && !in_array($aFile['id'], $aItemIds))
  5112. continue;
  5113. $iFileId = (int)$aFile['id'];
  5114. if($aFile['private'])
  5115. $oStorage->setFilePrivate($iFileId, 1);
  5116. $oStorage->updateGhostsContentId($iFileId, $iProfileId, $iContentId, $this->_isModerator());
  5117. $this->_oDb->saveMedia($sType, $iContentId, $iFileId);
  5118. }
  5119. }
  5120. protected function _deleteMedia($sType, $iContentId)
  5121. {
  5122. $aItems = $this->_oDb->getMedia($sType, $iContentId);
  5123. if(empty($aItems) || !is_array($aItems))
  5124. return;
  5125. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  5126. foreach($aItems as $iItemId)
  5127. $oStorage->deleteFile($iItemId);
  5128. $this->_oDb->deleteMedia($sType, $iContentId);
  5129. }
  5130. protected function _setParamsType($sType, &$aParams)
  5131. {
  5132. if(isset($aParams['type']) && $aParams['type'] == $sType)
  5133. return;
  5134. $iPerPage = $this->_oConfig->getPerPage($sType);
  5135. $aParams = array_merge($aParams, [
  5136. 'type' => $sType,
  5137. 'per_page' => $iPerPage,
  5138. 'per_page_default' => $iPerPage
  5139. ]);
  5140. }
  5141. protected function _prepareParams($aParams)
  5142. {
  5143. if(empty($aParams['name']))
  5144. $aParams['name'] = '';
  5145. if(empty($aParams['browse']))
  5146. $aParams['browse'] = 'list';
  5147. if(empty($aParams['view']))
  5148. $aParams['view'] = BX_TIMELINE_VIEW_DEFAULT;
  5149. if(empty($aParams['type']))
  5150. $aParams['type'] = BX_TIMELINE_TYPE_DEFAULT;
  5151. if(empty($aParams['owner_id']))
  5152. $aParams['owner_id'] = $this->getUserId();
  5153. if(!isset($aParams['start']) || (int)$aParams['start'] < 0)
  5154. $aParams['start'] = 0;
  5155. if(!isset($aParams['per_page_default']) || (int)$aParams['per_page_default'] <= 0)
  5156. $aParams['per_page_default'] = $this->_oConfig->getPerPage($aParams['type']);
  5157. if(!isset($aParams['per_page']) || (int)$aParams['per_page'] <= 0)
  5158. $aParams['per_page'] = $aParams['per_page_default'];
  5159. if(empty($aParams['timeline']) || (int)$aParams['timeline'] < 0)
  5160. $aParams['timeline'] = 0;
  5161. if(empty($aParams['filter']))
  5162. $aParams['filter'] = BX_TIMELINE_FILTER_ALL;
  5163. if(empty($aParams['modules']) || !is_array($aParams['modules']))
  5164. $aParams['modules'] = array();
  5165. if(empty($aParams['media']))
  5166. $aParams['media'] = '';
  5167. if(empty($aParams['context']))
  5168. $aParams['context'] = '';
  5169. if(empty($aParams['blink']) || !is_array($aParams['blink']))
  5170. $aParams['blink'] = array();
  5171. $iViewerId = $this->getUserId();
  5172. if(empty($aParams['viewer_id']) || (int)$aParams['viewer_id'] != $iViewerId)
  5173. $aParams['viewer_id'] = $iViewerId;
  5174. if(isset($aParams['validate']) && !is_array($aParams['validate']))
  5175. $aParams['validate'] = !empty($aParams['validate']) ? explode(',', $aParams['validate']) : [];
  5176. if(empty($aParams['status']))
  5177. $aParams['status'] = BX_TIMELINE_STATUS_ACTIVE;
  5178. if(empty($aParams['moderator']))
  5179. $aParams['moderator'] = $this->isModeratorForProfile($aParams['viewer_id']);
  5180. if(empty($aParams['dynamic_mode']))
  5181. $aParams['dynamic_mode'] = false;
  5182. return $aParams;
  5183. }
  5184. protected function _prepareParamsGet($mParams = false)
  5185. {
  5186. $aKeys = ['name', 'view', 'type', 'owner_id', 'start', 'per_page', 'per_page_default', 'timeline', 'filter', 'modules', 'media', 'context', 'blink', 'viewer_id', 'validate'];
  5187. $aParams = [];
  5188. if(!empty($mParams) && is_array($mParams))
  5189. foreach($aKeys as $sKey)
  5190. $aParams[$sKey] = isset($mParams[$sKey]) ? $mParams[$sKey] : false;
  5191. else
  5192. foreach($aKeys as $sKey)
  5193. $aParams[$sKey] = bx_get($sKey);
  5194. $aParams['name'] = $this->_oConfig->processParam($aParams['name']);
  5195. $aParams['view'] = $this->_oConfig->processParamWithDefault($aParams['view'], BX_TIMELINE_VIEW_DEFAULT);
  5196. $aParams['type'] = $this->_oConfig->processParamWithDefault($aParams['type'], BX_TIMELINE_TYPE_DEFAULT);
  5197. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  5198. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  5199. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage($aParams['type']);
  5200. $aParams['per_page_default'] = $aParams['per_page_default'] !== false ? bx_process_input($aParams['per_page_default'], BX_DATA_INT) : $this->_oConfig->getPerPage($aParams['type']);
  5201. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline']) : '';
  5202. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  5203. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : [];
  5204. $aParams['media'] = $aParams['media'] !== false ? $this->_oConfig->processParam($aParams['media']) : '';
  5205. $aParams['context'] = $aParams['context'] !== false ? $this->_oConfig->processParam($aParams['context']) : '';
  5206. if($aParams['blink'] !== false)
  5207. $aParams['blink'] = bx_process_input(is_string($aParams['blink']) ? explode(',', $aParams['blink']) : $aParams['blink'], BX_DATA_TEXT);
  5208. else
  5209. $aParams['blink'] = [];
  5210. $iViewerId = $this->getUserId();
  5211. if($aParams['viewer_id'] !== false)
  5212. $aParams['viewer_id'] = bx_process_input($aParams['viewer_id'], BX_DATA_INT);
  5213. if(!$aParams['viewer_id'] || $aParams['viewer_id'] != $iViewerId)
  5214. $aParams['viewer_id'] = $iViewerId;
  5215. if(isset($aParams['validate']) && !is_array($aParams['validate']))
  5216. $aParams['validate'] = !empty($aParams['validate']) ? explode(',', $aParams['validate']) : [];
  5217. $aParams = array_merge($aParams, [
  5218. 'browse' => 'list',
  5219. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  5220. 'moderator' => $this->isModeratorForProfile($aParams['viewer_id']),
  5221. 'dynamic_mode' => true,
  5222. ]);
  5223. return $aParams;
  5224. }
  5225. protected function _prepareTextForSave($s)
  5226. {
  5227. return bx_process_input($s, BX_DATA_HTML);
  5228. }
  5229. protected function _prepareFormForAutoSubmit(&$oForm, &$aValues)
  5230. {
  5231. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  5232. $oForm->aParams['csrf']['disable'] = true;
  5233. if(!empty($oForm->aParams['db']['submit_name'])) {
  5234. $sSubmitName = $sSubmitValue = false;
  5235. if(is_array($oForm->aParams['db']['submit_name'])) {
  5236. foreach ($oForm->aParams['db']['submit_name'] as $sName) {
  5237. if(isset($oForm->aInputs[$sName])) {
  5238. $sSubmitName = $sName;
  5239. $sSubmitValue = $oForm->aInputs[$sName]['value'];
  5240. break;
  5241. }
  5242. else if(isset($oForm->aInputs['controls']))
  5243. foreach($oForm->aInputs['controls'] as $mixedKey => $mixedInput)
  5244. if(is_numeric($mixedKey) && isset($mixedInput['name']) && $mixedInput['name'] == $sName) {
  5245. $sSubmitName = $sName;
  5246. $sSubmitValue = $mixedInput['value'];
  5247. break 2;
  5248. }
  5249. }
  5250. }
  5251. else {
  5252. $sName = $oForm->aParams['db']['submit_name'];
  5253. if(isset($oForm->aInputs[$sName])) {
  5254. $sSubmitName = $sName;
  5255. $sSubmitValue = $oForm->aInputs[$sName]['value'];
  5256. }
  5257. else if(isset($oForm->aInputs['controls']))
  5258. foreach($oForm->aInputs['controls'] as $mixedKey => $mixedInput)
  5259. if(is_numeric($mixedKey) && isset($mixedInput['name']) && $mixedInput['name'] == $sName) {
  5260. $sSubmitName = $sName;
  5261. $sSubmitValue = $mixedInput['value'];
  5262. break;
  5263. }
  5264. }
  5265. if($sSubmitName && $sSubmitValue)
  5266. $aValues[$sSubmitName] = $sSubmitValue;
  5267. }
  5268. }
  5269. protected function _getFieldValue($sField, $iContentId)
  5270. {
  5271. $CNF = &$this->_oConfig->CNF;
  5272. if(empty($CNF[$sField]))
  5273. return false;
  5274. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  5275. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  5276. return false;
  5277. return $aEvent[$CNF[$sField]];
  5278. }
  5279. /**
  5280. * Returns records for React Jot using OAuth2
  5281. * @param int $iProfileId
  5282. * @param string $sPage
  5283. * @param string $sTab
  5284. * @param int $iStart
  5285. * @param int $iPerPage
  5286. * @return array
  5287. */
  5288. public function serviceGetUserPosts($iProfileId = 0, $sPage = 'home', $sTab = 'hot', $iStart = 0, $iPerPage = 0)
  5289. {
  5290. $iProfileId = (int)$iProfileId ? (int)$iProfileId : bx_get_logged_profile_id();
  5291. if(empty($iProfileId))
  5292. return array(
  5293. 'code' => 1,
  5294. 'result' => array(),
  5295. 'message' => _t('_bx_timeline_txt_msg_no_profile_id'),
  5296. 'page' => $sPage,
  5297. 'tab' => $sTab
  5298. );
  5299. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  5300. $sView = BX_TIMELINE_VIEW_DEFAULT;
  5301. $sFilter = BX_TIMELINE_FILTER_ALL;
  5302. $aModules = array();
  5303. switch($sPage){
  5304. case 'profile':
  5305. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  5306. $sFilter = BX_TIMELINE_FILTER_OWNER;
  5307. break;
  5308. default:
  5309. if ($this -> _oDb -> isModuleByName($sPage))
  5310. $aModules = array($sPage);
  5311. }
  5312. switch($sTab)
  5313. {
  5314. case 'latest':
  5315. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  5316. break;
  5317. case 'popular':
  5318. $sType = BX_TIMELINE_TYPE_HOT;
  5319. break;
  5320. case 'feed':
  5321. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  5322. break;
  5323. default:
  5324. if ($this -> _oDb -> isModuleByName($sTab))
  5325. $aModules = array($sTab);
  5326. }
  5327. $aParams = $this->getParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules);
  5328. $aEvents = $this->_oDb->getEvents($aParams);
  5329. $iCount = $this->_oDb->getEvents(array_merge($aParams, array('count' => true)));
  5330. if(empty($aEvents) || !is_array($aEvents))
  5331. return array(
  5332. 'code' => 0,
  5333. 'result' => array(),
  5334. 'message' => _t('_bx_timeline_txt_msg_no_results'),
  5335. 'page' => $sPage,
  5336. 'tab' => $sTab
  5337. );
  5338. $aBrowseParams = array();
  5339. $aItems = array();
  5340. foreach($aEvents as $aEvent) {
  5341. $aResult = $this->_oTemplate->getData($aEvent, $aBrowseParams);
  5342. if($aResult === false)
  5343. continue;
  5344. $oOwnerProfile = BxDolProfile::getInstance($aResult['owner_id']);
  5345. $aFiles = array();
  5346. $aContent = &$aResult['content'];
  5347. if (!empty($aContent['image']))
  5348. $aFiles['images'] = array_values($aContent['images']);
  5349. if (!empty($aContent['images_attach']))
  5350. $aFiles['images'] = array_values($aContent['images_attach']);
  5351. if (!empty($aContent['videos']))
  5352. $aFiles['videos'] = array_values($aContent['videos']);
  5353. else
  5354. if (!empty($aContent['videos_attach']))
  5355. $aFiles['videos'] = array_values($aContent['videos_attach']);
  5356. if (!empty($aContent['files']))
  5357. $aFiles['files'] = array_values($aContent['files']);
  5358. else
  5359. if (!empty($aContent['files_attach']))
  5360. $aFiles['files'] = array_values($aContent['files_attach']);
  5361. $aItems[$aEvent['id']] = array_merge(array(
  5362. 'owner' => array(
  5363. 'icon' => $oOwnerProfile -> getThumb(),
  5364. 'name' => $oOwnerProfile -> getDisplayName(),
  5365. 'url' => $oOwnerProfile -> getUrl()
  5366. ),
  5367. 'sample' => !empty($aResult['sample']) ? _t($aResult['sample']) : _t('_bx_timeline_txt_sample'),
  5368. 'sample_action' => !empty($aResult['sample_action']) ? _t($aResult['sample_action']) : _t('_bx_timeline_txt_added_sample'),
  5369. 'url' => isset($aResult['url']) ? $aResult['url'] : '',
  5370. 'raw' => isset($aContent['raw']) ? strip_tags($aContent['raw']) : '',
  5371. 'text' => isset($aContent['text']) ? strip_tags($aContent['text']) : '',
  5372. 'views' => isset($aResult['views']['count']) ? (int)$aResult['views']['count'] : 0,
  5373. 'votes' => isset($aResult['votes']['count']) ? (int)$aResult['votes']['count'] : 0,
  5374. 'reactions' => isset($aResult['reactions']['count']) ? (int)$aResult['reactions']['count'] : 0,
  5375. 'scores' => isset($aResult['scores']['count']) ? (int)$aResult['scores']['count'] : 0,
  5376. 'reports' => isset($aResult['reports']['count']) ? (int)$aResult['reports']['count'] : 0,
  5377. 'comments' => isset($aResult['comments']['count']) ? (int)$aResult['comments']['count'] : 0,
  5378. 'date' => isset($aResult['date']) ? $aResult['date'] : $aEvent['date'],
  5379. 'type' => stripos($aEvent['type'], 'timeline') !== false ? 'bx_timeline' : $aEvent['type'],
  5380. 'event_type' => $aEvent['type'],
  5381. 'id' => $aEvent['id'],
  5382. 'content' => $aResult['content'],
  5383. 'title' => isset($aResult['title']) ? _t($aResult['title']) : '',
  5384. 'description' => isset($aResult['description']) ? $aResult['description'] : ''
  5385. ), $aFiles);
  5386. }
  5387. return array(
  5388. 'result' => $aItems,
  5389. 'code' => 0,
  5390. 'message' => '',
  5391. 'page' => $sPage,
  5392. 'tab' => $sTab,
  5393. 'total' => $iCount,
  5394. 'start' => (int)$iStart
  5395. );
  5396. }
  5397. }
  5398. /** @} */