Skip to content

Commit

Permalink
Support {} parameter. RE: #4
Browse files Browse the repository at this point in the history
  • Loading branch information
brendo committed Jun 8, 2012
1 parent 0fe3c6b commit 87f433c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 7 additions & 3 deletions content/content.importers.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,12 @@ public function __actionEditNormal() {
$this->_errors['source'] = __('Source must not be empty.');
}

else if(!filter_var($fields['source'], FILTER_VALIDATE_URL)) {
$this->_errors['source'] = __('Source is not a valid URL.');
else {
// Support {$root}
$evaluated_source = str_replace('{$root}', URL, $fields['source']);
if(!filter_var($evaluated_source, FILTER_VALIDATE_URL)) {
$this->_errors['source'] = __('Source is not a valid URL.');
}
}

// Namespaces ---------------------------------------------------------
Expand All @@ -285,7 +289,7 @@ public function __actionEditNormal() {
) {
$gateway = new Gateway();
$gateway->init();
$gateway->setopt('URL', $fields['source']);
$gateway->setopt('URL', $evaluated_source);
$gateway->setopt('TIMEOUT', 60);
$data = $gateway->exec();

Expand Down
10 changes: 6 additions & 4 deletions lib/class.xmlimporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,19 @@ function handleXMLError($errno, $errstr, $errfile, $errline, $context) {
$options['source'] = $source;
}

// Support {$root}
$options['source'] = str_replace('{$root}', URL, $options['source']);

// Fetch document:
$gateway = new Gateway();
$gateway->init();
$gateway->setopt('URL', $options['source']);
$gateway->setopt('TIMEOUT', 60);
$data = $gateway->exec();

if (empty($data)) {
$this->_errors[] = __('No data to import.');
$info = $gateway->getInfoLast();
if (empty($data) || $info['http_code'] >= 400) {
$this->_errors[] = __('No data to import. URL returned HTTP code %d', array($info['http_code']));
$passed = false;
}
}
Expand Down Expand Up @@ -379,5 +383,3 @@ public function commit() {
}
}
}

?>

0 comments on commit 87f433c

Please sign in to comment.