2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Abstract class for the external transformations plugins
6 * @package PhpMyAdmin-Transformations
9 if (! defined('PHPMYADMIN')) {
13 /* Get the transformations interface */
14 require_once 'libraries/plugins/TransformationsPlugin.class.php';
17 * Provides common methods for all of the external transformations plugins.
21 abstract class ExternalTransformationsPlugin
extends TransformationsPlugin
24 * Gets the transformation description of the specific plugin
28 public static function getInfo()
31 'LINUX ONLY: Launches an external application and feeds it the column'
32 . ' data via standard input. Returns the standard output of the'
33 . ' application. The default is Tidy, to pretty-print HTML code.'
34 . ' For security reasons, you have to manually edit the file'
35 . ' libraries/plugins/transformations/Text_Plain_External'
36 . '.class.php and list the tools you want to make available.'
37 . ' The first option is then the number of the program you want to'
38 . ' use and the second option is the parameters for the program.'
39 . ' The third option, if set to 1, will convert the output using'
40 . ' htmlspecialchars() (Default 1). The fourth option, if set to 1,'
41 . ' will prevent wrapping and ensure that the output appears all on'
42 . ' one line (Default 1).'
49 * @param array $options transformation options
53 public function applyTransformationNoWrap($options = array())
55 if (! isset($options[3]) ||
$options[3] == '') {
57 } elseif ($options[3] == '1' ||
$options[3] == 1) {
67 * Does the actual work of each specific transformations plugin.
69 * @param string $buffer text to be transformed
70 * @param array $options transformation options
71 * @param string $meta meta information
75 public function applyTransformation($buffer, $options = array(), $meta = '')
77 // possibly use a global transform and feed it with special options
79 // further operations on $buffer using the $options[] array.
81 $allowed_programs = array();
86 // It's up to administrator to allow anything here. Note that users may
87 // specify any parameters, so when programs allow output redirection or
88 // any other possibly dangerous operations, you should write wrapper
89 // script that will publish only functions you really want.
91 // Add here program definitions like (note that these are NOT safe
94 //$allowed_programs[0] = '/usr/local/bin/tidy';
95 //$allowed_programs[1] = '/usr/local/bin/validate';
97 // no-op when no allowed programs
98 if (count($allowed_programs) == 0) {
102 if (! isset($options[0])
104 ||
! isset($allowed_programs[$options[0]])
106 $program = $allowed_programs[0];
108 $program = $allowed_programs[$options[0]];
111 if (!isset($options[1]) ||
$options[1] == '') {
112 $poptions = '-f /dev/null -i -wrap -q';
114 $poptions = $options[1];
117 if (!isset($options[2]) ||
$options[2] == '') {
121 if (!isset($options[3]) ||
$options[3] == '') {
125 // needs PHP >= 4.3.0
127 $descriptorspec = array(
128 0 => array("pipe", "r"),
129 1 => array("pipe", "w")
131 $process = proc_open($program . ' ' . $poptions, $descriptorspec, $pipes);
132 if (is_resource($process)) {
133 fwrite($pipes[0], $buffer);
136 while (!feof($pipes[1])) {
137 $newstring .= fgets($pipes[1], 1024);
140 // we don't currently use the return value
141 proc_close($process);
144 if ($options[2] == 1 ||
$options[2] == '2') {
145 $retstring = htmlspecialchars($newstring);
147 $retstring = $newstring;
154 * This method is called when any PluginManager to which the observer
155 * is attached calls PluginManager::notify()
157 * @param SplSubject $subject The PluginManager notifying the observer
163 public function update (SplSubject
$subject)
169 /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
173 * Gets the transformation name of the specific plugin
177 public static function getName()