X-Git-Url: http://git.alex.org.uk diff --git a/ambdownload.php b/ambdownload.php index c32d715..139bd64 100644 --- a/ambdownload.php +++ b/ambdownload.php @@ -10,14 +10,17 @@ Author URI: http://blog.alex.org.uk class ambdownload { - function getDownloadLink($user, $file="default") + function getDownloadLink($user, $link, $error, $file="default") { + if (empty($user) && !empty($error)) + { + return ($error); + } $time = time(); $secret = rtrim(file_get_contents("/etc/apache2/download.secret")); $id = $user; $hash = hash("sha256",$time.":".$id.":".$file.":".$secret); - $link = "http://server.example.com/download?"; - return $link.sprintf("id=%s&file=%s&time=%s&hash=%s",urlencode($id),urlencode($file),$time,$hash); + return $link.sprintf("?id=%s&file=%s&time=%s&hash=%s",urlencode($id),urlencode($file),$time,$hash); } function downloadRedirect() @@ -25,11 +28,16 @@ class ambdownload global $post; if ((is_single() || is_singular() || is_page())) { + /* Tag of file to download, e.g. 'default' */ $download_file = get_post_meta($post->ID, 'download_file', true); - if ($download_file) { + /* EG 'http://server.example.com/download' */ + $download_url = get_post_meta($post->ID, 'download_url', true); + /* EG URL where redirected if no username exists */ + $download_error = get_post_meta($post->ID, 'download_error', true); + if ($download_file && $download_url) { global $current_user; get_currentuserinfo(); - wp_redirect(ambdownload::getDownloadLink($current_user->user_email, $download_file)); + wp_redirect(ambdownload::getDownloadLink($current_user->user_email, $download_url, $download_error, $download_file)); exit; } }