*/ // 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) { global $conf; list($state, $cdata) = $data; //Parametres /////////////////////////////// //Taille de l'ecran du navigateur //Browser screen size $screenx=1280; $screeny=1024; //Proportions largeur/hauteur de l'image de la capture //Proportions width/height of the snap $imFactor=4/3; //Taille de l'image par defaut //Default image size $defLarg=300; $defHaut=round($defLarg/$imFactor,0); //Taille maximale autorisee pour l'image //Max allowed image size $maxLarg=400; $maxHaut=round($maxLarg/$imFactor,0); //Serveur de capture (voir le parametrage de server.sh) //Snap server (see server.sh parameters) $snapServer="localhost"; $snapPort=8888; $tryTimeout=3; //Secondes //Utiliser le cache ? //Use cache? $checkCache=true; //////////////////////////////////////////// $defaultWiki=DOKU_URL."doku.php?id="; $chem=realpath($conf['datadir']).'/../snap/'; if (!file_exists($chem.".")) mkdir($chem); $snapServer="localhost"; $snapPort=8888; 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 .= "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; if (!$larg && !$haut) { $larg=$defLarg; $haut=$defHaut; } else if (!$larg) $larg=round($haut*$imFactor,0); else if (!$haut) $haut=round($larg/$imFactor,0); if ($larg>$maxLarg) $larg=$maxLarg; if ($haut>$maxHaut) $haut=$maxHaut; if (!preg_match('/^http:\/\//',$param)) { $url=$defaultWiki.$param."&u=".urlencode($_SESSION[DOKU_COOKIE]['auth']['user'])."&phash=".urlencode($_SESSION[DOKU_COOKIE]['auth']['pass']); $pagelist = plugin_load('helper', 'pagelist'); if (!$pagelist) { $titrePage=explode(":",$param); $titrePage=$titrePage[sizeof($titrePage)-1]; $titrePage=str_replace('_',' ',$titrePage); } else { $pagelist->page['id']=$param; $pagelist->page['exists'] = 1; $pagelist->_meta=NULL; $titrePage = $pagelist->_getMeta('title'); if (!$titrePage) $titrePage = str_replace('_', ' ', noNS($param)); $titrePage = hsc($titrePage); } $titrePage=" - $titrePage"; } else { $url=$param; $titrePage=""; } if ($url==$param) $image="web_".rawurlencode($param); else $image=$param; $image.="_".$larg."x".$haut.".jpg"; $imagePath=realpath($conf['datadir']).'/../snap/'.$image; if (file_exists($imagePath)) list($imLarg, $imHaut, $imType, $imAttr) = getimagesize($imagePath); //Si l'image n'existe pas ou qu'elle est trop vieille ou qu'on demande une taille differente de celle existante, on la capture if (!$checkCache || !file_exists($imagePath) || ((time()-filemtime($imagePath))>$conf['cachetime']) || $imLarg != $larg || $imHaut != $haut) { $try=0; $fp = fsockopen($snapServer, $snapPort, $errno, $errstr, 30); while (!$fp && $try<$tryTimeout) { error_log("$image try #$try"); sleep(1); $fp = fsockopen($snapServer, $snapPort, $errno, $errstr, 30); $try++; } if (!$fp) { error_log("$image aborting"); //FIXME !!! $renderer->doc .= "Serveur snap $snapServer:$snapPort non trouvé $errstr ($errno)
\n"; return; } else { error_log("$image launch snap"); fwrite($fp, "$url $imagePath $screenx $screeny 5000 $larg $haut\n"); while (!feof($fp)) fgets($fp, 128); fclose($fp); } } else error_log("$image found in cache"); if (file_exists($imagePath)) { $titrePage.=" (".strftime($conf['dformat'],filemtime($imagePath)).")"; } if ($url==$param) $renderer->doc .= ""; else $renderer->doc .= ""; $renderer->doc .= ""; $renderer->doc .= ""; break; case DOKU_LEXER_EXIT: break; } return true; } return false; } } ?>