Ticket #6380: 6380.3.diff

File 6380.3.diff, 1.3 KB (added by azaozz, 5 years ago)
Line 
1Index: formatting.php
2===================================================================
3--- formatting.php      (revision 7502)
4+++ formatting.php      (working copy)
5@@ -830,8 +830,8 @@
6        if ( '' == $text ) {
7                $text = get_the_content('');
8                $text = apply_filters('the_content', $text);
9+               $text = strip_all_tags($text);
10                $text = str_replace(']]>', ']]>', $text);
11-               $text = strip_tags($text);
12                $excerpt_length = 55;
13                $words = explode(' ', $text, $excerpt_length + 1);
14                if (count($words) > $excerpt_length) {
15@@ -1406,4 +1406,24 @@
16        return $str;
17 }
18 
19-?>
20+/*
21+ * strip_all_tags() - strip all html and php tags, improved version of strip_tags()
22+ * 
23+ * will remove all tags, including <script> and <style>
24+ *
25+ * @param string $str The input string that needs stripping of tags
26+ * @param string $keep Optional. Keep some tags.
27+ *  HTML comments (including the <!--more--> tag), <script>, <style> and php tags are always removed
28+ */
29+function strip_all_tags( $str, $keep = '' ) {
30+
31+       if ( strpos( $str, '<script' ) )
32+               $str = preg_replace( '|<script[^>]*?>.*?</script>|si', '', $str );
33+
34+       if ( strpos( $str, '<style' ) )
35+               $str = preg_replace( '|<style[^>]*?>.*?</style>|si', '', $str );
36+
37+       return strip_tags( $str, $keep );
38+}
39+
40+?>
41\ No newline at end of file