前端模板增加主题管理

This commit is contained in:
2016-11-25 13:55:03 +08:00
parent 06906a5b22
commit 2bb2af2c0c
46 changed files with 265 additions and 106 deletions

View File

@@ -160,4 +160,39 @@ class Base extends \think\Controller {
return array();
}
}
/**
* 是否为手机访问
* @return boolean [description]
*/
public function isMobile() {//return true;
// 如果有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;
}
}

View File

@@ -24,10 +24,32 @@ class Fornt extends Base {
$this->setSeo();
$this->setHoverNav();
//主题设置
$this->setThemes();
}
//当前栏目导航
protected function setHoverNav() {
//dump($_SERVER['PHP_SELF']);
}
protected function setThemes() {
//网站主题设置
$themes['mobile'] = config('mobile_themes') ? config('mobile_themes') : 'default';
$themes['pc'] = config('pc_themes') ? config('pc_themes') : 'default';
$view_path = $this->isMobile() ? 'template/mobile/' . $themes['mobile'] . '/' : 'template/pc/' . $themes['pc'] . '/';
$module = $this->request->module();
if (!in_array($module, array('index', 'install'))) {
$view_path_pre = $module . '/';
} else {
$view_path_pre = '';
}
$this->view->config('view_path', $view_path . $view_path_pre)
->config('tpl_replace_string',array(
'__IMG__' => '/' . $view_path . 'static/images',
'__JS__' => '/' . $view_path . 'static/js',
'__CSS__' => '/' . $view_path . 'static/css',
));
}
}

View File

@@ -9,7 +9,7 @@
namespace app\common\controller;
class User extends Base {
class User extends Fornt {
public function _initialize() {
parent::_initialize();

View File

@@ -71,4 +71,28 @@ class Config extends Base{
}
return $value;
}
public function getThemesList(){
$files = array();
$files['pc'] = $this->getList('pc');
$files['mobile'] = $this->getList('mobile');
return $files;
}
protected function getList($type){
$path = ROOT_PATH . 'template/' . $type . '/';
$file = opendir($path);
while (false !== ($filename = readdir($file))) {
if (!in_array($filename, array('.', '..'))) {
$files = $path . $filename . '/info.php';
if (is_file($files)) {
$info = include($files);
$info['id'] = $filename;
$info['img'] = '/template/' . $type . '/' . $filename . '/' . $info['img'];
$list[] = $info;
}
}
}
return isset($list) ? $list : array();
}
}