Element Browsing Plug-in

18 views
Skip to first unread message

kevin.reiss

unread,
Nov 22, 2009, 3:39:24 PM11/22/09
to Omeka Dev
I'm trying to think of an effective strategy for creating a plug-in to
add some new browsing features to Omeka. and was wondering if anyone
else on the list has thought about this. Our Omeka project [http://
nycdigital.org/dmetro/] has a detailed Dublin core taxonomy that we'd
like to highlight by:

1. Create clean URLs (similar to what Wordpress does with the category
construct). It is possible to build hyperlinks for this content on the
fly by manipulating element ID values and the Omeka advanced searching
options in the following fashion:

http://nycdigital.org/dmetro/items/browse?search=&advanced[0][element_id]=51&advanced[0][type]=contains&advanced[0][terms]=Sound%20recordings&range=&collection=&type=&tags=&submit_search=Search

We'd rather produce URLs that follow the convention:
http://nycdigital.org/dmetro/items/browse/format/sound+recordings/

Would the best way to do this be to create a new controller that could
populate views of item content based on the requested element name and
value? Does this seem possible without having alter the .htaccess
rules that come standard with omeka.

2. Once the system can handle these clean URLs we want to create an
admin screen for the plug-in where site managers can select the
elements that they want to users to be able to address with this style
of URL and be part of a theme's browsing structure. That would happen
by some custom plug-in functions that would build a navigational
structure that utilzes the elements that are designated for browsing
in the plug-in admin menu.

Is there any existing plug-in work that might have already tried to
address this? Thanks in advance for any comments or ideas on this sort
of effort.

Kris Kelly

unread,
Nov 24, 2009, 10:41:47 AM11/24/09
to omek...@googlegroups.com
It seems like the easiest way to create custom URLs in this case would
be to add some new routes, which is easily done via a plugin,
specifically the 'define_routes' hook. That hook receives the Zend
Framework router as the first argument, so you can do something like
the following:

add_plugin_hook('define_routes', 'my_routes_definition');

function my_routes_definition($router)
{
// define routes here.
}

Here is the Zend documentation on routes: http://framework.zend.com/manual/en/zend.controller.router.html

I don't think you'll need to create a new controller for this, most
likely you can just create a route like "/items/browse/format/foobar/"
that just converts into something like "/items/browse/?advanced[0]
[element_id]=51&advanced[0][terms]=foobar", or at least it seems like
it should be possible to do that.

As far as managing it via the admin, it should be pretty easy to add a
plugin configuration page that toggles any of these routes with a form
containing a series of checkboxes.

Hope that helps.

Kris
> --
>
> You received this message because you are subscribed to the Google
> Groups "Omeka Dev" group.
> To post to this group, send email to omek...@googlegroups.com.
> To unsubscribe from this group, send email to omeka-dev+...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/omeka-dev?hl=
> .
>
>

kevin.reiss

unread,
Nov 29, 2009, 1:42:20 PM11/29/09
to Omeka Dev
Thanks for the response. Do I need to create a new "browse_items" hook
for the plugin in order for the route to fire and collection current
parameter values in the URL? I've been experimenting with defining
"default" values for the routes just to see if it will work but didn't
have much luck probably because I missing the right way to make Omeka
aware of my test route definitions. Any ideas on how to get the route
properly registered within Omeka? Thanks,

Kevin

Here is an example of what I'm trying to do:

function metadata_browser_route() {

// create new router for plugin
$router = new Zend_Controller_Router_Rewrite();

// route goal is convert the following style URL:
//
//http://nycdigital.org/nycbeta/items/browse?advanced[0][element_id]
=51&advanced[0][type]=contains&advanced[0][terms]
=photographs&submit_search=Search
//
// into something that looks like:
//
// http://nycdigital.org/nycbeta/items/browse/51/contains/photographs/Search
// were 51 is the format element type ID
// and "photographs" is a format element values
$route = new Zend_Controller_Router_Route(
'items/browse/:advanced[0][element_id]/:advanced[0][type]/:advanced
[0][terms]/:submit_action',
array(
'controller' => 'items',
'action' => 'browse',
'advanced[0][element_id]' => '51',
'advanced[0][type]' => 'contains',
'advanced[0][terms]' => 'photographs',
'submit_search' => 'Search'
)
);
$router->addRoute('formats', $route);

}

function metadata_browser_browse_items() {

// need to activate "formats" route defined in the previous
function
metadata_browser_route();

Kris Kelly

unread,
Nov 29, 2009, 2:05:57 PM11/29/09
to omek...@googlegroups.com
Hi,

You won't be able to use the 'browse_items' hook to modify your
routes, because routes are loaded / matched way back at the beginning
of the request. The Zend Framework site has a ton of documentation on
their particular implementation of MVC, but the basic gist is that
routing is one of the first things that happens in any given request.
The application matches your URL against the list of defined routes
and then uses that to parse out the parameters. It doesn't know you
are trying to browse the items until *after* the browse items route
has been matched against the current URL, meaning modifying the routes
after the matching process won't change Omeka's behavior.

That said, you should try using the 'define_routes' hook that I
mentioned previously. That receives the router as the first argument
($router), so you don't need to (and shouldn't) create a new instance
of the RewriteRouter.

Other than that, you've got the correct method call to add routes,
$router->addRoute($name, new Zend_Controller_Router_Route); but you'll
need to tweak your routes to get that working. I'm not totally clear
on how to make your routes match properly, but that seems to me to be
the heart of the problem you are trying to solve. The easiest way to
see whether your routes are being matched properly is to edit the
config.ini file and set debug.request = true. Then open the URL that
you think should be matched, e.g. items/browse/format/photograph or
something like that, and Omeka will dump the request object to the
screen, so you can check if the correct controller/action and
parameters were matched.

Hope that helps!

Kris
> For more options, visit this group at http://groups.google.com/group/omeka-dev?hl=en
> .
>
>

kevin.reiss

unread,
Nov 30, 2009, 10:48:26 PM11/30/09
to Omeka Dev
Thanks for the response Kris,

So if understand how to properly use the "define_routes" hook I should
not instantiate the router object within the function I'm trying to
define for the plugin.

Right now I'm trying:

add_plugin_hook('define_routes', 'metadata_browser_define_routes');

function metadata_browser_define_routes() {

// following line is not needed
//$router = new Zend_Controller_Router_Rewrite();

$route = new Zend_Controller_Router_Route(
'items/browse/:advanced[0][element_id]/:advanced[0]
[type]/:advanced[0][terms]/:submit_action',
array(
'controller' => 'items',
'action' => 'browse',
'advanced[0][element_id]' => '51',
'advanced[0][type]' => 'contains',
'advanced[0][terms]' => 'photographs',
'submit_search' => 'Search'
)
);
$router->addRoute('formats', $route); // formats is the name of
this test route
}

However when I comment out the line "$router = new
Zend_Controller_Router_Rewrite();" I get a call method on non-object
error for the "->addRoute" call on $router. Should I be adding -
>addRoute to the generic $router variable or is there a different
object name that I should be using or should have referenced in a
different fashion.

Thanks,

Kevin
> >    //http://nycdigital.org/nycbeta/items/browse/51/contains/photographs/Se...

Kris Kelly

unread,
Dec 1, 2009, 9:35:56 AM12/1/09
to omek...@googlegroups.com
Hi, instead of:

function metadata_browser_define_routes() {

Should be this:

function metadata_browser_define_routes($router) {


Kris

On Nov 30, 2009, at 10:48 PM, kevin.reiss wrote:

> function metadata_browser_define_routes() {

Reply all
Reply to author
Forward
0 new messages