author | Dan |
Fri, 02 Nov 2007 20:37:26 -0400 | |
changeset 221 | e5302cb1945c |
parent 67 | f6454d5fec7a |
child 713 | 6865705ec8a6 |
permissions | -rw-r--r-- |
1 | 1 |
<?php |
2 |
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: |
|
3 |
/** |
|
4 |
* Wikilink 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: Wikilink.php,v 1.17 2006/02/28 03:15:09 justinpatrin Exp $ |
|
13 |
* @link http://pear.php.net/package/Text_Wiki |
|
14 |
*/ |
|
15 |
||
16 |
/** |
|
17 |
* This class renders wiki 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_Wikilink extends Text_Wiki_Render { |
|
27 |
||
28 |
var $conf; |
|
29 |
||
30 |
function Text_Wiki_Render_Xhtml_Wikilink() { |
|
31 |
$_utemp = contentPath.'%s'; |
|
32 |
$this->conf = array( |
|
33 |
'pages' => array(), // set to null or false to turn off page checks |
|
34 |
'view_url' => $_utemp, |
|
35 |
'new_url' => $_utemp, |
|
36 |
'new_text' => ' [x]', |
|
37 |
'new_text_pos' => false, // 'before', 'after', or null/false |
|
38 |
'css' => null, |
|
39 |
'css_new' => null, |
|
40 |
'exists_callback' => 'isPage' // call_user_func() callback |
|
41 |
); |
|
42 |
} |
|
43 |
||
44 |
/** |
|
45 |
* |
|
46 |
* Renders a token into XHTML. |
|
47 |
* |
|
48 |
* @access public |
|
49 |
* |
|
50 |
* @param array $options The "options" portion of the token (second |
|
51 |
* element). |
|
52 |
* |
|
53 |
* @return string The text rendered from the token options. |
|
54 |
* |
|
55 |
*/ |
|
56 |
||
57 |
function token($options) |
|
58 |
{ |
|
59 |
global $session; |
|
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
|
60 |
if ( $session->sid_super ) |
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
|
61 |
{ |
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
|
62 |
$as = htmlspecialchars(urlSeparator) . 'auth='.$session->sid_super; |
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
|
63 |
} |
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
|
64 |
else |
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
|
65 |
{ |
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
|
66 |
$as = ''; |
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
|
67 |
} |
1 | 68 |
// make nice variable names (page, anchor, text) |
69 |
extract($options); |
|
70 |
||
71 |
// is there a "page existence" callback? |
|
72 |
// we need to access it directly instead of through |
|
73 |
// getConf() because we'll need a reference (for |
|
74 |
// object instance method callbacks). |
|
75 |
if (isset($this->conf['exists_callback'])) { |
|
76 |
$callback =& $this->conf['exists_callback']; |
|
77 |
} else { |
|
78 |
$callback = false; |
|
79 |
} |
|
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
|
80 |
|
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
|
81 |
$page = sanitize_page_id( $page ); |
1 | 82 |
|
83 |
if ($callback) { |
|
84 |
// use the callback function |
|
85 |
$exists = call_user_func($callback, $page); |
|
86 |
} else { |
|
87 |
// no callback, go to the naive page array. |
|
88 |
$list = $this->getConf('pages'); |
|
89 |
if (is_array($list)) { |
|
90 |
// yes, check against the page list |
|
91 |
$exists = in_array($page, $list); |
|
92 |
} else { |
|
93 |
// no, assume it exists |
|
94 |
$exists = true; |
|
95 |
} |
|
96 |
} |
|
97 |
||
98 |
// convert *after* checking against page names so as not to mess |
|
99 |
// up what the user typed and what we're checking. |
|
100 |
//$page = $this->urlEncode($page); |
|
101 |
$anchor = $this->urlEncode($anchor); |
|
67 | 102 |
// $text = $this->textEncode($text); |
103 |
||
104 |
// hackish fix for the "external" image in Oxygen [added for Enano] |
|
105 |
if ( preg_match('/<(.+?)>/is', $text) ) |
|
106 |
{ |
|
107 |
$nobg = ' style="background-image: none; padding-right: 0;"'; |
|
108 |
} |
|
109 |
else |
|
110 |
{ |
|
111 |
$nobg = ''; |
|
112 |
} |
|
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
|
113 |
|
1 | 114 |
// does the page exist? |
115 |
if ($exists) { |
|
116 |
||
117 |
// PAGE EXISTS. |
|
118 |
||
119 |
// link to the page view, but we have to build |
|
120 |
// the HREF. we support both the old form where |
|
121 |
// the page always comes at the end, and the new |
|
122 |
// form that uses %s for sprintf() |
|
123 |
$href = $this->getConf('view_url'); |
|
124 |
||
125 |
if (strpos($href, '%s') === false) { |
|
126 |
// use the old form (page-at-end) |
|
127 |
$href = $href . $page . $anchor; |
|
128 |
} else { |
|
129 |
// use the new form (sprintf format string) |
|
130 |
$href = sprintf($href, $page . $anchor); |
|
131 |
} |
|
132 |
||
133 |
// get the CSS class and generate output |
|
134 |
$css = $this->formatConf(' class="%s"', 'css'); |
|
135 |
||
67 | 136 |
$start = '<a'.$css.' href="'.$href.$as.'"'.$nobg.'>'; |
1 | 137 |
$end = '</a>'; |
138 |
} else { |
|
139 |
||
140 |
// PAGE DOES NOT EXIST. |
|
141 |
||
142 |
// link to the page view, but we have to build |
|
143 |
// the HREF. we support both the old form where |
|
144 |
// the page always comes at the end, and the new |
|
145 |
// form that uses %s for sprintf() |
|
146 |
$href = $this->getConf('view_url'); |
|
147 |
||
148 |
if (strpos($href, '%s') === false) { |
|
149 |
// use the old form (page-at-end) |
|
150 |
$href = $href . $page . $anchor; |
|
151 |
} else { |
|
152 |
// use the new form (sprintf format string) |
|
153 |
$href = sprintf($href, $page . $anchor); |
|
154 |
} |
|
155 |
||
156 |
// get the CSS class and generate output |
|
157 |
$css = $this->formatConf(' class="%s"', 'css'); |
|
158 |
||
67 | 159 |
$start = '<a'.$css.' href="'.$href.$as.'"'.$nobg.' class="wikilink-nonexistent">'; |
1 | 160 |
$end = '</a>'; |
161 |
||
162 |
} |
|
163 |
if (!strlen($text)) { |
|
164 |
$start .= $this->textEncode($options['page']); |
|
165 |
} |
|
166 |
if (isset($type)) { |
|
167 |
switch ($type) { |
|
168 |
case 'start': |
|
169 |
$output = $start; |
|
170 |
break; |
|
171 |
case 'end': |
|
172 |
$output = $end; |
|
173 |
break; |
|
174 |
} |
|
175 |
} else { |
|
176 |
$output = $start.$text.$end; |
|
177 |
} |
|
178 |
return $output; |
|
179 |
} |
|
180 |
} |
|
181 |
?> |