From 1b7975ad33a734dc1dca8d338ef5f21d49ce9bfd Mon Sep 17 00:00:00 2001 From: "Janus B. Kristensen" Date: Fri, 13 May 2005 19:13:30 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=6146 --- html/inc/forum_show.inc | 24 ++-- html/inc/text_transform.inc | 218 ++++++++++++++++++++++++++++++++++++ html/inc/util.inc | 2 +- 3 files changed, 234 insertions(+), 10 deletions(-) create mode 100644 html/inc/text_transform.inc diff --git a/html/inc/forum_show.inc b/html/inc/forum_show.inc index 5d65ae124d..05f73f26c7 100644 --- a/html/inc/forum_show.inc +++ b/html/inc/forum_show.inc @@ -86,7 +86,7 @@ function show_forum($category, $forum, $start, $sort_style, $logged_in_user) { if ($category->is_helpdesk) { start_forum_table(array("Question", "Answers")); } else { - start_forum_table(array("", "Threads", "Posts", "Author", "Views", "Last post")); + start_forum_table(array("", "Threads", "Posts", "Author", "Views", "Last post")); } $sticky_first = !$logged_in_user->ignore_sticky_posts; $threads = getThreads($forum->id, $start, $threads_per_page, $sort_style, 0, $sticky_first); @@ -120,7 +120,13 @@ function show_forum($category, $forum, $start, $sort_style, $logged_in_user) { } echo ""; } - echo "id, "\">", cleanup_title($thread->title), "
"; + $titlelength = 42; // The answer to Life, the Universe, and Everything + // ...and it makes the forum look better + $title = cleanup_title($thread->title); + if (strlen($title) > $titlelength) { + $title = substr($title,0,$titlelength)."..."; + } + echo "
id, "\">", $title, "
"; $n = ($n+1)%2; if ($category->is_helpdesk) { @@ -132,22 +138,22 @@ function show_forum($category, $forum, $start, $sort_style, $logged_in_user) { echo "
Asked $x; asked $na times"; } - echo ""; + echo "
"; $x = time_diff_str($thread->timestamp, time()); if ($category->is_helpdesk) { if ($thread->replies == 0) $x = "---"; - echo " + echo "
Total: $thread->replies
Last: $x - +
"; } else { echo " - ", $thread->replies+1, " - ", user_links($user), " - ", $thread->views, " - ", $x, " +
", $thread->replies+1, "
+
", user_links($user), "
+
", $thread->views, "
+
", $x, "
"; } diff --git a/html/inc/text_transform.inc b/html/inc/text_transform.inc new file mode 100644 index 0000000000..06f4fcb7a8 --- /dev/null +++ b/html/inc/text_transform.inc @@ -0,0 +1,218 @@ +'s? (on) + var $htmlitems; // Convert special chars to HTML entities? (off) + var $htmlscrub; // Scrub "bad" HTML tags? (off) + var $stripslashes; // Strip slashes (depends) + + function output_options() { + // Set defaults - should we DEFINE these somewhere else? + $this->bb2html = 1; + $this->images_as_links = 0; + $this->link_popup = 0; + $this->closeTags = 1; + $this->nl2br = 1; + $this->htmlitems = 0; + $this->htmlscrub = 0; + if (get_magic_quotes_gpc()) { + $this->stripslashes = 1; + } + return true; + } +} + +function output_transform($text, $options = NULL) { + // Options is a output_options object, defined above + if (!$options) { + $options = new output_options; // Defaults in the class definition + } + + if ($options->stripslashes) { + $text = stripslashes($text); + } + if ($options->htmlitems) { + $text = htmlentities($text); + } + if ($options->htmlscrub) { + $text = sanitize_html($text); + } + if ($options->nl2br) { + $text = nl2br($text); + } + if ($options->bb2html) { + $text = bb2html($text); + } + if ($options->images_as_links) { + $text = image_as_link($text); + } + if ($options->link_popup) { + $text = externalize_links($text); + } + + return $text; +} + +function get_transform_settings_from_user($user, $options = '') { + // $user - a user object + // $options - a output_options object (optional) + if (!$options) { + $options = new output_options; // Give defaults + } + if ($user->images_as_links==1){ + $options->images_as_links = 1; + } + if ($user->link_popup==1){ + $options->link_popup = 1; + } + return $options; +} + +function bb2html($text) { + // Function converts bbcode to HTML + + $urlregex = "(?:\"?)(?:(http\:\/\/)?)([^\[\"<\ ]+)(?:\"?)"; + // List of allowable tags + $bbtags = array ( + "@\[b\](.*?)\[/b\]@is", + "@\[i\](.*?)\[/i\]@is", + "@\[u\](.*?)\[/u\]@is", + "@\[link=$urlregex\](.*?)\[/link\]@i", + "@\[link\]$urlregex\[/link\]@i", + "@\[url=$urlregex\](.*?)\[/url\]@i", + "@\[url\]$urlregex\[/url\]@i", + "@\[quote=(.*?)\](.*?)\[/quote\]@is", + "@\[quote\](.*?)\[/quote\]@is", + "@\[font=(.*?)\](.*?)\[/font\]@is", + "@\[list\](.*?)\[/list\]@is", + "@\[list=1\](.*?)\[/list\]@is", + "@\[pre\](.*?)\[/pre\]@is", + "@\[img\]$urlregex\[/img\]@is", + "@\[color=(?:\"?)(.{3,8})(?:\"?)\](.*?)\[/color\]@is", + "@((?:
    |
      ).*?)\n\*([^\n]+)\n(.*?(
|))@is", + "@\[size=([1-9]|[0-2][0-9])\](.*?)\[/size\]@is", + "@\[code\](.*?)\[/code\]@is", + "@\[mailto\](.*?)\[/mailto\]@is", + "@\[email\](.*?)\[/email\]@is" + //Note: The above list array member ensures we're within a list + // when doing list item transformations. + //TODO: Make sure we're not between two lists + ); + + // What the above tags are turned in to + $htmltags = array ( + "\\1", + "\\1", + "\\1", + "\\3", + "http://\\2", + "\\3", + "http://\\2", + "
\\2
", + "
\\1
", + "\\2", + "", + "
    \\1
