social 0.9: Add fallback image

This commit is contained in:
onli 2016-08-12 15:53:45 +02:00
parent 4ea6cba371
commit e4a03e58a7
6 changed files with 33 additions and 7 deletions

View file

@ -1,3 +1,7 @@
0.9:
* Add option to set a fallback image for
twitter and facebook tags
0.8:
* set twitter card type to summary
* Fix: Headertags were not emitted

View file

@ -15,4 +15,6 @@
@define('PLUGIN_EVENT_SOCIAL_TWITTER_DESC', 'Twittername, der am Ende des Tweets angehängtwerden soll ("none" deaktiviert dies).');
@define('PLUGIN_EVENT_SOCIAL_LANG_DESC', 'Sprache der Sharebuttons.');
@define('PLUGIN_EVENT_SOCIAL_BACKEND', 'Backend für Zähler');
@define('PLUGIN_EVENT_SOCIAL_BACKEND_DESC', 'URL für ein Shariff-Backend, mit dem einige der Buttons (u.a. Facebook) anzeigen wie oft der Artikel geteilt wurde. "none" deaktiviert den Zähler. Standard: "https://onli.columba.uberspace.de/s9y_shariff"');
@define('PLUGIN_EVENT_SOCIAL_BACKEND_DESC', 'URL für ein Shariff-Backend, mit dem einige der Buttons (u.a. Facebook) anzeigen wie oft der Artikel geteilt wurde. "none" deaktiviert den Zähler. Standard: "https://onli.columba.uberspace.de/s9y_shariff"');
@define('PLUGIN_EVENT_SOCIAL_IMAGE', 'Fallback-Bild');
@define('PLUGIN_EVENT_SOCIAL_IMAGE_DESC', 'Ein Bild, das auf Twitter und Facebook angezeigt wird wenn der Eintrag kein eigenes Bild erhält. "none" deaktiviert es.');

View file

@ -15,4 +15,6 @@
@define('PLUGIN_EVENT_SOCIAL_TWITTER_DESC', 'Username of the twitter user that shall be mentioned (set to "none" to disable.');
@define('PLUGIN_EVENT_SOCIAL_LANG_DESC', 'Language of the share buttons');
@define('PLUGIN_EVENT_SOCIAL_BACKEND', 'Backend for share counter');
@define('PLUGIN_EVENT_SOCIAL_BACKEND_DESC', 'URL to a shariff backend, that provides some buttons (like Facebook) with a share counter. Set to "none" to deacivate. Default: "https://onli.columba.uberspace.de/s9y_shariff"');
@define('PLUGIN_EVENT_SOCIAL_BACKEND_DESC', 'URL to a shariff backend, that provides some buttons (like Facebook) with a share counter. Set to "none" to deacivate. Default: "https://onli.columba.uberspace.de/s9y_shariff"');
@define('PLUGIN_EVENT_SOCIAL_IMAGE', 'Fallback Image');
@define('PLUGIN_EVENT_SOCIAL_IMAGE_DESC', 'Image shown on Twitter and Facebok if the entry contains no own image. Set to "none" to deacivate.');

View file

@ -16,3 +16,5 @@
@define('PLUGIN_EVENT_SOCIAL_LANG_DESC', 'Sprache der Sharebuttons.');
@define('PLUGIN_EVENT_SOCIAL_BACKEND', 'Backend für Zähler');
@define('PLUGIN_EVENT_SOCIAL_BACKEND_DESC', 'URL für ein Shariff-Backend, mit dem einige der Buttons (u.a. Facebook) anzeigen wie oft der Artikel geteilt wurde. "none" deaktiviert den Zähler. Standard: "https://onli.columba.uberspace.de/s9y_shariff"');
@define('PLUGIN_EVENT_SOCIAL_IMAGE', 'Fallback-Bild');
@define('PLUGIN_EVENT_SOCIAL_IMAGE_DESC', 'Ein Bild, das auf Twitter und Facebook angezeigt wird wenn der Eintrag kein eigenes Bild erhält. "none" deaktiviert es.');

View file

