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; }
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 }; }
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); } }
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(); }
public void AddCustomSiteMapData(Webpage webpage, XElement urlset, XDocument xmlDocument) { if (webpage == null) return; var info = GetInfo(webpage); info.Append(webpage, urlset, xmlDocument); }
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)); } }
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 }, }; }
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); } }
public void ClearFormData(Webpage webpage) { _session.Transact(session => { webpage.FormPostings.ForEach(session.Delete); webpage.FormPostings.Clear(); }); }
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 + "'"); }
public bool ShouldExclude(Webpage webpage) { if (webpage == null) return true; return _siteSettings.Error403PageId == webpage.Id || _siteSettings.Error404PageId == webpage.Id || _siteSettings.Error500PageId == webpage.Id; }
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."); }
private static Layout GetPageTemplateLayout(Webpage webpage) { if (webpage.PageTemplate != null && webpage.PageTemplate.Layout != null) { return webpage.PageTemplate.Layout; } return null; }
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); }
private void UpdateUrlHistories(Webpage webpage, List<string> urlsToAdd, List<UrlHistory> urlsToRemove) { _session.Transact(session => { AddUrls(webpage, urlsToAdd, session); RemoveUrls(webpage, urlsToRemove, session); }); }
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; }
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); }
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); }
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; } }
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); } }
public void SetEditPageViewData(ViewDataDictionary viewData, Webpage page) { DocumentMetadata documentMetadata = page.GetMetadata(); if (documentMetadata != null) { viewData["EditView"] = documentMetadata.EditPartialView; } viewData["edit-tabs"] = _getWebpageEditTabsService.GetEditTabs(page); }
public CommentingInfo Get(Webpage webpage) { if (webpage == null) return null; return _session.QueryOver<CommentingInfo>() .Where(info => info.Webpage.Id == webpage.Id) .Cacheable() .SingleOrDefault(); }
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); }
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))); }
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; }
public TemporaryPublisher(ISession session, Webpage webpage) { _session = session; _webpage = webpage; _published = webpage.Published; if (!_published) { webpage.Published = true; _session.Transact(s => s.Update(_webpage)); } }
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); }
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>(); }
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 })); }
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()); }