diff --git a/composer.json b/composer.json index ddf47155deedac9f3184db0228008bfb326fb066..0828a515d23f506f72af71361b533e54386fb518 100644 --- a/composer.json +++ b/composer.json @@ -57,8 +57,7 @@ "symfony/doctrine-bridge": "^7.0", "bref/bref": "^2.1", "symfony/http-foundation": "^7.0", - "symfony/expression-language": "^7.0", - "embed/embed": "^4.4" + "symfony/expression-language": "^7.0" }, "require-dev": { "phpunit/phpunit": "^11.0", diff --git a/composer.lock b/composer.lock index af6f6e380d6f6cf86c6d36d0b6119eb78455baca..041c89f9f680f82d2ff3c6eb44e27d8ec2055b3a 100644 --- a/composer.lock +++ b/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": "93d0e2fe2c71e7ea9f7c17b349067d52", + "content-hash": "ef6348bdeee54a23ab896acae84599e3", "packages": [ { "name": "amphp/amp", @@ -641,82 +641,6 @@ ], "time": "2024-03-15T10:23:05+00:00" }, - { - "name": "composer/ca-bundle", - "version": "1.5.0", - "source": { - "type": "git", - "url": "https://github.com/composer/ca-bundle.git", - "reference": "0c5ccfcfea312b5c5a190a21ac5cef93f74baf99" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/ca-bundle/zipball/0c5ccfcfea312b5c5a190a21ac5cef93f74baf99", - "reference": "0c5ccfcfea312b5c5a190a21ac5cef93f74baf99", - "shasum": "" - }, - "require": { - "ext-openssl": "*", - "ext-pcre": "*", - "php": "^7.2 || ^8.0" - }, - "require-dev": { - "phpstan/phpstan": "^1.10", - "psr/log": "^1.0", - "symfony/phpunit-bridge": "^4.2 || ^5", - "symfony/process": "^4.0 || ^5.0 || ^6.0 || ^7.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Composer\\CaBundle\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - } - ], - "description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.", - "keywords": [ - "cabundle", - "cacert", - "certificate", - "ssl", - "tls" - ], - "support": { - "irc": "irc://irc.freenode.org/composer", - "issues": "https://github.com/composer/ca-bundle/issues", - "source": "https://github.com/composer/ca-bundle/tree/1.5.0" - }, - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], - "time": "2024-03-15T14:00:32+00:00" - }, { "name": "crwlr/query-string", "version": "v1.0.3", @@ -2124,95 +2048,6 @@ ], "time": "2023-10-06T06:47:41+00:00" }, - { - "name": "embed/embed", - "version": "v4.4.10", - "source": { - "type": "git", - "url": "https://github.com/oscarotero/Embed.git", - "reference": "8ac21505d048e8796c6cb9172ec5e81e5d0e0408" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/oscarotero/Embed/zipball/8ac21505d048e8796c6cb9172ec5e81e5d0e0408", - "reference": "8ac21505d048e8796c6cb9172ec5e81e5d0e0408", - "shasum": "" - }, - "require": { - "composer/ca-bundle": "^1.0", - "ext-curl": "*", - "ext-dom": "*", - "ext-json": "*", - "ext-mbstring": "*", - "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|^2.0" - }, - "require-dev": { - "brick/varexporter": "^0.3.1", - "friendsofphp/php-cs-fixer": "^2.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" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Oscar Otero", - "email": "oom@oscarotero.com", - "homepage": "http://oscarotero.com", - "role": "Developer" - } - ], - "description": "PHP library to retrieve page info using oembed, opengraph, etc", - "homepage": "https://github.com/oscarotero/Embed", - "keywords": [ - "embed", - "embedly", - "oembed", - "opengraph", - "twitter cards" - ], - "support": { - "email": "oom@oscarotero.com", - "issues": "https://github.com/oscarotero/Embed/issues", - "source": "https://github.com/oscarotero/Embed/tree/v4.4.10" - }, - "funding": [ - { - "url": "https://paypal.me/oscarotero", - "type": "custom" - }, - { - "url": "https://github.com/oscarotero", - "type": "github" - }, - { - "url": "https://www.patreon.com/misteroom", - "type": "patreon" - } - ], - "time": "2023-12-10T12:30:47+00:00" - }, { "name": "ezyang/htmlpurifier", "version": "v4.17.0", @@ -4595,110 +4430,6 @@ ], "time": "2023-11-24T15:40:42+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.1", - "source": { - "type": "git", - "url": "https://github.com/lanthaler/JsonLD.git", - "reference": "537e68e87a6bce23e57c575cd5dcac1f67ce25d8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/lanthaler/JsonLD/zipball/537e68e87a6bce23e57c575cd5dcac1f67ce25d8", - "reference": "537e68e87a6bce23e57c575cd5dcac1f67ce25d8", - "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.1" - }, - "time": "2022-09-29T08:45:17+00:00" - }, { "name": "nette/php-generator", "version": "v4.1.4", @@ -5114,59 +4845,6 @@ ], "time": "2023-11-08T09:30:43+00:00" }, - { - "name": "oscarotero/html-parser", - "version": "v0.1.8", - "source": { - "type": "git", - "url": "https://github.com/oscarotero/html-parser.git", - "reference": "10f3219267a365d9433f2f7d1694209c9d436c8d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/oscarotero/html-parser/zipball/10f3219267a365d9433f2f7d1694209c9d436c8d", - "reference": "10f3219267a365d9433f2f7d1694209c9d436c8d", - "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.8" - }, - "time": "2023-11-29T20:28:41+00:00" - }, { "name": "paragonie/random_compat", "version": "v9.99.100", diff --git a/resources/css/docs-page-document.css b/resources/css/docs-page-document.css index 02e4758521ef38e3af0a5b8b09dabf90ad64f1da..18ac6f9caee5e2628c4b3423e440e009230db9d3 100644 --- a/resources/css/docs-page-document.css +++ b/resources/css/docs-page-document.css @@ -73,6 +73,7 @@ iframe { align-self: center; + min-height: 480px; width: 100%; } } diff --git a/src/CommonMarkEmbedAdapter.php b/src/CommonMarkEmbedAdapter.php new file mode 100644 index 0000000000000000000000000000000000000000..1f8fe2114d8224cd8230d0194e45b17511b59acc --- /dev/null +++ b/src/CommonMarkEmbedAdapter.php @@ -0,0 +1,43 @@ +<?php + +declare(strict_types=1); + +namespace Distantmagic\Resonance; + +use Distantmagic\Resonance\Attribute\Singleton; +use League\CommonMark\Extension\Embed\Embed; +use League\CommonMark\Extension\Embed\EmbedAdapterInterface; +use League\CommonMark\Util\HtmlElement; + +#[Singleton] +readonly class CommonMarkEmbedAdapter implements EmbedAdapterInterface +{ + private const PATTERN = '(?:.+?)?(?:\/v\/|watch\/|\?v=|\&v=|youtu\.be\/|\/v=|^youtu\.be\/|watch\%3Fv\%3D)([a-zA-Z0-9_-]{11})+?'; + + public function getHtmlElement(Embed $embed): HtmlElement + { + return new HtmlElement( + 'iframe', + [ + 'src' => 'https://www.youtube-nocookie.com/embed/'.$this->getId($embed->getUrl()), + 'frameborder' => '0', + 'allow' => 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture', + 'allowfullscreen' => '', + ], + ); + } + + public function updateEmbeds(array $embeds): void + { + foreach ($embeds as $embed) { + $embed->setEmbedCode((string) $this->getHtmlElement($embed)); + } + } + + protected function getId(string $url): string + { + preg_match('/'.self::PATTERN.'/', $url, $matches); + + return $matches[1] ?? ''; + } +} diff --git a/src/StaticPageMarkdownParser.php b/src/StaticPageMarkdownParser.php index d5f7c5197db45d751ae0032544a91dbc9d5624c8..b721e8889e8ef758eb1dd5d02a21e8af555e72ba 100644 --- a/src/StaticPageMarkdownParser.php +++ b/src/StaticPageMarkdownParser.php @@ -6,13 +6,11 @@ namespace Distantmagic\Resonance; use Distantmagic\Resonance\Attribute\GrantsFeature; use Distantmagic\Resonance\Attribute\Singleton; -use Embed\Embed; use League\CommonMark\Environment\Environment; use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode; use League\CommonMark\Extension\CommonMark\Node\Inline\Code; use League\CommonMark\Extension\DescriptionList\DescriptionListExtension; -use League\CommonMark\Extension\Embed\Bridge\OscaroteroEmbedAdapter; use League\CommonMark\Extension\Embed\EmbedExtension; use League\CommonMark\Extension\ExternalLink\ExternalLinkExtension; use League\CommonMark\Extension\GithubFlavoredMarkdownExtension; @@ -27,20 +25,13 @@ readonly class StaticPageMarkdownParser public Environment $environment; public function __construct( + CommonMarkEmbedAdapter $commonMarkEmbedAdapter, StaticPageAggregate $staticPageAggregate, StaticPageConfiguration $staticPageConfiguration, ) { - $embed = new Embed(); - $embed->setSettings([ - 'oembed:query_parameters' => [ - 'maxwidth' => 800, - 'maxheight' => 600, - ], - ]); - $this->environment = new Environment([ 'embed' => [ - 'adapter' => new OscaroteroEmbedAdapter($embed), + 'adapter' => $commonMarkEmbedAdapter, 'allowed_domains' => [ 'github.com', 'youtube.com',