@using Mediaparts.Features.PublicationExporting.DAL.Razor @using Mediaparts.Features.PublicationExporting.DAL.Razor.Contexts @using Mediaparts.Features.PublicationExporting.DAL.Razor.PageContent @using Mediaparts.Features.PublicationExporting.DAL.Razor.Settings @using Newtonsoft.Json @{ RazorPageContext PublicationModel = null; string tocURL = "./toc.html"; var IS_DEBUG = false; if (Model is RazorPageContext) { PublicationModel = (RazorPageContext)Model; //Костыль, потому что basic находится в папке assets/basic-html PublicationModel.DynamicFilesFolder = new Uri("./..", UriKind.Relative); PublicationModel.StaticFilesFolder = new Uri(".", UriKind.Relative); } else { //Fill this to debug PublicationModel = new RazorPageContext(); PublicationModel.DynamicFilesFolder = new Uri("./debug", UriKind.Relative); PublicationModel.StaticFilesFolder = new Uri(".", UriKind.Relative); using (var fs = File.OpenRead(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "debug/model.bin"))) { var deserializer = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); PublicationModel.ProjectModel = (RazorProjectModel)deserializer.Deserialize(fs); } var PAGE_ID = 1; PublicationModel.PageIndex = PublicationModel.ProjectModel.Pages.Select((a, i) => new { a, i }).First(x => x.a.Id == PAGE_ID).i; tocURL = "./toc.cshtml"; IS_DEBUG = true; } if (PublicationModel.ProjectModel.TableOfContents == null || PublicationModel.ProjectModel.TableOfContents.Children.Count() == 0) { tocURL = String.Empty; } } @{ RazorPageModel current = (RazorPageModel)PublicationModel.ProjectModel.Pages.ElementAt(PublicationModel.PageIndex); int lastIndex = PublicationModel.ProjectModel.Pages.Count() - 1; var textColor = System.Drawing.ColorTranslator.ToHtml(PublicationModel.ProjectModel.Styles.BackgroundTextСolor); var bgColor = System.Drawing.ColorTranslator.ToHtml(PublicationModel.ProjectModel.Styles.PublicationBackgroundColor); string coverPath = PublicationModel.DynamicFilesFolder + "/flash/pages/page0001_s." + ImageFormat(PublicationModel.ProjectModel.Pages.ElementAt(0).ThumbnailImageType); string bgImage = (PublicationModel.ProjectModel.Styles.PublicationBackgroundImage == null) ? "" : (PublicationModel.DynamicFilesFolder + "/" + PublicationModel.ProjectModel.Styles.PublicationBackgroundImage.OriginalString); var GALLERY_CONTENT = new Dictionary>(); var videos = current.Content.OfType().ToArray(); var VIDEOS_DICT = new Dictionary(); var VIDEOS_INFO = new Dictionary(); for (var i = 0; i < videos.Length; i++) { var videoId = "video" + i; var razorVideo = videos[i]; VIDEOS_DICT.Add(razorVideo, videoId); VIDEOS_INFO.Add(videoId, new { thumb = (razorVideo.Image!=null && razorVideo.ShowImage)? (PublicationModel.DynamicFilesFolder + "/common/pages-content/" + razorVideo.Image.ToString()): "", videoId = razorVideo.Id }); } } @PublicationModel.ProjectModel.PublicationName @if (PublicationModel.ProjectModel.Styles.FavIcon != null) { } @if (!String.IsNullOrEmpty(current.SeoSettings.Description)) { } @if (!String.IsNullOrEmpty(PublicationModel.ProjectModel.Analytics.GoogleUANumber)) { if (PublicationModel.ProjectModel.Analytics.UseUniversalAnalytics) { } } @if (!String.IsNullOrEmpty(bgImage)) { Background Image }
@if (!String.IsNullOrEmpty(tocURL)) { Table of Contents Table of Contents } @{ var downloads = PublicationModel.ProjectModel.Downloads; var hasDownloads = (downloads != null && (downloads.Mac!=null || downloads.Pdf!=null || (downloads.UserFiles!=null && downloads.UserFiles.Any()) || downloads.Windows!=null)) || PublicationModel.ProjectModel.PublicationType == RazorPublicationType.PhotoAlbum; } @if (hasDownloads) { }
@{ var prev = PublicationModel.PageIndex == 0 ? tocURL : PageUrl(PublicationModel.ProjectModel.Pages.ElementAt(PublicationModel.PageIndex - 1)); var next = PublicationModel.PageIndex == lastIndex ? "" : PageUrl(PublicationModel.ProjectModel.Pages.ElementAt(PublicationModel.PageIndex + 1)); var prevPageId = PublicationModel.PageIndex == 0 ? "tocPageArrow" : "pagePrevArrow"; } @if (PublicationModel.ProjectModel.Settings.RtlModeEnabled) { if (!String.IsNullOrEmpty(next)) { Next Page } } else { if (!String.IsNullOrEmpty(prev)) { Previous Page } } @{ var currentPageName = String.IsNullOrEmpty(current.Name) ? current.Id.ToString() : current.Name; var totalPages = ""; if (String.IsNullOrEmpty(PublicationModel.ProjectModel.Styles.CustomTotalPages)) { var totalPagesCount = CountTotalPages(PublicationModel.ProjectModel.Settings.PageTypeHelper, PublicationModel.ProjectModel.Styles.NumerationOffset); if (totalPagesCount > 0) { totalPages = "/ " + totalPagesCount.ToString(); } else { totalPages = "/ " + PublicationModel.ProjectModel.Pages.ElementAt(lastIndex).Name; } } else { totalPages = PublicationModel.ProjectModel.Styles.CustomTotalPages; } }  @currentPageName @totalPages @if (PublicationModel.ProjectModel.Settings.RtlModeEnabled) { if (!String.IsNullOrEmpty(prev)) { Previous Page } } else { if (!String.IsNullOrEmpty(next)) { Next Page } } @if (PublicationModel.ProjectModel.IsShareEnabled) { }
Information
@{ var mobileButtonStyle = "display:none;"; var mobileButtonId = ""; if (!String.IsNullOrEmpty(tocURL) || PublicationModel.ProjectModel.IsShareEnabled || hasDownloads ) { mobileButtonStyle = ""; mobileButtonId = "mobileMenuButton"; } } Show Menu
@if (PublicationModel.ProjectModel.Settings.RtlModeEnabled) { if (!String.IsNullOrEmpty(next)) { Next Page } } else { if (!String.IsNullOrEmpty(prev)) { Previous Page } } @currentPageName @totalPages @if (PublicationModel.ProjectModel.Settings.RtlModeEnabled) { if (!String.IsNullOrEmpty(prev)) { Previous Page } } else { if (!String.IsNullOrEmpty(next)) { Next Page } }
Page Background @{ var fontsDoctionary = new Dictionary(); } @foreach (RazorContentItemBase item in current.Content) { var styles = new Dictionary(); styles.Add("top", PercentSize(item.Top, current.Size.Height)); styles.Add("left", PercentSize(item.Left, current.Size.Width)); styles.Add("width", PercentSize(item.Width, current.Size.Width)); styles.Add("height", PercentSize(item.Height, current.Size.Height)); if (item is RazorTextBlock) { var textBlock = (RazorTextBlock)item; styles.Add("font-size", FontSizeEm(textBlock.Size)); styles.Add("color", System.Drawing.ColorTranslator.ToHtml(textBlock.Color)); //TODO Обернуть текст в кавычки styles.Add("font-family", @textBlock.Font.Name); //обработка шрифтов var addSpan = ""; var key = textBlock.Font.Name + (textBlock.Font.IsItalic ? "_italic" : "") + (textBlock.Font.IsBold ? "_bold" : ""); if (!fontsDoctionary.ContainsKey(key)) { fontsDoctionary[key] = textBlock; addSpan = "testString"; } if (item is RazorTextLink) { var textLink = (RazorTextLink)item; var href = textLink.TargetPageId.HasValue ? PageUrl(PageModelById(PublicationModel, textLink.TargetPageId.Value)) : (textLink.TargetUrl.AbsoluteUri); var addClassName = textLink.TargetPageId.HasValue ? "internalLink" : ""; var linkTarget = textLink.TargetPageId.HasValue ? "_self" : (textLink.TargetType.HasValue ? TargetType(textLink.TargetType.Value) : ""); i.Key + ":" + i.Value)));"> @MakeText(textLink, String.IsNullOrEmpty("addSpan")) } else {

i.Key + ":" + i.Value)));"> @MakeText(textBlock, String.IsNullOrEmpty("addSpan"))

} } if (item is RazorLink) { var areaLink = (RazorLink)item; var href = areaLink.TargetPageId.HasValue ? PageUrl(PageModelById(PublicationModel, areaLink.TargetPageId.Value)) : areaLink.TargetUrl.OriginalString; string id = areaLinkIndexDictionary.ContainsKey(areaLink) ? ("areaLink" + areaLinkIndexDictionary[areaLink].ToString()) : null; var addClassName = areaLink.TargetPageId.HasValue ? "internalLink" : ""; var linkTarget = areaLink.TargetPageId.HasValue ? "_self" : (areaLink.TargetType.HasValue ? TargetType(areaLink.TargetType.Value) : ""); i.Key + ":" + i.Value))"> } if (item is RazorVideo) { var video = (RazorVideo)item; var videoItemStyle = ""; var videoID = VIDEOS_DICT[video]; if (video.ShowImage && video.Image == null) { { videoItemStyle = "background-color: #000000"; } }
i.Key + ":" + i.Value))); @videoItemStyle"> Play Video
} if (item is RazorImage) { var image = (RazorImage)item; var guid = Guid.NewGuid().ToString(); GALLERY_CONTENT.Add(guid, image.Images.Select(a => (PublicationModel.DynamicFilesFolder) + "/common/pages-content/" + a.ToString())); var imageItemAddClass = image.PreviewImage == null ? "emptyImage" : ""; var imageItemStyle = image.PreviewImage == null ? "" : ("background:url('" + (PublicationModel.DynamicFilesFolder) + "/common/pages-content/" + image.PreviewImage.ToString() + "') center center no-repeat; background-size:cover;");
i.Key + ":" + i.Value))); @imageItemStyle"> @{if (image.PreviewImage != null) {
} }
} }
@helper areaLinkBgStyle(System.Drawing.Color color) { var htmlColor = System.Drawing.ColorTranslator.ToHtml(color); var a = (color.A / 255.0).ToString("N1", System.Globalization.CultureInfo.InvariantCulture); background: transparent; filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=@(htmlColor),endColorstr=@(htmlColor)); zoom:1; background:rgb(@color.R,@color.G,@color.B); background:rgba(@color.R,@color.G,@color.B, @a); } @helper MetaRobots(RazorPageSeoSettings seoSettings) { var list = new List(); if (seoSettings.NoFollow) { list.Add("nofollow"); } if (seoSettings.NoIndex) { list.Add("noindex"); } if (list.Count == 0) { @Html.Raw("all"); } else { @Html.Raw(String.Join(",", list.ToArray())); } } @helper MakeText(RazorTextBlock textBlock, bool addSpan) { var start = ""; var end = ""; if (addSpan) { start += ""; end = "" + end; } if (textBlock.Font.IsBold) { start += ""; end = "" + end; } if (textBlock.Font.IsItalic) { start += ""; end = "" + end; } WriteLiteral(start); Write(textBlock.Text); WriteLiteral(end); } @functions{ public static int DEFAULT_SIZE = 20; public static Dictionary areaLinkIndexDictionary = new Dictionary(); public static string PercentSize(Double currentSize, Double pageSize) { return (currentSize / pageSize * 100).ToString("N6", System.Globalization.CultureInfo.InvariantCulture) + "%"; } public static string FontSizeEm(decimal fontSizePX) { return (fontSizePX / DEFAULT_SIZE).ToString("N6", System.Globalization.CultureInfo.InvariantCulture) + "em"; } public static string TargetType(RazorUrlTargetType type) { switch (type) { case RazorUrlTargetType.Blank: return "_blank"; case RazorUrlTargetType.Parent: return "_parent"; case RazorUrlTargetType.Self: return "_self"; case RazorUrlTargetType.Top: return "_top"; } return type.ToString(); } public static string ImageFormat(RazorImageFormatType format) { switch (format) { case RazorImageFormatType.Jpeg: return "jpg"; case RazorImageFormatType.Png: return "png"; } return ""; } public RazorPageModel PageModelById(RazorPageContext PublicationModel, int id) { return PublicationModel.ProjectModel.Pages.First(x => x.Id == id); } public static string PageUrl(RazorPageModel model) { return String.Format("./page-{0}.html", model.UrlHeader); } public static int CountTotalPages(string pageTypeHelper, int offset) { var count = 0; var str = String.IsNullOrEmpty(pageTypeHelper)? "" : pageTypeHelper.ToLower() ; for (int i = 0; i < str.Length; i++) { switch (str[i]) { case 'w': count += 2; break; case 'l': case 'r': case 's': count++; break; default: break; } } return count - offset; } public static string JavaScriptStringEncode(string value, bool addDoubleQuotes) { if (String.IsNullOrEmpty(value)) return addDoubleQuotes ? "\"\"" : String.Empty; int len = value.Length; bool needEncode = false; char c; for (int i = 0; i < len; i++) { c = value[i]; if (c >= 0 && c <= 31 || c == 34 || c == 39 || c == 60 || c == 62 || c == 92) { needEncode = true; break; } } if (!needEncode) return addDoubleQuotes ? "\"" + value + "\"" : value; var sb = new System.Text.StringBuilder(); if (addDoubleQuotes) sb.Append('"'); for (int i = 0; i < len; i++) { c = value[i]; if (c >= 0 && c <= 7 || c == 11 || c >= 14 && c <= 31 || c == 39 || c == 60 || c == 62) sb.AppendFormat("\\u{0:x4}", (int)c); else switch ((int)c) { case 8: sb.Append("\\b"); break; case 9: sb.Append("\\t"); break; case 10: sb.Append("\\n"); break; case 12: sb.Append("\\f"); break; case 13: sb.Append("\\r"); break; case 34: sb.Append("\\\""); break; case 92: sb.Append("\\\\"); break; default: sb.Append(c); break; } } if (addDoubleQuotes) sb.Append('"'); return sb.ToString(); } public static string GetFileName(string path) { int fileExtPos = path.LastIndexOf("."); if (fileExtPos >= 0) return path.Substring(0, fileExtPos); return path; } }