diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php
index 47de9599..af5b5b9a 100644
--- a/bl-kernel/functions.php
+++ b/bl-kernel/functions.php
@@ -35,7 +35,7 @@ function buildPage($key) {
$contentRaw = $page->contentRaw();
$content = Text::pre2htmlentities($contentRaw); // Parse pre code with htmlentities
$content = $Parsedown->text($content); // Parse Markdown
- $content = Text::imgRel2Abs($content, HTML_PATH_UPLOADS); // Parse img src relative to absolute.
+ $content = Text::imgRel2Abs($content, DOMAIN_UPLOADS); // Parse img src relative to absolute (with domain)
$page->setField('content', $content, true);
// Pagebrake
diff --git a/bl-kernel/helpers/text.class.php b/bl-kernel/helpers/text.class.php
index 03eba173..87f9b20b 100644
--- a/bl-kernel/helpers/text.class.php
+++ b/bl-kernel/helpers/text.class.php
@@ -220,8 +220,8 @@ class Text {
public static function imgRel2Abs($string, $base)
{
- $pattern = "/]*) src=\"([^http|https|ftp|\/\/][^\"]*)\"/";
- $replace = "]*)(src)=\"(?!https:)(?!http:)(?!\/\/)(.*?)\"(.*?)>/';
+ $replace = "";
return preg_replace($pattern, $replace, $string);
}
diff --git a/bl-plugins/opengraph/plugin.php b/bl-plugins/opengraph/plugin.php
index ea66372e..13900734 100644
--- a/bl-plugins/opengraph/plugin.php
+++ b/bl-plugins/opengraph/plugin.php
@@ -2,25 +2,32 @@
class pluginOpenGraph extends Plugin {
- // Returns the first image from the HTML content
- private function getImage($content)
+ public function init()
{
- $dom = new DOMDocument();
- $dom->loadHTML(''.$content);
- $finder = new DomXPath($dom);
+ // Fields and default values for the database of this plugin
+ $this->dbFields = array(
+ 'defaultImage'=>''
+ );
+ }
- $images = $finder->query("//img");
+ public function form()
+ {
+ global $Language;
- 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;
+ $html = '
';
+ $html .= '';
+ $html .= '';
+ $html .= '
';
+
+ return $html;
}
public function siteHead()
@@ -41,7 +48,7 @@ class pluginOpenGraph extends Plugin {
'siteName' =>$Site->title()
);
- switch($WHERE_AM_I) {
+ switch ($WHERE_AM_I) {
// The user filter by page
case 'page':
$og['type'] = 'article';
@@ -73,11 +80,13 @@ class pluginOpenGraph extends Plugin {
$html .= ''.PHP_EOL;
// If the page doesn't have a coverImage try to get an image from the HTML content
- if( empty($og['image']) ) {
+ if (empty($og['image'])) {
// Get the image from the content
$src = $this->getImage($content);
- if($src!==false) {
- $og['image'] = DOMAIN.$src;
+ if ($src!==false) {
+ $og['image'] = $src;
+ } else {
+ $og['image'] = DOMAIN_UPLOADS.$this->getValue('defaultImage');
}
}
@@ -85,4 +94,25 @@ 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 0cdfe143..8c9bba7a 100644
--- a/bl-plugins/twitter-cards/plugin.php
+++ b/bl-plugins/twitter-cards/plugin.php
@@ -2,6 +2,34 @@
class pluginTwitterCards extends Plugin {
+ public function init()
+ {
+ // Fields and default values for the database of this plugin
+ $this->dbFields = array(
+ 'defaultImage'=>''
+ );
+ }
+
+ public function form()
+ {
+ global $Language;
+
+ $html = '
';
+ $html .= '';
+ $html .= '';
+ $html .= '
';
+
+ return $html;
+ }
+
public function siteHead()
{
global $Url;
@@ -49,8 +77,10 @@ class pluginTwitterCards extends Plugin {
if( empty($data['image']) ) {
// Get the image from the content
$src = $this->getImage($content);
- if($src!==false) {
- $data['image'] = DOMAIN.$src;
+ if ($src!==false) {
+ $og['image'] = $src;
+ } else {
+ $og['image'] = DOMAIN_UPLOADS.$this->getValue('defaultImage');
}
}