如何讓用戶在手機等移動端瀏覽phpBB時自動切換至適用於手機的界面

近期打算重新建起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整體複製進去。

第五步,測試
用手機瀏覽器訪問你的網站,成功~
如果有問題,請按照上述步驟檢查,祝你好運。

參考文章:

作者: 椰林物語

博士,摩托車手。發布內容為:生活、站點、其他。

發表回復

您的郵箱地址不會被公開。 必填項已用 * 標註