BxTimelineModule.php 201 KB

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