BxTimelineModule.php 206 KB

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