Index: glossary.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/glossary/glossary.module,v
retrieving revision 1.121.2.66
diff -u -p -r1.121.2.66 glossary.module
--- glossary.module	20 Jan 2009 01:55:57 -0000	1.121.2.66
+++ glossary.module	26 Nov 2009 16:54:35 -0000
@@ -252,6 +252,16 @@ function glossary_menu($may_cache) {
   else {
     drupal_add_css(drupal_get_path('module', 'glossary') .'/glossary.css');
 
+    // Add Nodewords term metadata - if they exist
+    if (arg(0) == 'glossary' && arg(1) == 'term' && is_numeric(arg(2)) && module_exists('nodewords')) {
+      $tags = nodewords_get('term', arg(2)); 
+      foreach ($tags as $name => $content) {
+        if (!empty($content)) {
+          drupal_set_html_head('<meta name="'. $name .'" content="'. $content .'" />');
+        }
+      }
+    }
+
     $result = db_query('SELECT format, name FROM {filter_formats}');
     $countem = db_query("SELECT format, COUNT(delta) as count FROM {filters} WHERE module='glossary' GROUP BY format");
     while ($row = db_fetch_array($countem)) {
@@ -409,6 +419,19 @@ function glossary_taxonomy($op, $type, $
   if ($array) {
     _glossary_clear_cache($array['vid']);
   }
+
+  if ($type == 'term') {
+    switch ($op) {
+      case 'insert' : case 'update' :
+        // Use the category info to automatically create an alias
+        $category = (object) $array;
+        if ($category->name) {
+          _pathauto_include();
+          $count = _glossary_pathauto_alias($category, $op);
+        }
+        break;
+    }
+  }
 }
 
 /**
@@ -1808,4 +1831,157 @@ function _alphabar_instruction_default()
   else {
     return t('Click one of the letters above to advance the page to terms beginning with that letter.');
   }
-}
\ No newline at end of file
+}
+
+
+function glossary_term_path($term) {
+  return 'glossary/term/'. $term->tid;
+}
+
+function glossary_pathauto($op) {
+  switch ($op) {
+    case 'settings':
+      $settings = array(
+        'module' => 'glossary',
+        'token_type' => 'taxonomy',
+        'groupheader' => t('Glossary Settings'),
+        'patterndescr' => t('Default Pattern for Glossary terms'),
+        'patterndefault' => 'glossary/[catpath-raw]',
+        'bulkname' => t('Bulk generate aliases for categories that are not aliased'),
+        'bulkdescr' => t('Generate aliases for all existing categories which do not already have aliases'),
+      );
+      // Define the available placeholders
+      $patterns = token_get_list('taxonomy');
+      foreach ($patterns as $type => $pattern_set) {
+        if ($type != 'global') {
+          foreach ($pattern_set as $pattern => $description) {
+            $settings['placeholders']["[{$pattern}]"] = $description;
+          }
+        }
+      }
+
+      $settings['patternitems'] = array();
+      if (variable_get('glossary_page_per_letter', 0)) {
+        $settings['patternitems']['perpage'] = t('Pattern for per-page groups');
+      }
+
+      // Get the enabed vocabs
+      $vids = _glossary_get_filter_vids();
+      if (sizeof($vids) > 0) {
+        foreach ($vids as $vid) {
+          $vocab = taxonomy_get_vocabulary($vid);
+          $fieldlabel = t('Pattern for all %vocab-name paths', array('%vocab-name' => $vocab->name));
+          $settings['patternitems'][$vocab->vid] = $fieldlabel;
+        }
+      }
+      return (object) $settings;
+  }
+}
+
+
+function glossary_pathauto_bulkupdate() {
+  // Get the enabed vocabs
+  $vids = _glossary_get_filter_vids();
+
+  // If none, don't both continuing
+  if (empty($vids)) { return; }
+
+  // Generate some placeholders for the vocab ID's
+  $placeholders = implode(',', array_fill(0, count($vids), '%d'));
+
+  // Do a check to see if (a) glossary_page_per_letter is enabled and (b) We have aliases for all alphabet pages
+  if (variable_get('glossary_page_per_letter', 0)) {
+    // Get any existing letter aliases
+    $query = "SELECT u.src, u.dst FROM {vocabulary} v LEFT JOIN {url_alias} u ON u.src LIKE CONCAT('glossary/', v.vid, '/letter%') WHERE u.src IS NOT NULL AND v.vid IN ({$placeholders})";
+    $result = db_query($query, $vids);
+    $existing = array();
+    while ($row = db_fetch_object($result)) {
+      $existing[$row->src] = $row->dst;
+    }
+
+    // Load the alphabet and digita into an array
+    $letters = variable_get('glossary_alphabet', range('a', 'z'));
+    $letters = array_merge($letters, variable_get('glossary_digits', range(0, 9)));
+
+    // Init count and loop over enabled vocabs...
+    $count = 0;
+    foreach ($vids as $vid) {
+      // ... and letters
+      foreach ($letters as $letter) {
+        // Define a source URL for this vocab & letter
+        $src = 'glossary/'. $vid .'/letter'. $letter;
+
+        // If its not set, create an alias for it
+        if (!isset($existing[$src])) {
+          // Manually create a "category" for the Glossary vocab + an entry for a glossary letter
+          $category = (object)array('vid' => $vid, 'name' => '', 'tid' => '', 'glossary_letter' => $letter);
+          $item_placeholders = pathauto_get_placeholders('taxonomy', $category);
+
+          // Define a new alias and add it to the existing array
+          if ($alias = pathauto_create_alias('glossary', 'bulkupdate', $item_placeholders, $src, NULL, 'perpage')) {
+            $count++;
+            $existing[$src] = $alias;
+          }
+        }
+      }
+    }
+    if ($count > 0) {
+      drupal_set_message(format_plural($count,
+        'Bulk generation of Glossary letter per page items complete, one alias generates',
+        'Bulk generation of Glossary letter per page items complete, @count aliases generated'));
+    }
+  }
+
+
+  // Define the SQL to select any terms from the vocabs which do not have an alias with src="glossary/term/[tid]" associated with them
+  $query = "SELECT tid, vid, name, src, dst FROM {term_data} LEFT JOIN {url_alias} ON CONCAT('glossary/term/', CAST(tid AS CHAR)) = src WHERE src IS NULL AND vid IN ({$placeholders})";
+  // Run the query and limite to the bulk update max - default 50
+  $result = db_query_range($query, $vids, 0, variable_get('pathauto_max_bulk_update', 50));
+
+  // Foreach one, try to generate an alias.
+  $count = 0;
+  $placeholders = array();
+  while ($category = db_fetch_object($result)) {
+    $count += _glossary_pathauto_alias($category, 'bulkupdate');
+  }
+
+  drupal_set_message(format_plural($count,
+    'Bulk generation of Glossary terms completed, one alias generated.',
+    'Bulk generation of Glossary terms completed, @count aliases generated.'));
+
+}
+
+function _glossary_pathauto_alias($category, $op) {
+  $placeholders = pathauto_get_placeholders('taxonomy', $category);
+  $src = taxonomy_term_path($category);
+  if ($alias = pathauto_create_alias('glossary', $op, $placeholders, $src, $category->tid, $category->vid)) {
+    return 1;
+  }
+  return 0;
+}
+
+function glossary_token_values($type, $object = NULL, $options = array()) {
+  $values = array();
+  switch ($type) {
+    case 'taxonomy':
+      if (isset($object->glossary_letter)) {
+        $values['glossary-letter'] = check_plain($object->glossary_letter);
+      }
+      elseif (isset($object->name)) {
+        $values['glossary-letter'] = check_plain($object->name{0});
+      }
+      else {
+        $values['glossary-letter'] = '';
+      }
+  }
+  return $values;
+}
+
+
+function glossary_token_list($type = 'all') {
+  if ($type == 'taxonomy' || $type == 'all') {
+    $tokens['taxonomy']['glossary-letter'] = t('The letter for the glossary letter-per-page sections');
+  }
+
+  return $tokens;
+}
