void url_buildConfig(string url, string content_ = "") { var fc = new FormDataSplitConfig(db, url, content_); fc.OnSubmit += (config, htm, content) => { CmsExtract cms = content.get_CmsExtract(url, config, htm); fc.Close(); }; fc.ShowDialog(); }
private void fillFormCMS(CmsExtract cms) { var data = new Dictionary <string, object>() { { "TITLE", cms.Title }, { "IMG_DEFAULT", cms.ImgDefault }, { "DESCRIPTION", cms.Description }, }; if (DataFieldEvent != null) { DataFieldEvent.BindDataUC(data); } }
public static CmsExtract get_CmsExtract(this string content, string url, CNSPLIT config, string htm) { CmsExtract cms = new CmsExtract(); cms.PLAIN_TEXT = content; string[] a = content.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).Where(x => x != "").ToArray(); if (config.SKIP_LINE_TOP == 1) { cms.Title = a[0]; cms.Description = a[1]; a = a.Where((x, k) => k > 1).ToArray(); } else { cms.Description = a[0]; a = a.Where((x, k) => k > 0).ToArray(); } if (config.SKIP_LINE_BOTTOM == 1) { a = a.Where((x, k) => k != a.Length - 1).ToArray(); } string[] ah = a.Select(x => string.Format("<div class={0}>{1}</div>", (x.Contains("{img") ? "_DIMG" : "_DTEXT"), x)).ToArray(); string _htmContent = string.Join(Environment.NewLine + Environment.NewLine, ah); List <string> listImg = new List <string>(); var ps2 = Regex.Matches(_htmContent, "{img(.+?)img}", RegexOptions.IgnoreCase); foreach (Match mi in ps2) { string img = mi.ToString(), src = img.Substring(4, img.Length - 8); string tag = string.Format(Environment.NewLine + "<p class=_PIMG><img class=\"_IMG\" src=\"{0}\"></p>" + Environment.NewLine, src); _htmContent = _htmContent.Replace(img, tag); listImg.Add(src); } cms.IMG_SRC = listImg.ToArray(); if (listImg.Count > 0) { cms.ImgDefault = listImg[0]; } cms.ContentHtml = _htmContent; return(cms); }
public void addButton_WebCopy() { var b = new ToolStripButton(); b.Image = ___HtmlEditorResource.GetImageIcon("web.gif"); b.ToolTipText = "Copy from URL Website"; b.Click += (se, ev) => { string urc = Clipboard.GetText(TextDataFormat.Text); if (!string.IsNullOrEmpty(urc) && !urc.ToLower().StartsWith("http")) { urc = ""; } var url = Interaction.InputBox("Please enter an site url", "URL", urc, 99, 99); if (!string.IsNullOrEmpty(url)) { // Set cursor as hourglass Cursor.Current = Cursors.WaitCursor; string dom = url.getDomainFromURL(); SearchResult rs = db.FindItemByContainFieldValue(new CNSPLIT() { SITE = dom }, "SITE", 1000, 1); if (rs == null || rs.Total == 0) { var fc = new FormDataSplitConfig(db, url); fc.OnSubmit += (config, htm, content) => { CmsExtract cms = content.get_CmsExtract(url, config, htm); this.Html = cms.ContentHtml; this.cmsExtract = cms; fillFormCMS(cms); fc.Close(); }; fc.ShowDialog(); } else { string Content = url.getContentTextFromURL(); var ls = ((IList)rs.Message).Convert <CNSPLIT>().ToArray(); CNSPLIT config = (CNSPLIT)ls[0]; IndexLine[] a = Content.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).Select(x => x.Trim()).Where(x => x != "").Select((x, k) => new IndexLine(k, x)).ToArray(); //int pLast = a.getIndex(config.TEXT_LAST, -1), pFirst = a.getIndex(config.TEXT_FIRST, pLast); int pLast = a.getIndex(new ConfigItem() { Text = config.TEXT_LAST, SkipLine = config.SKIP_LINE_BOTTOM }, -1), pFirst = a.getIndex(new ConfigItem() { Text = config.TEXT_FIRST, SkipLine = config.SKIP_LINE_TOP }, pLast); if (pFirst == -1 || pLast == -1) { MessageBox.Show("Config wrong, can not find position first or last of data content"); return; } string[] con = a.Where(x => x.Index > pFirst && x.Index < pLast).Select(x => x.Line).ToArray(); string data = string.Join(Environment.NewLine, con); CmsExtract cms = data.get_CmsExtract(url, config, ""); this.Html = cms.ContentHtml; this.cmsExtract = cms; fillFormCMS(cms); } // Set cursor as default arrow Cursor.Current = Cursors.Default; } }; this.AddToolbarItem(b); }