ImageUploadTransformationsPlugin.class.php 3.6 KB

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