hacklog-downloadmanager相关修改,使之可以上传中文文件,以适合国人习惯
最终效果如下:
9、上传目录按照“年-月”自动创建并选择当前月为默认上传目录
文件includes/hacklogdm_admin.class.php约345行
public static function print_list_folders($dir, $orginal_dir)
{
global $download_folders;
echo '<option value="/">/</option>' . "\n";
$monthFloder = date('Y-m', time());
if(!is_dir($dir . '/' . $monthFloder)){
mkdir($dir . '/' . $monthFloder, 0755);
}
self::list_downloads_folders($dir, $orginal_dir);
if ($download_folders)
{
natcasesort($download_folders);
$t__ = count($download_folders);
$c__ = '';
foreach ($download_folders as $k => $download_folder)
{
if($t__ == ($k + 1)) $c__ = ' selected=selected';
echo '<option value="' . $download_folder . '" '. $c__ .'>' . $download_folder . '</option>' . "\n";
}
}
}
8、列表显示中文文件名正常,否则会报不存在
hacklog-downloadmanager\includes\download_list.php文件约182行:对照改
$t__ = $file_path.stripslashes($file->file);
if ( strtoupper ( substr ( PHP_OS , 0 , 3 )) === 'WIN' ) {
$t__ = iconv('utf-8','GBK//IGNORE', $t__);
}
$file_nicename = !hacklogdm::is_remote_file(stripslashes($file->file)) && !file_exists($t__)?'<span style="color:red;">'.sprintf(__('file <strong>%s</strong> does not exists!', hacklogdm::textdomain ),$file->file_name).'</span>':stripslashes($file->file_name);
7、下载中文文件
hacklog-downloadmanager\includes\hacklogdm.class.php文件public function download_file()函数:约551行左右:对照修改:
if (!self::is_remote_file($file_name))
{
$t__ = $file_path . $file_name;
if ( strtoupper ( substr ( PHP_OS , 0 , 3 )) === 'WIN' ) {
//$t__ = mb_convert_encoding($t__, 'gbk', 'gb2312,gbk,utf-8'); $t__ = iconv("utf-8", "gbk//IGNORE", $t__);
}
//var_dump(mb_detect_encoding($t__));exit;
if (!is_file( $t__ ))
{
status_header(404);
wp_die(__('File does not exist.', self::textdomain));
}
6、上传支持中文文件名
hacklog-downloadmanager\includes\hacklogdm_admin.class.php文件public static function upload_local_file($file_upload_to, $is_edit = 0)
$full_path = $file_path . $file_upload_to . $uniq_name;
if ( strtoupper ( substr ( PHP_OS , 0 , 3 )) === 'WIN' ) {
$full_path = iconv('utf-8','GBK//IGNORE', $full_path);
}
if (move_uploaded_file($_FILES['file_upload']['tmp_name'], $full_path))
{
$relative_file_path = $file_upload_to . $uniq_name;
//remove invalid chars and rename non-latin chars
$file = self::download_rename_file($file_path, $relative_file_path);
$t__ = $file_path . $file;
if ( strtoupper ( substr ( PHP_OS , 0 , 3 )) === 'WIN' ) {
$t__ = iconv('utf-8','GBK//IGNORE', $t__);
}
$file_size = filesize($t__);
$file_hash = self::get_file_hash($file_path . $file);
}
public static function download_uniq_name($file)中直接删除以下内容:
if (preg_match("/[\x7f-\xff]/", $file))
$file = self::get_download_uniq_name($file);
public static function download_rename_file($file_path, $file)中删除或者注释掉以下内容:
//对中文名直接生成唯一文件名,结果全变成英文
if (preg_match("/[\x7f-\xff]/", $file) || @preg_match("/[\x{4e00}-\x{9fa5}]+/u", $file))
{
$file = self::get_download_uniq_name($file);
}
else
{
$file = preg_replace("/[^A-Za-z0-9\-._\/\[\]\(\)]/", '', $file);
}
5、添加本地文件支持中文文件名
hacklog-downloadmanager\includes\hacklogdm_admin.class.php文件public static function add_server_file()函数:
$file_size = filesize($file_path . $file);这一行改为:
if ( strtoupper ( substr ( PHP_OS , 0 , 3 )) === 'WIN' ) {
$file_size = filesize(iconv('utf-8','GBK//IGNORE',$file_path . $file));
}else{
$file_size = filesize($file_path . $file);
}
4、删除中文文件名
hacklog-downloadmanager\includes\hacklogdm_admin.class.php文件public static function delete_file()函数
找到if (!@unlink(,并改为:
$t__ = $file_path . '/' . $file;
if(strtoupper(substr(PHP_OS, 0, 3) == 'WIN')){
$t__ = mb_convert_encoding($t__, 'gbk', 'utf-8,gb2312');
}
if (!@unlink($t__))
3、让hacklog-downloadmanager支持中文文件名上传
hacklog-downloadmanager/includes/hacklogdm_admin.class.php第388行函数:
public static function download_rename_file($file_path, $file)注释以下内容:
if (preg_match("/[\x7f-\xff]/", $file) || @preg_match("/[\x{4e00}-\x{9fa5}]+/u", $file))函数:public static function download_uniq_name($file)注释以下内容:
{
$file = self::get_download_uniq_name($file);
}
else
{
$file = preg_replace("/[^A-Za-z0-9\-._\/\[\]\(\)]/", '', $file);
}
if (preg_match("/[\x7f-\xff]/", $file))
$file = self::get_download_uniq_name($file); //说白了,就是不想转换多字节文字
2、让hacklog-downloadmanager可以显示上传中文文件名。
hacklog-downloadmanager/js/jqueryFileTree/jqueryFileTree.php第59行:
echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";
// All dirs
foreach( $files as $file ) {
if( hacklogdm_admin::is_normal_file($root . $dir, $file) && is_dir($root . $dir . $file) ) {
$file= mb_convert_encoding($file, 'utf-8', 'gb18030,gb2312,utf-8');
echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . htmlspecialchars($dir . $file) . "/\">" . ($file) . "</a></li>";
}
}
// All files
foreach( $files as $file ) {
if( hacklogdm_admin::is_normal_file($root . $dir, $file) && !is_dir($root . $dir . $file) ) {
$file= mb_convert_encoding($file, 'utf-8', 'gb18030,gb2312,utf-8');
$ext = preg_replace('/^.*\./', '', $file);
echo "<li class=\"file ext_$ext\"><a href=\"#\" rel=\"" . htmlspecialchars($dir . $file) . "\">" . ($file) . "</a></li>";
}
}
echo "</ul>";
1、鼠标乱点控,为防止一不小心点到左侧菜单的”卸载hacklog-downloadmanager",导致添加半年的数据丢失。
找到此插件目录:hacklog-downloadmanager/includes/hacklogdm.cloass.php第403行,类似Uninstall Hacklog-DownloadManager字样。注释掉,或者删除就行了。