UBB parsing class

xiaoxiao2021-03-06  54

UBB parsing class

HTML, * If you need to filter the HTML tag before calling this code, * 2. Before calling the code, please remove the redundant backslash in the conversion content before calling the code. * Otherwise, there may be problems * 3. The space is not allowed in theUBB tab ************************* **************************************************** /

Define ("Sversion", "1.2.1.15 beta");

// UBBCODE Class Class Ubbcode {var $ nest; // Regenerative depth, for debug // Processable label and handler table var $ tags = array ('url' => '$ this-> url', 'email' = > '$ this-> email', 'mail' => '$ this-> email', // For fault tolerance, [Mail] and [Email] equivalent 'img' => '$ this-> img', ' B '=>' $ this-> Simple ',' i '=>' $ this-> simple ',' u '=>' $ this-> Simple ',' TT '=>' $ this-> Simple ' , 'S' => $ this-> simple ',' strike '=>' $ this-> simple ',' h1 '=>' $ this-> simple ',' h2 '=>' $ this-> Simple ',' h3 '=>' $ this-> simple ',' h4 '=>' $ this-> simple ',' h5 '=>' $ this-> simple ',' h6 '=>' $ this -> Simple ',' Sup '=>' $ this-> Simple ',' Sub '=>' $ this-> Simple ',' EM '=>' $ THIS-> Simple ',' Strong '=>' $ this-> simple ',' code '=>' $ this-> simple ',' samp '=>' $ this-> simple ',' KBD '=>' $ this-> simple ',' var '= > '$ this-> simple', 'DFN' => '$ this-> Simple', 'CIT E '=>' $ this-> simvert ',' small '=>

'$ this-> Simple', 'Big' => '$ this-> Simple', 'blink' => '$ this-> simple', 'fly' => '$ this-> fly', 'move' => $ this-> Move ',' Glow '=>' $ this-> cssstyle ',' Shadow '=>' $ this-> cssstyle ',' blur '=>' $ this-> cssstyle ',' Wave '=>' $ this-> cssstyle ',' Sub '=>' $ this-> simple ',' sup '=>' $ this-> simple ',' size '=>' $ this-> size ' , 'Face' => '$ this-> face', 'font' => '$ this-> face', // For fault tolerance, [font] and [Face] equivalent 'color' => '$ this- > color '); function ubbcode () {$ this -> $ nest = 0; $ this -> $ SLASTMODIFIED = Sprintf ("% s", Date ("YMJ H: I", getLastMod ()));} / *********************************************************** ************** * E-mail to the user is simple to check, * Check if the user's E-mail string is @ 字 元, * There is an English alphabet or number before the @ 元, after which the number string is there, * only two or three English letters after the last decimal point. * Super@mail.wilson.gs can pass check, super @ mail.wilson can't pass check ************************* *************************************************************************************** / FUNCTION EMAILCHECK ($ STR ) {IF (EREGI ("^ [_ /. 0-9a-z] @ (0-9a-z] /.) [AZ] {2,3} $ ", $ STR)) Return True; Else Return False;}

