ckEditor与ckFinder的集成

1. ckEditor

删除不相关的文件或文件夹,如:_打头的文件夹

 

2. ckFinder

config.ascx

授权:

  Seekdream.Site.Helper.Mvc.SysController sys = new Seekdream.Site.Helper.Mvc.SysController();
  bool vIsLogin = System.Web.HttpContext.Current.Session[sys.GetSessionKey("LoginUser")] != null;
  return vIsLogin;

路径:

BaseUrl = Helper.GetUrl();

 

ascx最后面放一个内部类:

    /// <summary>
    /// CKFinder的辅助类库
    /// </summary>
    public static class Helper
    {

        #region 基础类库

        /// <summary>
        /// CKFinder配置前缀:默认为CKFinder
        /// </summary>
        public const string Default_Config_Prefix = @"CKFinder";


        /// <summary>
        /// CKFinder上传时的第一个根Url:默认为/u/ckf/
        /// </summary>
        public const string Default_FirstRootUrl = @"/u/ckf/";

        /// <summary>
        /// CKFinder上传时的第三个子目录:默认为default/
        /// </summary>
        public const string Default_SubDir = @"default/";


        /// <summary>
        /// 创建URL对应的物理路径
        /// </summary>
        /// <param name="pUrl">URL</param>
        public static void General_Url_Path(string pUrl)
        {
            if (!string.IsNullOrEmpty(pUrl))
            {
                string vTempPath = System.Web.HttpContext.Current.Request.MapPath(pUrl);
                if (!System.IO.Directory.Exists(vTempPath))
                {
                    try
                    {
                        System.IO.Directory.CreateDirectory(vTempPath);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }

        /// <summary>
        /// 生成Url形式的年月日,如:2012/12/20/
        /// </summary>
        /// <param name="pIsYear">是否取年</param>
        /// <param name="pIsMonth">是否取月</param>
        /// <param name="pIsDay">是否取日</param>
        /// <returns></returns>
        public static string General_Url_YYYYMMDD(bool pIsYear = true, bool pIsMonth = true, bool pIsDay = true)
        {
            StringBuilder sb = new StringBuilder();
            if (pIsYear)
            {
                sb.AppendFormat(@"{0}/", DateTime.Now.ToString("yyyy"));
            }
            if (pIsMonth)
            {
                sb.AppendFormat(@"{0}/", DateTime.Now.ToString("MM"));
            }
            if (pIsDay)
            {
                sb.AppendFormat(@"{0}/", DateTime.Now.ToString("dd"));
            }
            return sb.ToString();
        }

        /// <summary>
        /// 生成Url形式的根路径
        /// </summary>
        /// <param name="pFirstRootUrl">第一个根路径</param>
        /// <param name="pIsSecondYear">是否取年份目录: 默认是</param>
        /// <param name="pIsSecondMonth">是否取月份子目录: 默认是</param>
        /// <param name="pIsSecondDay">是否取日的子目录: 默认否</param>
        /// <returns></returns>
        public static string General_Url_Root(string pFirstRootUrl, bool pIsSecondYear = true, bool pIsSecondMonth = true, bool pIsSecondDay = false)
        {
            if (string.IsNullOrEmpty(pFirstRootUrl))
            {
                pFirstRootUrl = Default_FirstRootUrl;
            }
            if (!pFirstRootUrl.StartsWith(@"/"))
            {
                pFirstRootUrl = @"/" + pFirstRootUrl;
            }
            if (!pFirstRootUrl.EndsWith(@"/"))
            {
                pFirstRootUrl += @"/";
            }


            StringBuilder sb = new StringBuilder(pFirstRootUrl);
            sb.AppendFormat(General_Url_YYYYMMDD(pIsSecondYear, pIsSecondMonth, pIsSecondDay));

            string vTempPath = System.Web.HttpContext.Current.Request.MapPath(sb.ToString());
            if (!System.IO.Directory.Exists(vTempPath))
            {
                try
                {
                    System.IO.Directory.CreateDirectory(vTempPath);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return sb.ToString();
            
        }


        #endregion


        #region 配置类库:从配置文件中读取的类库


        /// <summary>
        /// 读取AppSetting的某个键对应的值
        /// </summary>
        /// <param name="pKey">键名</param>
        /// <returns></returns>
        public static string GetAppSetting(string pKey)
        {
            string vStr = string.Empty;
            vStr = ConfigurationManager.AppSettings[string.Format("{0}_{1}", Default_Config_Prefix, pKey)];
            if (string.IsNullOrEmpty(vStr))
            {
                vStr = "";
            }
            return vStr;
        }

        /// <summary>
        /// 取得Url形式的根路径
        /// </summary>
        /// <returns></returns>
        public static string GetUrl()
        {

            string vFirstRootUrl = GetAppSetting("FirstRootUrl");
            bool vIsSecondYear = GetAppSetting("IsSecondYear") == "false" ? false : true;
            bool vIsSecondMonth = GetAppSetting("IsSecondMonth") == "false" ? false : true;
            bool vIsSecondDay = GetAppSetting("IsSecondDay") == "true" ? true : false;

            return General_Url_Root(vFirstRootUrl, vIsSecondYear, vIsSecondMonth, vIsSecondDay);
        }




        #endregion

    }

  

程序集:

bin\CKFinder.dll

 

 

3. 页面

    <script src="@Url.Content("~/Common/Editor/CKEditor/ckeditor3.6.6/ckeditor.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Common/Editor/CKFinder/ckfinder2.2.2/ckfinder.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Common/Editor/CKFinder/ckfinder2.2.2/plugins/onchange/plugin.js")" type="text/javascript"></script>

 


     var CKFinder_Path = "/Common/Editor/CKFinder/ckfinder2.2.2/";

     var config = {
  skin: "kama", width: ($(window).width() - 300), height: 300,
  toolbar: [
   ['Source'],
   ['Styles', 'Format', 'Font', 'FontSize'],
   ['TextColor', 'BGColor'],
   ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'],
   ['-'],
   ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
   ['Link', 'Unlink', 'Anchor'],
   ['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak'],
   ['Maximize', 'ShowBlocks', '-', 'Source', '-', 'Undo', 'Redo']
   ['Image', 'Smiley'],
   ['Bold', 'Italic'],
         ],
     };

        var News_Contents_editor = CKEDITOR.replace("News_Contents", config);
 CKFinder.setupCKEditor(News_Contents_editor, CKFinder_Path);

 

4. web.config

    <add key="CKFinder_FirstRootUrl" value="/up/" />
    <add key="CKFinder_IsSecondYear" value="true" />
    <add key="CKFinder_IsSecondMonth" value="true" />
    <add key="CKFinder_IsSecondDay" value="false" />

 

 

 

posted on 2013-04-16 14:01  天涯人  阅读(328)  评论(0编辑  收藏  举报

导航