Personal tools

Talk:Gallery2:Modules:tags

From Gallery Codex

Contents

This module/plugin should be default in gallery2!

Hello! Congratulation Floridave for this module. Basically, I am just wondering how gallery2 could live without this tag functionality until now! (see flickr, del.icio.us or just any Web2.0 site nowadays!)

You did just a perfect job:

1) you added a keyword/tags table in the database! with your crosstable g2_TagItemMap, a clean structure (many-to-many) between the items and the tag is possible, unlike the keyword list that was in the item table (bad initial design in my opinion).

2) the user can add tags to a picture by clicking on existing tags. Yes! this is just the first functionality a keyword/tag list MUST have. Otherwise, the users are just adding many versions of the same tags, with typos ;) Concerning this point, I suggest you show the list of exisiting tags as default in the "edit photo"/ tag tab, instead of having the "popular tags" button. For exemple, you could list the existing tags below the "add" tag line. (just like del.icio.us is doing)

3) tag clouds. This is just soooo web2.0. Must have!

If you need some support for coding, I can php/mysql so tell me where I can help you (see my profile: User: Taglover)

So what else to say. I just suggest that your plugin becomes a default in the gallery2 distribution. This is so crucial!

All the best,

Taglover 15:22, 5 April 2007 (PDT)

Tag cloud ok, but search?

Hi again,

I could activate the tag cloud by clicking on the album-edit-> Theme. Would be nice to be able to activate it from the "Site admin -> tags settings" as well.

Something else: how do I search my tags??

Regards,

Taglover 16:22, 5 April 2007 (PDT)

Multi-tag Virtual Album

This is about the request is for multi-tag albums. I would like to see if this can be done in a hierachical manner. The given example is: "Say you have a tag called Canada and wanted to view flowers in Canada, you would have a link like: /tags/Canada-and-flowers. It would return a virtual album with items that are taged Canada and flowers."

  • What about having it link as /tags/Canada/flowers. Which would return call items that are tagged Canada AND Flowers?
  • Also could the title just be "flowers Canada"? (not Canada/flowers)
  • Finally, could the breadcrumb be gallery>>Canada>>Flowers? (therfore, if someone clicks "Canada" it would show the tag-album "Canada" with the url: /tag/Canada

Another example would be if you wanted to see only white flowers in Canada.

  • You would tag the items, "white", "flowers", and "Canada".
  • The url would be: tags/Canada/flowers/white
  • the breadcrumb would be gallery>>Canada>>flowers>>white. So if you clicked "flowers" it would show you all the items tagged flowers AND Canada.
  • Finally, the title for this could be "white flowers Canada".

I am trying to figure out a way to link Drupal to Gallery,2 in a hierarchical manner, using tags and the above would make things SO much easier.

Multi-Tag Virtual Album for Mysql 5 and upwards

Hey guys,

I changed the VirtualAlbum.inc function getChildIds to get multiple tags to work. its not that clean, but a first effort which works for me. unfortunately it will not work with databases below version 5 as it uses the exists feature to test against multiple tagIds.

comments are welcome...

works like a AND operator, and multiple Tags are queries by using g2_tagName[]=firsttag&g2_tagName[]=secondtag and so on...

cheers,

Oliver

hofburg.com

function getChildIds($userId, $tagName=null) {
	global $gallery;
	$storage =& $gallery->getStorage();

	if (!isset($tagName)) {
	    $tagName = GalleryUtilities::getRequestVariables('tagName');
	}
	if (empty($tagName)) {
	    return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER), null);
	}

	/* Force case-sensitive look-up to make the query use an column index */
	/*obsolete*/
	/*list ($ret, $tagId) = TagsHelper::getTagIdFromName($tagName, true);
	if ($ret) {
	    return array($ret, null);
	}

	if (empty($tagId)) {
	    return array(null, array());
	}*/
	
	/*old behaviour not being able to cope with multiple tags 
	//list ($ret, $query, $data) = GalleryCoreApi::buildItemQuery('TagItemMap', 'itemId',
	//    '[TagItemMap::tagId] = ?', null, null, null, 'core.view', false, $userId);
	*/
	
	/*new behaviour*/
	$ids = $where = array();
	
	if(!is_array($tagName))	{
		$temp_id=TagsHelper::getTagIdFromName($tagName, true);
		$ids[0]=$temp_id[1];
		$where[0] = '[TagItemMap::tagId] = ? ';
	}
	else	{
		for($i=0;$i<count($tagName);$i++)	{
			$temp_id=TagsHelper::getTagIdFromName($tagName[$i], true);
			$ids[$i]=$temp_id[1];
	/*
	Following Subquery BREAKS gallery2_prefix!!! g_tagId is referenced directly, as well as g2_TagItemMap
	*/
			$where[$i] = 'EXISTS(SELECT g_tagId FROM g2_TagItemMap AS temp WHERE temp.g_tagId = ? AND temp.g_itemId=g2_TagItemMap.g_itemId)';
		}
	}

	list ($ret, $query, $data) = GalleryCoreApi::buildItemQuery(
		'TagItemMap', 'itemId', implode(' AND ', $where),
		null, null, null, 'core.view', false, $userId);
	
	if ($ret) {
	    return array($ret, null);
	}

	list ($ret, $searchResults) = $gallery->search($query, array_merge($ids, $data));
	if ($ret) {
	    return array($ret, null);
	}
	$itemIds = array();
	while ($result = $searchResults->nextResult()) {
	    $itemIds[] = $result[0];
	}

	return array(null, array_unique($itemIds));
    }

