forked from radgeek/feedwordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feedwordpresshtml.class.php
87 lines (78 loc) · 1.96 KB
/
feedwordpresshtml.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
class FeedWordPressHTML {
static function attributeRegex ($tag, $attr) {
return ":(
(<($tag)\s+[^>]*)
($attr)=
)
(
\s*(\"|')
(((?!\\6).)*)
\\6([^>]*>)
|
\s*(((?!/>)[^\s>])*)
([^>]*>)
)
:ix";
} /* function FeedWordPressHTML::attributeRegex () */
static function attributeMatch ($matches) {
for ($i = 0; $i <= 12; $i++) :
if (!isset($matches[$i])) :
$matches[$i] = '';
endif;
endfor;
$suffix = $matches[12].$matches[9];
$value = $matches[10].$matches[7];
return array(
"tag" => $matches[3],
"attribute" => $matches[4],
"value" => $value,
"quote" => $matches[6],
"prefix" => $matches[1].$matches[6],
"suffix" => $matches[6].$suffix,
"before_attribute" => $matches[2],
"after_attribute" => $suffix,
);
} /* function FeedWordPressHTML::attributeMatch () */
static function tagWithAttributeRegex ($tag, $attr, $value, $closing = true) {
return ":(
(<($tag)\s+[^>]*)
($attr)=
)
(
\s*(\"|')
((((?!\\6).)*\s)*($value)(\s((?!\\6).)*)*)
\\6([^>]*>)
|
\s*((?!/>)($value))
([^>]*>)
)".($closing ? "
(((?!</($tag)>).)*)
(</($tag)>)
" : "")."
:ix";
} /* FeedWordPressHTML::tagWithAttributeRegex () */
static function tagWithAttributeMatch ($matches, $closing = true) {
for ($i = 0; $i <= 21; $i++) :
if (!isset($matches[$i])) :
$matches[$i] = '';
endif;
endfor;
$suffix = $matches[16].$matches[13];
$value = $matches[14].$matches[7];
return array(
"full" => $matches[0],
"tag" => $matches[3],
"attribute" => $matches[4],
"value" => $value,
"quote" => $matches[6],
"prefix" => $matches[1].$matches[6],
"suffix" => $matches[6].$suffix,
"before_attribute" => $matches[2],
"after_attribute" => $suffix,
"open_tag" => $matches[1].$matches[6].$value.$matches[6].$suffix,
"content" => ($closing ? $matches[17] : NULL),
"close_tag" => ($closing ? $matches[20] : NULL),
);
} /* FeedWordPressHTML::tagWithAttributeMatch () */
} /* class FeedWordPressHTML */