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__ );
111 private function scripts_join1( $Files , $Handle )
117 foreach( $Files as $k => $v )
121 if( strpos( $v[
'path' ] ,
'{http_host}/' ) === 0 )
123 $v[
'path' ] = str_replace(
'{http_host}/' ,
'./' , $v[
'path' ] );
125 $v[
'path' ] = $this->Tags->compile_ultimix_tags( $v[
'path' ] );
126 $Content = $this->CachedMultyFS->file_get_contents( $v[
'path' ] );
127 fwrite( $Handle ,
"$Content\r\n" );
131 $RetFiles [] = array(
'path' => $v[
'path' ] );
137 catch( Exception $e )
165 private function scripts_join2( $Files )
171 foreach( $Files as $k => $v )
175 $RetFiles [] = array(
'path' => $v[
'path' ] );
181 catch( Exception $e )
209 private function join_compressed_scripts( $Files )
213 $FilesHash = md5(
implode_ex(
'' , $Files ,
'path' ) );
214 $UnionFilePath = dirname( __FILE__ ).
"/tmp/$FilesHash.js";
216 if( $this->CachedMultyFS->file_exists( $UnionFilePath ) ===
false ||
217 $this->Cache->get_data( $UnionFilePath ) === false )
219 $Handle = fopen( dirname( __FILE__ ).
"/tmp/$FilesHash.js" ,
"wb" );
221 $RetFiles = $this->scripts_join1( $Files , $Handle );
227 $RetFiles = $this->scripts_join2( $Files );
232 catch( Exception $e )
264 if( is_array( $Files ) && count( $Files ) > 0 )
266 $RetFiles = $this->join_compressed_scripts( $Files );
268 $FilesHash = md5(
implode_ex(
'' , $Files ,
'path' ) );
270 $UnionFilePath = dirname( __FILE__ ).
"/tmp/$FilesHash.js";
272 $RetFiles [] = array(
273 'path' => str_replace(
285 catch( Exception $e )
309 private function get_scripts_content()
313 $PageName = $this->Security->get_gp(
'page_name' ,
'command' );
315 if( $this->Cache->data_exists(
"$PageName scripts" ) )
317 $Content = $this->Cache->get_data(
"$PageName scripts" );
322 $Start = $this->CachedMultyFS->get_template( __FILE__ ,
'script_link_start.tpl' );
323 $End = $this->CachedMultyFS->get_template( __FILE__ ,
'script_link_end.tpl' );
324 $Content = $Start.implode_ex( $End.$Start , $this->JSFiles ,
'path' ).$End;
326 $this->Cache->add_data(
"$PageName scripts" , $Content );
331 catch( Exception $e )
365 if( is_array( $this->JSFiles ) && count( $this->JSFiles ) )
367 $Content = $this->get_scripts_content();
370 $this->JSFiles = array();
374 catch( Exception $e )
406 if( $this->PageComposer ===
false )
408 $this->PageComposer =
get_package(
'page::page_composer' ,
'last' , __FILE__ );
410 $Path = $this->PageComposer->Template->compile_string( $Path );
411 foreach( $this->JSFiles as $k => $v )
413 if( $v[
'path' ] == $Path )
418 $this->JSFiles [] = array(
'path' => $Path ,
'join' => $Join );
420 catch( Exception $e )