<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -0,0 +1,90 @@
+&lt;?php
+
+function help() {
+	echo &quot;Optimize a single image or a whole folder in the cloud.\n&quot;;
+	echo &quot;\n&quot;;
+	echo &quot;gif's:\n&quot;;
+	echo &quot;  - called with a folder gif`s will not be optimized\n&quot;;
+	echo &quot;  - called on a singe .gif, it will be optimized if it is optimizeable\n&quot;;
+	echo &quot;\n&quot;;
+	echo &quot;Usage:\n&quot;;
+	echo &quot;  php smusher.php /images [options]\n&quot;;
+	echo &quot;  php smusher.php /images/x.png [options]\n&quot;;
+	echo &quot;\n&quot;;
+	echo &quot;Options are:\n&quot;;
+	echo str_pad(&quot;  -q, --quiet&quot;, 26, &quot; &quot;) . &quot;no output\n&quot;;
+	echo str_pad(&quot;  -c, --convert-gifs&quot;, 26, &quot; &quot;) . &quot;convert all .gif's in the given folder\n&quot;;
+	echo str_pad(&quot;  -pc, --pretend&quot;, 26, &quot; &quot;) . &quot;no changes are made\n&quot;;
+	echo str_pad(&quot;  -r, --recursive&quot;, 26, &quot; &quot;) . &quot;execute the action on all subdirectories\n&quot;;
+	echo str_pad(&quot;  -h, --help&quot;, 26, &quot; &quot;) . &quot;show this\n&quot;;
+
+	exit;
+}
+
+if ($_SERVER['argc'] == 1)
+	help();
+
+require_once 'compiler.php';
+
+$options = array();
+$path = false;
+
+$arguments = array_splice($_SERVER['argv'], 1);
+
+foreach ($arguments as $arg) {
+	$is_option = preg_match('/^-/', $arg);
+
+	if ($is_option &amp;&amp; !$path)
+		help();
+
+	switch ($arg) {
+		case '--supress_warnings':
+		case '-nw':
+			$options[] = 'supress_warnings';
+			break;
+
+		case '--join':
+		case '-j':
+			$options[] = 'join';
+			break;
+
+		case '--quiet':
+		case '-q':
+			$options[] = 'quiet';
+			break;
+
+		case '--pretend':
+		case '-p':
+			$options[] = 'pretend';
+			break;
+
+		case '--recursive':
+		case '-r':
+			$options[] = 'recursive';
+			break;
+
+		default:
+			$exploded = explode('=', $arg);
+
+			if (count($exploded) == 2)
+				switch ($exploded[0]) {
+					case '--compilation_level':
+					case '-l':
+						$option['compilation_level'] = $exploded[1];
+						break;
+
+					default:
+						help();
+				}
+			else {
+				if ($is_option || $path)
+					help();
+
+				$path = $arg;
+			}
+	}
+}
+
+compiler::it($path, $options);
+
+?&gt;
\ No newline at end of file</diff>
      <filename>compile.php</filename>
    </modified>
    <modified>
      <diff>@@ -0,0 +1,156 @@
+&lt;?php
+
+Class compiler {
+
+	// google url to compile the code
+	const url = 'http://closure-compiler.appspot.com/compile';
+
+	/*
+	*/
+	static function it($path, $options = array()) {
+		$quiet = in_array('quiet', $options);
+		$pretend = in_array('pretend', $options);
+		$recursive = in_array('recursive', $options);
+		$join = in_array('join', $options);
+		$supress_warnings = in_array('supress_warnings', $options);
+		$compilation_level = in_array('compilation_level', $options) ? $options['compilation_level'] : 'SIMPLE_OPTIMIZATIONS';
+
+		// create the curl object
+		$curl = curl_init(self::url);
+
+		// set default options
+		curl_setopt_array($curl, array(
+			CURLOPT_RETURNTRANSFER =&gt; true,
+			CURLOPT_POST =&gt; true
+		));
+
+		// is the path is a folder, we get all javascript files on these folder
+		if (is_dir($path))
+			self::folder($curl, $path, $quiet, $pretend, $recursive, $join, $supress_warnings, $compilation_level);
+		else
+			self::file($curl, $path, $quiet, $pretend, $supress_warnings, $compilation_level);
+
+		// close curl to free memory
+		curl_close($curl);
+	}
+
+	/*
+	*/
+	private static function folder($curl, $path, $quiet, $pretend, $recursive, $join, $supress_warnings, $compilation_level) {
+		// loop through all files on the folder to get javascript files
+		$it = new DirectoryIterator($path);
+
+		foreach ($it as $file)
+			// ignore the dot file
+			if (!$file-&gt;isDot()) {
+				$path = $file-&gt;getPathname();
+
+				// if it's a folder, scan it too
+				if ($file-&gt;isDir()) {
+					if ($recursive)
+						self::folder($curl, $path, $quiet, $pretend, $recursive, $join, $supress_warnings, $compilation_level);
+				}
+				elseif (preg_match('/\.js$/i', $path)) {
+					self::file($curl, $path, $quiet, $pretend, $supress_warnings, $compilation_level);
+
+					if (!$quiet)
+						echo &quot;\n&quot;;
+				}
+			}
+	}
+
+	/*
+	*/
+	private static function file($curl, $path, $quiet, $pretend, $supress_warnings, $compilation_level) {
+		// check that the file exists
+		if (!file_exists($path))
+			throw new Exception('Invalid file path: ' . $path);
+		// check it is a valid field
+		elseif (preg_match('/\.js$/i', $path)) {
+			$code = file_get_contents($path);
+
+			$post_data = 'js_code=' . urlencode($code) . '&amp;compilation_level=' . $compilation_level . '&amp;output_format=json&amp;output_info=compiled_code&amp;output_info=warnings&amp;output_info=errors&amp;output_info=statistics&amp;warning_level=verbose';
+
+			curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
+
+			if (!$quiet)
+				echo &quot;  compiling &quot; . $path . &quot;\n&quot;;
+
+			// call the server app
+			$response = curl_exec($curl);
+
+			// if no response from the server
+			if ($response === false) {
+				if (!$quiet)
+					echo &quot;  error: the server has gone\n&quot;;
+			}
+			// server respond
+			else {
+				// remove conflict chars on json_decode
+				$response = preg_replace('/\t/', ' ', $response);
+
+				// decode the json response
+				$data = json_decode($response);
+
+
+				// if there is some error
+				if (!empty($data-&gt;serverErrors)) {
+					if (!$quiet)
+						echo &quot;  error: &quot; . strtolower($data-&gt;serverErrors[0]-&gt;error) . &quot;\n&quot;;
+				}
+				// look for errors on the file
+				elseif (!empty($data-&gt;errors)) {
+					if (!$quiet) {
+						echo &quot;  error: syntax error\n&quot;;
+
+						foreach ($data-&gt;errors as $error) {
+							echo &quot;    &quot; . strtolower($error-&gt;error) . &quot;, line &quot; . $error-&gt;lineno . &quot;, char &quot; . $error-&gt;charno . &quot;\n&quot;;
+
+							echo &quot;    &quot; . trim($error-&gt;line) . &quot;\n\n&quot;;
+						}
+					}
+				}
+				// look for errors on the file
+				elseif (!$supress_warnings &amp;&amp; !empty($data-&gt;warnings)) {
+					if (!$quiet) {
+						echo &quot;  error: syntax warning\n&quot;;
+
+						foreach ($data-&gt;warnings as $warning) {
+							echo &quot;    &quot; . strtolower($warning-&gt;warning) . &quot;, line &quot; . $warning-&gt;lineno . &quot;, char &quot; . $warning-&gt;charno . &quot;\n&quot;;
+
+							echo &quot;    &quot; . trim($warning-&gt;line) . &quot;\n\n&quot;;
+						}
+					}
+				}
+				// if optimized size is larget than the original
+				elseif ($data-&gt;statistics-&gt;originalSize &lt; $data-&gt;statistics-&gt;compressedSize) {
+					if (!$quiet)
+						echo &quot;  error: got larger\n&quot;;
+				}
+				// if size are equal
+				elseif ($data-&gt;statistics-&gt;originalSize == $data-&gt;statistics-&gt;compressedSize) {
+					if (!$quiet)
+						echo &quot;  cannot be optimized further&quot;;
+				}
+				else {
+					if (!$quiet)
+						echo str_pad(&quot;  &quot; . $data-&gt;statistics-&gt;originalSize . &quot; -&gt; &quot; . $data-&gt;statistics-&gt;compressedSize . &quot; (&quot; . $data-&gt;statistics-&gt;compressedGzipSize . &quot; gzip)&quot;, 26, &quot; &quot;) . &quot; = &quot; . round($data-&gt;statistics-&gt;compressedSize * 100 / $data-&gt;statistics-&gt;originalSize) . &quot;% (&quot; . round($data-&gt;statistics-&gt;compressedGzipSize * 100 / $data-&gt;statistics-&gt;originalSize) . &quot;% gzip)\n&quot;;
+
+					if ($pretend)
+						return true;
+
+					$content = $data-&gt;compiledCode;
+
+					return;
+					
+					return file_put_contents($path, $content);
+				}
+			}
+		}
+		elseif (!$quiet)
+			echo &quot;  error: invalid file &quot; . $path . &quot;\n&quot;;
+	}
+
+}
+
+?&gt;
\ No newline at end of file</diff>
      <filename>compiler.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>77feb7cbc4dcc20f4b83e8bd7c5238a9a168f567</id>
    </parent>
  </parents>
  <author>
    <name>Javier Martinez Fernandez</name>
    <email>ecentinela@gmail.com</email>
  </author>
  <url>http://github.com/ecentinela/compiler/commit/5d7030afa6dfe6f6c8a780841da142e7c3c6f956</url>
  <id>5d7030afa6dfe6f6c8a780841da142e7c3c6f956</id>
  <committed-date>2009-11-06T02:08:07-08:00</committed-date>
  <authored-date>2009-11-06T02:08:07-08:00</authored-date>
  <message>the compile part is done</message>
  <tree>a2f16d0ef9d5cef2b777760aa5a51c077ae4654b</tree>
  <committer>
    <name>Javier Martinez Fernandez</name>
    <email>ecentinela@gmail.com</email>
  </committer>
</commit>
