diff --git a/browse_foreigners.php b/browse_foreigners.php index ac28f30423..d1b39822a1 100644 --- a/browse_foreigners.php +++ b/browse_foreigners.php @@ -8,7 +8,6 @@ use PMA\libraries\Response; require_once 'libraries/common.inc.php'; -require_once 'libraries/transformations.lib.php'; require_once 'libraries/browse_foreigners.lib.php'; /** diff --git a/db_datadict.php b/db_datadict.php index 544709acce..8c02c89431 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -5,8 +5,10 @@ * * @package PhpMyAdmin */ -use PMA\libraries\URL; + use PMA\libraries\Response; +use PMA\libraries\Transformations; +use PMA\libraries\URL; /** * Gets the variables sent or posted to this script, then displays headers @@ -37,8 +39,6 @@ $header->enablePrintView(); */ $cfgRelation = PMA_getRelationsParam(); -require_once 'libraries/transformations.lib.php'; - /** * Check parameters */ @@ -186,7 +186,7 @@ foreach ($tables as $table) { } echo '' , "\n"; if ($cfgRelation['mimework']) { - $mime_map = PMA_getMIME($db, $table, true); + $mime_map = Transformations::getMIME($db, $table, true); echo ' '; if (isset($mime_map[$column_name])) { diff --git a/export.php b/export.php index aebab9f0e3..c3dd8447ef 100644 --- a/export.php +++ b/export.php @@ -407,9 +407,6 @@ do { if ($do_relation || $do_comments || $do_mime) { $cfgRelation = PMA_getRelationsParam(); } - if ($do_mime) { - include_once 'libraries/transformations.lib.php'; - } // Include dates in export? $do_dates = isset($GLOBALS[$what . '_dates']); diff --git a/libraries/DisplayResults.php b/libraries/DisplayResults.php index 0969c77491..25243ed960 100644 --- a/libraries/DisplayResults.php +++ b/libraries/DisplayResults.php @@ -9,10 +9,9 @@ namespace PMA\libraries; use PhpMyAdmin\SqlParser\Utils\Query; use PMA\libraries\plugins\transformations\Text_Plain_Link; -use PMA\libraries\URL; use PMA\libraries\Sanitize; - -require_once './libraries/transformations.lib.php'; +use PMA\libraries\Transformations; +use PMA\libraries\URL; /** * Handle all the functionalities related to displaying results @@ -2915,7 +2914,7 @@ class DisplayResults ) { $mimeMap = array_merge( $mimeMap, - PMA_getMIME($this->__get('db'), $meta->orgtable, false, true) + Transformations::getMIME($this->__get('db'), $meta->orgtable, false, true) ); $added[$orgFullTableName] = true; } @@ -3060,14 +3059,14 @@ class DisplayResults if (file_exists($include_file)) { include_once $include_file; - $class_name = PMA_getTransformationClassName($include_file); + $class_name = Transformations::getClassName($include_file); // todo add $plugin_manager $plugin_manager = null; $transformation_plugin = new $class_name( $plugin_manager ); - $transform_options = PMA_Transformation_getOptions( + $transform_options = Transformations::getOptions( isset( $mime_map[$orgFullColName] ['transformation_options'] @@ -3100,7 +3099,7 @@ class DisplayResults $transformation_plugin = new $this->transformation_info [$dbLower][$tblLower][$nameLower][1](null); - $transform_options = PMA_Transformation_getOptions( + $transform_options = Transformations::getOptions( isset($mime_map[$orgFullColName]['transformation_options']) ? $mime_map[$orgFullColName]['transformation_options'] : '' diff --git a/libraries/Transformations.php b/libraries/Transformations.php new file mode 100644 index 0000000000..00cfa214f7 --- /dev/null +++ b/libraries/Transformations.php @@ -0,0 +1,460 @@ + + * getOptions("'option ,, quoted',abd,'2,3',"); + * // array { + * // 'option ,, quoted', + * // 'abc', + * // '2,3', + * // '', + * // } + * + * + * @param string $option_string comma separated options + * + * @return array options + */ + public static function getOptions($option_string) + { + $result = array(); + + if (strlen($option_string) === 0 + || ! $transform_options = preg_split('/,/', $option_string) + ) { + return $result; + } + + while (($option = array_shift($transform_options)) !== null) { + $trimmed = trim($option); + if (strlen($trimmed) > 1 + && $trimmed[0] == "'" + && $trimmed[strlen($trimmed) - 1] == "'" + ) { + // '...' + $option = mb_substr($trimmed, 1, -1); + } elseif (isset($trimmed[0]) && $trimmed[0] == "'") { + // '..., + $trimmed = ltrim($option); + while (($option = array_shift($transform_options)) !== null) { + // ..., + $trimmed .= ',' . $option; + $rtrimmed = rtrim($trimmed); + if ($rtrimmed[strlen($rtrimmed) - 1] == "'") { + // ,...' + break; + } + } + $option = mb_substr($rtrimmed, 1, -1); + } + $result[] = stripslashes($option); + } + + return $result; + } + + /** + * Gets all available MIME-types + * + * @access public + * @staticvar array mimetypes + * @return array array[mimetype], array[transformation] + */ + public static function getAvailableMIMEtypes() + { + static $stack = null; + + if (null !== $stack) { + return $stack; + } + + $stack = array(); + $sub_dirs = array( + 'input/' => 'input_', + 'output/' => '', + '' => '' + ); + + foreach ($sub_dirs as $sd => $prefix) { + $handle = opendir('libraries/plugins/transformations/' . $sd); + + if (! $handle) { + $stack[$prefix . 'transformation'] = array(); + $stack[$prefix . 'transformation_file'] = array(); + continue; + } + + $filestack = array(); + while ($file = readdir($handle)) { + // Ignore hidden files + if ($file[0] == '.') { + continue; + } + // Ignore old plugins (.class in filename) + if (strpos($file, '.class') !== false) { + continue; + } + $filestack[] = $file; + } + + closedir($handle); + sort($filestack); + + foreach ($filestack as $file) { + if (preg_match('|^[^.].*_.*_.*\.php$|', $file)) { + // File contains transformation functions. + $parts = explode('_', str_replace('.php', '', $file)); + $mimetype = $parts[0] . "/" . $parts[1]; + $stack['mimetype'][$mimetype] = $mimetype; + + $stack[$prefix . 'transformation'][] = $mimetype . ': ' . $parts[2]; + $stack[$prefix . 'transformation_file'][] = $sd . $file; + if ($sd === '') { + $stack['input_transformation'][] = $mimetype . ': ' . $parts[2]; + $stack['input_transformation_file'][] = $sd . $file; + } + + } elseif (preg_match('|^[^.].*\.php$|', $file)) { + // File is a plain mimetype, no functions. + $base = str_replace('.php', '', $file); + + if ($base != 'global') { + $mimetype = str_replace('_', '/', $base); + $stack['mimetype'][$mimetype] = $mimetype; + $stack['empty_mimetype'][$mimetype] = $mimetype; + } + } + } + } + return $stack; + } + + /** + * Returns the class name of the transformation + * + * @param string $filename transformation file name + * + * @return string the class name of transformation + */ + public static function getClassName($filename) + { + // get the transformation class name + $class_name = explode(".php", $filename); + $class_name = 'PMA\\' . str_replace('/', '\\', $class_name[0]); + + return $class_name; + } + + /** + * Returns the description of the transformation + * + * @param string $file transformation file + * + * @return String the description of the transformation + */ + public static function getDescription($file) + { + $include_file = 'libraries/plugins/transformations/' . $file; + /* @var $class_name PMA\libraries\plugins\TransformationsInterface */ + $class_name = self::getClassName($include_file); + // include and instantiate the class + include_once $include_file; + return $class_name::getInfo(); + } + + /** + * Returns the name of the transformation + * + * @param string $file transformation file + * + * @return String the name of the transformation + */ + public static function getName($file) + { + $include_file = 'libraries/plugins/transformations/' . $file; + /* @var $class_name PMA\libraries\plugins\TransformationsInterface */ + $class_name = self::getClassName($include_file); + // include and instantiate the class + include_once $include_file; + return $class_name::getName(); + } + + /** + * Gets the mimetypes for all columns of a table + * + * @param string $db the name of the db to check for + * @param string $table the name of the table to check for + * @param boolean $strict whether to include only results having a mimetype set + * @param boolean $fullName whether to use full column names as the key + * + * @access public + * + * @return array [field_name][field_key] = field_value + */ + public static function getMIME($db, $table, $strict = false, $fullName = false) + { + $cfgRelation = PMA_getRelationsParam(); + + if (! $cfgRelation['commwork']) { + return false; + } + + $com_qry = ''; + if ($fullName) { + $com_qry .= "SELECT CONCAT(" + . "`db_name`, '.', `table_name`, '.', `column_name`" + . ") AS column_name, "; + } else { + $com_qry = "SELECT `column_name`, "; + } + $com_qry .= '`mimetype`, + `transformation`, + `transformation_options`, + `input_transformation`, + `input_transformation_options` + FROM ' . Util::backquote($cfgRelation['db']) . '.' + . Util::backquote($cfgRelation['column_info']) . ' + WHERE `db_name` = \'' . $GLOBALS['dbi']->escapeString($db) . '\' + AND `table_name` = \'' . $GLOBALS['dbi']->escapeString($table) . '\' + AND ( `mimetype` != \'\'' . (!$strict ? ' + OR `transformation` != \'\' + OR `transformation_options` != \'\' + OR `input_transformation` != \'\' + OR `input_transformation_options` != \'\'' : '') . ')'; + $result = $GLOBALS['dbi']->fetchResult( + $com_qry, 'column_name', null, $GLOBALS['controllink'] + ); + + foreach ($result as $column => $values) { + // replacements in mimetype and transformation + $values = str_replace("jpeg", "JPEG", $values); + $values = str_replace("png", "PNG", $values); + + // convert mimetype to new format (f.e. Text_Plain, etc) + $delimiter_space = '- '; + $delimiter = "_"; + $values['mimetype'] = str_replace( + $delimiter_space, + $delimiter, + ucwords( + str_replace( + $delimiter, + $delimiter_space, + $values['mimetype'] + ) + ) + ); + + // For transformation of form + // output/image_jpeg__inline.inc.php + // extract dir part. + $dir = explode('/', $values['transformation']); + $subdir = ''; + if (count($dir) === 2) { + $subdir = $dir[0] . '/'; + $values['transformation'] = $dir[1]; + } + + $values['transformation'] = str_replace( + $delimiter_space, + $delimiter, + ucwords( + str_replace( + $delimiter, + $delimiter_space, + $values['transformation'] + ) + ) + ); + $values['transformation'] = $subdir . $values['transformation']; + $result[$column] = $values; + } + + return $result; + } // end of the 'getMIME()' function + + /** + * Set a single mimetype to a certain value. + * + * @param string $db the name of the db + * @param string $table the name of the table + * @param string $key the name of the column + * @param string $mimetype the mimetype of the column + * @param string $transformation the transformation of the column + * @param string $transformationOpts the transformation options of the column + * @param string $inputTransform the input transformation of the column + * @param string $inputTransformOpts the input transformation options of the column + * @param boolean $forcedelete force delete, will erase any existing + * comments for this column + * + * @access public + * + * @return boolean true, if comment-query was made. + */ + public static function setMIME($db, $table, $key, $mimetype, $transformation, + $transformationOpts, $inputTransform, $inputTransformOpts, $forcedelete = false + ) { + $cfgRelation = PMA_getRelationsParam(); + + if (! $cfgRelation['commwork']) { + return false; + } + + // lowercase mimetype & transformation + $mimetype = mb_strtolower($mimetype); + $transformation = mb_strtolower($transformation); + + $test_qry = ' + SELECT `mimetype`, + `comment` + FROM ' . Util::backquote($cfgRelation['db']) . '.' + . Util::backquote($cfgRelation['column_info']) . ' + WHERE `db_name` = \'' . $GLOBALS['dbi']->escapeString($db) . '\' + AND `table_name` = \'' . $GLOBALS['dbi']->escapeString($table) . '\' + AND `column_name` = \'' . $GLOBALS['dbi']->escapeString($key) . '\''; + + $test_rs = PMA_queryAsControlUser( + $test_qry, true, DatabaseInterface::QUERY_STORE + ); + + if ($test_rs && $GLOBALS['dbi']->numRows($test_rs) > 0) { + $row = @$GLOBALS['dbi']->fetchAssoc($test_rs); + $GLOBALS['dbi']->freeResult($test_rs); + + if (! $forcedelete + && (strlen($mimetype) > 0 + || strlen($transformation) > 0 + || strlen($transformationOpts) > 0 + || strlen($row['comment']) > 0) + ) { + $upd_query = 'UPDATE ' + . Util::backquote($cfgRelation['db']) . '.' + . Util::backquote($cfgRelation['column_info']) + . ' SET ' + . '`mimetype` = \'' + . $GLOBALS['dbi']->escapeString($mimetype) . '\', ' + . '`transformation` = \'' + . $GLOBALS['dbi']->escapeString($transformation) . '\', ' + . '`transformation_options` = \'' + . $GLOBALS['dbi']->escapeString($transformationOpts) . '\', ' + . '`input_transformation` = \'' + . $GLOBALS['dbi']->escapeString($inputTransform) . '\', ' + . '`input_transformation_options` = \'' + . $GLOBALS['dbi']->escapeString($inputTransformOpts) . '\''; + } else { + $upd_query = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['column_info']); + } + $upd_query .= ' + WHERE `db_name` = \'' . $GLOBALS['dbi']->escapeString($db) . '\' + AND `table_name` = \'' . $GLOBALS['dbi']->escapeString($table) + . '\' + AND `column_name` = \'' . $GLOBALS['dbi']->escapeString($key) + . '\''; + } elseif (strlen($mimetype) > 0 + || strlen($transformation) > 0 + || strlen($transformationOpts) > 0 + ) { + + $upd_query = 'INSERT INTO ' + . Util::backquote($cfgRelation['db']) + . '.' . Util::backquote($cfgRelation['column_info']) + . ' (db_name, table_name, column_name, mimetype, ' + . 'transformation, transformation_options, ' + . 'input_transformation, input_transformation_options) ' + . ' VALUES(' + . '\'' . $GLOBALS['dbi']->escapeString($db) . '\',' + . '\'' . $GLOBALS['dbi']->escapeString($table) . '\',' + . '\'' . $GLOBALS['dbi']->escapeString($key) . '\',' + . '\'' . $GLOBALS['dbi']->escapeString($mimetype) . '\',' + . '\'' . $GLOBALS['dbi']->escapeString($transformation) . '\',' + . '\'' . $GLOBALS['dbi']->escapeString($transformationOpts) . '\',' + . '\'' . $GLOBALS['dbi']->escapeString($inputTransform) . '\',' + . '\'' . $GLOBALS['dbi']->escapeString($inputTransformOpts) . '\')'; + } + + if (isset($upd_query)) { + return PMA_queryAsControlUser($upd_query); + } else { + return false; + } + } // end of 'setMIME()' function + + + /** + * GLOBAL Plugin functions + */ + + /** + * Delete related transformation details + * after deleting database. table or column + * + * @param string $db Database name + * @param string $table Table name + * @param string $column Column name + * + * @return boolean State of the query execution + */ + public static function clear($db, $table = '', $column = '') + { + $cfgRelation = PMA_getRelationsParam(); + + if (! isset($cfgRelation['column_info'])) { + return false; + } + + $delete_sql = 'DELETE FROM ' + . Util::backquote($cfgRelation['db']) . '.' + . Util::backquote($cfgRelation['column_info']) + . ' WHERE '; + + if (($column != '') && ($table != '')) { + + $delete_sql .= '`db_name` = \'' . $db . '\' AND ' + . '`table_name` = \'' . $table . '\' AND ' + . '`column_name` = \'' . $column . '\' '; + + } else if ($table != '') { + + $delete_sql .= '`db_name` = \'' . $db . '\' AND ' + . '`table_name` = \'' . $table . '\' '; + + } else { + $delete_sql .= '`db_name` = \'' . $db . '\' '; + } + + return $GLOBALS['dbi']->tryQuery($delete_sql); + + } +} diff --git a/libraries/controllers/table/TableStructureController.php b/libraries/controllers/table/TableStructureController.php index 20b5ea9eb4..b2ecc7171f 100644 --- a/libraries/controllers/table/TableStructureController.php +++ b/libraries/controllers/table/TableStructureController.php @@ -19,10 +19,10 @@ use PhpMyAdmin\SqlParser; use PhpMyAdmin\SqlParser\Statements\CreateStatement; use PhpMyAdmin\SqlParser\Utils\Table as SqlTable; use PMA\libraries\Table; +use PMA\libraries\Transformations; use PMA\libraries\controllers\TableController; use PMA\libraries\URL; -require_once 'libraries/transformations.lib.php'; require_once 'libraries/util.lib.php'; require_once 'libraries/config/messages.inc.php'; require_once 'libraries/config/user_preferences.forms.php'; @@ -1037,7 +1037,7 @@ class TableStructureController extends TableController if (isset($_REQUEST['field_name'][$fieldindex]) && strlen($_REQUEST['field_name'][$fieldindex]) > 0 ) { - PMA_setMIME( + Transformations::setMIME( $this->db, $this->table, $_REQUEST['field_name'][$fieldindex], $mimetype, @@ -1163,10 +1163,9 @@ class TableStructureController extends TableController $mime_map = array(); if ($GLOBALS['cfg']['ShowPropertyComments']) { - include_once 'libraries/transformations.lib.php'; $comments_map = PMA_getComments($this->db, $this->table); if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) { - $mime_map = PMA_getMIME($this->db, $this->table, true); + $mime_map = Transformations::getMIME($this->db, $this->table, true); } } include_once 'libraries/central_columns.lib.php'; diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index bdbafb796b..07594fbe0b 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -8,8 +8,9 @@ use PMA\libraries\Message; use PMA\libraries\plugins\TransformationsPlugin; use PMA\libraries\Response; -use PMA\libraries\URL; use PMA\libraries\Sanitize; +use PMA\libraries\Transformations; +use PMA\libraries\URL; /** * Retrieve form parameters for insert/edit form @@ -2182,14 +2183,13 @@ function PMA_transformEditedValues($db, $table, 'where_clause' => $_REQUEST['where_clause'], 'transform_key' => $column_name ); - $transform_options = PMA_Transformation_getOptions( + $transform_options = Transformations::getOptions( isset($transformation[$type . '_options']) ? $transformation[$type . '_options'] : '' ); - $transform_options['wrapper_link'] - = URL::getCommon($_url_params); - $class_name = PMA_getTransformationClassName($include_file); + $transform_options['wrapper_link'] = URL::getCommon($_url_params); + $class_name = Transformations::getClassName($include_file); /** @var TransformationsPlugin $transformation_plugin */ $transformation_plugin = new $class_name(); @@ -2887,9 +2887,9 @@ function PMA_getHtmlForInsertEditFormColumn($table_columns, $column_number, $include_file = 'libraries/plugins/transformations/' . $file; if (is_file($include_file)) { include_once $include_file; - $class_name = PMA_getTransformationClassName($include_file); + $class_name = Transformations::getClassName($include_file); $transformation_plugin = new $class_name(); - $transformation_options = PMA_Transformation_getOptions( + $transformation_options = Transformations::getOptions( $column_mime['input_transformation_options'] ); $_url_params = array( @@ -2977,7 +2977,7 @@ function PMA_getHtmlForInsertEditRow($url_params, $table_columns, //store the default value for CharEditing $default_char_editing = $GLOBALS['cfg']['CharEditing']; - $mime_map = PMA_getMIME($db, $table); + $mime_map = Transformations::getMIME($db, $table); $where_clause = ''; if (isset($where_clause_array[$row_id])) { $where_clause = $where_clause_array[$row_id]; diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index 7a1784c64a..ddbffd93ac 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -12,7 +12,6 @@ if (! defined('PHPMYADMIN')) { exit; } -require_once 'libraries/transformations.lib.php'; require_once 'libraries/sql.lib.php'; require_once 'libraries/mult_submits.lib.php'; diff --git a/libraries/mult_submits.lib.php b/libraries/mult_submits.lib.php index e7d61046ec..69d7321e68 100644 --- a/libraries/mult_submits.lib.php +++ b/libraries/mult_submits.lib.php @@ -8,6 +8,7 @@ * @package PhpMyAdmin */ use PMA\libraries\Table; +use PMA\libraries\Transformations; use PMA\libraries\URL; /** @@ -295,11 +296,11 @@ function PMA_buildOrExecuteQueryForMulti( $result = $GLOBALS['dbi']->query($a_query); if ($query_type == 'drop_db') { - PMA_clearTransformations($selected[$i]); + Transformations::clear($selected[$i]); } elseif ($query_type == 'drop_tbl') { - PMA_clearTransformations($db, $selected[$i]); + Transformations::clear($db, $selected[$i]); } else if ($query_type == 'drop_fld') { - PMA_clearTransformations($db, $table, $selected[$i]); + Transformations::clear($db, $table, $selected[$i]); } } // end if } // end for @@ -575,4 +576,3 @@ function PMA_getQueryFromSelected($what, $table, $selected, $views) return array($full_query, $reload, $full_query_views); } - diff --git a/libraries/normalization.lib.php b/libraries/normalization.lib.php index 39572ec9fd..beb7003b84 100644 --- a/libraries/normalization.lib.php +++ b/libraries/normalization.lib.php @@ -6,8 +6,9 @@ * @package PhpMyAdmin */ use PMA\libraries\Message; -use PMA\libraries\Util; +use PMA\libraries\Transformations; use PMA\libraries\URL; +use PMA\libraries\Util; /** * build the html for columns of $colTypeCategory category @@ -78,8 +79,8 @@ function PMA_getHtmlForCreateNewColumn( $available_mime = array(); $mime_map = array(); if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) { - $mime_map = PMA_getMIME($db, $table); - $available_mime = PMA_getAvailableMIMEtypes(); + $mime_map = Transformations::getMIME($db, $table); + $available_mime = Transformations::getAvailableMIMEtypes(); } $comments_map = PMA_getComments($db, $table); for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { diff --git a/libraries/plugins/export/ExportHtmlword.php b/libraries/plugins/export/ExportHtmlword.php index b0467f6904..09057a1fb5 100644 --- a/libraries/plugins/export/ExportHtmlword.php +++ b/libraries/plugins/export/ExportHtmlword.php @@ -8,15 +8,16 @@ */ namespace PMA\libraries\plugins\export; -use PMA\libraries\properties\options\items\BoolPropertyItem; -use PMA\libraries\properties\options\groups\OptionsPropertyMainGroup; -use PMA\libraries\properties\options\groups\OptionsPropertyRootGroup; +use PMA\libraries\DatabaseInterface; use PMA\libraries\plugins\ExportPlugin; use PMA\libraries\properties\plugins\ExportPluginProperties; -use PMA\libraries\DatabaseInterface; -use PMA\libraries\Util; +use PMA\libraries\properties\options\groups\OptionsPropertyMainGroup; +use PMA\libraries\properties\options\groups\OptionsPropertyRootGroup; +use PMA\libraries\properties\options\items\BoolPropertyItem; use PMA\libraries\properties\options\items\RadioPropertyItem; use PMA\libraries\properties\options\items\TextPropertyItem; +use PMA\libraries\Transformations; +use PMA\libraries\Util; /** * Handles the export for the HTML-Word format @@ -409,7 +410,7 @@ class ExportHtmlword extends ExportPlugin $schema_insert .= '' . htmlspecialchars('MIME') . ''; - $mime_map = PMA_getMIME($db, $table, true); + $mime_map = Transformations::getMIME($db, $table, true); } $schema_insert .= ''; diff --git a/libraries/plugins/export/ExportLatex.php b/libraries/plugins/export/ExportLatex.php index 651ef5babc..678c234245 100644 --- a/libraries/plugins/export/ExportLatex.php +++ b/libraries/plugins/export/ExportLatex.php @@ -8,15 +8,16 @@ */ namespace PMA\libraries\plugins\export; -use PMA\libraries\properties\options\items\BoolPropertyItem; +use PMA\libraries\DatabaseInterface; +use PMA\libraries\plugins\ExportPlugin; use PMA\libraries\properties\plugins\ExportPluginProperties; use PMA\libraries\properties\options\groups\OptionsPropertyMainGroup; use PMA\libraries\properties\options\groups\OptionsPropertyRootGroup; -use PMA\libraries\plugins\ExportPlugin; -use PMA\libraries\DatabaseInterface; -use PMA\libraries\Util; +use PMA\libraries\properties\options\items\BoolPropertyItem; use PMA\libraries\properties\options\items\RadioPropertyItem; use PMA\libraries\properties\options\items\TextPropertyItem; +use PMA\libraries\Transformations; +use PMA\libraries\Util; /** * Handles the export for the Latex format @@ -533,7 +534,7 @@ class ExportLatex extends ExportPlugin } if ($do_mime && $cfgRelation['mimework']) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}'; - $mime_map = PMA_getMIME($db, $table, true); + $mime_map = Transformations::getMIME($db, $table, true); } // Table caption for first page and label diff --git a/libraries/plugins/export/ExportOdt.php b/libraries/plugins/export/ExportOdt.php index 86693c3c44..9852219673 100644 --- a/libraries/plugins/export/ExportOdt.php +++ b/libraries/plugins/export/ExportOdt.php @@ -8,16 +8,17 @@ */ namespace PMA\libraries\plugins\export; -use PMA\libraries\properties\options\items\BoolPropertyItem; +use PMA\libraries\DatabaseInterface; +use PMA\libraries\plugins\ExportPlugin; use PMA\libraries\properties\plugins\ExportPluginProperties; use PMA\libraries\properties\options\groups\OptionsPropertyMainGroup; use PMA\libraries\properties\options\groups\OptionsPropertyRootGroup; -use PMA\libraries\DatabaseInterface; -use PMA\libraries\plugins\ExportPlugin; -use PMA\libraries\Util; +use PMA\libraries\properties\options\items\BoolPropertyItem; use PMA\libraries\properties\options\items\RadioPropertyItem; use PMA\libraries\properties\options\items\TextPropertyItem; use PMA\libraries\OpenDocument; +use PMA\libraries\Transformations; +use PMA\libraries\Util; $GLOBALS['odt_buffer'] = ''; @@ -503,7 +504,7 @@ class ExportOdt extends ExportPlugin $GLOBALS['odt_buffer'] .= '' . '' . __('MIME type') . '' . ''; - $mime_map = PMA_getMIME($db, $table, true); + $mime_map = Transformations::getMIME($db, $table, true); } $GLOBALS['odt_buffer'] .= ''; diff --git a/libraries/plugins/export/ExportPdf.php b/libraries/plugins/export/ExportPdf.php index 4f6f907dec..be90da19e4 100644 --- a/libraries/plugins/export/ExportPdf.php +++ b/libraries/plugins/export/ExportPdf.php @@ -24,8 +24,6 @@ if (! class_exists('TCPDF')) { return; } -require_once 'libraries/transformations.lib.php'; - /** * Handles the export for the PDF class * diff --git a/libraries/plugins/export/ExportSql.php b/libraries/plugins/export/ExportSql.php index b24206ecd2..2f86f95109 100644 --- a/libraries/plugins/export/ExportSql.php +++ b/libraries/plugins/export/ExportSql.php @@ -8,25 +8,26 @@ */ namespace PMA\libraries\plugins\export; -use PMA\libraries\properties\options\items\BoolPropertyItem; -use PMA\libraries\properties\plugins\ExportPluginProperties; -use PMA\libraries\properties\options\items\MessageOnlyPropertyItem; -use PMA\libraries\properties\options\items\NumberPropertyItem; -use PMA\libraries\properties\options\groups\OptionsPropertyMainGroup; -use PMA\libraries\properties\options\groups\OptionsPropertyRootGroup; -use PMA\libraries\properties\options\groups\OptionsPropertySubgroup; -use PMA\libraries\Charsets; -use PMA\libraries\DatabaseInterface; -use PMA\libraries\plugins\ExportPlugin; -use PMA\libraries\Util; -use PMA\libraries\properties\options\items\RadioPropertyItem; -use PMA\libraries\properties\options\items\SelectPropertyItem; use PhpMyAdmin\SqlParser\Components\CreateDefinition; use PhpMyAdmin\SqlParser\Context; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Statements\SelectStatement; use PhpMyAdmin\SqlParser\Token; +use PMA\libraries\Charsets; +use PMA\libraries\DatabaseInterface; +use PMA\libraries\plugins\ExportPlugin; +use PMA\libraries\properties\plugins\ExportPluginProperties; +use PMA\libraries\properties\options\groups\OptionsPropertyMainGroup; +use PMA\libraries\properties\options\groups\OptionsPropertyRootGroup; +use PMA\libraries\properties\options\groups\OptionsPropertySubgroup; +use PMA\libraries\properties\options\items\BoolPropertyItem; +use PMA\libraries\properties\options\items\MessageOnlyPropertyItem; +use PMA\libraries\properties\options\items\NumberPropertyItem; +use PMA\libraries\properties\options\items\RadioPropertyItem; +use PMA\libraries\properties\options\items\SelectPropertyItem; use PMA\libraries\properties\options\items\TextPropertyItem; +use PMA\libraries\Transformations; +use PMA\libraries\Util; /** * Handles the export for the SQL class @@ -1843,7 +1844,7 @@ class ExportSql extends ExportPlugin ); if ($do_mime && $cfgRelation['mimework']) { - if (!($mime_map = PMA_getMIME($db, $table, true))) { + if (!($mime_map = Transformations::getMIME($db, $table, true))) { unset($mime_map); } } diff --git a/libraries/plugins/export/ExportTexytext.php b/libraries/plugins/export/ExportTexytext.php index 93f96bdc2d..f8e0bbf09a 100644 --- a/libraries/plugins/export/ExportTexytext.php +++ b/libraries/plugins/export/ExportTexytext.php @@ -8,15 +8,16 @@ */ namespace PMA\libraries\plugins\export; -use PMA\libraries\properties\options\items\BoolPropertyItem; +use PMA\libraries\DatabaseInterface; +use PMA\libraries\plugins\ExportPlugin; use PMA\libraries\properties\plugins\ExportPluginProperties; use PMA\libraries\properties\options\groups\OptionsPropertyMainGroup; use PMA\libraries\properties\options\groups\OptionsPropertyRootGroup; -use PMA\libraries\DatabaseInterface; -use PMA\libraries\plugins\ExportPlugin; -use PMA\libraries\Util; +use PMA\libraries\properties\options\items\BoolPropertyItem; use PMA\libraries\properties\options\items\RadioPropertyItem; use PMA\libraries\properties\options\items\TextPropertyItem; +use PMA\libraries\Transformations; +use PMA\libraries\Util; /** * Handles the export for the Texy! text class @@ -385,7 +386,7 @@ class ExportTexytext extends ExportPlugin } if ($do_mime && $cfgRelation['mimework']) { $text_output .= '|' . htmlspecialchars('MIME'); - $mime_map = PMA_getMIME($db, $table, true); + $mime_map = Transformations::getMIME($db, $table, true); } $text_output .= "\n|------\n"; diff --git a/libraries/plugins/export/helpers/Pdf.php b/libraries/plugins/export/helpers/Pdf.php index aef8339ed5..62410a54d9 100644 --- a/libraries/plugins/export/helpers/Pdf.php +++ b/libraries/plugins/export/helpers/Pdf.php @@ -10,6 +10,7 @@ namespace PMA\libraries\plugins\export\helpers; use PMA\libraries\DatabaseInterface; use PMA\libraries\PDF as PdfLib; +use PMA\libraries\Transformations; use PMA\libraries\Util; use TCPDF_STATIC; @@ -518,7 +519,7 @@ class Pdf extends PdfLib $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { - $mime_map = PMA_getMIME($db, $table, true); + $mime_map = Transformations::getMIME($db, $table, true); } $columns = $GLOBALS['dbi']->getColumns($db, $table); diff --git a/libraries/plugins/schema/pdf/Pdf.php b/libraries/plugins/schema/pdf/Pdf.php index 7971090048..de8c6af912 100644 --- a/libraries/plugins/schema/pdf/Pdf.php +++ b/libraries/plugins/schema/pdf/Pdf.php @@ -25,8 +25,6 @@ if (getcwd() == dirname(__FILE__)) { die('Attack stopped'); } -require_once 'libraries/transformations.lib.php'; - /** * Extends the "TCPDF" class and helps * in developing the structure of PDF Schema Export diff --git a/libraries/plugins/schema/pdf/PdfRelationSchema.php b/libraries/plugins/schema/pdf/PdfRelationSchema.php index a8e4c97764..780249741c 100644 --- a/libraries/plugins/schema/pdf/PdfRelationSchema.php +++ b/libraries/plugins/schema/pdf/PdfRelationSchema.php @@ -7,9 +7,10 @@ */ namespace PMA\libraries\plugins\schema\pdf; -use PMA\libraries\plugins\schema\ExportRelationSchema; -use PMA\libraries\Util; use PMA\libraries\PDF as PDF_lib; +use PMA\libraries\plugins\schema\ExportRelationSchema; +use PMA\libraries\Transformations; +use PMA\libraries\Util; /** * Skip the plugin if TCPDF is not available. @@ -26,8 +27,6 @@ if (getcwd() == dirname(__FILE__)) { die('Attack stopped'); } -require_once 'libraries/transformations.lib.php'; - /** * Pdf Relation Schema Class * @@ -550,7 +549,7 @@ class PdfRelationSchema extends ExportRelationSchema $cfgRelation = PMA_getRelationsParam(); $comments = PMA_getComments($this->db, $table); if ($cfgRelation['mimework']) { - $mime_map = PMA_getMIME($this->db, $table, true); + $mime_map = Transformations::getMIME($this->db, $table, true); } /** diff --git a/libraries/plugins/transformations/abs/ImageLinkTransformationsPlugin.php b/libraries/plugins/transformations/abs/ImageLinkTransformationsPlugin.php index 429b5cfdb8..a60369c941 100644 --- a/libraries/plugins/transformations/abs/ImageLinkTransformationsPlugin.php +++ b/libraries/plugins/transformations/abs/ImageLinkTransformationsPlugin.php @@ -14,9 +14,6 @@ if (!defined('PHPMYADMIN')) { exit; } -/* For PMA_Transformation_globalHtmlReplace */ -require_once 'libraries/transformations.lib.php'; - /** * Provides common methods for all of the link transformations plugins. * diff --git a/libraries/plugins/transformations/abs/InlineTransformationsPlugin.php b/libraries/plugins/transformations/abs/InlineTransformationsPlugin.php index ac9134a3de..4263501bb8 100644 --- a/libraries/plugins/transformations/abs/InlineTransformationsPlugin.php +++ b/libraries/plugins/transformations/abs/InlineTransformationsPlugin.php @@ -14,9 +14,6 @@ if (!defined('PHPMYADMIN')) { exit; } -/* For PMA_Transformation_globalHtmlReplace */ -require_once 'libraries/transformations.lib.php'; - /** * Provides common methods for all of the inline transformations plugins. * diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 4d0a6aa055..928f74ec05 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -5,12 +5,14 @@ * * @package PhpMyAdmin */ + +use PMA\libraries\Bookmark; use PMA\libraries\DisplayResults; use PMA\libraries\Message; -use PMA\libraries\Table; use PMA\libraries\Response; +use PMA\libraries\Table; +use PMA\libraries\Transformations; use PMA\libraries\URL; -use PMA\libraries\Bookmark; /** * Parses and analyzes the given SQL query. @@ -1297,14 +1299,13 @@ function PMA_executeTheQuery($analyzed_sql_results, $full_sql_query, $is_gotofil */ function PMA_deleteTransformationInfo($db, $table, $analyzed_sql_results) { - include_once 'libraries/transformations.lib.php'; $statement = $analyzed_sql_results['statement']; if ($statement instanceof PhpMyAdmin\SqlParser\Statements\AlterStatement) { if (!empty($statement->altered[0]) && $statement->altered[0]->options->has('DROP') ) { if (!empty($statement->altered[0]->field->column)) { - PMA_clearTransformations( + Transformations::clear( $db, $table, $statement->altered[0]->field->column @@ -1312,7 +1313,7 @@ function PMA_deleteTransformationInfo($db, $table, $analyzed_sql_results) } } } elseif ($statement instanceof PhpMyAdmin\SqlParser\Statements\DropStatement) { - PMA_clearTransformations($db, $table); + Transformations::clear($db, $table); } } diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index 4286a1a889..0966133aa9 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -8,6 +8,7 @@ */ use PMA\libraries\Response; use PMA\libraries\Table; +use PMA\libraries\Transformations; use PMA\Util; if (!defined('PHPMYADMIN')) { @@ -83,7 +84,6 @@ if (isset($selected) && is_array($selected)) { $is_backup = ($action != 'tbl_create.php' && $action != 'tbl_addfield.php'); -require_once './libraries/transformations.lib.php'; $cfgRelation = PMA_getRelationsParam(); $comments_map = PMA_getComments($db, $table); @@ -97,8 +97,8 @@ if (isset($fields_meta)) { $available_mime = array(); if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) { - $mime_map = PMA_getMIME($db, $table); - $available_mime = PMA_getAvailableMIMEtypes(); + $mime_map = Transformations::getMIME($db, $table); + $available_mime = Transformations::getAvailableMIMEtypes(); } // workaround for field_fulltext, because its submitted indices contain diff --git a/libraries/transformations.lib.php b/libraries/transformations.lib.php deleted file mode 100644 index e100013078..0000000000 --- a/libraries/transformations.lib.php +++ /dev/null @@ -1,452 +0,0 @@ - - * PMA_Transformation_getOptions("'option ,, quoted',abd,'2,3',"); - * // array { - * // 'option ,, quoted', - * // 'abc', - * // '2,3', - * // '', - * // } - * - * - * @param string $option_string comma separated options - * - * @return array options - */ -function PMA_Transformation_getOptions($option_string) -{ - $result = array(); - - if (strlen($option_string) === 0 - || ! $transform_options = preg_split('/,/', $option_string) - ) { - return $result; - } - - while (($option = array_shift($transform_options)) !== null) { - $trimmed = trim($option); - if (strlen($trimmed) > 1 - && $trimmed[0] == "'" - && $trimmed[strlen($trimmed) - 1] == "'" - ) { - // '...' - $option = mb_substr($trimmed, 1, -1); - } elseif (isset($trimmed[0]) && $trimmed[0] == "'") { - // '..., - $trimmed = ltrim($option); - while (($option = array_shift($transform_options)) !== null) { - // ..., - $trimmed .= ',' . $option; - $rtrimmed = rtrim($trimmed); - if ($rtrimmed[strlen($rtrimmed) - 1] == "'") { - // ,...' - break; - } - } - $option = mb_substr($rtrimmed, 1, -1); - } - $result[] = stripslashes($option); - } - - return $result; -} - -/** - * Gets all available MIME-types - * - * @access public - * @staticvar array mimetypes - * @return array array[mimetype], array[transformation] - */ -function PMA_getAvailableMIMEtypes() -{ - static $stack = null; - - if (null !== $stack) { - return $stack; - } - - $stack = array(); - $sub_dirs = array( - 'input/' => 'input_', - 'output/' => '', - '' => '' - ); - - foreach ($sub_dirs as $sd => $prefix) { - $handle = opendir('libraries/plugins/transformations/' . $sd); - - if (! $handle) { - $stack[$prefix . 'transformation'] = array(); - $stack[$prefix . 'transformation_file'] = array(); - continue; - } - - $filestack = array(); - while ($file = readdir($handle)) { - // Ignore hidden files - if ($file[0] == '.') { - continue; - } - // Ignore old plugins (.class in filename) - if (strpos($file, '.class') !== false) { - continue; - } - $filestack[] = $file; - } - - closedir($handle); - sort($filestack); - - foreach ($filestack as $file) { - if (preg_match('|^[^.].*_.*_.*\.php$|', $file)) { - // File contains transformation functions. - $parts = explode('_', str_replace('.php', '', $file)); - $mimetype = $parts[0] . "/" . $parts[1]; - $stack['mimetype'][$mimetype] = $mimetype; - - $stack[$prefix . 'transformation'][] = $mimetype . ': ' . $parts[2]; - $stack[$prefix . 'transformation_file'][] = $sd . $file; - if ($sd === '') { - $stack['input_transformation'][] = $mimetype . ': ' . $parts[2]; - $stack['input_transformation_file'][] = $sd . $file; - } - - } elseif (preg_match('|^[^.].*\.php$|', $file)) { - // File is a plain mimetype, no functions. - $base = str_replace('.php', '', $file); - - if ($base != 'global') { - $mimetype = str_replace('_', '/', $base); - $stack['mimetype'][$mimetype] = $mimetype; - $stack['empty_mimetype'][$mimetype] = $mimetype; - } - } - } - } - return $stack; -} - -/** - * Returns the class name of the transformation - * - * @param string $filename transformation file name - * - * @return string the class name of transformation - */ -function PMA_getTransformationClassName($filename) -{ - // get the transformation class name - $class_name = explode(".php", $filename); - $class_name = 'PMA\\' . str_replace('/', '\\', $class_name[0]); - - return $class_name; -} - -/** - * Returns the description of the transformation - * - * @param string $file transformation file - * - * @return String the description of the transformation - */ -function PMA_getTransformationDescription($file) -{ - $include_file = 'libraries/plugins/transformations/' . $file; - /* @var $class_name PMA\libraries\plugins\TransformationsInterface */ - $class_name = PMA_getTransformationClassName($include_file); - // include and instantiate the class - include_once $include_file; - return $class_name::getInfo(); -} - -/** - * Returns the name of the transformation - * - * @param string $file transformation file - * - * @return String the name of the transformation - */ -function PMA_getTransformationName($file) -{ - $include_file = 'libraries/plugins/transformations/' . $file; - /* @var $class_name PMA\libraries\plugins\TransformationsInterface */ - $class_name = PMA_getTransformationClassName($include_file); - // include and instantiate the class - include_once $include_file; - return $class_name::getName(); -} - -/** - * Gets the mimetypes for all columns of a table - * - * @param string $db the name of the db to check for - * @param string $table the name of the table to check for - * @param boolean $strict whether to include only results having a mimetype set - * @param boolean $fullName whether to use full column names as the key - * - * @access public - * - * @return array [field_name][field_key] = field_value - */ -function PMA_getMIME($db, $table, $strict = false, $fullName = false) -{ - $cfgRelation = PMA_getRelationsParam(); - - if (! $cfgRelation['commwork']) { - return false; - } - - $com_qry = ''; - if ($fullName) { - $com_qry .= "SELECT CONCAT(" - . "`db_name`, '.', `table_name`, '.', `column_name`" - . ") AS column_name, "; - } else { - $com_qry = "SELECT `column_name`, "; - } - $com_qry .= '`mimetype`, - `transformation`, - `transformation_options`, - `input_transformation`, - `input_transformation_options` - FROM ' . PMA\libraries\Util::backquote($cfgRelation['db']) . '.' - . PMA\libraries\Util::backquote($cfgRelation['column_info']) . ' - WHERE `db_name` = \'' . $GLOBALS['dbi']->escapeString($db) . '\' - AND `table_name` = \'' . $GLOBALS['dbi']->escapeString($table) . '\' - AND ( `mimetype` != \'\'' . (!$strict ? ' - OR `transformation` != \'\' - OR `transformation_options` != \'\' - OR `input_transformation` != \'\' - OR `input_transformation_options` != \'\'' : '') . ')'; - $result = $GLOBALS['dbi']->fetchResult( - $com_qry, 'column_name', null, $GLOBALS['controllink'] - ); - - foreach ($result as $column => $values) { - // replacements in mimetype and transformation - $values = str_replace("jpeg", "JPEG", $values); - $values = str_replace("png", "PNG", $values); - - // convert mimetype to new format (f.e. Text_Plain, etc) - $delimiter_space = '- '; - $delimiter = "_"; - $values['mimetype'] = str_replace( - $delimiter_space, - $delimiter, - ucwords( - str_replace( - $delimiter, - $delimiter_space, - $values['mimetype'] - ) - ) - ); - - // For transformation of form - // output/image_jpeg__inline.inc.php - // extract dir part. - $dir = explode('/', $values['transformation']); - $subdir = ''; - if (count($dir) === 2) { - $subdir = $dir[0] . '/'; - $values['transformation'] = $dir[1]; - } - - $values['transformation'] = str_replace( - $delimiter_space, - $delimiter, - ucwords( - str_replace( - $delimiter, - $delimiter_space, - $values['transformation'] - ) - ) - ); - $values['transformation'] = $subdir . $values['transformation']; - $result[$column] = $values; - } - - return $result; -} // end of the 'PMA_getMIME()' function - -/** - * Set a single mimetype to a certain value. - * - * @param string $db the name of the db - * @param string $table the name of the table - * @param string $key the name of the column - * @param string $mimetype the mimetype of the column - * @param string $transformation the transformation of the column - * @param string $transformationOpts the transformation options of the column - * @param string $inputTransform the input transformation of the column - * @param string $inputTransformOpts the input transformation options of the column - * @param boolean $forcedelete force delete, will erase any existing - * comments for this column - * - * @access public - * - * @return boolean true, if comment-query was made. - */ -function PMA_setMIME($db, $table, $key, $mimetype, $transformation, - $transformationOpts, $inputTransform, $inputTransformOpts, $forcedelete = false -) { - $cfgRelation = PMA_getRelationsParam(); - - if (! $cfgRelation['commwork']) { - return false; - } - - // lowercase mimetype & transformation - $mimetype = mb_strtolower($mimetype); - $transformation = mb_strtolower($transformation); - - $test_qry = ' - SELECT `mimetype`, - `comment` - FROM ' . PMA\libraries\Util::backquote($cfgRelation['db']) . '.' - . PMA\libraries\Util::backquote($cfgRelation['column_info']) . ' - WHERE `db_name` = \'' . $GLOBALS['dbi']->escapeString($db) . '\' - AND `table_name` = \'' . $GLOBALS['dbi']->escapeString($table) . '\' - AND `column_name` = \'' . $GLOBALS['dbi']->escapeString($key) . '\''; - - $test_rs = PMA_queryAsControlUser( - $test_qry, true, PMA\libraries\DatabaseInterface::QUERY_STORE - ); - - if ($test_rs && $GLOBALS['dbi']->numRows($test_rs) > 0) { - $row = @$GLOBALS['dbi']->fetchAssoc($test_rs); - $GLOBALS['dbi']->freeResult($test_rs); - - if (! $forcedelete - && (strlen($mimetype) > 0 - || strlen($transformation) > 0 - || strlen($transformationOpts) > 0 - || strlen($row['comment']) > 0) - ) { - $upd_query = 'UPDATE ' - . PMA\libraries\Util::backquote($cfgRelation['db']) . '.' - . PMA\libraries\Util::backquote($cfgRelation['column_info']) - . ' SET ' - . '`mimetype` = \'' - . $GLOBALS['dbi']->escapeString($mimetype) . '\', ' - . '`transformation` = \'' - . $GLOBALS['dbi']->escapeString($transformation) . '\', ' - . '`transformation_options` = \'' - . $GLOBALS['dbi']->escapeString($transformationOpts) . '\', ' - . '`input_transformation` = \'' - . $GLOBALS['dbi']->escapeString($inputTransform) . '\', ' - . '`input_transformation_options` = \'' - . $GLOBALS['dbi']->escapeString($inputTransformOpts) . '\''; - } else { - $upd_query = 'DELETE FROM ' - . PMA\libraries\Util::backquote($cfgRelation['db']) - . '.' . PMA\libraries\Util::backquote($cfgRelation['column_info']); - } - $upd_query .= ' - WHERE `db_name` = \'' . $GLOBALS['dbi']->escapeString($db) . '\' - AND `table_name` = \'' . $GLOBALS['dbi']->escapeString($table) - . '\' - AND `column_name` = \'' . $GLOBALS['dbi']->escapeString($key) - . '\''; - } elseif (strlen($mimetype) > 0 - || strlen($transformation) > 0 - || strlen($transformationOpts) > 0 - ) { - - $upd_query = 'INSERT INTO ' - . PMA\libraries\Util::backquote($cfgRelation['db']) - . '.' . PMA\libraries\Util::backquote($cfgRelation['column_info']) - . ' (db_name, table_name, column_name, mimetype, ' - . 'transformation, transformation_options, ' - . 'input_transformation, input_transformation_options) ' - . ' VALUES(' - . '\'' . $GLOBALS['dbi']->escapeString($db) . '\',' - . '\'' . $GLOBALS['dbi']->escapeString($table) . '\',' - . '\'' . $GLOBALS['dbi']->escapeString($key) . '\',' - . '\'' . $GLOBALS['dbi']->escapeString($mimetype) . '\',' - . '\'' . $GLOBALS['dbi']->escapeString($transformation) . '\',' - . '\'' . $GLOBALS['dbi']->escapeString($transformationOpts) . '\',' - . '\'' . $GLOBALS['dbi']->escapeString($inputTransform) . '\',' - . '\'' . $GLOBALS['dbi']->escapeString($inputTransformOpts) . '\')'; - } - - if (isset($upd_query)) { - return PMA_queryAsControlUser($upd_query); - } else { - return false; - } -} // end of 'PMA_setMIME()' function - - -/** - * GLOBAL Plugin functions - */ - -/** - * Delete related transformation details - * after deleting database. table or column - * - * @param string $db Database name - * @param string $table Table name - * @param string $column Column name - * - * @return boolean State of the query execution - */ -function PMA_clearTransformations($db, $table = '', $column = '') -{ - $cfgRelation = PMA_getRelationsParam(); - - if (! isset($cfgRelation['column_info'])) { - return false; - } - - $delete_sql = 'DELETE FROM ' - . PMA\libraries\Util::backquote($cfgRelation['db']) . '.' - . PMA\libraries\Util::backquote($cfgRelation['column_info']) - . ' WHERE '; - - if (($column != '') && ($table != '')) { - - $delete_sql .= '`db_name` = \'' . $db . '\' AND ' - . '`table_name` = \'' . $table . '\' AND ' - . '`column_name` = \'' . $column . '\' '; - - } else if ($table != '') { - - $delete_sql .= '`db_name` = \'' . $db . '\' AND ' - . '`table_name` = \'' . $table . '\' '; - - } else { - $delete_sql .= '`db_name` = \'' . $db . '\' '; - } - - return $GLOBALS['dbi']->tryQuery($delete_sql); - -} - diff --git a/normalization.php b/normalization.php index b1087bfdc2..5251dce3fc 100644 --- a/normalization.php +++ b/normalization.php @@ -12,7 +12,6 @@ use PMA\libraries\Response; * */ require_once 'libraries/common.inc.php'; -require_once 'libraries/transformations.lib.php'; require_once 'libraries/normalization.lib.php'; if (isset($_REQUEST['getColumns'])) { diff --git a/tbl_addfield.php b/tbl_addfield.php index e7e9452058..ac89d87dc9 100644 --- a/tbl_addfield.php +++ b/tbl_addfield.php @@ -5,8 +5,10 @@ * * @package PhpMyAdmin */ -use PMA\libraries\URL; + use PMA\libraries\Response; +use PMA\libraries\Transformations; +use PMA\libraries\URL; /** * Get some core libraries @@ -65,9 +67,6 @@ if (isset($_REQUEST['do_save_data'])) { list($result, $sql_query) = PMA_tryColumnCreationQuery($db, $table, $err_url); if ($result === true) { - // If comments were sent, enable relation stuff - include_once 'libraries/transformations.lib.php'; - // Update comment table for mime types [MIME] if (isset($_REQUEST['field_mimetype']) && is_array($_REQUEST['field_mimetype']) @@ -77,7 +76,7 @@ if (isset($_REQUEST['do_save_data'])) { if (isset($_REQUEST['field_name'][$fieldindex]) && strlen($_REQUEST['field_name'][$fieldindex]) > 0 ) { - PMA_setMIME( + Transformations::setMIME( $db, $table, $_REQUEST['field_name'][$fieldindex], $mimetype, diff --git a/tbl_change.php b/tbl_change.php index 478b12f1bb..437ccb97ef 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -28,7 +28,6 @@ require_once 'libraries/db_table_exists.inc.php'; * functions implementation for this script */ require_once 'libraries/insert_edit.lib.php'; -require_once 'libraries/transformations.lib.php'; /** * Determine whether Insert or Edit and set global variables diff --git a/tbl_create.php b/tbl_create.php index 882d873677..c275275521 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -5,8 +5,10 @@ * * @package PhpMyAdmin */ -use PMA\libraries\URL; + use PMA\libraries\Response; +use PMA\libraries\Transformations; +use PMA\libraries\URL; /** * Get some core libraries @@ -66,8 +68,6 @@ if (isset($_REQUEST['do_save_data'])) { $result = $GLOBALS['dbi']->tryQuery($sql_query); if ($result) { - // If comments were sent, enable relation stuff - include_once 'libraries/transformations.lib.php'; // Update comment table for mime types [MIME] if (isset($_REQUEST['field_mimetype']) && is_array($_REQUEST['field_mimetype']) @@ -77,7 +77,7 @@ if (isset($_REQUEST['do_save_data'])) { if (isset($_REQUEST['field_name'][$fieldindex]) && strlen($_REQUEST['field_name'][$fieldindex]) > 0 ) { - PMA_setMIME( + Transformations::setMIME( $db, $table, $_REQUEST['field_name'][$fieldindex], $mimetype, $_REQUEST['field_transformation'][$fieldindex], diff --git a/tbl_replace.php b/tbl_replace.php index 8dd8ed1bb0..25903ebfaa 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -14,6 +14,7 @@ use PMA\libraries\plugins\IOTransformationsPlugin; use PMA\libraries\Response; use PMA\libraries\Table; +use PMA\libraries\Transformations; /** * Gets some core libraries @@ -24,7 +25,6 @@ require_once 'libraries/common.inc.php'; * functions implementation for this script */ require_once 'libraries/insert_edit.lib.php'; -require_once 'libraries/transformations.lib.php'; // Check parameters PMA\libraries\Util::checkParameters(array('db', 'table', 'goto')); @@ -127,7 +127,7 @@ $gis_from_wkb_functions = array( ); //if some posted fields need to be transformed. -$mime_map = PMA_getMIME($GLOBALS['db'], $GLOBALS['table']); +$mime_map = Transformations::getMIME($GLOBALS['db'], $GLOBALS['table']); if ($mime_map === false) { $mime_map = array(); } @@ -219,10 +219,10 @@ foreach ($loop_array as $rownumber => $where_clause) { . $mime_map[$column_name]['input_transformation']; if (is_file($filename)) { include_once $filename; - $classname = PMA_getTransformationClassName($filename); + $classname = Transformations::getClassName($filename); /** @var IOTransformationsPlugin $transformation_plugin */ $transformation_plugin = new $classname(); - $transformation_options = PMA_Transformation_getOptions( + $transformation_options = Transformations::getOptions( $mime_map[$column_name]['input_transformation_options'] ); $current_value = $transformation_plugin->applyTransformation( diff --git a/templates/columns_definitions/transformation.phtml b/templates/columns_definitions/transformation.phtml index 99bab34053..4750a8d35d 100644 --- a/templates/columns_definitions/transformation.phtml +++ b/templates/columns_definitions/transformation.phtml @@ -1,3 +1,4 @@ +