*/ if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'admin.php'); require_once(dirname(__FILE__).'/latexinc.php'); /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ class admin_plugin_latex extends DokuWiki_Admin_Plugin { var $output; /** * return some info */ function getInfo(){ $a = ''; if(method_exists(DokuWiki_Admin_Plugin,"getInfo")) { $a = parent::getInfo(); /// this will grab the data from the plugin.info.txt $a['name'] = 'LaTeX plugin administration'; return $a; } else // Otherwise return some hardcoded data for old dokuwikis return array( 'author' => 'Alexander Kraus, Michael Boyle, and Mark Lundeberg)', 'email' => '.', 'date' => '???', 'name' => 'LaTeX plugin', 'desc' => 'LaTeX rendering plugin; requires LaTeX, dvips, ImageMagick.', 'url' => 'http://www.dokuwiki.org/plugin:latex' ); } /** * return sort order for position in admin menu */ function getMenuSort() { return 999; } // Purgers. function vio_atime($fname) { if(time() - fileatime($fname) - $this->_timelimit > 0) { unlink($fname); return $this->_timelimit; } return false; } function vio_mtime($fname) { if(time() - filemtime($fname) - $this->_timelimit > 0) { unlink($fname); return true; } return false; } function vio_all($fname) { unlink($fname); return true; } // purge all files older than $timelimit (in seconds) // $mode = // atime: age based on fileatime(). // mtime: age based on filemtime(). // all: delete all cached files. function latexpurge($mode, $timelimit) { global $conf, $config_cascade; $meddir = $conf['mediadir'] . '/' . strtr($this->getConf('latex_namespace'),':','/'); $images = glob($meddir.'/img*'); $this->_timelimit = $timelimit; switch($mode) { case 'atime': $vio = array_map(array($this,'vio_atime'),$images); break; case 'mtime': $vio = array_map(array($this,'vio_mtime'),$images); break; case 'all': $vio = array_map(array($this,'vio_all'),$images); break; default: return false; } return array_combine($images,$vio); } /** * handle user request */ function handle() { global $conf, $config_cascade; $this->output = ""; if(isset($_POST['latexpurge'])) { $mode = $_POST['purgemode']; $days = $_POST['purgedays']; if(is_numeric($days) && $days == 0) $mode = 'all'; if($mode == 'all') { // If the admin wants to delete all of the images, probably it's good to print this reminder // since they are likely doing it after changing the colour or something. // (I don't know how many hours I spent trying to fix LaTeX heisenbugs that were just cached... grr.) $this->output .= '
Purge result ([x] = deleted):\n";
if($mode == 'all' || (is_numeric($days) && $days >= 0)) {
$res = $this->latexpurge($mode, $days*86400);
foreach($res as $img => $vio){
if($vio) {
$this->output .= '[x] '.$img . "\n";
$numdeleted += 1;
} else {
// $this->output .= '[ ] '.$img . "\n";
$numkept += 1;
}
}
} else {
$this->output = "Purger: Bad form inputs. No action taken.".$this->output;
}
$this->output .= "Totals: $numdeleted deleted, $numkept kept (kept files not shown).\n";
if ($numdeleted > 0) {
touch($config_cascade['main']['local']);
}
$this->output .= "";
}
}
/**
* output appropriate html
*/
function html() {
global $ID,$INFO;
ptln(''.$this->output.'
'); ptln('| command | output |
|---|---|
');
$cmd = $path." --version 2>&1";
echo htmlspecialchars($cmd);
ptln(' | ');
unset($execout);
exec($cmd,$execout,$statuscode);
if($statuscode == 0)
echo '';
else
echo ' |
'.$plug->_latex->getPicturePath().''.$plug->_latex->getPicturePath().'
'.$plug->_latex->_tmp_dir.''.$plug->_latex->_tmp_dir.'
'.$outname.''.$outname.''.$outname.''.$rendstr.''.$fname.''.$tmpf.'.* will be deleted at the end of this script.'.$outname.''.$outname.'| Input LaTeX file | Final result |
|---|---|
');
if(is_readable($tmpf.'.tex') && is_file($tmpf.'.tex'))
echo htmlspecialchars(file_get_contents($tmpf.'.tex'));
else
echo 'MISSING';
ptln(' | ');
// ptln(htmlspecialchars($plug->_url));
// ptln(' '); ptln(' |
'; echo $plug->_latex->_cmdoutput; echo ''; ptln('Contents of '.$tmpf.'.log:'); echo '
'; echo htmlspecialchars(file_get_contents($tmpf.'.log')); echo ''; if(! isset($_REQUEST['keep_tmp'])) $plug->_latex->cleanTemporaryDirectory(); ptln('