*/
// based on http://wiki.splitbrain.org/plugin:tutorial
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
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_snap extends DokuWiki_Syntax_Plugin {
function getInfo() {
return array(
'author' => 'Etienne M.',
'email' => 'emauvaisfr@yahoo.fr',
'date' => @file_get_contents(DOKU_PLUGIN.'snap/VERSION'),
'name' => 'snap Plugin',
'desc' => html_entity_decode($this->getLang('snap_description')),
'url' => 'http://www.dokuwiki.org/plugin:snap'
);
}
function connectTo($mode) { $this->Lexer->addEntryPattern('{{\[\[(?=.*?\]\]}})',$mode,'plugin_snap'); }
function postConnect() { $this->Lexer->addExitPattern('\]\]}}','plugin_snap'); }
function getType() { return 'disabled'; }
function getSort() { return 100; }
/**
* Handle the match
*/
function handle($match, $state, $pos, &$handler){
if ($state == DOKU_LEXER_ENTER){
$match = trim(substr($match,4,-1)); // strip markup
$handler->status['plugin_snap'] = true;
}
return array($state, $match);
}
/**
* Create output
*/
function render($mode, &$renderer, $data) {
list($state, $cdata) = $data;
if($mode == 'xhtml') {
switch ($state){
case DOKU_LEXER_ENTER:
break;
case DOKU_LEXER_UNMATCHED:
$param=$cdata;
//Recuperation des options
//(ex : url ou url|larg ou url|xhaut ou url|largxhaut; + un ! pour forcer la capture sans recherche dans le cache)
$param=explode("|",$param);
if ($param) $url=$param[0];
else {
//FIXME !!!
$renderer->doc .= "SNAP : Erreur de syntaxe
";
return false;
}
if (isset($param[1])) $options=$param[1];
$param=$url;
if (preg_match("/!/",$options)) {
$checkCache=false;
$options=preg_replace("/!/","",$options);
}
if ($options) $options=explode("x",$options);
if ($options[0]) $larg=$options[0]*1;
if ($options[1]) $haut=$options[1]*1;
$snap=plugin_load('helper','snap');
if (!$snap) {
//FIXME !!!
$renderer->doc .= "SNAP : Snap helper non trouvé
";
return false;
}
list($imagePath, $titrePage, $target)=$snap->getSnap($param, $larg, $haut, $checkCache);
if (!$snap->succeed || !$imagePath) {
//FIXME !!!
$renderer->doc .= "SNAP : Probleme lors du snap de $param
";
return false;
}
if ($titrePage) $titrePage=" - ".$titrePage;
if ($snap->snapTimeFormatted) $titrePage.=" (".$snap->snapTimeFormatted.")";
$renderer->doc .= "url."\" title=\"$param$titrePage\" $target>";
$renderer->doc .= "";
$renderer->doc .= "";
break;
case DOKU_LEXER_EXIT:
break;
}
return true;
}
return false;
}
}
?>