近期打算重新建起vlc中文社区(2012年10月成立,后来由于种种原因2013年夏天停运),原来是用drupal搭建的,这次想和videolan官方组保持步调一致,也用phpBB来搭建一个vlc技术较流型论坛。于是前一段时间快速安装了phpBB,但是发现手机体验不佳,遂在网中使劲儿寻找解决方案。
终于找到了~
下面就说说该如何做吧。
第一步,先下载几个适用于手机的phpBB主题或界面
(这里提供几个:
下载1-phpBBmobile
下载2-Artodia: Mobile
下载3-phpBB3 mobile )
第二步,下载代码与修改
2.1 自动跳转的代码,这里称之为“附件stg”
点此下载phpBB_mobile_detect
2.2 下载后请解压phpBB_mobile_detect.zip文件,编辑其中的\phpBB_mobile_detect\install.xml文件,将“$style = 3; ”改为你第一步安装的手机主题或界面的style id,找了一些资料也没找到现在的phpBB怎么查找style id,如果你还记得安装顺序的话,按照安装顺序就好了,比如某个主题是安装的第五个,他们这里的数字“3”改为“5”,如果主题安装的不多的话,可以输入不同的数字来试验;
2.3 将“http://yoursite.com/phpBB3/ ”中的“yoursite.com”改为你的网址(其中的phpBB3貌似删除了也不影响);
2.4 保存这些设置,然后把它打包为一个新的phpBB_mobile_detect.zip并上传到你的网站目录的“styles”目录下。
第三步,编辑
3.1 编辑phpBB网站目录中的includes/session.php文件
3.1.1 将代码:
function setup($lang_set = false, $style = false)
{
global $db, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache;
if ($this->data[‘user_id’] != ANONYMOUS)
替换为:
function setup($lang_set = false, $style = false)
{
global $db, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache;
// phpBB_mobile_detect – Mobile Stlye Redirect MOD
$this->data[‘is_mobile’] = false;
include_once($phpbb_root_path . ‘includes/mods/mobile_device_detect.’ . $phpEx);
$this->data[‘is_mobile’] = mobile_device_detect();
if ($this->data[‘is_mobile’] == true)
{
$style = 5;
$this->data[‘is_mobile’] = true;
}
// phpBB_mobile_detect End
if ($this->data[‘user_id’] != ANONYMOUS)
注:这里的“$style = 5; ”和上方的style id一致。
3.1.2 将代码:
if (!empty($_GET['style']) && $auth->acl_get('a_styles') && !defined('ADMIN_START'))
替换为:
// Setup for ?style=# to work for style viewing.
// if (!empty($_GET['style']) && $auth->acl_get('a_styles') && !defined('ADMIN_START'))
if (!empty($_GET['style']))
3.2 编辑phpBB网站目录中的posting.php文件
将代码:
// Parse Attachments - before checksum is calculated
$message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
// Grab md5 ‘checksum’ of new message
替换为:
// Parse Attachments - before checksum is calculated
$message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
// phpBB_mobile_detect – Mobile Stlye Redirect MOD
if ($user->data[‘is_mobile’] && $mode != ‘edit’ && !$preview && !$refresh)
{
include_once($phpbb_root_path . ‘includes/mods/mobile_device_detect.’ . $phpEx);
$status = mobile_device_detect();
$message_parser->message .= “\n\n[size=75][b][i][ Post made via ” . $status[1] . ” ][/i][/b][/size] [img]http://www.exees.com/phpbb/phpBB3/images/mobile/” . $status[1] . “.png[/img]”;
}
// phpBB_mobile_detect End
P.S.上述代码中的“Post made via”你可以更换为其他内容,比如改为“通过” . $status[1] . “发送”,修改之后如果你通过android手机发送,会显示“通过android发送”并附带对应android手机小图标,但是已经通过手机发表的帖子还是会显示原来的“Post made via android”。
第四步,复制
4.1 将“附件stg”中root/images/mobile目录拷贝到网站的images目录中,即将附件中images文件夹里的mobil文件夹复制到网站images文件夹里;
4.2 将“附件stg”中root/includes/mods目录拷贝到网站的includes目录中,即将附件中includes文件夹里的mods文件夹复制到网站includes文件夹里;
4.3 由于路径的关系,最好在网站跟目录下创建文件夹“phpBB3”并将“附件stg”中root/images目录拷贝到该目录中,即将root下的images整体复制进去。
第五步,测试
用手机浏览器访问你的网站,成功~
如果有问题,请按照上述步骤检查,祝你好运。
参考文章: