BxTimelineModule.php 261 KB

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