euromark 12 年 前
コミット
98cad3295d
2 ファイル変更93 行追加79 行削除
  1. 9 9
      Test/Case/View/RssViewTest.php
  2. 84 70
      View/RssView.php

+ 9 - 9
Test/Case/View/RssViewTest.php

@@ -2,17 +2,11 @@
 /**
 /**
  * PHP 5
  * PHP 5
  *
  *
- * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
  * Licensed under The MIT License
  * Licensed under The MIT License
  * For full copyright and license information, please see the LICENSE.txt
  * For full copyright and license information, please see the LICENSE.txt
  * Redistributions of files must retain the above copyright notice
  * Redistributions of files must retain the above copyright notice
  *
  *
- * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
- * @package       Cake.Test.Case.View
- * @since         CakePHP(tm) v 2.5.0
+ * @author        Mark Scherer
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
  */
 
 
@@ -29,13 +23,19 @@ class RssViewTest extends CakeTestCase {
 
 
 	public $Rss;
 	public $Rss;
 
 
+	public $baseUrl;
+
+	/**
+	 * RssViewTest::setUp()
+	 *
+	 * @return void
+	 */
 	public function setUp() {
 	public function setUp() {
 		parent::setUp();
 		parent::setUp();
-		//Configure::write('debug', 0);
 
 
 		$this->Rss = new RssView();
 		$this->Rss = new RssView();
 
 
-		$this->baseUrl = HTTP_BASE;
+		$this->baseUrl = $this->baseUrl = php_sapi_name() == 'cli' ? '' : HTTP_BASE;
 	}
 	}
 
 
 	/**
 	/**

+ 84 - 70
View/RssView.php

@@ -47,26 +47,26 @@ App::uses('Routing', 'Router');
  */
  */
 class RssView extends View {
 class RssView extends View {
 
 
-/**
- * Default spec version of generated RSS.
- *
- * @var string
- */
+	/**
+	 * Default spec version of generated RSS.
+	 *
+	 * @var string
+	 */
 	public $version = '2.0';
 	public $version = '2.0';
 
 
-/**
- * The subdirectory. RSS views are always in rss. Currently not in use.
- *
- * @var string
- */
+	/**
+	 * The subdirectory. RSS views are always in rss. Currently not in use.
+	 *
+	 * @var string
+	 */
 	public $subDir = 'rss';
 	public $subDir = 'rss';
 
 
-/**
- * Holds usable namespaces.
- *
- * @var array
- * @link http://validator.w3.org/feed/docs/howto/declare_namespaces.html
- */
+	/**
+	 * Holds usable namespaces.
+	 *
+	 * @var array
+	 * @link http://validator.w3.org/feed/docs/howto/declare_namespaces.html
+	 */
 	protected $_namespaces = array(
 	protected $_namespaces = array(
 		'atom' => 'http://www.w3.org/2005/Atom',
 		'atom' => 'http://www.w3.org/2005/Atom',
 		'content' => 'http://purl.org/rss/1.0/modules/content/',
 		'content' => 'http://purl.org/rss/1.0/modules/content/',
@@ -74,18 +74,25 @@ class RssView extends View {
 		'sy' => 'http://purl.org/rss/1.0/modules/syndication/'
 		'sy' => 'http://purl.org/rss/1.0/modules/syndication/'
 	);
 	);
 
 
-/**
- * Holds the namespace keys in use.
- *
- * @var array
- */
+	/**
+	 * Holds the namespace keys in use.
+	 *
+	 * @var array
+	 */
 	protected $_usedNamespaces = array();
 	protected $_usedNamespaces = array();
 
 
-/**
- * Constructor
- *
- * @param Controller $controller
- */
+	/**
+	 * Holds CDATA placeholders.
+	 *
+	 * @var array
+	 */
+	protected $_cdata = array();
+
+	/**
+	 * Constructor
+	 *
+	 * @param Controller $controller
+	 */
 	public function __construct(Controller $controller = null) {
 	public function __construct(Controller $controller = null) {
 		parent::__construct($controller);
 		parent::__construct($controller);
 
 
@@ -106,14 +113,14 @@ class RssView extends View {
 		$this->_namespaces[$prefix] = $url;
 		$this->_namespaces[$prefix] = $url;
 	}
 	}
 
 
-/**
- * Converts an array into an `<item />` element and its contents
- *
- * @param array $att The attributes of the `<item />` element
- * @param array $elements The list of elements contained in this `<item />`
- * @return string An RSS `<item />` element
- * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/rss.html#RssHelper::item
- */
+	/**
+	 * Converts an array into an `<item />` element and its contents
+	 *
+	 * @param array $att The attributes of the `<item />` element
+	 * @param array $elements The list of elements contained in this `<item />`
+	 * @return string An RSS `<item />` element
+	 * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/rss.html#RssHelper::item
+	 */
 	public function channel($channel) {
 	public function channel($channel) {
 		if (!isset($channel['title']) && !empty($this->pageTitle)) {
 		if (!isset($channel['title']) && !empty($this->pageTitle)) {
 			$channel['title'] = $this->pageTitle;
 			$channel['title'] = $this->pageTitle;
@@ -127,22 +134,22 @@ class RssView extends View {
 		return $channel;
 		return $channel;
 	}
 	}
 
 
-/**
- * Converts a time in any format to an RSS time
- *
- * @param integer|string|DateTime $time
- * @return string An RSS-formatted timestamp
- * @see CakeTime::toRSS
- */
+	/**
+	 * Converts a time in any format to an RSS time
+	 *
+	 * @param integer|string|DateTime $time
+	 * @return string An RSS-formatted timestamp
+	 * @see CakeTime::toRSS
+	 */
 	public function time($time) {
 	public function time($time) {
 		return CakeTime::toRSS($time);
 		return CakeTime::toRSS($time);
 	}
 	}
 
 
-/**
- * Skip loading helpers if this is a _serialize based view.
- *
- * @return void
- */
+	/**
+	 * Skip loading helpers if this is a _serialize based view.
+	 *
+	 * @return void
+	 */
 	public function loadHelpers() {
 	public function loadHelpers() {
 		if (isset($this->viewVars['_serialize'])) {
 		if (isset($this->viewVars['_serialize'])) {
 			return;
 			return;
@@ -150,18 +157,18 @@ class RssView extends View {
 		parent::loadHelpers();
 		parent::loadHelpers();
 	}
 	}
 
 
-/**
- * Render a RSS view.
- *
- * Uses the special '_serialize' parameter to convert a set of
- * view variables into a XML response. Makes generating simple
- * XML responses very easy. You can omit the '_serialize' parameter,
- * and use a normal view + layout as well.
- *
- * @param string $view The view being rendered.
- * @param string $layout The layout being rendered.
- * @return string The rendered view.
- */
+	/**
+	 * Render a RSS view.
+	 *
+	 * Uses the special '_serialize' parameter to convert a set of
+	 * view variables into a XML response. Makes generating simple
+	 * XML responses very easy. You can omit the '_serialize' parameter,
+	 * and use a normal view + layout as well.
+	 *
+	 * @param string $view The view being rendered.
+	 * @param string $layout The layout being rendered.
+	 * @return string The rendered view.
+	 */
 	public function render($view = null, $layout = null) {
 	public function render($view = null, $layout = null) {
 		if (isset($this->viewVars['_serialize'])) {
 		if (isset($this->viewVars['_serialize'])) {
 			return $this->_serialize($this->viewVars['_serialize']);
 			return $this->_serialize($this->viewVars['_serialize']);
@@ -171,12 +178,12 @@ class RssView extends View {
 		}
 		}
 	}
 	}
 
 
-/**
- * Serialize view vars.
- *
- * @param array $serialize The viewVars that need to be serialized.
- * @return string The serialized data
- */
+	/**
+	 * Serialize view vars.
+	 *
+	 * @param array $serialize The viewVars that need to be serialized.
+	 * @return string The serialized data
+	 */
 	protected function _serialize($serialize) {
 	protected function _serialize($serialize) {
 		$rootNode = isset($this->viewVars['_rootNode']) ? $this->viewVars['_rootNode'] : 'channel';
 		$rootNode = isset($this->viewVars['_rootNode']) ? $this->viewVars['_rootNode'] : 'channel';
 
 
@@ -206,7 +213,7 @@ class RssView extends View {
 		$channel = $this->channel($data['channel']);
 		$channel = $this->channel($data['channel']);
 
 
 		foreach ($data['items'] as $item) {
 		foreach ($data['items'] as $item) {
-	 		$channel['item'][] = $this->_prepareOutput($item);
+			$channel['item'][] = $this->_prepareOutput($item);
 		}
 		}
 
 
 		$array = array(
 		$array = array(
@@ -227,9 +234,6 @@ class RssView extends View {
 		}
 		}
 
 
 		$output = Xml::fromArray($array, $options)->asXML();
 		$output = Xml::fromArray($array, $options)->asXML();
-		//$output = preg_replace('/version="([0-9\.]+)" encoding="([a-z-]+)"/i', 'version="\1"', $output);
-		//$output = str_replace(' encoding="UTF-8"', '', $output);
-
 		$output = $this->_replaceCdata($output);
 		$output = $this->_replaceCdata($output);
 
 
 		return $output;
 		return $output;
@@ -340,14 +344,24 @@ class RssView extends View {
 		return $item;
 		return $item;
 	}
 	}
 
 
-	protected $_cdata = array();
-
+	/**
+	 * RssView::_newCdata()
+	 *
+	 * @param string $content
+	 * @return string
+	 */
 	protected function _newCdata($content) {
 	protected function _newCdata($content) {
 		$i = count($this->_cdata);
 		$i = count($this->_cdata);
 		$this->_cdata[$i] = $content;
 		$this->_cdata[$i] = $content;
 		return '###CDATA-' . $i . '###';
 		return '###CDATA-' . $i . '###';
 	}
 	}
 
 
+	/**
+	 * RssView::_replaceCdata()
+	 *
+	 * @param string $content
+	 * @return string
+	 */
 	protected function _replaceCdata($content) {
 	protected function _replaceCdata($content) {
 		foreach ($this->_cdata as $n => $data) {
 		foreach ($this->_cdata as $n => $data) {
 			$data = '<![CDATA[' . $data . ']]>';
 			$data = '<![CDATA[' . $data . ']]>';