BxTimelineModule.php 256 KB

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