-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcolorfields.php
More file actions
32 lines (22 loc) · 813 Bytes
/
colorfields.php
File metadata and controls
32 lines (22 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
/**
* Colorfields plugin for Adminer.
*
* @link https://github.com/smuuf/adminer-colorfields
* @author Premysl Karbula, http://www.premyslkarbula.cz
*/
class AdminerColorfields {
public static $template = '%s<span style="margin-left: 1ex; vertical-align: middle; display: inline-block; width: 1em; height: 1em; border-radius: 50%%; background-color: %s;"></span>';
public function selectVal(&$val, $link, $field, $original) {
$trimmed = trim($val);
if (self::isHex($trimmed) || self::isRGBa($trimmed)) {
$val = sprintf(self::$template, $val, $trimmed);
}
}
private static function isHex($input) {
return preg_match("~^#?([0-9a-fA-F]{3}){1,2}$~", $input);
}
private static function isRGBa($input) {
return preg_match("~^rgba?\((\d+),(\d+),(\d+)(,(\d+))?\)$~", $input);
}
}