自带的手机门户根本不会用,逻辑和原先的又有差距,忍无可忍,自己做了一个
规则:
以模板,"mb"为例,用的是phpcms\templates\mb\里面的模板文件
正常电脑打开无影响
手机打开时,访问的是phpcms\templates\mb_wap\的模板
也不改模板的js什么文件,为模板解析一个新域名了,简单明了见效开。
添加判断手机访问函数(这个函数不是我写的,随便百度的,当然你又更好的函数可以自己写):
\phpcms\libs\functions\global.func.php
添加如下代码,弱弱的提醒,在<?php 和?>之间添加…不过都明白吧,当我没说
- //判断是否是手机访问的函数
- function isphone()
- { // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
- if(isset ($_SERVER['HTTP_X_WAP_PROFILE']))
- {
- return true;
- }
- // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
- if(isset ($_SERVER['HTTP_VIA']))
- {
- // 找不到为flase,否则为true
- return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
- }
- // 脑残法,判断手机发送的客户端标志,兼容性有待提高
- if(isset ($_SERVER['HTTP_USER_AGENT'])) {
- $clientkeywords= array('nokia',
- 'sony',
- 'ericsson',
- 'mot',
- 'samsung',
- 'htc',
- 'sgh',
- 'lg',
- 'sharp',
- 'sie-',
- 'philips',
- 'panasonic',
- 'alcatel',
- 'lenovo',
- 'iphone',
- 'ipod',
- 'blackberry',
- 'meizu',
- 'android',
- 'netfront',
- 'symbian',
- 'ucweb',
- 'windowsce',
- 'palm',
- 'operamini',
- 'operamobi',
- 'openwave',
- 'nexusone',
- 'cldc',
- 'midp',
- 'wap',
- 'mobile'
- );
- // 从HTTP_USER_AGENT中查找手机浏览器的关键字
- if(preg_match("/(". implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
- { return true;
- }
- }
- // 协议法,因为有可能不准确,放到最后判断
- if(isset ($_SERVER['HTTP_ACCEPT']))
- {
- // 如果只支持wml并且不支持html那一定是移动设备
- // 如果支持wml和html但是wml在html之前则是移动设备
- if((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
- {
- return true;
- }
- }
- return false;
- }
复制代码
2、修改
\phpcms\modules\content\index.php
(有一处要改)
源代码:
include template('content','index',$default_style);
改为:
$phone=isphone();
if($phone)$default_style=$default_style."_wap";
include template('content','index',$default_style);
源代码:
include template('content',$template);
改为:
$sitelist = getcache('sitelist','commons');
$phone=isphone();
if($phone){
include template('content',$template,$sitelist[$siteid]['default_style'].'_wap');
}
else{
include template('content',$template);
}
ok大工告成,自己为手机模块做个模板适配起来吧,mb_wap
|