[OEmbed][Embed] Renamed OEmbed plugin to Embed
This commit is contained in:
parent
1d41ff16d6
commit
52819d39d9
@ -349,7 +349,7 @@ $default =
|
|||||||
'DirectMessage' => array(),
|
'DirectMessage' => array(),
|
||||||
'EmailAuthentication' => array(),
|
'EmailAuthentication' => array(),
|
||||||
'Event' => array(),
|
'Event' => array(),
|
||||||
'Oembed' => array(),
|
'Embed' => array(),
|
||||||
'OpenID' => array(),
|
'OpenID' => array(),
|
||||||
'OpportunisticQM' => array(),
|
'OpportunisticQM' => array(),
|
||||||
'OStatus' => array(),
|
'OStatus' => array(),
|
||||||
|
@ -15,13 +15,14 @@
|
|||||||
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OembedPlugin implementation for GNU social
|
* OEmbed and OpenGraph implementation for GNU social
|
||||||
*
|
*
|
||||||
* @package GNUsocial
|
* @package GNUsocial
|
||||||
* @author Stephen Paul Weber
|
* @author Stephen Paul Weber
|
||||||
* @author hannes
|
* @author hannes
|
||||||
* @author Mikael Nordfeldth
|
* @author Mikael Nordfeldth
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
|
* @author Miguel Dantas <biodantasgs@gmail.com>
|
||||||
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
|
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
|
||||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
*/
|
*/
|
||||||
@ -29,29 +30,31 @@
|
|||||||
defined('GNUSOCIAL') || die();
|
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.
|
* and display representations for remote content.
|
||||||
*
|
*
|
||||||
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
|
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
|
||||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
* @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', ...));
|
// 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
|
// WARNING, these are _regexps_ (slashes added later). Always escape your dots and end ('$') your strings
|
||||||
public $domain_whitelist = array( // hostname => service provider
|
|
||||||
|
public $domain_whitelist = [
|
||||||
|
// hostname => service provider
|
||||||
'^i\d*\.ytimg\.com$' => 'YouTube',
|
'^i\d*\.ytimg\.com$' => 'YouTube',
|
||||||
'^i\d*\.vimeocdn\.com$' => 'Vimeo',
|
'^i\d*\.vimeocdn\.com$' => 'Vimeo',
|
||||||
);
|
];
|
||||||
public $append_whitelist = array(); // fill this array as domain_whitelist to add more trusted sources
|
public $append_whitelist = array(); // fill this array as domain_whitelist to add more trusted sources
|
||||||
public $check_whitelist = false; // security/abuse precaution
|
public $check_whitelist = false; // security/abuse precaution
|
||||||
|
|
||||||
protected $imgData = array();
|
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
|
* Returns true if it initialized properly, the exception object if it
|
||||||
* doesn't.
|
* doesn't.
|
||||||
*/
|
*/
|
||||||
@ -77,19 +80,19 @@ class OembedPlugin extends Plugin
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This code executes when GNU social creates the page routing, and we hook
|
* 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.
|
* @param $m URLMapper the router that was initialized.
|
||||||
* @return bool true if successful, the exception object if it isn't.
|
* @return bool true if successful, the exception object if it isn't.
|
||||||
*/
|
*/
|
||||||
public function onRouterInitialized(URLMapper $m)
|
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
|
* 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.
|
* oEmbed endpoint or image to try to represent in the post.
|
||||||
*
|
*
|
||||||
* @param $url string the remote URL we're looking at
|
* @param $url string the remote URL we're looking at
|
||||||
@ -218,7 +221,7 @@ class OembedPlugin extends Plugin
|
|||||||
|
|
||||||
public function onEndShowStylesheets(Action $action)
|
public function onEndShowStylesheets(Action $action)
|
||||||
{
|
{
|
||||||
$action->cssLink($this->path('css/oembed.css'));
|
$action->cssLink($this->path('css/embed.css'));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,9 +236,9 @@ class OembedPlugin extends Plugin
|
|||||||
*/
|
*/
|
||||||
public function onEndFileSaveNew(File $file)
|
public function onEndFileSaveNew(File $file)
|
||||||
{
|
{
|
||||||
$fo = File_oembed::getKV('file_id', $file->getID());
|
$fo = File_embed::getKV('file_id', $file->getID());
|
||||||
if ($fo instanceof File_oembed) {
|
if ($fo instanceof File_embed) {
|
||||||
common_log(LOG_WARNING, "Strangely, a File_oembed object exists for new file {$file->getID()}", __FILE__);
|
common_log(LOG_WARNING, "Strangely, a File_embed object exists for new file {$file->getID()}", __FILE__);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,51 +246,51 @@ class OembedPlugin extends Plugin
|
|||||||
&& (('text/html' === substr($file->mimetype, 0, 9)
|
&& (('text/html' === substr($file->mimetype, 0, 9)
|
||||||
|| 'application/xhtml+xml' === substr($file->mimetype, 0, 21)))) {
|
|| 'application/xhtml+xml' === substr($file->mimetype, 0, 21)))) {
|
||||||
try {
|
try {
|
||||||
$oembed_data = File_oembed::_getOembed($file->url);
|
$embed_data = File_embed::_getEmbed($file->url);
|
||||||
if ($oembed_data === false) {
|
if ($embed_data === false) {
|
||||||
throw new Exception('Did not get oEmbed data from URL');
|
throw new Exception('Did not get embed data from URL');
|
||||||
}
|
}
|
||||||
$file->setTitle($oembed_data->title);
|
$file->setTitle($embed_data->title);
|
||||||
} catch (Exception $e) {
|
} 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
File_oembed::saveNew($oembed_data, $file->getID());
|
File_embed::saveNew($embed_data, $file->getID());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onEndShowAttachmentLink(HTMLOutputter $out, File $file)
|
public function onEndShowAttachmentLink(HTMLOutputter $out, File $file)
|
||||||
{
|
{
|
||||||
$oembed = File_oembed::getKV('file_id', $file->getID());
|
$embed = File_embed::getKV('file_id', $file->getID());
|
||||||
if (empty($oembed->author_name) && empty($oembed->provider)) {
|
if (empty($embed->author_name) && empty($embed->provider)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$out->elementStart('div', array('id'=>'oembed_info', 'class'=>'e-content'));
|
$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');
|
$out->elementStart('div', 'fn vcard author');
|
||||||
if (empty($oembed->author_url)) {
|
if (empty($embed->author_url)) {
|
||||||
$out->text($oembed->author_name);
|
$out->text($embed->author_name);
|
||||||
} else {
|
} else {
|
||||||
$out->element(
|
$out->element(
|
||||||
'a',
|
'a',
|
||||||
array('href' => $oembed->author_url,
|
array('href' => $embed->author_url,
|
||||||
'class' => 'url'),
|
'class' => 'url'),
|
||||||
$oembed->author_name
|
$embed->author_name
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($oembed->provider)) {
|
if (!empty($embed->provider)) {
|
||||||
$out->elementStart('div', 'fn vcard');
|
$out->elementStart('div', 'fn vcard');
|
||||||
if (empty($oembed->provider_url)) {
|
if (empty($embed->provider_url)) {
|
||||||
$out->text($oembed->provider);
|
$out->text($embed->provider);
|
||||||
} else {
|
} else {
|
||||||
$out->element(
|
$out->element(
|
||||||
'a',
|
'a',
|
||||||
array('href' => $oembed->provider_url,
|
array('href' => $embed->provider_url,
|
||||||
'class' => 'url'),
|
'class' => 'url'),
|
||||||
$oembed->provider
|
$embed->provider
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -297,15 +300,15 @@ class OembedPlugin extends Plugin
|
|||||||
public function onFileEnclosureMetadata(File $file, &$enclosure)
|
public function onFileEnclosureMetadata(File $file, &$enclosure)
|
||||||
{
|
{
|
||||||
// Never treat generic HTML links as an enclosure type!
|
// Never treat generic HTML links as an enclosure type!
|
||||||
// But if we have oEmbed info, we'll consider it golden.
|
// But if we have embed info, we'll consider it golden.
|
||||||
$oembed = File_oembed::getKV('file_id', $file->getID());
|
$embed = File_embed::getKV('file_id', $file->getID());
|
||||||
if (!$oembed instanceof File_oembed || !in_array($oembed->type, array('photo', 'video'))) {
|
if (!$embed instanceof File_embed || !in_array($embed->type, array('photo', 'video'))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array('mimetype', 'url', 'title', 'modified', 'width', 'height') as $key) {
|
foreach (array('mimetype', 'url', 'title', 'modified', 'width', 'height') as $key) {
|
||||||
if (isset($oembed->{$key}) && !empty($oembed->{$key})) {
|
if (isset($embed->{$key}) && !empty($embed->{$key})) {
|
||||||
$enclosure->{$key} = $oembed->{$key};
|
$enclosure->{$key} = $embed->{$key};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -314,59 +317,59 @@ class OembedPlugin extends Plugin
|
|||||||
public function onStartShowAttachmentRepresentation(HTMLOutputter $out, File $file)
|
public function onStartShowAttachmentRepresentation(HTMLOutputter $out, File $file)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$oembed = File_oembed::getByFile($file);
|
$embed = File_embed::getByFile($file);
|
||||||
} catch (NoResultException $e) {
|
} catch (NoResultException $e) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show thumbnail as usual if it's a photo.
|
// Show thumbnail as usual if it's a photo.
|
||||||
if ($oembed->type === 'photo') {
|
if ($embed->type === 'photo') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$out->elementStart('article', ['class'=>'h-entry oembed']);
|
$out->elementStart('article', ['class'=>'h-entry embed']);
|
||||||
$out->elementStart('header');
|
$out->elementStart('header');
|
||||||
try {
|
try {
|
||||||
$thumb = $file->getThumbnail(128, 128);
|
$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);
|
unset($thumb);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$out->element('div', ['class'=>'error'], $e->getMessage());
|
$out->element('div', ['class'=>'error'], $e->getMessage());
|
||||||
}
|
}
|
||||||
$out->elementStart('h5', ['class'=>'p-name oembed']);
|
$out->elementStart('h5', ['class'=>'p-name embed']);
|
||||||
$out->element('a', ['class'=>'u-url', 'href'=>$file->getUrl()], common_strip_html($oembed->title));
|
$out->element('a', ['class'=>'u-url', 'href'=>$file->getUrl()], common_strip_html($embed->title));
|
||||||
$out->elementEnd('h5');
|
$out->elementEnd('h5');
|
||||||
$out->elementStart('div', ['class'=>'p-author oembed']);
|
$out->elementStart('div', ['class'=>'p-author embed']);
|
||||||
if (!empty($oembed->author_name)) {
|
if (!empty($embed->author_name)) {
|
||||||
// TRANS: text before the author name of oEmbed attachment representation
|
// 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.
|
// FIXME: The whole "By x from y" should be i18n because of different language constructions.
|
||||||
$out->text(_('By '));
|
$out->text(_('By '));
|
||||||
$attrs = ['class'=>'h-card p-author'];
|
$attrs = ['class'=>'h-card p-author'];
|
||||||
if (!empty($oembed->author_url)) {
|
if (!empty($embed->author_url)) {
|
||||||
$attrs['href'] = $oembed->author_url;
|
$attrs['href'] = $embed->author_url;
|
||||||
$tag = 'a';
|
$tag = 'a';
|
||||||
} else {
|
} else {
|
||||||
$tag = 'span';
|
$tag = 'span';
|
||||||
}
|
}
|
||||||
$out->element($tag, $attrs, $oembed->author_name);
|
$out->element($tag, $attrs, $embed->author_name);
|
||||||
}
|
}
|
||||||
if (!empty($oembed->provider)) {
|
if (!empty($embed->provider)) {
|
||||||
// TRANS: text between the oEmbed author name and provider url
|
// 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.
|
// FIXME: The whole "By x from y" should be i18n because of different language constructions.
|
||||||
$out->text(_(' from '));
|
$out->text(_(' from '));
|
||||||
$attrs = ['class'=>'h-card'];
|
$attrs = ['class'=>'h-card'];
|
||||||
if (!empty($oembed->provider_url)) {
|
if (!empty($embed->provider_url)) {
|
||||||
$attrs['href'] = $oembed->provider_url;
|
$attrs['href'] = $embed->provider_url;
|
||||||
$tag = 'a';
|
$tag = 'a';
|
||||||
} else {
|
} else {
|
||||||
$tag = 'span';
|
$tag = 'span';
|
||||||
}
|
}
|
||||||
$out->element($tag, $attrs, $oembed->provider);
|
$out->element($tag, $attrs, $embed->provider);
|
||||||
}
|
}
|
||||||
$out->elementEnd('div');
|
$out->elementEnd('div');
|
||||||
$out->elementEnd('header');
|
$out->elementEnd('header');
|
||||||
$out->elementStart('div', ['class'=>'p-summary oembed']);
|
$out->elementStart('div', ['class'=>'p-summary oembed']);
|
||||||
$out->raw(common_purify($oembed->html));
|
$out->raw(common_purify($embed->html));
|
||||||
$out->elementEnd('div');
|
$out->elementEnd('div');
|
||||||
$out->elementStart('footer');
|
$out->elementStart('footer');
|
||||||
$out->elementEnd('footer');
|
$out->elementEnd('footer');
|
||||||
@ -378,20 +381,21 @@ class OembedPlugin extends Plugin
|
|||||||
public function onShowUnsupportedAttachmentRepresentation(HTMLOutputter $out, File $file)
|
public function onShowUnsupportedAttachmentRepresentation(HTMLOutputter $out, File $file)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$oembed = File_oembed::getByFile($file);
|
$embed = File_embed::getByFile($file);
|
||||||
} catch (NoResultException $e) {
|
} catch (NoResultException $e) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the 'photo' type is shown through ordinary means, using StartShowAttachmentRepresentation!
|
// the 'photo' type is shown through ordinary means, using StartShowAttachmentRepresentation!
|
||||||
switch ($oembed->type) {
|
switch ($embed->type) {
|
||||||
case 'video':
|
case 'video':
|
||||||
case 'link':
|
case 'link':
|
||||||
if (!empty($oembed->html)
|
if (!empty($embed->html)
|
||||||
&& (GNUsocial::isAjax() || common_config('attachments', 'show_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 <object> and <embed> here? we did that when we used htmLawed, but I'm not sure anymore...
|
// FIXME: do we allow <object> and <embed> here? we did that when we used htmLawed, but I'm not sure anymore...
|
||||||
$out->raw($purifier->purify($oembed->html));
|
$out->raw($purifier->purify($embed->html));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -401,7 +405,7 @@ class OembedPlugin extends Plugin
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This event executes when GNU social is creating a file thumbnail entry in
|
* This event executes when GNU social is creating a file thumbnail entry in
|
||||||
* the database. We glom onto this to create proper information for oEmbed
|
* the database. We glom onto this to create proper information for Embed
|
||||||
* object thumbnails.
|
* object thumbnails.
|
||||||
*
|
*
|
||||||
* @param $file File the file of the created thumbnail
|
* @param $file File the file of the created thumbnail
|
||||||
@ -418,20 +422,20 @@ class OembedPlugin extends Plugin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// All our remote Oembed images lack a local filename property in the File object
|
// All our remote Embed images lack a local filename property in the File object
|
||||||
if (!is_null($file->filename)) {
|
if (!is_null($file->filename)) {
|
||||||
common_debug(sprintf('Filename of file id==%d is not null (%s), so nothing oEmbed '.
|
common_debug(sprintf('Filename of file id==%d is not null (%s), so nothing Embed '.
|
||||||
'should handle.', $file->getID(), _ve($file->filename)));
|
'should handle.', $file->getID(), _ve($file->filename)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// If we have proper oEmbed data, there should be an entry in the File_oembed
|
// If we have proper Embed data, there should be an entry in the File_embed
|
||||||
// and File_thumbnail tables respectively. If not, we're not going to do anything.
|
// and File_thumbnail tables respectively. If not, we're not going to do anything.
|
||||||
$thumbnail = File_thumbnail::byFile($file);
|
$thumbnail = File_thumbnail::byFile($file);
|
||||||
} catch (NoResultException $e) {
|
} catch (NoResultException $e) {
|
||||||
// Not Oembed data, or at least nothing we either can or want to use.
|
// Not Embed data, or at least nothing we either can or want to use.
|
||||||
common_debug('No oEmbed data found for file id=='.$file->getID());
|
common_debug('No Embed data found for file id=='.$file->getID());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +444,7 @@ class OembedPlugin extends Plugin
|
|||||||
} catch (AlreadyFulfilledException $e) {
|
} catch (AlreadyFulfilledException $e) {
|
||||||
// aw yiss!
|
// aw yiss!
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
common_debug(sprintf('oEmbed encountered an exception (%s) for file id==%d: %s',
|
common_debug(sprintf('Embed encountered an exception (%s) for file id==%d: %s',
|
||||||
get_class($e), $file->getID(), _ve($e->getMessage())));
|
get_class($e), $file->getID(), _ve($e->getMessage())));
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
@ -512,11 +516,11 @@ class OembedPlugin extends Plugin
|
|||||||
private function isRemoteImage($url)
|
private function isRemoteImage($url)
|
||||||
{
|
{
|
||||||
if (!filter_var($url, FILTER_VALIDATE_URL)) {
|
if (!filter_var($url, FILTER_VALIDATE_URL)) {
|
||||||
common_log(LOG_ERR, "Invalid URL in OEmbed::isRemoteImage()");
|
common_log(LOG_ERR, "Invalid URL in Embed::isRemoteImage()");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($url==null) {
|
if ($url==null) {
|
||||||
common_log(LOG_ERR, "URL not specified in OEmbed::isRemoteImage()");
|
common_log(LOG_ERR, "URL not specified in Embed::isRemoteImage()");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -585,7 +589,7 @@ class OembedPlugin extends Plugin
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// We'll trust sha256 (File::FILEHASH_ALG) not to have collision issues any time soon :)
|
// We'll trust sha256 (File::FILEHASH_ALG) not to have collision issues any time soon :)
|
||||||
$original_filename = bin2hex('oembed.' . $ext);
|
$original_filename = bin2hex('embed.' . $ext);
|
||||||
$filehash = hash(File::FILEHASH_ALG, $imgData);
|
$filehash = hash(File::FILEHASH_ALG, $imgData);
|
||||||
$filename = "{$original_filename}-{$filehash}";
|
$filename = "{$original_filename}-{$filehash}";
|
||||||
$fullpath = File_thumbnail::path($filename);
|
$fullpath = File_thumbnail::path($filename);
|
||||||
@ -594,7 +598,7 @@ class OembedPlugin extends Plugin
|
|||||||
throw new ServerException(_('Could not write downloaded file to disk.'));
|
throw new ServerException(_('Could not write downloaded file to disk.'));
|
||||||
}
|
}
|
||||||
} catch (Exception $err) {
|
} catch (Exception $err) {
|
||||||
common_log(LOG_ERROR, "Went to write a thumbnail to disk in OembedPlugin::storeRemoteThumbnail " .
|
common_log(LOG_ERROR, "Went to write a thumbnail to disk in EmbedPlugin::storeRemoteThumbnail " .
|
||||||
"but encountered error: {$err}");
|
"but encountered error: {$err}");
|
||||||
return $err;
|
return $err;
|
||||||
} finally {
|
} finally {
|
||||||
@ -611,7 +615,7 @@ class OembedPlugin extends Plugin
|
|||||||
$thumbnail->updateWithKeys($orig);
|
$thumbnail->updateWithKeys($orig);
|
||||||
} catch (exception $err) {
|
} catch (exception $err) {
|
||||||
common_log(LOG_ERROR, "Went to write a thumbnail entry to the database in " .
|
common_log(LOG_ERROR, "Went to write a thumbnail entry to the database in " .
|
||||||
"OembedPlugin::storeRemoteThumbnail but encountered error: ".$err);
|
"EmbedPlugin::storeRemoteThumbnail but encountered error: ".$err);
|
||||||
return $err;
|
return $err;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -626,13 +630,13 @@ class OembedPlugin extends Plugin
|
|||||||
*/
|
*/
|
||||||
public function onPluginVersion(array &$versions)
|
public function onPluginVersion(array &$versions)
|
||||||
{
|
{
|
||||||
$versions[] = array('name' => 'Oembed',
|
$versions[] = array('name' => 'Embed',
|
||||||
'version' => self::PLUGIN_VERSION,
|
'version' => self::PLUGIN_VERSION,
|
||||||
'author' => 'Mikael Nordfeldth',
|
'author' => 'Mikael Nordfeldth',
|
||||||
'homepage' => 'http://gnu.io/social/',
|
'homepage' => 'http://gnu.io/social/',
|
||||||
'description' =>
|
'description' =>
|
||||||
// TRANS: Plugin description.
|
// TRANS: Plugin description.
|
||||||
_m('Plugin for using and representing Oembed data.'));
|
_m('Plugin for using and representing oEmbed, OpenGraph and other data.'));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,7 +36,7 @@ defined('GNUSOCIAL') || die();
|
|||||||
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
|
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
|
||||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
*/
|
*/
|
||||||
class OembedAction extends Action
|
class EmbedAction extends Action
|
||||||
{
|
{
|
||||||
protected function handle()
|
protected function handle()
|
||||||
{
|
{
|
@ -92,7 +92,7 @@ class File_oembed extends Managed_DataObject
|
|||||||
*/
|
*/
|
||||||
public static function getByFile(File $file)
|
public static function getByFile(File $file)
|
||||||
{
|
{
|
||||||
$fo = new File_oembed();
|
$fo = new File_embed();
|
||||||
$fo->file_id = $file->id;
|
$fo->file_id = $file->id;
|
||||||
if (!$fo->find(true)) {
|
if (!$fo->find(true)) {
|
||||||
throw new NoResultException($fo);
|
throw new NoResultException($fo);
|
||||||
@ -113,47 +113,47 @@ class File_oembed extends Managed_DataObject
|
|||||||
*/
|
*/
|
||||||
public static function saveNew($data, $file_id)
|
public static function saveNew($data, $file_id)
|
||||||
{
|
{
|
||||||
$file_oembed = new File_oembed;
|
$file_embed = new File_embed;
|
||||||
$file_oembed->file_id = $file_id;
|
$file_embed->file_id = $file_id;
|
||||||
if (!isset($data->version)) {
|
if (!isset($data->version)) {
|
||||||
common_debug('DEBUGGING oEmbed: data->version undefined in variable $data: '.var_export($data, true));
|
common_debug('DEBUGGING oEmbed: data->version undefined in variable $data: '.var_export($data, true));
|
||||||
}
|
}
|
||||||
$file_oembed->version = $data->version;
|
$file_embed->version = $data->version;
|
||||||
$file_oembed->type = $data->type;
|
$file_embed->type = $data->type;
|
||||||
if (!empty($data->provider_name)) {
|
if (!empty($data->provider_name)) {
|
||||||
$file_oembed->provider = $data->provider_name;
|
$file_embed->provider = $data->provider_name;
|
||||||
}
|
}
|
||||||
if (!empty($data->provider)) {
|
if (!empty($data->provider)) {
|
||||||
$file_oembed->provider = $data->provider;
|
$file_embed->provider = $data->provider;
|
||||||
}
|
}
|
||||||
if (!empty($data->provider_url)) {
|
if (!empty($data->provider_url)) {
|
||||||
$file_oembed->provider_url = $data->provider_url;
|
$file_embed->provider_url = $data->provider_url;
|
||||||
}
|
}
|
||||||
if (!empty($data->width)) {
|
if (!empty($data->width)) {
|
||||||
$file_oembed->width = intval($data->width);
|
$file_embed->width = intval($data->width);
|
||||||
}
|
}
|
||||||
if (!empty($data->height)) {
|
if (!empty($data->height)) {
|
||||||
$file_oembed->height = intval($data->height);
|
$file_embed->height = intval($data->height);
|
||||||
}
|
}
|
||||||
if (!empty($data->html)) {
|
if (!empty($data->html)) {
|
||||||
$file_oembed->html = $data->html;
|
$file_embed->html = $data->html;
|
||||||
}
|
}
|
||||||
if (!empty($data->title)) {
|
if (!empty($data->title)) {
|
||||||
$file_oembed->title = $data->title;
|
$file_embed->title = $data->title;
|
||||||
}
|
}
|
||||||
if (!empty($data->author_name)) {
|
if (!empty($data->author_name)) {
|
||||||
$file_oembed->author_name = $data->author_name;
|
$file_embed->author_name = $data->author_name;
|
||||||
}
|
}
|
||||||
if (!empty($data->author_url)) {
|
if (!empty($data->author_url)) {
|
||||||
$file_oembed->author_url = $data->author_url;
|
$file_embed->author_url = $data->author_url;
|
||||||
}
|
}
|
||||||
if (!empty($data->url)) {
|
if (!empty($data->url)) {
|
||||||
$file_oembed->url = $data->url;
|
$file_embed->url = $data->url;
|
||||||
$given_url = File_redirection::_canonUrl($file_oembed->url);
|
$given_url = File_redirection::_canonUrl($file_embed->url);
|
||||||
if (! empty($given_url)) {
|
if (! empty($given_url)) {
|
||||||
try {
|
try {
|
||||||
$file = File::getByUrl($given_url);
|
$file = File::getByUrl($given_url);
|
||||||
$file_oembed->mimetype = $file->mimetype;
|
$file_embed->mimetype = $file->mimetype;
|
||||||
} catch (NoResultException $e) {
|
} catch (NoResultException $e) {
|
||||||
// File_redirection::where argument 'discover' is false to avoid loops
|
// File_redirection::where argument 'discover' is false to avoid loops
|
||||||
$redir = File_redirection::where($given_url, false);
|
$redir = File_redirection::where($given_url, false);
|
||||||
@ -163,9 +163,9 @@ class File_oembed extends Managed_DataObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result = $file_oembed->insert();
|
$result = $file_embed->insert();
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
throw new ServerException('Failed to insert File_oembed data into database!');
|
throw new ServerException('Failed to insert File_embed data into database!');
|
||||||
}
|
}
|
||||||
if (!empty($data->thumbnail_url) || ($data->type == 'photo')) {
|
if (!empty($data->thumbnail_url) || ($data->type == 'photo')) {
|
||||||
$ft = File_thumbnail::getKV('file_id', $file_id);
|
$ft = File_thumbnail::getKV('file_id', $file_id);
|
Loading…
Reference in New Issue
Block a user