Welcome to Blog Tienich Mobile of Nk2klove

Trang ChủTải xuốngGiới thiệuSITEMAPLiên kếtRSSPhòng chat

Games cực đỉnh trên di động. TẢI NGAY MIỄN PHÍ!!!
Date: 15 Feb 2012 15:32
Category: Code - Script
Shot link: http://Mobiblog.org/2363
Người đăng: nk2klove
Lượt xem: 2/628
Tags: Cài|đặt||thiết|lập|tự|động|nhận|style|mobile|trong|phpBB3
Đánh giá: 48/56 (+/-)
[Edit] [Delete]


Khi bạn dùng máy tính thì sẽ có style riêng. Nhưng khi dùng mobile vào diễn đàn thì style dành cho máy tính không thích hợp và rất nặng, làm cho người dùng khó chịu, không có lợi cho SEO.
Bài viết này sẽ hướng dẫn cách cài đặt và thiết lập nhận style (dành cho mobile) tự động khi dùng mobile. Tức là, khi dùng iPhone, Android, Windows Phone, Blackberry và các dạng mobile khác vào diễn đàn thì giao diện mobile đó sẽ tự nhận thiết bị.
Giao diện dành cho máy tính và giao diện dành cho điện thoại dùng song song.
Cài đặt giao diện:
Trước tiên, bạn cần phải tải về style dành điện thoại di động phpBB.
Có rất nhiều style để lựa chọn, tải về một trong những từ thể loại này và cài đặt nó trên diễn đàn của bạn. Bạn có thể tìm trên diễn đàn Tổng hợp 24, có nhiều giao diện đẹp.
Sau khi cài xong, bạn hãy tìm ID style rồi vào admin control panel -> styles -> click "preview" button:
img
Tải ảnh gốc
VD: index.php?style=11&sid=
img
Tải ảnh gốc
Chỉnh sửa tập tin
Bạn sẽ cần phải chỉnh sửa các tập tin hệ thống phpBB và thêm tự động phát hiện thiết bị di động.
1. Mở includes/session.php, tìm:
Code:
$result = $db->sql_query($sql, 3600);
$this->theme = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

// User has wrong style


Thêm vào trước đó:
Code:
// MOD start: Mobile/SEO style
if($this->check_mobile($sql, $style))
{
// MOD end: Mobile/SEO style

Tìm kiếm:

Code:
if (!$this->theme)
{
trigger_error('Could not get style data', E_USER_ERROR);
}

Thêm vào trước đó:

Mã: Chọn tất cả
Code:
// MOD start: Mobile/SEO style
}
if(defined('MOBILE_DEVICE_OFF'))
{
global $SID, $_EXTRA_URL;
$SID .= '&nomobile=1';
$_EXTRA_URL[] = 'nomobile=1';
}
// MOD end: Mobile/SEO style

Tìm kiếm:
Code:

/**
* More advanced language substitution


Thêm vào trước đó:
Code:
// MOD start: Mobile/SEO style
/**
* Check for mobile/seo, get style
*/
function check_mobile($sql, $style)
{
$browser = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
if (empty($this->data['is_bot']) && strpos($browser, 'Mobile') === false && strpos($browser, 'Symbian') === false && strpos($browser, 'Opera M') === false && strpos($browser, 'Android') === false && stripos($browser, 'HTC_') === false && strpos($browser, 'Fennec/') === false && stripos($browser, 'Blackberry') === false && strpos($browser, 'Windows Phone') === false && strpos($browser, 'WP7') === false && strpos($browser, 'WP8') === false)
{
return true;
}
define('MOBILE_DEVICE', true);
if(!empty($_REQUEST['nomobile']))
{
define('MOBILE_DEVICE_OFF', true);
return true;
}
global $db;
// Important: change number 0 below to ID of Artodia:Mobile style.
// If it is set to 0, script will automatically find style, but it will use extra time and resources.
$mobile_style_id = 0;
if($mobile_style_id)
{
$sql2 = str_replace('s.style_id = ' . $style, 's.style_id = ' . $mobile_style_id, $sql);
$result = $db->sql_query($sql2, 3600);
$this->theme = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if($this->theme !== false)
{
define('MOBILE_STYLE', true);
return false;
}
}
// try to find style
global $phpbb_root_path;
$files = scandir($phpbb_root_path . 'styles');
$base = $phpbb_root_path . 'styles/';
for($i=0; $i<count($files); $i++)
{
if($files[$i] != '.' && $files[$i] != '..' && is_dir($base . $files[$i]) && @file_exists($base . $files[$i] . '/style.cfg'))
{
// found directory with style
$data = file_get_contents($base . $files[$i] . '/style.cfg');
if(strpos($data, 'mobile = 1') !== false && ($pos = strpos($data, 'name = ')) !== false)
{
$list = explode("\n", substr($data, $pos + 7), 2);
$name = trim($list[0]);
// found style
$sql2 = str_replace('s.style_id = ' . $style, 's.style_name = \'' . $db->sql_escape($name) . '\'', $sql);
$result = $db->sql_query($sql2, 3600);
$this->theme = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if($this->theme !== false)
{
define('MOBILE_STYLE', true);
return false;
}
}
}
}
return true;
}
// MOD end: Mobile/SEO style

Ở dòng thứ 21 của đoạn này, bạn cần thay thế bằng ID style của giao diện mobile muốn dùng.


2. Mở includes/functions.php, tìm kiếm:

Code:
// The following assigns all _common_ variables that may be used at any point in a template.

Thêm vào trước đó:
Code:
// MOD start: Mobile/SEO style
if(defined('MOBILE_DEVICE'))
{
$full_style = defined('MOBILE_DEVICE_OFF');
if($full_style)
{
$s_search_hidden_fields['nomobile'] = 1;
$mobile_text = isset($user->lang['MOBILE_ON']) ? $user->lang['MOBILE_ON'] : 'Mobile Version';
$mobile_link = str_replace('nomobile=1&', '', append_sid("{$phpbb_root_path}index.$phpEx", 'nomobile=0'));
}
else
{
$mobile_text = isset($user->lang['MOBILE_OFF']) ? $user->lang['MOBILE_OFF'] : 'Full Version';
$mobile_link = append_sid("{$phpbb_root_path}index.$phpEx", 'nomobile=1');
}
$mobile_html = '<a href="' . $mobile_link . '">' . $mobile_text . '</a>';
$user->lang['TRANSLATION_INFO'] = (isset($user->lang['TRANSLATION_INFO']) ? $user->lang['TRANSLATION_INFO'] . ' ' : '') . $mobile_html;
$template->assign_var('MOBILE_LINK', $mobile_html);
}
// MOD end: Mobile/SEO style


Lưu ý: các đoạn code đều thêm vào trước các code tìm thấy.


Comment (0)
No Comment.
Leave a Comment
Name*:
b i u s quote url red green blue blue


Url:
Comment*:
[BB Code] Smiley Disabled
Vietnamese
Code*: 8325
Name*:

Mesage*:
[BB Code] Smiley Disabled
Code*: 6178
359 Online | Today: 65535 visit | Total: 13980543 visit