Ignore:
Timestamp:
11/17/09 09:02:41 (15 years ago)
Author:
amuller
Message:

Ticket #597 - melhoria no modulo gerenciador de arquivos

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/filemanager/tp/dompdf/dompdf.php

    r1575 r1654  
    3333 * dompdf.php is a simple script to drive DOMPDF.  It can be executed from 
    3434 * a browser or from the command line. 
    35  *  
     35 * 
    3636 * @link http://www.digitaljunkies.ca/dompdf 
    3737 * @copyright 2004 Benj Carson 
     
    4141 */ 
    4242 
    43 /* $Id: dompdf.php,v 1.17 2006/07/07 21:31:02 benjcarson Exp $ */ 
     43/* $Id: dompdf.php 186 2009-10-19 22:42:06Z eclecticgeek@gmail.com $ */ 
    4444 
    4545/** 
     
    4747 * 
    4848 * Usage: ./dompdf.php [options] html_file 
    49  *  
     49 * 
    5050 * html_file can be a filename, a url if fopen_wrappers are enabled, or the '-' 
    5151 * character to read from standard input. 
    52  *  
     52 * 
    5353 * Options: 
    5454 *  -h             Show this message 
     
    6464 *  -d             very verbose: display oodles of debugging output: every frame in the 
    6565 *                 tree is printed to stdout. 
    66  *  
     66 *  -t             comma separated list of debugging types (page-break,reflow,split) 
     67 *  -r             write the render time to the log file 
     68 * 
    6769 * 
    6870 */ 
     
    8587    " -v     \tverbose: display html parsing warnings and file not found errors.\n". 
    8688    " -d     \tvery verbose:  display oodles of debugging output: every frame\n". 
    87     "        \tin the tree printed to stdout.\n\n"; 
    88    
     89    "        \tin the tree printed to stdout.\n". 
     90    " -t             comma separated list of debugging types (page-break,reflow,split)\n\n"; 
     91     
     92 
    8993} 
    9094 
     
    9599  if ( $_SERVER["argc"] == 1 ) 
    96100    return $opts; 
    97    
     101 
    98102  $i = 1; 
    99103  while ($i < $_SERVER["argc"]) { 
     
    111115      $i++; 
    112116      break; 
    113        
     117 
    114118    case "-p": 
    115119      if ( !isset($_SERVER["argv"][$i+1]) ) 
     
    128132    case "-b": 
    129133      if ( !isset($_SERVER["argv"][$i+1]) ) 
    130         die("-b switch requires an path parameter\n"); 
     134        die("-b switch requires a path parameter\n"); 
    131135      $opts["b"] = $_SERVER["argv"][$i+1]; 
    132136      $i += 2; 
     
    135139    case "-f": 
    136140      if ( !isset($_SERVER["argv"][$i+1]) ) 
    137         die("-f switch requires an filename parameter\n"); 
     141        die("-f switch requires a filename parameter\n"); 
    138142      $opts["f"] = $_SERVER["argv"][$i+1]; 
    139143      $i += 2; 
    140144      break; 
    141        
     145 
    142146    case "-v": 
    143147      $opts["v"] = true; 
     
    150154      break; 
    151155 
    152     default: 
     156    case "-t": 
     157      if ( !isset($_SERVER['argv'][$i + 1]) ) 
     158        die("-t switch requires a comma separated list of types\n"); 
     159      $opts["t"] = $_SERVER['argv'][$i+1]; 
     160      $i += 2; 
     161      break; 
     162 
     163   default: 
    153164      $opts["filename"] = $_SERVER["argv"][$i]; 
    154165      $i++; 
    155166      break; 
    156167    } 
    157      
    158   } 
    159   return $opts;   
     168 
     169  } 
     170  return $opts; 
    160171} 
    161172 
     
    163174global $_dompdf_show_warnings; 
    164175global $_dompdf_debug; 
    165  
    166 $old_limit = ini_set("memory_limit", "80M"); 
     176global $_DOMPDF_DEBUG_TYPES; 
    167177 
    168178$sapi = php_sapi_name(); 
     
    171181 
    172182 case "cli": 
    173     
     183 
    174184  $opts = getoptions(); 
    175   
     185 
    176186  if ( isset($opts["h"]) || (!isset($opts["filename"]) && !isset($opts["l"])) ) { 
    177187    dompdf_usage(); 
     
    181191  if ( isset($opts["l"]) ) { 
    182192    echo "\nUnderstood paper sizes:\n"; 
    183      
     193 
    184194    foreach (array_keys(CPDF_Adapter::$PAPER_SIZES) as $size) 
    185195      echo "  " . mb_strtoupper($size) . "\n"; 
     
    187197  } 
    188198  $file = $opts["filename"]; 
    189    
     199 
    190200  if ( isset($opts["p"]) ) 
    191201    $paper = $opts["p"]; 
     
    210220  } 
    211221 
    212   if ( isset($opts["v"]) )  
     222  if ( isset($opts["v"]) ) 
    213223    $_dompdf_show_warnings = true; 
    214224 
     
    217227    $_dompdf_debug = true; 
    218228  } 
     229 
     230  if ( isset($opts['t']) ) { 
     231    $arr = split(',',$opts['t']); 
     232    $types = array(); 
     233    foreach ($arr as $type) 
     234      $types[ trim($type) ] = 1; 
     235    $_DOMPDF_DEBUG_TYPES = $types; 
     236  } 
    219237   
    220238  $save_file = true; 
    221    
     239 
    222240  break; 
    223241 
    224242 default: 
    225243 
    226    if ( isset($_GET["input_file"]) ) 
    227      $file = rawurldecode($_GET["input_file"]); 
    228    else 
    229      throw new DOMPDF_Exception("An input file is required (i.e. input_file _GET variable)."); 
    230     
    231    if ( isset($_GET["paper"]) ) 
    232      $paper = rawurldecode($_GET["paper"]); 
    233    else 
    234      $paper = DOMPDF_DEFAULT_PAPER_SIZE; 
    235  
    236    if ( isset($_GET["orientation"]) ) 
    237      $orientation = rawurldecode($_GET["orientation"]); 
    238    else 
    239      $orientation = "portrait"; 
    240  
    241    if ( isset($_GET["base_path"]) ) 
    242      $base_path = rawurldecode($_GET["base_path"]); 
    243  
    244    if ( isset($_GET["output_file"]) ) 
    245      $outfile = rawurldecode($_GET["output_file"]); 
    246    else 
    247      $outfile = "dompdf_out.pdf"; 
    248  
    249    if ( isset($_GET["save_file"]) ) 
    250      $save_file = true; 
    251    else 
    252      $save_file = false; 
     244        if ( isset($_GET["input_file"]) ) 
     245                $file = basename(rawurldecode($_GET["input_file"])); 
     246        else 
     247                throw new DOMPDF_Exception("An input file is required (i.e. input_file _GET variable)."); 
     248                 
     249        if ( isset($_GET["paper"]) ) 
     250                $paper = rawurldecode($_GET["paper"]); 
     251        else 
     252                $paper = DOMPDF_DEFAULT_PAPER_SIZE; 
     253                 
     254        if ( isset($_GET["orientation"]) ) 
     255                $orientation = rawurldecode($_GET["orientation"]); 
     256        else 
     257                $orientation = "portrait"; 
     258                 
     259        if ( isset($_GET["base_path"]) ) 
     260                $base_path = rawurldecode($_GET["base_path"]); 
     261                 
     262                 
     263                $outfile = "dompdf_out.pdf"; # Don't allow them to set the output file 
     264                $save_file = false; # Don't save the file 
     265                $file = $base_path . $file; # Set the input file 
     266 
     267                /* Check to see if the input file and base path = www/test */ 
     268                if(!$base_path=="www/test/")             
     269                        throw new DOMPDF_Exception("Access to dompdf.php via non-cli SAPI has been deprecated due to security concerns.  Please use the dompdf class directly."); 
    253270 
    254271   break; 
     
    264281  $dompdf->load_html($str); 
    265282 
    266 } else  
     283} else 
    267284  $dompdf->load_html_file($file); 
    268285 
     
    276293 
    277294if ( $_dompdf_show_warnings ) { 
     295  global $_dompdf_warnings; 
    278296  foreach ($_dompdf_warnings as $msg) 
    279297    echo $msg . "\n"; 
     298  echo $dompdf->get_canvas()->get_cpdf()->messages; 
    280299  flush(); 
    281300} 
    282       
     301 
    283302if ( $save_file ) { 
    284 //   if ( !is_writable($outfile) )  
     303//   if ( !is_writable($outfile) ) 
    285304//     throw new DOMPDF_Exception("'$outfile' is not writable."); 
    286   if ( strtolower(DOMPDF_PDF_BACKEND) == "gd" )  
     305  if ( strtolower(DOMPDF_PDF_BACKEND) == "gd" ) 
    287306    $outfile = str_replace(".pdf", ".png", $outfile); 
    288      
    289   file_put_contents($outfile, $dompdf->output()); 
     307 
     308  list($proto, $host, $path, $file) = explode_url($outfile); 
     309  if ( $proto != "" ) // i.e. not file:// 
     310    $outfile = $file; // just save it locally, FIXME? could save it like wget: ./host/basepath/file 
     311 
     312  $outfile = dompdf_realpath($outfile); 
     313 
     314  if ( strpos($outfile, DOMPDF_CHROOT) !== 0 ) 
     315    throw new DOMPDF_Exception("Permission denied."); 
     316 
     317  file_put_contents($outfile, $dompdf->output( array("compress" => 0) )); 
    290318  exit(0); 
    291319} 
Note: See TracChangeset for help on using the changeset viewer.