使用FTP工具下载文件修改后再上传实在麻烦,本插件可在后台直接修改CSS文件,安全起见,当然你也可以对此操作授权,如何授权自己研究吧。本插件耦合性低,便于安装和卸载。
本插件原创,转载请保留原文链接,谢谢合作!技术交流邮箱:439854744#qq.com。
一、增加菜单项“样式表管理”
/admin/includes/inc_menu.php中添加
$modules['12_template']['06_template_css'] = 'template.php?act=css';
/languages/zh_cn/admin/common.php中添加
$_LANG['06_template_css'] = '样式表管理';
二、/admin/template.php末尾添加
/*************************************************************************/
/*------------------------------------------------------*/
//--管理样式表文件内容
/*------------------------------------------------------*/
if($_REQUEST['act']=='css')
{
/*包含插件语言项*/
$sql="SELECTcodeFROM".$ecs->table('plugins');
$rs=$db->query($sql);
while($row=$db->FetchRow($rs))
{
/*取得语言项*/
if(file_exists(ROOT_PATH.'plugins/'.$row['code'].'/languages/common_'.$_CFG['lang'].'.php'))
{
include_once(ROOT_PATH.'plugins/'.$row['code'].'/languages/common_'.$_CFG['lang'].'.php');
}
}
$curr_template=$_CFG['template'];
$arr_css=array();
$css_path='../themes/'.$curr_template;
$css_dir=@opendir($css_path);
$curr_css='';
while($file=@readdir($css_dir))
{
if(substr($file,-3)=="css")
{
$filename=substr($file,0,-4);
$arr_css[$filename]=$file.'-'.@$_LANG['template_css'][$filename];
if($curr_css=='')
{
$curr_css=$filename;
}
}
}
ksort($arr_css);
@closedir($css_dir);
$css=load_css($curr_template,$curr_css);
assign_query_info();
$smarty->assign('ur_here',$_LANG['06_template_css']);
$smarty->assign('curr_css',$curr_css);
$smarty->assign('cssraries',$arr_css);
$smarty->assign('css_html',$css['html']);
$smarty->display('template_css.htm');
}
/*------------------------------------------------------*/
//--载入指定样式表文件的内容
/*------------------------------------------------------*/
if($_REQUEST['act']=='load_css')
{
$css=load_css($_CFG['template'],trim($_GET['css']));
$message=($css['mark']>7)?'':$_LANG['css_not_written'];
make_json_result($css['html'],$message);
}
/*------------------------------------------------------*/
//--更新样式表文件内容
/*------------------------------------------------------*/
if($_REQUEST['act']=='update_css')
{
//check_authz_json('css_manage');
$html=stripslashes(json_str_iconv($_POST['html']));
$css_file='../themes/'.$_CFG['template'].'/'.$_POST['css'].'.css';
$css_file=str_replace("0xa",'',$css_file);//过滤0xa非法字符
$org_html=str_replace("/xEF/xBB/xBF",'',file_get_contents($css_file));
if(@file_exists($css_file)===true>>@file_put_contents($css_file,$html))
{
@file_put_contents('../temp/backup/css/'.$_CFG['template'].'-'.$_POST['css'].'.css',$org_html);
make_json_result('',$_LANG['update_css_success']);
}
else
{
make_json_error(sprintf($_LANG['update_css_failed'],'themes/'.$_CFG['template'].'/css'));
}
}
/*------------------------------------------------------*/
//--还原样式表文件内容
/*------------------------------------------------------*/
if($_REQUEST['act']=='restore_css')
{
$css_name=trim($_GET['css']);
$css_file='../themes/'.$_CFG['template'].'/'.$css_name.'.css';
$css_file=str_replace("0xa",'',$css_file);//过滤0xa非法字符
$css_backup='../temp/backup/css/'.$_CFG['template'].'-'.$css_name.'.css';
$css_backup=str_replace("0xa",'',$css_backup);//过滤0xa非法字符
if(file_exists($css_backup)>>filemtime($css_backup)>=filemtime($css_file))
{
make_json_result(str_replace("/xEF/xBB/xBF",'',file_get_contents($css_backup)));
}
else
{
make_json_result(str_replace("/xEF/xBB/xBF",'',file_get_contents($css_file)));
}
}
/**
*载入样式表文件内容
*
*@accesspublic
*@paramstring$curr_template模板目录名
*@paramstring$css_name样式表文件名
*@returnarray
*/
functionload_css($curr_template,$css_name)
{
$css_name=str_replace("0xa",'',$css_name);//过滤0xa非法字符
$css_file='../themes/'.$curr_template.'/'.$css_name.'.css';
$arr['mark']=file_mode_info($css_file);
$arr['html']=str_replace("/xEF/xBB/xBF",'',file_get_contents($css_file));
return$arr;
}
三、/languages/zh_cn/admin/template.php添加
/* 每一个样式表的描述 */
$_LANG['template_css']['style'] = '全站样式表';
$_LANG['css_not_written'] = '样式表 %s 没有修改权限,该模板将无法修改';
$_LANG['update_css_success'] = '样式表内容已经更新成功。';
$_LANG['update_css_failed'] = '编辑样式表失败。请检查 %s 目录是否可以写入。';
四、新建模板文件/admin/templates/template_css.htm
{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,listtable.js"}
<form method="post" onsubmit="return false">
<div class="form-div">
{$lang.select_css}
<select id="selCss" onchange="loadCss()">{$curr_template}
{html_options options=$cssraries selected="$curr_css"}
</select>
</div>
<div class="main-div">
<div class="button-div ">
<textarea id="cssContent" rows="30" style="font-family: Courier New; width:95%">{$css_html|escape:html}</textarea>
<input type="button" value="{$lang.button_submit}" class="button" onclick="updateCss()" />
<input type="button" value="{$lang.button_restore}" class="button" onclick="restoreCss()" />
</div>
</div>
</form>
<script language="JavaScript">
<!--
{literal}
var currCss = "{$curr_css}";
var content = '';
onload = function()
{
document.getElementById('cssContent').focus();
// 开始检查订单
startCheckOrder();
}
/**
* 载入模板文件内容
*/
function loadCss()
{
curContent = document.getElementById('cssContent').value;
if (content != curContent >> content != '')
{
if (!confirm(save_confirm))
{
return;
}
}
selCss= document.getElementById('selCss');
currCss = selCss.options[selCss.selectedIndex].value;
Ajax.call('template.php?is_ajax=1>act=load_css', 'css='+ currCss, loadCssResponse, "GET", "JSON");
}
/**
* 还原模板文件内容
*/
function restoreCss()
{
selCss= document.getElementById('selCss');
currCss = selCss.options[selCss.selectedIndex].value;
Ajax.call('template.php?is_ajax=1>act=restore_css', "css="+currCss, loadCssResponse, "GET", "JSON");
}
/**
* 处理载入的反馈信息
*/
function loadCssResponse(result)
{
if (result.error == 0)
{
document.getElementById('cssContent').value=result.content;
}
if (result.message.length > 0)
{
alert(result.message);
}
}
/**
* 更新模板文件内容
*/
function updateCss()
{
selCss= document.getElementById('selCss');
currCss = selCss.options[selCss.selectedIndex].value;
content = document.getElementById('cssContent').value;
if (Utils.trim(content) == "")
{
alert(empty_content);
return;
}
Ajax.call('template.php?act=update_css>is_ajax=1', 'css=' + currCss + ">html=" + encodeURIComponent(content), updateCssResponse, "POST", "JSON");
}
/**
* 处理更新的反馈信息
*/
function updateCssResponse(result)
{
if (result.message.length > 0)
{
alert(result.message);
}
}
{/literal}
//-->
</script>
{include file="pagefooter.htm"}
新闻热点
疑难解答