registerURI replaces parsepage.inc.php (now deprecated) as of the beta1 release.
Capturing URIs - program flowAll page requests in Jojo are send to index.php - index.php must decide which plugin to send the request to for processing.
Jojo will work through all installed plugins until a plugin indicates that it wants control of the request.
If no plugin wants the request, Jojo will try to match against a page in the database. If no match is found, a 404 error is returned.
Do I need to capture URIs?If your plugin needs a special URL format, and is spread across several pages, it probably needs this.
The following standard plugins, amongst others, make use of this feature.
jojo_gallery3The gallery3 plugin uses custom URIs in the following format.
As you can see, 2 formats of URI are acceptable for this plugin. The first is an example of basic formating which we will discuss in a moment, it includes a galleryid (34). The second format is especially coded in the plugin to work.
The plugin needs to register the URI format with Jojo so it can take control of any requests that come to these URIs. This is done with the plugins api.php
Call Jojo::registerUri with 2 arguments. The first is the format you wish to capture, and the second is the plugin class to send the request to.
The above example demonstrates 3 different parts to make up the URI, separated by a forward slash "/".
Match a URI starting with "gallery" literally.
Then, match an integer (0-9). If a match is made, save the value into a GET variable, $_GET['id'].
Then, match a string, being alphanumeric characters, dashes and underscores. Matches will not be made on spaces or other special characters. Because no variable name was specified, not GET variable will be set. In this case, the string is not required for the plugin to work.
- "string" means alphanumeric characters, dashes and underscores.
- "integer" means characters 0-9 only.
- "phrase" means alphanumeric characters, dashes and underscores, and spaces.
- Anything else is considered to be a regular expression or regex. These can be as complicated as you need the to be. We use RegexBuddy to make dealing with Regexes easier (aff).
Complex exampleOur Google Verification plugin makes use of a regex to match against URIs such as google487f41eac1c4595a.html - the format for Google's webmaster tools verification file.
This will match a URI starting with "google" then 16 characters of hexadecimal, followed by ".html". If a match is made, $_GET['filename'] is set so the plugin can access the name of the file that was matched.