您现在的位置是:首页 > 教程 > ecshop商城教程ecshop商城教程
ecshop后台编辑增加样css式表插件代码实例
黎舒旺2023-12-16 23:25:03ecshop商城教程已有人查阅
导读一、增加菜单项“样式表管理”/admin/includes/inc_menu.php中添加$modules['12_template']['06_template_css'] = 'template.php?act=css';/admin/includes/common.php.php中添加
一、增加菜单项“样式表管理”
/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"}
/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"}
本文标签:
很赞哦! ()
相关文章
随机图文
-
ecshop订单操作状态对应值说明
ecshop电子商务系统中,ECSHOP的订单有很多的状态。这些状态,是维持和保证ECSHOP后台操作订单状态转换的依据。 -
ecshop客服管理不同会员二次开发方法
ecshop不同客服管理不同会员,这个看起来相当有必要,也相当实 用。我们很多人用ecshop做货源批发站。这个就牵涉到一个问题。如果不同的客服 -
ecshop后台订单列表显示配送方式的方法
熟悉ECSHOP后台的人都知道,只有点击某个具体的订单,进入订单详细页面才能看到该订单的配送方式,本次修改的目的 -
ecshop首页显示最新交易订单的方法
1. 在根目录修改index.php文件:2、在index.php最后面加一个函数:3.在模版文件夹themes\xxx\library\ 把原来order_query.lbi模板内容改为以下内容(注意备份原文件):
留言与评论 (共有 条评论) |