Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #19 from dereuromark/master-cleanup
Browse files Browse the repository at this point in the history
spaces to tabs - correct indentation
  • Loading branch information
Cerdic committed Aug 9, 2012
2 parents 259638e + 5bd2889 commit 2743c4c
Show file tree
Hide file tree
Showing 13 changed files with 514 additions and 557 deletions.
83 changes: 38 additions & 45 deletions class.csstidy.php
Expand Up @@ -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;
Expand All @@ -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 */
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 = '';
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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 = '';
}
Expand All @@ -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};
Expand Down Expand Up @@ -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)));
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]))
Expand All @@ -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;

Expand All @@ -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;
}
}
Expand All @@ -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])
Expand Down Expand Up @@ -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'));
}

/**
Expand Down Expand Up @@ -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};
Expand Down
21 changes: 10 additions & 11 deletions class.csstidy_optimise.php
Expand Up @@ -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 <http://www.gnu.org/licenses/>.
*
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions class.csstidy_print.php
Expand Up @@ -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 <http://www.gnu.org/licenses/>.
*
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 2743c4c

Please sign in to comment.