1: <?php
2:
3: namespace Budabot\Core;
4:
5: use Exception;
6:
7: require_once 'SettingHandler.class.php';
8:
9: class ColorSettingHandler extends SettingHandler {
10:
11: public function __construct(DBRow $row) {
12: parent::__construct($row);
13: }
14:
15: 16: 17:
18: function displayValue() {
19: return $this->row->value . htmlspecialchars($this->row->value) . "</font>";
20: }
21:
22: 23: 24:
25: function getDescription() {
26: $msg = "For this setting you can set any Color in the HTML Hexadecimal Color Format.\n";
27: $msg .= "You can change it manually with the command: \n\n";
28: $msg .= "/tell <myname> settings save {$this->row->name} <i>HTML-Color</i>\n\n";
29: $msg .= "Or you can choose one of the following Colors\n\n";
30: $msg .= "Red: <font color='#ff0000'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #ff0000'>Save it</a>) \n";
31: $msg .= "White: <font color='#FFFFFF'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #FFFFFF'>Save it</a>) \n";
32: $msg .= "Grey: <font color='#808080'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #808080'>Save it</a>) \n";
33: $msg .= "Light Grey: <font color='#DDDDDD'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #DDDDDD'>Save it</a>) \n";
34: $msg .= "Dark Grey: <font color='#9CC6E7'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #9CC6E7'>Save it</a>) \n";
35: $msg .= "Black: <font color='#000000'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #000000'>Save it</a>) \n";
36: $msg .= "Yellow: <font color='#FFFF00'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #FFFF00'>Save it</a>) \n";
37: $msg .= "Blue: <font color='#8CB5FF'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #8CB5FF'>Save it</a>) \n";
38: $msg .= "Deep Sky Blue: <font color='#00BFFF'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #00BFFF'>Save it</a>) \n";
39: $msg .= "Green: <font color='#00DE42'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #00DE42'>Save it</a>) \n";
40: $msg .= "Orange: <font color='#FCA712'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #FCA712'>Save it</a>) \n";
41: $msg .= "Gold: <font color='#FFD700'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #FFD700'>Save it</a>) \n";
42: $msg .= "Deep Pink: <font color='#FF1493'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #FF1493'>Save it</a>) \n";
43: $msg .= "Violet: <font color='#EE82EE'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #EE82EE'>Save it</a>) \n";
44: $msg .= "Brown: <font color='#8B7355'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #8B7355'>Save it</a>) \n";
45: $msg .= "Cyan: <font color='#00FFFF'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #00FFFF'>Save it</a>) \n";
46: $msg .= "Navy Blue: <font color='#000080'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #000080'>Save it</a>) \n";
47: $msg .= "Dark Orange: <font color='#FF8C00'>Example Text</font> (<a href='chatcmd:///tell <myname> settings save {$this->row->name} #FF8C00'>Save it</a>) \n";
48: return $msg;
49: }
50:
51: 52: 53:
54: function save($newValue) {
55: if (preg_match("/^#([0-9a-f]{6})$/i", $newValue)) {
56: return "<font color='$newValue'>";
57: } else {
58: throw new Exception("<highlight>{$newValue}<end> is not a valid HTML-Color (example: <i>#FF33DD</i>).");
59: }
60: }
61: }
62: