Overhaul/Update to RegisterURI

Overhaul/Update to RegisterURI, a forum discussion on Jojo CMS. Join us for more discussions on Overhaul/Update to RegisterURI on our Administration (backend and configuration) forum.

Back to Forum Index : Back to Administration (backend and configuration)   RSS
Rick Rick

12 Dec 2013
Posts: 336

For a long time I've been thinking of updating the Jojo::registerURI() system to accept some new parameters so we don't have every "isURI()" function being called on every request.

What if we could register URIs not only against the site root, but against a page class?

Jojo::registerURI(
"jojo_article",
"slug:([a-z0-9\-]+)/action:(rss)",
"jojo_plugin_jojo_article");


Jojo::registerURI(
"jojo_article",
"slug:([a-z0-9\-]+)",
"jojo_plugin_jojo_article");


we could expand that out and specify the function to call...
Jojo::registerURI("jojo_article", "slug:([a-z0-9\-]+)/rss", array("jojo_plugin_jojo_article","comments_rss"));

or default it to the function of the class used earlier in the call...
Jojo::registerURI("jojo_article", "slug:([a-z0-9\-]+)/rss", "comments_rss");

We could even go as far as to add RESTful attributes if we wanted, using another parameter on the end.

The problem with all this is that I haven't needed to use the multi-section/multi-lingual features of Jojo so I don't know how much this will effect it. Also, I don't any edge cases any of you may be using with the current system. I can look through the public repos etc but I don't know what private code I'll break.

Is this something that anyone else is interested in? I'm just sick of writing "isURL()" functions as it seems messy and doing it this way would (as far as I see) tidy a lot of things up.

Any feedback?
Rick Rick

12 Dec 2013
Posts: 336

Maybe I'd pass it through a new Jojo::registerClassURI() function to keep code tidy without breaking historical plugins.
tom

Developer

tom

17 Jan 2014
Posts: 379

Sounds Ok to me but then I'm not sure exactly what it does... would't you still need some mechanism to identify the prefix part of the uri and check whether that prefix belongs to a plugin?

For simple plugins you could probably go back to the old way of doing it whereby you get (or hard code) the prefix(es) and register them directly rather than calling a function. That approach gets messy when you add in section prefixes as well though.

Core has a basic url pattern checker which covers a good chunk of what most plugins need in an isUrl function
if ($uribits = parent::isPluginUrl($uri)) {
$prefix = $uribits['prefix'];
$getvars = $uribits['getvars'];
}
- it could be extended though to make them even simpler by including args for the class and common extras like comment unsubscribes.
Rick Rick

17 Jan 2014
Posts: 336

The idea is that if someone visits "blogs/section/my-post/" then Jojo sees that there's no page with that URL so it finds the deepest page in the URL that works, which may be "blogs/section" then checks if that page's plugin has registered a URI (the second example above) comparing only the remainder of the URL to the registered URI.

I tried using the old way of hard coding, but found that if you have multiple pages using the same plugin then the same one is set as $page for every request to any of them.

I'll look at the core isUrl function and have a play with tweaking it :)
tom

Developer

tom

17 Jan 2014
Posts: 379

The only issue I can see with that approach would be ensuring that cases like blogs/blog-subcategory/my-post/ and blogs/my-parent-category-post work. Sounds like it would still need to pass a check around each plugin to find a matching prefix though, at which point you're kind of back at a isUrl type function?
Rick Rick

17 Jan 2014
Posts: 336

I think my proposed change would handle your use-case. The updated code would do the following...

  • See the URL "blogs/my-parent-category-post"
  • Look for page: "blogs/my-parent-category-post" -> not found, trim the end and try again
  • Look for page: "blogs" -> found, plugin is jojo_article
  • Loop through jojo_article's registered URIs and match them to the stuff trimmed from the URL ("my-parent-category-post")
  • jojo_article route "slug:([a-z0-9\-]+)" matches "my-parent-category-post"
  • Set page as current page ("blogs")
  • Set URI matched data (slug) to the vars system


  • Or see the URL "blogs/blog-subcategory/my-post"
  • Look for page: "blogs/blog-subcategory/my-post" -> not found, trim the end and try again
  • Look for page: "blogs/blog-subcategory" -> found, plugin is jojo_article
  • Loop through jojo_article's registered URIs and match them to the stuff trimmed from the URL ("my-post")
  • jojo_article route "slug:([a-z0-9\-]+)" matches "my-post"
  • Set page as current page ("my-post")
  • Set URI matched data (slug) to the vars system


So far the only issue I can see would be that if you had a post and category with the same URL and parent (Eg if there was a sub category with the URL of "blogs/test" as well as a post with the same URL. The system would show the category (since the page URL matches).

There's already code in there to find the page that matches the most URL segments, though I don't think it was doing what I'm proposing.
tom

Developer

tom

17 Jan 2014
Posts: 379

Sounds good.
As long as it checks/trims for subsection prefixes. And maybe falls back to the current behaviour as a last resort before 404ing. The PDF plugin for example (for converting any given page into a PDF), looks for pdf/ slapped on the front of any normal url request (including those for plugin pages) so it's not going to turn up as a page url with that method.
Rick Rick

17 Jan 2014
Posts: 336

I don't know when I'll get time to start it but I'll do it on a branch for lots of testing and fallback to the old method. I don't do much with sub sections so I'll test everything I can think of and see how I go.

Cheers for the feedback :)
tom

Developer

tom

17 Jan 2014
Posts: 379

The pdf plugin could have a handler page in not-in-menu with url pdf/ I guess, which would then work with that method... there may be other equally odd plugins about though.

In between job hunting, if you need cash flow, don't forget gH has some going for anyone willing to stump up with Jojo documentation
Rick Rick

17 Jan 2014
Posts: 336

I'd still allow for plugins to register for URIs without requiring them to have a page. I'll just have to decide whether to check root based URIs or paged ones first. Each list would be separate but sorted by plugin order.

I thought the docs project was postponed. I might get in touch with them, thanks.
Rick Rick

17 Jan 2014
Posts: 336

I think my new code would also let you use a plugin page as the homepage and the plugins registered URIs would still work.
Back to Forum Index : Back to Administration (backend and configuration)   RSS
You must be logged in to post a reply



You need to Register or Log In before posting on these forums.