This commit is contained in:
Your Name
2026-04-22 13:39:28 +08:00
parent b943ea2ab7
commit c1ac050c6a
17 changed files with 893 additions and 20 deletions

View File

@@ -776,18 +776,24 @@ namespace {
return $strZh;
}
$strPinYinToolsPath = root_path() . '/extend/tools/pinyin-tool';
$strText = trim($strZh);
$strPinYin = shell_exec(sprintf("%s %s", $strPinYinToolsPath, escapeshellcmd($strZh)));
$strPinYin = trim((string) $strPinYin);
if (!is_string($strPinYin) || trim($strPinYin) === '') {
return 'k_' . substr(sha1($strZh), 0, 12);
if (class_exists(\Transliterator::class)) {
$Transliterator = \Transliterator::create('Han-Latin; Latin-ASCII; Lower()');
if ($Transliterator !== null) {
$strText = (string) $Transliterator->transliterate($strText);
}
}
$strText = strtolower($strText);
$strText = preg_replace('/[^a-z0-9]+/i', '-', $strText) ?? '';
$strText = trim($strText, '-');
return $strPinYin;
if ($strText === '') {
return 'k-' . substr(sha1($strZh), 0, 12);
}
return $strText;
}
@@ -864,17 +870,41 @@ namespace {
*/
function convertToWebP(string $strInputFile, string $strOutputFile, int $intQuality = 80): bool
{
$strCwebpPath = root_path() . '/extend/tools/cwebp';
$strCMD = escapeshellcmd("$strCwebpPath -q $intQuality " . escapeshellarg($strInputFile) . " -o " . escapeshellarg($strOutputFile));
exec($strCMD . ' 2>&1', $strOutput, $intReturnCode);
if ($intReturnCode === 0) {
return true;
} else {
if (!is_file($strInputFile) || !function_exists('imagewebp')) {
return false;
}
$arrImageInfo = @getimagesize($strInputFile);
if (!is_array($arrImageInfo)) {
return false;
}
$Image = match ($arrImageInfo[2] ?? null) {
IMAGETYPE_JPEG => @imagecreatefromjpeg($strInputFile),
IMAGETYPE_PNG => @imagecreatefrompng($strInputFile),
IMAGETYPE_GIF => @imagecreatefromgif($strInputFile),
IMAGETYPE_WEBP => function_exists('imagecreatefromwebp') ? @imagecreatefromwebp($strInputFile) : false,
default => false,
};
if ($Image === false) {
return false;
}
imagepalettetotruecolor($Image);
imagealphablending($Image, true);
imagesavealpha($Image, true);
$strOutputDir = dirname($strOutputFile);
if (!is_dir($strOutputDir) && !@mkdir($strOutputDir, 0777, true) && !is_dir($strOutputDir)) {
imagedestroy($Image);
return false;
}
$boolResult = @imagewebp($Image, $strOutputFile, max(0, min(100, $intQuality)));
imagedestroy($Image);
return $boolResult && is_file($strOutputFile);
}
/**

View File

@@ -516,7 +516,10 @@ class SiteContext
public function getSiteMapByCode(string $strCode): Response
{
$strFile = root_path('storage/SiteMap') . $this->DomainModel->d_domain . '/';
$strFile = rtrim((string)root_path('storage/SiteMap'), DIRECTORY_SEPARATOR)
. DIRECTORY_SEPARATOR
. $this->DomainModel->d_domain
. DIRECTORY_SEPARATOR;
$intPage = $this->Request->route('page', 1);

View File

@@ -52,7 +52,7 @@ class SiteMapLogic
$this->arrNovelStatus = StaticConfig::$arrNovelStatus;
$this->strDate = date('Y-m-d');
$this->strSiteMapPath = root_path('storage/SiteMap');
$this->strSiteMapPath = rtrim((string)root_path('storage/SiteMap'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$this->NovelModel = NovelModel::getInstance();

View File

@@ -67,7 +67,7 @@ class VideoSiteMapLogic
$this->arrVideoYear = StaticConfig::$arrVideoYear;
$this->strDate = date('Y-m-d');
$this->strSiteMapPath = root_path('storage/SiteMap');
$this->strSiteMapPath = rtrim((string)root_path('storage/SiteMap'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$this->VideoModel = VideoModel::getInstance();