ECSHOP后台编辑增加样css式表插件
ECSHOP教程 来源: ecshop插件网www.ecshop520.com 时间:2013-06-30 ECSHOP教程分类:ECSHOP二次开发教程
一、增加菜单项“样式表管理”
/admin/includes/inc_menu.php中添加
$modules['12_template']['06_template_css'] = 'template.php?act=css';
/admin/includes/common.php.php中添加
$_LANG['06_template_css'] = '样式表管理';
二、/admin/template.php末尾添加
//-- 管理样式表文件内容
if ($_REQUEST['act'] == 'css')
{
$sql = "SELECT code FROM ".$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)));
}
}
function load_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
<!-- $Id: template_css.htm 14869 2012-03-02 17:50:58Z jacklee $ -->
{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"}