| 1 |
lars |
1 |
<?php
|
|
|
2 |
// $Header: /cvsroot/html2ps/box.iframe.php,v 1.14 2006/12/18 19:44:21 Konstantin Exp $
|
|
|
3 |
|
|
|
4 |
class IFrameBox extends InlineBlockBox {
|
|
|
5 |
function &create(&$root, &$pipeline) {
|
|
|
6 |
$box =& new IFrameBox($root, $pipeline);
|
|
|
7 |
$box->readCSS($pipeline->get_current_css_state());
|
|
|
8 |
return $box;
|
|
|
9 |
}
|
|
|
10 |
|
|
|
11 |
// Note that IFRAME width is NOT determined by its content, thus we need to override 'get_min_width' and
|
|
|
12 |
// 'get_max_width'; they should return the constrained frame width.
|
|
|
13 |
function get_min_width(&$context) {
|
|
|
14 |
return $this->get_max_width($context);
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
function get_max_width(&$context) {
|
|
|
18 |
return $this->get_width();
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
function IFrameBox(&$root, $pipeline) {
|
|
|
22 |
$this->InlineBlockBox();
|
|
|
23 |
|
|
|
24 |
// If NO src attribute specified, just return.
|
|
|
25 |
if (!$root->has_attribute('src') ||
|
|
|
26 |
trim($root->get_attribute('src')) == '') {
|
|
|
27 |
return;
|
|
|
28 |
};
|
|
|
29 |
|
|
|
30 |
// Determine the fullly qualified URL of the frame content
|
|
|
31 |
$src = $root->get_attribute('src');
|
|
|
32 |
$url = $pipeline->guess_url($src);
|
|
|
33 |
$data = $pipeline->fetch($url);
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* If framed page could not be fetched return immediately
|
|
|
37 |
*/
|
|
|
38 |
if (is_null($data)) { return; };
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Render only iframes containing HTML only
|
|
|
42 |
*
|
|
|
43 |
* Note that content-type header may contain additional information after the ';' sign
|
|
|
44 |
*/
|
|
|
45 |
$content_type = $data->get_additional_data('Content-Type');
|
|
|
46 |
$content_type_array = explode(';', $content_type);
|
|
|
47 |
if ($content_type_array[0] != "text/html") { return; };
|
|
|
48 |
|
|
|
49 |
$html = $data->get_content();
|
|
|
50 |
|
|
|
51 |
// Remove control symbols if any
|
|
|
52 |
$html = preg_replace('/[\x00-\x07]/', "", $html);
|
|
|
53 |
$converter = Converter::create();
|
|
|
54 |
$html = $converter->to_utf8($html, $data->detect_encoding());
|
|
|
55 |
$html = html2xhtml($html);
|
|
|
56 |
$tree = TreeBuilder::build($html);
|
|
|
57 |
|
|
|
58 |
// Save current stylesheet, as each frame may load its own stylesheets
|
|
|
59 |
//
|
|
|
60 |
$pipeline->pushCSS();
|
|
|
61 |
$css =& $pipeline->get_current_css();
|
|
|
62 |
$css->scan_styles($tree, $pipeline);
|
|
|
63 |
|
|
|
64 |
$frame_root = traverse_dom_tree_pdf($tree);
|
|
|
65 |
$box_child =& create_pdf_box($frame_root, $pipeline);
|
|
|
66 |
$this->add_child($box_child);
|
|
|
67 |
|
|
|
68 |
// Restore old stylesheet
|
|
|
69 |
//
|
|
|
70 |
$pipeline->pop_css();
|
|
|
71 |
|
|
|
72 |
$pipeline->pop_base_url();
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
?>
|