2012-05-25 23:21:31 -07:00
#!/usr/bin/env php
2007-07-02 05:51:26 +00:00
< ? php
2025-02-25 17:17:31 +01:00
include __DIR__ . " /adminer/include/version.inc.php " ;
include __DIR__ . " /adminer/include/errors.inc.php " ;
include __DIR__ . " /externals/JsShrink/jsShrink.php " ;
2025-03-15 09:38:06 +01:00
include __DIR__ . " /externals/PhpShrink/phpShrink.php " ;
2009-05-29 14:53:42 +00:00
2025-03-15 09:10:43 +01:00
function add_apo_slashes ( $s ) {
return addcslashes ( $s , " \\ ' " );
}
2012-09-26 21:45:04 -07:00
function add_quo_slashes ( $s ) {
$return = $s ;
$return = addcslashes ( $return , " \n \r \$ \" \\ " );
$return = preg_replace ( '~\0(?![0-7])~' , '\\\\0' , $return );
$return = addcslashes ( $return , " \0 " );
return $return ;
2012-09-06 22:15:03 -07:00
}
2007-07-05 07:34:42 +00:00
function remove_lang ( $match ) {
2007-07-26 16:47:28 +00:00
$idf = strtr ( $match [ 2 ], array ( " \\ ' " => " ' " , " \\ \\ " => " \\ " ));
2025-03-29 22:43:44 +01:00
$s = ( Adminer\Lang :: $translations [ $idf ] ? : $idf );
2009-06-21 23:20:32 +00:00
if ( $match [ 3 ] == " , " ) { // lang() has parameters
2018-02-06 16:25:58 +01:00
return $match [ 1 ] . ( is_array ( $s ) ? " lang(array(' " . implode ( " ', ' " , array_map ( 'add_apo_slashes' , $s )) . " '), " : " sprintf(' " . add_apo_slashes ( $s ) . " ', " );
2007-07-09 15:28:37 +00:00
}
return ( $match [ 1 ] && $match [ 4 ] ? $s : " $match[1] ' " . add_apo_slashes ( $s ) . " ' $match[4] " );
2007-07-05 07:34:42 +00:00
}
2008-05-23 14:46:52 +00:00
function lang_ids ( $match ) {
global $lang_ids ;
2009-07-11 19:45:57 +00:00
$lang_id = & $lang_ids [ stripslashes ( $match [ 1 ])];
2012-05-13 23:54:07 -07:00
if ( $lang_id === null ) {
2009-07-11 19:45:57 +00:00
$lang_id = count ( $lang_ids ) - 1 ;
}
2009-09-10 19:05:27 +00:00
return ( $_SESSION [ " lang " ] ? $match [ 0 ] : " lang( $lang_id $match[2] " );
2008-05-23 14:46:52 +00:00
}
2007-07-02 05:51:26 +00:00
function put_file ( $match ) {
2025-03-17 05:54:24 +01:00
global $project , $vendor ;
2025-03-28 18:11:26 +01:00
if ( preg_match ( '~LANG~' , $match [ 2 ])) {
2009-07-11 19:45:57 +00:00
return $match [ 0 ]; // processed later
2007-07-26 16:47:28 +00:00
}
2025-02-25 17:17:31 +01:00
$return = file_get_contents ( __DIR__ . " / $project / $match[2] " );
2025-03-11 06:30:31 +01:00
$return = preg_replace ( '~namespace Adminer;\s*~' , '' , $return );
2025-03-17 05:54:24 +01:00
if ( $vendor && preg_match ( '~/drivers/~' , $match [ 2 ])) {
$return = preg_replace ( '~^if \(isset\(\$_GET\["' . $vendor . '"]\)\) \{(.*)^}~ms' , '\1' , $return );
2025-02-24 10:05:31 +01:00
// check function definition in drivers
2025-03-17 05:54:24 +01:00
if ( $vendor != " mysql " ) {
2025-02-24 10:05:31 +01:00
preg_match_all (
'~\bfunction ([^(]+)~' ,
2025-03-05 14:12:42 +01:00
preg_replace ( '~class Driver.*\n\t}~sU' , '' , file_get_contents ( __DIR__ . " /adminer/drivers/mysql.inc.php " )),
2025-02-24 10:05:31 +01:00
$matches
); //! respect context (extension, class)
$functions = array_combine ( $matches [ 1 ], $matches [ 0 ]);
2025-02-25 06:30:16 +01:00
$requires = array (
" copy " => array ( " copy_tables " ),
2025-03-18 13:29:48 +01:00
" database " => array ( " create_database " , " rename_database " , " drop_databases " , " move_tables " ),
2025-02-25 06:30:16 +01:00
" dump " => array ( " use_sql " , " create_sql " , " truncate_sql " , " trigger_sql " ),
" kill " => array ( " kill_process " , " connection_id " , " max_connections " ),
" processlist " => array ( " process_list " ),
2025-02-26 16:31:20 +01:00
" routine " => array ( " routines " , " routine " , " routine_languages " , " routine_id " ),
2025-02-25 06:30:16 +01:00
" scheme " => array ( " schemas " , " get_schema " , " set_schema " ),
2025-03-18 13:29:48 +01:00
" sql " => array ( " multi_query " , " store_result " , " next_result " , " explain " ),
2025-02-25 06:30:16 +01:00
" status " => array ( " show_status " ),
2025-03-18 13:29:48 +01:00
" indexes " => array ( " alter_indexes " ),
" table " => array ( " auto_increment " ),
2025-02-25 06:30:16 +01:00
" trigger " => array ( " triggers " , " trigger " , " trigger_options " , " trigger_sql " ),
2025-02-26 23:55:17 +01:00
" type " => array ( " types " , " type_values " ),
2025-02-25 06:30:16 +01:00
" variables " => array ( " show_variables " ),
2025-03-18 13:29:48 +01:00
" view " => array ( " drop_views " , " view " ),
2025-02-25 06:30:16 +01:00
);
foreach ( $requires as $support => $fns ) {
2025-03-05 13:14:21 +01:00
if ( ! Adminer\support ( $support )) {
2025-02-25 06:30:16 +01:00
foreach ( $fns as $fn ) {
unset ( $functions [ $fn ]);
}
}
}
2025-03-28 22:55:50 +01:00
unset ( $functions [ " __construct " ], $functions [ " __destruct " ], $functions [ " set_charset " ], $functions [ " multi_query " ], $functions [ " store_result " ], $functions [ " next_result " ]);
2025-02-24 10:05:31 +01:00
foreach ( $functions as $val ) {
if ( ! strpos ( $return , " $val ( " )) {
2025-03-17 05:54:24 +01:00
fprintf ( STDERR , " Missing $val in $vendor\n " );
2025-02-24 10:05:31 +01:00
}
}
}
2021-02-08 19:56:15 +01:00
}
2009-09-10 19:05:27 +00:00
if ( basename ( $match [ 2 ]) != " lang.inc.php " || ! $_SESSION [ " lang " ]) {
2013-04-28 00:26:29 -07:00
if ( basename ( $match [ 2 ]) == " lang.inc.php " ) {
2025-03-28 09:03:09 +01:00
$return = str_replace ( 'function lang(string $idf, $number = null): string {' , ' function lang ( $idf , $number = null ) {
2013-04-28 00:26:29 -07:00
if ( is_string ( $idf )) { // compiled version uses numbers, string comes from a plugin
// English translation is closest to the original identifiers //! pluralized translations are not found
$pos = array_search ( $idf , get_translations ( " en " )); //! this should be cached
if ( $pos !== false ) {
$idf = $pos ;
}
} ' , $return , $count );
if ( ! $count ) {
echo " lang() not found \n " ;
}
}
2009-06-21 23:20:32 +00:00
$tokens = token_get_all ( $return ); // to find out the last token
2009-06-01 16:20:06 +00:00
return " ?> \n $return " . ( in_array ( $tokens [ count ( $tokens ) - 1 ][ 0 ], array ( T_CLOSE_TAG , T_INLINE_HTML ), true ) ? " <?php " : " " );
2018-02-20 16:27:40 +01:00
} elseif ( preg_match ( '~\s*(\$pos = (.+\n).+;)~sU' , $return , $match2 )) {
2009-06-21 23:20:32 +00:00
// single language lang() is used for plural
2025-04-04 16:20:51 +02:00
return " define('Adminer \\ LANG', ' $_SESSION[lang] ');
2010-12-30 13:53:39 +01:00
2013-04-28 00:26:29 -07:00
function lang ( \ $translation , \ $number = null ) {
2013-04-27 23:36:43 -07:00
if ( is_array ( \ $translation )) {
2025-03-15 02:32:00 +01:00
\ $pos = $match2 [ 2 ] \t\t\t : " . (preg_match( " ~ '$_SESSION[lang]' .* \\ ? ( .+ ) \n ~ U " , $match2[1] , $match3 ) ? $match3[1] : " 1 " ) . '
2013-04-27 23:36:43 -07:00
);
$translation = $translation [ $pos ];
}
$translation = str_replace ( " %d " , " %s " , $translation );
2014-03-19 21:56:42 -07:00
$number = format_number ( $number );
2012-06-04 17:44:04 -07:00
return sprintf ( $translation , $number );
2010-12-30 13:53:39 +01:00
}
' ;
2009-06-01 16:20:06 +00:00
} else {
2013-04-28 00:26:29 -07:00
echo " lang() \$ pos not found \n " ;
2007-07-02 05:51:26 +00:00
}
}
2012-09-02 06:44:32 -07:00
function lzw_compress ( $string ) {
// compression
$dictionary = array_flip ( range ( " \0 " , " \xFF " ));
$word = " " ;
$codes = array ();
for ( $i = 0 ; $i <= strlen ( $string ); $i ++ ) {
2020-12-09 15:09:28 +01:00
$x = @ $string [ $i ];
2012-09-02 06:44:32 -07:00
if ( strlen ( $x ) && isset ( $dictionary [ $word . $x ])) {
$word .= $x ;
} elseif ( $i ) {
$codes [] = $dictionary [ $word ];
$dictionary [ $word . $x ] = count ( $dictionary );
$word = $x ;
}
}
// convert codes to binary string
$dictionary_count = 256 ;
$bits = 8 ; // ceil(log($dictionary_count, 2))
$return = " " ;
$rest = 0 ;
$rest_length = 0 ;
foreach ( $codes as $code ) {
$rest = ( $rest << $bits ) + $code ;
$rest_length += $bits ;
$dictionary_count ++ ;
if ( $dictionary_count >> $bits ) {
$bits ++ ;
}
while ( $rest_length > 7 ) {
$rest_length -= 8 ;
$return .= chr ( $rest >> $rest_length );
$rest &= ( 1 << $rest_length ) - 1 ;
}
}
return $return . ( $rest_length ? chr ( $rest << ( 8 - $rest_length )) : " " );
}
2009-07-11 19:45:57 +00:00
function put_file_lang ( $match ) {
2025-03-28 18:26:48 +01:00
global $lang_ids , $project ;
2009-09-10 19:05:27 +00:00
if ( $_SESSION [ " lang " ]) {
2009-07-11 19:45:57 +00:00
return " " ;
}
2012-09-03 15:59:05 -07:00
$return = " " ;
2025-03-28 18:26:48 +01:00
foreach ( Adminer\langs () as $lang => $val ) {
2025-03-29 22:43:44 +01:00
include __DIR__ . " /adminer/lang/ $lang .inc.php " ;
2009-07-11 19:45:57 +00:00
$translation_ids = array_flip ( $lang_ids ); // default translation
2025-03-29 22:43:44 +01:00
foreach ( Adminer\Lang :: $translations as $key => $val ) {
2012-05-13 23:54:07 -07:00
if ( $val !== null ) {
2012-09-03 15:59:05 -07:00
$translation_ids [ $lang_ids [ $key ]] = implode ( " \t " , ( array ) $val );
2009-07-11 19:45:57 +00:00
}
}
2012-09-26 21:45:04 -07:00
$return .= '
case " ' . $lang . ' " : $compressed = " ' . add_quo_slashes(lzw_compress(implode( " \n " , $translation_ids ))) . ' " ; break ; ' ;
2009-07-11 19:45:57 +00:00
}
2012-09-03 15:59:05 -07:00
$translations_version = crc32 ( $return );
2025-03-29 22:43:44 +01:00
return ' Lang :: $translations = $_SESSION [ " translations " ];
if ( $_SESSION [ " translations_version " ] != LANG . ' . $translations_version . ' ) {
Lang :: $translations = array ();
$_SESSION [ " translations_version " ] = LANG . ' . $translations_version . ' ;
}
if ( ! Lang :: $translations ) {
Lang :: $translations = get_translations ( LANG );
$_SESSION [ " translations " ] = Lang :: $translations ;
2012-09-03 15:00:06 -07:00
}
2013-04-28 00:26:29 -07:00
function get_translations ( $lang ) {
switch ( $lang ) { ' . $return . '
2012-09-03 15:59:05 -07:00
}
$translations = array ();
2012-09-26 21:45:04 -07:00
foreach ( explode ( " \n " , lzw_decompress ( $compressed )) as $val ) {
2012-09-03 15:59:05 -07:00
$translations [] = ( strpos ( $val , " \t " ) ? explode ( " \t " , $val ) : $val );
}
2013-04-28 00:26:29 -07:00
return $translations ;
}
2012-09-02 06:44:32 -07:00
' ;
2009-07-11 19:45:57 +00:00
}
2009-06-26 20:43:41 +00:00
function minify_css ( $file ) {
2025-03-26 00:08:16 +01:00
global $project ;
if ( $project == " editor " ) {
2025-04-04 07:39:08 +02:00
$file = preg_replace ( '~.*url\(data:image/gif.*~' , '' , $file );
2025-03-26 00:08:16 +01:00
}
2025-04-04 07:39:08 +02:00
$file = preg_replace_callback ( '~url\((\w+\.(gif|png|jpg))\)~' , function ( $match ) {
return " url(data:image/ $match[2] ;base64, " . base64_encode ( file_get_contents ( __DIR__ . " /adminer/static/ $match[1] " )) . " ) " ; // we don't have ME in *.css; logo.png is still used for apple-touch-icon
}, $file );
2025-03-13 18:00:54 +01:00
return lzw_compress ( preg_replace ( '~\s*([:;{},])\s*~' , '\1' , preg_replace ( '~/\*.*?\*/\s*~s' , '' , $file )));
2009-06-26 20:43:41 +00:00
}
2012-09-06 22:23:27 -07:00
function minify_js ( $file ) {
2025-03-27 10:11:35 +01:00
$file = preg_replace_callback ( " ~'use strict';~ " , function ( $match ) { // keep only the first one
static $count = 0 ;
$count ++ ;
return ( $count == 1 ? $match [ 0 ] : '' );
}, $file );
2012-09-06 22:23:27 -07:00
if ( function_exists ( 'jsShrink' )) {
$file = jsShrink ( $file );
}
2012-09-06 22:37:24 -07:00
return lzw_compress ( $file );
2012-09-06 22:23:27 -07:00
}
2025-03-26 22:22:14 +01:00
function compile_file ( $match , $callback = '' ) { // $callback only to match signature
2009-07-13 21:40:43 +00:00
global $project ;
2012-09-06 22:23:27 -07:00
$file = " " ;
2014-01-30 08:27:56 -08:00
list (, $filenames , $callback ) = $match ;
if ( $filenames != " " ) {
2025-03-07 07:44:26 +01:00
foreach ( preg_split ( '~;\s*~' , $filenames ) as $filename ) {
2025-02-25 17:17:31 +01:00
$file .= file_get_contents ( __DIR__ . " / $project / $filename " );
2014-01-30 08:27:56 -08:00
}
2012-09-06 22:23:27 -07:00
}
2014-01-30 08:27:56 -08:00
if ( $callback ) {
$file = call_user_func ( $callback , $file );
2012-09-06 22:37:24 -07:00
}
2012-09-26 21:45:04 -07:00
return '"' . add_quo_slashes ( $file ) . '"' ;
2009-06-26 20:43:41 +00:00
}
2018-02-06 15:52:48 +01:00
function number_type () {
return '' ;
}
2025-02-26 16:15:55 +01:00
function ini_bool () {
return true ;
}
2012-09-22 07:53:50 -07:00
$project = " adminer " ;
if ( $_SERVER [ " argv " ][ 1 ] == " editor " ) {
$project = " editor " ;
array_shift ( $_SERVER [ " argv " ]);
}
2025-03-17 05:54:24 +01:00
$vendor = " " ;
2025-02-25 17:27:48 +01:00
$driver_path = " /adminer/drivers/ " . $_SERVER [ " argv " ][ 1 ] . " .inc.php " ;
if ( ! file_exists ( __DIR__ . $driver_path )) {
$driver_path = " /plugins/drivers/ " . $_SERVER [ " argv " ][ 1 ] . " .php " ;
}
if ( file_exists ( __DIR__ . $driver_path )) {
2025-03-17 05:54:24 +01:00
$vendor = $_SERVER [ " argv " ][ 1 ];
2010-04-21 12:01:32 +00:00
array_shift ( $_SERVER [ " argv " ]);
}
2009-09-10 19:05:27 +00:00
unset ( $_COOKIE [ " adminer_lang " ]);
$_SESSION [ " lang " ] = $_SERVER [ " argv " ][ 1 ]; // Adminer functions read language from session
2025-03-28 18:26:48 +01:00
include __DIR__ . " /adminer/include/functions.inc.php " ;
2025-02-25 17:17:31 +01:00
include __DIR__ . " /adminer/include/lang.inc.php " ;
2025-03-28 18:26:48 +01:00
if ( Adminer\idx ( Adminer\langs (), $_SESSION [ " lang " ])) {
2025-02-25 17:17:31 +01:00
include __DIR__ . " /adminer/lang/ $_SESSION[lang] .inc.php " ;
2012-09-22 07:53:50 -07:00
array_shift ( $_SERVER [ " argv " ]);
}
if ( $_SERVER [ " argv " ][ 1 ]) {
echo " Usage: php compile.php [editor] [driver] [lang] \n " ;
echo " Purpose: Compile adminer[-driver][-lang].php or editor[-driver][-lang].php. \n " ;
exit ( 1 );
2007-07-05 10:46:44 +00:00
}
2007-08-04 19:36:01 +00:00
2025-03-27 15:28:14 +01:00
include __DIR__ . " /adminer/include/db.inc.php " ;
2025-02-25 17:17:31 +01:00
include __DIR__ . " /adminer/include/pdo.inc.php " ;
include __DIR__ . " /adminer/include/driver.inc.php " ;
2025-03-18 13:29:48 +01:00
$features = array ( " check " , " call " => " routine " , " dump " , " event " , " privileges " , " procedure " => " routine " , " processlist " , " routine " , " scheme " , " sequence " , " sql " , " status " , " trigger " , " type " , " user " => " privileges " , " variables " , " view " );
2012-09-22 07:53:50 -07:00
$lang_ids = array (); // global variable simplifies usage in a callback function
2025-02-25 17:17:31 +01:00
$file = file_get_contents ( __DIR__ . " / $project /index.php " );
2025-03-28 17:52:49 +01:00
$file = preg_replace ( '~\*/~' , " * @version " . Adminer\VERSION . " \n */ " , $file , 1 );
2025-03-17 05:54:24 +01:00
if ( $vendor ) {
$_GET [ $vendor ] = true ; // to load the driver
2025-02-25 17:27:48 +01:00
include_once __DIR__ . $driver_path ;
2025-03-30 08:18:25 +02:00
Adminer\Db :: $instance = ( object ) array ( 'flavor' => '' , 'server_info' => '99' ); // used in support()
2012-09-22 07:53:50 -07:00
foreach ( $features as $key => $feature ) {
2025-03-05 13:14:21 +01:00
if ( ! Adminer\support ( $feature )) {
2012-09-22 07:53:50 -07:00
if ( ! is_int ( $key )) {
$feature = $key ;
2010-04-21 12:01:32 +00:00
}
2012-09-22 07:53:50 -07:00
$file = str_replace ( " } elseif (isset( \$ _GET[ \" $feature\ " ])) { \n\tinclude \ " ./ $feature .inc.php \" ; \n " , " " , $file );
2010-04-21 12:01:32 +00:00
}
}
2025-03-05 13:14:21 +01:00
if ( ! Adminer\support ( " routine " )) {
2012-09-22 07:53:50 -07:00
$file = str_replace ( " if (isset( \$ _GET[ \" callf \" ])) { \n \t \$ _GET[ \" call \" ] = \$ _GET[ \" callf \" ]; \n } \n if (isset( \$ _GET[ \" function \" ])) { \n \t \$ _GET[ \" procedure \" ] = \$ _GET[ \" function \" ]; \n } \n " , " " , $file );
2010-04-21 12:01:32 +00:00
}
2012-09-22 07:53:50 -07:00
}
2018-02-20 16:27:40 +01:00
$file = preg_replace_callback ( '~\b(include|require) "([^"]*)";~' , 'put_file' , $file );
2012-09-22 07:53:50 -07:00
$file = str_replace ( 'include "../adminer/include/coverage.inc.php";' , '' , $file );
2025-03-17 05:54:24 +01:00
if ( $vendor ) {
2025-02-25 17:27:48 +01:00
if ( preg_match ( '~^/plugins/~' , $driver_path )) {
$file = preg_replace ( '((include "..)/adminer/drivers/mysql.inc.php)' , " \\ 1 $driver_path " , $file );
}
2025-03-17 05:54:24 +01:00
$file = preg_replace ( '(include "../adminer/drivers/(?!' . preg_quote ( $vendor ) . '\.).*\s*)' , '' , $file );
2012-09-22 07:53:50 -07:00
}
2018-02-20 16:27:40 +01:00
$file = preg_replace_callback ( '~\b(include|require) "([^"]*)";~' , 'put_file' , $file ); // bootstrap.inc.php
2025-03-17 05:54:24 +01:00
if ( $vendor ) {
2012-09-22 07:53:50 -07:00
foreach ( $features as $feature ) {
2025-03-05 13:14:21 +01:00
if ( ! Adminer\support ( $feature )) {
2025-03-05 13:19:17 +01:00
$file = preg_replace ( " (( \t *) " . preg_quote ( 'if (support("' . $feature . '")' ) . " .*? \n \\ 1 \\ }( else)?)s " , '' , $file );
2010-05-28 11:13:37 +02:00
}
2010-05-21 15:42:17 +02:00
}
2025-03-28 22:39:12 +01:00
if ( $project != " editor " && count ( Adminer\SqlDriver :: $drivers ) == 1 ) {
$file = str_replace ( 'html_select("auth[driver]", SqlDriver::$drivers, DRIVER, "loginDriver(this);")' , 'input_hidden("auth[driver]", "' . ( $vendor == " mysql " ? " server " : $vendor ) . '") . "' . reset ( Adminer\SqlDriver :: $drivers ) . '"' , $file , $count );
2025-03-17 06:13:48 +01:00
if ( ! $count ) {
2025-02-25 17:43:33 +01:00
echo " auth[driver] form field not found \n " ;
}
2025-04-01 18:27:04 +02:00
$file = str_replace ( " . script( \" const authDriver = qs('#username').form['auth[driver]']; authDriver && authDriver.onchange(); \" ) " , " " , $file );
2025-03-17 06:13:48 +01:00
if ( $vendor == " sqlite " ) {
$file = str_replace ( " ); \n \t \t echo \$ this->loginFormField('server', '<tr><th>' . lang('Server') . '<td>', '<input name= \" auth[server] " , ' . \'<input type="hidden" name="auth[server]"' , $file );
}
2009-10-06 11:49:31 +00:00
}
2025-03-17 05:54:24 +01:00
$file = preg_replace ( '(;\s*../externals/jush/modules/jush-(?!textarea\.|txt\.|js\.|' . preg_quote ( $vendor == " mysql " ? " sql " : $vendor ) . '\.)[^.]+.js)' , '' , $file );
$file = preg_replace_callback ( '~doc_link\(array\((.*)\)\)~sU' , function ( $match ) use ( $vendor ) {
2019-08-28 10:57:47 +02:00
list (, $links ) = $match ;
2025-03-17 05:54:24 +01:00
$links = preg_replace ( " ~'(?!( " . ( $vendor == " mysql " ? " sql|mariadb " : $vendor ) . " )')[^']*' => [^,]*,?~ " , '' , $links );
2019-08-28 10:57:47 +02:00
return ( trim ( $links ) ? " doc_link(array( $links )) " : " '' " );
}, $file );
//! strip doc_link() definition
2013-12-19 12:34:15 -08:00
}
if ( $project == " editor " ) {
2025-03-15 01:49:42 +01:00
$file = preg_replace ( '~;.\.\/externals/jush/jush(-dark)?\.css~' , '' , $file );
2025-03-26 00:08:16 +01:00
$file = preg_replace ( '~compile_file\(\'\.\./(externals/jush/modules/jush\.js)[^)]+\)~' , " '' " , $file );
2009-10-06 11:49:31 +00:00
}
2012-09-22 07:53:50 -07:00
$file = preg_replace_callback ( " ~lang \\ ('((?:[^ \\ \\ ']+| \\ \\ .)*)'([,)])~s " , 'lang_ids' , $file );
2025-03-28 18:11:26 +01:00
$file = preg_replace_callback ( '~\b(include|require) "([^"]*" . LANG . ".inc.php)";~' , 'put_file_lang' , $file );
2012-09-22 07:53:50 -07:00
$file = str_replace ( " \r " , " " , $file );
if ( $_SESSION [ " lang " ]) {
// single language version
$file = preg_replace_callback ( " ~(< \\ ?php \\ s*echo )?lang \\ ('((?:[^ \\ \\ ']+| \\ \\ .)*)'([,)])(; \\ s* \\ ?>)?~s " , 'remove_lang' , $file );
2025-02-23 11:18:28 +01:00
$file = str_replace ( " switch_lang(); " , " " , $file );
2025-03-28 18:11:26 +01:00
$file = str_replace ( '<?php echo LANG; ?>' , $_SESSION [ " lang " ], $file );
2012-09-22 07:53:50 -07:00
}
2025-03-13 17:33:19 +01:00
$file = str_replace ( 'echo script_src("static/editing.js");' . " \n " , " " , $file ); // merged into functions.js
$file = preg_replace ( '~\s+echo script_src\("\.\./externals/jush/modules/jush-(textarea|txt|js|" \. JUSH \. ")\.js"\);~' , '' , $file ); // merged into jush.js
2025-03-15 01:49:42 +01:00
$file = preg_replace ( '~echo .*/jush(-dark)?.css\'>.*~' , '' , $file ); // merged into default.css or dark.css
2025-03-28 10:47:20 +01:00
if ( function_exists ( 'stripTypes' )) {
$file = stripTypes ( $file );
}
2012-09-22 07:53:50 -07:00
$file = preg_replace_callback ( " ~compile_file \\ ('([^']+)'(?:, '([^']*)')? \\ )~ " , 'compile_file' , $file ); // integrate static files
2025-03-28 17:52:49 +01:00
$replace = 'preg_replace("~\\\\\\\\?.*~", "", ME) . "?file=\1&version=' . Adminer\VERSION . '"' ;
2025-03-15 08:51:51 +01:00
$file = preg_replace ( '~\.\./adminer/static/(default\.css)~' , '<?php echo h(' . $replace . '); ?>' , $file );
2018-02-20 16:27:40 +01:00
$file = preg_replace ( '~"\.\./adminer/static/(functions\.js)"~' , $replace , $file );
$file = preg_replace ( '~\.\./adminer/static/([^\'"]*)~' , '" . h(' . $replace . ') . "' , $file );
$file = preg_replace ( '~"\.\./externals/jush/modules/(jush\.js)"~' , $replace , $file );
2025-03-15 09:38:06 +01:00
if ( function_exists ( 'phpShrink' )) {
$file = phpShrink ( $file );
}
2012-09-22 07:53:50 -07:00
2025-03-28 17:52:49 +01:00
$filename = $project . ( preg_match ( '~-dev$~' , Adminer\VERSION ) ? " " : " - " . Adminer\VERSION ) . ( $vendor ? " - $vendor " : " " ) . ( $_SESSION [ " lang " ] ? " - $_SESSION[lang] " : " " ) . " .php " ;
2013-08-08 17:16:04 -07:00
file_put_contents ( $filename , $file );
2012-09-22 07:53:50 -07:00
echo " $filename created ( " . strlen ( $file ) . " B). \n " ;