Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.67 KB | None | 0 0
  1. using Sitecore.Modules.WeBlog.Components;
  2. using Sitecore.Modules.WeBlog.Configuration;
  3. using Sitecore.Modules.WeBlog.Data.Items;
  4. using Sitecore.Mvc.Presentation;
  5. using System.Collections.Generic;
  6. using Sitecore.Modules.WeBlog.Mvc.Model;
  7.  
  8. namespace Company.ViewModels
  9. {
  10. public class PostBlogList : BlogRenderingModelBase
  11. {
  12. protected const string DefaultPostTemplate = "~/Views/WeBlog/PostListEntry.cshtml";
  13.  
  14. public IEnumerable<EntryItem> BlogEntries { get; set; }
  15.  
  16. public bool ShowViewMoreLink { get; set; }
  17.  
  18. public string ViewMoreHref { get; set; }
  19.  
  20. public string PostTemplate { get; set; }
  21.  
  22. protected IPostListCore PostListCore { get; set; }
  23.  
  24. public PostBlogList()
  25. : this((IPostListCore)null)
  26. {
  27. }
  28.  
  29. public PostBlogList(IPostListCore postListCore)
  30. {
  31. this.PostListCore = postListCore ?? (IPostListCore)new Sitecore.Modules.WeBlog.Components.PostListCore(this.CurrentBlog, (IWeBlogSettings)null);
  32. }
  33.  
  34. public override void Initialize(Rendering rendering)
  35. {
  36. base.Initialize(rendering);
  37. this.PostListCore.Initialize(RenderingContext.Current.PageContext.RequestContext.HttpContext.Request.QueryString);
  38. if (string.IsNullOrEmpty(this.PostTemplate))
  39. this.PostTemplate = "~/Views/WeBlog/PostListEntry.cshtml";
  40. this.BlogEntries = this.PostListCore.Entries;
  41. this.PostTemplate = this.PostTemplate;
  42. if (this.PostListCore.ShowViewMoreLink)
  43. {
  44. this.ShowViewMoreLink = true;
  45. this.ViewMoreHref = this.PostListCore.ViewMoreHref;
  46. }
  47. else
  48. this.ShowViewMoreLink = false;
  49. }
  50. }
  51. }
  52.  
  53. using System;
  54. using System.Collections.Generic;
  55. using System.Linq;
  56. using System.Text;
  57. using System.Threading.Tasks;
  58. using Sitecore.Modules.WeBlog.Data.Items;
  59. using Glass.Mapper.Sc.Configuration.Attributes;
  60. using Glass.Mapper.Sc.Fields;
  61. using Sitecore.Modules.WeBlog.Managers;
  62. using Sitecore.Modules.WeBlog.Mvc.Model;
  63. using Sitecore.Data.Items;
  64. using Sitecore.Modules.WeBlog.Pipelines.GetSummary;
  65. using Sitecore.Pipelines;
  66. using System.Drawing;
  67. using Company.Models.Concrete.Items;
  68.  
  69. namespace Company.ViewModels
  70. {
  71. public class BlogEntryList
  72. {
  73. public EntryItem EntryItem { get; set; }
  74.  
  75. public string Summary { get; set; }
  76.  
  77. public int MaxWidth { get; set; }
  78.  
  79. public int MaxHeight { get; set; }
  80.  
  81. public bool ShowCommentsCount { get; set; }
  82.  
  83. /*-- new field --*/
  84. [SitecoreField("Authors")]
  85. public virtual IEnumerable<Person> Authors { get; set; }
  86.  
  87. public BlogEntryList(EntryItem entry)
  88. {
  89. this.EntryItem = entry;
  90. BlogHomeItem currentBlog = ManagerFactory.BlogManagerInstance.GetCurrentBlog((Item)entry);
  91. Size imageSizeDimension = currentBlog.MaximumThumbnailImageSizeDimension;
  92. if (imageSizeDimension != Size.Empty)
  93. {
  94. this.MaxWidth = imageSizeDimension.Width;
  95. this.MaxHeight = imageSizeDimension.Height;
  96. }
  97. this.Summary = this.GetSummary(this.EntryItem);
  98. this.ShowCommentsCount = currentBlog.EnableComments.Checked && !this.EntryItem.DisableComments.Checked;
  99.  
  100. }
  101.  
  102. protected string GetSummary(EntryItem entry)
  103. {
  104. GetSummaryArgs getSummaryArgs = new GetSummaryArgs();
  105. getSummaryArgs.Entry = entry;
  106. CorePipeline.Run("weblogGetSummary", (PipelineArgs)getSummaryArgs, true);
  107. return getSummaryArgs.Summary;
  108. }
  109. }
  110. }
  111.  
  112. // Decompiled with JetBrains decompiler
  113. // Type: Sitecore.Modules.WeBlog.Data.Items.EntryItem
  114. // Assembly: Sitecore.Modules.WeBlog, Version=3.1.0.41507, Culture=neutral, PublicKeyToken=null
  115. // MVID: 60C67A20-E02A-42BD-B187-B3ED588D19A1
  116. // Assembly location: C:Dev SitesCompanyWebsiteBinSitecore.Modules.WeBlog.dll
  117.  
  118. using Sitecore.Data.Fields;
  119. using Sitecore.Data.Items;
  120. using Sitecore.Links;
  121. using Sitecore.Modules.WeBlog.Data.Fields;
  122. using Sitecore.Modules.WeBlog.Extensions;
  123. using Sitecore.Modules.WeBlog.Managers;
  124. using Sitecore.Security.Accounts;
  125. using System;
  126. using System.Collections;
  127. using System.Collections.Generic;
  128. using System.Linq;
  129. using System.Web;
  130.  
  131. namespace Sitecore.Modules.WeBlog.Data.Items
  132. {
  133. public class EntryItem : CustomItem
  134. {
  135. public EntryItem(Item innerItem)
  136. : base(innerItem)
  137. {
  138. }
  139.  
  140. public static implicit operator EntryItem(Item innerItem)
  141. {
  142. if (innerItem == null)
  143. return (EntryItem) null;
  144. return new EntryItem(innerItem);
  145. }
  146.  
  147. public static implicit operator Item(EntryItem customItem)
  148. {
  149. return customItem?.InnerItem;
  150. }
  151.  
  152. public CustomMultiListField Category
  153. {
  154. get
  155. {
  156. return new CustomMultiListField(this.InnerItem, (MultilistField) this.InnerItem.Fields[nameof (Category)]);
  157. }
  158. }
  159.  
  160. public CustomCheckboxField DisableComments
  161. {
  162. get
  163. {
  164. return new CustomCheckboxField(this.InnerItem, (CheckboxField) this.InnerItem.Fields["Disable Comments"]);
  165. }
  166. }
  167.  
  168. public CustomTextField Title
  169. {
  170. get
  171. {
  172. return new CustomTextField(this.InnerItem, (TextField) this.InnerItem.Fields[nameof (Title)]);
  173. }
  174. }
  175.  
  176. public CustomTextField Introduction
  177. {
  178. get
  179. {
  180. return new CustomTextField(this.InnerItem, (TextField) this.InnerItem.Fields[nameof (Introduction)]);
  181. }
  182. }
  183.  
  184. public CustomTextField Tags
  185. {
  186. get
  187. {
  188. return new CustomTextField(this.InnerItem, (TextField) this.InnerItem.Fields[nameof (Tags)]);
  189. }
  190. }
  191.  
  192. public CustomTextField Content
  193. {
  194. get
  195. {
  196. return new CustomTextField(this.InnerItem, (TextField) this.InnerItem.Fields[nameof (Content)]);
  197. }
  198. }
  199.  
  200. public CustomTextField Author
  201. {
  202. get
  203. {
  204. return new CustomTextField(this.InnerItem, (TextField) this.InnerItem.Fields[nameof (Author)]);
  205. }
  206. }
  207.  
  208. public CustomDateField EntryDate
  209. {
  210. get
  211. {
  212. return new CustomDateField(this.InnerItem, (DateField) this.InnerItem.Fields["Entry Date"]);
  213. }
  214. }
  215.  
  216. public CustomImageField Image
  217. {
  218. get
  219. {
  220. return new CustomImageField(this.InnerItem, (ImageField) this.InnerItem.Fields[nameof (Image)]);
  221. }
  222. }
  223.  
  224. public CustomImageField ThumbnailImage
  225. {
  226. get
  227. {
  228. return new CustomImageField(this.InnerItem, (ImageField) this.InnerItem.Fields["Thumbnail Image"]);
  229. }
  230. }
  231.  
  232. public string[] TagsSplit
  233. {
  234. get
  235. {
  236. return this.ExtractTags(false);
  237. }
  238. set
  239. {
  240. this.Tags.Field.Value = EntryItem.FormTags(value);
  241. }
  242. }
  243.  
  244. public string Url
  245. {
  246. get
  247. {
  248. return LinkManager.GetItemUrl(this.InnerItem);
  249. }
  250. }
  251.  
  252. public string AbsoluteUrl
  253. {
  254. get
  255. {
  256. UrlOptions defaultOptions = UrlOptions.DefaultOptions;
  257. defaultOptions.AlwaysIncludeServerUrl = true;
  258. return LinkManager.GetItemUrl(this.InnerItem, defaultOptions);
  259. }
  260. }
  261.  
  262. public int CommentCount
  263. {
  264. get
  265. {
  266. return ManagerFactory.CommentManagerInstance.GetCommentsCount((Item) this);
  267. }
  268. }
  269.  
  270. public DateTime Created
  271. {
  272. get
  273. {
  274. if (!(this.EntryDate.DateTime != DateTime.MinValue))
  275. return this.InnerItem.Statistics.Created;
  276. return this.EntryDate.DateTime;
  277. }
  278. }
  279.  
  280. public User CreatedBy
  281. {
  282. get
  283. {
  284. string accountName = this.InnerItem[FieldIDs.CreatedBy];
  285. if (!string.IsNullOrEmpty(accountName))
  286. return Account.FromName(accountName, AccountType.User) as User;
  287. return (User) null;
  288. }
  289. }
  290.  
  291. public string AuthorName
  292. {
  293. get
  294. {
  295. if (this.Author.Raw.Contains("\"))
  296. {
  297. if (!User.Exists(this.Author.Raw))
  298. return this.Author.Rendered;
  299. User user = User.FromName(this.Author.Raw, false);
  300. if ((Account) user == (Account) null)
  301. return this.Author.Rendered;
  302. string str = user.LocalName;
  303. if (user.Profile != null && !string.IsNullOrEmpty(user.Profile.FullName))
  304. str = user.Profile.FullName;
  305. return str;
  306. }
  307. if (string.IsNullOrEmpty(this.Author.Raw) || this.Author.Raw == "$currentuser")
  308. return this.CreatedBy.LocalName;
  309. return this.Author.Rendered;
  310. }
  311. }
  312.  
  313. public string DisplayTitle
  314. {
  315. get
  316. {
  317. if (string.IsNullOrEmpty(this.Title.Text))
  318. return this.Name;
  319. return this.Title.Text;
  320. }
  321. }
  322.  
  323. private static string FormTags(string[] tags)
  324. {
  325. string str = string.Empty;
  326. for (int index = 0; index < tags.Length; ++index)
  327. str = str + tags[index].Trim() + (index < tags.Length - 1 ? "," : string.Empty);
  328. return str;
  329. }
  330.  
  331. private string[] ExtractTags(bool isEncode)
  332. {
  333. string[] strArray = this.InnerItem["Tags"].Trim().Split(',');
  334. ArrayList arrayList = new ArrayList();
  335. foreach (string s in ((IEnumerable<string>) strArray).Where<string>((Func<string, bool>) (tag => tag.Trim() != string.Empty)))
  336. arrayList.Add(isEncode ? (object) HttpUtility.HtmlEncode(s) : (object) s.Trim());
  337. return (string[]) arrayList.ToArray(typeof (string));
  338. }
  339.  
  340. public bool DoesFieldRequireWrapping(string fieldName)
  341. {
  342. return this.InnerItem.DoesFieldRequireWrapping(fieldName);
  343. }
  344. }
  345. }
  346.  
  347. @using Company.Models.Concrete.Items
  348. @using Company.ViewModels
  349. @using Company.ViewModels.Items
  350. @using Sitecore.Modules.WeBlog.Extensions
  351. @using Sitecore.Modules.WeBlog.Globalization
  352. @using Sitecore.Modules.WeBlog.Model
  353. @using Sitecore.Modules.WeBlog.Mvc.Model
  354. @model Company.ViewModels.PostBlogList
  355.  
  356. <div class="wb-entry-list">
  357.  
  358. @foreach (var entry in Model.BlogEntries)
  359. {
  360. Html.RenderPartial(Model.PostTemplate, new BlogEntryList(entry));
  361. }
  362. @if (Model.ShowViewMoreLink)
  363. {
  364. <div class="wb-view-more-wrapper">
  365. <a id="ancViewMore" class="wb-view-more" href="@Model.ViewMoreHref">
  366. @Sitecore.Modules.WeBlog.Globalization.Translator.Render("VIEW_MORE").ToHtmlString()
  367. </a>
  368. <span class="wb-loading-animation" style="display: none;">Loading...</span>
  369. </div>
  370. }
  371. </div>
  372.  
  373. @using AE.Core.ViewModels
  374. @using Glass.Mapper
  375. @using Sitecore.Modules.WeBlog
  376. @using Sitecore.Modules.WeBlog.Extensions
  377. @using Sitecore.Modules.WeBlog.Globalization
  378. @using Sitecore.Modules.WeBlog.Mvc
  379. @model Company.ViewModels.BlogEntryList
  380.  
  381. <section>
  382. <header>
  383. <h2>
  384. <a href="@Model.EntryItem.Url">@Model.EntryItem.DisplayTitle.ToHtmlString()</a>
  385. </h2>
  386.  
  387. @if (Convert.ToString(Model.EntryItem.ThumbnailImage.Field.Value) != "")
  388. {
  389. <div class="thumbnail">
  390. @Html.Sitecore().Field("Thumbnail Image", Model.EntryItem, new { @class = "wb-image", mw = Model.MaxWidth, mh = Model.MaxHeight })
  391. </div>
  392. }
  393.  
  394. <div class="wb-details">
  395. @Model.Authors &nbsp; @* -- new field --*@
  396. </div>
  397. </header>
  398.  
  399. <div class="description">
  400. <div class="summary">
  401. @Model.Summary.ToHtmlString()
  402. </div>
  403. @if (Model.ShowCommentsCount)
  404. {
  405. <span class="wb-comment-count">
  406. @Translator.Render("COMMENTS").ToHtmlString() (@Model.EntryItem.CommentCount)
  407. </span>
  408. }
  409. <a class="wb-read-more" href="@Model.EntryItem.Url">@Translator.Text("READ_MORE").ToHtmlString()</a>
  410. </div>
  411. </section>
  412.  
  413. [InvalidOperationException: Could not locate type 'Company.ViewModels.PostBlogListViewModel, Company'. Model reference: 'Company.ViewModels.PostBlogListViewModel, Company']
  414. Sitecore.Mvc.Presentation.ModelLocator.GetModelFromTypeName(String typeName,
  415. String model, Boolean throwOnTypeCreationError) +244
  416.  
  417. etc. etc. etc.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement