public CmsUrl(CmsUrl other) { scheme = other.scheme; authority = other.authority; path = other.path; query = other.query; fragment = other.fragment; }
public CmsUrlWalker(CmsUrl url) { this.url = url; String path = this.url.Path; if (path.StartsWith("/")) path = path.Substring(1); String[] arr = path.Split('/'); pieces = new List<String>(arr); currentPosition = 0; }
protected void Generate_Click(object sender, EventArgs e) { String guid = Request.QueryString["id"]; String link; String landingPage; if (RdoFilePage.Checked) landingPage = this.LstFileDownloads.SelectedValue; else landingPage = this.LandingPage.Text; link = CampaignManager.Instance.GenerateTrackingLink(guid, this.Source.Text, this.Type.SelectedValue, landingPage, RdoFilePage.Checked); CmsUrl url = new CmsUrl(link); this.InfoPanel.Visible = false; this.ResultPanel.Visible = true; this.Result.Text = link; this.InternalLink.Text = url.ApplicationRelativePathAndQuery; }
public override StringBuilder Convert(StringBuilder markup) { Match match = Form.Match(markup.ToString()); while (match.Success) { String content = match.Groups[1].Value; String id = System.Guid.NewGuid().ToString(); //Find the form and pull it out of the markup StringBuilder html = new StringBuilder(); FormMetaInfoParser metainfo = new FormMetaInfoParser(id); FormFieldParser fields = new FormFieldParser(id,base.FormatEngine); WebRequestContext context = new WebRequestContext(); CmsUrl url = new CmsUrl(context.Request.RawUrl); String pagename = url.PathWithoutExtension; String token = AntiXss.UrlEncode(TokenManager.Issue(pagename, TimeSpan.FromMinutes(2))); html.Append(@"<div class=""webscript-form"">").AppendLine(); html.Append(@"<form class=""gooeycms-form"" action=""/gooeyforms/formprocess.handler?token=" + token + @"&pagename=" + AntiXss.UrlEncode(pagename) + @""" method=""post"">").AppendLine(); html = metainfo.Convert(html, content); html = fields.Convert(html, content); html.AppendFormat(SubmitFormat, id, "submit", metainfo.SubmitButtonText).AppendLine(); html.Append(@"</form>").AppendLine(); html.Append(@"<span id=""form_error""></span>"); html.Append("</div>").AppendLine(); //Replace the form markup with the html markup = new StringBuilder(Form.Replace(markup.ToString(), html.ToString(), 1)); match = match.NextMatch(); } return markup; }
public CmsUrl SetQueryParameter(string key, string value) { if (query == null) return AppendQuery(key, value); CmsUrl clone = new CmsUrl(this); string[] queries = query.Split(querySplitter, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < queries.Length; i++) { if (queries[i].StartsWith(key + "=", StringComparison.InvariantCultureIgnoreCase)) { if (value != null) { queries[i] = key + "=" + HttpUtility.UrlEncode(value); clone.query = string.Join(Amp, queries); return clone; } else { if (queries.Length == 1) clone.query = null; else if (query.Length == 2) clone.query = queries[i == 0 ? 1 : 0]; else if (i == 0) clone.query = string.Join(Amp, queries, 1, queries.Length - 1); else if (i == queries.Length - 1) clone.query = string.Join(Amp, queries, 0, queries.Length - 1); else clone.query = string.Join(Amp, queries, 0, i) + Amp + string.Join(Amp, queries, i + 1, queries.Length - i - 1); return clone; } } } return AppendQuery(key, value); }
public CmsUrl AppendQuery(NameValueCollection queryString) { CmsUrl u = new CmsUrl(scheme, authority, path, query, fragment); foreach (string key in queryString.AllKeys) u = u.SetQueryParameter(key, queryString[key]); return u; }
public CmsUrl AppendQuery(string keyValue) { CmsUrl clone = new CmsUrl(this); if (string.IsNullOrEmpty(query)) clone.query = keyValue; else if (!string.IsNullOrEmpty(keyValue)) clone.query += Amp + keyValue; return clone; }
private String FormEvaluator(Match match) { WebRequestContext context = new WebRequestContext(); CmsUrl url = new CmsUrl(context.Request.RawUrl); String currentUrl = url.RelativePath; String formMetaInfo = match.Groups[1].Value; String content = match.Groups[2].Value; StringBuilder metainfo = new StringBuilder(); String error = GetHiddenFields(currentUrl, formMetaInfo, metainfo); String pagename = url.PathWithoutExtension; if (error == null) { StringBuilder formhtml = new StringBuilder(); formhtml.Append(@"<form class=""gooeycms-form"" action=""/gooeyforms/formprocess.handler?&pagename=" + AntiXss.UrlEncode(pagename) + @""" method=""post"">").AppendLine(); formhtml.AppendLine(metainfo.ToString()); formhtml.Append(content); formhtml.Append(@"</form>").AppendLine(); formhtml.Append(@"<span id=""form_error""></span>"); return formhtml.Replace("{form_id}", System.Guid.NewGuid().ToString()).ToString(); } else return error; }
public IList<CmsPage> GetPages(Data.Guid siteGuid, CmsUrl url) { CmsPageDao dao = new CmsPageDao(); return dao.FindByPageHash(siteGuid, TextHash.MD5(url.ToString())); }
/// <summary> /// Gets the latest page based upon the path /// </summary> /// <param name="siteGuid">The site guid</param> /// <param name="path">The page path</param> /// <returns></returns> public CmsPage GetLatestPage(Data.Guid siteGuid, CmsUrl uri, bool loadData, bool forceLatest) { String path = uri.Path; Data.Hash pathHash = TextHash.MD5(path); CmsPageDao dao = new CmsPageDao(); Boolean approvedOnly = false; if (!forceLatest) approvedOnly = !(CurrentSite.IsStagingHost); CmsPage result = dao.FindLatesBySiteAndHash(siteGuid, pathHash, approvedOnly); //Check if there's a default page that should be loaded if (result == null) { String separator = CmsSiteMap.PathSeparator; if (path.EndsWith(CmsSiteMap.PathSeparator)) separator = String.Empty; Data.Hash hashWithDefault = TextHash.MD5(path + separator + CmsSiteMap.DefaultPageName); result = dao.FindLatesBySiteAndHash(siteGuid, hashWithDefault, approvedOnly); } //Load the page contents if (loadData) LoadPageData(result); return result; }
public CmsPage GetLatestPage(Data.Guid siteGuid, CmsUrl uri, bool loadData) { return GetLatestPage(siteGuid, uri, loadData, false); }
public CmsPage GetLatestPage(CmsUrl uri, bool loadData) { return GetLatestPage(CurrentSite.Guid, uri, loadData); }
public CmsPage GetLatestPage(Data.Guid siteGuid, CmsUrl uri) { return GetLatestPage(siteGuid, uri, true); }
/// <summary> /// Gets the latest page for the current site and path. /// </summary> /// <param name="path"></param> public CmsPage GetLatestPage(CmsUrl uri) { return GetLatestPage(CurrentSite.Guid, uri, true); }
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); }
/// <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; }
public List<String> Import(ImportSiteMessage message) { Data.Hash importHash = Data.Hash.New(message.ImportHash); Data.Guid subscriptionId = Data.Guid.New(message.SubscriptionId); Boolean deleteExisting = message.DeleteExisting; List<String> status = new List<String>(); byte[] data; AddStatus(importHash, status, "Site import started at " + UtcDateTime.Now.ToString()); CmsSubscription subscription = SubscriptionManager.GetSubscription(subscriptionId); CmsTheme defaultTheme = ThemeManager.Instance.GetDefaultBySite(subscriptionId); //Check if the import-template already exists CmsTemplate template = TemplateManager.Instance.GetTemplate(subscriptionId, "import-template"); if (template == null) { template = new CmsTemplate(); template.Content = "{content}"; template.Name = "import-template"; template.IsGlobalTemplateType = false; template.LastSaved = UtcDateTime.Now; template.SubscriptionGuid = subscriptionId.Value; template.Theme = defaultTheme; TemplateManager.Instance.Save(template); AddStatus(importHash, status, "Successfully created and associated import template to deafult theme"); } IDictionary<ImportType, IList<ImportedItem>> items = this.GetImportedItems(importHash); //Check if we need to delete the existing site if (deleteExisting) { //Erase all of the existing data SubscriptionManager.Erase(subscription.Guid, false, false); SessionProvider.Instance.Close(); SessionProvider.Instance.GetOpenSession(); //Setup the default SiteHelper.Configure(subscription.Guid); } //First, import all of the images IList<ImportedItem> images = items[ImportType.Image]; foreach (ImportedItem image in images) { CmsUrl uri = new CmsUrl(image.Uri); data = SimpleWebClient.GetResponse(uri.ToUri()); ImageManager.Instance.AddImage(subscriptionId, StorageClientConst.RootFolder, uri.Path, image.ContentType, data); AddStatus(importHash, status, "Successfully imported image: " + uri.ToString() + " (" + image.ContentType + ")"); } //Create the sitemap and then add the page itself CmsSitePath root = CmsSiteMap.Instance.GetPath(subscriptionId, CmsSiteMap.RootPath); Dictionary<CmsUrl, int> cssUses = new Dictionary<CmsUrl, int>(); Dictionary<CmsUrl, int> jsUses = new Dictionary<CmsUrl, int>(); IList<ImportedItem> pages = NormalizeImport(items[ImportType.Page]); foreach (ImportedItem page in pages) { try { CmsUrl uri = new CmsUrl(page.Uri); CmsUrlWalker walker = new CmsUrlWalker(uri); while (walker.Next()) { String parent = walker.GetParentPath(); String current = walker.GetIndividualPath(); String fullpath = CmsSiteMap.PathCombine(parent, current); int depth = walker.Depth; if (!walker.IsLast) { //Check if the current path exists, if not, create it if (!CmsSiteMap.Instance.Exists(subscriptionId, fullpath)) CmsSiteMap.Instance.AddChildDirectory(subscriptionId, parent, current); } } String pageName = walker.GetIndividualPath(); CmsPage newpage = GetPage(template.Name, subscription.Culture, pageName, message.ReplacePhoneNumbers, page, cssUses, jsUses); newpage.SubscriptionId = subscriptionId.Value; //Add the page to the cms system PageManager.Instance.AddNewPage(walker.GetParentPath(), pageName, newpage); AddStatus(importHash, status, "Successfully imported page " + page.Uri); } catch (Exception ex) { if (!ex.Message.Contains("404")) Logging.Database.Write("import-site-manager", "Failed to import page: " + page.Uri + ", cause:" + ex.Message + ", stack:" + ex.StackTrace); AddStatus(importHash, status, "Failed to import page " + page.Uri + ", Reason:" + ex.Message); } } //Import the css IList<ImportedItem> css = items[ImportType.Css]; int sortOrder = 0; CssManager cssManager = new CssManager(null); cssManager.SubscriptionId = subscriptionId; foreach (ImportedItem item in css) { CmsUrl uri = new CmsUrl(item.Uri); data = SimpleWebClient.GetResponse(uri.ToUri()); cssManager.Save(defaultTheme.ThemeGuid, uri.Path, data, true, 0); cssManager.UpdateSortInfo(defaultTheme, uri.Path, sortOrder++); AddStatus(importHash, status, "Successfully imported css file: " + uri.ToString()); } //Import the javascript IList<ImportedItem> js = items[ImportType.Javascript]; sortOrder = 0; JavascriptManager jsManager = new JavascriptManager(null); jsManager.SubscriptionId = subscriptionId; foreach (ImportedItem item in js) { CmsUrl uri = new CmsUrl(item.Uri); data = SimpleWebClient.GetResponse(uri.ToUri()); jsManager.Save(defaultTheme.ThemeGuid, uri.Path, data, true, 0); jsManager.UpdateSortInfo(defaultTheme, uri.Path, sortOrder++); AddStatus(importHash, status, "Successfully imported javascript file: " + uri.ToString()); } //Import any documents IList<ImportedItem> documents = items[ImportType.Document]; foreach (ImportedItem item in documents) { CmsUrl uri = new CmsUrl(item.Uri); ContentFileUploadImpl handler = new ContentFileUploadImpl(); String filename = uri.Path; if (ContentFileUploadImpl.IsValidFileType(filename)) { data = SimpleWebClient.GetResponse(uri.ToUri()); handler.Save(subscriptionId, data, uri.Path, true); } } AddStatus(importHash, status, "Site import completed successfully at " + UtcDateTime.Now.ToString()); ImportedItemDao dao = new ImportedItemDao(); dao.DeleteAllByImportHash(importHash); return status; }
static void Main(string[] args) { IList<ImportedItem> imports = ImportManager.Instance.GetImportedItems(Data.Hash.New("39815301DDC751A5086141163128A817"))[ImportType.Page]; imports = ImportManager.NormalizeImport(imports); foreach (ImportedItem page in imports) { CmsUrl uri = new CmsUrl(page.Uri); CmsUrlWalker walker = new CmsUrlWalker(uri); while (walker.Next()) { String parent = walker.GetParentPath(); String current = walker.GetIndividualPath(); String fullpath = CmsSiteMap.PathCombine(parent, current); int depth = walker.Depth; if (!walker.IsLast) { //Check if the current path exists, if not, create it //if (!CmsSiteMap.Instance.Exists(subscriptionId, fullpath)) Console.WriteLine("Adding directory " + current + " as child of " + parent); //CmsSiteMap.Instance.AddChildDirectory(subscriptionId, parent, current); } } String pageName = walker.GetIndividualPath(); Console.WriteLine("Adding page:" + pageName + " as child of " + walker.GetParentPath()); } Console.ReadLine(); /* ImportedItem item = new ImportedItem(); item.Uri = "tesT"; item.Expires = DateTime.Now; item.Inserted = DateTime.Now; ImportedItemDao dao = new ImportedItemDao(); using (Transaction tx = new Transaction()) { dao.Save<ImportedItem>(item); tx.Commit(); } */ /* String html = "<img src=\"../images/test.jpg\" /><img src=\"http://www.google.com/image.jpg\" /><img src='images/blah.gif'>"; html = new ImageRewriter("location").Rewrite(html); */ /* GooeyCrawler crawler = new GooeyCrawler(new Uri("http://tribecadentaldesign.com")); crawler.AddPipelineStep(new CssImageProcessor()); crawler.AddPipelineStep(new ConsoleOutputProcessor()); //crawler.AddPipelineStep(new DatabasePersistenceProcessor(Data.Guid.Empty)); crawler.Progress += new EventHandler<Business.Import.Events.CrawlProgressEventArgs>(crawler_Progress); crawler.Crawl(); */ /* CmsUrl url = new CmsUrl("http://www.a123systems.com/Collateral/Templates/English-US/images/topnav_about_on.gif"); CmsUrlWalker walker = new CmsUrlWalker(url); while (walker.Next()) { int depth = walker.Depth; String indivdual = walker.GetIndividualPath(); String path = walker.GetCurrentPath(); Console.WriteLine(walker.GetParentPath() + "," + walker.GetCurrentPath() + "," + depth); } */ /* ImportedItem item = new ImportedItem(); item.Uri = "http://www.a123systems.com/Collateral/Flash/English-US/Animation/bae_pack.html"; CmsUrl uri = new CmsUrl(item.Uri); CmsUrlWalker walker = new CmsUrlWalker(uri); while (walker.Next()) { String parent = walker.GetParentPath(); String current = walker.GetIndividualPath(); String fullpath = CmsSiteMap.PathCombine(parent, current); int depth = walker.Depth; if (!walker.IsLast) { //Check if the current path exists, if not, create it if (!CmsSiteMap.Instance.Exists("99a2a4a3-6748-4155-8bf2-fb781b7d8ccc", fullpath)) CmsSiteMap.Instance.AddChildDirectory("99a2a4a3-6748-4155-8bf2-fb781b7d8ccc", parent, current); } } String pageName = walker.GetIndividualPath(); CmsPage page = ImportManager.Instance.GetPage("copyright.htm", "en-us", "import-template", item); */ /* TwilioClient client = new TwilioClient("ACe6a95690dcdee460400d44ae94e4e637", "707b003f01b09e45d998a487828c8625"); client.SearchAvailableLocalNumbers("123"); */ /* client.PurchasePhoneNumber("816", "http://control.gooeycms.com/twilio-handler.aspx"); */ /* IList<AvailablePhoneNumber> numbers = client.SearchAvailableLocalNumbers("816"); foreach (AvailablePhoneNumber number in numbers) { System.Console.WriteLine(number.FriendName); } IList<AvailablePhoneNumber> numbers2 = client.SearchAvailableTollFreeNumbers(); foreach (AvailablePhoneNumber number in numbers2) { System.Console.WriteLine(number.FriendName); } System.Console.ReadLine(); */ /* GooeyCrawler crawler = new GooeyCrawler(new Uri("http://www.emaildatasource.com/")); crawler.GetSiteMap(); */ /* WebSiteDownloaderOptions options = new WebSiteDownloaderOptions(); options.DownloadUri = new Uri("http://www.firstmgt.com"); options.MaximumLinkDepth = 3; options.StayOnSite = true; WebSiteDownloader downloader = new WebSiteDownloader(options); downloader.Process(); */ /* String test = "\u001FTESTING\u001FTESTING1\u001FTESTING2"; Console.WriteLine(test); String[] items = test.Split('\u001F'); foreach (String item in items) Console.WriteLine(item); Console.ReadLine(); */ /* string test = @" #H1 Header ##H2 Header ###H3 Header ####H4 Header *Hello World* **Hello World2** Link Style 1 [Google][1] Link Style 2 [Google](http://www.google.com ""Title Attribute"") Link Style 3 [Google][google] Link Style 4 http://www.google.com Link Style 5 <http://www.google.com>? [1]: http:/www.google.com ""Title Attribute"" [google]: http://www.google.com ""Title Attribute"" This is a test <*****@*****.**> + Item 1 + Item 2 + Item 3 With Sub Items - Must be tabbed or indented * Sub list again - More content This paragraph is still part of item 3 > This is a blockquote > Blockquote Line 2 > > Newline in the blockquote ![Image Alt Text](http://w3.org/Icons/valid-xhtml10) Testing manual line break{BR} This is a test{BR} [form responseTemplate=""myresponse.tpl"" emailTo=""*****@*****.**"" submitText=""Register""] [table] -------------- <textbox fname> || Hello World --------------- --------------- This is a test || <textarea cols=15 rows=5 comments> ----------------- [/table] [/form] "; MarkdownSharp.Markdown m = new MarkdownSharp.Markdown(); m.AutoHyperlink = true; m.LinkEmails = true; String result = m.Transform(test); Console.WriteLine(test); Console.WriteLine("----------------"); Console.WriteLine(result); Console.ReadLine(); File.WriteAllText("c:\\markup.txt",test + "\r\n----------------\r\n" + result); File.WriteAllText("c:\\markup.html", "<html><head></head><body>" + result + "</body></html>"); } */ }