class_bbcode_core.php
来自「sabreipb 2.1.6 utf-8中文版本!」· PHP 代码 · 共 1,825 行 · 第 1/4 页
PHP
1,825 行
//----------------------------------------- if ( $count[ $r['bbcode_id'] ]['open'] != $count[ $r['bbcode_id'] ]['closed'] ) { if ( $count[ $r['bbcode_id'] ]['wrongopen'] == $count[ $r['bbcode_id'] ]['closed'] ) { $this->error = 'custom_tags_incorrect2'; } else { $this->error = 'custom_tags_incorrect'; } } } return $t; } /*-------------------------------------------------------------------------*/ // Post DB parse BBCode /*-------------------------------------------------------------------------*/ /** * Pre-display parse custom BBCode * * @param string Raw text * @return string Converted text */ function post_db_parse_bbcode($t="") { //----------------------------------------- // INIT //----------------------------------------- $snapback = 0; //----------------------------------------- // Check... //----------------------------------------- if ( is_array( $this->ipsclass->cache['bbcode'] ) and count( $this->ipsclass->cache['bbcode'] ) ) { foreach( $this->ipsclass->cache['bbcode'] as $i => $row ) { if ( strtolower($row['bbcode_tag']) == 'snapback' ) { $snapback = 1; } $preg_tag = preg_quote($row['bbcode_tag'], '#' ); if ( substr_count( $row['bbcode_replace'], '{content}' ) >= 1 ) { //----------------------------------------- // Slightly slower //----------------------------------------- if ( $row['bbcode_useoption'] ) { preg_match_all( "#(\[".preg_quote($row['bbcode_tag'], '#' )."=(?:"|&\#39;)?(.+?)(?:"|&\#39;)?\])(.+?)(\[/".preg_quote($row['bbcode_tag'], '#' )."\])#si", $t, $match ); for ($i=0; $i < count($match[0]); $i++) { # XSS Check: Bug ID: 980 if ( $row['bbcode_tag'] == 'post' OR $row['bbcode_tag'] == 'topic' ) { $match[2][$i] = intval( $match[2][$i] ); } $tmp = $row['bbcode_replace']; $tmp = str_replace( '{option}' , $match[2][$i], $tmp ); $tmp = str_replace( '{content}', $match[3][$i], $tmp ); $t = str_replace( $match[0][$i], $tmp, $t ); } } else { # Tricky.. match anything that's not a closing tag, or nothing preg_match_all( "#(\[$preg_tag\])((?!\[/$preg_tag\]).+?)?(\[/$preg_tag\])#si", $t, $match ); for ($i=0; $i < count($match[0]); $i++) { $tmp = $row['bbcode_replace']; $tmp = str_replace( '{content}', $match[2][$i], $tmp ); $t = str_replace( $match[0][$i], $tmp, $t ); } } } else { $replace = explode( '{content}', $row['bbcode_replace'] ); if ( $row['bbcode_useoption'] ) { $t = preg_replace( "#\[".$row['bbcode_tag']."=(?:"|&\#39;)?(.+?)(?:"|&\#39;)?\]#si", str_replace( '{option}', "\\1", $replace[0] ), $t ); } else { $t = preg_replace( '#\['.$row['bbcode_tag'].'\]#i' , $replace[0], $t ); } $t = preg_replace( '#\[/'.$row['bbcode_tag'].'\]#i', $replace[1], $t ); } } } //----------------------------------------- // Snapback used? //----------------------------------------- if ( ! $snapback ) { $t = preg_replace( "#\[snapback\](\d+?)\[/snapback\]is#", "<a href='index.php?act=findpost&pid=\\1'><{POST_SNAPBACK}></a>", $t ); } return $t; } //----------------------------------------- // Word wrap, wraps 'da word innit //----------------------------------------- /** * Custom word wrap * * @param string Raw text * @return string Converted text */ function my_wordwrap($t="", $chrs=0, $replace="<br />") { if ( $t == "" ) { return $t; } if ( $chrs < 1 ) { return $t; } $t = preg_replace("#([^\s<>'\"/\.\\-\?&\n\r\%]{".$chrs."})#i", " \\1".$replace ,$t); return $t; } //----------------------------------------- // parse_html // Converts the doHTML tag //----------------------------------------- /** * Pre-display convert HTML entities for use * when HTML is enabled * * @param string Raw text * @return string Converted text */ function post_db_parse_html($t="") { if ( $t == "" ) { return $t; } //----------------------------------------- // Remove <br>s 'cos we know they can't // be user inputted, 'cos they are still // <br> at this point :) //----------------------------------------- if ( $this->parse_nl2br != 1 ) { $t = str_replace( "<br>" , "\n" , $t ); $t = str_replace( "<br />" , "\n" , $t ); } $t = str_replace( "'" , "'", $t ); $t = str_replace( "!" , "!", $t ); $t = str_replace( "$" , "$", $t ); $t = str_replace( "|" , "|", $t ); $t = str_replace( "&" , "&", $t ); $t = str_replace( ">" , ">", $t ); $t = str_replace( "<" , "<", $t ); $t = str_replace( """ , '"', $t ); //----------------------------------------- // Take a crack at parsing some of the nasties // NOTE: THIS IS NOT DESIGNED AS A FOOLPROOF METHOD // AND SHOULD NOT BE RELIED UPON! //----------------------------------------- $t = preg_replace( "/javascript/i" , "javascript", $t ); $t = preg_replace( "/alert/i" , "alert" , $t ); $t = preg_replace( "/about:/i" , "about:" , $t ); $t = preg_replace( "/onmouseover/i", "onmouseover" , $t ); $t = preg_replace( "/onclick/i" , "onclick" , $t ); $t = preg_replace( "/onload/i" , "onload" , $t ); $t = preg_replace( "/onsubmit/i" , "onsubmit" , $t ); return $t; } //----------------------------------------- // Badwords: // Swops naughty, naugty words and stuff //----------------------------------------- /** * Replace bad words * * @param string Raw text * @return string Converted text */ function bad_words($text = "") { if ($text == "") { return ""; } if ( $this->bypass_badwords == 1 ) { return $text; } //----------------------------------------- // Go all loopy //----------------------------------------- if ( is_array( $this->ipsclass->cache['badwords'] ) ) { usort( $this->ipsclass->cache['badwords'] , array( 'class_bbcode_core', 'word_length_sort' ) ); if ( count($this->ipsclass->cache['badwords']) > 0 ) { foreach($this->ipsclass->cache['badwords'] as $idx => $r) { if ($r['swop'] == "") { $replace = '######'; } else { $replace = $r['swop']; } $r['type'] = preg_quote($r['type'], "/"); if ($r['m_exact'] == 1) { $text = preg_replace( "/(^|\b)".$r['type']."(\b|!|\?|\.|,|$)/i", "$replace", $text ); } else { $text = preg_replace( "/".$r['type']."/i", "$replace", $text ); } } } } return $text; } /*-------------------------------------------------------------------------*/ // wrap style: code and quote table HTML generator /*-------------------------------------------------------------------------*/ /** * Wrap quote / code / html / sql divs * * @param string Type * @param string Extra vars * @return array Converted text */ function wrap_style( $type='quote', $extra="" ) { $used = array( 'quote' => array( 'title' => "{$this->ipsclass->lang['bbcode_wrap_quote']}", 'css_top' => 'quotetop' , 'css_main' => 'quotemain' ), 'code' => array( 'title' => "{$this->ipsclass->lang['bbcode_wrap_code']}" , 'css_top' => 'codetop' , 'css_main' => 'codemain' ), 'sql' => array( 'title' => "{$this->ipsclass->lang['bbcode_wrap_sql']}" , 'css_top' => 'sqltop' , 'css_main' => 'sqlmain' ), 'html' => array( 'title' => "{$this->ipsclass->lang['bbcode_wrap_html']}" , 'css_top' => 'htmltop' , 'css_main' => 'htmlmain' ) ); $this->wrap_top = "<div class='{$used[ $type ]['css_top']}'>{$used[ $type ]['title']}{$extra}</div><div class='{$used[ $type ]['css_main']}'>"; $this->wrap_bottom = "</div>"; /*if ( ! $this->wrap_top ) { if ( $this->ipsclass->compiled_templates['skin_global'] ) { $this->wrap_top = $this->ipsclass->compiled_templates['skin_global']->bbcode_wrap_start(); $this->wrap_bottom = $this->ipsclass->compiled_templates['skin_global']->bbcode_wrap_end(); $this->wrap_top = str_replace( '<!--css.top-->' , "{$used[ $type ]['css_top']}" , $this->wrap_top ); $this->wrap_top = str_replace( '<!--css.main-->', "{$used[ $type ]['css_main']}", $this->wrap_top ); $this->wrap_top = str_replace( '<!--title-->' , "{$used[ $type ]['title']}" , $this->wrap_top ); $this->wrap_top = str_replace( '<!--extra-->' , $extra , $this->wrap_top ); } }*/ return array( 'START' => $this->wrap_top, 'END' => $this->wrap_bottom ); } /*-------------------------------------------------------------------------*/ // regex_html_tag: HTML syntax highlighting /*-------------------------------------------------------------------------*/ /** * Custom HTML syntax highlighting * * @param string Raw text * @return string Converted text */ function regex_html_tag($html="") { if ($html == "") { return; } //----------------------------------------- // Take a stab at removing most of the common // smilie characters. //----------------------------------------- $html = str_replace( ":" , ":", $html ); $html = str_replace( "[" , "[", $html ); $html = str_replace( "]" , "]", $html ); $html = str_replace( ")" , ")", $html ); $html = str_replace( "(" , "(", $html ); $html = str_replace( "{" , "{", $html ); $html = str_replace( "}" , "}", $html ); $html = str_replace( "$" , "$", $html ); $html = preg_replace( "/^<br>/" , "", $html ); $html = preg_replace( "#^<br />#", "", $html ); $html = preg_replace( "/^\s+/" , "", $html ); $html = preg_replace( "#<([^&<>]+)>#" , "<<span style='color:blue'>\\1</span>>" , $html ); //Matches <tag> $html = preg_replace( "#<([^&<>]+)=#" , "<<span style='color:blue'>\\1</span>=" , $html ); //Matches <tag $html = preg_replace( "#</([^&]+)>#" , "</<span style='color:blue'>\\1</span>>" , $html ); //Matches </tag> $html = preg_replace( "!=("|')(.+?)?("|')(\s|>)!" , "=\\1<span style='color:orange'>\\2</span>\\3\\4" , $html ); //Matches ='this' $html = preg_replace( "!<!--(.+?)-->!" , "<!<span style='color:red'>--\\1--</span>>", $html ); $wrap = $this->wrap_style( 'html' ); return "<!--html-->{$wrap['START']}<!--html1-->$html<!--html2-->{$wrap['END']}<!--html3-->"; } /*-------------------------------------------------------------------------*/ // regex_sql_tag: SQL syntax highlighting /*-------------------------------------------------------------------------*/ /** * Custom SQL syntax highlighting * * @param string Raw text * @return string Converted text */ function regex_sql_tag($sql="") { if ($sql == "") { return; } //----------------------------------------- // Knock off any preceeding newlines (which have // since been converted into <br>) //----------------------------------------- $sql = preg_replace( "/^<br>/" , "", $sql ); $sql = preg_replace( "#^<br />#", "", $sql ); $sql = preg_replace( "/^\s+/" , "", $sql ); //----------------------------------------- // Make certain regex work.. //----------------------------------------- if (! preg_match( "/\s+$/" , $sql) ) { $sql = $sql.' '; } $sql = preg_replace( "#(=|\+|\-|>|<|~|==|\!=|LIKE|NOT LIKE|REGEXP)#i" , "<span style='color:orange'>\\1</span>", $sql ); $sql = preg_replace( "#(MAX|AVG|SUM|COUNT|MIN)\(#i" , "<span style='color:blue'>\\1</span>(" , $sql ); $sql = preg_replace( "#(FROM|INTO)\s{1,}(\S+?)\s{1,}#i" , "<span style='color:green'>\\1</span> <span style='color:orange'>\\2</span> ", $sql ); $sql = preg_replace( "!("|'|')(.+?)("|'|')!i" , "<span style='color:red'>\\1\\2\\3</span>" , $sql ); $sql = preg_replace( "#\s{1,}(AND|OR)\s{1,}#i" , " <span style='color:blue'>\\1</span> " , $sql ); $sql = preg_replace( "#(LEFT|JOIN|WHERE|MODIFY|CHANGE|AS|DISTINCT|IN|ASC|DESC|ORDER BY)\s{1,}#i" , "<span style='color:green'>\\1</span> " , $sql ); $sql = preg_replace( "#LIMIT\s*(\d+)\s*,\s*(\d+)#i" , "<span style='color:green'>LIMIT</span> <span style='color:orange'>\\1, \\2</span>" , $sql ); $sql = preg_replace( "#(SELECT|INSERT|UPDATE|DELETE|ALTER TABLE|DROP)#i" , "<span style='color:blue;font-weight:bold'>\\1</span>" , $sql ); $html = $this->wrap_style( 'sql' ); return "<!--sql-->{$html['START']}<!--sql1-->{$sql}<!--sql2-->{$html['END']}<!--sql3-->"; } /*-------------------------------------------------------------------------*/ // regex_code_tag: Builds this code tag HTML /*-------------------------------------------------------------------------*/ /** * Build code tag, make contents safe * * @param string Raw text * @return string Converted text */ function regex_code_tag($txt="") { $default = "\[code\]$txt\[/code\]"; if ( $txt == "" ) { return; } //----------------------------------------- // Take a stab at removing most of the common // smilie characters. //----------------------------------------- //$txt = str_replace( "&" , "&", $txt ); $txt = str_replace( "<" , "<" , $txt ); $txt = str_replace( ">" , ">" , $txt ); $txt = str_replace( """ , """ , $txt ); $txt = str_replace( ":" , ":" , $txt ); $txt = str_replace( "[" , "[" , $txt ); $txt = str_replace( "]" , "]" , $txt ); $txt = str_replace( ")" , ")" , $txt ); $txt = str_replace( "(" , "(" , $txt ); $txt = str_replace( "\r" , "<br />", $txt ); $txt = str_replace( "\n" , "<br />", $txt ); $txt = preg_replace( "#\s{1};#" , ";" , $txt ); //----------------------------------------- // Ensure that spacing is preserved //----------------------------------------- $txt = preg_replace( "#\t#" , " ", $txt ); $txt = preg_replace( "#\s{2}#", " " , $txt ); $html = $this->wrap_style( 'code' ); return "<!--c1-->{$html['START']}<!--ec1-->$txt<!--c2-->{$html['END']}<!--ec2-->"; } /*-------------------------------------------------------------------------*/ // regex_check_image: Checks, and builds the <img> /*-------------------------------------------------------------------------*/ /** * Check image URL and return HTML *
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?