Can Plugin Edit Image Meta Fields?

Is it theoretically possible to create a plugin to change the photo meta-information fields visible when a photo is viewed or edited in backend of a ZenPhoto site?

I'm trying to ensure that certain fields are highlighted to indicate that they Must be filled in, and, if possible, that non-essential fields are hidden altogether, but I'd rather do this with a plugin, that hack around the ZenPhoto core files.

This kind of thing is achieved in the Wordpress world using custom post types, so was wondering if it something equivalent was possible in Zenphoto.

Cheers,

a|x

Comments

  • acrylian Administrator, Developer
    What meta fields do you mean? I assume you mean the `` meta tags and not the image meta data (EXIF/IPTC).

    Zenphoto does not have fields for these html meta tags. The html_meta_tags plugin does generated the entries automatically via the content that is there (like tags, titles, descriptions).

    Acually on WP I would not use custom post types but the `post_meta` table to create extra fields for meta data. Zenphoto has a similar general table called `plugin_storage` you can use for the purpose of extra fields.

    This table has no API since there is no "fixed" usage as it can be used for anything. So you need to use it with queries. ZP has a bunch sql related functions (http://www.zenphoto.org/documentation/core/_functions-db-MySQL.php.html#functionquery_full_array).

    To create the fields you can use the `image_custom_data` filters. You basically have to pass through the standard custom field and add your custom ones from the `plugin_storage` table.
    http://www.zenphoto.org/news/zenphoto-plugin-architecture#media
  • Hi acrylic, thanks very much for the explanation.
    I think we may be talking slightly at cross-purposes. When I said 'meta', I really just meant the information that gets saved for each image, rather than the HTML meta tags of the page displaying the image.

    Do you happen to know of any existing plugins that add fields to or customise the look of the image data form (not sure of the terminology here, but I think you know what I mean)? I really just want to add a 'Photographer' field, and make sure it is visible by default, rather than the user having to click the 'Show more fields' link.

    a|x
  • acrylian Administrator, Developer
    Ok, my advice above is the same anyway regardles if html meta or just image extra fields. You can use the custom data field filter or one of the utility or general box on the right to add extra fields. There is an example plugin for the custom data and the multiple_layouts plugin for example uses a utility box filter as does the tweet_news plugin.

    You could also just use the custom data field for the "photographer". The front end does not really care how the field on the backend is named, it is a general purpose field.
  • I see. I'll have a look at the the plugins you mention.

    I realise that the custom data field could be used, but I wanted to make it a bit more intuitive, and make it obvious that this field was required. I'm making an image library for an online journalism project, and the library will be used by a large number of students, or widely varying levels of technical competence and inclinations to read documentation, so I want to make things as simple as possible.

    Thanks again,

    a|x
  • acrylian Administrator, Developer
    Sure, I understand. You could use jQuery for example to change the name printed before the custom data field as well to "mimic" your purpose. But that would of course also require a plugin using a filter.
  • That would probably work OK, actually. So can a plugin inject CSS and JavaScript scripts into the ZenPhoto backend, then?

    a|x
  • acrylian Administrator, Developer
    Yes, see the plugin architecture article I linked above.
  • The closest plugin we have is the unsupported `disableAction` plugin. You might look at that for a start. Basically you need to implement some javascript to "edit" the DOM of the page and make the highlighting you want.

    The example plugin disables the field, but you should be able to add a highlight instead.

    You can find the plugin on GitHub in the "unsupported" repository.
  • Hi sbillard,

    thanks for the tip- I'll have a look!
    Incidentally, I read somewhere on the forum about a possible backend rewrite. Would that maybe include steps to make targeting items like the field in question with JavaScript/jQuery easier i.e. by adding more specific classes, IDs or data attributes to form items?

    Cheers,

    a|x
  • acrylian Administrator, Developer
    A html/css cleanup is planned for next year, hopefully for 1.4.7: https://github.com/zenphoto/zenphoto/issues/191

    Yes, that would include some more classes to address items more specifially. In this case just proper form element labels would help…

    However, that's quite a major task and since we are volunteers you need to have the time for it which is quite an issue. Since it involves a lot backend functions and other stuff you sadly cannot just partly start but have to constantly work on it.
  • I see. I completely understand about this being a volunteer project. Was just wondering…

    Thanks, guys,

    a|x
  • acrylian Administrator, Developer
    Sure, was just an explaination. I think the best for your purpose is probably to use a filter plugin.
  • @acrylian a filter plugin to inject jQuery code and tweak the admin DOM, you mean?

    a|x
  • acrylian Administrator, Developer
    Actually not really as the custom data field especially has only a class on the input element but not on the name before it. It is currently not even a label.
  • @acrylian I noticed that. Thought I might be able to select it using a jQuery 'td:contains()' selector.

    a|x
  • acrylian Administrator, Developer
    Yes, but the problem is there are a lot "td" on the edit pages. You could use the "nth-child" selector but that of course will not work on some (older) browsers like especially IEs. But if that is no isssue that would be a way.
  • @acrylian you're right. It's harder than I thought to target the relevant DOM element…

    a|x
  • This seems to work:

    $("td:contains('Custom data')").filter(function() {
    return (
    $(this).clone() //clone the element
    .children() //select all the children
    .remove() //remove all the children
    .end() //again go back to selected element
    .filter(":contains('Custom data')").length > 0)
    })

    as a selector. I'm sure it's a massively inefficient way to do it, though.

    a|x
  • acrylian Administrator, Developer
    Did not check in detail but couldn't you get the children right away with the first jquery call?
  • Hi acrylian,

    do you mean?
    $("td:contains('Custom data')")

    Unfortunately, that returns all the elements containing 'Custom data', including the parent elements of the tds I want to get.

    a|x
  • acrylian Administrator, Developer
    I haven't tried but wouldn't this help?:
    http://api.jquery.com/nth-child-selector/
    I mean the number of <td> and even <tr> is known so it should be possible to get the nth tr with the nth td within to change the value.
  • Hi acrylian,

    the problem is the tables containing the items I want to select are also not uniquely identified, so if I use nth:child I may end up selecting items in other backend tabs or panels.

    a|x
  • This seems to work:

    $("table[id|='image'] tbody tr:nth-child(n)").hide();

    where n is the row number. It's complicated by the fact that some of the rows of the containing table for the data for each image contain further tables, but the method above does appear to work.

    a|x
  • acrylian Administrator, Developer
    Good that you figured something out.
Sign In or Register to comment.