| 1 | <?php |
| 2 | |
| 3 | |
| 4 | class Text_Wiki_Render_Xhtml_Url extends Text_Wiki_Render { |
| 5 | |
| 6 | |
| 7 | var $conf = array( |
| 8 | 'target' => '_blank', |
| 9 | 'images' => true, |
| 10 | 'img_ext' => array('jpg', 'jpeg', 'gif', 'png'), |
| 11 | 'css_inline' => null, |
| 12 | 'css_footnote' => null, |
| 13 | 'css_descr' => null, |
| 14 | 'css_img' => null |
| 15 | ); |
| 16 | |
| 17 | /** |
| 18 | * |
| 19 | * Renders a token into text matching the requested format. |
| 20 | * |
| 21 | * @access public |
| 22 | * |
| 23 | * @param array $options The "options" portion of the token (second |
| 24 | * element). |
| 25 | * |
| 26 | * @return string The text rendered from the token options. |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | function token($options) |
| 31 | { |
| 32 | // create local variables from the options array (text, |
| 33 | // href, type) |
| 34 | extract($options); |
| 35 | |
| 36 | // find the rightmost dot and determine the filename |
| 37 | // extension. |
| 38 | $pos = strrpos($href, '.'); |
| 39 | $ext = strtolower(substr($href, $pos + 1)); |
| 40 | $href = htmlspecialchars($href, ENT_COMPAT | ENT_HTML401, "ISO-8859-1"); |
| 41 | |
| 42 | // does the filename extension indicate an image file? |
| 43 | if ($this->getConf('images') && |
| 44 | in_array($ext, $this->getConf('img_ext', array()))) { |
| 45 | |
| 46 | // create alt text for the image |
| 47 | if (! isset($text) || $text == '') { |
| 48 | $text = basename($href); |
| 49 | $text = htmlspecialchars($text, ENT_COMPAT | ENT_HTML401, "ISO-8859-1"); |
| 50 | } |
| 51 | |
| 52 | // generate an image tag |
| 53 | $css = $this->formatConf(' class="%s"', 'css_img'); |
| 54 | $output = "<img$css src=\"$href\" alt=\"$text\" />"; |
| 55 | |
| 56 | } else { |
| 57 | |
| 58 | // should we build a target clause? |
| 59 | if ($href{0} == '#' || |
| 60 | strtolower(substr($href, 0, 7)) == 'mailto:') { |
| 61 | // targets not allowed for on-page anchors |
| 62 | // and mailto: links. |
| 63 | $target = ''; |
| 64 | } else { |
| 65 | // allow targets on non-anchor non-mailto links |
| 66 | $target = $this->getConf('target'); |
| 67 | } |
| 68 | |
| 69 | // generate a regular link (not an image) |
| 70 | $text = htmlspecialchars($text, ENT_COMPAT | ENT_HTML401, "ISO-8859-1"); |
| 71 | $css = $this->formatConf(' class="%s"', "css_$type"); |
| 72 | $output = "<a$css href=\"$href\""; |
| 73 | |
| 74 | if ($target) { |
| 75 | // use a "popup" window. this is XHTML compliant, suggested by |
| 76 | // Aaron Kalin. uses the $target as the new window name. |
| 77 | $target = htmlspecialchars($target, ENT_COMPAT | ENT_HTML401, "ISO-8859-1"); |
| 78 | $output .= " onclick=\"window.open(this.href, '$target');"; |
| 79 | $output .= " return false;\""; |
| 80 | } |
| 81 | |
| 82 | // finish up output |
| 83 | $output .= ">$text</a>"; |
| 84 | |
| 85 | // make numbered references look like footnotes when no |
| 86 | // CSS class specified, make them superscript by default |
| 87 | if ($type == 'footnote' && ! $css) { |
| 88 | $output = '<sup>' . $output . '</sup>'; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return $output; |
| 93 | } |
| 94 | } |
| 95 | ?> |