diff --git a/bl-kernel/helpers/dom.class.php b/bl-kernel/helpers/dom.class.php
index d655fb8a..3917035a 100644
--- a/bl-kernel/helpers/dom.class.php
+++ b/bl-kernel/helpers/dom.class.php
@@ -4,6 +4,8 @@ class DOM {
public static function getFirstImage($content)
{
+ // Disable warning
+ libxml_use_internal_errors();
$dom = new DOMDocument();
$dom->loadHTML(''.$content);
$finder = new DomXPath($dom);
diff --git a/bl-plugins/opengraph/plugin.php b/bl-plugins/opengraph/plugin.php
index ed8b357c..0642bc4c 100644
--- a/bl-plugins/opengraph/plugin.php
+++ b/bl-plugins/opengraph/plugin.php
@@ -89,7 +89,7 @@ class pluginOpenGraph extends Plugin {
// If the page doesn't have a coverImage try to get an image from the HTML content
if (empty($og['image'])) {
// Get the image from the content
- $src = $this->getImage($content);
+ $src = DOM::getFirstImage($content);
if ($src!==false) {
$og['image'] = $src;
} else {
@@ -103,24 +103,4 @@ class pluginOpenGraph extends Plugin {
return $html;
}
- // Returns the first image from the HTML content
- private function getImage($content)
- {
- $dom = new DOMDocument();
- $dom->loadHTML(''.$content);
- $finder = new DomXPath($dom);
-
- $images = $finder->query("//img");
-
- if($images->length>0) {
- // First image from the list
- $image = $images->item(0);
- // Get value from attribute src
- $imgSrc = $image->getAttribute('src');
- // Returns the image src
- return $imgSrc;
- }
-
- return false;
- }
}
\ No newline at end of file
diff --git a/bl-plugins/twitter-cards/plugin.php b/bl-plugins/twitter-cards/plugin.php
index 2456406c..8a9e0def 100644
--- a/bl-plugins/twitter-cards/plugin.php
+++ b/bl-plugins/twitter-cards/plugin.php
@@ -83,7 +83,7 @@ class pluginTwitterCards extends Plugin {
// If the page doesn't have a coverImage try to get an image from the HTML content
if( empty($data['image']) ) {
// Get the image from the content
- $src = $this->getImage($content);
+ $src = DOM::getFirstImage($content);
if ($src!==false) {
$data['image'] = $src;
} else {
@@ -96,25 +96,4 @@ class pluginTwitterCards extends Plugin {
$html .= ''.PHP_EOL;
return $html;
}
-
- // Returns the first image from the HTML content
- private function getImage($content)
- {
- $dom = new DOMDocument();
- $dom->loadHTML(''.$content);
- $finder = new DomXPath($dom);
-
- $images = $finder->query("//img");
-
- if($images->length>0) {
- // First image from the list
- $image = $images->item(0);
- // Get value from attribute src
- $imgSrc = $image->getAttribute('src');
- // Returns the image src
- return $imgSrc;
- }
-
- return false;
- }
}
\ No newline at end of file