Skip to:
Content

bbPress.org


Ignore:
Timestamp:
12/27/2004 11:22:22 AM (22 years ago)
Author:
matt
Message:

Login, logout, sanitize everything, be fast.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-includes/formatting-functions.php

    r4 r5  
    1818}
    1919
    20 function bb_autop($pee, $br = 1) {
     20function bb_autop($pee, $br = 1) { // Reduced to be faster
    2121        $pee = $pee . "\n"; // just to make things a little easier, pad the end
    2222        $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    2323        // Space things out a little
    24         $pee = preg_replace('!(<(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|math|p|h[1-6])[^>]*>)!', "\n$1", $pee);
    25         $pee = preg_replace('!(</(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|math|p|h[1-6])>)!', "$1\n", $pee);
     24        $pee = preg_replace('!(<(?:ul|ol|li|pre|blockquote|p|h[1-6])[^>]*>)!', "\n$1", $pee);
     25        $pee = preg_replace('!(</(?:ul|ol|li|pre|blockquote|p|h[1-6])>)!', "$1\n", $pee);
    2626        $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
    2727        $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
    2828        $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "\t<p>$1</p>\n", $pee); // make paragraphs, including one at the end
    2929        $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
    30     $pee = preg_replace('!<p>\s*(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|math|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
     30    $pee = preg_replace('!<p>\s*(</?(?:ul|ol|li|pre|blockquote|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
    3131        $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists
    3232        $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
    3333        $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    34         $pee = preg_replace('!<p>\s*(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|math|p|h[1-6])[^>]*>)!', "$1", $pee);
    35         $pee = preg_replace('!(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|math|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee);
     34        $pee = preg_replace('!<p>\s*(</?(?:ul|ol|li|pre|blockquote|p|h[1-6])[^>]*>)!', "$1", $pee);
     35        $pee = preg_replace('!(</?(?:ul|ol|li|pre|blockquote|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee);
    3636        if ($br) $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
    37         $pee = preg_replace('!(</?(?:table|thead|tfoot|caption|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|math|p|h[1-6])[^>]*>)\s*<br />!', "$1", $pee);
     37        $pee = preg_replace('!(</?(?:ul|ol|li|pre|blockquote|p|h[1-6])[^>]*>)\s*<br />!', "$1", $pee);
    3838        $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)!', '$1', $pee);
    3939        $pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') .  clean_pre('$2')  . '</pre>' ", $pee);
    … …  
    4242}
    4343function encodeit($text) {
    44         $text = stripslashes($text);
    45         $text = preg_replace("|\n+|", "\n", $text);
    46         $text = nl2br($text);
    47         return $text;
     44        $text = stripslashes($text); // because it's a regex callback
     45        $text = htmlspecialchars($text, ENT_QUOTES);
     46        $text = preg_replace("|\n+|", "\n", $text);
     47        $text = nl2br($text);
     48        return $text;
    4849}
    4950
    … …  
    6162        $text = preg_replace('|&lt;(/?ul)&gt;|', '<$1>', $text);
    6263        $text = preg_replace('|&lt;(/?li)&gt;|', '<$1>', $text);
    63         $text = preg_replace('|&lt;(/?blockquote)&gt;|', '<$1>', $text);
     64        $text = preg_replace('|&lt;(/?blockquote.*?)&gt;|', '<$1>', $text);
    6465        $text = preg_replace('|&lt;(/?code)&gt;|', '<$1>', $text);
     66
     67        $text = preg_replace("|`(.*?)`|se", "'<code>' . encodeit('$1') . '</code>'", $text);
     68
    6569        return $text;
    6670}
    6771
    68 function wp_filter_kses($data) {
     72function bb_filter_kses($data) {
    6973        $allowedtags = array(
    7074                'a' => array(
    … …  
    8690        return wp_kses($data, $allowedtags);
    8791}
     92
     93function user_sanitize( $text ) {
     94    $text = preg_replace('/[^a-z0-9_-]/i', '', $text);
     95        return $text;
     96}
    8897?>
Note: See TracChangeset for help on using the changeset viewer.