Hi,
I'm making a plugin to customise the Admin UI of ZenPhoto. I'm wondering if it would be possible for my plugin to automatically name new albums that are created. Our users will be saving photos into albums on a week-by-week basis, and I want to automate the naming of albums to maintain the same naming format each week.
My plugin would need to either:
1. Automatically insert the generated album name into the alert that pops up when the 'New Album' button is pressed, or
2. Replace the 'New Album' button with a similar button that automatically creates the required album with the correct name.
Can either of these things be achieved using the ZenPhoto API?
Cheers,
a|x
Comments
It should possible to use jQuery to insert a new album name instead of "new album" as it is used now using the `admin_head()`filter.
All available filters are listed here:
http://www.zenphoto.org/news/zenphoto-plugin-architecture#zenphoto-filters
I was starting to think that was probably the case. I'm already using a linked js file inserted using the admin_head() filter to hide un-needed fields on various edit pages, so I'll look into using jQuery to achieve this.
Incidentally, is it likely that a future release of ZenPhoto will use more unique identifiers for admin UI elements? I've had to jump through some rather tortuous hoops in order to target various form fields and table rows with jQuery, and in the process, created a completely non-futureproof plugin. I'm sure it's not a priority for you, but it might make it easier for your own future development of the platform if the various form fields had unique ID or title attributes, as well as making it easier for 3rd-party plugin developers to tweak the UI in various ways.
Cheers,
a|x
I think it won't be possible to modify the content of the browser prompt once it has been created, unfortunately.
I could use jQuery to remove the inline 'onClick' attribute from the New Album button, and write my own JS function to handle new album creation (overriding the script in the head of the document). However, I think this would fail due to the presence of the XSRFToken argument being sent to launchScript, which presumably is written into the document head by PHP at page load, and is there to stop exactly the kind of thing I'd trying to do…
Hmmm. Maybe I'm missing something…
a|x
There are already filters to add custom fields (for all items). There is also a plugin named userAddress fields that can be adapted to add extra fields to items programmatically. However how it does it is technically will probably not be the way we will follow in the future.
I'll have a look at userAddressFields, but at the moment, I'm more interested in removing fields, than adding them. A selection of the existing default fields will fit our needs, I think.
The background is that I'm setting up an image library for a collaborative student journalism project. Because the role of Picture Editor is typically assigned to a new person each week, it's not possible to give everyone who will be using ZenPhoto detailed training, so I've found it necessary to strip all non-essential fields from the various album and picture-edit pages.
a|x
These `onClick` usages are sort of legacy anyway and will be removed on that major release as well…
You maybe could replace the onClick() via jQuery and attach a new call to the js function `newAlbum` and set your preferred folder name then. Or you indeed hack the file to do so directly…
As I said, I can remove the onClick with jQuery, and replace it with my own slightly tweaked version of the newAlbum function, but the problem would then be the XSRFToken argument that gets sent to launchScript when it's called by newAlbum(). I presume this is generated and written into the document head by PHP at runtime, and my newAlbum replacement isn't going to be able to get hold of this string, unless I find some way of parsing the raw page source for the value of XSRFToken or some similarly horrible hack…
I thought about trying to override the value of the album var that receives the result of the prompt, but it's scoped inside the newAlbum() function, so this isn't going to work, I think.
a|x
a|x
would I need to declare some globals if I wanted to place my new newAlbum function in a linked php-generated javascript file within my plugin folder?
I tried doing that, and adding at the relevant point
<?php echo getXSRFToken('newalbum'); ?>
but got an 'Internal server error 500'.
a|x
a|x