I just migrated from a flickr account to a new G2 installation after i realized how sucky the flickr free account is.
One thing the G2 needs is the flickr tags, and it sounds like a lot of other people agree.
Has anyone started on a new module to accomplish this? If not can anyone with general G2 knowledge offer some design hints? I'm thinking i might take this on.
eg. opinions on things like:
--is it better to add a new table, that stores entity id and tag name. Thus one entity to many tag rows relationship. Or is it better to just add a col to the entity table (guessing there is one) and lists all the tags for the given entity?
--how should the user add tags? add an item to the drop down like when want to edit/delete a pic.
etc
--Matthias
Posts: 32509
there have been a few discussions in these forums about flickr style tags in G2, e.g.
http://gallery.menalto.com/node/28309 (found with the search function)
a few notes:
- there are a few developers that plan to implement such a feature, but it seems noone actually did it, so you're welcome to do it
- g2 custom fields (customfield module) are quite similar to tags, or the G2 keywords too. but none of them are exactly image tags
g2 development:
see:
http://codex.gallery2.org/index.php/Main_Page
http://gallery.menalto.com/node/36885#comment-134279
implementation:
- it should be a new g2 module
- i guess you should go for separate / new db tables (a Tags table: tagId, tag name, tag description, ..., a Map table: mapping itemId with tagId=
- adding tags:
__you can add an item action link "add tag" and offer a menu, maybe a drop down list plus the option to define a new tag
__you can add a block which can be shown in the sidebar / on photo pages / on album pages
__.... there a lot of possibilities
- search by tags: implement the search plugin interface in your module
- browsing by tags: offer a block in your module, similar to the albumselect block, you could offer a tag block to browse g2 by tags
- showing the tags a photo / album already has: maybe with a block, similar to the customfields or exif block.
Posts: 15
cool. thanks
i read that thread you referenced. The Q posed there is more of making Flickr be an external File System. I think that's kind of a silly idea. Seems like implementing a WebDav module would be more useful in that case.
As for the other links i've read them before, but there seems to be some good info there anyways. So i think i'll probably start this. I'm guessing "customfield module" would be a good starting point... i'll look this up.
Here are my current ideas. Lots are stolen from Flickr, b/c they do it very well (quick/simple)
--user can set tags during upload.
--user can change using the drop down in album (like delete image)
--user can pick any tags (ie there is not a list of approved tags).
--user enter's tags into text box, separated by spaces, this is inserted into a tags table (as Valiant described)... do it quick/simple!.
--make a tag view (don't need search func for now). This would look like http://www.flickr.com/photos/thias_l/tags/
that should be a good start.
If anyone has any ideas/requests, please holler. This is an RFC.
--matthias
Posts: 32509
i'd argue for a database Map table with 2 colums:
itemId, tagId
and you'd have an row in this table for each tag you add / remove to a specific item.
why do i mention this?
because the current customfields module uses a single comma separated table column. so instead of a row for each value, it has a single row with comma separated values.
- this doesn't scale (browse / search by tags) as well as the other approach
- this is limited (the db column is limited to maximally xxx chars). which can be a problem in some rare cases
thus, i'd do it with a row per tagId and not a comma separated list of tags in the database.
the presentation can differ of course. you can present the list as a comma separated list.
Posts: 15
This was what you recommended in your first reply. I'd argue that this is overkill. The tags table is not needed only the TagMapping table. I agree with you that the relationship should be one entity to many TagMappings, otherwise getting a list of entities that have a specific tag requires a LIKE in the WHERE clause (slow, and not ideal). Also doing a select count(*) from tagsMapping is really a pain in the butt.
I think we are on the same page on this one.
one clarification: when i say that the user enters the tags using one text field i mean that the code will tokenize this and insert one row into the TagMappings table for each token. Thus easy to use, easy to add new tags, easy to search, a little bit hard to write the SQL... Hence easy for the user.
Anything more?
--Matthias
Posts: 32509
why i also mentioned the Tags table:
- it ensures referential integrity (if we had / introduced foreign keys)
- i guess you want to add a tag description or other attributes a tag might have. then you almost have to introduce a Tags table, else you end up with a lot of redundant entries or entries that don't match 100%
plus, getting a list of all existing tags would be easier (no select distinct query).
Posts: 15
yeah i see your point... i'll mark that as an enhancement. Right now i just want to get something simple working...
Posts: 15
i have a few dev questions:
why are .inc files called .inc? are they included into something?
This is the start of a module.inc i'm writing. it doesn't seem to do anything though. Its based off of the shutterfly module. Module.inc is the handle for installing the module right? i'm guessing that i need to register all the events that my module needs in this class (via performFactoryRegistrations?). These registrations will map an event (like painting the header) to a controller .class file. That controller will run, and somewhere specify a template to render the controller's view. I'm making a guess here. I'm i on the right path?
Posts: 32509
@inc:
yes, inc as in includes i guess.
right, but it's also used for more. module.inc tells G2 a lot of things about your module.
yes and no.
"painting the header" is not an event. so your definition of an event in G2 may be wrong.
there's an event when an entity is saved / deleted, there's an event when a user logs in / out, there's an event when permissions get changed and that's about it. you can register your module as a event handler, see albumselect as an example. but i don't think you need to register any event handler in your module.
@performFactoryRegistrations:
only needed if you e.g. register a search plugin or event handlers. or if you register a new entity type.
@getItemLinks:
these links are shown in the sidebar in the item actions list, so "Add Tag to this image" would appear in the same list as "Edit photo" etc.
$params['view'] = 'tags.AddTag'; tells G2 that it should load the GalleryView modules/tags/AddTag.inc when someone clicks on this link.
see my explanations about views / controllers in the link i mentioned in the second post of this topic.
maybe you want to add your tags list on the edit photo -> general page or in a separate tab. then you should look at itemEditOptions and ItemEditPlugins. grep the existing modules for such occurrences.
Posts: 15
cool i'll take a look into this stuff in a bit.
Can we make a "how to make a module" codex page? i tried, but i can't seem to figure out how to make a new page... i can only edit. Do i need a perm? (my user name is mlathe at the codex).
--Matthias
Posts: 32509
creating a new codex page = just enter a new address in the browser.
http://codex.gallery2.org/index.php/Gallery2:Module_Development_Tutorial would show a new page which can be edited.
btw: on http://gallery.menalto.com/dev
there's also a link to:
http://txtdump.com/g2dev/
Posts: 15
Dude... this is EXACTLY what i was looking for (wanting to make). I will now start from here.
thanks
Posts: 32509
well, the tutorial is very incomplete and only touches very few aspects of module making. feel free to extend it ;)
Posts: 15
so i finally got around to getting started. Had to install Linux and all the little packages that come with it. I must say some of these distros are getting pretty easy to manage.
In any case. I checked out that tutorial. It helped, but its really out of date, and doesn't seem to work right out of the box. Had to edit some things.
I've got the beginning of this module working, now i need to get the SQL to work. I found the following link.
http://gallery.menalto.com/node/37137?highlight=member-name%2CSQL
--am i right that all i need to do is make a file like /modules/tag/class/Tag.class? copy the GNUmakefile from another module, and make it? is that it?
--I'm a bit confused about the difference between a Map and an Entity. I understand what they are/mean, but which one should i use in this case?
--How are the tables made? (i think gmake makes the CREATE stmts, but when/how is this run).
I think that's enough for now :D
thanks again
--Matthias
Posts: 32509
yes. you need to change the xml instructions in the Tag.class too though.
these are all comment lines that start with @g2, e.g.
* @g2 <class-name>GalleryItem</class-name>
* @g2 <parent-class-name>GalleryFileSystemEntity</parent-class-name>
* @g2 <schema>
* @g2 <schema-major>1</schema-major>
* @g2 <schema-minor>0</schema-minor>
* @g2 </schema>
* @g2 <requires-id/>
use maps when you map something together.
use non-maps if you're dealing with objects / things. e.g. a Tag is an object, it has attributes.
a tag has a name, a description, ...
but when you're tagging, you're mapping a tag with an item.
so you'll certainly need a map to map tagId with itemId.
and i'd also recommend using additionally a tags table just to have a single list of all registered tags and you could then easily add attributes like "description" to each tag, in a normalized (SQL-sense of normalization) manner.
the SQL CREATE TABLE stuff is generated with gmake.
the table is generated in your database when installing the module.
Posts: 15
Ok i'll try to get the gmake to work... ie get the prereqs as described in the link in my previous post.
I see that g2 almost forces an almost "star" schema on data. That is, there are data tables but these have no foreign keys, and there are map tables, that don't have any data, but only foreign keys. So i guess i will implement this as you recommended in one of the first posts (make two tables....)
Can you point to some documentation or explain about what the following means?
--are these "@g2" grep-ed by the gmake and used as an xsd as described in the sql files?
--This looks like it was taken from core/classes/GalleryItem.class.
----is that why the class name is set as it is in the class-name tag?
----the "parent-class-name" implies this is a file. So this is a file entity, like an image, right?
----what is schema-major and schema-minor?
Thanks, I'll try to get this written up into the codex tomorrow for everyone's enjoyment.
--Matthias
Posts: 32509
- yes, the @g2 comment lines are parsed by lib/tools/bin/extractClassXml.pl (therefore our current perl requirement when generating interface and sql files). this is valid XML, the corresponding dtd is in lib/tools/dtd/ . the resulting xml is validated and then used to generate the interfaces (which add setter and getter methods for object/entity classes and add, update, remove map entry methods for map classes), and it generates the create table SQL for all database management systems (currently DB2, mysql, oracle, postgresql).
- yes the example is from GalleryItem.class
-- yes, the <class-name> must be the same as the class name which must be the same as the file name
-- the <parent-class-name> is only required if your class extends another class
-- schema major / minor are the version of the class / table. here i made it 1,0. all first versions of a class / table should be 1,0.
the purpose is: when you later have to change the table, you'll change the class and increment the schema to 1,1. and our upgrade code will check if the existing db tables must be upgraded or no.
but the upgrade table code must still be written manually in such a case (modules/*/classes/GalleryStorage/DatabaseStorage/schema/xml-src/ A_ for alter, R_ for remove table. T_ is a special case for our T as in Test that we use in the installer.
that would be great!
Posts: 15
thanks for the info
I have some of the DB stuff working... but i'm stuck on the actual INSERT. This is some code from the comments module. I read this as getting a handle to the interface in tag/classes/interface. However it always returns with ERROR_MISSING_OBJECT. Can you tell me a little more about the newFactoryInstance method? and maybe how to debug this some more?
thanks
Posts: 32509
to clarify:
G2 has two types of db tables:
- Maps
- Entities
(the rest; Lock, Schema and Sequences are for internal use)
if you use
GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryTag');
then you have to declare a GalleryTag to a GalleryEntity.
(GalleryEntities are generic objects, you'll get created, modified since timestampts and some other attributes).
i'd say, yeah, why not, make your Tags to be Entities.
see modules/comment/classes/GalleryComment.class
it's defined to be a ChildEntity. Do you need a parent / child relationship for tags? can tags be categorized hierarchically? i'd say no. what you want are flickr style tags and AFAIK, they are all on the same level, flat.
so you want
class GalleryTag extends GalleryEntity {
and you want:
* @g2 <class-name>GalleryTag</class-name>
* @g2 <parent-class-name>GalleryEntity</parent-class-name>
* @g2 <schema>
* @g2 <schema-major>1</schema-major>
* @g2 <schema-minor>0</schema-minor>
* @g2 </schema>
* @g2 <requires-id/>
and finally you need to register your entity:
in module.inc:
Posts: 15
How do you do a debug stmt... echo "foo"; thows an error, "headers already sent by".
valiant, thanks for all your help. Seems like despite the large number of people who voted for this module, there isn't much interest in it.
Posts: 15
am i right to assume that if you extend a GalleryChildEntity G2 handles the entry into the ChildEntity table, and thus when you delete the Entity a trigger is fired that helps clean up the extended class? e.g. a Comment is added to a picture, if you delete the picture do all the comments get dumped too?
seems like this is what we want here. a Tag is like a specialized comment, that is marked across several entities.
Posts: 32509
yes, if you declare and register an entity as entity type X (e.g. DerivativeImage), then G2 inserts automatically db rows in all necessary tables when creating / saving and it deletes them again when you call $entity->delete();
and yes, you're right, i guess it makes sense to extend the childentity...it's a lot like comments.
and no, we're not yet deleting all comments when you delete an item or a user (the owner of the comment), but that's a bug. you can assume we're taking care of that such that when an item get's deleted, all child entities related to it get deleted too.
Posts: 15
Well i have it about 70% done. However one thing that is a real pain in the butt is that you have to edit the tags for each entity by itself. This is not ideal. I've read that G2 has a problem in that batch changes can't be done (at least not now). Have you seen/know of any way to do a batch edit?
ideas?
--Matthias
Posts: 32509
well, you could do something like the modules/core/ItemEditCaptions.inc for tags as a temporary solution.
Posts: 8601
are you using a separate table rather than the existing keywords so each tag is in its own row in the table? (ie don't need to use LIKE in queries) will lots of people say "hey, I already keyworded all my items, I can't use them??"
Posts: 32509
well, keywords and tags serve a slightly different purpose. some users might want to use both of them at the same time, differently.
however, if we decided to change keywords to tags, we'd have to change the design from a single comma separated column to multiple rows.
Posts: 8601
i don't have too much time/interest in this feature, but it does get a lot of votes so here I will post a bit of code I hacked together... we'll see if it provides any ideas or leads anywhere.
the attached file include a module and small patch to modules/core/classes/GalleryTheme.class
what does work:
(replace "word" with keyword to search for)
(again replace "word" with keyword to search for)
caveats and what doesn't work:
perhaps this will give bharat or others some ideas about how the framework can be adjusted to better handle non-album containers.
Posts: 8601
has interest in this feature declined? should i reset all the votes? hehe
Posts: 1
Interest hasn't declined here, I'd love to hear any updates...
Posts: 219
Definitely not here either - it's still number 2 most requested, only just behind bulk watermarking. I'd love to see this feature as well.
Posts: 4
Here's what I have done, I am a complete beginner at Gallery2, but I think this tag module is better than what's currently available (umm, nothing, that I know of). I certainly don't consider it production quality by any means, but here's the info on it if anyone else wants to use it for now or pick up where I've left off
- haven't tried it with rewrite module
- has a search component just for tags
- lists tags below the item with links to find all others with that tag and to remove tag if they have permission
- basic functions of add and delete (can't edit and make a sitewide tag change)
- only tested on mysql
- and because I don't know enough about the inner system of gallery2, the tag table is inefficient, but i based it on my original thinking that childentities were automatically efficient (i found out later my assumption was wrong)...basically...multiple tags are stored multiple times instead of the optimized way
- there's no list page that lists all entered tags
- it's based greatly off of the comment module so you will see all the php comments refer to that guy who did the main work
- it utilizes that autocomplete javascript to fill in for new tags
- can only enter one tag at a time (phrase or single word)
- it surely has bugs in it, but i haven't found any major ones in my use yet
Anyway, I like how it works for my own use and I hope someone else comes out with a better one I can use...but here's for all the other people like me. I'm just too preoccupied to continue experimenting with it and certainly want to know when an official tag module comes out
-Danny
Posts: 32509
just....wow! this is great!
so you went with a tag entity instead of a itemId <-> tag map table. maybe we'll have to change that but the rest looks awesome.
maybe we can then use mindless' idea of keyword / tag albums somehow.
i'll test the module tomorrow.
Posts: 33
Excellent. Thanks for sharing!
I've installed it on my test site and it seems to work fine. A couple of comments.
* After installing, be sure to add the tags to your themes. Otherwise, you won't see them. (I'm new to Gallery2 and missed this initially.)
* I must be missing a permissions thing, because as I'm using it right now only the tag author can see the tags. I'd like to make tags visible to all users of the site.
* Can more than one tag be added at a time?
Regards and thanks!
Jeremy
Posts: 33
Here's a possible bug in modules-tag:
Adding tags to images in the top-level of Gallery worked, but when I tried to add some to images in an individual album, they did not display. The tags appear to have been attached to the images because the thumbnail of the image accurately displays something like:
DayForNight02_jpg
Date: 12/02/2005
Owner: Screenpedia Administrator
Views: 13
Tags: 4
However, when you go to the full-sized image, tags are not listed.
Regards,
P.S. I tested this while logged in as administrator so I don't think it's a permissions issue.
P.P.S. The first image I tried this on had a comment already attached, but I don't think that's the problem. When I tried another image without a comment, it also did not display the tags.
Jeremy Butler
www.ScreenSite.org
www.TVCrit.com
www.AllThingsAcoustic.org
Posts: 32509
- when developing php applications, set error_reporting to E_ALL in php.ini
- i had to copy GNUmakefile's from the current comment module to make it work with the current nightly snapshots (the database schema has changed)
- getting: "Notice: Undefined variable: totalTags in /var/www/localhost/htdocs/clean/gallery2/modules/tag/Callbacks.inc on line 86"
if no tags have been added yet (added the show tags block to album and photo pages)
- postgres compatibility issue:
postgres7 error: [-1: ERROR: zero-length delimited identifier at or near """" at character 72] in EXECUTE(" SELECT g2_ChildEntity.g_id, g2_Tag.g_tagName, "", "", g2_ChildEntity.g_parentId FROM g2_ChildEntity, g2_Tag, g2_AccessSubscriberMap WHERE g2_ChildEntity.g_id = g2_Tag.g_id AND g2_ChildEntity.g_parentId = g2_AccessSubscriberMap.g_itemId AND g2_AccessSubscriberMap.g_accessListId IN (17,18,20,167) AND (g2_Tag.g_tagName LIKE '%door%') ORDER BY g2_Tag.g_tagName DESC, g2_ChildEntity.g_id DESC LIMIT 20")
when clicking on an existing tag (search)
the problem is this code
in GalleryTagSearch.class, which doesn't make a lot of sense
- when deleting a tag, i get "Notice: Undefined index: tag in /var/www/localhost/htdocs/clean/gallery2/g2data/smarty/templates_c/%%672277621/%%38^385^385FFEDD%%Tag.tpl.php on line 4" in the delete tag view
(but deleting works)
- rewrite rules: i tested the module with url rewrite active, but the rewrite rules were not used.
@Jeremy Butler:
- @permissions, go to your top album, click "edit permissions", add the tag permissions to the everybody group
- @adding more than one tag at a time: no
- @bugs: can't reproduce what you think is a bug. just add the show tags block to album and photo pages in site admin -> themes and it does exactly what it should
Posts: 33
Hmmmm... I'm new to Gallery so I may have done this wrong, but I went to "New Group Permission" and added the tag permissions to Everybody. Permissions now look like:
Group name Permission Action
Everybody [core] View all versions
Everybody [tag] View tags
Site Admins All access
But the tags are still not displayed. What have I missed?
Thanks!
Posts: 32509
what did you miss?
probably the view tags block. you must add it to photo and album pages separately.
Posts: 33
Still mystified about the lack of tags.
And, something new, when I'm looking at the Album permissions page (trying to figure out how I've messed up the permissions), and I click "View Tags" in the sidebar, I get:
Error Detail -
Error (ERROR_BAD_PARAMETER) : /www/html/spgallery/modules/core/classes/../../../modules/tag/ShowTags.inc
* in modules/core/classes/GalleryView.class at line 158 (gallerystatus::error)
* in modules/core/ItemAdmin.inc at line 130 (galleryview::loadview)
* in modules/core/classes/GalleryTheme.class at line 688 (itemadminview::loadtemplate)
* in modules/core/classes/GalleryView.class at line 285 (classictheme::loadtemplate)
* in main.php at line 287 (itemadminview::doloadtemplate)
* in main.php at line 87
* in main.php at line 80
Jeremy Butler
www.ScreenSite.org
www.TVCrit.com
www.AllThingsAcoustic.org
Posts: 33
Hey, it started working!
That is, the tags started showing up in the photo pages within an album.
I don't know if this is what did the trick, but I shifted from one theme to another and then back to the original (Matrix). After going through that process, the tags began showing up!
Jeremy Butler
www.ScreenSite.org
www.TVCrit.com
www.AllThingsAcoustic.org
Posts: 32509
dbchip2000
i hope i didn't scare you off with my mini review
it would be great if you could continue your work on this module. i'm sure it will one of the most popular modules, once it's in a mature state (add multiple tags at once, virtual tag album support using mindless' work, ..).
Posts: 5
this is kinda great
Posts: 7
yes.. this is an essential feature for me - I'm waiting till it's finished (or until I can find other open source gallery software that supports it) to install g2
Posts: 2
Sorry to bump a relatively old thread, but I was curious as to where this has gone, if anywhere?
Posts: 8601
this thread is the only thing i've seen about work on this feature.. so, not much progress.
Posts: 219
Fingers crossed, though. It's the most requested item in the feature vote (1204624 - not counting bulk watermarking as that is done and closed now). Probably the most requested on the forums, too.
Whoever adds this essential feature is going to be a popular person!
Posts: 132
Have this gotten any development lately at all?
Posts: 7
this sourceforge message has some info on the project: http://sourceforge.net/mailarchive/message.php?msg_id=12601674
Posts: 35
can you update your module tag please ?
Posts: 132
I have downloaded this module and test it with a 2.0 version. I ahve to say it really does do exactly what Tag are suppose to. Perhaps just a few more improvement and it will be exactly like how Flickr's tag work.
Can anyone try make this compatiable with 2.1?
Thanks!
Posts: 4
I've started work on a better Tags module that will replace the old one I attached a long time ago. Hopefully soon...
-Danny
Posts: 132
I can only say I will eagerly await. My skill in coding is still too low to try modifies complex module like this. Thank you for your work so far! I love it!