BxTimelineModule.php 257 KB

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