1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-08 07:36:44 +02:00

PHP: Use ?:

This commit is contained in:
Jakub Vrana
2025-03-06 18:12:22 +01:00
parent dc50bf17ea
commit 94a4f61db2
17 changed files with 24 additions and 24 deletions

View File

@@ -1,7 +1,7 @@
<?php <?php
namespace Adminer; namespace Adminer;
$PROCEDURE = ($_GET["name"] ? $_GET["name"] : $_GET["call"]); $PROCEDURE = ($_GET["name"] ?: $_GET["call"]);
page_header(lang('Call') . ": " . h($PROCEDURE), $error); page_header(lang('Call') . ": " . h($PROCEDURE), $error);
$routine = routine($_GET["call"], (isset($_GET["callf"]) ? "FUNCTION" : "PROCEDURE")); $routine = routine($_GET["call"], (isset($_GET["callf"]) ? "FUNCTION" : "PROCEDURE"));

View File

@@ -654,8 +654,8 @@ if (!defined('Adminer\DRIVER')) {
"table" => idf_unescape($match[4] != "" ? $match[4] : $match[3]), "table" => idf_unescape($match[4] != "" ? $match[4] : $match[3]),
"source" => array_map('Adminer\idf_unescape', $source[0]), "source" => array_map('Adminer\idf_unescape', $source[0]),
"target" => array_map('Adminer\idf_unescape', $target[0]), "target" => array_map('Adminer\idf_unescape', $target[0]),
"on_delete" => ($match[6] ? $match[6] : "RESTRICT"), "on_delete" => ($match[6] ?: "RESTRICT"),
"on_update" => ($match[7] ? $match[7] : "RESTRICT"), "on_update" => ($match[7] ?: "RESTRICT"),
); );
} }
} }

View File

