Beispiel #1
0
        public string GetFirstImg(ArticleSettingModels setting)
        {
            if (CustomIcon && !string.IsNullOrWhiteSpace(Icon))
            {
                ResourceImagesModels img = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(Icon);
                if (!string.IsNullOrWhiteSpace(img?.Img))
                {
                    return(img.Img);
                }
            }

            string paragraphImg = ParagraphDAO.GetFirstImage(ID);

            if (!string.IsNullOrWhiteSpace(paragraphImg))
            {
                return(paragraphImg);
            }

            if (!string.IsNullOrWhiteSpace(setting?.DefaultImg))
            {
                ResourceImagesModels img = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(setting.DefaultImg);
                if (!string.IsNullOrWhiteSpace(img?.Img))
                {
                    return(img.Img);
                }
            }

            return(null);
        }
Beispiel #2
0
        public ActionResult Edit(long siteId, long menuId, ArticleIntroModels item, IEnumerable <ParagraphModels> paragraphs, string deletedParagraphs)
        {
            if (!string.IsNullOrWhiteSpace(item.Icon))
            {
                ResourceImagesModels imgModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(item.Icon);
                if (imgModel.ID == 0)   // 新上傳的圖片
                {
                    HttpPostedFileBase postedFile         = Request.Files["fIcon"];
                    string             fIconBase64        = Request.Form["fIconBase64"];
                    string             fIconBase64_Resize = Request.Form["fIconBase64_Resize"];
                    if (postedFile == null || postedFile.ContentLength == 0)
                    {
                        item.Icon = string.Empty;
                    }
                    else
                    {
                        string saveName = WorkV3.Golbal.UpdFileInfo.SaveFilesByMenuID(postedFile, siteId, menuId, fIconBase64, fIconBase64_Resize);
                        imgModel.ID  = 1;
                        imgModel.Img = saveName;

                        item.Icon = Newtonsoft.Json.JsonConvert.SerializeObject(imgModel);
                    }
                }
            }

            item.MenuID     = menuId;
            item.Creator    = MemberDAO.SysCurrent.Id;
            item.CreateTime = DateTime.Now;
            item.Modifier   = item.Creator;
            item.ModifyTime = item.CreateTime;

            ArticleIntroDAO.SetItem(item);

            if (paragraphs?.Count() > 0)
            {
                for (int i = 0, len = paragraphs.Count(); i < len; ++i)
                {
                    ParagraphModels p = paragraphs.ElementAt(i);
                    p.Sort     = (byte)i;
                    p.SourceNo = item.ID;
                    ParagraphDAO.SetItem(p);
                }
            }

            if (!string.IsNullOrWhiteSpace(deletedParagraphs))
            {
                IEnumerable <long> delParagraphIds = deletedParagraphs.Split(',').Select(p => long.Parse(p));
                ParagraphDAO.Delete(delParagraphIds);
            }

            ViewBag.SiteID    = siteId;
            ViewBag.MenuID    = menuId;
            ViewBag.Success   = true;
            ViewBag.DateFmt   = WebInfo.DateFmt; // View 中,WebInfo 會出現命名衝突
            ViewBag.UploadUrl = WorkV3.Golbal.UpdFileInfo.GetVPathByMenuID(siteId, menuId);

            return(View(item));
        }
Beispiel #3
0
        public ResourceVideosModels GetFirstVideo()
        {
            if (isShowVideo && !string.IsNullOrWhiteSpace(VideoID))
            {
                return(new ResourceVideosModels {
                    Type = "youtube", Link = VideoID
                });
            }

            return(ParagraphDAO.GetFirstVideo(ID));
        }
Beispiel #4
0
        public ActionResult Paragraphs(long siteId, long menuId, long sourceNo, string siteSN, int readMode = 0, IEnumerable <ArticleCategoryModels> readModeCategories = null)
        {
            IEnumerable <ParagraphModels> paragraphs = ParagraphDAO.GetItems(sourceNo);

            ViewBag.SiteID             = siteId;
            ViewBag.MenuID             = menuId;
            ViewBag.UploadUrl          = WorkV3.Golbal.UpdFileInfo.GetVPathByMenuID(siteId, menuId).TrimEnd('/') + "/";
            ViewBag.SiteSN             = siteSN;
            ViewBag.ReadMode           = readMode;           //是否限制會員才能觀看
            ViewBag.IdentityType       = IdentityType;
            ViewBag.ReadModeCategories = readModeCategories; //文章限制可觀看的身分

            return(View(paragraphs));
        }
Beispiel #5
0
        private static void SaveParagraph(ArticleModels item, IEnumerable <ParagraphModels> paragraphs, string deletedParagraphs)
        {
            //WorkLib.WriteLog.Write(true, paragraphs.Count().ToString());
            if (paragraphs != null && paragraphs.Count() > 0)
            {
                for (int i = 0, len = paragraphs.Count(); i < len; ++i)
                {
                    ParagraphModels p = paragraphs.ElementAt(i);
                    p.Sort     = (byte)i;
                    p.SourceNo = item.ID;
                    ParagraphDAO.SetItem(p);
                }
            }

            if (!string.IsNullOrWhiteSpace(deletedParagraphs))
            {
                IEnumerable <long> delParagraphIds = deletedParagraphs.Split(',').Select(p => long.Parse(p));
                ParagraphDAO.Delete(delParagraphIds);
            }
        }
