Exemplo n.º 1
0
 /**
  * Output the feed to the browser.
  *
  * TODO: Pass $response object to ->outputToBrowser() to loosen dependence on global state for easier testing/prototyping so dev can inject custom SS_HTTPResponse instance.
  *
  * @return	HTMLText
  */
 public function outputToBrowser()
 {
     $prevState = Config::inst()->get('SSViewer', 'source_file_comments');
     Config::inst()->update('SSViewer', 'source_file_comments', false);
     $response = Controller::curr()->getResponse();
     if (is_int($this->lastModified)) {
         HTTP::register_modification_timestamp($this->lastModified);
         $response->addHeader("Last-Modified", gmdate("D, d M Y H:i:s", $this->lastModified) . ' GMT');
     }
     if (!empty($this->etag)) {
         HTTP::register_etag($this->etag);
     }
     if (!headers_sent()) {
         HTTP::add_cache_headers();
         $response->addHeader("Content-Type", "application/rss+xml; charset=utf-8");
     }
     Config::inst()->update('SSViewer', 'source_file_comments', $prevState);
     return $this->renderWith($this->getTemplate());
 }
 public function rss()
 {
     $this->setDefaultView();
     $events = $this->Events();
     foreach ($events as $event) {
         $event->Title = strip_tags($event->DateRange()) . " : " . $event->getTitle();
         $event->Description = $event->getContent();
     }
     $rss_title = $this->RSSTitle ? $this->RSSTitle : sprintf(_t("Calendar.UPCOMINGEVENTSFOR", "Upcoming Events for %s"), $this->Title);
     $rss = new RSSFeed($events, $this->Link(), $rss_title, "", "Title", "Description");
     if (is_int($rss->lastModified)) {
         HTTP::register_modification_timestamp($rss->lastModified);
         header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $rss->lastModified) . ' GMT');
     }
     if (!empty($rss->etag)) {
         HTTP::register_etag($rss->etag);
     }
     $xml = str_replace(' ', ' ', $rss->renderWith('RSSFeed'));
     $xml = preg_replace('/<!--(.|\\s)*?-->/', '', $xml);
     $xml = trim($xml);
     HTTP::add_cache_headers();
     $this->getResponse()->addHeader('Content-Type', 'application/rss+xml');
     echo $xml;
 }
Exemplo n.º 3
0
	/**
	 * Output the feed to the browser
	 */
	function outputToBrowser() {
		if(is_int($this->lastModified)) {
			HTTP::register_modification_timestamp($this->lastModified);
			header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $this->lastModified) . ' GMT');
		}
		if(!empty($this->etag)) {
			HTTP::register_etag($this->etag);
		}

		$body = $this->feedContent();
		HTTP::add_cache_headers();
		header("Content-type: text/xml");
		echo $body;
	}
