コード例 #1
0
        public static int TotalViewsFor(this HtmlHelper helper, Webpage webpage)
        {
            if (webpage == null)
                return 0;

            var session = helper.ViewContext.HttpContext.Get<ISession>();

            AnalyticsPageView pageView = null;
            AnalyticsSession analyticsSession = null;
            AnalyticsUser analyticsUser = null;
            IQueryOver<AnalyticsPageView, AnalyticsPageView> queryOver = session.QueryOver(() => pageView)
                .JoinAlias(() => pageView.AnalyticsSession, () => analyticsSession)
                .JoinAlias(() => analyticsSession.AnalyticsUser, () => analyticsUser)
                .Where(x => x.Webpage.Id == webpage.Id);


            PageViewResult result = null;
            var viewResult = queryOver
                .SelectList(builder =>
                    builder
                        .SelectGroup(() => pageView.Url)
                        .WithAlias(() => result.Url)
                        .SelectGroup(() => pageView.Webpage.Id)
                        .WithAlias(() => result.WebpageId)
                        .SelectCountDistinct(() => analyticsUser.Id)
                        .WithAlias(() => result.Unique)
                        .SelectCountDistinct(() => analyticsSession.Id)
                        .WithAlias(() => result.Sessions)
                        .SelectCountDistinct(() => pageView.Id)
                        .WithAlias(() => result.Total)
                )
                .TransformUsing(Transformers.AliasToBean<PageViewResult>())
                .Take(1).SingleOrDefault<PageViewResult>();
            return viewResult == null ? 0 : viewResult.Total;
        }
コード例 #2
0
 private VoteResponse RegisterAnonymousVote(VoteModel voteModel, Comment comment, Webpage webpage, bool isUpvote)
 {
     if (comment.Votes.Any(v => v.IPAddress == voteModel.IPAddress))
     {
         return new VoteResponse
                {
                    Type = CommentResponseType.Info,
                    Message = "Already voted",
                    RedirectUrl = "~/" + webpage.LiveUrlSegment
                };
     }
     var vote = new Vote
                {
                    IsUpvote = isUpvote,
                    Comment = comment,
                    IPAddress = voteModel.IPAddress
                };
     comment.Votes.Add(vote);
     _session.Transact(session => session.Save(vote));
     return new VoteResponse
            {
                Message = "Vote registered",
                RedirectUrl = "~/" + webpage.LiveUrlSegment,
                Type = CommentResponseType.Success
            };
 }
コード例 #3
0
        public List<MobileFriendlyNavigationRootNode> GetRootNodes(Webpage rootWebpage)
        {
            using (MiniProfiler.Current.Step("Get Root Nodes"))
            {
                return _cacheManager.Get(
                    string.Format("mobile-friendly-nav.{0}.{1}", _site.Id, (rootWebpage == null ? "0" : rootWebpage.Id.ToString())), () =>
                    {
                        var rootNodes = _session.QueryOver<Webpage>()
                            .Where(
                                node => node.Parent == rootWebpage && node.RevealInNavigation && node.Published)
                            .OrderBy(node => node.DisplayOrder).Asc
                            .Cacheable()
                            .List();

                        var mobileFriendlyNavigationChildNodes = GetMobileFriendlyNavigationChildNodes(rootNodes);

                        var mobileFriendlyNavigationRootNodes = rootNodes
                            .Select(root => new MobileFriendlyNavigationRootNode
                            {
                                Id = root.Id,
                                Name = root.Name,
                                UrlSegment = root.LiveUrlSegment,
                                Children = GetChildNodeTransforms(mobileFriendlyNavigationChildNodes, root),
                                DocumentType = root.GetType().FullName,
                                DisplayOrder = root.DisplayOrder
                            }).ToList();

                        mobileFriendlyNavigationRootNodes = _processRootNodes.Process(mobileFriendlyNavigationRootNodes);

                        return mobileFriendlyNavigationRootNodes.OrderBy(node => node.DisplayOrder).ToList();
                    }, TimeSpan.FromMinutes(5), CacheExpiryType.Absolute);
            }
        }
