Questions on API for plugin development

So, this page describes how to develop a ZP plugin:

http://www.zenphoto.org/2008/04/zenphoto-plugin-architecture/

The theme plugins are reasonable well explained. My question is on the "other" type of plugin, to quote the page:
The second category of plugin is used to provide alternative implementations of Zenphoto core functions. Examples of these plugins are: The spamfilter set and the theme options implementation. ...
The implication here is that one can create a plugin to modify the behavior of core ZP functions. But that is not really described in any additional detail. Furthermore, creating a plugin that tries to redefine a ZP core function gives a PHP "can't redeclare function foo()" error.

Now, redeclaring funcs/methods is totally possible if the core functions are class methods. But they are not.

So how does one redefine or otherwise add functionality to a ZP core function? As is suggested is possible by that quote from the developer's manual, above.

THANKS

Comments

  • Let me add further:

    I would like to create a plugin that modifies the way an image is displayed withour having to add a line to a given theme.

    It seems to me that a flaw in the design of plugins is that theme plugins have to also be added to themes to work. A bit clunky. I mean, you can't just switch on a plugin and it works, you also have to make sure the theme you are using supports the plugin, and add that support as required.

    Am I getting this right? Please show there is something I'm missing.

    I want to add simple changes to the way an image is displayed wihtout also having to t modify the theme I'm using, so that this modification will "just work" in any theme, if I decide to change themes.

    THANKS
  • There are several examples of the core plugins, most notably the spam filters and the `text object` handler. You can make another instance of those plugins by simply following the structure of the one you wish to mimic.

    There are also `back-end` plugins that you will find in the zp-core/utilities folder. Again, for this type of extension just follow their lead.

    Any other kind of extension to the zenphoto core requires that the core itself be modified to recognize and link to the plugin. (This was what was done in all three cases above, each requiring a different core modification.)

    Zenphoto is a script based photo album. This means that all themes are essentially pieces of code. You modify them by modifying their code. Adding functions to a theme with a plugin is no different in that senes than adding functions by changing the HTML/PHP code of the theme.

    As for the case of change you are considering, there are two approaches you could take. First you could create a replacement set of image handling functions that reside in your plugin and are used in your theme (and any theme which chooses to support it.)

    Second, you could propose hooks into the zenphoto image handling functons which would link to the plugin to provide custom processing.

    The plugin architecture is relative new in terms of the zenphoto architecture. Most of all of the image handling functions were already in existance in their current form before the possibility of plugins existed.

    It certainly would be possible to re-do all these functions into a plugin structure. This was done for the admin-toolbox. Then extensions could be made by creating replacement image handling functions.

    But of course, this would be a large and perhaps minimally beneficial task so there is no plan to do so.
  • Thanks for the reply. I will get more specific and that may help.

    I want to create a plugin that lets me do some simple image editing in-browser. For now, only image rotation. Once I get it going, then adding things like sharpening and cropping will be easier.

    I want the plugin to work so that, once logged in, the admin sees a row of buttons underneath each image. For now, just "rot left; rot right; rot 180" buttons.

    I can see a way to do this using the theme type plugins but then one would also have to add at least one line to each theme that one wants the plugin to work in.

    I want it to be as simple as enabling the plugin gets you the image editing buttons.

    To do this, I think that modifying a core function's output somwhere is necessary. I'm guessing maybe printDefaultSizedImage() or similar, to just spit out HTML for these buttons as well as the image HTML. Or maybe printAdminToolbox(), and there is some JS or CSS to place the buttons where I want them to go on the page.

    Now, when you say, "propose hooks into the zenphoto image handling functons", what do you mean? Add code to the ZP core? Propose them to the core developers to be added? I really don't want to touch core code as I don't think a plugin should ever have to do that. But I'd be happy to make [as helpful as possible] suggestions to the ZP core developers. (Which is who? You? How many of you are there?)

    Incidentally, a little background: I have extensive PHP development background and am comfortable with this stuff. I looked at several "photogallery" apps and found ZP to be the best "put together" at least from the user's perspective. I like to support, encourage, and help F/OSS projects, so I will try to be as helpful as possible (time permitting :) ). I really just wanted an easy way to rotate my images in-browser!

    THANKS
  • acrylian Administrator, Developer
    You should try the svn/nightly version. There is brandnew already a image rotating function on the admin backend. Also there is already a custom crop feature since 1.2.2. Maybe that already fits your needs? Just to save work...:-)
  • It sounds like it will fit my needs. However I am still interested in learning how to write a ZP plugin and I may as well start with one that I find useful for myself.

    THanks! I'll try SVN
Sign In or Register to comment.