From 3067b81c679608342feceee4e5516fa021988ef0 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 7 May 2021 07:39:20 +0300 Subject: use core youtube vid helper --- init.php | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/init.php b/init.php index c1eaee1..9a5cf0f 100644 --- a/init.php +++ b/init.php @@ -20,32 +20,11 @@ class Af_Youtube_Thumb extends Plugin { return file_get_contents(__DIR__ . "/init.css"); } - function url_to_youtube_vid($url) { - $url = str_replace("youtube.com", "youtube-nocookie.com", $url); - - $regexps = [ - "/\/\/www\.youtube-nocookie\.com\/v\/([\w-]+)/", - "/\/\/www\.youtube-nocookie\.com\/embed\/([\w-]+)/", - "/\/\/www\.youtube-nocookie\.com\/watch?v=([\w-]+)/", - "/\/\/youtu.be\/([\w-]+)/", - ]; - - foreach ($regexps as $re) { - $matches = []; - - if (preg_match($re, $url, $matches)) { - return $matches[1]; - } - } - - return false; - } - function hook_render_enclosure($entry, $hide_images) { $url = $entry["content_url"]; - if ($vid_id = $this->url_to_youtube_vid($url)) { + if ($vid_id = UrlHelper::url_to_youtube_vid($url)) { $thumb_url = htmlspecialchars("https://img.youtube.com/vi/$vid_id/hqdefault.jpg"); $url = htmlspecialchars($url); @@ -80,7 +59,7 @@ class Af_Youtube_Thumb extends Plugin { foreach ($iframes as $iframe) { $url = $iframe->getAttribute("src"); - if ($vid_id = $this->url_to_youtube_vid($url)) { + if ($vid_id = UrlHelper::url_to_youtube_vid($url)) { $thumb_url = htmlspecialchars("https://img.youtube.com/vi/$vid_id/hqdefault.jpg"); $img = $doc->createElement("img"); -- cgit v1.2.3