1
0

BxTimelineModule.php 175 KB

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