From: Jaben C. <ja...@us...> - 2007-03-20 08:59:14
|
Update of /cvsroot/yafdotnet/yafsrc/classes In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv4832/yafsrc/classes Modified Files: Tag: v1_0_2_NETv2 URLBuilderRewrite.cs Utils.cs Log Message: Refined URL rewriting added search-engine friendly pagination stuff. Index: URLBuilderRewrite.cs =================================================================== RCS file: /cvsroot/yafdotnet/yafsrc/classes/Attic/URLBuilderRewrite.cs,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** URLBuilderRewrite.cs 8 Feb 2007 00:49:08 -0000 1.1.2.1 --- URLBuilderRewrite.cs 20 Mar 2007 08:58:18 -0000 1.1.2.2 *************** *** 12,108 **** 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 { --- 12,15 ---- *************** *** 112,118 **** 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 ); --- 19,25 ---- string newURL = string.Format( "{0}?{1}", scriptname, url ); ! if ( scriptname.EndsWith(".aspx") ) { ! string before = ""; SimpleURLParameterParser parser = new SimpleURLParameterParser( url ); *************** *** 123,126 **** --- 30,34 ---- string useKey = ""; string pageName = parser ["g"]; + string pageNameExtension = string.Empty; bool showKey = false; *************** *** 131,134 **** --- 39,52 ---- if ( parser ["t"] != null ) { useKey = "t"; pageName += "bytopic"; } else if ( parser ["m"] != null ) { useKey = "m"; pageName += "bymessage"; } + if ( parser ["p"] != null ) + { + int page = Convert.ToInt32( parser ["p"] ); + if ( page != 1 ) + { + pageNameExtension = "--p" + page.ToString(); + } + // remove the page + parser.Parameters.Remove( "p" ); + } break; case "profile": useKey = "u"; break; *************** *** 140,144 **** newURL += pageName; ! if (useKey.Length > 0) { if ( !showKey ) --- 58,62 ---- newURL += pageName; ! if ( useKey.Length > 0 ) { if ( !showKey ) *************** *** 148,168 **** } ! 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 --- 66,74 ---- } ! if ( pageNameExtension != string.Empty ) newURL += pageNameExtension; ! newURL += ".aspx"; ! string restURL = parser.CreateQueryString( new string [] { "g", useKey } ); // append to the url if there are additional (unsupported) parameters Index: Utils.cs =================================================================== RCS file: /cvsroot/yafdotnet/yafsrc/classes/Attic/Utils.cs,v retrieving revision 1.34.2.6 retrieving revision 1.34.2.7 diff -C2 -d -r1.34.2.6 -r1.34.2.7 *** Utils.cs 9 Oct 2006 12:42:25 -0000 1.34.2.6 --- Utils.cs 20 Mar 2007 08:58:18 -0000 1.34.2.7 *************** *** 374,376 **** --- 374,497 ---- } } + + 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 CreateQueryString(string [] excludeValues) + { + string queryString = ""; + bool bFirst = true; + + for ( int i = 0; i < _nameValues.Count; i++ ) + { + string key = _nameValues.Keys [i].ToLower(); + string value = _nameValues [i]; + if ( !KeyInsideArray(excludeValues,key) ) + { + if ( bFirst ) bFirst = false; + else queryString += "&"; + queryString += key + "=" + value; + } + } + + return queryString; + } + + private bool KeyInsideArray( string [] array, string key ) + { + foreach ( string tmp in array ) + { + if ( tmp.Equals( key ) ) return true; + } + return false; + } + + 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]; + } + } + } } |