Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-02-09 15:37:09

redneck
Member
From: Costa Mesa, CA
Registered: 2004-08-14
Posts: 37
Website

Proposal for a simple hyphen-to-underscore plugin

Please let me know if this has been done. I can’t be the only person who wants to see this change (I notice the member Ace of Dubs feels the same way I do).

I have a real problem with Textpattern’s default behavior of, with clean URIs, replacing spaces in article titles with hyphens (also in section names). For fifteen years I have been using underscores for this purpose.

Hyphens are problematic for a couple of reasons. First, e-mail clients tend to use the hyphens to break up long URIs, which makes it difficult for people to access the websites being referenced.

Another problem is that whereas an underscore simply represents a space, a hyphen is real punctuation. For example, the word “AK-47” includes a hyphen in it, so the hyphen should be part of word distinct from a placeholder for a space, eg, ak-47_files makes a lot more sense than ak-47-files.

So today during my walk to work (I love California) I decided to hack into Textpattern to figure out where the hypen is and change it to an underscore. Then after another block, I decided this could be a problem with updates, and so I should do a plugin instead. I’ve never done a plugin before, but I doubt it is rocket science, especially for something as simple as this.

So I was wondering if anyone could help me find the code that needs to be changed in Textpattern. Or let me know if this has already been done. If not, I’ll tackle the plugin.

Offline

#2 2007-02-09 16:06:30

hakjoon
Member
From: Arlington, VA
Registered: 2004-07-29
Posts: 1,634
Website

Re: Proposal for a simple hyphen-to-underscore plugin

The replace happens here

Which calls this function which calls this one which runs the regex.

I don’t think there is any way to intercept just that call but you could setup a plugin to create the url title in $_POST before it gets passed off to article_post() that way it will not get pushed through stripSpace().

There might be better ways too.


Shoving is the answer – pusher robot

Offline

#3 2007-02-09 16:44:14

redneck
Member
From: Costa Mesa, CA
Registered: 2004-08-14
Posts: 37
Website

Re: Proposal for a simple hyphen-to-underscore plugin

Thanks, Patrick.

I agree that it would be cleaner to simply intercept the URL before it runs through the stripSpace() and sanitizeForUrl() filters. I’m not sure how to do that yet, but it shouldn’t be hard.

Can the same technique be used for when Txp automagically changes the IDs of the sections?

Offline

#4 2007-02-09 18:48:33

hakjoon
Member
From: Arlington, VA
Registered: 2004-07-29
Posts: 1,634
Website

Re: Proposal for a simple hyphen-to-underscore plugin

Something like this should get you started.

function register_callback('my_function', 'article', 'publish', '1');

function myfunction() {
   Get url-title and make it match what I want;
}

the 1 makes it run before the built in step is called so you can massage the data that step sees.

Plugin development in Textbook

Can the same technique be used for when Txp automagically changes the IDs of the sections?

I’m not following you here.

Last edited by hakjoon (2007-02-09 18:49:31)


Shoving is the answer – pusher robot

Offline

#5 2007-02-09 18:57:18

redneck
Member
From: Costa Mesa, CA
Registered: 2004-08-14
Posts: 37
Website

Re: Proposal for a simple hyphen-to-underscore plugin

hakjoon wrote:

I’m not following you here.

When you create a section, if the section name you provide (as opposed to the section title) has spaces in it, they are changed to hyphens when the section is saved.

Offline

#6 2007-02-10 00:07:37

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website Mastodon

Re: Proposal for a simple hyphen-to-underscore plugin

You might also consider that the search engine with the larger audience considers hyphens as word delimiters which they don’t for underscores. Just in case you wanted your site to be popular, of course…

Offline

#7 2007-02-10 00:38:30

masa
Member
From: Asturias, Spain
Registered: 2005-11-25
Posts: 1,091

Re: Proposal for a simple hyphen-to-underscore plugin

wet wrote:

You might also consider that the search engine with the larger audience “considers hyphens as word delimiters which they don’t for underscores.

That’s interesting; I had come to suspect that.
Personally I prefer hyphens (dashes) for two reasons:

  • everybody knows how to type a hyphen while far fewer how to type an undescore
  • esthetically a hyphen looks much more pleasing in a string, not like computer lingo

Offline

#8 2007-02-10 15:44:20

redneck
Member
From: Costa Mesa, CA
Registered: 2004-08-14
Posts: 37
Website

Re: Proposal for a simple hyphen-to-underscore plugin

wet wrote:

You might also consider that the search engine with the larger audience considers hyphens as word delimiters which they don’t for underscores. Just in case you wanted your site to be popular, of course…

I’d be worried about this if I thought the URL carried more weight with the seach algorithms than the title, metadata, headers and keywords in the body of the article. I find many, many documents with URLs like www.snord.edu/docs/med099/chap06.html getting good placement in Google for this very reason.

This comment to that post rather reinforced my feelings on the matter:

[A]n underscore has always stood as the replacement for a space in text formats where spaces were not possible. This is because an underscore has no grammatical use, whereas a hyphen does. This convention precedes Google, and the Web in general. … For instance, consider the quandry of Catherine Zeta-Jones. If you are to use hyphens to represent spaces in her name you would write it Catherine-Zeta-Jones. This is ambiguos as the viewer cannot tell if she hyphenates her last name, or if the hyphens are merely space replacement. If you wrote it Catherine_Zeta-Jones it’d be obvious that her last name is hyphenated.

Offline

Board footer

Powered by FluxBB