Drupal taxonomy_menu to display keyword Albums

pinxi

Joined: 2007-01-29
Posts: 10
Posted: Tue, 2007-05-08 15:12

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:

Quote:
$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:

Quote:
$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;
$items[] = array('path' => $path, 'title' => t($vocabulary->name),
'callback' => 'g2Keyword_menu_page', 'access' => $access,
'weight' => $vocabulary->weight);

This makes it so that I can set up g2keyword menu items to display gallery2 keyword albums based on drupal taxonomy structure. But I am now completely stuck (very novice at this stuff). The above works for the main category, but doesn't for all subcategories. Also, the menu doesn't expand the way the taxonomy_menu expands when you click on it.

Any help would be great!

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

 
pinxi

Joined: 2007-01-29
Posts: 10
Posted: Wed, 2007-05-09 17:10

Here is my basic hacks of taxonomy_menu.module-

old hook_menu() for taxonomy_menu:

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

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

    $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);

        $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->tid;
          $old_depth = $term->depth;
          $old_path = $path;
          $items[] = array('path' => $path, 'title' => t($term->name),
            'weight' => $term->weight);
        }
      }
    }
  }

  return $items;
}

I changed that to:

new hook_menu() for g2keyword_menu:

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;
}

Therefore, if my taxonomy is:

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

And I have an image that is keyworded:
Photography/Animals/Dogs

when I click the menu item, "Dogs" it will load and the image will be displayed (the urls is: http://example.com/main/?q=gallery&g2_view=keyalbum.keywordAlbum&g2_keyword=Photography/Animals/Dogs)

If I click "Animals", the same image will show and the url is:
http://example.com/main/?q=gallery&g2_view=keyalbum.keywordAlbum&g2_keyword=Photography/Animals

The nice thing about this is that I only have to add the keyword "Photography/Animals/Dogs" to an item and it will be displayed in the "Dogs", "Animals", and "Photography" keyword albums. This doesn't work in tagging.

Problems are:
1) The title is "Photography/Animals/Dogs".
2) Breadcrumbs don't work.
3) Menus don't expand.

Actually, I would rather use tagging because it would be easier to admin. It would be great if multiple tags could called at once. For example, if you entered:
http://example.com/main/?q=gallery&g2_view=tags.VirtualAlbum&g2_tagName=Photography/Animals
you would get all images that are tagged with Photography AND animals.

Basically, I am trying Drupal's taxonomy, I would like to organize my Gallery2 keyword albums 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.) Rather than using keyword clouds.

BTW, URL rewrite does not work with this hack.