what handle to access Media.php for a new plugin

Hi All,

I added Lightbox support to our omeka installation. It was done as follows.
- Added "Lightbox" folder to the /common in my theme.
- Modified the header file to include the css and scripts from the lightbox folder.
- Modified "image" function in the Media.php file and added "rel='lightbox'" to the anchor tag. So lightbox would be invoked only when an image is been displayed.
It is currently working fine, but as you can see I had to edit a core omeka file "Media.php"

I'm trying to find a better way of doing this without editing the core files. It seems like there is no way that i can do this using a theme, so I thought of creating a pluging.

Using the handle for the theme header I'll be able to include the css and js references.

Only problem I'm having to how to insert the "rel='lightbox'" string to the image() function in the media.php.

Can someone pls help me to find a way to do this without touching the omeka core codes.

Thanks in advance.

Hi Dhanu,

You're right that you never want to edit the core of Omeka to make this type of theme modification. Our plugin architecture has been designed to help. We're in the process of adding additional options which will make this easier, and hopefully be included in the next full release: (https://omeka.org/trac/ticket/479). In the meantime, I have a solution that will work. It's a little extra code than I'd prefer, but it will get the job done.

You'll want to create a plugin. Please refer to plugin best practices (http://omeka.org/codex/Plugin_Writing_Best_Practices), and join our developer mailing list (http://groups.google.com/group/omeka-dev) to discuss this further. There's a plugin hook that allows you to switch out the display of files of a particular mime type. So it'd be relatively straight-forward to change how, for example, a JPEG image is handled and how it's displayed on the page. Here's some example code of a plugin.php file that could be in a potential plugin:

// Arguments = MIME types to catch, callback to use, default options to pass to callback (can be overridden in theme call to display_files())
add_mime_display_type(array('image/jpeg'), 'displayImageLightbox', array());

public function displayImageLightbox($file, array $options=array())
    $html = '';
    $item_title = item('Dublin Core', 'Title');
    if ($options['linkToFile']) {
        $html .= '<a href="'.file_download_uri($file).'" class="download-file">';
     * Setting a variable for content for the alt attribute for images.
     * Problem with alternative text is that it should describe what's going
     * on in the image, so should use the file description first. Item title
     * usually doesn't describe what's in the image specifically, but is provided
     * as a last resort.
    if (!empty($file->description)) {
        $alt = $file->description;
    elseif (!empty($file->title)) {
        $alt = $file->title;
    elseif (!empty($item_title)) {
        $alt = $item_title;

    $img = '';
    switch ($options['imageSize']) {
        case 'thumbnail':
            $img = thumbnail($file, array('class'=>'thumb', 'alt' => $alt, 'rel' => 'lightbox'));
        case 'square_thumbnail':
            $img = square_thumbnail($file, array('class'=>'thumb', 'alt' => $alt, 'rel' => 'lightbox'));
        case 'fullsize':
            $img = fullsize($file, array('class'=>'full', 'alt' => $alt, 'rel' => 'lightbox'));

	$html .= !empty($img) ? $img : htmlentities($file->original_filename);	

	if ($options['linkToFile']) {
	  $html .= '</a>';

	return $html;

The displayImageLightbox function is almost identical to what's included in the Media.php file, however I've added 'rel' => 'lightbox'. That should work fine. You can also use the public_theme_header function to add the necessary javascript files to the theme as well.

I believe Mark Matienzo at the New York Public Library has done some work with a lightbox as well. It'd be great if you could release whatever you build for others to use.


Thanks for the reply. I'll take a look at it and get back to you if I have any more questions.

Another questions ->

As an example I'll take the following line inside function image() in Media.php.

$html .= '<a href="'.file_download_uri($file).'" class="download-file">';

Since this is a core omeka file why are you having html tags over there. Wouldn't it be better to just return the file_download_uri($file) and have the theme decide how to handle it.

Am I correct with my suggestion or have I totally missed the bigger picture?

P.S. - I'll share my themes/plugins with the community once I finalized them and do a code clean up. Currently it's a mess such that no one would be able to understand my non-commented code. :-)

In response to your latest question, the display_files() helper takes care of all the HTML markup when displaying the files associated with an item. if you just want the URI for the file, you can get that directly instead of calling display_files().

In the case of display_files(), it shouldn't return a string URI in one case and HTML in every other case b/c that will create more headaches for a theme writer. A theme writer could not predict when the output of display_files() will need more logic around it to display properly.

Hope that answers your question!

Just as a heads up, I'm working on including more options in display_files() for the next version of Omeka. For example, you will be able to do what you are trying to do here by something like the following:

echo display_files_for_item(array('linkAttributes'=>array('rel'=>'lightbox')));

I looked for documentation on display_files_for_item and didn't find any. Any way to know if this change made it into the current version of Omeka? I would love to set up lightbox for viewing multiple images associated with a single item (or any set of images on a page really).


Thanks for the post