1<?php 2header('Content-Type:text/html; charset=utf-8'); 3require('class.csstidy.php'); 4require('lang.inc.php'); 5 6 7if (isset($_REQUEST['css_text']) && get_magic_quotes_gpc()) { 8 $_REQUEST['css_text'] = stripslashes($_REQUEST['css_text']); 9} 10 11function rmdirr($dirname,$oc=0) 12{ 13 // Sanity check 14 if (!file_exists($dirname)) { 15 return false; 16 } 17 // Simple delete for a file 18 if (is_file($dirname) && (time()-fileatime($dirname))>3600) { 19 return unlink($dirname); 20 } 21 // Loop through the folder 22 if(is_dir($dirname)) 23 { 24 $dir = dir($dirname); 25 while (false !== $entry = $dir->read()) { 26 // Skip pointers 27 if ($entry == '.' || $entry == '..') { 28 continue; 29 } 30 // Recurse 31 rmdirr("$dirname/$entry",$oc); 32 } 33 $dir->close(); 34 } 35 // Clean up 36 if ($oc==1) 37 { 38 return rmdir($dirname); 39 } 40} 41 42function options($options, $selected = null, $labelIsValue = false) 43{ 44 $html = ''; 45 46 settype($selected, 'array'); 47 settype($options, 'array'); 48 49 foreach ($options as $value=>$label) 50 { 51 if (is_array($label)) { 52 $value = $label[0]; 53 $label = $label[1]; 54 } 55 $label = htmlspecialchars($label, ENT_QUOTES, "utf-8"); 56 $value = $labelIsValue ? $label 57 : htmlspecialchars($value, ENT_QUOTES, "utf-8"); 58 59 $html .= '<option value="'.$value.'"'; 60 if (in_array($value, $selected)) { 61 $html .= ' selected="selected"'; 62 } 63 $html .= '>'.$label.'</option>'; 64 } 65 if (!$html) { 66 $html .= '<option value="0">---</option>'; 67 } 68 69 return $html; 70} 71 72$css = new csstidy(); 73if(isset($_REQUEST['custom']) && !empty($_REQUEST['custom'])) 74{ 75 setcookie ('custom_template', $_REQUEST['custom'], time()+360000); 76} 77rmdirr('temp'); 78 79if(isset($_REQUEST['case_properties'])) $css->set_cfg('case_properties',$_REQUEST['case_properties']); 80if(isset($_REQUEST['lowercase'])) $css->set_cfg('lowercase_s',true); 81if(!isset($_REQUEST['compress_c']) && isset($_REQUEST['post'])) $css->set_cfg('compress_colors',false); 82if(!isset($_REQUEST['compress_fw']) && isset($_REQUEST['post'])) $css->set_cfg('compress_font-weight',false); 83if(isset($_REQUEST['merge_selectors'])) $css->set_cfg('merge_selectors', $_REQUEST['merge_selectors']); 84if(isset($_REQUEST['optimise_shorthands'])) $css->set_cfg('optimise_shorthands',$_REQUEST['optimise_shorthands']); 85if(!isset($_REQUEST['rbs']) && isset($_REQUEST['post'])) $css->set_cfg('remove_bslash',false); 86if(isset($_REQUEST['preserve_css'])) $css->set_cfg('preserve_css',true); 87if(isset($_REQUEST['sort_sel'])) $css->set_cfg('sort_selectors',true); 88if(isset($_REQUEST['sort_de'])) $css->set_cfg('sort_properties',true); 89if(isset($_REQUEST['remove_last_sem'])) $css->set_cfg('remove_last_;',true); 90if(isset($_REQUEST['discard'])) $css->set_cfg('discard_invalid_properties',true); 91if(isset($_REQUEST['css_level'])) $css->set_cfg('css_level',$_REQUEST['css_level']); 92if(isset($_REQUEST['timestamp'])) $css->set_cfg('timestamp',true); 93 94?> 95<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 96 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 97<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 98 <head> 99 <title> 100 <?php echo $lang[$l][0]; echo $css->version; ?>) 101 </title> 102 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> 103 <link rel="stylesheet" href="cssparse.css" type="text/css" /> 104 <script type="text/javascript"> 105 function enable_disable_preserve() 106 { 107 var inputs = new Array('sort_sel', 'sort_de', 'optimise_shorthands', 'merge_selectors', 'none'); 108 var inputs_v = new Array( true, true, true, true, false); 109 for(var i = 0; i < inputs.length; i++) 110 { 111 if(document.getElementById('preserve_css').checked) { 112 document.getElementById(inputs[i]).disabled = inputs_v[i]; 113 } else { 114 document.getElementById(inputs[i]).disabled = !inputs_v[i]; 115 } 116 } 117 } 118 </script> 119 </head> 120 <body onload="enable_disable_preserve()"> 121 <div><h1 style="display:inline"> 122 <?php echo $lang[$l][1]; ?> 123 </h1> 124 <?php echo $lang[$l][2]; ?> <a 125 href="http://csstidy.sourceforge.net/">csstidy</a> <?php echo $css->version; ?>) 126 </div><p> 127 <?php echo $lang[$l][39]; ?>: <a hreflang="en" href="?lang=en">English</a> <a hreflang="de" href="?lang=de">Deutsch</a> <a hreflang="fr" href="?lang=fr">French</a> <a hreflang="zh" href="?lang=zh">Chinese</a></p> 128 <p><?php echo $lang[$l][4]; ?> 129 <?php echo $lang[$l][6]; ?> 130 </p> 131 132 <form method="post" action=""> 133 <div> 134 <fieldset id="field_input"> 135 <legend><?php echo $lang[$l][8]; ?></legend> <label for="css_text" 136 class="block"><?php echo $lang[$l][9]; ?></label><textarea id="css_text" name="css_text" rows="20" cols="35"><?php if(isset($_REQUEST['css_text'])) echo htmlspecialchars($_REQUEST['css_text']); ?></textarea> 137 <label for="url"><?php echo $lang[$l][10]; ?></label> <input type="text" 138 name="url" id="url" <?php if(isset($_REQUEST['url']) && 139 !empty($_REQUEST['url'])) echo 'value="'.$_REQUEST['url'].'"'; ?> 140 size="35" /><br /> 141 <input type="submit" value="<?php echo $lang[$l][35]; ?>" id="submit" /> 142 </fieldset> 143 <div id="rightcol"> 144 <fieldset id="code_layout"> 145 <legend><?php echo $lang[$l][11]; ?></legend> <label for="template" 146 class="block"><?php echo $lang[$l][12]; ?></label> <select 147 id="template" name="template" style="margin-bottom:1em;"> 148 <?php 149 $num = ($_REQUEST['template']) ? intval($_REQUEST['template']) : 1; 150 echo options(array(3 => $lang[$l][13], 2 => $lang[$l][14], 1 => $lang[$l][15], 0 => $lang[$l][16], 4 => $lang[$l][17]), $num); 151 ?> 152 </select><br /> 153 <label for="custom" class="block"> 154 <?php echo $lang[$l][18]; ?> </label> <textarea id="custom" 155 name="custom" cols="33" rows="4"><?php 156 if(isset($_REQUEST['custom']) && !empty($_REQUEST['custom'])) echo 157 htmlspecialchars($_REQUEST['custom']); 158 elseif(isset($_COOKIE['custom_template']) && 159 !empty($_COOKIE['custom_template'])) echo 160 htmlspecialchars($_COOKIE['custom_template']); 161 ?></textarea> 162 </fieldset> 163 <fieldset id="options"> 164 <legend><?php echo $lang[$l][19]; ?></legend> 165 166 <input onchange="enable_disable_preserve()" type="checkbox" name="preserve_css" id="preserve_css" 167 <?php if($css->get_cfg('preserve_css')) echo 'checked="checked"'; ?> /> 168 <label for="preserve_css" title="<?php echo $lang[$l][52]; ?>" class="help"><?php echo $lang[$l][51]; ?></label><br /> 169 170 171 <input type="checkbox" name="sort_sel" id="sort_sel" 172 <?php if($css->get_cfg('sort_selectors')) echo 'checked="checked"'; ?> /> 173 <label for="sort_sel" title="<?php echo $lang[$l][41]; ?>" class="help"><?php echo $lang[$l][20]; ?></label><br /> 174 175 176 <input type="checkbox" name="sort_de" id="sort_de" 177 <?php if($css->get_cfg('sort_properties')) echo 'checked="checked"'; ?> /> 178 <label for="sort_de"><?php echo $lang[$l][21]; ?></label><br /> 179 180 181 <label for="merge_selectors"><?php echo $lang[$l][22]; ?></label> 182 <select style="width:15em;" name="merge_selectors" id="merge_selectors"> 183 <?php echo options(array('0' => $lang[$l][47], '1' => $lang[$l][48], '2' => $lang[$l][49]), $css->get_cfg('merge_selectors')); ?> 184 </select><br /> 185 186 <label for="optimise_shorthands"><?php echo $lang[$l][23]; ?></label> 187 <select name="optimise_shorthands" id="optimise_shorthands"> 188 <?php echo options(array($lang[$l][54], $lang[$l][55], $lang[$l][56]), $css->get_cfg('optimise_shorthands')); ?> 189 </select><br /> 190 191 192 <input type="checkbox" name="compress_c" id="compress_c" 193 <?php if($css->get_cfg('compress_colors')) echo 'checked="checked"';?> /> 194 <label for="compress_c"><?php echo $lang[$l][24]; ?></label><br /> 195 196 197 <input type="checkbox" name="compress_fw" id="compress_fw" 198 <?php if($css->get_cfg('compress_font-weight')) echo 'checked="checked"';?> /> 199 <label for="compress_fw"><?php echo $lang[$l][45]; ?></label><br /> 200 201 202 <input type="checkbox" name="lowercase" id="lowercase" value="lowercase" 203 <?php if($css->get_cfg('lowercase_s')) echo 'checked="checked"'; ?> /> 204 <label title="<?php echo $lang[$l][30]; ?>" class="help" for="lowercase"><?php echo $lang[$l][25]; ?></label><br /> 205 206 207 <?php echo $lang[$l][26]; ?><br /> 208 <input type="radio" name="case_properties" id="none" value="0" 209 <?php if($css->get_cfg('case_properties') == 0) echo 'checked="checked"'; ?> /> 210 <label for="none"><?php echo $lang[$l][53]; ?></label> 211 <input type="radio" name="case_properties" id="lower_yes" value="1" 212 <?php if($css->get_cfg('case_properties') == 1) echo 'checked="checked"'; ?> /> 213 <label for="lower_yes"><?php echo $lang[$l][27]; ?></label> 214 <input type="radio" name="case_properties" id="upper_yes" value="2" 215 <?php if($css->get_cfg('case_properties') == 2) echo 'checked="checked"'; ?> /> 216 <label for="upper_yes"><?php echo $lang[$l][29]; ?></label><br /> 217 218 <input type="checkbox" name="rbs" id="rbs" 219 <?php if($css->get_cfg('remove_bslash')) echo 'checked="checked"'; ?> /> 220 <label for="rbs"><?php echo $lang[$l][31]; ?></label><br /> 221 222 223 <input type="checkbox" id="remove_last_sem" name="remove_last_sem" 224 <?php if($css->get_cfg('remove_last_;')) echo 'checked="checked"'; ?> /> 225 <label for="remove_last_sem"><?php echo $lang[$l][42]; ?></label><br /> 226 227 228 <input type="checkbox" id="discard" name="discard" 229 <?php if($css->get_cfg('discard_invalid_properties')) echo 'checked="checked"'; ?> /> 230 <label for="discard"><?php echo $lang[$l][43]; ?></label> 231 <select name="css_level"><?php echo options(array('CSS2.1','CSS2.0','CSS1.0'),$css->get_cfg('css_level'), true); ?></select><br /> 232 233 234 <input type="checkbox" id="timestamp" name="timestamp" 235 <?php if($css->get_cfg('timestamp')) echo 'checked="checked"'; ?> /> 236 <label for="timestamp"><?php echo $lang[$l][57]; ?></label><br /> 237 238 239 <input type="checkbox" name="file_output" id="file_output" value="file_output" 240 <?php if(isset($_REQUEST['file_output'])) echo 'checked="checked"'; ?> /> 241 <label class="help" title="<?php echo $lang[$l][34]; ?>" for="file_output"> 242 <strong><?php echo $lang[$l][33]; ?></strong> 243 </label><br /> 244 245 </fieldset> 246 <input type="hidden" name="post" /> 247 </div> 248 </div> 249 </form> 250 <?php 251 252 $file_ok = false; 253 $result = false; 254 255 $url = (isset($_REQUEST['url']) && !empty($_REQUEST['url'])) ? $_REQUEST['url'] : false; 256 257 if(isset($_REQUEST['template'])) 258 { 259 switch($_REQUEST['template']) 260 { 261 case 4: 262 if(isset($_REQUEST['custom']) && !empty($_REQUEST['custom'])) 263 { 264 $css->load_template($_REQUEST['custom'],false); 265 } 266 break; 267 268 case 3: 269 $css->load_template('highest_compression'); 270 break; 271 272 case 2: 273 $css->load_template('high_compression'); 274 break; 275 276 case 0: 277 $css->load_template('low_compression'); 278 break; 279 } 280 } 281 282 if($url) 283 { 284 if(substr($_REQUEST['url'],0,7) != 'http://') 285 { 286 $_REQUEST['url'] = 'http://'.$_REQUEST['url']; 287 } 288 $result = $css->parse_from_url($_REQUEST['url'],0); 289 } 290 elseif(isset($_REQUEST['css_text']) && strlen($_REQUEST['css_text'])>5) 291 { 292 $result = $css->parse($_REQUEST['css_text']); 293 } 294 295 if($result) 296 { 297 $ratio = $css->print->get_ratio(); 298 $diff = $css->print->get_diff(); 299 if(isset($_REQUEST['file_output'])) 300 { 301 $filename = md5(mt_rand().time().mt_rand()); 302 $handle = fopen('temp/'.$filename.'.css','w'); 303 if($handle) { 304 if(fwrite($handle,$css->print->plain())) 305 { 306 $file_ok = true; 307 } 308 } 309 fclose($handle); 310 } 311 if($ratio>0) $ratio = '<span style="color:green;">'.$ratio.'%</span> 312 ('.$diff.' Bytes)'; else $ratio = '<span 313 style="color:red;">'.$ratio.'%</span> ('.$diff.' Bytes)'; 314 if(count($css->log) > 0): ?> 315 <fieldset id="messages"><legend>Messages</legend> 316 <div><dl><?php 317 foreach($css->log as $line => $array) 318 { 319 echo '<dt>'.$line.'</dt>'; 320 for($i = 0; $i < count($array); $i++) 321 { 322 echo '<dd class="'.$array[$i]['t'].'">'.$array[$i]['m'].'</dd>'; 323 } 324 } 325 ?></dl></div> 326 </fieldset> 327 <?php endif; 328 echo '<fieldset><legend>'.$lang[$l][37].': '.$css->print->size('input').'KB, '.$lang[$l][38].':'.$css->print->size('output').'KB, '.$lang[$l][36].': '.$ratio; 329 if($file_ok) 330 { 331 echo ' - <a href="temp/'.$filename.'.css">Download</a>'; 332 } 333 echo '</legend>'; 334 echo '<pre><code>'; 335 echo $css->print->formatted(); 336 echo '</code></pre>'; 337 echo '</fieldset>'; 338 } 339 elseif(isset($_REQUEST['css_text']) || isset($_REQUEST['url'])) { 340 echo '<p class="important">'.$lang[$l][28].'</p>'; 341 } 342 ?> 343 <p style="text-align:center;font-size:0.8em;clear:both;"> 344 For bugs and suggestions feel free to <a 345 href="http://csstidy.sourceforge.net/contact.php">contact me</a>. 346 </p> 347 </body> 348</html>