From a3c27ce3558a296bf90f9470ff3188696e87d0f3 Mon Sep 17 00:00:00 2001 From: filesite Date: Thu, 16 May 2024 09:10:29 +0800 Subject: [PATCH] parse url from string function improved --- plugins/Common.php | 11 +++++++++++ themes/tajian/controller/FrontapiController.php | 13 +------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/Common.php b/plugins/Common.php index 948991b..45e03ff 100644 --- a/plugins/Common.php +++ b/plugins/Common.php @@ -186,4 +186,15 @@ Class Common { return session_destroy(); } + public static function getShareUrlFromContent($content) { + $url = ''; + + preg_match("/http(s)?:\/\/[\w\-\.]+\.([a-z]){2,}[\/\w\-\.\?\=]*/i", $content, $matches); + if (!empty($matches)) { + $url = $matches[0]; + } + + return $url; + } + } \ No newline at end of file diff --git a/themes/tajian/controller/FrontapiController.php b/themes/tajian/controller/FrontapiController.php index b8fcfb8..9029cdc 100644 --- a/themes/tajian/controller/FrontapiController.php +++ b/themes/tajian/controller/FrontapiController.php @@ -87,7 +87,7 @@ Class FrontApiController extends SiteController { } //分享内容来源平台检查 - $shareUrl = $this->getShareUrlFromContent($content); + $shareUrl = Common::getShareUrlFromContent($content); $platform = Html::getShareVideosPlatform($shareUrl); if (!in_array($platform, FSC::$app['config']['tajian']['supportedPlatforms'])) { $code = 0; @@ -147,17 +147,6 @@ Class FrontApiController extends SiteController { return md5($url); } - protected function getShareUrlFromContent($content) { - $url = ''; - - preg_match("/https:\/\/[\w\.]+(\/\w+){1,}\/?/i", $content, $matches); - if (!empty($matches)) { - $url = $matches[0]; - } - - return $url; - } - //保存分享视频 protected function saveShareVideo($shareUrl, $title, $tagName) { $done = true;