transformations.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <title>Transformations &#8212; phpMyAdmin 5.1.1 documentation</title>
  8. <link rel="stylesheet" href="_static/classic.css" type="text/css" />
  9. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  10. <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
  11. <script type="text/javascript" src="_static/jquery.js"></script>
  12. <script type="text/javascript" src="_static/underscore.js"></script>
  13. <script type="text/javascript" src="_static/doctools.js"></script>
  14. <script type="text/javascript" src="_static/language_data.js"></script>
  15. <link rel="index" title="Index" href="genindex.html" />
  16. <link rel="search" title="Search" href="search.html" />
  17. <link rel="copyright" title="Copyright" href="copyright.html" />
  18. <link rel="next" title="Bookmarks" href="bookmarks.html" />
  19. <link rel="prev" title="Two-factor authentication" href="two_factor.html" />
  20. </head><body>
  21. <div class="related" role="navigation" aria-label="related navigation">
  22. <h3>Navigation</h3>
  23. <ul>
  24. <li class="right" style="margin-right: 10px">
  25. <a href="genindex.html" title="General Index"
  26. accesskey="I">index</a></li>
  27. <li class="right" >
  28. <a href="bookmarks.html" title="Bookmarks"
  29. accesskey="N">next</a> |</li>
  30. <li class="right" >
  31. <a href="two_factor.html" title="Two-factor authentication"
  32. accesskey="P">previous</a> |</li>
  33. <li class="nav-item nav-item-0"><a href="index.html">phpMyAdmin 5.1.1 documentation</a> &#187;</li>
  34. <li class="nav-item nav-item-1"><a href="user.html" accesskey="U">User Guide</a> &#187;</li>
  35. </ul>
  36. </div>
  37. <div class="document">
  38. <div class="documentwrapper">
  39. <div class="bodywrapper">
  40. <div class="body" role="main">
  41. <div class="section" id="transformations">
  42. <span id="id1"></span><h1>Transformations<a class="headerlink" href="#transformations" title="Permalink to this headline">¶</a></h1>
  43. <div class="admonition note">
  44. <p class="first admonition-title">Note</p>
  45. <p class="last">You need to have configured the <a class="reference internal" href="setup.html#linked-tables"><span class="std std-ref">phpMyAdmin configuration storage</span></a> to use the transformations
  46. feature.</p>
  47. </div>
  48. <div class="section" id="introduction">
  49. <span id="transformationsintro"></span><h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
  50. <p>To enable transformations, you have to set up the <code class="docutils literal notranslate"><span class="pre">column_info</span></code>
  51. table and the proper directives. Please see the <a class="reference internal" href="config.html#config"><span class="std std-ref">Configuration</span></a> on how to do so.</p>
  52. <p>phpMyAdmin has two different types of transformations: browser display
  53. transformations, which affect only how the data is shown when browsing
  54. through phpMyAdmin; and input transformations, which affect a value
  55. prior to being inserted through phpMyAdmin.
  56. You can apply different transformations to the contents of each
  57. column. Each transformation has options to define how it will affect the
  58. stored data.</p>
  59. <p>Say you have a column <code class="docutils literal notranslate"><span class="pre">filename</span></code> which contains a filename. Normally
  60. you would see in phpMyAdmin only this filename. Using display transformations
  61. you can transform that filename into a HTML link, so you can click
  62. inside of the phpMyAdmin structure on the column’s link and will see
  63. the file displayed in a new browser window. Using transformation
  64. options you can also specify strings to append/prepend to a string or
  65. the format you want the output stored in.</p>
  66. <p>For a general overview of all available transformations and their
  67. options, you can either go to the <code class="docutils literal notranslate"><span class="pre">Change</span></code> link for an existing column
  68. or from the dialog to create a new column, in either case there is a link
  69. on that column structure page for “Browser display transformation” and
  70. “Input transformation” which will show more information about each
  71. transformation that is available on your system.</p>
  72. <p>For a tutorial on how to effectively use transformations, see our
  73. <a class="reference external" href="https://www.phpmyadmin.net/docs/">Link section</a> on the
  74. official phpMyAdmin homepage.</p>
  75. </div>
  76. <div class="section" id="usage">
  77. <span id="transformationshowto"></span><h2>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
  78. <p>Go to the table structure page (reached by clicking on
  79. the ‘Structure’ link for a table). There click on “Change” (or the change
  80. icon) and there you will see the five transformation–related fields at the end of the line.
  81. They are called ‘<a class="reference internal" href="glossary.html#term-media-type"><span class="xref std std-term">Media type</span></a>’, ‘Browser transformation’ and
  82. ‘Transformation options’.</p>
  83. <ul class="simple">
  84. <li>The field ‘<a class="reference internal" href="glossary.html#term-media-type"><span class="xref std std-term">Media type</span></a>’ is a drop-down field. Select the <a class="reference internal" href="glossary.html#term-media-type"><span class="xref std std-term">Media type</span></a> that
  85. corresponds to the column’s contents. Please note that many transformations
  86. are inactive until a <a class="reference internal" href="glossary.html#term-media-type"><span class="xref std std-term">Media type</span></a> is selected.</li>
  87. <li>The field ‘Browser display transformation’ is a drop-down field. You can
  88. choose from a hopefully growing amount of pre-defined transformations.
  89. See below for information on how to build your own transformation.
  90. There are global transformations and mimetype-bound transformations.
  91. Global transformations can be used for any mimetype. They will take
  92. the mimetype, if necessary, into regard. Mimetype-bound
  93. transformations usually only operate on a certain mimetype. There are
  94. transformations which operate on the main mimetype (like ‘image’),
  95. which will most likely take the subtype into regard, and those who
  96. only operate on a specific subtype (like ‘image/jpeg’). You can use
  97. transformations on mimetypes for which the function was not defined
  98. for. There is no security check for you selected the right
  99. transformation, so take care of what the output will be like.</li>
  100. <li>The field ‘Browser display transformation options’ is a free-type textfield. You have
  101. to enter transform-function specific options here. Usually the
  102. transforms can operate with default options, but it is generally a
  103. good idea to look up the overview to see which options are necessary.
  104. Much like the ENUM/SET-Fields, you have to split up several options
  105. using the format ‘a’,’b’,’c’,…(NOTE THE MISSING BLANKS). This is
  106. because internally the options will be parsed as an array, leaving the
  107. first value the first element in the array, and so forth. If you want
  108. to specify a MIME character set you can define it in the
  109. transformation_options. You have to put that outside of the pre-
  110. defined options of the specific mime-transform, as the last value of
  111. the set. Use the format “’; charset=XXX’”. If you use a transform, for
  112. which you can specify 2 options and you want to append a character
  113. set, enter “‘first parameter’,’second parameter’,’charset=us-ascii’”.
  114. You can, however use the defaults for the parameters: “’‘,’‘,’charset
  115. =us-ascii’”. The default options can be configured using
  116. <span class="target" id="index-0"></span><a class="reference internal" href="config.html#cfg_DefaultTransformations"><code class="xref config config-option docutils literal notranslate"><span class="pre">$cfg['DefaultTransformations']</span></code></a>.</li>
  117. <li>‘Input transformation’ is another drop-down menu that corresponds exactly
  118. with the instructions above for “Browser display transformation” except
  119. these these affect the data before insertion in to the database. These are
  120. most commonly used to either provide a specialized editor (for example, using
  121. the phpMyAdmin SQL editor interface) or selector (such as for uploading an image).
  122. It’s also possible to manipulate the data such as converting an IPv4 address to binary
  123. or parsing it through a regular expression.</li>
  124. <li>Finally, ‘Input transformation options’ is the equivalent of the “Browser display
  125. transformation options” section above and is where optional and required parameters are entered.</li>
  126. </ul>
  127. </div>
  128. <div class="section" id="file-structure">
  129. <span id="transformationsfiles"></span><h2>File structure<a class="headerlink" href="#file-structure" title="Permalink to this headline">¶</a></h2>
  130. <p>All specific transformations for mimetypes are defined through class
  131. files in the directory <code class="file docutils literal notranslate"><span class="pre">libraries/classes/Plugins/Transformations/</span></code>. Each of
  132. them extends a certain transformation abstract class declared in
  133. <code class="file docutils literal notranslate"><span class="pre">libraries/classes/Plugins/Transformations/Abs</span></code>.</p>
  134. <p>They are stored in files to ease customization and to allow easy adding of
  135. new or custom transformations.</p>
  136. <p>Because the user cannot enter their own mimetypes, it is kept certain that
  137. the transformations will always work. It makes no sense to apply a
  138. transformation to a mimetype the transform-function doesn’t know to
  139. handle.</p>
  140. <p>There is a file called <code class="file docutils literal notranslate"><span class="pre">libraries/classes/Plugins/Transformations.php</span></code> that provides some
  141. basic functions which can be included by any other transform function.</p>
  142. <p>The file name convention is <code class="docutils literal notranslate"><span class="pre">[Mimetype]_[Subtype]_[Transformation</span>
  143. <span class="pre">Name].php</span></code>, while the abstract class that it extends has the
  144. name <code class="docutils literal notranslate"><span class="pre">[Transformation</span> <span class="pre">Name]TransformationsPlugin</span></code>. All of the
  145. methods that have to be implemented by a transformations plug-in are:</p>
  146. <ol class="arabic simple">
  147. <li>getMIMEType() and getMIMESubtype() in the main class;</li>
  148. <li>getName(), getInfo() and applyTransformation() in the abstract class
  149. it extends.</li>
  150. </ol>
  151. <p>The getMIMEType(), getMIMESubtype() and getName() methods return the
  152. name of the MIME type, MIME Subtype and transformation accordingly.
  153. getInfo() returns the transformation’s description and possible
  154. options it may receive and applyTransformation() is the method that
  155. does the actual work of the transformation plug-in.</p>
  156. <p>Please see the <code class="file docutils literal notranslate"><span class="pre">libraries/classes/Plugins/Transformations/TEMPLATE</span></code> and
  157. <code class="file docutils literal notranslate"><span class="pre">libraries/classes/Plugins/Transformations/TEMPLATE_ABSTRACT</span></code> files for adding
  158. your own transformation plug-in. You can also generate a new
  159. transformation plug-in (with or without the abstract transformation
  160. class), by using
  161. <code class="file docutils literal notranslate"><span class="pre">scripts/transformations_generator_plugin.sh</span></code> or
  162. <code class="file docutils literal notranslate"><span class="pre">scripts/transformations_generator_main_class.sh</span></code>.</p>
  163. <p>The applyTransformation() method always gets passed three variables:</p>
  164. <ol class="arabic simple">
  165. <li><strong>$buffer</strong> - Contains the text inside of the column. This is the
  166. text, you want to transform.</li>
  167. <li><strong>$options</strong> - Contains any user-passed options to a transform
  168. function as an array.</li>
  169. <li><strong>$meta</strong> - Contains an object with information about your column. The
  170. data is drawn from the output of the <a class="reference external" href="https://www.php.net/mysql_fetch_field">mysql_fetch_field()</a> function. This means, all
  171. object properties described on the <a class="reference external" href="https://www.php.net/mysql_fetch_field">manual page</a> are available in this
  172. variable and can be used to transform a column accordingly to
  173. unsigned/zerofill/not_null/… properties. The $meta-&gt;mimetype
  174. variable contains the original <a class="reference internal" href="glossary.html#term-media-type"><span class="xref std std-term">Media type</span></a> of the column (i.e.
  175. ‘text/plain’, ‘image/jpeg’ etc.)</li>
  176. </ol>
  177. </div>
  178. </div>
  179. </div>
  180. </div>
  181. </div>
  182. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  183. <div class="sphinxsidebarwrapper">
  184. <h3><a href="index.html">Table of Contents</a></h3>
  185. <ul>
  186. <li><a class="reference internal" href="#">Transformations</a><ul>
  187. <li><a class="reference internal" href="#introduction">Introduction</a></li>
  188. <li><a class="reference internal" href="#usage">Usage</a></li>
  189. <li><a class="reference internal" href="#file-structure">File structure</a></li>
  190. </ul>
  191. </li>
  192. </ul>
  193. <h4>Previous topic</h4>
  194. <p class="topless"><a href="two_factor.html"
  195. title="previous chapter">Two-factor authentication</a></p>
  196. <h4>Next topic</h4>
  197. <p class="topless"><a href="bookmarks.html"
  198. title="next chapter">Bookmarks</a></p>
  199. <div role="note" aria-label="source link">
  200. <h3>This Page</h3>
  201. <ul class="this-page-menu">
  202. <li><a href="_sources/transformations.rst.txt"
  203. rel="nofollow">Show Source</a></li>
  204. </ul>
  205. </div>
  206. <div id="searchbox" style="display: none" role="search">
  207. <h3>Quick search</h3>
  208. <div class="searchformwrapper">
  209. <form class="search" action="search.html" method="get">
  210. <input type="text" name="q" />
  211. <input type="submit" value="Go" />
  212. <input type="hidden" name="check_keywords" value="yes" />
  213. <input type="hidden" name="area" value="default" />
  214. </form>
  215. </div>
  216. </div>
  217. <script type="text/javascript">$('#searchbox').show(0);</script>
  218. </div>
  219. </div>
  220. <div class="clearer"></div>
  221. </div>
  222. <div class="related" role="navigation" aria-label="related navigation">
  223. <h3>Navigation</h3>
  224. <ul>
  225. <li class="right" style="margin-right: 10px">
  226. <a href="genindex.html" title="General Index"
  227. >index</a></li>
  228. <li class="right" >
  229. <a href="bookmarks.html" title="Bookmarks"
  230. >next</a> |</li>
  231. <li class="right" >
  232. <a href="two_factor.html" title="Two-factor authentication"
  233. >previous</a> |</li>
  234. <li class="nav-item nav-item-0"><a href="index.html">phpMyAdmin 5.1.1 documentation</a> &#187;</li>
  235. <li class="nav-item nav-item-1"><a href="user.html" >User Guide</a> &#187;</li>
  236. </ul>
  237. </div>
  238. <div class="footer" role="contentinfo">
  239. &#169; <a href="copyright.html">Copyright</a> 2012 - 2021, The phpMyAdmin devel team.
  240. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.4.
  241. </div>
  242. </body>
  243. </html>