New transform functions.

This commit is contained in:
Garvin Hicking
2003-03-18 15:30:25 +00:00
parent 9d1647d364
commit 606369c3f6
6 changed files with 208 additions and 6 deletions

View File

@@ -5,6 +5,18 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2003-03-18 Garvin Hicking <me@supergarv.de>
* libraries/display_export.lib.php3: Fixed variable usage.
* lang/*, libraries/transformations/*, libraries/display_tbl.lib.php3,
libraries/common.lib.php3: Added new transforms for a substr()
function, a dateformat() modified and a basic plugin for external
programs. Support for TIDY has been experimentally been built in.
External programs make use of piping and thus cannot be used in
Windows.
Added the ability for transforms to adjust the "nowrap" option of a
cell.
Some german translation.
2003-03-18 Marc Delisle <lem9@users.sourceforge.net> 2003-03-18 Marc Delisle <lem9@users.sourceforge.net>
* libraries/select_lang.lib.php3: modify order of Russian lang files * libraries/select_lang.lib.php3: modify order of Russian lang files
because MSIE does not accept cp866 and users do not see anything, because MSIE does not accept cp866 and users do not see anything,

View File

@@ -1628,15 +1628,19 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold}
* *
* @access public * @access public
*/ */
function PMA_localisedDate($timestamp = -1) function PMA_localisedDate($timestamp = -1, $format = '')
{ {
global $datefmt, $month, $day_of_week; global $datefmt, $month, $day_of_week;
if ($format == '') {
$format = $datefmt;
}
if ($timestamp == -1) { if ($timestamp == -1) {
$timestamp = time(); $timestamp = time();
} }
$date = ereg_replace('%[aA]', $day_of_week[(int)strftime('%w', $timestamp)], $datefmt); $date = ereg_replace('%[aA]', $day_of_week[(int)strftime('%w', $timestamp)], $format);
$date = ereg_replace('%[bB]', $month[(int)strftime('%m', $timestamp)-1], $date); $date = ereg_replace('%[bB]', $month[(int)strftime('%m', $timestamp)-1], $date);
return strftime($date, $timestamp); return strftime($date, $timestamp);

View File

@@ -1123,7 +1123,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
|| (function_exists('is_null') && is_null($row[$pointer]))) { || (function_exists('is_null') && is_null($row[$pointer]))) {
$vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n"; $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
} else if ($row[$pointer] != '') { } else if ($row[$pointer] != '') {
$vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">'; $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '" nowrap="nowrap">';
reset($analyzed_sql[0]['select_expr']); reset($analyzed_sql[0]['select_expr']);
while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) { while (list ($select_expr_position, $select_expr) = each ($analyzed_sql[0]['select_expr'])) {
@@ -1166,7 +1166,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
} }
$vertical_display['data'][$row_no][$i] .= '</td>' . "\n"; $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
} else { } else {
$vertical_display['data'][$row_no][$i] = ' <td align="right" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n"; $vertical_display['data'][$row_no][$i] = ' <td align="right" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '" nowrap="nowrap">&nbsp;</td>' . "\n";
} }
// b l o b // b l o b
@@ -1202,7 +1202,6 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
} }
// loic1: displays all space characters, 4 space // loic1: displays all space characters, 4 space
// characters for tabulations and <cr>/<lf> // characters for tabulations and <cr>/<lf>
$row[$pointer] = ($default_function != $transform_function ? $transform_function($row[$pointer], $transform_options) : $default_function($row[$pointer])); $row[$pointer] = ($default_function != $transform_function ? $transform_function($row[$pointer], $transform_options) : $default_function($row[$pointer]));
$row[$pointer] = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $row[$pointer])); $row[$pointer] = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $row[$pointer]));
$row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]); $row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]);
@@ -1245,8 +1244,12 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
$row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]); $row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]);
} }
// garvin: transform functions may enable nowrapping:
$function_nowrap = $transform_function . '_nowrap';
$bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
// loic1: do not wrap if date field type // loic1: do not wrap if date field type
$nowrap = (eregi('DATE|TIME', $meta->type) ? ' nowrap="nowrap"' : ''); $nowrap = ((eregi('DATE|TIME', $meta->type) || $bool_nowrap) ? ' nowrap="nowrap"' : '');
$vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"' . $nowrap . '>'; $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"' . $nowrap . '>';
reset($analyzed_sql[0]['select_expr']); reset($analyzed_sql[0]['select_expr']);

