72 $this->Cache =
get_package(
'cache' ,
'last' , __FILE__ );
73 $this->CachedMultyFS =
get_package(
'cached_multy_fs' ,
'last' , __FILE__ );
74 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
75 $this->String =
get_package(
'string' ,
'last' , __FILE__ );
76 $this->Tags =
get_package(
'string::tags' ,
'last' , __FILE__ );
77 $this->Trace =
get_package(
'trace' ,
'last' , __FILE__ );
107 private function compress_stylesheets( $Files )
111 $Compressed = array();
113 foreach( $Files as $k => $v )
115 $v = $this->String->clear_ultimix_tags( $v );
118 $Compressed[
'join' ] [] = $v[
'path' ];
122 $Key = str_replace(
'././' ,
'./' , dirname( $v[
'path' ] ) );
123 if( isset( $Compressed[ $Key ] ) ==
false )
125 $Compressed[ $Key ] = array();
127 $Compressed[ $Key ] [] = basename( $v[
'path' ] );
131 return( $Compressed );
133 catch( Exception $e )
161 private function fill_file( $FileName , $Files )
165 $Handle = fopen( dirname( __FILE__ ).
"/tmp/$FileName.css" ,
"wb" );
167 foreach( $Files as $k2 => $v2 )
169 $Content = $this->CachedMultyFS->file_get_contents(
"$v2" );
170 fwrite( $Handle , $Content );
171 fwrite( $Handle ,
"\r\n" );
176 catch( Exception $e )
208 private function stylesheets_join1( $Files , $RetFiles )
212 $FilesHash = md5(
implode_ex(
'' , $Files ,
'path' ) );
213 $UnionFilePath = dirname( __FILE__ ).
"/tmp/$FilesHash.css";
215 if( $this->CachedMultyFS->file_exists( $UnionFilePath ) ===
false ||
216 $this->Cache->get_data( $UnionFilePath ) === false )
218 $this->fill_file( $FilesHash , $Files );
220 $RetFiles [] = array(
226 $RetFiles [] = array(
233 catch( Exception $e )
269 private function stylesheets_join3( $Path , $Files , $RetFiles )
273 $FilesHash = md5( implode(
'' , $Files ) );
274 $UnionFilePath =
"$Path/$FilesHash.css";
276 if( $this->CachedMultyFS->file_exists( $UnionFilePath ) ===
false ||
277 $this->Cache->get_data( $UnionFilePath ) === false )
279 $Handle = fopen( $UnionFilePath ,
"wb" );
281 foreach( $Files as $k2 => $v2 )
283 $Content = $this->CachedMultyFS->file_get_contents(
"$Path/$v2" );
284 fwrite( $Handle , $Content );
285 fwrite( $Handle ,
"\r\n" );
291 $RetFiles [] = array(
'path' => str_replace(
'./' ,
'{http_host}/' , $UnionFilePath ) );
295 catch( Exception $e )
323 private function join_compressed_stylesheets( $Compressed )
329 foreach( $Compressed as $k1 => $v1 )
333 $RetFiles = $this->stylesheets_join1( $v1 , $RetFiles );
335 elseif( count( $v1 ) == 1 )
337 $RetFiles [] = array(
'path' => str_replace(
'./' ,
'{http_host}/' ,
"$k1/".$v1[ 0 ] ) );
341 $RetFiles = $this->stylesheets_join3( $k1 ,$v1 , $RetFiles );
347 catch( Exception $e )
379 if( is_array( $Files ) && count( $Files ) > 0 )
381 $Compressed = $this->compress_stylesheets( $Files );
383 $RetFiles = $this->join_compressed_stylesheets( $Compressed );
392 catch( Exception $e )
416 private function get_stylesheets_content()
422 $Start = $this->CachedMultyFS->get_template( __FILE__ ,
'stylesheet_link_start.tpl' );
423 $End = $this->CachedMultyFS->get_template( __FILE__ ,
'stylesheet_link_end.tpl' );
425 return( $Start.implode_ex( $End.$Start , $this->CSSFiles ,
'path' ).$End );
427 catch( Exception $e )
461 if( is_array( $this->CSSFiles ) && count( $this->CSSFiles ) )
463 $Content = $this->get_stylesheets_content();
466 $this->CSSFiles = array();
470 catch( Exception $e )
502 if( $this->PageComposer ===
false )
504 $this->PageComposer =
get_package(
'page::page_composer' ,
'last' , __FILE__ );
506 $Path = $this->PageComposer->Template->compile_string( $Path );
507 $Path = str_replace(
'/./' ,
'/' , $Path );
508 foreach( $this->CSSFiles as $k => $v )
510 if( $v[
'path' ] == $Path )
515 $this->CSSFiles [] = array(
'path' => $Path ,
'join' => $Join );
517 catch( Exception $e )