.

JCSSManager Class Reference

Helepr class for JCSSMAnager. More...

List of all members.

Static Public Member Functions

static  collect_and_compress ()
  Collect and compres all JS and CSS.
static  concat_css_files ($arr_files)
static  get_css_types ()
  Returns all possible CSS types.
static  get_types ()
  Returns all possible types.
static  make_absolute ($path)
  Make path relativ to web root an absolute one.
static  make_relativ ($path)
  Make path relativ to web root.
static  transform_css_file ($file)

Public Attributes

const  TYPE_CSS = 'CSS'
const  TYPE_CSS_IE50 = 'CSS_IE50'
const  TYPE_CSS_IE55 = 'CSS_IE55'
const  TYPE_CSS_IE6 = 'CSS_IE6'
const  TYPE_CSS_IE7 = 'CSS_IE7'
const  TYPE_JS = 'JS'

Detailed Description

Helepr class for JCSSMAnager.

Definition at line 5 of file jcssmanager.cls.php.


Member Function Documentation

static JCSSManager::collect_and_compress (  )  [static]

Collect and compres all JS and CSS.

Returns:
Status

Definition at line 65 of file jcssmanager.cls.php.

00065                                                       {
00066                 $err = new Status();
00067                 Load::commands('jcssmanager/compress.js', 'jcssmanager/compress.css');
00068                 Load::models('jcsscompressedfiles');
00069                 
00070                 $out_file = Config::get_value(Config::URL_ABSPATH) . Config::get_value(ConfigJCSSManager::JS_DIR) . 'compressed.js';
00071                 $in_files = array();
00072                 EventSource::Instance()->invoke_event('jcssmanager_compress', JCSSManager::TYPE_JS, $in_files);
00073                 $js = new JCSSManagerCompressJSCommand($in_files, $out_file);
00074                 $err->merge($js->execute());
00075                 
00076                 $css_base = Config::get_value(ConfigJCSSManager::CSS_DIR);
00077                 foreach(JCSSManager::get_css_types() as $type => $tr) {
00078                         $out_file = ($type !== JCSSManager::TYPE_CSS) ? 'compressed.' . strtolower($type) . '.css' : 'compressed.css';
00079                         $out_file = JCSSManager::make_absolute($css_base . $out_file);
00080                         $in_files = array();
00081                         EventSource::Instance()->invoke_event('jcssmanager_compress', $type, $in_files);
00082                         $css = new JCSSManagerCompressCSSCommand($in_files, $out_file, $type);
00083                         $err->merge($css->execute());
00084                 }               
00085 
00086                 // Update htaccess
00087                 if ($err->is_ok()) {
00088                         $err->merge(self::update_htaccess());
00089                 }
00090                 return $err;
00091         }
static JCSSManager::concat_css_files ( arr_files  )  [static]

Definition at line 141 of file jcssmanager.cls.php.

00141                                                             {
00142                 $ret = '';
00143                 foreach($arr_files as $file) {
00144                         $ret .= self::transform_css_file($file);
00145                 }
00146                 return $ret;
00147         }
static JCSSManager::get_css_types (  )  [static]

Returns all possible CSS types.

Returns:
array

Definition at line 30 of file jcssmanager.cls.php.

00030                                                {
00031                 return array(
00032                         self::TYPE_CSS => tr(self::TYPE_CSS, 'jcssmanager'),
00033                         self::TYPE_CSS_IE50 => tr(self::TYPE_CSS_IE50, 'jcssmanager'),
00034                         self::TYPE_CSS_IE55 => tr(self::TYPE_CSS_IE55, 'jcssmanager'),
00035                         self::TYPE_CSS_IE6 => tr(self::TYPE_CSS_IE6, 'jcssmanager'),
00036                         self::TYPE_CSS_IE7 => tr(self::TYPE_CSS_IE7, 'jcssmanager'),
00037                 );              
00038         }
static JCSSManager::get_types (  )  [static]

Returns all possible types.

Returns:
array

Definition at line 18 of file jcssmanager.cls.php.

00018                                            {
00019                 return array_merge(
00020                         array(self::TYPE_JS => tr(self::TYPE_JS, 'jcssmanager')),
00021                         self::get_css_types()
00022                 );
00023         }
static JCSSManager::make_absolute ( path  )  [static]

Make path relativ to web root an absolute one.

Parameters:
string  $path
Returns:
string

Definition at line 56 of file jcssmanager.cls.php.

00056                                                     {
00057                 return Config::get_value(Config::URL_ABSPATH) . $path;
00058         }
static JCSSManager::make_relativ ( path  )  [static]

Make path relativ to web root.

Parameters:
string  $path
Returns:
string

Definition at line 46 of file jcssmanager.cls.php.

00046                                                    {
00047                 return str_replace(Config::get_value(Config::URL_ABSPATH), '', $path);
00048         }
static JCSSManager::transform_css_file ( file  )  [static]

Definition at line 149 of file jcssmanager.cls.php.

00149                                                          {
00150                 $ret = '';
00151                 if (substr($file, 0, 1) !== '/') {
00152                         $file = Config::get_value(Config::URL_ABSPATH) . $file;
00153                 }
00154                 $handle = fopen($file, 'r');
00155                 $regex = '@(url\s*\(\s*"?)([\w.][^"\)]*)@';
00156                 $rel_path = str_replace(Config::get_value(Config::URL_ABSPATH), '/', realpath($file));
00157                 $replace = '$1' .  dirname($rel_path) . '/$2'; 
00158                 while(($line = fgets($handle)) !== false) {
00159                         // Works around a bug in WebKit, which dislikes two charset declarations in one file
00160                         $line = trim($line);
00161                         $token = substr($line, 0, 7);
00162                         if ($token === '@charse') {
00163                                 continue;
00164                         }
00165                         // Resolve imports                      
00166                         if ($token === '@import') {
00167                                 $start = strpos($line, '(', 7);
00168                                 if ($start !== false) {
00169                                         $end = strpos($line, ')', $start);
00170                                         if ($end !== false) {
00171                                                 $start++;
00172                                                 $file_to_include = trim(substr($line, $start, $end - $start), "'\" \t");
00173                                                 if (substr($file_to_include, 0, 1) !== '/') {
00174                                                         $file_to_include = dirname($file) . '/' . $file_to_include;
00175                                                 }
00176                                                 else {
00177                                                         $file_to_include = JCSSManager::make_absolute($file_to_include);
00178                                                 }
00179                                                 $line = self::transform_css_file($file_to_include);
00180                                         }
00181                                 }
00182                         }
00183                         // Set all url(..) stuff absolute
00184                         $line = preg_replace($regex, $replace, $line);
00185                         $ret .= $line;
00186                 }
00187 
00188                 return $ret;            
00189         }

Member Data Documentation

const JCSSManager::TYPE_CSS = 'CSS'

Definition at line 7 of file jcssmanager.cls.php.

const JCSSManager::TYPE_CSS_IE50 = 'CSS_IE50'

Definition at line 8 of file jcssmanager.cls.php.

const JCSSManager::TYPE_CSS_IE55 = 'CSS_IE55'

Definition at line 9 of file jcssmanager.cls.php.

const JCSSManager::TYPE_CSS_IE6 = 'CSS_IE6'

Definition at line 10 of file jcssmanager.cls.php.

const JCSSManager::TYPE_CSS_IE7 = 'CSS_IE7'

Definition at line 11 of file jcssmanager.cls.php.

const JCSSManager::TYPE_JS = 'JS'

Definition at line 6 of file jcssmanager.cls.php.


The documentation for this class was generated from the following file: