edit:Here are some of my experiences in creating my module, hopefully you will find some of the information here useful.
Currently I am trying to use gallery2 to make a gallery for serving my content in a custom manner.
Looking though the code i have added a few hacks to the core module to do some of the things I require
eg:-
-renaming files on upload
-processing gallery items before download
Now I have come to a halt in my development, this is what I want to do:-
1. Have certain meta data associated with a file depending on the mime type or extension of a file (like custom fields but only for certain mime/extension).
2. Have gallery items that do not have any file, i.e. just meta data (e.g. just a url)
3. Be able to edit these values on a per item basis, similare to the edit photo panel.
4. These items would display in a custom way, be edited in a custom way and downloaded in a custom way aswell.
5. I would also like to create a sub album when a jpg file is uploaded of the same name. (eg upload "123.jpg" would createa an album called "123_files" in the album the jpg is in.)
Through reading these forums and documentation I feel that what I will need is a module and some derived types. Any recommendations on where to start would be greatly appreciated (tutorials, examples etc), also some pointers on what type would be what i would want to derive from.
I do have some php experience but a lot of the workings in gallery2 seem very foreign to me.
Thanks in advance :D[/]
[/]
Posts: 25
What you're proposing could solve somthing for me too. I'm looking for a better way of integrating audio files, so that a meta-data playlist file is created when an audio file is uploaded.
So for example:
1. I upload test.wma
2. Gallery puts test.wma in the filesystem, but also creates test.wax from a template, and stores this in the database in the same way as a thumbnail.
3. Then the user has the option to 'click here to download' or 'click here to play this audio now'
Will this kind of scenarios be included in your plans or are you mainly aiming at images?
I'll help if I can, but I think I'm more of a newbie than you, as I'm still on the basics of PHP, and have only found G2 a couple of days ago!
Thanks
Steve
Posts: 40
Ok, so I have started on this, I have extended a GalleryItem, should probably be a GalleryPhotoItem for the jpg's.
I can't seem to work out how to make all the jpgs in the gallery become one of my items rather than a normal photo item? Actually there is a lot I can't work out but this would get me headed in the right direction I would imagine
Posts: 40
created a MyImage class as follows:-
class MyImage_core extends GalleryPhotoItem
this has 3 extra fields, an int and 2 bools.
I have generated the database and inc files using gmake all in the classes directory, all seems to be ok here.
But, I still dont know how to make all jpg's in the gallery an instance of this item.
Any help would be greatly appreciated.
Thanks again.
Posts: 8601
you need a row in your table for every id in g2_PhotoItem that is a jpg (check mime type in g2_DataItem).. then you can change g_entityType in g2_Entity to MyImage for all those entities.
Posts: 8601
oh, and to make newly uploaded jpgs use your type I think you need to register your class with the factory.. see performFactoryRegistrations in modules/core/CoreModuleExtras.inc where it registers GalleryPhotoItem for image/*.. register your for image/jpeg
Posts: 40
Looking in CoreModuleExtras.inc i think i have extracted the right calls
Does this go in my module.inc? That where i have it now but I don't seem to get any of my items
I have uploaded a jpg to the server but i do not seem to get my custom view
Do I need to unregisterFactoryImplementations or should mine overwrite the existing one?
I am not going to worry about
as my database does not contain much except development test things atm.
Posts: 40
Oh yeah and this is what is in my Debug tree
Thanks again for your help mindless, hopefully with a little help from you I will be able to make the gallery and site live by next week.
Posts: 8601
add performFactoryRegistrations to setCallbacks for your module and bump the module version.. see other module.inc files for examples. just image/jpeg will do.. jpg and jpeg and jpe extension all use that. image/jpg isn't a mime type in G2..
Posts: 40
No result with that, the debug tree looks the same and displays normally aswell...this is what i did, the comments in the code section explain the changes.
is actually what i was aiming for, don't know what i did there.
Is the render() function what i should be using to see my results aswell?
Also, do i need to fill out some entity type in the MyPhotoItem class (perhaps in the create function)?
Looking at the embedded audio play example by stephen I don't see any major differences except that he has registered his class in CoreModuleExtras.inc
I don't think that this would be necessary, wouldn't this defeat the purpose of a module?
Posts: 8601
correct, you should definitely register the class in your module, not in core.
oops, I should have looked at the code before my last reply.. performFactoryRegistrations is always called.. didn't need that in the setCallbacks list.
the first param to registerFactoryImplementation should be 'GalleryItem' not 'GalleryPhotoItem'. G2 looks for a GalleryItem implementation that supports the mime type of the uploaded file.
Posts: 40
Thanks for all your help, a couple of questions about locking when using get and set members.
1. Do I need to lock and unlock to use the get methods?
2. Is this how I should be using the locking mechanism?
Posts: 8601
1. no.. you only need to lock if you're going to save changes.
2. the if ($ret->isError()) checks are missing, and save() returns an error status.. but basically, yes.
Posts: 40
Cheers for that... I had taken all the ret->isError stuff for the post, that's why $item->save ended up without the semi-colon.
I thought I had it all working but now I have another question about using the inc & tpl system in gallery2. How did I accept
I have tried a couple of things in my code
any hint or pointer to some code that does this would be very helpful, not only do I want the tmp_name I would also like the name size and other fields usually found in the $_FILES variable
Posts: 8601
there are several examples.. how about modules/thumbnail/CustomThumbnailOption.inc, handleRequestAfterEdit.
Posts: 40
Cheers, just what i was looking for
Posts: 40
This is how the download works at the moment.
I want to be able to call my own download in MyModule, I think that I need to do something in the module.inc either with performFactoryRegistrations or something similar.
obviously something like this would required an assocaited file
but this is in the photo.tpl which is in the core...
Posts: 8601
i don't really understand what you're asking now.. yes, you can use mymodule.DownloadItem in g->url or generateUrl() if you have a DownloadItem.inc in your modules/mymodule dir that defines class DownloadItemView. nothing needs to be registered.
Posts: 40
So what you are saying is that I just put a DownloadItem.inc in my MyModule directory that contains something like
and gallery2 will pick this up?
What files would i find this DownloadItemView interface in?
/modules/core/classes/GalleryView.class
do i need to anything in module.inc?
Is there anywhere I can find a list of these classes perhaps with a description of what they are for?
http://dev.gallery2.org/modules/GalleryAPI/apidoc/GalleryCore/Classes/GalleryView.html
Posts: 8601
i was thinking DownloadItemView extends GalleryView.. but i suppose you could extend DownloadItemView if you rename your view (DownloadItemView can't extend DownloadItemView), and you need some functionality of core.DownloadItem.
correct, you don't need anything in module.inc to define a view.. if you make a link to mymodule.something it looks for something.inc in modules/mymodule and that file should define somethingView.
browsing through core/classes (esp GalleryCoreApi.class) and looking at the apidoc is the best reference.. there's bits of other info on codex.gallery2.org.
Posts: 40
the thing is in the matrix theme there are calls to core.ShowItem and core.DownloadItem which I would like to call class, templates etc in MyModule rather than in the core.
I have made a DownloadItem.inc in modules/MyModule but it seems from what you are saying is that this will only get called if referenced by
ideally I would like this to be called by
which appears all throughout the photo.tpl in the matrix theme.
Is there anyway I can override core.DownloadItem for a certain file type such as MyPhotoItem.class?
BTW there seems to be issues when posting html in a code block...
Posts: 8601
sorry, i really have no idea what you're trying to do.
you could write an urlgenerator that changes core.Download/ShowItem to your module, but currently you can only use 1 url generator, so they you couldn't use rewrite. you can always hack core code instead if you like, but that makes upgrades hard.
Posts: 40
ok, i justed edited the tpl files in the theme, seems to work ok, not as clean as I would like but if you can't change it via the module, i guess this will do.
On another note, am I only allowed to register 1 galleryItem per module, I have 1 item that works correctly that extends the GalleryPhotoItem but I am now trying to add 2 more that extend the GalleryDataItem, these register fine (no errors on install or activate) but then when I try to view an album containing one of these items I get an error
by the looks of this error my item isn't in the database or something similar.
Maybe this is my fault, I don't know if this is legal but basically what i did was create a new mime type for my item, 'application/My2ndItem'
and I create it from a 'ItemEditPlugin' page like this
Posts: 32509
just a small note: module directory names should be lower case. vista and not Vista.
could you please use g 2.0, the databasestorage.class file changed since rc2 a little, or at least an error on line 2270 doesn't make sense in 2.0.
Posts: 40
Is it possible my database is corrupt? can I flush the entire database and rebuild it?
I'm know from some of my hacking around I may have broken it...
Posts: 40
Changed every modules/Vista/
to modules/vista/
This is with a fresh install of the gallery2 from cvs
Posts: 32509
yep, now it's missing since you already registered it with performFactoryRegistraction. you need to uninstall (read: not just deactivate) the module and install it again.
Posts: 40
I don't think it's missing, its in my database, I created a new object using addItemToAlbum.
I am now using a clean install and database, and have installed and activate my module.
My1stItem object creates an album called objectname_files and an object in that album of type My2ndItem
Looking at the database the only thing a can see that is missing is g2_AccessSubscriberMap entry for the g_id of the item in my database.
Is it possible that there is a problem with adding more than 1
or should I be adding all of my items in an array or something?
Posts: 32509
i hope you have this registerFactoryImplementation only in your performFactoryRegistrations function and nowhere else. and no, you can register multiple implementations, but they have to differ somehow. registering the same class twice, does that make sense?
Posts: 40
Does the error make sense to you with the new line numbers?
This is im my performFactoryRegistrations and they are not called anywhere else, this also contain a couple of 'ItemEditPlugin' registrations
Looking in the database at g2_factoryMap i noticed items like GalleryMovieItem, GalleryPhotoItem, GalleryUnknownItem etc are listed twice once with a g_classType of GalleryEntity and once as a GalleryItem
Posts: 32509
in DatabaseStorage.class, please add var_dump($entityName); var_dump($entity); exit; right before
return array(GalleryStatus::error(ERROR_MISSING_OBJECT, __FILE__, __LINE__,
$entityName), null);
right after if (!isset($entity)) {
on line 2263.
what do you get there.
Posts: 40
string(10) "HVistaItem" NULL
HVista is the name of my class not My2ndItem but you get the idea, don't really want to post my actual code to give away anything
Posts: 32509
HVistaItem, did you ever register such a entity type? perhaps some time ago?
Posts: 40
I am working with a fresh install, i have registered my module once
Posts: 40
Posts: 32509
read the modules/core/CoreModuleExtras.inc function performFactoryImplementations as an example.
it's 2.23h AM here, i'm off, and for chats, we have irf.freenode.net #gallery
Posts: 40
GalleryItem needs to have a corresponding GalleryEntity.
I don't know why it worked for my original item but once I had more than one GalleryItem it was causing problems
Posts: 32509
yep, makes sense.
when you add an item to g2 by upload, ite uses
GalleryCoreApi::newItemByMimeType($mimeType);
which uses GalleryCoreApi::newFactoryInstanceByHint('GalleryItem',
array($mimeType, substr($mimeType, 0, strpos($mimeType, '/')) . '/*'));
so that's why you need to register a GalleryItem. item -> data type / mime type
and when showing a page with this item, it uses GalleryCoreApi::loadEntitiesById() and as the name says, it loads an entity.
in the databasestorage.class, it does newFactoryInstance('GalleryEntity', $entityName);
which is why you need it to register as entity too. entity -> entity name
Posts: 40
when I add an item to an album using
the file is not directly copied to the album folder, it also has the . in the filename changed to an underscore_
will have to do for now but its really annoying losing the extension esp on download
Is there any way to stop this?
Posts: 32509
hmm, don't know why it does that. maybe it doesn't detect the extension?
why do you use your own GalleryCoreApi::addItemToAlbum call and don't try it with the add item methods?
or is this in a unit test of yours?
@ g2 naming conventions / coding guidelines:
variable and function names are in camelCase. so the first letter of a function or variable is always lower-case, $fileName and not $FileName.
abbreviations and acronyms are treated like a normal word, it's getFilesAlbumId and not getFilesAlbumID, it's getRssFeed and not getRSSFeed. etc.
class names are the same, just with the difference that they start with a capital letter.
Posts: 40
This is a standard API call and it does exactly what i want.
What I do is have an uploaded item that has an ItemEditPlugin, I generate another file of my own type using the $platform->fopen fwrite, fseek, fclose etc, then I add this file to an album associated with the uploaded jpg.
to tell you the truth thats not my actual variable name, but i'll keep that in mind. I'm suprised you didn't have a go at the { brace being on its own line aswell. I guess it's just my preffered style ;).
Posts: 32509
weird things you do there why do you need fseek? you kept your questions very general, what are you actually doing?
Posts: 40
i need fseek because the fwrite functions in PHP do not behave the same way as they do in C, in PHP the write will end after the length of a string in a variable while in C you can specify a number of bytes to write. Perhaps there is another version of the fwrite that does this but my way works ok anyway...
Something along these lines
Can't really tell you what I'm doing exactly but the basics are that you can upload files in one format and download them in another...
Don't worry I'll post the link when the site goes live...
here's the start http://www.360desktop.com