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.  
  3.     var $conf = array(
  4.         'base' => '/',
  5.         'url_base' => null,
  6.         'css'  => null,
  7.         'css_link' => null
  8.     );
  9.     
  10.     
  11.     /**
  12.     * 
  13.     * Renders a token into text matching the requested format.
  14.     * 
  15.     * @access public
  16.     * 
  17.     * @param array $options The "options" portion of the token (second
  18.     *  element).
  19.     * 
  20.     * @return string The text rendered from the token options.
  21.     * 
  22.     */
  23.     
  24.     function token($options)
  25.     {
  26.         // note the image source
  27.         $src $options['src'];
  28.         
  29.         // is the source a local file or URL?
  30.         if (strpos($src'://'=== false{
  31.             // the source refers to a local file.
  32.             // add the URL base to it.
  33.             $src $this->getConf('base''/'$src;
  34.         }
  35.         
  36.         // stephane@metacites.net
  37.         // is the image clickable? 
  38.         if (isset($options['attr']['link'])) {
  39.             // yes, the image is clickable.
  40.             // are we linked to a URL or a wiki page?
  41.             if (strpos($options['attr']['link']'://')) {
  42.                 // it's a URL, prefix the URL base
  43.                 $href $this->getConf('url_base'$options['attr']['link'];
  44.             else {
  45.                 // it's a WikiPage; assume it exists.
  46.                 /** @todo This needs to honor sprintf wikilinks (pmjones) */
  47.                 /** @todo This needs to honor interwiki (pmjones) */
  48.                 /** @todo This needs to honor freelinks (pmjones) */
  49.                 $href $this->wiki->getRenderConf('xhtml''wikilink''view_url'.
  50.                     $options['attr']['link'];
  51.             }
  52.         else {
  53.             // image is not clickable.
  54.             $href = null;
  55.         }
  56.         // unset so it won't show up as an attribute
  57.         unset($options['attr']['link']);
  58.         
  59.         // stephane@metacites.net -- 25/07/2004 
  60.         // we make up an align="center" value for the <img> tag.
  61.         if (isset($options['attr']['align']&&
  62.             $options['attr']['align'== 'center'{
  63.             
  64.             // unset so it won't show up as an attribute
  65.             unset($options['attr']['align']);
  66.             
  67.             // make sure we have a style attribute
  68.             if (isset($options['attr']['style'])) {
  69.                 // no style, set up a blank one
  70.                 $options['attr']['style''';
  71.             else {
  72.                 // style exists, add a space
  73.                 $options['attr']['style'.= ' ';
  74.             }
  75.             
  76.             // add a "center" style to the existing style.
  77.             $options['attr']['style'.=
  78.                 'display: block; margin-left: auto; margin-right: auto;';
  79.         }
  80.         
  81.         // stephane@metacites.net -- 25/07/2004 
  82.         // try to guess width and height
  83.         if (isset($options['attr']['width']&&
  84.             isset($options['attr']['height'])) {
  85.             
  86.             // does the source refer to a local file or a URL?
  87.             if (strpos($src,'://')) {
  88.                 // is a URL link
  89.                 $imageFile $src;
  90.             elseif ($src[0== '.'{
  91.                 // reg at dav-muz dot net -- 2005-03-07
  92.                 // is a local file on relative path.
  93.                 $imageFile $src# ...don't do anything because it's perfect!
  94.             else {
  95.                 // is a local file on absolute path.
  96.                 $imageFile $_SERVER['DOCUMENT_ROOT'$src;
  97.             }
  98.             
  99.             // attempt to get the image size
  100.             $imageSize @getimagesize($imageFile);
  101.             
  102.             if (is_array($imageSize)) {
  103.                 $options['attr']['width'$imageSize[0];
  104.                 $options['attr']['height'$imageSize[1];
  105.             }
  106.             
  107.         }
  108.         
  109.         // start the HTML output
  110.         $output '<img src="' htmlspecialchars($src'"';
  111.         
  112.         // get the CSS class but don't add it yet
  113.         $css $this->formatConf(' class="%s"''css');
  114.         
  115.         // add the attributes to the output, and be sure to
  116.         // track whether or not we find an "alt" attribute
  117.         $alt = false;
  118.         foreach ($options['attr'as $key => $val{
  119.             
  120.             // track the 'alt' attribute
  121.             if (strtolower($key== 'alt'{
  122.                 $alt = true;
  123.             }
  124.             
  125.             // the 'class' attribute overrides the CSS class conf
  126.             if (strtolower($key== 'class'{
  127.                 $css = null;
  128.             }
  129.             
  130.             $key htmlspecialchars($key);
  131.             $val htmlspecialchars($val);
  132.             $output .= " $key=\"$val\"";
  133.         }
  134.         
  135.         // always add an "alt" attribute per Stephane Solliec
  136.         if ($alt{
  137.             $alt htmlspecialchars(basename($options['src']));
  138.             $output .= " alt=\"$alt\"";
  139.         }
  140.         
  141.         // end the image tag with the automatic CSS class (if any)
  142.         $output .= "$css />";
  143.         
  144.         // was the image clickable?
  145.         if ($href{
  146.             // yes, add the href and return
  147.             $href htmlspecialchars($href);
  148.             $css $this->formatConf(' class="%s"''css_link');
  149.             $output = "<a$css href=\"$href\">$output</a>";
  150.         }
  151.         
  152.         return $output;
  153.     }
  154. }
  155. ?>

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