diff --git a/inc/Services/Embed/EmbedService.php b/inc/Services/Embed/EmbedService.php new file mode 100644 index 00000000..eb3ba21b --- /dev/null +++ b/inc/Services/Embed/EmbedService.php @@ -0,0 +1,64 @@ +log = $log; + } + + /** + * Undocumented function + * + * @param Context $ctx + * @param string $rawText + * @return void + */ + public function matchEmbed(Context $ctx, string $rawText) { + if (\filter_var($rawText, \FILTER_VALIDATE_URL) === false) { + return null; + } + $rawText = \trim($rawText); + + foreach ($this->tuples as $cfg) { + if (!isset($cfg['match_regex'])) { + throw new \RuntimeException('Missing \'match_regex\' field'); + } + $match_regex = $cfg['match_regex']; + + if (\preg_match($match_regex, $rawText, $matches)) { + if (!isset($cfg['type'])) { + throw new \RuntimeException('Missing \'type\' field'); + } + $type = $cfg['type']; + + if ($type === 'oembed') { + if (!isset($cfg['provider'])) { + throw new \RuntimeException('Missing \'provider\' field'); + } + $provider = $cfg['provider']; + + $extractor = $ctx->get(OembedExtractor::class); + $oembed_resp = $extractor->fetch($provider, $rawText); + + + } elseif ($type === 'regex') { + if (!isset($cfg['thumbnail_url'])) { + throw new \RuntimeException('Missing \'thumbnail_url\' field'); + } + $thumbnail_url_regex = $cfg['thumbnail_url']; + // Plz somebody review this. + $thumbnail_url = \preg_replace($match_regex, $thumbnail_url_regex, $rawText); + } else { + $this->log->log(LogDriver::ERROR, "Unknown embed type '$type', ignoring"); + } + } + } + } +}