コード例 #1
0
        public static string GetFileHtmlWithoutCount(SiteInfo siteInfo, string fileUrl, NameValueCollection attributes, string innerHtml, bool isStlEntity, bool isLower, bool isUpper)
        {
            if (siteInfo == null || string.IsNullOrEmpty(fileUrl))
            {
                return(string.Empty);
            }

            string retVal;

            if (isStlEntity)
            {
                retVal = PageUtility.ParseNavigationUrl(siteInfo, fileUrl, true);
            }
            else
            {
                var stlAnchor = new HtmlAnchor();
                ControlUtils.AddAttributesIfNotExists(stlAnchor, attributes);
                stlAnchor.HRef      = ApiRouteActionsDownload.GetUrl(siteInfo.Additional.ApiUrl, siteInfo.Id, fileUrl);
                stlAnchor.InnerHtml = string.IsNullOrEmpty(innerHtml) ? PageUtils.GetFileNameFromUrl(fileUrl) : innerHtml;

                if (isLower)
                {
                    stlAnchor.InnerHtml = stlAnchor.InnerHtml.ToLower();
                }
                if (isUpper)
                {
                    stlAnchor.InnerHtml = stlAnchor.InnerHtml.ToUpper();
                }

                retVal = ControlUtils.GetControlRenderHtml(stlAnchor);
            }

            return(retVal);
        }
コード例 #2
0
        public static string GetImageOrFlashHtml(PublishmentSystemInfo publishmentSystemInfo, string imageUrl, StringDictionary attributes, bool isStlEntity)
        {
            var retval = string.Empty;

            if (!string.IsNullOrEmpty(imageUrl))
            {
                imageUrl = PageUtility.ParseNavigationUrl(publishmentSystemInfo, imageUrl);
                if (isStlEntity)
                {
                    retval = imageUrl;
                }
                else
                {
                    if (!imageUrl.ToUpper().Trim().EndsWith(".SWF"))
                    {
                        var htmlImage = new HtmlImage();
                        ControlUtils.AddAttributesIfNotExists(htmlImage, attributes);
                        htmlImage.Src = imageUrl;
                        retval        = ControlUtils.GetControlRenderHtml(htmlImage);
                    }
                    else
                    {
                        var width  = 100;
                        var height = 100;
                        if (attributes != null)
                        {
                            if (!string.IsNullOrEmpty(attributes["width"]))
                            {
                                try
                                {
                                    width = int.Parse(attributes["width"]);
                                }
                                catch { }
                            }
                            if (!string.IsNullOrEmpty(attributes["height"]))
                            {
                                try
                                {
                                    height = int.Parse(attributes["height"]);
                                }
                                catch { }
                            }
                        }
                        retval = $@"
<object classid=""clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"" codebase=""http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"" width=""{width}"" height=""{height}"">
                <param name=""movie"" value=""{imageUrl}"">
                <param name=""quality"" value=""high"">
                <param name=""wmode"" value=""transparent"">
                <embed src=""{imageUrl}"" width=""{width}"" height=""{height}"" quality=""high"" pluginspage=""http://www.macromedia.com/go/getflashplayer"" type=""application/x-shockwave-flash"" wmode=""transparent""></embed></object>
";
                    }
                }
            }
            return(retval);
        }
コード例 #3
0
        public static string GetVideoHtml(PublishmentSystemInfo publishmentSystemInfo, string videoUrl, StringDictionary attributes, bool isStlEntity)
        {
            var retval = string.Empty;

            if (!string.IsNullOrEmpty(videoUrl))
            {
                videoUrl = PageUtility.ParseNavigationUrl(publishmentSystemInfo, videoUrl);
                if (isStlEntity)
                {
                    retval = videoUrl;
                }
                else
                {
                    retval = $@"
<embed src=""{SiteFilesAssets.GetUrl(publishmentSystemInfo.Additional.ApiUrl, SiteFilesAssets.BrPlayer.Swf)}"" allowfullscreen=""true"" flashvars=""controlbar=over&autostart={true
                        .ToString().ToLower()}&image={string.Empty}&file={videoUrl}"" width=""{450}"" height=""{350}""/>
";
                }
            }
            return(retval);
        }
