slitaz-doc-wiki-data diff plugins/note/syntax.php @ rev 22

Add meta/fr/handbook folder.
author Christopher Rogers <slaxemulator@gmail.com>
date Wed Apr 20 19:12:59 2011 +0000 (2011-04-20)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/note/syntax.php	Wed Apr 20 19:12:59 2011 +0000
     1.3 @@ -0,0 +1,191 @@
     1.4 +<?php
     1.5 +/**
     1.6 + * Add Note capability to dokuwiki
     1.7 + *
     1.8 + * <note>This is note</note>
     1.9 + * <note classic>This is note</note>
    1.10 + * <note important>This is an important note</note>
    1.11 + * <note warning>This is a big warning</note>
    1.12 + * <note tip>This is a tip</note>
    1.13 + *
    1.14 + * by Olivier Cortès <olive@deep-ocean.net>
    1.15 + * under the terms of the GNU GPL v2.
    1.16 + *
    1.17 + * Originaly derived from the work of :
    1.18 + * Stephane Chamberland <stephane.chamberland@ec.gc.ca> (Side Notes PlugIn)
    1.19 + * Carl-Christian Salvesen <calle@ioslo.net> (Graphviz plugin)
    1.20 + *
    1.21 + * Contributions by Eric Hameleers <alien [at] slackware [dot] com> :
    1.22 + *   use <div> instead of <table>,
    1.23 + *   contain the images and stylesheet inside the plugin,
    1.24 + *   permit nesting of notes,
    1.25 + *
    1.26 + * Contributed by Christopher Smith <chris [at] jalakai [dot] co [dot] uk>
    1.27 + *   fix some parsing problems and a security hole.
    1.28 + *   make note types case independent
    1.29 + *   simplify code reading
    1.30 + *   modernise the plugin for changes/fixes/improvements to the underlying Dokuwiki plugin class,
    1.31 + *   improve efficiency.
    1.32 + *
    1.33 + * Contributed by Aurélien Bompard <aurelien [at] bompard [dot] org>
    1.34 + *   support for the ODT output format.
    1.35 + *
    1.36 + * @license    GNU_GPL_v2
    1.37 + * @author     Olivier Cortes <olive@deep-ocean.net>
    1.38 + */
    1.39 + 
    1.40 +if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
    1.41 +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
    1.42 +require_once(DOKU_PLUGIN.'syntax.php');
    1.43 +
    1.44 +
    1.45 +class syntax_plugin_note extends DokuWiki_Syntax_Plugin {
    1.46 + 
    1.47 +    var $notes = array(
    1.48 +        'noteimportant' => array('important', 'importante'),
    1.49 +        'notewarning'   => array('warning','bloquante','critique'),
    1.50 +        'notetip'       => array('tip','tuyau','idée'),
    1.51 +        'noteclassic'   => array('','classic','classique')
    1.52 +      );
    1.53 +      
    1.54 +    var $default = 'noteclassic';
    1.55 +  
    1.56 +    function getInfo(){
    1.57 +        return confToHash(dirname(__FILE__).'/info.txt');
    1.58 +    }
    1.59 + 
    1.60 + 
    1.61 +    function getType(){ return 'container'; }
    1.62 +    function getPType(){ return 'normal'; }
    1.63 +    function getAllowedTypes() { 
    1.64 +        return array('container','substition','protected','disabled','formatting','paragraphs');
    1.65 +    }
    1.66 +    function getSort(){ return 195; }
    1.67 +
    1.68 +    // override default accepts() method to allow nesting 
    1.69 +    // - ie, to get the plugin accepts its own entry syntax
    1.70 +    function accepts($mode) {
    1.71 +      if ($mode == substr(get_class($this), 7)) return true;
    1.72 +        return parent::accepts($mode);
    1.73 +      }
    1.74 +
    1.75 +    function connectTo($mode) {
    1.76 +        $this->Lexer->addEntryPattern('<note.*?>(?=.*?</note>)',$mode,'plugin_note');
    1.77 +    }
    1.78 +    function postConnect() {
    1.79 +        $this->Lexer->addExitPattern('</note>','plugin_note');
    1.80 +    }
    1.81 + 
    1.82 +    function handle($match, $state, $pos, &$handler){
    1.83 +
    1.84 +        switch ($state) {
    1.85 +
    1.86 +          case DOKU_LEXER_ENTER : 
    1.87 +            $note = strtolower(trim(substr($match,5,-1)));
    1.88 + 
    1.89 +            foreach( $this->notes as $class => $names ) {
    1.90 +              if (in_array($note, $names))
    1.91 +                return array($state, $class);
    1.92 +            }            
    1.93 +            
    1.94 +            return array($state, $this->default);          
    1.95 + 
    1.96 +          case DOKU_LEXER_UNMATCHED :
    1.97 +            return array($state, $match);
    1.98 +        
    1.99 +          default:
   1.100 +            return array($state);
   1.101 +        }
   1.102 +    }
   1.103 + 
   1.104 +    function render($mode, &$renderer, $indata) {
   1.105 +
   1.106 +        if($mode == 'xhtml'){
   1.107 +
   1.108 +          list($state, $data) = $indata;
   1.109 +
   1.110 +          switch ($state) {
   1.111 +            case DOKU_LEXER_ENTER :
   1.112 +              $renderer->doc .= '<p><div class="'.$data.'">';
   1.113 +              break;
   1.114 +  
   1.115 +            case DOKU_LEXER_UNMATCHED :
   1.116 +              $renderer->doc .= $renderer->_xmlEntities($data);
   1.117 +              break;
   1.118 +  
   1.119 +            case DOKU_LEXER_EXIT :
   1.120 +              $renderer->doc .= "\n</div></p>";
   1.121 +              break;
   1.122 +          }
   1.123 +          return true;
   1.124 +
   1.125 +        } elseif ($mode == 'odt'){
   1.126 +
   1.127 +          list($state, $data) = $indata;
   1.128 +
   1.129 +          switch ($state) {
   1.130 +            case DOKU_LEXER_ENTER :
   1.131 +              $type = substr($data, 4);
   1.132 +              if ($type == "classic") {
   1.133 +                $type = "note"; // the icon for classic notes is named note.png
   1.134 +              }
   1.135 +              $colors = array("note"=>"#eeffff", "warning"=>"#ffdddd", "important"=>"#ffffcc", "tip"=>"#ddffdd");
   1.136 +              $renderer->autostyles["pluginnote"] = '
   1.137 +                  <style:style style:name="pluginnote" style:family="table">
   1.138 +                      <style:table-properties style:width="15cm" table:align="center" style:shadow="#808080 0.18cm 0.18cm"/>
   1.139 +                  </style:style>';
   1.140 +              $renderer->autostyles["pluginnote.A"] = '
   1.141 +                  <style:style style:name="pluginnote.A" style:family="table-column">
   1.142 +                      <style:table-column-properties style:column-width="1.5cm"/>
   1.143 +                  </style:style>';
   1.144 +              $renderer->autostyles["pluginnote.B"] = '
   1.145 +                  <style:style style:name="pluginnote.B" style:family="table-column">
   1.146 +                      <style:table-column-properties style:column-width="13.5cm"/>
   1.147 +                  </style:style>';
   1.148 +              $renderer->autostyles["pluginnote".$type.".A1"] = '
   1.149 +                  <style:style style:name="pluginnote'.$type.'.A1" style:family="table-cell">
   1.150 +                      <style:table-cell-properties style:vertical-align="middle" fo:padding="0.1cm" fo:border-left="0.002cm solid #000000" fo:border-right="none" fo:border-top="0.002cm solid #000000" fo:border-bottom="0.002cm solid #000000" fo:background-color="'.$colors[$type].'"/>
   1.151 +                  </style:style>';
   1.152 +              $renderer->autostyles["pluginnote".$type.".B1"] = '
   1.153 +                  <style:style style:name="pluginnote'.$type.'.B1" style:family="table-cell">
   1.154 +                      <style:table-cell-properties style:vertical-align="middle" fo:padding="0.3cm" fo:border-left="none" fo:border-right="0.002cm solid #000000" fo:border-top="0.002cm solid #000000" fo:border-bottom="0.002cm solid #000000" fo:background-color="'.$colors[$type].'"/>
   1.155 +                  </style:style>';
   1.156 +              // Content
   1.157 +              $renderer->p_close();
   1.158 +              $renderer->doc .= '<table:table table:name="" table:style-name="pluginnote">';
   1.159 +              $renderer->doc .= '<table:table-column table:style-name="pluginnote.A"/>';
   1.160 +              $renderer->doc .= '<table:table-column table:style-name="pluginnote.B"/>';
   1.161 +              $renderer->doc .= '<table:table-row>';
   1.162 +              $renderer->doc .= '<table:table-cell table:style-name="pluginnote'.$type.'.A1" office:value-type="string">';
   1.163 +              // Don't use p_open, as it's not the same style-name
   1.164 +              $renderer->doc .= '<text:p text:style-name="Table_20_Contents">';
   1.165 +              $src = DOKU_PLUGIN."note/images/".$type.".png";
   1.166 +              $renderer->_odtAddImage($src);
   1.167 +              $renderer->doc .= '</text:p>';
   1.168 +              $renderer->doc .= '</table:table-cell>';
   1.169 +              $renderer->doc .= '<table:table-cell table:style-name="pluginnote'.$type.'.B1" office:value-type="string">';
   1.170 +              $renderer->p_open();
   1.171 +              break;
   1.172 +  
   1.173 +            case DOKU_LEXER_UNMATCHED :
   1.174 +              $renderer->cdata($data);
   1.175 +              break;
   1.176 +  
   1.177 +            case DOKU_LEXER_EXIT :
   1.178 +              $renderer->p_close();
   1.179 +              $renderer->doc .= '</table:table-cell>';
   1.180 +              $renderer->doc .= '</table:table-row>';
   1.181 +              $renderer->doc .= '</table:table>';
   1.182 +              $renderer->p_open();
   1.183 +              break;
   1.184 +          }
   1.185 +          return true;
   1.186 +        }
   1.187 +        
   1.188 +        // unsupported $mode
   1.189 +        return false;
   1.190 +    } 
   1.191 +}
   1.192 + 
   1.193 +//Setup VIM: ex: et ts=4 enc=utf-8 :
   1.194 +?>