BxTimelineModule.php 213 KB

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