Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / plugins / transformations / abstract / ExternalTransformationsPlugin.class.php
blobf93f0695a2f2e1394fb76570891398cfad399d90
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Abstract class for the external transformations plugins
6 * @package PhpMyAdmin-Transformations
7 * @subpackage External
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /* Get the transformations interface */
14 require_once 'libraries/plugins/TransformationsPlugin.class.php';
16 /**
17 * Provides common methods for all of the external transformations plugins.
19 * @package PhpMyAdmin
21 abstract class ExternalTransformationsPlugin extends TransformationsPlugin
23 /**
24 * Gets the transformation description of the specific plugin
26 * @return string
28 public static function getInfo()
30 return __(
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).'
46 /**
47 * Enables no-wrapping
49 * @param array $options transformation options
51 * @return bool
53 public function applyTransformationNoWrap($options = array())
55 if (! isset($options[3]) || $options[3] == '') {
56 $nowrap = true;
57 } elseif ($options[3] == '1' || $options[3] == 1) {
58 $nowrap = true;
59 } else {
60 $nowrap = false;
63 return $nowrap;
66 /**
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
73 * @return void
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();
84 // WARNING:
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
92 // programs):
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) {
99 return $buffer;
102 if (! isset($options[0])
103 || $options[0] == ''
104 || ! isset($allowed_programs[$options[0]])
106 $program = $allowed_programs[0];
107 } else {
108 $program = $allowed_programs[$options[0]];
111 if (!isset($options[1]) || $options[1] == '') {
112 $poptions = '-f /dev/null -i -wrap -q';
113 } else {
114 $poptions = $options[1];
117 if (!isset($options[2]) || $options[2] == '') {
118 $options[2] = 1;
121 if (!isset($options[3]) || $options[3] == '') {
122 $options[3] = 1;
125 // needs PHP >= 4.3.0
126 $newstring = '';
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);
134 fclose($pipes[0]);
136 while (!feof($pipes[1])) {
137 $newstring .= fgets($pipes[1], 1024);
139 fclose($pipes[1]);
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);
146 } else {
147 $retstring = $newstring;
150 return $retstring;
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
158 * of an update.
160 * @todo implement
161 * @return void
163 public function update (SplSubject $subject)
169 /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
173 * Gets the transformation name of the specific plugin
175 * @return string
177 public static function getName()
179 return "External";