Пример #1
0
        public ActionResult Content(CardsModels model)
        {
            long menuId = CardsDAO.GetMenuID(model.No);
            ArticleSettingModels setting = ArticleSettingDAO.GetItem(menuId);

            ViewBag.Setting = setting;

            ArticleModels item = ArticleDAO.GetItemByCard(model.No);

            item.ReplyCommentSetting = setting;
            IEnumerable <ArticleTypesModels> types = item.GetTypes();

            ViewBag.Types = types;
            IEnumerable <ArticleSeriesModels> series = item.GetSeries();

            ViewBag.Series = series;
            IEnumerable <ArticleCategoryModels> readModeCategories = item.GetCategories(IdentityType);

            ViewBag.ReadModeCategories = readModeCategories;

            string uploadUrl = UpdFileInfo.GetVPathByMenuID(model.SiteID, menuId).TrimEnd('/') + "/";

            RecommendHandler(item.ID, setting, uploadUrl, types);
            RecommendHandler2(item.ID, setting, uploadUrl, types);

            //string key = "AllArticleID_" + menuId;
            //long[] allArticleIds = HttpRuntime.Cache[key] as long[];
            //if(allArticleIds == null) {
            //    allArticleIds = ArticleDAO.GetAllIDs(menuId).ToArray();
            //    HttpRuntime.Cache.Add(key, allArticleIds, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0), System.Web.Caching.CacheItemPriority.Normal, null);
            //}
            long[] allArticleIds = ArticleDAO.GetAllIDs(setting).ToArray();
            int    index         = Array.IndexOf(allArticleIds, item.ID);

            ViewBag.ListSitePageIndex = (index / setting.PageSize) + 1;

            if (index <= 0)
            {
                ViewBag.Prev = null;
            }
            else
            {
                ArticleModels prev = ArticleDAO.GetItem(allArticleIds[index - 1]);
                ViewBag.Prev         = prev;
                ViewBag.PrevSitePage = CardsDAO.GetPage(prev.CardNo);
            }

            ViewBag.ListSitePage = MenusDAO.GetListPage(menuId);

            if (index == allArticleIds.Length - 1)
            {
                ViewBag.Next = null;
            }
            else
            {
                ArticleModels next = ArticleDAO.GetItem(allArticleIds[index + 1]);
                ViewBag.Next         = next;
                ViewBag.NextSitePage = CardsDAO.GetPage(next.CardNo);
            }
            SitePage page   = CardsDAO.GetPage(model.No);
            long     pageID = page.PageNo;

            ViewBag.UploadUrl        = uploadUrl;
            ViewBag.SiteID           = model.SiteID;
            ViewBag.SiteSN           = page.SiteSN;
            ViewBag.MenuID           = menuId;
            ViewBag.PageID           = pageID;
            ViewBag.CollectionResult = MemberShipDAO.CheckMemberCollectionExist(pageID);
            ViewBag.CollectionCount  = MemberShipDAO.GetPageCollectionCount(pageID);
            ViewBag.Style            = model.StylesID == 0 ? 1 : model.StylesID;

            ArticleDAO.AddItemClicks(item.ID);

            int    style        = model.StylesID == 0 ? 1 : model.StylesID;
            string ViewFileName = string.Format("~/Views/Article/ContentStyle{0}.cshtml", style);

            if (!System.IO.File.Exists(Server.MapPath(ViewFileName)))
            {
                style = 1;
            }
            ViewFileName = string.Format("~/Views/Article/ContentStyle{0}.cshtml", style);
            return(View(ViewFileName, item));
        }
