From 02dbd14fc7a212b591ae050998c6eebf60298b00 Mon Sep 17 00:00:00 2001 From: Alex Marin Date: Wed, 20 Jun 2012 16:28:10 +0300 Subject: [PATCH] oop: integrate transformations - no errors, but not working. --- libraries/DisplayResults.class.php | 530 ++++++++++-------- libraries/insert_edit.lib.php | 2 +- .../plugins/TransformationsPlugin.class.php | 13 + ...Application_Octetstream_Download.class.php | 16 - .../Application_Octetstream_Hex.class.php | 14 - .../Image_JPEG_Inline.class.php | 13 - .../transformations/Image_JPEG_Link.class.php | 16 +- .../Image_PNG_Inline.class.php | 13 - .../Text_Plain_Append.class.php | 13 - .../Text_Plain_Dateformat.class.php | 20 - .../Text_Plain_External.class.php | 23 - .../Text_Plain_Formatted.class.php | 14 - .../Text_Plain_Imagelink.class.php | 18 +- .../transformations/Text_Plain_Link.class.php | 18 +- .../Text_Plain_Longtoipv4.class.php | 13 - .../transformations/Text_Plain_Sql.class.php | 12 - .../Text_Plain_Substring.class.php | 16 - .../AppendTransformationsPlugin.class.php | 24 +- .../DateFormatTransformationsPlugin.class.php | 114 +++- .../DownloadTransformationsPlugin.class.php | 49 +- .../ExternalTransformationsPlugin.class.php | 121 +++- .../FormattedTransformationsPlugin.class.php | 19 +- .../HexTransformationsPlugin.class.php | 30 +- .../ImageLinkTransformationsPlugin.class.php | 34 +- .../InlineTransformationsPlugin.class.php | 40 +- .../LongToIPv4TransformationsPlugin.class.php | 22 +- .../SQLTransformationsPlugin.class.php | 20 +- .../SubstringTransformationsPlugin.class.php | 55 +- ...xtImageLinkTransformationsPlugin.class.php | 94 ++++ ...> TextLinkTransformationsPlugin.class.php} | 33 +- tbl_replace.php | 51 +- 31 files changed, 960 insertions(+), 510 deletions(-) create mode 100644 libraries/plugins/transformations/abstract/TextImageLinkTransformationsPlugin.class.php rename libraries/plugins/transformations/abstract/{LinkTransformationsPlugin.class.php => TextLinkTransformationsPlugin.class.php} (57%) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index 0061047fb2..003d9e79a8 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -13,33 +13,33 @@ if (! defined('PHPMYADMIN')) { * Handle all the functionalities related to displaying results * of sql queries, stored procedure, browsing sql processes or * displaying binary log. - * + * * @package PhpMyAdmin */ class PMA_DisplayResults { - + const NO_EDIT_OR_DELETE = 'nn'; const UPDATE_ROW = 'ur'; const DELETE_ROW = 'dr'; const KILL_PROCESS = 'kp'; - + const POSITION_LEFT = 'left'; const POSITION_RIGHT = 'right'; const POSITION_BOTH = 'both'; const POSITION_NONE = 'none'; - + const DISP_DIR_HORIZONTAL = 'horizontal'; const DISP_DIR_HORIZONTAL_FLIPPED = 'horizontalflipped'; const DISP_DIR_VERTICAL = 'vertical'; - + const DISPLAY_FULL_TEXT = 'F'; const DISPLAY_PARTIAL_TEXT = 'P'; - + const HEADER_FLIP_TYPE_AUTO = 'auto'; const HEADER_FLIP_TYPE_CSS = 'css'; const HEADER_FLIP_TYPE_FAKE = 'fake'; - + const DATE_FIELD = 'date'; const DATETIME_FIELD = 'datetime'; const TIMESTAMP_FIELD = 'timestamp'; @@ -47,34 +47,34 @@ class PMA_DisplayResults const GEOMETRY_FIELD = 'geometry'; const BLOB_FIELD = 'BLOB'; const BINARY_FIELD = 'BINARY'; - + const RELATIONAL_KEY = 'K'; const RELATIONAL_DISPLAY_COLUMN = 'D'; - + const GEOMETRY_DISP_GEOM = 'GEOM'; const GEOMETRY_DISP_WKT = 'WKT'; const GEOMETRY_DISP_WKB = 'WKB'; - + const SMART_SORT_ORDER = 'SMART'; const ASCENDING_SORT_DIR = 'ASC'; const DESCENDING_SORT_DIR = 'DESC'; - + const TABLE_TYPE_INNO_DB = 'InnoDB'; const ALL_ROWS = 'all'; const QUERY_TYPE_SELECT = 'SELECT'; - - + + private $_db, $_table, $_goto, $_sql_query, $_cfgRelation; /** * Constructor for PMA_DisplayResults class - * + * * @param string $db the database name * @param string $table the table name * @param string $goto the URL to go back in case of errors * @param string $sql_query the SQL query - * + * * @access public */ public function __construct($db, $table, $goto, $sql_query) @@ -275,9 +275,9 @@ class PMA_DisplayResults * "SELECT * FROM ..." * * @return boolean - * + * * @access private - * + * * @see _getTableHeaders(), _getColumnParams() */ private function _isSelect() @@ -534,7 +534,7 @@ class PMA_DisplayResults * @param integer $pos_prev the offset for the "previous" page * * @return string html content - * + * * @access private * * @see _getTableNavigation() @@ -556,9 +556,9 @@ class PMA_DisplayResults * Prepare Show All button for table navigation * * @param string $html_sql_query the sql encoded by html special characters - * + * * @return string html content - * + * * @access private * * @see _getTableNavigation() @@ -590,7 +590,7 @@ class PMA_DisplayResults * @param integer $num_rows the total number of rows returned by the * * @return string $buttons_html html content - * + * * @access private * * @see _getTableNavigation() @@ -652,7 +652,7 @@ class PMA_DisplayResults * @param string $id_for_direction_dropdown the id for the direction dropdown * * @return string $additional_fields_html html content - * + * * @access private * * @see _getTableNavigation() @@ -1164,7 +1164,7 @@ class PMA_DisplayResults * @param string $unsorted_sql_query the unsorted sql query * * @return string $drop_down_html html content - * + * * @access private * * @see _getTableHeaders() @@ -1249,7 +1249,7 @@ class PMA_DisplayResults * Prepare data for column restoring and show/hide * * @return string $data_html html content - * + * * @access private * * @see _getTableHeaders() @@ -1292,7 +1292,7 @@ class PMA_DisplayResults * Prepare option fields block * * @return string $options_html html content - * + * * @access private * * @see _getTableHeaders() @@ -1413,7 +1413,7 @@ class PMA_DisplayResults * Get full/partial text button or link * * @return string html content - * + * * @access private * * @see _getTableHeaders() @@ -1455,7 +1455,7 @@ class PMA_DisplayResults * @param string $del_lnk the delete link of current row * * @return string $form_html html content - * + * * @access private * * @see _getTableHeaders() @@ -1497,7 +1497,7 @@ class PMA_DisplayResults * @param array $fields_meta set of field properties * * @return string $comment html content - * + * * @access private * * @see _getTableHeaders() @@ -1528,7 +1528,7 @@ class PMA_DisplayResults * @param string $name_to_use_in_sort the sorting column name * * @return boolean $is_in_sort the column sorted or not - * + * * @access private * * @see _getTableHeaders() @@ -1585,7 +1585,7 @@ class PMA_DisplayResults * @param integer $column_index the index of the column * * @return array 2 element array - $sort_order, $order_img - * + * * @access private * * @see _getTableHeaders() @@ -1651,7 +1651,7 @@ class PMA_DisplayResults * @param string $order_url the url for sort * * @return string the sort order link - * + * * @access private * * @see _getTableHeaders() @@ -1717,7 +1717,7 @@ class PMA_DisplayResults * @param string $comments the comment for the column * * @return string $draggable_html html content - * + * * @access private * * @see _getTableHeaders() @@ -1774,7 +1774,7 @@ class PMA_DisplayResults * @param string $comments the comment for the column * * @return string $draggable_html html content - * + * * @access private * * @see _getTableHeaders() @@ -1838,9 +1838,9 @@ class PMA_DisplayResults * @param string $value value to display * * @return string the td - * + * * @access private - * + * * @see _getDataCellForBlobColumns(), _getDataCellForGeometryColumns(), * _getDataCellForNonNumericAndNonBlobColumns() */ @@ -1860,9 +1860,9 @@ class PMA_DisplayResults * @param string $align cell allignment * * @return string the td - * + * * @access private - * + * * @see _getDataCellForNumericColumns(), _getDataCellForBlobColumns(), * _getDataCellForGeometryColumns(), * _getDataCellForNonNumericAndNonBlobColumns() @@ -1887,9 +1887,9 @@ class PMA_DisplayResults * @param string $align cell allignment * * @return string the td - * + * * @access private - * + * * @see _getDataCellForNumericColumns(), _getDataCellForBlobColumns(), * _getDataCellForGeometryColumns(), * _getDataCellForNonNumericAndNonBlobColumns() @@ -1907,23 +1907,25 @@ class PMA_DisplayResults /** * Adds the relavant classes. * - * @param string $class class of table cell - * @param bool $condition_field whether to add CSS class condition - * @param object $meta the meta-information about this field - * @param string $nowrap avoid wrapping - * @param bool $is_field_truncated is field truncated (display ...) - * @param string $transform_function transformation function - * @param string $default_function default transformation function + * @param string $class class of table cell + * @param bool $condition_field whether to add CSS class condition + * @param object $meta the meta-information about the field + * @param string $nowrap avoid wrapping + * @param bool $is_field_truncated is field truncated (display ...) + * @param string $transformation_plugin transformation plugin. + * Can also be the default function: + * PMA_mimeDefaultFunction + * @param string $default_function default transformation function * * @return string the list of classes - * + * * @access private - * + * * @see _buildNullDisplay(), _getRowData() */ private function _addClass( $class, $condition_field, $meta, $nowrap, $is_field_truncated = false, - $transform_function = '', $default_function = '' + $transformation_plugin = '', $default_function = '' ) { // Define classes to be added to this data field based on the type of data @@ -1949,7 +1951,7 @@ class PMA_DisplayResults return $class . ($condition_field ? ' condition' : '') . $nowrap . ' ' . ($is_field_truncated ? ' truncated' : '') - . ($transform_function != $default_function ? ' transformed' : '') + . ($transformation_plugin != $default_function ? ' transformed' : '') . $enum_class . $set_class . $bit_class . $mime_type_class; } // end of the '_addClass()' function @@ -2154,51 +2156,50 @@ class PMA_DisplayResults // Wrap MIME-transformations. [MIME] $default_function = 'PMA_mimeDefaultFunction'; // default_function - $transform_function = $default_function; + $transformation_plugin = $default_function; $transform_options = array(); if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] ) { - if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation']) ) { + $file = $GLOBALS['mime_map'][$meta->name]['transformation']; + $file = PMA_securePath( + str_replace( + ".inc.php", + ".class.php", + str_replace( + "__", + "_", + $file + ) + ) + ); + $file_parts = explode("_", $file); + $file = strtoupper($file_parts[0]) . "_" + . strtoupper($file_parts[1]) . "_" + . strtoupper($file_parts[2]); - $include_file - = './libraries/transformations/' . PMA_securePath( - $GLOBALS['mime_map'][$meta->name]['transformation'] - ); - + $include_file = 'libraries/transformations/plugins/' . $file; if (file_exists($include_file)) { - - $transformfunction_name = 'PMA_transformation_' - . str_replace( - '.inc.php', '', - $GLOBALS['mime_map'][$meta->name]['transformation'] - ); - include_once $include_file; - - if (function_exists($transformfunction_name)) { - - $transform_function = $transformfunction_name; - - $transform_options = PMA_transformation_getOptions( - isset($GLOBALS['mime_map'][$meta->name] - ['transformation_options'] - ) - ? $GLOBALS['mime_map'][$meta->name] + $class_name = str_replace('.class.php', '', $file); + $transformation_plugin = new $class_name; + $transform_options = PMA_transformation_getOptions( + isset($GLOBALS['mime_map'][$meta->name] ['transformation_options'] - : '' - ); - - $meta->mimetype = str_replace( - '_', '/', - $GLOBALS['mime_map'][$meta->name]['mimetype'] - ); - } + ) + ? $GLOBALS['mime_map'][$meta->name] + ['transformation_options'] + : '' + ); + $meta->mimetype = str_replace( + '_', '/', + $GLOBALS['mime_map'][$meta->name]['mimetype'] + ); } // end if file_exists } // end if transformation is set } // end if mime/transformation works. @@ -2228,8 +2229,9 @@ class PMA_DisplayResults $GLOBALS['vertical_display']['data'][$row_no][$i] = $this->_getDataCellForNumericColumns( $row[$i], $class, $condition_field, $meta, $map, - $is_field_truncated, $analyzed_sql, $transform_function, - $default_function, $transform_options + $is_field_truncated, $analyzed_sql, + $transformation_plugin, $default_function, + $transform_options ); } elseif (stristr($meta->type, self::BLOB_FIELD)) { @@ -2242,7 +2244,7 @@ class PMA_DisplayResults $GLOBALS['vertical_display']['data'][$row_no][$i] = $this->_getDataCellForBlobColumns( $row[$i], $class, $meta, $_url_params, $field_flags, - $transform_function, $default_function, + $transformation_plugin, $default_function, $transform_options, $condition_field, $is_field_truncated ); @@ -2256,8 +2258,9 @@ class PMA_DisplayResults $GLOBALS['vertical_display']['data'][$row_no][$i] = $this->_getDataCellForGeometryColumns( $row[$i], $class, $meta, $map, $_url_params, - $condition_field, $transform_function, $default_function, - $transform_options, $is_field_truncated, $analyzed_sql + $condition_field, $transformation_plugin, + $default_function, $transform_options, + $is_field_truncated, $analyzed_sql ); } else { @@ -2266,9 +2269,9 @@ class PMA_DisplayResults $GLOBALS['vertical_display']['data'][$row_no][$i] = $this->_getDataCellForNonNumericAndNonBlobColumns( $row[$i], $class, $meta, $map, $_url_params, - $condition_field, $transform_function, $default_function, - $transform_options, $is_field_truncated, $analyzed_sql, - $dt_result, $i + $condition_field, $transformation_plugin, + $default_function, $transform_options, + $is_field_truncated, $analyzed_sql, $dt_result, $i ); } @@ -2393,9 +2396,9 @@ class PMA_DisplayResults * Get url sql query without conditions to shorten URLs * * @param array $analyzed_sql analyzed query - * + * * @return string $url_sql analyzed sql query - * + * * @access private * * @see _getTableBody() @@ -2432,7 +2435,7 @@ class PMA_DisplayResults * Get column order and column visibility * * @return array 2 element array - $col_order, $col_visib - * + * * @access private * * @see _getTableBody() @@ -2461,7 +2464,7 @@ class PMA_DisplayResults * @param boolean $directionCondition the directional condition * * @return string $vertical_disp_html html content - * + * * @access private * * @see _getTableBody() @@ -2516,7 +2519,7 @@ class PMA_DisplayResults * * @return array 5 element array - $edit_url, $copy_url, * $edit_str, $copy_str, $edit_anchor_class - * + * * @access private * * @see _getTableBody() @@ -2568,7 +2571,7 @@ class PMA_DisplayResults * * @return array 4 element array - $del_query, * $del_url, $del_str, $js_conf - * + * * @access private * * @see _getTableBody() @@ -2662,7 +2665,7 @@ class PMA_DisplayResults * @param string $js_conf text for the JS confirmation * * @return string html content - * + * * @access private * * @see _getTableBody() @@ -2698,7 +2701,7 @@ class PMA_DisplayResults * @param integer $row_no the row index * * @return string $class the resetted class - * + * * @access private * * @see _getTableBody() @@ -2736,7 +2739,7 @@ class PMA_DisplayResults * @param string $type the type of the column field * * @return string $field_type_class the class for the column - * + * * @access private * * @see _getTableBody() @@ -2759,28 +2762,31 @@ class PMA_DisplayResults /** * Prepare data cell for numeric type fields * - * @param string $column the relavent column in data row - * @param string $class the html class for column - * @param boolean $condition_field the column should highlighted or not - * @param object $meta the meta-information about this field - * @param array $map the list of relations - * @param boolean $is_field_truncated the condition for blob data replacements - * @param array $analyzed_sql the analyzed query - * @param string $transform_function the name of transformation function - * @param string $default_function the default transformation function - * @param string $transform_options the transformation parameters + * @param string $column the relavent column in data row + * @param string $class the html class for column + * @param boolean $condition_field the column should highlighted + * or not + * @param object $meta the meta-information about this + * field + * @param array $map the list of relations + * @param boolean $is_field_truncated the condition for blob data + * replacements + * @param array $analyzed_sql the analyzed query + * @param string $transformation_plugin the name of transformation plugin + * @param string $default_function the default transformation function + * @param string $transform_options the transformation parameters + * + * @return string $cell the prepared cell, html content * - * @return string $cell the prepared cell, html content - * * @access private * * @see _getTableBody() */ private function _getDataCellForNumericColumns( $column, $class, $condition_field, $meta, $map, $is_field_truncated, - $analyzed_sql, $transform_function, $default_function, $transform_options + $analyzed_sql, $transformation_plugin, $default_function, + $transform_options ) { - if (! isset($column) || is_null($column)) { $cell = $this->_buildNullDisplay( @@ -2795,7 +2801,7 @@ class PMA_DisplayResults $cell = $this->_getRowData( 'right '.$class, $condition_field, $analyzed_sql, $meta, $map, $column, - $transform_function, $default_function, $nowrap, + $transformation_plugin, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated ); @@ -2814,25 +2820,29 @@ class PMA_DisplayResults /** * Get data cell for blob type fields * - * @param string $column the relavent column in data row - * @param string $class the html class for column - * @param object $meta the meta-information about this field - * @param array $_url_params the parameters for generate url - * @param string $field_flags field flags for column(blob, primary etc) - * @param string $transform_function the name of transformation function - * @param string $default_function the default transformation function - * @param string $transform_options the transformation parameters - * @param boolean $condition_field the column should highlighted or not - * @param boolean $is_field_truncated the condition for blob data replacements + * @param string $column the relavent column in data row + * @param string $class the html class for column + * @param object $meta the meta-information about this + * field + * @param array $_url_params the parameters for generate url + * @param string $field_flags field flags for column(blob, + * primary etc) + * @param string $transformation_plugin the name of transformation function + * @param string $default_function the default transformation function + * @param string $transform_options the transformation parameters + * @param boolean $condition_field the column should highlighted + * or not + * @param boolean $is_field_truncated the condition for blob data + * replacements + * + * @return string $cell the prepared cell, html content * - * @return string $cell the prepared cell, html content - * * @access private * * @see _getTableBody() */ private function _getDataCellForBlobColumns( - $column, $class, $meta, $_url_params, $field_flags, $transform_function, + $column, $class, $meta, $_url_params, $field_flags, $transformation_plugin, $default_function, $transform_options, $condition_field, $is_field_truncated ) { @@ -2849,7 +2859,7 @@ class PMA_DisplayResults $blobtext = $this->_handleNonPrintableContents( self::BLOB_FIELD, (isset($column) ? $column : ''), - $transform_function, $transform_options, + $transformation_plugin, $transform_options, $default_function, $meta, $_url_params ); @@ -2879,8 +2889,12 @@ class PMA_DisplayResults // displays all space characters, 4 space // characters for tabulations and / - $column = ($default_function != $transform_function) - ? $transform_function($column, $transform_options, $meta) + $column = ($default_function != $transformation_plugin) + ? $transformation_plugin->applyTransformation( + $column, + $transform_options, + $meta + ) : $default_function($column, array(), $meta); if ($is_field_truncated) { @@ -2902,27 +2916,27 @@ class PMA_DisplayResults /** * Get data cell for geometry type fields * - * @param string $column the relavent column in data row - * @param string $class the html class for column - * @param object $meta the meta-information about this field - * @param array $map the list of relations - * @param array $_url_params the parameters for generate url - * @param boolean $condition_field the column should highlighted or not - * @param string $transform_function the name of transformation function - * @param string $default_function the default transformation function - * @param string $transform_options the transformation parameters - * @param boolean $is_field_truncated the condition for blob data replacements - * @param array $analyzed_sql the analyzed query + * @param string $column the relavent column in data row + * @param string $class the html class for column + * @param object $meta the meta-information about this field + * @param array $map the list of relations + * @param array $_url_params the parameters for generate url + * @param boolean $condition_field the column should highlighted or not + * @param string $transformation_plugin the name of transformation function + * @param string $default_function the default transformation function + * @param string $transform_options the transformation parameters + * @param boolean $is_field_truncated the condition for blob data replacements + * @param array $analyzed_sql the analyzed query + * + * @return string $cell the prepared data cell, html content * - * @return string $cell the prepared data cell, html content - * * @access private * * @see _getTableBody() */ private function _getDataCellForGeometryColumns( $column, $class, $meta, $map, $_url_params, $condition_field, - $transform_function, $default_function, $transform_options, + $transformation_plugin, $default_function, $transform_options, $is_field_truncated, $analyzed_sql ) { @@ -2937,7 +2951,7 @@ class PMA_DisplayResults $geometry_text = $this->_handleNonPrintableContents( strtoupper(self::GEOMETRY_FIELD), - (isset($column) ? $column : ''), $transform_function, + (isset($column) ? $column : ''), $transformation_plugin, $transform_options, $default_function, $meta ); @@ -2965,7 +2979,7 @@ class PMA_DisplayResults $cell = $this->_getRowData( $class, $condition_field, $analyzed_sql, $meta, $map, - $wktval, $transform_function, $default_function, '', + $wktval, $transformation_plugin, $default_function, '', $where_comparison, $transform_options, $is_field_truncated ); @@ -2999,14 +3013,14 @@ class PMA_DisplayResults $cell = $this->_getRowData( $class, $condition_field, $analyzed_sql, $meta, $map, $wkbval, - $transform_function, $default_function, '', + $transformation_plugin, $default_function, '', $where_comparison, $transform_options, $is_field_truncated ); } else { $wkbval = $this->_handleNonPrintableContents( - self::BINARY_FIELD, $column, $transform_function, + self::BINARY_FIELD, $column, $transformation_plugin, $transform_options, $default_function, $meta, $_url_params ); @@ -3028,30 +3042,32 @@ class PMA_DisplayResults /** * Get data cell for non numeric and non blob type fields * - * @param string $column the relavent column in data row - * @param string $class the html class for column - * @param object $meta the meta-information about this field - * @param array $map the list of relations - * @param array $_url_params the parameters for generate url - * @param boolean $condition_field the column should highlighted or not - * @param string $transform_function the name of transformation function - * @param string $default_function the default transformation function - * @param string $transform_options the transformation parameters - * @param boolean $is_field_truncated the condition for blob data replacements - * @param array $analyzed_sql the analyzed query - * @param integer &$dt_result the link id associated to the query - * which results have to be displayed - * @param integer $col_index the column index + * @param string $column the relavent column in data row + * @param string $class the html class for column + * @param object $meta the meta-information about the field + * @param array $map the list of relations + * @param array $_url_params the parameters for generate url + * @param boolean $condition_field the column should highlighted + * or not + * @param string $transformation_plugin the name of transformation function + * @param string $default_function the default transformation function + * @param string $transform_options the transformation parameters + * @param boolean $is_field_truncated the condition for blob data + * replacements + * @param array $analyzed_sql the analyzed query + * @param integer &$dt_result the link id associated to the query + * which results have to be displayed + * @param integer $col_index the column index * * @return string $cell the prepared data cell, html content - * + * * @access private * * @see _getTableBody() */ private function _getDataCellForNonNumericAndNonBlobColumns( $column, $class, $meta, $map, $_url_params, $condition_field, - $transform_function, $default_function, $transform_options, + $transformation_plugin, $default_function, $transform_options, $is_field_truncated, $analyzed_sql, &$dt_result, $col_index ) { @@ -3065,7 +3081,7 @@ class PMA_DisplayResults // (unless it's a link-type transformation) if (PMA_strlen($column) > $GLOBALS['cfg']['LimitChars'] && ($_SESSION['tmp_user_values']['display_text'] == self::DISPLAY_PARTIAL_TEXT) - && !strpos($transform_function, 'link') === true + && ! strpos($transformation_plugin, 'Link') === true ) { $column = PMA_substr($column, 0, $GLOBALS['cfg']['LimitChars']) . '...'; @@ -3108,7 +3124,7 @@ class PMA_DisplayResults // we show the BINARY message and field's size // (or maybe use a transformation) $column = $this->_handleNonPrintableContents( - self::BINARY_FIELD, $column, $transform_function, + self::BINARY_FIELD, $column, $transformation_plugin, $transform_options, $default_function, $meta, $_url_params ); @@ -3125,11 +3141,11 @@ class PMA_DisplayResults } else { // transform functions may enable no-wrapping: - $function_nowrap = $transform_function . '_nowrap'; + $function_nowrap = 'applyTransformationNoWrap'; - $bool_nowrap = (($default_function != $transform_function) - && function_exists($function_nowrap)) - ? $function_nowrap($transform_options) + $bool_nowrap = (($default_function != $transformation_plugin) + && function_exists($transformation_plugin->$function_nowrap)) + ? $transformation_plugin->$function_nowrap($transform_options) : false; // do not wrap if date field type @@ -3142,7 +3158,7 @@ class PMA_DisplayResults $cell = $this->_getRowData( $class, $condition_field, $analyzed_sql, $meta, $map, $column, - $transform_function, $default_function, $nowrap, + $transformation_plugin, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated ); @@ -3322,7 +3338,7 @@ class PMA_DisplayResults * @param string $operation edit/copy/delete * * @return string $links_html html content - * + * * @access private * * @see _getVerticalTable() @@ -3364,7 +3380,7 @@ class PMA_DisplayResults * @param string $dir _left / _right * * @return $checkBoxes_html html content - * + * * @access private * * @see _getVerticalTable() @@ -3408,9 +3424,9 @@ class PMA_DisplayResults * @todo move/split into SQL class!? * @todo currently this is called twice unnecessary * @todo ignore LIMIT and ORDER in query!? - * + * * @return void - * + * * @access public * * @see sql.php file @@ -3885,7 +3901,7 @@ class PMA_DisplayResults * Get offsets for next page and previous page * * @return array array with two elements - $pos_next, $pos_prev - * + * * @access private * * @see getTable() @@ -3921,7 +3937,7 @@ class PMA_DisplayResults * * @return array 3 element array: $sort_expression, * $sort_expression_nodirection, $sort_direction - * + * * @access private * * @see getTable() @@ -3969,10 +3985,10 @@ class PMA_DisplayResults * @param integer $num_rows the total number of rows returned * by the SQL query * @param string $sort_expression_nodirection sort expression without direction - * + * * @return string html content * null if not found sorted column - * + * * @access private * * @see getTable() @@ -4012,7 +4028,7 @@ class PMA_DisplayResults // initializing default arguments $default_function = 'PMA_mimeDefaultFunction'; - $transform_function = $default_function; + $transformation_plugin = $default_function; $transform_options = array(); // check for non printable sorted row data @@ -4023,8 +4039,9 @@ class PMA_DisplayResults ) { $column_for_first_row = $this->_handleNonPrintableContents( - $meta->type, $row[$sorted_column_index], $transform_function, - $transform_options, $default_function, $meta, null + $meta->type, $row[$sorted_column_index], + $transformation_plugin, $transform_options, + $default_function, $meta, null ); } else { @@ -4046,8 +4063,9 @@ class PMA_DisplayResults ) { $column_for_last_row = $this->_handleNonPrintableContents( - $meta->type, $row[$sorted_column_index], $transform_function, - $transform_options, $default_function, $meta, null + $meta->type, $row[$sorted_column_index], + $transformation_plugin, $transform_options, + $default_function, $meta, null ); } else { @@ -4089,7 +4107,7 @@ class PMA_DisplayResults * @param string $after_count the string renders after row count * * @return PMA_Message $message an object of PMA_Message - * + * * @access private * * @see getTable() @@ -4201,7 +4219,7 @@ class PMA_DisplayResults * @param string $del_link the display element - 'del_link' * * @return string $links_html html content - * + * * @access private * * @see getTable() @@ -4490,25 +4508,27 @@ class PMA_DisplayResults * Verifies what to do with non-printable contents (binary or BLOB) * in Browse mode. * - * @param string $category BLOB|BINARY|GEOMETRY - * @param string $content the binary content - * @param string $transform_function transformation function - * @param string $transform_options transformation parameters - * @param string $default_function default transformation function - * @param object $meta the meta-information about this field - * @param array $url_params parameters that should go to the - * download link + * @param string $category BLOB|BINARY|GEOMETRY + * @param string $content the binary content + * @param string $transformation_plugin transformation plugin. + * Can also be the default function: + * PMA_mimeDefaultFunction + * @param string $transform_options transformation parameters + * @param string $default_function default transformation function + * @param object $meta the meta-information about the field + * @param array $url_params parameters that should go to the + * download link * * @return mixed string or float - * + * * @access private - * + * * @see _getDataCellForBlobColumns(), _getDataCellForGeometryColumns(), * _getDataCellForNonNumericAndNonBlobColumns(), * _getSortedColumnMessage() */ private function _handleNonPrintableContents( - $category, $content, $transform_function, $transform_options, + $category, $content, $transformation_plugin, $transform_options, $default_function, $meta, $url_params = array() ) { @@ -4529,14 +4549,18 @@ class PMA_DisplayResults $result .= ']'; - if (strpos($transform_function, 'octetstream')) { + if (strpos($transformation_plugin, 'Octetstream')) { $result = $content; } if ($size > 0) { - if ($default_function != $transform_function) { - $result = $transform_function($result, $transform_options, $meta); + if ($default_function != $transformation_plugin) { + $result = $transformation_plugin->applyTransformation( + $result, + $transform_options, + $meta + ); } else { $result = $default_function($result, array(), $meta); @@ -4565,39 +4589,41 @@ class PMA_DisplayResults * Prepares the displayable content of a data cell in Browse mode, * taking into account foreign key description field and transformations * - * @param string $class css classes for the td element - * @param bool $condition_field whether the column is a part of the - * where clause - * @param string $analyzed_sql the analyzed query - * @param object $meta the meta-information about this field - * @param array $map the list of relations - * @param string $data data - * @param string $transform_function transformation function - * @param string $default_function default function - * @param string $nowrap 'nowrap' if the content should not be - * wrapped - * @param string $where_comparison data for the where cluase - * @param array $transform_options array of options for transformation - * @param bool $is_field_truncated whether the field is truncated + * @param string $class css classes for the td element + * @param bool $condition_field whether the column is a part of the + * where clause + * @param string $analyzed_sql the analyzed query + * @param object $meta the meta-information about the field + * @param array $map the list of relations + * @param string $data data + * @param string $transformation_plugin transformation plugin. + * Can also be the default function: + * PMA_mimeDefaultFunction + * @param string $default_function default function + * @param string $nowrap 'nowrap' if the content should not + * be wrapped + * @param string $where_comparison data for the where cluase + * @param array $transform_options array of options for transformation + * @param bool $is_field_truncated whether the field is truncated * * @return string formatted data - * + * * @access private - * + * * @see _getDataCellForNumericColumns(), _getDataCellForGeometryColumns(), * _getDataCellForNonNumericAndNonBlobColumns(), - * + * */ private function _getRowData( $class, $condition_field, $analyzed_sql, $meta, $map, $data, - $transform_function, $default_function, $nowrap, $where_comparison, + $transformation_plugin, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated ) { $result = ''; @@ -4653,10 +4679,15 @@ class PMA_DisplayResults if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') { - $result .= ($transform_function != $default_function - ? $transform_function($data, $transform_options, $meta) - : $transform_function($data, array(), $meta)) - . ' [->' . $dispval . ']'; + $result .= ($transformation_plugin != $default_function + ? $transformation_plugin->applyTransformation( + $data, + $transform_options, + $meta + ) + : $default_function($data) + ) + . ' [->' . $dispval . ']'; } else { @@ -4686,19 +4717,31 @@ class PMA_DisplayResults $result .= ''; - if ($transform_function != $default_function) { + if ($transformation_plugin != $default_function) { // always apply a transformation on the real data, // not on the display field - $result .= $transform_function($data, $transform_options, $meta); + $result .= $transformation_plugin->applyTransformation( + $data, + $transform_options, + $meta + ); } else { if ($_SESSION['tmp_user_values']['relational_display'] == self::RELATIONAL_DISPLAY_COLUMN) { // user chose "relational display field" in the // display options, so show display field in the cell - $result .= $transform_function($dispval, array(), $meta); + $result .= $transformation_plugin->applyTransformation( + $dispval, + array(), + $meta + ); } else { // otherwise display data in the cell - $result .= $transform_function($data, array(), $meta); + $result .= $transformation_plugin->applyTransformation( + $data, + array(), + $meta + ); } } @@ -4706,9 +4749,14 @@ class PMA_DisplayResults } } else { - $result .= ($transform_function != $default_function) - ? $transform_function($data, $transform_options, $meta) - : $transform_function($data, array(), $meta); + $result .= ($transformation_plugin != $default_function + ? $transformation_plugin->applyTransformation( + $data, + $transform_options, + $meta + ) + : $default_function($data) + ); } // create hidden field if results from structure table @@ -4754,9 +4802,9 @@ class PMA_DisplayResults * @param string $class css classes for the td element * * @return string the generated HTML - * + * * @access private - * + * * @see _getTableBody(), _getCheckboxAndLinks() */ private function _getCheckboxForMultiRowSubmissions( @@ -4803,9 +4851,9 @@ class PMA_DisplayResults * @param string $where_clause_html url encoded where cluase * * @return string the generated HTML - * + * * @access private - * + * * @see _getTableBody(), _getCheckboxAndLinks() */ private function _getEditLink( @@ -4843,9 +4891,9 @@ class PMA_DisplayResults * @param string $class css classes for the td element * * @return string the generated HTML - * + * * @access private - * + * * @see _getTableBody(), _getCheckboxAndLinks() */ private function _getCopyLink( @@ -4888,9 +4936,9 @@ class PMA_DisplayResults * @param string $class css classes for the td element * * @return string the generated HTML - * + * * @access private - * + * * @see _getTableBody(), _getCheckboxAndLinks() */ private function _getDeleteLink($del_url, $del_str, $js_conf, $class) @@ -4937,9 +4985,9 @@ class PMA_DisplayResults * @param string $js_conf text for the JS confirmation * * @return string the generated HTML - * + * * @access private - * + * * @see _getPlacedLinks() */ private function _getCheckboxAndLinks( @@ -4995,6 +5043,6 @@ class PMA_DisplayResults return $ret; } // end of the '_getCheckboxAndLinks()' function - + } ?> diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index 2c8148f762..bc2dd90351 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -97,7 +97,7 @@ function PMA_getWhereClauseArray($where_clause) * * @return array $where_clauses, $result, $rows */ -function PMA_analyzeWhereClauses(\ +function PMA_analyzeWhereClauses( $where_clause_array, $table, $db, $found_unique_key ) { $rows = array(); diff --git a/libraries/plugins/TransformationsPlugin.class.php b/libraries/plugins/TransformationsPlugin.class.php index a9bb5bd9a6..6f59c02896 100644 --- a/libraries/plugins/TransformationsPlugin.class.php +++ b/libraries/plugins/TransformationsPlugin.class.php @@ -23,6 +23,19 @@ require_once "TransformationsInterface.int.php"; abstract class TransformationsPlugin extends PluginObserver implements TransformationsInterface { + /** + * Does the actual work of each specific transformations plugin. + * + * @param array $options transformation options + * + * @todo implement + * @return void + */ + public function applyTransformationNoWrap($options = array()) + { + ; + } + /** * Does the actual work of each specific transformations plugin. * diff --git a/libraries/plugins/transformations/Application_Octetstream_Download.class.php b/libraries/plugins/transformations/Application_Octetstream_Download.class.php index e986631c6e..e88e34386f 100644 --- a/libraries/plugins/transformations/Application_Octetstream_Download.class.php +++ b/libraries/plugins/transformations/Application_Octetstream_Download.class.php @@ -19,22 +19,6 @@ require_once "abstract/DownloadTransformationsPlugin.class.php"; */ class Application_Octetstream_Download extends DownloadTransformationsPlugin { - /** - * Gets the transformation description of the specific plugin - * - * @return string - */ - public static function getInfo() - { - return __( - 'Displays a link to download the binary data of the column. You can' - . ' use the first option to specify the filename, or use the second' - . ' option as the name of a column which contains the filename. If' - . ' you use the second option, you need to set the first option to' - . ' the empty string.' - ); - } - /** * Gets the plugin`s MIME type * diff --git a/libraries/plugins/transformations/Application_Octetstream_Hex.class.php b/libraries/plugins/transformations/Application_Octetstream_Hex.class.php index 121548374c..09c87ed74a 100644 --- a/libraries/plugins/transformations/Application_Octetstream_Hex.class.php +++ b/libraries/plugins/transformations/Application_Octetstream_Hex.class.php @@ -20,20 +20,6 @@ require_once "abstract/HexTransformationsPlugin.class.php"; */ class Application_Octetstream_Hex extends HexTransformationsPlugin { - /** - * Gets the transformation description of the specific plugin - * - * @return string - */ - public static function getInfo() - { - return __( - 'Displays hexadecimal representation of data. Optional first' - . ' parameter specifies how often space will be added (defaults' - . ' to 2 nibbles).' - ); - } - /** * Gets the plugin`s MIME type * diff --git a/libraries/plugins/transformations/Image_JPEG_Inline.class.php b/libraries/plugins/transformations/Image_JPEG_Inline.class.php index 41d481da01..5db7fe9f1e 100644 --- a/libraries/plugins/transformations/Image_JPEG_Inline.class.php +++ b/libraries/plugins/transformations/Image_JPEG_Inline.class.php @@ -20,19 +20,6 @@ require_once "abstract/InlineTransformationsPlugin.class.php"; */ class Image_JPEG_Inline extends InlineTransformationsPlugin { - /** - * Gets the transformation description of the specific plugin - * - * @return string - */ - public static function getInfo() - { - return __( - 'Displays a clickable thumbnail. The options are the maximum width' - . ' and height in pixels. The original aspect ratio is preserved.' - ); - } - /** * Gets the plugin`s MIME type * diff --git a/libraries/plugins/transformations/Image_JPEG_Link.class.php b/libraries/plugins/transformations/Image_JPEG_Link.class.php index 0f5258072e..1f9577667f 100644 --- a/libraries/plugins/transformations/Image_JPEG_Link.class.php +++ b/libraries/plugins/transformations/Image_JPEG_Link.class.php @@ -11,27 +11,15 @@ if (! defined('PHPMYADMIN')) { } /* Get the link transformations interface */ -require_once "abstract/LinkTransformationsPlugin.class.php"; +require_once "abstract/ImageLinkTransformationsPlugin.class.php"; /** * Handles the link transformation for image jpeg * * @package PhpMyAdmin */ -class Image_JPEG_Link extends LinkTransformationsPlugin + class Image_JPEG_Link extends ImageLinkTransformationsPlugin { - /** - * Gets the transformation description of the specific plugin - * - * @return string - */ - public static function getInfo() - { - return __( - 'Displays a link to download this image.' - ); - } - /** * Gets the plugin`s MIME type * diff --git a/libraries/plugins/transformations/Image_PNG_Inline.class.php b/libraries/plugins/transformations/Image_PNG_Inline.class.php index 6a722d305c..af60e315ee 100644 --- a/libraries/plugins/transformations/Image_PNG_Inline.class.php +++ b/libraries/plugins/transformations/Image_PNG_Inline.class.php @@ -20,19 +20,6 @@ require_once "abstract/InlineTransformationsPlugin.class.php"; */ class Image_PNG_Inline extends InlineTransformationsPlugin { - /** - * Gets the transformation description of the specific plugin - * - * @return string - */ - public static function getInfo() - { - return __( - 'Displays a clickable thumbnail. The options are the maximum width' - . ' and height in pixels. The original aspect ratio is preserved.' - ); - } - /** * Gets the plugin`s MIME type * diff --git a/libraries/plugins/transformations/Text_Plain_Append.class.php b/libraries/plugins/transformations/Text_Plain_Append.class.php index b2f914ec48..50072baa43 100644 --- a/libraries/plugins/transformations/Text_Plain_Append.class.php +++ b/libraries/plugins/transformations/Text_Plain_Append.class.php @@ -21,19 +21,6 @@ require_once "abstract/AppendTransformationsPlugin.class.php"; */ class Text_Plain_Append extends AppendTransformationsPlugin { - /** - * Gets the transformation description of the specific plugin - * - * @return string - */ - public static function getInfo() - { - return __( - 'Appends text to a string. The only option is the text to be appended' - . ' (enclosed in single quotes, default empty string).' - ); - } - /** * Gets the plugin`s MIME type * diff --git a/libraries/plugins/transformations/Text_Plain_Dateformat.class.php b/libraries/plugins/transformations/Text_Plain_Dateformat.class.php index d76c612183..3d2c912b15 100644 --- a/libraries/plugins/transformations/Text_Plain_Dateformat.class.php +++ b/libraries/plugins/transformations/Text_Plain_Dateformat.class.php @@ -20,26 +20,6 @@ require_once "abstract/DateFormatTransformationsPlugin.class.php"; */ class Text_Plain_Dateformat extends DateFormatTransformationsPlugin { - /** - * Gets the transformation description of the specific plugin - * - * @return string - */ - public static function getInfo() - { - return __( - 'Displays a TIME, TIMESTAMP, DATETIME or numeric unix timestamp' - . ' column as formatted date. The first option is the offset (in' - . ' hours) which will be added to the timestamp (Default: 0). Use' - . ' second option to specify a different date/time format string.' - . ' Third option determines whether you want to see local date or' - . ' UTC one (use "local" or "utc" strings) for that. According to' - . ' that, date format has different value - for "local" see the' - . ' documentation for PHP\'s strftime() function and for "utc" it' - . ' is done using gmdate() function.' - ); - } - /** * Gets the plugin`s MIME type * diff --git a/libraries/plugins/transformations/Text_Plain_External.class.php b/libraries/plugins/transformations/Text_Plain_External.class.php index b7155485d5..2fbc3ce4d0 100644 --- a/libraries/plugins/transformations/Text_Plain_External.class.php +++ b/libraries/plugins/transformations/Text_Plain_External.class.php @@ -20,29 +20,6 @@ require_once "abstract/ExternalTransformationsPlugin.class.php"; */ class Text_Plain_External extends ExternalTransformationsPlugin { - /** - * Gets the transformation description of the specific plugin - * - * @return string - */ - public static function getInfo() - { - return __( - 'LINUX ONLY: Launches an external application and feeds it the column' - . ' data via standard input. Returns the standard output of the' - . ' application. The default is Tidy, to pretty-print HTML code.' - . ' For security reasons, you have to manually edit the file' - . ' libraries/plugins/transformations/TransformationTextPlainExternal' - . '.class.php and list the tools you want to make available.' - . ' The first option is then the number of the program you want to' - . ' use and the second option is the parameters for the program.' - . ' The third option, if set to 1, will convert the output using' - . ' htmlspecialchars() (Default 1). The fourth option, if set to 1,' - . ' will prevent wrapping and ensure that the output appears all on' - . ' one line (Default 1).' - ); - } - /** * Gets the plugin`s MIME type * diff --git a/libraries/plugins/transformations/Text_Plain_Formatted.class.php b/libraries/plugins/transformations/Text_Plain_Formatted.class.php index 2865323719..714d808890 100644 --- a/libraries/plugins/transformations/Text_Plain_Formatted.class.php +++ b/libraries/plugins/transformations/Text_Plain_Formatted.class.php @@ -20,20 +20,6 @@ require_once "abstract/FormattedTransformationsPlugin.class.php"; */ class Text_Plain_Formatted extends FormattedTransformationsPlugin { - /** - * Gets the transformation description of the specific plugin - * - * @return string - */ - public static function getInfo() - { - return __( - 'Displays the contents of the column as-is, without running it' - . ' through htmlspecialchars(). That is, the column is assumed' - . ' to contain valid HTML.' - ); - } - /** * Gets the plugin`s MIME type * diff --git a/libraries/plugins/transformations/Text_Plain_Imagelink.class.php b/libraries/plugins/transformations/Text_Plain_Imagelink.class.php index 3d23824900..d9e0110afb 100644 --- a/libraries/plugins/transformations/Text_Plain_Imagelink.class.php +++ b/libraries/plugins/transformations/Text_Plain_Imagelink.class.php @@ -11,29 +11,15 @@ if (! defined('PHPMYADMIN')) { } /* Get the image link transformations interface */ -require_once "abstract/ImageLinkTransformationsPlugin.class.php"; +require_once "abstract/TextImageLinkTransformationsPlugin.class.php"; /** * Handles the image link transformation for text plain * * @package PhpMyAdmin */ -class Text_Plain_Imagelink extends ImageLinkTransformationsPlugin +class Text_Plain_Imagelink extends TextImageLinkTransformationsPlugin { - /** - * Gets the transformation description of the specific plugin - * - * @return string - */ - public static function getInfo() - { - return __( - 'Displays an image and a link; the column contains the filename. The' - . ' first option is a URL prefix like "http://www.example.com/". The' - . ' second and third options are the width and the height in pixels.' - ); - } - /** * Gets the plugin`s MIME type * diff --git a/libraries/plugins/transformations/Text_Plain_Link.class.php b/libraries/plugins/transformations/Text_Plain_Link.class.php index 1ed058bb34..da93d3c00a 100644 --- a/libraries/plugins/transformations/Text_Plain_Link.class.php +++ b/libraries/plugins/transformations/Text_Plain_Link.class.php @@ -11,29 +11,15 @@ if (! defined('PHPMYADMIN')) { } /* Get the link transformations interface */ -require_once "abstract/LinkTransformationsPlugin.class.php"; +require_once "abstract/TextLinkTransformationsPlugin.class.php"; /** * Handles the link transformation for text plain * * @package PhpMyAdmin */ -class Text_Plain_Link extends LinkTransformationsPlugin +class Text_Plain_Link extends TextLinkTransformationsPlugin { - /** - * Gets the transformation description of the specific plugin - * - * @return string - */ - public static function getInfo() - { - return __( - 'Displays a link; the column contains the filename. The first option' - . ' is a URL prefix like "http://www.example.com/". The second option' - . ' is a title for the link.' - ); - } - /** * Gets the plugin`s MIME type * diff --git a/libraries/plugins/transformations/Text_Plain_Longtoipv4.class.php b/libraries/plugins/transformations/Text_Plain_Longtoipv4.class.php index 32373ad7f3..202b0c73bf 100644 --- a/libraries/plugins/transformations/Text_Plain_Longtoipv4.class.php +++ b/libraries/plugins/transformations/Text_Plain_Longtoipv4.class.php @@ -20,19 +20,6 @@ require_once "abstract/LongToIPv4TransformationsPlugin.class.php"; */ class Text_Plain_Longtoipv4 extends LongToIPv4TransformationsPlugin { - /** - * Gets the transformation description of the specific plugin - * - * @return string - */ - public static function getInfo() - { - return __( - 'Converts an (IPv4) Internet network address into a string in' - . ' Internet standard dotted format.' - ); - } - /** * Gets the plugin`s MIME type * diff --git a/libraries/plugins/transformations/Text_Plain_Sql.class.php b/libraries/plugins/transformations/Text_Plain_Sql.class.php index 816069faab..3b892b2827 100644 --- a/libraries/plugins/transformations/Text_Plain_Sql.class.php +++ b/libraries/plugins/transformations/Text_Plain_Sql.class.php @@ -20,18 +20,6 @@ require_once "abstract/SQLTransformationsPlugin.class.php"; */ class Text_Plain_Sql extends SQLTransformationsPlugin { - /** - * Gets the transformation description of the specific plugin - * - * @return string - */ - public static function getInfo() - { - return __( - 'Formats text as SQL query with syntax highlighting.' - ); - } - /** * Gets the plugin`s MIME type * diff --git a/libraries/plugins/transformations/Text_Plain_Substring.class.php b/libraries/plugins/transformations/Text_Plain_Substring.class.php index 187e5fdbb8..3f28c987e4 100644 --- a/libraries/plugins/transformations/Text_Plain_Substring.class.php +++ b/libraries/plugins/transformations/Text_Plain_Substring.class.php @@ -20,22 +20,6 @@ require_once "abstract/SubstringTransformationsPlugin.class.php"; */ class Text_Plain_Substring extends SubstringTransformationsPlugin { - /** - * Gets the transformation description of the specific plugin - * - * @return string - */ - public static function getInfo() - { - return __( - 'Displays a part of a string. The first option is the number of' - . ' characters to skip from the beginning of the string (Default 0).' - . ' The second option is the number of characters to return (Default:' - . ' until end of string). The third option is the string to append' - . ' and/or prepend when truncation occurs (Default: "...").' - ); - } - /** * Gets the plugin`s MIME type * diff --git a/libraries/plugins/transformations/abstract/AppendTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/AppendTransformationsPlugin.class.php index 9b811a057d..bd0661f805 100644 --- a/libraries/plugins/transformations/abstract/AppendTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/AppendTransformationsPlugin.class.php @@ -20,6 +20,19 @@ require_once "libraries/plugins/TransformationsPlugin.class.php"; */ abstract class AppendTransformationsPlugin extends TransformationsPlugin { + /** + * Gets the transformation description of the specific plugin + * + * @return string + */ + public static function getInfo() + { + return __( + 'Appends text to a string. The only option is the text to be appended' + . ' (enclosed in single quotes, default empty string).' + ); + } + /** * Does the actual work of each specific transformations plugin. * @@ -27,12 +40,17 @@ abstract class AppendTransformationsPlugin extends TransformationsPlugin * @param array $options transformation options * @param string $meta meta information * - * @todo implement * @return void */ - public function applyTransformation($buffer, $options, $meta) + public function applyTransformation($buffer, $options = array(), $meta = '') { - ; + if (! isset($options[0]) || $options[0] == '') { + $options[0] = ''; + } + //just append the option to the original text + $newtext = $buffer . htmlspecialchars($options[0]); + + return $newtext; } /** diff --git a/libraries/plugins/transformations/abstract/DateFormatTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/DateFormatTransformationsPlugin.class.php index bd4d82d67c..03b96657c6 100644 --- a/libraries/plugins/transformations/abstract/DateFormatTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/DateFormatTransformationsPlugin.class.php @@ -20,6 +20,26 @@ require_once "libraries/plugins/TransformationsPlugin.class.php"; */ abstract class DateFormatTransformationsPlugin extends TransformationsPlugin { + /** + * Gets the transformation description of the specific plugin + * + * @return string + */ + public static function getInfo() + { + return __( + 'Displays a TIME, TIMESTAMP, DATETIME or numeric unix timestamp' + . ' column as formatted date. The first option is the offset (in' + . ' hours) which will be added to the timestamp (Default: 0). Use' + . ' second option to specify a different date/time format string.' + . ' Third option determines whether you want to see local date or' + . ' UTC one (use "local" or "utc" strings) for that. According to' + . ' that, date format has different value - for "local" see the' + . ' documentation for PHP\'s strftime() function and for "utc" it' + . ' is done using gmdate() function.' + ); + } + /** * Does the actual work of each specific transformations plugin. * @@ -27,12 +47,100 @@ abstract class DateFormatTransformationsPlugin extends TransformationsPlugin * @param array $options transformation options * @param string $meta meta information * - * @todo implement * @return void */ - public function applyTransformation($buffer, $options, $meta) + public function applyTransformation($buffer, $options = array(), $meta = '') { - ; + // possibly use a global transform and feed it with special options + + // further operations on $buffer using the $options[] array. + if (empty($options[0])) { + $options[0] = 0; + } + + if (empty($options[2])) { + $options[2] = 'local'; + } else { + $options[2] = strtolower($options[2]); + } + + if (empty($options[1])) { + if ($options[2] == 'local') { + $options[1] = __('%B %d, %Y at %I:%M %p'); + } else { + $options[1] = 'Y-m-d H:i:s'; + } + } + + $timestamp = -1; + + // INT columns will be treated as UNIX timestamps + // and need to be detected before the verification for + // MySQL TIMESTAMP + if ($meta->type == 'int') { + $timestamp = $buffer; + + // Detect TIMESTAMP(6 | 8 | 10 | 12 | 14) + // TIMESTAMP (2 | 4) not supported here. + // (Note: prior to MySQL 4.1, TIMESTAMP has a display size + // for example TIMESTAMP(8) means YYYYMMDD) + } else if (preg_match('/^(\d{2}){3,7}$/', $buffer)) { + + if (strlen($buffer) == 14 || strlen($buffer) == 8) { + $offset = 4; + } else { + $offset = 2; + } + + $d = array(); + $d['year'] = substr($buffer, 0, $offset); + $d['month'] = substr($buffer, $offset, 2); + $d['day'] = substr($buffer, $offset + 2, 2); + $d['hour'] = substr($buffer, $offset + 4, 2); + $d['minute'] = substr($buffer, $offset + 6, 2); + $d['second'] = substr($buffer, $offset + 8, 2); + + if (checkdate($d['month'], $d['day'], $d['year'])) { + $timestamp = mktime( + $d['hour'], + $d['minute'], + $d['second'], + $d['month'], + $d['day'], + $d['year'] + ); + } + // If all fails, assume one of the dozens of valid strtime() syntaxes + // (http://www.gnu.org/manual/tar-1.12/html_chapter/tar_7.html) + } else { + if (preg_match('/^[0-9]\d{1,9}$/', $buffer)) { + $timestamp = (int)$buffer; + } else { + $timestamp = strtotime($buffer); + } + } + + // If all above failed, maybe it's a Unix timestamp already? + if ($timestamp < 0 && preg_match('/^[1-9]\d{1,9}$/', $buffer)) { + $timestamp = $buffer; + } + + // Reformat a valid timestamp + if ($timestamp >= 0) { + $timestamp -= $options[0] * 60 * 60; + $source = $buffer; + if ($options[2] == 'local') { + $text = PMA_localisedDate($timestamp, $options[1]); + } elseif ($options[2] == 'utc') { + $text = gmdate($options[1], $timestamp); + } else { + $text = 'INVALID DATE TYPE'; + } + $buffer = '' . $text . ''; + } + + return $buffer; } /** diff --git a/libraries/plugins/transformations/abstract/DownloadTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/DownloadTransformationsPlugin.class.php index 77bd39ecda..3f081c3895 100644 --- a/libraries/plugins/transformations/abstract/DownloadTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/DownloadTransformationsPlugin.class.php @@ -20,6 +20,22 @@ require_once "libraries/plugins/TransformationsPlugin.class.php"; */ abstract class DownloadTransformationsPlugin extends TransformationsPlugin { + /** + * Gets the transformation description of the specific plugin + * + * @return string + */ + public static function getInfo() + { + return __( + 'Displays a link to download the binary data of the column. You can' + . ' use the first option to specify the filename, or use the second' + . ' option as the name of a column which contains the filename. If' + . ' you use the second option, you need to set the first option to' + . ' the empty string.' + ); + } + /** * Does the actual work of each specific transformations plugin. * @@ -27,12 +43,39 @@ abstract class DownloadTransformationsPlugin extends TransformationsPlugin * @param array $options transformation options * @param string $meta meta information * - * @todo implement * @return void */ - public function applyTransformation($buffer, $options, $meta) + public function applyTransformation($buffer, $options = array(), $meta = '') { - ; + global $row, $fields_meta; + + if (isset($options[0]) && !empty($options[0])) { + $cn = $options[0]; // filename + } else { + if (isset($options[1]) && !empty($options[1])) { + foreach ($fields_meta as $key => $val) { + if ($val->name == $options[1]) { + $pos = $key; + break; + } + } + if (isset($pos)) { + $cn = $row[$pos]; + } + } + if (empty($cn)) { + $cn = 'binary_file.dat'; + } + } + + return sprintf( + '%s', + $options['wrapper_link'], + urlencode($cn), + htmlspecialchars($cn), + htmlspecialchars($cn) + ); } /** diff --git a/libraries/plugins/transformations/abstract/ExternalTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/ExternalTransformationsPlugin.class.php index 2a7c495584..d2ceea5885 100644 --- a/libraries/plugins/transformations/abstract/ExternalTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/ExternalTransformationsPlugin.class.php @@ -20,6 +20,49 @@ require_once "libraries/plugins/TransformationsPlugin.class.php"; */ abstract class ExternalTransformationsPlugin extends TransformationsPlugin { + /** + * Gets the transformation description of the specific plugin + * + * @return string + */ + public static function getInfo() + { + return __( + 'LINUX ONLY: Launches an external application and feeds it the column' + . ' data via standard input. Returns the standard output of the' + . ' application. The default is Tidy, to pretty-print HTML code.' + . ' For security reasons, you have to manually edit the file' + . ' libraries/plugins/transformations/Text_Plain_External' + . '.class.php and list the tools you want to make available.' + . ' The first option is then the number of the program you want to' + . ' use and the second option is the parameters for the program.' + . ' The third option, if set to 1, will convert the output using' + . ' htmlspecialchars() (Default 1). The fourth option, if set to 1,' + . ' will prevent wrapping and ensure that the output appears all on' + . ' one line (Default 1).' + ); + } + + /** + * Enables no-wrapping + * + * @param array $options transformation options + * + * @return bool + */ + public function applyTransformationNoWrap($options = array()) + { + if (! isset($options[3]) || $options[3] == '') { + $nowrap = true; + } elseif ($options[3] == '1' || $options[3] == 1) { + $nowrap = true; + } else { + $nowrap = false; + } + + return $nowrap; + } + /** * Does the actual work of each specific transformations plugin. * @@ -27,12 +70,84 @@ abstract class ExternalTransformationsPlugin extends TransformationsPlugin * @param array $options transformation options * @param string $meta meta information * - * @todo implement * @return void */ - public function applyTransformation($buffer, $options, $meta) + public function applyTransformation($buffer, $options = array(), $meta = '') { - ; + // possibly use a global transform and feed it with special options + + // further operations on $buffer using the $options[] array. + + $allowed_programs = array(); + + // + // WARNING: + // + // It's up to administrator to allow anything here. Note that users may + // specify any parameters, so when programs allow output redirection or + // any other possibly dangerous operations, you should write wrapper + // script that will publish only functions you really want. + // + // Add here program definitions like (note that these are NOT safe + // programs): + // + //$allowed_programs[0] = '/usr/local/bin/tidy'; + //$allowed_programs[1] = '/usr/local/bin/validate'; + + // no-op when no allowed programs + if (count($allowed_programs) == 0) { + return $buffer; + } + + if (! isset($options[0]) + || $options[0] == '' + || ! isset($allowed_programs[$options[0]]) + ) { + $program = $allowed_programs[0]; + } else { + $program = $allowed_programs[$options[0]]; + } + + if (!isset($options[1]) || $options[1] == '') { + $poptions = '-f /dev/null -i -wrap -q'; + } else { + $poptions = $options[1]; + } + + if (!isset($options[2]) || $options[2] == '') { + $options[2] = 1; + } + + if (!isset($options[3]) || $options[3] == '') { + $options[3] = 1; + } + + // needs PHP >= 4.3.0 + $newstring = ''; + $descriptorspec = array( + 0 => array("pipe", "r"), + 1 => array("pipe", "w") + ); + $process = proc_open($program . ' ' . $poptions, $descriptorspec, $pipes); + if (is_resource($process)) { + fwrite($pipes[0], $buffer); + fclose($pipes[0]); + + while (!feof($pipes[1])) { + $newstring .= fgets($pipes[1], 1024); + } + fclose($pipes[1]); + // we don't currently use the return value + proc_close($process); + } + + if ($options[2] == 1 || $options[2] == '2') { + $retstring = htmlspecialchars($newstring); + } else { + $retstring = $newstring; + } + + return $retstring; } /** diff --git a/libraries/plugins/transformations/abstract/FormattedTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/FormattedTransformationsPlugin.class.php index e089fac77a..0e93835380 100644 --- a/libraries/plugins/transformations/abstract/FormattedTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/FormattedTransformationsPlugin.class.php @@ -20,6 +20,20 @@ require_once "libraries/plugins/TransformationsPlugin.class.php"; */ abstract class FormattedTransformationsPlugin extends TransformationsPlugin { + /** + * Gets the transformation description of the specific plugin + * + * @return string + */ + public static function getInfo() + { + return __( + 'Displays the contents of the column as-is, without running it' + . ' through htmlspecialchars(). That is, the column is assumed' + . ' to contain valid HTML.' + ); + } + /** * Does the actual work of each specific transformations plugin. * @@ -27,12 +41,11 @@ abstract class FormattedTransformationsPlugin extends TransformationsPlugin * @param array $options transformation options * @param string $meta meta information * - * @todo implement * @return void */ - public function applyTransformation($buffer, $options, $meta) + public function applyTransformation($buffer, $options = array(), $meta = '') { - ; + return $buffer; } /** diff --git a/libraries/plugins/transformations/abstract/HexTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/HexTransformationsPlugin.class.php index 76ff6741ae..9bb14475ad 100644 --- a/libraries/plugins/transformations/abstract/HexTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/HexTransformationsPlugin.class.php @@ -20,6 +20,20 @@ require_once "libraries/plugins/TransformationsPlugin.class.php"; */ abstract class HexTransformationsPlugin extends TransformationsPlugin { + /** + * Gets the transformation description of the specific plugin + * + * @return string + */ + public static function getInfo() + { + return __( + 'Displays hexadecimal representation of data. Optional first' + . ' parameter specifies how often space will be added (defaults' + . ' to 2 nibbles).' + ); + } + /** * Does the actual work of each specific transformations plugin. * @@ -27,12 +41,22 @@ abstract class HexTransformationsPlugin extends TransformationsPlugin * @param array $options transformation options * @param string $meta meta information * - * @todo implement * @return void */ - public function applyTransformation($buffer, $options, $meta) + public function applyTransformation($buffer, $options = array(), $meta = '') { - ; + // possibly use a global transform and feed it with special options + if (!isset($options[0])) { + $options[0] = 2; + } else { + $options[0] = (int)$options[0]; + } + + if ($options[0] < 1) { + return bin2hex($buffer); + } else { + return chunk_split(bin2hex($buffer), $options[0], ' '); + } } /** diff --git a/libraries/plugins/transformations/abstract/ImageLinkTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/ImageLinkTransformationsPlugin.class.php index c98568a579..99e28e4698 100644 --- a/libraries/plugins/transformations/abstract/ImageLinkTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/ImageLinkTransformationsPlugin.class.php @@ -1,10 +1,10 @@ '[BLOB]' + ); + $buffer = PMA_transformation_global_html_replace( + $buffer, + $transform_options + ); + + return $buffer; } /** @@ -61,7 +81,7 @@ abstract class ImageLinkTransformationsPlugin extends TransformationsPlugin */ public static function getName() { - return "Image Link"; + return "Link"; } } ?> \ No newline at end of file diff --git a/libraries/plugins/transformations/abstract/InlineTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/InlineTransformationsPlugin.class.php index 16683b92c4..0b7452911b 100644 --- a/libraries/plugins/transformations/abstract/InlineTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/InlineTransformationsPlugin.class.php @@ -20,6 +20,19 @@ require_once "libraries/plugins/TransformationsPlugin.class.php"; */ abstract class InlineTransformationsPlugin extends TransformationsPlugin { + /** + * Gets the transformation description of the specific plugin + * + * @return string + */ + public static function getInfo() + { + return __( + 'Displays a clickable thumbnail. The options are the maximum width' + . ' and height in pixels. The original aspect ratio is preserved.' + ); + } + /** * Does the actual work of each specific transformations plugin. * @@ -27,12 +40,33 @@ abstract class InlineTransformationsPlugin extends TransformationsPlugin * @param array $options transformation options * @param string $meta meta information * - * @todo implement * @return void */ - public function applyTransformation($buffer, $options, $meta) + public function applyTransformation($buffer, $options = array(), $meta = '') { - ; + if (PMA_IS_GD2) { + $transform_options = array ( + 'string' => '[__BUFFER__]' + ); + } else { + $transform_options = array ( + 'string' => '[__BUFFER__]' + ); + } + $buffer = PMA_transformation_global_html_replace( + $buffer, + $transform_options + ); + + return $buffer; } /** diff --git a/libraries/plugins/transformations/abstract/LongToIPv4TransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/LongToIPv4TransformationsPlugin.class.php index 53f1180f59..e7b2ddb33d 100644 --- a/libraries/plugins/transformations/abstract/LongToIPv4TransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/LongToIPv4TransformationsPlugin.class.php @@ -20,6 +20,19 @@ require_once "libraries/plugins/TransformationsPlugin.class.php"; */ abstract class LongToIPv4TransformationsPlugin extends TransformationsPlugin { + /** + * Gets the transformation description of the specific plugin + * + * @return string + */ + public static function getInfo() + { + return __( + 'Converts an (IPv4) Internet network address into a string in' + . ' Internet standard dotted format.' + ); + } + /** * Does the actual work of each specific transformations plugin. * @@ -27,12 +40,15 @@ abstract class LongToIPv4TransformationsPlugin extends TransformationsPlugin * @param array $options transformation options * @param string $meta meta information * - * @todo implement * @return void */ - public function applyTransformation($buffer, $options, $meta) + public function applyTransformation($buffer, $options = array(), $meta = '') { - ; + if ($buffer < 0 || $buffer > 4294967295) { + return $buffer; + } + + return long2ip($buffer); } /** diff --git a/libraries/plugins/transformations/abstract/SQLTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/SQLTransformationsPlugin.class.php index 32cd9b889d..c6d8e6513f 100644 --- a/libraries/plugins/transformations/abstract/SQLTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/SQLTransformationsPlugin.class.php @@ -20,6 +20,18 @@ require_once "libraries/plugins/TransformationsPlugin.class.php"; */ abstract class SQLTransformationsPlugin extends TransformationsPlugin { + /** + * Gets the transformation description of the specific plugin + * + * @return string + */ + public static function getInfo() + { + return __( + 'Formats text as SQL query with syntax highlighting.' + ); + } + /** * Does the actual work of each specific transformations plugin. * @@ -27,12 +39,14 @@ abstract class SQLTransformationsPlugin extends TransformationsPlugin * @param array $options transformation options * @param string $meta meta information * - * @todo implement * @return void */ - public function applyTransformation($buffer, $options, $meta) + public function applyTransformation($buffer, $options = array(), $meta = '') { - ; + $result = PMA_SQP_formatHtml(PMA_SQP_parse($buffer)); + // Need to clear error state not to break subsequent queries display. + PMA_SQP_resetError(); + return $result; } /** diff --git a/libraries/plugins/transformations/abstract/SubstringTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/SubstringTransformationsPlugin.class.php index de0e794989..03e7639651 100644 --- a/libraries/plugins/transformations/abstract/SubstringTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/SubstringTransformationsPlugin.class.php @@ -20,6 +20,22 @@ require_once "libraries/plugins/TransformationsPlugin.class.php"; */ abstract class SubstringTransformationsPlugin extends TransformationsPlugin { + /** + * Gets the transformation description of the specific plugin + * + * @return string + */ + public static function getInfo() + { + return __( + 'Displays a part of a string. The first option is the number of' + . ' characters to skip from the beginning of the string (Default 0).' + . ' The second option is the number of characters to return (Default:' + . ' until end of string). The third option is the string to append' + . ' and/or prepend when truncation occurs (Default: "...").' + ); + } + /** * Does the actual work of each specific transformations plugin. * @@ -27,12 +43,45 @@ abstract class SubstringTransformationsPlugin extends TransformationsPlugin * @param array $options transformation options * @param string $meta meta information * - * @todo implement * @return void */ - public function applyTransformation($buffer, $options, $meta) + public function applyTransformation($buffer, $options = array(), $meta = '') { - ; + // possibly use a global transform and feed it with special options + + // further operations on $buffer using the $options[] array. + if (!isset($options[0]) || $options[0] == '') { + $options[0] = 0; + } + + if (!isset($options[1]) || $options[1] == '') { + $options[1] = 'all'; + } + + if (!isset($options[2]) || $options[2] == '') { + $options[2] = '...'; + } + + $newtext = ''; + if ($options[1] != 'all') { + $newtext = PMA_substr($buffer, $options[0], $options[1]); + } else { + $newtext = PMA_substr($buffer, $options[0]); + } + + $length = strlen($newtext); + $baselength = strlen($buffer); + if ($length != $baselength) { + if ($options[0] != 0) { + $newtext = $options[2] . $newtext; + } + + if (($length + $options[0]) != $baselength) { + $newtext .= $options[2]; + } + } + + return $newtext; } /** diff --git a/libraries/plugins/transformations/abstract/TextImageLinkTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/TextImageLinkTransformationsPlugin.class.php new file mode 100644 index 0000000000..772e412cbc --- /dev/null +++ b/libraries/plugins/transformations/abstract/TextImageLinkTransformationsPlugin.class.php @@ -0,0 +1,94 @@ + '' + . $buffer . '' + ); + + $buffer = PMA_transformation_global_html_replace( + $buffer, + $transform_options + ); + + return $buffer; + } + + /** + * This method is called when any PluginManager to which the observer + * is attached calls PluginManager::notify() + * + * @param SplSubject $subject The PluginManager notifying the observer + * of an update. + * + * @todo implement + * @return void + */ + public function update (SplSubject $subject) + { + ; + } + + + /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */ + + + /** + * Gets the transformation name of the specific plugin + * + * @return string + */ + public static function getName() + { + return "Image Link"; + } +} +?> \ No newline at end of file diff --git a/libraries/plugins/transformations/abstract/LinkTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/TextLinkTransformationsPlugin.class.php similarity index 57% rename from libraries/plugins/transformations/abstract/LinkTransformationsPlugin.class.php rename to libraries/plugins/transformations/abstract/TextLinkTransformationsPlugin.class.php index d655ea2b17..43bc65792d 100644 --- a/libraries/plugins/transformations/abstract/LinkTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/TextLinkTransformationsPlugin.class.php @@ -18,8 +18,22 @@ require_once "libraries/plugins/TransformationsPlugin.class.php"; * * @package PhpMyAdmin */ -abstract class LinkTransformationsPlugin extends TransformationsPlugin +abstract class TextLinkTransformationsPlugin extends TransformationsPlugin { + /** + * Gets the transformation description of the specific plugin + * + * @return string + */ + public static function getInfo() + { + return __( + 'Displays a link; the column contains the filename. The first option' + . ' is a URL prefix like "http://www.example.com/". The second option' + . ' is a title for the link.' + ); + } + /** * Does the actual work of each specific transformations plugin. * @@ -27,12 +41,23 @@ abstract class LinkTransformationsPlugin extends TransformationsPlugin * @param array $options transformation options * @param string $meta meta information * - * @todo implement * @return void */ - public function applyTransformation($buffer, $options, $meta) + public function applyTransformation($buffer, $options = array(), $meta = '') { - ; + $transform_options = array ( + 'string' => '' . (isset($options[1]) ? $options[1] : $buffer) . '' + ); + + $buffer = PMA_transformation_global_html_replace( + $buffer, + $transform_options + ); + + return $buffer; } /** diff --git a/tbl_replace.php b/tbl_replace.php index ef6c39e4c3..38d737a2f4 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -371,7 +371,9 @@ if ($GLOBALS['is_ajax_request'] == true) { } // end of loop for each relation cell } - if (isset($_REQUEST['do_transformations']) && $_REQUEST['do_transformations'] == true ) { + if (isset($_REQUEST['do_transformations']) + && $_REQUEST['do_transformations'] == true + ) { include_once 'libraries/transformations.lib.php'; //if some posted fields need to be transformed, generate them here. $mime_map = PMA_getMIME($db, $table); @@ -384,9 +386,27 @@ if ($GLOBALS['is_ajax_request'] == true) { parse_str($_REQUEST['transform_fields_list'], $edited_values); foreach ($mime_map as $transformation) { - $include_file = PMA_securePath($transformation['transformation']); $column_name = $transformation['column_name']; + $include_file = $transformation['transformation']; + $include_file = PMA_securePath( + str_replace( + ".inc.php", + ".class.php", + str_replace( + "__", + "_", + $include_file + ) + ) + ); + $file_parts = explode("_", $include_file); + $include_file = strtoupper($file_parts[0]) . "_" + . strtoupper($file_parts[1]) . "_" + . strtoupper($file_parts[2]); + + $include_file = 'libraries/transformations/plugins/' . $include_file; + foreach ($edited_values as $cell_index => $curr_cell_edited_values) { if (isset($curr_cell_edited_values[$column_name])) { $column_data = $curr_cell_edited_values[$column_name]; @@ -398,21 +418,24 @@ if ($GLOBALS['is_ajax_request'] == true) { 'transform_key' => $column_name, ); - if (file_exists('libraries/transformations/' . $include_file)) { - $transformfunction_name = str_replace('.inc.php', '', $transformation['transformation']); + if (file_exists($include_file)) { + include_once $include_file; + $class_name = str_replace('.class.php', '', $file); + $transformation_plugin = new $class_name; - include_once 'libraries/transformations/' . $include_file; - - if (function_exists('PMA_transformation_' . $transformfunction_name)) { - $transform_function = 'PMA_transformation_' . $transformfunction_name; - $transform_options = PMA_transformation_getOptions( - isset($transformation['transformation_options']) ? $transformation['transformation_options'] : '' - ); - $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params); - } + $transform_options = PMA_transformation_getOptions( + isset($transformation['transformation_options']) + ? $transformation['transformation_options'] : '' + ); + $transform_options['wrapper_link'] = + PMA_generate_common_url($_url_params); } - $extra_data['transformations'][$cell_index] = $transform_function($column_data, $transform_options); + $extra_data['transformations'][$cell_index] = + $transformation_plugin->applyTransformation( + $column_data, + $transform_options + ); } } // end of loop for each transformation cell } // end of loop for each $mime_map