From ab97a702d9682d7149cee989247d1c5e8104562b Mon Sep 17 00:00:00 2001 From: Chris Leppanen <chris.leppanen@gmail.com> Date: Wed, 5 Sep 2012 22:23:02 -0700 Subject: [PATCH] Add support for SimplePie 1.3 --- README.txt | 5 ++-- feeds.module | 42 ++++++++++++++++++++++++++++---- feeds.plugins.inc | 2 +- plugins/FeedsSimplePieParser.inc | 4 +-- tests/feeds.test | 33 +++++++++---------------- tests/feeds_mapper_file.test | 6 ++--- 6 files changed, 58 insertions(+), 34 deletions(-) diff --git a/README.txt b/README.txt index f932d94a..5c137a2f 100644 --- a/README.txt +++ b/README.txt @@ -49,8 +49,9 @@ Installation Feeds News, Feeds Import, Feeds Fast News (more info below). - Make sure cron is correctly configured http://drupal.org/cron - Go to import/ to import data. -- To use SimplePie parser, download SimplePie and place simplepie.inc into - feeds/libraries. Recommended version: 1.2. +- To use SimplePie parser, download either the compiled or minified SimplePie + and place simplepie_[version].compiled.php into feeds/libraries as + simplepie.compiled.php. Recommended version: 1.3. http://simplepie.org/ Feature modules diff --git a/feeds.module b/feeds.module index 54eb3a20..2084b783 100644 --- a/feeds.module +++ b/feeds.module @@ -960,27 +960,35 @@ function feeds_include_library($file, $library) { // We can safely use E_DEPRECATED since Drupal 7 requires PHP 5.3+ error_reporting($level ^ E_DEPRECATED ^ E_STRICT); } - // Try first whether libraries module is present and load the file from - // there. If this fails, require the library from the local path. + $library_dir = variable_get('feeds_library_dir', FALSE); + $feeds_library_path = DRUPAL_ROOT . '/' . drupal_get_path('module', 'feeds') . "/libraries/$file"; + // Try first whether libraries module is present and load the file from + // there. If this fails, require the library from the local path. if (module_exists('libraries') && file_exists(libraries_get_path($library) . "/$file")) { require libraries_get_path($library) . "/$file"; + $included[$file] = TRUE; } elseif ($library_dir && file_exists("$library_dir/$library/$file")) { require "$library_dir/$library/$file"; + $included[$file] = TRUE; } - else { + elseif (file_exists($feeds_library_path)) { // @todo: Throws "Deprecated function: Assigning the return value of new // by reference is deprecated." - require DRUPAL_ROOT . '/' . drupal_get_path('module', 'feeds') . "/libraries/$file"; + require $feeds_library_path; + $included[$file] = TRUE; } // Restore error reporting level if (isset($level)) { error_reporting($level); } } - $included[$file] = TRUE; + if (isset($included[$file])) { + return TRUE; + } + return FALSE; } /** @@ -1012,6 +1020,30 @@ function feeds_library_exists($file, $library) { return FALSE; } + /** + * Checks whether simplepie exists. + */ +function feeds_simplepie_exists() { + return (feeds_library_exists('simplepie.compiled.php', 'simplepie') || + feeds_library_exists('simplepie.mini.php', 'simplepie') || + feeds_library_exists('simplepie.inc', 'simplepie') + ); +} + +/** + * Includes the simplepie library. + */ +function feeds_include_simplepie() { + $files = array('simplepie.mini.php', 'simplepie.compiled.php', 'simplepie.inc'); + + foreach ($files as $file) { + if (feeds_include_library($file, 'simplepie')) { + return TRUE; + } + } + return FALSE; +} + /** * Simplified drupal_alter(). * diff --git a/feeds.plugins.inc b/feeds.plugins.inc index 26d9bff1..3f23cb81 100644 --- a/feeds.plugins.inc +++ b/feeds.plugins.inc @@ -106,7 +106,7 @@ function _feeds_feeds_plugins() { 'path' => $path, ), ); - if (feeds_library_exists('simplepie.inc', 'simplepie')) { + if (feeds_simplepie_exists()) { $info['FeedsSimplePieParser'] = array( 'name' => 'SimplePie parser', 'description' => 'Parse RSS and Atom feeds.', diff --git a/plugins/FeedsSimplePieParser.inc b/plugins/FeedsSimplePieParser.inc index 164b1716..cadb6b81 100644 --- a/plugins/FeedsSimplePieParser.inc +++ b/plugins/FeedsSimplePieParser.inc @@ -35,7 +35,7 @@ class FeedsSimplePieEnclosure extends FeedsEnclosure { * Ensure that the simplepie class definitions are loaded for the enclosure when unserializing. */ public function __wakeup() { - feeds_include_library('simplepie.inc', 'simplepie'); + feeds_include_simplepie(); $this->simplepie_enclosure = unserialize($this->_serialized_simplepie_enclosure); } @@ -65,7 +65,7 @@ class FeedsSimplePieParser extends FeedsParser { * Implements FeedsParser::parse(). */ public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) { - feeds_include_library('simplepie.inc', 'simplepie'); + feeds_include_simplepie(); // Please be quiet SimplePie. $level = error_reporting(); diff --git a/tests/feeds.test b/tests/feeds.test index ef5374e2..77472801 100644 --- a/tests/feeds.test +++ b/tests/feeds.test @@ -148,7 +148,7 @@ class FeedsWebTestCase extends DrupalWebTestCase { <body> <outline text="Feeds test group" > <outline title="Development Seed - Technological Solutions for Progressive Organizations" text="" xmlUrl="' . $path . 'developmentseed.rss2" type="rss" /> - <outline title="Magyar Nemzet Online - H’rek" text="" xmlUrl="' . $path . 'feed_without_guid.rss2" type="rss" /> + <outline title="Magyar Nemzet Online - H?rek" text="" xmlUrl="' . $path . 'feed_without_guid.rss2" type="rss" /> <outline title="Drupal planet" text="" type="rss" xmlUrl="' . $path . 'drupalplanet.rss2" /> </outline> </body> @@ -440,13 +440,10 @@ class FeedsWebTestCase extends DrupalWebTestCase { * * Sets the 'feeds_simplepie_library_dir' variable to the directory where * SimplePie is downloaded. - * - * @param $version - * The SimplePie version number to download and extract. */ function downloadExtractSimplePie($version) { - $url = "https://github.com/simplepie/simplepie/tarball/$version"; - $filename = "SimplePIE-$version.tar.gz"; + $url = "http://simplepie.org/downloads/simplepie_$version.mini.php"; + $filename = 'simplepie.mini.php'; // Avoid downloading the file dozens of times $library_dir = $this->originalFileDirectory . '/simpletest/feeds'; @@ -456,8 +453,12 @@ class FeedsWebTestCase extends DrupalWebTestCase { mkdir($library_dir, '0777', TRUE); } - // Local archive name. - $local_archive = $library_dir . '/' . $filename; + if (!file_exists($simplepie_library_dir)) { + mkdir($simplepie_library_dir, '0777', TRUE); + } + + // Local file name. + $local_file = $simplepie_library_dir . '/' . $filename; // Begin single threaded code. if (function_exists('sem_get')) { @@ -466,17 +467,8 @@ class FeedsWebTestCase extends DrupalWebTestCase { } // Download and extact the archive, but only in one thread. - if (!file_exists($local_archive)) { - $local_archive = system_retrieve_file($url, $local_archive, FALSE, FILE_EXISTS_REPLACE); - } - - if (!file_exists($simplepie_library_dir)) { - // Extract the files. - $archiver = archiver_get_archiver($local_archive); - $archiver->extract($library_dir); - $dirs = glob($library_dir . '/simplepie*', GLOB_ONLYDIR); - $dir = reset($dirs); - rename($dir, $simplepie_library_dir); + if (!file_exists($local_file)) { + $local_file = system_retrieve_file($url, $local_file, FALSE, FILE_EXISTS_REPLACE); } if (function_exists('sem_get')) { @@ -485,8 +477,7 @@ class FeedsWebTestCase extends DrupalWebTestCase { // End single threaded code. // Verify that files were successfully extracted. - $file = $simplepie_library_dir . '/simplepie.inc'; - $this->assertTrue(file_exists($file), t('@file found.', array('@file' => $file))); + $this->assertTrue(file_exists($local_file), t('@file found.', array('@file' => $local_file))); // Set the simpletest library directory. variable_set('feeds_library_dir', $library_dir); diff --git a/tests/feeds_mapper_file.test b/tests/feeds_mapper_file.test index 15d3f558..4738d4c1 100644 --- a/tests/feeds_mapper_file.test +++ b/tests/feeds_mapper_file.test @@ -34,9 +34,9 @@ class FeedsMapperFileTestCase extends FeedsMapperTestCase { // Only download simplepie if the plugin doesn't already exist somewhere. // People running tests locally might have it. - if (!feeds_library_exists('simplepie.inc', 'simplepie')) { - $this->downloadExtractSimplePie('1.2.1'); - $this->assertTrue(feeds_library_exists('simplepie.inc', 'simplepie')); + if (!feeds_simplepie_exists()) { + $this->downloadExtractSimplePie('1.3'); + $this->assertTrue(feeds_simplepie_exists()); // Reset all the caches! $this->resetAll(); } -- GitLab