BxTimelineModule.php 174 KB

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