BxTimelineModule.php 261 KB

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