summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Barth2010-09-20 15:41:03 +0000
committerAlex Barth2010-09-20 15:41:03 +0000
commit5ae1fd73b93b391ba4498cd0c9b6d20f2c1f8f86 (patch)
tree52ed5867971bb4712a64b09aee40f0cda3b170c9
parent0be4cf207c51d7bede33490edd1be3c4025fd264 (diff)
Upgrade file handling.
-rw-r--r--includes/FeedsBatch.inc10
-rw-r--r--plugins/FeedsFileFetcher.inc6
-rw-r--r--plugins/FeedsParser.inc5
3 files changed, 12 insertions, 9 deletions
diff --git a/includes/FeedsBatch.inc b/includes/FeedsBatch.inc
index 99d7150..59144c4 100644
--- a/includes/FeedsBatch.inc
+++ b/includes/FeedsBatch.inc
@@ -142,6 +142,7 @@ class FeedsBatch {
* @see FeedsHTTPBatch
*/
class FeedsImportBatch extends FeedsBatch {
+ protected $file_path;
protected $title;
protected $description;
protected $link;
@@ -159,6 +160,7 @@ class FeedsImportBatch extends FeedsBatch {
FEEDS_PARSING => FEEDS_BATCH_COMPLETE,
FEEDS_PROCESSING => FEEDS_BATCH_COMPLETE,
);
+ $this->file_path = NULL;
$this->title = '';
$this->description = '';
$this->link = '';
@@ -189,15 +191,17 @@ class FeedsImportBatch extends FeedsBatch {
*/
public function getFilePath() {
if (!isset($this->file_path)) {
- $dir = file_directory_path() .'/feeds';
+ $dir = 'public://feeds';
if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
throw new Exception(t('Feeds directory either cannot be created or is not writable.'));
}
$dest = file_destination($dir . '/' . get_class($this) .'_'. drupal_get_token($this->url) .'_'. time(), FILE_EXISTS_RENAME);
- $this->file_path = file_save_data($this->getRaw(), $dest);
- if($this->file_path === 0) {
+ $this->file_path = FALSE;
+ $file = file_save_data($this->getRaw(), $dest);
+ if ($file === FALSE) {
throw new Exception(t('Cannot write content to %dest', array('%dest' => $dest)));
}
+ $this->file_path = $file->uri;
}
return $this->file_path;
}
diff --git a/plugins/FeedsFileFetcher.inc b/plugins/FeedsFileFetcher.inc
index 0385458..a582671 100644
--- a/plugins/FeedsFileFetcher.inc
+++ b/plugins/FeedsFileFetcher.inc
@@ -11,8 +11,6 @@
* FeedsFileFetcher.
*/
class FeedsFileBatch extends FeedsImportBatch {
- protected $file_path;
-
/**
* Constructor.
*/
@@ -87,8 +85,8 @@ class FeedsFileFetcher extends FeedsFetcher {
* Override parent::sourceFormValidate().
*/
public function sourceFormValidate(&$values) {
- $feed_dir = file_directory_path() .'/feeds';
- file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
+ $feed_dir = 'public://feeds';
+ file_prepare_directory($feed_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
// If there is a file uploaded, save it, otherwise validate input on
// file.
diff --git a/plugins/FeedsParser.inc b/plugins/FeedsParser.inc
index a7b0acd..254f289 100644
--- a/plugins/FeedsParser.inc
+++ b/plugins/FeedsParser.inc
@@ -247,7 +247,7 @@ class FeedsEnclosure extends FeedsElement {
if(empty($this->file) && $this->getValue()) {
// Check if this enclosure contains a local file.
if (!parse_url($this->getValue(), PHP_URL_SCHEME)) {
- if (file_check_location($this->getValue(), file_directory_path())) {
+ if (strpos($this->getValue(), 'public://') === 0) {
if (file_exists($this->getValue())) {
$this->file = $this->getValue();
return $this->file;
@@ -265,7 +265,8 @@ class FeedsEnclosure extends FeedsElement {
$this->file = copy($this->getValue(), $dest) ? $dest : 0;
}
else {
- $this->file = file_save_data($this->getContent(), $dest);
+ $file = file_save_data($this->getContent(), $dest);
+ $this->file = $file ? $file->uri : 0;
}
if ($this->file === 0) {
throw new Exception(t('Cannot write content to %dest', array('%dest' => $dest)));