2007-02-23 00:41:25 +03:00
|
|
|
<?php
|
|
|
|
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
|
|
|
/**
|
|
|
|
* Url rule end renderer for Xhtml
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* @category Text
|
|
|
|
* @package Text_Wiki
|
|
|
|
* @author Paul M. Jones <pmjones@php.net>
|
|
|
|
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
2007-07-20 12:03:04 +04:00
|
|
|
* @version CVS: $Id: Url.php,v 1.18 2007/05/26 17:15:41 mic Exp $
|
2007-02-23 00:41:25 +03:00
|
|
|
* @link http://pear.php.net/package/Text_Wiki
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class renders URL links in XHTML.
|
|
|
|
*
|
|
|
|
* @category Text
|
|
|
|
* @package Text_Wiki
|
|
|
|
* @author Paul M. Jones <pmjones@php.net>
|
|
|
|
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
|
|
|
* @version Release: @package_version@
|
|
|
|
* @link http://pear.php.net/package/Text_Wiki
|
|
|
|
*/
|
|
|
|
class Text_Wiki_Render_Xhtml_Url extends Text_Wiki_Render {
|
|
|
|
|
|
|
|
|
|
|
|
var $conf = array(
|
|
|
|
'target' => '_blank',
|
|
|
|
'images' => true,
|
|
|
|
'img_ext' => array('jpg', 'jpeg', 'gif', 'png'),
|
|
|
|
'css_inline' => null,
|
|
|
|
'css_footnote' => null,
|
|
|
|
'css_descr' => null,
|
|
|
|
'css_img' => null
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Renders a token into text matching the requested format.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
* @param array $options The "options" portion of the token (second
|
|
|
|
* element).
|
|
|
|
*
|
|
|
|
* @return string The text rendered from the token options.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
function token($options)
|
|
|
|
{
|
|
|
|
// create local variables from the options array (text,
|
|
|
|
// href, type)
|
|
|
|
extract($options);
|
|
|
|
|
|
|
|
// find the rightmost dot and determine the filename
|
|
|
|
// extension.
|
|
|
|
$pos = strrpos($href, '.');
|
|
|
|
$ext = strtolower(substr($href, $pos + 1));
|
|
|
|
$href = $this->textEncode($href);
|
|
|
|
|
|
|
|
// does the filename extension indicate an image file?
|
|
|
|
if ($this->getConf('images') &&
|
|
|
|
in_array($ext, $this->getConf('img_ext', array()))) {
|
|
|
|
|
|
|
|
// create alt text for the image
|
|
|
|
if (! isset($text) || $text == '') {
|
|
|
|
$text = basename($href);
|
|
|
|
$text = $this->textEncode($text);
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate an image tag
|
|
|
|
$css = $this->formatConf(' class="%s"', 'css_img');
|
2007-07-20 12:03:04 +04:00
|
|
|
$start = "<img$css src=\"$href\" alt=\"$text\" title=\"$text\" /><!-- ";
|
|
|
|
$end = " -->";
|
2007-02-23 00:41:25 +03:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// should we build a target clause?
|
|
|
|
if ($href{0} == '#' ||
|
2007-07-20 12:03:04 +04:00
|
|
|
strtolower(substr($href, 0, 7)) == 'mailto:') {
|
|
|
|
// targets not allowed for on-page anchors
|
|
|
|
// and mailto: links.
|
2007-02-23 00:41:25 +03:00
|
|
|
$target = '';
|
|
|
|
} else {
|
2007-07-20 12:03:04 +04:00
|
|
|
// allow targets on non-anchor non-mailto links
|
2007-02-23 00:41:25 +03:00
|
|
|
$target = $this->getConf('target');
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate a regular link (not an image)
|
|
|
|
$text = $this->textEncode($text);
|
|
|
|
$css = $this->formatConf(' class="%s"', "css_$type");
|
2007-07-20 12:03:04 +04:00
|
|
|
$start = "<a$css href=\"$href\"";
|
2007-02-23 00:41:25 +03:00
|
|
|
|
2007-07-20 12:03:04 +04:00
|
|
|
if ($target && $target != '_self') {
|
2007-02-23 00:41:25 +03:00
|
|
|
// use a "popup" window. this is XHTML compliant, suggested by
|
|
|
|
// Aaron Kalin. uses the $target as the new window name.
|
|
|
|
$target = $this->textEncode($target);
|
2007-07-20 12:03:04 +04:00
|
|
|
$start .= " onclick=\"window.open(this.href, '$target');";
|
|
|
|
$start .= " return false;\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($name)) {
|
|
|
|
$start .= " id=\"$name\"";
|
2007-02-23 00:41:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// finish up output
|
2007-07-20 12:03:04 +04:00
|
|
|
$start .= ">";
|
|
|
|
$end = "</a>";
|
2007-02-23 00:41:25 +03:00
|
|
|
|
|
|
|
// make numbered references look like footnotes when no
|
|
|
|
// CSS class specified, make them superscript by default
|
|
|
|
if ($type == 'footnote' && ! $css) {
|
2007-07-20 12:03:04 +04:00
|
|
|
$start = '<sup>' . $start;
|
|
|
|
$end = $end . '</sup>';
|
2007-02-23 00:41:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-20 12:03:04 +04:00
|
|
|
if ($options['type'] == 'start') {
|
|
|
|
$output = $start;
|
|
|
|
} else if ($options['type'] == 'end') {
|
|
|
|
$output = $end;
|
|
|
|
} else {
|
|
|
|
$output = $start . $text . $end;
|
|
|
|
}
|
2007-02-23 00:41:25 +03:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|