♻️ Merge the twitter card and opengraph plugins
This commit is contained in:
parent
e76f511738
commit
89caf537b9
15 changed files with 10 additions and 200 deletions
|
@ -7,8 +7,7 @@ class pluginOpenGraph extends Plugin
|
||||||
{
|
{
|
||||||
// Fields and default values for the database of this plugin
|
// Fields and default values for the database of this plugin
|
||||||
$this->dbFields = array(
|
$this->dbFields = array(
|
||||||
'defaultImage' => '',
|
'defaultImage' => ''
|
||||||
'fbAppId' => ''
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,12 +21,6 @@ class pluginOpenGraph extends Plugin
|
||||||
$html .= '<span class="tip">' . $L->g('set-a-default-image-for-content') . '</span>';
|
$html .= '<span class="tip">' . $L->g('set-a-default-image-for-content') . '</span>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
$html .= '<div>';
|
|
||||||
$html .= '<label>' . $L->get('Facebook App ID') . '</label>';
|
|
||||||
$html .= '<input name="fbAppId" type="text" dir="auto" value="' . $this->getValue('fbAppId') . '" placeholder="App ID">';
|
|
||||||
$html .= '<span class="tip">' . $L->g('set-your-facebook-app-id') . '</span>';
|
|
||||||
$html .= '</div>';
|
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +39,8 @@ class pluginOpenGraph extends Plugin
|
||||||
'description' => $site->description(),
|
'description' => $site->description(),
|
||||||
'url' => $site->url(),
|
'url' => $site->url(),
|
||||||
'image' => '',
|
'image' => '',
|
||||||
'siteName' => $site->title()
|
'siteName' => $site->title(),
|
||||||
|
'card' => 'summary',
|
||||||
);
|
);
|
||||||
|
|
||||||
switch ($WHERE_AM_I) {
|
switch ($WHERE_AM_I) {
|
||||||
|
@ -81,6 +75,12 @@ 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:site_name" content="' . $og['siteName'] . '">' . PHP_EOL;
|
$html .= '<meta property="og:site_name" content="' . $og['siteName'] . '">' . PHP_EOL;
|
||||||
|
|
||||||
|
$html .= PHP_EOL . '<!-- Twitter Cards -->' . PHP_EOL;
|
||||||
|
$html .= '<meta property="twitter:card" content="' . $og['card'] . '">' . PHP_EOL;
|
||||||
|
$html .= '<meta property="twitter:site" content="' . $og['siteName'] . '">' . PHP_EOL;
|
||||||
|
$html .= '<meta property="twitter:title" content="' . $og['title'] . '">' . PHP_EOL;
|
||||||
|
$html .= '<meta property="twitter:description" content="' . $og['description'] . '">' . PHP_EOL;
|
||||||
|
|
||||||
// If the page doesn't have a coverImage try to get an image from the HTML content
|
// 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
|
// Get the image from the content
|
||||||
|
@ -95,9 +95,7 @@ class pluginOpenGraph extends Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
$html .= '<meta property="og:image" content="' . $og['image'] . '">' . PHP_EOL;
|
$html .= '<meta property="og:image" content="' . $og['image'] . '">' . PHP_EOL;
|
||||||
if (Text::isNotEmpty($this->getValue('fbAppId'))) {
|
$html .= '<meta property="twitter:image" content="' . $og['image'] . '">' . PHP_EOL;
|
||||||
$html .= '<meta property="fb:app_id" content="' . $this->getValue('fbAppId') . '">' . PHP_EOL;
|
|
||||||
}
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
{
|
|
||||||
"default-image": "Standardbillede",
|
|
||||||
"plugin-data": {
|
|
||||||
"description": "Med Twitter kort kan du vedhæfte vigtige billeder, videoer og medieoplevelser til tweets, hvilket hjælper med at få trafik på din hjemmeside.",
|
|
||||||
"name": "Twitter Cards"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Twitter Cards",
|
|
||||||
"description": "Twitter Cards hängt Medien wie Bilder oder Videos an einen Tweet, wenn ein Link der Website auf Twitter geteilt wird."
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Twitter Cards",
|
|
||||||
"description": "Twitter Cards hängt Medien wie Bilder oder Videos an einen Tweet, wenn ein Link der Website auf Twitter geteilt wird."
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Twitter Cards",
|
|
||||||
"description": "With Twitter Cards, you can attach rich photos, videos and media experiences to Tweets, helping to drive traffic to your website."
|
|
||||||
},
|
|
||||||
"default-image": "Default image"
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Twitter Cards",
|
|
||||||
"description": "Con las tarjetas de Twitter puedes adjuntar fotos, videos y experiencias multimedia a tweets."
|
|
||||||
},
|
|
||||||
"default-image": "Imagen predeterminada"
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Twitter Cards",
|
|
||||||
"description": "بوسیله Twitter Cards ، شما میتوانید تصاویر، ویدئو و تجربیات رسانه ای را به توئیت پیوست کرده، و با اینکار کمکی میشود تا ترافیک بیشتری به سمت وبسایت شما روانه شود."
|
|
||||||
},
|
|
||||||
"default-image": "تصویر پیشفرض"
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Cartes Twitter",
|
|
||||||
"description": "Les Cartes Twitter sont des protocoles qui vous permettent d’attacher des photos, des vidéos et autres médias interactifs à vos tweets, cela vas vous aider à générer du trafic vers votre site."
|
|
||||||
},
|
|
||||||
"default-image": "Image par défaut."
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Twitter Cards",
|
|
||||||
"description": "Con Twitter Cards, puoi aggiungere foto, video e media ai tuoi tweet, aiutando a guidare il traffico sul tuo sito."
|
|
||||||
},
|
|
||||||
"default-image": "Immagine predefinita"
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Twitter Cards",
|
|
||||||
"description": "With Twitter Cards, you can attach rich photos, videos and media experiences to Tweets, helping to drive traffic to your website."
|
|
||||||
},
|
|
||||||
"default-image": "Default image"
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Twitter Cards",
|
|
||||||
"description": "Met Twitter Cards kunnen foto's, video's and media-ervaringen worden gekoppeld aan tweets om zo bezoekers naar deze website te trekken."
|
|
||||||
},
|
|
||||||
"default-image": "Standaardafbeelding"
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Twitter Cards",
|
|
||||||
"description": "C Twitter Cards вы можете добавить фото, видео и медиа к твиттам, тем самым привлекая дополнительный трафик для вашего сайта."
|
|
||||||
},
|
|
||||||
"default-image": "Изображение по умолчанию"
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Twitter Cards",
|
|
||||||
"description": "Twitter Kartları ile zengin fotoğraf, video ve medya deneyimlerini Tweetlere ekleyebilir ve web sitenize trafik çekmenize yardımcı olabilirsiniz."
|
|
||||||
},
|
|
||||||
"default-image": "Varsayılan resim"
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"author": "Koblog",
|
|
||||||
"email": "",
|
|
||||||
"website": "https://plugins.koblog.com",
|
|
||||||
"version": "kb_0.0.1",
|
|
||||||
"releaseDate": "2024-08-23",
|
|
||||||
"license": "MIT",
|
|
||||||
"compatible": "kb_0.0.1",
|
|
||||||
"notes": ""
|
|
||||||
}
|
|
|
@ -1,85 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
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 $L;
|
|
||||||
|
|
||||||
$html = '<div>';
|
|
||||||
$html .= '<label>' . $L->get('Default image') . '</label>';
|
|
||||||
$html .= '<input id="jsdefaultImage" name="defaultImage" type="text" dir="auto" value="' . $this->getValue('defaultImage') . '" placeholder="https://">';
|
|
||||||
$html .= '</div>';
|
|
||||||
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function siteHead()
|
|
||||||
{
|
|
||||||
global $url;
|
|
||||||
global $site;
|
|
||||||
global $WHERE_AM_I;
|
|
||||||
global $content;
|
|
||||||
global $page;
|
|
||||||
|
|
||||||
$data = array(
|
|
||||||
'card' => 'summary',
|
|
||||||
'site' => '',
|
|
||||||
'title' => $site->title(),
|
|
||||||
'description' => $site->description(),
|
|
||||||
'image' => ''
|
|
||||||
);
|
|
||||||
|
|
||||||
switch ($WHERE_AM_I) {
|
|
||||||
// The user filter by page
|
|
||||||
case 'page':
|
|
||||||
$data['title'] = $page->title();
|
|
||||||
$data['description'] = $page->description();
|
|
||||||
$data['image'] = $page->coverImage($absolute = true);
|
|
||||||
|
|
||||||
$pageContent = $page->content();
|
|
||||||
break;
|
|
||||||
|
|
||||||
// The user is in the homepage
|
|
||||||
default:
|
|
||||||
$pageContent = '';
|
|
||||||
// The image it's from the first page
|
|
||||||
if (isset($content[0])) {
|
|
||||||
$data['image'] = $content[0]->coverImage($absolute = true);
|
|
||||||
$pageContent = $content[0]->content();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$html = PHP_EOL . '<!-- Twitter Cards -->' . PHP_EOL;
|
|
||||||
$html .= '<meta property="twitter:card" content="' . $data['card'] . '">' . PHP_EOL;
|
|
||||||
$html .= '<meta property="twitter:site" content="' . $data['site'] . '">' . PHP_EOL;
|
|
||||||
$html .= '<meta property="twitter:title" content="' . $data['title'] . '">' . PHP_EOL;
|
|
||||||
$html .= '<meta property="twitter:description" content="' . $data['description'] . '">' . PHP_EOL;
|
|
||||||
|
|
||||||
// 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 = DOM::getFirstImage($pageContent);
|
|
||||||
if ($src !== false) {
|
|
||||||
$data['image'] = $src;
|
|
||||||
} else {
|
|
||||||
if (Text::isNotEmpty($this->getValue('defaultImage'))) {
|
|
||||||
$data['image'] = $this->getValue('defaultImage');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$html .= '<meta property="twitter:image" content="' . $data['image'] . '">' . PHP_EOL;
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue