summaryrefslogtreecommitdiff
path: root/modules/taxonomy/taxonomy.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/taxonomy/taxonomy.module')
-rw-r--r--modules/taxonomy/taxonomy.module71
1 files changed, 66 insertions, 5 deletions
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 9c4ed8dec..0857e169b 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -24,6 +24,12 @@ function taxonomy_theme() {
'taxonomy_term_page' => array(
'arguments' => array('tids' => array(), 'result' => NULL),
),
+ 'taxonomy_overview_vocabularies' => array(
+ 'arguments' => array('form' => array()),
+ ),
+ 'taxonomy_overview_terms' => array(
+ 'arguments' => array('form' => array()),
+ ),
);
}
@@ -106,7 +112,8 @@ function taxonomy_menu() {
$items['admin/content/taxonomy'] = array(
'title' => 'Taxonomy',
'description' => 'Manage tagging, categorization, and classification of your content.',
- 'page callback' => 'taxonomy_overview_vocabularies',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('taxonomy_overview_vocabularies'),
'access arguments' => array('administer taxonomy'),
'file' => 'taxonomy.admin.inc',
);
@@ -158,8 +165,8 @@ function taxonomy_menu() {
);
$items['admin/content/taxonomy/%taxonomy_vocabulary'] = array(
'title' => 'List terms',
- 'page callback' => 'taxonomy_overview_terms',
- 'page arguments' => array(3),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('taxonomy_overview_terms', 3),
'access arguments' => array('administer taxonomy'),
'type' => MENU_CALLBACK,
'file' => 'taxonomy.admin.inc',
@@ -242,6 +249,47 @@ function taxonomy_del_vocabulary($vid) {
}
/**
+ * Dynamicly check and update the hierarachy flag of a vocabulary.
+ *
+ * Checks the current parents of all terms in a vocabulary and updates the
+ * vocabularies hierarchy setting to the lowest possible level. A hierarchy with
+ * no parents in any of its terms will be given a hierarchy of 0. If terms
+ * contain at most a single parent, the vocabulary will be given a hierarchy of
+ * 1. If any term contain multiple parents, the vocabulary will be given a
+ * hieararchy of 2.
+ *
+ * @param $vocabulary
+ * An array of the vocabulary structure.
+ * @param $changed_term
+ * An array of the term structure that was updated.
+ */
+function taxonomy_check_vocabulary_hierarchy($vocabulary, $changed_term) {
+ $tree = taxonomy_get_tree($vocabulary['vid']);
+ $hierarchy = 0;
+ foreach ($tree as $term) {
+ // Update the changed term with the new parent value before comparision.
+ if ($term->tid == $changed_term['tid']) {
+ $term = (object)$changed_term;
+ $term->parents = $term->parent;
+ }
+ // Check this term's parent count.
+ if (count($term->parents) > 1) {
+ $hierarchy = 2;
+ break;
+ }
+ elseif (count($term->parents) == 1 && 0 !== array_shift($term->parents)) {
+ $hierarchy = 1;
+ }
+ }
+ if ($hierarchy != $vocabulary['hierarchy']) {
+ $vocabulary['hierarchy'] = $hierarchy;
+ taxonomy_save_vocabulary($vocabulary);
+ }
+
+ return $hierarchy;
+}
+
+/**
* Helper function for taxonomy_form_term_submit().
*
* @param $form_state['values']
@@ -412,7 +460,7 @@ function taxonomy_get_vocabularies($type = NULL) {
// If no node types are associated with a vocabulary, the LEFT JOIN will
// return a NULL value for type.
if (isset($voc->type)) {
- $node_types[$voc->vid][] = $voc->type;
+ $node_types[$voc->vid][$voc->type] = $voc->type;
unset($voc->type);
$voc->nodes = $node_types[$voc->vid];
}
@@ -928,7 +976,7 @@ function taxonomy_vocabulary_load($vid) {
$node_types = array();
while ($voc = db_fetch_object($result)) {
if (!empty($voc->type)) {
- $node_types[] = $voc->type;
+ $node_types[$voc->type] = $voc->type;
}
unset($voc->type);
$voc->nodes = $node_types;
@@ -1182,6 +1230,19 @@ function taxonomy_help($path, $arg) {
return $output;
case 'admin/content/taxonomy':
return '<p>'. t("The taxonomy module allows you to categorize your content using both tags and administrator defined terms. It is a flexible tool for classifying content with many advanced features. To begin, create a 'Vocabulary' to hold one set of terms or tags. You can create one free-tagging vocabulary for everything, or seperate controlled vocabularies to define the various properties of your content, for example 'Countries' or 'Colours'.") .'</p>';
+ case 'admin/content/taxonomy/%':
+ $vocabulary = taxonomy_vocabulary_load($arg[3]);
+ if ($vocabulary->tags) {
+ return '<p>'. t('%capital_name is a free-tagging vocabulary. To change the name or description of a term, click the <em>edit</em> link next to the term.', array('%capital_name' => drupal_ucfirst($vocabulary->name))) .'</p>';
+ }
+ switch ($vocabulary->hierarchy) {
+ case 0:
+ return '<p>'. t('%capital_name is a flat vocabulary. You may organize the terms in the %name vocabulary by using the handles on the left side of the table. To change the name or description of a term, click the <em>edit</em> link next to the term.', array('%capital_name' => drupal_ucfirst($vocabulary->name), '%name' => $vocabulary->name)) .'</p>';
+ case 1:
+ return '<p>'. t('%capital_name is a single hierarchy vocabulary. You may organize the terms in the %name vocabulary by using the handles on the left side of the table. To change the name or description of a term, click the <em>edit</em> link next to the term.', array('%capital_name' => drupal_ucfirst($vocabulary->name), '%name' => $vocabulary->name)) .'</p>';
+ case 2:
+ return '<p>'. t('%capital_name is a multiple hierarchy vocabulary. To change the name or description of a term, click the <em>edit</em> link next to the term. Drag and drop of multiple hierarchies is not supported, but you can re-enable drag and drop support by editing each term to include only a single parent.', array('%capital_name' => drupal_ucfirst($vocabulary->name))) .'</p>';
+ }
case 'admin/content/taxonomy/add/vocabulary':
return '<p>'. t('Define how your vocabulary will be presented to administrators and users, and which content types to categorize with it. Tags allows users to create terms when submitting posts by typing a comma separated list. Otherwise terms are chosen from a select list and can only be created by users with the "administer taxonomy" permission.') .'</p>';
}