public static void LoadPageData(CmsPage result) { if (result != null) { IStorageClient client = StorageHelper.GetStorageClient(); result.Content = client.OpenAsString(CurrentSite.PageStorageContainer, StorageClientConst.RootFolder, result.Guid); } }
public static void CreateDefaultPage(string subscriptionGuid, string templateName) { String fullurl = CmsSiteMap.PathCombine("/", GooeyConfigManager.DefaultPageName); CmsPage page = new CmsPage(); page.SubscriptionId = subscriptionGuid; page.Content = GooeyConfigManager.DefaultHomepage; page.Culture = GooeyConfigManager.DefaultCulture; page.DateSaved = UtcDateTime.Now; page.Description = "GooeyCMS Default Homepage"; page.Template = templateName; page.Title = "Default Homepage"; page.Url = fullurl; page.UrlHash = TextHash.MD5(page.Url).Value; page.Guid = System.Guid.NewGuid().ToString(); page.IsApproved = true; page.ApprovedBy = "System"; PageManager.Instance.AddNewPage("/", GooeyConfigManager.DefaultPageName, page); }
protected void BtnSave_Click(Object sender, EventArgs e) { try { String url = Request.QueryString["pid"]; CmsPage existingPage = PageManager.Instance.GetLatestPage(url); CmsPage page = new CmsPage(); Boolean isNewPage = false; String existingPageGuid = Request.QueryString["pid"]; String path = url; String fullurl = url; page.Guid = System.Guid.NewGuid().ToString(); page.Url = fullurl; page.UrlHash = TextHash.MD5(page.Url).Value; page.SubscriptionId = CurrentSite.Guid.Value; page.DateSaved = UtcDateTime.Now; page.IsApproved = false; page.Author = LoggedInUser.Username; page.Culture = CurrentSite.Culture; page.Title = existingPage.Title; page.Content = this.PageMarkupText.Text; page.Keywords = existingPage.Keywords; page.Description = existingPage.Description; page.Template = this.PageTemplate.SelectedValue; page.OnBodyLoad = existingPage.OnBodyLoad; PageManager.Validate(page,isNewPage); PageManager.PublishToWorker(page, PageTaskMessage.Actions.Save); CurrentSite.GetAndSetIsDirty(true); this.Status.Text = "The page has been successfully saved."; this.Status.ForeColor = System.Drawing.Color.Green; } catch (Exception ex) { this.Status.Text = ex.Message; this.Status.ForeColor = System.Drawing.Color.Red; } }
protected void LoadExisting() { String url = Request.QueryString["pid"]; //always display the latest version CmsPage page = PageManager.Instance.GetLatestPage(url); if (page != null) { CmsSitePath path = CmsSiteMap.Instance.GetPath(page.Url); this.ParentDirectories.SelectedValue = path.Parent; this.PageName.Text = path.Name; this.PageTitle.Text = page.Title; this.PageDescription.Text = page.Description; this.PageKeywords.Text = page.Keywords; this.PageMarkupText.Text = page.Content; this.PageTemplate.SelectedValue = page.Template.ToString(); this.BodyLoadOptions.Text = page.OnBodyLoad; this.ParentDirectories.Enabled = false; this.PageName.Enabled = false; this.CssManagePanel.Visible = true; this.CssNotAvailablePanel.Visible = false; this.existingPage = page; } else { throw new ApplicationException("The page " + url + " is not currently available. If you recently created this page it may take a few moments for the page to become available."); } }
private void DeleteAndRefreshPage(RadTreeNode node) { String fullpath = this.GetNodeUrl(node); CmsPage page = PageManager.Instance.GetLatestPage(fullpath); if (page == null) { page = new CmsPage(); page.Url = fullpath; page.UrlHash = TextHash.MD5(page.Url).Value; } PageManager.Instance.DeleteAll(page); node.Remove(); }
private void AddNewDefaultPage(string parent, string current) { String fullurl = CmsSiteMap.PathCombine(parent, current); CmsPage page = new CmsPage(); page.Guid = System.Guid.NewGuid().ToString(); page.Url = fullurl; page.UrlHash = TextHash.MD5(page.Url).Value; page.SubscriptionId = CurrentSite.Guid.Value; page.DateSaved = UtcDateTime.Now; page.IsApproved = false; page.Author = LoggedInUser.Username; page.Culture = CurrentSite.Culture; page.Title = "My New Page"; page.Content = "# My New Page"; page.Keywords = ""; page.Description = "My Default Description"; page.Template = CurrentSite.GetDefaultTemplateName(); page.OnBodyLoad = ""; PageRoleWorker.SavePage(page); }
public PageAdapter(CmsPage item) { this.page = item; }
public static void Validate(CmsPage page, Boolean checkPageCount) { if (CurrentSite.IsAvailable) { if (checkPageCount) { if (!IsAddPageAvailable()) throw new SubscriptionRestrictionException("This subscription has reached its max number of allowed pages of " + CurrentSite.Restrictions.MaxAllowedPages, SubscriptionRestrictionException.RestrictionType.MaxPageCountReached); } if (!CurrentSite.Restrictions.IsJavascriptAllowed) { if (JavascriptPattern.IsMatch(page.Content)) throw new SubscriptionRestrictionException("Script tags are not allowed with this subscription type.", SubscriptionRestrictionException.RestrictionType.IllegalScriptTags); } } }
/// <summary> /// Removes all versions of the page /// </summary> /// <param name="page"></param> public void DeleteAll(CmsPage page) { if (page != null) { String container = SiteHelper.GetStorageKey(SiteHelper.PageContainerKey, page.SubscriptionId); IStorageClient client = StorageHelper.GetStorageClient(); CmsPageDao dao = new CmsPageDao(); IList<CmsPage> pages = dao.FindAllPages(Data.Guid.New(page.SubscriptionId), Data.Hash.New(page.UrlHash)); using (Transaction tx = new Transaction()) { foreach (CmsPage temp in pages) { client.Delete(container, StorageClientConst.RootFolder, temp.Guid); dao.Delete<CmsPage>(temp); } tx.Commit(); } } CmsSitePath path = CmsSiteMap.Instance.GetPath(page.SubscriptionId,page.Url); if (path != null) CmsSiteMap.Instance.Remove(path); }
public void Save(CmsPage page) { CmsPageDao dao = new CmsPageDao(); using (Transaction tx = new Transaction()) { dao.Save<CmsPage>(page); tx.Commit(); } IStorageClient client = StorageHelper.GetStorageClient(); client.Save(SiteHelper.GetStorageKey(SiteHelper.PageContainerKey, page.SubscriptionId), StorageClientConst.RootFolder, page.Guid, page.Content, Permissions.Private); }
public void RemoveObsoletePages(CmsPage page) { CmsPageDao dao = new CmsPageDao(); IList<CmsPage> unapproved = dao.FindUnapprovedPages(Data.Guid.New(page.SubscriptionId),Data.Hash.New(page.UrlHash)); IList<CmsPage> approved = dao.FindApprovedPages(Data.Guid.New(page.SubscriptionId), Data.Hash.New(page.UrlHash)); IStorageClient client = StorageHelper.GetStorageClient(); String container = SiteHelper.GetStorageKey(SiteHelper.PageContainerKey, page.SubscriptionId); //Loop through all of the unapproved pages and remove any old versions. //Start at the first one, since we always want to leave the latest unapproved version using (Transaction tx = new Transaction()) { for (int i = 1; i < unapproved.Count; i++) { client.Delete(container, StorageClientConst.RootFolder, unapproved[i].Guid); dao.Delete<CmsPage>(unapproved[i]); } tx.Commit(); } //Loop through all of the approved pages and remove any old versions. //Start at the first one, since we always want to leave the latest approved version using (Transaction tx = new Transaction()) { for (int i = 1; i < approved.Count; i++) { client.Delete(container, StorageClientConst.RootFolder, approved[i].Guid); dao.Delete<CmsPage>(approved[i]); } tx.Commit(); } }
public void Remove(CmsPage page) { if (page != null) { String container = SiteHelper.GetStorageKey(SiteHelper.PageContainerKey, page.SubscriptionId); IStorageClient client = StorageHelper.GetStorageClient(); CmsPageDao dao = new CmsPageDao(); using (Transaction tx = new Transaction()) { client.Delete(container, StorageClientConst.RootFolder, page.Guid); dao.Delete<CmsPage>(page); tx.Commit(); } } }
public void DeleteFolder(CmsSitePath folder) { if (!folder.IsDirectory) throw new ArgumentException("This method may only be used to delete folders not pages"); IList<CmsSitePath> pages = CmsSiteMap.Instance.GetChildren(folder); foreach (CmsSitePath path in pages) { CmsUrl url = new CmsUrl(path.Url); CmsPage page = this.GetLatestPage(url, false); if (page == null) { page = new CmsPage(); page.Url = path.Url; page.UrlHash = TextHash.MD5(page.Url).Value; } this.DeleteAll(page); } //Delete the directory itself from the sitemap CmsSiteMap.Instance.Remove(folder); }
protected void OnSave_Click(Object sender, EventArgs e) { CmsPage page = new CmsPage(); try { String existingPageGuid = Request.QueryString["pid"]; String path = CmsSiteMap.PathCombine(this.ParentDirectories.SelectedValue, this.PageName.Text); Boolean isNewPage = false; //If we're adding a new page, make sure the page path isn't already in use if (existingPageGuid == null) { CmsSitePath sitepath = CmsSiteMap.Instance.GetPath(path); if (sitepath != null) throw new ApplicationException("This page name already exists and may not be used again."); isNewPage = true; } String fullurl = CmsSiteMap.PathCombine(this.ParentDirectories.SelectedValue, this.PageName.Text); page.Guid = System.Guid.NewGuid().ToString(); page.Url = fullurl; page.UrlHash = TextHash.MD5(page.Url).Value; page.SubscriptionId = CurrentSite.Guid.Value; page.DateSaved = UtcDateTime.Now; page.IsApproved = false; page.Author = LoggedInUser.Username; page.Culture = GetSelectedCulture(); page.Title = this.PageTitle.Text; page.Content = this.PageMarkupText.Text; page.Keywords = this.PageKeywords.Text; page.Description = this.PageDescription.Text; page.Template = this.PageTemplate.SelectedValue; page.OnBodyLoad = this.BodyLoadOptions.Text; PageManager.Validate(page, isNewPage); PageManager.PublishToWorker(page, PageTaskMessage.Actions.Save); String msg = "The page has been successfully saved."; if (Request.QueryString["a"] == null) { System.Threading.Thread.Sleep(5000); Response.Redirect("Edit.aspx?a=edit&pid=" + Server.UrlEncode(page.Url) + "&msg=" + Server.UrlEncode(msg), true); } else { this.Status.Text = msg; this.Status.ForeColor = System.Drawing.Color.Green; } } catch (SubscriptionRestrictionException ex) { Response.Redirect("http://store.gooeycms.net/signup/upgrade.aspx?type=" + ex.TypeOfRestriction.ToString(), true); } catch (Exception ex) { base.LogException(ex); this.Status.Text = ex.Message; this.Status.ForeColor = System.Drawing.Color.Red; } }
public static void PublishToWorker(CmsPage page,Gooeycms.Business.Pages.PageTaskMessage.Actions action) { PageTaskMessage message = new PageTaskMessage(); message.Action = action; message.Page = page; QueueManager queue = new QueueManager(QueueNames.PageActionQueue); queue.Put<PageTaskMessage>(message, TimeSpan.FromMinutes(60)); }
/// <summary> /// Downloads the page content and parses it /// </summary> /// <param name="pagename"></param> /// <param name="item"></param> /// <returns></returns> public static CmsPage GetPage(String defaultTemplate, String culture, String pagename, Boolean replacePhoneNumber, ImportedItem item, Dictionary<CmsUrl, int> cssUses, Dictionary<CmsUrl, int> jsUses) { CmsUrl uri = new CmsUrl(item.Uri); String html = Encoding.UTF8.GetString(SimpleWebClient.GetResponse(uri.ToUri())); HtmlAgilityPack.HtmlDocument htmldoc = new HtmlAgilityPack.HtmlDocument(); htmldoc.OptionFixNestedTags = true; htmldoc.LoadHtml(html); HtmlNode titleNode = htmldoc.DocumentNode.SelectSingleNode("//title"); HtmlNode bodyNode = htmldoc.DocumentNode.SelectSingleNode("//body"); String description = ""; String keywords = ""; StringBuilder otherMetaTags = new StringBuilder(); HtmlNodeCollection metaNodes = htmldoc.DocumentNode.SelectNodes("//meta"); foreach (HtmlNode node in metaNodes) { if (node.OuterHtml.ToLower().Contains("description")) description = node.Attributes["content"].Value; else if (node.OuterHtml.ToLower().Contains("keywords")) keywords = node.Attributes["content"].Value; else otherMetaTags.AppendLine(node.OuterHtml); } StringBuilder inlineScripts = new StringBuilder(); HtmlNodeCollection scriptTags = htmldoc.DocumentNode.SelectNodes("//head//script"); if ((scriptTags != null) && (scriptTags.Count > 0)) { foreach (HtmlNode node in scriptTags) { if (!node.OuterHtml.ToLower().Contains("src")) inlineScripts.AppendLine(node.OuterHtml); else { //track the # of script tags } } } StringBuilder inlineCss = new StringBuilder(); HtmlNodeCollection cssTags = htmldoc.DocumentNode.SelectNodes("//head//style"); if ((cssTags != null) && (cssTags.Count > 0)) { foreach (HtmlNode node in cssTags) { inlineCss.AppendLine(node.OuterHtml); } } StringBuilder bodyOptions = new StringBuilder(); foreach (HtmlAttribute attribute in bodyNode.Attributes) { bodyOptions.AppendFormat("{0}=\"{1}\" ", attribute.Name, attribute.Value); } String path = uri.Path; if (path.EndsWith("/")) path = path + GooeyConfigManager.DefaultPageName; String body = bodyNode.InnerHtml; body = "<!-- nomarkup-begin -->\r\n" + body + "\r\n<!-- nomarkup-end -->"; body = body + "<!-- Imported by Gooeycms Import Tool. Site:" + item.Uri + " at " + UtcDateTime.Now.ToString() + " -->\r\n"; //If a company phone number has been specified, find any instances of a phone number //on the site and replace it with the phone tag if (replacePhoneNumber) body = RegexHelper.ReplacePhoneNumbers(body, "{phone}"); CmsPage page = new CmsPage(); page.SubscriptionId = item.SubscriptionId; page.Author = "Site Importer"; page.Content = body; page.Culture = culture; page.DateSaved = UtcDateTime.Now; page.Description = description; page.Guid = System.Guid.NewGuid().ToString(); page.Url = path; page.UrlHash = TextHash.MD5(page.Url).Value; page.Template = defaultTemplate; page.Keywords = keywords; page.Title = (titleNode != null) ? titleNode.InnerText : ""; page.JavascriptInline = inlineScripts.ToString(); page.CssInline = inlineCss.ToString(); page.OnBodyLoad = bodyOptions.ToString().Trim(); return page; }
/// <summary> /// Adds a new page to the CMS system. /// </summary> /// <param name="parent"></param> /// <param name="pageName"></param> /// <param name="page"></param> public void AddNewPage(string parent, string pageName, CmsPage page) { CmsPageDao dao = new CmsPageDao(); CmsSitePath path = null; try { path = CmsSiteMap.Instance.AddNewPage(Data.Guid.New(page.SubscriptionId),parent, pageName); Save(page); } catch (Exception ex) { Logging.Error("There was an unexpected exception adding the page", ex); CmsSiteMap.Instance.Remove(path); this.Remove(page); } }