コード例 #4
0
        public List<UrlHistoryInfo> GetAllOtherUrls(Webpage webpage)
        {
            var urlHistoryInfo = new UrlHistoryInfo();
            var urlHistoryInfoList =
                _session.QueryOver<UrlHistory>()
                    .SelectList(
                        builder =>
                            builder.Select(history => history.UrlSegment)
                                .WithAlias(() => urlHistoryInfo.UrlSegment)
                                .Select(history => history.Webpage.Id)
                                .WithAlias(() => urlHistoryInfo.WebpageId))
                    .TransformUsing(Transformers.AliasToBean<UrlHistoryInfo>())
                    .Cacheable()
                    .List<UrlHistoryInfo>();
            var webpageHistoryInfoList =
                _session.QueryOver<Webpage>()
                    .SelectList(
                        builder =>
                            builder.Select(page => page.UrlSegment)
                                .WithAlias(() => urlHistoryInfo.UrlSegment)
                                .Select(page => page.Id)
                                .WithAlias(() => urlHistoryInfo.WebpageId))
                    .TransformUsing(Transformers.AliasToBean<UrlHistoryInfo>())
                    .Cacheable()
                    .List<UrlHistoryInfo>();

            return urlHistoryInfoList.Union(webpageHistoryInfoList).Where(info => info.WebpageId != webpage.Id).ToList();
        }
コード例 #5
0
 public void AddCustomSiteMapData(Webpage webpage, XElement urlset, XDocument xmlDocument)
 {
     if (webpage == null)
         return;
     var info = GetInfo(webpage);
     info.Append(webpage, urlset, xmlDocument);
 }
コード例 #6
0
ファイル: UpdateTagsService.cs プロジェクト: neozhu/MrCMS
        public void SetTags(DocumentImportDTO documentDto, Webpage webpage)
        {
            List<string> tagsToAdd =
                documentDto.Tags.Where(
                    s => !webpage.Tags.Select(tag => tag.Name).Contains(s, StringComparer.InvariantCultureIgnoreCase))
                    .ToList();
            List<Tag> tagsToRemove =
                webpage.Tags.Where(
                    tag => !documentDto.Tags.Contains(tag.Name, StringComparer.InvariantCultureIgnoreCase)).ToList();
            foreach (string item in tagsToAdd)
            {
                Tag tag = GetExistingTag(item);
                bool isNew = tag == null;
                if (isNew)
                {
                    tag = new Tag {Name = item};
                    _session.Transact(session => session.Save(tag));
                }
                if (!webpage.Tags.Contains(tag))
                    webpage.Tags.Add(tag);

                if (!tag.Documents.Contains(webpage))
                    tag.Documents.Add(webpage);
                _session.Transact(session => session.Update(tag));
            }

            foreach (Tag tag in tagsToRemove)
            {
                webpage.Tags.Remove(tag);
                tag.Documents.Remove(webpage);
                Tag closureTag = tag;
                _session.Transact(session => session.Update(closureTag));
            }
        }
コード例 #7
0
 public CommentsViewInfo GetAddCommentsInfo(Webpage webpage)
 {
     if (!webpage.AreCommentsEnabled(_getWebpageCommentingInfo.Get(webpage), _settings))
     {
         return new CommentsViewInfo { Disabled = true };
     }
     if (!_settings.AllowGuestComments && CurrentRequestData.CurrentUser == null)
     {
         return new CommentsViewInfo
                {
                    View = "Login",
                    Model = new LoginModel(),
                };
     }
     if (CurrentRequestData.CurrentUser == null)
     {
         return new CommentsViewInfo
                {
                    View = "Guest",
                    Model = new GuestAddCommentModel { WebpageId = webpage.Id },
                };
     }
     return new CommentsViewInfo
            {
                View = "LoggedIn",
                Model = new LoggedInUserAddCommentModel { WebpageId = webpage.Id },
            };
 }
コード例 #8
0
ファイル: ImportCategories.cs プロジェクト: neozhu/Ecommerce
 private void UpdateCategory(ISession session, CategoryData categoryData, Webpage parent, HashSet<CategoryData> allData, NopImportContext nopImportContext)
 {
     CategoryData data = categoryData;
     var suggestParams = new SuggestParams
     {
         DocumentType = typeof(Category).FullName,
         PageName = data.Name,
         UseHierarchy = true
     };
     var category = new Category
     {
         Name = data.Name,
         UrlSegment = string.IsNullOrWhiteSpace(data.Url) ? _webpageUrlService.Suggest(parent, suggestParams) : data.Url,
         Parent = parent,
         CategoryAbstract = data.Abstract.LimitCharacters(500),
         PublishOn = data.Published ? CurrentRequestData.Now.Date : (DateTime?)null,
         RevealInNavigation = true
     };
     var mediaFile = nopImportContext.FindNew<MediaFile>(data.PictureId);
     if (mediaFile != null)
     {
         category.FeatureImage = mediaFile.FileUrl;
     }
     session.Save(category);
     nopImportContext.AddEntry(data.Id, category);
     List<CategoryData> children = allData.Where(d => d.ParentId == data.Id).ToList();
     foreach (CategoryData child in children)
     {
         UpdateCategory(session, child, category, allData, nopImportContext);
     }
 }
コード例 #9
0
ファイル: FormAdminService.cs プロジェクト: neozhu/MrCMS
 public void ClearFormData(Webpage webpage)
 {
     _session.Transact(session =>
     {
         webpage.FormPostings.ForEach(session.Delete);
         webpage.FormPostings.Clear();
     });
 }
