+// Implements [ambdownloadinfo url file='FILENAME'dp='DECIMALPLACES']FORMAT[/ambdownloadinfo]\r
+// Format is like printf, but\r
+// $NAME is the name of the file\r
+// $SIZE is the size of the file in bytes\r
+// $MD5SUM is the md5sum of the file\r
+// $FSIZE is the size of the file in friendly notation\r
+//\r
+// Example usage (to be entered in the HTML editor)\r
+// The file is [ambdownloadinfo url='http://www.example.com/download' file='default']named <b>$NAME</b> has an\r
+// md5sum of <tt>$MD5SUM</tt> and is roughly $FSIZE in size[/ambdownloadinfo]\r
+\r
+function ambdownloadinfo_shortcode ($atts, $content = null)\r
+{\r
+ extract( shortcode_atts( array(\r
+ 'url' => null,\r
+ 'file' => 'default',\r
+ 'dp' => 0,\r
+ ), $atts ) );\r
+ if (empty($url))\r
+ return "";\r
+ $info = file_get_contents($url."?info=".$file);\r
+ if (empty($info))\r
+ return "";\r
+ if (empty($content))\r
+ $content='$NAME ($FSIZE)';\r
+ $items=explode(" ", $info);\r
+ $name = $items[0];\r
+ $size = $items[1];\r
+ $md5sum = $items[2];\r
+ // replace percentage signs\r
+ $content = preg_replace('/%/','%%',$content);\r
+ $content = preg_replace('/\$NAME\b/','%1$s',$content);\r
+ $content = preg_replace('/\$SIZE\b/','%2$s',$content);\r
+ $content = preg_replace('/\$MD5SUM\b/','%3$s',$content);\r
+ $content = preg_replace('/\$FSIZE\b/','%4$s',$content);\r
+ $friendlysize = ambdownloadinfo_friendlyfilesize($size, $dp);\r
+ return sprintf($content, $name, $size, $md5sum, $friendlysize);\r
+}\r