This commit is contained in:
Jakub Vrana 2011-02-09 17:57:10 +01:00
parent 37ecc2932b
commit 4f9ff89fed
13 changed files with 597 additions and 0 deletions

3
.gitmodules vendored
View file

@ -4,3 +4,6 @@
[submodule "jsmin-php"]
path = externals/jsmin-php
url = git://github.com/rgrove/jsmin-php.git
[submodule "tinymce"]
path = externals/tinymce
url = git://github.com/tinymce/tinymce.git

23
adminer/plugin.php Normal file
View file

@ -0,0 +1,23 @@
<?php
function adminer_object() {
// required to run any plugin
include_once "../plugins/plugin.php";
// autoloader
foreach (glob("../plugins/*.php") as $filename) {
include_once $filename;
}
return new AdminerPlugin(array(
// specify enabled plugins here
new AdminerDumpXml,
new AdminerTinymce("../externals/tinymce/jscripts/tiny_mce/tiny_mce_dev.js"),
new AdminerFileUpload(""),
new AdminerSlugify,
new AdminerTranslation,
new AdminerForeignSystem,
));
}
// include original Adminer or Adminer Editor (usually named adminer.php)
include "./index.php";

1
externals/tinymce vendored Submodule

@ -0,0 +1 @@
Subproject commit 00968708de306f79d7bf799a2269dc31d447f097

46
plugins/dump-xml.php Normal file
View file

@ -0,0 +1,46 @@
<?php
/** Dump to XML format in structure <database name=""><table name=""><column name="">value
* @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)
*/
class AdminerDumpXml {
function dumpFormat() {
return array('xml' => 'XML');
}
function dumpTable($table, $style, $is_view = false) {
if ($_POST["format"] == "xml") {
return true;
}
}
function dumpData($table, $style, $query) {
if ($_POST["format"] == "xml") {
echo "<database name='" . h(DB) . "'>\n";
$connection = connection();
$result = $connection->query($query, 1);
if ($result) {
while ($row = $result->fetch_assoc()) {
echo "\t<table name='" . h($table) . "'>\n";
foreach ($row as $key => $val) {
echo "\t\t<column name='" . h($key) . "'>" . h($val) . "</column>\n";
}
echo "\t</table>\n";
}
}
echo "</database>\n";
return true;
}
}
function dumpHeaders($identifier, $multi_table = false) {
if ($_POST["format"] == "xml") {
header("Content-Type: text/xml; charset=utf-8");
return "xml";
}
}
}

0
plugins/email-html.php Normal file
View file

48
plugins/file-upload.php Normal file
View file

@ -0,0 +1,48 @@
<?php
/** Edit fields ending with "_path" by <input type="file"> and link to the uploaded files from select
* @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)
*/
class AdminerFileUpload {
var $uploadPath, $displayPath;
/**
* @param string prefix for uploading data (create writable subdirectory for each table containing uploadable fields)
* @param string prefix for displaying data, null stands for $uploadPath
*/
function AdminerFileUpload($uploadPath = "../static/data/", $displayPath = null) {
$this->uploadPath = $uploadPath;
$this->displayPath = (isset($displayPath) ? $displayPath : $uploadPath);
}
function editInput($table, $field, $attrs, $value) {
if (ereg('(.*)_path$', $field["field"])) {
return "<input type='file' name='fields-$field[field]'>";
}
}
function processInput($field, $value, $function = "") {
if (ereg('(.*)_path$', $field["field"], $regs)) {
$table = ($_GET["edit"] != "" ? $_GET["edit"] : $_GET["select"]);
$name = "fields-$field[field]";
if ($_FILES[$name]["error"] || !eregi('(\\.([a-z0-9]+))?$', $_FILES[$name]["name"], $regs2)) {
return false;
}
//! unlink old
$filename = uniqid() . $regs2[0];
if (!move_uploaded_file($_FILES[$name]["tmp_name"], "$this->uploadPath$table/$regs[1]-$filename")) {
return false;
}
return q($filename);
}
}
function selectVal($val, &$link, $field) {
if ($val != "&nbsp;" && ereg('(.*)_path$', $field["field"], $regs)) {
$link = "$this->displayPath$_GET[select]/$regs[1]-$val";
}
}
}

View file

