diff options
author | Andreas Gohr <andi@splitbrain.org> | 2014-01-08 20:28:17 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2014-01-08 20:28:17 +0100 |
commit | bc1b7a8a0fdd1812e352cab5e2362bd5770d5b3b (patch) | |
tree | d8912a5e37370dcc55bd7120acc2caa457819d50 /lib/plugins/extension/helper | |
parent | 4bad83d828217dc64292223b268c6a3674984070 (diff) | |
download | rpg-bc1b7a8a0fdd1812e352cab5e2362bd5770d5b3b.tar.gz rpg-bc1b7a8a0fdd1812e352cab5e2362bd5770d5b3b.tar.bz2 |
better filename parsing
The filename found in the URL will be used for old plugins missing a
base entry in their plugin.info.txt and lacking a subdirectory inside
the archive as well. This patch makes sure possible query strings aren't
included in the filename.
Note: io_download() will also try to get a filename from any
content-disposition header.
If no filename can be found we simply use an md5 sum of the URL and hope
the plugin will contain it's own hint for naming.
Diffstat (limited to 'lib/plugins/extension/helper')
-rw-r--r-- | lib/plugins/extension/helper/extension.php | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/plugins/extension/helper/extension.php b/lib/plugins/extension/helper/extension.php index c13aa983d..7958cd2da 100644 --- a/lib/plugins/extension/helper/extension.php +++ b/lib/plugins/extension/helper/extension.php @@ -783,11 +783,17 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { */ public function download($url) { // check the url - $matches = array(); - if(!preg_match('/[^\/]*$/', $url, $matches) || !$matches[0]) { + if(!preg_match('/https?:\/\//i', $url)){ throw new Exception($this->getLang('error_badurl')); } - $file = $matches[0]; + + // try to get the file from the path (used as plugin name fallback) + $file = parse_url($url, PHP_URL_PATH); + if(is_null($file)){ + $file = md5($url); + }else{ + $file = utf8_basename($file); + } // create tmp directory for download if(!($tmp = $this->mkTmpDir())) { |