|
6 | 6 |
|
7 | 7 | class Loader
|
8 | 8 | {
|
| 9 | + private $entities; |
| 10 | + |
| 11 | + public function __construct(array $entities = null) |
| 12 | + { |
| 13 | + if ($entities === null) { |
| 14 | + // get all HTML entities (minus those for XML parsing) |
| 15 | + $entities = get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES, 'UTF-8'); |
| 16 | + unset($entities['<'], $entities['>'], $entities['&']); |
| 17 | + } |
| 18 | + |
| 19 | + $this->entities = $entities; |
| 20 | + } |
| 21 | + |
9 | 22 | public function loadXmlFile($path)
|
10 | 23 | {
|
11 | 24 | return $this->loadXmlString(file_get_contents($path));
|
12 | 25 | }
|
13 | 26 |
|
14 | 27 | public function loadXmlString($html)
|
15 | 28 | {
|
16 |
| - // fix invalid markup of help link in footer of outdated ViewVC versions |
| 29 | + // fix invalid markup of outdated ViewVC versions |
| 30 | + // - help link in footer not terminated |
| 31 | + // - selected branch/tag in CVS "sticky tag" dropdown has not attribute value |
| 32 | + // - clear button for selected branch/tag has no trailing slash |
17 | 33 | $html = str_replace('Help</strong></td>', 'Help</a></strong></td>', $html);
|
| 34 | + $html = str_replace('selected>', 'selected="selected">', $html); |
| 35 | + $html = preg_replace('#<input([^\/]+)>#', '<input$1 />', $html); |
18 | 36 |
|
19 |
| - // replace unneeded HTML entities |
20 |
| - $html = str_replace(' ', ' ', $html); |
| 37 | + // replace named HTML entities with their UTF-8 value |
| 38 | + $html = str_replace(array_values($this->entities), array_keys($this->entities), $html); |
21 | 39 |
|
22 | 40 | // clean up namespace declaration
|
23 | 41 | $html = str_replace('xmlns="', 'ns="', $html);
|
|
0 commit comments