BxTimelineModule.php 234 KB

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