Quellcode durchsuchen

Default Settings: Enhance swatch display on color values.

reliberate vor 9 Jahren
Ursprung
Commit
9947372fbc
2 geänderte Dateien mit 41 neuen und 9 gelöschten Zeilen
  1. 5 8
      core/default_settings/default_settings.php
  2. 36 1
      resources/functions.php

+ 5 - 8
core/default_settings/default_settings.php

@@ -427,16 +427,13 @@ else {
 			}
 			else {
 				if ($category == "theme" && substr_count($subcategory, "_color") > 0 && ($name == "text" || $name == 'array')) {
-					$border = (
-						substr_count(strtolower($row['default_setting_value']), '#fff') > 0 ||
-						substr_count(strtolower($row['default_setting_value']), '#ffffff') > 0 ||
-						substr_count(str_replace(' ','',strtolower($row['default_setting_value'])), '255,255,255,') > 0
-					) ? "border: 1px solid #ccc; padding: -1px;" : null;
-					echo "		<img src='data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' style='background: ".$row['default_setting_value']."; width: 15px; height: 15px; margin-right: 4px; vertical-align: middle; ".$border."'>";
+					echo "		<img src='data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' style='background: ".$row['default_setting_value']."; width: 15px; height: 15px; margin-right: 4px; vertical-align: middle; border: 1px solid ".(color_adjust($row['default_setting_value'], -0.18))."; padding: -1px;'>";
+					echo "<span style=\"font-family: 'Courier New'; line-height: 6pt;\">".htmlspecialchars($row['default_setting_value'])."</span>\n";
+				}
+				else {
+					echo "		".htmlspecialchars($row['default_setting_value'])."\n";
 				}
-				echo "		".htmlspecialchars($row['default_setting_value']);
 			}
-			echo "		&nbsp;\n";
 			echo "	</td>\n";
 			echo "	<td valign='top' class='".$row_style[$c]." tr_link_void' style='text-align: center;'>\n";
 			if (permission_exists('default_setting_edit')) {

+ 36 - 1
resources/functions.php

@@ -1173,7 +1173,42 @@ function number_pad($number,$n) {
 		}
 	}
 
-//function to lighten or darken a hexidecimal, rgb, or rgba color value by a percentage (requires functions rgb_to_hsl and hsl_to_rgb, also below)
+//function to get a color's luminence level -- dependencies: rgb_to_hsl()
+	if (!function_exists('get_color_luminence')) {
+		function get_color_luminence($color) {
+			//convert hex to rgb
+			if (substr_count($color, ',') == 0) {
+				$color = str_replace(' ', '', $color);
+				$color = str_replace('#', '', $color);
+				if (strlen($color) == 3) {
+					$r = hexdec(substr($color,0,1).substr($color,0,1));
+					$g = hexdec(substr($color,1,1).substr($color,1,1));
+					$b = hexdec(substr($color,2,1).substr($color,2,1));
+				}
+				else {
+					$r = hexdec(substr($color,0,2));
+					$g = hexdec(substr($color,2,2));
+					$b = hexdec(substr($color,4,2));
+				}
+				$color = $r.','.$g.','.$b;
+			}
+
+			//color to array, pop alpha
+			if (substr_count($color, ',') > 0) {
+				$color = str_replace(' ', '', $color);
+				$color = str_replace('rgb', '', $color);
+				$color = str_replace('a(', '', $color);
+				$color = str_replace(')', '', $color);
+				$color = explode(',', $color);
+				$hsl = rgb_to_hsl($color[0], $color[1], $color[2]);
+			}
+
+			//return luminence value
+			return (is_array($hsl) && is_numeric($hsl[2])) ? $hsl[2] : null;
+		}
+	}
+
+//function to lighten or darken a hexidecimal, rgb, or rgba color value by a percentage -- dependencies: rgb_to_hsl(), hsl_to_rgb()
 	if (!function_exists('color_adjust')) {
 		function color_adjust($color, $percent) {
 			/*