Beispiel #1
0
        public static SeoMetaInfo GetSeoMetaInfo(string siteUrl, ECharset charset)
        {
            siteUrl = PageUtils.AddProtocolToUrl(siteUrl);
            var content = WebClientUtils.GetRemoteFileSource(siteUrl, charset);

            return(GetSeoMetaInfo(content));
        }
Beispiel #2
0
        public void GatherUrls_Click(object sender, EventArgs e)
        {
            if (_isFileRule)
            {
                var gatherFileRuleInfo = DataProvider.GatherFileRuleDao.GetGatherFileRuleInfo(_gatherRuleName, PublishmentSystemId);

                var builder = new StringBuilder();
                if (gatherFileRuleInfo.IsToFile == false)
                {
                    var regexTitle          = GatherUtility.GetRegexTitle(gatherFileRuleInfo.ContentTitleStart, gatherFileRuleInfo.ContentTitleEnd);
                    var regexContentExclude = GatherUtility.GetRegexString(gatherFileRuleInfo.ContentExclude);
                    var regexContent        = GatherUtility.GetRegexContent(gatherFileRuleInfo.ContentContentStart, gatherFileRuleInfo.ContentContentEnd);

                    var contentAttributes    = TranslateUtils.StringCollectionToStringList(gatherFileRuleInfo.ContentAttributes);
                    var contentAttributesXML = TranslateUtils.ToNameValueCollection(gatherFileRuleInfo.ContentAttributesXml);

                    var attributes = GatherUtility.GetContentNameValueCollection(gatherFileRuleInfo.Charset, gatherFileRuleInfo.GatherUrl, string.Empty, regexContentExclude, gatherFileRuleInfo.ContentHtmlClearCollection, gatherFileRuleInfo.ContentHtmlClearTagCollection, regexTitle, regexContent, string.Empty, string.Empty, string.Empty, string.Empty, contentAttributes, contentAttributesXML);

                    var styleInfoList = TableStyleManager.GetTableStyleInfoList(ETableStyle.BackgroundContent, PublishmentSystemInfo.AuxiliaryTableForContent, null);
                    foreach (var styleInfo in styleInfoList)
                    {
                        if (string.IsNullOrEmpty(attributes[styleInfo.AttributeName.ToLower()]))
                        {
                            continue;
                        }
                        builder.Append($"{styleInfo.DisplayName}: {attributes[styleInfo.AttributeName.ToLower()]}<br><br>");
                    }
                }
                else
                {
                    try
                    {
                        var fileContent = WebClientUtils.GetRemoteFileSource(gatherFileRuleInfo.GatherUrl, gatherFileRuleInfo.Charset, string.Empty);

                        builder.Append(StringUtils.HtmlEncode(fileContent));
                    }
                    catch (Exception ex)
                    {
                        FailMessage(ex, ex.Message);
                    }
                }

                Content.Text = builder.ToString();
            }
            else
            {
                var gatherUrl      = GatherUrls.SelectedValue;
                var errorBuilder   = new StringBuilder();
                var gatherRuleInfo = DataProvider.GatherRuleDao.GetGatherRuleInfo(_gatherRuleName, PublishmentSystemId);

                var regexUrlInclude = GatherUtility.GetRegexString(gatherRuleInfo.UrlInclude);
                var regexListArea   = GatherUtility.GetRegexArea(gatherRuleInfo.ListAreaStart, gatherRuleInfo.ListAreaEnd);

                var contentUrlArrayList = GatherUtility.GetContentUrls(gatherUrl, gatherRuleInfo.Charset, gatherRuleInfo.CookieString, regexListArea, regexUrlInclude, errorBuilder);

                ContentUrlRepeater.DataSource     = contentUrlArrayList;
                ContentUrlRepeater.ItemDataBound += ContentUrlRepeater_ItemDataBound;
                ContentUrlRepeater.DataBind();

                InfoMessage($"采集名称:{_gatherRuleName}&nbsp;&nbsp;内容数:{contentUrlArrayList.Count}");

                Content.Text = string.Empty;
            }
        }
