1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: namespace ManiaLib\Utils;
14:
15: 16: 17:
18: abstract class Formatting
19: {
20: 21: 22: 23: 24:
25: static function stripCodes($string, $codes)
26: {
27: if(preg_match('/[hlp]/iu', $codes))
28: $string = self::stripLinks($string);
29: if(preg_match('/[0-9a-f]/iu', $codes))
30: $string = self::stripColors($string);
31: return preg_replace('/(?<!\$)((?:\$\$)*)\$['.$codes.']/iu', '$1', $string);
32: }
33:
34: 35: 36:
37: static function stripWideFonts($string)
38: {
39: return self::stripTag($string, 'wos');
40: }
41:
42: 43: 44:
45: static function stripLinks($string)
46: {
47: return preg_replace('/(?<!\$)((?:\$\$)*)\$[hlp](?:\[.*?\]|\[.*?$)?(.*?)(?:\$[hlp]|(\$z)|$)/iu', '$1$2$3', $string);
48: }
49:
50: 51: 52:
53: static function stripColors($string)
54: {
55: return preg_replace('/(?<!\$)((?:\$\$)*)\$(?:g|[0-9a-f][^\$]{0,2})/iu', '$1', $string);
56: }
57:
58: 59: 60:
61: static function stripStyles($string)
62: {
63: $string = preg_replace('/(?<!\$)((?:\$\$)*)\$[^$0-9a-hlp]/iu', '$1', $string);
64: $string = self::stripLinks($string);
65: $string = self::stripColors($string);
66: return $string;
67: }
68:
69: static function contrastColors($string, $background)
70: {
71: $background = Color::StringToRgb24($background);
72: return preg_replace_callback('/(?<!\$)((?:\$\$)*)(\$[0-9a-f][^\$]{0,2})/iu',
73: function($matches) use ($background)
74: {
75: $color = Color::StringToRgb24($matches[2]);
76: $color = Color::Contrast($color, $background);
77: $color = Color::Rgb24ToRgb12($color);
78: $color = Color::Rgb12ToString($color);
79: return $matches[1].'$'.$color;
80: }, $string);
81: }
82: }
83:
84: ?>