BxTimelineModule.php 175 KB

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