Text_Plain_Json.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Text Plain JSON Transformations plugin for phpMyAdmin
  5. *
  6. * @package PhpMyAdmin-Transformations
  7. * @subpackage SQL
  8. */
  9. namespace PhpMyAdmin\Plugins\Transformations\Output;
  10. use PhpMyAdmin\Plugins\TransformationsPlugin;
  11. use PhpMyAdmin\Response;
  12. /**
  13. * Handles the json transformation for text plain
  14. *
  15. * @package PhpMyAdmin-Transformations
  16. * @subpackage JSON
  17. */
  18. // @codingStandardsIgnoreLine
  19. class Text_Plain_Json extends TransformationsPlugin
  20. {
  21. /**
  22. * No-arg constructor
  23. */
  24. public function __construct()
  25. {
  26. if (!empty($GLOBALS['cfg']['CodemirrorEnable'])) {
  27. $response = Response::getInstance();
  28. $scripts = $response->getHeader()
  29. ->getScripts();
  30. $scripts->addFile('vendor/codemirror/lib/codemirror.js');
  31. $scripts->addFile('vendor/codemirror/mode/javascript/javascript.js');
  32. $scripts->addFile('vendor/codemirror/addon/runmode/runmode.js');
  33. $scripts->addFile('transformations/json.js');
  34. }
  35. }
  36. /**
  37. * Gets the transformation description of the specific plugin
  38. *
  39. * @return string
  40. */
  41. public static function getInfo()
  42. {
  43. return __(
  44. 'Formats text as JSON with syntax highlighting.'
  45. );
  46. }
  47. /**
  48. * Does the actual work of each specific transformations plugin.
  49. *
  50. * @param string $buffer text to be transformed
  51. * @param array $options transformation options
  52. * @param string $meta meta information
  53. *
  54. * @return string
  55. */
  56. public function applyTransformation($buffer, array $options = array(), $meta = '')
  57. {
  58. return '<code class="json"><pre>' . "\n"
  59. . htmlspecialchars($buffer) . "\n"
  60. . '</pre></code>';
  61. }
  62. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  63. /**
  64. * Gets the plugin`s MIME type
  65. *
  66. * @return string
  67. */
  68. public static function getMIMEType()
  69. {
  70. return "Text";
  71. }
  72. /**
  73. * Gets the plugin`s MIME subtype
  74. *
  75. * @return string
  76. */
  77. public static function getMIMESubtype()
  78. {
  79. return "Plain";
  80. }
  81. /**
  82. * Gets the transformation name of the specific plugin
  83. *
  84. * @return string
  85. */
  86. public static function getName()
  87. {
  88. return "JSON";
  89. }
  90. }