@ -0,0 +1,55 @@
<?php
/** Link system tables (in mysql and information_schema databases) by foreign keys
* @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)
*/
class AdminerForeignSystem {
function foreignKeys($table) {
if (DRIVER == "server" && DB == "mysql") {
switch ($table) {
case "columns_priv": return array(array("table" => "user", "source" => array("Host", "User"), "target" => array("Host", "User")));
case "db": return array(array("table" => "user", "source" => array("Host", "User"), "target" => array("Host", "User")));
case "help_category": return array(array("table" => "help_category", "source" => array("parent_category_id"), "target" => array("help_category_id")));
case "help_relation": return array(array("table" => "help_topic", "source" => array("help_topic_id"), "target" => array("help_topic_id")), array("table" => "help_keyword", "source" => array("help_keyword_id"), "target" => array("help_keyword_id")));
case "help_topic": return array(array("table" => "help_category", "source" => array("help_category_id"), "target" => array("help_category_id")));
case "procs_priv": return array(array("table" => "user", "source" => array("Host", "User"), "target" => array("Host", "User")), array("table" => "proc", "source" => array("Db", "Routine_name"), "target" => array("db", "name")));
case "tables_priv": return array(array("table" => "user", "source" => array("Host", "User"), "target" => array("Host", "User")));
case "time_zone_name": return array(array("table" => "time_zone", "source" => array("Time_zone_id"), "target" => array("Time_zone_id")));
case "time_zone_transition": return array(array("table" => "time_zone", "source" => array("Time_zone_id"), "target" => array("Time_zone_id")), array("table" => "time_zone_transition_type", "source" => array("Time_zone_id", "Transition_type_id"), "target" => array("Time_zone_id", "Transition_type_id")));
case "time_zone_transition_type": return array(array("table" => "time_zone", "source" => array("Time_zone_id"), "target" => array("Time_zone_id")));
}
} elseif (DB == "information_schema") {
$schemata = array("table" => "SCHEMATA", "source" => array("TABLE_CATALOG", "TABLE_SCHEMA"), "target" => array("CATALOG_NAME", "SCHEMA_NAME"));
$tables = array("table" => "TABLES", "source" => array("TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME"), "target" => array("TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME"));
$columns = array("table" => "COLUMNS", "source" => array("TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME", "COLUMN_NAME"), "target" => array("TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME", "COLUMN_NAME"));
$character_sets = array("table" => "CHARACTER_SETS", "source" => array("CHARACTER_SET_NAME"), "target" => array("CHARACTER_SET_NAME"));
$collations = array("table" => "COLLATIONS", "source" => array("COLLATION_NAME"), "target" => array("COLLATION_NAME"));
$routine_charsets = array(array("source" => array("CHARACTER_SET_CLIENT")) + $character_sets, array("source" => array("COLLATION_CONNECTION")) + $collations, array("source" => array("DATABASE_COLLATION")) + $collations);
switch ($table) {
case "CHARACTER_SETS": return array(array("source" => array("DEFAULT_COLLATE_NAME")) + $collations);
case "COLLATIONS": return array($character_sets);
case "COLLATION_CHARACTER_SET_APPLICABILITY": return array($collations, $character_sets);
case "COLUMNS": return array($schemata, $tables, $character_sets, $collations);
case "COLUMN_PRIVILEGES": return array($schemata, $tables, $columns);
case "TABLES": return array($schemata, array("source" => array("TABLE_COLLATION")) + $collations);
case "SCHEMATA": return array(array("source" => array("DEFAULT_CHARACTER_SET_NAME")) + $character_sets, array("source" => array("DEFAULT_COLLATION_NAME")) + $collations);
case "EVENTS": return array_merge(array(array("source" => array("EVENT_CATALOG", "EVENT_SCHEMA")) + $schemata), $routine_charsets);
case "FILES": return array($schemata, $tables);
case "KEY_COLUMN_USAGE": return array(array("source" => array("CONSTRAINT_CATALOG", "CONSTRAINT_SCHEMA")) + $schemata, $schemata, $tables, $columns, array("source" => array("TABLE_CATALOG", "REFERENCED_TABLE_SCHEMA")) + $schemata, array("source" => array("TABLE_CATALOG", "REFERENCED_TABLE_SCHEMA", "REFERENCED_TABLE_NAME")) + $tables, array("source" => array("TABLE_CATALOG", "REFERENCED_TABLE_SCHEMA", "REFERENCED_TABLE_NAME", "REFERENCED_COLUMN_NAME")) + $columns);
case "PARTITIONS": return array($schemata, $tables);
case "REFERENTIAL_CONSTRAINTS": return array(array("source" => array("CONSTRAINT_CATALOG", "CONSTRAINT_SCHEMA")) + $schemata, array("source" => array("UNIQUE_CONSTRAINT_CATALOG", "UNIQUE_CONSTRAINT_SCHEMA")) + $schemata, array("source" => array("CONSTRAINT_CATALOG", "CONSTRAINT_SCHEMA", "TABLE_NAME")) + $tables, array("source" => array("CONSTRAINT_CATALOG", "CONSTRAINT_SCHEMA", "REFERENCED_TABLE_NAME")) + $tables);
case "ROUTINES": return array_merge(array(array("source" => array("ROUTINE_CATALOG", "ROUTINE_SCHEMA")) + $schemata), $routine_charsets);
case "SCHEMA_PRIVILEGES": return array($schemata);
case "STATISTICS": return array($schemata, $tables, $columns, array("source" => array("TABLE_CATALOG", "INDEX_SCHEMA")) + $schemata);
case "TABLE_CONSTRAINTS": return array(array("source" => array("CONSTRAINT_CATALOG", "CONSTRAINT_SCHEMA")) + $schemata, array("source" => array("CONSTRAINT_CATALOG", "TABLE_SCHEMA")) + $schemata, array("source" => array("CONSTRAINT_CATALOG", "TABLE_SCHEMA", "TABLE_NAME")) + $tables);
case "TABLE_PRIVILEGES": return array($schemata, $tables);
case "TRIGGERS": return array_merge(array(array("source" => array("TRIGGER_CATALOG", "TRIGGER_SCHEMA")) + $schemata, array("source" => array("EVENT_OBJECT_CATALOG", "EVENT_OBJECT_SCHEMA")) + $schemata, array("source" => array("EVENT_OBJECT_CATALOG", "EVENT_OBJECT_SCHEMA", "EVENT_OBJECT_TABLE")) + $tables), $routine_charsets);
case "VIEWS": return array($schemata);
}
}
}
}