コード例 #10
0
ファイル: URLContainsTerm.cs プロジェクト: neozhu/MrCMS
 public override IEnumerable<SEOAnalysisFacet> GetFacets(Webpage webpage, HtmlNode document, string analysisTerm)
 {
     string url = webpage.AbsoluteUrl;
     yield return
         url.Replace("-", " ").Contains(analysisTerm, StringComparison.OrdinalIgnoreCase)
             ? GetFacet("URL contains term", SEOAnalysisStatus.Success, "The URL contains '" + analysisTerm + "'")
             : GetFacet("URL contains term", SEOAnalysisStatus.Error, "The URL does not contain '" + analysisTerm + "'");
 }
コード例 #11
0
 public bool ShouldExclude(Webpage webpage)
 {
     if (webpage == null)
         return true;
     return _siteSettings.Error403PageId == webpage.Id
            || _siteSettings.Error404PageId == webpage.Id
            || _siteSettings.Error500PageId == webpage.Id;
 }
コード例 #12
0
ファイル: SingleH1Tag.cs プロジェクト: neozhu/MrCMS
 public override IEnumerable<SEOAnalysisFacet> GetFacets(Webpage webpage, HtmlNode document, string analysisTerm)
 {
     var elements = document.GetElementsOfType("h1");
     if (elements.Count() > 1)
         yield return
             GetFacet("Document contains multiple H1 tags", SEOAnalysisStatus.Error,
                 "There should only be one H1 tag in a document.");
 }
コード例 #13
0
ファイル: GetCurrentLayout.cs プロジェクト: neozhu/MrCMS
 private static Layout GetPageTemplateLayout(Webpage webpage)
 {
     if (webpage.PageTemplate != null && webpage.PageTemplate.Layout != null)
     {
         return webpage.PageTemplate.Layout;
     }
     return null;
 }
コード例 #14
0
ファイル: FormRenderingManager.cs プロジェクト: neozhu/MrCMS
 public string RenderForm(Webpage webpage, FormSubmittedStatus submitted)
 {
     if (webpage == null)
         return string.Empty;
     return string.IsNullOrWhiteSpace(webpage.FormDesign)
                ? _defaultFormRenderer.GetDefault(webpage, submitted)
                : _customFormRenderer.GetForm(webpage, submitted);
 }
コード例 #15
0
        private void UpdateUrlHistories(Webpage webpage, List<string> urlsToAdd, List<UrlHistory> urlsToRemove)
        {
            _session.Transact(session =>
            {
                AddUrls(webpage, urlsToAdd, session);

                RemoveUrls(webpage, urlsToRemove, session);
            });
        }
コード例 #16
0
ファイル: DefaultFormRenderer.cs プロジェクト: neozhu/MrCMS
        public TagBuilder GetForm(Webpage webpage)
        {
            var tagBuilder = new TagBuilder("form");
            tagBuilder.Attributes["method"] = "POST";
            tagBuilder.Attributes["enctype"] = "multipart/form-data";
            tagBuilder.Attributes["action"] = string.Format("/save-form/{0}", webpage.Id);

            return tagBuilder;
        }
コード例 #17
0
 public IEnumerable<string> GetSecondary(Webpage webpage)
 {
     Tag tagAlias = null;
     var documentTags = _session.QueryOver<Webpage>()
         .Where(page => page.Id == webpage.Id)
         .JoinAlias(page => page.Tags, () => tagAlias)
         .Select(page => tagAlias.Name).List<string>();
     return GetSecondaryTerms(webpage, documentTags);
 }
コード例 #18
0
 public bool ShouldAppend(Webpage webpage)
 {
     if (webpage == null)
         return false;
     if (_exclusionReasons.Any(sitemap => sitemap.ShouldExclude(webpage)))
         return false;
     var info = GetInfo(webpage);
     return info.ShouldAppend(webpage);
 }
コード例 #19
0
 private IEnumerable<string> GetSecondaryTerms(Webpage webpage, IEnumerable<string> tags)
 {
     yield return webpage.BodyContent;
     yield return webpage.UrlSegment;
     foreach (string tag in tags)
     {
         yield return tag;
     }
 }
コード例 #20
0
 private static void RemoveUrls(Webpage webpage, List<UrlHistory> urlsToRemove, ISession session)
 {
     foreach (UrlHistory history in urlsToRemove)
     {
         webpage.Urls.Remove(history);
         history.Webpage = null;
         UrlHistory closureHistory = history;
         session.Update(closureHistory);
     }
 }
