1
0

BxTimelineModule.php 225 KB

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