~thomas-juberg/bebot/main

« back to all changes in this revision

Viewing changes to Main/15_Colors.php

  • Committer: GitHub
  • Author(s): Thomas Juberg
  • Date: 2020-08-10 10:54:53 UTC
  • mfrom: (297.1.7)
  • Revision ID: git-v1:7e6d9efe4491bec5329d83a54d57e09c07571b55
Merge pull request #4 from bitnykk/master

Show diffs side-by-side

added added

removed removed

Lines of Context:
525
525
        if (strpos($text, "##") === false) {
526
526
            return $text;
527
527
        }
528
 
        // Go ahead and replace all tags
529
 
        foreach ($this->color_tags as $tag => $font) {
530
 
            $text = str_ireplace($tag, $font, $text);
531
 
        }
532
 
        return $text;
 
528
        // Go ahead and replace all tags
 
529
        $maxpass = 3; // Increase for more sublevels only if needed
 
530
        $stop = "##end##";
 
531
        $trig = "(?:(?!#{2}).)+";
 
532
        for($i=1;$i<$maxpass+1;$i++) {
 
533
                foreach ($this -> color_tags as $tag => $font) {
 
534
                        if ($tag != $stop) {
 
535
                                while (preg_match("/(".$tag.$trig.$stop.")/i", $text, $match, PREG_OFFSET_CAPTURE)) {
 
536
                                          $prev = substr($text, 0, $match[1][1]);
 
537
                                          $repl = preg_replace("/".$tag."/i", $font, $match[1][0], 1);
 
538
                                          $repl = preg_replace("/".$stop."/i", "</font>", $repl, 1);
 
539
                                          $post = substr($text, $match[1][1] + strlen($match[1][0]));
 
540
                                          $text = $prev.$repl.$post;
 
541
                                }
 
542
                        }
 
543
                }
 
544
        }
 
545
        $text = preg_replace("/##[^#]+##/i", "", $text);
 
546
        return $text;
533
547
    }
534
548
 
535
549