diff --git a/class.csstidy.php b/class.csstidy.php index 8cfd7e6..7c456f8 100644 --- a/class.csstidy.php +++ b/class.csstidy.php @@ -260,9 +260,9 @@ function csstidy() { $this->settings['compress_font-weight'] = true; $this->settings['lowercase_s'] = false; /* - 1 common shorthands optimization - 2 + font property optimization - 3 + background property optimization + 1 common shorthands optimization + 2 + font property optimization + 3 + background property optimization */ $this->settings['optimise_shorthands'] = 1; $this->settings['remove_last_;'] = true; @@ -273,9 +273,9 @@ function csstidy() { */ $this->settings['sort_properties'] = false; /* - 1, 3, 5, etc -- enable sorting selectors inside @media: a{}b{}c{} - 2, 5, 8, etc -- enable sorting selectors inside one CSS declaration: a,b,c{} - preserve order by default cause it can break functionnality + 1, 3, 5, etc -- enable sorting selectors inside @media: a{}b{}c{} + 2, 5, 8, etc -- enable sorting selectors inside one CSS declaration: a,b,c{} + preserve order by default cause it can break functionnality */ $this->settings['sort_selectors'] = 0; /* is dangeroues to be used: CSS is broken sometimes */ @@ -354,7 +354,7 @@ function set_cfg($setting, $value=null) { $this->_load_template($this->settings['template']); } return true; - } else if (isset($this->settings[$setting]) && $value !== '') { + } elseif (isset($this->settings[$setting]) && $value !== '') { $this->settings[$setting] = $value; if ($setting === 'template') { $this->_load_template($this->settings['template']); @@ -609,7 +609,7 @@ function parse($string) { foreach ($at_rules as $name => $type) { if (!strcasecmp(substr($string, $i + 1, strlen($name)), $name)) { ($type === 'at') ? $this->at = '@' . $name : $this->selector = '@' . $name; - if ($type === "atis"){ + if ($type === "atis") { $this->next_selector_at = ($this->next_selector_at?$this->next_selector_at:($this->at?$this->at:DEFAULT_AT)); $this->at = $this->css_new_media_section(' '); $type = "is"; @@ -641,13 +641,13 @@ function parse($string) { } elseif ($this->invalid_at && $string{$i} === ';') { $this->invalid_at = false; $this->status = 'is'; - if($this->next_selector_at){ + if ($this->next_selector_at) { $this->at = $this->css_new_media_section($this->next_selector_at); $this->next_selector_at = ''; } } elseif ($string{$i} === '{') { $this->status = 'ip'; - if($this->at == '') { + if ($this->at == '') { $this->at = $this->css_new_media_section(DEFAULT_AT); } $this->selector = $this->css_new_selector($this->at,$this->selector); @@ -696,7 +696,7 @@ function parse($string) { $this->_add_token(SEL_END, $this->selector); $this->selector = ''; $this->property = ''; - if($this->next_selector_at){ + if ($this->next_selector_at) { $this->at = $this->css_new_media_section($this->next_selector_at); $this->next_selector_at = ''; } @@ -708,11 +708,10 @@ function parse($string) { // else this is dumb IE a hack, keep it // including // elseif (($this->property=='' AND !ctype_space($string{$i})) - OR ($this->property=='/' OR $string{$i}=="/")) { + OR ($this->property=='/' OR $string{$i}=="/")) { $this->property .= $string{$i}; } - } - elseif (!ctype_space($string{$i})) { + } elseif (!ctype_space($string{$i})) { $this->property .= $string{$i}; } break; @@ -762,7 +761,7 @@ function parse($string) { $this->sub_value .= $string{$i}; } if (($string{$i} === '}' || $string{$i} === ';' || $pn) && !empty($this->selector)) { - if($this->at == ''){ + if ($this->at == '') { $this->at = $this->css_new_media_section(DEFAULT_AT); } @@ -779,9 +778,9 @@ function parse($string) { } $this->value = ''; - while(count($this->sub_value_arr)){ + while (count($this->sub_value_arr)) { $sub = array_shift($this->sub_value_arr); - if (strstr($this->selector, "font-face")){ + if (strstr($this->selector, "font-face")) { $sub = $this->quote_font_format($sub); } @@ -815,7 +814,7 @@ function parse($string) { $this->status = 'is'; $this->invalid_at = false; $this->selector = ''; - if($this->next_selector_at){ + if ($this->next_selector_at) { $this->at = $this->css_new_media_section($this->next_selector_at); $this->next_selector_at = ''; } @@ -840,7 +839,7 @@ function parse($string) { $_quoted_string = $this->quoted_string[count($this->quoted_string)-1]; $temp_add = $string{$i}; - // Add another string to the stack. Strings can't be nested inside of quotes, only parentheses, but + // Add another string to the stack. Strings can't be nested inside of quotes, only parentheses, but // parentheticals can be nested more than once. if ($_str_char === ")" && ($string{$i} === "(" || $string{$i} === '"' || $string{$i} === '\'') && !csstidy::escaped($string, $i)) { $this->cur_string[] = $string{$i}; @@ -887,7 +886,7 @@ function parse($string) { } if ($this->status === 'iv') { - if (!$_quoted_string){ + if (!$_quoted_string) { if (strpos($_cur_string,',')!==false) // we can on only remove space next to ',' $_cur_string = implode(',',array_map('trim',explode(',',$_cur_string))); @@ -901,8 +900,7 @@ function parse($string) { } elseif ($this->status === 'instr') { $this->cur_string[count($this->cur_string)-1] .= $_cur_string; } - } - else { + } else { $this->cur_string[count($this->cur_string)-1] = $_cur_string; } break; @@ -937,15 +935,14 @@ function parse($string) { * @param $value * @return string */ - function quote_font_format($value){ + function quote_font_format($value) { if (strncmp($value,'format',6)==0) { $p = strrpos($value,")"); $end = substr($value,$p); $format_strings = csstidy::parse_string_list(substr($value, 7, $p-7)); if (!$format_strings) { $value = ""; - } - else { + } else { $value = "format("; foreach ($format_strings as $format_string) { @@ -1035,19 +1032,19 @@ function css_add_property($media, $selector, $property, $new_val) { * @param string $media * @return string */ - function css_new_media_section($media){ - if($this->get_cfg('preserve_css')) { + function css_new_media_section($media) { + if ($this->get_cfg('preserve_css')) { return $media; } // if the last @media is the same as this // keep it - if (!$this->css OR !is_array($this->css) OR empty($this->css)){ + if (!$this->css OR !is_array($this->css) OR empty($this->css)) { return $media; } end($this->css); list($at,) = each($this->css); - if ($at == $media){ + if ($at == $media) { return $media; } while (isset($this->css[$media])) @@ -1071,12 +1068,12 @@ function css_new_media_section($media){ * @param string $selector * @return string */ - function css_new_selector($media,$selector){ - if($this->get_cfg('preserve_css')) { + function css_new_selector($media,$selector) { + if ($this->get_cfg('preserve_css')) { return $selector; } $selector = trim($selector); - if (strncmp($selector,"@font-face",10)!=0){ + if (strncmp($selector,"@font-face",10)!=0) { if ($this->settings['merge_selectors'] != false) return $selector; @@ -1086,7 +1083,7 @@ function css_new_selector($media,$selector){ // if last is the same, keep it end($this->css[$media]); list($sel,) = each($this->css[$media]); - if ($sel == $selector){ + if ($sel == $selector) { return $selector; } } @@ -1106,8 +1103,8 @@ function css_new_selector($media,$selector){ * @param string $property * @return string */ - function css_new_property($media, $selector, $property){ - if($this->get_cfg('preserve_css')) { + function css_new_property($media, $selector, $property) { + if ($this->get_cfg('preserve_css')) { return $property; } if (!$this->css OR !isset($this->css[$media][$selector]) OR !$this->css[$media][$selector]) @@ -1143,7 +1140,7 @@ function merge_css_blocks($media, $selector, $css_add) { static function is_important(&$value) { return ( strpos($value,"!")!==false // quick test - AND !strcasecmp(substr(str_replace($GLOBALS['csstidy']['whitespace'], '', $value), -10, 10), '!important')); + AND !strcasecmp(substr(str_replace($GLOBALS['csstidy']['whitespace'], '', $value), -10, 10), '!important')); } /** @@ -1232,23 +1229,19 @@ function parse_string_list($value) { $in_str = false; $strings[] = $current_string; $current_string = ""; - } - else if ($value{$i} == '"' || $value{$i} == "'"){ + } elseif ($value{$i} == '"' || $value{$i} == "'") { if ($in_str === $value{$i}) { $strings[] = $current_string; $in_str = false; $current_string = ""; continue; - } - else if (!$in_str) { + } elseif (!$in_str) { $in_str = $value{$i}; } - } - else { - if ($in_str){ + } else { + if ($in_str) { $current_string .= $value{$i}; - } - else { + } else { if (!preg_match("/[\s,]/", $value{$i})) { $in_str = true; $current_string = $value{$i}; diff --git a/class.csstidy_optimise.php b/class.csstidy_optimise.php index 9001202..6642ad2 100644 --- a/class.csstidy_optimise.php +++ b/class.csstidy_optimise.php @@ -19,7 +19,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * @@ -179,7 +179,7 @@ function subvalue() { if ($this->sub_value === 'bold') { $this->sub_value = '700'; $this->parser->log('Optimised font-weight: Changed "bold" to "700"', 'Information'); - } else if ($this->sub_value === 'normal') { + } elseif ($this->sub_value === 'normal') { $this->sub_value = '400'; $this->parser->log('Optimised font-weight: Changed "normal" to "400"', 'Information'); } @@ -282,19 +282,19 @@ function cut_color($color) { return $color; /* expressions complexes de type gradient */ - if (strpos($color,"(")!==false AND strncmp($color,'rgb(',4)!=0){ + if (strpos($color,"(")!==false AND strncmp($color,'rgb(',4)!=0) { // on ne touche pas aux couleurs dans les expression ms, c'est trop sensible if (stripos($color,"progid:")!==false) return $color; preg_match_all(",rgb\([^)]+\),i",$color,$matches,PREG_SET_ORDER); - if (count($matches)){ - foreach ($matches as $m){ + if (count($matches)) { + foreach ($matches as $m) { $color = str_replace($m[0],$this->cut_color($m[0]),$color); } } preg_match_all(",#[0-9a-f]{6}(?=[^0-9a-f]),i",$color,$matches,PREG_SET_ORDER); - if (count($matches)){ - foreach ($matches as $m){ + if (count($matches)) { + foreach ($matches as $m) { $color = str_replace($m[0],$this->cut_color($m[0]),$color); } } @@ -647,7 +647,7 @@ function dissolve_short_bg($str_value) { // don't try to explose background gradient ! if (stripos($str_value, "gradient(")!==FALSE) return array('background'=>$str_value); - + $background_prop_default = & $GLOBALS['csstidy']['background_prop_default']; $repeat = array('repeat', 'repeat-x', 'repeat-y', 'no-repeat', 'space'); $attachment = array('scroll', 'fixed', 'local'); @@ -695,8 +695,7 @@ function dissolve_short_bg($str_value) { $return['background-position'] .= ' '; else $return['background-position'].= ','; $have['pos'] = true; - } - elseif (!$have['color']) { + } elseif (!$have['color']) { $return['background-color'] .= $str_value[$i][$j] . ','; $have['color'] = true; } @@ -733,7 +732,7 @@ function merge_bg($input_css) { // if background properties is here and not empty, don't try anything if (isset($input_css['background']) AND $input_css['background']) return $input_css; - + for ($i = 0; $i < $number_of_values; $i++) { foreach ($background_prop_default as $bg_property => $default_value) { // Skip if property does not exist diff --git a/class.csstidy_print.php b/class.csstidy_print.php index 9897fbd..5a7bb9b 100644 --- a/class.csstidy_print.php +++ b/class.csstidy_print.php @@ -19,7 +19,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * @@ -308,14 +308,13 @@ function _convert_raw_css($default_media='') { ksort($val); if (intval($medium) < DEFAULT_AT) { // un medium vide (contenant @font-face ou autre @) ne produit aucun conteneur - if (strlen(trim($medium))){ + if (strlen(trim($medium))) { $this->parser->_add_token(AT_START, $medium, true); } - } - elseif ($default_media) { + } elseif ($default_media) { $this->parser->_add_token(AT_START, $default_media, true); } - + foreach ($val as $selector => $vali) { if ($sort_properties) ksort($vali); @@ -328,7 +327,7 @@ function _convert_raw_css($default_media='') { '-' => array() // IE6 hacks ); foreach ($vali as $property => $valj) { - if (strncmp($property,"//",2)!==0){ + if (strncmp($property,"//",2)!==0) { $matches = array(); if ($sort_properties && preg_match('/^(\*|_|\/|-)(?!(ms|moz|o\b|xv|atsc|wap|khtml|webkit|ah|hp|ro|rim|tc)-)/', $property, $matches)) { $invalid[$matches[1]][$property] = $valj; @@ -349,11 +348,10 @@ function _convert_raw_css($default_media='') { if (intval($medium) < DEFAULT_AT) { // un medium vide (contenant @font-face ou autre @) ne produit aucun conteneur - if (strlen(trim($medium))){ + if (strlen(trim($medium))) { $this->parser->_add_token(AT_END, $medium, true); } - } - elseif ($default_media) { + } elseif ($default_media) { $this->parser->_add_token(AT_END, $default_media, true); } } diff --git a/css_optimiser.php b/css_optimiser.php index b282062..e172a01 100644 --- a/css_optimiser.php +++ b/css_optimiser.php @@ -17,7 +17,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * @@ -47,111 +47,103 @@ function rmdirr($dirname,$oc=0) { // Sanity check if (!file_exists($dirname)) { - return false; + return false; } // Simple delete for a file if (is_file($dirname) && (time()-fileatime($dirname))>3600) { - return unlink($dirname); + return unlink($dirname); } // Loop through the folder - if(is_dir($dirname)) - { - $dir = dir($dirname); - while (false !== $entry = $dir->read()) { - // Skip pointers - if ($entry === '.' || $entry === '..') { - continue; - } - // Recurse - rmdirr($dirname.'/'.$entry,$oc); - } - $dir->close(); + if (is_dir($dirname)) { + $dir = dir($dirname); + while (false !== $entry = $dir->read()) { + // Skip pointers + if ($entry === '.' || $entry === '..') { + continue; + } + // Recurse + rmdirr($dirname.'/'.$entry,$oc); + } + $dir->close(); } // Clean up - if ($oc==1) - { + if ($oc==1) { return rmdir($dirname); } } function options($options, $selected = null, $labelIsValue = false) { - $html = ''; - - settype($selected, 'array'); - settype($options, 'array'); - - foreach ($options as $value=>$label) - { - if (is_array($label)) { - $value = $label[0]; - $label = $label[1]; - } - $label = htmlspecialchars($label, ENT_QUOTES, 'utf-8'); - $value = $labelIsValue ? $label - : htmlspecialchars($value, ENT_QUOTES, 'utf-8'); - - $html .= ''; - } - - return $html; + $html = ''; + + settype($selected, 'array'); + settype($options, 'array'); + + foreach ($options as $value=>$label) { + if (is_array($label)) { + $value = $label[0]; + $label = $label[1]; + } + $label = htmlspecialchars($label, ENT_QUOTES, 'utf-8'); + $value = $labelIsValue ? $label + : htmlspecialchars($value, ENT_QUOTES, 'utf-8'); + + $html .= ''; + } + + return $html; } $css = new csstidy(); $is_custom = isset($_REQUEST['custom']) && !empty($_REQUEST['custom']) && isset($_REQUEST['template']) && ($_REQUEST['template'] === '4'); -if($is_custom) +if ($is_custom) { - setcookie ('custom_template', $_REQUEST['custom'], time()+360000); + setcookie ('custom_template', $_REQUEST['custom'], time()+360000); } rmdirr('temp'); -if(isset($_REQUEST['case_properties'])) $css->set_cfg('case_properties',$_REQUEST['case_properties']); -if(isset($_REQUEST['lowercase'])) $css->set_cfg('lowercase_s',true); -if(!isset($_REQUEST['compress_c']) && isset($_REQUEST['post'])) $css->set_cfg('compress_colors',false); -if(!isset($_REQUEST['compress_fw']) && isset($_REQUEST['post'])) $css->set_cfg('compress_font-weight',false); -if(isset($_REQUEST['merge_selectors'])) $css->set_cfg('merge_selectors', $_REQUEST['merge_selectors']); -if(isset($_REQUEST['optimise_shorthands'])) $css->set_cfg('optimise_shorthands',$_REQUEST['optimise_shorthands']); -if(!isset($_REQUEST['rbs']) && isset($_REQUEST['post'])) $css->set_cfg('remove_bslash',false); -if(isset($_REQUEST['preserve_css'])) $css->set_cfg('preserve_css',true); -if(isset($_REQUEST['sort_sel'])) $css->set_cfg('sort_selectors',true); -if(isset($_REQUEST['sort_de'])) $css->set_cfg('sort_properties',true); -if(isset($_REQUEST['remove_last_sem'])) $css->set_cfg('remove_last_;',true); -if(isset($_REQUEST['discard'])) $css->set_cfg('discard_invalid_properties',true); -if(isset($_REQUEST['css_level'])) $css->set_cfg('css_level',$_REQUEST['css_level']); -if(isset($_REQUEST['timestamp'])) $css->set_cfg('timestamp',true); +if (isset($_REQUEST['case_properties'])) $css->set_cfg('case_properties',$_REQUEST['case_properties']); +if (isset($_REQUEST['lowercase'])) $css->set_cfg('lowercase_s',true); +if (!isset($_REQUEST['compress_c']) && isset($_REQUEST['post'])) $css->set_cfg('compress_colors',false); +if (!isset($_REQUEST['compress_fw']) && isset($_REQUEST['post'])) $css->set_cfg('compress_font-weight',false); +if (isset($_REQUEST['merge_selectors'])) $css->set_cfg('merge_selectors', $_REQUEST['merge_selectors']); +if (isset($_REQUEST['optimise_shorthands'])) $css->set_cfg('optimise_shorthands',$_REQUEST['optimise_shorthands']); +if (!isset($_REQUEST['rbs']) && isset($_REQUEST['post'])) $css->set_cfg('remove_bslash',false); +if (isset($_REQUEST['preserve_css'])) $css->set_cfg('preserve_css',true); +if (isset($_REQUEST['sort_sel'])) $css->set_cfg('sort_selectors',true); +if (isset($_REQUEST['sort_de'])) $css->set_cfg('sort_properties',true); +if (isset($_REQUEST['remove_last_sem'])) $css->set_cfg('remove_last_;',true); +if (isset($_REQUEST['discard'])) $css->set_cfg('discard_invalid_properties',true); +if (isset($_REQUEST['css_level'])) $css->set_cfg('css_level',$_REQUEST['css_level']); +if (isset($_REQUEST['timestamp'])) $css->set_cfg('timestamp',true); // This by itself is enough since our scripts don't use DOM to create elements (in which case the namespace aware ones -// should be used when serving as application/xhtml+xml but not when served as text/html ; -// also, case will be different when retrieving element names, as HTML DOM returns in upper case, +// should be used when serving as application/xhtml+xml but not when served as text/html ; +// also, case will be different when retrieving element names, as HTML DOM returns in upper case, // genuine XHTML DOM (when XHTML served as such) as lower if (stristr($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml')) { $http_accept = 'application/xhtml+xml'; -} -elseif (stristr($_SERVER['HTTP_ACCEPT'], 'application/xml')) { +} elseif (stristr($_SERVER['HTTP_ACCEPT'], 'application/xml')) { $http_accept = 'application/xml'; -} -elseif (stristr($_SERVER['HTTP_ACCEPT'], 'text/xml')) { +} elseif (stristr($_SERVER['HTTP_ACCEPT'], 'text/xml')) { $http_accept = 'text/xml'; -} -elseif (stristr($_SERVER['HTTP_USER_AGENT'], 'Opera ') || stristr($_SERVER['HTTP_USER_AGENT'], 'Opera/')) { +} elseif (stristr($_SERVER['HTTP_USER_AGENT'], 'Opera ') || stristr($_SERVER['HTTP_USER_AGENT'], 'Opera/')) { preg_match('@Opera/(\d)@', $_SERVER['HTTP_USER_AGENT'], $matches); if (isset($matches[1]) && $matches[1] >= 7) { $http_accept = 'application/xhtml+xml'; - } - else { + } else { $http_accept = 'text/html'; } -} -else { +} else { $http_accept = 'text/html'; } @@ -160,209 +152,200 @@ function options($options, $selected = null, $labelIsValue = false) if ($http_accept === 'text/html') { ?> + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - - - - <?php echo $lang[$l][0]; echo $css->version; ?>) - - - - - -

- -

- csstidy version; ?>) -

- : English Deutsch French Chinese

-

- -

- -
-
-
- - - size="35" />
- -
-
-
-
- + + size="35" />
+ +
+
+
+
+ -
-
- + ?> +
+
+ - get_cfg('preserve_css')) echo 'checked="checked"'; ?> /> -
+ get_cfg('preserve_css')) echo 'checked="checked"'; ?> /> +
- get_cfg('sort_selectors')) echo 'checked="checked"'; ?> /> -
+ get_cfg('sort_selectors')) echo 'checked="checked"'; ?> /> +
- get_cfg('sort_properties')) echo 'checked="checked"'; ?> /> -
+ get_cfg('sort_properties')) echo 'checked="checked"'; ?> /> +
- -
+ +
- -
+ +
- get_cfg('compress_colors')) echo 'checked="checked"';?> /> -
+ get_cfg('compress_colors')) echo 'checked="checked"';?> /> +
- get_cfg('compress_font-weight')) echo 'checked="checked"';?> /> -
+ get_cfg('compress_font-weight')) echo 'checked="checked"';?> /> +
- get_cfg('lowercase_s')) echo 'checked="checked"'; ?> /> -
+ get_cfg('lowercase_s')) echo 'checked="checked"'; ?> /> +
-
- get_cfg('case_properties') === 0) echo 'checked="checked"'; ?> /> - - get_cfg('case_properties') === 1) echo 'checked="checked"'; ?> /> - - get_cfg('case_properties') === 2) echo 'checked="checked"'; ?> /> -
+
+ get_cfg('case_properties') === 0) echo 'checked="checked"'; ?> /> + + get_cfg('case_properties') === 1) echo 'checked="checked"'; ?> /> + + get_cfg('case_properties') === 2) echo 'checked="checked"'; ?> /> +
- get_cfg('remove_bslash')) echo 'checked="checked"'; ?> /> -
+ get_cfg('remove_bslash')) echo 'checked="checked"'; ?> /> +
- get_cfg('remove_last_;')) echo 'checked="checked"'; ?> /> -
+ get_cfg('remove_last_;')) echo 'checked="checked"'; ?> /> +
- get_cfg('discard_invalid_properties')) echo 'checked="checked"'; ?> /> - -
+ get_cfg('discard_invalid_properties')) echo 'checked="checked"'; ?> /> + +
- get_cfg('timestamp')) echo 'checked="checked"'; ?> /> -
- + get_cfg('timestamp')) echo 'checked="checked"'; ?> /> +
+ /> -
+ /> +
- /> -
- -
-
- - + +
+ + + load_template($_REQUEST['custom'],false); } break; @@ -381,26 +364,20 @@ class="block"> print->plain())) - { - $file_ok = true; - } - } - fclose($handle); - } - if($ratio>0) $ratio = ''.$ratio.'% - ('.$diff.' Bytes)'; else $ratio = ''.$ratio.'% ('.$diff.' Bytes)'; - if(count($css->log) > 0): ?> -
Messages + $handle = fopen('temp/'.$filename.'.css','w'); + if ($handle) { + if (fwrite($handle,$css->print->plain())) { + $file_ok = true; + } + } + fclose($handle); + } + if ($ratio>0) $ratio = ''.$ratio.'% + ('.$diff.' Bytes)'; else $ratio = ''.$ratio.'% ('.$diff.' Bytes)'; + if (count($css->log) > 0): ?> +
Messages
log as $line => $array) - { + foreach ($css->log as $line => $array) { echo '
',$line,'
'; $array_size = count($array); - for($i = 0; $i < $array_size; ++$i) - { + for ($i = 0; $i < $array_size; ++$i) { echo '
',$array[$i]['m'],'
'; } } ?>
-
- ',$lang[$l][37],': ',$css->print->size('input'),'KB, ',$lang[$l][38],':',$css->print->size('output'),'KB, ',$lang[$l][36],': ',$ratio; - if($file_ok) - { - echo ' - Download'; - } - echo ' - ',$lang[$l][58],''; - echo ''; - echo ''; - echo $css->print->formatted(); - echo '

'; - + + ',$lang[$l][37],': ',$css->print->size('input'),'KB, ',$lang[$l][38],':',$css->print->size('output'),'KB, ',$lang[$l][36],': ',$ratio; + if ($file_ok) { + echo ' - Download'; + } + echo ' - ',$lang[$l][58],''; + echo ''; + echo ''; + echo $css->print->formatted(); + echo '

'; + echo '
',$lang[$l][64],''; - echo '
'; echo '
',$lang[$l][65],''; echo ''; - + echo '

↑ ',$lang[$l][59],'

'; - - } - elseif(isset($_REQUEST['css_text']) || isset($_REQUEST['url'])) { - echo '

',$lang[$l][28],'

'; - } - ?> -

- . -

- + + } elseif (isset($_REQUEST['css_text']) || isset($_REQUEST['url'])) { + echo '

',$lang[$l][28],'

'; + } + ?> +

+ . +

+ diff --git a/data.inc.php b/data.inc.php index 4c703e8..30e24f6 100644 --- a/data.inc.php +++ b/data.inc.php @@ -76,9 +76,9 @@ * @version 1.2 */ $GLOBALS['csstidy']['unit_values'] = array ('background', 'background-position', 'background-size', 'border', 'border-top', 'border-right', 'border-bottom', 'border-left', 'border-width', - 'border-top-width', 'border-right-width', 'border-left-width', 'border-bottom-width', 'bottom', 'border-spacing', 'column-gap', 'column-width', + 'border-top-width', 'border-right-width', 'border-left-width', 'border-bottom-width', 'bottom', 'border-spacing', 'column-gap', 'column-width', 'font-size', 'height', 'left', 'margin', 'margin-top', 'margin-right', 'margin-bottom', 'margin-left', 'max-height', - 'max-width', 'min-height', 'min-width', 'outline', 'outline-width', 'padding', 'padding-top', 'padding-right', + 'max-width', 'min-height', 'min-width', 'outline', 'outline-width', 'padding', 'padding-top', 'padding-right', 'padding-bottom', 'padding-left', 'perspective', 'right', 'top', 'text-indent', 'letter-spacing', 'word-spacing', 'width'); /** diff --git a/lang.inc.php b/lang.inc.php index 6452b42..d646fd6 100644 --- a/lang.inc.php +++ b/lang.inc.php @@ -16,26 +16,24 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License * @package csstidy * @author Florian Schmitz (floele at gmail dot com) 2005-2007 - * @author Brett Zamir (brettz9 at yahoo dot com) 2007 + * @author Brett Zamir (brettz9 at yahoo dot com) 2007 */ -if(isset($_GET['lang'])) { - $l = $_GET['lang']; -} -else if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { - $l = $_SERVER['HTTP_ACCEPT_LANGUAGE']; - $l = strtolower(substr($l, 0, 2)); -} -else { - $l = ''; +if (isset($_GET['lang'])) { + $l = $_GET['lang']; +} elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + $l = $_SERVER['HTTP_ACCEPT_LANGUAGE']; + $l = strtolower(substr($l, 0, 2)); +} else { + $l = ''; } $l = (in_array($l, array('de', 'fr', 'zh'))) ? $l : 'en'; @@ -128,7 +126,7 @@ $lang['de'][16] = 'Niedrig (höhere Lesbarkeit)'; $lang['de'][17] = 'Benutzerdefiniert (unten eingeben)'; $lang['de'][18] = 'Benutzerdefinierte Vorlage'; -$lang['de'][19] = 'Optionen'; +$lang['de'][19] = 'Optionen'; $lang['de'][20] = 'Selektoren sortieren (Vorsicht)'; $lang['de'][21] = 'Eigenschaften sortieren'; $lang['de'][22] = 'Selektoren umgruppieren'; @@ -140,7 +138,7 @@ $lang['de'][28] = 'Keine oder ungültige CSS Eingabe oder falsche URL!'; $lang['de'][29] = 'Großbuchstaben'; $lang['de'][30] = 'kleingeschriebene Elementnamen benötigt für XHTML'; -$lang['de'][31] = 'Unnötige Backslashes entfernen'; +$lang['de'][31] = 'Unnötige Backslashes entfernen'; $lang['de'][32] = '!important-Hack konvertieren'; $lang['de'][33] = 'Als Datei ausgeben'; $lang['de'][34] = 'Größere Komprimierung augrund von kleineren Neuezeile-Zeichen'; @@ -271,7 +269,7 @@ $lang['zh'][25] = '改用小寫選擇符'; $lang['zh'][26] = '屬性的字形:'; $lang['zh'][27] = '小寫'; -$lang['zh'][28] = '沒有輸入CSS, 語法不符合規定, 或是網址錯誤!'; +$lang['zh'][28] = '沒有輸入CSS, 語法不符合規定, 或是網址錯誤!'; $lang['zh'][29] = '大寫'; $lang['zh'][30] = 'XHTML必須使用小寫的元素名稱'; $lang['zh'][31] = '移除不必要的反斜線'; diff --git a/testing/unit-tests.inc b/testing/unit-tests.inc index 4982a38..bf7d24b 100644 --- a/testing/unit-tests.inc +++ b/testing/unit-tests.inc @@ -5,31 +5,31 @@ */ function globr($sDir, $sPattern, $nFlags = NULL) { - $aFiles = glob("$sDir/$sPattern", $nFlags); - $files = getDir($sDir); - if (is_array($files)) { - foreach( $files as $file ) { - $aSubFiles = globr($file, $sPattern, $nFlags); - $aFiles = array_merge($aFiles,$aSubFiles); - } - } - return $aFiles; + $aFiles = glob("$sDir/$sPattern", $nFlags); + $files = getDir($sDir); + if (is_array($files)) { + foreach( $files as $file ) { + $aSubFiles = globr($file, $sPattern, $nFlags); + $aFiles = array_merge($aFiles,$aSubFiles); + } + } + return $aFiles; } function getDir($sDir) { - $i=0; - $aDirs = array(); - if(is_dir($sDir)) { - if($rContents = opendir($sDir)) { - while($sNode = readdir($rContents)) { - if(is_dir($sDir.'/'.$sNode )) { - if($sNode !="." && $sNode !="..") { - $aDirs[$i] = $sDir.'/'.$sNode ; - $i++; - } - } - } - } - } - return $aDirs; + $i=0; + $aDirs = array(); + if(is_dir($sDir)) { + if($rContents = opendir($sDir)) { + while($sNode = readdir($rContents)) { + if(is_dir($sDir.'/'.$sNode )) { + if($sNode !="." && $sNode !="..") { + $aDirs[$i] = $sDir.'/'.$sNode ; + $i++; + } + } + } + } + } + return $aDirs; } diff --git a/testing/unit-tests.php b/testing/unit-tests.php index 5a0c173..a8447ac 100644 --- a/testing/unit-tests.php +++ b/testing/unit-tests.php @@ -34,9 +34,9 @@ // Setup test files $test = new GroupTest('CSSTidy unit tests'); foreach ($test_files as $test_file) { - require_once "unit-tests/$test_file"; - list($x, $class_suffix) = explode('.', $test_file); - $test->addTestClass("csstidy_test_$class_suffix"); + require_once "unit-tests/$test_file"; + list($x, $class_suffix) = explode('.', $test_file); + $test->addTestClass("csstidy_test_$class_suffix"); } if (SimpleReporter::inCli()) $reporter = new TextReporter(); diff --git a/testing/unit-tests/class.Text_Diff_Renderer_parallel.php b/testing/unit-tests/class.Text_Diff_Renderer_parallel.php index 4db78aa..44da2f0 100644 --- a/testing/unit-tests/class.Text_Diff_Renderer_parallel.php +++ b/testing/unit-tests/class.Text_Diff_Renderer_parallel.php @@ -6,31 +6,31 @@ */ class Text_Diff_Renderer_parallel extends Text_Diff_Renderer { - /** String header for left column */ - var $original = 'Original'; - /** String header for right column */ - var $final = 'Final'; - var $_leading_context_lines = 10000; // these are big to ensure entire string is output - var $_trailing_context_lines = 10000; - function _blockHeader() {} - function _startDiff() { - return ''; - } - function _endDiff() { - return '
'. $this->original .''. $this->final .'
'; - } - function _context($lines) { - return '
'. htmlspecialchars(implode("\n", $lines)) .'
-
'. htmlspecialchars(implode("\n", $lines)) .'
'; - } - function _added($lines) { - return ' 
'. htmlspecialchars(implode("\n", $lines)) .'
'; - } - function _deleted($lines) { - return '
'. htmlspecialchars(implode("\n", $lines)) .'
 '; - } - function _changed($orig, $final) { - return '
'. htmlspecialchars(implode("\n", $orig)) .'
-
'. htmlspecialchars(implode("\n", $final)) .'
'; - } + /** String header for left column */ + var $original = 'Original'; + /** String header for right column */ + var $final = 'Final'; + var $_leading_context_lines = 10000; // these are big to ensure entire string is output + var $_trailing_context_lines = 10000; + function _blockHeader() {} + function _startDiff() { + return ''; + } + function _endDiff() { + return '
'. $this->original .''. $this->final .'
'; + } + function _context($lines) { + return '
'. htmlspecialchars(implode("\n", $lines)) .'
+
'. htmlspecialchars(implode("\n", $lines)) .'
'; + } + function _added($lines) { + return ' 
'. htmlspecialchars(implode("\n", $lines)) .'
'; + } + function _deleted($lines) { + return '
'. htmlspecialchars(implode("\n", $lines)) .'
 '; + } + function _changed($orig, $final) { + return '
'. htmlspecialchars(implode("\n", $orig)) .'
+
'. htmlspecialchars(implode("\n", $final)) .'
'; + } } diff --git a/testing/unit-tests/class.csstidy_csst.php b/testing/unit-tests/class.csstidy_csst.php index 6d8ddad..942a455 100644 --- a/testing/unit-tests/class.csstidy_csst.php +++ b/testing/unit-tests/class.csstidy_csst.php @@ -7,129 +7,127 @@ */ class csstidy_csst extends SimpleExpectation { - /** Filename of test */ - var $filename; - - /** Test name */ - var $test; - - /** CSS for test to parse */ - var $css = ''; - - /** Settings for csstidy */ - var $settings = array(); - - /** Expected var_export() output of $css->css[41] (no at block) */ - var $expect = ''; - - /** Boolean whether or not to use $css->css instead for $expect */ - var $fullexpect = false; + /** Filename of test */ + var $filename; + + /** Test name */ + var $test; + + /** CSS for test to parse */ + var $css = ''; + + /** Settings for csstidy */ + var $settings = array(); + + /** Expected var_export() output of $css->css[41] (no at block) */ + var $expect = ''; + + /** Boolean whether or not to use $css->css instead for $expect */ + var $fullexpect = false; /** Print form of CSS that can be tested **/ - var $print = false; + var $print = false; var $default_media = ""; - /** Actual result */ - var $actual; - - /** - * Loads this class from a file. - * @param $filename String filename to load - */ - function load($filename) { - $this->filename = $filename; - $fh = fopen($filename, 'r'); - $state = ''; - while (($line = fgets($fh)) !== false) { - $line = rtrim($line, "\n\r"); // normalize newlines - if (substr($line, 0, 2) == '--') { - // detected section - $state = $line; - continue; - } - if ($state === null) continue; - switch ($state) { - case '--TEST--': - $this->test = trim($line); - break; - case '--CSS--': - $this->css .= $line . "\n"; - break; - case '--FULLEXPECT--': - $this->fullexpect = true; - $this->expect .= $line . "\n"; - break; - case '--EXPECT--': - $this->expect .= $line . "\n"; - break; - case '--SETTINGS--': - list($n, $v) = array_map('trim',explode('=', $line, 2)); - $v = eval("return $v;"); - if ($n=="default_media" AND $this->print) - $this->default_media = $v; - else - $this->settings[$n] = $v; - break; - case '--PRINT--': - $this->print = true; - $this->expect .= $line . "\n"; - break; - } - } + /** Actual result */ + var $actual; + + /** + * Loads this class from a file. + * @param $filename String filename to load + */ + function load($filename) { + $this->filename = $filename; + $fh = fopen($filename, 'r'); + $state = ''; + while (($line = fgets($fh)) !== false) { + $line = rtrim($line, "\n\r"); // normalize newlines + if (substr($line, 0, 2) == '--') { + // detected section + $state = $line; + continue; + } + if ($state === null) continue; + switch ($state) { + case '--TEST--': + $this->test = trim($line); + break; + case '--CSS--': + $this->css .= $line . "\n"; + break; + case '--FULLEXPECT--': + $this->fullexpect = true; + $this->expect .= $line . "\n"; + break; + case '--EXPECT--': + $this->expect .= $line . "\n"; + break; + case '--SETTINGS--': + list($n, $v) = array_map('trim',explode('=', $line, 2)); + $v = eval("return $v;"); + if ($n=="default_media" AND $this->print) + $this->default_media = $v; + else + $this->settings[$n] = $v; + break; + case '--PRINT--': + $this->print = true; + $this->expect .= $line . "\n"; + break; + } + } if ($this->print) { $this->expect = trim($this->expect); - } - else { + } else { if ($this->expect) $this->expect = eval("return ".$this->expect.";"); if (!$this->fullexpect) $this->expect = array(41=>$this->expect); } - fclose($fh); - } - - /** - * Implements SimpleExpectation::test(). - * @param $filename Filename of test file to test. - */ - function test($filename = false) { - if ($filename) $this->load($filename); - $css = new csstidy(); - $css->set_cfg($this->settings); - $css->parse($this->css); - if ($this->print){ + fclose($fh); + } + + /** + * Implements SimpleExpectation::test(). + * @param $filename Filename of test file to test. + */ + function test($filename = false) { + if ($filename) $this->load($filename); + $css = new csstidy(); + $css->set_cfg($this->settings); + $css->parse($this->css); + if ($this->print) { $this->actual = $css->print->plain($this->default_media); - } - else{ + } else { $this->actual = $css->css; } - return $this->expect === $this->actual; - } - - /** - * Implements SimpleExpectation::testMessage(). - */ - function testMessage() { - $message = $this->test . ' test at '. htmlspecialchars($this->filename); - return $message; - } - - /** - * Renders the test with an HTML diff table. - */ - function render() { - $message = '
'. htmlspecialchars($this->css) .'
'; - $diff = new Text_Diff( + return $this->expect === $this->actual; + } + + /** + * Implements SimpleExpectation::testMessage(). + */ + function testMessage() { + $message = $this->test . ' test at '. htmlspecialchars($this->filename); + return $message; + } + + /** + * Renders the test with an HTML diff table. + */ + function render() { + $message = '
'. htmlspecialchars($this->css) .'
'; + $diff = new Text_Diff( 'auto', array( explode("\n", $this->print?$this->expect:var_export($this->expect,true)), explode("\n", $this->print?$this->actual:var_export($this->actual,true)) ) ); - $renderer = new Text_Diff_Renderer_parallel(); - $renderer->original = 'Expected'; - $renderer->final = 'Actual'; - $message .= $renderer->render($diff); - return $message; - } + $renderer = new Text_Diff_Renderer_parallel(); + $renderer->original = 'Expected'; + $renderer->final = 'Actual'; + $message .= $renderer->render($diff); + return $message; + } } diff --git a/testing/unit-tests/class.csstidy_harness.php b/testing/unit-tests/class.csstidy_harness.php index eb6d2af..097f628 100644 --- a/testing/unit-tests/class.csstidy_harness.php +++ b/testing/unit-tests/class.csstidy_harness.php @@ -5,17 +5,17 @@ */ class csstidy_harness extends UnitTestCase { - /** - * Modified testing algorithm that allows a single test method to be - * prefixed with __only in order to make it the only one run. - */ - function getTests() { - // __onlytest makes only one test get triggered - foreach (get_class_methods(get_class($this)) as $method) { - if (strtolower(substr($method, 0, 10)) == '__onlytest') { - return array($method); - } - } - return parent::getTests(); - } + /** + * Modified testing algorithm that allows a single test method to be + * prefixed with __only in order to make it the only one run. + */ + function getTests() { + // __onlytest makes only one test get triggered + foreach (get_class_methods(get_class($this)) as $method) { + if (strtolower(substr($method, 0, 10)) == '__onlytest') { + return array($method); + } + } + return parent::getTests(); + } } diff --git a/testing/unit-tests/class.csstidy_reporter.php b/testing/unit-tests/class.csstidy_reporter.php index 8a9a2c4..d8bb6e0 100644 --- a/testing/unit-tests/class.csstidy_reporter.php +++ b/testing/unit-tests/class.csstidy_reporter.php @@ -6,16 +6,16 @@ */ class csstidy_reporter extends HTMLReporter { - - function _getCss() { - $css = parent::_getCss(); - $css .= ' + + function _getCss() { + $css = parent::_getCss(); + $css .= ' .diff {margin-bottom: 1em;} .diff th {width:50%;} .diff pre {margin:0; padding:0; background:none;} .diff .changed, .diff .deleted, .diff .added {background: #FF5;} - '; - return $css; - } - + '; + return $css; + } + } diff --git a/testing/unit-tests/test.csst.php b/testing/unit-tests/test.csst.php index 3b007ac..a9bebec 100644 --- a/testing/unit-tests/test.csst.php +++ b/testing/unit-tests/test.csst.php @@ -7,15 +7,15 @@ */ class csstidy_test_csst extends csstidy_harness { - function testAll() { - $files = globr(dirname(__FILE__) . '/csst', '*.csst'); - foreach ($files as $filename) { - $expectation = new csstidy_csst(); - $result = $this->assert($expectation, $filename, '%s'); - // this is necessary because SimpleTest doesn't support - // HTML messages; this probably should be in the reporter. - // This is *not* compatible with XmlReporter - if (!$result) echo $expectation->render(); - } - } + function testAll() { + $files = globr(dirname(__FILE__) . '/csst', '*.csst'); + foreach ($files as $filename) { + $expectation = new csstidy_csst(); + $result = $this->assert($expectation, $filename, '%s'); + // this is necessary because SimpleTest doesn't support + // HTML messages; this probably should be in the reporter. + // This is *not* compatible with XmlReporter + if (!$result) echo $expectation->render(); + } + } }