BxTimelineModule.php 176 KB

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