1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-30 09:39:51 +02:00

Clean up the code for PHP < 5.6

This commit is contained in:
Peter Knut
2024-10-09 19:14:22 +02:00
parent 96c0177422
commit dd122a1056
7 changed files with 28 additions and 57 deletions

View File

@@ -432,7 +432,7 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
function error() {
global $connection;
return nl_br(h(preg_replace('~^(\[[^]]*])+~m', '', $connection->error)));
return nl2br(h(preg_replace('~^(\[[^]]*])+~m', '', $connection->error)));
}
function create_database($db, $collation) {

View File

@@ -14,7 +14,7 @@ if (!defined("DRIVER")) {
function connect($server = "", $username = "", $password = "", $database = null, $port = null, $socket = null) {
global $adminer;
mysqli_report(MYSQLI_REPORT_OFF); // stays between requests, not required since PHP 5.3.4
mysqli_report(MYSQLI_REPORT_OFF);
list($host, $port) = explode(":", $server, 2); // part after : is used for port or socket
$ssl = $adminer->connectSsl();
@@ -34,7 +34,7 @@ if (!defined("DRIVER")) {
$database,
(is_numeric($port) ? $port : ini_get("mysqli.default_port")),
(!is_numeric($port) ? $port : $socket),
($ssl ? 64 : 0) // 64 - MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT (not available before PHP 5.6.16)
($ssl ? MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT : 0)
);
$this->options(MYSQLI_OPT_LOCAL_INFILE, false);
return $return;
@@ -262,7 +262,7 @@ if (!defined("DRIVER")) {
}
function set_charset($charset) {
$this->query("SET NAMES $charset"); // charset in DSN is ignored before PHP 5.3.6
$this->query("SET NAMES $charset");
}
function select_db($database) {
@@ -375,7 +375,7 @@ if (!defined("DRIVER")) {
$connection = new Min_DB;
$credentials = $adminer->credentials();
if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
$connection->set_charset(charset($connection)); // available in MySQLi since PHP 5.0.5
$connection->set_charset(charset($connection));
$connection->query("SET sql_quote_show_create = 1, autocommit = 1");
if (min_version('5.7.8', 10.2, $connection)) {
$structured_types[lang('Strings')][] = "json";

View File

@@ -488,7 +488,7 @@ ORDER BY connamespace, conname") as $row) {
if (preg_match('~^(.*\n)?([^\n]*)\n( *)\^(\n.*)?$~s', $return, $match)) {
$return = $match[1] . preg_replace('~((?:[^&]|&[^;]*;){' . strlen($match[3]) . '})(.*)~', '\1<b>\2</b>', $match[2]) . $match[4];
}
return nl_br($return);
return nl2br($return);
}
function create_database($db, $collation) {

View File

@@ -158,14 +158,6 @@ function h($string) {
return str_replace("\0", "&#0;", htmlspecialchars($string, ENT_QUOTES, 'utf-8'));
}
/** Convert \n to <br>
* @param string
* @return string
*/
function nl_br($string) {
return str_replace("\n", "<br>", $string); // nl2br() uses XHTML before PHP 5.3
}
/** Generate HTML checkbox
* @param string
* @param string
@@ -956,7 +948,7 @@ function input($field, $value, $function) {
if (version_compare(PHP_VERSION, 5.4) >= 0) {
$args[] = JSON_PRETTY_PRINT;
}
$value = call_user_func_array('json_encode', $args); //! requires PHP 5.2
$value = call_user_func_array('json_encode', $args);
$function = "json";
}
$reset = ($jush == "mssql" && $field["auto_increment"]);

View File

@@ -17,7 +17,7 @@ function email_header($header) {
* @return bool
*/
function send_mail($email, $subject, $message, $from = "", $files = array()) {
$eol = (DIRECTORY_SEPARATOR == "/" ? "\n" : "\r\n"); // PHP_EOL available since PHP 5.0.2
$eol = "\r\n";
$message = str_replace("\n", $eol, wordwrap(str_replace("\r", "", "$message\n")));
$boundary = uniqid("boundary");
$attachments = "";

View File

@@ -437,22 +437,6 @@ if (isset($_GET["simpledb"])) {
function last_id() {
}
function hmac($algo, $data, $key, $raw_output = false) {
// can use hash_hmac() since PHP 5.1.2
$blocksize = 64;
if (strlen($key) > $blocksize) {
$key = pack("H*", $algo($key));
}
$key = str_pad($key, $blocksize, "\0");
$k_ipad = $key ^ str_repeat("\x36", $blocksize);
$k_opad = $key ^ str_repeat("\x5C", $blocksize);
$return = $algo($k_opad . pack("H*", $algo($k_ipad . $data)));
if ($raw_output) {
$return = pack("H*", $return);
}
return $return;
}
function sdb_request($action, $params = array()) {
global $adminer, $connection;
list($host, $params['AWSAccessKeyId'], $secret) = $adminer->credentials();
@@ -467,7 +451,7 @@ if (isset($_GET["simpledb"])) {
$query .= '&' . rawurlencode($key) . '=' . rawurlencode($val);
}
$query = str_replace('%7E', '~', substr($query, 1));
$query .= "&Signature=" . urlencode(base64_encode(hmac('sha1', "POST\n" . preg_replace('~^https?://~', '', $host) . "\n/\n$query", $secret, true)));
$query .= "&Signature=" . urlencode(base64_encode(hash_hmac('sha1', "POST\n" . preg_replace('~^https?://~', '', $host) . "\n/\n$query", $secret, true)));
@ini_set('track_errors', 1); // @ - may be disabled
$file = @file_get_contents($connection->_url, false, stream_context_create(array('http' => array(

View File

@@ -7,28 +7,23 @@
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerPlugin extends Adminer {
/** @access protected */
var $plugins;
protected $plugins;
function _findRootClass($class) { // is_subclass_of(string, string) is available since PHP 5.0.3
do {
$return = $class;
} while ($class = get_parent_class($class));
return $return;
}
/** Register plugins
* @param array object instances or null to register all classes starting by 'Adminer'
/**
* Registers plugins.
* @param array $plugins Object instances or null to register all classes starting by 'Adminer'.
*/
function __construct($plugins) {
function __construct(array $plugins = null)
{
if ($plugins === null) {
$plugins = array();
$plugins = [];
foreach (get_declared_classes() as $class) {
if (preg_match('~^Adminer.~i', $class) && strcasecmp($this->_findRootClass($class), 'Adminer')) { //! can use interface
if (preg_match('~^Adminer.~i', $class) && !is_subclass_of($class, 'Adminer')) { //! can use interface
$plugins[$class] = new $class;
}
}
}
$this->plugins = $plugins;
//! it is possible to use ReflectionObject to find out which plugins defines which methods at once
}