Browse Source

Upgrade Embed to v4.x and add Twitter integration

pull/1082/head
Timothée Jaussoin 3 years ago
parent
commit
e064b1b8e4
  1. 1
      CHANGELOG.md
  2. 1
      app/Configuration.php
  3. 51
      app/Url.php
  4. 5
      app/helpers/StringHelper.php
  5. 25
      app/widgets/AdminMain/adminmain.tpl
  6. 6
      app/widgets/AdminMain/locales.ini
  7. 2
      app/widgets/Chat/_chat_embed.tpl
  8. 3
      app/widgets/Preview/_preview.tpl
  9. 3
      app/widgets/Preview/_preview_gallery.tpl
  10. 4
      app/widgets/Publish/_publish_embed.tpl
  11. 2
      composer.json
  12. 265
      composer.lock
  13. 21
      database/migrations/20220722133156_add_twitter_token_to_configuration_table.php
  14. 2
      src/Movim/Bootstrap.php
  15. 23
      src/Movim/EmbedImagesExtractor.php
  16. 67
      src/Movim/EmbedLight.php

1
CHANGELOG.md

@ -6,6 +6,7 @@ v0.21 (trunk)
* Implement XEP-0461: Message Replies
* Add PWA Push Notification support through the service worker
* CSS fixes
* Upgrade Embed to v4.x and add Twitter integration
v0.20
---------------------------

1
app/Configuration.php

@ -21,6 +21,7 @@ class Configuration extends Model
'loglevel',
'username',
'password',
'twittertoken',
'xmppdomain',
'xmppdescription',
'xmppwhitelist'

51
app/Url.php

