home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / transformations / text_plain__external.inc.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  2.6 KB  |  98 lines

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