Idea for a simple custom functions auto loader

acrylian Administrator, Developer
I came to this simple idea: If you make a folder "customfunctions" in the zp root directory and insert in index.php (the one in the root folder) this code right behind the require for the template functions,php then you can automatically load any custom function (of course deep core hacks like zenvideo won't work):

`

$dir="customfunctions";

$verz=opendir ($dir);

while ($file = readdir ($verz)) {

if(substr($file,-4,4) === ".php")

{

require_once("customfunctions/".$file);

}

}

closedir($verz);

`

All custom functions would then be avaiable to all themes.
Does anyone finds this useful? Then I could try making a little backend page for uploading, deleting and displaying installed custom functions files. Of course a very basic plugin system but maybe a good idea?

Comments

  • Something like this would be very beneficial but before implementation I think there should be some sort of consensus.

    What I had always envisioned was a plugins tab in the admin. Inside of this tab would be a list of all the files listed within the plugin folder, each of which can be activated and deactivated. Much like how wordpress works. A new table 'plugins' would be created with fields like 'filename', 'plugin_name', 'active'

    The active field could be bit/logical, and set to True when the plugin is set to active in the admin tab.

    What you wrote above could be improvised to grab the list of plugins in the plugin directory and also be edited to run the includes if active=true for each plugin.
  • I agree with that. Plugins, and in fact all custom functionality should be able to be activated/deactivated at whim, as not everyone will want all the features built in. That's what creates code bloat over time. Wordpress does it right in that they introduce certain core features, and let the plugins do the rest of the customization. That's why a plugin API is so important as it lets users handle the custom stuff themselves with minimal core code modification.

    What we need to decide is what core function zenphoto will support going forward, and then what functions can be moved to plugins, which will allow the user to choose the functionality they want. Things like RSS, EXIF, Basic Comments and Comment SPAM moderation should be core code stuff.
  • What I believe will be most difficult is making it so that themes will not be broken. For example: the printDefaultSizedImage() is built into zenphoto core. It is required to be modified for ZenVideo to work. Somewhere along the line, when the ZenVideo plugin is included, its printDefaultSizedImage() function must override the printDefaultSizedImage() from the ZP Core.

    Something else I think is important to add to the ZP Core is password protection on a album by album basis and for the entire gallery.
  • Zenphoto should stay simploe in its own core : just show photos !
    Everything around these basics functions may be a plugin (video, rss, comments, language), but the themes can be seen as a plugin too !

    Even the security can be a plugin... but it would be hard to create.
  • Security is something that needs to be built from the core. It is very difficult to design an app from a plugin standpoint with security, as security should be something you build into a webapp at the heart of it, not as a plugin.

    If we are looking at zenphoto to be something similar that people are familiar with already (wordpress), the themes and plugins should be separate administrative functions. That way you can use x plugin with y theme. That way if something goes awry with the plugin functionality, your themes aren't affected by it (and vice versa).
  • Ok, security must be in the core of zenphoto...

    What access an api should provide ?
    In others terms, we must define what a plugin can do ... and what it can't do.

    List albums, list galleries, list photos (or items), modify them ?

    We should write everything clearly on the wiki !
  • Plugins should not be able to delete anything, but modifying just about everything should be allowed. I am thinking about ordering, rotating/cropping, ect.

    The plugins should definitely be theme agnostic and for the most part require only one line or no lines to implement. printRSS() or printComments() and something like ZenVideo would require no changes to themes, but like I said above would require overwriting functions that are built into the core.

    Redoing the admin seems like the #1 priority here. After the bones are laid out, all the functionality that albums have can be implemented into subalbums, something that is badly needed. As I see it, the plugin functionality should then follow, IMO. You guys are basically the developers now, I'm just thinking out loud!
Sign In or Register to comment.