Skip to content

Commit

Permalink
fix issue #954
Browse files Browse the repository at this point in the history
增强对Alpine Linux的兼容性
  • Loading branch information
leaphy-dev authored Oct 22, 2024
1 parent 9a7330c commit f5d2f0b
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions inc/classes/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,20 @@ public function SMMS_API($image) {

public static function cover_gallery($size = 'source') {
if (iro_opt('random_graphs_options') == 'local') {
$img_array = glob(STYLESHEETPATH . '/manifest/gallary/*.{gif,jpg,jpeg,png}', GLOB_BRACE);
// $img_array = glob(STYLESHEETPATH . '/manifest/gallary/*.{gif,jpg,jpeg,png}', GLOB_BRACE);
// Alpine不支持GLOB_BRACE常量,出于兼容性考虑,不使用glob函数
$folderPath = STYLESHEETPATH . '/manifest/gallary/';
$allowedExtensions = array('jpg', 'jpeg', 'png', 'gif');
$img_array = array();
$files = scandir($folderPath);
foreach ($files as $file) {
// 检查文件扩展名是否在允许的范围内
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (in_array($extension, $allowedExtensions)) {
$img_array[] = STYLESHEETPATH . '/manifest/gallary/' . $file;
}
}

if (count($img_array) == 0){
return ['status'=>False,'msg'=>'ERROR:请联系管理员查看gallary目录中是否存在图片!'];
}
Expand Down Expand Up @@ -220,7 +233,22 @@ public static function cover_gallery($size = 'source') {

public static function mobile_cover_gallery() {
if (iro_opt('random_graphs_options') == 'local') {
$img_array = glob(STYLESHEETPATH . '/manifest/gallary/*.{gif,jpg,jpeg,png}', GLOB_BRACE);
// $img_array = glob(STYLESHEETPATH . '/manifest/gallary/*.{gif,jpg,jpeg,png}', GLOB_BRACE);

$folderPath = STYLESHEETPATH . '/manifest/gallary/';

$allowedExtensions = array('jpg', 'jpeg', 'png', 'gif', 'webp');
$img_array = array();

$files = scandir($folderPath);
foreach ($files as $file) {
// 检查文件扩展名是否在允许的范围内
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (in_array($extension, $allowedExtensions)) {
$img_array[] = STYLESHEETPATH . '/manifest/gallary/' . $file;
}
}

if (count($img_array) == 0){
return ['status'=>False,'msg'=>'没有找到图片,请联系管理员检查gallary目录下是否存在图片'];
}
Expand Down Expand Up @@ -261,4 +289,4 @@ public static function feature_gallery($size = 'source') {
return $imgurl;
}

}
}

0 comments on commit f5d2f0b

Please sign in to comment.