コード例 #21
0
        public void SetEditPageViewData(ViewDataDictionary viewData, Webpage page)
        {
            DocumentMetadata documentMetadata = page.GetMetadata();
            if (documentMetadata != null)
            {
                viewData["EditView"] = documentMetadata.EditPartialView;
            }

            viewData["edit-tabs"] = _getWebpageEditTabsService.GetEditTabs(page);
        }
コード例 #22
0
 public CommentingInfo Get(Webpage webpage)
 {
     if (webpage == null)
         return null;
     return
         _session.QueryOver<CommentingInfo>()
             .Where(info => info.Webpage.Id == webpage.Id)
             .Cacheable()
             .SingleOrDefault();
 }
コード例 #23
0
        public void Set(Webpage webpage, int? parentVal)
        {
            if (webpage == null) return;

            Webpage parent = parentVal.HasValue ? _session.Get<Webpage>(parentVal.Value) : null;

            webpage.Parent = parent;

            _documentService.SaveDocument(webpage);
        }
コード例 #24
0
ファイル: SEOAnalysisService.cs プロジェクト: neozhu/MrCMS
 public SEOAnalysisResult Analyze(Webpage webpage, string analysisTerm)
 {
     HtmlNode htmlNode;
     using (new TemporaryPublisher(_session, webpage))
     {
         htmlNode = GetDocument(webpage);
     }
     return
         new SEOAnalysisResult(
             _analysisFacetProviders.SelectMany(provider => provider.GetFacets(webpage, htmlNode, analysisTerm)));
 }
コード例 #25
0
ファイル: SEOAnalysisService.cs プロジェクト: neozhu/MrCMS
        private HtmlNode GetDocument(Webpage webpage)
        {
            string absoluteUrl = webpage.AbsoluteUrl;
            WebRequest request = WebRequest.Create(absoluteUrl);

            var document = new HtmlDocument();
            document.Load(request.GetResponse().GetResponseStream());

            HtmlNode htmlNode = document.DocumentNode;
            return htmlNode;
        }
コード例 #26
0
ファイル: SEOAnalysisService.cs プロジェクト: neozhu/MrCMS
 public TemporaryPublisher(ISession session, Webpage webpage)
 {
     _session = session;
     _webpage = webpage;
     _published = webpage.Published;
     if (!_published)
     {
         webpage.Published = true;
         _session.Transact(s => s.Update(_webpage));
     }
 }
コード例 #27
0
        public void Show(Webpage webpage, int widgetId)
        {
            var widget = _session.Get<Widget>(widgetId);

            if (webpage == null || widget == null) return;

            if (webpage.HiddenWidgets.Contains(widget))
                webpage.HiddenWidgets.Remove(widget);
            else if (!webpage.ShownWidgets.Contains(widget))
                webpage.ShownWidgets.Add(widget);
            _documentService.SaveDocument(webpage);
        }
コード例 #28
0
        private ISitemapGenerationInfo GetInfo(Webpage webpage)
        {
            ISitemapGenerationInfo generationInfo = null;
            if (webpage == null)
                return null;

            var typeName = webpage.GetType().FullName;
            if (SitemapGenerationInfoTypes.ContainsKey(typeName))
            {
                generationInfo = _kernel.Get(SitemapGenerationInfoTypes[typeName]) as ISitemapGenerationInfo;
            }
            return generationInfo ?? _kernel.Get<DefaultSitemapGenerationInfo>();
        }
コード例 #29
0
        public void AddInfo(Webpage webpage)
        {
            if (_session.QueryOver<CommentingInfo>().Where(info => info.Webpage.Id == webpage.Id).Cacheable().Any())
            {
                return;
            }

            _session.Transact(session => session.Save(new CommentingInfo
            {
                Webpage = webpage,
                CommentingEnabledStatus = CommentingEnabledStatus.System
            }));
        }
コード例 #30
0
ファイル: AllImagesHaveAltTags.cs プロジェクト: neozhu/MrCMS
        public override IEnumerable<SEOAnalysisFacet> GetFacets(Webpage webpage, HtmlNode document, string analysisTerm)
        {
            var images = document.GetElementsOfType("img").ToList();

            IEnumerable<HtmlNode> imagesWithoutAlt = images.FindAll(node => !node.Attributes.Contains("alt"));

            string hasNotGotAnAltTag = _stringResourceProvider.GetValue("Admin SEO Analysis Has not got", " has not got an alt tag");
            yield return GetFacet(_stringResourceProvider.GetValue("Admin SEO Analysis Has not got alt tags", "All images have alt tags"),
                !imagesWithoutAlt.Any()
                    ? SEOAnalysisStatus.Success
                    : SEOAnalysisStatus.Error,
                imagesWithoutAlt.Select(node => node.GetAttributeValue("src", "") + hasNotGotAnAltTag).ToArray());
        }