diff options
author | Andrew Dolgov <[email protected]> | 2021-05-07 07:39:20 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-05-07 07:39:20 +0300 |
commit | 3067b81c679608342feceee4e5516fa021988ef0 (patch) | |
tree | 6b97b3748fa74abba997a52c5c5b80963fc54c41 | |
parent | 417bfe1db1ec316e6644e35aa39e0ac8077059be (diff) |
use core youtube vid helper
-rw-r--r-- | init.php | 25 |
1 files changed, 2 insertions, 23 deletions
@@ -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"); |