Skip to content
Snippets Groups Projects
Commit ab97a702 authored by Chris Leppanen's avatar Chris Leppanen
Browse files

Add support for SimplePie 1.3

parent 76115061
No related branches found
No related tags found
No related merge requests found
...@@ -49,8 +49,9 @@ Installation ...@@ -49,8 +49,9 @@ Installation
Feeds News, Feeds Import, Feeds Fast News (more info below). Feeds News, Feeds Import, Feeds Fast News (more info below).
- Make sure cron is correctly configured http://drupal.org/cron - Make sure cron is correctly configured http://drupal.org/cron
- Go to import/ to import data. - Go to import/ to import data.
- To use SimplePie parser, download SimplePie and place simplepie.inc into - To use SimplePie parser, download either the compiled or minified SimplePie
feeds/libraries. Recommended version: 1.2. and place simplepie_[version].compiled.php into feeds/libraries as
simplepie.compiled.php. Recommended version: 1.3.
http://simplepie.org/ http://simplepie.org/
Feature modules Feature modules
......
...@@ -960,27 +960,35 @@ function feeds_include_library($file, $library) { ...@@ -960,27 +960,35 @@ function feeds_include_library($file, $library) {
// We can safely use E_DEPRECATED since Drupal 7 requires PHP 5.3+ // We can safely use E_DEPRECATED since Drupal 7 requires PHP 5.3+
error_reporting($level ^ E_DEPRECATED ^ E_STRICT); 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); $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")) { if (module_exists('libraries') && file_exists(libraries_get_path($library) . "/$file")) {
require libraries_get_path($library) . "/$file"; require libraries_get_path($library) . "/$file";
$included[$file] = TRUE;
} }
elseif ($library_dir && file_exists("$library_dir/$library/$file")) { elseif ($library_dir && file_exists("$library_dir/$library/$file")) {
require "$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 // @todo: Throws "Deprecated function: Assigning the return value of new
// by reference is deprecated." // 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 // Restore error reporting level
if (isset($level)) { if (isset($level)) {
error_reporting($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) { ...@@ -1012,6 +1020,30 @@ function feeds_library_exists($file, $library) {
return FALSE; 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(). * Simplified drupal_alter().
* *
......
...@@ -106,7 +106,7 @@ function _feeds_feeds_plugins() { ...@@ -106,7 +106,7 @@ function _feeds_feeds_plugins() {
'path' => $path, 'path' => $path,
), ),
); );
if (feeds_library_exists('simplepie.inc', 'simplepie')) { if (feeds_simplepie_exists()) {
$info['FeedsSimplePieParser'] = array( $info['FeedsSimplePieParser'] = array(
'name' => 'SimplePie parser', 'name' => 'SimplePie parser',
'description' => 'Parse RSS and Atom feeds.', 'description' => 'Parse RSS and Atom feeds.',
......
...@@ -35,7 +35,7 @@ class FeedsSimplePieEnclosure extends FeedsEnclosure { ...@@ -35,7 +35,7 @@ class FeedsSimplePieEnclosure extends FeedsEnclosure {
* Ensure that the simplepie class definitions are loaded for the enclosure when unserializing. * Ensure that the simplepie class definitions are loaded for the enclosure when unserializing.
*/ */
public function __wakeup() { public function __wakeup() {
feeds_include_library('simplepie.inc', 'simplepie'); feeds_include_simplepie();
$this->simplepie_enclosure = unserialize($this->_serialized_simplepie_enclosure); $this->simplepie_enclosure = unserialize($this->_serialized_simplepie_enclosure);
} }
...@@ -65,7 +65,7 @@ class FeedsSimplePieParser extends FeedsParser { ...@@ -65,7 +65,7 @@ class FeedsSimplePieParser extends FeedsParser {
* Implements FeedsParser::parse(). * Implements FeedsParser::parse().
*/ */
public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) { public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
feeds_include_library('simplepie.inc', 'simplepie'); feeds_include_simplepie();
// Please be quiet SimplePie. // Please be quiet SimplePie.
$level = error_reporting(); $level = error_reporting();
......
...@@ -148,7 +148,7 @@ class FeedsWebTestCase extends DrupalWebTestCase { ...@@ -148,7 +148,7 @@ class FeedsWebTestCase extends DrupalWebTestCase {
<body> <body>
<outline text="Feeds test group" > <outline text="Feeds test group" >
<outline title="Development Seed - Technological Solutions for Progressive Organizations" text="" xmlUrl="' . $path . 'developmentseed.rss2" type="rss" /> <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 title="Drupal planet" text="" type="rss" xmlUrl="' . $path . 'drupalplanet.rss2" />
</outline> </outline>
</body> </body>
...@@ -440,13 +440,10 @@ class FeedsWebTestCase extends DrupalWebTestCase { ...@@ -440,13 +440,10 @@ class FeedsWebTestCase extends DrupalWebTestCase {
* *
* Sets the 'feeds_simplepie_library_dir' variable to the directory where * Sets the 'feeds_simplepie_library_dir' variable to the directory where
* SimplePie is downloaded. * SimplePie is downloaded.
*
* @param $version
* The SimplePie version number to download and extract.
*/ */
function downloadExtractSimplePie($version) { function downloadExtractSimplePie($version) {
$url = "https://github.com/simplepie/simplepie/tarball/$version"; $url = "http://simplepie.org/downloads/simplepie_$version.mini.php";
$filename = "SimplePIE-$version.tar.gz"; $filename = 'simplepie.mini.php';
// Avoid downloading the file dozens of times // Avoid downloading the file dozens of times
$library_dir = $this->originalFileDirectory . '/simpletest/feeds'; $library_dir = $this->originalFileDirectory . '/simpletest/feeds';
...@@ -456,8 +453,12 @@ class FeedsWebTestCase extends DrupalWebTestCase { ...@@ -456,8 +453,12 @@ class FeedsWebTestCase extends DrupalWebTestCase {
mkdir($library_dir, '0777', TRUE); mkdir($library_dir, '0777', TRUE);
} }
// Local archive name. if (!file_exists($simplepie_library_dir)) {
$local_archive = $library_dir . '/' . $filename; mkdir($simplepie_library_dir, '0777', TRUE);
}
// Local file name.
$local_file = $simplepie_library_dir . '/' . $filename;
// Begin single threaded code. // Begin single threaded code.
if (function_exists('sem_get')) { if (function_exists('sem_get')) {
...@@ -466,17 +467,8 @@ class FeedsWebTestCase extends DrupalWebTestCase { ...@@ -466,17 +467,8 @@ class FeedsWebTestCase extends DrupalWebTestCase {
} }
// Download and extact the archive, but only in one thread. // Download and extact the archive, but only in one thread.
if (!file_exists($local_archive)) { if (!file_exists($local_file)) {
$local_archive = system_retrieve_file($url, $local_archive, FALSE, FILE_EXISTS_REPLACE); $local_file = system_retrieve_file($url, $local_file, 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 (function_exists('sem_get')) { if (function_exists('sem_get')) {
...@@ -485,8 +477,7 @@ class FeedsWebTestCase extends DrupalWebTestCase { ...@@ -485,8 +477,7 @@ class FeedsWebTestCase extends DrupalWebTestCase {
// End single threaded code. // End single threaded code.
// Verify that files were successfully extracted. // Verify that files were successfully extracted.
$file = $simplepie_library_dir . '/simplepie.inc'; $this->assertTrue(file_exists($local_file), t('@file found.', array('@file' => $local_file)));
$this->assertTrue(file_exists($file), t('@file found.', array('@file' => $file)));
// Set the simpletest library directory. // Set the simpletest library directory.
variable_set('feeds_library_dir', $library_dir); variable_set('feeds_library_dir', $library_dir);
......
...@@ -34,9 +34,9 @@ class FeedsMapperFileTestCase extends FeedsMapperTestCase { ...@@ -34,9 +34,9 @@ class FeedsMapperFileTestCase extends FeedsMapperTestCase {
// Only download simplepie if the plugin doesn't already exist somewhere. // Only download simplepie if the plugin doesn't already exist somewhere.
// People running tests locally might have it. // People running tests locally might have it.
if (!feeds_library_exists('simplepie.inc', 'simplepie')) { if (!feeds_simplepie_exists()) {
$this->downloadExtractSimplePie('1.2.1'); $this->downloadExtractSimplePie('1.3');
$this->assertTrue(feeds_library_exists('simplepie.inc', 'simplepie')); $this->assertTrue(feeds_simplepie_exists());
// Reset all the caches! // Reset all the caches!
$this->resetAll(); $this->resetAll();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment