Rev Author Line No. Line
250 kaklik 1 <?php
2 /* $Id: text_plain__external.inc.php,v 2.8 2006/01/19 15:39:29 cybot_tm Exp $ */
3 // vim: expandtab sw=4 ts=4 sts=4:
4  
5 function PMA_transformation_text_plain__external_nowrap($options = array()) {
6 if (!isset($options[3]) || $options[3] == '') {
7 $nowrap = true;
8 } elseif ($options[3] == '1' || $options[3] == 1) {
9 $nowrap = true;
10 } else {
11 $nowrap = false;
12 }
13  
14 return $nowrap;
15 }
16  
17 function PMA_transformation_text_plain__external($buffer, $options = array(), $meta = '') {
18 // possibly use a global transform and feed it with special options:
19 // include('./libraries/transformations/global.inc.php');
20  
21 // further operations on $buffer using the $options[] array.
22  
23 $allowed_programs = array();
24  
25 //
26 // WARNING:
27 //
28 // It's up to administrator to allow anything here. Note that users may
29 // specify any parameters, so when programs allow output redirection or
30 // any other possibly dangerous operations, you should write wrapper
31 // script that will publish only functions you really want.
32 //
33 // Add here program definitions like (note that these are NOT safe
34 // programs):
35 //
36 //$allowed_programs[0] = '/usr/local/bin/tidy';
37 //$allowed_programs[1] = '/usr/local/bin/validate';
38  
39 // no-op when no allowed programs
40 if (count($allowed_programs) == 0) {
41 return $buffer;
42 }
43  
44 if (!isset($options[0]) || $options[0] == '' || !isset($allowed_programs[$options[0]])) {
45 $program = $allowed_programs[0];
46 } else {
47 $program = $allowed_programs[$options[0]];
48 }
49  
50 if (!isset($options[1]) || $options[1] == '') {
51 $poptions = '-f /dev/null -i -wrap -q';
52 } else {
53 $poptions = $options[1];
54 }
55  
56 if (!isset($options[2]) || $options[2] == '') {
57 $options[2] = 1;
58 }
59  
60 if (!isset($options[3]) || $options[3] == '') {
61 $options[3] = 1;
62 }
63  
64 // needs PHP >= 4.3.0
65 $newstring = '';
66 $descriptorspec = array(
67  
68 1 => array("pipe", "w")
69 );
70 $process = proc_open($program . ' ' . $poptions, $descriptorspec, $pipes);
71 if (is_resource($process)) {
72 fwrite($pipes[0], $buffer);
73 fclose($pipes[0]);
74  
75 while (!feof($pipes[1])) {
76 $newstring .= fgets($pipes[1], 1024);
77 }
78 fclose($pipes[1]);
79 // we don't currently use the return value
80 $return_value = proc_close($process);
81 }
82  
83 if ($options[2] == 1 || $options[2] == '2') {
84 $retstring = htmlspecialchars($newstring);
85 } else {
86 $retstring = $newstring;
87 }
88  
89 return $retstring;
90 }
91 ?>