csstidy
[ class tree: csstidy ] [ index: csstidy ] [ all elements ]

Class: csstidy

Source Location: /css_parser.php

Class Overview


CSS Parser class


Author(s):

  • Florian Schmitz (floele at gmail dot com) 2005

Version:

  • 1.1

Variables

Methods



Class Details

[line 60]
CSS Parser class

This class represents a CSS parser which reads CSS code and saves it in an array. In opposite to most other CSS parsers, it does not use regular expressions and thus has full CSS2 support and a higher reliability. Additional to that it applies some optimisations and fixes to the CSS code. An online version should be available here: http://cdburnerxp.se/cssparse/css_optimiser.php




Tags:

version:  1.1
author:  Florian Schmitz (floele at gmail dot com) 2005


[ Top ]


Class Variables

$added =  false

[line 245]

=true if something has been added to the current selector



Tags:

access:  private

Type:   bool


[ Top ]

$at =  ''

[line 162]

Saves the current at rule (@media)



Tags:

access:  private

Type:   string


[ Top ]

$charset =  ''

[line 74]

Saves the CSS charset (@charset)



Tags:

access:  private

Type:   string


[ Top ]

$comments = array()

[line 131]

Stores comments



Tags:

access:  private

Type:   array


[ Top ]

$comment_from =  ''

[line 252]

Status where the comment has been started



Tags:

access:  private

Type:   string


[ Top ]

$css = array()

[line 67]

Saves the parsed CSS



Tags:

access:  public

Type:   array


[ Top ]

$import = array()

[line 81]

Saves all @import URLs



Tags:

access:  private

Type:   array


[ Top ]

$input_css =  ''

[line 95]

Saves the input CSS string



Tags:

access:  private

Type:   string


[ Top ]

$invalid_at =  false

[line 238]

=true if in invalid at-rule



Tags:

access:  private

Type:   bool


[ Top ]

$line =  1

[line 266]

Saves the line number



Tags:

access:  private

Type:   integer


[ Top ]

$log = array()

[line 259]

Array which saves the message log



Tags:

access:  private

Type:   array


[ Top ]

$namespace =  ''

[line 88]

Saves the namespace



Tags:

access:  private

Type:   string


[ Top ]

$output_css =  ''

[line 102]

Saves the formatted CSS string



Tags:

access:  public

Type:   string


[ Top ]

$output_css_plain =  ''

[line 109]

Saves the formatted CSS string (plain text)



Tags:

access:  public

Type:   string


[ Top ]

$property =  ''

[line 176]

Saves the current property



Tags:

access:  private

Type:   string


[ Top ]

$selector =  ''

[line 169]

Saves the current selector



Tags:

access:  private

Type:   string


[ Top ]

$sel_seperate = array()

[line 183]

Saves the position of , in selectors



Tags:

access:  private

Type:   array


[ Top ]

$settings = array()

[line 138]

Stores the settings



Tags:

access:  private

Type:   array


[ Top ]

$status =  'is'

[line 154]

Saves the parser-status.

Possible values:

  • is = in selector
  • ip = in property
  • iv = in value
  • instr = in string (started at " or ' or ( )
  • ic = in comment (ignore everything)
  • at = in @-block




Tags:

access:  private

Type:   string


[ Top ]

$str_char =  ''

[line 217]

Saves the char which opened the last string



Tags:

access:  private

Type:   string


[ Top ]

$str_from =  ''

[line 224]

Status where the string has been started (is or iv)



Tags:

access:  private

Type:   string


[ Top ]

$str_in_str =  false

[line 231]

Variable needed to manage string-in-strings, for example url("foo.png")



Tags:

access:  private

Type:   string


[ Top ]

$sub_value =  ''

[line 202]

Saves the current sub-value

Example for a subvalue: background:url(foo.png) red no-repeat; "url(foo.png)", "red", and "no-repeat" are subvalues, seperated by whitespace




Tags:

access:  private

Type:   string


[ Top ]

$sub_value_arr = array()

[line 210]

Array which saves all subvalues for a property.



Tags:

access:  private
see:  csstidy::$sub_value

Type:   array


[ Top ]

$template = array()

[line 117]

Saves the templates



Tags:

see:  http://cdburnerxp.se/cssparse/template.htm
access:  private

Type:   array


[ Top ]

$value =  ''

[line 190]

Saves the current value



Tags:

access:  private

Type:   string


[ Top ]

$version =  '1.1'

[line 124]

Contains the version of csstidy



Tags:

access:  private

Type:   string


[ Top ]



Class Methods


constructor csstidy [line 273]

csstidy csstidy( )

Loads standard template and sets default settings



Tags:

version:  1.1
access:  private


[ Top ]

method css_add_property [line 1103]

void css_add_property( string $media, string $selector, string $property, string $new_val, [bool $ie = true])

Adds a property with value to the existing CSS code



Tags:

version:  1.1
access:  private


Parameters:

string   $media  
string   $selector  
string   $property  
string   $new_val  
bool   $ie   if $ie == false IE Hacks are not saved even if it is enabled in settings

[ Top ]

method c_font_weight [line 1411]

bool c_font_weight( string &$value)

Compresses font-weight (not very effective but anyway :-p )



Tags:

version:  1.1
access:  private


Parameters:

string   $value  

[ Top ]

method c_important [line 1256]

string c_important( string &$string)

Removes unnecessary whitespace in ! important



Tags:

version:  1.1
access:  public


Parameters:

string   $string  

[ Top ]

method escaped [line 1088]

bool escaped( string &$string, integer $pos)

Checks if a character is escaped (and returns true if it is)



Tags:

version:  1.01
access:  public


Parameters:

string   $string  
integer   $pos  

[ Top ]

method explode_selectors [line 1006]

void explode_selectors( )

Explodes selectors



Tags:

version:  1.0
access:  private


[ Top ]

method get_cfg [line 301]

mixed get_cfg( string $setting)

Get the value of a setting.



Tags:

version:  1.0
access:  public


Parameters:

string   $setting  

[ Top ]

method get_diff [line 482]

string get_diff( )

Get difference between the old and new code in bytes and prints the code if necessary.



Tags:

version:  1.1
access:  public


[ Top ]

method get_ratio [line 467]

float get_ratio( )

Get compression ratio and prints the code if necessary.



Tags:

version:  1.1
access:  public


[ Top ]

method gvw_important [line 1235]

string gvw_important( string $value)

Returns a value without !important



Tags:

version:  1.0
access:  public


Parameters:

string   $value  

[ Top ]

method htmlsp [line 1274]

string htmlsp( string $string, bool $plain)

Same as htmlspecialchars, only that chars are not replaced if $plain !== true. This makes print_code() cleaner.



Tags:

version:  1.0
access:  public
see:  csstidy::print_code()


Parameters:

string   $string  
bool   $plain  

[ Top ]

method is_important [line 1218]

bool is_important( string &$value)

Checks if $value is !important.



Tags:

version:  1.0
access:  public


Parameters:

string   $value  

[ Top ]

method is_token [line 577]

void is_token( string &$string, integer $i)

Checks if there is a token at the current position



Tags:

version:  1.1
access:  public


Parameters:

string   $string  
integer   $i  

[ Top ]

method load_template [line 536]

void load_template( string $content, [bool $from_file = true])

Loads a new template



Tags:

see:  http://csstidy.sourceforge.net/templates.php
version:  1.1
access:  public


Parameters:

string   $content   either filename (if $from_file == true), content of a template file, "high_compression", "highest_compression", "low_compression", or "default"
bool   $from_file   uses $content as filename if true

[ Top ]

method log [line 336]

void log( string $message, string $type, [integer $line = -1])

Add a message to the message log



Tags:

version:  1.0
access:  private


Parameters:

string   $message  
string   $type  
integer   $line  

[ Top ]

method merge_css_blocks [line 1152]

void merge_css_blocks( string $media, string $selector, array $css_add)

Adds CSS to an existing media/selector



Tags:

version:  1.1
access:  private


Parameters:

string   $media  
string   $selector  
array   $css_add  

[ Top ]

method merge_selectors [line 1168]

array merge_selectors( array &$array)

Merges selectors with same properties. Example: a{color:red} b{color:red} -> a,b{color:red} Very basic and has at least one bug. Hopefully there is a replacement soon.



Tags:

version:  1.2
access:  public


Parameters:

array   $array  

[ Top ]

method optimise_add_subvalue [line 1041]

void optimise_add_subvalue( )

Optimises a sub-value and adds it to sub_value_arr



Tags:

version:  1.0
access:  private


[ Top ]

method parse [line 591]

bool parse( string $string)

Parses CSS in $string. The code is saved as array in $this->css



Tags:

version:  1.1
access:  public


Parameters:

string   $string   the CSS code

[ Top ]

method parse_from_url [line 564]

void parse_from_url( string $url)

Starts parsing from URL



Tags:

version:  1.0
access:  public


Parameters:

string   $url  

[ Top ]

method print_code [line 1290]

string print_code( [array $css = NULL], [mixed $plain = false])

Returns the formatted CSS Code and saves it into $this->output_css



Tags:

version:  1.3
access:  public


Parameters:

array   $css  

[ Top ]

method property_is_next [line 1386]

bool property_is_next( string $istring, integer $pos)

Checks if the next word in a string from pos is a CSS property



Tags:

version:  1.2
access:  private


Parameters:

string   $istring  
integer   $pos  

[ Top ]

method set_cfg [line 318]

bool set_cfg( string $setting, mixed $value)

Set the value of a setting.



Tags:

version:  1.0
access:  public


Parameters:

string   $setting  
mixed   $value  

[ Top ]

method shorthand [line 411]

string shorthand( string $value)

Compresses shorthand values. Example: margin:1px 1px 1px 1px -> margin:1px



Tags:

version:  1.0
access:  private


Parameters:

string   $value  

[ Top ]

method size [line 511]

integer size( [string $loc = 'output'])

Get the size of either input or output CSS in KB



Tags:

version:  1.0
access:  public


Parameters:

string   $loc   default is "output"

[ Top ]

method unicode [line 358]

string unicode( string &$string, integer &$i)

Parse unicode notations and find a replacement character



Tags:

version:  1.2
access:  private


Parameters:

string   $string  
integer   $i  

[ Top ]


Documentation generated on Fri, 3 Feb 2006 16:21:43 +0100 by phpDocumentor 1.3.0RC3