Convert transformation descriptions to gettext.
[phpmyadmin/blinky.git] / libraries / transformations / text_plain__external.inc.php
blob981faecff0b9450ecfc1d13d210d81d6417276b3
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @package phpMyAdmin-Transformation
5 * @version $Id$
6 */
8 function PMA_transformation_text_plain__external_info() {
9 return array(
10 'info' => __('LINUX ONLY: Launches an external application and feeds it the field 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()) {
18 if (!isset($options[3]) || $options[3] == '') {
19 $nowrap = true;
20 } elseif ($options[3] == '1' || $options[3] == 1) {
21 $nowrap = true;
22 } else {
23 $nowrap = false;
26 return $nowrap;
29 function PMA_transformation_text_plain__external($buffer, $options = array(), $meta = '') {
30 // possibly use a global transform and feed it with special options:
31 // include './libraries/transformations/global.inc.php';
33 // further operations on $buffer using the $options[] array.
35 $allowed_programs = array();
38 // WARNING:
40 // It's up to administrator to allow anything here. Note that users may
41 // specify any parameters, so when programs allow output redirection or
42 // any other possibly dangerous operations, you should write wrapper
43 // script that will publish only functions you really want.
45 // Add here program definitions like (note that these are NOT safe
46 // programs):
48 //$allowed_programs[0] = '/usr/local/bin/tidy';
49 //$allowed_programs[1] = '/usr/local/bin/validate';
51 // no-op when no allowed programs
52 if (count($allowed_programs) == 0) {
53 return $buffer;
56 if (!isset($options[0]) || $options[0] == '' || !isset($allowed_programs[$options[0]])) {
57 $program = $allowed_programs[0];
58 } else {
59 $program = $allowed_programs[$options[0]];
62 if (!isset($options[1]) || $options[1] == '') {
63 $poptions = '-f /dev/null -i -wrap -q';
64 } else {
65 $poptions = $options[1];
68 if (!isset($options[2]) || $options[2] == '') {
69 $options[2] = 1;
72 if (!isset($options[3]) || $options[3] == '') {
73 $options[3] = 1;
76 // needs PHP >= 4.3.0
77 $newstring = '';
78 $descriptorspec = array(
79 0 => array("pipe", "r"),
80 1 => array("pipe", "w")
82 $process = proc_open($program . ' ' . $poptions, $descriptorspec, $pipes);
83 if (is_resource($process)) {
84 fwrite($pipes[0], $buffer);
85 fclose($pipes[0]);
87 while (!feof($pipes[1])) {
88 $newstring .= fgets($pipes[1], 1024);
90 fclose($pipes[1]);
91 // we don't currently use the return value
92 $return_value = proc_close($process);
95 if ($options[2] == 1 || $options[2] == '2') {
96 $retstring = htmlspecialchars($newstring);
97 } else {
98 $retstring = $newstring;
101 return $retstring;