Hmmm .....

I didn't realize there was some discussions going on in here :-) !

@taglover:

- You can now search the tags via the regular gallery search a couple search boxes (1 in the Tag Cloud, 1 i the edit interface) - As for automatically update the Theme settings from the site admin, it's not possible yet without some pretty dirty hacks (which I have done for the Map Module but i don't want tot redo)

@Anonymous right underneath taglover's comments, yes this will be possible and it will be in the next version ;-)

See you all ! Termite

make tag entry possible on the "caption edit page" and some other ideas

Hi. I just finished testing this plugin and the main difficulty I had was initially entering tags. Here's my short wish list:

--tag entry possible while using the upload applet or "from web browser" --tag entry on the page you get when clicking "edit captions". You're entering everything there anyway--it's kind of a pain to have to access a different page to add tags. --when you have the field for entering new tags, the existing tags were listed somehow so you don't get people entering "sue" when there's already a "suzanne" tag, for example. Maybe an ajaxy thing that slides down when the cursor is put in the new tags field?


Aside from that, thanks so much for all the work you've done on this. It's a huge benefit and addition to g2.

Valerie

Tag Cloud Link?

I activated the option "Show the tag Cloud Link" in the Tag Settings. I expected a link to a tag cloud page popping up somewhere easy to find, but I can't find anything of the kind. What am I missing? Anke 00:58, 11 September 2007 (PDT) Yah, found it, right next to the Slideshow link in visitor mode. oh, well.

Tag Cloud Privacy Issues

Tags that are unique to images (or pictures in albums) that are access-restricted show up in the tag cloud, even to anonymous viewers. Can tag clouds be generated in such a way to include only the tags associated with images a user has permission to see? Thanks...

Separate settings for sidebar cloud vs "large" cloud

