Add OK and Cancel button for grid editing
[phpmyadmin/arisferyanto.git] / libraries / transformations / text_plain__external.inc.php
blobeb71ef2efaeb34370adcb3d9f5767af1b44b77c6
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @package PhpMyAdmin-Transformation
5 */
7 function PMA_transformation_text_plain__external_info()
9 return array(
10 'info' => __('LINUX ONLY: Launches an external application and feeds it the column data via standard input. Returns the standard output of the application. The default is Tidy, to pretty-print HTML code. For security reasons, you have to manually edit the file libraries/transformations/text_plain__external.inc.php and list the tools you want to make available. The first option is then the number of the program you want to use and the second option is the parameters for the program. The third option, if set to 1, will convert the output using htmlspecialchars() (Default 1). The fourth option, if set to 1, will prevent wrapping and ensure that the output appears all on one line (Default 1).'),
14 /**
17 function PMA_transformation_text_plain__external_nowrap($options = array())
19 if (!isset($options[3]) || $options[3] == '') {
20 $nowrap = true;
21 } elseif ($options[3] == '1' || $options[3] == 1) {
22 $nowrap = true;
23 } else {
24 $nowrap = false;
27 return $nowrap;
30 function PMA_transformation_text_plain__external($buffer, $options = array(), $meta = '')
32 // possibly use a global transform and feed it with special options:
33 // include './libraries/transformations/global.inc.php';
35 // further operations on $buffer using the $options[] array.
37 $allowed_programs = array();
40 // WARNING:
42 // It's up to administrator to allow anything here. Note that users may
43 // specify any parameters, so when programs allow output redirection or
44 // any other possibly dangerous operations, you should write wrapper
45 // script that will publish only functions you really want.
47 // Add here program definitions like (note that these are NOT safe
48 // programs):
50 //$allowed_programs[0] = '/usr/local/bin/tidy';
51 //$allowed_programs[1] = '/usr/local/bin/validate';
53 // no-op when no allowed programs
54 if (count($allowed_programs) == 0) {
55 return $buffer;
58 if (!isset($options[0]) || $options[0] == '' || !isset($allowed_programs[$options[0]])) {
59 $program = $allowed_programs[0];
60 } else {
61 $program = $allowed_programs[$options[0]];
64 if (!isset($options[1]) || $options[1] == '') {
65 $poptions = '-f /dev/null -i -wrap -q';
66 } else {
67 $poptions = $options[1];
70 if (!isset($options[2]) || $options[2] == '') {
71 $options[2] = 1;
74 if (!isset($options[3]) || $options[3] == '') {
75 $options[3] = 1;
78 // needs PHP >= 4.3.0
79 $newstring = '';
80 $descriptorspec = array(
81 0 => array("pipe", "r"),
82 1 => array("pipe", "w")
84 $process = proc_open($program . ' ' . $poptions, $descriptorspec, $pipes);
85 if (is_resource($process)) {
86 fwrite($pipes[0], $buffer);
87 fclose($pipes[0]);
89 while (!feof($pipes[1])) {
90 $newstring .= fgets($pipes[1], 1024);
92 fclose($pipes[1]);
93 // we don't currently use the return value
94 $return_value = proc_close($process);
97 if ($options[2] == 1 || $options[2] == '2') {
98 $retstring = htmlspecialchars($newstring);
99 } else {
100 $retstring = $newstring;
103 return $retstring;