Nextgen Gallery 支援中文目錄以及檔案
Nextgen Gallery 會將中文名稱自動變成目錄名稱,導致目錄路徑變成亂碼如%4%5%3%5%78%5465 等形式,造成目錄名稱與資料庫的名稱不符,會找不到圖片!
最裡想的方式還是目錄檔名以時間日期來建立資料夾,目錄名稱規目錄名稱
1. 支援中文目錄
修改 functions.php 內的 create_gallery
function create_gallery($title, $defaultpath, $output = true) {
global $user_ID;
// get the current user ID
get_currentuserinfo();
//cleanup pathname
//$name = sanitize_file_name( sanitize_title($title) );
//$name = apply_filters('ngg_gallery_name', $name);
$nggRoot = WINABSPATH .'wp-content/blogs.dir/'.$user_ID.'/files/'; //因為我用WPMU多人版,所以會給每個USER以他們ID建立
// call wp_unique_filename instead
$name = wp_unique_filename( $nggRoot, date("YmdHis"), null ); //最精華就是這段了,目錄以日期時間當作檔名
$txt = '';
...
}
2. 支援中文檔案
修改 functions.php 內的 scan_dir
function scandir( $dirname = '.' ) {
$ext = apply_filters('ngg_allowed_file_types', array('jpeg', 'jpg', 'png', 'gif') );
$files = array();
if( $handle = opendir( $dirname ) ) {
while( false !== ( $file = readdir( $handle ) ) ) {
$info = pathinfo( $file );
// just look for images with the correct extension
if ( isset($info['extension']) )
if ( in_array( strtolower($info['extension']), $ext) ) {
// no need encode anymore
//$files[] = utf8_encode( $file );
$files[] = $file;
}
}
closedir( $handle );
}
sort( $files );
return ( $files );
}
修改 core.php 內的 fileinfo
function fileinfo( $name ) {
...
$filepart['filename'] = urldecode( sanitize_title_with_dashes( $filepart['filename'] ) );
...
}