263
plugins/plugin.php Normal file
View file

@ -0,0 +1,263 @@
<?php
/** Adminer customization allowing usage of plugins
* @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)
*/
class AdminerPlugin extends Adminer {
var $plugins;
/**
* @param array
*/
function AdminerPlugin($plugins) {
$this->plugins = $plugins;
// it is possible to use ReflectionObject in PHP 5 to find out which plugins defines which methods at once
}
function _applyPlugin($function, $args) {
foreach ($this->plugins as $plugin) {
if (method_exists($plugin, $function)) {
foreach ($args as $key => $val) {
$args[$key] = &$args[$key]; // allows modification of parameters
}
$return = call_user_func_array(array($plugin, $function), $args);
if (isset($return)) {
return $return;
}
}
}
return call_user_func_array(array($this, "parent::$function"), $args);
}
function _appendPlugin($function, $args) {
$return = call_user_func_array(array($this, "parent::$function"), $args);
foreach ($this->plugins as $plugin) {
if (method_exists($plugin, $function)) {
$return += call_user_func_array(array($plugin, $function), $args);
}
}
return $return;
}
// appendPlugin
function dumpFormat() {
$args = func_get_args();
return $this->_appendPlugin(__FUNCTION__, $args);
}
function dumpOutput() {
$args = func_get_args();
return $this->_appendPlugin(__FUNCTION__, $args);
}
function editFunctions() {
$args = func_get_args();
return $this->_appendPlugin(__FUNCTION__, $args);
}
// applyPlugin
function name() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function credentials() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function permanentLogin() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function database() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function headers() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function loginForm() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function login() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function tableName() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function fieldName() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectLinks() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function foreignKeys() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function backwardKeys() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function backwardKeysPrint() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectQuery() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function rowDescription() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function rowDescriptions() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectVal() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function editVal() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectColumnsPrint() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectSearchPrint() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectOrderPrint() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectLimitPrint() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectLengthPrint() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectActionPrint() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectEmailPrint() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectColumnsProcess() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectSearchProcess() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectOrderProcess() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectLimitProcess() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectLengthProcess() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectEmailProcess() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function messageQuery() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function editInput() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function processInput() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function dumpTable() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function dumpData() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function dumpHeaders() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function homepage() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function navigation() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function tablesPrint() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
}

2
plugins/readme.txt Normal file
View file

@ -0,0 +1,2 @@
../adminer/plugin.php - demo usage
http://www.adminer.org/en/plugins/ - documentation

40
plugins/slugify.php Normal file
View file

@ -0,0 +1,40 @@
<?php
/** Prefill field containg "_slug" with slugified value of a previous field (JavaScript)
* @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)
*/
class AdminerSlugify {
var $from, $to;
/**
* @param string find these characters ...
* @param string ... and replace them by these
*/
function AdminerSlugify($from = 'áčďéěíňóřšťúůýž', $to = 'acdeeinorstuuyz') {
$this->from = $from;
$this->to = $to;
}
function editInput($table, $field, $attrs, $value) {
static $slugify;
if (!$_GET["select"] && !$_GET["where"]) {
if (!isset($slugify)) {
$slugify = array();
$prev = null;
foreach (fields($table) as $name => $field) {
if ($prev && ereg('(^|_)slug(_|$)', $name)) {
$slugify[$prev] = $name;
}
$prev = $name;
}
}
$slug = $slugify[$field["field"]];
if (isset($slug)) {
return "<input value='" . h($value) . "' maxlength='$field[length]' size='40'$attrs onchange=\"var find = '$this->from'; var repl = '$this->to'; this.form['fields[$slug]'].value = this.value.toLowerCase().replace(new RegExp('[' + find + ']', 'g'), function (str) { return repl[find.indexOf(str)]; }).replace(/[^a-z0-9_]+/g, '-').replace(/^-|-\$/g, '').substr(0, $field[length]);\">";
}
}
}
}

