From: Jaben C. <ja...@us...> - 2007-02-08 00:49:12
|
Update of /cvsroot/yafdotnet/yafsrc/classes In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv25495/yafsrc/classes Modified Files: Tag: v1_0_2_NETv2 Config.cs Data.cs Added Files: Tag: v1_0_2_NETv2 URLBuilderRewrite.cs Log Message: updates versions and added new URL Rewriter builder class --- NEW FILE: URLBuilderRewrite.cs --- using System; using System.Data; using System.Collections.Specialized; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; namespace yaf { public class SimpleURLParameterParser { private string _urlParameters = ""; private string _urlAnchor = ""; private NameValueCollection _nameValues = new NameValueCollection(); public SimpleURLParameterParser( string urlParameters ) { _urlParameters = urlParameters; ParseURLParameters(); } private void ParseURLParameters() { string urlTemp = _urlParameters; int index; // get the url end anchor (#blah) if there is one... _urlAnchor = ""; index = urlTemp.LastIndexOf( '#' ); if ( index > 0 ) { // there's an anchor _urlAnchor = urlTemp.Substring( index+1 ); // remove the anchor from the url... urlTemp = urlTemp.Remove( index ); } _nameValues.Clear(); string [] arrayPairs = urlTemp.Split( new char [] { '&' } ); foreach ( string tValue in arrayPairs ) { if ( tValue.Trim().Length > 0 ) { // parse... string [] nvalue = tValue.Trim().Split( new char [] { '=' } ); _nameValues.Add( nvalue [0], nvalue [1] ); } } } public string Anchor { get { return _urlAnchor; } } public bool HasAnchor { get { return ( _urlAnchor != "" ); } } public NameValueCollection Parameters { get { return _nameValues; } } public int Count { get { return _nameValues.Count; } } public string this[string name] { get { return _nameValues[name]; } } public string this [int index] { get { return _nameValues [index]; } } } public class RewriteUrlBuilder : yaf.IUrlBuilder { public string BuildUrl( string url ) { string scriptname = HttpContext.Current.Request.ServerVariables ["SCRIPT_NAME"].ToLower(); string newURL = string.Format( "{0}?{1}", scriptname, url ); if ( scriptname.EndsWith("default.aspx") ) { string before = scriptname.Remove( scriptname.LastIndexOf( "default.aspx" ) ); SimpleURLParameterParser parser = new SimpleURLParameterParser( url ); // create "rewritten" url... newURL = before; string useKey = ""; string pageName = parser ["g"]; bool showKey = false; switch (parser["g"]) { case "topics": useKey = "f"; break; case "posts": if ( parser ["t"] != null ) { useKey = "t"; pageName += "bytopic"; } else if ( parser ["m"] != null ) { useKey = "m"; pageName += "bymessage"; } break; case "profile": useKey = "u"; break; case "forum": if ( parser ["c"] != null ) useKey = "c"; break; } newURL += pageName; if (useKey.Length > 0) { if ( !showKey ) newURL += parser [useKey]; else newURL += useKey + parser [useKey]; } newURL += ".aspx"; string restURL = ""; bool bFirst = true; // create url parameters... for ( int i = 0; i < parser.Count; i++ ) { string key = parser.Parameters.Keys [i].ToLower(); string value = parser[i]; if ( key != "g" && key != useKey ) { if (bFirst) bFirst = false; else restURL += "&"; restURL += key + "=" + value; } } // append to the url if there are additional (unsupported) parameters if ( restURL.Length > 0 ) { newURL += "?" + restURL; } // add anchor if ( parser.HasAnchor ) newURL += "#" + parser.Anchor; } return newURL; } } } Index: Config.cs =================================================================== RCS file: /cvsroot/yafdotnet/yafsrc/classes/Attic/Config.cs,v retrieving revision 1.8.2.3 retrieving revision 1.8.2.4 diff -C2 -d -r1.8.2.3 -r1.8.2.4 *** Config.cs 24 Sep 2006 13:09:14 -0000 1.8.2.3 --- Config.cs 8 Feb 2007 00:49:08 -0000 1.8.2.4 *************** *** 67,70 **** --- 67,78 ---- } + static public string EnableURLRewriting + { + get + { + return configSection ["enableurlrewriting"]; + } + } + static public string UploadDir { *************** *** 145,148 **** --- 153,160 ---- urlAssembly = "Portal.UrlBuilder,Portal"; } + else if ( EnableURLRewriting == "true" ) + { + urlAssembly = "yaf.RewriteUrlBuilder,yaf"; + } else { Index: Data.cs =================================================================== RCS file: /cvsroot/yafdotnet/yafsrc/classes/Attic/Data.cs,v retrieving revision 1.80.2.13 retrieving revision 1.80.2.14 diff -C2 -d -r1.80.2.13 -r1.80.2.14 *** Data.cs 10 Oct 2006 13:06:26 -0000 1.80.2.13 --- Data.cs 8 Feb 2007 00:49:08 -0000 1.80.2.14 *************** *** 343,347 **** get { ! return 21; } } --- 343,347 ---- get { ! return 22; } } *************** *** 350,354 **** get { ! return 0x01090000; } } --- 350,354 ---- get { ! return 0x01090100; } } *************** *** 357,361 **** get { ! return new DateTime( 2006, 10, 10 ); } } --- 357,361 ---- get { ! return new DateTime( 2007, 02, 07 ); } } |