diff --git a/adminer.php b/adminer.php index 3c78112..8a25c96 100644 --- a/adminer.php +++ b/adminer.php @@ -2,60 +2,30 @@ /** * @package WordPress * @subpackage Adminer - * @author Frank Bültge + * @author Frank Bültge * - * PHP Version 5.2 * * Plugin Name: Adminer - * Plugin URI: http://bueltge.de/adminer-fuer-wordpress/1014/ + * Plugin URI: https://wordpress.org/plugins/adminer/ * Text Domain: adminer * Domain Path: /languages * Description: Adminer (formerly phpMinAdmin) is a full-featured MySQL management tool written in PHP. This plugin include this tool in WordPress for a fast management of your database. * Author: Frank Bültge - * Version: 1.4.2 * Author URI: http://bueltge.de/ - * Donate URI: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6069955 - * License: Apache License - * Last change: 2015-06-11 - * - * - * License: - * ============================================================================== - * Copyright 2009/2015 Frank Bueltge (email : frank@bueltge.de) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Requirements: - * ============================================================================== - * This plugin requires WordPress >= 3.3 and tested with WP 3.9-alpha and PHP >= 5.3 + * Version: 1.4.5 + * License: GPLv3+ */ // avoid direct calls to this file, because now WP core and framework has been used -if ( ! function_exists( 'add_filter' ) ) { - header( 'Status: 403 Forbidden' ); - header( 'HTTP/1.1 403 Forbidden' ); - exit(); -} elseif ( version_compare( phpversion(), '5.0.0', '<' ) ) { - header( 'Status: 403 Forbidden' ); - header( 'HTTP/1.1 403 Forbidden' ); - exit( 'The plugin require PHP 5 or newer' ); +if ( ! function_exists( 'add_action' ) ) { + echo "Hi there! I'm just a part of plugin, not much I can do when called directly."; + exit; } define( 'ADMINER_BASE_FILE', plugin_basename( __FILE__ ) ); add_action( 'plugins_loaded', array( 'AdminerForWP', 'get_object' ) ); + class AdminerForWP { private static $classobj; @@ -64,14 +34,16 @@ class AdminerForWP { public function __construct() { - if ( ! is_admin() ) - return NULL; + if ( ! is_admin() ) { + return; + } - if ( is_multisite() && ! function_exists( 'is_plugin_active_for_network' ) ) + if ( is_multisite() && ! function_exists( 'is_plugin_active_for_network' ) ) { require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); + } - add_action( 'init', array( $this, 'register_styles' ) ); - add_action( 'init', array( $this, 'on_init' ) ); + add_action( 'init', array( $this, 'register_styles' ) ); + add_action( 'init', array( $this, 'on_init' ) ); add_action( 'admin_init', array( $this, 'text_domain' ) ); } @@ -84,8 +56,9 @@ public function __construct() { */ public static function get_object() { - if ( NULL === self::$classobj ) + if ( NULL === self::$classobj ) { self::$classobj = new self; + } return self::$classobj; } @@ -98,15 +71,16 @@ public static function get_object() { public function on_init() { // active for MU ? - if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) + if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) { add_action( 'network_admin_menu', array( $this, 'on_network_admin_menu' ) ); - else + } else { add_action( 'admin_menu', array( $this, 'on_admin_menu' ) ); + } } public function text_domain() { - load_plugin_textdomain( 'adminer', false, dirname( plugin_basename(__FILE__) ) . '/languages' ); + load_plugin_textdomain( 'adminer', FALSE, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } public function register_styles() { @@ -127,38 +101,39 @@ public function on_load_page() { public function on_admin_menu() { - if ( current_user_can( 'unfiltered_html' ) ) { + if ( current_user_can( 'import' ) ) { + wp_enqueue_style( 'adminer-menu' ); - $menutitle = __( 'Adminer', 'adminer' ); + $menutitle = __( 'Adminer', 'adminer' ); $this->pagehook = add_management_page( __( 'Adminer', 'adminer' ), $menutitle, - 'unfiltered_html', - plugin_basename(__FILE__), + 'import', + plugin_basename( __FILE__ ), array( $this, 'on_show_page' ) ); - add_action( 'load-' . $this -> pagehook, array( $this, 'on_load_page' ) ); + add_action( 'load-' . $this->pagehook, array( $this, 'on_load_page' ) ); } } public function on_network_admin_menu() { - if ( current_user_can('unfiltered_html' ) ) { + if ( current_user_can( 'import' ) ) { wp_enqueue_style( 'adminer-menu' ); - $menutitle = __( 'Adminer', 'adminer' ); + $menutitle = __( 'Adminer', 'adminer' ); $this->pagehook = add_submenu_page( 'settings.php', __( 'Adminer', 'adminer' ), $menutitle, - 'unfiltered_html', - plugin_basename(__FILE__), + 'import', + plugin_basename( __FILE__ ), array( $this, 'on_show_page' ) ); - add_action( 'load-' . $this -> pagehook, array( $this, 'on_load_page' ) ); + add_action( 'load-' . $this->pagehook, array( $this, 'on_load_page' ) ); } } @@ -178,17 +153,29 @@ public function add_wp_admin_bar_item( $wp_admin_bar ) { public function contextual_help( $contextual_help, $screen_id, $screen ) { - if ( 'tools_page_adminer/adminer' !== $screen_id ) + if ( 'tools_page_adminer/adminer' !== $screen_id ) { return FALSE; + } - $contextual_help = '

'; - $contextual_help .= __( 'Start the Thickbox inside the Adminer-tool with the button ›Start Adminer inside‹.', 'adminer' ); + $contextual_help = '

'; + $contextual_help .= __( + 'Start the Thickbox inside the Adminer-tool with the button ›Start Adminer inside‹.', + 'adminer' + ); $contextual_help .= '
'; - $contextual_help .= __( 'Alternatively, you can use the button for use ›Adminer in a new Tab‹.', 'adminer' ); + $contextual_help .= __( + 'Alternatively, you can use the button for use ›Adminer in a new Tab‹.', 'adminer' + ); $contextual_help .= '

' . "\n"; - $contextual_help .= '

' . __( 'Documentation on Plugin Directory', 'adminer' ); - $contextual_help .= ' · ' . __( 'Donate', 'adminer' ); - $contextual_help .= ' · ' .__( 'Blog of Plugin author', 'adminer' ); + $contextual_help .= '

' . __( + 'Documentation on Plugin Directory', + 'adminer' + ); + $contextual_help .= ' · ' . __( + 'Donate', + 'adminer' + ); + $contextual_help .= ' · ' . __( 'Blog of Plugin author', 'adminer' ); $contextual_help .= ' · ' . __( 'Adminer website

', 'adminer' ); return $contextual_help; @@ -198,16 +185,18 @@ public function contextual_help( $contextual_help, $screen_id, $screen ) { * Strip slashes for different var * * @param array|string $value optional + * * @return array|null $value */ - static function gpc_strip_slashes( $value = NULL ) { + public static function gpc_strip_slashes( $value = NULL ) { // crazy check, WP change the rules and also Adminer core // result; we must check wrong to the php doc if ( ! get_magic_quotes_gpc() ) { - if ( NULL !== $value ) + if ( NULL !== $value ) { $value = self::array_map_recursive( 'stripslashes_deep', $value ); + } // stripslashes_deep or stripslashes $_REQUEST = self::array_map_recursive( 'stripslashes_deep', $_REQUEST ); @@ -223,11 +212,12 @@ static function gpc_strip_slashes( $value = NULL ) { * Deeper array_map() * * @param string $callback Callback function to map - * @param array, string $value Array to map + * @param array , string $value Array to map + * * @see http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/ * @return array, string */ - static function array_map_recursive( $callback, $values ) { + public static function array_map_recursive( $callback, $values ) { $r = NULL; if ( is_string( $values ) ) { @@ -236,8 +226,8 @@ static function array_map_recursive( $callback, $values ) { $r = array(); foreach ( $values as $k => $v ) { - $r[$k] = is_scalar($v) - ? $callback($v) + $r[ $k ] = is_scalar( $v ) + ? $callback( $v ) : self::array_map_recursive( $callback, $v ); } } @@ -252,43 +242,57 @@ static function array_map_recursive( $callback, $values ) { */ public function on_show_page() { - if ( '' == DB_USER ) + if ( '' === DB_USER ) { $db_user = __( 'empty', 'adminer' ); - else + } else { $db_user = DB_USER; + } - if ( '' == DB_PASSWORD ) + if ( '' === DB_PASSWORD ) { $db_password = __( 'empty', 'adminer' ); - else + } else { $db_password = DB_PASSWORD; + } + + if ( ! defined( 'WP_PLUGIN_DIR' ) ) { + define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); + } // full path, no trailing slash ?>

- Adminer Logo -

Adminer

-
+ Adminer Logo +

Adminer

+

- +

 

