summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/taxonomy/taxonomy.module66
-rw-r--r--modules/taxonomy/taxonomy.pages.inc156
2 files changed, 88 insertions, 134 deletions
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 9fb5a54d5..a8996514d 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -168,15 +168,17 @@ function taxonomy_menu() {
'type' => MENU_LOCAL_TASK,
);
- $items['taxonomy/term/%taxonomy_terms'] = array(
+ $items['taxonomy/term/%taxonomy_term'] = array(
'title' => 'Taxonomy term',
+ 'title callback' => 'taxonomy_term_title',
+ 'title arguments' => array(2),
'page callback' => 'taxonomy_term_page',
'page arguments' => array(2),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
- $items['taxonomy/term/%taxonomy_terms/view'] = array(
+ $items['taxonomy/term/%taxonomy_term/view'] = array(
'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
@@ -189,7 +191,15 @@ function taxonomy_menu() {
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
-
+ $items['taxonomy/term/%taxonomy_term/feed'] = array(
+ 'title' => 'Taxonomy term',
+ 'title callback' => 'taxonomy_term_title',
+ 'title arguments' => array(2),
+ 'page callback' => 'taxonomy_term_feed',
+ 'page arguments' => array(2),
+ 'access arguments' => array('access content'),
+ 'type' => MENU_CALLBACK,
+ );
$items['taxonomy/autocomplete'] = array(
'title' => 'Autocomplete taxonomy',
'page callback' => 'taxonomy_autocomplete',
@@ -1331,17 +1341,6 @@ function taxonomy_vocabulary_load($vid) {
}
/**
- * Return array of tids and join operator.
- *
- * This is a wrapper function for taxonomy_terms_parse_string which is called
- * by the menu system when loading a path with taxonomy terms.
- */
-function taxonomy_terms_load($str_tids) {
- $terms = taxonomy_terms_parse_string($str_tids);
- return $terms;
-}
-
-/**
* Load multiple taxonomy terms based on certain conditions.
*
* This function should be used whenever you need to load more than one term
@@ -1408,6 +1407,7 @@ function taxonomy_term_load_multiple($tids = array(), $conditions = array()) {
// $tids still to load, or if $conditions was passed without $tids.
if ($tids || ($conditions && !$passed_tids)) {
$query = db_select('taxonomy_term_data', 't');
+ $query->addTag('term_access');
$query->join('taxonomy_vocabulary', 'v', 't.vid = v.vid');
$taxonomy_term_data = drupal_schema_fields_sql('taxonomy_term_data');
$query->addField('v', 'machine_name', 'vocabulary_machine_name');
@@ -1731,32 +1731,6 @@ function taxonomy_node_update_index($node) {
}
/**
- * Parses a comma or plus separated string of term IDs.
- *
- * @param $str_tids
- * A string of term IDs, separated by plus or comma.
- * comma (,) means AND
- * plus (+) means OR
- *
- * @return an associative array with an operator key (either 'and'
- * or 'or') and a tid key containing an array of the term ids.
- */
-function taxonomy_terms_parse_string($str_tids) {
- $terms = array('operator' => '', 'tids' => array());
- if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str_tids)) {
- $terms['operator'] = 'or';
- // The '+' character in a query string may be parsed as ' '.
- $terms['tids'] = preg_split('/[+ ]/', $str_tids);
- }
- elseif (preg_match('/^([0-9]+,)*[0-9]+$/', $str_tids)) {
- $terms['operator'] = 'and';
- $terms['tids'] = explode(',', $str_tids);
- }
- $terms['str_tids'] = $str_tids;
- return $terms;
-}
-
-/**
* Implement hook_help().
*/
function taxonomy_help($path, $arg) {
@@ -1840,3 +1814,15 @@ function taxonomy_hook_info() {
),
);
}
+
+/**
+ * Title callback for term pages.
+ *
+ * @param $term
+ * A term object.
+ * @return
+ * The term name to be used as the page title.
+ */
+function taxonomy_term_title($term) {
+ return check_plain($term->name);
+}
diff --git a/modules/taxonomy/taxonomy.pages.inc b/modules/taxonomy/taxonomy.pages.inc
index e2cdf516e..983ea3ac9 100644
--- a/modules/taxonomy/taxonomy.pages.inc
+++ b/modules/taxonomy/taxonomy.pages.inc
@@ -8,104 +8,72 @@
/**
* Menu callback; displays all nodes associated with a term.
+ *
+ * @param $term
+ * The taxonomy term.
+ * @return
+ * The page content.
*/
-function taxonomy_term_page($terms, $depth = 0, $op = 'page') {
- if ($terms['operator'] != 'and' && $terms['operator'] != 'or') {
- drupal_not_found();
+function taxonomy_term_page($term) {
+ // Build breadcrumb based on the hierarchy of the term.
+ $current = (object) array(
+ 'tid' => $term->tid,
+ );
+ $breadcrumb = array();
+ while ($parents = taxonomy_get_parents($current->tid)) {
+ $current = array_shift($parents);
+ $breadcrumb[] = l($current->name, taxonomy_term_path($current));
+ }
+ $breadcrumb[] = l(t('Home'), NULL);
+ $breadcrumb = array_reverse($breadcrumb);
+ drupal_set_breadcrumb($breadcrumb);
+ drupal_add_feed(url('taxonomy/term/' . $term->tid . '/feed'), 'RSS - ' . $term->name);
+ drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css');
+
+ $build = array();
+ $build += field_attach_view('taxonomy_term', $term);
+ if (!empty($term->description)) {
+ $build['term_description'] = array(
+ '#markup' => filter_xss_admin($term->description),
+ '#weight' => -1,
+ '#prefix' => '<div class="taxonomy-term-description">',
+ '#suffix' => '</div>',
+ );
}
- $str_tids = $terms['str_tids'];
-
- if ($terms['tids']) {
- $query = db_select('taxonomy_term_data', 't');
- $query->addTag('term_access');
-
- // Load array with all tid's the user has access to in the format tid => name.
- $term_results = $query
- ->fields('t', array('tid', 'name'))
- ->condition('tid', $terms['tids'], 'IN')
- ->execute()
- ->fetchAllKeyed();
- $tids = array_keys($term_results);
- $names = array_values($term_results);
-
- if ($names) {
- $title = implode(', ', $names);
- drupal_set_title($title);
-
- switch ($op) {
- case 'page':
- // Build breadcrumb based on first hierarchy of first term:
- $current = (object) array(
- 'tid' => $tids[0],
- );
- $breadcrumb = array();
- while ($parents = taxonomy_get_parents($current->tid)) {
- $current = array_shift($parents);
- $breadcrumb[] = l($current->name, taxonomy_term_path($current));
- }
- $breadcrumb[] = l(t('Home'), NULL);
- $breadcrumb = array_reverse($breadcrumb);
- drupal_set_breadcrumb($breadcrumb);
- drupal_add_feed(url('taxonomy/term/' . $str_tids . '/' . $depth . '/feed'), 'RSS - ' . $title);
- drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css');
-
- $build = array();
- // Only display fields if we have a single term, to avoid clutter and
- // confusion.
- if (count($tids) == 1) {
- $term = taxonomy_term_load($tids[0]);
- $build += field_attach_view('taxonomy_term', $term);
- if (!empty($term->description)) {
- $build['term_description'] = array(
- '#markup' => filter_xss_admin($term->description),
- '#weight' => -1,
- '#prefix' => '<div class="taxonomy-term-description">',
- '#suffix' => '</div>',
- );
- }
- }
-
- if ($nids = taxonomy_select_nodes($tids, $terms['operator'], $depth, TRUE)) {
- $nodes = node_load_multiple($nids);
- $build += node_build_multiple($nodes);
- $build['pager'] = array(
- '#markup' => theme('pager', NULL),
- '#weight' => 5,
- );
- }
- else {
- $build['no_content'] = array(
- '#prefix' => '<p>',
- '#markup' => t('There are currently no posts in this category.'),
- '#suffix' => '</p>',
- );
- }
-
- return $build;
-
- case 'feed':
- $channel['link'] = url('taxonomy/term/' . $str_tids . '/' . $depth, array('absolute' => TRUE));
- $channel['title'] = variable_get('site_name', 'Drupal') . ' - ' . $title;
- // Only display the description if we have a single term, to avoid clutter and confusion.
- if (count($tids) == 1) {
- $term = taxonomy_term_load($tids[0]);
- // HTML will be removed from feed description, so no need to filter here.
- $channel['description'] = $term->description;
- }
-
- $nids = taxonomy_select_nodes($tids, $terms['operator'], $depth, FALSE);
-
- node_feed($nids, $channel);
- break;
- default:
- drupal_not_found();
- }
- }
- else {
- drupal_not_found();
- }
+ if ($nids = taxonomy_select_nodes(array($term->tid), NULL, TRUE)) {
+ $nodes = node_load_multiple($nids);
+ $build += node_build_multiple($nodes);
+ $build['pager'] = array(
+ '#markup' => theme('pager', NULL),
+ '#weight' => 5,
+ );
+ }
+ else {
+ $build['no_content'] = array(
+ '#prefix' => '<p>',
+ '#markup' => t('There are currently no posts in this category.'),
+ '#suffix' => '</p>',
+ );
}
+ return $build;
+}
+
+/**
+ * Generate the content feed for a taxonomy term.
+ *
+ * @param $term
+ * The taxonomy term.
+ */
+function taxonomy_term_feed($term) {
+ $channel['link'] = url('taxonomy/term/' . $term->tid, array('absolute' => TRUE));
+ $channel['title'] = variable_get('site_name', 'Drupal') . ' - ' . $term->name;
+ // Only display the description if we have a single term, to avoid clutter and confusion.
+ // HTML will be removed from feed description, so no need to filter here.
+ $channel['description'] = $term->description;
+ $nids = taxonomy_select_nodes(array($term->tid, NULL, NULL, FALSE));
+
+ node_feed($nids, $channel);
}
/**