diff -Naur /root/Projects/dokuwiki/plugins/format.orig/syntax.php format/syntax.php --- /root/Projects/dokuwiki/plugins/format.orig/syntax.php 2008-03-08 20:45:28.000000000 +0000 +++ format/syntax.php 2008-03-09 13:24:39.000000000 +0000 @@ -19,7 +19,7 @@ * need to inherit from this class */ class syntax_plugin_format extends DokuWiki_Syntax_Plugin { - + private static $first_removal = true; // Used to work out the first time handle is called function getInfo(){ return array( @@ -65,6 +65,7 @@ function handle($match, $state, $pos) { global $conf; + global $ID; if ( $state == DOKU_LEXER_UNMATCHED ) { $matches = preg_split('/>/u',$match,2); $matches[0] = trim($matches[0]); @@ -73,6 +74,10 @@ } // $matches[0] is the format name // $matches[1] is the text inside the format block + if (self::$first_removal == true) { + $this->removeOld($matches[0]); + self::$first_removal = false; + } return array($matches[1],$matches[0]); } return TRUE; @@ -82,6 +87,7 @@ */ function render($mode, &$renderer, $data) { global $conf; + global $ID; $program = $data[1]; $text = $data[0]; if(($mode == 'xhtml' || $mode == 'latex' ) @@ -101,15 +107,16 @@ $multipart = false; } - // TODO: make directory mediadir/format/program/namespace/page - $dirname = $conf['mediadir'] . '/format/' . $program; + $ns_path = $ID; + $ns_path = str_replace(":","/",$ns_path); // Work out the namespace and page + $dirname = $conf['mediadir'].'/auto/format/'.$program.'/'.$ns_path; if( !is_dir($dirname) ) io_mkdir_p($dirname); //Using dokuwiki framework $hashname = md5(serialize($data)).'.'.$config[$mode]['ext']; $medianame = $dirname.'/'.$hashname; - $medians = ":format:".$program.":"; + $medians = "auto:format:".$program.":".$ID.":"; if($multipart) { $medians = $medians.$hashname.":"; } @@ -211,6 +218,34 @@ print("
".$data."
"); } + /* The first time handle() is called for the page, we need to remove any existing created + files Within data/auto/format////* */ + function removeOld($progname) { + global $ID; + global $conf; + + /* Path of Files to remove is /data/media/auto/format/ * ///* */ + $base_dir = realpath(DOKU_PLUGIN."../../".$conf['savedir']."/media"); // Determine media directory + $base_dir .= "/auto/format"; + if (is_dir($base_dir)) { + $d1 = dir($base_dir); // iterate for each progname + while ( FALSE !== ($entry1 = $d1->read()) ) { + $ns_path = $base_dir."/".$entry1; + if ( $entry1 == '.' || $entry1 == '..' || is_dir($ns_path) == false) { continue; } + $ns_path .= "/".str_replace(":","/",$ID); // Add the namespace and page + if (is_dir($ns_path)) { + $d2 = dir($ns_path); + while ( FALSE !== ($entry2 = $d2->read()) ) { + if ( $entry2 == '.' || $entry2 == '..' || is_dir($ns_path.$entry2)) { continue; } + unlink($ns_path."/".$entry2); + } + $d2->close(); + } + } + $d1->close(); + } + } + } ?>