BxTimelineModule.php 235 KB

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