- fixed indentation.

- added $Id$
4.0.x
Kjartan Mannes 2002-05-02 21:41:29 +00:00
parent a93b2a1740
commit ce4993d29c
2 changed files with 1212 additions and 1210 deletions

View File

@ -1,6 +1,7 @@
<?php <?php
// $Id$
function taxonomy_feed() { function taxonomy_feed() {
global $id, $or, $and, $type; global $id, $or, $and, $type;
if ($type == "voc") { if ($type == "voc") {
@ -31,25 +32,25 @@
node_feed($result, $channel); node_feed($result, $channel);
} }
} }
function taxonomy_perm() { function taxonomy_perm() {
return array("administer taxonomy"); return array("administer taxonomy");
} }
function taxonomy_link($type) { function taxonomy_link($type) {
if ($type == "admin" && user_access("administer taxonomy")) { if ($type == "admin" && user_access("administer taxonomy")) {
$links[] = la(t("taxonomy"), array("mod" => "taxonomy")); $links[] = la(t("taxonomy"), array("mod" => "taxonomy"));
} }
return $links ? $links : array(); return $links ? $links : array();
} }
/* /*
** admin pages (form, save, overview) ** admin pages (form, save, overview)
*/ */
function taxonomy_form_vocabulary($edit = array()) { function taxonomy_form_vocabulary($edit = array()) {
foreach (module_list() as $name) { foreach (module_list() as $name) {
if (module_hook($name, "node")) { if (module_hook($name, "node")) {
$nodetypes[$name] = $name; $nodetypes[$name] = $name;
@ -72,10 +73,10 @@
} }
return form($form); return form($form);
} }
function taxonomy_save_vocabulary($edit) { function taxonomy_save_vocabulary($edit) {
$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"]); $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"]) { if ($edit["vid"] && $edit["name"]) {
db_query("UPDATE vocabulary SET ". _prepare_update($data) ." WHERE vid = '". check_input($edit["vid"]) ."'"); db_query("UPDATE vocabulary SET ". _prepare_update($data) ." WHERE vid = '". check_input($edit["vid"]) ."'");
@ -86,23 +87,23 @@
else { else {
db_query("INSERT INTO vocabulary ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2)); db_query("INSERT INTO vocabulary ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2));
} }
} }
function taxonomy_del_vocabulary($vid) { function taxonomy_del_vocabulary($vid) {
db_query("DELETE FROM vocabulary WHERE vid = '%s'", $vid); db_query("DELETE FROM vocabulary WHERE vid = '%s'", $vid);
$result = db_query("SELECT tid FROM term_data WHERE vid = '%s'", $vid); $result = db_query("SELECT tid FROM term_data WHERE vid = '%s'", $vid);
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
taxonomy_del_term($term->tid); taxonomy_del_term($term->tid);
} }
} }
function taxonomy_form_term($edit = array()) { function taxonomy_form_term($edit = array()) {
global $vocabulary_id; global $vocabulary_id;
if (!$vocabulary_id) { if (!$vocabulary_id) {
$vocabulary_id = $edit["vid"]; $vocabulary_id = $edit["vid"];
} }
$vocabulary = taxonomy_get_vocabulary($vocabulary_id); $vocabulary = taxonomy_get_vocabulary($vocabulary_id);
$form .= form_textfield("Term name", "name", $edit["name"], 50, 64, "Required. The name for this term. Example: 'Linux'."); $form = form_textfield("Term name", "name", $edit["name"], 50, 64, "Required. The name for this term. Example: 'Linux'.");
$form .= form_textarea("Description", "description", $edit["description"], 60, 5, "Optional. Description of the term, can be used by modules."); $form .= form_textarea("Description", "description", $edit["description"], 60, 5, "Optional. Description of the term, can be used by modules.");
if ($vocabulary->relations) { if ($vocabulary->relations) {
@ -135,9 +136,9 @@
} }
return form($form); return form($form);
} }
function taxonomy_save_term($edit) { function taxonomy_save_term($edit) {
if ($edit["tid"] && $edit["name"]) { if ($edit["tid"] && $edit["name"]) {
$data = array("name" => $edit["name"], "description" => $edit["description"], "weight" => $edit["weight"]); $data = array("name" => $edit["name"], "description" => $edit["description"], "weight" => $edit["weight"]);
@ -194,17 +195,17 @@
$synonyms_query = implode(", ", $syn_q); $synonyms_query = implode(", ", $syn_q);
db_query("INSERT INTO term_synonym (tid, name) VALUES $synonyms_query"); db_query("INSERT INTO term_synonym (tid, name) VALUES $synonyms_query");
} }
} }
function taxonomy_del_term($tid) { function taxonomy_del_term($tid) {
db_query("DELETE FROM term_data WHERE tid = '%s'", $tid); db_query("DELETE FROM term_data WHERE tid = '%s'", $tid);
db_query("DELETE FROM term_hierarchy WHERE tid = '%s'", $tid); db_query("DELETE FROM term_hierarchy WHERE tid = '%s'", $tid);
db_query("DELETE FROM term_relation WHERE tid1 = '%s' OR tid2 = '%s'", $tid, $tid); db_query("DELETE FROM term_relation WHERE tid1 = '%s' OR tid2 = '%s'", $tid, $tid);
db_query("DELETE FROM term_synonym WHERE tid = '%s'", $tid); db_query("DELETE FROM term_synonym WHERE tid = '%s'", $tid);
db_query("DELETE FROM term_node WHERE tid = '%s'", $tid); db_query("DELETE FROM term_node WHERE tid = '%s'", $tid);
} }
function taxonomy_overview() { function taxonomy_overview() {
global $tree; global $tree;
$output .= "<h3>vocabularies overview</h3>"; $output .= "<h3>vocabularies overview</h3>";
@ -225,7 +226,7 @@
if ($tree) { if ($tree) {
$output .= "<tr><td colspan=\"3\"><table><tr><td>"; $output .= "<tr><td colspan=\"3\"><table><tr><td>";
foreach ($tree as $term) { foreach ($tree as $term) {
$output .= "<tr><td>". la(_taxonomy_depth($term->depth).check_output($term->name), array("mod" => "taxonomy", "op" => "edit", "type" => "term", "id" => check_output($term->tid))) ."</td></tr>"; $output .= "<tr><td>". la(_taxonomy_depth($term->depth) . check_output($term->name), array("mod" => "taxonomy", "op" => "edit", "type" => "term", "id" => check_output($term->tid))) ."</td></tr>";
} }
$output .= "</td></tr></table></td></tr>\n"; $output .= "</td></tr></table></td></tr>\n";
} }
@ -233,9 +234,9 @@
$output .= "</table>\n"; $output .= "</table>\n";
return $output; return $output;
} }
function taxonomy_form($vocabulary_id, $value = 0) { function taxonomy_form($vocabulary_id, $value = 0) {
$vocabulary = taxonomy_get_vocabulary($vocabulary_id); $vocabulary = taxonomy_get_vocabulary($vocabulary_id);
if ($vocabulary->required) { if ($vocabulary->required) {
$verb = "must"; $verb = "must";
@ -254,14 +255,14 @@
$multiple = 0; $multiple = 0;
} }
return _taxonomy_term_select($vocabulary->name, "taxonomy", $value, $vocabulary_id, $description, $multiple, $blank); return _taxonomy_term_select($vocabulary->name, "taxonomy", $value, $vocabulary_id, $description, $multiple, $blank);
} }
/* /*
** API functions ** API functions
*/ */
// return array of vocabularies, as objects // return array of vocabularies, as objects
function taxonomy_get_vocabularies($type = '', $key = "vid") { function taxonomy_get_vocabularies($type = '', $key = "vid") {
if ($type) { if ($type) {
$result = db_query("SELECT * FROM vocabulary WHERE types LIKE '%%%s%%' ORDER BY weight, name", $type); $result = db_query("SELECT * FROM vocabulary WHERE types LIKE '%%%s%%' ORDER BY weight, name", $type);
} }
@ -273,10 +274,10 @@
$vocabularies[$voc->$key] = $voc; $vocabularies[$voc->$key] = $voc;
} }
return $vocabularies; return $vocabularies;
} }
// return form with current term // return form with current term
function taxonomy_node_form($type, $node = '') { function taxonomy_node_form($type, $node = '') {
if (!$node->taxonomy) { if (!$node->taxonomy) {
if ($node->nid) { if ($node->nid) {
$terms = array_keys(taxonomy_node_get_terms($node->nid)); $terms = array_keys(taxonomy_node_get_terms($node->nid));
@ -294,27 +295,27 @@
$result[] .= taxonomy_form($vocabulary->vid, $terms); $result[] .= taxonomy_form($vocabulary->vid, $terms);
} }
return $result ? $result : array(); return $result ? $result : array();
} }
// return 1 if node identified by $nid contains a taxonomy term identified by $tid in his body or title // return 1 if node identified by $nid contains a taxonomy term identified by $tid in his body or title
function taxonomy_node_has_term($nid, $tid) { function taxonomy_node_has_term($nid, $tid) {
$term_name = db_result(db_query("SELECT name FROM term_data WHERE tid = '%s'", $tid)); $term_name = db_result(db_query("SELECT name FROM term_data WHERE tid = '%s'", $tid));
return db_result(db_query("SELECT COUNT(n.nid) FROM node n WHERE n.nid = '%s' AND ((n.body LIKE '%%%s%%') OR (n.body LIKE '%%%s%%'))", $nid, $term_name, $term_name)); return db_result(db_query("SELECT COUNT(n.nid) FROM node n WHERE n.nid = '%s' AND ((n.body LIKE '%%%s%%') OR (n.body LIKE '%%%s%%'))", $nid, $term_name, $term_name));
} }
// return array of terms of a node beloging to a particular vocabulary identified by $vid // return array of terms of a node beloging to a particular vocabulary identified by $vid
function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = "tid") { function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = "tid") {
$result = db_query("SELECT t.* FROM term_data t, term_node r WHERE t.tid = r.tid AND t.vid = '%s' AND r.nid = '%s' ORDER BY weight", $vid, $nid); $result = db_query("SELECT t.* FROM term_data t, term_node r WHERE t.tid = r.tid AND t.vid = '%s' AND r.nid = '%s' ORDER BY weight", $vid, $nid);
$terms = array(); $terms = array();
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
$terms[$term->$key] = $term; $terms[$term->$key] = $term;
} }
return $terms; return $terms;
} }
// return array of terms of a node // return array of terms of a node
function taxonomy_node_get_terms($nid, $key = "tid") { function taxonomy_node_get_terms($nid, $key = "tid") {
static $terms; static $terms;
if (!$terms[$nid]) { if (!$terms[$nid]) {
@ -325,10 +326,10 @@
} }
} }
return $terms[$nid]; return $terms[$nid];
} }
// save terms of a node // save terms of a node
function taxonomy_node_save($nid, $terms) { function taxonomy_node_save($nid, $terms) {
taxonomy_node_delete($nid); taxonomy_node_delete($nid);
if ($terms) { if ($terms) {
@ -337,15 +338,15 @@
} }
db_query("INSERT INTO term_node (nid, tid) VALUES ". implode(", ", $query)); db_query("INSERT INTO term_node (nid, tid) VALUES ". implode(", ", $query));
} }
} }
// clean up terms // clean up terms
function taxonomy_node_delete($nid) { function taxonomy_node_delete($nid) {
db_query("DELETE FROM term_node WHERE nid = '%s'", $nid); db_query("DELETE FROM term_node WHERE nid = '%s'", $nid);
} }
// relations: return array of related terms // relations: return array of related terms
function taxonomy_get_related($tid, $key = "tid") { function taxonomy_get_related($tid, $key = "tid") {
if ($tid) { if ($tid) {
$result = db_query("SELECT t.*, tid1, tid2 FROM term_relation, term_data t WHERE (t.tid = tid1 OR t.tid = tid2) AND (tid1 = '%s' OR tid2 = '%s') ORDER BY weight", $tid, $tid); $result = db_query("SELECT t.*, tid1, tid2 FROM term_relation, term_data t WHERE (t.tid = tid1 OR t.tid = tid2) AND (tid1 = '%s' OR tid2 = '%s') ORDER BY weight", $tid, $tid);
$related = array(); $related = array();
@ -357,10 +358,10 @@
else { else {
return array(); return array();
} }
} }
// hierarchy: get parent terms // hierarchy: get parent terms
function taxonomy_get_parents($tid, $key = "tid") { function taxonomy_get_parents($tid, $key = "tid") {
if ($tid) { if ($tid) {
$result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE h.parent = t.tid AND h.tid = '%s' ORDER BY weight, name", $tid); $result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE h.parent = t.tid AND h.tid = '%s' ORDER BY weight, name", $tid);
$parents = array(); $parents = array();
@ -372,10 +373,10 @@
else { else {
return array(); return array();
} }
} }
// hierarchy: get children // hierarchy: get children
function taxonomy_get_children($tid, $vid = 0, $key = "tid") { function taxonomy_get_children($tid, $vid = 0, $key = "tid") {
if ($vid) { if ($vid) {
$result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE t.vid = '%s' AND h.tid = t.tid AND h.parent = '%s' ORDER BY weight, name", $vid, $tid); $result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE t.vid = '%s' AND h.tid = t.tid AND h.parent = '%s' ORDER BY weight, name", $vid, $tid);
} }
@ -387,10 +388,10 @@
$children[$term->$key] = $term; $children[$term->$key] = $term;
} }
return $children; return $children;
} }
// hierarchy: get whole family, with tid, parent and depth; useful to show // hierarchy: get whole family, with tid, parent and depth; useful to show
function taxonomy_get_tree($vocabulary_id, &$tree, $parent = 0, $depth = -1, $key = "tid") { function taxonomy_get_tree($vocabulary_id, &$tree, $parent = 0, $depth = -1, $key = "tid") {
static $children, $terms; static $children, $terms;
if ($depth == -1) { if ($depth == -1) {
$children = array(); $children = array();
@ -417,10 +418,10 @@
else { else {
return 0; return 0;
} }
} }
// synonyms: return array of synonyms // synonyms: return array of synonyms
function taxonomy_get_synonyms($tid) { function taxonomy_get_synonyms($tid) {
if ($tid) { if ($tid) {
$result = db_query("SELECT name FROM term_synonym WHERE tid = '%s'", $tid); $result = db_query("SELECT name FROM term_synonym WHERE tid = '%s'", $tid);
while ($synonym = db_fetch_array($result)) { while ($synonym = db_fetch_array($result)) {
@ -431,15 +432,15 @@
else { else {
return array(); return array();
} }
} }
// synonyms: return original term // synonyms: return original term
function taxonomy_get_synonym_root($term) { function taxonomy_get_synonym_root($term) {
return db_fetch_object(db_query("SELECT * FROM term_synonym s, term_data t WHERE t.tid = s.tid AND s.name = '%s'", $term)); return db_fetch_object(db_query("SELECT * FROM term_synonym s, term_data t WHERE t.tid = s.tid AND s.name = '%s'", $term));
} }
// given a term id, count number of nodes in it // given a term id, count number of nodes in it
function taxonomy_term_count_nodes($tid) { function taxonomy_term_count_nodes($tid) {
static $count; static $count;
if (!$count) { if (!$count) {
@ -453,10 +454,10 @@
$children_count += taxonomy_term_count_nodes($c); $children_count += taxonomy_term_count_nodes($c);
} }
return $count[$tid] + $children_count; return $count[$tid] + $children_count;
} }
// helper for above function // helper for above function
function _taxonomy_term_children($tid) { function _taxonomy_term_children($tid) {
static $children; static $children;
if (!$children) { if (!$children) {
@ -466,23 +467,23 @@
} }
} }
return $children[$tid] ? $children[$tid] : array(); return $children[$tid] ? $children[$tid] : array();
} }
function taxonomy_get_vocabulary($vid) { function taxonomy_get_vocabulary($vid) {
// simple cache using a static var? // simple cache using a static var?
return db_fetch_object(db_query("SELECT * FROM vocabulary WHERE vid = '%s'", $vid)); return db_fetch_object(db_query("SELECT * FROM vocabulary WHERE vid = '%s'", $vid));
} }
function taxonomy_get_term($tid) { function taxonomy_get_term($tid) {
// simple cache using a static var? // simple cache using a static var?
return db_fetch_object(db_query("SELECT * FROM term_data WHERE tid = '%s'", $tid)); return db_fetch_object(db_query("SELECT * FROM term_data WHERE tid = '%s'", $tid));
} }
/* /*
** service functions ** service functions
*/ */
function _taxonomy_term_select($title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude = array()) { function _taxonomy_term_select($title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude = array()) {
taxonomy_get_tree($vocabulary_id, $tree); taxonomy_get_tree($vocabulary_id, $tree);
if ($blank) { if ($blank) {
@ -511,24 +512,24 @@
return form_item($title, "<select name=\"edit[$name][]\"". ($multiple ? " multiple size=\"$size\"" : "") . ($extra ? " $extra" : "") .">$select</select>", $description); return form_item($title, "<select name=\"edit[$name][]\"". ($multiple ? " multiple size=\"$size\"" : "") . ($extra ? " $extra" : "") .">$select</select>", $description);
} }
} }
function _taxonomy_depth($depth, $graphic = '--') { function _taxonomy_depth($depth, $graphic = '--') {
for ($n = 0; $n < $depth; $n++) { for ($n = 0; $n < $depth; $n++) {
$result .= $graphic; $result .= $graphic;
} }
return $result; return $result;
} }
function _prepare_update($data) { function _prepare_update($data) {
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
$q[] = "$key = '". check_query($value) ."'"; $q[] = "$key = '". check_query($value) ."'";
} }
$result = implode(", ", $q); $result = implode(", ", $q);
return $result; return $result;
} }
function _prepare_insert($data, $stage) { function _prepare_insert($data, $stage) {
if ($stage == 1) { if ($stage == 1) {
$result = implode(", ", array_keys($data)); $result = implode(", ", array_keys($data));
} }
@ -539,9 +540,9 @@
$result = implode(", ", $q); $result = implode(", ", $q);
} }
return "($result)"; return "($result)";
} }
function taxonomy_page() { function taxonomy_page() {
global $op; global $op;
switch ($op) { switch ($op) {
@ -551,13 +552,13 @@
default: default:
// TODO: pretty display of all vocabularies // TODO: pretty display of all vocabularies
} }
} }
/* /*
** admin ** admin
*/ */
function taxonomy_admin() { function taxonomy_admin() {
global $edit, $type, $op, $id, $tree; global $edit, $type, $op, $id, $tree;
if (user_access("administer taxonomy")) { if (user_access("administer taxonomy")) {
@ -602,11 +603,11 @@
else { else {
print message_access(); print message_access();
} }
} }
function taxonomy_help() { function taxonomy_help() {
?> ?>
<h3>Background</h3> <h3>Background</h3>
Classifying nodes allows for the organization of content into categories and Classifying nodes allows for the organization of content into categories and
subcategories of description. These categories can be used to organize and retrieve subcategories of description. These categories can be used to organize and retrieve
similarly described content. Drupal's <i>taxonomy.module</i> is an extremely flexible similarly described content. Drupal's <i>taxonomy.module</i> is an extremely flexible
@ -614,11 +615,11 @@
(controlled vocabularies) and offers the possibility of creating thesauri (controlled (controlled vocabularies) and offers the possibility of creating thesauri (controlled
vocabularies that indicate the relationship of terms) and taxonomies (controlled vocabularies that indicate the relationship of terms) and taxonomies (controlled
vocabularies where relationships are indicated hierarchically). For details about vocabularies where relationships are indicated hierarchically). For details about
<a href="http://www.eleganthack.com/archives/002165.html#002165">classification <a href="http://www.eleganthack.com/archives/002165.html#002165">classification
types</a> and insight into the development of <i>taxonomy.module</i>, see this types</a> and insight into the development of <i>taxonomy.module</i>, see this
<a href="http://www.drupal.org/node.php?id=55">drupal.org discussion</a>.<br /> <a href="http://www.drupal.org/node.php?id=55">drupal.org discussion</a>.<br />
<h3>An Example Taxonomy - Foods</h3> <h3>An Example Taxonomy - Foods</h3>
<p>Dairy <br /> <p>Dairy <br />
--Milk <br /> --Milk <br />
Drink <br /> Drink <br />
--Alchohol <br /> --Alchohol <br />
@ -630,14 +631,14 @@
--Lamb <br /> --Lamb <br />
Spices <br /> Spices <br />
--Sugar</p> --Sugar</p>
<p><b>Notes</b></p> <p><b>Notes</b></p>
<ul> <ul>
<li>The term <i>Milk</i> appears within both <i>Dairy</i> and <i>Drink</i>. <li>The term <i>Milk</i> appears within both <i>Dairy</i> and <i>Drink</i>.
This is an example of <i>Multiple Parents</i> for a term.</li> This is an example of <i>Multiple Parents</i> for a term.</li>
<li>The order of siblings (e.g. <i>Beef</i>, <i>Chicken</i>, <i>Lamb</i>) in <li>The order of siblings (e.g. <i>Beef</i>, <i>Chicken</i>, <i>Lamb</i>) in
the taxonomy may be controlled with the <i>Weight</i> parameter. </li> the taxonomy may be controlled with the <i>Weight</i> parameter. </li>
</ul> </ul>
<h4></h4> <h4></h4>
<h3>Vocabularies</h3> <h3>Vocabularies</h3>
When you create a controlled vocabulary you are creating a set of terms to use 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 for describing content (known as descriptors in indexing lingo). Drupal allows
@ -649,12 +650,12 @@
<h4>Setting up a vocabulary</h4> <h4>Setting up a vocabulary</h4>
<p>When you set up a controlled vocabulary, you will be asked to enter some descriptive <p>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 data and define the attributes of this vocabulary. For example, if you select
the <i>Hierarchy </i>option, you will be defining a taxonomy or a thesaurus. If the <i>Hierarchy </i>option, you will be defining a taxonomy or a thesaurus. If
you select <i>Related Terms</i> option, you are allowing the definition of related you select <i>Related Terms</i> option, you are allowing the definition of related
terms as in a thesaurus. Selecting <i>Multiple Select</i> will allow you to describe terms as in a thesaurus. Selecting <i>Multiple Select</i> will allow you to describe
a node using more than one term. That node will then appear in each term's page, 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.</p> thus increasing the chance that a user will find it.</p>
<i>Vocabulary name</i><br /> <i>Vocabulary name</i><br />
Required. The name for this vocabulary. Example: <i>Dairy</i>.<br /> Required. The name for this vocabulary. Example: <i>Dairy</i>.<br />
<br /> <br />
@ -673,33 +674,33 @@
Allows a tree-like taxonomy, as in our <i>Foods</i> example above<br /> Allows a tree-like taxonomy, as in our <i>Foods</i> example above<br />
<br /> <br />
<i>Multiple Select</i><br /> <i>Multiple Select</i><br />
Allows nodes to be described using more than one term. Nodes may then appear on Allows nodes to be described using more than one term. Nodes may then appear on
multiple taxonomy pages.<br /> multiple taxonomy pages.<br />
<h4>Adding terms to a vocabulary</h4> <h4>Adding terms to a vocabulary</h4>
The options you see when adding a term to a vocabulary will depend on what you The options you see when adding a term to a vocabulary will depend on what you
selected for <i>Related Terms</i>, <i>Hierarchy </i>and <i>Multiple Select</i> selected for <i>Related Terms</i>, <i>Hierarchy </i>and <i>Multiple Select</i>
when you created the corrosponding vocabulary.<br /> when you created the corrosponding vocabulary.<br />
<br /> <br />
<i>Term name</i><br /> <i>Term name</i><br />
Required. The name for this term. Example: <i>Milk</i><br /> Required. The name for this term. Example: <i>Milk</i><br />
<br /> <br />
<i>Description</i><br /> <i>Description</i><br />
Optional. Description of the term that may be used by modules and RSS feeds. Optional. Description of the term that may be used by modules and RSS feeds.
This is synonymous with a 'Scope note'.<br /> This is synonymous with a 'Scope note'.<br />
<br /> <br />
<i><a name="parent"></a>Parent</i><br /> <i><a name="parent"></a>Parent</i><br />
Required. Select the term under which this term is a subset -- the branch of the hierarchy 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 that this term belongs under. This is also known as the "Broader term" indicator
used in thesauri.<br /> used in thesauri.<br />
<br /> <br />
<i><a name="synonyms"></a>Synonyms</i><br /> <i><a name="synonyms"></a>Synonyms</i><br />
Optional. Enter synonyms for this term, one synonym per line. Synonyms can be used for 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 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. <i>unauthorized added term, but which are not explicitly listed in this thesaurus (i.e. <i>unauthorized
terms</i>).<br /> terms</i>).<br />
<h3>Displaying Nodes Organized by Term(s)</h3> <h3>Displaying Nodes Organized by Term(s)</h3>
<p>In order to view the nodes associated with a term or a collection of terms, you <p>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 should browse to a properly formed URL. For example, see
<a href="<?php print path_uri().drupal_url(array("mod" => "node", "or" => "1,2"), "module"); ?>"><?php print path_uri().drupal_url(array("mod" => "node", "or" => "1,2"), "module"); ?></a>. <a href="<?php print path_uri().drupal_url(array("mod" => "node", "or" => "1,2"), "module"); ?>"><?php print path_uri().drupal_url(array("mod" => "node", "or" => "1,2"), "module"); ?></a>.
Taxonomy URLs always contain a termID or list of termIDs at the end of the URL (aka <i>querystring</i>). Taxonomy URLs always contain a termID or list of termIDs at the end of the URL (aka <i>querystring</i>).
@ -708,12 +709,12 @@
Also, the name of the querystring parameter may be <i>or</i> or <i>and</i>. Also, the name of the querystring parameter may be <i>or</i> or <i>and</i>.
<i>or</i> shows nodes which appear in <b>any</b> of the termIDs while <i>and</i> shows nodes in <b>all</b> the specified termIDs. <i>or</i> shows nodes which appear in <b>any</b> of the termIDs while <i>and</i> shows nodes in <b>all</b> the specified termIDs.
Thus, <i>or</i> is less specific than <i>and</i>. Thus, <i>or</i> is less specific than <i>and</i>.
</p> </p>
<h3>RSS Feeds</h3> <h3>RSS Feeds</h3>
<p>Every term, or collection of terms, provides an <a href="http://backend.userland.com/stories/rss091">RSS</a> feed to which interested <p>Every term, or collection of terms, provides an <a href="http://backend.userland.com/stories/rss091">RSS</a> feed to which interested
users may subscribe. The URL format for an sample RSS feed is users may subscribe. The URL format for an sample RSS feed is
<a href="<?php print path_uri().drupal_url(array("mod" => "node", "op" => "feed", "or" => "1,2"), "module"); ?>"><?php print path_uri().drupal_url(array("mod" => "node", "op" => "feed", "or" => "1,2"), "module"); ?></a>.</p> <a href="<?php print path_uri().drupal_url(array("mod" => "node", "op" => "feed", "or" => "1,2"), "module"); ?>"><?php print path_uri().drupal_url(array("mod" => "node", "op" => "feed", "or" => "1,2"), "module"); ?></a>.</p>
<?php <?php
} }
?> ?>

View File

@ -1,6 +1,7 @@
<?php <?php
// $Id$
function taxonomy_feed() { function taxonomy_feed() {
global $id, $or, $and, $type; global $id, $or, $and, $type;
if ($type == "voc") { if ($type == "voc") {
@ -31,25 +32,25 @@
node_feed($result, $channel); node_feed($result, $channel);
} }
} }
function taxonomy_perm() { function taxonomy_perm() {
return array("administer taxonomy"); return array("administer taxonomy");
} }
function taxonomy_link($type) { function taxonomy_link($type) {
if ($type == "admin" && user_access("administer taxonomy")) { if ($type == "admin" && user_access("administer taxonomy")) {
$links[] = la(t("taxonomy"), array("mod" => "taxonomy")); $links[] = la(t("taxonomy"), array("mod" => "taxonomy"));
} }
return $links ? $links : array(); return $links ? $links : array();
} }
/* /*
** admin pages (form, save, overview) ** admin pages (form, save, overview)
*/ */
function taxonomy_form_vocabulary($edit = array()) { function taxonomy_form_vocabulary($edit = array()) {
foreach (module_list() as $name) { foreach (module_list() as $name) {
if (module_hook($name, "node")) { if (module_hook($name, "node")) {
$nodetypes[$name] = $name; $nodetypes[$name] = $name;
@ -72,10 +73,10 @@
} }
return form($form); return form($form);
} }
function taxonomy_save_vocabulary($edit) { function taxonomy_save_vocabulary($edit) {
$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"]); $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"]) { if ($edit["vid"] && $edit["name"]) {
db_query("UPDATE vocabulary SET ". _prepare_update($data) ." WHERE vid = '". check_input($edit["vid"]) ."'"); db_query("UPDATE vocabulary SET ". _prepare_update($data) ." WHERE vid = '". check_input($edit["vid"]) ."'");
@ -86,23 +87,23 @@
else { else {
db_query("INSERT INTO vocabulary ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2)); db_query("INSERT INTO vocabulary ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2));
} }
} }
function taxonomy_del_vocabulary($vid) { function taxonomy_del_vocabulary($vid) {
db_query("DELETE FROM vocabulary WHERE vid = '%s'", $vid); db_query("DELETE FROM vocabulary WHERE vid = '%s'", $vid);
$result = db_query("SELECT tid FROM term_data WHERE vid = '%s'", $vid); $result = db_query("SELECT tid FROM term_data WHERE vid = '%s'", $vid);
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
taxonomy_del_term($term->tid); taxonomy_del_term($term->tid);
} }
} }
function taxonomy_form_term($edit = array()) { function taxonomy_form_term($edit = array()) {
global $vocabulary_id; global $vocabulary_id;
if (!$vocabulary_id) { if (!$vocabulary_id) {
$vocabulary_id = $edit["vid"]; $vocabulary_id = $edit["vid"];
} }
$vocabulary = taxonomy_get_vocabulary($vocabulary_id); $vocabulary = taxonomy_get_vocabulary($vocabulary_id);
$form .= form_textfield("Term name", "name", $edit["name"], 50, 64, "Required. The name for this term. Example: 'Linux'."); $form = form_textfield("Term name", "name", $edit["name"], 50, 64, "Required. The name for this term. Example: 'Linux'.");
$form .= form_textarea("Description", "description", $edit["description"], 60, 5, "Optional. Description of the term, can be used by modules."); $form .= form_textarea("Description", "description", $edit["description"], 60, 5, "Optional. Description of the term, can be used by modules.");
if ($vocabulary->relations) { if ($vocabulary->relations) {
@ -135,9 +136,9 @@
} }
return form($form); return form($form);
} }
function taxonomy_save_term($edit) { function taxonomy_save_term($edit) {
if ($edit["tid"] && $edit["name"]) { if ($edit["tid"] && $edit["name"]) {
$data = array("name" => $edit["name"], "description" => $edit["description"], "weight" => $edit["weight"]); $data = array("name" => $edit["name"], "description" => $edit["description"], "weight" => $edit["weight"]);
@ -194,17 +195,17 @@
$synonyms_query = implode(", ", $syn_q); $synonyms_query = implode(", ", $syn_q);
db_query("INSERT INTO term_synonym (tid, name) VALUES $synonyms_query"); db_query("INSERT INTO term_synonym (tid, name) VALUES $synonyms_query");
} }
} }
function taxonomy_del_term($tid) { function taxonomy_del_term($tid) {
db_query("DELETE FROM term_data WHERE tid = '%s'", $tid); db_query("DELETE FROM term_data WHERE tid = '%s'", $tid);
db_query("DELETE FROM term_hierarchy WHERE tid = '%s'", $tid); db_query("DELETE FROM term_hierarchy WHERE tid = '%s'", $tid);
db_query("DELETE FROM term_relation WHERE tid1 = '%s' OR tid2 = '%s'", $tid, $tid); db_query("DELETE FROM term_relation WHERE tid1 = '%s' OR tid2 = '%s'", $tid, $tid);
db_query("DELETE FROM term_synonym WHERE tid = '%s'", $tid); db_query("DELETE FROM term_synonym WHERE tid = '%s'", $tid);
db_query("DELETE FROM term_node WHERE tid = '%s'", $tid); db_query("DELETE FROM term_node WHERE tid = '%s'", $tid);
} }
function taxonomy_overview() { function taxonomy_overview() {
global $tree; global $tree;
$output .= "<h3>vocabularies overview</h3>"; $output .= "<h3>vocabularies overview</h3>";
@ -225,7 +226,7 @@
if ($tree) { if ($tree) {
$output .= "<tr><td colspan=\"3\"><table><tr><td>"; $output .= "<tr><td colspan=\"3\"><table><tr><td>";
foreach ($tree as $term) { foreach ($tree as $term) {
$output .= "<tr><td>". la(_taxonomy_depth($term->depth).check_output($term->name), array("mod" => "taxonomy", "op" => "edit", "type" => "term", "id" => check_output($term->tid))) ."</td></tr>"; $output .= "<tr><td>". la(_taxonomy_depth($term->depth) . check_output($term->name), array("mod" => "taxonomy", "op" => "edit", "type" => "term", "id" => check_output($term->tid))) ."</td></tr>";
} }
$output .= "</td></tr></table></td></tr>\n"; $output .= "</td></tr></table></td></tr>\n";
} }
@ -233,9 +234,9 @@
$output .= "</table>\n"; $output .= "</table>\n";
return $output; return $output;
} }
function taxonomy_form($vocabulary_id, $value = 0) { function taxonomy_form($vocabulary_id, $value = 0) {
$vocabulary = taxonomy_get_vocabulary($vocabulary_id); $vocabulary = taxonomy_get_vocabulary($vocabulary_id);
if ($vocabulary->required) { if ($vocabulary->required) {
$verb = "must"; $verb = "must";
@ -254,14 +255,14 @@
$multiple = 0; $multiple = 0;
} }
return _taxonomy_term_select($vocabulary->name, "taxonomy", $value, $vocabulary_id, $description, $multiple, $blank); return _taxonomy_term_select($vocabulary->name, "taxonomy", $value, $vocabulary_id, $description, $multiple, $blank);
} }
/* /*
** API functions ** API functions
*/ */
// return array of vocabularies, as objects // return array of vocabularies, as objects
function taxonomy_get_vocabularies($type = '', $key = "vid") { function taxonomy_get_vocabularies($type = '', $key = "vid") {
if ($type) { if ($type) {
$result = db_query("SELECT * FROM vocabulary WHERE types LIKE '%%%s%%' ORDER BY weight, name", $type); $result = db_query("SELECT * FROM vocabulary WHERE types LIKE '%%%s%%' ORDER BY weight, name", $type);
} }
@ -273,10 +274,10 @@
$vocabularies[$voc->$key] = $voc; $vocabularies[$voc->$key] = $voc;
} }
return $vocabularies; return $vocabularies;
} }
// return form with current term // return form with current term
function taxonomy_node_form($type, $node = '') { function taxonomy_node_form($type, $node = '') {
if (!$node->taxonomy) { if (!$node->taxonomy) {
if ($node->nid) { if ($node->nid) {
$terms = array_keys(taxonomy_node_get_terms($node->nid)); $terms = array_keys(taxonomy_node_get_terms($node->nid));
@ -294,27 +295,27 @@
$result[] .= taxonomy_form($vocabulary->vid, $terms); $result[] .= taxonomy_form($vocabulary->vid, $terms);
} }
return $result ? $result : array(); return $result ? $result : array();
} }
// return 1 if node identified by $nid contains a taxonomy term identified by $tid in his body or title // return 1 if node identified by $nid contains a taxonomy term identified by $tid in his body or title
function taxonomy_node_has_term($nid, $tid) { function taxonomy_node_has_term($nid, $tid) {
$term_name = db_result(db_query("SELECT name FROM term_data WHERE tid = '%s'", $tid)); $term_name = db_result(db_query("SELECT name FROM term_data WHERE tid = '%s'", $tid));
return db_result(db_query("SELECT COUNT(n.nid) FROM node n WHERE n.nid = '%s' AND ((n.body LIKE '%%%s%%') OR (n.body LIKE '%%%s%%'))", $nid, $term_name, $term_name)); return db_result(db_query("SELECT COUNT(n.nid) FROM node n WHERE n.nid = '%s' AND ((n.body LIKE '%%%s%%') OR (n.body LIKE '%%%s%%'))", $nid, $term_name, $term_name));
} }
// return array of terms of a node beloging to a particular vocabulary identified by $vid // return array of terms of a node beloging to a particular vocabulary identified by $vid
function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = "tid") { function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = "tid") {
$result = db_query("SELECT t.* FROM term_data t, term_node r WHERE t.tid = r.tid AND t.vid = '%s' AND r.nid = '%s' ORDER BY weight", $vid, $nid); $result = db_query("SELECT t.* FROM term_data t, term_node r WHERE t.tid = r.tid AND t.vid = '%s' AND r.nid = '%s' ORDER BY weight", $vid, $nid);
$terms = array(); $terms = array();
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
$terms[$term->$key] = $term; $terms[$term->$key] = $term;
} }
return $terms; return $terms;
} }
// return array of terms of a node // return array of terms of a node
function taxonomy_node_get_terms($nid, $key = "tid") { function taxonomy_node_get_terms($nid, $key = "tid") {
static $terms; static $terms;
if (!$terms[$nid]) { if (!$terms[$nid]) {
@ -325,10 +326,10 @@
} }
} }
return $terms[$nid]; return $terms[$nid];
} }
// save terms of a node // save terms of a node
function taxonomy_node_save($nid, $terms) { function taxonomy_node_save($nid, $terms) {
taxonomy_node_delete($nid); taxonomy_node_delete($nid);
if ($terms) { if ($terms) {
@ -337,15 +338,15 @@
} }
db_query("INSERT INTO term_node (nid, tid) VALUES ". implode(", ", $query)); db_query("INSERT INTO term_node (nid, tid) VALUES ". implode(", ", $query));
} }
} }
// clean up terms // clean up terms
function taxonomy_node_delete($nid) { function taxonomy_node_delete($nid) {
db_query("DELETE FROM term_node WHERE nid = '%s'", $nid); db_query("DELETE FROM term_node WHERE nid = '%s'", $nid);
} }
// relations: return array of related terms // relations: return array of related terms
function taxonomy_get_related($tid, $key = "tid") { function taxonomy_get_related($tid, $key = "tid") {
if ($tid) { if ($tid) {
$result = db_query("SELECT t.*, tid1, tid2 FROM term_relation, term_data t WHERE (t.tid = tid1 OR t.tid = tid2) AND (tid1 = '%s' OR tid2 = '%s') ORDER BY weight", $tid, $tid); $result = db_query("SELECT t.*, tid1, tid2 FROM term_relation, term_data t WHERE (t.tid = tid1 OR t.tid = tid2) AND (tid1 = '%s' OR tid2 = '%s') ORDER BY weight", $tid, $tid);
$related = array(); $related = array();
@ -357,10 +358,10 @@
else { else {
return array(); return array();
} }
} }
// hierarchy: get parent terms // hierarchy: get parent terms
function taxonomy_get_parents($tid, $key = "tid") { function taxonomy_get_parents($tid, $key = "tid") {
if ($tid) { if ($tid) {
$result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE h.parent = t.tid AND h.tid = '%s' ORDER BY weight, name", $tid); $result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE h.parent = t.tid AND h.tid = '%s' ORDER BY weight, name", $tid);
$parents = array(); $parents = array();
@ -372,10 +373,10 @@
else { else {
return array(); return array();
} }
} }
// hierarchy: get children // hierarchy: get children
function taxonomy_get_children($tid, $vid = 0, $key = "tid") { function taxonomy_get_children($tid, $vid = 0, $key = "tid") {
if ($vid) { if ($vid) {
$result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE t.vid = '%s' AND h.tid = t.tid AND h.parent = '%s' ORDER BY weight, name", $vid, $tid); $result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE t.vid = '%s' AND h.tid = t.tid AND h.parent = '%s' ORDER BY weight, name", $vid, $tid);
} }
@ -387,10 +388,10 @@
$children[$term->$key] = $term; $children[$term->$key] = $term;
} }
return $children; return $children;
} }
// hierarchy: get whole family, with tid, parent and depth; useful to show // hierarchy: get whole family, with tid, parent and depth; useful to show
function taxonomy_get_tree($vocabulary_id, &$tree, $parent = 0, $depth = -1, $key = "tid") { function taxonomy_get_tree($vocabulary_id, &$tree, $parent = 0, $depth = -1, $key = "tid") {
static $children, $terms; static $children, $terms;
if ($depth == -1) { if ($depth == -1) {
$children = array(); $children = array();
@ -417,10 +418,10 @@
else { else {
return 0; return 0;
} }
} }
// synonyms: return array of synonyms // synonyms: return array of synonyms
function taxonomy_get_synonyms($tid) { function taxonomy_get_synonyms($tid) {
if ($tid) { if ($tid) {
$result = db_query("SELECT name FROM term_synonym WHERE tid = '%s'", $tid); $result = db_query("SELECT name FROM term_synonym WHERE tid = '%s'", $tid);
while ($synonym = db_fetch_array($result)) { while ($synonym = db_fetch_array($result)) {
@ -431,15 +432,15 @@
else { else {
return array(); return array();
} }
} }
// synonyms: return original term // synonyms: return original term
function taxonomy_get_synonym_root($term) { function taxonomy_get_synonym_root($term) {
return db_fetch_object(db_query("SELECT * FROM term_synonym s, term_data t WHERE t.tid = s.tid AND s.name = '%s'", $term)); return db_fetch_object(db_query("SELECT * FROM term_synonym s, term_data t WHERE t.tid = s.tid AND s.name = '%s'", $term));
} }
// given a term id, count number of nodes in it // given a term id, count number of nodes in it
function taxonomy_term_count_nodes($tid) { function taxonomy_term_count_nodes($tid) {
static $count; static $count;
if (!$count) { if (!$count) {
@ -453,10 +454,10 @@
$children_count += taxonomy_term_count_nodes($c); $children_count += taxonomy_term_count_nodes($c);
} }
return $count[$tid] + $children_count; return $count[$tid] + $children_count;
} }
// helper for above function // helper for above function
function _taxonomy_term_children($tid) { function _taxonomy_term_children($tid) {
static $children; static $children;
if (!$children) { if (!$children) {
@ -466,23 +467,23 @@
} }
} }
return $children[$tid] ? $children[$tid] : array(); return $children[$tid] ? $children[$tid] : array();
} }
function taxonomy_get_vocabulary($vid) { function taxonomy_get_vocabulary($vid) {
// simple cache using a static var? // simple cache using a static var?
return db_fetch_object(db_query("SELECT * FROM vocabulary WHERE vid = '%s'", $vid)); return db_fetch_object(db_query("SELECT * FROM vocabulary WHERE vid = '%s'", $vid));
} }
function taxonomy_get_term($tid) { function taxonomy_get_term($tid) {
// simple cache using a static var? // simple cache using a static var?
return db_fetch_object(db_query("SELECT * FROM term_data WHERE tid = '%s'", $tid)); return db_fetch_object(db_query("SELECT * FROM term_data WHERE tid = '%s'", $tid));
} }
/* /*
** service functions ** service functions
*/ */
function _taxonomy_term_select($title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude = array()) { function _taxonomy_term_select($title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude = array()) {
taxonomy_get_tree($vocabulary_id, $tree); taxonomy_get_tree($vocabulary_id, $tree);
if ($blank) { if ($blank) {
@ -511,24 +512,24 @@
return form_item($title, "<select name=\"edit[$name][]\"". ($multiple ? " multiple size=\"$size\"" : "") . ($extra ? " $extra" : "") .">$select</select>", $description); return form_item($title, "<select name=\"edit[$name][]\"". ($multiple ? " multiple size=\"$size\"" : "") . ($extra ? " $extra" : "") .">$select</select>", $description);
} }
} }
function _taxonomy_depth($depth, $graphic = '--') { function _taxonomy_depth($depth, $graphic = '--') {
for ($n = 0; $n < $depth; $n++) { for ($n = 0; $n < $depth; $n++) {
$result .= $graphic; $result .= $graphic;
} }
return $result; return $result;
} }
function _prepare_update($data) { function _prepare_update($data) {
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
$q[] = "$key = '". check_query($value) ."'"; $q[] = "$key = '". check_query($value) ."'";
} }
$result = implode(", ", $q); $result = implode(", ", $q);
return $result; return $result;
} }
function _prepare_insert($data, $stage) { function _prepare_insert($data, $stage) {
if ($stage == 1) { if ($stage == 1) {
$result = implode(", ", array_keys($data)); $result = implode(", ", array_keys($data));
} }
@ -539,9 +540,9 @@
$result = implode(", ", $q); $result = implode(", ", $q);
} }
return "($result)"; return "($result)";
} }
function taxonomy_page() { function taxonomy_page() {
global $op; global $op;
switch ($op) { switch ($op) {
@ -551,13 +552,13 @@
default: default:
// TODO: pretty display of all vocabularies // TODO: pretty display of all vocabularies
} }
} }
/* /*
** admin ** admin
*/ */
function taxonomy_admin() { function taxonomy_admin() {
global $edit, $type, $op, $id, $tree; global $edit, $type, $op, $id, $tree;
if (user_access("administer taxonomy")) { if (user_access("administer taxonomy")) {
@ -602,11 +603,11 @@
else { else {
print message_access(); print message_access();
} }
} }
function taxonomy_help() { function taxonomy_help() {
?> ?>
<h3>Background</h3> <h3>Background</h3>
Classifying nodes allows for the organization of content into categories and Classifying nodes allows for the organization of content into categories and
subcategories of description. These categories can be used to organize and retrieve subcategories of description. These categories can be used to organize and retrieve
similarly described content. Drupal's <i>taxonomy.module</i> is an extremely flexible similarly described content. Drupal's <i>taxonomy.module</i> is an extremely flexible
@ -614,11 +615,11 @@
(controlled vocabularies) and offers the possibility of creating thesauri (controlled (controlled vocabularies) and offers the possibility of creating thesauri (controlled
vocabularies that indicate the relationship of terms) and taxonomies (controlled vocabularies that indicate the relationship of terms) and taxonomies (controlled
vocabularies where relationships are indicated hierarchically). For details about vocabularies where relationships are indicated hierarchically). For details about
<a href="http://www.eleganthack.com/archives/002165.html#002165">classification <a href="http://www.eleganthack.com/archives/002165.html#002165">classification
types</a> and insight into the development of <i>taxonomy.module</i>, see this types</a> and insight into the development of <i>taxonomy.module</i>, see this
<a href="http://www.drupal.org/node.php?id=55">drupal.org discussion</a>.<br /> <a href="http://www.drupal.org/node.php?id=55">drupal.org discussion</a>.<br />
<h3>An Example Taxonomy - Foods</h3> <h3>An Example Taxonomy - Foods</h3>
<p>Dairy <br /> <p>Dairy <br />
--Milk <br /> --Milk <br />
Drink <br /> Drink <br />
--Alchohol <br /> --Alchohol <br />
@ -630,14 +631,14 @@
--Lamb <br /> --Lamb <br />
Spices <br /> Spices <br />
--Sugar</p> --Sugar</p>
<p><b>Notes</b></p> <p><b>Notes</b></p>
<ul> <ul>
<li>The term <i>Milk</i> appears within both <i>Dairy</i> and <i>Drink</i>. <li>The term <i>Milk</i> appears within both <i>Dairy</i> and <i>Drink</i>.
This is an example of <i>Multiple Parents</i> for a term.</li> This is an example of <i>Multiple Parents</i> for a term.</li>
<li>The order of siblings (e.g. <i>Beef</i>, <i>Chicken</i>, <i>Lamb</i>) in <li>The order of siblings (e.g. <i>Beef</i>, <i>Chicken</i>, <i>Lamb</i>) in
the taxonomy may be controlled with the <i>Weight</i> parameter. </li> the taxonomy may be controlled with the <i>Weight</i> parameter. </li>
</ul> </ul>
<h4></h4> <h4></h4>
<h3>Vocabularies</h3> <h3>Vocabularies</h3>
When you create a controlled vocabulary you are creating a set of terms to use 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 for describing content (known as descriptors in indexing lingo). Drupal allows
@ -649,12 +650,12 @@
<h4>Setting up a vocabulary</h4> <h4>Setting up a vocabulary</h4>
<p>When you set up a controlled vocabulary, you will be asked to enter some descriptive <p>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 data and define the attributes of this vocabulary. For example, if you select
the <i>Hierarchy </i>option, you will be defining a taxonomy or a thesaurus. If the <i>Hierarchy </i>option, you will be defining a taxonomy or a thesaurus. If
you select <i>Related Terms</i> option, you are allowing the definition of related you select <i>Related Terms</i> option, you are allowing the definition of related
terms as in a thesaurus. Selecting <i>Multiple Select</i> will allow you to describe terms as in a thesaurus. Selecting <i>Multiple Select</i> will allow you to describe
a node using more than one term. That node will then appear in each term's page, 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.</p> thus increasing the chance that a user will find it.</p>
<i>Vocabulary name</i><br /> <i>Vocabulary name</i><br />
Required. The name for this vocabulary. Example: <i>Dairy</i>.<br /> Required. The name for this vocabulary. Example: <i>Dairy</i>.<br />
<br /> <br />
@ -673,33 +674,33 @@
Allows a tree-like taxonomy, as in our <i>Foods</i> example above<br /> Allows a tree-like taxonomy, as in our <i>Foods</i> example above<br />
<br /> <br />
<i>Multiple Select</i><br /> <i>Multiple Select</i><br />
Allows nodes to be described using more than one term. Nodes may then appear on Allows nodes to be described using more than one term. Nodes may then appear on
multiple taxonomy pages.<br /> multiple taxonomy pages.<br />
<h4>Adding terms to a vocabulary</h4> <h4>Adding terms to a vocabulary</h4>
The options you see when adding a term to a vocabulary will depend on what you The options you see when adding a term to a vocabulary will depend on what you
selected for <i>Related Terms</i>, <i>Hierarchy </i>and <i>Multiple Select</i> selected for <i>Related Terms</i>, <i>Hierarchy </i>and <i>Multiple Select</i>
when you created the corrosponding vocabulary.<br /> when you created the corrosponding vocabulary.<br />
<br /> <br />
<i>Term name</i><br /> <i>Term name</i><br />
Required. The name for this term. Example: <i>Milk</i><br /> Required. The name for this term. Example: <i>Milk</i><br />
<br /> <br />
<i>Description</i><br /> <i>Description</i><br />
Optional. Description of the term that may be used by modules and RSS feeds. Optional. Description of the term that may be used by modules and RSS feeds.
This is synonymous with a 'Scope note'.<br /> This is synonymous with a 'Scope note'.<br />
<br /> <br />
<i><a name="parent"></a>Parent</i><br /> <i><a name="parent"></a>Parent</i><br />
Required. Select the term under which this term is a subset -- the branch of the hierarchy 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 that this term belongs under. This is also known as the "Broader term" indicator
used in thesauri.<br /> used in thesauri.<br />
<br /> <br />
<i><a name="synonyms"></a>Synonyms</i><br /> <i><a name="synonyms"></a>Synonyms</i><br />
Optional. Enter synonyms for this term, one synonym per line. Synonyms can be used for 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 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. <i>unauthorized added term, but which are not explicitly listed in this thesaurus (i.e. <i>unauthorized
terms</i>).<br /> terms</i>).<br />
<h3>Displaying Nodes Organized by Term(s)</h3> <h3>Displaying Nodes Organized by Term(s)</h3>
<p>In order to view the nodes associated with a term or a collection of terms, you <p>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 should browse to a properly formed URL. For example, see
<a href="<?php print path_uri().drupal_url(array("mod" => "node", "or" => "1,2"), "module"); ?>"><?php print path_uri().drupal_url(array("mod" => "node", "or" => "1,2"), "module"); ?></a>. <a href="<?php print path_uri().drupal_url(array("mod" => "node", "or" => "1,2"), "module"); ?>"><?php print path_uri().drupal_url(array("mod" => "node", "or" => "1,2"), "module"); ?></a>.
Taxonomy URLs always contain a termID or list of termIDs at the end of the URL (aka <i>querystring</i>). Taxonomy URLs always contain a termID or list of termIDs at the end of the URL (aka <i>querystring</i>).
@ -708,12 +709,12 @@
Also, the name of the querystring parameter may be <i>or</i> or <i>and</i>. Also, the name of the querystring parameter may be <i>or</i> or <i>and</i>.
<i>or</i> shows nodes which appear in <b>any</b> of the termIDs while <i>and</i> shows nodes in <b>all</b> the specified termIDs. <i>or</i> shows nodes which appear in <b>any</b> of the termIDs while <i>and</i> shows nodes in <b>all</b> the specified termIDs.
Thus, <i>or</i> is less specific than <i>and</i>. Thus, <i>or</i> is less specific than <i>and</i>.
</p> </p>
<h3>RSS Feeds</h3> <h3>RSS Feeds</h3>
<p>Every term, or collection of terms, provides an <a href="http://backend.userland.com/stories/rss091">RSS</a> feed to which interested <p>Every term, or collection of terms, provides an <a href="http://backend.userland.com/stories/rss091">RSS</a> feed to which interested
users may subscribe. The URL format for an sample RSS feed is users may subscribe. The URL format for an sample RSS feed is
<a href="<?php print path_uri().drupal_url(array("mod" => "node", "op" => "feed", "or" => "1,2"), "module"); ?>"><?php print path_uri().drupal_url(array("mod" => "node", "op" => "feed", "or" => "1,2"), "module"); ?></a>.</p> <a href="<?php print path_uri().drupal_url(array("mod" => "node", "op" => "feed", "or" => "1,2"), "module"); ?>"><?php print path_uri().drupal_url(array("mod" => "node", "op" => "feed", "or" => "1,2"), "module"); ?></a>.</p>
<?php <?php
} }
?> ?>