$str) { $string[$index] = self::strip_slashes($str); } } elseif (is_string($string)) { $string = stripslashes($string); } return $string; } /** * Array validator for empty values * @since 1.0.0 * @param array $array - array for checking * @param array $keys - array of keys that should be checked: [id, settings => [email => [name, subject, to]]] * @param string $prefix - internal parameter for building path of array keys * @throws Validate */ public static function validate_for_empty(array $array, array $keys, $prefix = '') { foreach ($keys as $key => $value) { if (is_array($value)) { $path = $prefix . "[$key]"; if (empty($array[$key])) { throw new Validate("Empty $path"); } self::validate_for_empty($array[$key], $value, $path); } else { if (is_string($key) && is_string($value)) { $path = $prefix . "[$key][$value]"; if (empty($array[$key][$value])) { throw new Validate("Empty $path"); } } else { $key = (string)$value; $path = $prefix . "[$key]"; if (empty($array[$key])) { throw new Validate("Empty $path"); } } } } } /** * Show exceptions only in debug mode * @since 1.0.0 * @param \Exception $e */ public static function handle_exception(\Exception $e) { if (defined('WP_DEBUG') && WP_DEBUG) { if (Router::instance()->is_ajax()) { (new Libs\Http\Response\Ajax()) ->set_message($e->getMessage()) ->set('trace', $e->__toString()) ->send(); } else { echo '
Exception: ' . $e->getMessage() . '' . PHP_EOL;
				var_dump($e);
				echo "
"; } } } /** * Convert hex color (#7fcc8d) to RGB array * @param $hex * @return array */ public static function hex2rgb($hex) { $hex = str_replace("#", '', $hex); if (strlen($hex) == 3) { $r = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1)); $g = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1)); $b = hexdec(substr($hex, 2, 1) . substr($hex, 2, 1)); } else { $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); } return [$r, $g, $b]; } /** * Determine whether color is dark * @param string $hex_color - color (#7fcc8d) * @return bool */ public static function is_dark_color($hex_color) { if ($hex_color == 'transparent') { return false; } $rgb = self::hex2rgb($hex_color); $brightness = (($rgb[0] * 299) + ($rgb[1] * 587) + ($rgb[2] * 114)) / 255000; // values range from 0 to 1 // anything greater than 0.5 should be bright enough for dark text return $brightness < 0.5; } }