Text_Wiki
[ class tree: Text_Wiki ] [ index: Text_Wiki ] [ all elements ]

Source for file image.php

Documentation is available at image.php

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

Documentation generated on Mon, 11 Mar 2019 10:14:14 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.