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