Skip to content

Commit

Permalink
Merge pull request #72 from gavinclive/meta-value
Browse files Browse the repository at this point in the history
Add get_meta_value
  • Loading branch information
shweshi authored Dec 15, 2020
2 parents e381710 + 33c2a74 commit 28533bf
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/OpenGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public function fetch($url, $allMeta = null, $lang = null, $options = LIBXML_NOW
$metaproperty = ($tag->hasAttribute('property')) ? $tag->getAttribute('property') : $tag->getAttribute('name');
if (!$allMeta && $metaproperty && strpos($tag->getAttribute('property'), 'og:') === 0) {
$key = strtr(substr($metaproperty, 3), '-', '_');
$value = $tag->getAttribute('content');
$value = $this->get_meta_value($tag);
}
if ($allMeta && $metaproperty) {
$key = (strpos($metaproperty, 'og:') === 0) ? strtr(substr($metaproperty, 3), '-', '_') : $metaproperty;
$value = $tag->getAttribute('content');
$value = $this->get_meta_value($tag);
}
if (!empty($key)) {
$metadata[$key] = $value;
Expand Down Expand Up @@ -110,4 +110,17 @@ protected function verify_image_url($url)
return false;
}
}

protected function get_meta_value($tag)
{
if (!empty($tag->getAttribute('content'))) {
$value = $tag->getAttribute('content');
} elseif (!empty($tag->getAttribute('value'))) {
$value = $tag->getAttribute('value');
} else {
$value = '';
}

return $value;
}
}

0 comments on commit 28533bf

Please sign in to comment.