今天在做原来的采集组件移植的过程中,发现Joomla! 1.53的RSS读取真是进步不少!已经做了编码的自动转换。强悍!通过代码分析,得知Joomla! 1.53里本身有一个完整的字符串处理类:JString(文件全名:/libraries/joomla/utilities/string.php),其中,transcode函数是用来进行编码转换地,以下是代码:
- function transcode($source, $from_encoding, $to_encoding) {
- /*
- * "//TRANSLIT" is appendd to the $to_encoding to ensure that when iconv comes
- * across a character that cannot be represented in the target charset, it can
- * be approximated through one or several similarly looking characters.
- */
- }
- }
- function change_encoding($data, $input, $output)
- {
- $input = SimplePie_Misc::encoding($input);
- $output = SimplePie_Misc::encoding($output);
- {
- return $return;
- }
- {
- return $return;
- }
- elseif (function_exists('mb_convert_encoding') && ($return = @mb_convert_encoding($data, $output, $input)))
- {
- return $return;
- }
- elseif ($input == 'ISO-8859-1' && $output == 'UTF-8')
- {
- }
- elseif ($input == 'UTF-8' && $output == 'ISO-8859-1')
- {
- }
- return $data;
- }
而我的问题也就是出现在了这里:我的服务器不支持ICONV,不支持MB_STRING,郁闷到了极点。只好自己手动改了。为了以后能够兼容,所以,我直接修改的是string.php,这样我在别的程序里就也可以实现编码的转换了(嘿嘿,尤其是我的采集,也是需要进行编码转换地)。
首先,将/libraries/simplepie/simplepie.php里的所有change_encoding调用改为JString::transcode(.....)格式的,然后,打开/media/D/usr/htdocs/j/libraries/joomla/utilities/string.php,找到function transcode,将其代码改为如下形式:
- /*
- * "//TRANSLIT" is appendd to the $to_encoding to ensure that when iconv comes
- * across a character that cannot be represented in the target charset, it can
- * be approximated through one or several similarly looking characters.
- */
- if($from_encoding == $to_encoding ) {
- $output = $source;
- } else {
- include_once(JPATH_BASE."/includes/Chinese.class.php");
- $cht = new Chinese($from_encoding, $to_encoding);
- $output = $cht->convert($source);
- }
- return $output;
- //return iconv($from_encoding, $to_encoding.'//TRANSLIT', $source);
- }
然后,将Discuz!论坛程序里的include下的chinese.class.php连同tables文件夹一并上传到网站的includes文件夹中,开始测试,一切OK!











社区信息


评论