Exemplo n.º 4
0
 /**
  * Get the RSS feed
  *
  * This method will output the RSS feed with the last 50 posts to the
  * browser.
  */
 function rss()
 {
     HTTP::set_cache_age(3600);
     // cache for one hour
     $threadID = null;
     $forumID = null;
     // optionally allow filtering of the forum posts by the url in the format
     // rss/thread/$ID or rss/forum/$ID
     if (isset($this->urlParams['ID']) && ($action = $this->urlParams['ID'])) {
         if (isset($this->urlParams['OtherID']) && ($id = $this->urlParams['OtherID'])) {
             switch ($action) {
                 case 'forum':
                     $forumID = (int) $id;
                     break;
                 case 'thread':
                     $threadID = (int) $id;
             }
         } else {
             // fallback is that it is the ID of a forum like it was in
             // previous versions
             $forumID = (int) $action;
         }
     }
     $data = array('last_created' => null, 'last_id' => null);
     if (!isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && !isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
         // just to get the version data..
         $this->getNewPostsAvailable(null, null, $forumID, $threadID, &$data);
         // No information provided by the client, just return the last posts
         $rss = new RSSFeed($this->getRecentPosts(50, $forumID, $threadID), $this->Link() . 'rss', sprintf(_t('Forum.RSSFORUMPOSTSTO'), $this->Title), "", "Title", "RSSContent", "RSSAuthor", $data['last_created'], $data['last_id']);
         $rss->outputToBrowser();
     } else {
         // Return only new posts, check the request headers!
         $since = null;
         $etag = null;
         if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
             // Split the If-Modified-Since (Netscape < v6 gets this wrong)
             $since = explode(';', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
             // Turn the client request If-Modified-Since into a timestamp
             $since = @strtotime($since[0]);
             if (!$since) {
                 $since = null;
             }
         }
         if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && is_numeric($_SERVER['HTTP_IF_NONE_MATCH'])) {
             $etag = (int) $_SERVER['HTTP_IF_NONE_MATCH'];
         }
         if ($this->getNewPostsAvailable($since, $etag, $forumID, $threadID, $data)) {
             HTTP::register_modification_timestamp($data['last_created']);
             $rss = new RSSFeed($this->getRecentPosts(50, $forumID, $threadID, $etag), $this->Link() . 'rss', sprintf(_t('Forum.RSSFORUMPOSTSTO'), $this->Title), "", "Title", "RSSContent", "RSSAuthor", $data['last_created'], $data['last_id']);
             $rss->outputToBrowser();
         } else {
             if ($data['last_created']) {
                 HTTP::register_modification_timestamp($data['last_created']);
             }
             if ($data['last_id']) {
                 HTTP::register_etag($data['last_id']);
             }
             // There are no new posts, just output an "304 Not Modified" message
             HTTP::add_cache_headers();
             header('HTTP/1.1 304 Not Modified');
         }
     }
     exit;
 }
Exemplo n.º 5
0
 public function rss()
 {
     $events = $this->getModel()->UpcomingEvents(null, $this->DefaultEventDisplay);
     foreach ($events as $event) {
         $event->Title = strip_tags($event->_Dates()) . " : " . $event->EventTitle();
         $event->Description = $event->EventContent();
     }
     $rss = new RSSFeed($events, $this->Link(), sprintf(_t("Calendar.UPCOMINGEVENTSFOR", "Upcoming Events for %s"), $this->Title), "", "Title", "Description");
     if (is_int($rss->lastModified)) {
         HTTP::register_modification_timestamp($rss->lastModified);
         header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $rss->lastModified) . ' GMT');
     }
     if (!empty($rss->etag)) {
         HTTP::register_etag($rss->etag);
     }
     $xml = str_replace('&nbsp;', '&#160;', $rss->renderWith('RSSFeed'));
     $xml = preg_replace('/<!--(.|\\s)*?-->/', '', $xml);
     $xml = trim($xml);
     HTTP::add_cache_headers();
     header("Content-type: text/xml");
     echo $xml;
 }
Exemplo n.º 6
0
 /**
  * Output the feed to the browser
  */
 function outputToBrowser()
 {
     if (is_int($this->lastModified)) {
         HTTP::register_modification_timestamp($this->lastModified);
         header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $this->lastModified) . ' GMT');
     }
     if (!empty($this->etag)) {
         HTTP::register_etag($this->etag);
     }
     $body = str_replace('&nbsp;', '&#160;', $this->renderWith('RSSFeed'));
     HTTP::add_cache_headers($body);
     header("Content-type: text/xml");
     echo $body;
 }
Exemplo n.º 7
0
 /**
  * Output the feed to the browser
  */
 public function outputToBrowser()
 {
     $prevState = SSViewer::get_source_file_comments();
     SSViewer::set_source_file_comments(false);
     if (is_int($this->lastModified)) {
         HTTP::register_modification_timestamp($this->lastModified);
         header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $this->lastModified) . ' GMT');
     }
     if (!empty($this->etag)) {
         HTTP::register_etag($this->etag);
     }
     if (!headers_sent()) {
         HTTP::add_cache_headers();
         header("Content-type: text/xml");
     }
     SSViewer::set_source_file_comments($prevState);
     return $this->renderWith($this->getTemplate());
 }