Beispiel #3
0
        public static bool TryGetOnlineTemplates(out List <Dictionary <string, string> > list)
        {
            list = new List <Dictionary <string, string> >();

            try
            {
                var content = WebClientUtils.GetRemoteFileSource(UrlTemplatesXml, ECharset.utf_8);

                var document = XmlUtils.GetXmlDocument(content);
                var rootNode = XmlUtils.GetXmlNode(document, "//siteTemplates");
                if (rootNode.ChildNodes.Count > 0)
                {
                    foreach (XmlNode node in rootNode.ChildNodes)
                    {
                        var ie           = node.ChildNodes.GetEnumerator();
                        var title        = string.Empty;
                        var description  = string.Empty;
                        var author       = string.Empty;
                        var source       = string.Empty;
                        var lastEditDate = string.Empty;

                        while (ie.MoveNext())
                        {
                            var childNode = (XmlNode)ie.Current;
                            if (childNode == null)
                            {
                                continue;
                            }

                            var nodeName = childNode.Name;
                            if (StringUtils.EqualsIgnoreCase(nodeName, "title"))
                            {
                                title = childNode.InnerText;
                            }
                            else if (StringUtils.EqualsIgnoreCase(nodeName, "description"))
                            {
                                description = childNode.InnerText;
                            }
                            else if (StringUtils.EqualsIgnoreCase(nodeName, "author"))
                            {
                                author = childNode.InnerText;
                            }
                            else if (StringUtils.EqualsIgnoreCase(nodeName, "source"))
                            {
                                source = childNode.InnerText;
                            }
                            else if (StringUtils.EqualsIgnoreCase(nodeName, "lastEditDate"))
                            {
                                lastEditDate = childNode.InnerText;
                            }
                        }

                        if (!string.IsNullOrEmpty(title))
                        {
                            list.Add(new Dictionary <string, string>
                            {
                                ["title"]        = StringUtils.Trim(title),
                                ["description"]  = StringUtils.Trim(description),
                                ["author"]       = StringUtils.Trim(author),
                                ["source"]       = StringUtils.Trim(source),
                                ["lastEditDate"] = StringUtils.Trim(lastEditDate)
                            });
                        }
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #4
0
        protected string GetWeatherHtml(string provider)
        {
            var result = string.Empty;

            try
            {
                var group = "title";
                if (provider == yahoo)
                {
                    var    pinyinCity = TranslateUtils.ToPinYin(City);
                    string weatherUrl = $"http://weather.cn.yahoo.com/weather.html?city={pinyinCity}&s=1";
                    string regex      =
                        $@"<\!--today\s+-->\s+<div\s+class=""dt_c"">\s+<div\s+class=""tn"">{DateTime.Now.Year}-{TranslateUtils
					        .ToTwoCharString(DateTime.Now.Month)}-{TranslateUtils.ToTwoCharString(DateTime.Now.Day)}</div>\s*(?<title>[\s\S]+?)\s*</div>\s+<\!--//today\s+-->"                    ;

                    var content = WebClientUtils.GetRemoteFileSource(weatherUrl, ECharset.utf_8);

                    if (!string.IsNullOrEmpty(content))
                    {
                        content = RegexUtils.GetContent(group, regex, content);

                        var flashRegex         = @"<p>\s*(?<title>[\s\S]+?)\s*</p>";
                        var weatherStringRegex = @"<span\s+class=""ft1"">\s*(?<title>[\s\S]+?)\s*</span>";
                        var highDegreeRegex    = @"<span\s+class=""hitp"">\s*(?<title>[\s\S]+?)\s*</span>";
                        var lowDegreeRegex     = @"<span\s+class=""lotp"">\s*(?<title>[\s\S]+?)\s*</span>";

                        var flashHtml = RegexUtils.GetContent(group, flashRegex, content);
                        flashHtml = flashHtml.Replace("width=\"64\" height=\"64\"", "width=\"20\" height=\"20\"");
                        var weatherString = RegexUtils.GetContent(group, weatherStringRegex, content);
                        var highDegree    = RegexUtils.GetContent(group, highDegreeRegex, content);
                        var lowDegree     = RegexUtils.GetContent(group, lowDegreeRegex, content);

                        if (!string.IsNullOrEmpty(highDegree))
                        {
                            result = flashHtml + weatherString + $"&nbsp;{highDegree} ~ {lowDegree}";
                        }
                    }
                }
                else if (provider == sina)
                {
                    string weatherUrl = $"http://php.weather.sina.com.cn/search.php?city={PageUtils.UrlEncode(City)}";
                    var    regex      = "<td\\s+bgcolor=\\#FEFEFF\\s+height=25\\s+style=\"padding-left:20px;\"\\s+align=center>24小时</td>\\s*(?<title>[\\s\\S]+?)\\s*</tr>";

                    var content = WebClientUtils.GetRemoteFileSource(weatherUrl, ECharset.gb2312);

                    if (!string.IsNullOrEmpty(content))
                    {
                        content = RegexUtils.GetContent(group, regex, content);

                        var contentArrayList = RegexUtils.GetTagInnerContents("td", content);

                        var weatherString = (string)contentArrayList[0];
                        var highDegree    = (string)contentArrayList[1];
                        var lowDegree     = (string)contentArrayList[2];

                        if (!string.IsNullOrEmpty(highDegree))
                        {
                            result = weatherString + $"&nbsp;{highDegree} ~ {lowDegree}";
                        }
                    }
                }
            }
            catch {}

            return(result);
        }
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            if (Body.IsQueryExists("Delete"))
            {
                var siteTemplateDir = Body.GetQueryString("SiteTemplateDir");

                try
                {
                    SiteTemplateManager.Instance.DeleteSiteTemplate(siteTemplateDir);

                    Body.AddAdminLog("删除站点模板", $"站点模板:{siteTemplateDir}");

                    SuccessDeleteMessage();
                }
                catch (Exception ex)
                {
                    FailDeleteMessage(ex);
                }
            }

            _directoryNameLowerList = SiteTemplateManager.Instance.GetDirectoryNameLowerList();

            if (!Page.IsPostBack)
            {
                BreadCrumbSys(AppManager.Sys.LeftMenu.Site, "在线模板下载", AppManager.Sys.Permission.SysSite);

                try
                {
                    var list = new List <Dictionary <string, string> > ();

                    var content = WebClientUtils.GetRemoteFileSource(StringUtils.Constants.UrlMoban, ECharset.utf_8);

                    var document = XmlUtils.GetXmlDocument(content);
                    var rootNode = XmlUtils.GetXmlNode(document, "//siteTemplates");
                    if (rootNode.ChildNodes.Count > 0)
                    {
                        foreach (XmlNode node in rootNode.ChildNodes)
                        {
                            var ie           = node.ChildNodes.GetEnumerator();
                            var templateName = string.Empty;
                            var templateType = string.Empty;
                            var size         = string.Empty;
                            var author       = string.Empty;
                            var uploadDate   = string.Empty;
                            var pageUrl      = string.Empty;
                            var demoUrl      = string.Empty;
                            var downloadUrl  = string.Empty;

                            while (ie.MoveNext())
                            {
                                var childNode = (XmlNode)ie.Current;
                                var nodeName  = childNode.Name;
                                if (StringUtils.EqualsIgnoreCase(nodeName, "templateName"))
                                {
                                    templateName = childNode.InnerText;
                                }
                                else if (StringUtils.EqualsIgnoreCase(nodeName, "templateType"))
                                {
                                    templateType = childNode.InnerText;
                                }
                                else if (StringUtils.EqualsIgnoreCase(nodeName, "size"))
                                {
                                    size = childNode.InnerText;
                                }
                                else if (StringUtils.EqualsIgnoreCase(nodeName, "author"))
                                {
                                    author = childNode.InnerText;
                                }
                                else if (StringUtils.EqualsIgnoreCase(nodeName, "uploadDate"))
                                {
                                    uploadDate = childNode.InnerText;
                                }
                                else if (StringUtils.EqualsIgnoreCase(nodeName, "pageUrl"))
                                {
                                    pageUrl = childNode.InnerText;
                                }
                                else if (StringUtils.EqualsIgnoreCase(nodeName, "demoUrl"))
                                {
                                    demoUrl = childNode.InnerText;
                                }
                                else if (StringUtils.EqualsIgnoreCase(nodeName, "downloadUrl"))
                                {
                                    downloadUrl = childNode.InnerText;
                                }
                            }

                            var directorName = PageUtils.GetFileNameFromUrl(downloadUrl);
                            directorName = directorName.Replace(".zip", string.Empty);

                            list.Add(new Dictionary <string, string>
                            {
                                ["templateName"]  = templateName,
                                ["templateType"]  = templateType,
                                ["size"]          = size,
                                ["author"]        = author,
                                ["uploadDate"]    = uploadDate,
                                ["pageUrl"]       = pageUrl,
                                ["demoUrl"]       = demoUrl,
                                ["downloadUrl"]   = downloadUrl,
                                ["directoryName"] = directorName
                            });
                        }
                    }

                    dgContents.DataSource     = list;
                    dgContents.ItemDataBound += dgContents_ItemDataBound;
                    dgContents.DataBind();
                }
                catch (Exception ex)
                {
                    FailMessage(ex, "在线模板获取失败:页面地址无法访问!");
                }
            }
        }