@@ -321,11 +329,25 @@ function hide_password() {

    -
  • -
  • -
  • -
  • -
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
@@ -341,28 +363,32 @@ function hide_password() { - - - - + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + +
+ +
@@ -384,8 +410,10 @@ function hide_password() { * @uses get_plugin_data * @access public * @since 1.1.0 + * * @param $value string, default = 'TextDomain' - * Name, PluginURI, Version, Description, Author, AuthorURI, TextDomain, DomainPath, Network, Title + * Name, PluginURI, Version, Description, Author, AuthorURI, TextDomain, DomainPath, Network, Title + * * @return string */ private static function get_plugin_data( $value = 'TextDomain' ) { @@ -393,13 +421,15 @@ private static function get_plugin_data( $value = 'TextDomain' ) { static $plugin_data = array(); // fetch the data just once. - if ( isset( $plugin_data[ $value ] ) ) + if ( isset( $plugin_data[ $value ] ) ) { return $plugin_data[ $value ]; + } - if ( ! function_exists( 'get_plugin_data' ) ) + if ( ! function_exists( 'get_plugin_data' ) ) { require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); + } - $plugin_data = get_plugin_data( __FILE__ ); + $plugin_data = get_plugin_data( __FILE__ ); return empty ( $plugin_data[ $value ] ) ? '' : $plugin_data[ $value ]; } diff --git a/config.php b/config.php index b235433..af2dff8 100644 --- a/config.php +++ b/config.php @@ -8,4 +8,4 @@ * Windows client with XAMPP: $wp_siteurl = 'C:/xampp/htdocs/wpbeta'; */ -// the path to wp-load.php +// the path to wp-load.php \ No newline at end of file diff --git a/inc/README b/inc/README index 0955913..2773d8d 100755 --- a/inc/README +++ b/inc/README @@ -4,7 +4,7 @@ add files: - adminer/loader.php - adminer/adminer.css -rename functions: +renamed functions: - is_mail() --> is_adminer_mail() - is_ajax() --> is_adminer_ajax() - js_escape() --> js_adminer_escape() @@ -12,9 +12,12 @@ rename functions: - checkbox() --> adminer_checkbox() - redirect() inkl. *redirect() --> *adminer_redirect() - get_temp_dir() --> get_adminer_temp_dir() -- table() --> adminer_table() - select() --> adminer_select() +currently not renamed: +- table() --> adminer_table() + +Changes: without javascript for check version, in inc/adminer/include/design.inc.php only: "> diff --git a/inc/adminer/adminer.css b/inc/adminer/adminer.css index 9ab182e..e2f662c 100644 --- a/inc/adminer/adminer.css +++ b/inc/adminer/adminer.css @@ -130,6 +130,10 @@ tr:nth-child(2n) td, tr:nth-child(2n) th, .odd td, .odd th, tr.odd { background-color: #F1F1F1; } +.js .checkable .checked td, .js .checkable .checked th { + background: #ffebe8; +} + tbody tr:hover td, tbody tr:hover th { background-color: #ffebe8; } diff --git a/inc/adminer/create.inc.php b/inc/adminer/create.inc.php index 6db9e17..72fc360 100644 --- a/inc/adminer/create.inc.php +++ b/inc/adminer/create.inc.php @@ -29,7 +29,7 @@ if ($_POST && !process_fields($row["fields"]) && !$error) { if ($_POST["drop"]) { - queries_adminer_redirect(substr(ME, 0, -1), lang('Table has been dropped.'), drop_tables(array($TABLE))); + queries_redirect(substr(ME, 0, -1), lang('Table has been dropped.'), drop_tables(array($TABLE))); } else { $fields = array(); $all_fields = array(); @@ -102,7 +102,7 @@ } $name = trim($row["name"]); - queries_adminer_redirect(ME . (support("table") ? "table=" : "select=") . urlencode($name), $message, alter_table( + queries_redirect(ME . (support("table") ? "table=" : "select=") . urlencode($name), $message, alter_table( $TABLE, $name, ($jush == "sqlite" && ($use_all_fields || $foreign) ? $all_fields : $fields), diff --git a/inc/adminer/database.inc.php b/inc/adminer/database.inc.php index 225c406..44b715a 100644 --- a/inc/adminer/database.inc.php +++ b/inc/adminer/database.inc.php @@ -5,12 +5,12 @@ $name = trim($row["name"]); if ($_POST["drop"]) { $_GET["db"] = ""; // to save in global history - queries_adminer_redirect(remove_from_uri("db|database"), lang('Database has been dropped.'), drop_databases(array(DB))); + queries_redirect(remove_from_uri("db|database"), lang('Database has been dropped.'), drop_databases(array(DB))); } elseif (DB !== $name) { // create or rename database if (DB != "") { $_GET["db"] = $name; - queries_adminer_redirect(preg_replace('~\bdb=[^&]*&~', '', ME) . "db=" . urlencode($name), lang('Database has been renamed.'), rename_database($name, $row["collation"])); + queries_redirect(preg_replace('~\bdb=[^&]*&~', '', ME) . "db=" . urlencode($name), lang('Database has been renamed.'), rename_database($name, $row["collation"])); } else { $databases = explode("\n", str_replace("\r", "", $name)); $success = true; @@ -25,14 +25,14 @@ } restart_session(); set_session("dbs", null); - queries_adminer_redirect(ME . "db=" . urlencode($last), lang('Database has been created.'), $success); + queries_redirect(ME . "db=" . urlencode($last), lang('Database has been created.'), $success); } } else { // alter database if (!$row["collation"]) { adminer_redirect(substr(ME, 0, -1)); } - query_adminer_redirect("ALTER DATABASE " . idf_escape($name) . (preg_match('~^[a-z0-9_]+$~i', $row["collation"]) ? " COLLATE $row[collation]" : ""), substr(ME, 0, -1), lang('Database has been altered.')); + query_redirect("ALTER DATABASE " . idf_escape($name) . (preg_match('~^[a-z0-9_]+$~i', $row["collation"]) ? " COLLATE $row[collation]" : ""), substr(ME, 0, -1), lang('Database has been altered.')); } } diff --git a/inc/adminer/db.inc.php b/inc/adminer/db.inc.php index 84bc408..6f0547a 100644 --- a/inc/adminer/db.inc.php +++ b/inc/adminer/db.inc.php @@ -41,7 +41,7 @@ } } - queries_adminer_redirect(substr(ME, 0, -1), $message, $result); + queries_redirect(substr(ME, 0, -1), $message, $result); } page_header(($_GET["ns"] == "" ? lang('Database') . ": " . h(DB) : lang('Schema') . ": " . h($_GET["ns"])), $error, true); diff --git a/inc/adminer/drivers/elastic.inc.php b/inc/adminer/drivers/elastic.inc.php index 78bd459..4320ed2 100644 --- a/inc/adminer/drivers/elastic.inc.php +++ b/inc/adminer/drivers/elastic.inc.php @@ -81,7 +81,7 @@ function quote($string) { class Min_Result { var $num_rows, $_rows; - function Min_Result($rows) { + function __construct($rows) { $this->num_rows = count($this->_rows); $this->_rows = $rows; reset($this->_rows); @@ -313,7 +313,7 @@ function foreign_keys($table) { return array(); } - function adminer_table($idf) { + function table($idf) { return $idf; } diff --git a/inc/adminer/drivers/firebird.inc.php b/inc/adminer/drivers/firebird.inc.php index 5d91081..68f9832 100644 --- a/inc/adminer/drivers/firebird.inc.php +++ b/inc/adminer/drivers/firebird.inc.php @@ -81,7 +81,7 @@ function result($query, $field = 0) { class Min_Result { var $num_rows, $_result, $_offset = 0; - function Min_Result($result) { + function __construct($result) { $this->_result = $result; // $this->num_rows = ibase_num_rows($result); } @@ -122,7 +122,7 @@ function idf_escape($idf) { return '"' . str_replace('"', '""', $idf) . '"'; } - function adminer_table($idf) { + function table($idf) { return idf_escape($idf); } diff --git a/inc/adminer/drivers/mongo.inc.php b/inc/adminer/drivers/mongo.inc.php index b4c4679..65a0568 100644 --- a/inc/adminer/drivers/mongo.inc.php +++ b/inc/adminer/drivers/mongo.inc.php @@ -52,7 +52,7 @@ function quote($string) { class Min_Result { var $num_rows, $_rows = array(), $_offset = 0, $_charset = array(); - function Min_Result($result) { + function __construct($result) { foreach ($result as $item) { $row = array(); foreach ($item as $key => $val) { @@ -337,7 +337,7 @@ function last_id() { return $connection->last_id; } - function adminer_table($idf) { + function table($idf) { return $idf; } diff --git a/inc/adminer/drivers/mssql.inc.php b/inc/adminer/drivers/mssql.inc.php index efe9aec..790ac3f 100644 --- a/inc/adminer/drivers/mssql.inc.php +++ b/inc/adminer/drivers/mssql.inc.php @@ -93,7 +93,7 @@ function result($query, $field = 0) { class Min_Result { var $_result, $_offset = 0, $_fields, $num_rows; - function Min_Result($result) { + function __construct($result) { $this->_result = $result; // $this->num_rows = sqlsrv_num_rows($result); // available only in scrollable results } @@ -201,7 +201,7 @@ function result($query, $field = 0) { class Min_Result { var $_result, $_offset = 0, $_fields, $num_rows; - function Min_Result($result) { + function __construct($result) { $this->_result = $result; $this->num_rows = mssql_num_rows($result); } @@ -251,7 +251,7 @@ function insertUpdate($table, $rows, $primary) { } } //! can use only one query for all rows - if (!queries("MERGE " . adminer_table($table) . " USING (VALUES(" . implode(", ", $set) . ")) AS source (c" . implode(", c", range(1, count($set))) . ") ON " . implode(" AND ", $where) //! source, c1 - possible conflict + if (!queries("MERGE " . table($table) . " USING (VALUES(" . implode(", ", $set) . ")) AS source (c" . implode(", c", range(1, count($set))) . ") ON " . implode(" AND ", $where) //! source, c1 - possible conflict . " WHEN MATCHED THEN UPDATE SET " . implode(", ", $update) . " WHEN NOT MATCHED THEN INSERT (" . implode(", ", array_keys($set)) . ") VALUES (" . implode(", ", $set) . ");" // ; is mandatory )) { @@ -273,7 +273,7 @@ function idf_escape($idf) { return "[" . str_replace("]", "]]", $idf) . "]"; } - function adminer_table($idf) { + function table($idf) { return ($_GET["ns"] != "" ? idf_escape($_GET["ns"]) . "." : "") . idf_escape($idf); } @@ -447,17 +447,17 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla } else { unset($val[6]); //! identity can't be removed if ($column != $val[0]) { - queries("EXEC sp_rename " . q(adminer_table($table) . ".$column") . ", " . q(idf_unescape($val[0])) . ", 'COLUMN'"); + queries("EXEC sp_rename " . q(table($table) . ".$column") . ", " . q(idf_unescape($val[0])) . ", 'COLUMN'"); } $alter["ALTER COLUMN " . implode("", $val)][] = ""; } } } if ($table == "") { - return queries("CREATE TABLE " . adminer_table($name) . " (" . implode(",", (array) $alter["ADD"]) . "\n)"); + return queries("CREATE TABLE " . table($name) . " (" . implode(",", (array) $alter["ADD"]) . "\n)"); } if ($table != $name) { - queries("EXEC sp_rename " . q(adminer_table($table)) . ", " . q($name)); + queries("EXEC sp_rename " . q(table($table)) . ", " . q($name)); } if ($foreign) { $alter[""] = $foreign; @@ -478,17 +478,17 @@ function alter_indexes($table, $alter) { if ($val[0] == "PRIMARY") { //! sometimes used also for UNIQUE $drop[] = idf_escape($val[1]); } else { - $index[] = idf_escape($val[1]) . " ON " . adminer_table($table); + $index[] = idf_escape($val[1]) . " ON " . table($table); } } elseif (!queries(($val[0] != "PRIMARY" - ? "CREATE $val[0] " . ($val[0] != "INDEX" ? "INDEX " : "") . idf_escape($val[1] != "" ? $val[1] : uniqid($table . "_")) . " ON " . adminer_table($table) - : "ALTER TABLE " . adminer_table($table) . " ADD PRIMARY KEY" + ? "CREATE $val[0] " . ($val[0] != "INDEX" ? "INDEX " : "") . idf_escape($val[1] != "" ? $val[1] : uniqid($table . "_")) . " ON " . table($table) + : "ALTER TABLE " . table($table) . " ADD PRIMARY KEY" ) . " (" . implode(", ", $val[2]) . ")")) { return false; } } return (!$index || queries("DROP INDEX " . implode(", ", $index))) - && (!$drop || queries("ALTER TABLE " . adminer_table($table) . " DROP " . implode(", ", $drop))) + && (!$drop || queries("ALTER TABLE " . table($table) . " DROP " . implode(", ", $drop))) ; } diff --git a/inc/adminer/drivers/mysql.inc.php b/inc/adminer/drivers/mysql.inc.php index deb3e55..0a919d6 100644 --- a/inc/adminer/drivers/mysql.inc.php +++ b/inc/adminer/drivers/mysql.inc.php @@ -9,20 +9,20 @@ class Min_DB extends MySQLi { var $extension = "MySQLi"; - function Min_DB() { + function __construct() { parent::init(); } - function connect($server, $username, $password) { + function connect($server = "", $username = "", $password = "", $database = null, $port = null, $socket = null) { mysqli_report(MYSQLI_REPORT_OFF); // stays between requests, not required since PHP 5.3.4 list($host, $port) = explode(":", $server, 2); // part after : is used for port or socket $return = @$this->real_connect( ($server != "" ? $host : ini_get("mysqli.default_host")), ($server . $username != "" ? $username : ini_get("mysqli.default_user")), ($server . $username . $password != "" ? $password : ini_get("mysqli.default_pw")), - null, + $database, (is_numeric($port) ? $port : ini_get("mysqli.default_port")), - (!is_numeric($port) ? $port : null) + (!is_numeric($port) ? $port : $socket) ); return $return; } @@ -181,7 +181,7 @@ class Min_Result { /** Constructor * @param resource */ - function Min_Result($result) { + function __construct($result) { $this->_result = $result; $this->num_rows = mysql_num_rows($result); } @@ -249,12 +249,12 @@ function query($query, $unbuffered = false) { class Min_Driver extends Min_SQL { function insert($table, $set) { - return ($set ? parent::insert($table, $set) : queries("INSERT INTO " . adminer_table($table) . " ()\nVALUES ()")); + return ($set ? parent::insert($table, $set) : queries("INSERT INTO " . table($table) . " ()\nVALUES ()")); } function insertUpdate($table, $rows, $primary) { $columns = array_keys(reset($rows)); - $prefix = "INSERT INTO " . adminer_table($table) . " (" . implode(", ", $columns) . ") VALUES\n"; + $prefix = "INSERT INTO " . table($table) . " (" . implode(", ", $columns) . ") VALUES\n"; $values = array(); foreach ($columns as $key) { $values[$key] = "$key = VALUES($key)"; @@ -293,7 +293,7 @@ function idf_escape($idf) { * @param string * @return string */ - function adminer_table($idf) { + function table($idf) { return idf_escape($idf); } @@ -471,7 +471,7 @@ function fk_support($table_status) { */ function fields($table) { $return = array(); - foreach (get_rows("SHOW FULL COLUMNS FROM " . adminer_table($table)) as $row) { + foreach (get_rows("SHOW FULL COLUMNS FROM " . table($table)) as $row) { preg_match('~^([^( ]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~', $row["Type"], $match); $return[$row["Field"]] = array( "field" => $row["Field"], @@ -499,7 +499,7 @@ function fields($table) { */ function indexes($table, $connection2 = null) { $return = array(); - foreach (get_rows("SHOW INDEX FROM " . adminer_table($table), $connection2) as $row) { + foreach (get_rows("SHOW INDEX FROM " . table($table), $connection2) as $row) { $return[$row["Key_name"]]["type"] = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE"))); $return[$row["Key_name"]]["columns"][] = $row["Column_name"]; $return[$row["Key_name"]]["lengths"][] = $row["Sub_part"]; @@ -516,7 +516,7 @@ function foreign_keys($table) { global $connection, $on_actions; static $pattern = '`(?:[^`]|``)+`'; $return = array(); - $create_table = $connection->result("SHOW CREATE TABLE " . adminer_table($table), 1); + $create_table = $connection->result("SHOW CREATE TABLE " . table($table), 1); if ($create_table) { preg_match_all("~CONSTRAINT ($pattern) FOREIGN KEY ?\\(((?:$pattern,? ?)+)\\) REFERENCES ($pattern)(?:\\.($pattern))? \\(((?:$pattern,? ?)+)\\)(?: ON DELETE ($on_actions))?(?: ON UPDATE ($on_actions))?~", $create_table, $matches, PREG_SET_ORDER); foreach ($matches as $match) { @@ -541,7 +541,7 @@ function foreign_keys($table) { */ function view($name) { global $connection; - return array("select" => preg_replace('~^(?:[^`]|`[^`]*`)*\\s+AS\\s+~isU', '', $connection->result("SHOW CREATE VIEW " . adminer_table($name), 1))); + return array("select" => preg_replace('~^(?:[^`]|`[^`]*`)*\\s+AS\\s+~isU', '', $connection->result("SHOW CREATE VIEW " . table($name), 1))); } /** Get sorted grouped list of collations @@ -581,16 +581,6 @@ function error() { return h(preg_replace('~^You have an error.*syntax to use~U', "Syntax error", $connection->error)); } - /** Get line of error - * @return int 0 for first line - */ - function error_line() { - global $connection; - if (preg_match('~ at line ([0-9]+)$~', $connection->error, $regs)) { - return $regs[1] - 1; - } - } - /** Create database * @param string * @param string @@ -622,7 +612,7 @@ function rename_database($name, $collation) { //! move triggers $rename = array(); foreach (tables_list() as $table => $type) { - $rename[] = adminer_table($table) . " TO " . idf_escape($name) . "." . adminer_table($table); + $rename[] = table($table) . " TO " . idf_escape($name) . "." . table($table); } $return = (!$rename || queries("RENAME TABLE " . implode(", ", $rename))); if ($return) { @@ -681,15 +671,15 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla . ($auto_increment != "" ? " AUTO_INCREMENT=$auto_increment" : "") ; if ($table == "") { - return queries("CREATE TABLE " . adminer_table($name) . " (\n" . implode(",\n", $alter) . "\n)$status$partitioning"); + return queries("CREATE TABLE " . table($name) . " (\n" . implode(",\n", $alter) . "\n)$status$partitioning"); } if ($table != $name) { - $alter[] = "RENAME TO " . adminer_table($name); + $alter[] = "RENAME TO " . table($name); } if ($status) { $alter[] = ltrim($status); } - return ($alter || $partitioning ? queries("ALTER TABLE " . adminer_table($table) . "\n" . implode(",\n", $alter) . $partitioning) : true); + return ($alter || $partitioning ? queries("ALTER TABLE " . table($table) . "\n" . implode(",\n", $alter) . $partitioning) : true); } /** Run commands to alter indexes @@ -704,7 +694,7 @@ function alter_indexes($table, $alter) { : "\nADD $val[0] " . ($val[0] == "PRIMARY" ? "KEY " : "") . ($val[1] != "" ? idf_escape($val[1]) . " " : "") . "(" . implode(", ", $val[2]) . ")" ); } - return queries("ALTER TABLE " . adminer_table($table) . implode(",", $alter)); + return queries("ALTER TABLE " . table($table) . implode(",", $alter)); } /** Run commands to truncate tables @@ -740,7 +730,7 @@ function drop_tables($tables) { function move_tables($tables, $views, $target) { $rename = array(); foreach (array_merge($tables, $views) as $table) { // views will report SQL error - $rename[] = adminer_table($table) . " TO " . idf_escape($target) . "." . adminer_table($table); + $rename[] = table($table) . " TO " . idf_escape($target) . "." . table($table); } return queries("RENAME TABLE " . implode(", ", $rename)); //! move triggers @@ -755,16 +745,16 @@ function move_tables($tables, $views, $target) { function copy_tables($tables, $views, $target) { queries("SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'"); foreach ($tables as $table) { - $name = ($target == DB ? adminer_table("copy_$table") : idf_escape($target) . "." . adminer_table($table)); + $name = ($target == DB ? table("copy_$table") : idf_escape($target) . "." . table($table)); if (!queries("\nDROP TABLE IF EXISTS $name") - || !queries("CREATE TABLE $name LIKE " . adminer_table($table)) - || !queries("INSERT INTO $name SELECT * FROM " . adminer_table($table)) + || !queries("CREATE TABLE $name LIKE " . table($table)) + || !queries("INSERT INTO $name SELECT * FROM " . table($table)) ) { return false; } } foreach ($views as $table) { - $name = ($target == DB ? adminer_table("copy_$table") : idf_escape($target) . "." . adminer_table($table)); + $name = ($target == DB ? table("copy_$table") : idf_escape($target) . "." . table($table)); $view = view($table); if (!queries("DROP VIEW IF EXISTS $name") || !queries("CREATE VIEW $name AS $view[select]") //! USE to avoid db.table @@ -924,7 +914,7 @@ function set_schema($schema) { */ function create_sql($table, $auto_increment) { global $connection; - $return = $connection->result("SHOW CREATE TABLE " . adminer_table($table), 1); + $return = $connection->result("SHOW CREATE TABLE " . table($table), 1); if (!$auto_increment) { $return = preg_replace('~ AUTO_INCREMENT=\\d+~', '', $return); //! skip comments } @@ -936,7 +926,7 @@ function create_sql($table, $auto_increment) { * @return string */ function truncate_sql($table) { - return "TRUNCATE " . adminer_table($table); + return "TRUNCATE " . table($table); } /** Get SQL command to change database @@ -956,7 +946,7 @@ function trigger_sql($table, $style) { $return = ""; foreach (get_rows("SHOW TRIGGERS LIKE " . q(addcslashes($table, "%_\\")), null, "-- ") as $row) { $return .= "\n" . ($style == 'CREATE+ALTER' ? "DROP TRIGGER IF EXISTS " . idf_escape($row["Trigger"]) . ";;\n" : "") - . "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . adminer_table($row["Table"]) . " FOR EACH ROW\n$row[Statement];;\n"; + . "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . table($row["Table"]) . " FOR EACH ROW\n$row[Statement];;\n"; } return $return; } diff --git a/inc/adminer/drivers/oracle.inc.php b/inc/adminer/drivers/oracle.inc.php index b02cfed..363481f 100644 --- a/inc/adminer/drivers/oracle.inc.php +++ b/inc/adminer/drivers/oracle.inc.php @@ -80,7 +80,7 @@ function result($query, $field = 1) { class Min_Result { var $_result, $_offset = 1, $num_rows; - function Min_Result($result) { + function __construct($result) { $this->_result = $result; } @@ -150,7 +150,7 @@ function idf_escape($idf) { return '"' . str_replace('"', '""', $idf) . '"'; } - function adminer_table($idf) { + function table($idf) { return idf_escape($idf); } @@ -299,7 +299,7 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla foreach ($fields as $field) { $val = $field[1]; if ($val && $field[0] != "" && idf_escape($field[0]) != $val[0]) { - queries("ALTER TABLE " . adminer_table($table) . " RENAME COLUMN " . idf_escape($field[0]) . " TO $val[0]"); + queries("ALTER TABLE " . table($table) . " RENAME COLUMN " . idf_escape($field[0]) . " TO $val[0]"); } if ($val) { $alter[] = ($table != "" ? ($field[0] != "" ? "MODIFY (" : "ADD (") : " ") . implode($val) . ($table != "" ? ")" : ""); //! error with name change only @@ -308,11 +308,11 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla } } if ($table == "") { - return queries("CREATE TABLE " . adminer_table($name) . " (\n" . implode(",\n", $alter) . "\n)"); + return queries("CREATE TABLE " . table($name) . " (\n" . implode(",\n", $alter) . "\n)"); } - return (!$alter || queries("ALTER TABLE " . adminer_table($table) . "\n" . implode("\n", $alter))) - && (!$drop || queries("ALTER TABLE " . adminer_table($table) . " DROP (" . implode(", ", $drop) . ")")) - && ($table == $name || queries("ALTER TABLE " . adminer_table($table) . " RENAME TO " . adminer_table($name))) + return (!$alter || queries("ALTER TABLE " . table($table) . "\n" . implode("\n", $alter))) + && (!$drop || queries("ALTER TABLE " . table($table) . " DROP (" . implode(", ", $drop) . ")")) + && ($table == $name || queries("ALTER TABLE " . table($table) . " RENAME TO " . table($name))) ; } diff --git a/inc/adminer/drivers/pgsql.inc.php b/inc/adminer/drivers/pgsql.inc.php index 45f4c12..22c9142 100644 --- a/inc/adminer/drivers/pgsql.inc.php +++ b/inc/adminer/drivers/pgsql.inc.php @@ -94,7 +94,7 @@ function result($query, $field = 0) { class Min_Result { var $_result, $_offset = 0, $num_rows; - function Min_Result($result) { + function __construct($result) { $this->_result = $result; $this->num_rows = pg_num_rows($result); } @@ -164,8 +164,8 @@ function insertUpdate($table, $rows, $primary) { $where[] = "$key = $val"; } } - if (!(($where && queries("UPDATE " . adminer_table($table) . " SET " . implode(", ", $update) . " WHERE " . implode(" AND ", $where)) && $connection->affected_rows) - || queries("INSERT INTO " . adminer_table($table) . " (" . implode(", ", array_keys($set)) . ") VALUES (" . implode(", ", $set) . ")") + if (!(($where && queries("UPDATE " . table($table) . " SET " . implode(", ", $update) . " WHERE " . implode(" AND ", $where)) && $connection->affected_rows) + || queries("INSERT INTO " . table($table) . " (" . implode(", ", array_keys($set)) . ") VALUES (" . implode(", ", $set) . ")") )) { return false; } @@ -181,7 +181,7 @@ function idf_escape($idf) { return '"' . str_replace('"', '""', $idf) . '"'; } - function adminer_table($idf) { + function table($idf) { return idf_escape($idf); } @@ -410,7 +410,7 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla $alter[] = ($table != "" ? "ADD " : " ") . implode($val); } else { if ($column != $val[0]) { - $queries[] = "ALTER TABLE " . adminer_table($table) . " RENAME $column TO $val[0]"; + $queries[] = "ALTER TABLE " . table($table) . " RENAME $column TO $val[0]"; } $alter[] = "ALTER $column TYPE$val[1]"; if (!$val[6]) { @@ -419,21 +419,21 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla } } if ($field[0] != "" || $val5 != "") { - $queries[] = "COMMENT ON COLUMN " . adminer_table($table) . ".$val[0] IS " . ($val5 != "" ? substr($val5, 9) : "''"); + $queries[] = "COMMENT ON COLUMN " . table($table) . ".$val[0] IS " . ($val5 != "" ? substr($val5, 9) : "''"); } } } $alter = array_merge($alter, $foreign); if ($table == "") { - array_unshift($queries, "CREATE TABLE " . adminer_table($name) . " (\n" . implode(",\n", $alter) . "\n)"); + array_unshift($queries, "CREATE TABLE " . table($name) . " (\n" . implode(",\n", $alter) . "\n)"); } elseif ($alter) { - array_unshift($queries, "ALTER TABLE " . adminer_table($table) . "\n" . implode(",\n", $alter)); + array_unshift($queries, "ALTER TABLE " . table($table) . "\n" . implode(",\n", $alter)); } if ($table != "" && $table != $name) { - $queries[] = "ALTER TABLE " . adminer_table($table) . " RENAME TO " . adminer_table($name); + $queries[] = "ALTER TABLE " . table($table) . " RENAME TO " . table($name); } if ($table != "" || $comment != "") { - $queries[] = "COMMENT ON TABLE " . adminer_table($name) . " IS " . q($comment); + $queries[] = "COMMENT ON TABLE " . table($name) . " IS " . q($comment); } if ($auto_increment != "") { //! $queries[] = "SELECT setval(pg_get_serial_sequence(" . q($name) . ", ), $auto_increment)"; @@ -460,11 +460,11 @@ function alter_indexes($table, $alter) { } elseif ($val[2] == "DROP") { $drop[] = idf_escape($val[1]); } else { - $queries[] = "CREATE INDEX " . idf_escape($val[1] != "" ? $val[1] : uniqid($table . "_")) . " ON " . adminer_table($table) . " (" . implode(", ", $val[2]) . ")"; + $queries[] = "CREATE INDEX " . idf_escape($val[1] != "" ? $val[1] : uniqid($table . "_")) . " ON " . table($table) . " (" . implode(", ", $val[2]) . ")"; } } if ($create) { - array_unshift($queries, "ALTER TABLE " . adminer_table($table) . implode(",", $create)); + array_unshift($queries, "ALTER TABLE " . table($table) . implode(",", $create)); } if ($drop) { array_unshift($queries, "DROP INDEX " . implode(", ", $drop)); @@ -489,7 +489,7 @@ function drop_views($views) { function drop_tables($tables) { foreach ($tables as $table) { $status = table_status($table); - if (!queries("DROP " . strtoupper($status["Engine"]) . " " . adminer_table($table))) { + if (!queries("DROP " . strtoupper($status["Engine"]) . " " . table($table))) { return false; } } @@ -499,7 +499,7 @@ function drop_tables($tables) { function move_tables($tables, $views, $target) { foreach (array_merge($tables, $views) as $table) { $status = table_status($table); - if (!queries("ALTER " . strtoupper($status["Engine"]) . " " . adminer_table($table) . " SET SCHEMA " . idf_escape($target))) { + if (!queries("ALTER " . strtoupper($status["Engine"]) . " " . table($table) . " SET SCHEMA " . idf_escape($target))) { return false; } } diff --git a/inc/adminer/drivers/simpledb.inc.php b/inc/adminer/drivers/simpledb.inc.php index 3919a48..76ba4e1 100644 --- a/inc/adminer/drivers/simpledb.inc.php +++ b/inc/adminer/drivers/simpledb.inc.php @@ -56,7 +56,7 @@ function quote($string) { class Min_Result { var $num_rows, $_rows = array(), $_offset = 0; - function Min_Result($result) { + function __construct($result) { foreach ($result as $item) { $row = array(); if ($item->Name != '') { // SELECT COUNT(*) @@ -143,7 +143,7 @@ function _extractIds($table, $queryWhere, $limit) { if (preg_match_all("~itemName\(\) = (('[^']*+')+)~", $queryWhere, $matches)) { $return = array_map('idf_unescape', $matches[1]); } else { - foreach (sdb_request_all('Select', 'Item', array('SelectExpression' => 'SELECT itemName() FROM ' . adminer_table($table) . $queryWhere . ($limit ? " LIMIT 1" : ""))) as $item) { + foreach (sdb_request_all('Select', 'Item', array('SelectExpression' => 'SELECT itemName() FROM ' . table($table) . $queryWhere . ($limit ? " LIMIT 1" : ""))) as $item) { $return[] = $item->Name; } } @@ -331,7 +331,7 @@ function foreign_keys($table) { return array(); } - function adminer_table($idf) { + function table($idf) { return idf_escape($idf); } diff --git a/inc/adminer/drivers/sqlite.inc.php b/inc/adminer/drivers/sqlite.inc.php index 3d69315..ab018e3 100644 --- a/inc/adminer/drivers/sqlite.inc.php +++ b/inc/adminer/drivers/sqlite.inc.php @@ -11,7 +11,7 @@ class Min_SQLite { var $extension = "SQLite3", $server_info, $affected_rows, $errno, $error, $_link; - function Min_SQLite($filename) { + function __construct($filename) { $this->_link = new SQLite3($filename); $version = $this->_link->version(); $this->server_info = $version["versionString"]; @@ -55,7 +55,7 @@ function result($query, $field = 0) { class Min_Result { var $_result, $_offset = 0, $num_rows; - function Min_Result($result) { + function __construct($result) { $this->_result = $result; } @@ -87,7 +87,7 @@ function __desctruct() { class Min_SQLite { var $extension = "SQLite", $server_info, $affected_rows, $error, $_link; - function Min_SQLite($filename) { + function __construct($filename) { $this->server_info = sqlite_libversion(); $this->_link = new SQLiteDatabase($filename); } @@ -127,7 +127,7 @@ function result($query, $field = 0) { class Min_Result { var $_result, $_offset = 0, $num_rows; - function Min_Result($result) { + function __construct($result) { $this->_result = $result; if (method_exists($result, 'numRows')) { // not available in unbuffered query $this->num_rows = $result->numRows(); @@ -172,7 +172,7 @@ function fetch_field() { class Min_SQLite extends Min_PDO { var $extension = "PDO_SQLite"; - function Min_SQLite($filename) { + function __construct($filename) { $this->dsn(DRIVER . ":$filename", "", ""); } } @@ -182,13 +182,13 @@ function Min_SQLite($filename) { if (class_exists("Min_SQLite")) { class Min_DB extends Min_SQLite { - function Min_DB() { - $this->Min_SQLite(":memory:"); + function __construct() { + parent::__construct(":memory:"); } function select_db($filename) { if (is_readable($filename) && $this->query("ATTACH " . $this->quote(preg_match("~(^[/\\\\]|:)~", $filename) ? $filename : dirname($_SERVER["SCRIPT_FILENAME"]) . "/$filename") . " AS a")) { // is_readable - SQLite 3 - $this->Min_SQLite($filename); + parent::__construct($filename); return true; } return false; @@ -213,7 +213,7 @@ function insertUpdate($table, $rows, $primary) { foreach ($rows as $set) { $values[] = "(" . implode(", ", $set) . ")"; } - return queries("REPLACE INTO " . adminer_table($table) . " (" . implode(", ", array_keys(reset($rows))) . ") VALUES\n" . implode(",\n", $values)); + return queries("REPLACE INTO " . table($table) . " (" . implode(", ", array_keys(reset($rows))) . ") VALUES\n" . implode(",\n", $values)); } } @@ -224,7 +224,7 @@ function idf_escape($idf) { return '"' . str_replace('"', '""', $idf) . '"'; } - function adminer_table($idf) { + function table($idf) { return idf_escape($idf); } @@ -294,7 +294,7 @@ function fields($table) { global $connection; $return = array(); $primary = ""; - foreach (get_rows("PRAGMA table_info(" . adminer_table($table) . ")") as $row) { + foreach (get_rows("PRAGMA table_info(" . table($table) . ")") as $row) { $name = $row["name"]; $type = strtolower($row["type"]); $default = $row["dflt_value"]; @@ -350,7 +350,7 @@ function indexes($table, $connection2 = null) { } } $sqls = get_key_vals("SELECT name, sql FROM sqlite_master WHERE type = 'index' AND tbl_name = " . q($table), $connection2); - foreach (get_rows("PRAGMA index_list(" . adminer_table($table) . ")", $connection2) as $row) { + foreach (get_rows("PRAGMA index_list(" . table($table) . ")", $connection2) as $row) { $name = $row["name"]; $index = array("type" => ($row["unique"] ? "UNIQUE" : "INDEX")); $index["lengths"] = array(); @@ -376,7 +376,7 @@ function indexes($table, $connection2 = null) { function foreign_keys($table) { $return = array(); - foreach (get_rows("PRAGMA foreign_key_list(" . adminer_table($table) . ")") as $row) { + foreach (get_rows("PRAGMA foreign_key_list(" . table($table) . ")") as $row) { $foreign_key = &$return[$row["id"]]; //! idf_unescape in SQLite2 if (!$foreign_key) { @@ -440,7 +440,7 @@ function create_database($db, $collation) { function drop_databases($databases) { global $connection; - $connection->Min_SQLite(":memory:"); // to unlock file, doesn't work in PDO on Windows + $connection->__construct(":memory:"); // to unlock file, doesn't work in PDO on Windows foreach ($databases as $db) { if (!@unlink($db)) { $connection->error = lang('File exists.'); @@ -455,7 +455,7 @@ function rename_database($name, $collation) { if (!check_sqlite_name($name)) { return false; } - $connection->Min_SQLite(":memory:"); + $connection->__construct(":memory:"); $connection->error = lang('File exists.'); return @rename(DB, $name); } @@ -484,11 +484,11 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla } if (!$use_all_fields) { foreach ($alter as $val) { - if (!queries("ALTER TABLE " . adminer_table($table) . " $val")) { + if (!queries("ALTER TABLE " . table($table) . " $val")) { return false; } } - if ($table != $name && !queries("ALTER TABLE " . adminer_table($table) . " RENAME TO " . adminer_table($name))) { + if ($table != $name && !queries("ALTER TABLE " . table($table) . " RENAME TO " . table($name))) { return false; } } elseif (!recreate_table($table, $name, $alter, $originals, $foreign)) { @@ -558,23 +558,23 @@ function recreate_table($table, $name, $fields, $originals, $foreign, $indexes = $fields[$key] = " " . implode($field); } $fields = array_merge($fields, array_filter($foreign)); - if (!queries("CREATE TABLE " . adminer_table($table != "" ? "adminer_$name" : $name) . " (\n" . implode(",\n", $fields) . "\n)")) { + if (!queries("CREATE TABLE " . table($table != "" ? "adminer_$name" : $name) . " (\n" . implode(",\n", $fields) . "\n)")) { // implicit ROLLBACK to not overwrite $connection->error return false; } if ($table != "") { - if ($originals && !queries("INSERT INTO " . adminer_table("adminer_$name") . " (" . implode(", ", $originals) . ") SELECT " . implode(", ", array_map('idf_escape', array_keys($originals))) . " FROM " . adminer_table($table))) { + if ($originals && !queries("INSERT INTO " . table("adminer_$name") . " (" . implode(", ", $originals) . ") SELECT " . implode(", ", array_map('idf_escape', array_keys($originals))) . " FROM " . table($table))) { return false; } $triggers = array(); foreach (triggers($table) as $trigger_name => $timing_event) { $trigger = trigger($trigger_name); - $triggers[] = "CREATE TRIGGER " . idf_escape($trigger_name) . " " . implode(" ", $timing_event) . " ON " . adminer_table($name) . "\n$trigger[Statement]"; + $triggers[] = "CREATE TRIGGER " . idf_escape($trigger_name) . " " . implode(" ", $timing_event) . " ON " . table($name) . "\n$trigger[Statement]"; } - if (!queries("DROP TABLE " . adminer_table($table))) { // drop before creating indexes and triggers to allow using old names + if (!queries("DROP TABLE " . table($table))) { // drop before creating indexes and triggers to allow using old names return false; } - queries("ALTER TABLE " . adminer_table("adminer_$name") . " RENAME TO " . adminer_table($name)); + queries("ALTER TABLE " . table("adminer_$name") . " RENAME TO " . table($name)); if (!alter_indexes($name, $indexes)) { return false; } @@ -591,7 +591,7 @@ function recreate_table($table, $name, $fields, $originals, $foreign, $indexes = function index_sql($table, $type, $name, $columns) { return "CREATE $type " . ($type != "INDEX" ? "INDEX " : "") . idf_escape($name != "" ? $name : uniqid($table . "_")) - . " ON " . adminer_table($table) + . " ON " . table($table) . " $columns" ; } @@ -726,7 +726,7 @@ function create_sql($table, $auto_increment) { } function truncate_sql($table) { - return "DELETE FROM " . adminer_table($table); + return "DELETE FROM " . table($table); } function use_sql($database) { diff --git a/inc/adminer/dump.inc.php b/inc/adminer/dump.inc.php index 69b6504..5036302 100644 --- a/inc/adminer/dump.inc.php +++ b/inc/adminer/dump.inc.php @@ -90,7 +90,7 @@ $views[] = $name; } elseif ($data) { $fields = fields($name); - $adminer->dumpData($name, $_POST["data_style"], "SELECT *" . convert_fields($fields, $fields) . " FROM " . adminer_table($name)); + $adminer->dumpData($name, $_POST["data_style"], "SELECT *" . convert_fields($fields, $fields) . " FROM " . table($name)); } if ($is_sql && $_POST["triggers"] && $table && ($triggers = trigger_sql($name, $_POST["table_style"]))) { echo "\nDELIMITER ;;\n$triggers\nDELIMITER ;\n"; @@ -178,11 +178,11 @@ foreach ($tables_list as $name => $type) { $prefix = preg_replace('~_.*~', '', $name); $checked = ($TABLE == "" || $TABLE == (substr($TABLE, -1) == "%" ? "$prefix%" : $name)); //! % may be part of table name - $print = "" . adminer_checkbox("tables[]", $name, $checked, $name, "adminer_checkboxClick(event, this); formUncheck('check-tables');", "block"); + $print = "" . adminer_checkbox("tables[]", $name, $checked, $name, "checkboxClick(event, this); formUncheck('check-tables');", "block"); if ($type !== null && !preg_match('~table~i', $type)) { $views .= "$print\n"; } else { - echo "$print\n"; + echo "$print\n"; } $prefixes[$prefix]++; } diff --git a/inc/adminer/edit.inc.php b/inc/adminer/edit.inc.php index b96db52..c15fea6 100644 --- a/inc/adminer/edit.inc.php +++ b/inc/adminer/edit.inc.php @@ -22,7 +22,7 @@ $query_where = "\nWHERE $where"; if (isset($_POST["delete"])) { - queries_adminer_redirect( + queries_redirect( $location, lang('Item has been deleted.'), $driver->delete($TABLE, $query_where, !$unique_array) @@ -41,12 +41,12 @@ if (!$set) { adminer_redirect($location); } - queries_adminer_redirect( + queries_redirect( $location, lang('Item has been updated.'), $driver->update($TABLE, $set, $query_where, !$unique_array) ); - if (is_adminer_ajax()) { + if (js_adminer_ajax()) { page_headers(); page_messages($error); exit; @@ -54,7 +54,7 @@ } else { $result = $driver->insert($TABLE, $set); $last_id = ($result ? last_id() : 0); - queries_adminer_redirect($location, lang('Item%s has been inserted.', ($last_id ? " $last_id" : "")), $result); //! link + queries_redirect($location, lang('Item%s has been inserted.', ($last_id ? " $last_id" : "")), $result); //! link } } } diff --git a/inc/adminer/event.inc.php b/inc/adminer/event.inc.php index 58ecab5..2f6a555 100644 --- a/inc/adminer/event.inc.php +++ b/inc/adminer/event.inc.php @@ -6,7 +6,7 @@ if ($_POST && !$error) { if ($_POST["drop"]) { - query_adminer_redirect("DROP EVENT " . idf_escape($EVENT), substr(ME, 0, -1), lang('Event has been dropped.')); + query_redirect("DROP EVENT " . idf_escape($EVENT), substr(ME, 0, -1), lang('Event has been dropped.')); } elseif (in_array($row["INTERVAL_FIELD"], $intervals) && isset($statuses[$row["STATUS"]])) { $schedule = "\nON SCHEDULE " . ($row["INTERVAL_VALUE"] ? "EVERY " . q($row["INTERVAL_VALUE"]) . " $row[INTERVAL_FIELD]" @@ -15,8 +15,8 @@ : "AT " . q($row["STARTS"]) ) . " ON COMPLETION" . ($row["ON_COMPLETION"] ? "" : " NOT") . " PRESERVE" ; - - queries_adminer_redirect(substr(ME, 0, -1), ($EVENT != "" ? lang('Event has been altered.') : lang('Event has been created.')), queries(($EVENT != "" + + queries_redirect(substr(ME, 0, -1), ($EVENT != "" ? lang('Event has been altered.') : lang('Event has been created.')), queries(($EVENT != "" ? "ALTER EVENT " . idf_escape($EVENT) . $schedule . ($EVENT != $row["EVENT_NAME"] ? "\nRENAME TO " . idf_escape($row["EVENT_NAME"]) : "") : "CREATE EVENT " . idf_escape($row["EVENT_NAME"]) . $schedule diff --git a/inc/adminer/foreign.inc.php b/inc/adminer/foreign.inc.php index c27948d..bad28c2 100644 --- a/inc/adminer/foreign.inc.php +++ b/inc/adminer/foreign.inc.php @@ -6,7 +6,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-js"]) { $message = ($_POST["drop"] ? lang('Foreign key has been dropped.') : ($name != "" ? lang('Foreign key has been altered.') : lang('Foreign key has been created.'))); $location = ME . "table=" . urlencode($TABLE); - + $row["source"] = array_filter($row["source"], 'strlen'); ksort($row["source"]); // enforce input order $target = array(); @@ -14,16 +14,16 @@ $target[$key] = $row["target"][$key]; } $row["target"] = $target; - + if ($jush == "sqlite") { - queries_adminer_redirect($location, $message, recreate_table($TABLE, $TABLE, array(), array(), array(" $name" => ($_POST["drop"] ? "" : " " . format_foreign_key($row))))); + queries_redirect($location, $message, recreate_table($TABLE, $TABLE, array(), array(), array(" $name" => ($_POST["drop"] ? "" : " " . format_foreign_key($row))))); } else { - $alter = "ALTER TABLE " . adminer_table($TABLE); + $alter = "ALTER TABLE " . table($TABLE); $drop = "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($name); if ($_POST["drop"]) { - query_adminer_redirect($alter . $drop, $location, $message); + query_redirect($alter . $drop, $location, $message); } else { - query_adminer_redirect($alter . ($name != "" ? "$drop," : "") . "\nADD" . format_foreign_key($row), $location, $message); + query_redirect($alter . ($name != "" ? "$drop," : "") . "\nADD" . format_foreign_key($row), $location, $message); $error = lang('Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exist.') . "
$error"; //! no partitioning } } diff --git a/inc/adminer/include/adminer.inc.php b/inc/adminer/include/adminer.inc.php index d07b6bb..444e906 100644 --- a/inc/adminer/include/adminer.inc.php +++ b/inc/adminer/include/adminer.inc.php @@ -9,7 +9,7 @@ class Adminer { * @return string HTML code */ function name() { - return "Adminer"; + return "Adminer"; } /** Connection parameters @@ -643,14 +643,14 @@ function dumpTable($table, $style, $is_view = 0) { foreach (fields($table) as $name => $field) { $fields[] = idf_escape($name) . " $field[full_type]"; } - $create = "CREATE TABLE " . adminer_table($table) . " (" . implode(", ", $fields) . ")"; + $create = "CREATE TABLE " . table($table) . " (" . implode(", ", $fields) . ")"; } else { $create = create_sql($table, $_POST["auto_increment"]); } set_utf8mb4($create); if ($style && $create) { if ($style == "DROP+CREATE" || $is_view == 1) { - echo "DROP " . ($is_view == 2 ? "VIEW" : "TABLE") . " IF EXISTS " . adminer_table($table) . ";\n"; + echo "DROP " . ($is_view == 2 ? "VIEW" : "TABLE") . " IF EXISTS " . table($table) . ";\n"; } if ($is_view == 1) { $create = remove_definer($create); @@ -702,7 +702,7 @@ function dumpData($table, $style, $query) { dump_csv($row); } else { if (!$insert) { - $insert = "INSERT INTO " . adminer_table($table) . " (" . implode(", ", array_map('idf_escape', $keys)) . ") VALUES"; + $insert = "INSERT INTO " . table($table) . " (" . implode(", ", array_map('idf_escape', $keys)) . ") VALUES"; } foreach ($row as $key => $val) { $field = $fields[$key]; @@ -778,7 +778,7 @@ function navigation($missing) { ?>

name(); ?> - +

bruteForceKey()]; $next_attempt = ($invalid[1] > 30 ? $invalid[0] - time() : 0); // allow 30 invalid attempts if ($next_attempt > 0) { //! do the same with permanent login @@ -78,7 +78,7 @@ function add_invalid_login() { ) { adminer_redirect(auth_url($vendor, $server, $username, $db)); } - + } elseif ($_POST["logout"]) { if ($has_token && !verify_token()) { page_header(lang('Logout'), lang('Invalid CSRF token. Send the form again.')); @@ -91,7 +91,7 @@ function add_invalid_login() { unset_permanent(); adminer_redirect(substr(preg_replace('~\b(username|db|ns)=[^&]*&~', '', ME), 0, -1), lang('Logout successful.')); } - + } elseif ($permanent && !$_SESSION["pwds"]) { session_regenerate_id(); $private = $adminer->permanentLogin(); @@ -131,7 +131,7 @@ function auth_error($error) { $password = get_password(); if ($password !== null) { if ($password === false) { - $error .= '
' . lang('Master password expired. Implement %s method to make it permanent.', 'permanentLogin()'); + $error .= '
' . lang('Master password expired. Implement %s method to make it permanent.', 'permanentLogin()'); } set_password(DRIVER, SERVER, $_GET["username"], null); } @@ -194,7 +194,7 @@ function auth_error($error) { : lang('Invalid CSRF token. Send the form again.') . ' ' . lang('If you did not send this request from Adminer then close this page.') ); } - + } elseif ($_SERVER["REQUEST_METHOD"] == "POST") { // posted form with no data means that post_max_size exceeded because Adminer always sends token at least $error = lang('Too big POST data. Reduce the data or increase the %s configuration directive.', "'post_max_size'"); diff --git a/inc/adminer/include/connect.inc.php b/inc/adminer/include/connect.inc.php index 0376b9a..fbd3d7a 100644 --- a/inc/adminer/include/connect.inc.php +++ b/inc/adminer/include/connect.inc.php @@ -6,9 +6,9 @@ function connect_error() { page_header(lang('Database') . ": " . h(DB), lang('Invalid database.'), true); } else { if ($_POST["db"] && !$error) { - queries_adminer_redirect(substr(ME, 0, -1), lang('Databases have been dropped.'), drop_databases($_POST["db"])); + queries_redirect(substr(ME, 0, -1), lang('Databases have been dropped.'), drop_databases($_POST["db"])); } - + page_header(lang('Select database'), $error, false); echo "
" . lang('Selected') . "
\n" @@ -65,7 +65,7 @@ function connect_error() { echo "\n"; } } - + page_footer("db"); } diff --git a/inc/adminer/include/design.inc.php b/inc/adminer/include/design.inc.php index 1ac1615..4cd2468 100644 --- a/inc/adminer/include/design.inc.php +++ b/inc/adminer/include/design.inc.php @@ -9,7 +9,7 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") { global $LANG, $VERSION, $adminer, $drivers, $jush; page_headers(); - if (is_adminer_ajax() && $error) { + if (js_adminer_ajax() && $error) { page_messages($error); exit; } diff --git a/inc/adminer/include/driver.inc.php b/inc/adminer/include/driver.inc.php index ac685e1..2689409 100644 --- a/inc/adminer/include/driver.inc.php +++ b/inc/adminer/include/driver.inc.php @@ -6,7 +6,7 @@ /** Create object for performing database operations * @param Min_DB */ - function Min_SQL($connection) { + function __construct($connection) { $this->_conn = $connection; } @@ -27,7 +27,7 @@ function adminer_select($table, $select, $where, $group, $order = array(), $limi $query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page); if (!$query) { $query = "SELECT" . limit( - ($_GET["page"] != "last" && +$limit && $group && $is_group && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) . "\nFROM " . adminer_table($table), + ($_GET["page"] != "last" && +$limit && $group && $is_group && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) . "\nFROM " . table($table), ($where ? "\nWHERE " . implode(" AND ", $where) : "") . ($group && $is_group ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : ""), ($limit != "" ? +$limit : null), ($page ? $limit * $page : 0), @@ -49,7 +49,7 @@ function adminer_select($table, $select, $where, $group, $order = array(), $limi * @return bool */ function delete($table, $queryWhere, $limit = 0) { - $query = "FROM " . adminer_table($table); + $query = "FROM " . table($table); return queries("DELETE" . ($limit ? limit1($query, $queryWhere) : " $query$queryWhere")); } @@ -66,7 +66,7 @@ function update($table, $set, $queryWhere, $limit = 0, $separator = "\n") { foreach ($set as $key => $val) { $values[] = "$key = $val"; } - $query = adminer_table($table) . " SET$separator" . implode(",$separator", $values); + $query = table($table) . " SET$separator" . implode(",$separator", $values); return queries("UPDATE" . ($limit ? limit1($query, $queryWhere) : " $query$queryWhere")); } @@ -76,7 +76,7 @@ function update($table, $set, $queryWhere, $limit = 0, $separator = "\n") { * @return bool */ function insert($table, $set) { - return queries("INSERT INTO " . adminer_table($table) . ($set + return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : " DEFAULT VALUES" )); diff --git a/inc/adminer/include/editing.inc.php b/inc/adminer/include/editing.inc.php index 4f294af..8815ab4 100644 --- a/inc/adminer/include/editing.inc.php +++ b/inc/adminer/include/editing.inc.php @@ -141,7 +141,7 @@ function edit_type($key, $field, $collations, $foreign_keys = array()) { global $structured_types, $types, $unsigned, $on_actions; $type = $field["type"]; ?> -> -" size="3" onfocus="editingLengthFocus(this);" onchange="editingLengthChange(this);" onkeyup="this.onchange();">
" + ); + } + if (like_bool($field)) { + return '"; + } + $hint = ""; + if (preg_match('~time~', $field["type"])) { + $hint = lang('HH:MM:SS'); + } + if (preg_match('~date|timestamp~', $field["type"])) { + $hint = lang('[yyyy]-mm-dd') . ($hint ? " [$hint]" : ""); + } + if ($hint) { + return " ($hint)"; //! maxlength + } + if (preg_match('~_(md5|sha1)$~i', $field["field"])) { + return ""; + } + return ''; + } + + function processInput($field, $value, $function = "") { + if ($function == "now") { + return "$function()"; + } + $return = $value; + if (preg_match('~date|timestamp~', $field["type"]) && preg_match('(^' . str_replace('\\$1', '(?P\\d*)', preg_replace('~(\\\\\\$([2-6]))~', '(?P\\d{1,2})', preg_quote(lang('$1-$3-$5')))) . '(.*))', $value, $match)) { + $return = ($match["p1"] != "" ? $match["p1"] : ($match["p2"] != "" ? ($match["p2"] < 70 ? 20 : 19) . $match["p2"] : gmdate("Y"))) . "-$match[p3]$match[p4]-$match[p5]$match[p6]" . end($match); + } + $return = ($field["type"] == "bit" && preg_match('~^[0-9]+$~', $value) ? $return : q($return)); + if ($value == "" && like_bool($field)) { + $return = "0"; + } elseif ($value == "" && ($field["null"] || !preg_match('~char|text~', $field["type"]))) { + $return = "NULL"; + } elseif (preg_match('~^(md5|sha1)$~', $function)) { + $return = "$function($return)"; + } + return unconvert_field($field, $return); + } + + function dumpOutput() { + return array(); + } + + function dumpFormat() { + return array('csv' => 'CSV,', 'csv;' => 'CSV;', 'tsv' => 'TSV'); + } + + function dumpDatabase($db) { + } + + function dumpTable() { + echo "\xef\xbb\xbf"; // UTF-8 byte order mark + } + + function dumpData($table, $style, $query) { + global $connection; + $result = $connection->query($query, 1); // 1 - MYSQLI_USE_RESULT + if ($result) { + while ($row = $result->fetch_assoc()) { + if ($style == "table") { + dump_csv(array_keys($row)); + $style = "INSERT"; + } + dump_csv($row); + } + } + } + + function dumpFilename($identifier) { + return friendly_url($identifier); + } + + function dumpHeaders($identifier, $multi_table = false) { + $ext = "csv"; + header("Content-Type: text/csv; charset=utf-8"); + return $ext; + } + + function homepage() { + return true; + } + + function navigation($missing) { + global $VERSION; + ?> +

+name(); ?> + +

+ $servers) { + foreach ($servers[""] as $username => $password) { + if ($password !== null) { + if ($first) { + echo "

\n"; + $first = false; + } + echo "" . ($username != "" ? h($username) : "" . lang('empty') . "") . "
\n"; + } + } + } + } else { + $this->databasesPrint($missing); + if ($missing != "db" && $missing != "ns") { + $table_status = table_status('', true); + if (!$table_status) { + echo "

" . lang('No tables.') . "\n"; + } else { + $this->tablesPrint($table_status); + } + } + } + } + + function databasesPrint($missing) { + } + + function tablesPrint($tables) { + echo "

\n"; + foreach ($tables as $row) { + $name = $this->tableName($row); + if (isset($row["Engine"]) && $name != "") { // ignore views and tables without name + echo "$name
\n" + ; + } + } + } + + function _foreignColumn($foreignKeys, $column) { + foreach ((array) $foreignKeys[$column] as $foreignKey) { + if (count($foreignKey["source"]) == 1) { + $name = $this->rowDescription($foreignKey["table"]); + if ($name != "") { + $id = idf_escape($foreignKey["target"][0]); + return array($foreignKey["table"], $id, $name); + } + } + } + } + + function _foreignKeyOptions($table, $column, $value = null) { + global $connection; + if (list($target, $id, $name) = $this->_foreignColumn(column_foreign_keys($table), $column)) { + $return = &$this->_values[$target]; + if ($return === null) { + $table_status = table_status($target); + $return = ($table_status["Rows"] > 1000 ? "" : array("" => "") + get_key_vals("SELECT $id, $name FROM " . table($target) . " ORDER BY 2")); + } + if (!$return && $value !== null) { + return $connection->result("SELECT $name FROM " . table($target) . " WHERE $id = " . q($value)); + } + return $return; + } + } + +} + +$adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer); diff --git a/inc/editor/include/connect.inc.php b/inc/editor/include/connect.inc.php new file mode 100644 index 0000000..feb69e2 --- /dev/null +++ b/inc/editor/include/connect.inc.php @@ -0,0 +1,2 @@ +select_db($adminer->database()); diff --git a/inc/editor/include/editing.inc.php b/inc/editor/include/editing.inc.php new file mode 100644 index 0000000..32d3f4e --- /dev/null +++ b/inc/editor/include/editing.inc.php @@ -0,0 +1,53 @@ + $val) { + if (!$val) { + $attachments .= "--$boundary$eol" + . "Content-Type: " . str_replace("\n", "", $files["type"][$key]) . $eol + . "Content-Disposition: attachment; filename=\"" . preg_replace('~["\\n]~', '', $files["name"][$key]) . "\"$eol" + . "Content-Transfer-Encoding: base64$eol$eol" + . chunk_split(base64_encode(file_get_contents($files["tmp_name"][$key])), 76, $eol) . $eol + ; + } + } + $beginning = ""; + $headers = "Content-Type: text/plain; charset=utf-8$eol" . "Content-Transfer-Encoding: 8bit"; + if ($attachments) { + $attachments .= "--$boundary--$eol"; + $beginning = "--$boundary$eol$headers$eol$eol"; + $headers = "Content-Type: multipart/mixed; boundary=\"$boundary\""; + } + $headers .= $eol . "MIME-Version: 1.0$eol" . "X-Mailer: Adminer Editor" + . ($from ? $eol . "From: " . str_replace("\n", "", $from) : "") //! should escape display name + ; + return mail($email, email_header($subject), $beginning . $message . $attachments, $headers); +} + +/** Check whether the column looks like boolean +* @param array single field returned from fields() +* @return bool +*/ +function like_bool($field) { + return preg_match("~bool|(tinyint|bit)\\(1\\)~", $field["full_type"]); +} diff --git a/inc/editor/index.php b/inc/editor/index.php new file mode 100644 index 0000000..97527e3 --- /dev/null +++ b/inc/editor/index.php @@ -0,0 +1,123 @@ +wp-load.php, see the readme?' ); + exit; + +} + + +$current_user = wp_get_current_user(); + +if ( is_user_logged_in() && user_can( $current_user->ID, 'administrator' ) ) { + + adminer_load_editor(); + +} else { + + wp_die( __( 'Cheatin’ uh?' ) ); + exit; +} + +/** + * Looking for the WordPress root path + * + * @return bool|string + */ +function adminer_get_wp_load_path() { + + $dir = dirname( __FILE__ ); + + do { + if ( file_exists( $dir . "/wp-load.php" ) ) { + return $dir; + } + } while ( $dir = realpath( "$dir/.." ) ); + + return FALSE; +} + +// search and include wp-load.php +function adminer_get_wp_root_path( $directory ) { + + $wp_root = FALSE; + foreach ( glob( $directory . "/*" ) as $f ) { + + if ( 'wp-load.php' == basename( $f ) ) { + $wp_root = str_replace( "\\", "/", dirname( $f ) ); + + return $wp_root; + } + + if ( is_dir( $f ) ) { + $newdir = dirname( dirname( $f ) ); + + foreach ( glob( $f . "/*" ) as $subf ) { + + if ( 'wp-load.php' == basename( $subf ) ) { + $wp_root = str_replace( "\\", "/", dirname( $subf ) ); + + return $wp_root; + } + } + } + } + + if ( isset( $newdir ) && $newdir != $directory ) { + if ( FALSE !== adminer_get_wp_root_path( $newdir ) ) { + $wp_root = adminer_get_wp_root_path( $newdir ); + } + } + + return $wp_root; +} + +/** + * Load the adminer Editior + */ +function adminer_load_editor(){ + + include "../adminer/include/bootstrap.inc.php"; + $drivers[DRIVER] = lang('Login'); + + if (isset($_GET["select"]) && ($_POST["edit"] || $_POST["clone"]) && !$_POST["save"]) { + $_GET["edit"] = $_GET["select"]; + } + + if (isset($_GET["download"])) { + include "../adminer/download.inc.php"; + } elseif (isset($_GET["edit"])) { + include "../adminer/edit.inc.php"; + } elseif (isset($_GET["select"])) { + include "../adminer/select.inc.php"; + } elseif (isset($_GET["script"])) { + include "./script.inc.php"; + } else { + include "./db.inc.php"; + } + + // each page calls its own page_header(), if the footer should not be called then the page exits + page_footer(); + +} \ No newline at end of file diff --git a/inc/editor/script.inc.php b/inc/editor/script.inc.php new file mode 100644 index 0000000..db57165 --- /dev/null +++ b/inc/editor/script.inc.php @@ -0,0 +1,16 @@ +query("KILL " . number($_POST["kill"])); + +} elseif (list($table, $id, $name) = $adminer->_foreignColumn(column_foreign_keys($_GET["source"]), $_GET["field"])) { + $limit = 11; + $result = $connection->query("SELECT $id, $name FROM " . table($table) . " WHERE " . (preg_match('~^[0-9]+$~', $_GET["value"]) ? "$id = $_GET[value] OR " : "") . "$name LIKE " . q("$_GET[value]%") . " ORDER BY 2 LIMIT $limit"); + for ($i=1; ($row = $result->fetch_row()) && $i < $limit; $i++) { + echo "" . h($row[1]) . "
\n"; + } + if ($row) { + echo "...\n"; + } +} + +exit; // don't print footer diff --git a/inc/editor/static/editing.js b/inc/editor/static/editing.js new file mode 100644 index 0000000..8b5c235 --- /dev/null +++ b/inc/editor/static/editing.js @@ -0,0 +1,40 @@ +// Editor specific functions + +function selectFieldChange() { +} + +var helpOpen; + +function helpMouseover() { +} + +function helpMouseout() { +} + +function whisperClick(event, field) { + var el = getTarget(event); + if (isTag(el, 'a') && !(event.button || event.shiftKey || event.altKey || isCtrl(event))) { + field.value = el.firstChild.data; + field.previousSibling.value = decodeURIComponent(el.href.replace(/.*=/, '')); + field.nextSibling.style.display = 'none'; + return false; + } +} + +function whisper(url, field) { + if (field.orig != field.value) { // ignore arrows, Shift, ... + field.orig = field.value; + field.previousSibling.value = field.value; // accept number, reject string + return ajax(url + encodeURIComponent(field.value), function (xmlhttp) { + if (xmlhttp.status && field.orig == field.value) { // ignore old responses + field.nextSibling.innerHTML = xmlhttp.responseText; + field.nextSibling.style.display = ''; + var a = field.nextSibling.firstChild; + if (a && a.firstChild.data == field.value) { + field.previousSibling.value = decodeURIComponent(a.href.replace(/.*=/, '')); + a.className = 'active'; + } + } + }); + } +} diff --git a/inc/plugins/database-hide.php b/inc/plugins/database-hide.php index 64e2db0..17e648c 100644 --- a/inc/plugins/database-hide.php +++ b/inc/plugins/database-hide.php @@ -1,7 +1,7 @@ disabled = array_map('strtolower', $disabled); } diff --git a/inc/plugins/dump-alter.php b/inc/plugins/dump-alter.php index 637302c..b38b8cb 100644 --- a/inc/plugins/dump-alter.php +++ b/inc/plugins/dump-alter.php @@ -1,7 +1,7 @@ value -* @link http://www.adminer.org/plugins/#use +* @link https://www.adminer.org/plugins/#use * @author Jakub Vrana, http://www.vrana.cz/ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) diff --git a/inc/plugins/dump-zip.php b/inc/plugins/dump-zip.php index a0a78f4..d1c4f27 100644 --- a/inc/plugins/dump-zip.php +++ b/inc/plugins/dump-zip.php @@ -1,7 +1,7 @@ \n\n\n\n", $langPath = "jquery-ui/i18n/jquery.ui.datepicker-%s.js") { + function __construct($prepend = "\n\n\n\n", $langPath = "jquery-ui/i18n/jquery.ui.datepicker-%s.js") { $this->prepend = $prepend; $this->langPath = $langPath; } diff --git a/inc/plugins/edit-foreign.php b/inc/plugins/edit-foreign.php index d9957bd..4b78c43 100644 --- a/inc/plugins/edit-foreign.php +++ b/inc/plugins/edit-foreign.php @@ -1,7 +1,7 @@ _limit = $limit; } @@ -26,7 +26,7 @@ function editInput($table, $field, $attrs, $value) { $id = $foreignKey["target"][0]; $options = &$values[$target][$id]; if (!$options) { - $options = array("" => "") + get_vals("SELECT " . idf_escape($id) . " FROM " . adminer_table($target) . " ORDER BY 1"); + $options = array("" => "") + get_vals("SELECT " . idf_escape($id) . " FROM " . table($target) . " ORDER BY 1"); if ($this->_limit && count($options) - 1 > $this->_limit) { return; } diff --git a/inc/plugins/edit-textarea.php b/inc/plugins/edit-textarea.php index 84d9193..a8e5be5 100644 --- a/inc/plugins/edit-textarea.php +++ b/inc/plugins/edit-textarea.php @@ -1,7 +1,7 @@ for char and varchar -* @link http://www.adminer.org/plugins/#use +* @link https://www.adminer.org/plugins/#use * @author Jakub Vrana, http://www.vrana.cz/ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) diff --git a/inc/plugins/email-table.php b/inc/plugins/email-table.php index 2272dde..d57130d 100644 --- a/inc/plugins/email-table.php +++ b/inc/plugins/email-table.php @@ -1,7 +1,7 @@ table = $table; $this->id = $id; $this->title = $title; diff --git a/inc/plugins/enum-option.php b/inc/plugins/enum-option.php index a3dec97..3aad975 100644 --- a/inc/plugins/enum-option.php +++ b/inc/plugins/enum-option.php @@ -1,7 +1,7 @@