/ ************************************************** ********************************************************************************************************************* *********************************************************** ***************************** / Function Checkurl ($ STR) {$ BVALIDURL = true; if (EREGI ("([A-Z0-9 -] ([[A-Z0-9 -] /.】 {/ * printf ("0.% s
/ n", $ Er_arr [0]); Printf ("0.% S
/ N", $ Er_arr [0]); Printf ("1.% S
/ N", $ Er_arr [1]); Printf ("2.% S
/ N", $ Er_arr [2]); Printf ("3.% s
/ n ", $ Er_arr [3]); Printf (" 4.% s
/ n ", $ Er_arr [4]); * /} else $ bvalidurl = false; return $ BVALIDURL;} / ** *********************************************************** **************** * The image URL input to the user is simple check, * Currently, it can only easily determine if the end is image file * does not support the dynamic generation by CGI Pictures, such as counter such as ************************************************************** **************************************** / Function CheckimGurl ($ STR) {IF ($ this-> Checkurl ($ STR)) {IF (EREGI ("/. (JPEG | JPG | GIF | BMP | PNG | PCX | TIFF | TGA | LWF) $", $ STR) Else Return False;} else returnaf;

/ ************************************************** ************** * Automatic complement URL section, mainly the protocol prefix, * default is htpp: //, support https: //; ftp: //; Finger: //; Gopher: // Wait * Function does not check the legality of the URL ********************************************** ***************************************************************** / FUNCTION FORMATURL ($ Str) {if (! EREGI ("(ftp | http | https | mms | gopher | finger | bbs | telnet): (|)", $ STR)) $ STR = 'http: ///' $ str; RETURN $ STR;} // Take UBB coding for $ STR Function Parse ($ STR) {$ Nest ; $ PARSE = ''. ($ STR); $ RET = ''; while (true) {// Find [XX] or [XX = XX], but not included [xx =] $ EREGI_RET = EREGI ("/ [([AZ] [A-Z0-9] {0,7}) (= [A-Z0- 9 #.: / @ | /?,% = _ / / "/ '] )? /]" $ Parse, $ estree); if (! $ Estree_ret) {$ RET. = $ PARSE; BREAK If not, return} / * for debug else {printf ("$.% S
", $ EREGI_RET); Printf ("0.% s
", $ EREGI_ARR [0]); Printf ("1. % S
, $ EREGI_ARR [1]); Printf ("2.% S
", $ EREGI_ARR [2]); Printf ("3.% s
", $ EREGI_ARR [3]) } * / $ POS = @STRPOS ($ PARSE, $ EREGI_ARR [0]); // Start location $ tag_start = $ EREGI_ARR [1]; $ tag = strtolower ($ EREGI_ARR [1]); $ tag_param = $ EREGI_ARR [2];

$ PARSE2 = Substr ($ PARSE, 0, $ POS); // Tag ($ PARSE, $ POS $ EREGI_RET); // Mark IF ($ THIS-> Tags [$ TAG ]))) {// echo "$ TAG. @ 133: Not supported"; // for debug $ re. = $ Parse2. '['. $ Tag_start. ']'; Continue; // If Is not supported marking} // Find the corresponding end tag $ EREGI_RET = EREGI ("/[ (((@ tag.") /] ", $ PARSE, $ EREGI_ARR); if (! $ EREGI_RET) {//// Echo ('There is no end tag ". $ rrr); // for debug $ re. = $ parse2.' ['. $ tag_start. $ tag_param.'] '; continue; // No end tag } $ POS = STRPOS ($ PARSE, $ EREGI_ARR [0]); $ value = Substr ($ PARSE, 0, $ POS); // The content between the start tag $ TAG_END = $ EREGI_ARR [1]; $ PARSE = SubStr ($ PARSE, $ POS $ EREGI_RET); // End the content // allows nested tags, recursive analysis if (($ tag == "URL" OR ($ tag == "URL" ) or ($ tag == "email") OR ($ T AG == "IMG")))))) {$ value = $ this-> parse ($ value);} $ re. = $ parse2; $ parsefun = sprintf ('$ RET. =% s ($ Tag_Start, $ Tag_Param, $ TAG_END, $ Value); ', $ THIS-> Tags [$ TAG]); Eval ($ PARSEFUN);} $ Nest -; Return $ Ret;}

/ ************************************************** **** * Simple replacement, similar to [b] becomes * Tag content is inconvenient, just replacing braces <> ******************** *************************************** / Function Simple ($ Start, $ Para, $ End, $ VALUE) {IF ( Strlen ($ Para)> 0) Return Sprintf ("[% S% S]% S [% s]", $ start, $ para, $ value, $ end); Else Return Sprintf ("<% s>% s <% s>, $ start, $ value, $ end);} / ****************************************** ******************** * If you think is legal, you can not "http: //"; FTP must add "ftp: //" * [url = http : //www.fogsun.com] 93611 [/ url] * [URL = http://www.fogsun.com] [/ url] * [url] http://www.fogsun.com [/ url] * *********************************************************** ** / Function URL ($ START, $ Para, $ End, $ Value) {$ SA = $ VALUE; $ SURL = Substr (Trim ($ Para), 1); IF (Strlen ($ SURL)> 0) { IF (Strlen) == 0) $ sa = $ surl;} else {$ surl = trim ($ value);} $ surl = $ this-> formaturl ($ surl); if ($ this-> checkurl ($ SU RL)) RETURN " "; Else {Return Sprintf (" [% s% s]% s [% s] ", $ start, $ para, $ Value, $ END);}}

/ ************************************************** **** * If you think is legal, you can don't "Mailto:" Head; * [email=pazee@21cn.com] paze [/ email] * [email=pazee@21cn.com] [/ email] * [email] Pazee @ 21cn.com [/ email] *************************************************** *********** / Function Email ($ START, $ Para, $ End, $ Value) {$ SA = $ Value; $ SURL = Substr (Trim ($ Para), 1); IF Strlen ($ surl)> 0) {if (Strlen ($ value) == 0) $ sa = $ surl;} else {$ surl = trim ($ value);}} (SUBSTR ($ surl, 0, 7)))))! = "Mailto:") $ surl = "Mailto:" $ surl; if ($ this-> Emailcheck (Substr ($ surl, 7))) Return $ SA "; Else Return Sprintf (" [% S% S]% s [% s] ", $ start, $ para, $ value, $ end);} / ******* ********************************************** * display image; The following use is considered to be legal * [img = www.21cn.com / title.jpg] [/ IMG] * [img] www.21cn.com/title.jpg [/ img] ********** **************************** **************** ($ SURL = SUBSTR (Trim ($ Para), 1); IF (Strlen ($ surl) {$ surl = SUBSTR (TRLEN) <= 0) $ surl = trim ($ Value); $ surl = $ this-> formaturl; if ($ this-> checkimgurl) Return Sprintf (" ", $ surl); Else Return Sprintf ("[% S% S]% s [% s", $ start, $ para, $ value, $ end);

/ ************************************************** **** * Strings from right to left cycle mobile * No parameters * Equivalent and HTML *********************** ********************************************** / Function Fly ($ Start, $ Para, $ End, $ VALUE) {IF (Strlen ($ Para)> 0) // Parameter RETURN SPRINTF ("[% S% S]% s [% s]", $ start, $ para, $ value, $ end); else return ' '. $ Value.' ';} / ***************************************** ****************** * Strings to return to move * No parameters * Equivalent and HTML ************* ****************************************************************************** / FUNCTION MOVE ($ Start, $ Para, $ End, $ value) {IF (Strlen> 0) // Parameter RETURN SPRINTF ("[% S% S]% s [% s]", $ Start, $ Para, $ Value, $ END) Else Return ''. $ Value. '';}

/ ************************************************** **** * Character halo effects include Glow, Shadow and Blur * Character Slin Effects [Glow = A, B, C] or [Shadow = A, B, C] * 3 parameters allowed by default * Implement text shadow Special effects, * glow, shadow, blur attributes are colors, width and boundary size * Wave properties are deformed frequency, width and boundary size ***************************** ***************************************** / Function CSSStyle (& $ Start, & $ Para, & $ End, & $ Value) {$ RETS = Sprintf ("[% s% s]% s [% s", $ start, $ para, $ value, $ end); if (Strlen ($ para) == 0) {$ Para = "=,";} If (EREGI ("^ = ([#]? [[: Xdigit:] {6} | [A-Z0-9] *), ([0-9] *), ([0-9] *) ", $ Para, $ Er_arr)) {$ color = ($ Er_arr [1]! =")? $ Er_arr [1]: red; // default color $ width = ($ Er_arr [2]! = "")? $ Er_arr [2]: 400; // default width $ border = ($ Er_arr [3]! = ")? $ Er_arr [3]: 5; // Default Border Switch ($ start) {case "glow": Case "Shadow": $ RETS = Sprintf (" % S , $ START, $ COL OR, $ BORDER, $ Width, $ Value; Break; Case "blur"; $ RETS = Sprintf ("% s ", $ Start, $ Border, $ Color, $ Width, $ Value; Break; Case "Wave": $ color = ($ Er_arr [1]! = "")? $ Er_arr [1]: 4; // Default Color $ Border = ($ Er_arr [3]! = ")? $ Er_arr [3]: 2; // Default Border $ RETS = Sprintf ("

/ "Filter:% S (FREQ =% s, strongth =% s); Width:% s /">% s ", $ Start, $ Color, $ Border, $ Width, $ VALUE); Break }}} RETURN $ RETS;} / ************************************************** ************ * Font Color [color = n] xxx [/ color] * n can be #xxxxxx or xxxxxx (6-bit 16) * Red, GREED, Blue, Black, etc. Color retention word also valid * Equivalent and HTML xxx * [color] xxxx [/ color] is equivalent to [color = red] ********** *********************************************************** / Function Color ($ Start, $ S) PARA, $ END, $ VALUE) {$ CL = STRTOLOWER (Substr ($ Para, 1)); if ($ CL == ") $ cl =" red "; if (EREGI (" (^ [#]? [[: xdigit:] {6}) | Red | Green | Blue | Yellow | Blue | White | Gray | Brown ", $ CL)) Return Sprintf (" % s ", $ cl, $ value); Else Return Sprintf (" [% s% s]% s [% s ", $ start, $ para, $ value, $ end);}

/ ************************************************** **** * Font size [size = n] xxx [/ size] 1 <= n xxx ******* * ******* *************************************************************** / FUNCTION SIZE ($ Start, $ Para, $ End, $ VALUE) {$ SIZE = Substr ($ Para, 1); IF ($ SIZE> = 1 && $ SIZE <= 7 && (Strlen ($ Para)> 1)) Return Sprintf % s , $ size, $ value); Else Return Sprintf ("[% s% s]% s [% s", $ Start, $ Para, $ VALUE , $ END);}

/ ************************************************** **** * Font Name [FACE = N] n font name, no quotation marks * equivalent and HTML xxx ************* ****************************************************************************** / Function Face ($ Start, $ Para, $ End, $ value) {$ fn = substr ($ Para, 1); if (! EREGI ("[[: Punct:], $ fn) && strlen ($ para)> 1) {switchper ($ Fn)) {CASE "ST": $ fn = "Song"; Break; Case "HT": $ fn = "black body"; Break; Case "KT": $ fn = "_gb2312"; break; casse FT ": $ fn =" imitation Song _GB2312 "; Break; Case" YY ": $ fn =" young circle "; Break; Case" LS ": $ fn =" 书 "; Break;} Return Sprintf (" % s ", $ fn, $ value);} else Return Sprintf (" [% S% S]% s [] ", $ Start, $ Para, $ Value, $ END);} / ************************************************** ************ * Return to the version of the UBB interpreter and final modification date *********************************** ************************************ / Function GetubBVER (& $ SVER, & $ SLASTMOD) {$ Sver = SVERSION; $ SLASTMOD = $ THIS -> $ SLASTMODIFIED; RETURN $ SVER;}}

/ ************************************************** ************** 2001.12.31 The basic complete UBB label support function increases support for several tags, such as Face, Size, Color, etc. Increase the extension name of the image URL Check, support GIF, BMP, PCX, TIFF, PNG, JPG, JPEG, TGA, LWF files add functions of automatic full URL protocol part, support HTTP, FPT, GOPHER, FINGER, BBS, TELNET, etc. Allow // and // The equivalent, 2002.01.07 modified the display error of [Face =], increase the Chinese character abbreviation 2002.01.08 to improve the [glow] tag function, add the default value, allow the function to have a default increase [shadow] tag , Use methods and [glow], and allow superimposed effect 2002.01.09 to add [Wave] [BLUR] tag function, use method, and [glow] to be similar, and allow superposition effect 2002.01.15 to modify the regular expression matching characters Strings, because [URL = XXXX] may appear = _ "'and other characters, but use [URL] XXXXX [/ URL] There will be no problem, it did not take into account; formaturl added support for MMS protocol, now Media Player has a lot of format; increase version function, you can return to the version of the UBB interpreter and final modification date ************************************** *************************************************** /?>

/ n"); echo " UBB code test </ title> </ head> / n" (Echo "<body style = /" font-size: 9pt; font-family: Song / "> / n"; echo "<marquee scroll > UBB expression test page </ marquee> / n"; $ ubbcode = new ubbcode (); $ ubbcode-> getubver ($ Sver, $ SLASTMOD); Printf ("<br> / N version:% s <br> / N final revision date:% s <br>", $ SVER, $ SLASTMOD); Echo "<form action =". ($ PATH_INFO). "Method = Post> / N"; Echo "<textarea name = ubb style = /" width: 95%; Height: 140px / ">". Stripslashes ($ ubb). "</ textarea> <br> / n"; echo "<input type = submit value = conversion> / n"; echo "</ form> / n"; if (isset ($ ubb) ) {Echo "<hr> / n". $ Ubbcode-> parse (StripsLashes));} echo "</ body> / n"; echo "</ html> / n";?>>>>>>>> Everyone can test the effect at http://our93611.51.net/ubb/ubb.php</p> <p>At this time, http://our93611.51.net/ubb/ubbintro.htm</p> <p>By writing a rule, everyone can easily write new UBB functions that support flash, MID, WMA and so on.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-111913.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="111913" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.035</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'xmVAh71KopU8_2F0YktTdeJeNzK6aM7A8t_2F9bGKXAmjUoJNbq8FE_2Bfce4Rh4_2FSu7n1RdZOz5ImZJKy8dKrzFofkQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>