Commit 9281d0cd authored by Dries's avatar Dries

- Applied Alastair's date patch.

- Removed all instances of '$user->nodes'.

- Committed Moshe's taxonomy patch - minus the node_compact_list() bit.  It needs a bit more thought/work.  This patch changes the links of taxonomy pages/feeds so update your custom code and themes accordingly!

Themes should now use "taxonomy_link("taxonomy terms", $node)" to get an array of taxonomy term links.  The old construct is deprecated and should be changed.

// old theme blob:
if (function_exists("taxonomy_node_get_terms")) {
  foreach (taxonomy_node_get_terms($node->nid) as $term) {
    $terms[] = l($term->name, NULL, array(), "or=$term->tid");
  }
}

// new theme blob:
if (module_exist("taxonomy")) {
  $terms = taxonomy_link("taxonomy terms", $node);
}

// old URL:
http://foo.com/index.php?or=1,2

// new URL:
http://foo.com/?q=taxonomy/page/or/1,2
parent 6953d95b
......@@ -40,16 +40,16 @@ function image($name) {
}
function node($node, $main) {
if (function_exists("taxonomy_node_get_terms")) {
foreach (taxonomy_node_get_terms($node->nid) as $term) {
$terms[] = l($term->name, NULL, array(), "or=$term->tid");
}
if (module_exist("taxonomy")) {
$terms = taxonomy_link("taxonomy terms", $node);
}
$output = "<b>$node->title</b> by ". format_name($node) ."<br />";
if (count($terms)) {
$output .= "<small>(". $this->links($terms) .")</small><br />";
}
if ($main && $node->teaser) {
$output .= check_output($node->teaser);
}
......
......@@ -155,23 +155,23 @@ function blog_page_user($uid = 0) {
$account = $user;
}
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND uid = '$account->uid' AND status = 1 ORDER BY nid DESC", $user->nodes ? $user->nodes : variable_get("default_nodes_main", 10));
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND uid = '$account->uid' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) {
node_view(node_load(array("nid" => $node->nid)), 1);
}
print pager_display(NULL, ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
print pager_display(NULL, variable_get("default_nodes_main", 10));
print l("<img align=\"right\" src=\"". $theme->image("xml.gif") ."\" width=\"36\" height=\"14\" border=\"0\" alt=\"\" />", "blog/feed/$account->uid", array("title" => t("View the XML version of %username's blog", array ("%username" => $account->name))));
}
function blog_page_last() {
global $user, $theme;
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND status = 1 ORDER BY nid DESC", $user->nodes ? $user->nodes : variable_get("default_nodes_main", 10));
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) {
$output = node_view(node_load(array("nid" => $node->nid)), 1);
}
$output .= pager_display(NULL, ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
$output .= pager_display(NULL, variable_get("default_nodes_main", 10));
$output .= l("<img align=\"right\" src=\"". $theme->image("xml.gif") ."\" width=\"36\" height=\"14\" border=\"0\" alt=\"\" />", "blog/feed", array("title" => t("Read the XML version of all blogs.")));
return $output;
}
......
......@@ -155,23 +155,23 @@ function blog_page_user($uid = 0) {
$account = $user;
}
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND uid = '$account->uid' AND status = 1 ORDER BY nid DESC", $user->nodes ? $user->nodes : variable_get("default_nodes_main", 10));
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND uid = '$account->uid' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) {
node_view(node_load(array("nid" => $node->nid)), 1);
}
print pager_display(NULL, ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
print pager_display(NULL, variable_get("default_nodes_main", 10));
print l("<img align=\"right\" src=\"". $theme->image("xml.gif") ."\" width=\"36\" height=\"14\" border=\"0\" alt=\"\" />", "blog/feed/$account->uid", array("title" => t("View the XML version of %username's blog", array ("%username" => $account->name))));
}
function blog_page_last() {
global $user, $theme;
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND status = 1 ORDER BY nid DESC", $user->nodes ? $user->nodes : variable_get("default_nodes_main", 10));
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) {
$output = node_view(node_load(array("nid" => $node->nid)), 1);
}
$output .= pager_display(NULL, ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
$output .= pager_display(NULL, variable_get("default_nodes_main", 10));
$output .= l("<img align=\"right\" src=\"". $theme->image("xml.gif") ."\" width=\"36\" height=\"14\" border=\"0\" alt=\"\" />", "blog/feed", array("title" => t("Read the XML version of all blogs.")));
return $output;
}
......
......@@ -19,18 +19,19 @@ function node_system($field){
return $system[$field];
}
// accepts a db result object which includes nid and title from node table, and name from the user table
// returns an HTML list suitable as content for a block, and eventually other uses.
/*
** Accepts a DB result object which can be used to fetch node objects.
** Returns an HTML list suitable as content for a block.
*/
function node_title_list($result, $title = NULL) {
// no queries if site is in distress
if (module_exist("statistics") && throttle_status() > 4) {
if (module_exist("statistics") && throttle_status() > 3) {
return;
}
while ($node = db_fetch_object($result)) {
$number = module_invoke("comment", "num_all", $node->nid);
$name = strip_tags(format_name($node)); // required for anonymous users to work
$items[] = l($node->title, "node/view/$node->nid", array("title" => t("Author: %name, comments: %number", array("%name" => $name, "%number" => $number))));
$items[] = l($node->title, "node/view/$node->nid", array("title" => t("Comments: %number", array("%number" => $number))));
}
return theme_invoke("theme_item_list", $items, $title);
......@@ -280,7 +281,7 @@ function node_view($node, $main = 0) {
/*
** Remove the delimiter (if any) that seperates the teaser from the
** body.
** body. TODO: this strips legitimate uses of --- also.
*/
$node->body = str_replace("---", "", $node->body);
......@@ -385,7 +386,7 @@ function node_search($keys) {
}
function node_conf_options() {
$output .= form_select(t("Number of posts on main page"), "default_nodes_main", variable_get("default_nodes_main", 10), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 25 => 25, 30 => 30), t("The default maximum number of posts to display on the main page."));
$output .= form_select(t("Number of posts on main page"), "default_nodes_main", variable_get("default_nodes_main", 10), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 25 => 25, 30 => 30), t("The default maximum number of posts to display on overview pages such as the main page."));
$output .= form_select(t("Length of trimmed posts"), "teaser_length", variable_get("teaser_length", 600), array(0 => t("Unlimited"), 200 => t("200 characters"), 400 => t("400 characters"), 600 => t("600 characters"), 800 => t("800 characters"), 1000 => t("1000 characters"), 1200 => t("1200 characters"), 1400 => t("1400 characters"), 1600 => t("1600 characters"), 1800 => t("1800 characters"), 2000 => t("2000 characters")), t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited'."));
return $output;
}
......@@ -712,7 +713,7 @@ function node_feed($nodes = 0, $channel = array()) {
$output .= "<?xml version=\"1.0\" ". t("encoding=\"ISO-8859-1\""). "?>\n";
$output .= "<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC \"-//W3C//ENTITIES Latin 1 for XHTML//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">]>\n";
// NOTE: &eacute; - for example - is the correct ISO-8859-1 translation of (e acute) but apparently XML parsers don't (have to) understand it. To solve this problem, we use a DTD that defines commonly used entity such as &eacute;.
// NOTE: &eacute; - for example - is the correct ISO-8859-1 translation of (e acute) but apparently XML parsers don't (have to) understand it. To solve this problem, we use a DTD that defines commonly used entity such as &eacute;.
if (!$channel["version"]) $channel["version"] = "0.91";
if (!$channel["title"]) $channel["title"] = variable_get("site_name", "drupal") ." - ". variable_get("site_slogan", "");
if (!$channel["link"]) $channel["link"] = path_uri();
......@@ -1264,35 +1265,12 @@ function node_page() {
$theme->box(t("Delete post"), node_delete($edit));
break;
default:
// prepare query
if ($or) {
foreach ((explode(",", $or)) as $t) {
$terms[] = "'".check_query($t)."'";
}
}
else if ($and) {
foreach ((explode(",", $and)) as $t) {
$terms[] = "'".check_query($t)."'";
}
}
if ($or) {
// this is an OR of terms
$result = pager_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", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
}
else if ($and) {
// this is an AND
$result = pager_query("SELECT n.nid, n.type 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, n.type, n.status, n.static, n.created HAVING COUNT(n.nid) = ".count($terms)." ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
}
else {
$result = pager_query("SELECT nid, type FROM node WHERE promote = '1' AND status = '1' ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
}
$result = pager_query("SELECT nid, type FROM node WHERE promote = '1' AND status = '1' ORDER BY static DESC, created DESC", variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) {
node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1);
}
print pager_display(NULL, ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
print pager_display(NULL, variable_get("default_nodes_main", 10));
}
}
else {
......
......@@ -19,18 +19,19 @@ function node_system($field){
return $system[$field];
}
// accepts a db result object which includes nid and title from node table, and name from the user table
// returns an HTML list suitable as content for a block, and eventually other uses.
/*
** Accepts a DB result object which can be used to fetch node objects.
** Returns an HTML list suitable as content for a block.
*/
function node_title_list($result, $title = NULL) {
// no queries if site is in distress
if (module_exist("statistics") && throttle_status() > 4) {
if (module_exist("statistics") && throttle_status() > 3) {
return;
}
while ($node = db_fetch_object($result)) {
$number = module_invoke("comment", "num_all", $node->nid);
$name = strip_tags(format_name($node)); // required for anonymous users to work
$items[] = l($node->title, "node/view/$node->nid", array("title" => t("Author: %name, comments: %number", array("%name" => $name, "%number" => $number))));
$items[] = l($node->title, "node/view/$node->nid", array("title" => t("Comments: %number", array("%number" => $number))));
}
return theme_invoke("theme_item_list", $items, $title);
......@@ -280,7 +281,7 @@ function node_view($node, $main = 0) {
/*
** Remove the delimiter (if any) that seperates the teaser from the
** body.
** body. TODO: this strips legitimate uses of --- also.
*/
$node->body = str_replace("---", "", $node->body);
......@@ -385,7 +386,7 @@ function node_search($keys) {
}
function node_conf_options() {
$output .= form_select(t("Number of posts on main page"), "default_nodes_main", variable_get("default_nodes_main", 10), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 25 => 25, 30 => 30), t("The default maximum number of posts to display on the main page."));
$output .= form_select(t("Number of posts on main page"), "default_nodes_main", variable_get("default_nodes_main", 10), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 25 => 25, 30 => 30), t("The default maximum number of posts to display on overview pages such as the main page."));
$output .= form_select(t("Length of trimmed posts"), "teaser_length", variable_get("teaser_length", 600), array(0 => t("Unlimited"), 200 => t("200 characters"), 400 => t("400 characters"), 600 => t("600 characters"), 800 => t("800 characters"), 1000 => t("1000 characters"), 1200 => t("1200 characters"), 1400 => t("1400 characters"), 1600 => t("1600 characters"), 1800 => t("1800 characters"), 2000 => t("2000 characters")), t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited'."));
return $output;
}
......@@ -712,7 +713,7 @@ function node_feed($nodes = 0, $channel = array()) {
$output .= "<?xml version=\"1.0\" ". t("encoding=\"ISO-8859-1\""). "?>\n";
$output .= "<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC \"-//W3C//ENTITIES Latin 1 for XHTML//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">]>\n";
// NOTE: &eacute; - for example - is the correct ISO-8859-1 translation of (e acute) but apparently XML parsers don't (have to) understand it. To solve this problem, we use a DTD that defines commonly used entity such as &eacute;.
// NOTE: &eacute; - for example - is the correct ISO-8859-1 translation of (e acute) but apparently XML parsers don't (have to) understand it. To solve this problem, we use a DTD that defines commonly used entity such as &eacute;.
if (!$channel["version"]) $channel["version"] = "0.91";
if (!$channel["title"]) $channel["title"] = variable_get("site_name", "drupal") ." - ". variable_get("site_slogan", "");
if (!$channel["link"]) $channel["link"] = path_uri();
......@@ -1264,35 +1265,12 @@ function node_page() {
$theme->box(t("Delete post"), node_delete($edit));
break;
default:
// prepare query
if ($or) {
foreach ((explode(",", $or)) as $t) {
$terms[] = "'".check_query($t)."'";
}
}
else if ($and) {
foreach ((explode(",", $and)) as $t) {
$terms[] = "'".check_query($t)."'";
}
}
if ($or) {
// this is an OR of terms
$result = pager_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", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
}
else if ($and) {
// this is an AND
$result = pager_query("SELECT n.nid, n.type 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, n.type, n.status, n.static, n.created HAVING COUNT(n.nid) = ".count($terms)." ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
}
else {
$result = pager_query("SELECT nid, type FROM node WHERE promote = '1' AND status = '1' ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
}
$result = pager_query("SELECT nid, type FROM node WHERE promote = '1' AND status = '1' ORDER BY static DESC, created DESC", variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) {
node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1);
}
print pager_display(NULL, ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
print pager_display(NULL, variable_get("default_nodes_main", 10));
}
}
else {
......
......@@ -74,8 +74,34 @@ function system_view_modules() {
$output .= "<hr />\n";
// date settings:
$output .= "<h3>" . t("Date format setting") . "</h3>\n";
$output .= form_select(t("Date format"), "date_format", variable_get("date_format", "m/d/Y - H:i"), array("m/d/Y - H:i" => "m/d/Y - H:i", "d/m/Y - H:i" => "d/m/Y - H:i", "Y/m/d - H:i" => "Y/m/d - H:i"), t("The format in which dates are displayed"));
$output .= "<h3>" . t("Date format settings") . "</h3>\n";
// date settings: possible date formats
$dateshort = array("m/d/Y - H:i", "d/m/Y - H:i", "Y/m/d - H:i",
"m/d/Y - g:ia", "d/m/Y - g:ia", "Y/m/d - g:ia",
"M j Y - H:i", "j M Y - H:i", "Y M j - H:i",
"M j Y - g:ia", "j M Y - g:ia", "Y M j - g:ia");
$datemedium = array("D, m/d/Y - H:i", "D, d/m/Y - H:i", "D, Y/m/d - H:i",
"F j, Y - H:i", "j F, Y - H:i", "Y, F j - H:i",
"D, m/d/Y - g:ia", "D, d/m/Y - g:ia", "D, Y/m/d - g:ia",
"F j, Y - g:ia", "j F, Y - g:ia", "Y, F j - g:ia");
$datelong = array("l, F j, Y - H:i", "l, j F, Y - H:i", "l, Y, F j - H:i",
"l, F j, Y - g:ia", "l, j F, Y - g:ia", "l, Y, F j - g:ia");
// date settings: construct choices for user
foreach ($dateshort as $f) {
$dateshortchoices[$f] = format_date(time(),"custom",$f);
}
foreach ($datemedium as $f) {
$datemediumchoices[$f] = format_date(time(),"custom",$f);
}
foreach ($datelong as $f) {
$datelongchoices[$f] = format_date(time(),"custom",$f);
}
$output .= form_select(t("Date format (short)"), "date_format_short", variable_get("date_format_short", $dateshort[0]), $dateshortchoices, t("The short format of date display."));
$output .= form_select(t("Date format (medium)"), "date_format_medium", variable_get("date_format_medium", $datemedium[0]), $datemediumchoices,t("The medium sized date display."));
$output .= form_select(t("Date format (long)"), "date_format_long", variable_get("date_format_long", $datelong[0]), $datelongchoices, t("Longer date format used for detailed display."));
$output .= "<hr />\n";
// layout settings:
......
......@@ -74,8 +74,34 @@ function system_view_modules() {
$output .= "<hr />\n";
// date settings:
$output .= "<h3>" . t("Date format setting") . "</h3>\n";
$output .= form_select(t("Date format"), "date_format", variable_get("date_format", "m/d/Y - H:i"), array("m/d/Y - H:i" => "m/d/Y - H:i", "d/m/Y - H:i" => "d/m/Y - H:i", "Y/m/d - H:i" => "Y/m/d - H:i"), t("The format in which dates are displayed"));
$output .= "<h3>" . t("Date format settings") . "</h3>\n";
// date settings: possible date formats
$dateshort = array("m/d/Y - H:i", "d/m/Y - H:i", "Y/m/d - H:i",
"m/d/Y - g:ia", "d/m/Y - g:ia", "Y/m/d - g:ia",
"M j Y - H:i", "j M Y - H:i", "Y M j - H:i",
"M j Y - g:ia", "j M Y - g:ia", "Y M j - g:ia");
$datemedium = array("D, m/d/Y - H:i", "D, d/m/Y - H:i", "D, Y/m/d - H:i",
"F j, Y - H:i", "j F, Y - H:i", "Y, F j - H:i",
"D, m/d/Y - g:ia", "D, d/m/Y - g:ia", "D, Y/m/d - g:ia",
"F j, Y - g:ia", "j F, Y - g:ia", "Y, F j - g:ia");
$datelong = array("l, F j, Y - H:i", "l, j F, Y - H:i", "l, Y, F j - H:i",
"l, F j, Y - g:ia", "l, j F, Y - g:ia", "l, Y, F j - g:ia");
// date settings: construct choices for user
foreach ($dateshort as $f) {
$dateshortchoices[$f] = format_date(time(),"custom",$f);
}
foreach ($datemedium as $f) {
$datemediumchoices[$f] = format_date(time(),"custom",$f);
}
foreach ($datelong as $f) {
$datelongchoices[$f] = format_date(time(),"custom",$f);
}
$output .= form_select(t("Date format (short)"), "date_format_short", variable_get("date_format_short", $dateshort[0]), $dateshortchoices, t("The short format of date display."));
$output .= form_select(t("Date format (medium)"), "date_format_medium", variable_get("date_format_medium", $datemedium[0]), $datemediumchoices,t("The medium sized date display."));
$output .= form_select(t("Date format (long)"), "date_format_long", variable_get("date_format_long", $datelong[0]), $datelongchoices, t("Longer date format used for detailed display."));
$output .= "<hr />\n";
// layout settings:
......
......@@ -6,35 +6,18 @@ function taxonomy_system($field){
return $system[$field];
}
function taxonomy_feed() {
global $id, $or, $and, $type;
function taxonomy_feed($taxonomy) {
global $id, $type;
if ($type == "voc") {
//TODO - vocabulary feed. How to represent an outline in XML?
//TODO - vocabulary feed.
}
else {
if ($or) {
foreach ((explode(",", $or)) as $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");
$term = taxonomy_get_term($or);
}
else if ($and) {
foreach ((explode(",", $and)) as $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, n.type HAVING c = ". count($terms) ." ORDER BY static DESC, created DESC LIMIT 15");
$term = taxonomy_get_term($and);
}
else {
return node_feed();
}
$result = taxonomy_select_nodes($taxonomy, 0);
$term = taxonomy_get_term($taxonomy->tids[0]);
$channel["link"] = path_uri(). url("taxonomy/view/$taxonomy->operator/$taxonomy->str_tids");
$channel["title"] = variable_get("site_name", "drupal") ." - ". $term->name;
$channel["link"] = path_uri() ."?or=$or";
$channel["description"] = $term->description;
node_feed($result, $channel);
}
}
......@@ -43,7 +26,7 @@ function taxonomy_perm() {
return array("administer taxonomy");
}
function taxonomy_link($type) {
function taxonomy_link($type, $node = NULL) {
if ($type == "admin" && user_access("administer taxonomy")) {
$help["taxonomy"] = "The taxonomy module allows you to classify post 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.";
......@@ -52,6 +35,23 @@ function taxonomy_link($type) {
menu_add("add new vocabulary", url("admin/taxonomy/add/vocabulary"), "Add a new vocabulary.", $help["vocabulary"], "taxonomy");
menu_add("help", url("admin/taxonomy/help"), "More information about taxonomies.", NULL, "taxonomy", 9);
}
else if ($type == "taxonomy terms" && $node != NULL) {
/*
** 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;
}
}
/*
......@@ -265,7 +265,6 @@ function _taxonomy_confirm_del_term($tid) {
}
function taxonomy_overview() {
global $tree;
$output .= "<h3>" . t("Vocabularies overview") . "</h3>";
......@@ -641,14 +640,66 @@ function _prepare_insert($data, $stage) {
return "($result)";
}
/*
** Accepts taxonomy conditions and returns a resource identifier. If
** you intend to use the nodes without a pager (eg. in a XML feed),
** then set $pager to false.
*/
function taxonomy_select_nodes($taxonomy, $pager = 1) {
global $user;
if ($taxonomy->operator == "or") {
$sql = "SELECT DISTINCT(n.nid), n.title, n.type, n.created, n.changed, n.uid, u.name FROM node n LEFT JOIN term_node r ON n.nid = r.nid LEFT JOIN users u ON n.uid = u.uid WHERE tid IN ($taxonomy->str_tids) AND n.status = '1' ORDER BY static DESC, created DESC";
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM node n LEFT JOIN term_node r ON n.nid = r.nid LEFT JOIN users u ON n.uid = u.uid WHERE tid IN ($taxonomy->str_tids) AND n.status = '1'";
}
else {
$sql = "SELECT n.nid, n.title, n.type, n.created, n.changed, n.uid, u.name FROM node n LEFT JOIN term_node r ON n.nid = r.nid LEFT JOIN users u ON n.uid = u.uid WHERE tid IN ($taxonomy->str_tids) AND n.status = '1' GROUP BY n.nid, n.title, n.type, n.created, n.changed, n.uid, u.name HAVING COUNT(n.nid) = ".count($taxonomy->tids)." ORDER BY static DESC, created DESC";
// Special trick as we could not find anything better:
$count = db_num_rows(db_query("SELECT n.nid FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN ($taxonomy->str_tids) AND n.status = '1' GROUP BY n.nid HAVING COUNT(n.nid) = ". count($taxonomy->tids)));
$sql_count = "SELECT $count";
}
if ($pager) {
$result = pager_query($sql, variable_get("default_nodes_main", 10) , 0, $sql_count);
}
else {
$result = db_query($sql ." LIMIT 15");
}
return $result;
}
/*
** Accepts the result of a db_query() and formats each node along
** with a pager.
*/
function taxonomy_render_nodes($result) {
while ($node = db_fetch_object($result)) {
node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1);
}
print pager_display_default(NULL, variable_get("default_nodes_main", 10), 0);
}
function taxonomy_page() {
global $theme;
// taxonomy querystring always parsed here
// TODO: support term *names* in URL (e.g. taxonomy/view/or/milk,beer,red+wine)
$taxonomy->operator = arg(2);
$taxonomy->str_tids = check_query(arg(3));
$taxonomy->tids = explode(",", $taxonomy->str_tids);
switch (arg(1)) {
case "feed":
taxonomy_feed();
taxonomy_feed($taxonomy);
break;
default:
// TODO: pretty display of all vocabularies
$theme->header();
taxonomy_render_nodes(taxonomy_select_nodes($taxonomy));
$theme->footer();
break;
}
}
......
......@@ -6,35 +6,18 @@ function taxonomy_system($field){
return $system[$field];
}
function taxonomy_feed() {
global $id, $or, $and, $type;
function taxonomy_feed($taxonomy) {
global $id, $type;
if ($type == "voc") {
//TODO - vocabulary feed. How to represent an outline in XML?
//TODO - vocabulary feed.
}
else {
if ($or) {
foreach ((explode(",", $or)) as $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");
$term = taxonomy_get_term($or);
}
else if ($and) {
foreach ((explode(",", $and)) as $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, n.type HAVING c = ". count($terms) ." ORDER BY static DESC, created DESC LIMIT 15");
$term = taxonomy_get_term($and);
}
else {
return node_feed();
}
$result = taxonomy_select_nodes($taxonomy, 0);
$term = taxonomy_get_term($taxonomy->tids[0]);
$channel["link"] = path_uri(). url("taxonomy/view/$taxonomy->operator/$taxonomy->str_tids");
$channel["title"] = variable_get("site_name", "drupal") ." - ". $term->name;
$channel["link"] = path_uri() ."?or=$or";
$channel["description"] = $term->description;
node_feed($result, $channel);
}
}
......@@ -43,7 +26,7 @@ function taxonomy_perm() {
return array("administer taxonomy");
}
function taxonomy_link($type) {
function taxonomy_link($type, $node = NULL) {
if ($type == "admin" && user_access("administer taxonomy")) {
$help["taxonomy"] = "The taxonomy module allows you to classify post 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.";
......@@ -52,6 +35,23 @@ function taxonomy_link($type) {
menu_add("add new vocabulary", url("admin/taxonomy/add/vocabulary"), "Add a new vocabulary.", $help["vocabulary"], "taxonomy");
menu_add("help", url("admin/taxonomy/help"), "More information about taxonomies.", NULL, "taxonomy", 9);
}
else if ($type == "taxonomy terms" && $node != NULL) {
/*
** 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;
}
}
/*
......@@ -265,7 +265,6 @@ function _taxonomy_confirm_del_term($tid) {
}
function taxonomy_overview() {
global $tree;
$output .= "<h3>" . t("Vocabularies overview") . "</h3>";
......@@ -641,14 +640,66 @@ function _prepare_insert($data, $stage) {
return "($result)";
}
/*
** Accepts taxonomy conditions and returns a resource identifier. If
** you intend to use the nodes without a pager (eg. in a XML feed),
** then set $pager to false.
*/
function taxonomy_select_nodes($taxonomy, $pager = 1) {
global $user;
if ($taxonomy->operator == "or") {
$sql = "SELECT DISTINCT(n.nid), n.title, n.type, n.created, n.changed, n.uid, u.name FROM node n LEFT JOIN term_node r ON n.nid = r.nid LEFT JOIN users u ON n.uid = u.uid WHERE tid IN ($taxonomy->str_tids) AND n.status = '1' ORDER BY static DESC, created DESC";
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM node n LEFT JOIN term_node r ON n.nid = r.nid LEFT JOIN users u ON n.uid = u.uid WHERE tid IN ($taxonomy->str_tids) AND n.status = '1'";
}
else {
$sql = "SELECT n.nid, n.title, n.type, n.created, n.changed, n.uid, u.name FROM node n LEFT JOIN term_node r ON n.nid = r.nid LEFT JOIN users u ON n.uid = u.uid WHERE tid IN ($taxonomy->str_tids) AND n.status = '1' GROUP BY n.nid, n.title, n.type, n.created, n.changed, n.uid, u.name HAVING COUNT(n.nid) = ".count($taxonomy->tids)." ORDER BY static DESC, created DESC";
// Special trick as we could not find anything better:
$count = db_num_rows(db_query("SELECT n.nid FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN ($taxonomy->str_tids) AND n.status = '1' GROUP BY n.nid HAVING COUNT(n.nid) = ". count($taxonomy->tids)));
$sql_count = "SELECT $count";
}
if ($pager) {
$result = pager_query($sql, variable_get("default_nodes_main", 10) , 0, $sql_count);
}
else {
$result = db_query($sql ." LIMIT 15");
}
return $result;
}
/*
** Accepts the result of a db_query() and formats each node along
** with a pager.
*/
function taxonomy_render_nodes($result) {
while ($node = db_fetch_object($result)) {
node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1);
}
print pager_display_default(NULL, variable_get("default_nodes_main", 10), 0);
}
function taxonomy_page() {
global $theme;