Пример #1
0
        public static void CreateSiteMapBaidu(PublishmentSystemInfo publishmentSystemInfo)
        {
            var publishmentSystemUrl = PageUtils.AddProtocolToUrl(publishmentSystemInfo.PublishmentSystemUrl.ToLower());

            var siteMapBuilder = new StringBuilder();

            siteMapBuilder.Append($@"<?xml version=""1.0"" encoding=""GB2312"" ?>
<document>
<webSite>{publishmentSystemUrl}</webSite>
<webMaster>{publishmentSystemInfo.Additional.SiteMapBaiduWebMaster}</webMaster>
<updatePeri>{publishmentSystemInfo.Additional.SiteMapBaiduUpdatePeri}</updatePeri>
");

            var urlArrayList = new ArrayList();

            //内容页
            var nodeIdList = DataProvider.NodeDao.GetNodeIdListByPublishmentSystemId(publishmentSystemInfo.PublishmentSystemId);

            if (nodeIdList != null && nodeIdList.Count > 0)
            {
                foreach (int nodeID in nodeIdList)
                {
                    var nodeInfo      = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeID);
                    var tableStyle    = NodeManager.GetTableStyle(publishmentSystemInfo, nodeInfo);
                    var tableName     = NodeManager.GetTableName(publishmentSystemInfo, nodeInfo);
                    var contentIdList = DataProvider.ContentDao.GetContentIdListChecked(tableName, nodeID, string.Empty);

                    if (contentIdList != null && contentIdList.Count > 0)
                    {
                        foreach (var contentId in contentIdList)
                        {
                            var contentInfo = DataProvider.ContentDao.GetContentInfo(tableStyle, tableName, contentId);
                            var contentUrl  = PageUtils.AddProtocolToUrl(PageUtility.GetContentUrl(publishmentSystemInfo, contentInfo));
                            if (!string.IsNullOrEmpty(contentUrl))
                            {
                                if (urlArrayList.Contains(contentUrl.ToLower()))
                                {
                                    continue;
                                }
                                else
                                {
                                    urlArrayList.Add(contentUrl.ToLower());
                                }
                                if (contentUrl.ToLower().StartsWith(publishmentSystemUrl))
                                {
                                    siteMapBuilder.Append($@"
<item>
    <link><![CDATA[{contentUrl}]]></link>
    <title><![CDATA[{contentInfo.Title}]]></title>
    <text><![CDATA[{StringUtils.StripTags(contentInfo.GetExtendedAttribute(BackgroundContentAttribute.Content))}]]></text>
    <image><![CDATA[{PageUtility.ParseNavigationUrl(publishmentSystemInfo, contentInfo.GetExtendedAttribute(BackgroundContentAttribute.ImageUrl))}]]></image>
    <category><![CDATA[{NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId, contentInfo.NodeId)}]]></category>
    <pubDate>{DateUtils.GetDateAndTimeString(contentInfo.AddDate)}</pubDate>
</item>
");
                                }
                            }
                        }
                    }
                }
            }

            siteMapBuilder.Append(@"
</document>");

            var siteMapPath = PathUtility.MapPath(publishmentSystemInfo, publishmentSystemInfo.Additional.SiteMapBaiduPath);

            FileUtils.WriteText(siteMapPath, ECharset.gb2312, siteMapBuilder.ToString());
        }