diff --git a/classes/class_text.php b/classes/class_text.php index 7ef19037..4908b1de 100644 --- a/classes/class_text.php +++ b/classes/class_text.php @@ -54,7 +54,7 @@ class TEXT { ); private $NoImg = 0; // If images should be turned into URLs - + private $Levels = 0; /** @@ -98,7 +98,7 @@ public function __construct ($TOC = false) { reset($this->Smileys); } - /** + /** * Output BBCode as XHTML * @param string $Str BBCode text * @param bool $OutputTOC Ouput TOC near (above) text @@ -434,9 +434,9 @@ private function parse ($Str) { case 'tex': $Array[$ArrayPos] = array('Type'=>'tex', 'Val'=>$Block); break; - case 'rule': - $Array[$ArrayPos] = array('Type'=>'rule', 'Val'=>$Block); - break; + case 'rule': + $Array[$ArrayPos] = array('Type'=>'rule', 'Val'=>$Block); + break; case 'pre': case 'code': case 'plain': @@ -529,10 +529,10 @@ public function parse_toc ($Min = 3) /** * Generates the list items and proper depth * - * First check if the item should be higher than the current level + * First check if the item should be higher than the current level * - Close the list and previous lists * - * Then check if the item should go lower than the current level + * Then check if the item should go lower than the current level * - If the list doesn't open on level one, use the Offset * - Open appropriate sub lists * @@ -584,7 +584,7 @@ private function to_html ($Array) { $Str.=''.$this->to_html($Block['Val']).""; break; case 's': - $Str.=''.$this->to_html($Block['Val']).''; + $Str.=''.$this->to_html($Block['Val']).''; break; case 'important': $Str.=''.$this->to_html($Block['Val']).''; @@ -595,13 +595,13 @@ private function to_html ($Array) { case 'artist': $Str.=''.$Block['Val'].''; break; - case 'rule': - $Rule = trim(strtolower($Block['Val'])); - if($Rule[0] != 'r' && $Rule[0] != 'h') { - $Rule = 'r'.$Rule; - } - $Str.=''.preg_replace('/[aA-zZ]/', '', $Block['Val']).''; - break; + case 'rule': + $Rule = trim(strtolower($Block['Val'])); + if($Rule[0] != 'r' && $Rule[0] != 'h') { + $Rule = 'r'.$Rule; + } + $Str.=''.preg_replace('/[aA-zZ]/', '', $Block['Val']).''; + break; case 'torrent': $Pattern = '/('.NONSSL_SITE_URL.'\/torrents\.php.*[\?&]id=)?(\d+)($|&|\#).*/i'; $Matches = array(); @@ -635,7 +635,7 @@ private function to_html ($Array) { $Str.=''.$Block['Val'].''; break; case 'list': - $Str .= '<'.$Block['ListType'].'>'; + $Str.='<'.$Block['ListType'].'>'; foreach($Block['Val'] as $Line) { $Str.='
  • '.$this->to_html($Line).'
  • '; @@ -686,13 +686,13 @@ private function to_html ($Array) { $this->InQuotes++; if(!empty($Block['Attr'])) { $Exploded = explode("|", $this->to_html($Block['Attr'])); - if(isset($Exploded[1]) && is_numeric($Exploded[1])) { + if(isset($Exploded[1]) && is_numeric($Exploded[1])) { $PostID = trim($Exploded[1]); - $Str.= ''.$Exploded[0].' wrote: '; + $Str.=''.$Exploded[0].' wrote: '; } else { - $Str.= ''.$Exploded[0].' wrote: '; - } + $Str.=''.$Exploded[0].' wrote: '; + } } $Str.='
    '.$this->to_html($Block['Val']).'
    '; $this->NoImg--; @@ -710,11 +710,11 @@ private function to_html ($Array) { $Str.=''; } else { - $Str .= 'Use of the [mature] tag requires a description. The correct format is as follows: [mature=description] ...content... [/mature], where "description" is a mandatory description of the post. Misleading descriptions will be penalized. For further information on our mature content policies, please refer to this wiki.'; + $Str.='Use of the [mature] tag requires a description. The correct format is as follows: [mature=description] ...content... [/mature], where "description" is a mandatory description of the post. Misleading descriptions will be penalized. For further information on our mature content policies, please refer to this wiki.'; } } else { - $Str .= 'Mature content has been blocked. You can choose to view mature content by editing your settings.'; + $Str.='Mature content has been blocked. You can choose to view mature content by editing your settings.'; } break; case 'img': diff --git a/classes/class_text2.php b/classes/class_text2.php index 2416cef2..fe1c53b4 100644 --- a/classes/class_text2.php +++ b/classes/class_text2.php @@ -49,17 +49,17 @@ class TEXT_2 { ':wtf:' => 'wtf.gif', ':wub:' => 'wub.gif', ); - + private $NoImg = 0; // If images should be turned into URLs private $Levels = 0; // If images should be turned into URLs - + function __construct() { foreach($this->Smileys as $Key=>$Val) { $this->Smileys[$Key] = ''; } reset($this->Smileys); } - + function full_format($Str) { $Str = display_str($Str); @@ -68,37 +68,37 @@ function full_format($Str) { $Str = preg_replace('/'.$URLPrefix.'\s+http/i', '$1http', $Str); $Str = preg_replace('/(?'?http', '=[inlineurl]http'=>'=http')); + $Str = strtr($Str, array('?[inlineurl]http'=>'?http', '=[inlineurl]http'=>'=http')); $callback = create_function('$matches', 'return str_replace("[inlineurl]","",$matches[0]);'); $Str = preg_replace_callback('/(?<=\[inlineurl\]|'.$URLPrefix.')(\S*\[inlineurl\]\S*)/m', $callback, $Str); $Str = preg_replace('/\=\=\=\=([^=].*)\=\=\=\=/i', '[inlinesize=3]$1[/inlinesize]', $Str); $Str = preg_replace('/\=\=\=([^=].*)\=\=\=/i', '[inlinesize=5]$1[/inlinesize]', $Str); $Str = preg_replace('/\=\=([^=].*)\=\=/i', '[inlinesize=7]$1[/inlinesize]', $Str); - + $Str = $this->parse($Str); - + $HTML = $this->to_html($Str); - + $HTML = nl2br($HTML); return $HTML; } - + function strip_bbcode($Str) { $Str = display_str($Str); - + //Inline links $Str = preg_replace('/(?parse($Str); - + $Str = $this->raw_text($Str); - + $Str = nl2br($Str); return $Str; } - - + + function valid_url($Str, $Extension = '', $Inline = false) { $Regex = '/^'; $Regex .= '(https?|ftps?|irc):\/\/'; // protocol @@ -123,10 +123,10 @@ function valid_url($Str, $Extension = '', $Inline = false) { $Regex .= '(#[a-z0-9\-_.,%\/\@[\]~&=:;()+*\^$!]*)?'; // #anchor $Regex .= '$/i'; - + return preg_match($Regex, $Str, $Matches); } - + function local_url($Str) { $URLInfo = parse_url($Str); if(!$URLInfo) { return false; } @@ -145,15 +145,15 @@ function local_url($Str) { } else { return false; } - + } - - + + /* How parsing works -Parsing takes $Str, breaks it into blocks, and builds it into $Array. +Parsing takes $Str, breaks it into blocks, and builds it into $Array. Blocks start at the beginning of $Str, when the parser encounters a [, and after a tag has been closed. -This is all done in a loop. +This is all done in a loop. EXPLANATION OF PARSER LOGIC @@ -173,14 +173,14 @@ function local_url($Str) { [quote=joe]I am a redneck!**[/quote] Me too! ***[/quote] - If we're at the position *, the first [/quote] tag is denoted by **. - However, our quote tag doesn't actually close there. We must perform - a loop which checks the number of opening [quote] tags, and make sure - they are all closed before we find our final [/quote] tag (***). + If we're at the position *, the first [/quote] tag is denoted by **. + However, our quote tag doesn't actually close there. We must perform + a loop which checks the number of opening [quote] tags, and make sure + they are all closed before we find our final [/quote] tag (***). - 5c) Get the contents between [open] and [/close] and call it the block. + 5c) Get the contents between [open] and [/close] and call it the block. In many cases, this will be parsed itself later on, in a new parse() call. - 5d) Move the pointer past the end of the [/close] tag. + 5d) Move the pointer past the end of the [/close] tag. 6) Depending on what type of tag we're dealing with, create an array with the attribute and block. In many cases, the block may be parsed here itself. Stick them in the $Array. 7) Increment array pointer, start again (past the end of the [/close] tag) @@ -194,7 +194,7 @@ function parse($Str) { while($i<$Len) { $Block = ''; - + // 1) Find and parse the next tag (regex) // [name=|[name]|[[wiki-link]] $IsTag = preg_match("/((\[[a-zA-Z*]{1,100})([=\]]))|(\[\[[^\n\"'\[\]]+\]\])/", $Str, $Tag, PREG_OFFSET_CAPTURE, $i); @@ -211,9 +211,9 @@ function parse($Str) { } elseif ($IsTag) { // 1b) If it's not a wiki link: $WikiLink = false; $TagName = strtolower(substr($Tag[2][0], 1)); - + $MaxAttribs = $this->ValidTags[$TagName]; - + // 1bi) check it against the $this->ValidTags array to see if it's actually a tag and not [bullshit] if(!isset($this->ValidTags[$TagName])) { $IsTag = 0; @@ -251,39 +251,39 @@ function parse($Str) { ++$ArrayPos; continue; } - + } - + // 2) If there aren't any tags left, write everything remaining to a block if(!$IsTag) { // No more tags $Array[$ArrayPos] = substr($Str, $i); break; } - + // 3) If the next tag isn't where the pointer is, write everything up to there to a text block. if($TagPos>$i) { $Array[$ArrayPos] = substr($Str, $i, $TagPos-$i); ++$ArrayPos; $i=$TagPos; } - + // 4) Move the pointer past the end of the tag $i=$TagPos+strlen($Tag[0][0])+$ExtraTagLen; - + // 5) Find out where the tag closes (beginning of [/tag]) - + // Unfortunately, BBCode doesn't have nice standards like xhtml // [*], [img=...], and http:// follow different formats // Thus, we have to handle these before we handle the majority of tags - - + + //5a) Different for different types of tag. Some tags don't close, others are weird like [*] if($TagName == 'img' && $HasAttrib) { //[img=...] $Block = ''; // Nothing inside this tag // Don't need to touch $i } elseif($TagName == 'inlineurl') { // We did a big replace early on to turn http:// into [inlineurl]http:// - + // Let's say the block can stop at a newline or a space $CloseTag = strcspn($Str, " \n\r", $i); if($CloseTag === false) { // block finishes with URL @@ -298,11 +298,11 @@ function parse($Str) { $URL = substr($URL, 0, -1); } $Block = $URL; // Get the URL - + // strcspn returns the number of characters after the offset $i, not after the beginning of the string // Therefore, we use += instead of the = everywhere else - $i += $CloseTag; // 5d) Move the pointer past the end of the [/close] tag. - } elseif($WikiLink == true || $TagName == 'n') { + $i += $CloseTag; // 5d) Move the pointer past the end of the [/close] tag. + } elseif($WikiLink == true || $TagName == 'n') { // Don't need to do anything - empty tag with no closing } elseif($TagName == '*') { // We're in a list. Find where it ends @@ -310,28 +310,28 @@ function parse($Str) { do { // Look for \n[*] $NewLine = strpos($Str, "\n", $NewLine+1); } while($NewLine!== false && substr($Str, $NewLine+1, 3) == '[*]'); - + $CloseTag = $NewLine; if($CloseTag === false) { // block finishes with list $CloseTag = $Len; } $Block = substr($Str, $i, $CloseTag-$i); // Get the list - $i = $CloseTag; // 5d) Move the pointer past the end of the [/close] tag. + $i = $CloseTag; // 5d) Move the pointer past the end of the [/close] tag. } else { //5b) If it's a normal tag, it may have versions of itself nested inside $CloseTag = $i-1; $InTagPos = $i-1; $NumInOpens = 0; $NumInCloses = -1; - + $InOpenRegex = '/\[('.$TagName.')'; if($MaxAttribs>0) { $InOpenRegex.="(=[^\n'\"\[\]]+)?"; } $InOpenRegex.='\]/i'; - - - // Every time we find an internal open tag of the same type, search for the next close tag + + + // Every time we find an internal open tag of the same type, search for the next close tag // (as the first close tag won't do - it's been opened again) do { $CloseTag = stripos($Str, '[/'.$TagName.']', $CloseTag+1); @@ -341,7 +341,7 @@ function parse($Str) { } else { $NumInCloses++; // Majority of cases } - + // Is there another open tag inside this one? $OpenTag = preg_match($InOpenRegex, $Str, $InTag, PREG_OFFSET_CAPTURE, $InTagPos+1); if(!$OpenTag || $InTag[0][1]>$CloseTag) { @@ -350,17 +350,17 @@ function parse($Str) { $InTagPos = $InTag[0][1]; $NumInOpens++; } - + } while($NumInOpens>$NumInCloses); - - + + // Find the internal block inside the tag $Block = substr($Str, $i, $CloseTag-$i); // 5c) Get the contents between [open] and [/close] and call it the block. - - $i = $CloseTag+strlen($TagName)+3; // 5d) Move the pointer past the end of the [/close] tag. - + + $i = $CloseTag+strlen($TagName)+3; // 5d) Move the pointer past the end of the [/close] tag. + } - + // 6) Depending on what type of tag we're dealing with, create an array with the attribute and block. switch($TagName) { case 'inlineurl': @@ -408,7 +408,7 @@ function parse($Str) { $Block = preg_replace('/\[inlinesize\=3\](.*?)\[\/inlinesize\]/i', '====$1====', $Block); $Block = preg_replace('/\[inlinesize\=5\](.*?)\[\/inlinesize\]/i', '===$1===', $Block); $Block = preg_replace('/\[inlinesize\=7\](.*?)\[\/inlinesize\]/i', '==$1==', $Block); - + $Array[$ArrayPos] = array('Type'=>$TagName, 'Val'=>$Block); break; case 'hide': @@ -427,27 +427,27 @@ function parse($Str) { default: if($WikiLink == true) { $Array[$ArrayPos] = array('Type'=>'wiki','Val'=>$TagName); - } else { - + } else { + // Basic tags, like [b] or [size=5] - + $Array[$ArrayPos] = array('Type'=>$TagName, 'Val'=>$this->parse($Block)); if(!empty($Attrib) && $MaxAttribs>0) { $Array[$ArrayPos]['Attr'] = strtolower($Attrib); } } } - + $ArrayPos++; // 7) Increment array pointer, start again (past the end of the [/close] tag) } return $Array; } - + function to_html($Array) { $this->Levels++; if($this->Levels>10) { return $Block['Val']; } // Hax prevention $Str = ''; - + foreach($Array as $Block) { if(is_string($Block)) { $Str.=$this->smileys($Block); @@ -488,9 +488,9 @@ function to_html($Array) { $Str.=''.$Block['Val'].''; break; case 'list': - $Str .= '