View File

@@ -0,0 +1,52 @@
<?php
/* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Plugin function TEMPLATE (Garvin Hicking).
* -----------------------------------------
*
* For instructions, read the libraries/transformations/README file.
*
* The string ENTER_FILENAME_HERE shall be substituted with the filename without the '.inc.php3'
* extension. For further information regarding naming conventions see the README file.
*/
if (!defined('PMA_TRANSFORMATION_TEXT_PLAIN__DATEFORMAT')){
define('PMA_TRANSFORMATION_TEXT_PLAIN__DATEFORMAT', 1);
function PMA_transformation_text_plain__dateformat($buffer, $options = array()) {
// possibly use a global transform and feed it with special options:
// include('./libraries/transformations/global.inc.php3');
// 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] = $GLOBALS['datefmt'];
}
$timestamp = -1;
if (strstr($buffer, ':')) {
$timestamp = strtotime($buffer);
} elseif (strlen($buffer) == 14 && eregi('^[0-9]*$', $buffer)) {
$d = array();
$d['year'] = substr($buffer, 0, 4);
$d['month'] = substr($buffer, 4, 2);
$d['day'] = substr($buffer, 6, 2);
$d['hour'] = substr($buffer, 8, 2);
$d['minute'] = substr($buffer, 10, 2);
$d['second'] = substr($buffer, 12, 2);
$timestamp = mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year']);
}
if ($timestamp != -1) {
$timestamp -= $options[0] * 60 * 60;
$buffer = PMA_localisedDate($timestamp, $options[1]);
}
return $buffer;
}
}

View File

@@ -0,0 +1,75 @@
<?php
/* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Plugin function TEMPLATE (Garvin Hicking).
* -----------------------------------------
*
* For instructions, read the libraries/transformations/README file.
*
* The string ENTER_FILENAME_HERE shall be substituted with the filename without the '.inc.php3'
* extension. For further information regarding naming conventions see the README file.
*/
if (!defined('PMA_TRANSFORMATION_TEXT_PLAIN__EXTERNAL')){
define('PMA_TRANSFORMATION_TEXT_PLAIN__EXTERNAL', 1);
function PMA_EscapeShellArg($string, $prepend = '\'') {
return $prepend . ereg_replace("'", "'\\''", $string) . $prepend;
}
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()) {
// possibly use a global transform and feed it with special options:
// include('./libraries/transformations/global.inc.php3');
// further operations on $buffer using the $options[] array.
$allowed_programs = array();
$allowed_programs[0] = '/usr/local/bin/tidy';
$allowed_programs[1] = '/usr/local/bin/validate';
if (!isset($options[0]) || $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;
}
$cmdline = 'echo ' . PMA_EscapeShellArg($buffer) . ' | ' . $program . ' ' . PMA_EscapeShellArg($poptions, '');
$newstring = `$cmdline`;
if ($options[2] == 1 || $options[2] == '2') {
$retstring = htmlspecialchars($newstring);
} else {
$retstring = $newstring;
}
return $retstring;
}
}

View File

@@ -0,0 +1,56 @@
<?php
/* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Plugin function TEMPLATE (Garvin Hicking).
* -----------------------------------------
*
* For instructions, read the libraries/transformations/README file.
*
* The string ENTER_FILENAME_HERE shall be substituted with the filename without the '.inc.php3'
* extension. For further information regarding naming conventions see the README file.
*/
if (!defined('PMA_TRANSFORMATION_TEXT_PLAIN__SUBSTR')){
define('PMA_TRANSFORMATION_TEXT_PLAIN__SUBSTR', 1);
function PMA_transformation_text_plain__substr($buffer, $options = array()) {
// possibly use a global transform and feed it with special options:
// include('./libraries/transformations/global.inc.php3');
// 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 = substr($buffer, $options[0], $options[1]);
} else {
$newtext = 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;
}
}