home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Text / Wiki / Render / Xhtml / Url.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  4.0 KB  |  132 lines

  1. <?php
  2. // vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
  3. /**
  4.  * Url rule end renderer for Xhtml
  5.  *
  6.  * PHP versions 4 and 5
  7.  *
  8.  * @category   Text
  9.  * @package    Text_Wiki
  10.  * @author     Paul M. Jones <pmjones@php.net>
  11.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  12.  * @version    CVS: $Id: Url.php,v 1.18 2007/05/26 17:15:41 mic Exp $
  13.  * @link       http://pear.php.net/package/Text_Wiki
  14.  */
  15.  
  16. /**
  17.  * This class renders URL links in XHTML.
  18.  *
  19.  * @category   Text
  20.  * @package    Text_Wiki
  21.  * @author     Paul M. Jones <pmjones@php.net>
  22.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  23.  * @version    Release: @package_version@
  24.  * @link       http://pear.php.net/package/Text_Wiki
  25.  */
  26. class Text_Wiki_Render_Xhtml_Url extends Text_Wiki_Render {
  27.  
  28.  
  29.     var $conf = array(
  30.         'target' => '_blank',
  31.         'images' => true,
  32.         'img_ext' => array('jpg', 'jpeg', 'gif', 'png'),
  33.         'css_inline' => null,
  34.         'css_footnote' => null,
  35.         'css_descr' => null,
  36.         'css_img' => null
  37.     );
  38.  
  39.     /**
  40.     *
  41.     * Renders a token into text matching the requested format.
  42.     *
  43.     * @access public
  44.     *
  45.     * @param array $options The "options" portion of the token (second
  46.     * element).
  47.     *
  48.     * @return string The text rendered from the token options.
  49.     *
  50.     */
  51.  
  52.     function token($options)
  53.     {
  54.         // create local variables from the options array (text,
  55.         // href, type)
  56.         extract($options);
  57.  
  58.         // find the rightmost dot and determine the filename
  59.         // extension.
  60.         $pos = strrpos($href, '.');
  61.         $ext = strtolower(substr($href, $pos + 1));
  62.         $href = $this->textEncode($href);
  63.  
  64.         // does the filename extension indicate an image file?
  65.         if ($this->getConf('images') &&
  66.             in_array($ext, $this->getConf('img_ext', array()))) {
  67.  
  68.             // create alt text for the image
  69.             if (! isset($text) || $text == '') {
  70.                 $text = basename($href);
  71.                 $text = $this->textEncode($text);
  72.             }
  73.  
  74.             // generate an image tag
  75.             $css = $this->formatConf(' class="%s"', 'css_img');
  76.             $start = "<img$css src=\"$href\" alt=\"$text\" title=\"$text\" /><!-- ";
  77.             $end = " -->";
  78.  
  79.         } else {
  80.  
  81.             // should we build a target clause?
  82.             if ($href{0} == '#' ||
  83.               strtolower(substr($href, 0, 7)) == 'mailto:') {
  84.               // targets not allowed for on-page anchors
  85.               // and mailto: links.
  86.                 $target = '';
  87.             } else {
  88.         // allow targets on non-anchor non-mailto links
  89.                 $target = $this->getConf('target');
  90.             }
  91.  
  92.             // generate a regular link (not an image)
  93.             $text = $this->textEncode($text);
  94.             $css = $this->formatConf(' class="%s"', "css_$type");
  95.             $start = "<a$css href=\"$href\"";
  96.  
  97.             if ($target && $target != '_self') {
  98.                 // use a "popup" window.  this is XHTML compliant, suggested by
  99.                 // Aaron Kalin.  uses the $target as the new window name.
  100.                 $target = $this->textEncode($target);
  101.                 $start .= " onclick=\"window.open(this.href, '$target');";
  102.                 $start .= " return false;\"";
  103.             }
  104.             
  105.             if (isset($name)) {
  106.                 $start .= " id=\"$name\"";
  107.             }
  108.  
  109.             // finish up output
  110.             $start .= ">";
  111.             $end = "</a>";
  112.  
  113.             // make numbered references look like footnotes when no
  114.             // CSS class specified, make them superscript by default
  115.             if ($type == 'footnote' && ! $css) {
  116.                 $start = '<sup>' . $start;
  117.                 $end = $end . '</sup>';
  118.             }
  119.         }
  120.  
  121.         if ($options['type'] == 'start') {
  122.             $output = $start;
  123.         } else if ($options['type'] == 'end') {
  124.             $output = $end;
  125.         } else {
  126.             $output = $start . $text . $end;
  127.         }
  128.         return $output;
  129.     }
  130. }
  131. ?>
  132.