1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-19 04:41:25 +02:00

Replace strlen() by != ""

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1288 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana
2010-01-09 23:33:41 +00:00
parent 55ce473397
commit 7352c2813e
28 changed files with 135 additions and 135 deletions

View File

@@ -207,7 +207,7 @@ class Adminer {
}
$i = 0;
foreach ((array) $_GET["where"] as $val) {
if (strlen("$val[col]$val[val]") && in_array($val["op"], $this->operators)) {
if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
echo "<div><select name='where[$i][col]'><option value=''>" . lang('(anywhere)') . optionlist($columns, $val["col"], true) . "</select>";
echo html_select("where[$i][op]", $this->operators, $val["op"]);
echo "<input name='where[$i][val]' value='" . h($val["val"]) . "'></div>\n";
@@ -308,15 +308,15 @@ class Adminer {
global $connection;
$return = array();
foreach ($indexes as $i => $index) {
if ($index["type"] == "FULLTEXT" && strlen($_GET["fulltext"][$i])) {
if ($index["type"] == "FULLTEXT" && $_GET["fulltext"][$i] != "") {
$return[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . $connection->quote($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")";
}
}
foreach ((array) $_GET["where"] as $val) {
if (strlen("$val[col]$val[val]") && in_array($val["op"], $this->operators)) {
if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
$in = process_length($val["val"]);
$cond = " $val[op]" . (ereg('NULL$', $val["op"]) ? "" : (ereg('IN$', $val["op"]) ? " (" . (strlen($in) ? $in : "NULL") . ")" : " " . $this->processInput($fields[$val["col"]], $val["val"])));
if (strlen($val["col"])) {
$cond = " $val[op]" . (ereg('NULL$', $val["op"]) ? "" : (ereg('IN$', $val["op"]) ? " (" . ($in != "" ? $in : "NULL") . ")" : " " . $this->processInput($fields[$val["col"]], $val["val"])));
if ($val["col"] != "") {
$return[] = idf_escape($val["col"]) . $cond;
} else {
// find anywhere
@@ -505,7 +505,7 @@ class Adminer {
<form action="">
<p>
<?php if (SID) { ?><input type="hidden" name="<?php echo session_name(); ?>" value="<?php echo h(session_id()); ?>"><?php } ?>
<?php if (strlen($_GET["server"])) { ?><input type="hidden" name="server" value="<?php echo h($_GET["server"]); ?>"><?php } ?>
<?php if ($_GET["server"] != "") { ?><input type="hidden" name="server" value="<?php echo h($_GET["server"]); ?>"><?php } ?>
<?php echo ($databases ? html_select("db", array("" => "(" . lang('database') . ")") + $databases, DB, "this.form.submit();") : '<input name="db" value="' . h(DB) . '">'); ?>
<?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value=""><?php } ?>
<?php if (isset($_GET["schema"])) { ?><input type="hidden" name="schema" value=""><?php } ?>
@@ -514,7 +514,7 @@ class Adminer {
</p>
</form>
<?php
if ($missing != "db" && strlen(DB) && $connection->select_db(DB)) {
if ($missing != "db" && DB != "" && $connection->select_db(DB)) {
$tables = tables_list();
if (!$tables) {
echo "<p class='message'>" . lang('No tables.') . "\n";

View File

@@ -11,7 +11,7 @@ if (isset($_POST["server"])) {
);
}
if (count($_POST) == 3 + ($_POST["permanent"] ? 1 : 0)) { // 3 - server, username, password
$location = ((string) $_GET["server"] === $_POST["server"] ? remove_from_uri(session_name()) : preg_replace('~^([^?]*).*~', '\\1', ME) . (strlen($_POST["server"]) ? '?server=' . urlencode($_POST["server"]) : ''));
$location = ((string) $_GET["server"] === $_POST["server"] ? remove_from_uri(session_name()) : preg_replace('~^([^?]*).*~', '\\1', ME) . ($_POST["server"] != "" ? '?server=' . urlencode($_POST["server"]) : ''));
if (SID) {
$pos = strpos($location, '?');
$location = ($pos ? substr_replace($location, SID . "&", $pos + 1, 0) : "$location?" . SID);
@@ -37,7 +37,7 @@ if (isset($_POST["server"])) {
}
} elseif ($_COOKIE["adminer_permanent"] && !isset($_SESSION["usernames"][$_GET["server"]])) {
list($server, $username, $cipher) = array_map('base64_decode', explode(":", $_COOKIE["adminer_permanent"]));
if (!strlen($_GET["server"]) || $server == $_GET["server"]) {
if ($_GET["server"] == "" || $server == $_GET["server"]) {
session_regenerate_id(); // defense against session fixation
$_SESSION["usernames"][$server] = $username;
$_SESSION["passwords"][$server] = decrypt_string($cipher, $adminer->permanentLogin());

View File

@@ -40,7 +40,7 @@ if (isset($_GET["file"])) {
}
if (!isset($_SERVER["REQUEST_URI"])) {
$_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"] . (strlen($_SERVER["QUERY_STRING"]) ? "?$_SERVER[QUERY_STRING]" : "");
$_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"] . ($_SERVER["QUERY_STRING"] != "" ? "?$_SERVER[QUERY_STRING]" : "");
}
session_write_close(); // disable session.auto_start
@@ -75,7 +75,7 @@ if (function_exists("set_magic_quotes_runtime")) {
@set_time_limit(0); // @ - can be disabled
define("DB", $_GET["db"]); // for the sake of speed and size
define("ME", preg_replace('~^[^?]*/([^?]*).*~', '\\1', $_SERVER["REQUEST_URI"]) . '?' . (SID ? SID . '&' : '') . (strlen($_GET["server"]) ? 'server=' . urlencode($_GET["server"]) . '&' : '') . (strlen(DB) ? 'db=' . urlencode(DB) . '&' : ''));
define("ME", preg_replace('~^[^?]*/([^?]*).*~', '\\1', $_SERVER["REQUEST_URI"]) . '?' . (SID ? SID . '&' : '') . ($_GET["server"] != "" ? 'server=' . urlencode($_GET["server"]) . '&' : '') . (DB != "" ? 'db=' . urlencode(DB) . '&' : ''));
include "../adminer/include/version.inc.php";
include "../adminer/include/functions.inc.php";

View File

@@ -1,7 +1,7 @@
<?php
function connect_error() {
global $connection, $VERSION, $token, $error;
if (strlen(DB)) {
if (DB != "") {
page_header(lang('Database') . ": " . h(DB), lang('Invalid database.'), false);
} else {
if ($_POST["db"] && !$error) {
@@ -51,8 +51,8 @@ function connect_error() {
if (isset($_GET["status"])) {
$_GET["variables"] = $_GET["status"];
}
if (!(strlen(DB) ? $connection->select_db(DB) : isset($_GET["sql"]) || isset($_GET["dump"]) || isset($_GET["database"]) || isset($_GET["processlist"]) || isset($_GET["privileges"]) || isset($_GET["user"]) || isset($_GET["variables"]))) {
if (strlen(DB)) {
if (!(DB != "" ? $connection->select_db(DB) : isset($_GET["sql"]) || isset($_GET["dump"]) || isset($_GET["database"]) || isset($_GET["processlist"]) || isset($_GET["privileges"]) || isset($_GET["user"]) || isset($_GET["variables"]))) {
if (DB != "") {
unset($_SESSION["databases"][$_GET["server"]]);
}
connect_error(); // separate function to catch SQLite error

View File

@@ -3,14 +3,14 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
global $LANG, $VERSION, $adminer, $connection;
header("Content-Type: text/html; charset=utf-8");
header("X-Frame-Options: deny"); // ClickJacking protection in IE8, Safari 4, Chrome 2, NoScript plugin
$title_all = $title . (strlen($title2) ? ": " . h($title2) : "");
$title_all = $title . ($title2 != "" ? ": " . h($title2) : "");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="<?php echo $LANG; ?>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta name="robots" content="noindex">
<title><?php echo $title_all . (strlen($_GET["server"]) && $_GET["server"] != "localhost" ? h("- $_GET[server]") : "") . " - " . $adminer->name(); ?></title>
<title><?php echo $title_all . ($_GET["server"] != "" && $_GET["server"] != "localhost" ? h("- $_GET[server]") : "") . " - " . $adminer->name(); ?></title>
<link rel="shortcut icon" type="image/x-icon" href="../adminer/static/favicon.ico">
<link rel="stylesheet" type="text/css" href="../adminer/static/default.css<?php // Ondrej Valka, http://valka.info ?>">
<?php if (file_exists("adminer.css")) { ?>
@@ -25,14 +25,14 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
<?php
if (isset($breadcrumb)) {
$link = substr(preg_replace('~db=[^&]*&~', '', ME), 0, -1);
echo '<p id="breadcrumb"><a href="' . (strlen($link) ? h($link) : ".") . '">' . (isset($_GET["server"]) ? h($_GET["server"]) : lang('Server')) . '</a> &raquo; ';
echo '<p id="breadcrumb"><a href="' . ($link != "" ? h($link) : ".") . '">' . (isset($_GET["server"]) ? h($_GET["server"]) : lang('Server')) . '</a> &raquo; ';
if (is_array($breadcrumb)) {
if (strlen(DB)) {
if (DB != "") {
echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h(DB) . '</a> &raquo; ';
}
foreach ($breadcrumb as $key => $val) {
$desc = (is_array($val) ? $val[1] : $val);
if (strlen($desc)) {
if ($desc != "") {
echo '<a href="' . h(ME . "$key=") . urlencode(is_array($val) ? $val[0] : $val) . '">' . h($desc) . '</a> &raquo; ';
}
}
@@ -49,7 +49,7 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
$_SESSION["passwords"] = array();
}
$databases = &$_SESSION["databases"][$_GET["server"]];
if (strlen(DB) && $databases && !in_array(DB, $databases, true)) {
if (DB != "" && $databases && !in_array(DB, $databases, true)) {
$databases = null;
}
if ($error) {

View File

@@ -20,7 +20,7 @@ function select($result, $connection2 = null) {
echo "<thead><tr>";
for ($j=0; $j < count($row); $j++) {
$field = $result->fetch_field();
if (strlen($field->orgtable)) {
if ($field->orgtable != "") {
if (!isset($indexes[$field->orgtable])) {
// find primary key in each table
$indexes[$field->orgtable] = array();
@@ -53,7 +53,7 @@ function select($result, $connection2 = null) {
} else {
if ($blobs[$key] && !is_utf8($val)) {
$val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>"; //! link to download
} elseif (!strlen($val)) {
} elseif ($val == "") {
$val = "&nbsp;"; // some content to print a border
} else {
$val = h($val);
@@ -132,7 +132,7 @@ function process_length($length) {
function process_type($field, $collate = "COLLATE") {
global $connection, $unsigned;
return " $field[type]"
. (strlen($field["length"]) && !ereg('^date|time$', $field["type"]) ? "(" . process_length($field["length"]) . ")" : "")
. ($field["length"] != "" && !ereg('^date|time$', $field["type"]) ? "(" . process_length($field["length"]) . ")" : "")
. (ereg('int|float|double|decimal', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "")
. (ereg('char|text|enum|set', $field["type"]) && $field["collation"] ? " $collate " . $connection->quote($field["collation"]) : "")
;
@@ -182,7 +182,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $allowed = 0, $forei
global $inout;
$column_comments = false;
foreach ($fields as $field) {
if (strlen($field["comment"])) {
if ($field["comment"] != "") {
$column_comments = true;
break;
}
@@ -213,7 +213,7 @@ if ($type == "PROCEDURE") {
echo "<td>" . html_select("fields[$i][inout]", $inout, $field["inout"]);
}
?>
<th><?php if ($display) { ?><input name="fields[<?php echo $i; ?>][field]" value="<?php echo h($field["field"]); ?>" onchange="<?php echo (strlen($field["field"]) || count($fields) > 1 ? "" : "editingAddRow(this, $allowed); "); ?>editingNameChange(this);" maxlength="64"><?php } ?><input type="hidden" name="fields[<?php echo $i; ?>][orig]" value="<?php echo h($field[($_POST ? "orig" : "field")]); ?>">
<th><?php if ($display) { ?><input name="fields[<?php echo $i; ?>][field]" value="<?php echo h($field["field"]); ?>" onchange="<?php echo ($field["field"] != "" || count($fields) > 1 ? "" : "editingAddRow(this, $allowed); "); ?>editingNameChange(this);" maxlength="64"><?php } ?><input type="hidden" name="fields[<?php echo $i; ?>][orig]" value="<?php echo h($field[($_POST ? "orig" : "field")]); ?>">
<?php edit_type("fields[$i]", $field, $collations, $foreign_keys); ?>
<?php if ($type == "TABLE") { ?>
<td><?php echo checkbox("fields[$i][null]", 1, $field["null"]); ?>
@@ -348,9 +348,9 @@ function drop_create($drop, $create, $location, $message_drop, $message_alter, $
if ($_POST["drop"]) {
return query_redirect($drop, $location, $message_drop, true, !$_POST["dropped"]);
}
$dropped = strlen($name) && ($_POST["dropped"] || queries($drop));
$dropped = $name != "" && ($_POST["dropped"] || queries($drop));
$created = queries($create);
if (!queries_redirect($location, (strlen($name) ? $message_alter : $message_create), $created) && $dropped) {
if (!queries_redirect($location, ($name != "" ? $message_alter : $message_create), $created) && $dropped) {
restart_session();
$_SESSION["messages"][] = $message_drop;
}

View File

@@ -167,7 +167,7 @@ function dump_data($table, $style, $select = "") {
}
function dump_headers($identifier, $multi_table = false) {
$filename = (strlen($identifier) ? friendly_url($identifier) : "dump");
$filename = ($identifier != "" ? friendly_url($identifier) : "dump");
$output = $_POST["output"];
$ext = ($_POST["format"] == "sql" ? "sql" : ($multi_table ? "tar" : "csv")); // multiple CSV packed to TAR
header("Content-Type: " .

View File

@@ -57,7 +57,7 @@ function h($string) {
* @return string
*/
function nbsp($string) {
return (strlen(trim($string)) ? h($string) : "&nbsp;");
return (trim($string) != "" ? h($string) : "&nbsp;");
}
/** Generate HTML checkbox
@@ -72,7 +72,7 @@ function checkbox($name, $value, $checked, $label = "", $onclick = "") {
static $id = 0;
$id++;
$return = "<input type='checkbox' name='$name' value='" . h($value) . "'" . ($checked ? " checked" : "") . ($onclick ? " onclick=\"$onclick\"" : "") . " id='checkbox-$id'>";
return (strlen($label) ? "<label for='checkbox-$id'>$return" . h($label) . "</label>" : $return);
return ($label != "" ? "<label for='checkbox-$id'>$return" . h($label) . "</label>" : $return);
}
/** Generate list of HTML options
@@ -227,7 +227,7 @@ function redirect($location, $message = null) {
restart_session();
$_SESSION["messages"][] = $message;
}
header("Location: " . (strlen($location) ? $location : "."));
header("Location: " . ($location != "" ? $location : "."));
exit;
}
@@ -430,7 +430,7 @@ function input($field, $value, $function) {
$attrs = " name='fields[$name]'$onchange";
echo (count($functions) > 1 ? html_select("function[$name]", $functions, !isset($function) || in_array($function, $functions) ? $function : "") : nbsp(reset($functions))) . '<td>';
$input = $adminer->editInput($_GET["edit"], $field, $attrs, $value); // usage in call is without a table
if (strlen($input)) {
if ($input != "") {
echo $input;
} elseif ($field["type"] == "set") { //! 64 bits
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
@@ -462,7 +462,7 @@ function process_input($field) {
$value = $_POST["fields"][$idf];
if ($field["type"] == "enum" ? $value == -1 : $function == "orig") {
return false;
} elseif ($field["type"] == "enum" || $field["auto_increment"] ? !strlen($value) : $function == "NULL") {
} elseif ($field["type"] == "enum" || $field["auto_increment"] ? $value == "" : $function == "NULL") {
return "NULL";
} elseif ($field["type"] == "enum") {
return intval($value);
@@ -485,7 +485,7 @@ function process_input($field) {
*/
function dump_csv($row) {
foreach ($row as $key => $val) {
if (preg_match("~[\"\n,]~", $val) || (isset($val) && !strlen($val))) {
if (preg_match("~[\"\n,]~", $val) || $val === "") {
$row[$key] = '"' . str_replace('"', '""', $val) . '"';
}
}

View File

@@ -11,9 +11,9 @@ if (extension_loaded("mysqli")) {
function connect($server, $username, $password) {
list($host, $port) = explode(":", $server, 2); // part after : is used for port or socket
return @$this->real_connect(
(strlen($server) ? $host : ini_get("mysqli.default_host")),
(strlen("$server$username") ? $username : ini_get("mysqli.default_user")),
(strlen("$server$username$password") ? $password : ini_get("mysqli.default_pw")),
($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,
(is_numeric($port) ? $port : ini_get("mysqli.default_port")),
(!is_numeric($port) ? $port : null)
@@ -39,9 +39,9 @@ if (extension_loaded("mysqli")) {
function connect($server, $username, $password) {
$this->_link = @mysql_connect(
(strlen($server) ? $server : ini_get("mysql.default_host")),
(strlen("$server$username") ? $username : ini_get("mysql.default_user")),
(strlen("$server$username$password") ? $password : ini_get("mysql.default_password")),
($server != "" ? $server : ini_get("mysql.default_host")),
("$server$username" != "" ? $username : ini_get("mysql.default_user")),
("$server$username$password" != "" ? $password : ini_get("mysql.default_password")),
true,
131072 // CLIENT_MULTI_RESULTS for CALL
);
@@ -229,13 +229,13 @@ function tables_list() {
function table_status($name = "") {
global $connection;
$return = array();
$result = $connection->query("SHOW TABLE STATUS" . (strlen($name) ? " LIKE " . $connection->quote(addcslashes($name, "%_")) : ""));
$result = $connection->query("SHOW TABLE STATUS" . ($name != "" ? " LIKE " . $connection->quote(addcslashes($name, "%_")) : ""));
while ($row = $result->fetch_assoc()) {
if ($row["Engine"] == "InnoDB") {
// ignore internal comment, unnecessary since MySQL 5.1.21
$row["Comment"] = preg_replace('~(?:(.+); )?InnoDB free: .*~', '\\1', $row["Comment"]);
}
if (strlen($name)) {
if ($name != "") {
return $row;
}
$return[$row["Name"]] = $row;
@@ -273,7 +273,7 @@ function fields($table) {
"type" => $match[1],
"length" => $match[2],
"unsigned" => ltrim($match[3] . $match[4]),
"default" => (strlen($row["Default"]) || ereg("char", $match[1]) ? $row["Default"] : null),
"default" => ($row["Default"] != "" || ereg("char", $match[1]) ? $row["Default"] : null),
"null" => ($row["Null"] == "YES"),
"auto_increment" => ($row["Extra"] == "auto_increment"),
"on_update" => (eregi('^on update (.+)', $row["Extra"], $match) ? $match[1] : ""), //! available since MySQL 5.1.23
@@ -325,8 +325,8 @@ function foreign_keys($table) {
preg_match_all("~`($pattern)`~", $match[2], $source);
preg_match_all("~`($pattern)`~", $match[5], $target);
$return[$match[1]] = array(
"db" => idf_unescape(strlen($match[4]) ? $match[3] : $match[4]),
"table" => idf_unescape(strlen($match[4]) ? $match[4] : $match[3]),
"db" => idf_unescape($match[4] != "" ? $match[3] : $match[4]),
"table" => idf_unescape($match[4] != "" ? $match[4] : $match[3]),
"source" => array_map('idf_unescape', $source[1]),
"target" => array_map('idf_unescape', $target[1]),
"on_delete" => $match[6],