cogmios
I made some code that shows me all @todo's throughout my wiki.
Although it works, I assume it is very bad since i did not look at any dokuwiki internal functions. How can it be improved ?
~~NOCACHE~~
<php>
global $data_path, $pages_path, $metadata_path;
$data_path = dirname( __FILE__) . '\\..\\..\\data\\';
$pages_path = $data_path . 'pages\\';
$metadata_path = $data_path . 'meta\\';
get_todos($pages_path);
function get_todos($directory) {
global $data_path, $pages_path, $metadata_path;
if (substr($directory,-1) == '/') {$directory = substr($directory,0,-1);}
if(!file_exists($directory) || !is_dir($directory)) {return FALSE;}
elseif(is_readable($directory)) {
$handle = opendir($directory);
while (FALSE !== ($file = readdir($handle))) {
if($file != '.' && $file != '..') {
$path = $directory.'/'.$file;
if(is_readable($path)) {
$subdirectories = explode('/',$path);
if(is_dir($path)) {get_todos($path, $filter);}
elseif(is_file($path)) {
$extension = end(explode('.',end($subdirectories)));
if (end($subdirectories) != 'todo.txt') {
$data = file_get_contents($path);
preg_match_all ('/@todo(.*?)\n/i', $data, $matches);
if($matches[1] && is_array($matches[1])) {
foreach($matches[1] as $match) {
$fullpath = '';
foreach($subdirectories as $dirpath) {
if ($subdirectories[0] != $dirpath) {$fullpath .= $dirpath . '/';}
}
$metdata_path_extension = substr($fullpath ,0,-5) . '.meta';
$metadata = unserialize(file_get_contents($metadata_path.$metdata_path_extension));
$subpath = $metadata['current']['last_change']['id'];
$subpath = str_replace(':','/',$subpath);
echo '<a href="http://' . $_SERVER["HTTP_HOST"] . '/' .$subpath . '">'
. $subpath . '</a> :' . $match . '<br />';
}
unset($match);
}}
} } } }
closedir($handle);
} else {return FALSE;}
}
</php>