It would be nice to have different settings for the sidebar cloud (e.g., I might choose smaller fonts, fewer tags, etc.) and the "large" cloud (e.g., I might include larger fonts, more tags, etc.). I expect this would take the form of separate tab-pages for each type of sidebar. (Oh, on a related note, on the "General Settings" tab, the following is misspelled: "Amount to limit to (only valid is [sic] above is checked)". Thanks!

(Don't you hate when you create something neat, and all people want to do is say how insufficient for their needs it is? To remove some of that sting I say, "Thanks! You're doing a great job!")

Make Virtual Tag Albums appear within the gallery?

First, I want to say that I love this module. I'd like to see tagging completely replace the concept of folders (since the concept of tagging provides a superset of folder functionality).

For the time being, though, I know you can display a virtual tag album using URL/tag/mytag, but is there a way to actually have a tag album item itself actually displayed? E.g. ideally, I'd like to get rid of all "real albums" (for non-admins, anyway), and have the front page of my gallery display a list of Tag Albums I've specified such that they look just like (or at least almost just like) regular albums, and they can click it to see the pictures tagged that way. This will be addressed by the great highly-flexible dynamic albums being discussed elsewhere, but is there a simple way of doing this just for tags for now?

Sorry if I'm missing the obvious here somewhere.

Manganeez 21:45, 15 November 2007 (PST)


Realized you can sort-of pull this off with the linkitems module. Just put in your tag URL as the "external" URL. It's pretty kludgy - you have to make your own thumbnail manually, for example, by it's one possibility. I'm hoping there's something that works a little better.

Manganeez 11:50, 16 November 2007 (PST)

set max amount of tags in cloud

For integrating the cloud into the sidebar, it seemed convenient to limit the maximal number of tags used for cloud generation. Here's my solution, quick & dirty:

TagsHelper.class

file /modules/tags/classes/TagsHelper.class $Revision: 1087 $ line 154:

    /**
     * Get a list of tags and number of occurrences
     *
     * @param boolean $includeNullCount (optional) True to include tags without instances (default false)
     * @param boolean $maxCount (optional) Limits number of tags retrieved
     * @return array object GalleryStatus a status code
     *               array of TagNames or array (string tagname => int instances, ...)
     */
    function getTagListWithTagCount($includeNullCount=false,$maxCount=true) {
	global $gallery;
	$storage =& $gallery->getStorage();

	list ($ret, $as) = $storage->getFunctionSql('AS', array());
	if ($ret) {
	    return array($ret, null);
	}
	if ($maxCount) { 
		list ($ret, $maxCount) = GalleryCoreApi::getPluginParameter('module','tags','CloudTaglimit');
		$LimitToMax = "LIMIT $maxCount";
	}

	$query = "
	    SELECT
	      [TagMap::tagName],
	      COUNT([TagItemMap::itemId]) $as TagsCount
	    FROM
	      [TagMap], [TagItemMap]
	    WHERE
	      [TagMap::tagId] = [TagItemMap::tagId]
	    GROUP BY
	      [TagMap::TagName]
	    ORDER BY
	      TagsCount DESC, [TagMap::tagName] ASC
	    $LimitToMax
	";

AdminSettingsTags.inc

file /modules/tags/AdminSettingsTags.inc $Revision: 1060 $ line 90:

			foreach (array('TagCloudLimit','classNumber', 'tagCssClass', 'tagCloudTemplate') 
				as $setting) {
			    $ret = GalleryCoreApi::setPluginParameter('module', 'tags', $setting,
				$form[$setting]);
			    if ($ret) {
				return array($ret, null);
			    }
			}
			$ret = GalleryCoreApi::setPluginParameter('module', 'tags',
			'CloudTaglimit', $form['CloudTaglimit']);
			if ($ret) {
				return array($ret, null);
			}

AdminSettingsTags.tpl

file /modules/tags/templates/AdminSettingsTags.tpl $Revision: 1054 $ line 126:

<div class="gbBlock">
     <table class="gbDataTable">
        <tr>
           <th><label for="tagCloudTemplate">{g->text text="Select a Template to use"}</label></th>
           <td><select id="tagCloudTemplate" name="{g->formVar var="form[tagCloudTemplate]"}">
             <option value="DefaultTextTemplate">{g->text text="Text Template"}</option>
           </select>
		   </td>
        </tr>
	<tr>
           <th><label for="CloudTaglimit">{g->text text="Max amount of tags in the cloud"}</label></th>
           <td><input id="CloudTaglimit" type="text" width="10" name="{g->formVar var="form[CloudTaglimit]"}"
           {if $Settings.LimitCloudTag}
              value="{$Settings.CloudTaglimit}"
           {/if}
           />
           {if isset($form.error.badlimit)}<span class="giError">{g->text text="Please enter a valid limit"}</span>{/if}
           </td>
        </tr>
     </table>
  </div>

I just copied and renamed the PopularTaglimit and LimitPopularTag fields of the admin section (Site-Administration->Tag Settings), added the CloudTaglimit integer to the tags module configuration settings (setPluginParameter('module', 'tags','CloudTaglimit') and used this information to tweak the SQL SELECT statement that retrieves tags from the db for cloud generation.

Hope this helps. Suggestions welcome. Cheers, Fluidspace

Moving items via tags

I very much wanted to be able to move and modify items based on their tags. An example of the usefulness of this is the following: I have a set of travel photos that I want to make available on a commercial gallery installation. Most of these are photos that I want anyone to be able to purchase (e.g. landscapes, street photography, etc.), but a subset are photos that I want to only be available to the other people in my tour group. My desired interaction for this is that a guest user will view the site and only see the general items, whereas a member of the tour group can use a login I've given and at that point they will see all of the photos in chronological order, both the public and private ones, and be able to purchase any of them.

After the making the following modifications, I am able to

  1. In lightroom, I tag all of the photos "commercial", but tag a subset of the photos "tour group"
  2. I export to jpg and upload the photos, then run the "copy keyword to tags" maintenance routine. (Is there any better way to get the tags embeded in the jpg exif into gallery as tags instead of keywords?)
  3. I create a temporary album in gallery
  4. I go to move photos, and choose "add items matching 'tour group'", which selects the appropriate photos. Before I actually move the photos, I am able to refine which photos end up getting moved
  5. I go to the destination folder and remove Everybody's permission to view the photos, then I give another user permission to view the photos
  6. I move all of these photos back to the original folder and delete the temporary folder

I would have liked to modify the permissions administration pages directly, but this seemed like an easier way to implement the permissions function (albeit indirectly), and it allows moving by tags as a side benefit.

These modifications are to the gallery core itself -- I'm not sure whether it's possible to modify the necessary pages with only modifications to a module? At the very least, there should be some code to check whether a user even has the tags module before running all of this code, but I wasn't sure how to implement that.

Here are the diffs (from Gallery 2.2.6): modules/core/ItemMove.inc:

20a21,22
> GalleryCoreApi::requireOnce('modules/tags/classes/TagsHelper.class');
> 
227c229,234
< 	}
---
> 	} else if (isset($form['action']['addTaggedImages'])) {
> 	    $page = GalleryUtilities::getRequestVariables('page');
> 	    $results['delegate']['itemId'] = $itemId;
> 	} else if (isset($form['action']['removeTaggedImages'])) {
> 	    $results['delegate']['itemId'] = $itemId;
> 	} 
252a260,264
>   $modTag = '';
> 	if (isset($form['action']['addTaggedImages']) || isset($form['action']['removeTaggedImages'])) {
>     $modTag = $form['modTag'];
>   }
> 
281a294,333
> 
>     if (isset($form['selectedIds'])) {
>       $selectedIds = $form['selectedIds'];
>     }
> 
>     if (isset($form['action']['addTaggedImages']) || isset($form['action']['removeTaggedImages'])) 
>     {
>       list ($ret, $peerItems) = GalleryCoreApi::loadEntitiesById($peerIds);
>       if ($ret) {
>         return array($ret, null);
>       }
> 
> 	    foreach ($peerItems as $peerItem) {
> 
>         /* Get the item's tags */
>         list ($ret, $itemTags) = TagsHelper::getTagsByItemId($peerItem->getID()); 
>         if ($ret) { 
>           return array($ret, null); 
>         } 
> 
>         /* Modify array based on tags, if set */
>         $peers[$peerItem->getId()]['tags'] = $itemTags;
>       
>         if ($modTag != '')  // Only set add/remove tagged images was pressed
>         {
>           if (in_array ($modTag, $itemTags)) 
>           { 
>             $peerId = $peerItem->getId();
>             if (isset($form['action']['addTaggedImages'])) { 
>               $selectedIds[$peerId] = 1;
>             } else { 
>               if (isset($selectedIds[$peerId])) {
>                 unset($selectedIds[$peerId]);
>               }
>             } 
>           } 
>         }
>       }
>     }
> 
296,301c348,352
< 		$selectedIds = $form['selectedIds'];
< 		foreach ($peerIds as $peerId) {
< 		    if (isset($selectedIds[$peerId])) {
< 			unset($selectedIds[$peerId]);
< 		    }
< 		}
---
>         foreach ($peerIds as $peerId) {
>           if (isset($selectedIds[$peerId])) {
>             unset($selectedIds[$peerId]);
>           }
>         }
306,311c357,362
< 		foreach ($form['error']['source'] as $id => $tmp) {
< 		    if (!in_array($id, $peerIds)) {
< 			array_unshift($peerIds, $id);
< 			unset($selectedIds[$id]);
< 		    }
< 		}
---
>         foreach ($form['error']['source'] as $id => $tmp) {
>           if (!in_array($id, $peerIds)) {
>             array_unshift($peerIds, $id);
>             unset($selectedIds[$id]);
>           }
>         }
315,318c366,369
< 	    list ($ret, $peerItems) = GalleryCoreApi::loadEntitiesById($peerIds);
< 	    if ($ret) {
< 		return array($ret, null);
< 	    }
---
>       list ($ret, $peerItems) = GalleryCoreApi::loadEntitiesById($peerIds);
>       if ($ret) {
>         return array($ret, null);
>       }
337a389,398
>     /* Get the item's tags */
>     list ($ret, $itemTags) = TagsHelper::getTagsByItemId($peerItem->getID()); 
>     if ($ret) { 
>       return array($ret, null); 
>     } 
> 
>     /* Modify array based on tags, if set */
>     $peers[$peerItem->getId()]['tags'] = $itemTags;
> 
> 
408a470,477
> 
>  	list ($ret, $tags) = TagsHelper::getTagListWithTagCount(true); 
>  	if ($ret) { 
>  	    return array($ret, null); 
>  	} 
> 
>  	$template->setVariable('Tags', $tags); 
> 

modules/core/templates/ItemMove.tpl:

163a164,176
>   
>   <i>
>   (
>   {if ($peer.tags|@count) > 0}
>     {g->text text="Tags: "}
>       {foreach from=$peer.tags item=tag}
>       {$tag} 
>       {/foreach}
>   {else}
>   {g->text text="No Tags"}
>   {/if}
>   )
>   </i>
227a241,265
> {assign var=numTags value=$Tags|@count}
> {if $numTags > 0}
> <div class="gbBlock">
>   <h3> {g->text text="Select By Tags"} </h3>
> 
>   <p class="giDescription">
>     {g->text text="Choose a tag to use to modify the selection"}
>   </p>
> 
>     <select name="{g->formVar var="form[modTag]"}">
>       {foreach from=$Tags  key=TagName item=count}
> 	<option value="{$TagName}">{$TagName}</option>
>       {/foreach}
>     </select>
> 
> </div>
> 
> <div class="gbBlock gcBackground1">
>   <input type="submit" class="inputTypeSubmit"
>    name="{g->formVar var="form[action][addTaggedImages]"}" value="{g->text text="Add Matching Images"}"/>
>     <input type="submit" class="inputTypeSubmit"
>      name="{g->formVar var="form[action][removeTaggedImages]"}" value="{g->text text="Remove Matching Images"}"/>
> </div>
> {/if}
>

Please contact me if there are any questions. I'd be happy to help with getting this officially added, but couldn't find who to contact or what channels to go through to make that happen. Stratvio

advertisements