[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/inc/savant2/Savant2/ -> Savant2_Plugin_image.php (source)

   1  <?php
   2  
   3  /**
   4  * Base plugin class.
   5  */
   6  require_once 'Savant2/Plugin.php';
   7  
   8  /**
   9  * 
  10  * Outputs an <image ... /> tag.
  11  *
  12  * Support for alpha transparency of PNG files in Microsoft IE added by
  13  * Edward Ritter; thanks, Edward.
  14  * 
  15  * $Id: Savant2_Plugin_image.php 18360 2005-05-26 19:38:09Z mipmip $
  16  * 
  17  * @author Paul M. Jones <pmjones@ciaweb.net>
  18  * 
  19  * @author Edward Ritter <esritter@gmail.com>
  20  * 
  21  * @package Savant2
  22  * 
  23  * @license http://www.gnu.org/copyleft/lesser.html LGPL
  24  * 
  25  * This program is free software; you can redistribute it and/or modify
  26  * it under the terms of the GNU Lesser General Public License as
  27  * published by the Free Software Foundation; either version 2.1 of the
  28  * License, or (at your option) any later version.
  29  * 
  30  * This program is distributed in the hope that it will be useful, but
  31  * WITHOUT ANY WARRANTY; without even the implied warranty of
  32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  33  * Lesser General Public License for more details.
  34  * 
  35  */
  36  
  37  class Savant2_Plugin_image extends Savant2_Plugin {
  38      
  39      
  40      /**
  41      * 
  42      * The document root.
  43      * 
  44      * @access public
  45      * 
  46      * @var string
  47      * 
  48      */
  49      
  50      var $documentRoot = null;
  51      
  52      
  53      /**
  54      * 
  55      * The base directory for images within the document root.
  56      * 
  57      * @access public
  58      * 
  59      * @var string
  60      * 
  61      */
  62      
  63      var $imageDir = null;
  64      
  65      
  66      /**
  67      * 
  68      * Outputs an <img ... /> tag.
  69      * 
  70      * Microsoft IE alpha PNG support added by Edward Ritter.
  71      * 
  72      * @access public
  73      * 
  74      * @param string $file The path to the image on the local file system
  75      * relative to $this->imageDir.
  76      * 
  77      * @param string $alt Alternative descriptive text for the image;
  78      * defaults to the filename of the image.
  79      * 
  80      * @param int $border The border width for the image; defaults to zero.
  81      * 
  82      * @param int $width The displayed image width in pixels; defaults to
  83      * the width of the image.
  84      * 
  85      * @param int $height The displayed image height in pixels; defaults to
  86      * the height of the image.
  87      * 
  88      */
  89      
  90  	function plugin($file, $alt = null, $height = null, $width = null,
  91          $attr = null)
  92      {
  93          // is the document root set?
  94          if (is_null($this->documentRoot)) {
  95              // no, so set it
  96              $this->documentRoot = $_SERVER['DOCUMENT_ROOT'];
  97          }
  98          
  99          // the image file type code (PNG = 3)
 100          $type = null;
 101          
 102          // get the file information
 103          $info = false;
 104          if (strpos($file, '://') === false) {
 105              // no "://" in the file, so it's local
 106              $file = $this->imageDir . $file;
 107              $info = @getimagesize($this->documentRoot . $file);
 108          } else {
 109              // get the file size info as from a stream
 110              $info = @getimagesize($file);
 111          }
 112          
 113          // did we find the file?
 114          if (is_array($info)) {
 115          
 116              // capture type info regardless
 117              $type = $info[2];
 118              
 119              // capture size info where both not specified
 120              if (is_null($width) && is_null($height)) {
 121                  $width = $info[0];
 122                  $height = $info[1];
 123              }
 124          }
 125          
 126          // clean up
 127          unset($info);
 128          
 129          // is the file a PNG? if so, check user agent, we will need to
 130          // make special allowances for Microsoft IE.
 131          if (stristr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && $type === 3) {
 132              
 133              // support alpha transparency for PNG files in MSIE
 134              $html = '<span style="position: relative;';
 135              
 136              if ($height) {
 137                  $html .= ' height: ' . $height . 'px;';
 138              }
 139              
 140              if ($width) {
 141                  $html .= ' width: ' . $width . 'px;';
 142              }
 143              
 144              $html .= ' filter:progid:DXImageTransform.Microsoft.AlphaImageLoader';
 145              $html .= "(src='$file',sizingMethod='scale');\"";
 146              $html .= ' title="' . htmlspecialchars($alt) . '"';
 147              
 148              $html .= $this->_attr($attr);
 149  
 150              // done
 151              $html .= '></span>';
 152              
 153          } else {
 154              
 155              // not IE, so build a normal image tag.
 156              $html = '<img';
 157              $html .= ' src="' . htmlspecialchars($file) . '"';
 158              
 159              // add the alt attribute
 160              if (is_null($alt)) {
 161                  $alt = basename($file);
 162              }
 163              $html .= ' alt="' . htmlspecialchars($alt) . '"';
 164              
 165              // add the height attribute
 166              if ($height) {
 167                  $html .= ' height="' . htmlspecialchars($height) . '"';
 168              }
 169              
 170              // add the width attribute
 171              if ($width) {
 172                  $html .= ' width="' . htmlspecialchars($width) . '"';
 173              }
 174              
 175              $html .= $this->_attr($attr);
 176              
 177              // done
 178              $html .= ' />';
 179              
 180          }
 181          
 182          // done!
 183          return $html;
 184      }
 185      
 186      
 187      /**
 188      * 
 189      * Create additional HTML attributes.
 190      * 
 191      * @access private
 192      * 
 193      * @param array|string $attr An array or string of attributes.
 194      * 
 195      * @return string A string of attributes.
 196      * 
 197      */
 198      
 199  	function _attr($attr = null)
 200      {
 201          $html = '';
 202          
 203          // add other attributes
 204          if (is_array($attr)) {
 205              // from array
 206              foreach ($attr as $key => $val) {
 207                  $key = htmlspecialchars($key);
 208                  $val = htmlspecialchars($val);
 209                  $html .= " $key=\"$val\"";
 210              }
 211          } elseif (! is_null($attr)) {
 212              // from scalar
 213              $html .= " $attr";
 214          }
 215          
 216          return $html;
 217      }
 218  }
 219  
 220  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7