oop: integrate transformations - no errors, but not working.

This commit is contained in:
Alex Marin 2012-06-20 16:28:10 +03:00
parent 1ad049d823
commit 02dbd14fc7
31 changed files with 960 additions and 510 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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();

View File

@ -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.
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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;
}
/**

View File

@ -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 = '<dfn onclick="alert(\'' . $source . '\');" title="'
. $source . '">' . $text . '</dfn>';
}
return $buffer;
}
/**

View File

@ -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(
'<a href="transformation_wrapper.php%s&amp;ct=application'
. '/octet-stream&amp;cn=%s" title="%s">%s</a>',
$options['wrapper_link'],
urlencode($cn),
htmlspecialchars($cn),
htmlspecialchars($cn)
);
}
/**

View File

@ -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;
}
/**

View File

@ -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;
}
/**

View File

@ -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], ' ');
}
}
/**

View File

@ -1,10 +1,10 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Abstract class for the image link transformations plugins
* Abstract class for the link transformations plugins
*
* @package PhpMyAdmin-Transformations
* @subpackage ImageLink
* @subpackage Link
*/
if (! defined('PHPMYADMIN')) {
exit;
@ -14,12 +14,24 @@ if (! defined('PHPMYADMIN')) {
require_once "libraries/plugins/TransformationsPlugin.class.php";
/**
* Provides common methods for all of the image link transformations plugins.
* Provides common methods for all of the link transformations plugins.
*
* @package PhpMyAdmin
*/
abstract class ImageLinkTransformationsPlugin extends TransformationsPlugin
{
/**
* Gets the transformation description of the specific plugin
*
* @return string
*/
public static function getInfo()
{
return __(
'Displays a link to download this image.'
);
}
/**
* Does the actual work of each specific transformations plugin.
*
@ -27,12 +39,20 @@ abstract class ImageLinkTransformationsPlugin 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' => '<a href="transformation_wrapper.php'
. $options['wrapper_link'] . '" alt="[__BUFFER__]">[BLOB]</a>'
);
$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";
}
}
?>

View File

@ -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' => '<a href="transformation_wrapper.php'
. $options['wrapper_link']
. '" target="_blank"><img src="transformation_wrapper.php'
. $options['wrapper_link'] . '&amp;resize=jpeg&amp;newWidth='
. (isset($options[0]) ? $options[0] : '100') . '&amp;newHeight='
. (isset($options[1]) ? $options[1] : 100)
. '" alt="[__BUFFER__]" border="0" /></a>'
);
} else {
$transform_options = array (
'string' => '<img src="transformation_wrapper.php'
. $options['wrapper_link']
. '" alt="[__BUFFER__]" width="320" height="240" />'
);
}
$buffer = PMA_transformation_global_html_replace(
$buffer,
$transform_options
);
return $buffer;
}
/**

View File

@ -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);
}
/**

View File

@ -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;
}
/**

View File

@ -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;
}
/**

View File

@ -0,0 +1,94 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Abstract class for the image link transformations plugins
*
* @package PhpMyAdmin-Transformations
* @subpackage ImageLink
*/
if (! defined('PHPMYADMIN')) {
exit;
}
/* Get the transformations interface */
require_once "libraries/plugins/TransformationsPlugin.class.php";
/**
* Provides common methods for all of the image link transformations plugins.
*
* @package PhpMyAdmin
*/
abstract class TextImageLinkTransformationsPlugin extends TransformationsPlugin
{
/**
* 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.'
);
}
/**
* Does the actual work of each specific transformations plugin.
*
* @param string $buffer text to be transformed
* @param array $options transformation options
* @param string $meta meta information
*
* @return void
*/
public function applyTransformation($buffer, $options = array(), $meta = '')
{
$transform_options = array (
'string' => '<a href="' . (isset($options[0]) ? $options[0] : '')
. $buffer . '" target="_blank"><img src="'
. (isset($options[0]) ? $options[0] : '') . $buffer
. '" border="0" width="' . (isset($options[1]) ? $options[1] : 100)
. '" height="' . (isset($options[2]) ? $options[2] : 50) . '" />'
. $buffer . '</a>'
);
$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";
}
}
?>

View File

@ -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' => '<a href="'
. PMA_linkURL((isset($options[0]) ? $options[0] : '') . $buffer)
. '" title="' . (isset($options[1]) ? $options[1] : '')
. '">' . (isset($options[1]) ? $options[1] : $buffer) . '</a>'
);
$buffer = PMA_transformation_global_html_replace(
$buffer,
$transform_options
);
return $buffer;
}
/**

View File

@ -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