author | Dan |
Fri, 28 Nov 2008 22:11:51 -0500 | |
changeset 751 | c1242466d061 |
parent 67 | f6454d5fec7a |
permissions | -rw-r--r-- |
1 | 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) |
|
67 | 103 |
// $text = $this->textEncode($text); |
1 | 104 |
$css = $this->formatConf(' class="%s"', "css_$type"); |
105 |
$output = "<a$css href={$quote}$href{$quote}"; |
|
67 | 106 |
|
107 |
// hackish fix for the "external" image in Oxygen [added for Enano] |
|
108 |
if ( preg_match('/<(.+?)>/is', $text) ) |
|
109 |
{ |
|
110 |
$output .= ' style="background-image: none; padding-right: 0;"'; |
|
111 |
} |
|
1 | 112 |
|
113 |
if ($target) { |
|
114 |
// use a "popup" window. this is XHTML compliant, suggested by |
|
115 |
// Aaron Kalin. uses the $target as the new window name. |
|
116 |
$target = $this->textEncode($target); |
|
117 |
$output .= " onclick={$quote}window.open(this.href, '$target');"; |
|
118 |
$output .= " return false;{$quote}"; |
|
119 |
} |
|
120 |
||
121 |
// finish up output |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
122 |
$output .= " rel=".'"'."nofollow".'"'.">$text</a>"; |
1 | 123 |
|
124 |
// make numbered references look like footnotes when no |
|
125 |
// CSS class specified, make them superscript by default |
|
126 |
if ($type == 'footnote' && ! $css) { |
|
127 |
$output = '<sup>' . $output . '</sup>'; |
|
128 |
} |
|
129 |
} |
|
130 |
||
131 |
return $output; |
|
132 |
} |
|
133 |
} |
|
134 |
?> |