Changeset 1654 for sandbox/filemanager/tp/dompdf/dompdf.php
- Timestamp:
- 11/17/09 09:02:41 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/filemanager/tp/dompdf/dompdf.php
r1575 r1654 33 33 * dompdf.php is a simple script to drive DOMPDF. It can be executed from 34 34 * a browser or from the command line. 35 * 35 * 36 36 * @link http://www.digitaljunkies.ca/dompdf 37 37 * @copyright 2004 Benj Carson … … 41 41 */ 42 42 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 $ */ 44 44 45 45 /** … … 47 47 * 48 48 * Usage: ./dompdf.php [options] html_file 49 * 49 * 50 50 * html_file can be a filename, a url if fopen_wrappers are enabled, or the '-' 51 51 * character to read from standard input. 52 * 52 * 53 53 * Options: 54 54 * -h Show this message … … 64 64 * -d very verbose: display oodles of debugging output: every frame in the 65 65 * 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 * 67 69 * 68 70 */ … … 85 87 " -v \tverbose: display html parsing warnings and file not found errors.\n". 86 88 " -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 89 93 } 90 94 … … 95 99 if ( $_SERVER["argc"] == 1 ) 96 100 return $opts; 97 101 98 102 $i = 1; 99 103 while ($i < $_SERVER["argc"]) { … … 111 115 $i++; 112 116 break; 113 117 114 118 case "-p": 115 119 if ( !isset($_SERVER["argv"][$i+1]) ) … … 128 132 case "-b": 129 133 if ( !isset($_SERVER["argv"][$i+1]) ) 130 die("-b switch requires a npath parameter\n");134 die("-b switch requires a path parameter\n"); 131 135 $opts["b"] = $_SERVER["argv"][$i+1]; 132 136 $i += 2; … … 135 139 case "-f": 136 140 if ( !isset($_SERVER["argv"][$i+1]) ) 137 die("-f switch requires a nfilename parameter\n");141 die("-f switch requires a filename parameter\n"); 138 142 $opts["f"] = $_SERVER["argv"][$i+1]; 139 143 $i += 2; 140 144 break; 141 145 142 146 case "-v": 143 147 $opts["v"] = true; … … 150 154 break; 151 155 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: 153 164 $opts["filename"] = $_SERVER["argv"][$i]; 154 165 $i++; 155 166 break; 156 167 } 157 158 } 159 return $opts; 168 169 } 170 return $opts; 160 171 } 161 172 … … 163 174 global $_dompdf_show_warnings; 164 175 global $_dompdf_debug; 165 166 $old_limit = ini_set("memory_limit", "80M"); 176 global $_DOMPDF_DEBUG_TYPES; 167 177 168 178 $sapi = php_sapi_name(); … … 171 181 172 182 case "cli": 173 183 174 184 $opts = getoptions(); 175 185 176 186 if ( isset($opts["h"]) || (!isset($opts["filename"]) && !isset($opts["l"])) ) { 177 187 dompdf_usage(); … … 181 191 if ( isset($opts["l"]) ) { 182 192 echo "\nUnderstood paper sizes:\n"; 183 193 184 194 foreach (array_keys(CPDF_Adapter::$PAPER_SIZES) as $size) 185 195 echo " " . mb_strtoupper($size) . "\n"; … … 187 197 } 188 198 $file = $opts["filename"]; 189 199 190 200 if ( isset($opts["p"]) ) 191 201 $paper = $opts["p"]; … … 210 220 } 211 221 212 if ( isset($opts["v"]) ) 222 if ( isset($opts["v"]) ) 213 223 $_dompdf_show_warnings = true; 214 224 … … 217 227 $_dompdf_debug = true; 218 228 } 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 } 219 237 220 238 $save_file = true; 221 239 222 240 break; 223 241 224 242 default: 225 243 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."); 253 270 254 271 break; … … 264 281 $dompdf->load_html($str); 265 282 266 } else 283 } else 267 284 $dompdf->load_html_file($file); 268 285 … … 276 293 277 294 if ( $_dompdf_show_warnings ) { 295 global $_dompdf_warnings; 278 296 foreach ($_dompdf_warnings as $msg) 279 297 echo $msg . "\n"; 298 echo $dompdf->get_canvas()->get_cpdf()->messages; 280 299 flush(); 281 300 } 282 301 283 302 if ( $save_file ) { 284 // if ( !is_writable($outfile) ) 303 // if ( !is_writable($outfile) ) 285 304 // throw new DOMPDF_Exception("'$outfile' is not writable."); 286 if ( strtolower(DOMPDF_PDF_BACKEND) == "gd" ) 305 if ( strtolower(DOMPDF_PDF_BACKEND) == "gd" ) 287 306 $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) )); 290 318 exit(0); 291 319 }
Note: See TracChangeset
for help on using the changeset viewer.