feat: 产品
refactor: 产品详情页seo
This commit is contained in:
@@ -13,3 +13,82 @@ if (!function_exists('str_contains')) {
|
||||
return \think\helper\Str::contains($haystack, $needle);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('rgb_or_image')) {
|
||||
/**
|
||||
* 判断字符串是否为RGB颜色值或图片链接
|
||||
* @param string $str 要判断的字符串
|
||||
* @return string IMAGE|RGB|''
|
||||
*/
|
||||
function rgb_or_image(string $str): string
|
||||
{
|
||||
if (
|
||||
\think\helper\Str::startsWith($str, ['http', 'https']) ||
|
||||
\think\helper\Str::endsWith($str, ['.png', '.jpg', '.jpeg', '.gif', '.tif', '.svg', '.webp', '.bmp']) ||
|
||||
preg_match('/^data:image\/[jpg|jpeg|png|svg\+xml];base64,.+$/', $str)
|
||||
) {
|
||||
return 'IMAGE';
|
||||
}
|
||||
|
||||
if (
|
||||
preg_match('/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/', $str) ||
|
||||
preg_match('/^rgb\(\d{1,3},\s*\d{1,3},\s*\d{1,3}\)$/', $str) ||
|
||||
preg_match('/^rgba\(\d{1,3},\s*\d{1,3},\s*\d{1,3},\s*\d*(\.\d+)?\)$/', $str)
|
||||
) {
|
||||
return 'RGB';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('style')) {
|
||||
/**
|
||||
* 输出style行内样式 - 避免编辑器因css校验规则提示错误
|
||||
* @param array|string $styles 样式数组
|
||||
* @return string
|
||||
*/
|
||||
function style(array|string $styles): string
|
||||
{
|
||||
$css = '';
|
||||
if (is_array($styles)) {
|
||||
$key = array_keys($styles);
|
||||
foreach ($key as $v) {
|
||||
$css .= $v . ':' . $styles[$v] . ';';
|
||||
}
|
||||
} else {
|
||||
$css = $styles;
|
||||
}
|
||||
return 'style="' . $css . '"';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('thumb')) {
|
||||
/**
|
||||
* 获取缩略图
|
||||
* @param string $url 图片地址
|
||||
* @return string
|
||||
*/
|
||||
function thumb(string $url): string
|
||||
{
|
||||
if (empty($url)) {
|
||||
return '';
|
||||
}
|
||||
if (
|
||||
str_contains($url, '_thumb') ||
|
||||
\think\helper\Str::startsWith($url, ['http://', 'https://']) ||
|
||||
!\think\helper\Str::endsWith($url, ['.png', '.jpg', '.jpeg', '.gif', '.tif', '.svg', '.webp', '.bmp'])
|
||||
) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$idx = mb_strripos($url, '.', 0, 'utf-8');
|
||||
if ($idx === false) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$len = mb_strlen($url, 'utf-8');
|
||||
|
||||
return mb_substr($url, 0, $idx, 'utf-8') . '_thumb' . mb_substr($url, $idx, $len - $idx, 'utf-8');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user