Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Sitecore.Modules.WeBlog.Components;
- using Sitecore.Modules.WeBlog.Configuration;
- using Sitecore.Modules.WeBlog.Data.Items;
- using Sitecore.Mvc.Presentation;
- using System.Collections.Generic;
- using Sitecore.Modules.WeBlog.Mvc.Model;
- namespace Company.ViewModels
- {
- public class PostBlogList : BlogRenderingModelBase
- {
- protected const string DefaultPostTemplate = "~/Views/WeBlog/PostListEntry.cshtml";
- public IEnumerable<EntryItem> BlogEntries { get; set; }
- public bool ShowViewMoreLink { get; set; }
- public string ViewMoreHref { get; set; }
- public string PostTemplate { get; set; }
- protected IPostListCore PostListCore { get; set; }
- public PostBlogList()
- : this((IPostListCore)null)
- {
- }
- public PostBlogList(IPostListCore postListCore)
- {
- this.PostListCore = postListCore ?? (IPostListCore)new Sitecore.Modules.WeBlog.Components.PostListCore(this.CurrentBlog, (IWeBlogSettings)null);
- }
- public override void Initialize(Rendering rendering)
- {
- base.Initialize(rendering);
- this.PostListCore.Initialize(RenderingContext.Current.PageContext.RequestContext.HttpContext.Request.QueryString);
- if (string.IsNullOrEmpty(this.PostTemplate))
- this.PostTemplate = "~/Views/WeBlog/PostListEntry.cshtml";
- this.BlogEntries = this.PostListCore.Entries;
- this.PostTemplate = this.PostTemplate;
- if (this.PostListCore.ShowViewMoreLink)
- {
- this.ShowViewMoreLink = true;
- this.ViewMoreHref = this.PostListCore.ViewMoreHref;
- }
- else
- this.ShowViewMoreLink = false;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Sitecore.Modules.WeBlog.Data.Items;
- using Glass.Mapper.Sc.Configuration.Attributes;
- using Glass.Mapper.Sc.Fields;
- using Sitecore.Modules.WeBlog.Managers;
- using Sitecore.Modules.WeBlog.Mvc.Model;
- using Sitecore.Data.Items;
- using Sitecore.Modules.WeBlog.Pipelines.GetSummary;
- using Sitecore.Pipelines;
- using System.Drawing;
- using Company.Models.Concrete.Items;
- namespace Company.ViewModels
- {
- public class BlogEntryList
- {
- public EntryItem EntryItem { get; set; }
- public string Summary { get; set; }
- public int MaxWidth { get; set; }
- public int MaxHeight { get; set; }
- public bool ShowCommentsCount { get; set; }
- /*-- new field --*/
- [SitecoreField("Authors")]
- public virtual IEnumerable<Person> Authors { get; set; }
- public BlogEntryList(EntryItem entry)
- {
- this.EntryItem = entry;
- BlogHomeItem currentBlog = ManagerFactory.BlogManagerInstance.GetCurrentBlog((Item)entry);
- Size imageSizeDimension = currentBlog.MaximumThumbnailImageSizeDimension;
- if (imageSizeDimension != Size.Empty)
- {
- this.MaxWidth = imageSizeDimension.Width;
- this.MaxHeight = imageSizeDimension.Height;
- }
- this.Summary = this.GetSummary(this.EntryItem);
- this.ShowCommentsCount = currentBlog.EnableComments.Checked && !this.EntryItem.DisableComments.Checked;
- }
- protected string GetSummary(EntryItem entry)
- {
- GetSummaryArgs getSummaryArgs = new GetSummaryArgs();
- getSummaryArgs.Entry = entry;
- CorePipeline.Run("weblogGetSummary", (PipelineArgs)getSummaryArgs, true);
- return getSummaryArgs.Summary;
- }
- }
- }
- // Decompiled with JetBrains decompiler
- // Type: Sitecore.Modules.WeBlog.Data.Items.EntryItem
- // Assembly: Sitecore.Modules.WeBlog, Version=3.1.0.41507, Culture=neutral, PublicKeyToken=null
- // MVID: 60C67A20-E02A-42BD-B187-B3ED588D19A1
- // Assembly location: C:Dev SitesCompanyWebsiteBinSitecore.Modules.WeBlog.dll
- using Sitecore.Data.Fields;
- using Sitecore.Data.Items;
- using Sitecore.Links;
- using Sitecore.Modules.WeBlog.Data.Fields;
- using Sitecore.Modules.WeBlog.Extensions;
- using Sitecore.Modules.WeBlog.Managers;
- using Sitecore.Security.Accounts;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace Sitecore.Modules.WeBlog.Data.Items
- {
- public class EntryItem : CustomItem
- {
- public EntryItem(Item innerItem)
- : base(innerItem)
- {
- }
- public static implicit operator EntryItem(Item innerItem)
- {
- if (innerItem == null)
- return (EntryItem) null;
- return new EntryItem(innerItem);
- }
- public static implicit operator Item(EntryItem customItem)
- {
- return customItem?.InnerItem;
- }
- public CustomMultiListField Category
- {
- get
- {
- return new CustomMultiListField(this.InnerItem, (MultilistField) this.InnerItem.Fields[nameof (Category)]);
- }
- }
- public CustomCheckboxField DisableComments
- {
- get
- {
- return new CustomCheckboxField(this.InnerItem, (CheckboxField) this.InnerItem.Fields["Disable Comments"]);
- }
- }
- public CustomTextField Title
- {
- get
- {
- return new CustomTextField(this.InnerItem, (TextField) this.InnerItem.Fields[nameof (Title)]);
- }
- }
- public CustomTextField Introduction
- {
- get
- {
- return new CustomTextField(this.InnerItem, (TextField) this.InnerItem.Fields[nameof (Introduction)]);
- }
- }
- public CustomTextField Tags
- {
- get
- {
- return new CustomTextField(this.InnerItem, (TextField) this.InnerItem.Fields[nameof (Tags)]);
- }
- }
- public CustomTextField Content
- {
- get
- {
- return new CustomTextField(this.InnerItem, (TextField) this.InnerItem.Fields[nameof (Content)]);
- }
- }
- public CustomTextField Author
- {
- get
- {
- return new CustomTextField(this.InnerItem, (TextField) this.InnerItem.Fields[nameof (Author)]);
- }
- }
- public CustomDateField EntryDate
- {
- get
- {
- return new CustomDateField(this.InnerItem, (DateField) this.InnerItem.Fields["Entry Date"]);
- }
- }
- public CustomImageField Image
- {
- get
- {
- return new CustomImageField(this.InnerItem, (ImageField) this.InnerItem.Fields[nameof (Image)]);
- }
- }
- public CustomImageField ThumbnailImage
- {
- get
- {
- return new CustomImageField(this.InnerItem, (ImageField) this.InnerItem.Fields["Thumbnail Image"]);
- }
- }
- public string[] TagsSplit
- {
- get
- {
- return this.ExtractTags(false);
- }
- set
- {
- this.Tags.Field.Value = EntryItem.FormTags(value);
- }
- }
- public string Url
- {
- get
- {
- return LinkManager.GetItemUrl(this.InnerItem);
- }
- }
- public string AbsoluteUrl
- {
- get
- {
- UrlOptions defaultOptions = UrlOptions.DefaultOptions;
- defaultOptions.AlwaysIncludeServerUrl = true;
- return LinkManager.GetItemUrl(this.InnerItem, defaultOptions);
- }
- }
- public int CommentCount
- {
- get
- {
- return ManagerFactory.CommentManagerInstance.GetCommentsCount((Item) this);
- }
- }
- public DateTime Created
- {
- get
- {
- if (!(this.EntryDate.DateTime != DateTime.MinValue))
- return this.InnerItem.Statistics.Created;
- return this.EntryDate.DateTime;
- }
- }
- public User CreatedBy
- {
- get
- {
- string accountName = this.InnerItem[FieldIDs.CreatedBy];
- if (!string.IsNullOrEmpty(accountName))
- return Account.FromName(accountName, AccountType.User) as User;
- return (User) null;
- }
- }
- public string AuthorName
- {
- get
- {
- if (this.Author.Raw.Contains("\"))
- {
- if (!User.Exists(this.Author.Raw))
- return this.Author.Rendered;
- User user = User.FromName(this.Author.Raw, false);
- if ((Account) user == (Account) null)
- return this.Author.Rendered;
- string str = user.LocalName;
- if (user.Profile != null && !string.IsNullOrEmpty(user.Profile.FullName))
- str = user.Profile.FullName;
- return str;
- }
- if (string.IsNullOrEmpty(this.Author.Raw) || this.Author.Raw == "$currentuser")
- return this.CreatedBy.LocalName;
- return this.Author.Rendered;
- }
- }
- public string DisplayTitle
- {
- get
- {
- if (string.IsNullOrEmpty(this.Title.Text))
- return this.Name;
- return this.Title.Text;
- }
- }
- private static string FormTags(string[] tags)
- {
- string str = string.Empty;
- for (int index = 0; index < tags.Length; ++index)
- str = str + tags[index].Trim() + (index < tags.Length - 1 ? "," : string.Empty);
- return str;
- }
- private string[] ExtractTags(bool isEncode)
- {
- string[] strArray = this.InnerItem["Tags"].Trim().Split(',');
- ArrayList arrayList = new ArrayList();
- foreach (string s in ((IEnumerable<string>) strArray).Where<string>((Func<string, bool>) (tag => tag.Trim() != string.Empty)))
- arrayList.Add(isEncode ? (object) HttpUtility.HtmlEncode(s) : (object) s.Trim());
- return (string[]) arrayList.ToArray(typeof (string));
- }
- public bool DoesFieldRequireWrapping(string fieldName)
- {
- return this.InnerItem.DoesFieldRequireWrapping(fieldName);
- }
- }
- }
- @using Company.Models.Concrete.Items
- @using Company.ViewModels
- @using Company.ViewModels.Items
- @using Sitecore.Modules.WeBlog.Extensions
- @using Sitecore.Modules.WeBlog.Globalization
- @using Sitecore.Modules.WeBlog.Model
- @using Sitecore.Modules.WeBlog.Mvc.Model
- @model Company.ViewModels.PostBlogList
- <div class="wb-entry-list">
- @foreach (var entry in Model.BlogEntries)
- {
- Html.RenderPartial(Model.PostTemplate, new BlogEntryList(entry));
- }
- @if (Model.ShowViewMoreLink)
- {
- <div class="wb-view-more-wrapper">
- <a id="ancViewMore" class="wb-view-more" href="@Model.ViewMoreHref">
- @Sitecore.Modules.WeBlog.Globalization.Translator.Render("VIEW_MORE").ToHtmlString()
- </a>
- <span class="wb-loading-animation" style="display: none;">Loading...</span>
- </div>
- }
- </div>
- @using AE.Core.ViewModels
- @using Glass.Mapper
- @using Sitecore.Modules.WeBlog
- @using Sitecore.Modules.WeBlog.Extensions
- @using Sitecore.Modules.WeBlog.Globalization
- @using Sitecore.Modules.WeBlog.Mvc
- @model Company.ViewModels.BlogEntryList
- <section>
- <header>
- <h2>
- <a href="@Model.EntryItem.Url">@Model.EntryItem.DisplayTitle.ToHtmlString()</a>
- </h2>
- @if (Convert.ToString(Model.EntryItem.ThumbnailImage.Field.Value) != "")
- {
- <div class="thumbnail">
- @Html.Sitecore().Field("Thumbnail Image", Model.EntryItem, new { @class = "wb-image", mw = Model.MaxWidth, mh = Model.MaxHeight })
- </div>
- }
- <div class="wb-details">
- @Model.Authors @* -- new field --*@
- </div>
- </header>
- <div class="description">
- <div class="summary">
- @Model.Summary.ToHtmlString()
- </div>
- @if (Model.ShowCommentsCount)
- {
- <span class="wb-comment-count">
- @Translator.Render("COMMENTS").ToHtmlString() (@Model.EntryItem.CommentCount)
- </span>
- }
- <a class="wb-read-more" href="@Model.EntryItem.Url">@Translator.Text("READ_MORE").ToHtmlString()</a>
- </div>
- </section>
- [InvalidOperationException: Could not locate type 'Company.ViewModels.PostBlogListViewModel, Company'. Model reference: 'Company.ViewModels.PostBlogListViewModel, Company']
- Sitecore.Mvc.Presentation.ModelLocator.GetModelFromTypeName(String typeName,
- String model, Boolean throwOnTypeCreationError) +244
- etc. etc. etc.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement