BxTimelineModule.php 214 KB

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