tids[0]); $channel["link"] = url("taxonomy/view/$taxonomy->operator/$taxonomy->str_tids"); $channel["title"] = variable_get("site_name", "drupal") ." - ". $term->name; $channel["description"] = $term->description; node_feed($result, $channel); } } function taxonomy_perm() { return array("administer taxonomy"); } function taxonomy_link($type, $node = NULL) { if ($type == "admin" && user_access("administer taxonomy")) { $help["taxonomy"] = "The taxonomy module allows you to classify posts into categories and subcategories; it allows multiple lists of categories for classification (controlled vocabularies) and offers the possibility of creating thesauri (controlled vocabularies that indicate the relationship of terms) and taxonomies (controlled vocabularies where relationships are indicated hierarchically)."; $help["vocabulary"] = "When you create a controlled vocabulary you are creating a set of terms to use for describing content (known as descriptors in indexing lingo). Drupal allows you to describe each node of content (blog, story, etc.) using one or many of these terms. For simple implementations, you might create a set of categories without subcategories, similar to Slashdot.org's or Kuro5hin.org's sections. For more complex implementations, you might create a hierarchical list of categories."; menu("admin/taxonomy", "taxonomy", "taxonomy_admin", $help["taxonomy"], 3); menu("admin/taxonomy/add/vocabulary", "create new vocabulary", "taxonomy_admin", $help["vocabulary"]); menu("admin/taxonomy/help", "help", "taxonomy_admin", NULL, 9); } else if ($type == "taxonomy terms" && $node != NULL) { if ($node->taxonomy) { foreach ($node->taxonomy as $tid) { $term = taxonomy_get_term($tid); $links[] = l($term->name, "taxonomy/page/or/$term->tid", $term->description ? array("title" => $term->description) : array()); } } else { /* ** Themes can print taxonomy links with: ** ** if (module_exist("taxonomy")) { ** $this->links(taxonomy_link("taxonomy terms", $node)); ** } */ $links = array(); foreach (taxonomy_node_get_terms($node->nid) as $term) { $links[] = l($term->name, "taxonomy/page/or/$term->tid", $term->description ? array("title" => $term->description) : array()); } } return $links; } } /* ** admin pages (form, save, overview) */ function taxonomy_form_vocabulary($edit = array()) { foreach (module_list() as $name) { if (module_hook($name, "node")) { $nodetypes[$name] = $name; } } $form .= form_textfield(t("Vocabulary name"), "name", $edit["name"], 50, 64, t("Required") . ". " . t("The name for this vocabulary. Example: 'Topic'") . "."); $form .= form_textarea(t("Description"), "description", $edit["description"], 60, 5, t("Optional") . ". " . t("Description of the vocabulary, can be used by modules.")); $form .= form_select(t("Types"), "types", explode(",", $edit["types"]), $nodetypes, t("Required") . ". " . t("A list of node types you want to associate this vocabulary with."), "", 1); $form .= form_checkbox(t("Related terms"), "relations", 1, $edit["relations"], t("Optional") . ". " . t("Allows ". l("related terms", "admin/taxonomy/help#relatedterms") ." in this vocabulary.")); $form .= form_select(t("Hierarchy"), "hierarchy", $edit["hierarchy"], array(t("Disabled"), t("Single"), t("Multiple")), t("Optional") . ". ". t("Allows ". l("a tree-like hierarchy", "admin/taxonomy/help#hierarchy") ." between terms of this vocabulary."), "", 0); $form .= form_checkbox(t("Multiple select"), "multiple", 1, $edit["multiple"], t("Optional") . ". " . t("Allows nodes to have more than one term in this vocabulary.")); $form .= form_checkbox(t("Required"), "required", 1, $edit["required"], t("If enabled every node must have at least one term in this vocabulary")); $form .= form_weight(t("Weight"), "weight", $edit["weight"], 10, t("Optional. In listings, the heavier vocabularies will sink and the lighter vocabularies will be positioned nearer the top.")); $form .= form_submit(t("Submit")); if ($edit["vid"]) { $form .= form_submit(t("Delete")); $form .= form_hidden("vid", $edit["vid"]); } return form($form); } function taxonomy_save_vocabulary($edit) { if (!$edit["types"]) { $edit["types"] = array(); } $data = array("name" => $edit["name"], "types" => implode(",", $edit["types"]), "description" => $edit["description"], "multiple" => $edit["multiple"], "required" => $edit["required"], "hierarchy" => $edit["hierarchy"], "relations" => $edit["relations"], "weight" => $edit["weight"]); if ($edit["vid"] && $edit["name"]) { db_query("UPDATE vocabulary SET ". _prepare_update($data) ." WHERE vid = %d", $edit["vid"]); module_invoke_all("taxonomy", "update", "vocabulary", $edit); $message = t("updated vocabulary '%name'.", array("%name" => $edit["name"])); } else if ($edit["vid"]) { $message = taxonomy_del_vocabulary($edit["vid"]); } else { $data["vid"] = $edit["vid"] = db_next_id("vocabulary_vid"); db_query("INSERT INTO vocabulary ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2)); module_invoke_all("taxonomy", "insert", "vocabulary", $edit); $message = t("created new vocabulary '%name'.", array("%name" => $edit["name"])); } cache_clear_all(); return $message; } function taxonomy_del_vocabulary($vid) { $vocabulary = taxonomy_get_vocabulary($vid); db_query("DELETE FROM vocabulary WHERE vid = %d", $vid); $result = db_query("SELECT tid FROM term_data WHERE vid = %d", $vid); while ($term = db_fetch_object($result)) { taxonomy_del_term($term->tid); } module_invoke_all("taxonomy", "delete", "vocabulary", $vocabulary); cache_clear_all(); return t("deleted vocabulary '%name'.", array("%name" => $vocabulary->name)); } function _taxonomy_confirm_del_vocabulary($vid) { $vocabulary = taxonomy_get_vocabulary($vid); $form .= form_hidden("confirm", 1); $form .= form_hidden("type", "vocabulary"); $form .= form_hidden("vid", $vid); $form .= form_submit(t("Delete")); $form .= form_submit(t("Cancel")); return form(form_item(t("Delete vocabulary '%name'", array("%name" => $vocabulary->name)), $form, t("Are you sure you want to delete the vocabulary and all its terms?"))); } function taxonomy_form_term($edit = array()) { $vocabulary_id = isset($edit["vid"]) ? $edit["vid"] : arg(4); $vocabulary = taxonomy_get_vocabulary($vocabulary_id); $form = form_textfield(t("Term name"), "name", $edit["name"], 50, 64, t("Required") . ". " . t("The name for this term. Example: 'Linux'.")); $form .= form_textarea(t("Description"), "description", $edit["description"], 60, 5, t("Optional") . ". " . t("A description of the term.")); if ($vocabulary->hierarchy) { $parent = array_keys(taxonomy_get_parents($edit["tid"])); $children = taxonomy_get_tree($vocabulary_id, $edit["tid"]); // you can't be son of yourself nor of your children foreach ($children as $child) { $exclude[] = $child->tid; } $exclude[] = $edit["tid"]; if ($vocabulary->hierarchy == 1) { $form .= _taxonomy_term_select(t("Parent"), "parent", $parent, $vocabulary_id, t("Required") . ". " . l(t("Parent term"), "admin/taxonomy/help#parent") .".", 0, "<" . t("root") . ">", $exclude); } elseif ($vocabulary->hierarchy == 2) { $form .= _taxonomy_term_select(t("Parents"), "parent", $parent, $vocabulary_id, t("Required") . ". ". l(t("Parent terms"), "admin/taxonomy/help#parent") .".", 1, "<" . t("root") . ">", $exclude); } } if ($vocabulary->relations) { $form .= _taxonomy_term_select(t("Related terms"), "relations", array_keys(taxonomy_get_related($edit["tid"])), $vocabulary_id, t("Optional") . ". ", 1, "<" . t("none") . ">", array($edit["tid"])); } $form .= form_textarea(t("Synonyms"), "synonyms", implode("\n", taxonomy_get_synonyms($edit["tid"])), 30, 5, t("Optional") . ". ". t(l("Synonyms", "admin/taxonomy/help#synonyms") ." of this term, one synonym per line.")); $form .= form_weight(t("Weight"), "weight", $edit["weight"], 10, t("Optional. In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.")); $form .= form_hidden("vid", $vocabulary->vid); $form .= form_submit(t("Submit")); if ($edit["tid"]) { $form .= form_submit(t("Delete")); $form .= form_hidden("tid", $edit["tid"]); } return form($form); } function taxonomy_save_term($edit) { if ($edit["tid"] && $edit["name"]) { $data = array("name" => $edit["name"], "description" => $edit["description"], "weight" => $edit["weight"]); db_query("UPDATE term_data SET ". _prepare_update($data) ." WHERE tid = %d", $edit["tid"]); module_invoke_all("taxonomy", "update", "term", $edit); $message = t("the term '%a' has been updated.", array("%a" => $edit["name"])); } else if ($edit["tid"]) { return taxonomy_del_term($edit["tid"]); } else { $edit["tid"] = db_next_id("term_data_tid"); $data = array("tid" => $edit["tid"], "name" => $edit["name"], "description" => $edit["description"], "vid" => $edit["vid"], "weight" => $edit["weight"]); db_query("INSERT INTO term_data ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2)); module_invoke_all("taxonomy", "insert", "term", $edit); $message = t("created new term '%name'.", array("%name" => $edit["name"])); } // relations (seem very powerful, but I have to understand it completely) db_query("DELETE FROM term_relation WHERE tid1 = %d OR tid2 = %d", $edit["tid"], $edit["tid"]); if ($edit["relations"]) { foreach ($edit["relations"] as $related_id) { if ($related_id != 0) { db_query("INSERT INTO term_relation (tid1, tid2) VALUES (%d, %d)", $edit["tid"], $related_id); } } } // hierarchy db_query("DELETE FROM term_hierarchy WHERE tid = %d", $edit["tid"]); if (!isset($edit["parent"])) { $edit["parent"] = 0; } if (is_array($edit["parent"])) { foreach ($edit["parent"] as $parent) { db_query("INSERT INTO term_hierarchy (tid, parent) VALUES (%d, %d)", $edit["tid"], $parent); } } else { db_query("INSERT INTO term_hierarchy (tid, parent) VALUES (%d, %d)", $edit["tid"], $edit["parent"][0]); } db_query("DELETE FROM term_synonym WHERE tid = %d", $edit["tid"]); if ($edit["synonyms"]) { foreach (explode ("\n", str_replace("\r", "", $edit["synonyms"])) as $synonym) { if ($synonym) { db_query("INSERT INTO term_synonym (tid, name) VALUES (%d, '%s')", $edit["tid"], chop($synonym)); } } } cache_clear_all(); return $message; } function taxonomy_del_term($tid) { $term = taxonomy_get_term($tid); db_query("DELETE FROM term_data WHERE tid = %d", $tid); db_query("DELETE FROM term_hierarchy WHERE tid = %d", $tid); db_query("DELETE FROM term_relation WHERE tid1 = %d OR tid2 = %d", $tid, $tid); db_query("DELETE FROM term_synonym WHERE tid = %d", $tid); db_query("DELETE FROM term_node WHERE tid = %d", $tid); module_invoke_all("taxonomy", "delete", "term", $term); cache_clear_all(); return t("deleted term '%name'.", array("%name" => $term->name)); } function _taxonomy_confirm_del_term($tid) { $term = taxonomy_get_term($tid); $form .= form_hidden("confirm", 1); $form .= form_hidden("type", "term"); $form .= form_hidden("tid", $tid); $form .= form_submit(t("Delete")); $form .= form_submit(t("Cancel")); return form(form_item(t("Delete term '%name'", array("%name" => $term->name)), $form, t("Are you sure you want to delete the term?"))); } function taxonomy_overview() { $output .= "
Classifying nodes allows for the organization of content into categories and subcategories of description. These categories can be used to organize and retrieve similarly described content. Drupal's taxonomy.module is an extremely flexible classification system that allows for multiple lists of categories for classification (controlled vocabularies) and offers the possibility of creating thesauri (controlled vocabularies that indicate the relationship of terms) and taxonomies (controlled vocabularies where relationships are indicated hierarchically). For details about classification types and insight into the development of taxonomy.module, see this drupal.org discussion.
Dairy
--Milk
Drink
--Alchohol
--Pop
--Milk
Meat
--Beef
--Chicken
--Lamb
Spices
--Sugar
Notes
When you create a controlled vocabulary you are creating a set of terms to use for describing content (known as descriptors in indexing lingo). Drupal allows you to describe each node of content (blog, story, etc.) using one or many of these terms. For simple implementations, you might create a set of categories without subcategories, similar to Slashdot's sections. For more complex implementations, you might create a hierarchical list of categories such as the example Food taxonomy above.
When you set up a controlled vocabulary, you will be asked to enter some descriptive data and define the attributes of this vocabulary. For example, if you select the hierarchy option, you will be defining a taxonomy or a thesaurus. If you select related terms option, you are allowing the definition of related terms as in a thesaurus. Selecting multiple select will allow you to describe a node using more than one term. That node will then appear in each term's page, thus increasing the chance that a user will find it.
Vocabulary name
Required. The name for this vocabulary. Example: Dairy.
Description
Optional. Description of the vocabulary, can be used by modules and feeds.
Types
Required. The list of node types you want to associate this vocabulary with. Some available types are: blog, book, forum, page, story.
Related terms
Allows relationships between terms within this vocabulary. Think of these as see also-references.
Hierarchy
Allows a tree-like taxonomy, as in our Foods example above
Multiple select
Allows nodes to be described using more than one term. Nodes may then appear on multiple taxonomy pages.
The options you see when adding a term to a vocabulary will depend on what you selected for related terms, hierarchy and multiple select when you created the corrosponding vocabulary.
Term name
Required. The name for this term. Example: Milk
Description
Optional. Description of the term that may be used by modules and RSS feeds. This is synonymous with a 'scope note'.
Parent
Required. Select the term under which this term is a subset -- the branch of the hierarchy that this term belongs under. This is also known as the "Broader term" indicator used in thesauri.
Synonyms
Optional. Enter synonyms for this term, one synonym per line. Synonyms can be used for variant spellings, acronyms, and other terms that have the same meaning as the added term, but which are not explicitly listed in this thesaurus (i.e. unauthorized terms).
In order to view the nodes associated with a term or a collection of terms, you should browse to a properly formed URL. For example, see ">. Taxonomy URLs always contain a term ID or list of term IDs at the end of the URL (aka querystring). You may learn the term ID for a given term by hovering over that term in the page in the Admin and noting the number after the querystring parameter called tid. If you wish to see nodes from a collection of term IDs, separate each term ID with a comma. Also, the name of the querystring parameter may be or or and: or shows nodes which appear in any of the term IDs while and shows nodes in all the specified term IDs. Thus, or is less specific than and.
Every term, or collection of terms, provides an RSS feed to which interested users may subscribe. The URL format for an sample RSS feed is ">.