Hi-

I am trying to figure out the best way to oragnize my Gallery 2 by drupal catergories. I was thought about using the custom fields in Gallery2 and then calling those from Drupal, but I think the quickest would be to use the Gallery2 keyword albums.

I was hacking at the taxonomy_menu module and figured out a way to display keyword albums using Drupal's taxonomy.

taxonomy_menu:

  $access = user_access('access content');

    foreach (taxonomy_get_vocabularies() as $vocabulary) {
      if (variable_get('taxonomy_menu_show_'. $vocabulary->vid, 1)) {
        $path = 'taxonomy_menu/'. $vocabulary->vid;
        $items[] = array('path' => $path, 'title' => t($vocabulary->name),
          'callback' => 'taxonomy_menu_page', 'access' => $access,
          'weight' => $vocabulary->weight);

I changed that to:

$access = user_access('access content');

foreach (taxonomy_get_vocabularies() as $vocabulary) {
      if (variable_get('g2Keyword_menu_show_'. $vocabulary->vid, 1)) {
        $path = 'http://localhost/main/key/'. $vocabulary->name;
        $items[] = array('path' => $path, 'title' => t($vocabulary->name),
          'callback' => 'g2Keyword_menu_page', 'access' => $access,
          'weight' => $vocabulary->weight);

Here is an example-

If my taxnomy is:

Photograpy
-Animals
-Dogs
-Cats
-People
-Couples
-Babies
Artwork
-Portraits
-Couples
-Babies

I have an image that has these keywords: photography animals dogs

I would like to:

  1. Using Drupal's taxonomy, I would like to organize my Gallery2 keyword albums (call the module g2keyword_menu) so that when you click "photography" you would be shown all items with the Keyword "photography". (I have been able to do this as above.)
  2. When you click on Animals. You should get a keyword album for all the items that have the keyword "photography animals". This doesn't work for animals because I end up with http://localhost/main/key/photography/9. This should be http://localhost/main/key/photography+animals.
  3. When you click on Animals, the title should be switched to just showing animals (not Keyword album: Photography Animals).
  4. The breadcrumb trails should be: home>gallery>photography>animals (not home>gallery>keyword album: photography animals)
  5. Also, the menus should expand the way taxonomy_menu expands when you click on a parent category.

Finally, I am thinking that it may make more sense to use Gallery2 tagging instead.

Any thoughts?

Any help would be great!

Gallery 2.2.1
Drupal 5.x
Drupal taxonomy_menu module
Gallery2 keyword album module

URL rewrite is on for both.

Comments

pinxi’s picture

Title: hacking taxonomy_menu to create hierarchical keyword albums » using tags and hack of taxonomy_menu to get hierarchal keyword albums
Category: support » feature

I have been talking with the programmers over at Gallery2 about the development of the taggin module. See tags codex.

I am trying to figure out a way to link Drupal to Gallery 2 using tags in a hierarchical manner. For example, say you have a tag called Canada and wanted to view flowers in Canada, you would have:

  • The url would be example.com/tags/Canada/flowers. Which would return call items that are tagged Canada AND Flowers
    (or example.com/?q=gallery&g2_view=tags.VirtualAlbum&g2_tagName=Canada/flowers without URL rewrite.) .
  • The title just be "flowers Canada". (not Canada/flowers)
  • The breadcrumb be gallery>>Canada>>Flowers. (therfore, if someone clicks "Canada" it would show the tag-album "Canada" with the url: example.com/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: example.com/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".

The second part of this would be to create the category list using Drupal's taxonomy. I hacked the taxonomy_menu module so you get the following:

  1. If you set up white as a subcategory of flowers as a subcategory of Canada and you keyworded several items "Canada/flowers/white"
  2. when you clicked on the menu item "white" which is a submenu of "flowers" which is a submenu of "Canada" you get a keyword album called "Canada/flowers/white" with a url is
    example.com/?q=gallery&g2_view=keyalbum.keywordAlbum&g2_keyword=Canada/flowers/white

If you click on menu item flowers,
the url is example.com/?q=gallery&g2_view=keyalbum.keywordAlbum&g2_keyword=Canada/flowers.

Please see the code below. I was using keywords before finding the tagging module which is a lot more powerful and scaleable. Still the idea is the same for tagging.

Currently, I have the following issues:

  1. Current version of tagging doesn't support queries for multiple tags (see tags codex.)
  2. Becuase keyword albums are only one level, the breadcrumb trail doesn't display sub categories (it is gallery>>Canada/flowers/white not gallery>>Canada>>flowers>>white.)
  3. The title is also messed up. It is Keyword Album=Canada/flowers/white not Keyword Album=white flowers Canada (or just simply Keyword Album=white.)
  4. doesn't seem to like URL rewrite.

Any help would be most appreciated!

function g2keyword_menu_menu($may_cache) {
  $items = array();

  if ($may_cache) {
   $items[]= array (
      'path' => 'admin/settings/g2keyword_menu',
      'title' => t('g2keyword menu settings'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('g2keyword_menu_admin_settings'),
      'access' => user_access('administer site configuration'),
      'description' => t('Global configuration of g2keyword menu functionality.'),
      'type' => MENU_NORMAL_ITEM,
    );

    $access = user_access('access content');

    foreach (taxonomy_get_vocabularies() as $vocabulary) {
      if (variable_get('g2keyword_menu_show_'. $vocabulary->vid, 1)) {
        $path = 'http://localhost/main/?q=gallery&g2_view=keyalbum.keywordAlbum&g2_keyword='. $vocabulary->name;
        /*changed from $path = 'taxonomy_menu/'. $vocabulary->vid;*/
        $items[] = array('path' => $path, 
          'title' => t($vocabulary->name),
          'callback' => 'g2keyword_menu_page', 
          'access' => $access,
          'weight' => $vocabulary->weight);

        $tree = taxonomy_get_tree($vocabulary->vid);
        $old_depth = -1;
        $old_path = $path;

        foreach ($tree as $term) {
          if ($term->depth <= $old_depth) {
            $slashes_to_remove = $old_depth - $term->depth + 1;
            for ($i = 0; $i < $slashes_to_remove; $i++) {
              $old_path = substr($old_path, 0, strrpos($old_path, '/'));
            }
          }
          $path = $old_path .'/'. $term->name;
          /*changed from $path = $old_path .'/'. $term->tid;*/
          $old_depth = $term->depth;
          $old_path = $path;
          $items[] = array('path' => $path, 
           'title' => t($term->name),
           'weight' => $term->weight);
        }
      }
    }
  }

  return $items;
}