您现在的位置是:首页 > 教程 > 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在购物结算中心页面显示出商品图片的方法!做购物流程页面时要求显示商品图,EC系统默认在购物车页面是可以显示商品图片的,但是点结算后到结算中心页面你会发现只有商品名称 -
ecshop商城ecs_sessions表报错的解决办法
ecshop前台ecs_sessions表报错的解决办法种错误:MySQL server error report:Array ( [0] => Arra -
ecshop订单付款之后向用户客户发送订单信息确认邮件
要实现这个功能,就要修改ECshop的程序文件:\includes\lib_payment.php,打开该文件,找到166行左右,在”如果需要,发短信”的代码下面,插入以下的代码: -
ecshop调用论坛bbs数据方法
前提保证论坛的数据表和我们ecshop的表在一个数据库的情况下$subject_list = $db->getAll("select tid,subject,dateline from cdb_post
留言与评论 (共有 条评论) |