PyroCMS设置成中文之后,调用组件 “日志存档”即archives 时时间会显示乱码,主要是月份处理的问题。
找了一下对应的代码,还没有从根本上解决问题。
只能暂时禁用日期的处理,简单记录如下:
blog archive 小组件前台控制代码位于
system/cms/modules/blog/widgets/archive/views/display.php
echo format_date($month->date, lang('blog_archive_date_format'))
这块显示导致,于是追寻 format_date 方法
到 system/cms/helpers/MY_date_helper.php
将对应方法代码修改如下
- function format_date($unix, $format = '')
- {
- if ($unix == '' || ! is_numeric($unix))
- {
- $unix = strtotime($unix);
- }
- $format = Settings::get('date_format');
- /*
- if ( ! $format)
- {
- $format = Settings::get('date_format');
- }
- return strstr($format, '%') !== FALSE
- ? ucfirst(utf8_encode(strftime($format, $unix))) //or? strftime($format, $unix)
- : date($format, $unix);
- */
- return date($format, $unix);
- }
暂时处理到这边,待以后在慢慢修正函数
------------------------晨鸽线---------------------------
晚上看到一点多,总算是把问题解决了,这边先做一下回顾
system/cms/helpers/MY_date_helper.php还原到默认的代码状态。可以看到已经采用了utf8转码,如果直接使用后面的strftime($format, $unix) 出现的也是中文编码,没有转化为utf8,不过同样会出现乱码。
回到语言文件system/cms/modules/blog/language/语言目录/blog_lang.php ,查看日期格式设置 $lang['blog_archive_date_format'] = "%B' %Y";
在php手册中我们可以在strftime 函数下查看这些参数的意义,这边就不赘述了。
这边会发现格式也没错,头疼了。那就是转码的函数有问题咯,寻找一下有没有其他的转换编码的函数,搜索后会发现mb_convert_encoding,替换转换函数为mb_convert_encoding(strftime($format, $unix),'UTF-8') 后测试依然乱码。继续搜索,有发现iconv,修改转换函数为iconv('','UTF-8',strftime($format, $unix)) 测试成功
ok,问题终于解决了,但是觉得这样数字加中文看起来不太协调,参考strftime函数中的日期格式参数后,可以对格式进行一个简单的修改
$lang['blog_archive_date_format'] = "%Y - %m";
显示十进制的月份,这样也不存在中文编码的问题了(如果不想动到CMS代码文件,那么就在语言文件中设置修改此参数吧) :-)
显示效果
转载于:https://blog.51cto.com/vsfor/762174