transformations.rst 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. .. _transformations:
  2. Transformations
  3. ===============
  4. .. _transformationsintro:
  5. Introduction
  6. ++++++++++++
  7. To enable transformations, you have to setup the ``column_info``
  8. table and the proper directives. Please see the :ref:`config` on how to do so.
  9. You can apply different transformations to the contents of each
  10. column. The transformation will take the content of each column and
  11. transform it with certain rules defined in the selected
  12. transformation.
  13. Say you have a column 'filename' which contains a filename. Normally
  14. you would see in phpMyAdmin only this filename. Using transformations
  15. you can transform that filename into a HTML link, so you can click
  16. inside of the phpMyAdmin structure on the column's link and will see
  17. the file displayed in a new browser window. Using transformation
  18. options you can also specify strings to append/prepend to a string or
  19. the format you want the output stored in.
  20. For a general overview of all available transformations and their
  21. options, you can consult your *<www.your-host.com>/<your-install-
  22. dir>/transformation\_overview.php* installation.
  23. For a tutorial on how to effectively use transformations, see our
  24. `Link section <http://www.phpmyadmin.net/home_page/docs.php>`_ on the
  25. official phpMyAdmin homepage.
  26. .. _transformationshowto:
  27. Usage
  28. +++++
  29. Go to your *tbl\_structure.php* page (i.e. reached through clicking on
  30. the 'Structure' link for a table). There click on "Change" (or change
  31. icon) and there you will see three new fields at the end of the line.
  32. They are called 'MIME-type', 'Browser transformation' and
  33. 'Transformation options'.
  34. * The field 'MIME-type' is a drop-down field. Select the MIME-type that
  35. corresponds to the column's contents. Please note that transformations
  36. are inactive as long as no MIME-type is selected.
  37. * The field 'Browser transformation' is a drop-down field. You can
  38. choose from a hopefully growing amount of pre-defined transformations.
  39. See below for information on how to build your own transformation.
  40. There are global transformations and mimetype-bound transformations.
  41. Global transformations can be used for any mimetype. They will take
  42. the mimetype, if necessary, into regard. Mimetype-bound
  43. transformations usually only operate on a certain mimetype. There are
  44. transformations which operate on the main mimetype (like 'image'),
  45. which will most likely take the subtype into regard, and those who
  46. only operate on a specific subtype (like 'image/jpeg'). You can use
  47. transformations on mimetypes for which the function was not defined
  48. for. There is no security check for you selected the right
  49. transformation, so take care of what the output will be like.
  50. * The field 'Transformation options' is a free-type textfield. You have
  51. to enter transform-function specific options here. Usually the
  52. transforms can operate with default options, but it is generally a
  53. good idea to look up the overview to see which options are necessary.
  54. Much like the ENUM/SET-Fields, you have to split up several options
  55. using the format 'a','b','c',...(NOTE THE MISSING BLANKS). This is
  56. because internally the options will be parsed as an array, leaving the
  57. first value the first element in the array, and so forth. If you want
  58. to specify a MIME character set you can define it in the
  59. transformation\_options. You have to put that outside of the pre-
  60. defined options of the specific mime-transform, as the last value of
  61. the set. Use the format "'; charset=XXX'". If you use a transform, for
  62. which you can specify 2 options and you want to append a character
  63. set, enter "'first parameter','second parameter','charset=us-ascii'".
  64. You can, however use the defaults for the parameters: "'','','charset
  65. =us-ascii'".
  66. .. _transformationsfiles:
  67. File structure
  68. ++++++++++++++
  69. All specific transformations for mimetypes are defined through class
  70. files in the directory 'libraries/plugins/transformations/'. Each of
  71. them extends a certain transformation abstract class declared in
  72. libraries/plugins/transformations/abstract.
  73. They are stored in files to ease up customization and easy adding of
  74. new transformations.
  75. Because the user cannot enter own mimetypes, it is kept sure that
  76. transformations always work. It makes no sense to apply a
  77. transformation to a mimetype the transform-function doesn't know to
  78. handle.
  79. There is a file called '*transformations.lib.php*' that provides some
  80. basic functions which can be included by any other transform function.
  81. The file name convention is ``[Mimetype]_[Subtype]_[Transformation
  82. Name].class.php``, while the abtract class that it extends has the
  83. name ``[Transformation Name]TransformationsPlugin``. All of the
  84. methods that have to be implemented by a transformations plug-in are:
  85. #. getMIMEType() and getMIMESubtype() in the main class;
  86. #. getName(), getInfo() and applyTransformation() in the abstract class
  87. it extends.
  88. The getMIMEType(), getMIMESubtype() and getName() methods return the
  89. name of the MIME type, MIME Subtype and transformation accordingly.
  90. getInfo() returns the transformation's description and possible
  91. options it may receive and applyTransformation() is the method that
  92. does the actual work of the transformation plug-in.
  93. Please see the libraries/plugins/transformations/TEMPLATE and
  94. libraries/plugins/transformations/TEMPLATE\_ABSTRACT files for adding
  95. your own transformation plug-in. You can also generate a new
  96. transformation plug-in (with or without the abstract transformation
  97. class), by using
  98. :file:`libraries/plugins/transformations/generator_plugin.sh` or
  99. :file:`libraries/plugins/transformations/generator_main_class.sh`.
  100. The applyTransformation() method always gets passed three variables:
  101. #. **$buffer** - Contains the text inside of the column. This is the
  102. text, you want to transform.
  103. #. **$options** - Contains any user-passed options to a transform
  104. function as an array.
  105. #. **$meta** - Contains an object with information about your column. The
  106. data is drawn from the output of the `mysql\_fetch\_field()
  107. <http://www.php.net/mysql_fetch_field>`_ function. This means, all
  108. object properties described on the `manual page
  109. <http://www.php.net/mysql_fetch_field>`_ are available in this
  110. variable and can be used to transform a column accordingly to
  111. unsigned/zerofill/not\_null/... properties. The $meta->mimetype
  112. variable contains the original MIME-type of the column (i.e.
  113. 'text/plain', 'image/jpeg' etc.)