Display MIME types to transform any table cell. You can only choose from a list of pre-defined MIME-types. The list gets built by a function searching a directory for valid transforms. For further information see README-file and soon documentation. ;)
This commit is contained in:
50
ChangeLog
50
ChangeLog
@@ -5,6 +5,56 @@ phpMyAdmin - Changelog
|
||||
$Id$
|
||||
$Source$
|
||||
|
||||
2003-02-24 Garvin Hicking <me@supergarv.de>
|
||||
Submitted multiple patches from the patch tracker:
|
||||
|
||||
* JS rowmarker now works in vertical display mode
|
||||
Files: libraries/functions.js, display_tbl.lib.php3
|
||||
|
||||
* Display nav_bar even when only one row is returned, to enable display in
|
||||
vertical/horizontal mode (especially for rotated headers)
|
||||
Files: libraries/display_tbl.lib.php3
|
||||
|
||||
* Measures basic query time [#571934]
|
||||
Files: sql.php3, display_tbl.lib.php3
|
||||
|
||||
* New display mode with 90 degree rotated table headers [#544361]. Works
|
||||
either as CSS or as 'faked' PHP-transformation.
|
||||
Files: libraries/common.lib.php3, libraries/display_tbl.lib.php3
|
||||
|
||||
* Update and display column comments in Add/Edit Fieldmode and CREATE table
|
||||
mode. Display comments in table structure (optional) with underlined
|
||||
CSS-mouseovers. Display comments in browser mode (optional), both in
|
||||
vertical and horizontal display mode. Keep column comments in synch, when
|
||||
DROPping/ALTERing and moving/copying tables.
|
||||
Files: tbl_addfield.php3, tbl_alter.php3, tbl_create.php3,
|
||||
tbl_properties.inc.php3, tbl_properties_structure.php3, db_details_links,
|
||||
tbl_relation.php3,tbl_move_copy.php3, tbl_properties_links.php3,
|
||||
tbl_rename.php3, sql.php3, db_details_structure.php3, db_details_links.php3,
|
||||
libraries/relation.lib.php3
|
||||
|
||||
* Display and enter DB/table comments for navigation, stored in pma comments table.
|
||||
May be displayed as Alias-Tooltips in left frame. [#650064]
|
||||
Files: db_details_structure.php3, left.php3, relation.lib.php3
|
||||
|
||||
* Display column comments in table/database dumps, as inline SQL-Comments
|
||||
Files: tbl_dump.php3, tbl_properties_export.php3, build_dump.lib.php3
|
||||
|
||||
* Display MIME types to transform any table cell. You can only choose from a
|
||||
list of pre-defined MIME-types. The list gets built by a function searching
|
||||
a directory for valid transforms. For further information see README-file and soon
|
||||
documentation. ;)
|
||||
Files: tbl_properties.inc.php3, transformations.lib.php3, relation.lib.php3,
|
||||
create_tables.sql, tbl_addfield.php3, tbl_alter.php3, tbl_create.php3,
|
||||
tbl_move_copy.php3, transformation_wrapper.php3,
|
||||
libraries/display_tbl.lib.php3, libraries/transformations/*
|
||||
TODO: Add predefined functions!
|
||||
|
||||
* IN PROGRESS: Display a (javascript) based query window as a new frame below the left
|
||||
frame with query history [#526008]
|
||||
Files: queryframe.php3, querywindow.php3, header.inc.php3,
|
||||
tbl_query_box.php3, common.lib.php3
|
||||
|
||||
2003-02-24 Olivier L. M<>ller <om@omnis.ch>
|
||||
* libraries/common.lib.php3: if $cfg['PmaAbsoluteUri'] is empty and
|
||||
port == 80 or port == 443, do not add ":80" or ":443" anymore to the
|
||||
|
@@ -527,6 +527,12 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
|
||||
$comments_map = array();
|
||||
}
|
||||
|
||||
if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfg']['BrowseMIME']) {
|
||||
require('./libraries/transformations.lib.php3');
|
||||
$GLOBALS['mime_map'] = PMA_getMIME($db, $table);
|
||||
}
|
||||
|
||||
|
||||
if ($is_display['sort_lnk'] == '1') {
|
||||
$is_join = eregi('(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN', $sql_query, $select_stt);
|
||||
} else {
|
||||
@@ -990,6 +996,40 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
|
||||
// available or not
|
||||
$pointer = (function_exists('is_null') ? $i : $meta->name);
|
||||
|
||||
// garvin: Wrap MIME-transformations. [MIME]
|
||||
$default_function = 'htmlspecialchars'; // default_function
|
||||
$transform_function = $default_function;
|
||||
$transform_options = array();
|
||||
|
||||
if ($GLOBALS['cfg']['BrowseMIME']) {
|
||||
|
||||
if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation'])) {
|
||||
// garvin: for security, never allow to break out from transformations directory
|
||||
$include_file = eregi_replace('^[\./]*(.*)', '\1', $GLOBALS['mime_map'][$meta->name]['transformation']);
|
||||
|
||||
$transformfunction_name = str_replace('.inc.php3', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
|
||||
|
||||
include('./libraries/transformations/' . $include_file);
|
||||
|
||||
if (defined('PMA_TRANSFORMATION_' . strtoupper($transformfunction_name)) && function_exists('PMA_transformation_' . $transformfunction_name)) {
|
||||
|
||||
$transform_function = 'PMA_transformation_' . $transformfunction_name;
|
||||
$transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$transform_options['wrapper_link'] = '?'
|
||||
. $url_query
|
||||
. '&primary_key=' . $uva_condition
|
||||
. '&sql_query=' . urlencode($sql_query)
|
||||
. '&goto=' . urlencode($lnk_goto)
|
||||
. '&transform_key=' . urlencode($meta->name);
|
||||
|
||||
|
||||
// n u m e r i c
|
||||
if ($meta->numeric == 1) {
|
||||
|
||||
@@ -1045,9 +1085,9 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
|
||||
. PMA_generate_common_url($db, $map[$meta->name][0])
|
||||
. '&pos=0&session_max_rows=' . $session_max_rows . '&dontlimitchars=' . $dontlimitchars
|
||||
. '&sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$pointer]) . '"' . $title . '>'
|
||||
. $row[$pointer] . '</a>';
|
||||
. ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options) : $transform_function($row[$pointer])) . '</a>';
|
||||
} else {
|
||||
$vertical_display['data'][$row_no][$i] .= $row[$pointer];
|
||||
$vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options) : $transform_function($row[$pointer]));
|
||||
}
|
||||
$vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
|
||||
} else {
|
||||
@@ -1062,28 +1102,36 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
|
||||
// even if $cfg['ShowBlob'] is false -> get the true type
|
||||
// of the fields.
|
||||
$field_flags = PMA_mysql_field_flags($dt_result, $i);
|
||||
|
||||
if (eregi('BINARY', $field_flags)) {
|
||||
$vertical_display['data'][$row_no][$i] = ' <td align="center" valign="top" bgcolor="' . $bgcolor . '">[BLOB';
|
||||
$blobtext = '[BLOB';
|
||||
if (isset($row[$pointer])) {
|
||||
$blob_size = PMA_formatByteDown(strlen($row[$pointer]), 3, 1);
|
||||
$vertical_display['data'][$row_no][$i] .= ' - '. $blob_size [0] . ' ' . $blob_size[1];
|
||||
$blobtext .= ' - '. $blob_size [0] . ' ' . $blob_size[1];
|
||||
unset($blob_size);
|
||||
}
|
||||
$vertical_display['data'][$row_no][$i] .= ']</td>' . "\n";
|
||||
|
||||
$blobtext .= ']';
|
||||
$blobtext = ($default_function != $transform_function ? $transform_function($blobtext, $transform_options) : $default_function($blobtext));
|
||||
|
||||
$vertical_display['data'][$row_no][$i] = ' <td align="center" valign="top" bgcolor="' . $bgcolor . '">' . $blobtext . '</td>';
|
||||
} else {
|
||||
//if (!isset($row[$meta->name])
|
||||
if (!isset($row[$pointer])
|
||||
|| (function_exists('is_null') && is_null($row[$pointer]))) {
|
||||
$vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
|
||||
} else if ($row[$pointer] != '') {
|
||||
// garvin: if a transform function for blob is set, none of these replacements will be made
|
||||
if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
|
||||
$row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
|
||||
}
|
||||
// loic1: displays all space characters, 4 space
|
||||
// characters for tabulations and <cr>/<lf>
|
||||
$row[$pointer] = htmlspecialchars($row[$pointer]);
|
||||
|
||||
$row[$pointer] = ($default_function != $transform_function ? $transform_function('BLOB', $transform_options) : $default_function($row[$pointer]));
|
||||
$row[$pointer] = str_replace("\011", ' ', str_replace(' ', ' ', $row[$pointer]));
|
||||
$row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]);
|
||||
|
||||
$vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '">' . $row[$pointer] . '</td>' . "\n";
|
||||
} else {
|
||||
$vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '"> </td>' . "\n";
|
||||
@@ -1112,15 +1160,16 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
|
||||
$row[$pointer] = str_replace("\x0a", '\n', $row[$pointer]);
|
||||
$row[$pointer] = str_replace("\x0d", '\r', $row[$pointer]);
|
||||
$row[$pointer] = str_replace("\x1a", '\Z', $row[$pointer]);
|
||||
$row[$pointer] = htmlspecialchars($row[$pointer]);
|
||||
$row[$pointer] = ($default_function != $transform_function ? $transform_function('BLOB', $transform_options) : $default_function($row[$pointer]));
|
||||
}
|
||||
// loic1: displays all space characters, 4 space
|
||||
// characters for tabulations and <cr>/<lf>
|
||||
else {
|
||||
$row[$pointer] = htmlspecialchars($row[$pointer]);
|
||||
$row[$pointer] = ($default_function != $transform_function ? $transform_function('BLOB', $transform_options) : $default_function($row[$pointer]));
|
||||
$row[$pointer] = str_replace("\011", ' ', str_replace(' ', ' ', $row[$pointer]));
|
||||
$row[$pointer] = ereg_replace("((\015\012)|(\015)|(\012))", '<br />', $row[$pointer]);
|
||||
}
|
||||
|
||||
// loic1: do not wrap if date field type
|
||||
$nowrap = (eregi('DATE|TIME', $meta->type) ? ' nowrap="nowrap"' : '');
|
||||
$vertical_display['data'][$row_no][$i] = ' <td valign="top" bgcolor="' . $bgcolor . '"' . $nowrap . '>';
|
||||
|
182
libraries/transformations.lib.php3
Normal file
182
libraries/transformations.lib.php3
Normal file
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
/**
|
||||
* Set of functions used with the relation and pdf feature
|
||||
*/
|
||||
|
||||
|
||||
if (!defined('PMA_TRANSFORMATION_LIB_INCLUDED')){
|
||||
define('PMA_TRANSFORMATION_LIB_INCLUDED', 1);
|
||||
|
||||
function PMA_transformation_getOptions($string) {
|
||||
$transform_options = array();
|
||||
|
||||
if ($string != '') {
|
||||
if (eregi('^\'.*\'$', $string)) {
|
||||
$transform_options = explode('\',\'', eregi_replace('^\'(.*)\'$', '\1', $string));
|
||||
} else {
|
||||
$transform_options = array(0 => $string);
|
||||
}
|
||||
}
|
||||
|
||||
return $transform_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all available MIME-types
|
||||
*
|
||||
* @return array array[mimetype], array[transformation]
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @author Garvin Hicking <me@supergarv.de>
|
||||
*/
|
||||
function PMA_getAvailableMIMEtypes() {
|
||||
$handle = opendir('./libraries/transformations');
|
||||
|
||||
$stack = array();
|
||||
$filestack = array();
|
||||
|
||||
while (($file = readdir($handle)) != false) {
|
||||
$filestack[$file] = $file;
|
||||
}
|
||||
|
||||
closedir($handle);
|
||||
|
||||
if (is_array($filestack)) {
|
||||
@ksort($filestack);
|
||||
@reset($filestack);
|
||||
while(list($key, $file) = each($filestack)) {
|
||||
|
||||
if (eregi('^.*__.*\.inc\.php3$', trim($file))) {
|
||||
// File contains transformation functions.
|
||||
$base = explode("__", str_replace(".inc.php3", "", $file));
|
||||
|
||||
$mimetype = str_replace("_", "/", $base[0]);
|
||||
$stack['mimetype'][$mimetype] = $mimetype;
|
||||
|
||||
$stack['transformation'][] = $mimetype . ': ' . $base[1];
|
||||
$stack['transformation_file'][] = $file;
|
||||
|
||||
} else if (eregi('^.*\.inc\.php3$', trim($file))) {
|
||||
// File is a plain mimetype, no functions.
|
||||
$base = str_replace(".inc.php3", "", $file);
|
||||
|
||||
if ($base != 'global') {
|
||||
$mimetype = str_replace("_", "/", $base);
|
||||
$stack['mimetype'][$mimetype] = $mimetype;
|
||||
$stack['empty_mimetype'][$mimetype] = $mimetype;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mimetypes for all rows of a table
|
||||
*
|
||||
* @param string the name of the db to check for
|
||||
* @param string the name of the table to check for
|
||||
* @param string whether to include only results having a mimetype set
|
||||
*
|
||||
* @return array [field_name][field_key] = field_value
|
||||
*
|
||||
* @global array the list of relations settings
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @author Mike Beck <mikebeck@users.sourceforge.net> / Garvin Hicking <me@supergarv.de>
|
||||
*/
|
||||
function PMA_getMIME($db, $table, $strict = false) {
|
||||
global $cfgRelation;
|
||||
|
||||
$com_qry = 'SELECT column_name, mimetype, transformation, transformation_options FROM ' . PMA_backquote($cfgRelation['column_comments'])
|
||||
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
|
||||
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
|
||||
. ' AND (mimetype != \'\'' . (!$strict ? ' OR transformation != \'\' OR transformation_options != \'\'' : '') . ')';
|
||||
$com_rs = PMA_query_as_cu($com_qry);
|
||||
|
||||
while ($row = @PMA_mysql_fetch_array($com_rs)) {
|
||||
$col = $row['column_name'];
|
||||
$mime[$col]['mimetype'] = $row['mimetype'];
|
||||
$mime[$col]['transformation'] = $row['transformation'];
|
||||
$mime[$col]['transformation_options'] = $row['transformation_options'];
|
||||
} // end while
|
||||
|
||||
if (isset($mime) && is_array($mime)) {
|
||||
return $mime;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
} // end of the 'PMA_getMIME()' function
|
||||
|
||||
/**
|
||||
* Set a single mimetype to a certain value.
|
||||
*
|
||||
* @param string the name of the db
|
||||
* @param string the name of the table
|
||||
* @param string the name of the column
|
||||
* @param string the mimetype of the column
|
||||
* @param string the transformation of the column
|
||||
* @param string the transformation options of the column
|
||||
* @param string (optional) force delete, will erase any existing comments for this column
|
||||
*
|
||||
* @return boolean true, if comment-query was made.
|
||||
*
|
||||
* @global array the list of relations settings
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_setMIME($db, $table, $key, $mimetype, $transformation, $transformation_options, $forcedelete = false) {
|
||||
global $cfgRelation;
|
||||
|
||||
$test_qry = 'SELECT mimetype, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_comments'])
|
||||
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
|
||||
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
|
||||
. ' AND column_name = \'' . PMA_handleSlashes($key) . '\'';
|
||||
$test_rs = PMA_query_as_cu($test_qry);
|
||||
|
||||
if ($test_rs && mysql_num_rows($test_rs) > 0) {
|
||||
$row = @PMA_mysql_fetch_array($test_rs);
|
||||
|
||||
if (!$forcedelete && (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0 || strlen($row['comment']) > 0)) {
|
||||
$upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_comments'])
|
||||
. ' SET mimetype = \'' . PMA_handleSlashes($mimetype) . '\','
|
||||
. ' transformation = \'' . PMA_handleSlashes($transformation) . '\','
|
||||
. ' transformation_options = \'' . PMA_handleSlashes($transformation_options) . '\''
|
||||
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
|
||||
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
|
||||
. ' AND column_name = \'' . PMA_handleSlashes($key) . '\'';
|
||||
} else {
|
||||
$upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_comments'])
|
||||
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
|
||||
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
|
||||
. ' AND column_name = \'' . PMA_handleSlashes($key) . '\'';
|
||||
}
|
||||
} else if (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0) {
|
||||
$upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments'])
|
||||
. ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) '
|
||||
. ' VALUES('
|
||||
. '\'' . PMA_sqlAddslashes($db) . '\','
|
||||
. '\'' . PMA_sqlAddslashes($table) . '\','
|
||||
. '\'' . PMA_handleSlashes($key) . '\','
|
||||
. '\'' . PMA_handleSlashes($mimetype) . '\','
|
||||
. '\'' . PMA_handleSlashes($transformation) . '\','
|
||||
. '\'' . PMA_handleSlashes($transformation_options) . '\')';
|
||||
}
|
||||
|
||||
if (isset($upd_query)){
|
||||
$upd_rs = PMA_query_as_cu($upd_query);
|
||||
unset($upd_query);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} // end of 'PMA_setMIME()' function
|
||||
} // $__PMA_TRANSFORMATION_LIB__
|
||||
?>
|
187
libraries/transformations/README
Normal file
187
libraries/transformations/README
Normal file
@@ -0,0 +1,187 @@
|
||||
TRANSFORMATION USAGE (Garvin Hicking, <me@supergarv.de>)
|
||||
====================
|
||||
|
||||
1. What are transformations?
|
||||
----------------------------
|
||||
|
||||
You can apply different transformations to the contents of each field. The transformation will take the content
|
||||
of each field and transform it with certain rules defined in the selected transformation.
|
||||
|
||||
Say you have a field 'filename' which contains a filename. Normale you would see in phpMyAdmin only this filename.
|
||||
Using transformations you can transform that filename into a html link, so you can click inside of the phpMyAdmin
|
||||
structure on the field's link and will see the file displayed in a new browser window. Using transformation
|
||||
options you can also specify strings to append/prepend to a string or the format you want the output stored in.
|
||||
|
||||
For a general overview of all available transformations and their options, you can consult your
|
||||
|
||||
http://<your phpMyAdmin installation>/libraries/transformations/overview.php
|
||||
|
||||
|
||||
2. How to use transformations
|
||||
-----------------------------
|
||||
|
||||
Go to your tbl_properties.inc.php3 page (like reached through clicking on the 'properties' link for a table).
|
||||
There you will see three new fields at the end of the line. They are called 'MIME-type', 'Browser transformation'
|
||||
and 'Transformation options'.
|
||||
|
||||
|
||||
* The field 'MIME-type' is a dropdown field. You have the options to leave that field empty or to use
|
||||
'auto' [this feature is not yet available]. Please note that transformations are inactive as long as no
|
||||
mimetype is selected.
|
||||
|
||||
|
||||
* The field 'Browser transformation' is a dropdown field. You can choose from a hopefully growing amount
|
||||
of pre-defined transformations. See below for information how to build your own transformation.
|
||||
|
||||
There are global transformations and mimetype-bound transformations. Global transformations can be used
|
||||
for any mimetype. They will take the mimetype, if neccessary, into regard. Mimetype-bound transformations
|
||||
usually only operate on a certain mimetype. There are transformations which operate on the main mimetype
|
||||
(like 'image'), which will most likely take the subtype into regard, and those who only operate on a
|
||||
specific subtype (like 'image/jpeg').
|
||||
|
||||
You can use transformations on mimetypes for which the function was not defined for. There is no security
|
||||
check for you selected the right transformation, so take care of what the output will be like.
|
||||
|
||||
* The field 'Transformation options' is a free-type textfield. You have to enter transform-function specific
|
||||
options here. Usually the transforms can operate with default options, but it is generally a good idea
|
||||
to look up the overview to see which options are neccessary.
|
||||
|
||||
Much like the ENUM/SET-Fields, you have to split up several options using the format 'a','b','c',...
|
||||
(NOTE THE MISSING BLANKS). This is because internally the options will be parsed as an array, leaving
|
||||
the first value the first element in the array, and so forth.
|
||||
|
||||
If you want to specify a MIME charset you can define it in the transformation_options. You have to
|
||||
put that outside of the pre-defined options of the specific mime-transform, as the last value of
|
||||
the set. Use the format "'; charset=XXX'". If you use a transform, for which you can specify 2
|
||||
options and you want to append a charset, enter "'first parameter','second parameter','charset=us-ascii'".
|
||||
You can, however use the defaults for the parameters: "'','','charset=us-ascii'".
|
||||
|
||||
3. Basic file structure
|
||||
------------------------
|
||||
|
||||
All mimetypes and their transformations are defined through single files in the directory
|
||||
'libraries/transformations/'.
|
||||
|
||||
They are stored in files to ease up customization and easy adding of new transformations.
|
||||
|
||||
Because the user cannot enter own mimetypes, it is kept sure that transformations always work. It makes
|
||||
no sense to apply a transformation to a mimetype, the transform-function doesn't know to handle.
|
||||
|
||||
One can, however, use empty mime-types and global transformations which should work for many mimetypes.
|
||||
You can also use transforms on a different mimetype they where built for, but pay attention to option
|
||||
usage as well as what the transformation does to your field.
|
||||
|
||||
All transformation functions are kept in the directory 'libraries/transformations'.
|
||||
|
||||
There is a basic file called 'global.inc.php3'. This function can be included by any other transform
|
||||
function and provides some basic functions.
|
||||
|
||||
There are X possible file names:
|
||||
|
||||
3.1
|
||||
A mimetype+subtype transform:
|
||||
|
||||
<mimetype>_<subtype>__<transform>.inc.php3
|
||||
|
||||
Please not that mimetype and subtype are seperated via '_', which shall not be contained in their names.
|
||||
The transform function/filename may contain only characters which cause no problems in the file system as well
|
||||
as the PHP function naming convention.
|
||||
|
||||
The transform function will the be called 'PMA_transform_<mimetype>_<subtype>__<transform>()'.
|
||||
|
||||
Example:
|
||||
|
||||
text_html__formatted.inc.php3
|
||||
PMA_transform_text_html__formatted()
|
||||
|
||||
3.2
|
||||
A mimetype (w/o subtype) transform:
|
||||
|
||||
<mimetype>__<transform>.inc.php3
|
||||
|
||||
Please note that there are no single '_' characters.
|
||||
The transform function/filename may contain only characters which cause no problems in the file system as well
|
||||
as the PHP function naming convention.
|
||||
|
||||
The transform function will the be called 'PMA_transform_<mimetype>__<transform>()'.
|
||||
|
||||
Example:
|
||||
|
||||
text__formatted.inc.php3
|
||||
PMA_transform_text__formatted()
|
||||
|
||||
3.3
|
||||
A mimetype+subtype without specific transform function
|
||||
|
||||
<mimetype>_<subtype>.inc.php3
|
||||
|
||||
Please note that there are no '__' characters in the filename. Do not use special characters in the filename
|
||||
causing problems with the file system.
|
||||
|
||||
No transformation function is defined in the file itself.
|
||||
|
||||
Example:
|
||||
|
||||
text_plain.inc.php3
|
||||
(No function)
|
||||
|
||||
3.4
|
||||
A mimetype (w/o subtype) without specific transform function
|
||||
|
||||
<mimetype>.inc.php3
|
||||
|
||||
Please note that there are no '_' characters in the filename. Do not use special characters in the filename
|
||||
causing problems with the file system.
|
||||
|
||||
No transformation function is defined in the file itself.
|
||||
|
||||
Example:
|
||||
|
||||
text.inc.php3
|
||||
(No function)
|
||||
|
||||
3.5
|
||||
A global transform function with no specific mimetype
|
||||
|
||||
global__<transform>.inc.php3
|
||||
|
||||
The transform function will the be called 'PMA_transform_global__<transform>()'.
|
||||
|
||||
Example:
|
||||
|
||||
global__formatted
|
||||
PMA_transform_global__formatted()
|
||||
|
||||
|
||||
So generally use '_' to split up mimetype and subtype, and '__' to provide a transform function.
|
||||
|
||||
All filenames containing no '__' in themselves are not shown as valid transform functions in the dropdown.
|
||||
|
||||
Please see the TEMPLATE file for adding your own transform function. See the TEMPLATE_MIMETYPE for adding
|
||||
a mimetype without a transform function. Also note the introduction of a function description in the language
|
||||
files. For each function a $strTransformation_<filename without .inc.php3> has to exist.
|
||||
|
||||
You can use the template generator (see 5) to generate new functions and entries in the language file.
|
||||
|
||||
|
||||
4. FAQ
|
||||
-------
|
||||
|
||||
4.1
|
||||
Q: I can't enter my own mimetype! WTF is this feature then useful for?
|
||||
|
||||
A: Slow down :). Defining mimetypes is of no use, if you can't put transformations on them.
|
||||
Otherwise you could just put a comment on the field. Because entering your own mimetype will
|
||||
cause serious syntax checking issues and validation, this introduces a high-risk false-user-input
|
||||
situation. Instead you have to initialize mimetypes using functions or empty mimetype definitions.
|
||||
|
||||
Plus, you have a whole overview of available mimetypes. Who knows all those mimetypes by heart so
|
||||
he/she can enter it at will?
|
||||
|
||||
|
||||
5. Template Generator
|
||||
----------------------
|
||||
|
||||
To create a new transform function please see template_generator.sh.
|
||||
|
||||
To create a new, empty mimetype please see template_generator_mimetype.sh.
|
26
libraries/transformations/TEMPLATE
Normal file
26
libraries/transformations/TEMPLATE
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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 substituded with the filename without the '.inc.php3'
|
||||
* extension. For further information regarding naming conventions see the README file.
|
||||
*/
|
||||
|
||||
if (!defined('PMA_TRANSFORMATION_[ENTER_FILENAME_HERE]')){
|
||||
define('PMA_TRANSFORMATION_[ENTER_FILENAME_HERE]', 1);
|
||||
|
||||
function PMA_transformation_[enter_filename_here]($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.
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
}
|
13
libraries/transformations/TEMPLATE_MIMETYPE
Normal file
13
libraries/transformations/TEMPLATE_MIMETYPE
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
// 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.
|
||||
*/
|
||||
|
||||
?>
|
34
libraries/transformations/generator.sh
Normal file
34
libraries/transformations/generator.sh
Normal file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
# $Id$
|
||||
#
|
||||
# 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:]`"
|
||||
|
||||
cat $1 | sed "s/\[ENTER_FILENAME_HERE\]/$functionupper/" | sed "s/\[enter_filename_here\]/$functionlower/" >> $2.inc.php3
|
||||
|
||||
if [ $3 ]
|
||||
then
|
||||
echo ""
|
||||
echo "DEBUG/TODO: Call"
|
||||
echo "../../lang/add_message.sh '\$strTransformation_${functionlower}' '$3'"
|
||||
echo "later!"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo "Created $2.inc.php3"
|
||||
echo ""
|
50
libraries/transformations/global.inc.php3
Normal file
50
libraries/transformations/global.inc.php3
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
/**
|
||||
* GLOBAL Plugin function (Garvin Hicking).
|
||||
* ---------------
|
||||
*
|
||||
* 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.php3
|
||||
*
|
||||
* The function name has to be the like above filename:
|
||||
*
|
||||
* -- function PMA_transformation_<mime_type>_<mime_subtype>__<transformation_name>.inc.php3
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
if (!defined('PMA_TRANSFORMATION_LIB_GLOBAL')){
|
||||
define('PMA_TRANSFORMATION_LIB_GLOBAL', 1);
|
||||
|
||||
function PMA_transformation_global_plain($buffer, $options = array()) {
|
||||
return htmlspecialchars($buffer);
|
||||
}
|
||||
|
||||
function PMA_transformation_global_html($buffer, $options = array()) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
function PMA_transformation_global_html_replace($buffer, $options = array()) {
|
||||
if (!isset($options['string'])) {
|
||||
$options['string'] = '';
|
||||
}
|
||||
|
||||
if (isset($options['regex']) && isset($options['regex_replace'])) {
|
||||
$buffer = eregi_replace($options['regex'], $options['regex_replace'], $buffer);
|
||||
}
|
||||
|
||||
// Replace occurences of [__BUFFER__] with actual text
|
||||
$return = str_replace("[__BUFFER__]", $buffer, $options['string']);
|
||||
return $return;
|
||||
}
|
||||
}
|
16
libraries/transformations/image_jpeg__inline.inc.php3
Normal file
16
libraries/transformations/image_jpeg__inline.inc.php3
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
if (!defined('PMA_TRANSFORMATION_IMAGE_JPEG__INLINE')){
|
||||
define('PMA_TRANSFORMATION_IMAGE_JPEG__INLINE', 1);
|
||||
|
||||
function PMA_transformation_image_jpeg__inline($buffer, $options = array()) {
|
||||
include('./libraries/transformations/global.inc.php3');
|
||||
|
||||
$transform_options = array ('string' => '<img src="transformation_wrapper.php3' . $options['wrapper_link'] . '" alt="[__BUFFER__]" width="320" height="240">');
|
||||
$buffer = PMA_transformation_global_html_replace($buffer, $transform_options);
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
}
|
16
libraries/transformations/image_jpeg__link.inc.php3
Normal file
16
libraries/transformations/image_jpeg__link.inc.php3
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
if (!defined('PMA_TRANSFORMATION_IMAGE_JPEG__LINK')){
|
||||
define('PMA_TRANSFORMATION_IMAGE_JPEG__LINK', 1);
|
||||
|
||||
function PMA_transformation_image_jpeg__link($buffer, $options = array()) {
|
||||
include('./libraries/transformations/global.inc.php3');
|
||||
|
||||
$transform_options = array ('string' => '<a href="transformation_wrapper.php3' . $options['wrapper_link'] . '" alt="[__BUFFER__]">[BLOB]</a>');
|
||||
$buffer = PMA_transformation_global_html_replace($buffer, $transform_options);
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
}
|
16
libraries/transformations/image_jpeg__plain.inc.php3
Normal file
16
libraries/transformations/image_jpeg__plain.inc.php3
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
if (!defined('PMA_TRANSFORMATION_IMAGE_JPEG__PLAIN')){
|
||||
define('PMA_TRANSFORMATION_IMAGE_JPEG__PLAIN', 1);
|
||||
|
||||
function PMA_transformation_image_jpeg__plain($buffer, $options = array()) {
|
||||
include('./libraries/transformations/global.inc.php3');
|
||||
|
||||
$transform_options = array ('string' => '<img src="' . (isset($options[0]) ? $options[0] : '') . '%s" border="0">');
|
||||
$buffer = PMA_transformation_global_html_replace($buffer, $transform_options);
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
}
|
82
libraries/transformations/overview.php3
Normal file
82
libraries/transformations/overview.php3
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
/**
|
||||
* Change to basedir for including/requiring other fields
|
||||
*/
|
||||
chdir('../../');
|
||||
|
||||
/**
|
||||
* Don't display the page heading
|
||||
*/
|
||||
define('PMA_DISPLAY_HEADING', 0);
|
||||
|
||||
/**
|
||||
* Gets some core libraries and displays a top message if required
|
||||
*/
|
||||
if (!defined('PMA_GRAB_GLOBALS_INCLUDED')) {
|
||||
include('./libraries/grab_globals.lib.php3');
|
||||
}
|
||||
if (!defined('PMA_COMMON_LIB_INCLUDED')) {
|
||||
include('./libraries/common.lib.php3');
|
||||
}
|
||||
|
||||
require('./header.inc.php3');
|
||||
|
||||
require('./libraries/relation.lib.php3');
|
||||
require('./libraries/transformations.lib.php3');
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
|
||||
$types = PMA_getAvailableMIMEtypes();
|
||||
?>
|
||||
|
||||
<h2><?php echo $strMIME_available_mime; ?></h2>
|
||||
<?php
|
||||
@reset($types);
|
||||
while(list($key, $mimetype) = each($types['mimetype'])) {
|
||||
|
||||
if (isset($types['empty_mimetype'][$mimetype])) {
|
||||
echo '<i>' . $mimetype . '</i><br />';
|
||||
} else {
|
||||
echo $mimetype . '<br />';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
<br />
|
||||
<i>(<?php echo $strMIME_without; ?>)</i>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<h2><?php echo $strMIME_available_transform; ?></h2>
|
||||
<table border="0" width="90%">
|
||||
<tr>
|
||||
<th><?php echo $strMIME_transformation; ?></th>
|
||||
<th><?php echo $strMIME_description; ?></th>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
@reset($types);
|
||||
$i = 0;
|
||||
while(list($key, $transform) = each($types['transformation'])) {
|
||||
$i++;
|
||||
$func = strtolower(str_replace('.inc.php3', '', $types['transformation_file'][$key]));
|
||||
$desc = 'strTransformation_' . $func;
|
||||
?>
|
||||
<tr bgcolor="<?php echo ($i % 2 ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']); ?>">
|
||||
<td><?php echo $transform; ?></td>
|
||||
<td><?php echo (isset($$desc) ? $$desc : '<font size="-1"><i>' . sprintf($strMIME_nodescription, 'PMA_transformation_' . $func . '()') . '</i></font>'); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Displays the footer
|
||||
*/
|
||||
echo "\n";
|
||||
require('./footer.inc.php3');
|
||||
?>
|
23
libraries/transformations/template_generator.sh
Normal file
23
libraries/transformations/template_generator.sh
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
# $Id$
|
||||
#
|
||||
# Shell script that adds a new mimetype with transform function.
|
||||
#
|
||||
# The filename should contain either 'mimetype_subtype' or 'mimetype'.
|
||||
# The suffix '.inc.php3' 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'
|
||||
echo " "
|
||||
echo "New TRANSFORM FUNCTION $1.inc.php3 added."
|
20
libraries/transformations/template_generator_mimetype.sh
Normal file
20
libraries/transformations/template_generator_mimetype.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
# $Id$
|
||||
#
|
||||
# Shell script that adds a new mimetype without transform function.
|
||||
#
|
||||
# The filename should contain either 'mimetype_subtype' or 'mimetype'.
|
||||
# The suffix '.inc.php3' 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.php3 added."
|
11
libraries/transformations/text_plain__formatted.inc.php3
Normal file
11
libraries/transformations/text_plain__formatted.inc.php3
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
if (!defined('PMA_TRANSFORMATION_TEXT_PLAIN__FORMATTED')){
|
||||
define('PMA_TRANSFORMATION_TEXT_PLAIN__FORMATTED', 1);
|
||||
|
||||
function PMA_transformation_text_plain__formatted($buffer, $options = array()) {
|
||||
return $buffer;
|
||||
}
|
||||
}
|
18
libraries/transformations/text_plain__link.inc.php3
Normal file
18
libraries/transformations/text_plain__link.inc.php3
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
if (!defined('PMA_TRANSFORMATION_TEXT_PLAIN__LINK')){
|
||||
define('PMA_TRANSFORMATION_TEXT_PLAIN__LINK', 1);
|
||||
|
||||
function PMA_transformation_text_plain__link($buffer, $options = array()) {
|
||||
include('./libraries/transformations/global.inc.php3');
|
||||
|
||||
$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>');
|
||||
$buffer = PMA_transformation_global_html_replace($buffer, $transform_options);
|
||||
|
||||
return $buffer;
|
||||
|
||||
return htmlspecialchars($buffer);
|
||||
}
|
||||
}
|
@@ -70,6 +70,10 @@ CREATE TABLE `PMA_column_comments` (
|
||||
table_name varchar(64) NOT NULL default '',
|
||||
column_name varchar(64) NOT NULL default '',
|
||||
`comment` varchar(255) NOT NULL default '',
|
||||
mimetype varchar(255) NOT NULL default '',
|
||||
transformation varchar(255) NOT NULL default '',
|
||||
transformation_options varchar(255) NOT NULL default '',
|
||||
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY db_name (db_name, table_name, column_name)
|
||||
) TYPE=MyISAM COMMENT='Comments for Columns';
|
||||
|
@@ -194,6 +194,7 @@ if (isset($submit)) {
|
||||
|
||||
// garvin: If comments were sent, enable relation stuff
|
||||
require('./libraries/relation.lib.php3');
|
||||
require('./libraries/transformations.lib.php3');
|
||||
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
|
||||
@@ -205,6 +206,29 @@ if (isset($submit)) {
|
||||
}
|
||||
}
|
||||
|
||||
// garvin: Update comment table for mime types [MIME]
|
||||
if (is_array($field_mimetype) && $cfgRelation['commwork'] && $cfg['BrowseMIME']) {
|
||||
@reset($field_mimetype);
|
||||
while(list($fieldindex, $mimetype) = each($field_mimetype)) {
|
||||
PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
|
||||
}
|
||||
}
|
||||
|
||||
// garvin: If comments were sent, enable relation stuff
|
||||
require('./libraries/relation.lib.php3');
|
||||
require('./libraries/transformations.lib.php3');
|
||||
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
|
||||
// garvin: Update comment table for mime types [MIME]
|
||||
if (is_array($field_mimetype) && $cfgRelation['commwork'] && $cfg['BrowseMIME']) {
|
||||
@reset($field_mimetype);
|
||||
while(list($fieldindex, $mimetype) = each($field_mimetype)) {
|
||||
PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Go back to the structure sub-page
|
||||
$sql_query = $sql_query_cpy;
|
||||
unset($sql_query_cpy);
|
||||
|
@@ -90,6 +90,7 @@ if (isset($submit)) {
|
||||
|
||||
// garvin: If comments were sent, enable relation stuff
|
||||
require('./libraries/relation.lib.php3');
|
||||
require('./libraries/transformations.lib.php3');
|
||||
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
|
||||
@@ -101,6 +102,14 @@ if (isset($submit)) {
|
||||
}
|
||||
}
|
||||
|
||||
// garvin: Update comment table for mime types [MIME]
|
||||
if (is_array($field_mimetype) && $cfgRelation['commwork'] && $cfg['BrowseMIME']) {
|
||||
@reset($field_mimetype);
|
||||
while(list($fieldindex, $mimetype) = each($field_mimetype)) {
|
||||
PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
|
||||
}
|
||||
}
|
||||
|
||||
include('./tbl_properties_structure.php3');
|
||||
exit();
|
||||
}
|
||||
|
@@ -195,6 +195,7 @@ if (isset($submit)) {
|
||||
|
||||
// garvin: If comments were sent, enable relation stuff
|
||||
require('./libraries/relation.lib.php3');
|
||||
require('./libraries/transformations.lib.php3');
|
||||
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
|
||||
@@ -206,6 +207,14 @@ if (isset($submit)) {
|
||||
}
|
||||
}
|
||||
|
||||
// garvin: Update comment table for mime types [MIME]
|
||||
if (is_array($field_mimetype) && $cfgRelation['commwork'] && $cfg['BrowseMIME']) {
|
||||
@reset($field_mimetype);
|
||||
while(list($fieldindex, $mimetype) = each($field_mimetype)) {
|
||||
PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
|
||||
}
|
||||
}
|
||||
|
||||
include('./' . $cfg['DefaultTabTable']);
|
||||
exit();
|
||||
} // end do create table
|
||||
|
@@ -50,6 +50,25 @@ if ($cfgRelation['commwork']) {
|
||||
echo '<th>' . $strComments . '</th>';
|
||||
}
|
||||
|
||||
$comments_map = array();
|
||||
$mime_map = array();
|
||||
$available_mime = array();
|
||||
|
||||
if ($cfgRelation['commwork']) {
|
||||
$comments_map = PMA_getComments($db, $table);
|
||||
echo '<th>' . $strComments . '</th>';
|
||||
|
||||
if ($cfg['BrowseMIME']) {
|
||||
$mime_map = PMA_getMIME($db, $table);
|
||||
$available_mime = PMA_getAvailableMIMEtypes();
|
||||
|
||||
echo '<th>' . $strMIME_MIMEtype . '</th>';
|
||||
echo '<th>' . $strMIME_transformation . '</th>';
|
||||
echo '<th>' . $strMIME_transformation_options . '***</th>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// lem9: We could remove this 'if' and let the key information be shown and
|
||||
// editable. However, for this to work, tbl_alter must be modified to use the
|
||||
// key fields, as tbl_addfield does.
|
||||
@@ -241,6 +260,47 @@ for ($i = 0 ; $i < $num_fields; $i++) {
|
||||
</td>
|
||||
<?php
|
||||
}
|
||||
|
||||
// garvin: MIME-types
|
||||
if ($cfg['BrowseMIME'] && $cfgRelation['commwork']) {
|
||||
?>
|
||||
<td bgcolor="<?php echo $bgcolor; ?>" valign="top">
|
||||
<select id="field_<?php echo $i; ?>_8" size="1" name="field_mimetype[]">
|
||||
<option value=""></option>
|
||||
<option value="auto">auto-detect</option>
|
||||
<?php
|
||||
if (is_array($available_mime['mimetype'])) {
|
||||
@reset($available_mime['mimetype']);
|
||||
while(list($mimekey, $mimetype) = each($available_mime['mimetype'])) {
|
||||
$checked = (isset($row) && isset($row['Field']) && isset($mime_map[$row['Field']]['mimetype']) && ($mime_map[$row['Field']]['mimetype'] == str_replace('/', '_', $mimetype)) ? 'selected ' : '');
|
||||
echo '<option value="' . str_replace('/', '_', $mimetype) . '" ' . $checked . '>' . htmlspecialchars($mimetype) . '</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
|
||||
<td bgcolor="<?php echo $bgcolor; ?>" valign="top">
|
||||
<select id="field_<?php echo $i; ?>_9" size="1" name="field_transformation[]">
|
||||
<option value=""></option>
|
||||
<?php
|
||||
if (is_array($available_mime['transformation'])) {
|
||||
@reset($available_mime['transformation']);
|
||||
while(list($mimekey, $transform) = each($available_mime['transformation'])) {
|
||||
$checked = (isset($row) && isset($row['Field']) && isset($mime_map[$row['Field']]['transformation']) && ($mime_map[$row['Field']]['transformation'] == $available_mime['transformation_file'][$mimekey]) ? 'selected ' : '');
|
||||
echo '<option value="' . $available_mime['transformation_file'][$mimekey] . '" ' . $checked . '>' . htmlspecialchars($transform) . '</option>' . "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
|
||||
<td bgcolor="<?php echo $bgcolor; ?>" valign="top">
|
||||
<input id="field_<?php echo $i; ?>_10" type="text" name="field_transformation_options[]" size="8" value="<?php echo (isset($row) && isset($row['Field']) && isset($mime_map[$row['Field']]['transformation_options']) ? htmlspecialchars($mime_map[$row['Field']]['transformation_options']) : ''); ?>" class="textfield" />
|
||||
</td>
|
||||
<?php
|
||||
}
|
||||
|
||||
// lem9: See my other comment about removing this 'if'.
|
||||
if (!$is_backup) {
|
||||
if (isset($row) && isset($row['Key']) && $row['Key'] == 'PRI') {
|
||||
@@ -407,6 +467,26 @@ echo "\n";
|
||||
<?php echo $strDefaultValueHelp . "\n"; ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
if ($cfgRelation['commwork'] && $cfg['BrowseMIME']) {
|
||||
?>
|
||||
<tr>
|
||||
<td valign="top" rowspan="2">*** </td>
|
||||
<td>
|
||||
<?php echo $strMIME_transformation_options_note . "\n"; ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<?php echo sprintf($strMIME_transformation_note, '<a href="libraries/transformations/overview.php3?' . PMA_generate_common_url($db, $table) . '" target="_new">', '</a>') . "\n"; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</table>
|
||||
<br />
|
||||
|
||||
|
@@ -73,6 +73,7 @@ $fields_cnt = mysql_num_rows($fields_rs);
|
||||
|
||||
<?php
|
||||
$comments_map = array();
|
||||
$mime_map = array();
|
||||
|
||||
if ($GLOBALS['cfg']['ShowPropertyComments']) {
|
||||
require('./libraries/relation.lib.php3');
|
||||
@@ -83,6 +84,10 @@ if ($GLOBALS['cfg']['ShowPropertyComments']) {
|
||||
|
||||
if ($cfgRelation['commwork']) {
|
||||
$comments_map = PMA_getComments($db, $table);
|
||||
|
||||
if ($cfg['BrowseMIME']) {
|
||||
$mime_map = PMA_getMIME($db, $table, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,6 +124,12 @@ while ($row = PMA_mysql_fetch_array($fields_rs)) {
|
||||
$unsigned = eregi('UNSIGNED', $row['Type'], $test);
|
||||
$zerofill = eregi('ZEROFILL', $row['Type'], $test);
|
||||
}
|
||||
|
||||
// garvin: Display basic mimetype [MIME]
|
||||
if ($cfg['BrowseMIME'] && isset($mime_map[$row['Field']]['mimetype'])) {
|
||||
$type .= '<br />MIME: ' . str_replace('_', '/', $mime_map[$row['Field']]['mimetype']);
|
||||
}
|
||||
|
||||
$strAttribute = ' ';
|
||||
if ($binary) {
|
||||
$strAttribute = 'BINARY';
|
||||
|
169
transformation_wrapper.php3
Normal file
169
transformation_wrapper.php3
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
/**
|
||||
* Get the variables sent or posted to this script and displays the header
|
||||
*/
|
||||
require('./libraries/grab_globals.lib.php3');
|
||||
|
||||
/**
|
||||
* Gets a core script and starts output buffering work
|
||||
*/
|
||||
if (!defined('PMA_COMMON_LIB_INCLUDED')) {
|
||||
include('./libraries/common.lib.php3');
|
||||
}
|
||||
if (!defined('PMA_OB_LIB_INCLUDED')) {
|
||||
include('./libraries/ob.lib.php3');
|
||||
}
|
||||
|
||||
require('./libraries/relation.lib.php3'); // foreign keys
|
||||
require('./libraries/transformations.lib.php3'); // Transformations
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
|
||||
|
||||
/**
|
||||
* Displays the query submitted and its result
|
||||
*/
|
||||
if (!empty($message)) {
|
||||
if (isset($goto)) {
|
||||
$goto_cpy = $goto;
|
||||
$goto = 'tbl_properties.php3?'
|
||||
. PMA_generate_common_url($db, $table)
|
||||
. '&$show_query=1'
|
||||
. '&sql_query=' . urlencode($disp_query);
|
||||
} else {
|
||||
$show_query = '1';
|
||||
}
|
||||
if (isset($sql_query)) {
|
||||
$sql_query_cpy = $sql_query;
|
||||
unset($sql_query);
|
||||
}
|
||||
if (isset($disp_query)) {
|
||||
$sql_query = (get_magic_quotes_gpc() ? stripslashes($disp_query) : $disp_query);
|
||||
}
|
||||
PMA_showMessage($message);
|
||||
if (isset($goto_cpy)) {
|
||||
$goto = $goto_cpy;
|
||||
unset($goto_cpy);
|
||||
}
|
||||
if (isset($sql_query_cpy)) {
|
||||
$sql_query = $sql_query_cpy;
|
||||
unset($sql_query_cpy);
|
||||
}
|
||||
}
|
||||
if (get_magic_quotes_gpc()) {
|
||||
if (!empty($sql_query)) {
|
||||
$sql_query = stripslashes($sql_query);
|
||||
}
|
||||
if (!empty($primary_key)) {
|
||||
$primary_key = stripslashes($primary_key);
|
||||
}
|
||||
} // end if
|
||||
|
||||
|
||||
/**
|
||||
* Defines the url to return to in case of error in a sql statement
|
||||
*/
|
||||
if (!isset($goto)) {
|
||||
$goto = 'db_details.php3';
|
||||
}
|
||||
if (!ereg('^(db_details|tbl_properties|tbl_select)', $goto)) {
|
||||
$err_url = $goto . "?" . PMA_generate_common_url($db) . "&sql_query=" . urlencode($sql_query);
|
||||
} else {
|
||||
$err_url = $goto . '?'
|
||||
. PMA_generate_common_url($db)
|
||||
. ((ereg('^(tbl_properties|tbl_select)', $goto)) ? '&table=' . urlencode($table) : '');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ensures db and table are valid, else moves to the "parent" script
|
||||
*/
|
||||
require('./libraries/db_table_exists.lib.php3');
|
||||
|
||||
|
||||
/**
|
||||
* Sets parameters for links and displays top menu
|
||||
*/
|
||||
$url_query = PMA_generate_common_url($db, $table)
|
||||
. '&goto=tbl_properties.php3';
|
||||
|
||||
/**
|
||||
* Get the list of the fields of the current table
|
||||
*/
|
||||
PMA_mysql_select_db($db);
|
||||
$table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table));
|
||||
if (isset($primary_key)) {
|
||||
$local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key;
|
||||
$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
|
||||
$row = PMA_mysql_fetch_array($result);
|
||||
// No row returned
|
||||
if (!$row) {
|
||||
unset($row);
|
||||
unset($primary_key);
|
||||
$goto_cpy = $goto;
|
||||
$goto = 'tbl_properties.php3?'
|
||||
. PMA_generate_common_url($db, $table)
|
||||
. '&$show_query=1'
|
||||
. '&sql_query=' . urlencode($local_query);
|
||||
if (isset($sql_query)) {
|
||||
$sql_query_cpy = $sql_query;
|
||||
unset($sql_query);
|
||||
}
|
||||
$sql_query = $local_query;
|
||||
PMA_showMessage($strEmptyResultSet);
|
||||
$goto = $goto_cpy;
|
||||
unset($goto_cpy);
|
||||
if (isset($sql_query_cpy)) {
|
||||
$sql_query = $sql_query_cpy;
|
||||
unset($sql_query_cpy);
|
||||
}
|
||||
} // end if (no record returned)
|
||||
}
|
||||
else
|
||||
{
|
||||
$local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1';
|
||||
$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
|
||||
unset($row);
|
||||
}
|
||||
|
||||
$default_ct = 'application/octet-stream';
|
||||
|
||||
if ($cfgRelation['commwork']) {
|
||||
$mime_map = PMA_getMime($db, $table);
|
||||
$mime_options = PMA_transformation_getOptions((isset($mime_map[urldecode($transform_key)]['transformation_options']) ? $mime_map[urldecode($transform_key)]['transformation_options'] : ''));
|
||||
|
||||
@reset($mime_options);
|
||||
while(list($key, $option) = each($mime_options)) {
|
||||
if (eregi('^; charset=.*$', $option)) {
|
||||
$mime_options['charset'] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends http headers
|
||||
*/
|
||||
// Don't use cache (required for Opera)
|
||||
$GLOBALS['now'] = gmdate('D, d M Y H:i:s') . ' GMT';
|
||||
header('Expires: ' . $GLOBALS['now']); // rfc2616 - Section 14.21
|
||||
header('Last-Modified: ' . $GLOBALS['now']);
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
|
||||
header('Pragma: no-cache'); // HTTP/1.0
|
||||
// [MIME]
|
||||
$content_type = 'Content-Type: ' . (isset($mime_map[urldecode($transform_key)]['mimetype']) ? str_replace("_", "/", $mime_map[urldecode($transform_key)]['mimetype']) : $default_ct) . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
|
||||
header($content_type);
|
||||
|
||||
echo $row[urldecode($transform_key)];
|
||||
|
||||
/**
|
||||
* Close MySql non-persistent connections
|
||||
*/
|
||||
if (isset($GLOBALS['dbh']) && $GLOBALS['dbh']) {
|
||||
@mysql_close($GLOBALS['dbh']);
|
||||
}
|
||||
if (isset($GLOBALS['userlink']) && $GLOBALS['userlink']) {
|
||||
@mysql_close($GLOBALS['userlink']);
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user