BxTimelineModule.php 204 KB

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