Пример #2
0
        public static ViewModels.SEORelationModel GetContentSEO(long SiteID, long MenuID, long PageNo)
        {
            ViewModels.SEORelationModel seoModel = new ViewModels.SEORelationModel();
            string newUploadUrl = WorkV3.Golbal.UpdFileInfo.GetVPathByMenuID(SiteID, MenuID).TrimEnd('/') + "/";
            //WorkLib.WriteLog.Write(true, MenuID.ToString());
            List <ZonesModels> zoneList = ZonesDAO.GetPageData(SiteID, PageNo);

            if (zoneList != null && zoneList.Count > 0)
            {
                for (int i = 0; i < zoneList.Count; i++)
                {
                    List <CardsModels> cardList = CardsDAO.GetZoneData(SiteID, zoneList[i].No);
                    if (cardList != null && cardList.Count > 0)
                    {
                        switch (cardList[0].CardsType)
                        {
                        case "Article":
                            ArticleModels articleModel = ArticleDAO.GetItemByCard(cardList[0].No);

                            if (articleModel != null)
                            {
                                var authors = ArticleDAO.GetItemPosters(articleModel.ID);
                                if (authors != null && authors.Count() > 0)
                                {
                                    foreach (ArticlePosterModels auhtor in authors)
                                    {
                                        seoModel.Author += auhtor.Name + ";";
                                    }
                                    seoModel.Author = seoModel.Author.Trim(';');
                                }
                                IEnumerable <ArticleTypesModels> types = articleModel.GetTypes();
                                seoModel.Keywords = string.Join(";", types.Select(t => t.Name));

                                if (!string.IsNullOrEmpty(articleModel.Icon))     // 取得[內文/頁面細節/自行設定代表圖]
                                {
                                    ResourceImagesModels imgModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(articleModel.Icon);
                                    seoModel.SocialImage = newUploadUrl + imgModel.Img;
                                }
                                else
                                {
                                    if (articleModel.CustomIcon)     // 取得[內文 主影片 自行上傳圖片]
                                    {
                                        if (!string.IsNullOrEmpty(articleModel.VideoImg))
                                        {
                                            ResourceImagesModels imgModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(articleModel.VideoImg);
                                            seoModel.SocialImage = newUploadUrl + imgModel.Img;
                                        }
                                    }
                                    else
                                    {
                                        if (!string.IsNullOrEmpty(articleModel.VideoImg))
                                        {
                                            seoModel.SocialImage = articleModel.VideoImg;     //[ 內文 主影片 影片截圖]
                                        }
                                    }
                                }
                                var paragraphs = ParagraphDAO.GetItems(articleModel.ID);
                                if (paragraphs != null && paragraphs.Count() > 0)
                                {
                                    foreach (ParagraphModels paragraph in paragraphs)
                                    {
                                        //都沒取到圖, 則繼續取段落的圖
                                        if (string.IsNullOrEmpty(seoModel.SocialImage))
                                        {
                                            if (paragraph.MatchType == "img")
                                            {
                                                IEnumerable <ResourceImagesModels> images = paragraph.GetImages().Where(m => m.IsShow);
                                                if (images != null && images.Count() > 0)
                                                {
                                                    ResourceImagesModels imgModel = images.FirstOrDefault();
                                                    seoModel.SocialImage = newUploadUrl + imgModel.Img;
                                                }
                                            }
                                        }
                                        if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                                        {
                                            if (string.IsNullOrEmpty(seoModel.Description))
                                            {
                                                seoModel.Description = paragraph.Contents.TrimTags().Truncate(100);
                                            }
                                        }
                                    }
                                }
                            }
                            break;

                        case "ArticleIntro":
                            ArticleIntroModels articleIntroModel = ArticleIntroDAO.GetItem(cardList[0].No);
                            if (articleIntroModel != null)
                            {
                                ArticleSettingModels             setting = ArticleSettingDAO.GetItem(MenuID);
                                IEnumerable <ArticleTypesModels> types   = ArticleTypesDAO.GetItems(MenuID);
                                if (setting.Types != "all")
                                {
                                    IEnumerable <long> allowTypeIds = setting.GetTypes();
                                    types             = types.Where(t => allowTypeIds.Contains(t.ID));
                                    seoModel.Keywords = string.Join(",", types.Select(t => t.Name));
                                }
                                else
                                {
                                    seoModel.Keywords = string.Join(",", types.Select(t => t.Name));
                                }

                                if (!string.IsNullOrEmpty(articleIntroModel.Icon))     // 取得[內文/頁面細節/自行設定代表圖]
                                {
                                    ResourceImagesModels imgModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(articleIntroModel.Icon);
                                    seoModel.SocialImage = newUploadUrl + imgModel.Img;
                                }
                                var paragraphs = ParagraphDAO.GetItems(articleIntroModel.ID);
                                if (paragraphs != null && paragraphs.Count() > 0)
                                {
                                    foreach (ParagraphModels paragraph in paragraphs)
                                    {
                                        //都沒取到圖, 則繼續取段落的圖
                                        if (string.IsNullOrEmpty(seoModel.SocialImage))
                                        {
                                            if (paragraph.MatchType == "img")
                                            {
                                                IEnumerable <ResourceImagesModels> images = paragraph.GetImages().Where(m => m.IsShow);
                                                if (images != null && images.Count() > 0)
                                                {
                                                    ResourceImagesModels imgModel = images.FirstOrDefault();
                                                    seoModel.SocialImage = newUploadUrl + imgModel.Img;
                                                }
                                            }
                                        }
                                        if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                                        {
                                            if (string.IsNullOrEmpty(seoModel.Description))
                                            {
                                                seoModel.Description = paragraph.Contents.TrimTags().Truncate(100);
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
            return(seoModel);
        }