BxTimelineModule.php 233 KB

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