initial commit

This commit is contained in:
Chris Sewell
2012-11-28 03:55:08 -05:00
parent 7adb399b2e
commit cf140a2e97
3247 changed files with 492437 additions and 0 deletions

View File

@ -0,0 +1,4 @@
TRANSFORMATION USAGE (Garvin Hicking, <me@supergarv.de>)
====================
See the Documentation.html for complete instructions on how to use transformation plugins.

View File

@ -0,0 +1,35 @@
<?php
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Plugin function TEMPLATE (Garvin Hicking).
* -----------------------------------------
*
* For instructions, read the /Documentation.html file.
*
* The string [ENTER_FILENAME_HERE] shall be substituted with the filename without the '.inc.php'
* extension. For further information regarding naming conventions see the /Documentation.html file.
*/
function PMA_transformation_[ENTER_FILENAME_HERE]_info()
{
return array(
'info' => __('Description of the transformation.'),
);
}
function PMA_transformation_[ENTER_FILENAME_HERE]($buffer, $options = array(), $meta = '')
{
// possibly use a global transform and feed it with special options:
// include('./libraries/transformations/global.inc.php');
// further operations on $buffer using the $options[] array.
// You can evaluate the propagated $meta Object. It's contained fields are described in http://www.php.net/mysql_fetch_field.
// This stored information can be used to get the field information about the transformed field.
// $meta->mimetype contains the original MimeType of the field (i.e. 'text/plain', 'image/jpeg' etc.)
return $buffer;
}
?>

View File

@ -0,0 +1,12 @@
<?php
// vim: expandtab sw=4 ts=4 sts=4:
/**
* MIME-Init function TEMPLATE (Garvin Hicking).
* -----------------------------------------
*
* This files serves no function. It's only kept here to add a mimetype value for selection.
* You can still use global or other mimetype's transforms with this mimetype.
*/
?>

View File

