BxBaseRss.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolRss');
  10. /**
  11. * Privacy representation.
  12. * @see BxDolPrivacy
  13. */
  14. class BxBaseRss extends BxDolRss
  15. {
  16. protected $_oTemplate;
  17. public function __construct ($aOptions, $oTemplate)
  18. {
  19. parent::__construct ($aOptions);
  20. if ($oTemplate)
  21. $this->_oTemplate = $oTemplate;
  22. else
  23. $this->_oTemplate = BxDolTemplate::getInstance();
  24. }
  25. public function getFeed($mixedId, $iUserId = 0)
  26. {
  27. $sUrl = $this->getUrl($mixedId);
  28. $aMarkers = array('SiteUrl' => BX_DOL_URL_ROOT);
  29. if($iUserId) {
  30. bx_import('BxDolProfile');
  31. $oProfile = BxDolProfile::getInstance($iUserId);
  32. if(!$oProfile) {
  33. bx_import('BxDolProfileUndefined');
  34. $oProfile = BxDolProfileUndefined::getInstance();
  35. }
  36. $aMarkers['NickName'] = $oProfile->getDisplayName();
  37. }
  38. $sUrl = bx_replace_markers($sUrl, $aMarkers);
  39. header('Content-Type: text/xml; charset=utf-8');
  40. return bx_file_get_contents($sUrl . (defined('BX_PROFILER') && BX_PROFILER && 0 == strncmp(BX_DOL_URL_ROOT, $sUrl, strlen(BX_DOL_URL_ROOT)) ? '&bx_profiler_disable=1' : ''));
  41. }
  42. /**
  43. * Outputs holder html for dynamically loaded RSS.
  44. * It automatically adds necessary js, css files and make injection into HTML HEAD section.
  45. * @param $mixedRssId - system rss name, or current block id (if inserted into builder page)
  46. * @param $iRssNum - numbr of rss items to disolay
  47. * @param $iMemberId - optional member id
  48. */
  49. public function getHolder($mixedRssId, $iRssNum, $iMemberId = 0, $bInit = true)
  50. {
  51. if($bInit && !self::$bInitialized) {
  52. $this->_addJsCss();
  53. $this->_addInjection();
  54. self::$bInitialized = true;
  55. }
  56. return $this->_oTemplate->parseHtmlByName('rss_holder.html', array (
  57. 'rss_object' => $this->_sObject,
  58. 'rss_id' => $mixedRssId,
  59. 'rss_num' => $iRssNum,
  60. 'member_id' => $iMemberId,
  61. ));
  62. }
  63. protected function _addJsCss()
  64. {
  65. $this->_oTemplate->addCss(array('rss.css'));
  66. $this->_oTemplate->addJs(array(
  67. 'jquery.jfeed.pack.js',
  68. 'jquery.dolRSSFeed.js',
  69. ));
  70. }
  71. protected function _addInjection()
  72. {
  73. $sContent = $this->_oTemplate->_wrapInTagJsCode('$(document).ready(function() {$("div.RSSAggrCont").dolRSSFeed();});');
  74. $this->_oTemplate->addInjection ('injection_head', 'text', $sContent);
  75. }
  76. }
  77. /** @} */