display message when search returns zero rows
[phpmyadmin/dkf.git] / libraries / transformations / text_plain__external.inc.php
blob2ed3cdd13124d31d509fcdf8d0687f2bdf6f7d37
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() {
8 return array(
9 '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).'),
13 /**
16 function PMA_transformation_text_plain__external_nowrap($options = array()) {
17 if (!isset($options[3]) || $options[3] == '') {
18 $nowrap = true;
19 } elseif ($options[3] == '1' || $options[3] == 1) {
20 $nowrap = true;
21 } else {
22 $nowrap = false;
25 return $nowrap;
28 function PMA_transformation_text_plain__external($buffer, $options = array(), $meta = '') {
29 // possibly use a global transform and feed it with special options:
30 // include './libraries/transformations/global.inc.php';
32 // further operations on $buffer using the $options[] array.
34 $allowed_programs = array();
37 // WARNING:
39 // It's up to administrator to allow anything here. Note that users may
40 // specify any parameters, so when programs allow output redirection or
41 // any other possibly dangerous operations, you should write wrapper
42 // script that will publish only functions you really want.
44 // Add here program definitions like (note that these are NOT safe
45 // programs):
47 //$allowed_programs[0] = '/usr/local/bin/tidy';
48 //$allowed_programs[1] = '/usr/local/bin/validate';
50 // no-op when no allowed programs
51 if (count($allowed_programs) == 0) {
52 return $buffer;
55 if (!isset($options[0]) || $options[0] == '' || !isset($allowed_programs[$options[0]])) {
56 $program = $allowed_programs[0];
57 } else {
58 $program = $allowed_programs[$options[0]];
61 if (!isset($options[1]) || $options[1] == '') {
62 $poptions = '-f /dev/null -i -wrap -q';
63 } else {
64 $poptions = $options[1];
67 if (!isset($options[2]) || $options[2] == '') {
68 $options[2] = 1;
71 if (!isset($options[3]) || $options[3] == '') {
72 $options[3] = 1;
75 // needs PHP >= 4.3.0
76 $newstring = '';
77 $descriptorspec = array(
78 0 => array("pipe", "r"),
79 1 => array("pipe", "w")
81 $process = proc_open($program . ' ' . $poptions, $descriptorspec, $pipes);
82 if (is_resource($process)) {
83 fwrite($pipes[0], $buffer);
84 fclose($pipes[0]);
86 while (!feof($pipes[1])) {
87 $newstring .= fgets($pipes[1], 1024);
89 fclose($pipes[1]);
90 // we don't currently use the return value
91 $return_value = proc_close($process);
94 if ($options[2] == 1 || $options[2] == '2') {
95 $retstring = htmlspecialchars($newstring);
96 } else {
97 $retstring = $newstring;
100 return $retstring;