NextGEN Gallery是Wordpress中最受欢迎的相册插件,遗憾的是不支持中文等unicode字符,本文将介绍如何将图集名转换为拼音,从而使NextGEN Gallery支持中文图集名。
打开wp-content/plugins/nextgen-gallery/admin/functions.php添加两处有注释标记的代码如下:
wp-content/plugins/nextgen-gallery/admin/functions.php
require_once('cn2pinyin.php'); // 中文转换为拼音
/**
* nggAdmin - Class for admin operation
*
* @package NextGEN Gallery
* @author Alex Rabe
*
* @access public
*/
class nggAdmin{
/**
* create a new gallery & folder
*
* @class nggAdmin
* @param string $name of the gallery
* @param string $defaultpath
* @param bool $output if the function should show an error messsage or not
* @return
*/
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 = cn2pinyin($name,1);// 中文转换为拼音
$name = apply_filters('ngg_gallery_name', $name);
$nggRoot = WINABSPATH . $defaultpath;
$txt = '';
也就是在原文件中增加以上2处代码。
再建一个名为cn2pinyin.php的文件,上传至nextgen-gallery/admin/文件夹下,然后NextGEN Gallery就支持中文图集名了,其中cn2pinyin.php的内容为:
= '5.0') ? array_combine($_TDataKey, $_TDataValue) : _Array_Combine($_TDataKey, $_TDataValue);
arsort($_Data);
reset($_Data);
if ($_Code != 'gb2312')
$_String = _U2_Utf8_Gb($_String);
$_Res = '';
for ($i = 0; $i160) {
$_Q = ord(substr($_String, ++$i, 1));
$_P = $_P * 256 + $_Q - 65536;
}
$_Res .= _Pinyin($_P, $_Data);
}
return preg_replace("/[^a-z0-9]*/", '', $_Res);
}
function _Pinyin($_Num, $_Data) {
if ($_Num > 0 && $_Num-10247)
return '';
else {
foreach ($_Data as $k => $v) {
if ($v > 6);
$_String .= chr(0x80 | $_C & 0x3F);
} elseif ($_C > 12);
$_String .= chr(0x80 | $_C >> 6 & 0x3F);
$_String .= chr(0x80 | $_C & 0x3F);
} elseif ($_C > 18);
$_String .= chr(0x80 | $_C >> 12 & 0x3F);
$_String .= chr(0x80 | $_C >> 6 & 0x3F);
$_String .= chr(0x80 | $_C & 0x3F);
}
return iconv('UTF-8', 'GB2312', $_String);
}
function _Array_Combine($_Arr1, $_Arr2) {
for ($i = 0; $i
wordpress的NextGEN Gallery相册插件支持中文图片名方法:
http://www.piis.cn/jiaocheng/web607.asp
wordpress上传中文附件出现乱码和后台上传中文图片不显示解决方法
www.piis.cn/jiaocheng/web606.asp
页:
[1]