Tag: nextgen gallery

[教學] Nextgen Gallery 支援中文目錄以及檔案 (unicode, utf-8 folder and filename support)

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 . $defaultpath;
   // call wp_unique_filename instead
   $name = wp_unique_filename( $nggRoot, $title, 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'] ) );
 
   ...
}
Tags : ,