phpcms 移动化

发布时间:2020-06-18 23:33:12 作者:刀心
来源:网络 阅读:408

感谢yidodo指点,才有此文。

思路如下:

1、自定义全局函数判断设备类型

2、pc访问为www域名,移动访问为wap域名

3、修改内容模型控制器,在选择模板的地方加上判断,如果是www域名则使用pc模板,如果是wap域名则使用移动模板。

好了就这样。

开始吧。判断设备类型的全局函数可以去网上找现成的。


function isMobile(){
    $useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
    $useragent_commentsblock=preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:'';
    function CheckSubstrs($substrs,$text){
        foreach($substrs as $substr)
            if(false!==strpos($text,$substr)){
            return true;
        }
        return false;
    }
    $mobile_os_list=array('Google Wireless Transcoder','Windows CE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','Opera Mobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ');
    $mobile_token_list=array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod');
                           
    $found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock) ||
    CheckSubstrs($mobile_token_list,$useragent);
                           
    if ($found_mobile){
        return true;
    }else{
        return false;
    }
}


放到phpcms/libs/function/extention.function.php中。

来到/phpcms/modules/content

新建 MY_index.php文件,内容如下。


<?php
defined('IN_PHPCMS') or exit('No permission resources.');
class MY_index extends index{
private $db;
function __construct() {
$this->db = pc_base::load_model('content_model');
$this->hosts = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
parent::__construct();
if(!strstr($this->hosts,'wap.')) $this->tomobile();
}
public function tomobile(){
$host = str_replace('www.','wap.',$this->hosts);
if(isMobile()){
header("Location: $host");
}
}
}
?>

修改/phpcms/modules/content/index.php 文件

凡是include template出现的地方都做一下判断。

if(strstr($this->hosts,'wap.')){
include template('content','shouyewap',$default_style);
}else{
include template('content','index',$default_style);
}



当然要解析一个wap域名过来用。

同理其实可以扩展到其他的前台模板中。

仅适用于动态网站。生成静态的是无法判断的。

完毕。


推荐阅读:
  1. phpcms如何开发的
  2. 什么是phpcms?

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

seo php 移动化

上一篇:Windows server 2008安装dns

下一篇:python安装cx_oracle

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》