author | Dan |
Sun, 25 Jan 2009 21:18:05 -0500 | |
changeset 825 | 9d5c04c1414f |
parent 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 |
{ |
|
713
6865705ec8a6
Marked Text_Wiki's parse_internal_links() as deprecated.
Dan
parents:
67
diff
changeset
|
59 |
## |
6865705ec8a6
Marked Text_Wiki's parse_internal_links() as deprecated.
Dan
parents:
67
diff
changeset
|
60 |
## THIS IS NOT WHAT YOU ARE LOOKING FOR!! |
6865705ec8a6
Marked Text_Wiki's parse_internal_links() as deprecated.
Dan
parents:
67
diff
changeset
|
61 |
## All of this code is deprecated. Patch RenderMan::parse_internal_links() instead! |
6865705ec8a6
Marked Text_Wiki's parse_internal_links() as deprecated.
Dan
parents:
67
diff
changeset
|
62 |
## |
6865705ec8a6
Marked Text_Wiki's parse_internal_links() as deprecated.
Dan
parents:
67
diff
changeset
|
63 |
|
1 | 64 |
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
|
65 |
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
|
66 |
{ |
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 |
$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
|
68 |
} |
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
|
69 |
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
|
70 |
{ |
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
|
71 |
$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
|
72 |
} |
1 | 73 |
// make nice variable names (page, anchor, text) |
74 |
extract($options); |
|
75 |
||
76 |
// is there a "page existence" callback? |
|
77 |
// we need to access it directly instead of through |
|
78 |
// getConf() because we'll need a reference (for |
|
79 |
// object instance method callbacks). |
|
80 |
if (isset($this->conf['exists_callback'])) { |
|
81 |
$callback =& $this->conf['exists_callback']; |
|
82 |
} else { |
|
83 |
$callback = false; |
|
84 |
} |
|
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
|
85 |
|
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
|
86 |
$page = sanitize_page_id( $page ); |
1 | 87 |
|
88 |
if ($callback) { |
|
89 |
// use the callback function |
|
90 |
$exists = call_user_func($callback, $page); |
|
91 |
} else { |
|
92 |
// no callback, go to the naive page array. |
|
93 |
$list = $this->getConf('pages'); |
|
94 |
if (is_array($list)) { |
|
95 |
// yes, check against the page list |
|
96 |
$exists = in_array($page, $list); |
|
97 |
} else { |
|
98 |
// no, assume it exists |
|
99 |
$exists = true; |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
// convert *after* checking against page names so as not to mess |
|
104 |
// up what the user typed and what we're checking. |
|
105 |
//$page = $this->urlEncode($page); |
|
106 |
$anchor = $this->urlEncode($anchor); |
|
67 | 107 |
// $text = $this->textEncode($text); |
108 |
||
109 |
// hackish fix for the "external" image in Oxygen [added for Enano] |
|
110 |
if ( preg_match('/<(.+?)>/is', $text) ) |
|
111 |
{ |
|
112 |
$nobg = ' style="background-image: none; padding-right: 0;"'; |
|
113 |
} |
|
114 |
else |
|
115 |
{ |
|
116 |
$nobg = ''; |
|
117 |
} |
|
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
|
118 |
|
1 | 119 |
// does the page exist? |
120 |
if ($exists) { |
|
121 |
||
122 |
// PAGE EXISTS. |
|
123 |
||
124 |
// link to the page view, but we have to build |
|
125 |
// the HREF. we support both the old form where |
|
126 |
// the page always comes at the end, and the new |
|
127 |
// form that uses %s for sprintf() |
|
713
6865705ec8a6
Marked Text_Wiki's parse_internal_links() as deprecated.
Dan
parents:
67
diff
changeset
|
128 |
$href = makeUrl($page, false, true); |
6865705ec8a6
Marked Text_Wiki's parse_internal_links() as deprecated.
Dan
parents:
67
diff
changeset
|
129 |
|
1 | 130 |
// get the CSS class and generate output |
131 |
$css = $this->formatConf(' class="%s"', 'css'); |
|
132 |
||
67 | 133 |
$start = '<a'.$css.' href="'.$href.$as.'"'.$nobg.'>'; |
1 | 134 |
$end = '</a>'; |
135 |
} else { |
|
136 |
||
137 |
// PAGE DOES NOT EXIST. |
|
138 |
||
139 |
// link to the page view, but we have to build |
|
140 |
// the HREF. we support both the old form where |
|
141 |
// the page always comes at the end, and the new |
|
142 |
// form that uses %s for sprintf() |
|
713
6865705ec8a6
Marked Text_Wiki's parse_internal_links() as deprecated.
Dan
parents:
67
diff
changeset
|
143 |
$href = makeUrl($page, false, true); |
1 | 144 |
|
145 |
// get the CSS class and generate output |
|
146 |
$css = $this->formatConf(' class="%s"', 'css'); |
|
147 |
||
713
6865705ec8a6
Marked Text_Wiki's parse_internal_links() as deprecated.
Dan
parents:
67
diff
changeset
|
148 |
$start = '<a'.$css.' href="'.$href.'"'.$nobg.' class="wikilink-nonexistent">'; |
1 | 149 |
$end = '</a>'; |
150 |
} |
|
151 |
if (!strlen($text)) { |
|
152 |
$start .= $this->textEncode($options['page']); |
|
153 |
} |
|
154 |
if (isset($type)) { |
|
155 |
switch ($type) { |
|
156 |
case 'start': |
|
157 |
$output = $start; |
|
158 |
break; |
|
159 |
case 'end': |
|
160 |
$output = $end; |
|
161 |
break; |
|
162 |
} |
|
163 |
} else { |
|
164 |
$output = $start.$text.$end; |
|
165 |
} |
|
166 |
return $output; |
|
167 |
} |
|
168 |
} |
|
169 |
?> |