Beispiel #6
0
 public IEnumerable <ParagraphModels> GetParagraphs()
 {
     return(ParagraphDAO.GetItems(ID));
 }
        /// <summary>
        /// 取得段落
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="uploadUrl"></param>
        /// <param name="uploadPath"></param>
        /// <returns></returns>
        public List <ParagraphItem> GetParagraphItem(long Id, string uploadUrl, string uploadPath)
        {
            List <ParagraphItem> paragraphList = new List <ParagraphItem>();

            IEnumerable <ParagraphModels> paragraphs = ParagraphDAO.GetItems(Id);

            foreach (var paragraph in paragraphs)
            {
                string matchType = (paragraph.MatchType ?? string.Empty).ToLower();
                if (matchType == "img")
                {
                    IEnumerable <ResourceImagesModels> images = paragraph.GetImages().Where(m => m.IsShow);
                    if (images == null)
                    {
                        continue;
                    }

                    if (images.Count() > 1)
                    {
                        List <ParagraphImageList> imgList = new List <ParagraphImageList>();

                        foreach (var img in images)
                        {
                            int width = 0, height = 0;
                            GetImageWidthAndHeight($"{uploadPath}\\{img.Img}", out width, out height);
                            imgList.Add(new ParagraphImageList()
                            {
                                Url    = uploadUrl + img.Img,
                                Width  = width,
                                Height = height
                            });
                        }

                        paragraphList.Add(new ParagraphItem()
                        {
                            Type        = "ImageGroup",
                            ContentList = imgList
                        });
                    }
                    else
                    {
                        foreach (var img in images)
                        {
                            int width = 0, height = 0;
                            GetImageWidthAndHeight($"{uploadPath}\\{img.Img}", out width, out height);
                            ParagraphImage imgItem = new ParagraphImage
                            {
                                Type    = "Image",
                                Content = uploadUrl + img.Img,
                                Width   = width,
                                Height  = height
                            };
                            paragraphList.Add(imgItem);
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(paragraph.Title))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Title", Content = paragraph.Title
                        });
                    }

                    if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Text", Content = paragraph.Contents
                        });
                    }
                }
                else if (matchType == "video")
                {
                    ResourceVideosModels video = paragraph.GetVideo();
                    string shotUrl = string.Empty, videoUrl = string.Empty;

                    if (video.Type == "custom")
                    {
                        videoUrl = uploadUrl + video.Link;
                        if (!string.IsNullOrWhiteSpace(video.Screenshot))
                        {
                            ResourceImagesModels img = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(video.Screenshot);
                            shotUrl = uploadUrl + img.Img;
                        }
                    }
                    else
                    {
                        videoUrl = video.Link;
                        shotUrl  = video.Screenshot;
                        if (video.ScreenshotIsCustom && !string.IsNullOrWhiteSpace(shotUrl))
                        {
                            ResourceImagesModels img = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(shotUrl);
                            shotUrl = uploadUrl + img.Img;
                        }
                    }
                    paragraphList.Add(new ParagraphVideo
                    {
                        Type       = "Video",
                        Content    = videoUrl,
                        VideoType  = video.Type,
                        Screenshot = shotUrl
                    });

                    if (!string.IsNullOrWhiteSpace(paragraph.Title))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Title", Content = paragraph.Title
                        });
                    }

                    if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Text", Content = paragraph.Contents
                        });
                    }
                }
                else if (matchType == "file")
                {
                    if (!string.IsNullOrWhiteSpace(paragraph.Title))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Title", Content = paragraph.Title
                        });
                    }

                    if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Text", Content = paragraph.Contents
                        });
                    }

                    IEnumerable <ResourceFilesModels> files = paragraph.GetFiles();
                    foreach (var file in files)
                    {
                        paragraphList.Add(new ParagraphFile
                        {
                            Type    = "File",
                            Content = uploadUrl + file.FileInfo,
                            Name    = (string.IsNullOrWhiteSpace(file.ShowName) ? System.Text.RegularExpressions.Regex.Replace(file.FileInfo, @"\.[^\.]*$", string.Empty) : file.ShowName)
                        });
                    }
                }
                else if (matchType == "link")
                {
                    if (!string.IsNullOrWhiteSpace(paragraph.Title))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Title", Content = paragraph.Title
                        });
                    }

                    if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Text", Content = paragraph.Contents
                        });
                    }

                    IEnumerable <ResourceLinksModels> links = paragraph.GetLinks();
                    foreach (var link in links)
                    {
                        paragraphList.Add(new ParagraphFile
                        {
                            Type    = "Link",
                            Content = link.LinkInfo,
                            Name    = link.Descriptions
                        });
                    }
                }
                else if (matchType == "voice")
                {
                    if (!string.IsNullOrWhiteSpace(paragraph.Title))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Title", Content = paragraph.Title
                        });
                    }

                    if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Text", Content = paragraph.Contents
                        });
                    }

                    IEnumerable <ResourceVoicesModels> voices = paragraph.GetVoices();
                    foreach (var voice in voices)
                    {
                        paragraphList.Add(new ParagraphItem
                        {
                            Type    = "Voice",
                            Content = uploadUrl + voice.Path
                        });
                    }
                }
                else if (string.IsNullOrWhiteSpace(matchType))
                {
                    if (!string.IsNullOrWhiteSpace(paragraph.Title))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Title", Content = paragraph.Title
                        });
                    }

                    if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Text", Content = paragraph.Contents
                        });
                    }
                }
            }

            return(paragraphList);
        }