Forums / Cotonti / Core Labs / Archive / URL gateway API

Customizable URL patterns in the core

Kilandor
#1137 2008-09-25 03:27
Well I kinda disagree This is a example of my plan.

We already have tons of data already in variables for every single part of the page, you don't even have to do extra query's or anything. So we can use that data with no other impact.

so here is a rough idea-example

if($cfg['customurls'])
{
	$url_data[] = $row['page_id'];
	$url_data[] = $page_alias;
	$url_data[] = $row['page_cat'];
	$url_data[] = $row['page_title'];
	$url_data[] = $cfg['mainurl'];
	// Etc so on, would store like cat/title/alias
	//maybe some others I can't think of atm
	$page_url = sed_url('page', $url_data);
}
else
{
	$page_url = 'blah the custom default url here';
}

function sed_url($area, $data)
{
	global $cfg;
	$url = vsprintf($cfg['customurls'][$area], $data);
	if($cfg['customurls'][$area]['callback'])
	{
		$url = $cfg['customurls'][$area]['callback']($url);
	}
	return $url;
}

Then we only simply need in the config area to list, what value matches. Which is a simple and easy enough task, allowing easy customizablity, a admin only need setup a string themselves like /%1$s/%2$S.html. You could even go so far as to substitute that with like special words /*category*/*title*-*id*.html, although this takes a bit more work, but would make it easier for the user. Also giving them an option to use a custom callback of their own creation, to filter/handle the url how they need.

To me this is the best way above any other to do it, we already have all the data there, all we have to do is push it into an array, and send it in, then everything is done.

And we can still use the masks to generate the mod_rewrite data as need, you have the data format in the mask of whats at each part. Even then if need, we could store whats what in a like hidden config, used by the plugin, or simply hard code what each part is if need be.

You know we could even go so far as to add a sql row, to store pre-generated URLS, only change them if say when something is edited. Just like the HTML cache does[/][/][/][/][/]