3 class Text_Wiki_Render_Xhtml_Wikilink
extends Text_Wiki_Render
{
6 'pages' => array(), // set to null or false to turn off page checks
7 'view_url' => 'http://example.com/index.php?page=%s',
8 'new_url' => 'http://example.com/new.php?page=%s',
10 'new_text_pos' => 'after', // 'before', 'after', or null/false
13 'exists_callback' => null
// call_user_func() callback
19 * Renders a token into XHTML.
23 * @param array $options The "options" portion of the token (second
26 * @return string The text rendered from the token options.
30 function token($options)
32 // make nice variable names (page, anchor, text)
35 // is there a "page existence" callback?
36 // we need to access it directly instead of through
37 // getConf() because we'll need a reference (for
38 // object instance method callbacks).
39 if (isset($this->conf
['exists_callback'])) {
40 $callback =& $this->conf
['exists_callback'];
46 // use the callback function
47 $exists = call_user_func($callback, $page);
49 // no callback, go to the naive page array.
50 $list =& $this->getConf('pages');
51 if (is_array($list)) {
52 // yes, check against the page list
53 $exists = in_array($page, $list);
55 // no, assume it exists
60 // convert *after* checking against page names so as not to mess
61 // up what the user typed and what we're checking.
62 $page = htmlspecialchars($page);
63 $anchor = htmlspecialchars($anchor);
64 $text = htmlspecialchars($text);
66 // does the page exist?
71 // link to the page view, but we have to build
72 // the HREF. we support both the old form where
73 // the page always comes at the end, and the new
74 // form that uses %s for sprintf()
75 $href = $this->getConf('view_url');
77 if (strpos($href, '%s') === false
) {
78 // use the old form (page-at-end)
79 $href = $href . $page . $anchor;
81 // use the new form (sprintf format string)
82 $href = sprintf($href, $page . $anchor);
85 // get the CSS class and generate output
86 $css = $this->formatConf(' class="%s"', 'css');
87 $output = "<a$css href=\"$href\">$text</a>";
91 // PAGE DOES NOT EXIST.
93 // link to a create-page url, but only if new_url is set
94 $href = $this->getConf('new_url', null
);
96 // set the proper HREF
97 if (! $href ||
trim($href) == '') {
99 // no useful href, return the text as it is
104 // yes, link to the new-page href, but we have to build
105 // it. we support both the old form where
106 // the page always comes at the end, and the new
107 // form that uses sprintf()
108 if (strpos($href, '%s') === false
) {
110 $href = $href . $page;
113 $href = sprintf($href, $page);
117 // get the appropriate CSS class and new-link text
118 $css = $this->formatConf(' class="%s"', 'css_new');
119 $new = $this->getConf('new_text');
121 // what kind of linking are we doing?
122 $pos = $this->getConf('new_text_pos');
123 if (! $pos ||
! $new) {
124 // no position (or no new_text), use css only on the page name
125 $output = "<a$css href=\"$href\">$page</a>";
126 } elseif ($pos == 'before') {
127 // use the new_text BEFORE the page name
128 $output = "<a$css href=\"$href\">$new</a>$text";
130 // default, use the new_text link AFTER the page name
131 $output = "$text<a$css href=\"$href\">$new</a>";