? .svn
? po/.svn
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	12 Mar 2009 17:36:06 -0000
@@ -409,6 +409,18 @@ function glossary_taxonomy($op, $type, $
   if ($array) {
     _glossary_clear_cache($array['vid']);
   }
+  if (module_exists('pathauto')) {
+    _pathauto_include();
+
+    if ($op == 'insert' || $op == 'update') {
+      $category = (object) $array;
+      $count = _glossary_pathauto_alias($category, $op);
+    }
+    elseif ($op == 'delete') {
+      $category = (object) $array;
+      path_set_alias('glossary/term/'. $category->tid);
+    }
+  }
 }
 
 /**
@@ -1808,4 +1820,92 @@ 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_pathauto($op) {
+  switch ($op) {
+    case 'settings':
+      $settings = array(
+        'module' => 'glossary',
+        'token_type' => 'taxonomy',
+        'groupheader' => t('Glossary term path settings'),
+        'patterndescr' => t('Default path pattern (applies to all vocabularies with blank patterns below)'),
+        'patterndefault' => '',
+        'patternitems' => array(),
+        'supportfeeds' => '',
+        'bulkname' => t('Bulk generate aliases for glossary entries that are not aliased'),
+        'bulkdescr' => t('Generate aliases for all existing glossary items which do not already have aliases'),
+      );
+      $patterns = token_get_list('taxonomy');
+      foreach ($patterns['taxonomy'] as $pattern => $description) {
+        $settings['placeholders']['['. $pattern .']'] = $description;
+      }
+      $vocabularies = taxonomy_get_vocabularies();
+      if (sizeof($vocabularies) > 0) {
+        foreach ($vocabularies as $vocab) {
+          $settings['patternitems'][$vocab->vid] = t('Pattern for all %vocab-name paths', array('%vocab-name' => $vocab->name));
+        }
+      }
+      return (object) $settings;
+    default:
+      break;
+  }
+}
+
+/**
+ * Generate aliases for all glossary items without aliases.
+ */
+function glossary_pathauto_bulkupdate() {
+  // From all node types, only attempt to update those with patterns
+  $pattern_vids = array();
+  $vid_where = array();
+
+  foreach (taxonomy_get_vocabularies() as $vid => $info) {
+    $pattern = trim(variable_get('pathauto_glossary_'. $vid .'_pattern', ''));
+
+    // If it's not set, check the default
+    if (empty($pattern)) {
+      $pattern = trim(variable_get('pathauto_glossary_pattern', ''));
+    }
+
+    if (!empty($pattern)) {
+      $pattern_vids[] = $vid;
+      $vid_where[] = "vid = '%s'";
+    }
+  }
+  $vid_where = ' AND ('. implode(' OR ', $vid_where) .')';
+
+  // Exclude the forums and join all the args into one array so they can be passed to db_query
+  $query = 'SELECT tid, vid, name, src, dst FROM {term_data} LEFT JOIN {url_alias} ON CONCAT("taxonomy/term/", CAST(tid AS CHAR)) = src WHERE src IS NULL '. $vid_where;
+  $result = db_query_range($query, $query_args, 0, variable_get('pathauto_max_bulk_update', 50));
+
+  $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 items completed, one alias generated.',
+    'Bulk generation of glossary items completed, @count aliases generated.')
+  );
+}
+
+/**
+ * Create aliases for taxonomy objects for glossaries.
+ *
+ * @param $category
+ *   A taxonomy object.
+ */
+function _glossary_pathauto_alias($category, $op) {
+  $placeholders = pathauto_get_placeholders('taxonomy', $category);
+
+  $src = 'glossary/term/'. $category->tid;
+  if (pathauto_create_alias('glossary', $op, $placeholders, $src, $category->tid, $category->vid)) {
+    return 1;
+  }
+
+  return 0;
+}
+
+