@ -16,3 +16,5 @@
@define('PLUGIN_EVENT_SOCIAL_LANG_DESC', 'Language of the share buttons');
@define('PLUGIN_EVENT_SOCIAL_BACKEND', 'Backend for share counter');
@define('PLUGIN_EVENT_SOCIAL_BACKEND_DESC', 'URL to a shariff backend, that provides some buttons (like Facebook) with a share counter. Set to "none" to deacivate. Default: "https://onli.columba.uberspace.de/s9y_shariff"');
@define('PLUGIN_EVENT_SOCIAL_IMAGE', 'Fallback Image');
@define('PLUGIN_EVENT_SOCIAL_IMAGE_DESC', 'Image shown on Twitter and Facebok if the entry contains no own image. Set to "none" to deacivate.');

View file

@ -16,7 +16,7 @@ class serendipity_event_social extends serendipity_event {
$propbag->add('description', PLUGIN_EVENT_SOCIAL_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'onli, Matthias Mees');
$propbag->add('version', '0.8');
$propbag->add('version', '0.9');
$propbag->add('requirements', array(
'serendipity' => '2.0'
));
@ -26,7 +26,7 @@ class serendipity_event_social extends serendipity_event {
'frontend_header' => true));
$propbag->add('groups', array('FRONTEND_EXTERNAL_SERVICES'));
$propbag->add('configuration', array('services', 'theme', 'overview', 'twitter_via', 'lang', 'backend'));
$propbag->add('configuration', array('services', 'theme', 'overview', 'twitter_via', 'social_image', 'lang', 'backend'));
}
function generate_content(&$title) {
@ -76,6 +76,13 @@ class serendipity_event_social extends serendipity_event {
$propbag->add('description', PLUGIN_EVENT_SOCIAL_BACKEND_DESC);
$propbag->add('default', 'https://onli.columba.uberspace.de/s9y_shariff/');
break;
case 'social_image':
$propbag->add('type', 'media');
$propbag->add('name', PLUGIN_EVENT_SOCIAL_IMAGE);
$propbag->add('description', PLUGIN_EVENT_SOCIAL_IMAGE_DESC);
$propbag->add('default', '');
break;
}
return true;
}
@ -135,6 +142,8 @@ class serendipity_event_social extends serendipity_event {
// we iterate over the internal smarty object to see which entry we are printing. This is hacky and should be improved
$entry = (current($eventData['smarty']->tpl_vars['entries']->value)['entries'][0]);
$blogURL = 'http' . ($_SERVER['HTTPS'] ? 's' : '') . '://' . $_SERVER['HTTP_HOST'];
echo '<!--serendipity_event_shariff-->' . "\n";
echo '<meta name="twitter:card" content="summary" />' . "\n";
@ -142,17 +151,22 @@ class serendipity_event_social extends serendipity_event {
echo '<meta property="og:description" content="' . substr(strip_tags($entry['body']), 0, 200) . '..." />' . "\n";
echo '<meta property="og:type" content="article" />' . "\n";
echo '<meta property="og:site_name" content="' . $serendipity['blogTitle'] . '" />' . "\n";
echo '<meta property="og:url" content="http' . ($_SERVER['HTTPS'] ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . serendipity_specialchars($_SERVER['REQUEST_URI']) . '" />' . "\n";
echo '<meta property="og:url" content="'. $blogURL . serendipity_specialchars($_SERVER['REQUEST_URI']) . '" />' . "\n";
$social_image = $blogURL . $this->get_config('social_image', '');
// This is searching for the first image in an entry to use as facebook article image.
// A better approach would be to register in the entry editor when an image was added
if (preg_match('@<img.*src=["\'](.+)["\']@imsU', $entry['body'] . $entry['extended'], $im)) {
if (preg_match('/^http/i', $im[1])) {
echo '<meta property="og:image" content="' . $im[1] . '" />' . "\n";
$social_image = $im[1];
} else {
echo '<meta property="og:image" content="http' . ($_SERVER['HTTPS'] ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $im[1] . '" />' . "\n";
$social_image = $blogURL . $im[1];
}
}
if ($social_image != $blogURL && $social_image != $blogURL . 'none') {
echo '<meta property="og:image" content="' . $social_image . '" />' . "\n";
}
}
default:
return false;