BxTimelineModule.php 258 KB

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