@@ -258,7 +258,7 @@ ORDER BY 1"
function get_current_db() { function get_current_db() {
global $connection; global $connection;
$db = $connection->_current_db ? $connection->_current_db : DB; $db = $connection->_current_db ?: DB;
unset($connection->_current_db); unset($connection->_current_db);
return $db; return $db;
} }
@@ -272,7 +272,7 @@ ORDER BY 1"
function views_table($columns) { function views_table($columns) {
$owner = where_owner(''); $owner = where_owner('');
return "(SELECT $columns FROM all_views WHERE " . ($owner ? $owner : "rownum < 0") . ")"; return "(SELECT $columns FROM all_views WHERE " . ($owner ?: "rownum < 0") . ")";
} }
function tables_list() { function tables_list() {
@@ -503,7 +503,7 @@ AND c_src.TABLE_NAME = " . q($table);
function schemas() { function schemas() {
$return = get_vals("SELECT DISTINCT owner FROM dba_segments WHERE owner IN (SELECT username FROM dba_users WHERE default_tablespace NOT IN ('SYSTEM','SYSAUX')) ORDER BY 1"); $return = get_vals("SELECT DISTINCT owner FROM dba_segments WHERE owner IN (SELECT username FROM dba_users WHERE default_tablespace NOT IN ('SYSTEM','SYSAUX')) ORDER BY 1");
return ($return ? $return : get_vals("SELECT DISTINCT owner FROM all_tables WHERE tablespace_name = " . q(DB) . " ORDER BY 1")); return ($return ?: get_vals("SELECT DISTINCT owner FROM all_tables WHERE tablespace_name = " . q(DB) . " ORDER BY 1"));
} }
function get_schema() { function get_schema() {

View File

@@ -133,7 +133,7 @@ function auth_error($error) {
$error = lang('Session support must be enabled.'); $error = lang('Session support must be enabled.');
} }
$params = session_get_cookie_params(); $params = session_get_cookie_params();
cookie("adminer_key", ($_COOKIE["adminer_key"] ? $_COOKIE["adminer_key"] : rand_string()), $params["lifetime"]); cookie("adminer_key", ($_COOKIE["adminer_key"] ?: rand_string()), $params["lifetime"]);
page_header(lang('Login'), $error, null); page_header(lang('Login'), $error, null);
echo "<form action='' method='post'>\n"; echo "<form action='' method='post'>\n";
echo "<div>"; echo "<div>";

View File

@@ -75,7 +75,7 @@ var thousandsSeparator = '<?php echo js_escape(lang(',')); ?>';
<?php <?php
if ($breadcrumb !== null) { if ($breadcrumb !== null) {
$link = substr(preg_replace('~\b(username|db|ns)=[^&]*&~', '', ME), 0, -1); $link = substr(preg_replace('~\b(username|db|ns)=[^&]*&~', '', ME), 0, -1);
echo '<p id="breadcrumb"><a href="' . h($link ? $link : ".") . '">' . $drivers[DRIVER] . '</a> » '; echo '<p id="breadcrumb"><a href="' . h($link ?: ".") . '">' . $drivers[DRIVER] . '</a> » ';
$link = substr(preg_replace('~\b(db|ns)=[^&]*&~', '', ME), 0, -1); $link = substr(preg_replace('~\b(db|ns)=[^&]*&~', '', ME), 0, -1);
$server = $adminer->serverName(SERVER); $server = $adminer->serverName(SERVER);
$server = ($server != "" ? $server : lang('Server')); $server = ($server != "" ? $server : lang('Server'));

View File

@@ -851,7 +851,7 @@ function hidden_fields_get() {
*/ */
function table_status1($table, $fast = false) { function table_status1($table, $fast = false) {
$return = table_status($table, $fast); $return = table_status($table, $fast);
return ($return ? $return : array("Name" => $table)); return ($return ?: array("Name" => $table));
} }
/** Find out foreign keys for each column /** Find out foreign keys for each column
@@ -1317,7 +1317,7 @@ var timeout = setTimeout(function () {
} }
ob_flush(); ob_flush();
flush(); flush();
$return = @get_key_vals(($slow_query ? $slow_query : $query), $connection2, false); // @ - may be killed $return = @get_key_vals(($slow_query ?: $query), $connection2, false); // @ - may be killed
if ($connection2) { if ($connection2) {
echo script("clearTimeout(timeout);"); echo script("clearTimeout(timeout);");
ob_flush(); ob_flush();

View File

@@ -65,7 +65,7 @@ function get_lang() {
*/ */
function lang($idf, $number = null) { function lang($idf, $number = null) {
global $LANG, $translations; global $LANG, $translations;
$translation = ($translations[$idf] ? $translations[$idf] : $idf); $translation = ($translations[$idf] ?: $idf);
if (is_array($translation)) { if (is_array($translation)) {
$pos = ($number == 1 ? 0 $pos = ($number == 1 ? 0
: ($LANG == 'cs' || $LANG == 'sk' ? ($number && $number < 5 ? 1 : 2) // different forms for 1, 2-4, other : ($LANG == 'cs' || $LANG == 'sk' ? ($number && $number < 5 ? 1 : 2) // different forms for 1, 2-4, other

View File

@@ -37,7 +37,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
$desc = $index["descs"][$key]; $desc = $index["descs"][$key];
$set[] = idf_escape($column) . ($length ? "(" . (+$length) . ")" : "") . ($desc ? " DESC" : ""); $set[] = idf_escape($column) . ($length ? "(" . (+$length) . ")" : "") . ($desc ? " DESC" : "");
$columns[] = $column; $columns[] = $column;
$lengths[] = ($length ? $length : null); $lengths[] = ($length ?: null);
$descs[] = $desc; $descs[] = $desc;
} }
} }

View File

@@ -1,7 +1,7 @@
<?php <?php
namespace Adminer; namespace Adminer;
$PROCEDURE = ($_GET["name"] ? $_GET["name"] : $_GET["procedure"]); $PROCEDURE = ($_GET["name"] ?: $_GET["procedure"]);
$routine = (isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE"); $routine = (isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE");
$row = $_POST; $row = $_POST;
$row["fields"] = (array) $row["fields"]; $row["fields"] = (array) $row["fields"];

View File

@@ -5,7 +5,7 @@ page_header(lang('Database schema'), "", array(), h(DB . ($_GET["ns"] ? ".$_GET[
$table_pos = array(); $table_pos = array();
$table_pos_js = array(); $table_pos_js = array();
$SCHEMA = ($_GET["schema"] ? $_GET["schema"] : $_COOKIE["adminer_schema-" . str_replace(".", "_", DB)]); // $_COOKIE["adminer_schema"] was used before 3.2.0 //! ':' in table name $SCHEMA = ($_GET["schema"] ?: $_COOKIE["adminer_schema-" . str_replace(".", "_", DB)]); // $_COOKIE["adminer_schema"] was used before 3.2.0 //! ':' in table name
preg_match_all('~([^:]+):([-0-9.]+)x([-0-9.]+)(_|$)~', $SCHEMA, $matches, PREG_SET_ORDER); preg_match_all('~([^:]+):([-0-9.]+)x([-0-9.]+)(_|$)~', $SCHEMA, $matches, PREG_SET_ORDER);
foreach ($matches as $i => $match) { foreach ($matches as $i => $match) {
$table_pos[$match[1]] = array($match[2], $match[3]); $table_pos[$match[1]] = array($match[2], $match[3]);
@@ -28,7 +28,7 @@ foreach (table_status('', true) as $table => $table_status) {
$field["pos"] = $pos; $field["pos"] = $pos;
$schema[$table]["fields"][$name] = $field; $schema[$table]["fields"][$name] = $field;
} }
$schema[$table]["pos"] = ($table_pos[$table] ? $table_pos[$table] : array($top, 0)); $schema[$table]["pos"] = ($table_pos[$table] ?: array($top, 0));
foreach ($adminer->foreignKeys($table) as $val) { foreach ($adminer->foreignKeys($table) as $val) {
if (!$val["db"]) { if (!$val["db"]) {
$left = $base_left; $left = $base_left;

View File

@@ -33,7 +33,7 @@ if ($_GET["val"] && is_ajax()) {
header("Content-Type: text/plain; charset=utf-8"); header("Content-Type: text/plain; charset=utf-8");
foreach ($_GET["val"] as $unique_idf => $row) { foreach ($_GET["val"] as $unique_idf => $row) {
$as = convert_field($fields[key($row)]); $as = convert_field($fields[key($row)]);
$select = array($as ? $as : idf_escape(key($row))); $select = array($as ?: idf_escape(key($row)));
$where[] = where_check($unique_idf, $fields); $where[] = where_check($unique_idf, $fields);
$return = $driver->select($TABLE, $select, $where, $select); $return = $driver->select($TABLE, $select, $where, $select);
if ($return) { if ($return) {

View File

@@ -19,7 +19,7 @@ function add_quo_slashes($s) {
function remove_lang($match) { function remove_lang($match) {
global $translations; global $translations;
$idf = strtr($match[2], array("\\'" => "'", "\\\\" => "\\")); $idf = strtr($match[2], array("\\'" => "'", "\\\\" => "\\"));
$s = ($translations[$idf] ? $translations[$idf] : $idf); $s = ($translations[$idf] ?: $idf);
if ($match[3] == ",") { // lang() has parameters if ($match[3] == ",") { // lang() has parameters
return $match[1] . (is_array($s) ? "lang(array('" . implode("', '", array_map('add_apo_slashes', $s)) . "')," : "sprintf('" . add_apo_slashes($s) . "',"); return $match[1] . (is_array($s) ? "lang(array('" . implode("', '", array_map('add_apo_slashes', $s)) . "')," : "sprintf('" . add_apo_slashes($s) . "',");
} }

View File

@@ -28,7 +28,7 @@ foreach (
} }
} }
foreach (glob(__DIR__ . "/adminer/lang/" . ($_SESSION["lang"] ? $_SESSION["lang"] : "*") . ".inc.php") as $filename) { foreach (glob(__DIR__ . "/adminer/lang/" . ($_SESSION["lang"] ?: "*") . ".inc.php") as $filename) {
$messages = $messages_all; $messages = $messages_all;
$file = file_get_contents($filename); $file = file_get_contents($filename);
$file = str_replace("\r", "", $file); $file = str_replace("\r", "", $file);

View File

@@ -57,7 +57,7 @@ if (isset($_GET["clickhouse"])) {
function connect($server, $username, $password) { function connect($server, $username, $password) {
preg_match('~^(https?://)?(.*)~', $server, $match); preg_match('~^(https?://)?(.*)~', $server, $match);
$this->_url = ($match[1] ? $match[1] : "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]"; $this->_url = ($match[1] ?: "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]";
$return = $this->query('SELECT 1'); $return = $this->query('SELECT 1');
return (bool) $return; return (bool) $return;
} }

View File

@@ -78,7 +78,7 @@ if (isset($_GET["elastic"])) {
*/ */
function connect($server, $username, $password) { function connect($server, $username, $password) {
preg_match('~^(https?://)?(.*)~', $server, $match); preg_match('~^(https?://)?(.*)~', $server, $match);
$this->_url = ($match[1] ? $match[1] : "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]"; $this->_url = ($match[1] ?: "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]";
$return = $this->query(''); $return = $this->query('');
if ($return) { if ($return) {
$this->server_info = $return['version']['number']; $this->server_info = $return['version']['number'];
@@ -529,7 +529,7 @@ if (isset($_GET["elastic"])) {
$properties = array(); $properties = array();
foreach ($fields as $f) { foreach ($fields as $f) {
$field_name = trim($f[1][0]); $field_name = trim($f[1][0]);
$field_type = trim($f[1][1] ? $f[1][1] : "text"); $field_type = trim($f[1][1] ?: "text");
$properties[$field_name] = array( $properties[$field_name] = array(
'type' => $field_type 'type' => $field_type
); );

View File

@@ -68,7 +68,7 @@ if (isset($_GET["elastic5"])) {
function connect($server, $username, $password) { function connect($server, $username, $password) {
preg_match('~^(https?://)?(.*)~', $server, $match); preg_match('~^(https?://)?(.*)~', $server, $match);
$this->_url = ($match[1] ? $match[1] : "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]"; $this->_url = ($match[1] ?: "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]";
$return = $this->query(''); $return = $this->query('');
if ($return) { if ($return) {
$this->server_info = $return['version']['number']; $this->server_info = $return['version']['number'];
@@ -505,7 +505,7 @@ if (isset($_GET["elastic5"])) {
$properties = array(); $properties = array();
foreach ($fields as $f) { foreach ($fields as $f) {
$field_name = trim($f[1][0]); $field_name = trim($f[1][0]);
$field_type = trim($f[1][1] ? $f[1][1] : "text"); $field_type = trim($f[1][1] ?: "text");
$properties[$field_name] = array( $properties[$field_name] = array(
'type' => $field_type 'type' => $field_type
); );

View File

@@ -439,7 +439,7 @@ if (isset($_GET["simpledb"])) {
} }
$connection->error = ''; $connection->error = '';
$tag = $action . "Result"; $tag = $action . "Result";
return ($xml->$tag ? $xml->$tag : true); return ($xml->$tag ?: true);
} }
function sdb_request_all($action, $tag, $params = array(), $timeout = 0) { function sdb_request_all($action, $tag, $params = array(), $timeout = 0) {