<?php
/**
* @Cscms 3.5 open source management system
* @copyright 2009-2013 chshcms.com. All rights reserved.
* @Author:Cheng Jie
* @Dtime:2013-05-02
*/
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class CsdjSkins extends CI_Model
{
function __construct ()
{
parent:: __construct ();
$this->load->helper('text');
}
//模版解析
function skins($template,$data = null,$return_template_string = false){
$template_string = $this->Common_Mark($template,$data); //通用标签解析
$template_string=$this->labelif($template_string);
if(!is_bool($return_template_string)) $return_template_string = false;
if(!$return_template_string){
echo $template_string;
}else{
return $template_string;
}
}
function is_mobile(){
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$mobile_agents = Array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ","fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei","hutchison","inno","ipad","ipaq","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce","wireless","xda","xde","zte");
$is_mobile = false;
foreach ($mobile_agents as $device) {
if (stristr($user_agent, $device)) {
$is_mobile = true;
break;
}
}
return $is_mobile;
}
//头部和底部
function TopandBottom($Mark_Text,$type='index',$path_sfcms){
$path = str_replace("\\", "/", FCPATH);
if($type=='home'){
if(PC_Mode_home=='0'){
if($path_sfcms==''){
$path = $path.'skins/'.Skins_home_dir.'/';
}else{$path=$path.'skins/'.$path_sfcms.'/';}
}else{
if($this->is_mobile()){
if($path_sfcms==''){
$path = $path.'mobile/'.Skins_home_mobile_dir.'/';
}else{$path=$path.'mobile/'.$path_sfcms.'/';}
}else{
if($path_sfcms==''){
$path = $path.'skins/'.Skins_home_dir.'/';
}else{$path=$path.'skins/'.$path_sfcms.'/';}
}
}
}elseif($type=='user'){
if(PC_Mode_user=='0'){
$path = $path.'skins/'.Skins_user_dir.'/';
}else{
if($this->is_mobile()){
$path = $path.'mobile/'.Skins_user_mobile_dir.'/';
}else{
$path = $path.'skins/'.Skins_user_dir.'/';
}
}
}else{
if(PC_Mode_index=='0'){
$path = $path.'skins/'.Skins_dir.'/';
}else{
if($this->is_mobile()){
$path = $path.'mobile/'.Skins_mobile_dir.'/';
}else{
$path = $path.'skins/'.Skins_dir.'/';
}
}
}
if($type=='home'){
$top_txt=@file_get_contents($path."home-head.html");
$bottom_txt=@file_get_contents($path."home-bottom.html");
$Mark_Text=str_replace('{cscms:head}',$top_txt,$Mark_Text);
$Mark_Text=str_replace('{cscms:bottom}',$bottom_txt,$Mark_Text);
if(PC_Mode_home=='0'){
if($path_sfcms==''){
$TempImg = Web_Path.'skins/'.Skins_home_dir.'/';
}else{$TempImg =Web_Path.'skins/'.$path_sfcms.'/';}
}else{
if($this->is_mobile()){
if($path_sfcms==''){
$TempImg = Web_Path.'mobile/'.Skins_home_mobile_dir.'/';
}else{$TempImg =Web_Path.'mobile/'.$path_sfcms.'/';}
}else{
if($path_sfcms==''){
$TempImg = Web_Path.'skins/'.Skins_home_dir.'/';
}else{$TempImg =Web_Path.'skins/'.$path_sfcms.'/';}
}
}
$TempImg = str_replace('//','/',$TempImg);
$TempImg = substr(substr($TempImg,0,strlen($TempImg)-1),0,strrpos(substr($TempImg,0,strlen($TempImg)-1),'/')+1);
$Mark_Text = str_replace("{cscms:tempurl}",$TempImg,$Mark_Text);
}elseif($type=='user'){
$top_txt=@file_get_contents($path."user-head.html");
$bottom_txt=@file_get_contents($path."user-bottom.html");
$Mark_Text=str_replace('{cscms:head}',$top_txt,$Mark_Text);
$Mark_Text=str_replace('{cscms:bottom}',$bottom_txt,$Mark_Text);
if(PC_Mode_user=='0'){
$TempImg = Web_Path.'skins/'.Skins_user_dir.'/';
}else{
if($this->is_mobile()){
$TempImg = Web_Path.'mobile/'.Skins_user_mobile_dir.'/';
}else{
$TempImg = Web_Path.'skins/'.Skins_user_dir.'/';
}
}
$TempImg = str_replace('//','/',$TempImg);
$TempImg = substr(substr($TempImg,0,strlen($TempImg)-1),0,strrpos(substr($TempImg,0,strlen($TempImg)-1),'/')+1);
$Mark_Text = str_replace("{cscms:tempurl}",$TempImg,$Mark_Text);
$log_ac='user';
}else{
$top_txt=@file_get_contents($path."cs-head.html");
$bottom_txt=@file_get_contents($path."cs-bottom.html");
$Mark_Text=str_replace('{cscms:head}',$top_txt,$Mark_Text);
$Mark_Text=str_replace('{cscms:bottom}',$bottom_txt,$Mark_Text);
if(PC_Mode_index=='0'){
$TempImg = Web_Path.'skins/'.Skins_dir.'/';
}else{
if($this->is_mobile()){
$TempImg = Web_Path.'mobile/'.Skins_mobile_dir.'/';
}else{
$TempImg = Web_Path.'skins/'.Skins_dir.'/';
}
}
$TempImg = str_replace('//','/',$TempImg);
$TempImg = substr(substr($TempImg,0,strlen($TempImg)-1),0,strrpos(substr($TempImg,0,strlen($TempImg)-1),'/')+1);
$Mark_Text = str_replace("{cscms:tempurl}",$TempImg,$Mark_Text);
$log_ac='index';
}
if($type!='home'){
//登入框
$cscmslogin="<script type='text/javascript' src='http://".Web_Url.Web_Path."csdj/js/logajax.js'></script>
<div id='cscms_login'></div>
<script type='text/javascript'>
var cscms_loginlink='".Web_Path."index.php/user/ulog/index/".$log_ac."';
var cscms_loginaddlink='".Web_Path."index.php/user/ulog/login';
var cscms_logoutlink='".Web_Path."index.php/user/ulog/logout';
CSCMS_Login();
</script>";
$Mark_Text = str_replace("{cscms:logkuang}",$cscmslogin,$Mark_Text);
}
return $Mark_Text;
}
//通用标签解析
function Common_Mark($Mark_Text,$data = null){
if(empty($Mark_Text)) die("模板文件无内容!!");
$Mark_Text = $this->TopandBottom($Mark_Text);
preg_match_all('/{cscmsself:([A-Za-z0-9-_]+)}/',$Mark_Text,$Arrself); //