@ -5,7 +5,11 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
use Respect\Validation\Validator;
use Movim\EmbedLight;
use Embed\Http\CurlDispatcher;
use Embed\Embed;
use Embed\Http\Crawler;
use Embed\Http\CurlClient;
use Movim\EmbedImagesExtractor;
class Url extends Model
{
@ -37,16 +41,7 @@ class Url extends Model
public function maybeResolveMessageFile($cache)
{
if ($cache->title == $cache->url
&& ((
$cache->type == 'photo'
&& !empty($cache->images)
&& isset($cache->contentType)
&& typeIsPicture($cache->contentType)
) || (
$cache->type == 'video'
&& isset($cache->contentType)
&& typeIsVideo($cache->contentType)
))
&& ($cache->type == 'image' || $cache->type == 'video')
) {
$name = '';
$path = parse_url($cache->url, PHP_URL_PATH);
@ -73,13 +68,35 @@ class Url extends Model
public function setCacheAttribute($url)
{
$dispatcher = new CurlDispatcher([
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 10,
CURLOPT_USERAGENT => DEFAULT_HTTP_USER_AGENT,
$client = new CurlClient;
$client->setSettings([
'max_redirs' => 3, // see CURLOPT_MAXREDIRS
'connect_timeout' => 5, // see CURLOPT_CONNECTTIMEOUT
'timeout' => 5, // see CURLOPT_TIMEOUT
'ssl_verify_host' => 2, // see CURLOPT_SSL_VERIFYHOST
'ssl_verify_peer' => 1, // see CURLOPT_SSL_VERIFYPEER
'follow_location' => true, // see CURLOPT_FOLLOWLOCATION
'user_agent' => DEFAULT_HTTP_USER_AGENT,
]);
$embed = new EmbedLight(\Embed\Embed::create($url, null, $dispatcher));
$this->attributes['cache'] = base64_encode(serialize($embed));
try {
$embed = new Embed(new Crawler($client));
$configuration = Configuration::get();
if (!empty($configuration->twittertoken)) {
$embed->setSettings([
'twitter:token' => $configuration->twittertoken
]);
}
$embed->getExtractorFactory()->addDetector('images', EmbedImagesExtractor::class);
$info = $embed->get($url);
$embed = new EmbedLight($info);
$this->attributes['cache'] = base64_encode(serialize($embed));
} catch (\Exception $e) {
error_log($e->getMessage());
}
}
}

5
app/helpers/StringHelper.php

@ -20,9 +20,7 @@ function addUrls($string, bool $preview = false)
if ($preview) {
try {
$embed = Embed\Embed::create($match[0]);
if ($embed->type == 'photo'
&& $embed->images[0]['width'] <= 1024
&& $embed->images[0]['height'] <= 1024) {
if ($embed->type == 'image') {
$content = '<img src="'.$match[0].'"/>';
} elseif ($embed->type == 'link') {
$content .= ' - '. $embed->title . ' - ' . $embed->providerName;
@ -440,6 +438,7 @@ function invertSign($num)
function firstLetterCapitalize($string, bool $firstOnly = false): string
{
$size = ($firstOnly) ? 1 : 2;
$string = empty($string) ? 'M' : $string;
return mb_convert_case(mb_substr($string, 0, $size), MB_CASE_TITLE);
}

25
app/widgets/AdminMain/adminmain.tpl

@ -139,7 +139,7 @@
<h3>{$c->__('whitelist.title')}</h3>
<div>
<input type="text" name="xmppwhitelist" id="xmppwhitelist" placeholder="{$c->__('whitelist.label')}" value="{$conf->xmppwhitelist_string}" />
<input type="text" name="xmppwhitelist" id="xmppwhitelist" placeholder="{$c->__('whitelist.label')}" value="{$conf->xmppwhitelist_string ?? ''}" />
<label for="xmppwhitelist">{$c->__('whitelist.label')}</label>
</div>
@ -182,14 +182,14 @@
<h3>{$c->__('tenor.title')}</h3>
<div>
<input type="text" name="gifapikey" id="gifapikey" placeholder="123ABC" value="{$conf->gifapikey}" />
<input type="text" name="gifapikey" id="gifapikey" placeholder="123ABC" value="{$conf->gifapikey ?? ''}" />
<label for="info">{$c->__('tenor.label')}</label>
</div>
<ul class="list thick">
<li>
<span class="primary icon bubble gray">
<i class="material-icons">gif</i>
<i class="material-icons">gif_box</i>
</span>
<div>
<p>{$c->__('tenor.info1')}</p>
@ -198,6 +198,25 @@
</li>
</ul>
<h3>{$c->__('twitter.title')}</h3>
<div>
<input type="text" name="twittertoken" id="twittertoken" placeholder="123ABC" value="{$conf->twittertoken ?? ''}" />
<label for="info">{$c->__('twitter.label')}</label>
</div>
<ul class="list thick">
<li>
<span class="primary icon bubble gray">
<i class="material-icons">text_snippet</i>
</span>
<div>
<p>{$c->__('twitter.info1')}</p>
<p><a href="https://developer.twitter.com/" target="_blank">{$c->__('twitter.info2')}</a></p>
</div>
</li>
</ul>
<input
type="submit"
class="button color oppose"

6
app/widgets/AdminMain/locales.ini

@ -53,6 +53,12 @@ label = Your Tenor API Key
info1 = Movim integrates the Tenor API to allow GIF search and publication in Chat
info2 = Access Tenor and get your API key
[twitter]
title = Twitter integration
label = Your Twitter Token
info1 = The Twitter integration allow Movim to embed and extract the Tweets shared on the instance
info2 = Generate your Token on the Developer Twitter website
[log]
empty = Empty
syslog = Syslog

2
app/widgets/Chat/_chat_embed.tpl

@ -17,7 +17,7 @@
{else}
<span class="primary icon bubble gray">
{if="$embed->providerIcon"}
<img src="{$embed->providerIcon}"/>
<img src="{$embed->providerIcon|protectPicture}"/>
{else}
<i class="material-icons">link</i>
{/if}

3
app/widgets/Preview/_preview.tpl

@ -8,9 +8,8 @@
<img src="{$url|protectPicture}" title="{$url}" class="transparent"/>
{if="!empty($embed->images) && array_key_exists('size', $embed->images[0])"}
<span class="pinfo">
{$embed->images[0]['width']} × {$embed->images[0]['height']}
{if="$embed->images[0]['size'] != 0"}
- {$embed->images[0]['size']|sizeToCleanSize}
{$embed->images[0]['size']|sizeToCleanSize}
{/if}
</span>
{/if}

3
app/widgets/Preview/_preview_gallery.tpl

@ -12,9 +12,8 @@
{if="array_key_exists('size', $embed->images[$imagenumber])"}
<span class="pinfo">
{$embed->images[$imagenumber]['width']} × {$embed->images[$imagenumber]['height']}
{if="$embed->images[$imagenumber]['size'] != 0"}
- {$embed->images[$imagenumber]['size']|sizeToCleanSize}
{$embed->images[$imagenumber]['size']|sizeToCleanSize}
{/if}
</span>
{/if}

4
app/widgets/Publish/_publish_embed.tpl

@ -15,7 +15,7 @@
{if="$embed->imagenumber > 0"}
style="background-image: url({$resolved->images[$imagenumber]['url']|protectPicture})"
title="{$resolved->images[$imagenumber]['width']} x {$resolved->images[$imagenumber]['height']} - {$resolved->images[$imagenumber]['size']|sizeToCleanSize}"
title="{$resolved->images[$imagenumber]['size']|sizeToCleanSize}"
{/if}
>
<i class="material-icons">collections</i>
@ -39,7 +39,7 @@
{/if}
<div>
{if="$resolved->type == 'photo'"}
{if="$resolved->type == 'image'"}
<p class="line">{$resolved->images[$embed->imagenumber]['width']} x {$resolved->images[$embed->imagenumber]['height']}</p>
<p class="line">{$resolved->images[$embed->imagenumber]['size']|sizeToCleanSize}</p>
{else}

2
composer.json

@ -21,7 +21,7 @@
"fabiang/sasl": "^1.1.0",
"rain/raintpl": "^3.1.1",
"embed/embed": "^v3.4",
"embed/embed": "^v4.0",
"league/commonmark": "2.3.*",
"respect/validation": "^2.2",

265
composer.lock

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "5c6d68d2f19e88c6aed43ae76fdc99b4",
"content-hash": "067c3516d4c5cf213024fc44c8cd9e07",
"packages": [
{
"name": "brick/math",
@ -434,16 +434,16 @@
},
{
"name": "composer/ca-bundle",
"version": "1.3.2",
"version": "1.3.3",
"source": {
"type": "git",
"url": "https://github.com/composer/ca-bundle.git",
"reference": "fd5dd441932a7e10ca6e5b490e272d34c8430640"
"reference": "30897edbfb15e784fe55587b4f73ceefd3c4d98c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/ca-bundle/zipball/fd5dd441932a7e10ca6e5b490e272d34c8430640",
"reference": "fd5dd441932a7e10ca6e5b490e272d34c8430640",
"url": "https://api.github.com/repos/composer/ca-bundle/zipball/30897edbfb15e784fe55587b4f73ceefd3c4d98c",
"reference": "30897edbfb15e784fe55587b4f73ceefd3c4d98c",
"shasum": ""
},
"require": {
@ -490,7 +490,7 @@
"support": {
"irc": "irc://irc.freenode.org/composer",
"issues": "https://github.com/composer/ca-bundle/issues",
"source": "https://github.com/composer/ca-bundle/tree/1.3.2"
"source": "https://github.com/composer/ca-bundle/tree/1.3.3"
},
"funding": [
{
@ -506,7 +506,7 @@
"type": "tidelift"
}
],
"time": "2022-05-24T11:56:16+00:00"
"time": "2022-07-20T07:14:26+00:00"
},
{
"name": "defuse/php-encryption",
@ -1145,31 +1145,47 @@
},
{
"name": "embed/embed",
"version": "3.4.17",
"version": "v4.4.4",
"source": {
"type": "git",
"url": "https://github.com/oscarotero/Embed.git",
"reference": "2c0e112f7332597ec6a55174f2353e04859ba356"
"reference": "52c2d77f58672868346ae09b0fa1eecc818bdf42"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/oscarotero/Embed/zipball/2c0e112f7332597ec6a55174f2353e04859ba356",
"reference": "2c0e112f7332597ec6a55174f2353e04859ba356",
"url": "https://api.github.com/repos/oscarotero/Embed/zipball/52c2d77f58672868346ae09b0fa1eecc818bdf42",
"reference": "52c2d77f58672868346ae09b0fa1eecc818bdf42",
"shasum": ""
},
"require": {
"composer/ca-bundle": "^1.0",
"ext-curl": "*",
"ext-dom": "*",
"ext-json": "*",
"ext-mbstring": "*",
"php": "^5.6|^7.0|^8.0"
"ml/json-ld": "^1.1",
"oscarotero/html-parser": "^0.1.4",
"php": "^7.4|^8",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0"
},
"require-dev": {
"brick/varexporter": "^0.3.1",
"friendsofphp/php-cs-fixer": "^2.0",
"phpunit/phpunit": "^5.7|^6.0|^7.0"
"nyholm/psr7": "^1.2",
"oscarotero/php-cs-fixer-config": "^1.0",
"phpunit/phpunit": "^9.0",
"symfony/css-selector": "^5.0"
},
"suggest": {
"symfony/css-selector": "If you want to get elements using css selectors"
},
"type": "library",
"autoload": {
"files": [
"src/functions.php"
],
"psr-4": {
"Embed\\": "src"
}
@ -1198,9 +1214,23 @@
"support": {
"email": "oom@oscarotero.com",
"issues": "https://github.com/oscarotero/Embed/issues",
"source": "https://github.com/oscarotero/Embed/tree/3.4.17"
"source": "https://github.com/oscarotero/Embed/tree/v4.4.4"
},
"time": "2021-05-30T11:21:47+00:00"
"funding": [
{
"url": "https://paypal.me/oscarotero",
"type": "custom"
},
{
"url": "https://github.com/oscarotero",
"type": "github"
},
{
"url": "https://www.patreon.com/misteroom",
"type": "patreon"
}
],
"time": "2022-04-13T18:22:11+00:00"
},
{
"name": "evenement/evenement",
@ -1825,7 +1855,7 @@
},
{
"name": "illuminate/bus",
"version": "v8.83.19",
"version": "v8.83.21",
"source": {
"type": "git",
"url": "https://github.com/illuminate/bus.git",
@ -1878,7 +1908,7 @@
},
{
"name": "illuminate/collections",
"version": "v8.83.19",
"version": "v8.83.21",
"source": {
"type": "git",
"url": "https://github.com/illuminate/collections.git",
@ -1932,7 +1962,7 @@
},
{
"name": "illuminate/container",
"version": "v8.83.19",
"version": "v8.83.21",
"source": {
"type": "git",
"url": "https://github.com/illuminate/container.git",
@ -1983,7 +2013,7 @@
},
{
"name": "illuminate/contracts",
"version": "v8.83.19",
"version": "v8.83.21",
"source": {
"type": "git",
"url": "https://github.com/illuminate/contracts.git",
@ -2031,16 +2061,16 @@
},
{
"name": "illuminate/database",
"version": "v8.83.19",
"version": "v8.83.21",
"source": {
"type": "git",
"url": "https://github.com/illuminate/database.git",
"reference": "c3ac7b0c8935cf224bdf1a1b0ea3f529fcfe2d86"
"reference": "9c056fddf7c2a5cf30d3ffac3c7e50fcc5f8a322"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/database/zipball/c3ac7b0c8935cf224bdf1a1b0ea3f529fcfe2d86",
"reference": "c3ac7b0c8935cf224bdf1a1b0ea3f529fcfe2d86",
"url": "https://api.github.com/repos/illuminate/database/zipball/9c056fddf7c2a5cf30d3ffac3c7e50fcc5f8a322",
"reference": "9c056fddf7c2a5cf30d3ffac3c7e50fcc5f8a322",
"shasum": ""
},
"require": {
@ -2095,11 +2125,11 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"time": "2022-07-01T20:43:43+00:00"
"time": "2022-07-14T14:03:49+00:00"
},
{
"name": "illuminate/events",
"version": "v8.83.19",
"version": "v8.83.21",
"source": {
"type": "git",
"url": "https://github.com/illuminate/events.git",
@ -2154,7 +2184,7 @@
},
{
"name": "illuminate/macroable",
"version": "v8.83.19",
"version": "v8.83.21",
"source": {
"type": "git",
"url": "https://github.com/illuminate/macroable.git",
@ -2200,7 +2230,7 @@
},
{
"name": "illuminate/pipeline",
"version": "v8.83.19",
"version": "v8.83.21",
"source": {
"type": "git",
"url": "https://github.com/illuminate/pipeline.git",
@ -2248,7 +2278,7 @@
},
{
"name": "illuminate/support",
"version": "v8.83.19",
"version": "v8.83.21",
"source": {
"type": "git",
"url": "https://github.com/illuminate/support.git",
@ -2316,16 +2346,16 @@
},
{
"name": "league/commonmark",
"version": "2.3.3",
"version": "2.3.4",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/commonmark.git",
"reference": "0da1dca5781dd3cfddbe328224d9a7a62571addc"
"reference": "155ec1c95626b16fda0889cf15904d24890a60d5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/0da1dca5781dd3cfddbe328224d9a7a62571addc",
"reference": "0da1dca5781dd3cfddbe328224d9a7a62571addc",
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/155ec1c95626b16fda0889cf15904d24890a60d5",
"reference": "155ec1c95626b16fda0889cf15904d24890a60d5",
"shasum": ""
},
"require": {
@ -2418,7 +2448,7 @@
"type": "tidelift"
}
],
"time": "2022-06-07T21:28:26+00:00"
"time": "2022-07-17T16:25:47+00:00"
},
{
"name": "league/config",
@ -2566,6 +2596,110 @@
},
"time": "2022-03-29T13:54:20+00:00"
},
{
"name": "ml/iri",
"version": "1.1.4",
"target-dir": "ML/IRI",
"source": {
"type": "git",
"url": "https://github.com/lanthaler/IRI.git",
"reference": "cbd44fa913e00ea624241b38cefaa99da8d71341"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/lanthaler/IRI/zipball/cbd44fa913e00ea624241b38cefaa99da8d71341",
"reference": "cbd44fa913e00ea624241b38cefaa99da8d71341",
"shasum": ""
},
"require": {
"lib-pcre": ">=4.0",
"php": ">=5.3.0"
},
"type": "library",
"autoload": {
"psr-0": {
"ML\\IRI": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Markus Lanthaler",
"email": "mail@markus-lanthaler.com",
"homepage": "http://www.markus-lanthaler.com",
"role": "Developer"
}
],
"description": "IRI handling for PHP",
"homepage": "http://www.markus-lanthaler.com",
"keywords": [
"URN",
"iri",
"uri",
"url"
],
"support": {
"issues": "https://github.com/lanthaler/IRI/issues",
"source": "https://github.com/lanthaler/IRI/tree/master"
},
"time": "2014-01-21T13:43:39+00:00"
},
{
"name": "ml/json-ld",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/lanthaler/JsonLD.git",
"reference": "c74a1aed5979ed1cfb1be35a55a305fd30e30b93"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/lanthaler/JsonLD/zipball/c74a1aed5979ed1cfb1be35a55a305fd30e30b93",
"reference": "c74a1aed5979ed1cfb1be35a55a305fd30e30b93",
"shasum": ""
},
"require": {
"ext-json": "*",
"ml/iri": "^1.1.1",
"php": ">=5.3.0"
},
"require-dev": {
"json-ld/tests": "1.0",
"phpunit/phpunit": "^4"
},
"type": "library",
"autoload": {
"psr-4": {
"ML\\JsonLD\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Markus Lanthaler",
"email": "mail@markus-lanthaler.com",
"homepage": "http://www.markus-lanthaler.com",
"role": "Developer"
}
],
"description": "JSON-LD Processor for PHP",
"homepage": "http://www.markus-lanthaler.com",
"keywords": [
"JSON-LD",
"jsonld"
],
"support": {
"issues": "https://github.com/lanthaler/JsonLD/issues",
"source": "https://github.com/lanthaler/JsonLD/tree/1.2.0"
},
"time": "2020-06-16T17:45:06+00:00"
},
{
"name": "monolog/monolog",
"version": "2.7.0",
@ -2919,6 +3053,59 @@
},
"time": "2022-01-24T11:29:14+00:00"
},
{
"name": "oscarotero/html-parser",
"version": "v0.1.6",
"source": {
"type": "git",
"url": "https://github.com/oscarotero/html-parser.git",
"reference": "b61e92f634d0dc184339d24630a6968d3ac64ded"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/oscarotero/html-parser/zipball/b61e92f634d0dc184339d24630a6968d3ac64ded",
"reference": "b61e92f634d0dc184339d24630a6968d3ac64ded",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.11",
"phpunit/phpunit": "^8.0"
},
"type": "library",
"autoload": {
"psr-4": {
"HtmlParser\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Oscar Otero",
"email": "oom@oscarotero.com",
"homepage": "http://oscarotero.com",
"role": "Developer"
}
],
"description": "Parse html strings to DOMDocument",
"homepage": "https://github.com/oscarotero/html-parser",
"keywords": [
"dom",
"html",
"parser"
],
"support": {
"email": "oom@oscarotero.com",
"issues": "https://github.com/oscarotero/html-parser/issues",
"source": "https://github.com/oscarotero/html-parser/tree/v0.1.6"
},
"time": "2020-11-19T17:43:46+00:00"
},
{
"name": "paragonie/random_compat",
"version": "v9.99.100",
@ -4585,16 +4772,16 @@
},
{
"name": "robmorgan/phinx",
"version": "0.12.11",
"version": "0.12.12",
"source": {
"type": "git",
"url": "https://github.com/cakephp/phinx.git",
"reference": "2046c447b1a4425956555118200138e22ebd680c"
"reference": "9a6ce1e7fdf0fa4e602ba5875b5bc9442ccaa115"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/cakephp/phinx/zipball/2046c447b1a4425956555118200138e22ebd680c",
"reference": "2046c447b1a4425956555118200138e22ebd680c",
"url": "https://api.github.com/repos/cakephp/phinx/zipball/9a6ce1e7fdf0fa4e602ba5875b5bc9442ccaa115",
"reference": "9a6ce1e7fdf0fa4e602ba5875b5bc9442ccaa115",
"shasum": ""
},
"require": {
@ -4665,9 +4852,9 @@
],
"support": {
"issues": "https://github.com/cakephp/phinx/issues",
"source": "https://github.com/cakephp/phinx/tree/0.12.11"
"source": "https://github.com/cakephp/phinx/tree/0.12.12"
},
"time": "2022-07-03T16:41:43+00:00"
"time": "2022-07-09T18:53:51+00:00"
},
{
"name": "spomky-labs/base64url",

21
database/migrations/20220722133156_add_twitter_token_to_configuration_table.php

@ -0,0 +1,21 @@
<?php
use Movim\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddTwitterTokenToConfigurationTable extends Migration
{
public function up()
{
$this->schema->table('configuration', function (Blueprint $table) {
$table->string('twittertoken')->nullable();
});
}
public function down()
{
$this->schema->table('configuration', function (Blueprint $table) {
$table->dropColumn('twittertoken');
});
}
}

2
src/Movim/Bootstrap.php

@ -312,8 +312,6 @@ class Bootstrap
{
if (\is_array($trace)) $trace = '';
echo 'An error occured, check syslog for more information'."\n";
$error = $errstr . " in " . $errfile . ' (line ' . $errline . ")\n" . 'Trace' . "\n" . $trace;
if (class_exists('Utils')) {

23
src/Movim/EmbedImagesExtractor.php

@ -0,0 +1,23 @@
<?php
declare(strict_types = 1);
namespace Movim;
use Embed\Detectors\Detector;
class EmbedImagesExtractor extends Detector
{
public function detect(): array
{
$document = $this->extractor->getDocument();
$images = [];
foreach ($document->select('.//img')->nodes() as $node) {
$src = $node->getAttribute('src');
$images[$src] = $this->extractor->resolveUri($src);
}
return $images;
}
}

67
src/Movim/EmbedLight.php

@ -6,43 +6,56 @@ class EmbedLight
{
public function __construct($embed)
{
$this->title = $embed->title;
$this->title = $embed->title ? (string)$embed->title : (string)$embed->url;
$this->description = $embed->description;
$this->url = $embed->url;
$this->type = $embed->type;
$this->contentType = $embed->getResponse()->getContentType();
$this->tags = $embed->tags;
$this->image = $embed->image;
$this->imageWidth = $embed->imageWidth;
$this->imageHeight = $embed->imageHeight;
$this->images = $embed->images;
$this->authorName = $embed->authorName;
$this->authorUrl = $embed->authorUrl;
$this->providerIcon = $embed->providerIcon;
$this->providerIcons = $embed->providerIcons;
$this->url = (string)$embed->url;
$this->contentType = $embed->getResponse()->getHeader('content-type')[0];
$this->type = 'text';
if (typeIsPicture($this->contentType)) {
$this->type = 'image';
} elseif (typeIsVideo($this->contentType)) {
$this->type = 'video';
}
$this->tags = (array)$embed->keywords;
$this->authorName = $embed->authorName ? (string)$embed->authorName : null;
$this->authorUrl = $embed->authorUrl ? (string)$embed->authorUrl : null;
$this->providerIcon = $embed->icon ? (string)$embed->icon : null;
$this->providerName = $embed->providerName;
$this->providerUrl = $embed->providerUrl;
$this->providerUrl = $embed->providerUrl ? (string)$embed->providerUrl : null;
$this->publishedTime = $embed->publishedTime;
$this->license = $embed->license;
// Adjust the default behavior of Embed by using the file size for the images size
foreach ($embed->getDispatcher()->getAllResponses() as $response) {
foreach ($this->images as $key => $image) {
if ($image['url'] == $response->getUrl()) {
$this->images[$key]['size'] = $response->getHeader('Content-Length');
}
}
}
// Images
$this->images = [];
foreach ($this->images as $key => $image) {
if ($key != 0 && $image['width'] < 512 && $image['height'] < 512) {
unset($this->images[$key]);
if ($this->type == 'image') {
$this->images = [
[
'url' => (string)$embed->url,
'size' => $embed->getResponse()->getHeader('content-length')[0]
]
];
} elseif ($embed->image) {
$this->images = [
[
'url' => (string)$embed->image,
'size' => 0
]
];
} /*elseif($embed->images) {
foreach ($embed->images as $key => $image) {
$this->images[$key] = [
'url' => (string)$key,
'size' => 0
];
}
}
}*/
// Reset the keys
$this->images = array_values($this->images);
return $this;
}
}
Loading…
Cancel
Save