2017-02-14 12:22:40 +01:00
|
|
|
#!/usr/bin/env php
|
2016-11-17 17:01:26 +01:00
|
|
|
<?php
|
2017-07-06 16:04:40 +02:00
|
|
|
/**
|
|
|
|
* IFM compiler
|
|
|
|
*
|
|
|
|
* This script compiles all sources into one single file.
|
|
|
|
*/
|
2016-11-17 17:01:26 +01:00
|
|
|
|
2017-07-06 16:04:40 +02:00
|
|
|
chdir( realpath( dirname( __FILE__ ) ) );
|
2016-11-17 17:01:26 +01:00
|
|
|
|
2017-07-31 11:34:07 +02:00
|
|
|
$IFM_SRC_PHP = array(
|
|
|
|
0 => "src/main.php",
|
|
|
|
1 => "src/ifmarchive.php",
|
|
|
|
2 => "src/htpasswd.php"
|
|
|
|
);
|
2016-11-17 17:01:26 +01:00
|
|
|
|
2017-07-06 16:04:40 +02:00
|
|
|
$IFM_BUILD_STANDALONE = "ifm.php";
|
2017-07-31 11:34:07 +02:00
|
|
|
$IFM_BUILD_STANDALONE_COMPRESSED = "build/ifm.min.php";
|
2017-07-18 13:51:23 +02:00
|
|
|
$IFM_BUILD_LIB_PHP = "build/libifm.php";
|
2016-11-17 17:01:26 +01:00
|
|
|
|
2017-08-08 17:48:39 +02:00
|
|
|
$options = getopt( null, array( "language::" ) );
|
|
|
|
$vars['languages'] = isset( $options['language'] ) ? explode( ',', $options['language'] ) : array( "en" );
|
|
|
|
$vars['defaultlanguage'] = $vars['languages'][0];
|
|
|
|
$vars['languageincludes'] = "";
|
|
|
|
foreach( $vars['languages'] as $l ) {
|
|
|
|
if( file_exists( "src/i18n/".$l.".json" ) )
|
|
|
|
$vars['languageincludes'] .=
|
|
|
|
'$i18n["'.$l.'"] = <<<\'f00bar\'' . "\n"
|
|
|
|
. file_get_contents( "src/i18n/".$l.".json" ) . "\n"
|
|
|
|
. 'f00bar;' . "\n"
|
|
|
|
. '$i18n["'.$l.'"] = json_decode( $i18n["'.$l.'"], true );' . "\n" ;
|
|
|
|
else
|
|
|
|
print "WARNING: Language file src/i18n/".$l.".json not found.\n";
|
|
|
|
}
|
|
|
|
|
2017-07-06 16:04:40 +02:00
|
|
|
/**
|
2017-07-31 11:34:07 +02:00
|
|
|
* Concat PHP Files
|
2017-07-06 16:04:40 +02:00
|
|
|
*/
|
2017-07-31 11:34:07 +02:00
|
|
|
$compiled = array( "<?php" );
|
|
|
|
foreach( $IFM_SRC_PHP as $phpfile ) {
|
|
|
|
$lines = file( $phpfile );
|
|
|
|
unset( $lines[0] ); // remove <?php line
|
|
|
|
$compiled = array_merge( $compiled, $lines );
|
2016-11-17 17:01:26 +01:00
|
|
|
}
|
2017-07-31 11:34:07 +02:00
|
|
|
$compiled = join( $compiled );
|
2016-11-17 17:01:26 +01:00
|
|
|
|
2017-07-06 16:04:40 +02:00
|
|
|
/**
|
2017-08-08 17:48:39 +02:00
|
|
|
* Process file includes
|
2017-07-06 16:04:40 +02:00
|
|
|
*/
|
2017-07-31 11:34:07 +02:00
|
|
|
$includes = NULL;
|
|
|
|
preg_match_all( "/\@\@\@file:([^\@]+)\@\@\@/", $compiled, $includes, PREG_SET_ORDER );
|
2017-08-08 17:48:39 +02:00
|
|
|
foreach( $includes as $file )
|
2017-07-31 11:34:07 +02:00
|
|
|
$compiled = str_replace( $file[0], file_get_contents( $file[1] ), $compiled );
|
2017-08-08 17:48:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process variable includes
|
|
|
|
*/
|
|
|
|
$includes = NULL;
|
|
|
|
preg_match_all( "/\@\@\@vars:([^\@]+)\@\@\@/", $compiled, $includes, PREG_SET_ORDER );
|
|
|
|
foreach( $includes as $var )
|
|
|
|
$compiled = str_replace( $var[0], $vars[$var[1]], $compiled );
|
2017-07-06 16:04:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Build standalone script
|
|
|
|
*/
|
2017-07-31 11:34:07 +02:00
|
|
|
file_put_contents( $IFM_BUILD_STANDALONE, $compiled );
|
2017-07-18 13:34:29 +02:00
|
|
|
file_put_contents( $IFM_BUILD_STANDALONE, '
|
2017-07-18 13:51:23 +02:00
|
|
|
/**
|
|
|
|
* start IFM
|
|
|
|
*/
|
|
|
|
$ifm = new IFM();
|
|
|
|
$ifm->run();
|
2017-07-18 13:34:29 +02:00
|
|
|
', FILE_APPEND );
|
|
|
|
|
2017-07-18 13:32:38 +02:00
|
|
|
/**
|
2017-07-18 13:34:29 +02:00
|
|
|
* Build compressed standalone script
|
2017-07-18 14:04:56 +02:00
|
|
|
* file_put_contents( $IFM_BUILD_STANDALONE_COMPRESSED, '<?php eval( gzdecode( file_get_contents( __FILE__, false, null, 85 ) ) ); exit(0); ?>' . gzencode( file_get_contents( "ifm.php", false, null, 5 ) ) );
|
|
|
|
*/
|
2017-07-06 16:04:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Build library
|
|
|
|
*/
|
2017-07-31 11:34:07 +02:00
|
|
|
file_put_contents( $IFM_BUILD_LIB_PHP, $compiled );
|