BxTimelineModule.php 175 KB

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