Want more features on Pastebin? Sign Up, it's FREE!
Guest

Dynamic CSS Colorer

By: katiek on Dec 21st, 2011  |  syntax: PHP  |  size: 2.14 KB  |  views: 225  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Note: two files needed here, Args.php (http://pastebin.com/WvEasCnB) and ColorScheme.php (http://pastebin.com/JL7CpLNy)
  2.  
  3. // For inserting colors into a CSS file. For example,
  4. // format .css like this, using double hashes and codes
  5. // from the color scheme (like in
  6. // http://students.washington.edu/kuksenok/colors/ColorScheme.php?demo)
  7. // and then call this file with REQUEST colors set to the scheme
  8. // pointer, and the styles - to the .css file. The output will be well-formatted
  9. // CSS. The benefit is that all the styles work perfectly fine without this,
  10. // and many schemes can be easily applied.
  11. // eg: http://students.washington.edu/kuksenok/colors/ColorCSS.php?colors=billow&styles=CW.css
  12. //     http://students.washington.edu/kuksenok/colors/ColorCSS.php?colors=grorange&styles=CW.css
  13. //     http://students.washington.edu/kuksenok/colors/CW.css
  14. //
  15. // .option{
  16. //     display:none;
  17. //     /*border:solid 5px ##_5;*/
  18. //     position:absolute;
  19. //     /*background-color:##_5;*/
  20. // }
  21. // .sel{
  22. //     padding:2px;
  23. //     /*color:##P0;*/
  24. //     /*border:solid 1px ##_5;*/
  25. // }
  26.  
  27.  
  28.  
  29. $schemes = array();
  30. if ($handle = opendir('./')) {
  31.     while (false !== ($file = readdir($handle))) {
  32.         if (substr($file, -7) == ".scheme") {
  33.             $schemes[] = substr($file, 0, -7);
  34.         }
  35.     }
  36. }
  37. require_once("ColorScheme.php");
  38. require_once("Args.php");
  39. $dark = getearg("dark", array("f", "t"));
  40. $txtdef = getearg("colors", $schemes) . ".scheme";
  41. $css = getsarg("styles", null);
  42. echo "/* Using " . $txtdef . " color scheme */\n\n";
  43. $text = file_get_contents($css);
  44. $text = explode("/*", $text);
  45. $colors = new ColorScheme($txtdef, $dark == "t");
  46. foreach ($text as $line) {
  47.     $line = explode("*/", $line);
  48.     $pos = strpos($line[0], "##");
  49.     if ($pos === false && $pos + 3 < strlen($line[0])) {
  50.         if (count($line) > 1)
  51.             echo "/*" . $line[0] . "*/" . $line[1];
  52.         else
  53.             echo $line[0];
  54.     }else {
  55.         $which = $line[0][$pos + 2];
  56.         $shade = $line[0][$pos + 3];
  57.         echo substr($line[0], 0, $pos) . $colors->hex($which, $shade) . substr($line[0], $pos + 4) . $line[1];
  58.     }
  59. }
clone this paste RAW Paste Data