plugin:tutorial
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:tutorial [2009-10-31 01:21] – created 66.162.247.154 | plugin:tutorial [2009-10-31 10:51] (current) – removed ach | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== color plugin ====== | ||
- | ---- plugin ---- | ||
- | description: | ||
- | author | ||
- | email : chris@jalakai.co.uk | ||
- | type : Syntax | ||
- | lastupdate : 2008-02-06 | ||
- | compatible : | ||
- | depends | ||
- | conflicts | ||
- | similar | ||
- | tags : typography, highlight | ||
- | ---- | ||
- | |||
- | |||
- | |||
- | ===== Straightforward Instructions ===== | ||
- | STEP ONE - upload your plugin | ||
- | |||
- | 1. in your plugins directory, create a new plugin folder titled " | ||
- | |||
- | 2. copy the PHP CODE below and name it syntax.php | ||
- | |||
- | 3. place the syntax.php in your plugin folder titled " | ||
- | |||
- | 4. upload the color/ | ||
- | |||
- | STEP TWO - use this example | ||
- | |||
- | place this code sample in your playground | ||
- | | ||
- | <color blue/ | ||
- | |||
- | |||
- | [[devel: | ||
- | |||
- | |||
- | <code php syntax.php> | ||
- | <?php | ||
- | /** | ||
- | * Plugin Color: Sets new colors for text and background. | ||
- | | ||
- | * @license | ||
- | * @author | ||
- | */ | ||
- | |||
- | // must be run within DokuWiki | ||
- | if(!defined(' | ||
- | |||
- | if(!defined(' | ||
- | require_once(DOKU_PLUGIN.' | ||
- | |||
- | /** | ||
- | * All DokuWiki plugins to extend the parser/ | ||
- | * need to inherit from this class | ||
- | */ | ||
- | class syntax_plugin_color extends DokuWiki_Syntax_Plugin { | ||
- | |||
- | /** | ||
- | * return some info | ||
- | */ | ||
- | function getInfo(){ | ||
- | return array( | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ); | ||
- | } | ||
- | |||
- | function getType(){ return ' | ||
- | function getAllowedTypes() { return array(' | ||
- | function getSort(){ return 158; } | ||
- | function connectTo($mode) { $this-> | ||
- | function postConnect() { $this-> | ||
- | |||
- | |||
- | /** | ||
- | * Handle the match | ||
- | */ | ||
- | function handle($match, | ||
- | switch ($state) { | ||
- | case DOKU_LEXER_ENTER : | ||
- | list($color, | ||
- | if ($color = $this-> | ||
- | if ($background = $this-> | ||
- | return array($state, | ||
- | |||
- | case DOKU_LEXER_UNMATCHED : return array($state, | ||
- | case DOKU_LEXER_EXIT : | ||
- | } | ||
- | return array(); | ||
- | } | ||
- | |||
- | /** | ||
- | * Create output | ||
- | */ | ||
- | function render($mode, | ||
- | if($mode == ' | ||
- | list($state, | ||
- | switch ($state) { | ||
- | case DOKU_LEXER_ENTER : | ||
- | list($color, | ||
- | $renderer-> | ||
- | break; | ||
- | |||
- | case DOKU_LEXER_UNMATCHED : $renderer-> | ||
- | case DOKU_LEXER_EXIT : | ||
- | } | ||
- | return true; | ||
- | } | ||
- | return false; | ||
- | } | ||
- | |||
- | // validate color value $c | ||
- | // this is cut price validation - only to ensure the basic format is correct and there is nothing harmful | ||
- | // three basic formats | ||
- | function _isValid($c) { | ||
- | $c = trim($c); | ||
- | |||
- | $pattern = "/ | ||
- | ([a-zA-z]+)| | ||
- | (\# | ||
- | (rgb\(([0-9]{1, | ||
- | )\s*$/ | ||
- | |||
- | if (preg_match($pattern, | ||
- | |||
- | return ""; | ||
- | } | ||
- | } | ||
- | ?> | ||
- | |||
- | </ | ||
- | |||
- | ===== Demos ===== | ||
- | http:// | ||
- | |||
- | ===== Discussion ===== | ||
- | |||
- | This source for this plugin is shown in the [[devel: | ||
- | |||
- | ===== Update History ===== | ||
- | |||
- | * 2008-02-06 --- Fixed a security vulnerability in the colour pattern. | ||
- | |||
- | ===== Version with ODT renderer support ===== | ||
- | |||
- | This modified version is no more suitable for a simple tutorial example. But I needed the ODT renderer support ;-) | ||
- | --- // | ||
- | > Ooops. The version picked up to add ODT support was from before the 2008-02-06 version (which fixed a Cross Site Scripting vulnerability). So the ODT version was again vulnerable. Now fixed again. | ||
- | |||
- | **'' | ||
- | <code php> | ||
- | <?php | ||
- | /** | ||
- | * Plugin Color: Sets new colors for text and background. | ||
- | | ||
- | * @license | ||
- | * @author | ||
- | */ | ||
- | |||
- | // must be run within DokuWiki | ||
- | if(!defined(' | ||
- | if(!defined(' | ||
- | require_once(DOKU_PLUGIN.' | ||
- | |||
- | /** | ||
- | * All DokuWiki plugins to extend the parser/ | ||
- | * need to inherit from this class | ||
- | */ | ||
- | class syntax_plugin_color extends DokuWiki_Syntax_Plugin { | ||
- | |||
- | var $odt_styles = array(); | ||
- | /** | ||
- | * return some info | ||
- | */ | ||
- | function getInfo(){ | ||
- | return array( | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ); | ||
- | } | ||
- | |||
- | function getType(){ return ' | ||
- | function getAllowedTypes() { return array(' | ||
- | function getSort(){ return 158; } | ||
- | function connectTo($mode) { $this-> | ||
- | function postConnect() { $this-> | ||
- | |||
- | |||
- | /** | ||
- | * Handle the match | ||
- | */ | ||
- | function handle($match, | ||
- | switch ($state) { | ||
- | case DOKU_LEXER_ENTER : | ||
- | list($color, | ||
- | $color = $this-> | ||
- | $background = $this-> | ||
- | return array($state, | ||
- | |||
- | case DOKU_LEXER_UNMATCHED : return array($state, | ||
- | case DOKU_LEXER_EXIT : | ||
- | } | ||
- | return array(); | ||
- | } | ||
- | |||
- | /** | ||
- | * Create output | ||
- | */ | ||
- | function render($mode, | ||
- | if($mode == ' | ||
- | list($state, | ||
- | switch ($state) { | ||
- | case DOKU_LEXER_ENTER : | ||
- | list($color, | ||
- | $color = $color?" | ||
- | $background = $background?" | ||
- | $renderer-> | ||
- | break; | ||
- | | ||
- | case DOKU_LEXER_UNMATCHED : $renderer-> | ||
- | case DOKU_LEXER_EXIT : | ||
- | } | ||
- | return true; | ||
- | } | ||
- | if($mode == ' | ||
- | list($state, | ||
- | switch ($state) { | ||
- | case DOKU_LEXER_ENTER : | ||
- | list($color, | ||
- | $style_index = $color.'/' | ||
- | if(empty($this-> | ||
- | { | ||
- | $stylename = " | ||
- | $this-> | ||
- | $color = $color?' | ||
- | $background = $background?' | ||
- | $renderer-> | ||
- | < | ||
- | < | ||
- | </ | ||
- | } | ||
- | $renderer-> | ||
- | break; | ||
- | | ||
- | case DOKU_LEXER_UNMATCHED : $renderer-> | ||
- | case DOKU_LEXER_EXIT : | ||
- | } | ||
- | return true; | ||
- | } | ||
- | return false; | ||
- | } | ||
- | | ||
- | // validate color value $c | ||
- | // this is cut price validation - only to ensure the basic format is correct and there is nothing harmful | ||
- | // three basic formats | ||
- | function _isValid($c) { | ||
- | $c = trim($c); | ||
- | | ||
- | $pattern = "/ | ||
- | ([a-zA-z]+)| | ||
- | (\# | ||
- | (rgb\(([0-9]{1, | ||
- | )\s*$/ | ||
- | | ||
- | if (preg_match($pattern, | ||
- | | ||
- | return ""; | ||
- | } | ||
- | /** | ||
- | * Translate color names and RGB to hex values | ||
- | */ | ||
- | function _color2hex($name) | ||
- | { | ||
- | static $colornames = null; | ||
- | if(is_null($colornames)) | ||
- | { | ||
- | include dirname(__FILE__).'/ | ||
- | } | ||
- | if(!preg_match('/ | ||
- | return $colornames[$name]; | ||
- | elseif(preg_match('/ | ||
- | { | ||
- | $colors = array(); | ||
- | for($i=1; | ||
- | { | ||
- | $percent = substr($matches[$i], | ||
- | $colors[$i] = $percent? | ||
- | } | ||
- | return sprintf('# | ||
- | } | ||
- | else | ||
- | return $name; | ||
- | } | ||
- | } | ||
- | |||
- | |||
- | //Setup VIM: ex: et ts=4 enc=utf-8 : | ||
- | </ | ||
- | **'' | ||
- | <code php> | ||
- | <?php | ||
- | |||
- | // HTML 4.01 color names | ||
- | $colornames = array( | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ); | ||
- | |||
- | </ |
plugin/tutorial.1256948518.txt.gz · Last modified: 2009-10-31 01:21 by 66.162.247.154