Browse Source

parse url from string function improved

master
filesite 6 months ago
parent
commit
a3c27ce355
  1. 11
      plugins/Common.php
  2. 13
      themes/tajian/controller/FrontapiController.php

11
plugins/Common.php

@ -186,4 +186,15 @@ Class Common {
return session_destroy(); 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;
}
} }

13
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); $platform = Html::getShareVideosPlatform($shareUrl);
if (!in_array($platform, FSC::$app['config']['tajian']['supportedPlatforms'])) { if (!in_array($platform, FSC::$app['config']['tajian']['supportedPlatforms'])) {
$code = 0; $code = 0;
@ -147,17 +147,6 @@ Class FrontApiController extends SiteController {
return md5($url); 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) { protected function saveShareVideo($shareUrl, $title, $tagName) {
$done = true; $done = true;

Loading…
Cancel
Save