コード例 #4
0
        public static string GetSpecialUrl(SiteInfo siteInfo, string url)
        {
            var virtualPath = PageUtils.RemoveFileNameFromUrl(url);

            return(PageUtility.ParseNavigationUrl(siteInfo, virtualPath, false));
        }
コード例 #5
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());
        }
コード例 #6
0
        public static void CreateSiteMapGoogle(PublishmentSystemInfo publishmentSystemInfo)
        {
            var totalNum = DataProvider.NodeDao.GetContentNumByPublishmentSystemId(publishmentSystemInfo.PublishmentSystemId);

            if (totalNum == 0 || totalNum <= publishmentSystemInfo.Additional.SiteMapGooglePageCount)
            {
                var siteMapBuilder = new StringBuilder();
                siteMapBuilder.Append(siteMapGoogleHead);

                var urlFormat    = publishmentSystemInfo.Additional.SiteMapGoogleIsShowLastModified ? siteMapGoogleUrlWithLastModifiedFotmat : siteMapGoogleUrlFotmat;
                var lastmode     = DateUtils.GetDateString(DateTime.Now);
                var urlArrayList = new ArrayList();
                //首页
                var publishmentSystemUrl = PageUtils.AddProtocolToUrl(publishmentSystemInfo.PublishmentSystemUrl.ToLower());
                siteMapBuilder.AppendFormat(urlFormat, publishmentSystemUrl, "1.0", publishmentSystemInfo.Additional.SiteMapGoogleChangeFrequency, lastmode);

                //栏目页
                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 channelUrl = PageUtils.AddProtocolToUrl(PageUtility.GetChannelUrl(publishmentSystemInfo, nodeInfo));
                        if (!string.IsNullOrEmpty(channelUrl))
                        {
                            if (urlArrayList.Contains(channelUrl.ToLower()))
                            {
                                continue;
                            }
                            else
                            {
                                urlArrayList.Add(channelUrl.ToLower());
                            }
                            if (channelUrl.ToLower().StartsWith(publishmentSystemUrl))
                            {
                                siteMapBuilder.AppendFormat(urlFormat, channelUrl, "0.8", publishmentSystemInfo.Additional.SiteMapGoogleChangeFrequency, lastmode);
                            }
                        }
                    }
                }

                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.AppendFormat(urlFormat, contentUrl, "0.5", publishmentSystemInfo.Additional.SiteMapGoogleChangeFrequency, lastmode);
                                    }
                                }
                            }
                        }
                    }
                }

                siteMapBuilder.Append(siteMapGoogleFoot);

                var siteMapPath = PathUtility.MapPath(publishmentSystemInfo, publishmentSystemInfo.Additional.SiteMapGooglePath);
                FileUtils.WriteText(siteMapPath, ECharset.utf_8, siteMapBuilder.ToString());
            }
            else
            {
                var nodeIdList = DataProvider.NodeDao.GetNodeIdListByPublishmentSystemId(publishmentSystemInfo.PublishmentSystemId);
                var nodeIDWithContentIDArrayList = new ArrayList();

                if (nodeIdList != null && nodeIdList.Count > 0)
                {
                    foreach (int nodeID in nodeIdList)
                    {
                        var nodeInfo  = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeID);
                        var tableName = NodeManager.GetTableName(publishmentSystemInfo, nodeInfo);
                        var idList    = DataProvider.ContentDao.GetContentIdListChecked(tableName, nodeID, string.Empty);
                        foreach (var contentId in idList)
                        {
                            nodeIDWithContentIDArrayList.Add($"{nodeID}_{contentId}");
                        }
                    }
                }

                var deci  = (double)nodeIDWithContentIDArrayList.Count / publishmentSystemInfo.Additional.SiteMapGooglePageCount;
                var count = Convert.ToInt32(Math.Ceiling(deci));
                var siteMapIndexBuilder = new StringBuilder();

                var siteMapGooglePath = publishmentSystemInfo.Additional.SiteMapGooglePath.ToLower();
                var ext = PageUtils.GetExtensionFromUrl(siteMapGooglePath);

                var urlFormat            = publishmentSystemInfo.Additional.SiteMapGoogleIsShowLastModified ? siteMapGoogleUrlWithLastModifiedFotmat : siteMapGoogleUrlFotmat;
                var lastmode             = DateUtils.GetDateString(DateTime.Now);
                var publishmentSystemUrl = PageUtils.AddProtocolToUrl(publishmentSystemInfo.PublishmentSystemUrl.ToLower());

                for (var i = 1; i <= count; i++)
                {
                    var virtualPath = StringUtils.InsertBefore(ext, siteMapGooglePath, i.ToString());

                    siteMapIndexBuilder.Append($@"
  <sitemap>
    <loc>{PageUtility.ParseNavigationUrl(publishmentSystemInfo, virtualPath)}</loc>
    <lastmod>{DateUtils.GetDateString(DateTime.Now)}</lastmod>
  </sitemap>
");

                    var siteMapBuilder = new StringBuilder();
                    siteMapBuilder.Append(siteMapGoogleHead);
                    var urlArrayList = new ArrayList();

                    if (i == 1)
                    {
                        //首页
                        siteMapBuilder.AppendFormat(urlFormat, publishmentSystemUrl, "1.0", publishmentSystemInfo.Additional.SiteMapGoogleChangeFrequency, lastmode);

                        //栏目页
                        if (nodeIdList != null && nodeIdList.Count > 0)
                        {
                            foreach (int nodeID in nodeIdList)
                            {
                                var nodeInfo   = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeID);
                                var channelUrl = PageUtils.AddProtocolToUrl(PageUtility.GetChannelUrl(publishmentSystemInfo, nodeInfo));
                                if (!string.IsNullOrEmpty(channelUrl))
                                {
                                    if (urlArrayList.Contains(channelUrl.ToLower()))
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        urlArrayList.Add(channelUrl.ToLower());
                                    }
                                    if (channelUrl.ToLower().StartsWith(publishmentSystemUrl))
                                    {
                                        siteMapBuilder.AppendFormat(urlFormat, channelUrl, "0.8", publishmentSystemInfo.Additional.SiteMapGoogleChangeFrequency, lastmode);
                                    }
                                }
                            }
                        }
                    }

                    var pageCount = publishmentSystemInfo.Additional.SiteMapGooglePageCount;
                    if (i == count)
                    {
                        pageCount = nodeIDWithContentIDArrayList.Count - (count - 1) * publishmentSystemInfo.Additional.SiteMapGooglePageCount;
                    }
                    var pageNodeIDWithContentIDArrayList = nodeIDWithContentIDArrayList.GetRange((i - 1) * publishmentSystemInfo.Additional.SiteMapGooglePageCount, pageCount);

                    //内容页
                    foreach (string nodeIDWithContentID in pageNodeIDWithContentIDArrayList)
                    {
                        var nodeID    = TranslateUtils.ToInt(nodeIDWithContentID.Split('_')[0]);
                        var contentID = TranslateUtils.ToInt(nodeIDWithContentID.Split('_')[1]);

                        var nodeInfo    = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeID);
                        var tableStyle  = NodeManager.GetTableStyle(publishmentSystemInfo, nodeInfo);
                        var tableName   = NodeManager.GetTableName(publishmentSystemInfo, nodeInfo);
                        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.AppendFormat(urlFormat, contentUrl, "0.5", publishmentSystemInfo.Additional.SiteMapGoogleChangeFrequency, lastmode);
                            }
                        }
                    }

                    siteMapBuilder.Append(siteMapGoogleFoot);

                    var siteMapPagePath = PathUtility.MapPath(publishmentSystemInfo, virtualPath);
                    FileUtils.WriteText(siteMapPagePath, ECharset.utf_8, siteMapBuilder.ToString());
                }

                string sitemapIndexString = $@"
<?xml version=""1.0"" encoding=""UTF-8""?>
<sitemapindex xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:schemaLocation=""http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd"">
{siteMapIndexBuilder.ToString()}
</sitemapindex>
";

                var siteMapPath = PathUtility.MapPath(publishmentSystemInfo, publishmentSystemInfo.Additional.SiteMapGooglePath);
                FileUtils.WriteText(siteMapPath, ECharset.utf_8, sitemapIndexString);
            }
        }