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">
-
-
-
- version; ?>)
-
-
-
-
-
-
- : English Deutsch French Chinese
-
-
-
-
-
+ load_template($_REQUEST['custom'],false);
}
break;
@@ -381,26 +364,20 @@ class="block">