Tag Management

If someone has some spare time...

I am trying to create or thinking of creating a plugin that would help with tag management.

What I would like to do is have a textarea on the album and/or image edit area. A place where you could type in relevant tags, hit save, and presto. instead of adding a tag to the system and then selecting that tag for your album. Make it a one step process instead of a two step.

Looking at things it seems tags are not inserted into the album or image tables. They have their own table and another "obj_to_tag" table that links it all.

Here is some logic I have come up with....

`
$newtag = $POST_DATA
for each $newtag
Query ZP_Tags SELECT from 'name', build array (strip case)
if $newtag == $sql_array
$tag_id = sql array(get 'ID' where 'name')
sql create new record in 'ZP_obj_to_tag'
sql insert(tagid=$tag_id, type=albums, objectid=$ZP_CurrentAlbum)

else

sql create new record in 'ZP_Tags'
sql insert(name=$newtag)
sql query('ZP_tags' select 'id' from where 'name' = $newtag)
$tag_id = sql array
sql create new record in 'ZP_obj_to_tag'
sql insert(tagid=$tag_id, type=albums, objectid=$ZP_CurrentAlbum)
`
Something like that anyway. Basically for each tag in the text area it will search zp_tags to see if it already exists, if it does it will get the tag id and create a link to the album or image in zp_obj_to_tag. If the tag doesn't exist it will create the tag record and then link it. It will do this for each tag entered.

My scripting is very limited and I bet someone could whip this up in 10 minutes where it would take me 2 weeks to get it to work.
«1

