expand error messages in subscribeToFeed(), provide proper error message
when URL download failed (refs #489)
This commit is contained in:
parent
9da07c8ad2
commit
23d2471c92
|
@ -250,6 +250,11 @@ class Dlg extends Handler_Protected {
|
||||||
print "<div class=\"dlgSec\">".__("Feed")."</div>";
|
print "<div class=\"dlgSec\">".__("Feed")."</div>";
|
||||||
print "<div class=\"dlgSecCont\">";
|
print "<div class=\"dlgSecCont\">";
|
||||||
|
|
||||||
|
print "<div style='float : right'>
|
||||||
|
<img style='display : none'
|
||||||
|
id='feed_add_spinner' src='".
|
||||||
|
theme_image($this->link, 'images/indicator_white.gif')."'></div>";
|
||||||
|
|
||||||
print "<input style=\"font-size : 16px; width : 20em;\"
|
print "<input style=\"font-size : 16px; width : 20em;\"
|
||||||
placeHolder=\"".__("Feed URL")."\"
|
placeHolder=\"".__("Feed URL")."\"
|
||||||
dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">";
|
dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">";
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
define('EXPECTED_CONFIG_VERSION', 25);
|
define('EXPECTED_CONFIG_VERSION', 25);
|
||||||
define('SCHEMA_VERSION', 94);
|
define('SCHEMA_VERSION', 94);
|
||||||
|
|
||||||
|
$fetch_last_error = false;
|
||||||
|
|
||||||
function __autoload($class) {
|
function __autoload($class) {
|
||||||
$class_file = str_replace("_", "/", strtolower(basename($class)));
|
$class_file = str_replace("_", "/", strtolower(basename($class)));
|
||||||
|
|
||||||
|
@ -281,6 +283,8 @@
|
||||||
$login = urlencode($login);
|
$login = urlencode($login);
|
||||||
$pass = urlencode($pass);
|
$pass = urlencode($pass);
|
||||||
|
|
||||||
|
global $fetch_last_error;
|
||||||
|
|
||||||
if (function_exists('curl_init') && !ini_get("open_basedir")) {
|
if (function_exists('curl_init') && !ini_get("open_basedir")) {
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
|
|
||||||
|
@ -306,6 +310,7 @@
|
||||||
$contents = @curl_exec($ch);
|
$contents = @curl_exec($ch);
|
||||||
|
|
||||||
if ($contents === false) {
|
if ($contents === false) {
|
||||||
|
$fetch_last_error = curl_error($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -330,7 +335,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return @file_get_contents($url);
|
$data = @file_get_contents($url);
|
||||||
|
|
||||||
|
if (!$data && function_exists('error_get_last')) {
|
||||||
|
$error = error_get_last();
|
||||||
|
$fetch_last_error = $error["message"];
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1792,7 +1803,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return integer Status code:
|
* @return array (code => Status code, message => error message if available)
|
||||||
|
*
|
||||||
* 0 - OK, Feed already exists
|
* 0 - OK, Feed already exists
|
||||||
* 1 - OK, Feed added
|
* 1 - OK, Feed added
|
||||||
* 2 - Invalid URL
|
* 2 - Invalid URL
|
||||||
|
@ -1805,11 +1817,13 @@
|
||||||
function subscribe_to_feed($link, $url, $cat_id = 0,
|
function subscribe_to_feed($link, $url, $cat_id = 0,
|
||||||
$auth_login = '', $auth_pass = '', $need_auth = false) {
|
$auth_login = '', $auth_pass = '', $need_auth = false) {
|
||||||
|
|
||||||
|
global $fetch_last_error;
|
||||||
|
|
||||||
require_once "include/rssfuncs.php";
|
require_once "include/rssfuncs.php";
|
||||||
|
|
||||||
$url = fix_url($url);
|
$url = fix_url($url);
|
||||||
|
|
||||||
if (!$url || !validate_feed_url($url)) return 2;
|
if (!$url || !validate_feed_url($url)) return array("code" => 2);
|
||||||
|
|
||||||
$update_method = 0;
|
$update_method = 0;
|
||||||
|
|
||||||
|
@ -1819,14 +1833,15 @@
|
||||||
$has_oauth = db_fetch_result($result, 0, 'twitter_oauth');
|
$has_oauth = db_fetch_result($result, 0, 'twitter_oauth');
|
||||||
|
|
||||||
if (!$need_auth || !$has_oauth || strpos($url, '://api.twitter.com') === false) {
|
if (!$need_auth || !$has_oauth || strpos($url, '://api.twitter.com') === false) {
|
||||||
if (!fetch_file_contents($url, false, $auth_login, $auth_pass)) return 5;
|
if (!fetch_file_contents($url, false, $auth_login, $auth_pass))
|
||||||
|
return array("code" => 5, "message" => $fetch_last_error);
|
||||||
|
|
||||||
if (url_is_html($url, $auth_login, $auth_pass)) {
|
if (url_is_html($url, $auth_login, $auth_pass)) {
|
||||||
$feedUrls = get_feeds_from_html($url, $auth_login, $auth_pass);
|
$feedUrls = get_feeds_from_html($url, $auth_login, $auth_pass);
|
||||||
if (count($feedUrls) == 0) {
|
if (count($feedUrls) == 0) {
|
||||||
return 3;
|
return array("code" => 3);
|
||||||
} else if (count($feedUrls) > 1) {
|
} else if (count($feedUrls) > 1) {
|
||||||
return 4;
|
return array("code" => 4);
|
||||||
}
|
}
|
||||||
//use feed url as new URL
|
//use feed url as new URL
|
||||||
$url = key($feedUrls);
|
$url = key($feedUrls);
|
||||||
|
@ -1834,7 +1849,7 @@
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!fetch_twitter_rss($link, $url, $_SESSION['uid']))
|
if (!fetch_twitter_rss($link, $url, $_SESSION['uid']))
|
||||||
return 5;
|
return array("code" => 5);
|
||||||
|
|
||||||
$update_method = 3;
|
$update_method = 3;
|
||||||
}
|
}
|
||||||
|
@ -1865,9 +1880,9 @@
|
||||||
update_rss_feed($link, $feed_id, true);
|
update_rss_feed($link, $feed_id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return array("code" => 1);
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return array("code" => 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -866,7 +866,7 @@ function quickAddFeed() {
|
||||||
|
|
||||||
var feed_url = this.attr('value').feed;
|
var feed_url = this.attr('value').feed;
|
||||||
|
|
||||||
notify_progress(__("Subscribing to feed..."), true);
|
Element.show("feed_add_spinner");
|
||||||
|
|
||||||
new Ajax.Request("backend.php", {
|
new Ajax.Request("backend.php", {
|
||||||
parameters: dojo.objectToQuery(this.attr('value')),
|
parameters: dojo.objectToQuery(this.attr('value')),
|
||||||
|
@ -875,13 +875,14 @@ function quickAddFeed() {
|
||||||
|
|
||||||
var reply = JSON.parse(transport.responseText);
|
var reply = JSON.parse(transport.responseText);
|
||||||
|
|
||||||
var rc = parseInt(reply['result']);
|
var rc = reply['result'];
|
||||||
|
|
||||||
notify('');
|
notify('');
|
||||||
|
Element.hide("feed_add_spinner");
|
||||||
|
|
||||||
console.log("GOT RC: " + rc);
|
console.log("GOT RC: " + rc);
|
||||||
|
|
||||||
switch (rc) {
|
switch (parseInt(rc['code'])) {
|
||||||
case 1:
|
case 1:
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
notify_info(__("Subscribed to %s").replace("%s", feed_url));
|
notify_info(__("Subscribed to %s").replace("%s", feed_url));
|
||||||
|
@ -928,7 +929,8 @@ function quickAddFeed() {
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
alert(__("Couldn't download the specified URL."));
|
alert(__("Couldn't download the specified URL: %s").
|
||||||
|
replace("%s", rc['message']));
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
alert(__("You are already subscribed to this feed."));
|
alert(__("You are already subscribed to this feed."));
|
||||||
|
|
Loading…
Reference in New Issue