ID, 'download_file', true); /* 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_url, $download_error, $download_file)); exit; } } } } function ambdownloadinfo_friendlyfilesize ($size, $dp=0) { $suffix = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); for ($n=0; $size > 1024 && $n$NAME has an // md5sum of $MD5SUM and is roughly $FSIZE in size[/ambdownloadinfo] function ambdownloadinfo_shortcode ($atts, $content = null) { extract( shortcode_atts( array( 'url' => null, 'file' => 'default', 'dp' => 0, ), $atts ) ); if (empty($url)) return ""; $info = file_get_contents($url."?info=".$file); if (empty($info)) return ""; if (empty($content)) $content='$NAME ($FSIZE)'; $items=explode(" ", $info); $name = $items[0]; $size = $items[1]; $md5sum = $items[2]; // replace percentage signs $content = preg_replace('/%/','%%',$content); $content = preg_replace('/\$NAME\b/','%1$s',$content); $content = preg_replace('/\$SIZE\b/','%2$s',$content); $content = preg_replace('/\$MD5SUM\b/','%3$s',$content); $content = preg_replace('/\$FSIZE\b/','%4$s',$content); $friendlysize = ambdownloadinfo_friendlyfilesize($size, $dp); return sprintf($content, $name, $size, $md5sum, $friendlysize); } add_shortcode( 'ambdownloadinfo', 'ambdownloadinfo_shortcode' ); add_action( 'template_redirect', array('ambdownload', 'downloadRedirect'), 1, 2);