DownloadTransformationsPlugin.class.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. if (! defined('PHPMYADMIN')) {
  10. exit;
  11. }
  12. /* Get the transformations interface */
  13. require_once 'libraries/plugins/TransformationsPlugin.class.php';
  14. /**
  15. * Provides common methods for all of the download transformations plugins.
  16. *
  17. * @package PhpMyAdmin
  18. */
  19. abstract class DownloadTransformationsPlugin extends TransformationsPlugin
  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. 'Displays a link to download the binary data of the column. You can'
  30. . ' use the first option to specify the filename, or use the second'
  31. . ' option as the name of a column which contains the filename. If'
  32. . ' you use the second option, you need to set the first option to'
  33. . ' the empty string.'
  34. );
  35. }
  36. /**
  37. * Does the actual work of each specific transformations plugin.
  38. *
  39. * @param string $buffer text to be transformed
  40. * @param array $options transformation options
  41. * @param string $meta meta information
  42. *
  43. * @return void
  44. */
  45. public function applyTransformation($buffer, $options = array(), $meta = '')
  46. {
  47. global $row, $fields_meta;
  48. if (isset($options[0]) && !empty($options[0])) {
  49. $cn = $options[0]; // filename
  50. } else {
  51. if (isset($options[1]) && !empty($options[1])) {
  52. foreach ($fields_meta as $key => $val) {
  53. if ($val->name == $options[1]) {
  54. $pos = $key;
  55. break;
  56. }
  57. }
  58. if (isset($pos)) {
  59. $cn = $row[$pos];
  60. }
  61. }
  62. if (empty($cn)) {
  63. $cn = 'binary_file.dat';
  64. }
  65. }
  66. return sprintf(
  67. '<a href="transformation_wrapper.php%s&amp;ct=application'
  68. . '/octet-stream&amp;cn=%s" title="%s">%s</a>',
  69. $options['wrapper_link'],
  70. htmlspecialchars(urlencode($cn)),
  71. htmlspecialchars($cn),
  72. htmlspecialchars($cn)
  73. );
  74. }
  75. /**
  76. * This method is called when any PluginManager to which the observer
  77. * is attached calls PluginManager::notify()
  78. *
  79. * @param SplSubject $subject The PluginManager notifying the observer
  80. * of an update.
  81. *
  82. * @todo implement
  83. * @return void
  84. */
  85. public function update (SplSubject $subject)
  86. {
  87. ;
  88. }
  89. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  90. /**
  91. * Gets the transformation name of the specific plugin
  92. *
  93. * @return string
  94. */
  95. public static function getName()
  96. {
  97. return "Download";
  98. }
  99. }
  100. ?>