From 129deb0273fbdd917f8dc9a3aba675c5caf282e7 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Mon, 29 Jun 2009 03:32:38 +0000 Subject: [PATCH] "MDL-19180, convert relative url to absolute url in url plugin" --- repository/url/lib.php | 434 ++++++++++++++++++++++++++++ repository/url/repository.class.php | 11 +- 2 files changed, 440 insertions(+), 5 deletions(-) create mode 100644 repository/url/lib.php diff --git a/repository/url/lib.php b/repository/url/lib.php new file mode 100644 index 0000000000..e96a06809e --- /dev/null +++ b/repository/url/lib.php @@ -0,0 +1,434 @@ + diff --git a/repository/url/repository.class.php b/repository/url/repository.class.php index b6ad1f3e3f..77de3dc851 100755 --- a/repository/url/repository.class.php +++ b/repository/url/repository.class.php @@ -7,6 +7,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ +require_once(dirname(__FILE__).'/lib.php'); + class repository_url extends repository { /** @@ -93,8 +95,8 @@ EOD; if (strstr($info['content_type'], 'text/html') || empty($info['content_type'])) { // analysis this web page, general file list $ret['list'] = array(); - $a = $curl->get($info['url']); - $this->analyse_page($a, $ret); + $content = $curl->get($info['url']); + $this->analyse_page($info['url'], $content, $ret); } else { // download this file $ret['list'][] = array( @@ -106,7 +108,7 @@ EOD; } return $ret; } - public function analyse_page($content, &$list) { + public function analyse_page($baseurl, $content, &$list) { global $CFG; $pattern = '#src="?\'?([[:alnum:]:?=&@/._+-]+)"?\'?#i'; $matches = null; @@ -116,8 +118,7 @@ EOD; foreach($matches as $url) { $list['list'][] = array( 'title'=>$this->guess_filename($url, ''), - // XXX: need to convert relative url to absolute url - 'source'=>$url, + 'source'=>url_to_absolute($baseurl, $url), 'thumbnail' => $CFG->pixpath .'/f/'. mimeinfo('icon32', $url) ); } -- 2.39.5