3 Plugin Name: ambdownload
\r
4 Plugin URI: http://blog.alex.org.uk/
\r
5 Description: Redirect a given page to a download URL
\r
8 Author URI: http://blog.alex.org.uk
\r
13 function getDownloadLink($user, $link, $error, $file="default")
\r
15 if (empty($user) && !empty($error))
\r
20 $secret = rtrim(file_get_contents("/etc/apache2/download.secret"));
\r
22 $hash = hash("sha256",$time.":".$id.":".$file.":".$secret);
\r
23 return $link.sprintf("?id=%s&file=%s&time=%s&hash=%s",urlencode($id),urlencode($file),$time,$hash);
\r
26 function downloadRedirect()
\r
29 if ((is_single() || is_singular() || is_page()))
\r
31 /* Tag of file to download, e.g. 'default' */
\r
32 $download_file = get_post_meta($post->ID, 'download_file', true);
\r
33 /* EG 'http://server.example.com/download' */
\r
34 $download_url = get_post_meta($post->ID, 'download_url', true);
\r
35 /* EG URL where redirected if no username exists */
\r
36 $download_error = get_post_meta($post->ID, 'download_error', true);
\r
37 if ($download_file && $download_url) {
\r
38 global $current_user;
\r
39 get_currentuserinfo();
\r
40 wp_redirect(ambdownload::getDownloadLink($current_user->user_email, $download_url, $download_error, $download_file));
\r
48 add_action( 'template_redirect', array('ambdownload', 'downloadRedirect'), 1, 2);
\r