BxTimelineModule.php 230 KB

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