Index: tagadelic.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/tagadelic/tagadelic.module,v
retrieving revision 1.16
diff -u -r1.16 tagadelic.module
--- tagadelic.module	18 Dec 2005 12:01:35 -0000	1.16
+++ tagadelic.module	20 Dec 2005 13:52:21 -0000
@@ -58,6 +58,21 @@
 }
 
 /**
+ * Implementation of hook_settings
+ */
+function tagadelic_settings() {
+  $options = array('weight,asc' => t('by weight, ascending'), 'weight,desc' => t('by weight, descending'), 'title,asc' => t('by title, ascending'), 'title,desc' => t('by title, descending'), 'random,none' => t('random'));
+  $form['tagadelic_sort_order'] = array(
+    '#type' => 'radios',
+    '#title' => t('Tagadelic sort order'),
+    '#options' => $options,
+    '#default_value' => variable_get('tagadelic_sort_order', 'title,asc'),
+    '#description' => t('Determines the sort order of the tags on the freetagging page.'),
+  );
+  return $form;
+}
+
+/**
  * menu callback renders a tagadelic page
  */
 function tagadelic_page_chunk() {
@@ -185,8 +200,21 @@
     $tags[$key]->weight = 1 + floor($steps * ($value->count - $min) / $range);
   }
 
-  // Sort by title
-  usort($tags, "_tagadelic_sort_by_title");
+  list($sort, $order) = explode(',', variable_get('tagadelic_sort_order', 'title,asc'));
+  switch ($sort) {
+    case 'title':
+      usort($tags, "_tagadelic_sort_by_title");
+      break;
+    case 'weight':
+      usort($tags, "_tagadelic_sort_by_weight");
+      break;
+    case 'random':
+      shuffle($tags);
+      break;
+  }
+  if ($order == 'desc') {
+    $tags = array_reverse($tags);
+  }
   return $tags;
 }

