Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3769432
D717.id1804.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D717.id1804.diff
View Options
diff --git a/page.php b/page.php
--- a/page.php
+++ b/page.php
@@ -196,45 +196,34 @@
* @return array an array where the keys are the metatags' names and the values the metatags' values
*/
function get_all_meta_tags () {
- //Thank you to Michael Knapp and Mariano
- //See http://php.net/manual/en/function.get-meta-tags.php comments
- preg_match_all('/<[\s]*meta[\s]+.*?\b(name|property|itemprop)\b="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $this->data, $match);
- if (isset($match) && is_array($match) && count($match) == 4) {
- $originals = $match[0];
- $names = $match[2];
- $values = $match[3];
-
- if (count($originals) == count($names) && count($names) == count($values)) {
- $metaTags = array();
-
- for ($i = 0, $limiti = count($names) ; $i < $limiti ; $i++) {
- $key = $names[$i];
- $value = $values[$i];
-
- //Sets an unique scalar value, or if several identical tag names are offered, an array of values.
- //Some publishers offer several times the same tag to list several values (see T241).
- if (array_key_exists($key, $metaTags)) {
- $currentValue = $metaTags[$key];
- if ($currentValue == $value) {
- continue;
- }
- if (is_array($currentValue)) {
- $metaTags[$key][] = $value;
- } else {
- //Scalar -> array
- $metaTags[$key] = [ $currentValue, $value ];
- }
- } else {
- $metaTags[$key] = $value;
- }
- }
- }
- }
-
- array_walk($metaTags, [ self, clean_tag ]);
-
- return $metaTags;
- }
+ // Thank you to Bobble Bubble
+ // See http://php.net/manual/en/function.get-meta-tags.php comments
+ $pattern = '
+ ~<\s*meta\s
+
+ # Lookahead to capture type to $1
+ (?=[^>]*?
+ \b(?:name|property|itemprop|http-equiv)\s*=\s*
+ (?|"\s*([^"]*?)\s*"|\'\s*([^\']*?)\s*\'|
+ ([^"\'>]*?)(?=\s*/?\s*>|\s\w+\s*=))
+ )
+
+ # Capture content to $2
+ [^>]*?\bcontent\s*=\s*
+ (?|"\s*([^"]*?)\s*"|\'\s*([^\']*?)\s*\'|
+ ([^"\'>]*?)(?=\s*/?\s*>|\s\w+\s*=))
+ [^>]*>
+
+ ~ix';
+
+ if (!preg_match_all($pattern, $this->data, $match)) {
+ return [];
+ }
+
+ $metaTags = array_combine($match[1], $match[2]);
+ array_walk($metaTags, 'self::clean_tag');
+ return $metaTags;
+ }
/**
* Cleans a tag value (callback for array_walk)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 14:35 (6 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260395
Default Alt Text
D717.id1804.diff (2 KB)
Attached To
Mode
D717: Fix meta tags parser
Attached
Detach File
Event Timeline
Log In to Comment