PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/uofmballroom.com/html/include/Text/Wiki/Render/Xhtml/Url.php

https://github.com/vinnivinsachi/uombalrm
PHP | 117 lines | 49 code | 16 blank | 52 comment | 13 complexity | 08e28eaf2777a07a30db35eb1b93331b MD5 | raw file
  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. * This class renders URL links in XHTML.
  17. *
  18. * @category Text
  19. * @package Text_Wiki
  20. * @author Paul M. Jones <pmjones@php.net>
  21. * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
  22. * @version Release: @package_version@
  23. * @link http://pear.php.net/package/Text_Wiki
  24. */
  25. class Text_Wiki_Render_Xhtml_Url extends Text_Wiki_Render {
  26. var $conf = array(
  27. 'target' => '_blank',
  28. 'images' => true,
  29. 'img_ext' => array('jpg', 'jpeg', 'gif', 'png'),
  30. 'css_inline' => null,
  31. 'css_footnote' => null,
  32. 'css_descr' => null,
  33. 'css_img' => null
  34. );
  35. /**
  36. *
  37. * Renders a token into text matching the requested format.
  38. *
  39. * @access public
  40. *
  41. * @param array $options The "options" portion of the token (second
  42. * element).
  43. *
  44. * @return string The text rendered from the token options.
  45. *
  46. */
  47. function token($options)
  48. {
  49. // create local variables from the options array (text,
  50. // href, type)
  51. extract($options);
  52. // find the rightmost dot and determine the filename
  53. // extension.
  54. $pos = strrpos($href, '.');
  55. $ext = strtolower(substr($href, $pos + 1));
  56. $href = $this->textEncode($href);
  57. // does the filename extension indicate an image file?
  58. if ($this->getConf('images') &&
  59. in_array($ext, $this->getConf('img_ext', array()))) {
  60. // create alt text for the image
  61. if (! isset($text) || $text == '') {
  62. $text = basename($href);
  63. $text = $this->textEncode($text);
  64. }
  65. // generate an image tag
  66. $css = $this->formatConf(' class="%s"', 'css_img');
  67. $output = "<img$css src=\"$href\" alt=\"$text\" />";
  68. } else {
  69. // should we build a target clause?
  70. if ($href{0} == '#' ||
  71. strtolower(substr($href, 0, 7)) == 'mailto:') {
  72. // targets not allowed for on-page anchors
  73. // and mailto: links.
  74. $target = '';
  75. } else {
  76. // allow targets on non-anchor non-mailto links
  77. $target = $this->getConf('target');
  78. }
  79. // generate a regular link (not an image)
  80. $text = $this->textEncode($text);
  81. $css = $this->formatConf(' class="%s"', "css_$type");
  82. $output = "<a$css href=\"$href\"";
  83. if ($target) {
  84. // use a "popup" window. this is XHTML compliant, suggested by
  85. // Aaron Kalin. uses the $target as the new window name.
  86. $target = $this->textEncode($target);
  87. $output .= " onclick=\"window.open(this.href, '$target');";
  88. $output .= " return false;\"";
  89. }
  90. // finish up output
  91. $output .= ">$text</a>";
  92. // make numbered references look like footnotes when no
  93. // CSS class specified, make them superscript by default
  94. if ($type == 'footnote' && ! $css) {
  95. $output = '<sup>' . $output . '</sup>';
  96. }
  97. }
  98. return $output;
  99. }
  100. }
  101. ?>