[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/bundled-libs/Text/Wiki/Rule/ -> image.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: image.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 embed the contents of a URL
  25  * inside the page.  Typically used to get script output.
  26  *
  27  * This rule is inherently not secure; it allows cross-site scripting to
  28  * occur if the embedded output has <script> or other similar tags.  Be
  29  * careful.
  30  *
  31  * In the future, we'll add a rule config options to set the base embed
  32  * path so that it is limited to one directory.
  33  *
  34  * @author Paul M. Jones <pmjones@ciaweb.net>
  35  *
  36  * @package Text_Wiki
  37  *
  38  */
  39  
  40  class Text_Wiki_Rule_image extends Text_Wiki_Rule {
  41      
  42      
  43      /**
  44      * 
  45      * The regular expression used to find source text matching this
  46      * rule.
  47      * 
  48      * @access public
  49      * 
  50      * @var string
  51      * 
  52      */
  53      
  54      var $regex = '/(\[\[image )(.+?)(\]\])/i';
  55      
  56      
  57      /**
  58      * 
  59      * Generates a token entry for the matched text.  Token options are:
  60      * 
  61      * 'src' => The image source, typically a relative path name.
  62      *
  63      * 'opts' => Any macro options following the source.
  64      * 
  65      * @access public
  66      *
  67      * @param array &$matches The array of matches from parse().
  68      *
  69      * @return A delimited token number to be used as a placeholder in
  70      * the source text.
  71      *
  72      */
  73      
  74      function process(&$matches)
  75      {
  76          $pos = strpos($matches[2], ' ');
  77          
  78          if ($pos === false) {
  79              $options = array(
  80                  'src' => $matches[2],
  81                  'args' => array());
  82          } else {
  83              // everything after the space is macro options
  84              $options = array(
  85                  'src' => substr($matches[2], 0, $pos),
  86                  'args' => $this->getMacroArgs(substr($matches[2], $pos+1))
  87              );
  88          }
  89          
  90          return $this->addToken($options);
  91      }
  92      
  93      
  94      /**
  95      * 
  96      * Renders a token into text matching the requested format.
  97      * 
  98      * @access public
  99      * 
 100      * @param array $options The "options" portion of the token (second
 101      * element).
 102      * 
 103      * @return string The text rendered from the token options.
 104      * 
 105      */
 106      
 107      function renderXhtml($options)
 108      {
 109          $src = '"' . $this->_conf['base'] . $options['src'] . '"';
 110          
 111          if (isset($options['args']['link'])) {
 112              // this image has a wikilink
 113              $href = $this->_wiki->getRuleConf('wikilink', 'view_url') .
 114                  $options['args']['link'];
 115          } else {
 116              // image is not linked
 117              $href = null;
 118          }
 119          
 120          // unset these so they don't show up as attributes
 121          unset($options['args']['src']);
 122          unset($options['args']['link']);
 123          
 124          $attr = '';
 125          foreach ($options['args'] as $key => $val) {
 126              $attr .= "$key=\"$val\" ";
 127          }
 128          
 129          if ($href) {
 130              return "<a href=\"$href\"><img src=$src $attr/></a>";
 131          } else {
 132              return "<img src=$src $attr/>";
 133          }
 134      }
 135  }
 136  ?>


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