diff --git a/feeds.plugins.inc b/feeds.plugins.inc index 0bc096d2369056057647e5454f9d54d757edaa35..e1e7e4975608510b007e5f5e09d79e64e3f6ae59 100644 --- a/feeds.plugins.inc +++ b/feeds.plugins.inc @@ -113,7 +113,7 @@ function _feeds_feeds_plugins() { 'description' => 'Parse RSS and Atom feeds.', 'help' => 'Use <a href="http://simplepie.org">SimplePie</a> to parse XML feeds in RSS 1, RSS 2 and Atom format.', 'handler' => array( - 'parent' => 'FeedsSyndicationParser', + 'parent' => 'FeedsParser', 'class' => 'FeedsSimplePieParser', 'file' => 'FeedsSimplePieParser.inc', 'path' => $path, diff --git a/plugins/FeedsParser.inc b/plugins/FeedsParser.inc index 3068c4edfcd009acc61269a225cd27399621bb9f..3f5cae009c0f3712fee25492c335da66a8a5ffe2 100644 --- a/plugins/FeedsParser.inc +++ b/plugins/FeedsParser.inc @@ -97,6 +97,67 @@ class FeedsElement { } } +/** + * Enclosure element, can be part of the result array. + */ +class FeedsEnclosure extends FeedsElement { + protected $mime_type; + protected $file; + + /** + * Constructor, requires MIME type. + */ + public function __construct($value, $mime_type) { + parent::__construct($value); + $this->mime_type = $mime_type; + } + + /** + * @return + * MIME type of return value of getValue(). + */ + public function getMIMEType() { + return $this->mime_type; + } + + /** + * @return + * The content of the referenced resource. + */ + public function getContent() { + feeds_include_library('http_request.inc', 'http_request'); + $result = http_request_get($this->getValue()); + if ($result->code != 200) { + throw new Exception(t('Download of @url failed with code !code.', array('@url' => $this->getValue(), '!code' => $result->code))); + } + return $result->data; + } + + /** + * @return + * The file path to the downloaded resource referenced by the enclosure. + * Downloads resource if not downloaded yet. + * + * @todo Get file extension from mime_type. + * @todo This is not concurrency safe. + */ + public function getFile() { + if(!isset($this->file)) { + $dest = file_destination(file_directory_temp() .'/'. get_class($this) .'-'. basename($this->getValue()), FILE_EXISTS_RENAME); + if (ini_get('allow_url_fopen')) { + $this->file = copy($this->getValue(), $dest) ? $dest : 0; + } + else { + $this->file = file_save_data($this->getContent(), $dest); + } + if ($this->file === 0) { + throw new Exception(t('Cannot write content to %dest', array('%dest' => $dest))); + } + } + return $this->file; + } +} + /** * Defines a date element of a parsed result (including ranges, repeat). */ diff --git a/plugins/FeedsSyndicationParser.inc b/plugins/FeedsSyndicationParser.inc index 08473e83a48a523bab22a2cdc974de33cb0508cd..1561bce211580055629b15453634b7a75a09bbb3 100644 --- a/plugins/FeedsSyndicationParser.inc +++ b/plugins/FeedsSyndicationParser.inc @@ -1,67 +1,6 @@ <?php // $Id$ -/** - * Enclosure element, can be part of the result array. - */ -class FeedsEnclosure extends FeedsElement { - protected $mime_type; - protected $file; - - /** - * Constructor, requires MIME type. - */ - public function __construct($value, $mime_type) { - parent::__construct($value); - $this->mime_type = $mime_type; - } - - /** - * @return - * MIME type of return value of getValue(). - */ - public function getMIMEType() { - return $this->mime_type; - } - - /** - * @return - * The content of the referenced resource. - */ - public function getContent() { - feeds_include_library('http_request.inc', 'http_request'); - $result = http_request_get($this->getValue()); - if ($result->code != 200) { - throw new Exception(t('Download of @url failed with code !code.', array('@url' => $this->getValue(), '!code' => $result->code))); - } - return $result->data; - } - - /** - * @return - * The file path to the downloaded resource referenced by the enclosure. - * Downloads resource if not downloaded yet. - * - * @todo Get file extension from mime_type. - * @todo This is not concurrency safe. - */ - public function getFile() { - if(!isset($this->file)) { - $dest = file_destination(file_directory_temp() .'/'. get_class($this) .'-'. basename($this->getValue()), FILE_EXISTS_RENAME); - if (ini_get('allow_url_fopen')) { - $this->file = copy($this->getValue(), $dest) ? $dest : 0; - } - else { - $this->file = file_save_data($this->getContent(), $dest); - } - if ($this->file === 0) { - throw new Exception(t('Cannot write content to %dest', array('%dest' => $dest))); - } - } - return $this->file; - } -} - /** * Class definition for Common Syndication Parser. *