@@ -346,9 +346,10 @@ |
||
346 | 346 | function DOMPDF_autoload($class) { |
347 | 347 | $filename = DOMPDF_INC_DIR . "/" . mb_strtolower($class) . ".cls.php"; |
348 | 348 | |
349 | - if ( is_file($filename) ) |
|
350 | - require_once($filename); |
|
351 | -} |
|
349 | + if ( is_file($filename) ) { |
|
350 | + require_once($filename); |
|
351 | + } |
|
352 | + } |
|
352 | 353 | |
353 | 354 | if ( function_exists("spl_autoload_register") ) { |
354 | 355 |
@@ -96,8 +96,9 @@ discard block |
||
96 | 96 | |
97 | 97 | $opts = array(); |
98 | 98 | |
99 | - if ( $_SERVER["argc"] == 1 ) |
|
100 | - return $opts; |
|
99 | + if ( $_SERVER["argc"] == 1 ) { |
|
100 | + return $opts; |
|
101 | + } |
|
101 | 102 | |
102 | 103 | $i = 1; |
103 | 104 | while ($i < $_SERVER["argc"]) { |
@@ -116,29 +117,33 @@ discard block |
||
116 | 117 | break; |
117 | 118 | |
118 | 119 | case "-p": |
119 | - if ( !isset($_SERVER["argv"][$i+1]) ) |
|
120 | - die("-p switch requires a size parameter\n"); |
|
120 | + if ( !isset($_SERVER["argv"][$i+1]) ) { |
|
121 | + die("-p switch requires a size parameter\n"); |
|
122 | + } |
|
121 | 123 | $opts["p"] = $_SERVER["argv"][$i+1]; |
122 | 124 | $i += 2; |
123 | 125 | break; |
124 | 126 | |
125 | 127 | case "-o": |
126 | - if ( !isset($_SERVER["argv"][$i+1]) ) |
|
127 | - die("-o switch requires an orientation parameter\n"); |
|
128 | + if ( !isset($_SERVER["argv"][$i+1]) ) { |
|
129 | + die("-o switch requires an orientation parameter\n"); |
|
130 | + } |
|
128 | 131 | $opts["o"] = $_SERVER["argv"][$i+1]; |
129 | 132 | $i += 2; |
130 | 133 | break; |
131 | 134 | |
132 | 135 | case "-b": |
133 | - if ( !isset($_SERVER["argv"][$i+1]) ) |
|
134 | - die("-b switch requires a path parameter\n"); |
|
136 | + if ( !isset($_SERVER["argv"][$i+1]) ) { |
|
137 | + die("-b switch requires a path parameter\n"); |
|
138 | + } |
|
135 | 139 | $opts["b"] = $_SERVER["argv"][$i+1]; |
136 | 140 | $i += 2; |
137 | 141 | break; |
138 | 142 | |
139 | 143 | case "-f": |
140 | - if ( !isset($_SERVER["argv"][$i+1]) ) |
|
141 | - die("-f switch requires a filename parameter\n"); |
|
144 | + if ( !isset($_SERVER["argv"][$i+1]) ) { |
|
145 | + die("-f switch requires a filename parameter\n"); |
|
146 | + } |
|
142 | 147 | $opts["f"] = $_SERVER["argv"][$i+1]; |
143 | 148 | $i += 2; |
144 | 149 | break; |
@@ -154,8 +159,9 @@ discard block |
||
154 | 159 | break; |
155 | 160 | |
156 | 161 | case "-t": |
157 | - if ( !isset($_SERVER['argv'][$i + 1]) ) |
|
158 | - die("-t switch requires a comma separated list of types\n"); |
|
162 | + if ( !isset($_SERVER['argv'][$i + 1]) ) { |
|
163 | + die("-t switch requires a comma separated list of types\n"); |
|
164 | + } |
|
159 | 165 | $opts["t"] = $_SERVER['argv'][$i+1]; |
160 | 166 | $i += 2; |
161 | 167 | break; |
@@ -191,36 +197,42 @@ discard block |
||
191 | 197 | if ( isset($opts["l"]) ) { |
192 | 198 | echo "\nUnderstood paper sizes:\n"; |
193 | 199 | |
194 | - foreach (array_keys(CPDF_Adapter::$PAPER_SIZES) as $size) |
|
195 | - echo " " . mb_strtoupper($size) . "\n"; |
|
200 | + foreach (array_keys(CPDF_Adapter::$PAPER_SIZES) as $size) { |
|
201 | + echo " " . mb_strtoupper($size) . "\n"; |
|
202 | + } |
|
196 | 203 | exit; |
197 | 204 | } |
198 | 205 | $file = $opts["filename"]; |
199 | 206 | |
200 | - if ( isset($opts["p"]) ) |
|
201 | - $paper = $opts["p"]; |
|
202 | - else |
|
203 | - $paper = DOMPDF_DEFAULT_PAPER_SIZE; |
|
204 | - |
|
205 | - if ( isset($opts["o"]) ) |
|
206 | - $orientation = $opts["o"]; |
|
207 | - else |
|
208 | - $orientation = "portrait"; |
|
209 | - |
|
210 | - if ( isset($opts["b"]) ) |
|
211 | - $base_path = $opts["b"]; |
|
212 | - |
|
213 | - if ( isset($opts["f"]) ) |
|
214 | - $outfile = $opts["f"]; |
|
215 | - else { |
|
216 | - if ( $file === "-" ) |
|
217 | - $outfile = "dompdf_out.pdf"; |
|
218 | - else |
|
219 | - $outfile = str_ireplace(array(".html", ".htm", ".php"), "", $file) . ".pdf"; |
|
207 | + if ( isset($opts["p"]) ) { |
|
208 | + $paper = $opts["p"]; |
|
209 | + } else { |
|
210 | + $paper = DOMPDF_DEFAULT_PAPER_SIZE; |
|
220 | 211 | } |
221 | 212 | |
222 | - if ( isset($opts["v"]) ) |
|
223 | - $_dompdf_show_warnings = true; |
|
213 | + if ( isset($opts["o"]) ) { |
|
214 | + $orientation = $opts["o"]; |
|
215 | + } else { |
|
216 | + $orientation = "portrait"; |
|
217 | + } |
|
218 | + |
|
219 | + if ( isset($opts["b"]) ) { |
|
220 | + $base_path = $opts["b"]; |
|
221 | + } |
|
222 | + |
|
223 | + if ( isset($opts["f"]) ) { |
|
224 | + $outfile = $opts["f"]; |
|
225 | + } else { |
|
226 | + if ( $file === "-" ) { |
|
227 | + $outfile = "dompdf_out.pdf"; |
|
228 | + } else { |
|
229 | + $outfile = str_ireplace(array(".html", ".htm", ".php"), "", $file) . ".pdf"; |
|
230 | + } |
|
231 | + } |
|
232 | + |
|
233 | + if ( isset($opts["v"]) ) { |
|
234 | + $_dompdf_show_warnings = true; |
|
235 | + } |
|
224 | 236 | |
225 | 237 | if ( isset($opts["d"]) ) { |
226 | 238 | $_dompdf_show_warnings = true; |
@@ -230,8 +242,9 @@ discard block |
||
230 | 242 | if ( isset($opts['t']) ) { |
231 | 243 | $arr = split(',',$opts['t']); |
232 | 244 | $types = array(); |
233 | - foreach ($arr as $type) |
|
234 | - $types[ trim($type) ] = 1; |
|
245 | + foreach ($arr as $type) { |
|
246 | + $types[ trim($type) ] = 1; |
|
247 | + } |
|
235 | 248 | $_DOMPDF_DEBUG_TYPES = $types; |
236 | 249 | } |
237 | 250 | |
@@ -241,23 +254,27 @@ discard block |
||
241 | 254 | |
242 | 255 | default: |
243 | 256 | |
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)."); |
|
257 | + if ( isset($_GET["input_file"]) ) { |
|
258 | + $file = basename(rawurldecode($_GET["input_file"])); |
|
259 | + } else { |
|
260 | + throw new DOMPDF_Exception("An input file is required (i.e. input_file _GET variable)."); |
|
261 | + } |
|
248 | 262 | |
249 | - if ( isset($_GET["paper"]) ) |
|
250 | - $paper = rawurldecode($_GET["paper"]); |
|
251 | - else |
|
252 | - $paper = DOMPDF_DEFAULT_PAPER_SIZE; |
|
263 | + if ( isset($_GET["paper"]) ) { |
|
264 | + $paper = rawurldecode($_GET["paper"]); |
|
265 | + } else { |
|
266 | + $paper = DOMPDF_DEFAULT_PAPER_SIZE; |
|
267 | + } |
|
253 | 268 | |
254 | - if ( isset($_GET["orientation"]) ) |
|
255 | - $orientation = rawurldecode($_GET["orientation"]); |
|
256 | - else |
|
257 | - $orientation = "portrait"; |
|
269 | + if ( isset($_GET["orientation"]) ) { |
|
270 | + $orientation = rawurldecode($_GET["orientation"]); |
|
271 | + } else { |
|
272 | + $orientation = "portrait"; |
|
273 | + } |
|
258 | 274 | |
259 | - if ( isset($_GET["base_path"]) ) |
|
260 | - $base_path = rawurldecode($_GET["base_path"]); |
|
275 | + if ( isset($_GET["base_path"]) ) { |
|
276 | + $base_path = rawurldecode($_GET["base_path"]); |
|
277 | + } |
|
261 | 278 | |
262 | 279 | |
263 | 280 | $outfile = "dompdf_out.pdf"; # Don't allow them to set the output file |
@@ -265,8 +282,9 @@ discard block |
||
265 | 282 | $file = $base_path . $file; # Set the input file |
266 | 283 | |
267 | 284 | /* 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."); |
|
285 | + if($base_path !== "www/test/") { |
|
286 | + 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."); |
|
287 | + } |
|
270 | 288 | |
271 | 289 | break; |
272 | 290 | } |
@@ -275,13 +293,15 @@ discard block |
||
275 | 293 | |
276 | 294 | if ( $file === "-" ) { |
277 | 295 | $str = ""; |
278 | - while ( !feof(STDIN) ) |
|
279 | - $str .= fread(STDIN, 4096); |
|
296 | + while ( !feof(STDIN) ) { |
|
297 | + $str .= fread(STDIN, 4096); |
|
298 | + } |
|
280 | 299 | |
281 | 300 | $dompdf->load_html($str); |
282 | 301 | |
283 | -} else |
|
302 | +} else { |
|
284 | 303 | $dompdf->load_html_file($file); |
304 | +} |
|
285 | 305 | |
286 | 306 | if ( isset($base_path) ) { |
287 | 307 | $dompdf->set_base_path($base_path); |
@@ -293,8 +313,9 @@ discard block |
||
293 | 313 | |
294 | 314 | if ( $_dompdf_show_warnings ) { |
295 | 315 | global $_dompdf_warnings; |
296 | - foreach ($_dompdf_warnings as $msg) |
|
297 | - echo $msg . "\n"; |
|
316 | + foreach ($_dompdf_warnings as $msg) { |
|
317 | + echo $msg . "\n"; |
|
318 | + } |
|
298 | 319 | echo $dompdf->get_canvas()->get_cpdf()->messages; |
299 | 320 | flush(); |
300 | 321 | } |
@@ -302,17 +323,22 @@ discard block |
||
302 | 323 | if ( $save_file ) { |
303 | 324 | // if ( !is_writable($outfile) ) |
304 | 325 | // throw new DOMPDF_Exception("'$outfile' is not writable."); |
305 | - if ( strtolower(DOMPDF_PDF_BACKEND) === "gd" ) |
|
306 | - $outfile = str_replace(".pdf", ".png", $outfile); |
|
326 | + if ( strtolower(DOMPDF_PDF_BACKEND) === "gd" ) { |
|
327 | + $outfile = str_replace(".pdf", ".png", $outfile); |
|
328 | + } |
|
307 | 329 | |
308 | 330 | 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 |
|
331 | + if ( $proto != "" ) { |
|
332 | + // i.e. not file:// |
|
333 | + $outfile = $file; |
|
334 | + } |
|
335 | + // just save it locally, FIXME? could save it like wget: ./host/basepath/file |
|
311 | 336 | |
312 | 337 | $outfile = realpath(dirname($outfile)) . DIRECTORY_SEPARATOR . basename($outfile); |
313 | 338 | |
314 | - if ( strpos($outfile, DOMPDF_CHROOT) !== 0 ) |
|
315 | - throw new DOMPDF_Exception("Permission denied."); |
|
339 | + if ( strpos($outfile, DOMPDF_CHROOT) !== 0 ) { |
|
340 | + throw new DOMPDF_Exception("Permission denied."); |
|
341 | + } |
|
316 | 342 | |
317 | 343 | file_put_contents($outfile, $dompdf->output( array("compress" => 0) )); |
318 | 344 | exit(0); |
@@ -3,8 +3,9 @@ discard block |
||
3 | 3 | require_once("../dompdf_config.inc.php"); |
4 | 4 | if ( isset( $_POST["html"] ) ) { |
5 | 5 | |
6 | - if ( get_magic_quotes_gpc() ) |
|
7 | - $_POST["html"] = stripslashes($_POST["html"]); |
|
6 | + if ( get_magic_quotes_gpc() ) { |
|
7 | + $_POST["html"] = stripslashes($_POST["html"]); |
|
8 | + } |
|
8 | 9 | |
9 | 10 | $dompdf = new DOMPDF(); |
10 | 11 | $dompdf->load_html($_POST["html"]); |
@@ -68,8 +69,9 @@ discard block |
||
68 | 69 | <p>Paper size and orientaion: |
69 | 70 | <select name="paper"> |
70 | 71 | <?php |
71 | -foreach ( array_keys(CPDF_Adapter::$PAPER_SIZES) as $size ) |
|
72 | +foreach ( array_keys(CPDF_Adapter::$PAPER_SIZES) as $size ) { |
|
72 | 73 | echo "<option ". ($size == "letter" ? "selected " : "" ) . "value=\"$size\">$size</option>\n"; |
74 | +} |
|
73 | 75 | ?> |
74 | 76 | </select> |
75 | 77 | <select name="orientation"> |
@@ -64,8 +64,9 @@ |
||
64 | 64 | |
65 | 65 | // End debugging |
66 | 66 | |
67 | - if ( !$p ) |
|
68 | - throw new DOMPDF_Exception("No block-level parent found. Not good."); |
|
67 | + if ( !$p ) { |
|
68 | + throw new DOMPDF_Exception("No block-level parent found. Not good."); |
|
69 | + } |
|
69 | 70 | |
70 | 71 | $line = $p->get_current_line(); |
71 | 72 |
@@ -88,7 +88,9 @@ discard block |
||
88 | 88 | $full_url_dbg = ''; |
89 | 89 | |
90 | 90 | //debugpng |
91 | - if ($DEBUGPNG) print 'resolve_url('.$url.','.$proto.','.$host.','.$base_path.')('.$parsed_url['protocol'].')'; |
|
91 | + if ($DEBUGPNG) { |
|
92 | + print 'resolve_url('.$url.','.$proto.','.$host.','.$base_path.')('.$parsed_url['protocol'].')'; |
|
93 | + } |
|
92 | 94 | |
93 | 95 | $remote = ($proto != "" && $proto !== "file://"); |
94 | 96 | $remote = $remote || ($parsed_url['protocol'] != ""); |
@@ -98,7 +100,9 @@ discard block |
||
98 | 100 | $ext = "png"; |
99 | 101 | |
100 | 102 | //debugpng |
101 | - if ($DEBUGPNG) $full_url_dbg = '(blockedremote)'; |
|
103 | + if ($DEBUGPNG) { |
|
104 | + $full_url_dbg = '(blockedremote)'; |
|
105 | + } |
|
102 | 106 | |
103 | 107 | } else if ( DOMPDF_ENABLE_REMOTE && $remote ) { |
104 | 108 | // Download remote files to a temporary directory |
@@ -108,13 +112,17 @@ discard block |
||
108 | 112 | list($resolved_url,$ext) = self::$_cache[$full_url]; |
109 | 113 | |
110 | 114 | //debugpng |
111 | - if ($DEBUGPNG) $full_url_dbg = $full_url.'(cache)'; |
|
115 | + if ($DEBUGPNG) { |
|
116 | + $full_url_dbg = $full_url.'(cache)'; |
|
117 | + } |
|
112 | 118 | |
113 | 119 | } else { |
114 | 120 | |
115 | 121 | $resolved_url = tempnam(DOMPDF_TEMP_DIR, "ca_dompdf_img_"); |
116 | 122 | //debugpng |
117 | - if ($DEBUGPNG) echo $resolved_url . "\n"; |
|
123 | + if ($DEBUGPNG) { |
|
124 | + echo $resolved_url . "\n"; |
|
125 | + } |
|
118 | 126 | |
119 | 127 | $old_err = set_error_handler("record_warnings"); |
120 | 128 | $image = file_get_contents($full_url); |
@@ -126,7 +134,9 @@ discard block |
||
126 | 134 | $ext = "png"; |
127 | 135 | |
128 | 136 | //debugpng |
129 | - if ($DEBUGPNG) $full_url_dbg = $full_url.'(missing)'; |
|
137 | + if ($DEBUGPNG) { |
|
138 | + $full_url_dbg = $full_url.'(missing)'; |
|
139 | + } |
|
130 | 140 | |
131 | 141 | } else { |
132 | 142 | |
@@ -167,25 +177,33 @@ discard block |
||
167 | 177 | } else { |
168 | 178 | |
169 | 179 | $resolved_url = build_url($proto, $host, $base_path, $url); |
170 | - if ($DEBUGPNG) print 'build_url('.$proto.','.$host.','.$base_path.','.$url.')('.$resolved_url.')'; |
|
180 | + if ($DEBUGPNG) { |
|
181 | + print 'build_url('.$proto.','.$host.','.$base_path.','.$url.')('.$resolved_url.')'; |
|
182 | + } |
|
171 | 183 | |
172 | 184 | if ( !preg_match("/.*\.(\w+)/",$url,$match) ) { |
173 | 185 | //debugpng |
174 | - if ($DEBUGPNG) print '[resolve_url exception '.$url.']'; |
|
186 | + if ($DEBUGPNG) { |
|
187 | + print '[resolve_url exception '.$url.']'; |
|
188 | + } |
|
175 | 189 | throw new DOMPDF_Exception("Unknown image type: $url."); |
176 | 190 | } |
177 | 191 | |
178 | 192 | $ext = $match[1]; |
179 | 193 | |
180 | 194 | //debugpng |
181 | - if ($DEBUGPNG) $full_url_dbg = '(local)'; |
|
195 | + if ($DEBUGPNG) { |
|
196 | + $full_url_dbg = '(local)'; |
|
197 | + } |
|
182 | 198 | |
183 | 199 | } |
184 | 200 | |
185 | 201 | if ( !is_readable($resolved_url) || !filesize($resolved_url) ) { |
186 | 202 | |
187 | 203 | //debugpng |
188 | - if ($DEBUGPNG) $full_url_dbg .= '(nocache'.$resolved_url.')'; |
|
204 | + if ($DEBUGPNG) { |
|
205 | + $full_url_dbg .= '(nocache'.$resolved_url.')'; |
|
206 | + } |
|
189 | 207 | |
190 | 208 | $_dompdf_warnings[] = "File " .$resolved_url . " is not readable or is an empty file.\n"; |
191 | 209 | $resolved_url = DOMPDF_LIB_DIR . "/res/broken_image.png"; |
@@ -193,7 +211,9 @@ discard block |
||
193 | 211 | } |
194 | 212 | |
195 | 213 | //debugpng |
196 | - if ($DEBUGPNG) print '[resolve_url '.$url.'|'.$full_url_dbg.'|'.$resolved_url.'|'.$ext.']'; |
|
214 | + if ($DEBUGPNG) { |
|
215 | + print '[resolve_url '.$url.'|'.$full_url_dbg.'|'.$resolved_url.'|'.$ext.']'; |
|
216 | + } |
|
197 | 217 | |
198 | 218 | return array($resolved_url, $ext); |
199 | 219 | } |
@@ -207,10 +227,13 @@ discard block |
||
207 | 227 | while ($entry = array_shift(self::$_cache)) { |
208 | 228 | list($file, $ext) = $entry; |
209 | 229 | //debugpng |
210 | - if (DEBUGPNG) print '[clear unlink '.$file.']'; |
|
211 | - if (!DEBUGKEEPTEMP) |
|
212 | - //XXX: Should we have some kind of fallback or warning if unlink() fails? |
|
230 | + if (DEBUGPNG) { |
|
231 | + print '[clear unlink '.$file.']'; |
|
232 | + } |
|
233 | + if (!DEBUGKEEPTEMP) { |
|
234 | + //XXX: Should we have some kind of fallback or warning if unlink() fails? |
|
213 | 235 | unlink($file); |
236 | + } |
|
214 | 237 | } |
215 | 238 | } |
216 | 239 | } |
@@ -80,7 +80,9 @@ |
||
80 | 80 | $url = $frame->get_node()->getAttribute("src"); |
81 | 81 | |
82 | 82 | //debugpng |
83 | - if (DEBUGPNG) print '[__construct '.$url.']'; |
|
83 | + if (DEBUGPNG) { |
|
84 | + print '[__construct '.$url.']'; |
|
85 | + } |
|
84 | 86 | |
85 | 87 | list($this->_image_url, $this->_image_ext) = Image_Cache::resolve_url($url, |
86 | 88 | $dompdf->get_protocol(), |
@@ -182,8 +182,9 @@ discard block |
||
182 | 182 | function dispose($recursive = false) { |
183 | 183 | |
184 | 184 | if ( $recursive ) { |
185 | - while ( $child = $this->_first_child ) |
|
186 | - $child->dispose(true); |
|
185 | + while ( $child = $this->_first_child ) { |
|
186 | + $child->dispose(true); |
|
187 | + } |
|
187 | 188 | } |
188 | 189 | |
189 | 190 | // Remove this frame from the tree |
@@ -246,14 +247,16 @@ discard block |
||
246 | 247 | |
247 | 248 | // Layout property accessors |
248 | 249 | function get_containing_block($i = null) { |
249 | - if ( isset($i) ) |
|
250 | - return $this->_containing_block[$i]; |
|
250 | + if ( isset($i) ) { |
|
251 | + return $this->_containing_block[$i]; |
|
252 | + } |
|
251 | 253 | return $this->_containing_block; |
252 | 254 | } |
253 | 255 | |
254 | 256 | function get_position($i = null) { |
255 | - if ( isset($i) ) |
|
256 | - return $this->_position[$i]; |
|
257 | + if ( isset($i) ) { |
|
258 | + return $this->_position[$i]; |
|
259 | + } |
|
257 | 260 | return array($this->_position["x"], |
258 | 261 | $this->_position["y"], |
259 | 262 | "x"=>$this->_position["x"], |
@@ -354,13 +357,15 @@ discard block |
||
354 | 357 | // We can only set attributes of DOMElement objects (nodeType == 1). |
355 | 358 | // Since these are the only objects that we can assign CSS rules to, |
356 | 359 | // this shortcoming is okay. |
357 | - if ( $this->_node->nodeType == 1) |
|
358 | - $this->_node->setAttribute("frame_id", $id); |
|
360 | + if ( $this->_node->nodeType == 1) { |
|
361 | + $this->_node->setAttribute("frame_id", $id); |
|
362 | + } |
|
359 | 363 | } |
360 | 364 | |
361 | 365 | function set_style(Style $style) { |
362 | - if ( is_null($this->_style) ) |
|
363 | - $this->_original_style = clone $style; |
|
366 | + if ( is_null($this->_style) ) { |
|
367 | + $this->_original_style = clone $style; |
|
368 | + } |
|
364 | 369 | |
365 | 370 | $this->_style = $style; |
366 | 371 | } |
@@ -399,8 +404,9 @@ discard block |
||
399 | 404 | } |
400 | 405 | |
401 | 406 | function set_position($x = null, $y = null) { |
402 | - if ( is_array($x) ) |
|
403 | - extract($x); |
|
407 | + if ( is_array($x) ) { |
|
408 | + extract($x); |
|
409 | + } |
|
404 | 410 | |
405 | 411 | if ( is_numeric($x) ) { |
406 | 412 | $this->_position[0] = $x; |
@@ -417,12 +423,14 @@ discard block |
||
417 | 423 | |
418 | 424 | function prepend_child(Frame $child, $update_node = true) { |
419 | 425 | |
420 | - if ( $update_node ) |
|
421 | - $this->_node->insertBefore($child->_node, $this->_first_child ? $this->_first_child->_node : null); |
|
426 | + if ( $update_node ) { |
|
427 | + $this->_node->insertBefore($child->_node, $this->_first_child ? $this->_first_child->_node : null); |
|
428 | + } |
|
422 | 429 | |
423 | 430 | // Remove the child from its parent |
424 | - if ( $child->_parent ) |
|
425 | - $child->_parent->remove_child($child, false); |
|
431 | + if ( $child->_parent ) { |
|
432 | + $child->_parent->remove_child($child, false); |
|
433 | + } |
|
426 | 434 | |
427 | 435 | $child->_parent = $this; |
428 | 436 | $child->_prev_sibling = null; |
@@ -444,12 +452,14 @@ discard block |
||
444 | 452 | |
445 | 453 | function append_child(Frame $child, $update_node = true) { |
446 | 454 | |
447 | - if ( $update_node ) |
|
448 | - $this->_node->appendChild($child->_node); |
|
455 | + if ( $update_node ) { |
|
456 | + $this->_node->appendChild($child->_node); |
|
457 | + } |
|
449 | 458 | |
450 | 459 | // Remove the child from its parent |
451 | - if ( $child->_parent ) |
|
452 | - $child->_parent->remove_child($child, false); |
|
460 | + if ( $child->_parent ) { |
|
461 | + $child->_parent->remove_child($child, false); |
|
462 | + } |
|
453 | 463 | |
454 | 464 | $child->_parent = $this; |
455 | 465 | $child->_next_sibling = null; |
@@ -482,23 +492,27 @@ discard block |
||
482 | 492 | return; |
483 | 493 | } |
484 | 494 | |
485 | - if ( $ref->_parent !== $this ) |
|
486 | - throw new DOMPDF_Exception("Reference child is not a child of this node."); |
|
495 | + if ( $ref->_parent !== $this ) { |
|
496 | + throw new DOMPDF_Exception("Reference child is not a child of this node."); |
|
497 | + } |
|
487 | 498 | |
488 | 499 | // Update the node |
489 | - if ( $update_node ) |
|
490 | - $this->_node->insertBefore($new_child->_node, $ref->_node); |
|
500 | + if ( $update_node ) { |
|
501 | + $this->_node->insertBefore($new_child->_node, $ref->_node); |
|
502 | + } |
|
491 | 503 | |
492 | 504 | // Remove the child from its parent |
493 | - if ( $new_child->_parent ) |
|
494 | - $new_child->_parent->remove_child($new_child, false); |
|
505 | + if ( $new_child->_parent ) { |
|
506 | + $new_child->_parent->remove_child($new_child, false); |
|
507 | + } |
|
495 | 508 | |
496 | 509 | $new_child->_parent = $this; |
497 | 510 | $new_child->_next_sibling = $ref; |
498 | 511 | $new_child->_prev_sibling = $ref->_prev_sibling; |
499 | 512 | |
500 | - if ( $ref->_prev_sibling ) |
|
501 | - $ref->_prev_sibling->_next_sibling = $new_child; |
|
513 | + if ( $ref->_prev_sibling ) { |
|
514 | + $ref->_prev_sibling->_next_sibling = $new_child; |
|
515 | + } |
|
502 | 516 | |
503 | 517 | $ref->_prev_sibling = $new_child; |
504 | 518 | } |
@@ -516,8 +530,9 @@ discard block |
||
516 | 530 | return; |
517 | 531 | } |
518 | 532 | |
519 | - if ( $ref->_parent !== $this ) |
|
520 | - throw new DOMPDF_Exception("Reference child is not a child of this node."); |
|
533 | + if ( $ref->_parent !== $this ) { |
|
534 | + throw new DOMPDF_Exception("Reference child is not a child of this node."); |
|
535 | + } |
|
521 | 536 | |
522 | 537 | // Update the node |
523 | 538 | if ( $update_node ) { |
@@ -530,15 +545,17 @@ discard block |
||
530 | 545 | } |
531 | 546 | |
532 | 547 | // Remove the child from its parent |
533 | - if ( $new_child->_parent) |
|
534 | - $new_child->_parent->remove_child($new_child, false); |
|
548 | + if ( $new_child->_parent) { |
|
549 | + $new_child->_parent->remove_child($new_child, false); |
|
550 | + } |
|
535 | 551 | |
536 | 552 | $new_child->_parent = $this; |
537 | 553 | $new_child->_prev_sibling = $ref; |
538 | 554 | $new_child->_next_sibling = $ref->_next_sibling; |
539 | 555 | |
540 | - if ( $ref->_next_sibling ) |
|
541 | - $ref->_next_sibling->_prev_sibling = $new_child; |
|
556 | + if ( $ref->_next_sibling ) { |
|
557 | + $ref->_next_sibling->_prev_sibling = $new_child; |
|
558 | + } |
|
542 | 559 | |
543 | 560 | $ref->_next_sibling = $new_child; |
544 | 561 | } |
@@ -546,23 +563,29 @@ discard block |
||
546 | 563 | |
547 | 564 | function remove_child(Frame $child, $update_node = true) { |
548 | 565 | |
549 | - if ( $child->_parent !== $this ) |
|
550 | - throw new DOMPDF_Exception("Child not found in this frame"); |
|
566 | + if ( $child->_parent !== $this ) { |
|
567 | + throw new DOMPDF_Exception("Child not found in this frame"); |
|
568 | + } |
|
551 | 569 | |
552 | - if ( $update_node ) |
|
553 | - $this->_node->removeChild($child->_node); |
|
570 | + if ( $update_node ) { |
|
571 | + $this->_node->removeChild($child->_node); |
|
572 | + } |
|
554 | 573 | |
555 | - if ( $child === $this->_first_child ) |
|
556 | - $this->_first_child = $child->_next_sibling; |
|
574 | + if ( $child === $this->_first_child ) { |
|
575 | + $this->_first_child = $child->_next_sibling; |
|
576 | + } |
|
557 | 577 | |
558 | - if ( $child === $this->_last_child ) |
|
559 | - $this->_last_child = $child->_prev_sibling; |
|
578 | + if ( $child === $this->_last_child ) { |
|
579 | + $this->_last_child = $child->_prev_sibling; |
|
580 | + } |
|
560 | 581 | |
561 | - if ( $child->_prev_sibling ) |
|
562 | - $child->_prev_sibling->_next_sibling = $child->_next_sibling; |
|
582 | + if ( $child->_prev_sibling ) { |
|
583 | + $child->_prev_sibling->_next_sibling = $child->_next_sibling; |
|
584 | + } |
|
563 | 585 | |
564 | - if ( $child->_next_sibling ) |
|
565 | - $child->_next_sibling->_prev_sibling = $child->_prev_sibling; |
|
586 | + if ( $child->_next_sibling ) { |
|
587 | + $child->_next_sibling->_prev_sibling = $child->_prev_sibling; |
|
588 | + } |
|
566 | 589 | |
567 | 590 | $child->_next_sibling = null; |
568 | 591 | $child->_prev_sibling = null; |
@@ -592,20 +615,23 @@ discard block |
||
592 | 615 | $str .= "<pre>'" . mb_substr($tmp,0,70) . |
593 | 616 | (mb_strlen($tmp) > 70 ? "..." : "") . "'</pre>"; |
594 | 617 | } |
595 | - if ( $this->_parent ) |
|
596 | - $str .= "\nParent:" . $this->_parent->_node->nodeName . |
|
618 | + if ( $this->_parent ) { |
|
619 | + $str .= "\nParent:" . $this->_parent->_node->nodeName . |
|
597 | 620 | " (" . spl_object_hash($this->_parent->_node) . ") " . |
598 | 621 | "<br/>"; |
622 | + } |
|
599 | 623 | |
600 | - if ( $this->_prev_sibling ) |
|
601 | - $str .= "Prev: " . $this->_prev_sibling->_node->nodeName . |
|
624 | + if ( $this->_prev_sibling ) { |
|
625 | + $str .= "Prev: " . $this->_prev_sibling->_node->nodeName . |
|
602 | 626 | " (" . spl_object_hash($this->_prev_sibling->_node) . ") " . |
603 | 627 | "<br/>"; |
628 | + } |
|
604 | 629 | |
605 | - if ( $this->_next_sibling ) |
|
606 | - $str .= "Next: " . $this->_next_sibling->_node->nodeName . |
|
630 | + if ( $this->_next_sibling ) { |
|
631 | + $str .= "Next: " . $this->_next_sibling->_node->nodeName . |
|
607 | 632 | " (" . spl_object_hash($this->_next_sibling->_node) . ") " . |
608 | 633 | "<br/>"; |
634 | + } |
|
609 | 635 | |
610 | 636 | $d = $this->get_decorator(); |
611 | 637 | while ($d && $d != $d->get_decorator()) { |
@@ -641,10 +667,11 @@ discard block |
||
641 | 667 | $str .= "</pre>"; |
642 | 668 | } |
643 | 669 | $str .= "\n"; |
644 | - if ( php_sapi_name() === "cli" ) |
|
645 | - $str = strip_tags(str_replace(array("<br/>","<b>","</b>"), |
|
670 | + if ( php_sapi_name() === "cli" ) { |
|
671 | + $str = strip_tags(str_replace(array("<br/>","<b>","</b>"), |
|
646 | 672 | array("\n","",""), |
647 | 673 | $str)); |
674 | + } |
|
648 | 675 | |
649 | 676 | return $str; |
650 | 677 | } |
@@ -701,8 +728,9 @@ discard block |
||
701 | 728 | function next() { |
702 | 729 | |
703 | 730 | $ret = $this->_cur; |
704 | - if ( !$ret ) |
|
705 | - return null; |
|
731 | + if ( !$ret ) { |
|
732 | + return null; |
|
733 | + } |
|
706 | 734 | |
707 | 735 | $this->_cur = $this->_cur->get_next_sibling(); |
708 | 736 | $this->_num++; |
@@ -764,8 +792,9 @@ discard block |
||
764 | 792 | // Push all children onto the stack in reverse order |
765 | 793 | if ( $c = $b->get_last_child() ) { |
766 | 794 | $this->_stack[] = $c; |
767 | - while ( $c = $c->get_prev_sibling() ) |
|
768 | - $this->_stack[] = $c; |
|
795 | + while ( $c = $c->get_prev_sibling() ) { |
|
796 | + $this->_stack[] = $c; |
|
797 | + } |
|
769 | 798 | } |
770 | 799 | return $b; |
771 | 800 | } |
@@ -63,16 +63,18 @@ discard block |
||
63 | 63 | " user=" . self::DB_USER . |
64 | 64 | " password=" . self::DB_PASS; |
65 | 65 | |
66 | - if ( !self::$__connection = pg_connect($con_str) ) |
|
67 | - throw new Exception("Database connection failed."); |
|
66 | + if ( !self::$__connection = pg_connect($con_str) ) { |
|
67 | + throw new Exception("Database connection failed."); |
|
68 | + } |
|
68 | 69 | } |
69 | 70 | } |
70 | 71 | |
71 | 72 | function __construct() { throw new Exception("Can not create instance of Page_Class. Class is static."); } |
72 | 73 | |
73 | 74 | private static function __query($sql) { |
74 | - if ( !($res = pg_query(self::$__connection, $sql)) ) |
|
75 | - throw new Exception(pg_last_error(self::$__connection)); |
|
75 | + if ( !($res = pg_query(self::$__connection, $sql)) ) { |
|
76 | + throw new Exception(pg_last_error(self::$__connection)); |
|
77 | + } |
|
76 | 78 | return $res; |
77 | 79 | } |
78 | 80 | |
@@ -84,12 +86,13 @@ discard block |
||
84 | 86 | |
85 | 87 | $row = pg_fetch_assoc($res); |
86 | 88 | |
87 | - if ( $row ) |
|
88 | - self::__query("UPDATE page_cache SET data='" . pg_escape_string($data) . "' " . $where); |
|
89 | - else |
|
90 | - self::__query("INSERT INTO page_cache (id, page_num, data) VALUES ('" . pg_escape_string($id) . "', ". |
|
89 | + if ( $row ) { |
|
90 | + self::__query("UPDATE page_cache SET data='" . pg_escape_string($data) . "' " . $where); |
|
91 | + } else { |
|
92 | + self::__query("INSERT INTO page_cache (id, page_num, data) VALUES ('" . pg_escape_string($id) . "', ". |
|
91 | 93 | pg_escape_string($page_num) . ", ". |
92 | 94 | "'". pg_escape_string($data) . "')"); |
95 | + } |
|
93 | 96 | |
94 | 97 | } |
95 | 98 | |
@@ -98,9 +101,10 @@ discard block |
||
98 | 101 | // Update the font information |
99 | 102 | self::__query("DELETE FROM page_fonts WHERE id='" . pg_escape_string($id) . "'"); |
100 | 103 | |
101 | - foreach (array_keys($fonts) as $font) |
|
102 | - self::__query("INSERT INTO page_fonts (id, font_name) VALUES ('" . |
|
104 | + foreach (array_keys($fonts) as $font) { |
|
105 | + self::__query("INSERT INTO page_fonts (id, font_name) VALUES ('" . |
|
103 | 106 | pg_escape_string($id) . "', '" . pg_escape_string($font) . "')"); |
107 | + } |
|
104 | 108 | self::__query("COMMIT"); |
105 | 109 | } |
106 | 110 | |
@@ -131,21 +135,24 @@ discard block |
||
131 | 135 | |
132 | 136 | // Ensure that the fonts needed by the cached document are loaded into |
133 | 137 | // the pdf |
134 | - while ($row = pg_fetch_assoc($res)) |
|
135 | - $pdf->get_cpdf()->selectFont($row["font_name"]); |
|
138 | + while ($row = pg_fetch_assoc($res)) { |
|
139 | + $pdf->get_cpdf()->selectFont($row["font_name"]); |
|
140 | + } |
|
136 | 141 | |
137 | 142 | $res = self::__query("SELECT data FROM page_cache WHERE id='" . pg_escape_string($id) . "'"); |
138 | 143 | |
139 | - if ( $new_page ) |
|
140 | - $pdf->new_page(); |
|
144 | + if ( $new_page ) { |
|
145 | + $pdf->new_page(); |
|
146 | + } |
|
141 | 147 | |
142 | 148 | $first = true; |
143 | 149 | while ($row = pg_fetch_assoc($res)) { |
144 | 150 | |
145 | - if ( !$first ) |
|
146 | - $pdf->new_page(); |
|
147 | - else |
|
148 | - $first = false; |
|
151 | + if ( !$first ) { |
|
152 | + $pdf->new_page(); |
|
153 | + } else { |
|
154 | + $first = false; |
|
155 | + } |
|
149 | 156 | |
150 | 157 | $page = $pdf->reopen_serialized_object($row["data"]); |
151 | 158 | //$pdf->close_object(); |
@@ -93,8 +93,9 @@ discard block |
||
93 | 93 | |
94 | 94 | // Collapse vertical margins: |
95 | 95 | $n = $this->_frame->get_next_sibling(); |
96 | - while ( $n && !in_array($n->get_style()->display, Style::$BLOCK_TYPES) ) |
|
97 | - $n = $n->get_next_sibling(); |
|
96 | + while ( $n && !in_array($n->get_style()->display, Style::$BLOCK_TYPES) ) { |
|
97 | + $n = $n->get_next_sibling(); |
|
98 | + } |
|
98 | 99 | |
99 | 100 | if ( $n ) { // && !$n instanceof Page_Frame_Decorator ) { |
100 | 101 | |
@@ -107,8 +108,9 @@ discard block |
||
107 | 108 | |
108 | 109 | // Collapse our first child's margin |
109 | 110 | $f = $this->_frame->get_first_child(); |
110 | - while ( $f && !in_array($f->get_style()->display, Style::$BLOCK_TYPES) ) |
|
111 | - $f = $f->get_next_sibling(); |
|
111 | + while ( $f && !in_array($f->get_style()->display, Style::$BLOCK_TYPES) ) { |
|
112 | + $f = $f->get_next_sibling(); |
|
113 | + } |
|
112 | 114 | |
113 | 115 | if ( $f ) { |
114 | 116 | $t = max( $t, $style->length_in_pt($f->get_style()->margin_top, $cb["w"])); |
@@ -123,8 +125,9 @@ discard block |
||
123 | 125 | $y = $this->_frame->get_position("y"); |
124 | 126 | $h = $style->length_in_pt($style->height); |
125 | 127 | // Check if we need to move to a new page |
126 | - if ( $y + $h >= $this->_frame->get_root()->get_page_height() ) |
|
127 | - return true; |
|
128 | + if ( $y + $h >= $this->_frame->get_root()->get_page_height() ) { |
|
129 | + return true; |
|
130 | + } |
|
128 | 131 | |
129 | 132 | } |
130 | 133 | |
@@ -157,8 +160,9 @@ discard block |
||
157 | 160 | $delta = $style->length_in_pt($dims, $cb_w); |
158 | 161 | |
159 | 162 | // Handle degenerate case |
160 | - if ( !$this->_frame->get_first_child() ) |
|
161 | - return $this->_min_max_cache = array($delta, $delta,"min" => $delta, "max" => $delta); |
|
163 | + if ( !$this->_frame->get_first_child() ) { |
|
164 | + return $this->_min_max_cache = array($delta, $delta,"min" => $delta, "max" => $delta); |
|
165 | + } |
|
162 | 166 | |
163 | 167 | $low = array(); |
164 | 168 | $high = array(); |
@@ -177,21 +181,24 @@ discard block |
||
177 | 181 | |
178 | 182 | $minmax = $child->get_min_max_width(); |
179 | 183 | |
180 | - if ( in_array( $iter->current()->get_style()->white_space, array("pre", "nowrap") ) ) |
|
181 | - $inline_min += $minmax["min"]; |
|
182 | - else |
|
183 | - $low[] = $minmax["min"]; |
|
184 | + if ( in_array( $iter->current()->get_style()->white_space, array("pre", "nowrap") ) ) { |
|
185 | + $inline_min += $minmax["min"]; |
|
186 | + } else { |
|
187 | + $low[] = $minmax["min"]; |
|
188 | + } |
|
184 | 189 | |
185 | 190 | $inline_max += $minmax["max"]; |
186 | 191 | $iter->next(); |
187 | 192 | |
188 | 193 | } |
189 | 194 | |
190 | - if ( $inline_max > 0 ) |
|
191 | - $high[] = $inline_max; |
|
195 | + if ( $inline_max > 0 ) { |
|
196 | + $high[] = $inline_max; |
|
197 | + } |
|
192 | 198 | |
193 | - if ( $inline_min > 0 ) |
|
194 | - $low[] = $inline_min; |
|
199 | + if ( $inline_min > 0 ) { |
|
200 | + $low[] = $inline_min; |
|
201 | + } |
|
195 | 202 | |
196 | 203 | if ( $iter->valid() ) { |
197 | 204 | list($low[], $high[]) = $iter->current()->get_min_max_width(); |
@@ -207,10 +214,12 @@ discard block |
||
207 | 214 | $width = $style->width; |
208 | 215 | if ( $width !== "auto" && !is_percent($width) ) { |
209 | 216 | $width = $style->length_in_pt($width, $cb_w); |
210 | - if ( $min < $width ) |
|
211 | - $min = $width; |
|
212 | - if ( $max < $width ) |
|
213 | - $max = $width; |
|
217 | + if ( $min < $width ) { |
|
218 | + $min = $width; |
|
219 | + } |
|
220 | + if ( $max < $width ) { |
|
221 | + $max = $width; |
|
222 | + } |
|
214 | 223 | } |
215 | 224 | |
216 | 225 | $min += $delta; |