using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Web; using System.Xml; using YAF.Classes.Data; using YAF.Core; using YAF.Types.Constants; using YAF.Utils; namespace YAF { public class SitemapHandler : IHttpHandler { protected enum ChangeFrequency { always, hourly, daily, weekly, monthly, yearly, never } #region IHttpHandler Members public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { if (context.Request.UrlReferrer == null || !context.Request.UrlReferrer.AbsoluteUri.Contains(BaseUrlBuilder.BaseUrl)) return; using (TextWriter textWriter = new StreamWriter(context.Response.OutputStream, System.Text.Encoding.UTF8)) { var writer = new XmlTextWriter(textWriter) {Formatting = Formatting.Indented}; writer.WriteStartDocument(); writer.WriteStartElement("urlset"); writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9"); writer.WriteAttributeString("xmlns:image", "http://www.google.com/schemas/sitemap-image/1.1"); writer.WriteAttributeString("xmlns:video", "http://www.google.com/schemas/sitemap-video/1.1"); // Add home page writer.WriteStartElement("url"); writer.WriteElementString("loc", "http://forum.yetanotherforum.net/"); writer.WriteElementString("lastmod", DateTime.Now.ToString("yyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)); writer.WriteElementString("changefreq", ChangeFrequency.always.ToString()); writer.WriteElementString("priority", "0.8"); writer.WriteEndElement(); // url // Forums here 1- boardid, 10 - a number of forum links. var dt = LegacyDb.forum_simplelist(1,10); foreach (DataRow drow in dt.Rows) { writer.WriteStartElement("url"); writer.WriteElementString("loc", YafBuildLink.GetLinkNotEscaped(ForumPages.topics, true, "f={0}", drow["ForumID"] )); writer.WriteElementString("lastmod", DateTime.Now.ToString("yyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)); writer.WriteElementString("changefreq", ChangeFrequency.always.ToString()); writer.WriteElementString("priority", "0.8"); writer.WriteEndElement(); // url } writer.WriteEndElement(); // urlset } context.Response.ContentType = "text/xml"; } #endregion } }
The YAF.NET Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies. More Details Close
The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.
www.yetanotherforum.net