*/
// must be run within DokuWiki
if(!defined('DOKU_INC')) die();
//ini_set("display_errors","1");
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once DOKU_PLUGIN.'syntax.php';
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_openas extends DokuWiki_Syntax_Plugin {
var $labels = array();
function getType() { return 'substition'; }
function getSort() { return 60; }
function getPType() { return 'block'; }
function connectTo($mode) {
$this->Lexer->addEntryPattern('~~OpenAsVarsStart~~', $mode, 'plugin_openas');
$this->Lexer->addPattern('~~OpenAsVar>TAreaOpen~~', $mode, 'plugin_openas');
$this->Lexer->addPattern('~~OpenAsVar>TAreaClose~~', $mode, 'plugin_openas');
$this->Lexer->addPattern('~~OpenAsVAR>.*?~~','plugin_openas');
$this->Lexer->addPattern('~~OpenAsNUM>.*?~~','plugin_openas');
$this->Lexer->addSpecialPattern('~~SaveAS>.*?~~',$mode,'plugin_openas');
$this->Lexer->addSpecialPattern('~~OpenAS>.*?~~',$mode,'plugin_openas');
$this->Lexer->addSpecialPattern('~~MoveTO>.*?~~',$mode,'plugin_openas');
}
function postConnect()
{
$this->Lexer->addExitPattern('~~OpenAsVarsClose~~', 'plugin_openas');
}
function handle($match, $state, $pos, Doku_Handler $handler) {
global $ID;
$actions = array('SaveAS' => 'save', 'MoveTO' => 'delete');
$which = array('SaveAS'=>'saved as', 'MoveTO' => 'renamed');
$file = wikiFN($ID);
list($type,$name,$newpagevars) = explode('>',(trim($match,'~')));
$name=trim($name);
$labels = $this->getConf('labels');
if($labels == 'none') {
$this->labels['open'] = "";
$this->labels['close'] = "";
}
else {
$labels = trim($labels);
$ltype = $labels[0];
$this->labels['open'] = "<$ltype>";
$this->labels['close'] = "$ltype>";
}
switch ($state) {
case DOKU_LEXER_ENTER : return array($state, '');
case DOKU_LEXER_UNMATCHED : return array($state, $match);
case DOKU_LEXER_MATCHED :
if($type == 'OpenAsNUM') {
return array($state,"$type:$name");
}
return array($state, $name);
case DOKU_LEXER_EXIT : return array($state, '');
case DOKU_LEXER_SPECIAL :
if($name[0] != ':') $name = ":$name";
if($type == 'SaveAS' || $type == 'MoveTO') {
$action = $actions[$type];
$newfile = wikiFN($name);
$contents = file_get_contents($file);
$contents = preg_replace('/~~' . $type .'.*?~~/',"",$contents,1);
io_saveFile($newfile,$contents);
$wikilink = html_wikilink("$name?saveas_orig=$ID&openas=$action");
$msg = "$ID " . $this->getLang('will_save') . $which[$type] ." $name.
";
$match = $msg . $this->getLang('open_wl') . "
$wikilink";
}
else if($type == 'OpenAS') {
list($id,$template) = explode('#',$name);
$newpagevars = urlencode($newpagevars);
$match = $this->getLang('open_page'). '
' .
html_wikilink("$id?do=edit&rev=&newpagetemplate=$template&newpagevars=$newpagevars");
}
return array($state,$match);
}
}
function render($mode, Doku_Renderer $renderer, $data) {
list($state,$match) = $data;
if($mode == 'xhtml'){
switch ($state) {
case DOKU_LEXER_ENTER :
$renderer->doc .= '