diff options
author | Kjartan Mannes <kjartan@2.no-reply.drupal.org> | 2002-04-22 09:05:36 +0000 |
---|---|---|
committer | Kjartan Mannes <kjartan@2.no-reply.drupal.org> | 2002-04-22 09:05:36 +0000 |
commit | de5b9a168daeef12b6f7bcf6e43b767a2d7f35d8 (patch) | |
tree | 8b0aa9828f941161183b27e74b6fdc0a167e0021 /modules/taxonomy/taxonomy.module | |
parent | 5b5551674d3721cee39c21dd6843700315521f91 (diff) | |
download | brdo-de5b9a168daeef12b6f7bcf6e43b767a2d7f35d8.tar.gz brdo-de5b9a168daeef12b6f7bcf6e43b767a2d7f35d8.tar.bz2 |
- bug fixes:
* fixed mails not being parsed properly.
* tracker now shows user name when you view your own recent
comments.
* link to submission queue now points to the right place.
* fixed jabber module.
* theme is now activated when changed.
- applied Gerhards coding style patch.
Diffstat (limited to 'modules/taxonomy/taxonomy.module')
-rw-r--r-- | modules/taxonomy/taxonomy.module | 146 |
1 files changed, 70 insertions, 76 deletions
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index fdac7c715..ad0833203 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -9,24 +9,24 @@ else { if ($or) { foreach ((explode(",", $or)) as $t) { - $terms[] = "'".check_query($t)."'"; + $terms[] = "'". check_query($t) ."'"; } - $result = db_query("SELECT DISTINCT(n.nid), type FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND status = '1' ORDER BY static DESC, created DESC LIMIT 15"); + $result = db_query("SELECT DISTINCT(n.nid), type FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (". implode(",", $terms) .") AND status = '1' ORDER BY static DESC, created DESC LIMIT 15"); $term = taxonomy_get_term($or); } else if ($and) { foreach ((explode(",", $and)) as $t) { - $terms[] = "'".check_query($t)."'"; + $terms[] = "'". check_query($t) ."'"; } - $result = db_query("SELECT n.nid, type, count(*) AS c FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND status = '1' GROUP BY n.nid HAVING c = ".count($terms)." ORDER BY static DESC, created DESC LIMIT 15"); + $result = db_query("SELECT n.nid, type, count(*) AS c FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (". implode(",", $terms) .") AND status = '1' GROUP BY n.nid HAVING c = ". count($terms) ." ORDER BY static DESC, created DESC LIMIT 15"); $term = taxonomy_get_term($and); } else { return node_feed(); } - $channel["title"] = variable_get("site_name", "drupal") . " - " . $term->name; - $channel["link"] = path_uri() . "index.php?or=$or"; + $channel["title"] = variable_get("site_name", "drupal") ." - ". $term->name; + $channel["link"] = path_uri() ."index.php?or=$or"; $channel["description"] = $term->description; node_feed($result, $channel); @@ -56,43 +56,35 @@ } } - $form .= form_textfield("Vocabulary name", "name", $edit[name], 50, 64, "Required. The name for this vocabulary. Example: 'Topic'."); - $form .= form_textarea("Description", "description", $edit[description], 60, 5, "Optional. Description of the vocabulary, can be used by modules."); - $form .= form_select("Types", "types", explode(",", $edit[types]), $nodetypes, "Required. A list of node types you want to associate this vocabulary with.", "", 1); - $form .= form_checkbox("Related terms", "relations", 1, $edit[relations], "Optional. Allows ".la("related terms", array("mod" => "taxonomy", "op" => "help#relatedterms"))." in this vocabulary."); - $form .= form_select("Hierarchy", "hierarchy", $edit[hierarchy], array("Disabled", "Single", "Multiple"), "Optional. Allows ".la("a tree-like hierarchy", array("mod" => "taxonomy", "op" => "help#hierarchy"))." between terms of this vocabulary.", "", 0); - $form .= form_checkbox("Multiple select", "multiple", 1, $edit[multiple], "Optional. Allows nodes to have more than one term in this vocabulary."); - $form .= form_checkbox("Required", "required", 1, $edit[required], "If enabled every node <b>must</b> have at least one term in this vocabulary"); + $form .= form_textfield("Vocabulary name", "name", $edit["name"], 50, 64, "Required. The name for this vocabulary. Example: 'Topic'."); + $form .= form_textarea("Description", "description", $edit["description"], 60, 5, "Optional. Description of the vocabulary, can be used by modules."); + $form .= form_select("Types", "types", explode(",", $edit["types"]), $nodetypes, "Required. A list of node types you want to associate this vocabulary with.", "", 1); + $form .= form_checkbox("Related terms", "relations", 1, $edit["relations"], "Optional. Allows ". la("related terms", array("mod" => "taxonomy", "op" => "help#relatedterms")) ." in this vocabulary."); + $form .= form_select("Hierarchy", "hierarchy", $edit["hierarchy"], array("Disabled", "Single", "Multiple"), "Optional. Allows ". la("a tree-like hierarchy", array("mod" => "taxonomy", "op" => "help#hierarchy")) ." between terms of this vocabulary.", "", 0); + $form .= form_checkbox("Multiple select", "multiple", 1, $edit["multiple"], "Optional. Allows nodes to have more than one term in this vocabulary."); + $form .= form_checkbox("Required", "required", 1, $edit["required"], "If enabled every node <b>must</b> have at least one term in this vocabulary"); $form .= form_textfield("Weight", "weight", $edit["weight"], 3, 3, "Optional. In listings, the heavier vocabularies will sink and the lighter vocabularies will be positioned nearer the top."); $form .= form_submit("Submit"); - if ($edit[vid]) { + if ($edit["vid"]) { $form .= form_submit("Delete"); - $form .= form_hidden("vid", $edit[vid]); + $form .= form_hidden("vid", $edit["vid"]); } return form($form); } 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"]) { - 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"]) ."'"); } else if ($edit["vid"]) { taxonomy_del_vocabulary($edit["vid"]); } 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)); } } @@ -125,13 +117,14 @@ $exclude = array_keys($children); $exclude[] = $edit["tid"]; if ($vocabulary->hierarchy == 1) { - $form .= _taxonomy_term_select("Parent", "parent", $parent, $vocabulary_id, "Required. ".la("Parent term", array("mod" => "taxonomy", "op" => "help#parent")).".", 0, "<root>", $exclude); - } elseif ($vocabulary->hierarchy == 2) { - $form .= _taxonomy_term_select("Parents", "parent", $parent, $vocabulary_id, "Required. ".la("Parent terms", array("mod" => "taxonomy", "op" => "help#parent")).".", 1, "<root>", $exclude); + $form .= _taxonomy_term_select("Parent", "parent", $parent, $vocabulary_id, "Required. ". la("Parent term", array("mod" => "taxonomy", "op" => "help#parent")) .".", 0, "<root>", $exclude); + } + elseif ($vocabulary->hierarchy == 2) { + $form .= _taxonomy_term_select("Parents", "parent", $parent, $vocabulary_id, "Required. ". la("Parent terms", array("mod" => "taxonomy", "op" => "help#parent")) .".", 1, "<root>", $exclude); } } - $form .= form_textarea("Synonyms", "synonyms", implode("\n", taxonomy_get_synonyms($edit["tid"])), 30, 5, "Optional. ".la("Synonyms", array("mod" => "taxonomy", "op" => "help#synonyms"))." of this term, one synonym per line."); + $form .= form_textarea("Synonyms", "synonyms", implode("\n", taxonomy_get_synonyms($edit["tid"])), 30, 5, "Optional. ". la("Synonyms", array("mod" => "taxonomy", "op" => "help#synonyms")) ." of this term, one synonym per line."); $form .= form_textfield("Weight", "weight", $edit["weight"], 3, 3, "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("Submit"); @@ -146,13 +139,9 @@ function taxonomy_save_term($edit) { 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"]); - db_query("UPDATE term_data SET "._prepare_update($data)." WHERE tid = '%s'", $edit["tid"]); + db_query("UPDATE term_data SET ". _prepare_update($data) ." WHERE tid = '%s'", $edit["tid"]); } else if ($edit["tid"]) { taxonomy_del_term($edit["tid"]); @@ -163,14 +152,8 @@ // first term $edit["tid"] = 1; } - $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)); + $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)); } // relations (seem very powerful, but I have to understand it completely) @@ -196,8 +179,9 @@ foreach ($edit["parent"] as $parent) { $sql[] = "('". check_query($edit["tid"]) ."', '". check_query($parent) ."')"; } - db_query("INSERT INTO term_hierarchy (tid, parent) VALUES ".implode(", ", $sql)); - } else { + db_query("INSERT INTO term_hierarchy (tid, parent) VALUES ". implode(", ", $sql)); + } + else { db_query("INSERT INTO term_hierarchy (tid, parent) VALUES ('%s', '%s')", $edit["tid"], $edit["parent"][0]); } @@ -233,14 +217,14 @@ $links[] = la(t("add term"), array("mod" => "taxonomy", "op" => "add", "type" => "leaf", "vocabulary_id" => $vocabulary->vid)); $links[] = la(t("preview form"), array("mod" => "taxonomy", "type" => "vocabulary", "op" => "preview", "id" => $vocabulary->vid)); - $output .= " <tr><td>". check_output($vocabulary->name) ."</td><td>". check_output($vocabulary->types) ."</td><td>".implode(" | ", $links)."</td></tr>\n"; + $output .= " <tr><td>". check_output($vocabulary->name) ."</td><td>". check_output($vocabulary->types) ."</td><td>". implode(" | ", $links) ."</td></tr>\n"; unset($tree); taxonomy_get_tree($vocabulary->vid, $tree); if ($tree) { $output .= "<tr><td colspan=\"3\"><table><tr><td>"; 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"; } @@ -255,14 +239,16 @@ if ($vocabulary->required) { $verb = "must"; $blank = 0; - } else { + } + else { $verb = "can"; $blank = "<none>"; } if ($vocabulary->multiple) { $description = "You $verb choose one or more terms for this node"; $multiple = 1; - } else { + } + else { $description = "You $verb choose one term for this node"; $multiple = 0; } @@ -277,7 +263,8 @@ function taxonomy_get_vocabularies($type = '', $key = "vid") { if ($type) { $result = db_query("SELECT * FROM vocabulary WHERE types LIKE '%%%s%%' ORDER BY weight, name", $type); - } else { + } + else { $result = db_query("SELECT * FROM vocabulary ORDER BY weight, name"); } $vocabularies = array(); @@ -292,10 +279,12 @@ if (!$node->taxonomy) { if ($node->nid) { $terms = array_keys(taxonomy_node_get_terms($node->nid)); - } else { + } + else { $terms = 0; } - } else { + } + else { $terms = $node->taxonomy; } @@ -343,9 +332,9 @@ if ($terms) { foreach ($terms as $t) { - $query[] = "('".check_query($nid)."', '".check_query($t)."')"; + $query[] = "('". check_query($nid) ."', '". check_query($t) ."')"; } - db_query("INSERT INTO term_node (nid, tid) VALUES ".implode(", ", $query)); + db_query("INSERT INTO term_node (nid, tid) VALUES ". implode(", ", $query)); } } @@ -375,7 +364,8 @@ $parents[$parent->$key] = $parent; } return $parents; - } else { + } + else { return array(); } } @@ -384,7 +374,8 @@ function taxonomy_get_children($tid, $vid = 0, $key = "tid") { 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); - } else { + } + else { $result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE h.tid = t.tid AND parent = '%s' ORDER BY weight", $tid); } $children = array(); @@ -418,7 +409,8 @@ taxonomy_get_tree($vocabulary_id, $tree, $child, $depth, $key); } } - } else { + } + else { return 0; } } @@ -431,7 +423,8 @@ $synonyms[] = $synonym["name"]; } return $synonyms ? $synonyms : array(); - } else { + } + else { return array(); } } @@ -512,12 +505,12 @@ // min 8, possibly options/3 (set max too?) $size = max(8, round(count($options)) / 3); - 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 = '--') { - for ($n=0; $n<$depth; $n++) { + for ($n = 0; $n < $depth; $n++) { $result .= $graphic; } return $result; @@ -534,7 +527,8 @@ function _prepare_insert($data, $stage) { if ($stage == 1) { $result = implode(", ", array_keys($data)); - } else { + } + else { foreach (array_values($data) as $value) { $q[] = "'". check_query($value) ."'"; } @@ -567,7 +561,7 @@ $links[] = la(t("overview"), array("mod" => "taxonomy")); $links[] = la(t("help"), array("mod" => "taxonomy", "op" => "help")); - print "<small>".implode(" | ", $links)."</small><hr>\n"; + print "<small>". implode(" | ", $links) ."</small><hr>\n"; switch ($op) { case "add": @@ -589,7 +583,7 @@ print taxonomy_help(); break; case "Delete": - $edit[name] = 0; + $edit["name"] = 0; // fall through: case "Submit": if ($type == "vocabulary") @@ -620,17 +614,17 @@ 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 /> <h3>An Example Taxonomy - Foods</h3> - <p>Dairy <br> - --Milk <br> - Drink <br> - --Alchohol <br> - --Pop <br> - --Milk<br> - Meat <br> - --Beef <br> - --Chicken <br> - --Lamb <br> - Spices <br> + <p>Dairy <br /> + --Milk <br /> + Drink <br /> + --Alchohol <br /> + --Pop <br /> + --Milk<br /> + Meat <br /> + --Beef <br /> + --Chicken <br /> + --Lamb <br /> + Spices <br /> --Sugar</p> <p><b>Notes</b></p> <ul> |