ShopNC中关于KindEditor编辑器的使用

1. 在html中调用showEditor函数

 showEditor('demo_service_pc');
该函数定义在  /core/framework/function/core.php
/**
 * 编辑器内容
 *
 * @param int $id 编辑器id名称,与name同名
 * @param string $value 编辑器内容
 * @param string $width 宽 带px
 * @param string $height 高 带px
 * @param string $style 样式内容
 * @param string $upload_state 上传状态,默认是开启
 */
function showEditor($id, $value='', $width='700px', $height='300px', $style='visibility:hidden;',$upload_state="true", $media_open=false, $type='all'){
    //是否开启多媒体
    $media = '';
    if ($media_open){
        $media = ", 'flash', 'media'";
    }
    switch($type) {
    case 'basic':
        $items = "['source', '|', 'fullscreen', 'undo', 'redo', 'cut', 'copy', 'paste', '|', 'about']";
        break;
    case 'simple':
        $items = "['source', '|', 'fullscreen', 'undo', 'redo', 'cut', 'copy', 'paste', '|',
            'fontname', 'fontsize', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
            'removeformat', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
            'insertunorderedlist', '|', 'emoticons', 'image', 'link', '|', 'about']";
        break;
    default:
        $items = "['source', '|', 'fullscreen', 'undo', 'redo', 'print', 'cut', 'copy', 'paste',
            'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
            'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
            'superscript', '|', 'selectall', 'clearhtml','quickformat','|',
            'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
            'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image'".$media.", 'table', 'hr', 'emoticons', 'link', 'unlink', '|', 'about']";
        break;
    }
    //图片、Flash、视频、文件的本地上传都可开启。默认只有图片,要启用其它的需要修改resource\kindeditor\php下的upload_json.php的相关参数
    echo ''.$value.'';
    echo '
    ';
    return true;
}

2. 在页面的显示效果,开始编辑内容

20160613144153

3. 提交后,会发现录入到数据库中的内容是,被转义了的字符,而我们是想要这样的效果

sqldemo001

4. 出现转义,是因为shopnc的安全过滤机制导致的,在【统一入口,初始化文件】shopnc.php

   对GET、 POST接收内容进行过滤,$ignore内的下标不被过滤,所以只需要在$ignore中加入新的id即可。

//统一ACTION
$_GET['act'] = preg_match('/^[\w]+$/i',$_GET['act']) ? $_GET['act'] : 'index';
$_GET['op'] = preg_match('/^[\w]+$/i',$_GET['op']) ? $_GET['op'] : 'index';
//对GET POST接收内容进行过滤,$ignore内的下标不被过滤
$ignore = array('article_content','pgoods_body','doc_content','content','sn_content','g_body',
'store_description','p_content','groupbuy_intro','remind_content','note_content','ref_url',
'adv_pic_url','adv_word_url','adv_slide_url','appcode','mail_content');
if (!class_exists('Security')) require(BASE_CORE_PATH.'/framework/libraries/security.php');
$_GET = !empty($_GET) ? Security::getAddslashesForInput($_GET,$ignore) : array();
$_POST = !empty($_POST) ? Security::getAddslashesForInput($_POST,$ignore) : array();
$_REQUEST = !empty($_REQUEST) ? Security::getAddslashesForInput($_REQUEST,$ignore) : array();
$_SERVER = !empty($_SERVER) ? Security::getAddSlashes($_SERVER) : array();

原创文章,转载请注明: 转载自HSBLOG

本文链接地址: ShopNC中关于KindEditor编辑器的使用