BxTimelineModule.php 223 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769
  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('profile'),
  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('profile'),
  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('profile'),
  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('profile'),
  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(),
  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(),
  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('home'),
  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('home'),
  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('home'),
  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('home'),
  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('account'),
  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('account'),
  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 = array())
  1791. {
  1792. return $this->_serviceGetBlockViewByType($aParams);
  1793. }
  1794. public function serviceGetBlockMenuDb($aParams = array())
  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. $aParams['type'] = $sType;
  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. $aParams['type'] = $sType;
  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. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  3180. if($bText)
  3181. $oMetatags->metaAdd($iId, $sText);
  3182. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  3183. //--- Process Link ---//
  3184. if($bLinkIds)
  3185. foreach($aLinkIds as $iLinkId)
  3186. $this->_oDb->saveLink($iId, $iLinkId);
  3187. //--- Process Media ---//
  3188. $this->_saveMedia($CNF['FIELD_PHOTO'], $iId, $aPhotoIds, $iUserId, true);
  3189. $this->_saveMedia($CNF['FIELD_VIDEO'], $iId, $aVideoIds, $iUserId, true);
  3190. $this->_saveMedia($CNF['FIELD_FILE'], $iId, $aFileIds, $iUserId, true);
  3191. $this->onPost($iId);
  3192. if(bx_is_api())
  3193. return ['form_object' => $oForm, 'id' => $iId];
  3194. return $this->_prepareResponse(['id' => $iId], $bAjaxMode, [
  3195. 'redirect' => $this->_oConfig->getItemViewUrl(['id' => $iId])
  3196. ]);
  3197. }
  3198. return $this->_prepareResponse(['message' => _t('_bx_timeline_txt_err_cannot_perform_action')], $bAjaxMode);
  3199. }
  3200. if(bx_is_api())
  3201. return ['form_object' => $oForm];
  3202. $mixedResult = $this->_prepareResponse([
  3203. 'form' => $oForm->getCode($bDynamicMode),
  3204. 'form_id' => $oForm->id
  3205. ], $bAjaxMode && $oForm->isSubmitted());
  3206. if(is_array($mixedResult))
  3207. $mixedResult['form_object'] = $oForm;
  3208. return $mixedResult;
  3209. }
  3210. public function getFormEdit($iId, $aParams = [], $aBrowseParams = [])
  3211. {
  3212. $CNF = &$this->_oConfig->CNF;
  3213. $sJsObjectView = $this->_oConfig->getJsObjectView($aBrowseParams);
  3214. $iUserId = $this->getUserId();
  3215. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iId]);
  3216. if(empty($aEvent) || !is_array($aEvent))
  3217. return [];
  3218. if(($mixedCheck = $this->isAllowedEdit($aEvent)) !== true)
  3219. 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')];
  3220. $aContent = unserialize($aEvent['content']);
  3221. if(is_array($aContent) && !empty($aContent['text']))
  3222. $aEvent['text'] = $aContent['text'];
  3223. if(empty($aParams['form_object']))
  3224. $aParams['form_object'] = 'form_post';
  3225. if(empty($aParams['form_display']))
  3226. $aParams['form_display'] = 'form_display_post_edit';
  3227. $oForm = $this->getFormPostObject($aParams);
  3228. $oForm->setId($this->_oConfig->getHtmlIds('view', 'edit_form') . $iId);
  3229. $aFormInitCheckerParams = [];
  3230. $bValues = !empty($aParams['values']) && is_array($aParams['values']);
  3231. if($bValues) {
  3232. $this->_prepareFormForAutoSubmit($oForm, $aParams['values']);
  3233. $aFormInitCheckerParams = [[], array_merge($aEvent, $aParams['values'])];
  3234. unset($aParams['values']);
  3235. }
  3236. else {
  3237. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit/' . $iId ;
  3238. if(!empty($aBrowseParams) && is_array($aBrowseParams))
  3239. $oForm->aFormAttrs['action'] = $this->_oConfig->addBrowseParams($oForm->aFormAttrs['action'], $aBrowseParams);
  3240. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  3241. if(!is_numeric($mixedIndex))
  3242. continue;
  3243. $oForm->aInputs[$CNF['FIELD_CONTROLS']][$mixedIndex]['attrs'] = bx_replace_markers($aInput['attrs'], [
  3244. 'js_object_view' => $sJsObjectView,
  3245. 'content_id' => $iId
  3246. ]);
  3247. }
  3248. $aFormInitCheckerParams = [$aEvent];
  3249. }
  3250. call_user_func_array([$oForm, 'initChecker'], $aFormInitCheckerParams);
  3251. $bAjaxMode = $oForm->isAjaxMode();
  3252. $bDynamicMode = $bAjaxMode || bx_is_dynamic_request();
  3253. $sCodeAdd = '';
  3254. if($bDynamicMode) {
  3255. $sCodeAdd .= $this->_oTemplate->getAddedJs('post', $bDynamicMode);
  3256. $sCodeAdd .= $this->_oTemplate->getJsCode('post', [], true, $bDynamicMode);
  3257. }
  3258. if($oForm->isSubmittedAndValid()) {
  3259. $aContent = [];
  3260. //--- Process Text ---//
  3261. $sText = $oForm->getCleanValue('text');
  3262. $sText = $this->_prepareTextForSave($sText);
  3263. $bText = !empty($sText);
  3264. unset($oForm->aInputs['text']);
  3265. if($bText)
  3266. $aContent['text'] = $sText;
  3267. $aValsToAdd = [
  3268. 'content' => serialize($aContent),
  3269. 'status_admin' => $this->getStatusAdmin()
  3270. ];
  3271. //--- Process Privacy ---//
  3272. if(isset($oForm->aInputs[$CNF['FIELD_OBJECT_PRIVACY_VIEW']])) {
  3273. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  3274. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  3275. if(empty($iObjectPrivacyView))
  3276. $aValsToAdd = array_merge($aValsToAdd, [
  3277. 'object_privacy_view' => $iObjectPrivacyViewDefault
  3278. ]);
  3279. else if($iObjectPrivacyView < 0)
  3280. $aValsToAdd = array_merge($aValsToAdd, [
  3281. 'owner_id' => abs($iObjectPrivacyView)
  3282. ]);
  3283. }
  3284. //--- Process Link ---//
  3285. $aLinkIds = $oForm->getCleanValue($CNF['FIELD_LINK']);
  3286. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  3287. //--- Process Media ---//
  3288. $aPhotoIds = $oForm->getCleanValue($CNF['FIELD_PHOTO']);
  3289. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  3290. $aVideoIds = $oForm->getCleanValue($CNF['FIELD_VIDEO']);
  3291. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  3292. if($bVideoIds)
  3293. $aValsToAdd[$CNF['FIELD_STATUS']] = 'awaiting';
  3294. $aFileIds = $oForm->getCleanValue($CNF['FIELD_FILE']);
  3295. $bFileIds = !empty($aFileIds) && is_array($aFileIds);
  3296. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds && !$bFileIds) {
  3297. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  3298. $oForm->setValid(false);
  3299. return bx_is_api ? ['form' => $oForm->getCodeAPI()] : $this->_prepareResponse([
  3300. 'form' => $sCodeAdd . $oForm->getCode($bDynamicMode),
  3301. 'form_id' => $oForm->id
  3302. ], $bAjaxMode);
  3303. }
  3304. if($oForm->update($iId, $aValsToAdd) === false)
  3305. 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')];
  3306. $this->isAllowedEdit($aEvent, true);
  3307. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  3308. if($bText)
  3309. $oMetatags->metaAdd($iId, $sText);
  3310. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  3311. //--- Process Link ---//
  3312. if($bLinkIds)
  3313. foreach($aLinkIds as $iLinkId)
  3314. $this->_oDb->saveLink($iId, $iLinkId);
  3315. //--- Process Media ---//
  3316. $this->_saveMedia($CNF['FIELD_PHOTO'], $iId, $aPhotoIds, $iUserId);
  3317. $this->_saveMedia($CNF['FIELD_VIDEO'], $iId, $aVideoIds, $iUserId);
  3318. $this->_saveMedia($CNF['FIELD_FILE'], $iId, $aFileIds, $iUserId);
  3319. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iId);
  3320. return bx_is_api() ? [ 'id' => $iId ] : [ 'id' => $iId ];
  3321. }
  3322. return bx_is_api() ? ['form' => $oForm->getCodeAPI()] : [
  3323. 'id' => $iId,
  3324. 'form' => $sCodeAdd . $oForm->getCode($bDynamicMode),
  3325. 'form_id' => $oForm->id,
  3326. 'eval' => $sJsObjectView . '.onEditPost(oData)'
  3327. ];
  3328. }
  3329. public function getFormPostObject($aParams)
  3330. {
  3331. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  3332. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  3333. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  3334. $oForm->aFormAttrs = bx_replace_markers($oForm->aFormAttrs, [
  3335. 'js_object_post' => $this->_oConfig->getJsObject('post')
  3336. ]);
  3337. $sParamsKey = 'type';
  3338. if(!empty($aParams[$sParamsKey]))
  3339. $oForm->setType($aParams[$sParamsKey]);
  3340. /**
  3341. * Note. 'ajax_mode' parameter isn't checked because
  3342. * timeline post form works as Ajax form by default.
  3343. */
  3344. $sParamsKey = 'visibility_autoselect';
  3345. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  3346. $oForm->setVisibilityAutoselect((bool)$aParams[$sParamsKey]);
  3347. $oForm->init();
  3348. return $oForm;
  3349. }
  3350. public function getCmtsObject($sSystem, $iId)
  3351. {
  3352. if(empty($sSystem) || (int)$iId == 0)
  3353. return false;
  3354. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3355. if(!$oCmts || !$oCmts->isEnabled())
  3356. return false;
  3357. return $oCmts;
  3358. }
  3359. public function getViewObject($sSystem, $iId)
  3360. {
  3361. if(empty($sSystem) || (int)$iId == 0)
  3362. return false;
  3363. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3364. if(!$oView || !$oView->isEnabled())
  3365. return false;
  3366. return $oView;
  3367. }
  3368. public function getVoteObject($sSystem, $iId)
  3369. {
  3370. if(empty($sSystem) || (int)$iId == 0)
  3371. return false;
  3372. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3373. if(!$oVote || !$oVote->isEnabled())
  3374. return false;
  3375. return $oVote;
  3376. }
  3377. public function getReactionObject($sSystem, $iId)
  3378. {
  3379. if(empty($sSystem) || (int)$iId == 0)
  3380. return false;
  3381. $oReaction = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3382. if(!$oReaction || !$oReaction->isEnabled())
  3383. return false;
  3384. return $oReaction;
  3385. }
  3386. public function getScoreObject($sSystem, $iId)
  3387. {
  3388. if(empty($sSystem) || (int)$iId == 0)
  3389. return false;
  3390. $oScore = BxDolScore::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3391. if(!$oScore || !$oScore->isEnabled())
  3392. return false;
  3393. return $oScore;
  3394. }
  3395. public function getReportObject($sSystem, $iId)
  3396. {
  3397. if(empty($sSystem) || (int)$iId == 0)
  3398. return false;
  3399. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  3400. if(!$oReport || !$oReport->isEnabled())
  3401. return false;
  3402. return $oReport;
  3403. }
  3404. public function getAttachmentsMenuObject()
  3405. {
  3406. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  3407. }
  3408. public function getManageMenuObject()
  3409. {
  3410. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  3411. }
  3412. public function getCacheItemObject()
  3413. {
  3414. $oCacheEngine = bx_instance('BxDolCache' . $this->_oConfig->getCacheItemEngine());
  3415. if(!$oCacheEngine->isAvailable())
  3416. $oCacheEngine = bx_instance('BxDolCacheFile');
  3417. return $oCacheEngine;
  3418. }
  3419. public function getConnectionMuteObject()
  3420. {
  3421. return BxDolConnection::getObjectInstance($this->_oConfig->getObject('connection_mute'));
  3422. }
  3423. //--- Check permissions methods ---//
  3424. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  3425. {
  3426. if(!$iProfileId)
  3427. $iProfileId = $this->_iProfileId;
  3428. $CNF = &$this->_oConfig->CNF;
  3429. // moderator and owner always have access
  3430. $iOwnerId = (int)$aDataEntry['owner_id'];
  3431. if(!empty($iProfileId) && (abs($iOwnerId) == (int)$iProfileId || $this->isModerator()))
  3432. return CHECK_ACTION_RESULT_ALLOWED;
  3433. // check ACL
  3434. if($iOwnerId != 0 && ($oOwner = BxDolProfile::getInstanceMagic($iOwnerId)) !== false && !($oOwner instanceof BxDolProfileUndefined)) {
  3435. $mixedCheckResult = bx_srv($oOwner->getModule(), 'check_allowed_with_content_for_profile', ['view', $oOwner->getContentId(), $iProfileId]);
  3436. if($mixedCheckResult !== CHECK_ACTION_RESULT_ALLOWED)
  3437. return $mixedCheckResult;
  3438. }
  3439. // check privacy
  3440. if(!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  3441. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  3442. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  3443. return _t('_sys_access_denied_to_private_content');
  3444. }
  3445. // check alert to allow custom checks
  3446. $mixedResult = null;
  3447. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  3448. if($mixedResult !== null)
  3449. return $mixedResult;
  3450. return CHECK_ACTION_RESULT_ALLOWED;
  3451. }
  3452. public function isModerator()
  3453. {
  3454. return $this->isModeratorForProfile((int)$this->getUserId());
  3455. }
  3456. public function isModeratorForProfile($iUserId)
  3457. {
  3458. if($this->checkAllowedEditAnyEntryForProfile(false, $iUserId) === CHECK_ACTION_RESULT_ALLOWED)
  3459. return true;
  3460. if($this->checkAllowedDeleteAnyEntryForProfile(false, $iUserId) === CHECK_ACTION_RESULT_ALLOWED)
  3461. return true;
  3462. return false;
  3463. }
  3464. public function isAllowedPost($bPerform = false)
  3465. {
  3466. if(isAdmin())
  3467. return true;
  3468. $iUserId = $this->getUserId();
  3469. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  3470. if($aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  3471. return $aCheckResult[CHECK_ACTION_MESSAGE];
  3472. if(!empty($this->_iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId)) !== false) {
  3473. if($oProfileOwner->checkAllowedPostInProfile($this->_iOwnerId, $this->getName()) !== CHECK_ACTION_RESULT_ALLOWED)
  3474. return _t('_sys_txt_access_denied');
  3475. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3476. }
  3477. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3478. }
  3479. public function isAllowedView($aEvent, $bPerform = false)
  3480. {
  3481. $CNF = $this->_oConfig->CNF;
  3482. if((int)$aEvent[$CNF['FIELD_OWNER_ID']] == 0)
  3483. return true;
  3484. $oProfileOwner = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']]);
  3485. if($oProfileOwner && $oProfileOwner->checkAllowedProfileView() !== CHECK_ACTION_RESULT_ALLOWED)
  3486. return false;
  3487. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  3488. if(!$oPrivacy)
  3489. return true;
  3490. $oPrivacy->setTableFieldAuthor($this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id');
  3491. return $oPrivacy->check($aEvent[$CNF['FIELD_ID']]);
  3492. }
  3493. public function isAllowedEdit($aEvent, $bPerform = false)
  3494. {
  3495. if(!isLogged())
  3496. return false;
  3497. //--- System posts and Reposts cannot be edited at all.
  3498. if(!$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) || $aEvent['type'] == $this->_oConfig->getPrefix('common_post') . 'repost')
  3499. return false;
  3500. if(isAdmin())
  3501. return true;
  3502. $iUserId = (int)$this->getUserId();
  3503. $iOwnerId = (int)$aEvent['owner_id'];
  3504. $iObjectId = abs((int)$aEvent['object_id']);
  3505. if($iObjectId == $iUserId && $this->_oConfig->isAllowEdit())
  3506. return true;
  3507. $aCheckResult = checkActionModule($iUserId, 'edit', $this->getName(), $bPerform);
  3508. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false) {
  3509. if(BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'edit_any')) === CHECK_ACTION_RESULT_ALLOWED)
  3510. return true;
  3511. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_edit', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3512. }
  3513. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3514. }
  3515. public function isAllowedDelete($aEvent, $bPerform = false)
  3516. {
  3517. if(!isLogged())
  3518. return false;
  3519. if(isAdmin())
  3520. return true;
  3521. $iUserId = (int)$this->getUserId();
  3522. $iOwnerId = (int)$aEvent['owner_id'];
  3523. $iObjectId = abs((int)$aEvent['object_id']);
  3524. if((($iOwnerId == $iUserId && $this->_oConfig->isAllowDelete()) || ($this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)))
  3525. return true;
  3526. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  3527. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false) {
  3528. if(BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'delete_any')) === CHECK_ACTION_RESULT_ALLOWED)
  3529. return true;
  3530. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3531. }
  3532. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3533. }
  3534. public function isAllowedComment($aEvent, $bPerform = false)
  3535. {
  3536. $mixedComments = $this->getCommentsData($aEvent['comments']);
  3537. if($mixedComments === false)
  3538. return false;
  3539. list($sSystem, $iObjectId, $iCount) = $mixedComments;
  3540. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  3541. if($oCmts->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED || ($iCount == 0 && !$oCmts->isPostAllowed()))
  3542. return false;
  3543. $oCmts->addCssJs();
  3544. return true;
  3545. }
  3546. public function isAllowedViewCounter($aEvent, $bPerform = false)
  3547. {
  3548. $mixedViews = $this->getViewsData($aEvent['views']);
  3549. if($mixedViews === false)
  3550. return false;
  3551. list($sSystem, $iObjectId) = $mixedViews;
  3552. $oView = $this->getViewObject($sSystem, $iObjectId);
  3553. if(!$oView->isAllowedViewView($bPerform))
  3554. return false;
  3555. $bResult = true;
  3556. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3557. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3558. return $bResult;
  3559. }
  3560. public function isAllowedVote($aEvent, $bPerform = false)
  3561. {
  3562. $mixedVotes = $this->getVotesData($aEvent['votes']);
  3563. if($mixedVotes === false)
  3564. return false;
  3565. list($sSystem, $iObjectId) = $mixedVotes;
  3566. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  3567. if(!$oVote->isAllowedVote($bPerform))
  3568. return false;
  3569. $bResult = true;
  3570. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3571. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3572. return $bResult;
  3573. }
  3574. public function isAllowedVoteView($aEvent, $bPerform = false)
  3575. {
  3576. $mixedVotes = $this->getVotesData($aEvent['votes']);
  3577. if($mixedVotes === false)
  3578. return false;
  3579. list($sSystem, $iObjectId) = $mixedVotes;
  3580. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  3581. if(!$oVote->isAllowedVoteView($bPerform))
  3582. return false;
  3583. $bResult = true;
  3584. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3585. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote_view', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3586. return $bResult;
  3587. }
  3588. public function isAllowedReaction($aEvent, $bPerform = false)
  3589. {
  3590. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  3591. if($mixedReactions === false)
  3592. return false;
  3593. list($sSystem, $iObjectId) = $mixedReactions;
  3594. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  3595. if(!$oReaction->isAllowedVote($bPerform))
  3596. return false;
  3597. $bResult = true;
  3598. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3599. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3600. return $bResult;
  3601. }
  3602. public function isAllowedReactionView($aEvent, $bPerform = false)
  3603. {
  3604. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  3605. if($mixedReactions === false)
  3606. return false;
  3607. list($sSystem, $iObjectId) = $mixedReactions;
  3608. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  3609. if(!$oReaction->isAllowedVoteView($bPerform))
  3610. return false;
  3611. $bResult = true;
  3612. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3613. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction_view', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3614. return $bResult;
  3615. }
  3616. public function isAllowedScore($aEvent, $bPerform = false)
  3617. {
  3618. $mixedScores = $this->getScoresData($aEvent['scores']);
  3619. if($mixedScores === false)
  3620. return false;
  3621. list($sSystem, $iObjectId) = $mixedScores;
  3622. $oScore = $this->getScoreObject($sSystem, $iObjectId);
  3623. if(!$oScore->isAllowedVote($bPerform))
  3624. return false;
  3625. $bResult = true;
  3626. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3627. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_score', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3628. return $bResult;
  3629. }
  3630. public function isAllowedReport($aEvent, $bPerform = false)
  3631. {
  3632. $mixedReports = $this->getReportsData($aEvent['reports']);
  3633. if($mixedReports === false)
  3634. return false;
  3635. list($sSystem, $iObjectId) = $mixedReports;
  3636. $oReport = $this->getReportObject($sSystem, $iObjectId);
  3637. if(!$oReport->isAllowedReport($bPerform))
  3638. return false;
  3639. $bResult = true;
  3640. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3641. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  3642. return $bResult;
  3643. }
  3644. public function isAllowedRepost($aEvent, $bPerform = false)
  3645. {
  3646. $mixedResult = $this->_isAllowedRepost($aEvent, $bPerform);
  3647. bx_alert($this->getName(), 'is_allowed_repost', 0, 0, [
  3648. 'content_info' => $aEvent,
  3649. 'override_result' => &$mixedResult
  3650. ]);
  3651. return $mixedResult;
  3652. }
  3653. public function isAllowedSend($aEvent, $bPerform = false)
  3654. {
  3655. if(!$this->_oDb->isEnabledByName('bx_convos'))
  3656. return false;
  3657. if(isAdmin())
  3658. return true;
  3659. $iUserId = (int)$this->getUserId();
  3660. if($iUserId == 0)
  3661. return false;
  3662. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  3663. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3664. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3665. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3666. }
  3667. public function isAllowedMute($aEvent, $bPerform = false)
  3668. {
  3669. $CNF = &$this->_oConfig->CNF;
  3670. if(!empty($aEvent[$CNF['FIELD_OWNER_ID']]) && $aEvent[$CNF['FIELD_OWNER_ID']] != $this->_iProfileId)
  3671. return false;
  3672. $iAuthor = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  3673. if(!$this->_oConfig->isSystem($aEvent['type'], $aEvent['action']))
  3674. $iAuthor = (int)$aEvent[$CNF['FIELD_OBJECT_ID']];
  3675. if($this->_iProfileId == $iAuthor || $this->getConnectionMuteObject()->isConnected($this->_iProfileId, $iAuthor))
  3676. return false;
  3677. return $this->_isAllowedMute($bPerform);
  3678. }
  3679. public function isAllowedUnmute($iAuthor, $bPerform = false)
  3680. {
  3681. if(!$this->getConnectionMuteObject()->isConnected($this->_iProfileId, $iAuthor))
  3682. return false;
  3683. return $this->_isAllowedMute($bPerform);
  3684. }
  3685. /**
  3686. * Pin - "Pin here" - pin the post on Profile Timeline for profile owner.
  3687. * Can be done by profile owner for himself or by admin for profile owner to see.
  3688. * @param type $aEvent
  3689. * @param type $bPerform
  3690. * @return boolean
  3691. */
  3692. public function isAllowedPin($aEvent, $bPerform = false)
  3693. {
  3694. if((int)$aEvent['pinned'] != 0)
  3695. return false;
  3696. return $this->_isAllowedPin($aEvent, $bPerform);
  3697. }
  3698. public function isAllowedUnpin($aEvent, $bPerform = false)
  3699. {
  3700. if((int)$aEvent['pinned'] == 0)
  3701. return false;
  3702. return $this->_isAllowedPin($aEvent, $bPerform);
  3703. }
  3704. /**
  3705. * Stick - "Pin for All" - pin the post on Public Timeline for everybody to see.
  3706. * Is available for Administrators/Moderators only.
  3707. * @param type $aEvent
  3708. * @param type $bPerform
  3709. * @return boolean
  3710. */
  3711. public function isAllowedStick($aEvent, $bPerform = false)
  3712. {
  3713. if((int)$aEvent['sticked'] != 0)
  3714. return false;
  3715. return $this->_isAllowedStick($aEvent, $bPerform);
  3716. }
  3717. public function isAllowedUnstick($aEvent, $bPerform = false)
  3718. {
  3719. if((int)$aEvent['sticked'] == 0)
  3720. return false;
  3721. return $this->_isAllowedStick($aEvent, $bPerform);
  3722. }
  3723. public function isAllowedPromote($aEvent, $bPerform = false)
  3724. {
  3725. if((int)$aEvent['promoted'] != 0)
  3726. return false;
  3727. return $this->_isAllowedPromote($aEvent, $bPerform);
  3728. }
  3729. public function isAllowedUnpromote($aEvent, $bPerform = false)
  3730. {
  3731. if((int)$aEvent['promoted'] == 0)
  3732. return false;
  3733. return $this->_isAllowedPromote($aEvent, $bPerform);
  3734. }
  3735. public function isAllowedNotes($aEvent, $bPerform = false)
  3736. {
  3737. return $this->isModerator();
  3738. }
  3739. public function isAllowedMore($aEvent, $bPerform = false)
  3740. {
  3741. $oMoreMenu = $this->getManageMenuObject();
  3742. if(!$oMoreMenu)
  3743. return false;
  3744. $oMoreMenu->setEvent($aEvent);
  3745. return $oMoreMenu->isVisible();
  3746. }
  3747. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  3748. {
  3749. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  3750. return _t('_sys_txt_access_denied');
  3751. return CHECK_ACTION_RESULT_ALLOWED;
  3752. }
  3753. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  3754. {
  3755. if(($mixedResult = $this->isAllowedDelete($aDataEntry, $isPerformAction)) !== true)
  3756. return is_string($mixedResult) ? $mixedResult : _t('_sys_txt_access_denied');
  3757. return CHECK_ACTION_RESULT_ALLOWED;
  3758. }
  3759. /**
  3760. * Checks if it's allowed to view a comment by checking the availability to view the content which was commented.
  3761. * Note. Don't check the related comments object for view action accessibility because this method is called from there.
  3762. */
  3763. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  3764. {
  3765. $CNF = $this->_oConfig->CNF;
  3766. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  3767. if($iOwner == 0) //--- in case of Public Timeline.
  3768. return CHECK_ACTION_RESULT_ALLOWED;
  3769. $oOwner = BxDolProfile::getInstance($iOwner);
  3770. if(!$oOwner) //--- in case of non-existed Timeline owner.
  3771. return _t('_sys_txt_access_denied');
  3772. $mixedResult = $oOwner->checkAllowedProfileView();
  3773. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  3774. return $mixedResult;
  3775. return $this->checkAllowedView($aContentInfo, $isPerformAction);
  3776. }
  3777. /**
  3778. * Checks if it's allowed to post a comment by checking the availability to post anything in the context.
  3779. * Note. Don't check the related comments object for post action accessibility because this method is called from there.
  3780. */
  3781. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  3782. {
  3783. $CNF = $this->_oConfig->CNF;
  3784. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  3785. if($iOwner == 0) //--- in case of Public Timeline.
  3786. return CHECK_ACTION_RESULT_ALLOWED;
  3787. $oOwner = BxDolProfile::getInstance($iOwner);
  3788. if(!$oOwner) //--- in case of non-existed Timeline owner.
  3789. return _t('_sys_txt_access_denied');
  3790. /*
  3791. * Disabled in accordance with #4238 ticket.
  3792. *
  3793. if(($mixedResult = $oOwner->checkAllowedPostInProfile()) !== CHECK_ACTION_RESULT_ALLOWED)
  3794. return $mixedResult;
  3795. */
  3796. return CHECK_ACTION_RESULT_ALLOWED;
  3797. }
  3798. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  3799. {
  3800. if(!$iProfileId)
  3801. $iProfileId = $this->_iProfileId;
  3802. $aCheck = checkActionModule($iProfileId, 'edit', $this->getName(), $isPerformAction);
  3803. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  3804. return CHECK_ACTION_RESULT_ALLOWED;
  3805. return _t('_sys_txt_access_denied');
  3806. }
  3807. public function checkAllowedDeleteAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  3808. {
  3809. if(!$iProfileId)
  3810. $iProfileId = $this->_iProfileId;
  3811. $aCheck = checkActionModule($iProfileId, 'delete', $this->getName(), $isPerformAction);
  3812. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  3813. return CHECK_ACTION_RESULT_ALLOWED;
  3814. return _t('_sys_txt_access_denied');
  3815. }
  3816. public function onPost($iContentId)
  3817. {
  3818. $CNF = &$this->_oConfig->CNF;
  3819. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3820. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  3821. //--- Request event's data from content module and update it in the Timeline DB.
  3822. $this->_oTemplate->getDataCached($aEvent);
  3823. $sPostType = 'system';
  3824. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  3825. }
  3826. else {
  3827. $sPostType = 'common';
  3828. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  3829. }
  3830. $this->rebuildSlice();
  3831. //--- Event -> Post/Defer for Alerts Engine ---//
  3832. $sAction = ($aEvent[$CNF['FIELD_STATUS']] == BX_TIMELINE_STATUS_AWAITING ? 'defer' : 'post') . '_' . $sPostType;
  3833. bx_alert($this->_oConfig->getObject('alert'), $sAction, $iContentId, $iSenderId, array(
  3834. 'source' => $this->_oConfig->getName() . '_' . $iContentId,
  3835. 'owner_id' => $aEvent['owner_id'],
  3836. 'object_author_id' => $iObjectAuthorId,
  3837. 'privacy_view' => $aEvent['object_privacy_view'],
  3838. ));
  3839. //--- Event -> Post for Alerts Engine ---//
  3840. }
  3841. public function onPublished($iContentId)
  3842. {
  3843. //--- Clear Item cache
  3844. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  3845. $this->onPost($iContentId);
  3846. }
  3847. public function onFailed($iContentId)
  3848. {
  3849. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3850. //--- Clear Item cache
  3851. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  3852. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  3853. //--- Request event's data from content module and update it in the Timeline DB.
  3854. $this->_oTemplate->getDataCached($aEvent);
  3855. $sPostType = 'system';
  3856. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  3857. }
  3858. else {
  3859. $sPostType = 'common';
  3860. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  3861. }
  3862. //--- Event -> Fail for Alerts Engine ---//
  3863. bx_alert($this->_oConfig->getObject('alert'), 'fail_' . $sPostType, $iContentId, $iSenderId, array(
  3864. 'owner_id' => $aEvent['owner_id'],
  3865. 'object_author_id' => $iObjectAuthorId,
  3866. 'privacy_view' => $aEvent['object_privacy_view'],
  3867. ));
  3868. //--- Event -> Post for Alerts Engine ---//
  3869. }
  3870. public function onRepost($iContentId, $aReposted = array())
  3871. {
  3872. $CNF = &$this->_oConfig->CNF;
  3873. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3874. if(empty($aReposted)) {
  3875. $aContent = unserialize($aEvent['content']);
  3876. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  3877. if(empty($aReposted) || !is_array($aReposted))
  3878. return;
  3879. }
  3880. $iUserId = (int)$aEvent[$CNF['FIELD_OBJECT_OWNER_ID']];
  3881. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  3882. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  3883. $this->rebuildSlice();
  3884. //--- Timeline -> Update for Alerts Engine ---//
  3885. bx_alert($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  3886. 'privacy_view' => $aEvent['object_privacy_view'],
  3887. 'object_author_id' => $aReposted['owner_id'],
  3888. 'repost_id' => $iContentId,
  3889. ));
  3890. //--- Timeline -> Update for Alerts Engine ---//
  3891. }
  3892. public function onHide($aEvent)
  3893. {
  3894. $CNF = &$this->_oConfig->CNF;
  3895. $iUserId = $this->getUserId();
  3896. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  3897. //--- Update parent event when repost event was deactivated.
  3898. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  3899. if($bRepost) {
  3900. $this->_oDb->updateRepostTrack(['active' => 0], ['event_id' => $aEvent[$CNF['FIELD_ID']]]);
  3901. $aContent = unserialize($aEvent['content']);
  3902. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  3903. if(!empty($aReposted) && is_array($aReposted))
  3904. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  3905. }
  3906. //--- Find and hide repost events when parent event was deactivated.
  3907. $aRepostEvents = $this->_oDb->getEvents(['browse' => 'reposted_by_track', 'value' => $aEvent[$CNF['FIELD_ID']]]);
  3908. foreach($aRepostEvents as $aRepostEvent) {
  3909. if((int)$this->_oDb->updateEvent(['active' => 0], ['id' => (int)$aRepostEvent[$CNF['FIELD_ID']]]) == 0)
  3910. continue;
  3911. $this->_oDb->updateRepostTrack(['active' => 0], ['event_id' => $aRepostEvent[$CNF['FIELD_ID']]]);
  3912. bx_alert($this->_oConfig->getObject('alert'), 'hide_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, array(
  3913. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  3914. ));
  3915. }
  3916. //--- Delete associated meta for Common events.
  3917. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  3918. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  3919. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  3920. }
  3921. //--- Delete item cache.
  3922. $this->deleteCacheItem($aEvent[$CNF['FIELD_ID']]);
  3923. //--- Rebuild cache table.
  3924. $this->rebuildSlice();
  3925. //--- Event -> Hide for Alerts Engine ---//
  3926. if($bRepost)
  3927. bx_alert($this->_oConfig->getObject('alert'), 'hide_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, array(
  3928. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  3929. ));
  3930. else
  3931. bx_alert($this->_oConfig->getObject('alert'), 'hide', $aEvent[$CNF['FIELD_ID']], $iUserId);
  3932. //--- Event -> Hide for Alerts Engine ---//
  3933. }
  3934. public function onUnhide($aEvent)
  3935. {
  3936. $CNF = &$this->_oConfig->CNF;
  3937. $iUserId = $this->getUserId();
  3938. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  3939. //--- Update parent event when repost event was activated back.
  3940. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  3941. if($bRepost) {
  3942. $this->_oDb->updateRepostTrack(['active' => 1], ['event_id' => $aEvent[$CNF['FIELD_ID']]]);
  3943. $aContent = unserialize($aEvent['content']);
  3944. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  3945. if(!empty($aReposted) && is_array($aReposted))
  3946. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], 1);
  3947. }
  3948. //--- Find and hide repost events when parent event was activated back.
  3949. $aRepostEvents = $this->_oDb->getEvents(['browse' => 'reposted_by_track', 'value' => $aEvent[$CNF['FIELD_ID']]]);
  3950. foreach($aRepostEvents as $aRepostEvent) {
  3951. if((int)$this->_oDb->updateEvent(['active' => 1], ['id' => (int)$aRepostEvent[$CNF['FIELD_ID']]]) == 0)
  3952. continue;
  3953. $this->_oDb->updateRepostTrack(['active' => 1], ['event_id' => $aRepostEvent[$CNF['FIELD_ID']]]);
  3954. bx_alert($this->_oConfig->getObject('alert'), 'unhide_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, array(
  3955. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  3956. ));
  3957. }
  3958. //--- Process meta for Common events.
  3959. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  3960. $aContent = unserialize($aEvent['content']);
  3961. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  3962. if(!empty($aContent['text']))
  3963. $oMetatags->metaAdd($aEvent[$CNF['FIELD_ID']], $aContent['text']);
  3964. $oMetatags->locationsAddFromForm($aEvent[$CNF['FIELD_ID']], $CNF['FIELD_LOCATION_PREFIX']);
  3965. }
  3966. //--- Rebuild cache table.
  3967. $this->rebuildSlice();
  3968. //--- Event -> Unhide for Alerts Engine ---//
  3969. if($bRepost)
  3970. bx_alert($this->_oConfig->getObject('alert'), 'unhide_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, array(
  3971. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  3972. ));
  3973. else
  3974. bx_alert($this->_oConfig->getObject('alert'), 'unhide', $aEvent[$CNF['FIELD_ID']], $iUserId);
  3975. //--- Event -> Unhide for Alerts Engine ---//
  3976. }
  3977. public function onDelete($aEvent)
  3978. {
  3979. $CNF = &$this->_oConfig->CNF;
  3980. $iUserId = $this->getUserId();
  3981. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  3982. $sCommonPostComment = $this->_oConfig->getObject('comment');
  3983. //--- Delete comments for Common posts.
  3984. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  3985. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent[$CNF['FIELD_ID']]);
  3986. if($oComments !== false)
  3987. $oComments->onObjectDelete($aEvent[$CNF['FIELD_ID']]);
  3988. }
  3989. //--- Delete attached photos, videos and links when common event was deleted.
  3990. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  3991. $this->_deleteMedia($CNF['FIELD_PHOTO'], $aEvent[$CNF['FIELD_ID']]);
  3992. $this->_deleteMedia($CNF['FIELD_VIDEO'], $aEvent[$CNF['FIELD_ID']]);
  3993. $this->_deleteMedia($CNF['FIELD_FILE'], $aEvent[$CNF['FIELD_ID']]);
  3994. $this->_deleteLinks($aEvent[$CNF['FIELD_ID']]);
  3995. }
  3996. //--- Update parent event when repost event was deleted.
  3997. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  3998. if($bRepost) {
  3999. $this->_oDb->deleteRepostTrack($aEvent[$CNF['FIELD_ID']]);
  4000. $aContent = unserialize($aEvent['content']);
  4001. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  4002. if(!empty($aReposted) && is_array($aReposted))
  4003. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  4004. }
  4005. //--- Find and delete repost events when parent event was deleted.
  4006. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_track', 'value' => $aEvent[$CNF['FIELD_ID']]));
  4007. foreach($aRepostEvents as $aRepostEvent) {
  4008. if((int)$this->_oDb->deleteEvent(array('id' => (int)$aRepostEvent[$CNF['FIELD_ID']])) == 0)
  4009. continue;
  4010. $this->_oDb->deleteRepostTrack($aRepostEvent[$CNF['FIELD_ID']]);
  4011. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent[$CNF['FIELD_ID']]);
  4012. if($oComments !== false)
  4013. $oComments->onObjectDelete($aRepostEvent[$CNF['FIELD_ID']]);
  4014. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, array(
  4015. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  4016. ));
  4017. }
  4018. //--- Delete associated meta for Common events.
  4019. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  4020. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  4021. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  4022. }
  4023. //--- Delete item cache.
  4024. $this->deleteCacheItem($aEvent[$CNF['FIELD_ID']]);
  4025. //--- Rebuild cache table.
  4026. $this->rebuildSlice();
  4027. //--- Event -> Delete for Alerts Engine ---//
  4028. if($bRepost)
  4029. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, array(
  4030. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  4031. ));
  4032. else
  4033. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent[$CNF['FIELD_ID']], $iUserId);
  4034. //--- Event -> Delete for Alerts Engine ---//
  4035. }
  4036. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0)
  4037. {
  4038. return $this->_prepareParams(array(
  4039. 'view' => $sView,
  4040. 'type' => $sType,
  4041. 'owner_id' => $iOwnerId,
  4042. 'start' => $iStart,
  4043. 'per_page' => $iPerPage,
  4044. 'timeline' => $iTimeline,
  4045. 'filter' => $sFilter,
  4046. 'modules' => $aModules
  4047. ));
  4048. }
  4049. public function getParamsExt($aParams = array())
  4050. {
  4051. return $this->_prepareParams($aParams);
  4052. }
  4053. public function getViewsData(&$aViews)
  4054. {
  4055. if(empty($aViews) || !is_array($aViews))
  4056. return false;
  4057. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  4058. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  4059. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  4060. if($sSystem == '' || $iObjectId == 0)
  4061. return false;
  4062. return array($sSystem, $iObjectId, $iCount);
  4063. }
  4064. public function getVotesData(&$aVotes)
  4065. {
  4066. if(empty($aVotes) || !is_array($aVotes))
  4067. return false;
  4068. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  4069. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  4070. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  4071. if($sSystem == '' || $iObjectId == 0)
  4072. return false;
  4073. return array($sSystem, $iObjectId, $iCount);
  4074. }
  4075. public function getReactionsData(&$aReactions)
  4076. {
  4077. if(empty($aReactions) || !is_array($aReactions))
  4078. return false;
  4079. $sSystem = isset($aReactions['system']) ? $aReactions['system'] : '';
  4080. $iObjectId = isset($aReactions['object_id']) ? (int)$aReactions['object_id'] : 0;
  4081. $iCount = isset($aReactions['count']) ? (int)$aReactions['count'] : 0;
  4082. if($sSystem == '' || $iObjectId == 0)
  4083. return false;
  4084. return array($sSystem, $iObjectId, $iCount);
  4085. }
  4086. public function getScoresData(&$aScores)
  4087. {
  4088. if(empty($aScores) || !is_array($aScores))
  4089. return false;
  4090. $sSystem = isset($aScores['system']) ? $aScores['system'] : '';
  4091. $iObjectId = isset($aScores['object_id']) ? (int)$aScores['object_id'] : 0;
  4092. $iScore = isset($aScores['score']) ? (int)$aScores['score'] : 0;
  4093. if($sSystem == '' || $iObjectId == 0)
  4094. return false;
  4095. return array($sSystem, $iObjectId, $iScore);
  4096. }
  4097. public function getReportsData(&$aReports)
  4098. {
  4099. if(empty($aReports) || !is_array($aReports))
  4100. return false;
  4101. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  4102. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  4103. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  4104. if($sSystem == '' || $iObjectId == 0)
  4105. return false;
  4106. return array($sSystem, $iObjectId, $iCount);
  4107. }
  4108. public function getCommentsData(&$aComments)
  4109. {
  4110. if(empty($aComments) || !is_array($aComments))
  4111. return false;
  4112. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  4113. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  4114. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  4115. if($sSystem == '' || $iObjectId == 0)
  4116. return false;
  4117. return [$sSystem, $iObjectId, $iCount];
  4118. }
  4119. public function getEventLinks($iEventId)
  4120. {
  4121. $aLinks = $this->_oDb->getLinks($iEventId);
  4122. if(empty($aLinks) || !is_array($aLinks))
  4123. return array();
  4124. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_preview'));
  4125. $aResult = array();
  4126. foreach($aLinks as $aLink)
  4127. $aResult[] = array(
  4128. 'url' => $aLink['url'],
  4129. 'title' => $aLink['title'],
  4130. 'text' => $aLink['text'],
  4131. 'thumbnail' => (int)$aLink['media_id'] != 0 ? $oTranscoder->getFileUrl($aLink['media_id']) : ''
  4132. );
  4133. return $aResult;
  4134. }
  4135. public function getEventImages($iEventId)
  4136. {
  4137. $CNF = &$this->_oConfig->CNF;
  4138. $aPhotos = $this->_oDb->getMedia($CNF['FIELD_PHOTO'], $iEventId);
  4139. if(empty($aPhotos) || !is_array($aPhotos))
  4140. return [];
  4141. $oTranscoderSm = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_view'));
  4142. $oTranscoderMd = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_medium'));
  4143. $oTranscoderLg = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_big'));
  4144. $aResult = [];
  4145. foreach($aPhotos as $iPhotoId) {
  4146. $sPhotoSrcMd = $oTranscoderMd->getFileUrl($iPhotoId);
  4147. if(empty($sPhotoSrcMd))
  4148. continue;
  4149. $sPhotoSrcSm = $oTranscoderSm->getFileUrl($iPhotoId);
  4150. if(empty($sPhotoSrcSm))
  4151. $sPhotoSrcSm = $sPhotoSrcMd;
  4152. $sPhotoSrcLg = $oTranscoderLg->getFileUrl($iPhotoId);
  4153. if(empty($sPhotoSrcLg))
  4154. $sPhotoSrcLg = $sPhotoSrcMd;
  4155. $aResult[] = [
  4156. 'id' => $iPhotoId,
  4157. 'src' => $sPhotoSrcMd,
  4158. 'src_small' => $sPhotoSrcSm,
  4159. 'src_medium' => $sPhotoSrcMd,
  4160. 'src_orig' => $sPhotoSrcLg,
  4161. ];
  4162. }
  4163. return $aResult;
  4164. }
  4165. public function getEventVideos($iEventId)
  4166. {
  4167. $CNF = &$this->_oConfig->CNF;
  4168. $aMediaIds = $this->_oDb->getMedia($CNF['FIELD_VIDEO'], $iEventId);
  4169. if(empty($aMediaIds) || !is_array($aMediaIds))
  4170. return array();
  4171. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_videos'));
  4172. $oTranscoderPoster = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_poster'));
  4173. $oTranscoderMp4 = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4'));
  4174. $oTranscoderMp4Hd = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4_hd'));
  4175. $oTranscoderPhoto = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_videos_photo_view'));
  4176. $oTranscoderPhotoBig = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_videos_photo_big'));
  4177. $aResult = array();
  4178. foreach($aMediaIds as $iMediaId) {
  4179. $aMediaFile = $oStorage->getFile($iMediaId);
  4180. $bVideoFile = strncmp('video/', $aMediaFile['mime_type'], 6) === 0 && $oTranscoderPoster->isMimeTypeSupported($aMediaFile['mime_type']);
  4181. if($bVideoFile) {
  4182. $sVideoUrlHd = '';
  4183. if (!empty($aMediaFile['dimensions']) && $oTranscoderMp4Hd->isProcessHD($aMediaFile['dimensions']))
  4184. $sVideoUrlHd = $oTranscoderMp4Hd->getFileUrl($iMediaId);
  4185. $aResult[$iMediaId] = array(
  4186. 'id' => $iMediaId,
  4187. 'src_poster' => $oTranscoderPoster->getFileUrl($iMediaId),
  4188. 'src_mp4' => $oTranscoderMp4->getFileUrl($iMediaId),
  4189. 'src_mp4_hd' => $sVideoUrlHd,
  4190. );
  4191. }
  4192. $bImageFile = strncmp('image/', $aMediaFile['mime_type'], 6) === 0 && $oTranscoderPhoto->isMimeTypeSupported($aMediaFile['mime_type']);
  4193. if($bImageFile) {
  4194. $sPhotoSrc = $oTranscoderPhoto->getFileUrl($iMediaId);
  4195. $sPhotoSrcBig = $oTranscoderPhotoBig->getFileUrl($iMediaId);
  4196. if(empty($sPhotoSrcBig) && !empty($sPhotoSrc))
  4197. $sPhotoSrcBig = $sPhotoSrc;
  4198. $aResult[$iMediaId] = array(
  4199. 'id' => $iMediaId,
  4200. 'src' => $sPhotoSrc,
  4201. 'src_orig' => $sPhotoSrcBig,
  4202. );
  4203. }
  4204. }
  4205. return $aResult;
  4206. }
  4207. public function getEventFiles($iEventId)
  4208. {
  4209. $CNF = &$this->_oConfig->CNF;
  4210. $aFiles = $this->_oDb->getMedia($CNF['FIELD_FILE'], $iEventId);
  4211. if(empty($aFiles) || !is_array($aFiles))
  4212. return [];
  4213. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_files'));
  4214. $aResult = [];
  4215. foreach($aFiles as $iFileId) {
  4216. $sFileUrl = $oStorage->getFileUrlById($iFileId);
  4217. $aFileFile = $oStorage->getFile($iFileId);
  4218. $aResult[$iFileId] = [
  4219. 'id' => $iFileId,
  4220. 'src' => $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFileFile['file_name'])),
  4221. 'src_medium' => '',
  4222. 'src_orig' => '',
  4223. 'url' => $sFileUrl,
  4224. 'title' => $aFileFile['file_name']
  4225. ];
  4226. }
  4227. return $aResult;
  4228. }
  4229. public function hasMedia($iEventId, $iProfileId = 0)
  4230. {
  4231. $CNF = &$this->_oConfig->CNF;
  4232. if(!empty($iEventId))
  4233. return $this->_oDb->hasMedia($iEventId);
  4234. if(empty($iProfileId))
  4235. $iProfileId = $this->_iProfileId;
  4236. $aTypes = [
  4237. $CNF['FIELD_PHOTO'],
  4238. $CNF['FIELD_VIDEO'],
  4239. $CNF['FIELD_FILE']
  4240. ];
  4241. $bResult = false;
  4242. foreach($aTypes as $sType) {
  4243. $sStorage = $this->_oConfig->getObject('storage_' . strtolower($sType) . 's');
  4244. if(($oStorage = BxDolStorage::getObjectInstance($sStorage)) !== false) {
  4245. $aGhosts = $oStorage->getGhosts($iProfileId, 0);
  4246. if(!empty($aGhosts) && is_array($aGhosts)) {
  4247. $bResult = true;
  4248. break;
  4249. }
  4250. }
  4251. }
  4252. return $bResult;
  4253. }
  4254. public function deleteCacheItem($iEventId)
  4255. {
  4256. $oCacheItem = $this->getCacheItemObject();
  4257. $aCacheKeys = $this->_oConfig->getCacheItemKeys($iEventId);
  4258. foreach($aCacheKeys as $sCacheKey)
  4259. $oCacheItem->delData($sCacheKey);
  4260. }
  4261. public function rebuildSlice()
  4262. {
  4263. if(!$this->_oConfig->isCacheTable())
  4264. return;
  4265. $this->_oDb->rebuildSlice();
  4266. }
  4267. /**
  4268. * Protected Methods
  4269. */
  4270. protected function _serviceGetBlockView($iProfileId = 0, $aBrowseParams = array())
  4271. {
  4272. if(empty($iProfileId) && bx_get('profile_id') !== false)
  4273. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  4274. if(empty($iProfileId) && isLogged())
  4275. $iProfileId = bx_get_logged_profile_id();
  4276. $aBrowseParams['owner_id'] = $iProfileId;
  4277. $aBlock = $this->_getBlockView($aBrowseParams);
  4278. if(!empty($aBlock))
  4279. return $aBlock;
  4280. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  4281. }
  4282. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $aBrowseParams = array())
  4283. {
  4284. if(empty($sProfileModule))
  4285. return array();
  4286. if(empty($iProfileContentId) && bx_get('id') !== false)
  4287. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  4288. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  4289. if(empty($oProfile))
  4290. return array();
  4291. $aBrowseParams['owner_id'] = $oProfile->id();
  4292. return $this->_getBlockView($aBrowseParams);
  4293. }
  4294. protected function _serviceGetBlockViews($aBrowseParams = array())
  4295. {
  4296. $aParams = $this->_prepareParams($aBrowseParams);
  4297. if(($sType = $this->_oConfig->getUserChoice('type')) !== false)
  4298. $aParams['type'] = $sType;
  4299. $this->_iOwnerId = $aParams['owner_id'];
  4300. return $this->_oTemplate->getViewsBlock($aParams);
  4301. }
  4302. protected function _serviceGetBlockViewHome($aBrowseParams = array())
  4303. {
  4304. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  4305. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  4306. return $this->_serviceGetBlockViewByType($aBrowseParams);
  4307. }
  4308. protected function _serviceGetBlockViewHot($aBrowseParams = array())
  4309. {
  4310. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  4311. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_hot'), $sRssUrl);
  4312. return $this->_serviceGetBlockViewByType($aBrowseParams);
  4313. }
  4314. protected function _serviceGetBlockViewByType($aBrowseParams = array())
  4315. {
  4316. $aParams = $this->_prepareParams($aBrowseParams);
  4317. $this->_iOwnerId = $aParams['owner_id'];
  4318. return bx_is_api() ? [bx_api_get_block('browse', [
  4319. 'unit' => 'feed',
  4320. 'request_url' => '/api.php?r=bx_timeline/get_posts/&params[]=',
  4321. 'params' => $aParams,
  4322. 'data' => $this->_oTemplate->getViewBlock($aParams)]),
  4323. ] : ['content' => $this->_oTemplate->getViewBlock($aParams)];
  4324. }
  4325. protected function _getBlockPost($iProfileId, $aParams = array())
  4326. {
  4327. $this->_iOwnerId = $iProfileId;
  4328. if($this->isAllowedPost() !== true)
  4329. return [];
  4330. $mixedResult = $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams);
  4331. /*if (bx_is_api()){
  4332. $this->actionPost();
  4333. }
  4334. */
  4335. return bx_is_api() ? $mixedResult : [
  4336. 'content' => $mixedResult
  4337. ];
  4338. }
  4339. protected function _getBlockView($aBrowseParams = array())
  4340. {
  4341. if(empty($aBrowseParams['owner_id']))
  4342. return array();
  4343. $aParams = $this->_prepareParams($aBrowseParams);
  4344. if(empty($aParams['per_page']))
  4345. $aParams['per_page'] = $this->_oConfig->getPerPage('profile');
  4346. $this->_iOwnerId = $aParams['owner_id'];
  4347. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  4348. if(!$oProfileOwner)
  4349. return array();
  4350. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  4351. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED) {
  4352. $this->_oTemplate->displayAccessDenied($mixedResult);
  4353. exit;
  4354. }
  4355. $sUserName = $this->getObjectUser($aParams['owner_id'])->getDisplayName();
  4356. $sView = $aParams['view'];
  4357. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $this->_iOwnerId . '/';
  4358. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  4359. $aMenu = array(
  4360. 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),
  4361. 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)),
  4362. 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')),
  4363. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'onclick' => '', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  4364. );
  4365. $sContent = '';
  4366. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  4367. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  4368. $oMenu->setSelected('', $sView . '-view-all');
  4369. if (!$sContent)
  4370. $sContent = $this->_oTemplate->getViewBlock($aParams);
  4371. if(bx_is_api())
  4372. return [bx_api_get_block('browse', [
  4373. 'unit' => 'feed',
  4374. 'request_url' => '/api.php?r=bx_timeline/get_posts/&params[]=',
  4375. 'params' => $aParams,
  4376. 'data' => $sContent
  4377. ])];
  4378. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  4379. return array('content' => $sContent, 'menu' => $oMenu);
  4380. }
  4381. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  4382. {
  4383. $CNF = &$this->_oConfig->CNF;
  4384. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  4385. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iId));
  4386. $sText = '';
  4387. if(isset($aContentInfo['content'])){
  4388. $aTmp = unserialize($aContentInfo['content']);
  4389. if(isset($aTmp['text']))
  4390. $sText = $aTmp['text'];
  4391. }
  4392. if(empty($sText) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  4393. $sText = $aContentInfo[$CNF['FIELD_TITLE']];
  4394. if(!empty($CNF['OBJECT_METATAGS']) && !empty($sText)) {
  4395. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  4396. $sText = $oMetatags->metaParse($iId, $sText);
  4397. }
  4398. return array(
  4399. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  4400. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  4401. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  4402. 'url' => $sUrl,
  4403. 'title' => '',
  4404. 'text' => $sText,
  4405. 'links' => $this->getEventLinks($iId),
  4406. 'images' => array(),
  4407. 'images_attach' => $this->getEventImages($iId),
  4408. 'videos' => array(),
  4409. 'videos_attach' => $this->getEventVideos($iId),
  4410. 'files' => array(),
  4411. 'files_attach' => $this->getEventFiles($iId)
  4412. );
  4413. }
  4414. protected function _isAllowedRepost($aEvent, $bPerform = false)
  4415. {
  4416. $iUserId = (int)$this->getUserId();
  4417. if($iUserId == 0)
  4418. return false;
  4419. $iPrivacy = (int)$aEvent['object_privacy_view'];
  4420. if($iPrivacy >= 0 && !in_array($iPrivacy, [BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS]))
  4421. return false;
  4422. if(isAdmin())
  4423. return true;
  4424. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  4425. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  4426. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  4427. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4428. }
  4429. protected function _isAllowedMute($bPerform = false)
  4430. {
  4431. if($this->_iProfileId == 0)
  4432. return false;
  4433. if(isAdmin())
  4434. return true;
  4435. $aCheckResult = checkActionModule($this->_iProfileId, 'mute', $this->getName(), $bPerform);
  4436. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4437. }
  4438. protected function _isAllowedPin($aEvent, $bPerform = false)
  4439. {
  4440. $iUserId = (int)$this->getUserId();
  4441. if($iUserId == 0)
  4442. return false;
  4443. if(isAdmin() || (int)$aEvent['owner_id'] == $iUserId || ((int)$aEvent['owner_id'] == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && (int)$aEvent['object_id'] == $iUserId))
  4444. return true;
  4445. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  4446. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false) {
  4447. if (BxDolService::call($oProfileOwner->getModule(), 'check_allowed_module_action_in_profile', array($oProfileOwner->getContentId(), $this->getName(), 'pin')) === CHECK_ACTION_RESULT_ALLOWED) {
  4448. return true;
  4449. }
  4450. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  4451. }
  4452. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4453. }
  4454. protected function _isAllowedStick($aEvent, $bPerform = false)
  4455. {
  4456. $iUserId = (int)$this->getUserId();
  4457. if($iUserId == 0)
  4458. return false;
  4459. if(isAdmin())
  4460. return true;
  4461. $aCheckResult = checkActionModule($iUserId, 'stick', $this->getName(), $bPerform);
  4462. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  4463. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_stick', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  4464. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4465. }
  4466. protected function _isAllowedPromote($aEvent, $bPerform = false)
  4467. {
  4468. if(isAdmin())
  4469. return true;
  4470. $iUserId = (int)$this->getUserId();
  4471. if($iUserId == 0)
  4472. return false;
  4473. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  4474. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  4475. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  4476. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  4477. }
  4478. protected function _addLink(&$oForm)
  4479. {
  4480. $iUserId = $this->getUserId();
  4481. $iEventId = (int)$oForm->getCleanValue('event_id');
  4482. $sLink = rtrim($oForm->getCleanValue('url'), '/');
  4483. $sHost = parse_url($sLink, PHP_URL_HOST);
  4484. if ($sHost && is_private_ip(gethostbyname($sHost)))
  4485. return array('message' => _t('_sys_txt_error_occured'));
  4486. $aMatches = array();
  4487. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  4488. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  4489. $aSiteInfo = bx_get_site_info($sLink, array(
  4490. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  4491. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  4492. ));
  4493. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  4494. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  4495. $sMediaUrl = '';
  4496. if(!empty($aSiteInfo['thumbnailUrl']))
  4497. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  4498. else if(!empty($aSiteInfo['OGImage']))
  4499. $sMediaUrl = $aSiteInfo['OGImage'];
  4500. $iMediaId = 0;
  4501. $oStorage = null;
  4502. if(!empty($sMediaUrl)) {
  4503. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  4504. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  4505. }
  4506. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  4507. if(!empty($iId)) {
  4508. if(!empty($oStorage) && !empty($iMediaId))
  4509. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  4510. return array(
  4511. 'id' => $iId,
  4512. 'event_id' => $iEventId,
  4513. 'url' => $sLink,
  4514. 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId)
  4515. );
  4516. }
  4517. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  4518. }
  4519. protected function _deleteLinks($iId)
  4520. {
  4521. $aLinks = $this->_oDb->getLinks($iId);
  4522. if(empty($aLinks) || !is_array($aLinks))
  4523. return;
  4524. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  4525. foreach($aLinks as $aLink)
  4526. if(!empty($aLink['media_id']))
  4527. $oStorage->deleteFile($aLink['media_id']);
  4528. $this->_oDb->deleteLinks($iId);
  4529. }
  4530. protected function _saveMedia($sType, $iContentId, $aItemIds, $iProfileId = 0, $isAssociateWithContent = false)
  4531. {
  4532. if(empty($iContentId))
  4533. return;
  4534. if(!$isAssociateWithContent)
  4535. $this->_oDb->deleteMedia($sType, $iContentId);
  4536. if(empty($aItemIds) || !is_array($aItemIds))
  4537. return;
  4538. if(empty($iProfileId))
  4539. $iProfileId = $this->_iProfileId;
  4540. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  4541. $aGhostFiles = $oStorage->getGhosts ($iProfileId, !$isAssociateWithContent ? $iContentId : 0, true, $this->_isModerator());
  4542. if(empty($aGhostFiles) || !is_array($aGhostFiles))
  4543. return;
  4544. foreach($aGhostFiles as $aFile) {
  4545. if(is_array($aItemIds) && !in_array($aFile['id'], $aItemIds))
  4546. continue;
  4547. $iFileId = (int)$aFile['id'];
  4548. if($aFile['private'])
  4549. $oStorage->setFilePrivate($iFileId, 1);
  4550. $oStorage->updateGhostsContentId($iFileId, $iProfileId, $iContentId, $this->_isModerator());
  4551. $this->_oDb->saveMedia($sType, $iContentId, $iFileId);
  4552. }
  4553. }
  4554. protected function _deleteMedia($sType, $iContentId)
  4555. {
  4556. $aItems = $this->_oDb->getMedia($sType, $iContentId);
  4557. if(empty($aItems) || !is_array($aItems))
  4558. return;
  4559. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  4560. foreach($aItems as $iItemId)
  4561. $oStorage->deleteFile($iItemId);
  4562. $this->_oDb->deleteMedia($sType, $iContentId);
  4563. }
  4564. protected function _prepareParams($aParams)
  4565. {
  4566. if(empty($aParams['name']))
  4567. $aParams['name'] = '';
  4568. if(empty($aParams['view']))
  4569. $aParams['view'] = BX_TIMELINE_VIEW_DEFAULT;
  4570. if(empty($aParams['type']))
  4571. $aParams['type'] = BX_TIMELINE_TYPE_DEFAULT;
  4572. if(empty($aParams['owner_id']))
  4573. $aParams['owner_id'] = $this->getUserId();
  4574. if(!isset($aParams['start']) || (int)$aParams['start'] < 0)
  4575. $aParams['start'] = 0;
  4576. if(!isset($aParams['per_page']) || (int)$aParams['per_page'] <= 0)
  4577. $aParams['per_page'] = isset($aParams['per_page_default']) && (int)$aParams['per_page_default'] > 0 ? $aParams['per_page_default'] : $this->_oConfig->getPerPage();
  4578. if(empty($aParams['timeline']) || (int)$aParams['timeline'] < 0)
  4579. $aParams['timeline'] = 0;
  4580. if(empty($aParams['filter']))
  4581. $aParams['filter'] = BX_TIMELINE_FILTER_ALL;
  4582. if(empty($aParams['modules']) || !is_array($aParams['modules']))
  4583. $aParams['modules'] = array();
  4584. if(empty($aParams['context']))
  4585. $aParams['context'] = 0;
  4586. if(empty($aParams['blink']) || !is_array($aParams['blink']))
  4587. $aParams['blink'] = array();
  4588. $iViewerId = $this->getUserId();
  4589. if(empty($aParams['viewer_id']) || (int)$aParams['viewer_id'] != $iViewerId)
  4590. $aParams['viewer_id'] = $iViewerId;
  4591. $aParams = array_merge($aParams, array(
  4592. 'browse' => 'list',
  4593. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  4594. 'moderator' => $this->isModeratorForProfile($aParams['viewer_id']),
  4595. 'dynamic_mode' => false,
  4596. ));
  4597. return $aParams;
  4598. }
  4599. protected function _prepareParamsGet($mParams = false)
  4600. {
  4601. $aKeys = ['name', 'view', 'type', 'owner_id', 'start', 'per_page', 'timeline', 'filter', 'modules', 'context', 'blink', 'viewer_id'];
  4602. $aParams = [];
  4603. if(!empty($mParams) && is_array($mParams))
  4604. foreach($aKeys as $sKey)
  4605. $aParams[$sKey] = isset($mParams[$sKey]) ? $mParams[$sKey] : false;
  4606. else
  4607. foreach($aKeys as $sKey)
  4608. $aParams[$sKey] = bx_get($sKey);
  4609. $aParams['name'] = $this->_oConfig->processParam($aParams['name']);
  4610. $aParams['view'] = $this->_oConfig->processParamWithDefault($aParams['view'], BX_TIMELINE_VIEW_DEFAULT);
  4611. $aParams['type'] = $this->_oConfig->processParamWithDefault($aParams['type'], BX_TIMELINE_TYPE_DEFAULT);
  4612. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  4613. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  4614. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  4615. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline']) : '';
  4616. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  4617. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : [];
  4618. $aParams['context'] = $aParams['context'] !== false ? bx_process_input($aParams['context'], BX_DATA_INT) : 0;
  4619. if($aParams['blink'] !== false)
  4620. $aParams['blink'] = bx_process_input(is_string($aParams['blink']) ? explode(',', $aParams['blink']) : $aParams['blink'], BX_DATA_TEXT);
  4621. else
  4622. $aParams['blink'] = [];
  4623. $iViewerId = $this->getUserId();
  4624. if($aParams['viewer_id'] !== false)
  4625. $aParams['viewer_id'] = bx_process_input($aParams['viewer_id'], BX_DATA_INT);
  4626. if(!$aParams['viewer_id'] || $aParams['viewer_id'] != $iViewerId)
  4627. $aParams['viewer_id'] = $iViewerId;
  4628. $aParams = array_merge($aParams, [
  4629. 'browse' => 'list',
  4630. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  4631. 'moderator' => $this->isModeratorForProfile($aParams['viewer_id']),
  4632. 'dynamic_mode' => true,
  4633. ]);
  4634. return $aParams;
  4635. }
  4636. protected function _prepareTextForSave($s)
  4637. {
  4638. return bx_process_input($s, BX_DATA_HTML);
  4639. }
  4640. protected function _prepareFormForAutoSubmit(&$oForm, &$aValues)
  4641. {
  4642. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  4643. $oForm->aParams['csrf']['disable'] = true;
  4644. if(!empty($oForm->aParams['db']['submit_name'])) {
  4645. $sSubmitName = $sSubmitValue = false;
  4646. if(is_array($oForm->aParams['db']['submit_name'])) {
  4647. foreach ($oForm->aParams['db']['submit_name'] as $sName) {
  4648. if(isset($oForm->aInputs[$sName])) {
  4649. $sSubmitName = $sName;
  4650. $sSubmitValue = $oForm->aInputs[$sName]['value'];
  4651. break;
  4652. }
  4653. else if(isset($oForm->aInputs['controls']))
  4654. foreach($oForm->aInputs['controls'] as $mixedKey => $mixedInput)
  4655. if(is_numeric($mixedKey) && isset($mixedInput['name']) && $mixedInput['name'] == $sName) {
  4656. $sSubmitName = $sName;
  4657. $sSubmitValue = $mixedInput['value'];
  4658. break 2;
  4659. }
  4660. }
  4661. }
  4662. else {
  4663. $sName = $oForm->aParams['db']['submit_name'];
  4664. if(isset($oForm->aInputs[$sName])) {
  4665. $sSubmitName = $sName;
  4666. $sSubmitValue = $oForm->aInputs[$sName]['value'];
  4667. }
  4668. else if(isset($oForm->aInputs['controls']))
  4669. foreach($oForm->aInputs['controls'] as $mixedKey => $mixedInput)
  4670. if(is_numeric($mixedKey) && isset($mixedInput['name']) && $mixedInput['name'] == $sName) {
  4671. $sSubmitName = $sName;
  4672. $sSubmitValue = $mixedInput['value'];
  4673. break;
  4674. }
  4675. }
  4676. if($sSubmitName && $sSubmitValue)
  4677. $aValues[$sSubmitName] = $sSubmitValue;
  4678. }
  4679. }
  4680. protected function _getFieldValue($sField, $iContentId)
  4681. {
  4682. $CNF = &$this->_oConfig->CNF;
  4683. if(empty($CNF[$sField]))
  4684. return false;
  4685. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  4686. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  4687. return false;
  4688. return $aEvent[$CNF[$sField]];
  4689. }
  4690. /**
  4691. * Returns records for React Jot using OAuth2
  4692. * @param int $iProfileId
  4693. * @param string $sPage
  4694. * @param string $sTab
  4695. * @param int $iStart
  4696. * @param int $iPerPage
  4697. * @return array
  4698. */
  4699. public function serviceGetUserPosts($iProfileId = 0, $sPage = 'home', $sTab = 'hot', $iStart = 0, $iPerPage = 0)
  4700. {
  4701. $iProfileId = (int)$iProfileId ? (int)$iProfileId : bx_get_logged_profile_id();
  4702. if(empty($iProfileId))
  4703. return array(
  4704. 'code' => 1,
  4705. 'result' => array(),
  4706. 'message' => _t('_bx_timeline_txt_msg_no_profile_id'),
  4707. 'page' => $sPage,
  4708. 'tab' => $sTab
  4709. );
  4710. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  4711. $sView = BX_TIMELINE_VIEW_DEFAULT;
  4712. $sFilter = BX_TIMELINE_FILTER_ALL;
  4713. $aModules = array();
  4714. switch($sPage){
  4715. case 'profile':
  4716. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  4717. $sFilter = BX_TIMELINE_FILTER_OWNER;
  4718. break;
  4719. default:
  4720. if ($this -> _oDb -> isModuleByName($sPage))
  4721. $aModules = array($sPage);
  4722. }
  4723. switch($sTab)
  4724. {
  4725. case 'latest':
  4726. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  4727. break;
  4728. case 'popular':
  4729. $sType = BX_TIMELINE_TYPE_HOT;
  4730. break;
  4731. case 'feed':
  4732. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  4733. break;
  4734. default:
  4735. if ($this -> _oDb -> isModuleByName($sTab))
  4736. $aModules = array($sTab);
  4737. }
  4738. $aParams = $this->getParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules);
  4739. $aEvents = $this->_oDb->getEvents($aParams);
  4740. $iCount = $this->_oDb->getEvents(array_merge($aParams, array('count' => true)));
  4741. if(empty($aEvents) || !is_array($aEvents))
  4742. return array(
  4743. 'code' => 0,
  4744. 'result' => array(),
  4745. 'message' => _t('_bx_timeline_txt_msg_no_results'),
  4746. 'page' => $sPage,
  4747. 'tab' => $sTab
  4748. );
  4749. $aBrowseParams = array();
  4750. $aItems = array();
  4751. foreach($aEvents as $aEvent) {
  4752. $aResult = $this->_oTemplate->getData($aEvent, $aBrowseParams);
  4753. if($aResult === false)
  4754. continue;
  4755. $oOwnerProfile = BxDolProfile::getInstance($aResult['owner_id']);
  4756. $aFiles = array();
  4757. $aContent = &$aResult['content'];
  4758. if (!empty($aContent['image']))
  4759. $aFiles['images'] = array_values($aContent['images']);
  4760. if (!empty($aContent['images_attach']))
  4761. $aFiles['images'] = array_values($aContent['images_attach']);
  4762. if (!empty($aContent['videos']))
  4763. $aFiles['videos'] = array_values($aContent['videos']);
  4764. else
  4765. if (!empty($aContent['videos_attach']))
  4766. $aFiles['videos'] = array_values($aContent['videos_attach']);
  4767. if (!empty($aContent['files']))
  4768. $aFiles['files'] = array_values($aContent['files']);
  4769. else
  4770. if (!empty($aContent['files_attach']))
  4771. $aFiles['files'] = array_values($aContent['files_attach']);
  4772. $aItems[$aEvent['id']] = array_merge(array(
  4773. 'owner' => array(
  4774. 'icon' => $oOwnerProfile -> getThumb(),
  4775. 'name' => $oOwnerProfile -> getDisplayName(),
  4776. 'url' => $oOwnerProfile -> getUrl()
  4777. ),
  4778. 'sample' => !empty($aResult['sample']) ? _t($aResult['sample']) : _t('_bx_timeline_txt_sample'),
  4779. 'sample_action' => !empty($aResult['sample_action']) ? _t($aResult['sample_action']) : _t('_bx_timeline_txt_added_sample'),
  4780. 'url' => isset($aResult['url']) ? $aResult['url'] : '',
  4781. 'raw' => isset($aContent['raw']) ? strip_tags($aContent['raw']) : '',
  4782. 'text' => isset($aContent['text']) ? strip_tags($aContent['text']) : '',
  4783. 'views' => isset($aResult['views']['count']) ? (int)$aResult['views']['count'] : 0,
  4784. 'votes' => isset($aResult['votes']['count']) ? (int)$aResult['votes']['count'] : 0,
  4785. 'reactions' => isset($aResult['reactions']['count']) ? (int)$aResult['reactions']['count'] : 0,
  4786. 'scores' => isset($aResult['scores']['count']) ? (int)$aResult['scores']['count'] : 0,
  4787. 'reports' => isset($aResult['reports']['count']) ? (int)$aResult['reports']['count'] : 0,
  4788. 'comments' => isset($aResult['comments']['count']) ? (int)$aResult['comments']['count'] : 0,
  4789. 'date' => isset($aResult['date']) ? $aResult['date'] : $aEvent['date'],
  4790. 'type' => stripos($aEvent['type'], 'timeline') !== false ? 'bx_timeline' : $aEvent['type'],
  4791. 'event_type' => $aEvent['type'],
  4792. 'id' => $aEvent['id'],
  4793. 'content' => $aResult['content'],
  4794. 'title' => isset($aResult['title']) ? _t($aResult['title']) : '',
  4795. 'description' => isset($aResult['description']) ? $aResult['description'] : ''
  4796. ), $aFiles);
  4797. }
  4798. return array(
  4799. 'result' => $aItems,
  4800. 'code' => 0,
  4801. 'message' => '',
  4802. 'page' => $sPage,
  4803. 'tab' => $sTab,
  4804. 'total' => $iCount,
  4805. 'start' => (int)$iStart
  4806. );
  4807. }
  4808. }
  4809. /** @} */