", + "
\\1
", + "", + "\\2", + "\\1
  • \\2
  • \n\\3", + "\\2", + "
    \\1
    ", + "\\1", + "\\1" + ); + + // Do the actual replacing - iterations for nested items + $lasttext = ""; + $i = 0; + // TODO: Speed this up a little bit + while ($text != $lasttext) { + $lasttext = $text; + $text = preg_replace($bbtags,$htmltags,$text); + $i = $i + 1; + } + return $text; +} + +function externalize_links($text){ + // TODO: Convert this to PCRE + $i=0;$linkpos=true; + while (true){ //Find a link + $linkpos=strpos($text,"]?', 'strong', 'ul', 'li', 'pre', 'blockquote', 'u'); + // Note on $tags - no br or img, as they have no closing tags - can we define this above? + // Maybe define two arrays, those with closing tags and those without, and combine the + // two of them for the standard HTML sanitizing function? + + // Don't do anything if the string is too short + if (strlen($str) < 3) { + return $str; + } else { + // Loop over $str and count the opening and closing for each tag in $tags + foreach ($tags as $tag) { + $m = array(); + $o = preg_match_all("/<(".$tag.")>/", $str, $m); + $c = substr_count($str, ""); + + $open[$tag] = ($o < $c) ? $c - $o : 0; + $close[$tag] = ($c < $o) ? $o - $c : 0; + + // Debuggin' + //echo "
    Tag: {$tag}\nOpen: {$o}\nClose: {$c}\nOT: {$open[$tag]}\nCT: {$close[$tag]}

    "; + } + + // Prepend the return string with an opening tag as needed + /* $pre = ''; ...uhh... doesn't work right + + foreach ($open as $tag => $cnt) { + $pre .= ($cnt > 0) ? "<{$tag}>" : ''; + } */ + + // Append the return string with a closing tag as needed + $post = ''; + + foreach ($close as $tag => $cnt) { + $post .= ($cnt > 0) ? "" : ''; + } + + return /*$pre.*/$str.$post; + } +} + +function cleanTextBox($content) { + /* Cleans current text boxes for display. Will be replaced with just an + * htmlentities() call after we stop allowing HTML posting. + */ + $answer = preg_replace('/</','&lt;',preg_replace('/>/','&gt;',$content)); + return $answer; +} diff --git a/html/inc/util.inc b/html/inc/util.inc index 9a8641bd70..0b79c8ca45 100644 --- a/html/inc/util.inc +++ b/html/inc/util.inc @@ -440,7 +440,7 @@ function close_output_buffer($filename) { } function html_info() { - return "
    You may use HTML tags\n"; + return "
    You may use BBCode tags\n"; } function get_int($name, $optional=false) {