4 Enable this plugin to get rid of the "md5md5md5md5md5" in uploaded
5 images` storage/filenames. It can automatically discard frivolous
6 names like "test0.gif" and "DSC00001.jpg" and provides the md5-name
9 This plugin must be included() BEFORE the binary_store plugin (if
10 that one was enabled)!
15 $ewiki_plugins["binary_store"][] = "ewiki_imgupload_better_fn";
18 function ewiki_imgupload_better_fn(&$fn, &$id, &$meta, &$ext) {
20 $parent = $_REQUEST[EWIKI_UP_PARENTID];
21 $name = $meta["Content-Location"];
22 $bad_names = '/^(DSC.?0\d+|test|bild.?\d+|pic.?\d+|image.?\d+|img.?\d+)/i';
24 #-- normalize desired name (discard path/ and old .extension)
25 $name = substr($name, strrpos($name, "/\\"));
26 $name = substr($name, 0, strrpos($name, "."));
27 $name = preg_replace('/[^-_+.\w\d]+/', "_", $name);
30 if (preg_match($bad_names, $name)) {
33 elseif (strlen($name) < 5) {
37 #-- check if wish name is free
39 $name = $name . ".$ext";
40 $found = ewiki_db::FIND(array($name));
42 $name = ""; // no, is used
46 #-- else use page name as base
47 if (!$name && $parent) {
48 for ($n=1; $n++; $n<=99) {
49 $name = "$parent.$n.$ext";
50 $found = ewiki_db::FIND(array($name));
52 $name = ""; // name is already occoupied
60 #-- assign new internal:// name
62 $id = EWIKI_IDF_INTERNAL . $name;
65 // (it else gets a md5md5md5md5-sum as name)