diff --git a/lib/default.php b/lib/default.php
index dd038236b2..150399bb46 100644
--- a/lib/default.php
+++ b/lib/default.php
@@ -349,7 +349,7 @@ $default =
'DirectMessage' => array(),
'EmailAuthentication' => array(),
'Event' => array(),
- 'Oembed' => array(),
+ 'Embed' => array(),
'OpenID' => array(),
'OpportunisticQM' => array(),
'OStatus' => array(),
diff --git a/plugins/Oembed/CONFIGURE b/plugins/Embed/CONFIGURE
similarity index 100%
rename from plugins/Oembed/CONFIGURE
rename to plugins/Embed/CONFIGURE
diff --git a/plugins/Oembed/OembedPlugin.php b/plugins/Embed/EmbedPlugin.php
similarity index 82%
rename from plugins/Oembed/OembedPlugin.php
rename to plugins/Embed/EmbedPlugin.php
index 668f3bfd18..7557fc0adc 100644
--- a/plugins/Oembed/OembedPlugin.php
+++ b/plugins/Embed/EmbedPlugin.php
@@ -15,13 +15,14 @@
// along with GNU social. If not, see .
/**
- * OembedPlugin implementation for GNU social
+ * OEmbed and OpenGraph implementation for GNU social
*
* @package GNUsocial
* @author Stephen Paul Weber
* @author hannes
* @author Mikael Nordfeldth
* @author Diogo Cordeiro
+ * @author Miguel Dantas
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
@@ -29,29 +30,31 @@
defined('GNUSOCIAL') || die();
/**
- * Base class for the oEmbed plugin that does most of the heavy lifting to get
+ * Base class for the Embed plugin that does most of the heavy lifting to get
* and display representations for remote content.
*
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
-class OembedPlugin extends Plugin
+class EmbedPlugin extends Plugin
{
- const PLUGIN_VERSION = '2.0.1';
+ const PLUGIN_VERSION = '0.1.0';
- // settings which can be set in config.php with addPlugin('Oembed', array('param'=>'value', ...));
- // WARNING, these are _regexps_ (slashes added later). Always escape your dots and end your strings
- public $domain_whitelist = array( // hostname => service provider
- '^i\d*\.ytimg\.com$' => 'YouTube',
- '^i\d*\.vimeocdn\.com$' => 'Vimeo',
- );
+ // settings which can be set in config.php with addPlugin('Embed', array('param'=>'value', ...));
+ // WARNING, these are _regexps_ (slashes added later). Always escape your dots and end ('$') your strings
+
+ public $domain_whitelist = [
+ // hostname => service provider
+ '^i\d*\.ytimg\.com$' => 'YouTube',
+ '^i\d*\.vimeocdn\.com$' => 'Vimeo',
+ ];
public $append_whitelist = array(); // fill this array as domain_whitelist to add more trusted sources
public $check_whitelist = false; // security/abuse precaution
protected $imgData = array();
/**
- * Initialize the oEmbed plugin and set up the environment it needs for it.
+ * Initialize the Embed plugin and set up the environment it needs for it.
* Returns true if it initialized properly, the exception object if it
* doesn't.
*/
@@ -77,19 +80,19 @@ class OembedPlugin extends Plugin
/**
* This code executes when GNU social creates the page routing, and we hook
- * on this event to add our action handler for oEmbed.
+ * on this event to add our action handler for Embed.
*
* @param $m URLMapper the router that was initialized.
* @return bool true if successful, the exception object if it isn't.
*/
public function onRouterInitialized(URLMapper $m)
{
- $m->connect('main/oembed', ['action' => 'oembed']);
+ $m->connect('main/embed', ['action' => 'embed']);
}
/**
* This event executes when GNU social encounters a remote URL we then decide
- * to interrogate for metadata. oEmbed gloms onto it to see if we have an
+ * to interrogate for metadata. Embed gloms onto it to see if we have an
* oEmbed endpoint or image to try to represent in the post.
*
* @param $url string the remote URL we're looking at
@@ -218,7 +221,7 @@ class OembedPlugin extends Plugin
public function onEndShowStylesheets(Action $action)
{
- $action->cssLink($this->path('css/oembed.css'));
+ $action->cssLink($this->path('css/embed.css'));
return true;
}
@@ -233,9 +236,9 @@ class OembedPlugin extends Plugin
*/
public function onEndFileSaveNew(File $file)
{
- $fo = File_oembed::getKV('file_id', $file->getID());
- if ($fo instanceof File_oembed) {
- common_log(LOG_WARNING, "Strangely, a File_oembed object exists for new file {$file->getID()}", __FILE__);
+ $fo = File_embed::getKV('file_id', $file->getID());
+ if ($fo instanceof File_embed) {
+ common_log(LOG_WARNING, "Strangely, a File_embed object exists for new file {$file->getID()}", __FILE__);
return true;
}
@@ -243,51 +246,51 @@ class OembedPlugin extends Plugin
&& (('text/html' === substr($file->mimetype, 0, 9)
|| 'application/xhtml+xml' === substr($file->mimetype, 0, 21)))) {
try {
- $oembed_data = File_oembed::_getOembed($file->url);
- if ($oembed_data === false) {
- throw new Exception('Did not get oEmbed data from URL');
+ $embed_data = File_embed::_getEmbed($file->url);
+ if ($embed_data === false) {
+ throw new Exception('Did not get embed data from URL');
}
- $file->setTitle($oembed_data->title);
+ $file->setTitle($embed_data->title);
} catch (Exception $e) {
- common_log(LOG_WARNING, sprintf(__METHOD__.': %s thrown when getting oEmbed data: %s', get_class($e), _ve($e->getMessage())));
+ common_log(LOG_WARNING, sprintf(__METHOD__.': %s thrown when getting embed data: %s', get_class($e), _ve($e->getMessage())));
return true;
}
- File_oembed::saveNew($oembed_data, $file->getID());
+ File_embed::saveNew($embed_data, $file->getID());
}
return true;
}
public function onEndShowAttachmentLink(HTMLOutputter $out, File $file)
{
- $oembed = File_oembed::getKV('file_id', $file->getID());
- if (empty($oembed->author_name) && empty($oembed->provider)) {
+ $embed = File_embed::getKV('file_id', $file->getID());
+ if (empty($embed->author_name) && empty($embed->provider)) {
return true;
}
$out->elementStart('div', array('id'=>'oembed_info', 'class'=>'e-content'));
- if (!empty($oembed->author_name)) {
+ if (!empty($embed->author_name)) {
$out->elementStart('div', 'fn vcard author');
- if (empty($oembed->author_url)) {
- $out->text($oembed->author_name);
+ if (empty($embed->author_url)) {
+ $out->text($embed->author_name);
} else {
$out->element(
'a',
- array('href' => $oembed->author_url,
+ array('href' => $embed->author_url,
'class' => 'url'),
- $oembed->author_name
+ $embed->author_name
);
}
}
- if (!empty($oembed->provider)) {
+ if (!empty($embed->provider)) {
$out->elementStart('div', 'fn vcard');
- if (empty($oembed->provider_url)) {
- $out->text($oembed->provider);
+ if (empty($embed->provider_url)) {
+ $out->text($embed->provider);
} else {
$out->element(
'a',
- array('href' => $oembed->provider_url,
+ array('href' => $embed->provider_url,
'class' => 'url'),
- $oembed->provider
+ $embed->provider
);
}
}
@@ -297,15 +300,15 @@ class OembedPlugin extends Plugin
public function onFileEnclosureMetadata(File $file, &$enclosure)
{
// Never treat generic HTML links as an enclosure type!
- // But if we have oEmbed info, we'll consider it golden.
- $oembed = File_oembed::getKV('file_id', $file->getID());
- if (!$oembed instanceof File_oembed || !in_array($oembed->type, array('photo', 'video'))) {
+ // But if we have embed info, we'll consider it golden.
+ $embed = File_embed::getKV('file_id', $file->getID());
+ if (!$embed instanceof File_embed || !in_array($embed->type, array('photo', 'video'))) {
return true;
}
foreach (array('mimetype', 'url', 'title', 'modified', 'width', 'height') as $key) {
- if (isset($oembed->{$key}) && !empty($oembed->{$key})) {
- $enclosure->{$key} = $oembed->{$key};
+ if (isset($embed->{$key}) && !empty($embed->{$key})) {
+ $enclosure->{$key} = $embed->{$key};
}
}
return true;
@@ -314,59 +317,59 @@ class OembedPlugin extends Plugin
public function onStartShowAttachmentRepresentation(HTMLOutputter $out, File $file)
{
try {
- $oembed = File_oembed::getByFile($file);
+ $embed = File_embed::getByFile($file);
} catch (NoResultException $e) {
return true;
}
// Show thumbnail as usual if it's a photo.
- if ($oembed->type === 'photo') {
+ if ($embed->type === 'photo') {
return true;
}
- $out->elementStart('article', ['class'=>'h-entry oembed']);
+ $out->elementStart('article', ['class'=>'h-entry embed']);
$out->elementStart('header');
try {
$thumb = $file->getThumbnail(128, 128);
- $out->element('img', $thumb->getHtmlAttrs(['class'=>'u-photo oembed']));
+ $out->element('img', $thumb->getHtmlAttrs(['class'=>'u-photo embed']));
unset($thumb);
} catch (Exception $e) {
$out->element('div', ['class'=>'error'], $e->getMessage());
}
- $out->elementStart('h5', ['class'=>'p-name oembed']);
- $out->element('a', ['class'=>'u-url', 'href'=>$file->getUrl()], common_strip_html($oembed->title));
+ $out->elementStart('h5', ['class'=>'p-name embed']);
+ $out->element('a', ['class'=>'u-url', 'href'=>$file->getUrl()], common_strip_html($embed->title));
$out->elementEnd('h5');
- $out->elementStart('div', ['class'=>'p-author oembed']);
- if (!empty($oembed->author_name)) {
- // TRANS: text before the author name of oEmbed attachment representation
+ $out->elementStart('div', ['class'=>'p-author embed']);
+ if (!empty($embed->author_name)) {
+ // TRANS: text before the author name of embed attachment representation
// FIXME: The whole "By x from y" should be i18n because of different language constructions.
$out->text(_('By '));
$attrs = ['class'=>'h-card p-author'];
- if (!empty($oembed->author_url)) {
- $attrs['href'] = $oembed->author_url;
+ if (!empty($embed->author_url)) {
+ $attrs['href'] = $embed->author_url;
$tag = 'a';
} else {
$tag = 'span';
}
- $out->element($tag, $attrs, $oembed->author_name);
+ $out->element($tag, $attrs, $embed->author_name);
}
- if (!empty($oembed->provider)) {
- // TRANS: text between the oEmbed author name and provider url
+ if (!empty($embed->provider)) {
+ // TRANS: text between the embed author name and provider url
// FIXME: The whole "By x from y" should be i18n because of different language constructions.
$out->text(_(' from '));
$attrs = ['class'=>'h-card'];
- if (!empty($oembed->provider_url)) {
- $attrs['href'] = $oembed->provider_url;
+ if (!empty($embed->provider_url)) {
+ $attrs['href'] = $embed->provider_url;
$tag = 'a';
} else {
$tag = 'span';
}
- $out->element($tag, $attrs, $oembed->provider);
+ $out->element($tag, $attrs, $embed->provider);
}
$out->elementEnd('div');
$out->elementEnd('header');
$out->elementStart('div', ['class'=>'p-summary oembed']);
- $out->raw(common_purify($oembed->html));
+ $out->raw(common_purify($embed->html));
$out->elementEnd('div');
$out->elementStart('footer');
$out->elementEnd('footer');
@@ -378,20 +381,21 @@ class OembedPlugin extends Plugin
public function onShowUnsupportedAttachmentRepresentation(HTMLOutputter $out, File $file)
{
try {
- $oembed = File_oembed::getByFile($file);
+ $embed = File_embed::getByFile($file);
} catch (NoResultException $e) {
return true;
}
// the 'photo' type is shown through ordinary means, using StartShowAttachmentRepresentation!
- switch ($oembed->type) {
+ switch ($embed->type) {
case 'video':
case 'link':
- if (!empty($oembed->html)
+ if (!empty($embed->html)
&& (GNUsocial::isAjax() || common_config('attachments', 'show_html'))) {
- $purifier = new \HTMLPurifier();
+ require_once INSTALLDIR.'/extlib/HTMLPurifier/HTMLPurifier.auto.php';
+ $purifier = new HTMLPurifier();
// FIXME: do we allow