[ 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_ahref.php (source)

   1  <?php
   2  
   3  /**
   4  * Base plugin class.
   5  */
   6  require_once 'Savant2/Plugin.php';
   7  
   8  /**
   9  * 
  10  * Outputs an HTML <a href="">...</a> tag.
  11  * 
  12  * $Id: Savant2_Plugin_ahref.php 18360 2005-05-26 19:38:09Z mipmip $
  13  * 
  14  * @author Paul M. Jones <pmjones@ciaweb.net>
  15  * 
  16  * @package Savant2
  17  * 
  18  * @license http://www.gnu.org/copyleft/lesser.html LGPL
  19  * 
  20  * This program is free software; you can redistribute it and/or modify
  21  * it under the terms of the GNU Lesser General Public License as
  22  * published by the Free Software Foundation; either version 2.1 of the
  23  * License, or (at your option) any later version.
  24  * 
  25  * This program is distributed in the hope that it will be useful, but
  26  * WITHOUT ANY WARRANTY; without even the implied warranty of
  27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  28  * Lesser General Public License for more details.
  29  * 
  30  */
  31  
  32  class Savant2_Plugin_ahref extends Savant2_Plugin {
  33  
  34      /**
  35      * 
  36      * Output an HTML <a href="">...</a> tag.
  37      * 
  38      * @access public
  39      * 
  40      * @param string|array $href A string URL for the resulting tag.  May
  41      * also be an array with any combination of the keys 'scheme',
  42      * 'host', 'path', 'query', and 'fragment' (c.f. PHP's native
  43      * parse_url() function).
  44      * 
  45      * @param string $text The displayed text of the link.
  46      * 
  47      * @param string|array $attr Any extra attributes for the <a> tag.
  48      * 
  49      * @return string The <a href="">...</a> tag.
  50      * 
  51      */
  52      
  53  	function plugin($href, $text, $attr = null)
  54      {
  55          $html = '<a href="';
  56          
  57          if (is_array($href)) {
  58              
  59              // add the HREF from an array
  60              $tmp = '';
  61              
  62              if (isset($href['scheme'])) {
  63                  $tmp .= $href['scheme'] . ':';
  64                  if (strtolower($href['scheme']) != 'mailto') {
  65                      $tmp .= '//';
  66                  }
  67              }
  68              
  69              if (isset($href['host'])) {
  70                  $tmp .= $href['host'];
  71              }
  72              
  73              if (isset($href['path'])) {
  74                  $tmp .= $href['path'];
  75              }
  76              
  77              if (isset($href['query'])) {
  78                  $tmp .= '?' . $href['query'];
  79              }
  80              
  81              if (isset($href['fragment'])) {
  82                  $tmp .= '#' . $href['fragment'];
  83              }
  84          
  85              $html .= htmlspecialchars($tmp);
  86              
  87          } else {
  88          
  89              // add the HREF from a scalar
  90              $html .= htmlspecialchars($href);
  91              
  92          }
  93          
  94          $html .= '"';
  95          
  96          // add attributes
  97          if (is_array($attr)) {
  98              // from array
  99              foreach ($attr as $key => $val) {
 100                  $key = htmlspecialchars($key);
 101                  $val = htmlspecialchars($val);
 102                  $html .= " $key=\"$val\"";
 103              }
 104          } elseif (! is_null($attr)) {
 105              // from scalar
 106              $html .= " $attr";
 107          }
 108          
 109          // set the link text, close the tag, and return
 110          $html .= '>' . htmlspecialchars($text) . '</a>';
 111          return $html;
 112      }
 113  }
 114  ?>


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