コード例 #1
0
        public static ReturnValue edit(TemplateInfo value, UserInfo user)
        {
            ReturnValue info = new ReturnValue();
            string      url  = @"/" + value.title;

            if (value.classId == 0)
            {
                if (!user.isAdministrator)
                {
                    info.errNo  = -1;
                    info.errMsg = "没有权限";
                    return(info);
                }
            }
            else
            {
                Permissions _perm      = null;
                ModuleInfo  moduleInfo = ModuleClass.get(value.classId);
                if (moduleInfo == null)
                {
                    ColumnInfo columnInfo = ColumnClass.get(value.classId);
                    url   = @"/" + columnInfo.dirName + "/" + value.title;
                    _perm = user.getColumnPermissions(value.classId);
                }
                else
                {
                    if (moduleInfo.type)
                    {
                        url = @"/" + moduleInfo.dirName + "/" + value.title;
                    }
                    _perm = user.getModulePermissions(value.classId);
                }
                if (!_perm.all)
                {
                    info.errNo  = -1;
                    info.errMsg = "没有权限";
                    return(info);
                }
            }


            MatchCollection mc, mc2;
            Regex           r = new Regex(@"(</title>).*?(</head>)", RegexOptions.Singleline | RegexOptions.IgnoreCase); //定义一个Regex对象实例

            mc = r.Matches(value.u_content);
            if (mc.Count > 0)//如果找到头部信息时
            {
                string H  = mc[0].Value;
                Regex  r2 = new Regex(@"<script(.*)</script>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                mc2 = r2.Matches(H);
                if (mc2.Count == 0)//如果没有js时
                {
                    string H2 = H.Replace("</head>", "<script type=\"text/javascript\" src=\"" + Config.webPath + "/static/m5_public.js\"></script>\n</head>");
                    value.u_content = value.u_content.Replace(H, H2);
                }
                else
                {
                    bool tag = false;
                    for (int i = 0; i < mc2.Count; i++)
                    {
                        if (mc2[i].Value.ToLower().IndexOf("m5_public.js") > -1)//如果包含系统js时
                        {
                            i   = mc2.Count;
                            tag = true;
                        }
                    }
                    if (!tag)//如果所有的js都不是系统js时
                    {
                        string H2 = H.Replace(mc2[0].Value, "<script type=\"text/javascript\" src=\"" + Config.webPath + "/static/m5_public.js\"></script>\n" + mc2[0].Value);
                        value.u_content = value.u_content.Replace(H, H2);
                    }
                }
            }
            //-----------------自定义页面重名检测--------------------
            if (value.u_type == -3 && TemplateClass.customPageExist(value.id, value.classId, value.title))
            {
                info.errNo  = -1;
                info.errMsg = "页面“" + value.title + "”已存在请不要重复创建";
                return(info);
            }
            //-------------------获取默认模板信息--------------------
            if (value.u_defaultFlag == 1)
            {
                object _id = Sql.ExecuteScalar("select B.id from template B where B.classId=@classId and B.u_type=@typeId and B.u_defaultFlag=@defaultTag and B.u_datatypeId=@datatypeId and B.u_webFAid=@webFAid",
                                               new MySqlParameter[] {
                    new MySqlParameter("classId", value.classId),
                    new MySqlParameter("typeId", value.u_type),
                    new MySqlParameter("defaultTag", value.u_defaultFlag),
                    new MySqlParameter("datatypeId", value.u_datatypeId),
                    new MySqlParameter("webFAid", value.u_webFAid)
                });
                if (_id != null)
                {
                    value.id = (double)_id;
                }
            }

            //-------------------编译模板----------------------------
            try
            {
                TemplateCode code = new TemplateCode(value.id.ToString(), value.u_content);
                code.compile();
            }
            catch (Exception ex)
            {
                info.errNo  = -1;
                info.errMsg = ex.Message;
                return(info);
            }
            //-------------------保存模板----------------------------
            int u_layer = 0;

            if (value.classId > 0)
            {
                object obj = Sql.ExecuteScalar("select id from module where id=" + value.classId);
                u_layer = 1;
                if (obj == null)
                {
                    obj     = Sql.ExecuteScalar("select id from class where id=" + value.classId);
                    u_layer = 2;
                }
            }
            MySqlParameter[] p = new MySqlParameter[] {
                new MySqlParameter("id", value.id),
                new MySqlParameter("classId", value.classId),
                new MySqlParameter("u_type", value.u_type),
                new MySqlParameter("title", value.title),
                new MySqlParameter("u_content", value.u_content),
                new MySqlParameter("u_defaultFlag", value.u_defaultFlag),
                new MySqlParameter("u_datatypeId", value.u_datatypeId),
                new MySqlParameter("u_editboxStatus", value.u_editboxStatus),
                new MySqlParameter("u_parameterValue", value.u_parameterValue),
                new MySqlParameter("u_webFAId", value.u_webFAid),
                new MySqlParameter("createDate", System.DateTime.Now),
                new MySqlParameter("updateDate", System.DateTime.Now),
                new MySqlParameter("url", url),
                new MySqlParameter("u_layer", u_layer)
            };
            if (value.id < 1)
            {
                p[0].Value = double.Parse(Tools.GetId());
                Sql.ExecuteNonQuery("insert into template (id,classId,u_type,title,u_content,u_defaultFlag,u_editboxStatus,u_parameterValue,u_webFAId,u_datatypeId,createDate,updateDate,url,u_layer)values(@id,@classId,@u_type,@title,@u_content,@u_defaultFlag,@u_editboxStatus,@u_parameterValue,@u_webFAId,@u_datatypeId,@createDate,@updateDate,@url,@u_layer)", p);
            }
            else
            {
                Sql.ExecuteNonQuery("update template set updateDate=@updateDate,classId=@classId,u_type=@u_type,title=@title,u_content=@u_content,u_defaultFlag=@u_defaultFlag,u_editboxStatus=@u_editboxStatus,u_parameterValue=@u_parameterValue,u_webFAId=@u_webFAId,u_datatypeId=@u_datatypeId,url=@url,u_layer=@u_layer where id=@id", p);
            }
            info.userData = p[0].Value;


            return(info);
        }
コード例 #2
0
        /// <summary>
        /// 删除模板
        /// </summary>
        /// <param name="id">ID</param>
        /// <returns></returns>
        public static ReturnValue del(double id, UserInfo user)
        {
            ReturnValue  v    = new ReturnValue();
            TemplateInfo info = TemplateClass.get(id);

            if (info != null)
            {
                #region 权限验证
                if (info.classId == 0)
                {
                    if (!user.isAdministrator)
                    {
                        v.errNo  = -1;
                        v.errMsg = "没有权限";
                        return(v);
                    }
                }
                else
                {
                    Permissions _perm      = null;
                    ModuleInfo  moduleInfo = ModuleClass.get(info.classId);
                    if (moduleInfo == null)
                    {
                        ColumnInfo columnInfo = ColumnClass.get(info.classId);
                        _perm = user.getColumnPermissions(info.classId);
                    }
                    else
                    {
                        _perm = user.getModulePermissions(info.classId);
                    }
                    if (!_perm.all)
                    {
                        v.errNo  = -1;
                        v.errMsg = "没有权限";
                        return(v);
                    }
                }
                #endregion
                if ((info.u_type == 1 || info.u_type == 2) && info.u_defaultFlag == 0)//自定义栏目模板时
                {
                    string flag = "";
                    if (info.u_webFAid == 1)
                    {
                        flag = "_";
                    }

                    if (info.u_type == 1)
                    {
                        Sql.ExecuteNonQuery("update class set " + flag + "skinId=0 where " + flag + "skinId=@skinId", new MySqlParameter[] { new MySqlParameter("skinId", info.id) });
                    }
                    if (info.u_type == 2)
                    {
                        Sql.ExecuteNonQuery("update class set " + flag + "contentSkinId=0 where " + flag + "contentSkinId=@skinId", new MySqlParameter[] { new MySqlParameter("skinId", info.id) });
                    }
                }
                Sql.ExecuteNonQuery("delete  template where id=@id", new MySqlParameter[] {
                    new MySqlParameter("id", id)
                });
            }
            v.errNo = 0;
            return(v);
        }