DownloadTransformationsPlugin.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Abstract class for the download transformations plugins
  5. *
  6. * @package PhpMyAdmin-Transformations
  7. * @subpackage Download
  8. */
  9. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  10. use PhpMyAdmin\Plugins\TransformationsPlugin;
  11. /**
  12. * Provides common methods for all of the download transformations plugins.
  13. *
  14. * @package PhpMyAdmin
  15. */
  16. abstract class DownloadTransformationsPlugin extends TransformationsPlugin
  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. 'Displays a link to download the binary data of the column. You can'
  27. . ' use the first option to specify the filename, or use the second'
  28. . ' option as the name of a column which contains the filename. If'
  29. . ' you use the second option, you need to set the first option to'
  30. . ' the empty string.'
  31. );
  32. }
  33. /**
  34. * Does the actual work of each specific transformations plugin.
  35. *
  36. * @param string $buffer text to be transformed
  37. * @param array $options transformation options
  38. * @param string $meta meta information
  39. *
  40. * @return string
  41. */
  42. public function applyTransformation($buffer, array $options = array(), $meta = '')
  43. {
  44. global $row, $fields_meta;
  45. if (isset($options[0]) && !empty($options[0])) {
  46. $cn = $options[0]; // filename
  47. } else {
  48. if (isset($options[1]) && !empty($options[1])) {
  49. foreach ($fields_meta as $key => $val) {
  50. if ($val->name == $options[1]) {
  51. $pos = $key;
  52. break;
  53. }
  54. }
  55. if (isset($pos)) {
  56. $cn = $row[$pos];
  57. }
  58. }
  59. if (empty($cn)) {
  60. $cn = 'binary_file.dat';
  61. }
  62. }
  63. return sprintf(
  64. '<a href="transformation_wrapper.php%s&amp;ct=application'
  65. . '/octet-stream&amp;cn=%s" title="%s" class="disableAjax">%s</a>',
  66. $options['wrapper_link'],
  67. htmlspecialchars(urlencode($cn)),
  68. htmlspecialchars($cn),
  69. htmlspecialchars($cn)
  70. );
  71. }
  72. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  73. /**
  74. * Gets the transformation name of the specific plugin
  75. *
  76. * @return string
  77. */
  78. public static function getName()
  79. {
  80. return "Download";
  81. }
  82. }