*/ // must be run within Dokuwiki if (!defined('DOKU_INC')) die(); if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once DOKU_PLUGIN.'syntax.php'; class syntax_plugin_translationbuddy extends DokuWiki_Syntax_Plugin { public function getType() { return 'substition'; } public function getPType() { return 'block'; } public function getSort() { return 99; } public function connectTo($mode) { $this->Lexer->addSpecialPattern('----+ *translationbuddy *-+\n.*?\n----+',$mode,'plugin_translationbuddy'); } public function handle($match, $state, $pos, &$handler){ return $this->parseData($match); } public function render($mode, &$renderer, $data) { if($mode == 'xhtml') { return $this->_showData($renderer,$data); } return false; } /** * Parse syntax data block, return keyed array of values * * You may use the # character to add comments to the block. * Those will be ignored and will neither be displayed nor saved. * If you need to enter # as data, escape it with a backslash (\#). * If you need a backslash, escape it as well (\\) */ function parseData($match){ // get lines $lines = explode("\n",$match); array_pop($lines); array_shift($lines); // parse info $data = array(); foreach ( $lines as $line ) { // ignore comments and bullet syntax $line = preg_replace('/(?getPages(); $items = array(); $new_pages = array(); foreach($pages as $id){ //skip hidden, non existing and restricted files if(isHiddenPage($id)) continue; if(auth_aclcheck($id,'','') < AUTH_READ) continue; $page = $id; $ns = $this->baseNS($page); $lc = 'en'; if ($ns && in_array($ns,$langs)) { $lc = $ns; $page = $this->skipBaseNS($page); $ns = $this->baseNS($page); } if (!$ns) $ns = '-'; $fn = wikiFN($id); $date = @filemtime($fn); if($date && !in_array($ns, $ignore_ns)) { $items[$lc][$ns][$page] = $date; if (filectime($fn) > time() - 60*60*24*$data['daysnew']) { $new_pages[] = $id; } } } sort($new_pages); // new page report $R->doc .= 'New pages last '.hsc($data['daysnew']).' days'; $R->listu_open(); foreach ($new_pages as $page) { $R->listitem_open(1); $R->listcontent_open(); $R->doc .= ''.$page.''; $R->listcontent_close(); $R->listitem_close(); } $R->listu_close(); $R->doc .= 'Translation status'; // translation effort report $R->doc .= ''; $R->doc .= ''; foreach ($items as $lc => $item) { $pageTotal = 0; $first = true; foreach ($item as $ns => $pages) { $R->doc .= ''; if ($first) { $first = false; $R->doc .= ''; $R->toc_additem('translationbuddy__'.$lc, $lc, $R->lastlevel+1); } $idx = ($ns=='-' ? ($lc=='en'?'-1':$lc) : ($lc=='en'?'':$lc.':').$ns); $R->doc .= ''; $R->doc .= ''; if (count($items['en'][$ns]) == 0) { $R->doc .= ''; } else { $R->doc .= ''; } $R->doc .= ''; $R->doc .= ''; $pageTotal += count($pages); } $R->doc .= ''; $R->doc .= ''; $R->doc .= ''; $R->doc .= ''; $R->doc .= ''; $R->doc .= ''; $R->doc .= ''; } $R->doc .= '
LangNamespacePagesTranslatedDetails
'.$lc.''.$ns.''.count($pages).' - '.round(100*count($pages)/count($items['en'][$ns])).'%'; // outdated $outdated = array(); foreach ($pages as $id => $date) { if ($date < $items['en'][$ns][$id]) { $outdated[] = $id; } } if (count($outdated) > 0) { $itr = 0; $R->doc .= 'Outdated:
'; do $R->doc .= ''.$outdated[$itr].' '; while (++$itr < $data['outdated'] && $itr < count($outdated)); if ($itr < count($outdated)) { $R->doc .= 'and '.(count($outdated)-$itr).' more.'; } $R->doc .= '
'; } // rouge pages if (count($items['en'][$ns]) > 0) { $extra_pages = array_keys(array_diff_key($pages,$items['en'][$ns])); $func = create_function('$id' , "return ''.\$id.'';"); if (count($extra_pages) > 0) { $extra_pages = array_map($func, $extra_pages); $R->doc .= 'Rogue pages:
'.implode(', ', $extra_pages).'
'; } } $R->doc .= '
'.$lc.'Total'.$pageTotal.'
'; } function baseNS($id){ $pos = strpos((string)$id,':'); if($pos!==false){ return substr((string)$id,0,$pos); } return false; } function skipBaseNS($id){ $pos = strpos((string)$id,':'); if($pos!==false){ return substr((string)$id,$pos+1); } return false; } }