home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / text_plain__external.inc.php < prev    next >
Encoding:
PHP Script  |  2003-11-26  |  1.8 KB  |  64 lines

  1. <?php
  2. /* $Id: text_plain__external.inc.php,v 2.1 2003/11/26 22:52:24 rabus Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. function PMA_EscapeShellArg($string, $prepend = '\'') {
  6.     return $prepend . ereg_replace("'", "'\\''", $string) . $prepend;
  7. }
  8.  
  9. function PMA_transformation_text_plain__external_nowrap($options = array()) {
  10.     if (!isset($options[3]) || $options[3] == '') {
  11.         $nowrap = true;
  12.     } elseif ($options[3] == '1' || $options[3] == 1) {
  13.         $nowrap = true;
  14.     } else {
  15.         $nowrap = false;
  16.     }
  17.  
  18.     return $nowrap;
  19. }
  20.  
  21. function PMA_transformation_text_plain__external($buffer, $options = array(), $meta = '') {
  22.     // possibly use a global transform and feed it with special options:
  23.     // include('./libraries/transformations/global.inc.php');
  24.  
  25.     // further operations on $buffer using the $options[] array.
  26.  
  27.     $allowed_programs = array();
  28.     $allowed_programs[0] = '/usr/local/bin/tidy';
  29.     $allowed_programs[1] = '/usr/local/bin/validate';
  30.  
  31.     if (!isset($options[0]) ||  $options[0] == '') {
  32.         $program = $allowed_programs[0];
  33.     } else {
  34.         $program = $allowed_programs[$options[0]];
  35.     }
  36.  
  37.     if (!isset($options[1]) || $options[1] == '') {
  38.         $poptions = '-f /dev/null -i -wrap -q';
  39.     } else {
  40.         $poptions = $options[1];
  41.     }
  42.  
  43.     if (!isset($options[2]) || $options[2] == '') {
  44.         $options[2] = 1;
  45.     }
  46.  
  47.     if (!isset($options[3]) || $options[3] == '') {
  48.         $options[3] = 1;
  49.     }
  50.  
  51.     $cmdline = 'echo ' . PMA_EscapeShellArg($buffer) . ' | ' . $program . ' ' . PMA_EscapeShellArg($poptions, '');
  52.     $newstring = `$cmdline`;
  53.  
  54.     if ($options[2] == 1 || $options[2] == '2') {
  55.         $retstring = htmlspecialchars($newstring);
  56.     } else {
  57.         $retstring = $newstring;
  58.     }
  59.  
  60.     return $retstring;
  61. }
  62.  
  63. ?>
  64.