BxTimelineModule.php 167 KB

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