includes/wikiengine/Render/Xhtml/Url.php
changeset 1 fe660c52c48f
child 21 663fcf528726
equal deleted inserted replaced
0:902822492a68 1:fe660c52c48f
       
     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.13 2006/02/10 23:07:03 toggg 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       global $email;
       
    55         // create local variables from the options array (text,
       
    56         // href, type)
       
    57         extract($options);
       
    58         
       
    59         $quote = '"';
       
    60 
       
    61         // find the rightmost dot and determine the filename
       
    62         // extension.
       
    63         $pos = strrpos($href, '.');
       
    64         $ext = strtolower(substr($href, $pos + 1));
       
    65         
       
    66         if(substr($href, 0, 7) == 'mailto:')
       
    67         {
       
    68           $a = substr($href, 7);
       
    69           $code = $email->encryptEmail($a, '', '', $text);
       
    70           return $code;
       
    71         }
       
    72         
       
    73         $href = $this->textEncode($href);
       
    74 
       
    75         // does the filename extension indicate an image file?
       
    76         if ($this->getConf('images') &&
       
    77             in_array($ext, $this->getConf('img_ext', array()))) {
       
    78 
       
    79             // create alt text for the image
       
    80             if (! isset($text) || $text == '') {
       
    81                 $text = basename($href);
       
    82                 $text = $this->textEncode($text);
       
    83             }
       
    84 
       
    85             // generate an image tag
       
    86             $css = $this->formatConf(' class="%s"', 'css_img');
       
    87             $output = "<img$css src={$quote}$href{$quote} alt={$quote}$text{$quote} />";
       
    88 
       
    89         } else {
       
    90           
       
    91             // should we build a target clause?
       
    92             if ($href{0} == '#' ||
       
    93             	strtolower(substr($href, 0, 7)) == 'mailto:') {
       
    94             	// targets not allowed for on-page anchors
       
    95             	// and mailto: links.
       
    96                 $target = '';
       
    97             } else {
       
    98 				// allow targets on non-anchor non-mailto links
       
    99                 $target = $this->getConf('target');
       
   100             }
       
   101 
       
   102             // generate a regular link (not an image)
       
   103             $text = $this->textEncode($text);
       
   104             $css = $this->formatConf(' class="%s"', "css_$type");
       
   105             $output = "<a$css href={$quote}$href{$quote}";
       
   106 
       
   107             if ($target) {
       
   108                 // use a "popup" window.  this is XHTML compliant, suggested by
       
   109                 // Aaron Kalin.  uses the $target as the new window name.
       
   110                 $target = $this->textEncode($target);
       
   111                 $output .= " onclick={$quote}window.open(this.href, '$target');";
       
   112                 $output .= " return false;{$quote}";
       
   113             }
       
   114 
       
   115             // finish up output
       
   116             $output .= ">$text</a>";
       
   117 
       
   118             // make numbered references look like footnotes when no
       
   119             // CSS class specified, make them superscript by default
       
   120             if ($type == 'footnote' && ! $css) {
       
   121                 $output = '<sup>' . $output . '</sup>';
       
   122             }
       
   123         }
       
   124 
       
   125         return $output;
       
   126     }
       
   127 }
       
   128 ?>