Browse Source

Merge pull request #3180 from Automattic/fix/wpcom-errors

Fix errors for redefined functions
Jeff Ong 4 năm trước cách đây
mục cha
commit
852f66926e

+ 40 - 32
blank-canvas/inc/wpcom-colors-utils.php

@@ -74,49 +74,57 @@ function seedlet_define_color_annotations( $colors ) {
 }
 
 // These functions are borrowed from the colorline lib
-function hex_to_rgb( $hex ) {
-	return sscanf( $hex, '%02X%02X%02X' );
+if ( ! function_exists( 'hex_to_rgb' ) ) {
+	function hex_to_rgb( $hex ) {
+		return sscanf( $hex, '%02X%02X%02X' );
+	}
 }
 
 // RGB values: 0-255
 // LUM values: 0-1
-function rgb_to_lum( $rgb ) {
-	list( $r, $g, $b ) = $rgb;
-	return sqrt( 0.241 * $r * $r + 0.691 * $g * $g + 0.068 * $b * $b ) / 255;
+if ( ! function_exists( 'rgb_to_lum' ) ) {
+	function rgb_to_lum( $rgb ) {
+		list( $r, $g, $b ) = $rgb;
+		return sqrt( 0.241 * $r * $r + 0.691 * $g * $g + 0.068 * $b * $b ) / 255;
+	}
 }
 
 // RGB values:    0-255, 0-255, 0-255
 // HSV values:    0-360, 0-100, 0-100, 0-100
-function rgb_to_hsvl( $rgb ) {
-	$l                 = rgb_to_lum( $rgb );
-	list( $r, $g, $b ) = $rgb;
-	$r                 = $r / 255;
-	$g                 = $g / 255;
-	$b                 = $b / 255;
-	$max_rgb           = max( $r, $g, $b );
-	$min_rgb           = min( $r, $g, $b );
-	$chroma            = $max_rgb - $min_rgb;
-	$v                 = 100 * $max_rgb;
-	if ( 0 === (int) $chroma ) {
-		return array( 0, 0, $v, $l );
+if ( ! function_exists( 'rgb_to_hsvl' ) ) {
+	function rgb_to_hsvl( $rgb ) {
+		$l                 = rgb_to_lum( $rgb );
+		list( $r, $g, $b ) = $rgb;
+		$r                 = $r / 255;
+		$g                 = $g / 255;
+		$b                 = $b / 255;
+		$max_rgb           = max( $r, $g, $b );
+		$min_rgb           = min( $r, $g, $b );
+		$chroma            = $max_rgb - $min_rgb;
+		$v                 = 100 * $max_rgb;
+		if ( 0 === (int) $chroma ) {
+			return array( 0, 0, $v, $l );
+		}
+		$s = 100 * ( $chroma / $max_rgb );
+		if ( $r === $min_rgb ) {
+			$h = 3 - ( ( $g - $b ) / $chroma );
+		} elseif ( $b === $min_rgb ) {
+			$h = 1 - ( ( $r - $g ) / $chroma );
+		} else { // $g === $min_rgb
+			$h = 5 - ( ( $b - $r ) / $chroma );
+		}
+		$h = 60 * $h;
+		return array( $h, $s, $v, $l );
 	}
-	$s = 100 * ( $chroma / $max_rgb );
-	if ( $r === $min_rgb ) {
-		$h = 3 - ( ( $g - $b ) / $chroma );
-	} elseif ( $b === $min_rgb ) {
-		$h = 1 - ( ( $r - $g ) / $chroma );
-	} else { // $g === $min_rgb
-		$h = 5 - ( ( $b - $r ) / $chroma );
-	}
-	$h = 60 * $h;
-	return array( $h, $s, $v, $l );
 }
 
-function change_color_luminescence( $hex, $amount ) {
-	$hex_without_hash = substr( $hex, 1, strlen( $hex ) );
-	$rgb              = hex_to_rgb( $hex_without_hash );
-	$hsvl             = rgb_to_hsvl( $rgb );
-	return 'hsl( ' . $hsvl[0] . ',' . $hsvl[1] . '%,' . ( $hsvl[2] + $amount ) . '%)';
+if ( ! function_exists( 'change_color_luminescence' ) ) {
+	function change_color_luminescence( $hex, $amount ) {
+		$hex_without_hash = substr( $hex, 1, strlen( $hex ) );
+		$rgb              = hex_to_rgb( $hex_without_hash );
+		$hsvl             = rgb_to_hsvl( $rgb );
+		return 'hsl( ' . $hsvl[0] . ',' . $hsvl[1] . '%,' . ( $hsvl[2] + $amount ) . '%)';
+	}
 }
 
 /**

+ 40 - 32
seedlet/inc/wpcom-colors-utils.php

@@ -74,49 +74,57 @@ function seedlet_define_color_annotations( $colors ) {
 }
 
 // These functions are borrowed from the colorline lib
-function hex_to_rgb( $hex ) {
-	return sscanf( $hex, '%02X%02X%02X' );
+if ( ! function_exists( 'hex_to_rgb' ) ) {
+	function hex_to_rgb( $hex ) {
+		return sscanf( $hex, '%02X%02X%02X' );
+	}
 }
 
 // RGB values: 0-255
 // LUM values: 0-1
-function rgb_to_lum( $rgb ) {
-	list( $r, $g, $b ) = $rgb;
-	return sqrt( 0.241 * $r * $r + 0.691 * $g * $g + 0.068 * $b * $b ) / 255;
+if ( ! function_exists( 'rgb_to_lum' ) ) {
+	function rgb_to_lum( $rgb ) {
+		list( $r, $g, $b ) = $rgb;
+		return sqrt( 0.241 * $r * $r + 0.691 * $g * $g + 0.068 * $b * $b ) / 255;
+	}
 }
 
 // RGB values:    0-255, 0-255, 0-255
 // HSV values:    0-360, 0-100, 0-100, 0-100
-function rgb_to_hsvl( $rgb ) {
-	$l                 = rgb_to_lum( $rgb );
-	list( $r, $g, $b ) = $rgb;
-	$r                 = $r / 255;
-	$g                 = $g / 255;
-	$b                 = $b / 255;
-	$max_rgb           = max( $r, $g, $b );
-	$min_rgb           = min( $r, $g, $b );
-	$chroma            = $max_rgb - $min_rgb;
-	$v                 = 100 * $max_rgb;
-	if ( 0 === (int) $chroma ) {
-		return array( 0, 0, $v, $l );
+if ( ! function_exists( 'rgb_to_hsvl' ) ) {
+	function rgb_to_hsvl( $rgb ) {
+		$l                 = rgb_to_lum( $rgb );
+		list( $r, $g, $b ) = $rgb;
+		$r                 = $r / 255;
+		$g                 = $g / 255;
+		$b                 = $b / 255;
+		$max_rgb           = max( $r, $g, $b );
+		$min_rgb           = min( $r, $g, $b );
+		$chroma            = $max_rgb - $min_rgb;
+		$v                 = 100 * $max_rgb;
+		if ( 0 === (int) $chroma ) {
+			return array( 0, 0, $v, $l );
+		}
+		$s = 100 * ( $chroma / $max_rgb );
+		if ( $r === $min_rgb ) {
+			$h = 3 - ( ( $g - $b ) / $chroma );
+		} elseif ( $b === $min_rgb ) {
+			$h = 1 - ( ( $r - $g ) / $chroma );
+		} else { // $g === $min_rgb
+			$h = 5 - ( ( $b - $r ) / $chroma );
+		}
+		$h = 60 * $h;
+		return array( $h, $s, $v, $l );
 	}
-	$s = 100 * ( $chroma / $max_rgb );
-	if ( $r === $min_rgb ) {
-		$h = 3 - ( ( $g - $b ) / $chroma );
-	} elseif ( $b === $min_rgb ) {
-		$h = 1 - ( ( $r - $g ) / $chroma );
-	} else { // $g === $min_rgb
-		$h = 5 - ( ( $b - $r ) / $chroma );
-	}
-	$h = 60 * $h;
-	return array( $h, $s, $v, $l );
 }
 
-function change_color_luminescence( $hex, $amount ) {
-	$hex_without_hash = substr( $hex, 1, strlen( $hex ) );
-	$rgb              = hex_to_rgb( $hex_without_hash );
-	$hsvl             = rgb_to_hsvl( $rgb );
-	return 'hsl( ' . $hsvl[0] . ',' . $hsvl[1] . '%,' . ( $hsvl[2] + $amount ) . '%)';
+if ( ! function_exists( 'change_color_luminescence' ) ) {
+	function change_color_luminescence( $hex, $amount ) {
+		$hex_without_hash = substr( $hex, 1, strlen( $hex ) );
+		$rgb              = hex_to_rgb( $hex_without_hash );
+		$hsvl             = rgb_to_hsvl( $rgb );
+		return 'hsl( ' . $hsvl[0] . ',' . $hsvl[1] . '%,' . ( $hsvl[2] + $amount ) . '%)';
+	}
 }
 
 /**

+ 40 - 32
spearhead/inc/wpcom-colors-utils.php

@@ -74,49 +74,57 @@ function seedlet_define_color_annotations( $colors ) {
 }
 
 // These functions are borrowed from the colorline lib
-function hex_to_rgb( $hex ) {
-	return sscanf( $hex, '%02X%02X%02X' );
+if ( ! function_exists( 'hex_to_rgb' ) ) {
+	function hex_to_rgb( $hex ) {
+		return sscanf( $hex, '%02X%02X%02X' );
+	}
 }
 
 // RGB values: 0-255
 // LUM values: 0-1
-function rgb_to_lum( $rgb ) {
-	list( $r, $g, $b ) = $rgb;
-	return sqrt( 0.241 * $r * $r + 0.691 * $g * $g + 0.068 * $b * $b ) / 255;
+if ( ! function_exists( 'rgb_to_lum' ) ) {
+	function rgb_to_lum( $rgb ) {
+		list( $r, $g, $b ) = $rgb;
+		return sqrt( 0.241 * $r * $r + 0.691 * $g * $g + 0.068 * $b * $b ) / 255;
+	}
 }
 
 // RGB values:    0-255, 0-255, 0-255
 // HSV values:    0-360, 0-100, 0-100, 0-100
-function rgb_to_hsvl( $rgb ) {
-	$l                 = rgb_to_lum( $rgb );
-	list( $r, $g, $b ) = $rgb;
-	$r                 = $r / 255;
-	$g                 = $g / 255;
-	$b                 = $b / 255;
-	$max_rgb           = max( $r, $g, $b );
-	$min_rgb           = min( $r, $g, $b );
-	$chroma            = $max_rgb - $min_rgb;
-	$v                 = 100 * $max_rgb;
-	if ( 0 === (int) $chroma ) {
-		return array( 0, 0, $v, $l );
+if ( ! function_exists( 'rgb_to_hsvl' ) ) {
+	function rgb_to_hsvl( $rgb ) {
+		$l                 = rgb_to_lum( $rgb );
+		list( $r, $g, $b ) = $rgb;
+		$r                 = $r / 255;
+		$g                 = $g / 255;
+		$b                 = $b / 255;
+		$max_rgb           = max( $r, $g, $b );
+		$min_rgb           = min( $r, $g, $b );
+		$chroma            = $max_rgb - $min_rgb;
+		$v                 = 100 * $max_rgb;
+		if ( 0 === (int) $chroma ) {
+			return array( 0, 0, $v, $l );
+		}
+		$s = 100 * ( $chroma / $max_rgb );
+		if ( $r === $min_rgb ) {
+			$h = 3 - ( ( $g - $b ) / $chroma );
+		} elseif ( $b === $min_rgb ) {
+			$h = 1 - ( ( $r - $g ) / $chroma );
+		} else { // $g === $min_rgb
+			$h = 5 - ( ( $b - $r ) / $chroma );
+		}
+		$h = 60 * $h;
+		return array( $h, $s, $v, $l );
 	}
-	$s = 100 * ( $chroma / $max_rgb );
-	if ( $r === $min_rgb ) {
-		$h = 3 - ( ( $g - $b ) / $chroma );
-	} elseif ( $b === $min_rgb ) {
-		$h = 1 - ( ( $r - $g ) / $chroma );
-	} else { // $g === $min_rgb
-		$h = 5 - ( ( $b - $r ) / $chroma );
-	}
-	$h = 60 * $h;
-	return array( $h, $s, $v, $l );
 }
 
-function change_color_luminescence( $hex, $amount ) {
-	$hex_without_hash = substr( $hex, 1, strlen( $hex ) );
-	$rgb              = hex_to_rgb( $hex_without_hash );
-	$hsvl             = rgb_to_hsvl( $rgb );
-	return 'hsl( ' . $hsvl[0] . ',' . $hsvl[1] . '%,' . ( $hsvl[2] + $amount ) . '%)';
+if ( ! function_exists( 'change_color_luminescence' ) ) {
+	function change_color_luminescence( $hex, $amount ) {
+		$hex_without_hash = substr( $hex, 1, strlen( $hex ) );
+		$rgb              = hex_to_rgb( $hex_without_hash );
+		$hsvl             = rgb_to_hsvl( $rgb );
+		return 'hsl( ' . $hsvl[0] . ',' . $hsvl[1] . '%,' . ( $hsvl[2] + $amount ) . '%)';
+	}
 }
 
 /**

+ 42 - 34
varia/inc/color-utils.php

@@ -1,46 +1,54 @@
-<?php 
+<?php
 // These functions are borrowed from the colorline lib
-function hex_to_rgb( $hex ) {
-	return sscanf( $hex, '%02X%02X%02X' );
+if ( ! function_exists( 'hex_to_rgb' ) ) {
+	function hex_to_rgb( $hex ) {
+		return sscanf( $hex, '%02X%02X%02X' );
+	}
 }
 
 // RGB values: 0-255
 // LUM values: 0-1
-function rgb_to_lum( $rgb ) {
-	list( $r, $g, $b ) = $rgb;
-	return sqrt( 0.241 * $r * $r + 0.691 * $g * $g + 0.068 * $b * $b ) / 255;
+if ( ! function_exists( 'rgb_to_lum' ) ) {
+	function rgb_to_lum( $rgb ) {
+		list( $r, $g, $b ) = $rgb;
+		return sqrt( 0.241 * $r * $r + 0.691 * $g * $g + 0.068 * $b * $b ) / 255;
+	}
 }
 
 // RGB values:    0-255, 0-255, 0-255
 // HSV values:    0-360, 0-100, 0-100, 0-100
-function rgb_to_hsvl( $rgb ) {
-	$l                 = rgb_to_lum( $rgb );
-	list( $r, $g, $b ) = $rgb;
-	$r                 = $r / 255;
-	$g                 = $g / 255;
-	$b                 = $b / 255;
-	$max_rgb           = max( $r, $g, $b );
-	$min_rgb           = min( $r, $g, $b );
-	$chroma            = $max_rgb - $min_rgb;
-	$v                 = 100 * $max_rgb;
-	if ( 0 === (int) $chroma ) {
-		return array( 0, 0, $v, $l );
-	}
-	$s = 100 * ( $chroma / $max_rgb );
-	if ( $r === $min_rgb ) {
-		$h = 3 - ( ( $g - $b ) / $chroma );
-	} elseif ( $b === $min_rgb ) {
-		$h = 1 - ( ( $r - $g ) / $chroma );
-	} else { // $g === $min_rgb
-		$h = 5 - ( ( $b - $r ) / $chroma );
+if ( ! function_exists( 'rgb_to_hsvl' ) ) {
+	function rgb_to_hsvl( $rgb ) {
+		$l                 = rgb_to_lum( $rgb );
+		list( $r, $g, $b ) = $rgb;
+		$r                 = $r / 255;
+		$g                 = $g / 255;
+		$b                 = $b / 255;
+		$max_rgb           = max( $r, $g, $b );
+		$min_rgb           = min( $r, $g, $b );
+		$chroma            = $max_rgb - $min_rgb;
+		$v                 = 100 * $max_rgb;
+		if ( 0 === (int) $chroma ) {
+			return array( 0, 0, $v, $l );
+		}
+		$s = 100 * ( $chroma / $max_rgb );
+		if ( $r === $min_rgb ) {
+			$h = 3 - ( ( $g - $b ) / $chroma );
+		} elseif ( $b === $min_rgb ) {
+			$h = 1 - ( ( $r - $g ) / $chroma );
+		} else { // $g === $min_rgb
+			$h = 5 - ( ( $b - $r ) / $chroma );
+		}
+		$h = 60 * $h;
+		return array( $h, $s, $v, $l );
 	}
-	$h = 60 * $h;
-	return array( $h, $s, $v, $l );
 }
 
-function change_color_luminescence( $hex, $amount ) {
-	$hex_without_hash = substr( $hex, 1, strlen( $hex ) );
-	$rgb              = hex_to_rgb( $hex_without_hash );
-	$hsvl             = rgb_to_hsvl( $rgb );
-	return 'hsl( ' . $hsvl[0] . ',' . $hsvl[1] . '%,' . ( $hsvl[2] + $amount ) . '%)';
-}
+if ( ! function_exists( 'change_color_luminescence' ) ) {
+	function change_color_luminescence( $hex, $amount ) {
+		$hex_without_hash = substr( $hex, 1, strlen( $hex ) );
+		$rgb              = hex_to_rgb( $hex_without_hash );
+		$hsvl             = rgb_to_hsvl( $rgb );
+		return 'hsl( ' . $hsvl[0] . ',' . $hsvl[1] . '%,' . ( $hsvl[2] + $amount ) . '%)';
+	}
+}