commit | author | age
|
8bd4d9
|
1 |
<?php |
JK |
2 |
class DOMHelper { |
|
3 |
static function ltrim($node) { |
ea5788
|
4 |
while(($node->firstChild instanceof DOMElement) && $node->firstChild->tagName == 'br' && $node->firstChild->getAttribute('auto')=='1') { |
8bd4d9
|
5 |
$node->removeChild($node->firstChild); |
JK |
6 |
} |
|
7 |
|
|
8 |
if($node->firstChild instanceof DOMElement) { |
abe89a
|
9 |
self::ltrim($node->firstChild); |
8bd4d9
|
10 |
} |
JK |
11 |
} |
|
12 |
|
|
13 |
static function rtrim($node) { |
|
14 |
while(($node->lastChild instanceof DOMElement) && $node->lastChild->tagName == 'br' && $node->lastChild->getAttribute('auto')=='1') { |
|
15 |
$node->removeChild($node->lastChild); |
|
16 |
} |
|
17 |
|
|
18 |
if($node->lastChild instanceof DOMElement) { |
|
19 |
self::rtrim($node->lastChild); |
|
20 |
} |
|
21 |
} |
|
22 |
|
|
23 |
static function trim($node) { |
|
24 |
self::ltrim($node); |
|
25 |
self::rtrim($node); |
|
26 |
} |
|
27 |
|
|
28 |
static function cloneNode($node, $saveto, $tag=NULL) { |
|
29 |
if($tag === NULL) { |
|
30 |
$tag = $node->tagName; |
|
31 |
} |
|
32 |
|
|
33 |
$saveto = $saveto->ownerDocument->createElement($tag); |
|
34 |
|
|
35 |
foreach($node->attributes as $attr) { |
|
36 |
if($attr->name == 'color' || $attr->name == 'style' || $attr->name == 'src') { |
|
37 |
$saveto->setAttributeNode($saveto->ownerDocument->importNode($attr, TRUE)); |
|
38 |
} |
|
39 |
} |
|
40 |
|
|
41 |
return $saveto; |
|
42 |
} |
|
43 |
|
|
44 |
static function insertElement($tag, $node) { |
|
45 |
$tag = $node->ownerDocument->createElement($tag); |
|
46 |
$tag->setAttribute('auto', '1'); |
|
47 |
$node->appendChild($tag); |
|
48 |
} |
|
49 |
} |
|
50 |
?> |