[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/bundled-libs/Text/Wiki/Rule/ -> colortext.php (source)

   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4: */
   3  // +----------------------------------------------------------------------+
   4  // | PHP version 4                                                        |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 1997-2003 The PHP Group                                |
   7  // +----------------------------------------------------------------------+
   8  // | This source file is subject to version 2.0 of the PHP license,       |
   9  // | that is bundled with this package in the file LICENSE, and is        |
  10  // | available through the world-wide-web at                              |
  11  // | http://www.php.net/license/2_02.txt.                                 |
  12  // | If you did not receive a copy of the PHP license and are unable to   |
  13  // | obtain it through the world-wide-web, please send a note to          |
  14  // | license@php.net so we can mail you a copy immediately.               |
  15  // +----------------------------------------------------------------------+
  16  // | Authors: Paul M. Jones <pmjones@ciaweb.net>                          |
  17  // +----------------------------------------------------------------------+
  18  //
  19  // $Id: colortext.php,v 1.2 2004/12/02 10:54:32 nohn Exp $
  20  
  21  
  22  /**
  23  * 
  24  * This class implements a Text_Wiki_Rule to find source text marked for
  25  * coloring.
  26  *
  27  * @author Paul M. Jones <pmjones@ciaweb.net>
  28  *
  29  * @package Text_Wiki
  30  *
  31  */
  32  
  33  class Text_Wiki_Rule_colortext extends Text_Wiki_Rule {
  34      
  35      var $colors = array(
  36          'aqua',
  37          'black',
  38          'blue',
  39          'fuchsia',
  40          'gray',
  41          'green',
  42          'lime',
  43          'maroon',
  44          'navy',
  45          'olive',
  46          'purple',
  47          'red',
  48          'silver',
  49          'teal',
  50          'white',
  51          'yellow'
  52      );
  53      
  54      
  55      /**
  56      * 
  57      * The regular expression used to parse the source text and find
  58      * matches conforming to this rule.  Used by the parse() method.
  59      * 
  60      * @access public
  61      * 
  62      * @var string
  63      * 
  64      * @see parse()
  65      * 
  66      */
  67      
  68      var $regex = "/\#\#(.+?)\|(.+?)\#\#/";
  69      
  70      
  71      /**
  72      * 
  73      * Generates a replacement for the matched text.  Token options are:
  74      * 
  75      * 'type' => ['start'|'end'] The starting or ending point of the
  76      * emphasized text.  The text itself is left in the source.
  77      * 
  78      * @access public
  79      *
  80      * @param array &$matches The array of matches from parse().
  81      *
  82      * @return string A pair of delimited tokens to be used as a
  83      * placeholder in the source text surrounding the text to be
  84      * emphasized.
  85      *
  86      */
  87      
  88      function process(&$matches)
  89      {
  90          $start = $this->addToken(
  91              array(
  92                  'type' => 'start',
  93                  'color' => $matches[1]
  94              )
  95          );
  96          
  97          $end = $this->addToken(
  98              array(
  99                  'type' => 'end',
 100                  'color' => $matches[1]
 101              )
 102          );
 103          
 104          return $start . $matches[2] . $end;
 105      }
 106      
 107      
 108      /**
 109      * 
 110      * Renders a token into text matching the requested format.
 111      * 
 112      * @access public
 113      * 
 114      * @param array $options The "options" portion of the token (second
 115      * element).
 116      * 
 117      * @return string The text rendered from the token options.
 118      * 
 119      */
 120      
 121      function renderXhtml($options)
 122      {
 123          $type = $options['type'];
 124          $color = $options['color'];
 125          
 126          if (! in_array($color, $this->colors)) {
 127              $color = '#' . $color;
 128          }
 129          
 130          if ($type == 'start') {
 131              return "<span style=\"color: $color;\">";
 132          }
 133          
 134          if ($options['type'] == 'end') {
 135              return '</span>';
 136          }
 137      }
 138  }
 139  ?>


Généré le : Sat Nov 24 09:00:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics