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

Class: csspp

Source Location: /css_parser2.php

Class Overview


CSS Parser class ( CSS PreProcessor or CSS PostProcessor, depends on the point of view )


Author(s):

  • Florian Schmitz (floele at gmail dot com) 2005

Version:

  • 0.98

Variables

Methods



Class Details

[line 43]
CSS Parser class ( CSS PreProcessor or CSS PostProcessor, depends on the point of view )

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. The downside of not using regular expressions is a lower speed though. 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:  0.98
author:  Florian Schmitz (floele at gmail dot com) 2005


[ Top ]


Class Variables

$charset =  ''

[line 57]

Saves the charset (@charset)



Tags:

access:  private

Type:   string


[ Top ]

$comment_from =  ''

[line 200]

Status where the comment has been started



Tags:

access:  private

Type:   string


[ Top ]

$css = array()

[line 50]

Saves the parsed CSS



Tags:

access:  public

Type:   array


[ Top ]

$cur_at =  ''

[line 131]

Saves the current at rule (@media)



Tags:

access:  private

Type:   string


[ Top ]

$cur_property =  ''

[line 145]

Saves the current property



Tags:

access:  private

Type:   string


[ Top ]

$cur_selector =  ''

[line 138]

Saves the current selector



Tags:

access:  private

Type:   string


[ Top ]

$cur_sub_value =  ''

[line 164]

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 ]

$cur_sub_value_arr = array()

[line 172]

Array which saves all subvalues for a property.



Tags:

access:  private
see:  csspp::$cur_sub_value

Type:   string


[ Top ]

$cur_value =  ''

[line 152]

Saves the current value



Tags:

access:  private

Type:   string


[ Top ]

$hex = array('a','b','c','d','e','f','\\',':','=')

[line 93]

A list of certain chars, needed for removing unnecessary backslashes



Tags:

access:  private

Type:   array


[ Top ]

$import = array()

[line 64]

Saves all @import URLs



Tags:

access:  private

Type:   array


[ Top ]

$input_css =  ''

[line 71]

Saves the input CSS string



Tags:

access:  private

Type:   string


[ Top ]

$output_css =  ''

[line 78]

Saves the formatted CSS string



Tags:

access:  public

Type:   string


[ Top ]

$settings = array()

[line 107]

Stores the settings



Tags:

access:  private

Type:   array


[ Top ]

$status =  'wfs'

[line 123]

Saves the parser-status:

