ImageUploadTransformationsPlugin.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Abstract class for the image upload input transformations plugins
  5. *
  6. * @package PhpMyAdmin-Transformations
  7. * @subpackage ImageUpload
  8. */
  9. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  10. use PhpMyAdmin\Plugins\IOTransformationsPlugin;
  11. /**
  12. * Provides common methods for all of the image upload transformations plugins.
  13. *
  14. * @package PhpMyAdmin
  15. */
  16. abstract class ImageUploadTransformationsPlugin extends IOTransformationsPlugin
  17. {
  18. /**
  19. * Gets the transformation description of the specific plugin
  20. *
  21. * @return string
  22. */
  23. public static function getInfo()
  24. {
  25. return __(
  26. 'Image upload functionality which also displays a thumbnail.'
  27. . ' The options are the width and height of the thumbnail'
  28. . ' in pixels. Defaults to 100 X 100.'
  29. );
  30. }
  31. /**
  32. * Does the actual work of each specific transformations plugin.
  33. *
  34. * @param string $buffer text to be transformed
  35. * @param array $options transformation options
  36. * @param string $meta meta information
  37. *
  38. * @return string
  39. */
  40. public function applyTransformation($buffer, array $options = array(), $meta = '')
  41. {
  42. return $buffer;
  43. }
  44. /**
  45. * Returns the html for input field to override default textarea.
  46. * Note: Return empty string if default textarea is required.
  47. *
  48. * @param array $column column details
  49. * @param int $row_id row number
  50. * @param string $column_name_appendix the name attribute
  51. * @param array $options transformation options
  52. * @param string $value Current field value
  53. * @param string $text_dir text direction
  54. * @param int $tabindex tab index
  55. * @param int $tabindex_for_value offset for the values tabindex
  56. * @param int $idindex id index
  57. *
  58. * @return string the html for input field
  59. */
  60. public function getInputHtml(
  61. array $column,
  62. $row_id,
  63. $column_name_appendix,
  64. array $options,
  65. $value,
  66. $text_dir,
  67. $tabindex,
  68. $tabindex_for_value,
  69. $idindex
  70. ) {
  71. $html = '';
  72. $src = '';
  73. if (!empty($value)) {
  74. $html = '<input type="hidden" name="fields_prev' . $column_name_appendix
  75. . '" value="' . bin2hex($value) . '"/>';
  76. $html .= '<input type="hidden" name="fields' . $column_name_appendix
  77. . '" value="' . bin2hex($value) . '"/>';
  78. $src = 'transformation_wrapper.php' . $options['wrapper_link'];
  79. }
  80. $html .= '<img src="' . $src . '" width="'
  81. . (isset($options[0]) ? intval($options[0]) : '100') . '" height="'
  82. . (isset($options[1]) ? intval($options[1]) : '100') . '" alt="'
  83. . __('Image preview here') . '"/>';
  84. $html .= '<br/><input type="file" name="fields_upload'
  85. . $column_name_appendix . '" accept="image/*" class="image-upload"/>';
  86. return $html;
  87. }
  88. /**
  89. * Returns the array of scripts (filename) required for plugin
  90. * initialization and handling
  91. *
  92. * @return array javascripts to be included
  93. */
  94. public function getScripts()
  95. {
  96. return array(
  97. 'transformations/image_upload.js',
  98. );
  99. }
  100. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  101. /**
  102. * Gets the transformation name of the specific plugin
  103. *
  104. * @return string
  105. */
  106. public static function getName()
  107. {
  108. return "Image upload";
  109. }
  110. }