public IHttpHandler GetHttpHandler(RequestContext requestContext) { HttpPageHelper.CurrentItem = null; var p = new IdeaSeedCMS.Core.Domain.Page(); if (HttpPageHelper.CurrentUser == null) { p = new PageServices().GetByNameAccessLevel(VirtualPath.Replace("-", " "), 60, Convert.ToInt16(ConfigurationManager.AppSettings["APPLICATIONID"])); } else { p = new PageServices().GetByNameAccessLevel(VirtualPath, HttpPageHelper.CurrentUser.AccessLevel, Convert.ToInt16(ConfigurationManager.AppSettings["APPLICATIONID"])); } HttpPageHelper.CurrentPage = p; if (p != null) { var item = new Item(); item.Description = p.Name; item.Name = p.Name; item.SEOTitle = p.SEOTitle; item.ItemReference = item; HttpPageHelper.CurrentItem = item; } AdminBasePage page; page = (AdminBasePage)BuildManager.CreateInstanceFromVirtualPath(ActualPath, typeof(System.Web.UI.Page)); HttpPageHelper.IsValidRequest = true; return(page); }
protected void GetData() { DataSet ds = spp.GetVirtualData(); // Clean up the path to match data in resource file. string path = VirtualPath.Replace(HostingEnvironment.ApplicationVirtualPath, ""); path = path.TrimEnd('/'); // Get the virtual directory from the resource table. DataTable dirs = ds.Tables["resource"]; DataRow[] rows = dirs.Select( String.Format("(name = '{0}') AND (type='dir')", path)); // If the select returned a row, the directory exists. if (rows.Length > 0) { exists = true; // Get children from the resource table. // This technique works for small numbers of virtual resources. // Sites with moderate to large numbers of virtual // resources should choose a method that consumes fewer // computer resources. DataRow[] childRows = dirs.Select( String.Format("parentPath = '{0}'", path)); foreach (DataRow childRow in childRows) { string childPath = (string)childRow["path"]; if (childRow["type"].ToString() == "dir") { SampleVirtualDirectory svd = new SampleVirtualDirectory(childPath, spp); children.Add(svd); directories.Add(svd); } else { SampleVirtualFile svf = new SampleVirtualFile(childPath, spp); children.Add(svf); files.Add(svf); } } } }
protected override void Init() { Permalink = FrontMatter.ContainsKey("permalink") ? (string)FrontMatter["permalink"] : null; Layout = FrontMatter.ContainsKey("layout") ? (string)FrontMatter["layout"] : null; Slug = FrontMatter.ContainsKey("slug") ? (string)FrontMatter["slug"] : null; Published = FrontMatter.ContainsKey("published") ? (bool)FrontMatter["published"] : true; NoCache = FrontMatter.ContainsKey("no_cache") ? (bool)FrontMatter["no_cache"] : false; Categories = new List <string>(); Tags = new List <string>(); // categories if (FrontMatter.ContainsKey("categories")) { var categories = FrontMatter["categories"] as List <object>; if (categories != null) { Categories = categories.Select(item => item.ToString()).ToList(); } else { var commaSeparatedString = FrontMatter["categories"] as string; if (commaSeparatedString != null) { Categories = commaSeparatedString.Split(new char[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); } } } // tags if (FrontMatter.ContainsKey("tags")) { var tags = FrontMatter["tags"] as List <object>; if (tags != null) { Tags = tags.Select(item => item.ToString()).ToList(); } else { var commaSeparatedString = FrontMatter["tags"] as string; if (commaSeparatedString != null) { Tags = commaSeparatedString.Split(new char[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); } } } // calculate Permalink if (String.IsNullOrWhiteSpace(Permalink)) { Permalink = "/" + VirtualPath.Replace('\\', '/').Trim('/'); // now we have /some_folder/file.html or /some_file.md // remove extension int idx = Permalink.LastIndexOf("."); if (idx != -1) { Permalink = Permalink.Substring(0, idx); } // check if it ends with /index if (Permalink.EndsWith("/index", StringComparison.OrdinalIgnoreCase)) { Permalink = Permalink.Substring(0, Permalink.Length - 6); } if (String.IsNullOrEmpty(Permalink)) { Permalink = "/"; } } // is it collection document? string[] permalinkParts = Permalink.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (permalinkParts.Length > 1 && permalinkParts[0].StartsWith("_")) { this.Collection = permalinkParts[0].Substring(1); var collectionMetadata = Site.GetCollectionMetadata(this.Collection); // calculate date and permalink from post URL string pageName = permalinkParts.Last(); var match = Regex.Match(pageName, @"^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})(-(?<title>.+))?"); if (match.Success) { string year = match.Groups["year"].Value; string month = match.Groups["month"].Value; string day = match.Groups["day"].Value; // replace permalink Permalink = collectionMetadata.Permalink .Replace(":year", year) .Replace(":month", month) .Replace(":day", day) .Replace(":title", match.Groups["title"].Value); // replace date Date = new DateTime(Int32.Parse(year), Int32.Parse(month), Int32.Parse(day)); } else { // replace '/_' in the beginning with '/' Permalink = "/" + Permalink.Substring(2); } // published state this.Published = collectionMetadata.Output; // add page to a collection Site.AddCollectionPage(this); } // override date from front matter if (FrontMatter.ContainsKey("date")) { Date = (DateTime)FrontMatter["date"]; } }