function hex2hsl($hex) { //Validate Hex Input $hex = validate_hex($hex); // Split input by color $hex = str_split($hex, 2); // Convert color values to value between 0 and 1 $r = hexdec($hex[0]) / 255; $g = hexdec($hex[1]) / 255; $b = hexdec($hex[2]) / 255; return rgb2hsl(array($r, $g, $b)); }
function getStylesheet($base = 'eeeeee', $accent = '00a836', $link = '0077dd') { $base = validate_hex($base); $accent = validate_hex($accent); $link = validate_hex($link); // If it's already there, return the filepath if (stylesheetIsValid($base, $accent, $link)) { return 'assets/css/shopkit.' . $base . '.' . $accent . '.' . $link . '.css'; } $defaultPath = kirby()->roots()->index() . '/assets/css/shopkit.css'; $newPath = kirby()->roots()->index() . '/assets/css/shopkit.' . $base . '.' . $accent . '.' . $link . '.css'; // Copy the default CSS file to the new path copy($defaultPath, $newPath); // Find and replace hex codes $colours = customColours($base, $accent, $link); $file_contents = file_get_contents($newPath); $file_contents = str_replace(array_keys($colours), array_values($colours), $file_contents); file_put_contents($newPath, $file_contents); // Spit out the filepath return 'assets/css/shopkit.' . $base . '.' . $accent . '.' . $link . '.css'; }