wfs = wait for selector is = in selector wfp = wait for property ip = in property iv = in value instr = in string (-> ",' ( => ignore } and ; etc.) ) ic = in comment (ignore everything) at = in @-block




Tags:

access:  private

Type:   string


[ Top ]

$str_char =  ''

[line 179]

Saves the char which opened the last string



Tags:

access:  private

Type:   string


[ Top ]

$str_from =  ''

[line 186]

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



Tags:

access:  private

Type:   string


[ Top ]

$str_in_str =  FALSE

[line 193]

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



Tags:

access:  private

Type:   string


[ Top ]

$template = array()

[line 86]

Saves the templates



Tags:

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

Type:   array


[ Top ]

$version =  '0.98dev'

[line 100]

Contains the version of CSSPP



Tags:

access:  private

Type:   string


[ Top ]



Class Methods


constructor csspp [line 208]

csspp csspp( )

Loads standard template and sets default settings



Tags:

version:  1.0
access:  private


[ Top ]

method css_add_property [line 907]

void css_add_property( array &$css, string $property, string $new_val, [bool $ie = TRUE])

Adds a property with value to an existing CSS block



Tags:

version:  1.0
access:  public


Parameters:

array   $css  
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_important [line 1068]

void c_important( string &$string)

Removes unnecessary whitespace in ! important



Tags:

version:  1.0
access:  public


Parameters:

string   $string  

[ Top ]

method escaped [line 843]

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

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



Tags:

version:  1.0
access:  public


Parameters:

string   $string  
integer   $pos  

[ Top ]

method get_cfg [line 243]

bool get_cfg( string $setting)

Get the value of a setting.



Tags:

version:  1.0
access:  public


Parameters:

string   $setting  

[ Top ]

method get_diff [line 383]

string get_diff( )

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



Tags:

version:  1.0
access:  public


[ Top ]

method get_ratio [line 368]

float get_ratio( )

Get compression ratio and prints the code if necessary.



Tags:

version:  1.0
access:  public


[ Top ]

method gvw_important [line 1045]

string gvw_important( string $value)

Returns a value without !important



Tags:

version:  1.0
access:  public


Parameters:

string   $value  

[ Top ]

method has_subkey [line 868]

mixed has_subkey( string $find, array $array, [integer $gv = 0])

Checks if $array has the key $find (array[x][$find]). If gv=1, the value of the key is returned.



Tags:

return:  depends on $gv, either bool or string
version:  1.0
access:  public


Parameters:

string   $find  
array   $array  
integer   $gv   default is 0

[ Top ]

method in_array_prop [line 969]

void in_array_prop( array $needle, array $haystack)

This function checks if the properties $needle also exist in other selectors $haystack and returs them as $keys



Tags:

version:  1.0
access:  public


Parameters:

array   $needle  
array   $haystack  

[ Top ]

method is_important [line 1028]

bool is_important( string &$value)

Checks if $value is !important.



Tags:

version:  1.0
access:  public


Parameters:

string   $value  

[ Top ]

method load_template [line 437]

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

Loads a new template



Tags:

see:  http://cdburnerxp.se/cssparse/template.htm
version:  1.0
access:  public


Parameters:

string   $content   either filename (if $from_file == true) or content of a template file
bool   $from_file   uses $content as filename if true

[ Top ]

method merge_css_blocks [line 947]

void merge_css_blocks( array &$existing_css, array $css_add)

Merges two CSS blocks



Tags:

version:  1.0
access:  public


Parameters:

array   $existing_css  
array   $css_add  

[ Top ]

method merge_selectors [line 993]

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.0
access:  public


Parameters:

array   $array  

[ Top ]

method parse [line 471]

bool parse( string $string)

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



Tags:

version:  0.98
access:  public


Parameters:

string   $string   the CSS code

[ Top ]

method parseurl [line 281]

bool parseurl( string $string, [bool $opt = TRUE])

Extract URL from @import value (if $opt == TRUE) and/or add missing http:// to URL



Tags:

version:  1.0
access:  public


Parameters:

string   $string  
bool   $opt  

[ Top ]

method parse_from_url [line 458]

void parse_from_url( string $url)

Starts parsing from URL



Tags:

version:  1.0
access:  public


Parameters:

string   $url  

[ Top ]

method print_code [line 1107]

string print_code( [array $css = NULL])

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



Tags:

version:  1.1
access:  public


Parameters:

array   $css  

[ Top ]

method property_is_next [line 1180]

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.1
access:  public


Parameters:

string   $istring  
integer   $pos  

[ Top ]

method rm_subkey [line 887]

void rm_subkey( string $find, array &$array, [string $del_val = NULL])

Removes all keys $find in $array (array[x][$find]).



Tags:

version:  1.0
access:  public


Parameters:

string   $find  
array   $array  
string   $del_val   if this is !== NULL, it only removes if the value of they key $find === $del_val

[ Top ]

method set_cfg [line 263]

bool set_cfg( string $setting, bool $value)

Set the value of a setting.



Tags:

version:  1.0
access:  public


Parameters:

string   $setting  
bool   $value  

[ Top ]

method shorthand [line 308]

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 412]

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 usort_properties [line 1084]

integer usort_properties( string $val1, string $val2)

Sort function for sorting the properties



Tags:

version:  1.0
access:  public


Parameters:

string   $val1  
string   $val2  

[ Top ]


Documentation generated on Sat, 20 Aug 2005 17:04:08 +0200 by phpDocumentor 1.3.0RC3