59
plugins/tinymce.php Normal file
View file

@ -0,0 +1,59 @@
<?php
/** Edit all fields containg "_html" by HTML editor TinyMCE and display the HTML in select
* @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)
*/
class AdminerTinymce {
var $path;
/**
* @param string
*/
function AdminerTinymce($path = "tiny_mce/tiny_mce.js") {
$this->path = $path;
}
function selectVal(&$val, $link, $field) {
if (ereg("_html", $field["field"]) && $val != '&nbsp;') {
$val = preg_replace('~<[^>]*$~', '', html_entity_decode($val, ENT_QUOTES, 'utf-8')); //! close all opened tags (text can be shortened)
}
}
function editInput($table, $field, $attrs, $value) {
static $tiny_mce = false;
if (ereg("text", $field["type"]) && ereg("_html", $field["field"])) {
if (!$tiny_mce) {
$tiny_mce = true;
$lang = "en";
if (function_exists('get_lang')) { // since Adminer 3.2.0
$lang = get_lang();
$lang = ($lang == "zh" ? "zh-cn" : ($lang == "zh-tw" ? "zh" : $lang));
if (!file_exists(dirname($this->path) . "/langs/$lang.js")) {
$lang = "en";
}
}
?>
<script type="text/javascript" src="<?php echo h($this->path); ?>"></script>
<script type="text/javascript">
tinyMCE.init({
mode: 'none',
theme: 'advanced',
plugins: 'contextmenu,paste,table',
entity_encoding: 'raw',
theme_advanced_buttons1: 'bold,italic,link,unlink,|,sub,sup,|,bullist,numlist,|,cleanup,code',
theme_advanced_buttons2: 'tablecontrols',
theme_advanced_buttons3: '',
theme_advanced_toolbar_location: 'top',
theme_advanced_toolbar_align: 'left',
language: '<?php echo $lang; ?>'
});
</script>
<?php
}
return "<textarea$attrs id='fields-$field[field]' rows='12' cols='50'>" . h($value) . "</textarea><script type='text/javascript'>tinyMCE.execCommand('mceAddControl', true, 'fields-$field[field]');</script>";
}
}
}

55
plugins/translation.php Normal file
View file

@ -0,0 +1,55 @@
<?php
/* Requires this table:
CREATE TABLE translation (
id int NOT NULL AUTO_INCREMENT, -- optional
language_id varchar(5) NOT NULL,
idf varchar(100) NOT NULL COLLATE utf8_bin,
translation text NOT NULL,
UNIQUE (language_id, idf),
PRIMARY KEY (id)
);
*/
/** Translate all table comments, field comments and enum values from the translation table (inserts new translations)
* @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)
*/
class AdminerTranslation {
function _translate($s) {
static $translations, $lang;
if (!isset($lang)) {
$lang = get_lang();
}
if ($s == "" || $lang == "en") {
return $s;
}
if (!isset($translations)) {
$translations = get_key_vals("SELECT idf, translation FROM translation WHERE language_id = " . q($lang));
}
$idf = preg_replace('~^(.{100}).*~su', '\\1', $s);
$return = &$translations[$idf];
if (!isset($return)) {
$return = $s;
$connection = connection();
$connection->query("INSERT INTO translation (language_id, idf, translation) VALUES (" . q($lang) . ", " . q($idf) . ", " . q($s) . ")");
}
return $return;
}
function tableName(&$tableStatus) {
$tableStatus["Comment"] = $this->_translate($tableStatus["Comment"]);
}
function fieldName(&$field, $order = 0) {
$field["comment"] = $this->_translate($field["comment"]);
}
function editVal(&$val, $field) {
if ($field["type"] == "enum") {
$val = $this->_translate($val);
}
}
}

View file

@ -9,6 +9,8 @@ Apache License 2.0 or GPL 2
adminer/index.php - Run development version of Adminer
editor/index.php - Run development version of Adminer Editor
editor/example.php - Example customization
plugins/readme.txt - Plugins for Adminer and Adminer Editor
adminer/plugin.php - Plugin demo
compile.php [driver] [lang] - Create a single file version
lang.php [lang] - Update translations
tests/selenium.html - Selenium test suite