BxTimelineModule.php 191 KB

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