transformations.rst.txt 6.5 KB

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