Minor changes on plugin opengraph

This commit is contained in:
dignajar 2016-06-06 21:11:19 -03:00
parent c87ce7daad
commit bd184ac380
1 changed files with 11 additions and 10 deletions

View File

@ -2,7 +2,7 @@
class pluginOpenGraph extends Plugin { class pluginOpenGraph extends Plugin {
// Returns the first image that is in the content // Returns the first image from the HTML content
private function getImage($content) private function getImage($content)
{ {
$dom = new DOMDocument(); $dom = new DOMDocument();
@ -41,6 +41,7 @@ class pluginOpenGraph extends Plugin {
switch($Url->whereAmI()) switch($Url->whereAmI())
{ {
// The user filter by post
case 'post': case 'post':
$og['type'] = 'article'; $og['type'] = 'article';
$og['title'] = $Post->title().' | '.$og['title']; $og['title'] = $Post->title().' | '.$og['title'];
@ -51,6 +52,7 @@ class pluginOpenGraph extends Plugin {
$content = $Post->content(); $content = $Post->content();
break; break;
// The user filter by page
case 'page': case 'page':
$og['type'] = 'article'; $og['type'] = 'article';
$og['title'] = $Page->title().' | '.$og['title']; $og['title'] = $Page->title().' | '.$og['title'];
@ -61,7 +63,9 @@ class pluginOpenGraph extends Plugin {
$content = $Page->content(); $content = $Page->content();
break; break;
// The user is in the homepage
default: default:
// The image it's from the first post
if(isset($posts[0])) { if(isset($posts[0])) {
$og['image'] = $posts[0]->coverImage(false); $og['image'] = $posts[0]->coverImage(false);
$content = $posts[0]->content(); $content = $posts[0]->content();
@ -77,21 +81,18 @@ class pluginOpenGraph extends Plugin {
$html .= '<meta property="og:url" content="'.$og['url'].'">'.PHP_EOL; $html .= '<meta property="og:url" content="'.$og['url'].'">'.PHP_EOL;
$html .= '<meta property="og:siteName" content="'.$og['siteName'].'">'.PHP_EOL; $html .= '<meta property="og:siteName" content="'.$og['siteName'].'">'.PHP_EOL;
$domain = trim($Site->domain(),'/'); // If the post o page doesn't have a coverImage try to get an image from the HTML content
$urlImage = $domain.HTML_PATH_UPLOADS; if($og['image']===false) {
// If the post o page doesn't have a coverImage try to get it from the content
if($og['image']===false)
{
// Get the image from the content // Get the image from the content
$src = $this->getImage( $content ); $src = $this->getImage( $content );
if($src!==false) { if($src!==false) {
$html .= '<meta property="og:image" content="'.$urlImage.str_replace(HTML_PATH_UPLOADS,'',$src).'">'.PHP_EOL; $html .= '<meta property="og:image" content="'.DOMAIN.$src.'">'.PHP_EOL;
} }
} }
else else {
{ $html .= '<meta property="og:image" content="'.DOMAIN_UPLOADS.$og['image'].'">'.PHP_EOL;
$html .= '<meta property="og:image" content="'.$urlImage.$og['image'].'">'.PHP_EOL;
} }
return $html; return $html;