首页 > Other > 关于zen-cart前台如何判断手机浏览器自动切换模板的思路

关于zen-cart前台如何判断手机浏览器自动切换模板的思路

zen-cart不支持同一语言下的多模板前台切换,如何想根据不同的浏览器或不同的需要在前台切换模板,就比较为难,查到不官方资料.
我自己找了一下zen-cart的模板数据库中模板路径字段是 template_dir,找到引用这个字段的代码分别在
/includes/init_includes/init_templates.php
/includes/modules/payment/paypal/ipn_application_top.php
代码结构是
$template_dir = “”;
$sql = “select template_dir
from ” . TABLE_TEMPLATE_SELECT . ”
where template_language = 0″;
$template_query = $db->Execute($sql);
$template_dir = $template_query->fields[‘template_dir’];

$sql = “select template_dir
from ” . TABLE_TEMPLATE_SELECT . ”
where template_language = ‘” . $_SESSION[‘languages_id’] . “‘”;
$template_query = $db->Execute($sql);
if ($template_query->RecordCount() > 0) {
$template_dir = $template_query->fields[‘template_dir’];
}

如果在这里增加一个判断手机浏览器或要求切换浏览器的代码,即可更换$template_dir中关于模板的变量,即可实现模板的动态更换.
那如何判断目前的浏览器是手机呢,以下给出示范代码.
function checkmobile(){
if(isset($_SERVER[“HTTP_X_WAP_PROFILE”])) return true;
if(preg_match(“/wap\.|\.wap/i”,$_SERVER[“HTTP_ACCEPT”])) return true;
if(isset($_SERVER[“HTTP_USER_AGENT”])){
if(preg_match(“/Creative\ AutoUpdate/i”,$_SERVER[“HTTP_USER_AGENT”])) return false;

$uamatches = array(“midp”, “j2me”, “avantg”, “docomo”, “novarra”, “palmos”, “palmsource”, “240×320”, “opwv”, “chtml”, “pda”, “windows\ ce”, “mmp\/”, “blackberry”, “mib\/”, “symbian”, “wireless”, “nokia”, “hand”, “mobi”, “phone”, “cdm”, “up\.b”, “audio”, “SIE\-“, “SEC\-“, “samsung”, “HTC”, “mot\-“, “mitsu”, “sagem”, “sony”, “alcatel”, “lg”, “erics”, “vx”, “NEC”, “philips”, “mmm”, “xx”, “panasonic”, “sharp”, “wap”, “sch”, “rover”, “pocket”, “benq”, “java”, “pt”, “pg”, “vox”, “amoi”, “bird”, “compal”, “kg”, “voda”, “sany”, “kdd”, “dbt”, “sendo”, “sgh”, “gradi”, “jb”, “\d\d\di”, “moto”);

foreach($uamatches as $uastring){
if(preg_match(“/”.$uastring.”/i”,$_SERVER[“HTTP_USER_AGENT”])) return true;
}

}
return false;
}

大家可以试试!

分类:Other
  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: