Lexer->addSpecialPattern('\{\(improg>[^}]*?\)\}',$mode,'plugin_improg');}
function handle($match, $state, $pos, Doku_Handler $handler){
$match = substr($match,9,-2);
$data = array();
$params = explode('|',$match);
foreach($params as $param){
$splitparam = explode('=',$param);
if ($splitparam[1] != '') {
if ($splitparam[0] == 'value') {
$data['improg_value'] = $splitparam[1]; // Umsetzungswert
} else if ($splitparam[0] == 'type') {
$data['improg_type'] = $splitparam[1];
} else if ($splitparam[0]=='ns') {
$data['improg_ns'] = $splitparam[1]; // Verzeichnis
} else if ($splitparam[0]=='name') {
$data['improg_name'] = $splitparam[1]; // descriptive item name
$needles = array(":","/","\\");
$data['improg_name'] = str_replace($needles, "_", $data['improg_name']);
}
}
}
return $data;
}
/******************************************************************************/
/* Create output
*/
function render($mode, Doku_Renderer $renderer, $data) {
global $ID;
global $auth;
global $lang;
global $conf;
if ($mode == 'xhtml'){
$renderer->info['cache'] = false;
$improg_value = trim($data['improg_value']);
$improg_type = trim($data['improg_type']);
$improg_ns = trim($data['improg_ns']);
/******************************************************************************/
// Rating page
if ($improg_type=="improg") {
// Assign star image
$improg_stars = $this->assign_star_image($improg_value);
$ret = '
Umsetzungsfortschritt |
';
$ret .= ' |
';
} elseif ($improg_type=="stat") {
global $conf;
$delim2 = ".txt";
clearstatcache();
if(strlen($improg_ns)>1) {
if(is_file($conf['datadir']."/".str_replace(":","/",$improg_ns))) {
$listPages = array($conf['datadir']."/".str_replace(":","/",$improg_ns));
}
else {
$r_datadir = $conf['datadir']."/".str_replace(":","/",$improg_ns);
$listPages = $this->list_rec_files_in_array($r_datadir, $delim2, $params_array);
}
} else {
$r_datadir = $conf['datadir'];
$listPages = $this->list_rec_files_in_array($r_datadir, $delim2, $params_array);
}
$returns = array();
if ($improg_type=="stat") {
foreach($listPages as &$page_filepath) {
$body = file_get_contents($page_filepath);
$links = array();
// define('LINK_PATTERN', "/\{\{.*\}\}/");
$body = preg_replace('/.*?<\/code>/si', '', $body);
define('LINK_PATTERN', "(improg>[^}]*)");
if( preg_match(LINK_PATTERN, $body) ) {
preg_match_all(LINK_PATTERN, $body, $links);
}
if (count($links) > 0) {
foreach ($links[0] as $link) {
$match = substr($link, 7,-1);
$params = explode('|', $match);
$data = array();
$data['improg_basename'] = basename($page_filepath);
$data['improg_file'] = $this->__savedir($page_filepath);
foreach ($params as $param) {
$splitparam = explode('=', $param);
if ($splitparam[1] != '') {
if ($splitparam[0] == 'value') {
$data['improg_value'] = $splitparam[1]; // Umsetzungswert
} else if ($splitparam[0] == 'type') {
$data['improg_type'] = $splitparam[1]; // Umsetzungswert
} else if ($splitparam[0] == 'name') {
$data['improg_name'] = $splitparam[1]; // descriptive item name
$needles = array(":", "/", "\\");
$data['improg_name'] = str_replace($needles, "_", $data['improg_name']);
}
}
}
$data['improg_link'] = html_wikilink(':' . $data['improg_file'], $data['improg_name']);
if ($data['improg_type'] == 'improg')
array_push($returns, $data);
}
}
}
}
usort($returns, "improgcmp");
$ret = '
Maßnahme |
Fortschritt |
';
foreach($returns as $findings) {
$alink_id++;
//$anker_id = 'anker_'.$alink_id;
$improg_stars = $this->assign_star_image($findings['improg_value']);
$ret .= ''.
''.$findings['improg_link'].' | '.
' | ';
$ret .= '
';
}
$ret .= '
'.NL;
}
$renderer->doc .= $ret;
}
}
/******************************************************************************/
function assign_star_image($improg_rating) {
if ($improg_rating == 1 ){$improg_stars = DOKU_BASE."lib/plugins/improg/img/1star.gif";}
else if ($improg_rating == 2 ){$improg_stars = DOKU_BASE."lib/plugins/improg/img/2star.gif";}
else if ($improg_rating == 3 ){$improg_stars = DOKU_BASE."lib/plugins/improg/img/3star.gif";}
else if ($improg_rating == 4 ){$improg_stars = DOKU_BASE."lib/plugins/improg/img/4star.gif";}
else if ($improg_rating >= 5 ){$improg_stars = DOKU_BASE."lib/plugins/improg/img/5star.gif";}
else { $improg_stars = DOKU_BASE . "lib/plugins/improg/img/00star.gif";
}
return $improg_stars;
}
function list_rec_files_in_array($dir, $delim, $excludes) {
$listDir = array();
if($handler = opendir($dir)) {
while (FALSE !== ($sub = readdir($handler))) {
if ($sub !== "." && $sub !== "..") {
if(is_file($dir."/".$sub)) {
$x = strpos(basename($dir."/".$sub),".txt");
if(($delim === '.txt') && ($x > 0)){
$listDir[] = $dir."/".$sub;
}
elseif($delim === 'all') {
$listDir[] = $dir."/".$sub;
}
}
elseif(is_dir($dir."/".$sub)) {
$listDir[$sub] = $this->list_rec_files_in_array($dir."/".$sub, $delim,$excludes);
}
}
}
closedir($handler);
}
$listDir = $this->array_flat($listDir);
return $listDir;
}
/******************************************************************************/
function array_flat($array) {
$out=array();
foreach($array as $k=>$v){
if(is_array($array[$k])) { $out=array_merge($out,$this->array_flat($array[$k])); }
else { $out[]=$v; }
}
return $out;
}
/******************************************************************************/
function __savedir($page_filepath) {
global $conf;
$savedir = $this->getConf('savedir');
if($savedir == '') $savedir='data';
$savedir = str_replace("../", "", $savedir);
$savedir = str_replace("./", "", $savedir);
$y_pos = stripos($page_filepath, $savedir."/pages");
$t1 = substr($page_filepath, $y_pos);
$t1 = substr(str_replace( ".txt" , "" , $t1 ) , strlen($savedir."/pages"), 9999);
// turn it into wiki link without "pages"
$t2 = str_replace("/", ":", $t1);
$t2 = substr($t2, 1, strlen($t2));
return $t2;
}
}