BxTimelineModule.php 206 KB

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