<?php /**/ ?><?php
 
// Check if the server supports "application/xhtml+xml" and if so feed it as such.
 
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) {
  
header("Content-type: application/xhtml+xml; charset=ISO-8859-1");
  echo 
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">\n";
 } else {
  
header("Content-type: text/html; charset=ISO-8859-1");
  echo 
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">\n";
 }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta name="description" content="This is a CSS syntax highlighter I wrote." />
<meta name="keywords"    content="css highlighter, css highlighting, css, highlight, syntax, customize, colors, Agilo" />
<meta name="language"    content="en" />
<meta name="author"      content="Agilo" />
<meta name="contact"     content="agilo3@gmail.com" />
<link rel="home" title="Home" href="http://agilo.acjs.net/" />
<title>CSS Highlighter</title>
<style type="text/css">
/* <![CDATA[ */


 /* Selectors */
 .sel {
  color: #C60;
 }
 /* Opening brace */
 .brace_open {
  color: #C60;
 }
 /* Closing brace */
 .brace_close {
  color: #C60;
 }
 /* Attributes */
 .attr {
  color: #060;
  font-weight: bold;
 }
 /* Attribute Values */
 .val {
  color: #933;
 }
 /* Comments */
 .com {
  color: #009;
 }


/* ]]> */
</style>
</head>

<body>

<!-- This page is valid XHTML 1.0 Strict. -->

<div style="line-height:12px">
<?php
// CSS highlighting script (written in five and a half hours).
// This was made on January 1, 2006.
// Very basic, nothing fancy (some might consider it "newbie", hehe).
//
// This script requires proper CSS syntax in this (or similar) form:
//
//  ---
//
//    html body .div {
//     color: #FF0000; /* Set a nice color for the text. */
//     background: #000000 url("background-image.jpg") no-repeat;
//     margin: 2px;
//     /*
//      * This line is very great!
//      * I got it from a friend of mine. :)
//      * It will make it a bit prettier, too:
//      */
//     text-decoration: blink;
//    }
//    .div_two .div,
//    .div_two span {
//     margin-bottom: 50px;
//    }
//    strong, .div_two a, div_two a:link, div_two #txt {
//     color: #00FF00;
//     text-decoration: underline;
//    }
//
//  ---
//
//  Some things to note:
//   - one attribute per line, ending in a semi-colon.
//   - the use of multi-line comments (with an asterisk preceding each line).
//   - opening braces are placed after the selectors at the end of the line.
//   - closing braces are placed on new lines.
//   - Multiple selectors can be placed on seperate lines or in one line.
//  !! This script does NOT support one-liners!
//  !! Do NOT place comments before any content!
//  !! This script does only partially supports the "*" selector (at the
//     beginning of the line).
//
//
//
// One last note: This has been writen for my own personal use.
//                If you decide to use this script and it doesn't
//                work for your CSS; do not contact me about it!
//                I am not supporting this script for any other
//                purpose other than my own.


// Define "$file".
$file $_GET['file'];

//echo preg_replace("/^[a-zA-Z0-9]+.css$/", "", $file)."\n\n\n<br /><br />";

// Check if the file exists.
if (file_exists($file) && preg_match("/^[a-zA-Z0-9\/\-\_]+.css$/"$file)) {
 
// TODO: better fix for security risk.
 
$css = @file($file);

 
// Some basic HTML correction (for the sake of being proper XHTML).
 
$css preg_replace("/&/""amam1337"$css);
 
$css preg_replace("/</""ltlt1337"$css);
 
$css preg_replace("/>/""gtgt1337"$css);
 
 
 
// The array which holds the expressions to find.
 
$find = Array(
               
// Selectors and opening braces.
               // -----------------------------
               //
               // Starting from the beginning of the line: if the line starts
               // with  an  asterisk  (*)  but  is  directly  after  followed
               // by "[", " .", " #" or " html" and the line ends in either
               // an opening brace or comma (multiple selectors); set it to
               // be replaced.
               //
               // Reason for the check if they're followed by either of those
               // characters is to check if they are not just CSS wildcards.
               // Some examples selectors:
               //
               //  *[type="button"] {
               //  * .div {
               //  * #uniquediv {
               //  * html div {
               //
               
"/^(?<=(?!\s*(\/?)\*(?!\[| \.| \#| html)\s*))(.*)(\{|\,) *$/",
 
               
// Closing braces.
               // ---------------
               //
               // Starting from the beginning of the line: even if there are
               // any whitespaces preceding the closing brace (but no other
               // characters); set it to be replaced.
               //
               
"/^(\s*)\}/",
 
               
// Attributes.
               // -----------
               //
               // Starting from the beginning of the line: check to see if
               // the line starts with "/*" or "*" (the start or broke-up 
               // comment-blocks in CSS), then look for the first-matching
               // colon which is not enclosed in HTML tags (since we have
               // to watch out for the already replaced expressions which
               // may contain it).
               //
               // Notes: This expression took me the longest to perfect.
               //        All I can say is: 
               //        THANK GOD FOR "PCRE_UNGREEDY" ("/U")!!!!
               //        That was a real life-saver. :')
               //
               
"/^(?<=(?!\s*(\/?)\*\s*))(.*)(?<=(?!<.*):(?!.*?>))/U",
 
               
// Values.
               // -------
               //
               // Look for a "</span>" (the ending span from the already
               // replaced attribute) and the first-matching semi-colon and
               // set everything in between to be replaced.
               //
               
"/<\/span>(.*);/U",
 
               
// Comments.
               // ---------
               //
               // Look for "/*", "*" or "*/" with anything after that except
               // for "html", "." or "#" (for the same reason as used in the
               // expression for the selectors).
               //
               
"/(?=(?>(\/?)\*(\/?)\s(?!html|\.|\#)))(.*)/",
 
               
// Miscellaneous.
               // --------------
               //
               // These few expressions are just used to beautify the output
               // and will create a whitespace-preserved output of the CSS.
               //
               
"/(?<=(?!span) (?!class))/",
               
"/\t/",
               
"/ &nbsp;/",
               
"/\n/");

 
// This is the HTML which replace the previous expressions with.
 
$repl = Array("<span class=\"sel\">$2</span><span class=\"brace_open\">$3</span>",
               
"<span class=\"brace_close\">$1}</span>",
               
"<span class=\"attr\">$2</span>",
               
"</span><span class=\"val\">$1</span><span class=\"attr\">;</span>",
               
"<span class=\"com\">$3</span>",
               
"&nbsp;",
               
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",
               
"&nbsp;",
               
"<br />\n");

 
// Here we actually make the replacements. 
 
$css preg_replace($find$repl$css);

 
// continue replacements.
 
$css preg_replace("/amam1337/""&amp;"$css);
 
$css preg_replace("/ltlt1337/""&lt;"$css);
 
$css preg_replace("/gtgt1337/""&gt;"$css);
 
 
// Echo our CSS! :-) 
 
echo "<code>\n";
 for (
$i=0$i<count($css); $i++) echo $css[$i];
 echo 
"</code>\n";
} else {
 
// Oh my god, an error. :-(
 
echo "<strong>Error:</strong> No (or wrong) file selected!".
      
" <small>(file must plain-text and end in .css)</small>\n";
}

?></div>


</body>
</html>