1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-18 12:21:24 +02:00

E-mail sending

Change Adminer class to adminer_ functions.inc.php
Unify includes
Unify adminer_credentials()
Don't use JUSH in Editor
Separate identifier and description in breadcrumb
Simplify where()

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@800 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana
2009-07-11 19:45:57 +00:00
parent 1ae22acb55
commit c16c57b1b1
27 changed files with 350 additions and 206 deletions

View File

@@ -1,35 +1,86 @@
<?php
class AdminerBase {
function name() {
return lang('Adminer');
/** Name in title and navigation
* @return string
*/
function adminer_name() {
return call_adminer('name', lang('Adminer'));
}
/** Connection parameters
* @return array ($server, $username, $password)
*/
function adminer_credentials() {
return call_adminer('credentials', array($_GET["server"], $_SESSION["usernames"][$_GET["server"]], $_SESSION["passwords"][$_GET["server"]]));
}
/** Identifier of selected database
* @return string
*/
function adminer_database() {
// should be used everywhere instead of $_GET["db"]
return call_adminer('database', $_GET["db"]);
}
/** Table caption used in navigation and headings
* @param array result of SHOW TABLE STATUS
* @return string
*/
function adminer_table_name($row) {
return call_adminer('table_name', htmlspecialchars($row["Name"]), $row);
}
/** Field caption used in select and edit
* @param array all fields in table, result of fields()
* @param string column identifier, function calls are not contained in $fields
* @return string
*/
function adminer_field_name($fields, $key) {
return call_adminer('field_name', htmlspecialchars($key), $fields, $key);
}
/** Links after select heading
* @param array result of SHOW TABLE STATUS
* @return string
*/
function adminer_select_links($table_status) {
global $SELF;
return call_adminer('select_links', '<a href="' . htmlspecialchars($SELF) . (isset($table_status["Engine"]) ? 'table=' : 'view=') . urlencode($_GET['select']) . '">' . lang('Table structure') . '</a>', $table_status);
}
/** Process and print select query before execution
* @param string query to be executed
* @return string
*/
function adminer_select_query($query) {
global $SELF;
// it would be nice if $query can be passed by reference and printed value would be returned but call_user() doesn't allow reference parameters
$return = call_adminer('select_query', "", $query);
if (!$return) {
echo "<p><code class='jush-sql'>" . htmlspecialchars($query) . "</code> <a href='" . htmlspecialchars($SELF) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a></p>\n";
return $query;
}
function server() {
return $_GET["server"];
}
function username() {
return $_SESSION["usernames"][$_GET["server"]];
}
function password() {
return $_SESSION["passwords"][$_GET["server"]];
}
function table_name($row) {
return htmlspecialchars($row["Name"]);
}
function field_name($fields, $key) {
return htmlspecialchars($key);
}
function navigation($missing) {
global $SELF;
if ($missing != "auth") {
$databases = get_databases();
?>
return $return;
}
/** Query printed after execution in the message
* @param string executed query
* @return string
*/
function adminer_message_query($query) {
global $SELF;
$id = "sql-" . count($_SESSION["messages"]);
return call_adminer('message_query', " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre class='jush-sql'>" . htmlspecialchars($query) . '</pre><a href="' . htmlspecialchars($SELF . 'sql=&history=' . count($_SESSION["history"][$_GET["server"]][$_GET["db"]])) . '">' . lang('Edit') . '</a></div>', $query);
}
/** Prints navigation after Adminer title
* @param string can be "auth" if there is no database connection or "db" if there is no database selected
* @return bool true if default navigation should be printed
*/
function adminer_navigation($missing) {
global $SELF;
if (call_adminer('navigation', true, $missing) && $missing != "auth") {
$databases = get_databases();
?>
<form action="" method="post">
<p>
<a href="<?php echo htmlspecialchars($SELF); ?>sql="><?php echo lang('SQL command'); ?></a>
@@ -52,22 +103,19 @@ class AdminerBase {
</p>
</form>
<?php
if ($missing != "db" && strlen($_GET["db"])) {
$table_status = table_status();
if (!$table_status) {
echo "<p class='message'>" . lang('No tables.') . "</p>\n";
} else {
echo "<p>\n";
foreach ($table_status as $row) {
echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '">' . lang('select') . '</a> ';
echo '<a href="' . htmlspecialchars($SELF) . (isset($row["Rows"]) ? 'table' : 'view') . '=' . urlencode($row["Name"]) . '">' . $this->table_name($row) . "</a><br />\n";
}
echo "</p>\n";
if ($missing != "db" && strlen($_GET["db"])) {
$table_status = table_status();
if (!$table_status) {
echo "<p class='message'>" . lang('No tables.') . "</p>\n";
} else {
echo "<p>\n";
foreach ($table_status as $row) {
echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '">' . lang('select') . '</a> ';
echo '<a href="' . htmlspecialchars($SELF) . (isset($row["Rows"]) ? 'table' : 'view') . '=' . urlencode($row["Name"]) . '">' . adminer_table_name($row) . "</a><br />\n";
}
echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a></p>\n";
echo "</p>\n";
}
echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a></p>\n";
}
}
}
$adminer = (class_exists("Adminer") ? new Adminer : new AdminerBase);

View File

@@ -24,6 +24,9 @@ if (isset($_GET["file"])) {
} elseif ($_GET["file"] == "functions.js") {
header("Content-Type: text/javascript");
?>compile_file('functions.js', 'JSMin::minify')<?php
} elseif ($_GET["file"] == "editing.js") {
header("Content-Type: text/javascript");
?>compile_file('editing.js', 'JSMin::minify')<?php
} else {
header("Content-Type: image/gif");
switch ($_GET["file"]) {
@@ -78,4 +81,20 @@ if (get_magic_quotes_gpc()) {
set_magic_quotes_runtime(false);
$SELF = (isset($_SERVER["REQUEST_URI"]) ? preg_replace('~^[^?]*/([^?]*).*~', '\\1', $_SERVER["REQUEST_URI"]) : $_SERVER["ORIG_PATH_INFO"]) . '?' . (strlen($_GET["server"]) ? 'server=' . urlencode($_GET["server"]) . '&' : '') . (strlen($_GET["db"]) ? 'db=' . urlencode($_GET["db"]) . '&' : '');
$on_actions = array("RESTRICT", "CASCADE", "SET NULL", "NO ACTION");
$on_actions = array("RESTRICT", "CASCADE", "SET NULL", "NO ACTION"); // used in foreign_keys()
include "../adminer/include/version.inc.php";
include "../adminer/include/functions.inc.php";
include "../adminer/include/lang.inc.php";
include "./lang/$LANG.inc.php";
include "./include/adminer.inc.php";
include "../adminer/include/design.inc.php";
if (isset($_GET["coverage"])) {
include "../adminer/coverage.inc.php";
}
include "../adminer/include/pdo.inc.php";
include "../adminer/include/mysql.inc.php";
include "./include/auth.inc.php";
include "./include/connect.inc.php";
include "./include/editing.inc.php";
include "./include/export.inc.php";

View File

@@ -1,6 +1,6 @@
<?php
function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
global $SELF, $LANG, $VERSION, $adminer;
global $SELF, $LANG, $VERSION;
header("Content-Type: text/html; charset=utf-8");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@@ -9,17 +9,17 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
<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 . (strlen($title2) ? ": " . htmlspecialchars($title2) : "") . (strlen($_GET["server"]) && $_GET["server"] != "localhost" ? htmlspecialchars("- $_GET[server]") : "") . " - " . $adminer->name(); ?></title>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
<title><?php echo $title . (strlen($title2) ? ": " . htmlspecialchars($title2) : "") . (strlen($_GET["server"]) && $_GET["server"] != "localhost" ? htmlspecialchars("- $_GET[server]") : "") . " - " . adminer_name(); ?></title>
<link rel="shortcut icon" type="image/x-icon" href="../adminer/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../adminer/default.css<?php // Ondrej Valka, http://valka.info ?>" />
<?php if (file_exists("adminer.css")) { ?>
<link rel="stylesheet" type="text/css" href="adminer.css" />
<?php } ?>
</head>
<body onload="load_jush();<?php echo (isset($_COOKIE["adminer_version"]) ? "" : " verify_version('$VERSION');"); ?>">
<body onload="body_load();<?php echo (isset($_COOKIE["adminer_version"]) ? "" : " verify_version('$VERSION');"); ?>">
<script type="text/javascript" src="../adminer/functions.js"></script>
<script type="text/javascript" src="./editing.js"></script>
<script type="text/javascript" src="./editing.js<?php // "./" to distinguish from $_GET["file"] ?>"></script>
<div id="content">
<?php
@@ -31,8 +31,9 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
echo '<a href="' . htmlspecialchars(substr($SELF, 0, -1)) . '">' . htmlspecialchars($_GET["db"]) . '</a> &raquo; ';
}
foreach ($breadcrumb as $key => $val) {
if (strlen($val)) {
echo '<a href="' . htmlspecialchars("$SELF$key=") . ($key != "privileges" ? urlencode($val) : "") . '">' . htmlspecialchars($val) . '</a> &raquo; ';
$desc = (is_array($val) ? $val[1] : $val);
if (strlen($desc)) {
echo '<a href="' . htmlspecialchars("$SELF$key=") . urlencode(is_array($val) ? $val[0] : $val) . '">' . htmlspecialchars($desc) . '</a> &raquo; ';
}
}
}
@@ -57,16 +58,16 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
}
function page_footer($missing = false) {
global $SELF, $VERSION, $dbh, $adminer;
global $SELF, $VERSION, $dbh;
?>
</div>
<?php switch_lang(); ?>
<div id="menu">
<h1><a href="http://www.adminer.org/" class="h1"><?php echo $adminer->name(); ?></a> &nbsp; <?php echo $VERSION; ?> &nbsp;
<h1><a href="http://www.adminer.org/" class="h1"><?php echo adminer_name(); ?></a> &nbsp; <?php echo $VERSION; ?> &nbsp;
<a href='http://www.adminer.org/#download' id="version"><?php echo (version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? htmlspecialchars($_COOKIE["adminer_version"]) : ""); ?></a>
</h1>
<?php $adminer->navigation($missing); ?>
<?php adminer_navigation($missing); ?>
</div>
</body>

View File

@@ -58,7 +58,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $allowed = 0, $forei
<td><input type="radio" name="auto_increment_col" value="" /><?php echo lang('Auto Increment'); ?></td>
<td<?php echo ($column_comments ? "" : " class='hidden'"); ?>><?php echo lang('Comment'); ?></td>
<?php } ?>
<td><?php echo "<input type='image' name='add[0]' src='../adminer/plus.gif' alt='+' title='" . lang("Add next") . "' />"; ?><script type="text/javascript">row_count = <?php echo count($fields); ?>;</script></td>
<td><?php echo "<input type='image' name='add[0]' src='../adminer/plus.gif' alt='+' title='" . lang('Add next') . "' />"; ?><script type="text/javascript">row_count = <?php echo count($fields); ?>;</script></td>
</tr></thead>
<?php
foreach ($fields as $i => $field) {

View File

@@ -73,7 +73,7 @@ function where($where) {
$key = bracket_escape($key, "back");
$return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]+|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " IS NULL";
}
return $return;
return implode(" AND ", $return);
}
function where_check($val) {
@@ -100,10 +100,9 @@ function redirect($location, $message = null) {
function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false) {
global $dbh, $error, $SELF;
$id = "sql-" . count($_SESSION["messages"]);
$sql = "";
if ($query) {
$sql = " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><span id='$id' class='hidden'><pre class='jush-sql'>" . htmlspecialchars($query) . '</pre><a href="' . htmlspecialchars($SELF . 'sql=&history=' . count($_SESSION["history"][$_GET["server"]][$_GET["db"]])) . '">' . lang('Edit') . '</a></span>';
$sql = adminer_message_query($query);
$_SESSION["history"][$_GET["server"]][$_GET["db"]][] = $query;
}
if ($execute) {
@@ -367,3 +366,26 @@ function dump_csv($row) {
}
echo implode(",", $row) . "\n";
}
function is_email($email) {
$atom = '[-a-z0-9!#$%&\'*+/=?^_`{|}~]'; // characters of local-name
$domain = '[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])'; // one domain component
return eregi("^$atom+(\\.$atom+)*@($domain?\\.)+$domain\$", $email);
}
function email_header($header) {
return chunk_split("=?UTF-8?B?" . base64_encode($header), 67, "\n "); // iconv_mime_encode requires PHP 5, imap_8bit requires IMAP extension
}
function call_adminer($method, $default, $arg1 = null, $arg2 = null) {
static $adminer;
if (!isset($adminer)) {
$adminer = (class_exists('Adminer') ? new Adminer : false); // user defined class
}
// maintains original method name in minification
if (method_exists($adminer, $method)) {
// can use func_get_args() and call_user_func_array()
return $adminer->$method($arg1, $arg2);
}
return $default; //! $default is evaluated even if not neccessary
}

View File

@@ -1,5 +1,5 @@
<?php
// not used in single language version
// not used in a single language version
$langs = array(
'en' => 'English', // Jakub Vrána - http://php.vrana.cz

View File

@@ -204,9 +204,9 @@ $types = array(
$unsigned = array("unsigned", "zerofill", "unsigned zerofill");
function connect() {
global $adminer;
$dbh = new Min_DB;
if ($dbh->connect($adminer->server(), $adminer->username(), $adminer->password())) {
$credentials = adminer_credentials();
if ($dbh->connect($credentials[0], $credentials[1], $credentials[2])) {
$dbh->query("SET SQL_QUOTE_SHOW_CREATE=1");
$dbh->query("SET NAMES utf8");
return $dbh;