[development] strange inconsistency: 'custom_url_rewrite'

Larry Garfield larry at garfieldtech.com
Tue Dec 27 19:35:47 UTC 2005


On Tuesday 27 December 2005 10:10 am, Gabor Hojtsy wrote:
> > The performance concern is real, though, given the number of links a
> > typical page has.  Some fast, well-cached module-based rewrite mechanism
> > is needed, I agree.  Perhaps just prefix-based?  I've been trying to
> > avoid proposing anything at this point, though, as any changes now would
> > just slow down the release of 4.7. :-)
>
> Speaking of users, these are quite easy to do these in regexps. This is
> an edited excerpt from the weblabor.hu aliasing code (generates
> Hungarian URLs):
>
> $userautoalias = array(
>   ''                       => '',
>   '/edit'                  => '/szerkesztes',
>   '/track'                 => '/kovetes',
>   '/track/navigation'      => '/kovetes/navigacio',
>   '/contact'               => '/kapcsolat',
> );
>
> if (preg_match("!^user/(\\d+)(.*)$!", $path, $match)) {
>   if (isset($userautoalias[$match[2]])) {
>     return 'tagok/' . $match[1] . $userautoalias[$match[2]];
>   }
> }
>
> This is all it takes to convert user/1234/track to tagok/1234/kovetes.
> User names can be similarly done, given that you either query the
> database for the name, or have it cached somewhere.
>
> Goba

Hm.  I hadn't thought of internationalization.  I was thinking something like 
where the user module could map URL prefixes, that way all user-extending 
modules would work as well without having to be individually changed.  Eg, 
for incoming URLs the user module would grab /user/ as a prefix, read the 
second parameter, and if it's a string translate it to the corresponding int 
via a single db hit (SELECT uid FROM users WHERE username='%s').  Then all 
other modules just see the numeric version, just as they do now with 
url_alias.

On outgoing, l() would again check for any prefix and translate the other way.  
Add caching or flavor where necessary.

The same mechanism would allow for a node to also have /nodetype/label 
or /nodetype/class/label URLs, and all actions (view, edit, etc.) would still 
work properly because by the time other modules see it, it's already been 
translated back down to /node/id# as now.

I suppose that could still work with internationalization if you just throw 
some t() calls into it.

<waits for someone to tell him why that is dumb>

-- 
Larry Garfield			AIM: LOLG42
larry at garfieldtech.com		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson


More information about the development mailing list