part of feature request #276: automatically prepend http:// if feed URL is incomplete

This commit is contained in:
Christian Weiske 2010-11-07 13:14:08 +01:00 committed by Andrew Dolgov
parent 2d1b7139a2
commit f2c6c0088b
1 changed files with 15 additions and 0 deletions

View File

@ -2943,6 +2943,7 @@
function subscribe_to_feed($link, $url, $cat_id = 0, function subscribe_to_feed($link, $url, $cat_id = 0,
$auth_login = '', $auth_pass = '') { $auth_login = '', $auth_pass = '') {
$url = fix_url($url);
$parts = parse_url($url); $parts = parse_url($url);
if (!validate_feed_url($url)) return 2; if (!validate_feed_url($url)) return 2;
@ -6671,6 +6672,20 @@
return $url; return $url;
} }
/**
* Fixes incomplete URLs by prepending "http://".
*
* @param string $url Possibly incomplete URL
*
* @return string Fixed URL.
*/
function fix_url($url) {
if (strpos($url, '://') === false) {
$url = 'http://' . $url;
}
return $url;
}
function validate_feed_url($url) { function validate_feed_url($url) {
$parts = parse_url($url); $parts = parse_url($url);