Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
// $Header: /cvsroot/html2ps/xhtml.tables.inc.php,v 1.9 2006/10/28 12:24:16 Konstantin Exp $
3
 
4
function process_cell(&$sample_html, $offset) {
5
  $r = autoclose_tag($sample_html, $offset,
6
                       "(table|td|th|tr|thead|tbody|tfoot|/td|/th|/table|/thead|/tbody|/tfoot|/tr)",
7
                       array("table" => "process_table"),
8
                       "/td");
9
  return $r;
10
};
11
 
12
function process_header_cell(&$sample_html, $offset) {
13
  return autoclose_tag($sample_html, $offset,
14
                       "(table|td|th|tr|thead|tbody|tfoot|/td|/th|/table|/thead|/tbody|/tfoot|/tr)",
15
                       array("table" => "process_table"),
16
                       "/th");
17
};
18
 
19
function process_cell_without_row(&$html, $offset) {
20
  // Insert missing <tr> tag and fall to the 'process_row'
21
 
22
  // get the LAST tag before offset point; it should be the TD tag outside the row
23
  preg_match("#<[^>]+>$#",substr($html,0,$offset),$matches);
24
 
25
  // Now 'matches' contains the bad TD tag (opening)
26
 
27
  // Insert the TR tag before the TD found
28
  $html = substr_replace($html, "<tr>".$matches[0], $offset - strlen($matches[0]), strlen($matches[0]));
29
 
30
  // Restart row processing from the beginning of inserted TR (not inclusing the TR tag itself!, as it will cause the closing
31
  // tag to be inserted automatically)
32
  //
33
  $r = process_row($html, $offset - strlen($matches[0]) + strlen("<tr>"));
34
 
35
  return $r;
36
};
37
 
38
function process_row(&$sample_html, $offset) {
39
  return autoclose_tag_cleanup($sample_html, $offset,
40
                               "(td|th|thead|tbody|tfoot|tr|/table|/thead|/tbody|/tfoot|/tr)",
41
                               array("td" => "process_cell",
42
                                     "th" => "process_header_cell"),
43
                               "/tr");
44
};
45
 
46
 
47
function process_rowgroup($group, &$sample_html, $offset) {
48
  return autoclose_tag_cleanup($sample_html, $offset,
49
                               "(thead|tbody|tfoot|td|th|tr|/table|/{$group})",
50
                               array("tr" => "process_row",
51
                                     "td" => "process_cell",
52
                                     "th" => "process_header_cell"),
53
                               "/{$group}");
54
}
55
 
56
function process_thead(&$html, $offset) { return process_rowgroup('thead', $html, $offset); }
57
function process_tbody(&$html, $offset) { return process_rowgroup('tbody', $html, $offset); }
58
function process_tfoot(&$html, $offset) { return process_rowgroup('tfoot', $html, $offset); }
59
 
60
function process_col(&$html, $offset) {
61
  // As COL is self-closing tag, we just continue processing
62
  return $offset;
63
}
64
 
65
function process_col_without_colgroup(&$html, $offset) {
66
  // Insert missing <colgroup> tag and fall to the 'process_colgroup'
67
 
68
  // get the LAST tag before offset point; it should be the COL tag outside the COLGROUP
69
  preg_match("#<[^>]+>$#",substr($html,0,$offset),$matches);
70
 
71
  // Now 'matches' contains this COL tag (self-closing)
72
 
73
  // Insert the COLGROUP tag before the COL found
74
  $sample_html = substr_replace($html, "<colgroup>".$matches[0], $offset - strlen($matches[0]), strlen($matches[0]));
75
 
76
  // Restart colgroup processing from the beginning of inserted COLGROUP
77
  return process_colgroup($html, $offset - strlen($matches[0]));
78
}
79
 
80
function process_colgroup(&$html, $offset) {
81
  return autoclose_tag_cleanup($html, $offset,
82
                               "(col|colgroup|thead|tbody|tfoot|tr|td|th|/colgroup)",
83
                               array("col"      => "process_col"),
84
                               "/colgroup");
85
}
86
 
87
function process_table(&$html, $offset) {
88
  return autoclose_tag_cleanup($html, $offset,
89
                               "(col|colgroup|thead|tbody|tfoot|tr|td|th|/table)",
90
                               array("col"      => "process_col_without_colgroup",
91
                                     "colgroup" => "process_colgroup",
92
                                     "thead"    => "process_thead",
93
                                     "tbody"    => "process_tbody",
94
                                     "tfoot"    => "process_tfoot",
95
                                     "tr"       => "process_row",
96
                                     "td"       => "process_cell_without_row",
97
                                     "th"       => "process_cell_without_row"),
98
                               "/table");
99
};
100
 
101
function process_tables(&$sample_html, $offset) {
102
  return autoclose_tag($sample_html, $offset,
103
                       "(table)",
104
                       array("table" => "process_table"),
105
                       "");
106
};
107
 
108
?>