Exemple #1
0
        private static CategoryDto InitCategoryDtoFromHttpPost(ICompatibleRequest form, CategoryDto category)
        {
            //form.BindToEntity(category);
            category.Keywords    = form.Form("Keywords");
            category.PageTitle   = form.Form("PageTitle");
            category.Tag         = form.Form("Tag");
            category.Name        = form.Form("Name");
            category.SortNumber  = int.Parse(form.Form("SortNumber"));
            category.Description = form.Form("Description");
            category.Location    = form.Form("Location");
            category.Icon        = form.Form("Icon");

            if (!string.IsNullOrEmpty(category.Keywords))
            {
                category.Keywords = Regex.Replace(category.Keywords, ",|\\s|\\|", ",");
            }

            //设置模板
            string categoryTplPath = form.Form("CategoryTemplate"),
                   archiveTplPath  = form.Form("CategoryArchiveTemplate");


            //如果设置了栏目视图路径,则保存
            category.CategoryTemplate = categoryTplPath;

            //如果设置了文档视图路径,则保存
            category.CategoryArchiveTemplate = archiveTplPath;

            return(category);
        }
Exemple #2
0
        public static string SaveByPostForm(ICompatibleRequest form)
        {
            var file = Cms.PhysicPath + CmsVariables.SITE_LOCALE_PATH;
            IList <LangKvPair> list = new List <LangKvPair>();
            var            row      = 0;
            var            lang     = 0;
            LangKvPair     p;
            IList <string> k1 = new List <string>();
            IList <string> v1 = new List <string>();

            foreach (var pk in form.FormKeys())
            {
                if (pk.StartsWith("k_"))
                {
                    k1.Add(pk);
                }
                else if (pk.StartsWith("f_"))
                {
                    v1.Add(pk);
                }
            }

            foreach (var k in k1)
            {
                if (int.TryParse(k.Substring(2), out row)) //获取行号
                {
                    p       = new LangKvPair();
                    p.key   = form.Form(k);
                    p.value = new Dictionary <int, string>();
                    var fPre = "f_" + row.ToString() + "_";
                    for (var j = 0; j < v1.Count; j++)
                    {
                        if (v1[j].StartsWith(fPre)) //获取对英语言的值,并移除
                        {
                            if (int.TryParse(v1[j].Substring(fPre.Length), out lang))
                            {
                                p.value[lang] = form.Form(v1[j]);
                            }
                        }
                    }
                    //v1.Remove(v1[j]);
                    list.Add(p);
                }
            }

            if (list.Count > 0)
            {
                var arr = SortLocaleList(list);
                return(FlushToFile(file, arr));
            }

            return(null);
        }
Exemple #3
0
        /// <summary>
        /// 上传
        /// </summary>
        /// <returns>异步则返回进程ID,同步返回上传文件的路径</returns>
        public string Upload(ICompatiblePostedFile postedFile)
        {
            ICompatibleRequest request = HttpHosting.Context.Request;
            String             baseDir = EnvUtil.GetBaseDirectory();

            string[] process   = request.Form("upload_process")[0].Split('|');
            string   processId = process[1];

            if (postedFile == null)
            {
                return(null);
            }

            string fileName = postedFile.GetFileName();
            string fileExt  = fileName.Substring(fileName.LastIndexOf('.') + 1); //扩展名

            InitUplDirectory(baseDir, this._saveAbsoluteDir);
            this._fileInfo = new UploadFileInfo
            {
                Id            = processId,
                ContentLength = postedFile.GetLength(),
                FilePath      = $"{this._saveAbsoluteDir}{this._fileName}.{fileExt}"
            };
            String targetPath = baseDir + this._fileInfo.FilePath;

            if (!this._autoRename && File.Exists(targetPath))
            {
                throw new IOException("文件已存在");
            }
            // 自动将重复的名称命名
            int i = 0;

            while (File.Exists(targetPath))
            {
                i++;
                this._fileInfo.FilePath = $"{this._saveAbsoluteDir}{this._fileName}_{i.ToString()}.{fileExt}";
                targetPath = baseDir + this._fileInfo.FilePath;
            }
            this.SaveStream(postedFile.OpenReadStream(), targetPath);
            return(_fileInfo.FilePath);
        }
Exemple #4
0
        private ArchiveDto GetFormCopyedArchive(int siteId, ICompatibleRequest form, ArchiveDto archive, string alias)
        {
            string content = form.Form("Content");

            //自动替换Tags
            if (form.Form("auto_tag") == "on")
            {
                //todo: tags 顺序调换了下

                /*
                 * HttpTags _tags = this.GetTags(siteId);
                 * content = _tags.Tags.RemoveAutoTags(content);
                 * content = _tags.Tags.ReplaceSingleTag(content);
                 */
            }

            archive.Flag = 0;
            if (form.Form("IsVisible") == "on")
            {
                archive.Flag |= (int)BuiltInArchiveFlags.Visible;
            }
            if (form.Form("AsPage") == "on")
            {
                archive.Flag |= (int)BuiltInArchiveFlags.AsPage;
            }
            if (form.Form("IsSpecial") == "on")
            {
                archive.Flag |= (int)BuiltInArchiveFlags.IsSpecial;
            }
            if (form.Form("IsSystem") == "on")
            {
                archive.Flag |= (int)BuiltInArchiveFlags.IsSystem;
            }
            archive.UpdateTime = DateTime.Now;
            archive.Title      = form.Form("Title").ToString().Trim();
            archive.SmallTitle = form.Form("SmallTitle").ToString().Trim();
            archive.Location   = form.Form("location").ToString().Trim();
            archive.Source     = form.Form("Source");
            archive.Outline    = form.Form("Outline");
            archive.Alias      = alias;
            archive.Tags       = form.Form("Tags").ToString().Replace(",", ",");
            archive.Content    = content;
            archive.Thumbnail  = form.Form("Thumbnail");

            //分类
            var categoryId = int.Parse(form.Form("categoryid"));

            archive.Category = new CategoryDto {
                ID = categoryId
            };

            //检测图片是否为默认图片
            if (archive.Thumbnail == CmsVariables.FRAMEWORK_ARCHIVE_NoPhoto)
            {
                archive.Thumbnail = string.Empty;
            }

            archive.ExtendValues = new List <IExtendValue>();

            //=============== 更新扩展字段 ===================

            IExtendField field;
            string       extendValue;

            foreach (var key in form.FormKeys())
            {
                if (key.StartsWith("extend_"))
                {
                    extendValue = form.Form(key);
                    field       = new ExtendField(int.Parse(key.Substring(7)), null);
                    archive.ExtendValues.Add(new ExtendValue(-1, field, extendValue));
                }
            }

            //更新模板设置
            archive.TemplatePath = form.Form("TemplatePath");
            if (archive.TemplatePath != string.Empty)
            {
                archive.IsSelfTemplate = true;
            }
            return(archive);
        }