diff --git a/classes/class_text.php b/classes/class_text.php index 9b0eb5cb..2597beaa 100644 --- a/classes/class_text.php +++ b/classes/class_text.php @@ -56,12 +56,30 @@ class TEXT { private $NoImg = 0; // If images should be turned into URLs private $Levels = 0; + + /** + * The maximum amount of nesting allowed (exclusive) + * In reality n-1 nests are shown. + * @var int $MaximumNests + */ + private $MaximumNests = 10; /** * Used to detect and disable parsing (e.g. TOC) within quotes * @var int $InQuotes */ private $InQuotes = 0; + + /** + * Used to [hide] quote trains starting with the specified depth (inclusive) + * @var int $NestsBeforeHide + * + * This defaulted to 5 but was raised to 10 to effectively "disable" it until + * an optimal number of nested [quote] tags is chosen. The variable $MaximumNests + * effectively overrides this variable, if $MaximumNests is less than the value + * of $NestsBeforeHide. + */ + private $NestsBeforeHide = 10; /** * Array of headlines for Table Of Contents (TOC) @@ -504,8 +522,7 @@ private function parse ($Str) { * Generates a navigation list for TOC * @param int $Min Minimum number of headlines required for a TOC list */ - public function parse_toc ($Min = 3) - { + public function parse_toc ($Min = 3) { if (count($this->Headlines) > $Min) { $list = '
', $diff); @@ -569,17 +585,30 @@ private function headline_level (&$ItemLevel, &$Level, &$List, $i, &$Offset) private function to_html ($Array) { global $SSL; $this->Levels++; - if ($this->Levels > 10) { - return $Block['Val']; - } // Hax prevention + /* + * Hax prevention + * That's the original comment on this. + * Most likely this was implemented to avoid anyone nesting enough + * elements to reach PHP's memory limit as nested elements are + * solved recursively. + * Original value of 10, it is now replaced in favor of + * $MaximumNests. + * If this line is ever executed then something is, infact + * being haxed as the if before the block type switch for different + * tags should always be limiting ahead of this line. + * (Larger than vs. smaller than.) + */ + if ($this->Levels > $this->MaximumNests) { + return $Block['Val']; // Hax prevention, breaks upon exceeding nests. + } $Str = ''; - foreach ($Array as $Block) { if (is_string($Block)) { $Str.=$this->smileys($Block); continue; } - switch($Block['Type']) { + if ($this->Levels < $this->MaximumNests) { + switch ($Block['Type']) { case 'b': $Str.=''.$this->to_html($Block['Val']).''; break; @@ -692,17 +721,24 @@ private function to_html ($Array) { case 'quote': $this->NoImg++; // No images inside quote tags $this->InQuotes++; + if ($this->InQuotes == $this->NestsBeforeHide) { //Put quotes that are nested beyond the specified limit in [hide] tags. + $Str.='Older quotes: Show'; + $Str.=''; + } 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.=''.$this->to_html($Block['Val']).''; + if($this->InQuotes == $this->NestsBeforeHide) { //Close quote the deeply nested quote [hide]. + $Str.='