BxTimelineModule.php 231 KB

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