Comments

  • Would it not be just as easy to keep two tabs open in your browser--the tags tab and the album/image you are editing?
  • Even a split screen approach still makes it a 2 step process if the tag doesnt already exist. Even if it does already exist, for galleries that have a lot of images/albums and/or a lot of tags it's a huge pain in the butt to have to search through and find the right tags out of hundreds or even thousands.

    If something like this existed the tags could be done very quickly, very effeciently, and very easily.

    Even the forum software here lets you add tags "on-the-fly" when creating a post.
  • This "tag texarea" that im suggesting could even be put on the upload screen too. That way tags could be added during the upload.
  • acrylian Administrator, Developer
    could even be put on the upload screen too
    It then would be much more efficient to add the tags via exif/xmp management tools before uploading. Then they would also be attached to the images directly.

    Regarding the idea, feel free to start on that plugin, we appreciate every third party stuff. There can't be enough plugins. Although I personally think that the idea has something, I will not give it a shot for now due to lack of time and similar things.
  • The best approach to adding tags at upload time is to put them in the image metadata.
  • ok, thus far ....

    `
    <?php

    mysql_connect("xxxx", "xxxx", "xxxxx");
    mysql_select_db("xxx");

    $newtag = $_POST['tag'];
    $album = $_post['album'];

    $albumid = mysql_query('SELECT ".zp_albums.".id FROM zp_albums WHERE ".zp_albums.".name = $album);

    $result = mysql_query("SELECT * FROM "zp_tags".name);
    $row = mysql_fetch_array( $result );
    if $newtag == $row['name'] {
    mysql_query("INSERT INTO zp_obj_to_tag (tagid, type, objectid) VALUES('$row['id'], 'albums', '$albumid')")
    }
    else {
    mysql_query("INSERT INTO zp_tags (name) VALUES('$newtag')");
    $tag_id = mysql_query('SELECT ".zp_tags.".id FROM zp_tags WHERE ".zp_tags.".name = $newtag);
    mysql_query("INSERT INTO zp_obj_to_tag (tagid, type, objectid) VALUES('$tagid, 'albums', '$albumid')");
    }
    ?>
    `
    Crude I know and a couple of things missing, but I could really use some feedback. I havent tested it yet ...

    Basically testing this would consist of creating a simple form that posts an album folder name and desired tags to this script.

    I didn't put a `for each` statement in it yet as I am not sure you can build an array from a single field of a form ... such as tag1, tag2, tag3, all being passed to the script via post individually... Would you have to specify in the script a deliminator? I dunno... Maybe you can help with that....

    See any issues with what I have?
  • Also....

    `
    if $newtag == $row['name']
    `
    Will case be an issue here?

    if `$newtag = this` will it match `ThIs`??? Do I need to strip case on both to avoid duplicate tag entries?
  • Personally, I like sidecar XMP approach, and I do not use any other tagging method.

    Should something go wrong online, all my tags are already there together with images on an offline location.

    And I can edit XMP in any text editor (using Notepad++ with XML syntax highlighting).

    This is template that I use. It's very simple, tags go in "<rdf:li></rdf:li>" and picture description in "<photoshop:Headline></photoshop:Headline>":

    `




















    `
  • acrylian Administrator, Developer
    Well, isn't it easier to use the metadata in the image itself. Photoshop can do that, Bridge and dozens of other image management systems as well.
  • Personally, I like the way I do it because I can edit text of XMP file virtually anywhere, a smartphone would be a good example. And I do not need to fire up bulky Photoshop just to add/amend tags or description.
  • acrylian Administrator, Developer
    Ok, each his own...;-) (Of course there are less demanding programs than PS..;-))
  • Sabyre:
    You really should be using the Zenphoto DB functions. No need to connect to the database, for instance, since that is done if you load the functions.php script. Also your way is subject to several security issues:

    SQL injection, Cross site request forgeries at least.

    Also, tage are case insensitive.

    Perhpas you could incorporate makar's approach and create the XMP sidecar? In fact, if you could create that on the browser client it could be uploaded with the image.

    Or just use the object model to store the tags.
  • And it's wonderful that you have a system that you like, unfortunately something like that would not work in my situation as I don't retain my images.

    What i need is exactly what I am working on and still hoping to get some feedback on my code.
  • acrylian Administrator, Developer
    You just got some feedback to your code...
  • What do you mean that you do not retain the images. Then what are the tags associated with? Anyway, nothing in the comments presumes that the images are retained, only that they are there when you wish to add the tags. (That seemed to be stated in your initial post.)
  • Oops,

    I'm sorry perhaps I misunderstood. I was under the impression that the sidecar thing was for adding tags offline and that some sort of editing program would need to be used. My albums are uploaded from remote locations (e.g. http://example.com/album.zip) I never have a local copy of them.

    I was looking for a way to add tags to the albums more effeciently while they are online in my gallery. The script I was working on would do this for me.

    The DB connection in the script is because I wrote this without incorporating into ZP. I do plan to make a plugin out of it, but what you see right now is a crude code for functionality and demonstration.

    Acrylian, I must have posted as abillard was replying. I appologize.

    I know tags are case sensitive, what I was wondering was more of the php comparision...

    `if $newtag == $row['name']`Will case be an issue here?

    if $newtag = this will it match ThIs??? Do I need to strip case on both to avoid duplicate tag entries?

    Meaning, is case important to a php string comparison?

    The other question I had was is it possible to pass an array from a form post?

    example: If my form has a text area and I comma seperate the tags in that text area when its passed to the script how can I make a loop so it will process each comma seperated tag?

    I know you guys get busy, and I'm not trying to be an annoyance. Sometimes I feel like I am bothering people when I post here on the forums. Sometimes the responses seem curt.

    I'm really just trying to contribute, whether it be a simple question or advice, every post on these forums has the potential to help others in the future.

    I am very greatful that you guys created Zenphoto, I think it is a wonderful project. I am simply trying to contribute. I know what I am trying to do here with my script will be helpful to a lot of people that use zenphoto, I have seen the posts where people have requested this very functionality.

    Again, if I have caused any problems, I am sorry.

    Thank you.
  • String comparison in PHP is case sensitive, so you will have to compare them in such a way. I would suggest using `strcasecmp()`. (There are many references to this method being faster than `strtolower()`.)

    Why would you want to pass an array? Simply pass the comma delimited string via `$_POST` and then `explode()` it. There's really no need to process it before POST, I think.

    All contributions are appreciated, and this support forum is here for users like you to get help. The above posters were just trying to provide alternatives, but of course you know what works best for you and your website.

    What you're working on sounds like it has quite the potential to add convenience to the tagging process. I look forward to trying it out once you've released it as a plugin.
  • Excellent, thank you for the reply.

    I didn't know of a way to pass the comma seperated tags from the form so it wouldn't try to treat everything in the text area as a tag. So it wouldn't think "tag1, tag2, tag3" was all one tag.

    I will look at your suggestions. Thanks again for the advice!
  • acrylian Administrator, Developer
    I agree on the `explode()`. I also agree it has potential as other CMS do tag adding in similar ways as well (I have no time to look into this myself, even because of other zp related stuff). However, my collegue sbillard apparently does not agree on that...:-)

    But that is exactly why have a plugin system now for everyone to add what he needs.
  • OK, cool... So I can do...

    `
    $tags = $_POST['tags'];
    $newtag = explode(",", $tags);
    foreach($newtag){
    `
    for the comma seperated tags.

    and....

    `
    if (strcasecmp($newtag, $row['name']) == 0) {
    `
    for the case insensitive comparison?
  • acrylian Administrator, Developer
    `foreach($newtag as $something) {` of course.

    I think it might be better to use `strtolower()` before checking as you otherwise might accidentally store double ones in the database later as you have still the value with the case difference.
  • Good point; I didn't think of that. Whether it's faster to use `strtolower()` or `strcasecmp()` + `array_unique()`, I'm not sure, but `strtolower()` is probably easier. :)
  • Also you might wish to have code that will deal with user input strings that might wish to include commas in their tag. (Or you could just tell them that is not allowed.)
  • acrylian Administrator, Developer
    I think normally tags are used as "keywords" and rarely include a comma. Of course a more rarely used `;` could be used as a delimiter as well or a `|`.
  • `
    foreach($newtag as $something)
    `
    Does that mean I have to reference $newtag as $something anywhere else in the loop? Does it change the variable?

    Would it be better to use

    `
    while($newtag = >0) {
    `
  • You probalby need to review your PHP syntax. http://www.php.net/manual/en/control-structures.foreach.php
  • acrylian Administrator, Developer
    Also I get a little the impression that you should learn a few more php basics before proceeding. This forum is of course not for learning these...
  • Understood, I know enough php/mysql to get me in trouble and I have enough tenacity to get what I want. I work at something and learn as I go until it has the desired effect.

    I created this on my own and it works fabulously:

    `
    <?php
    mysql_connect("xxx", "xxx", "xxx");
    mysql_select_db("xxx");

    $album = $_POST['album'];
    $tags = $_POST['tags'];

    $sqlalbumid = mysql_query("SELECT id FROM zp_albums WHERE folder ='" . $album . "'");
    $albumid = mysql_fetch_array( $sqlalbumid );

    $newtag = explode(",", $tags);
    foreach($newtag as $key){
    $otags = mysql_query("SELECT * FROM zp_tags");
    $otag = mysql_fetch_array( $otags );
    if (strcasecmp($key, $otag['name']) == 0) {
    mysql_query("INSERT INTO zp_obj_to_tag (tagid, type, objectid) VALUES ('" . $otag['id'] . "', 'albums', '" . $albumid['id'] . "')");
    }
    else {
    mysql_query("INSERT INTO zp_tags (name) VALUES('" . $key . "')");
    $newtagid = mysql_query("SELECT id FROM zp_tags WHERE name ='" . $key . "'");
    $tagid = mysql_fetch_array( $newtagid );
    mysql_query("INSERT INTO zp_obj_to_tag (tagid, type, objectid) VALUES('" . $tagid['id'] . "', 'albums', '" . $albumid['id'] . "')");
    }
    }
    ?>
    `
    I will hide it behind a password protection and use it, I need to look more at the backend for the admin area and I will make this a plugin.

    Thank you for all the feedback.
  • oops, for my purposes i will need to write something that checks if the folder exists....
  • Got it...

    added:
    `
    $sqlalbumid = mysql_query("SELECT id, folder FROM zp_albums WHERE folder ='" . $album . "'");
    $albumid = mysql_fetch_array( $sqlalbumid );
    if (strcasecmp($album, $albumid['folder']) <> 0) {
    echo "Album folder " .$album. " does NOT exist, please check the spelling.";
    }

    else {
    `
Sign In or Register to comment.