Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#145 2005-06-18 10:30:08

andreas
Member
Registered: 2004-02-28
Posts: 453
Website

Re: [plugin] [ORPHAN] sgb_url_handler - support all url variations at the same time

I’d also prefer the method Andrew proposes. It would make things cleaner while serving the same purpose as now.

Offline

#146 2005-06-18 23:28:02

sungodbiff
Archived Plugin Author
Registered: 2004-03-23
Posts: 57
Website

Re: [plugin] [ORPHAN] sgb_url_handler - support all url variations at the same time

All -

Dum da da daa! I (finally) got off my lazy butt and completed the next installment in the sordid little affair that is sgb_url_handler.

I’ve updated the download links on my site but haven’t had a chance to update the text. The help within the plugins has been updated (although I may rewrite it for the next release if things aren’t clear).

So, check the links on my site (<a href=“http://mighthitgold.net/sgb_url_handler”>sgb_url_handler</a> and <a href=“http://mighthitgold.net/sgb_error_documents”>sgb_error_documents</a>). I also updated the links on the first post of this tread.

I’ll make a second post going into more details about what’s new later this evening/tomorrow.

Enjoy!

- sgb

Last edited by sungodbiff (2005-06-18 23:29:05)

Offline

#147 2005-06-19 00:35:54

sungodbiff
Archived Plugin Author
Registered: 2004-03-23
Posts: 57
Website

Re: [plugin] [ORPHAN] sgb_url_handler - support all url variations at the same time

Continuing the above post…

All configuration options are made in the function <code>sgb_url_handler_confg()</code>.

Customizable URL Schemes
This is similar to zem_rewrite, I didn’t set out to copy it, but there isn’t really a different way to do it.

Literal words can be put into schemes, e.g. /blog/&#37;section&#37;/&#37;title&#37; would match articles for URLs starting with “blog”. This is useful if you want to set up a redirect or reserve a URL for another plugin/action.

There are 6 keywords relating to TxP posts: &#37;section&#37;, &#37;category&#37;, &#37;title&#37;, &#37;year&#37;, &#37;month&#37;, and &#37;day&#37;. There are also 2 “blank” keywords, &#37;string&#37; and &#37;number&#37;. Lastly, there are 4 locale specific keywords: &#37;_section&#37;, &#37;_category&#37;, &#37;_author&#37;, and &#37;_file&#37;. For English TxP installations these would translate as section, category, author, and file_download, respectively.

It is not necessary to add a trailing slash to these schemes.

All schemes are put into the <code>$schemes</code> array in the configuration function. Schemes should be ordered in the order you wish to satisfy them. Every scheme needs to have a unique scheme name: <code>$schemes[‘scheme_name’] = ‘/&#37;section&#37;/&#37;title&#37;’;</code>. Schemes don’t automatically “flatten” so you’ll need to write a scheme for each “step” e.g. <pre>
$schemes[‘section’] = ‘/&#37;section&#37;’;
$schemes[‘section_category’] = ‘/&#37;section&#37;/&#37;category&#37;’;
$schemes[‘section_category_title’] = ‘/&#37;section&#37;/&#37;category&#37;/&#37;title&#37;’;</pre>

Per-section URL Schemes
It’s now possible to specify different URL schemes for different sections. In the configuration function just add entries to the <code>$sections</code> array e.g. <code>$sections[‘about’] = ‘section_title’;</code> would use the ‘section_title’ scheme for posts in the about section.

The permlink mode set in the TxP admin is the “default” mode, the section specified is the “preferred” mode. If the plugin is configured to send 301s it will use the scheme defined in <code>$sections</code>, if one is set.

Permlink Tag
To write permlinks with the scheme specified in <code>$sections</code> use the tag: <code>&#60;txp:sgb_url_handler_permlink&#62;</code>. This tag will use the URL scheme defined in <code>$sections</code> if there is one, otherwise it defaults to the permlink mode set in the TxP admin. This tag accepts a couple of parameters: <code>section=“some section”</code>, <code>scheme=“some_scheme”</code> and <code>mode=“some_scheme”</code>. Mode and scheme do the same thing, mode is here for compatibility with mic_permlink.

Triggers
Triggers are actions that can be executed instead of the normal TxP article response. Triggers are defined in the configuration function in the <code>$triggers</code> array.

There are a 6 triggers: RSS, ATOM, FILE, REDIRECT, AUTHOR, and NOTHING.

Currently AUTHOR and NOTHING do … nothing. They simply exit and allow sgb_url_handler to pass on the handling to TxP or whatever follows.

REDIRECT allows you to redirect URLs matching a scheme to another location, e.g. <code>$triggers[‘google’] = ‘REDIRECT::http://www.google.com’;</code> would redirect the URL http://example.com/google to http://www.google.com. Future versions will support cooler stuff like taking parts of the URL and passing them as variables in the redirection.

RSS and ATOM execute TxP’s default RSS & Atom feed responses.

FILE executes TxP’s file_download stuff.

Error Handling
To get the most out of the error handling make sure you update sgb_error_documents to version 0.1.2 or higher. sgb_url_handler now supports issuing 301 Permanently Moved headers when <code>$config[‘send_301’]</code> is set to true (it’s false by default).

sgb_url_handler will look at the scheme matched and compare it to the scheme defined for that section (or the permlink mode defined in TxP’s admin) — if the schemes are different than the user is 301-ed to the correct scheme.

If you’re running a site with send_301 enabled, you’ll want to change <code>$config[‘match’]</code> to “exact”, since you won’t really be handling “best” fits any more.

As long as <code>$config[‘send_404’]</code> is set to true, sgb_url_handler will issue 404s when an article is not found. Again, you’ll probably want to set <code>$config[‘match’]</code> to “exact”.

Well that’s the crash-course. I tested this as much as I could, but I’m sure there’ll be issues with some setups — so let me know if you have any problems.

Thanks!

- sgb

Last edited by sungodbiff (2005-06-19 00:44:59)

Offline

#148 2005-06-19 00:39:36

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: [plugin] [ORPHAN] sgb_url_handler - support all url variations at the same time

Oh baby! ;D

Offline

#149 2005-06-19 03:48:07

soulship
Member
From: Always Sunny Charleston
Registered: 2004-04-30
Posts: 669
Website

Re: [plugin] [ORPHAN] sgb_url_handler - support all url variations at the same time

WOW. I won’t know where to begin. Thanks!

Offline

#150 2005-06-19 06:20:48

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: [plugin] [ORPHAN] sgb_url_handler - support all url variations at the same time

very nice indeed

Offline

#151 2005-06-19 06:22:48

andreas
Member
Registered: 2004-02-28
Posts: 453
Website

Re: [plugin] [ORPHAN] sgb_url_handler - support all url variations at the same time

Lovely! That’ll be a lot to try out! Thanks sgb!

Offline

#152 2005-06-19 11:45:17

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [plugin] [ORPHAN] sgb_url_handler - support all url variations at the same time

sungodbiff wrote:
<br />
Error Handling
To get the most out of the error handling make sure you update sgb_error_documents to version 0.1.2 or higher. sgb_url_handler now supports issuing 301 Permanently Moved headers when <code>$config[‘send_301’]</code> is set to true (it’s false by default).
<br />
sgb_url_handler will look at the scheme matched and compare it to the scheme defined for that section (or the permlink mode defined in TxP’s admin) — if the schemes are different than the user is 301-ed to the correct scheme.
<br />
If you’re running a site with send_301 enabled, you’ll want to change <code>$config[‘match’]</code> to “exact”, since you won’t really be handling “best” fits any more.

I must be missing something.
In Admin > Preferences permanent link mode is set to /section/title.
I updated and activated both plugins.
In sgb_error_documents the only thing I changed is this:
<code>

// 404 File Not Found $r[‘error_documents’][‘404’][‘id’] = 242;

</code>
In sgb_url_handler:
<code>

// Defines which mode to match $config[‘match’] = ‘exact’;

// Send 301 redirects? $config[‘send_301’] = 1; // bool

// Send 404 not founds? $config[‘send_404’] = 1; // bool

</code>

What I thought would happen, is this:

1. requested url /section/id/title will be sent to section/title
2. requested non-existing url will be sent to article 242

But:
1. requested url /section/id/title is giving the correct article, but not showing the correct url (still showing /section/id/title instead of /section/title)
2. requested non-existing url is sent to the home page

I’m sure there’s something I’m misunderstanding about this plugin, now if I only knew what…

Offline

#153 2005-06-19 16:05:18

sungodbiff
Archived Plugin Author
Registered: 2004-03-23
Posts: 57
Website

Re: [plugin] [ORPHAN] sgb_url_handler - support all url variations at the same time

doggiez -

You’re right it should work as you described. It worked for me so let me poke around a bit. Make sure you’re using sgb_error_documents 0.1.2 as 0.1.1 does not support 301s.

- sgb

Offline

#154 2005-06-19 16:27:48

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [plugin] [ORPHAN] sgb_url_handler - support all url variations at the same time

> sungodbiff wrote:

> Make sure you’re using sgb_error_documents 0.1.2 as 0.1.1 does not support 301s.

I’m using sgb_error_documents 0.1.2 and sgb_url_handler 0.1.8, just downloaded them today.
Thanks for poking around.

Offline

#155 2005-06-19 19:37:36

sungodbiff
Archived Plugin Author
Registered: 2004-03-23
Posts: 57
Website

Re: [plugin] [ORPHAN] sgb_url_handler - support all url variations at the same time

doggies -

I updated the links in the first post and on my site. The new version is 0.1.8.1. Please let me know if this fixes the problem you were experiencing.

Thanks,

- sgb

Offline

#156 2005-06-19 20:09:40

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [plugin] [ORPHAN] sgb_url_handler - support all url variations at the same time

Unfortunately nothing changed. I’m having doubts if it is the plugin, if it’s working for everyone else.

Some examples: (http://www.doggiez.nl/artikel/project-click is the permlink to my article that has id 240.)

http://www.doggiez.nl/artikel/240/project-click is going to the right article, but the url doesn’t change to the one without id.
http://www.doggiez.nl/artikel/138/project-click (existing id, other article) is going to article 138, but the url again doesn’t change.
http://www.doggiez.nl/artikel/5555/project-click (non-existing id) is going to the home page.
(If I de-activate the plugin all go to the home page).

Am I wrong in assuming that the first two would lead to the requested article, but show the url as set in Preferences: /section/title, and that the third one would lead to my Not Found article?

I can call my 404 article that has id 242 (http://www.doggiez.nl/foutje/niet-gevonden), so I know it’s there, but even something like http://www.doggiez.nl/some-really-nonexisting-url takes me to the home page.

Again, it’s probably something outside the plugin (in my mind for instance…)

[Edit]: by the way it was the same with sgb_url_handler 0.1.5 and sgb_error_documents 0.1.1.

Last edited by doggiez (2005-06-19 20:21:59)

Offline

Board footer

Powered by FluxBB