Skip to content

Commit

Permalink
🔨 修复 部分环境下 GLOB_BRACE 不支持问题
Browse files Browse the repository at this point in the history
fix #131
  • Loading branch information
bhaoo committed Mar 4, 2025
1 parent 082687c commit 8e7d6de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,18 @@ function randPic(){
if ($setting == 'api.ohmyga.cn') {
$output = 'https://api.ohmyga.cn/wallpaper/?rand='.$rand;
}elseif ($setting == 'local') {
$openfile = glob(Helper::options()->themeFile("Cuckoo", "random/*"), GLOB_BRACE);
$img = array_rand($openfile);
preg_match('/\/random\/\S*\.(jpg|png|gif|webp)/', $openfile[$img], $out);
$output = Helper::options()->siteUrl.'usr/themes/Cuckoo'.$out[0];
$allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
$dirPath = getcwd() . "/usr/themes/Cuckoo/random/";
$files = scandir($dirPath);
$images = array_filter($files, function ($file) use ($dirPath, $allowedExtensions) {
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
return in_array($extension, $allowedExtensions) && is_file($dirPath . $file);
});
if (!empty($images)) {
$output = Helper::options()->siteUrl.'usr/themes/Cuckoo/random/'.$images[array_rand($images)];
} else {
$output = "Error, please check /random.";
}
}elseif ($setting == 'cdn'){
$output = preg_replace('/{rand}/', $rand, $setting_cdn);
}elseif ($setting == '9jojo'){
Expand Down
1 change: 1 addition & 0 deletions random/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
上传随机文章图片之前,请确认已将“主题设置-更多设置-随机文章图源”设置为本地哦。

0 comments on commit 8e7d6de

Please sign in to comment.