@ -0,0 +1,51 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @package PhpMyAdmin-Transformation
*/
function PMA_transformation_application_octetstream__download_info()
{
return array(
'info' => __('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.'),
);
}
/**
*
*/
function PMA_transformation_application_octetstream__download(&$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

@ -0,0 +1,35 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @package PhpMyAdmin-Transformation
*/
function PMA_transformation_application_octetstream__hex_info()
{
return array(
'info' => __('Displays hexadecimal representation of data. Optional first parameter specifies how often space will be added (defaults to 2 nibbles).'),
);
}
/**
*
*/
function PMA_transformation_application_octetstream__hex($buffer, $options = array(), $meta = '')
{
// possibly use a global transform and feed it with special options:
// include './libraries/transformations/global.inc.php';
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

@ -0,0 +1,23 @@
#!/bin/bash
#
# Shell script that adds a new function file using a template. Should not be called directly
# but instead by template_Generator.sh and template_generator_mimetype.sh
#
#
# $1: Template
# $2: Filename
# $3: (optional) Description
if [ $# == 0 ]
then
echo "Please call template_generator.sh or template_generator_mimetype.sh instead"
echo ""
exit 65
fi
functionupper="`echo $2 | tr [:lower:] [:upper:]`"
functionlower="`echo $2 | tr [:upper:] [:lower:]`"
sed "s/\[ENTER_FILENAME_HERE\]/$functionupper/; s/\[enter_filename_here\]/$functionlower/; s/Description of the transformation./$3/;" < $1 > $2.inc.php
echo "Created $2.inc.php"
echo ""

View File

@ -0,0 +1,53 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* GLOBAL Plugin function.
* ---------------
*
* THIS FILE PROVIDES BASIC FUNCTIONS TO USE IN OTHER PLUGINS!
*
* The basic filename usage for any plugin, residing in the libraries/transformations directory is:
*
* -- <mime_type>_<mime_subtype>__<transformation_name>.inc.php
*
* The function name has to be the like above filename:
*
* -- function PMA_transformation_<mime_type>_<mime_subtype>__<transformation_name>.inc.php
*
* Please use short and expressive names. For now, special characters which aren't allowed in
* filenames or functions should not be used.
*
* Please provide a comment for your function, what it does and what parameters are available.
*
* @package PhpMyAdmin-Transformation
*/
/**
*
*/
function PMA_transformation_global_plain($buffer, $options = array(), $meta = '')
{
return htmlspecialchars($buffer);
}
function PMA_transformation_global_html($buffer, $options = array(), $meta = '')
{
return $buffer;
}
function PMA_transformation_global_html_replace($buffer, $options = array(), $meta = '')
{
if (!isset($options['string'])) {
$options['string'] = '';
}
if (isset($options['regex']) && isset($options['regex_replace'])) {
$buffer = preg_replace('@' . str_replace('@', '\@', $options['regex']) . '@si', $options['regex_replace'], $buffer);
}
// Replace occurences of [__BUFFER__] with actual text
$return = str_replace("[__BUFFER__]", $buffer, $options['string']);
return $return;
}
?>

View File

@ -0,0 +1,31 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @package PhpMyAdmin-Transformation
*/
function PMA_transformation_image_jpeg__inline_info()
{
return array(
'info' => __('Displays a clickable thumbnail. The options are the maximum width and height in pixels. The original aspect ratio is preserved.'),
);
}
/**
*
*/
function PMA_transformation_image_jpeg__inline($buffer, $options = array(), $meta = '')
{
include_once './libraries/transformations/global.inc.php';
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

@ -0,0 +1,27 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @package PhpMyAdmin-Transformation
*/
function PMA_transformation_image_jpeg__link_info()
{
return array(
'info' => __('Displays a link to download this image.'),
);
}
/**
*
*/
function PMA_transformation_image_jpeg__link($buffer, $options = array(), $meta = '')
{
include_once './libraries/transformations/global.inc.php';
$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;
}
?>

View File

@ -0,0 +1,31 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @package PhpMyAdmin-Transformation
*/
function PMA_transformation_image_png__inline_info()
{
return array(
'info' => __('Displays a clickable thumbnail. The options are the maximum width and height in pixels. The original aspect ratio is preserved.'),
);
}
/**
*
*/
function PMA_transformation_image_png__inline($buffer, $options = array(), $meta = '')
{
include_once './libraries/transformations/global.inc.php';
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=png&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

@ -0,0 +1,24 @@
#!/bin/bash
#
# Shell script that adds a new mimetype with transform function.
#
# The filename should contain either 'mimetype_subtype' or 'mimetype'.
# The suffix '.inc.php' is appended automatically!
#
# The 'description' parameter will add a new entry in the language file. Watch out for
# special escaping.
#
# Example: template_generator.sh 'filename' 'description'
#
if [ $# == 0 ]
then
echo "Usage: template_generator.sh 'filename' 'description'"
echo ""
exit 65
fi
./generator.sh 'TEMPLATE' "$1" "$2"
echo " "
echo "New TRANSFORM FUNCTION $1.inc.php added."

View File

@ -0,0 +1,19 @@
#!/bin/bash
#
# Shell script that adds a new mimetype without transform function.
#
# The filename should contain either 'mimetype_subtype' or 'mimetype'.
# The suffix '.inc.php' is appended automatically!
#
# Example: template_generator_mimetype.sh 'filename'
#
if [ $# == 0 ]
then
echo "Usage: template_generator_mimetype.sh 'filename'"
echo ""
exit 65
fi
./generator.sh 'TEMPLATE_MIMETYPE' "$1"
echo " "
echo "New MIMETYPE $1.inc.php added."

View File

@ -0,0 +1,103 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @package PhpMyAdmin-Transformation
*/
function PMA_transformation_text_plain__dateformat_info()
{
return array(
'info' => __('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.'),
);
}
/**
*
*/
function PMA_transformation_text_plain__dateformat($buffer, $options = array(), $meta = '')
{
// possibly use a global transform and feed it with special options:
// include './libraries/transformations/global.inc.php';
// 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

@ -0,0 +1,105 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @package PhpMyAdmin-Transformation
*/
function PMA_transformation_text_plain__external_info()
{
return array(
'info' => __('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/transformations/text_plain__external.inc.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).'),
);
}
/**
*
*/
function PMA_transformation_text_plain__external_nowrap($options = array())
{
if (!isset($options[3]) || $options[3] == '') {
$nowrap = true;
} elseif ($options[3] == '1' || $options[3] == 1) {
$nowrap = true;
} else {
$nowrap = false;
}
return $nowrap;
}
function PMA_transformation_text_plain__external($buffer, $options = array(), $meta = '')
{
// possibly use a global transform and feed it with special options:
// include './libraries/transformations/global.inc.php';
// 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
$return_value = proc_close($process);
}
if ($options[2] == 1 || $options[2] == '2') {
$retstring = htmlspecialchars($newstring);
} else {
$retstring = $newstring;
}
return $retstring;
}
?>

View File

@ -0,0 +1,22 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @package PhpMyAdmin-Transformation
*/
function PMA_transformation_text_plain__formatted_info()
{
return array(
'info' => __('Displays the contents of the column as-is, without running it through htmlspecialchars(). That is, the column is assumed to contain valid HTML.'),
);
}
/**
*
*/
function PMA_transformation_text_plain__formatted($buffer, $options = array(), $meta = '')
{
return $buffer;
}
?>

View File

@ -0,0 +1,26 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @package PhpMyAdmin-Transformation
*/
function PMA_transformation_text_plain__imagelink_info()
{
return array(
'info' => __('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.'),
);
}
/**
*
*/
function PMA_transformation_text_plain__imagelink($buffer, $options = array(), $meta = '')
{
include_once './libraries/transformations/global.inc.php';
$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;
}
?>

View File

@ -0,0 +1,31 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @package PhpMyAdmin-Transformation
*/
function PMA_transformation_text_plain__link_info()
{
return array(
'info' => __('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.'),
);
}
/**
*
*/
function PMA_transformation_text_plain__link($buffer, $options = array(), $meta = '')
{
include_once './libraries/transformations/global.inc.php';
// $transform_options = array ('string' => '<a href="' . (isset($options[0]) ? $options[0] : '') . '%1$s" title="' . (isset($options[1]) ? $options[1] : '%1$s') . '">' . (isset($options[1]) ? $options[1] : '%1$s') . '</a>');
$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

@ -0,0 +1,28 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @package PhpMyAdmin-Transformation
*/
function PMA_transformation_text_plain__longToIpv4_info()
{
return array(
'info' => __('Converts an (IPv4) Internet network address into a string in Internet standard dotted format.'),
);
}
/**
* returns IPv4 address
*
* @see http://php.net/long2ip
*/
function PMA_transformation_text_plain__longToIpv4($buffer, $options = array(), $meta = '')
{
if ($buffer < 0 || $buffer > 4294967295) {
return $buffer;
}
return long2ip($buffer);
}
?>

View File

@ -0,0 +1,25 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @package PhpMyAdmin-Transformation
*/
function PMA_transformation_text_plain__sql_info()
{
return array(
'info' => __('Formats text as SQL query with syntax highlighting.'),
);
}
/**
*
*/
function PMA_transformation_text_plain__sql($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

@ -0,0 +1,57 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @package PhpMyAdmin-Transformation
*/
function PMA_transformation_text_plain__substr_info()
{
return array(
'info' => __('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: "...").'),
);
}
/**
*
*/
function PMA_transformation_text_plain__substr($buffer, $options = array(), $meta = '')
{
// possibly use a global transform and feed it with special options:
// include './libraries/transformations/global.inc.php';
// 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;
}
?>