Download & Extend

Taxonomy browser for drupal 7

Project:Taxonomy Browser
Version:master
Component:Code
Category:support request
Priority:normal
Assigned:yoann54
Status:active

Issue Summary

This module would be perfect on drupal 7 anyone knows if there will be soon a dev version of it ?

i'm ready to work on the french translation po

yoann

Comments

#1

subscribing

#2

yes i would like to work on it in order to make it appear on drupal 7 so i will try to understand the code little by little..............i really think this module is one of the best module for drupal cauz it gives peoples the opportunity to construct their own page.......should be in the core of d7 ! Thanks nancy to help us to work on it....

#3

Hi,

after running this module with coder...we have now a base to work (where there is "todo" or "TODO" are the things we have to change manually......)

Franck

Only in /home/boombato/public_html_d7/sites/upgrade.boombatower.com/files/coder_upgrade/old/tar_extract: form_fun
diff -up -r taxonomy_browser/taxonomy_browser.info taxonomy_browser/taxonomy_browser.info
--- taxonomy_browser/taxonomy_browser.info 2011-02-25 01:52:21.000000000 -0600
+++ taxonomy_browser/taxonomy_browser.info 2011-03-25 13:36:43.000000000 -0500
@@ -1,9 +1,12 @@
name = Taxonomy Browser
description = Enables users to construct their own view of content from terms across multiple vocabularies.
-core = 6.x
+core = 7.x
; Information added by drupal.org packaging script on 2011-02-25
version = "6.x-1.x-dev"
-core = "6.x"
+core = 7.x
project = "taxonomy_browser"
datestamp = "1298620341"

+
+files[] = taxonomy_browser.install
+files[] = taxonomy_browser.module
diff -up -r taxonomy_browser/taxonomy_browser.install taxonomy_browser/taxonomy_browser.install
--- taxonomy_browser/taxonomy_browser.install 2011-02-24 20:06:04.000000000 -0600
+++ taxonomy_browser/taxonomy_browser.install 2011-03-25 13:36:43.000000000 -0500
@@ -6,15 +6,19 @@
*/

/**
- * Implementation of hook_enable().
+ * Implements hook_enable().
*/
function taxonomy_browser_enable() {
- drupal_set_message(t('The Taxonomy Browser module has been enabled. You may wish to go to the settings page.', array('!url' => url('admin/settings/taxonomy-browser'))));
+ drupal_set_message(t('The Taxonomy Browser module has been enabled. You may wish to go to the settings page.', array('!url' => url('admin/config/taxonomy-browser'))));
}

/* Implementation of hook_uninstall.
* There are no tables, so we just delete all variables.
*/
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
function taxonomy_browser_uninstall() {
global $user;

diff -up -r taxonomy_browser/taxonomy_browser.module taxonomy_browser/taxonomy_browser.module
--- taxonomy_browser/taxonomy_browser.module 2011-02-24 20:06:04.000000000 -0600
+++ taxonomy_browser/taxonomy_browser.module 2011-03-25 13:36:43.000000000 -0500
@@ -3,7 +3,7 @@

/**
* @file
- * Enables users to construct their own view of content from terms across
+ * Enables users to construct their own view of content from terms across
* multiple vocabularies.
*/

@@ -12,7 +12,7 @@
//*******************************************************************
<?php
/**
- * Implementation of hook_menu().
+ * Implements hook_menu().
*/
function taxonomy_browser_menu() {
$items = array();
@@ -23,27 +23,27 @@ function taxonomy_browser_menu() {
'access arguments' => array('access content'),
'description' => 'Find content on your own terms.',
);
-
- $items['admin/settings/taxonomy-browser'] = array(
+
+ $items['admin/config/taxonomy-browser'] = array(
'title' => 'Taxonomy Browser',
'description' => 'Set usage guidelines and included vocabularies.',
'page callback' => 'drupal_get_form',
'page arguments' => array('taxonomy_browser_admin_settings'),
- 'access arguments' => array('administer site configuration'),
+ 'access arguments' => array('administer site configuration'),
);

return $items;
}

/**
- * Implementation of hook_init().
+ * Implements hook_init().
*/
function taxonomy_browser_init() {
- drupal_add_css(drupal_get_path('module', 'taxonomy_browser') .'/taxonomy_browser.css');
+ drupal_add_css(drupal_get_path('module', 'taxonomy_browser') . '/taxonomy_browser.css');
}

/**
- * Implementation of hook_help().
+ * Implements hook_help().
*/
function taxonomy_browser_help($path, $arg) {
switch ($path) {
@@ -52,18 +52,23 @@ function taxonomy_browser_help($path, $a
case 'taxonomy_browser':
$output = check_markup(variable_get('taxonomy_browser_guidelines', _taxonomy_browser_guidelines_default()));
if (user_access('administer site configuration')) {
- $output .= '

';
+ $output .= '

';
}
return $output;
}
}

/**
- * Implementation of hook_perm().
+ * Implements hook_permission().
*/
-function taxonomy_browser_perm() {
+function taxonomy_browser_permission() {
if (variable_get('taxonomy_browser_need_perm', FALSE)) {
- return array('access taxonomy browser');
+ return array(
+ 'access taxonomy browser' => array(
+ 'title' => t('access taxonomy browser'),
+ 'description' => t('TODO Add a description for \'access taxonomy browser\''),
+ ),
+ );
}
else {
return array();
@@ -71,7 +76,7 @@ function taxonomy_browser_perm() {
}

/**
- * Implementation of hook_menu_alter().
+ * Implements hook_menu_alter().
*/
function taxonomy_browser_menu_alter(&$callbacks) {
$callbacks['taxonomy_browser']['access arguments'] = array(variable_get('taxonomy_browser_need_perm', FALSE) ? 'access taxonomy browser' : 'access content');
@@ -82,34 +87,43 @@ function taxonomy_browser_menu_alter(&$c
//********************************************************************

/**
- * Implementation of hook_block().
+ * Implements hook_block_info().
*/
-function taxonomy_browser_block($op = 'list', $delta = 0, $edit = array()) {
- $block = array();
- switch ($op) {
- case 'list':
- $block[0]['info'] = t('Category browser');
- return $block;
-
- case 'view':
- switch ($delta) {
- case 0:
- $block = _taxonomy_browser_block_view($delta);
- break;
- }
- return $block;
+function taxonomy_browser_block_info() {
+ $block[0]['info'] = t('Category browser');
+ return $block;
+}
+
+/**
+ * Implements hook_block_view().
+ */
+function taxonomy_browser_block_view($delta) {
+ // TODO Rename block deltas (e.g. delta-0) to readable strings.
+ switch ($delta) {
+ case 'delta-0':
+ $block = _taxonomy_browser_block_view($delta);
+ break;
}
+ return $block;
+}
+
+/**
+ * Implements hook_block().
+ */
+function taxonomy_browser_block_OLD($op = 'list', $delta = 0, $edit = array()) {
+ // TODO Remaining code in this function needs to be moved to the appropriate new hook function.
+ $block = array();
}

/**
* Settings form.
*/
-function taxonomy_browser_admin_settings() {
+function taxonomy_browser_admin_settings($form, &$form_state) {
if (!module_exists('node_type_filter') && !drupal_set_message()) {
drupal_set_message(t('You do not have the node_type_filter module installed. This means that the "restrict search by content type" option will not be available on the category browser page.'), 'status');
}

- drupal_add_js(drupal_get_path('module', 'taxonomy_browser') .'/taxonomy_browser.js', 'module');
+ drupal_add_js(drupal_get_path('module', 'taxonomy_browser') . '/taxonomy_browser.js');

$form['taxonomy_browser_guidelines'] = array(
'#title' => t('Guidelines'),
@@ -174,7 +188,7 @@ function taxonomy_browser_admin_settings
'#title' => t('Requires permission'),
'#type' => 'checkbox',
'#default_value' => variable_get('taxonomy_browser_need_perm', FALSE),
- '#description' => t('Do you want to require permission to see the browser page? If you change this you need to clear the menu cache, such as at the Performance page.', array('!clear' => url('admin/settings/performance'))),
+ '#description' => t('Do you want to require permission to see the browser page? If you change this you need to clear the menu cache, such as at the Performance page.', array('!clear' => url('admin/config/development/performance'))),
);

$form['taxonomy_browser_show_types'] = array(
@@ -201,7 +215,7 @@ function taxonomy_browser_admin_settings
);

if (module_exists('node_type_filter')) {
- $filter_options = node_get_types('names');
+ $filter_options = node_type_get_names();
$form['taxonomy_browser_omit'] = array(
'#type' => 'checkboxes',
'#title' => t('Omit content types'),
@@ -216,13 +230,17 @@ function taxonomy_browser_admin_settings
return system_settings_form($form);
}

+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
function taxonomy_browser_admin_settings_validate($form, &$form_state) {
if ($form_state['values']['taxonomy_browser_count_nodes'] == FALSE
- && $form_state['values']['taxonomy_browser_show_unused'] == TRUE) {
+ && $form_state['values']['taxonomy_browser_show_unused'] == TRUE) {
form_set_error('taxonomy_browser_show_unused', t('"Show unused" requires "count nodes."'));
}
if ($form_state['values']['taxonomy_browser_collapse'] != 0
- && $form_state['values']['taxonomy_browser_select_type'] != 1) {
+ && $form_state['values']['taxonomy_browser_select_type'] != 1) {
form_set_error('taxonomy_browser_collapse', t('"Make vocabularies collapsible" requires "Check boxes."'));
}
}
@@ -232,7 +250,7 @@ function taxonomy_browser_admin_settings
//********************************************************************

/**
- * Menu callback: the query building interface for nodes selected based on
+ * Menu callback: the query building interface for nodes selected based on
* taxonomy terms.
*/
function taxonomy_browser_page() {
@@ -240,7 +258,11 @@ function taxonomy_browser_page() {
return $output;
}

-function taxonomy_browser_form() {
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
+function taxonomy_browser_form($form) {
$form = array();
$selection_types = array('select', 'checkboxes');
$select_type = $selection_types[variable_get('taxonomy_browser_select_type', 1)];
@@ -248,7 +270,7 @@ function taxonomy_browser_form() {
$count_nodes = variable_get('taxonomy_browser_count_nodes', FALSE);
$show_unused = variable_get('taxonomy_browser_show_unused', FALSE);
$allow_children = variable_get('taxonomy_browser_allow_children', FALSE);
- $node_types = node_get_types('names');
+ $node_types = node_type_get_names();

$form['scope'] = array(
'#type' => 'fieldset',
@@ -261,14 +283,14 @@ function taxonomy_browser_form() {
if (module_exists('node_type_filter')) {
if ($count_nodes) {
$total_count = 0;
- $result = db_query('SELECT DISTINCT(type), COUNT(nid) AS count FROM {node} WHERE status=1 GROUP BY type ORDER BY type');
+ $result = db_query('SELECT DISTINCT(type), COUNT(nid) AS count FROM {node} WHERE status = :status GROUP BY type ORDER BY type', array(':status' => 1));
while ($counter = db_fetch_array($result)) {
// Check if we know about this type - a disabled module could have orphans.
if (isset($node_types[$counter['type']])) {
- $node_types[$counter['type']] .= ' ('. $counter['count'] .')';
+ $node_types[$counter['type']] .= ' (' . $counter['count'] . ')';
}
else {
- $node_types['unknown'] .= $counter['type'] .' ??? ('. $counter['count'] .') ';
+ $node_types['unknown'] .= $counter['type'] . ' ??? (' . $counter['count'] . ') ';
watchdog('Taxonomy Browser', 'Unknown content type found: @type', array('@type' => $counter['type']), WATCHDOG_WARNING);
}
$total_count += $counter['count'];
@@ -283,7 +305,7 @@ function taxonomy_browser_form() {
}
$desc = t('Not selecting any type is the same as selecting all types.');
if ($count_nodes) {
- $desc .= ' '. t('The total count of all types is !count.', array('!count' => $total_count));
+ $desc .= ' ' . t('The total count of all types is !count.', array('!count' => $total_count));
}
$form['scope']['node_filter'] = array(
'#type' => $select_type,
@@ -301,7 +323,7 @@ function taxonomy_browser_form() {
'#value' => array(),
);
}
-
+
$form['scope']['operator'] = array(
'#type' => 'radios',
'#title' => t('Items containing'),
@@ -319,7 +341,7 @@ function taxonomy_browser_form() {
$vocabularies[$vocabulary->vid] = 1;
}
}
-
+
if ($allow_children) {
$form['children'] = array(
'#type' => 'fieldset',
@@ -380,7 +402,7 @@ function taxonomy_browser_form() {
if ($count_nodes) {
$count = taxonomy_term_count_nodes($term->tid);
if ($count > 0 || $show_unused) {
- $opt_string = decode_entities(check_plain($term->name)) .' ('. $count .')';
+ $opt_string = decode_entities(check_plain($term->name)) . ' (' . $count . ')';
}
}
else {
@@ -395,7 +417,7 @@ function taxonomy_browser_form() {
$vocname = check_plain($voc->name);
$description = $voc->description ? check_markup($voc->description) : NULL;
if (variable_get('taxonomy_browser_show_types', FALSE)) {
- $used_for = t('"!name" is used for: !types.', array('!name' => ''. $vocname .'', '!types' => (empty($node_type_list) ? ''. t('nothing') .'' : $node_type_list)));
+ $used_for = t('"!name" is used for: !types.', array('!name' => '' . $vocname . '', '!types' => (empty($node_type_list) ? '' . t('nothing') . '' : $node_type_list)));
}

if (!empty($term_opts)) {
@@ -405,14 +427,14 @@ function taxonomy_browser_form() {
'#options' => $term_opts,
'#multiple' => TRUE,
'#description' => $collapsible ? $used_for : $description . $used_for,
- '#prefix' => '',
+ '#prefix' => '',
'#suffix' => '',
'#field_suffix' => $node_type_list,
'#weight' => $i,
);

if ($collapsible) {
- $fld_set = 'set'. $voc->vid;
+ $fld_set = 'set' . $voc->vid;
$form['taxonomy'][$fld_set] = array(
'#type' => 'fieldset',
'#title' => $vocname,
@@ -428,23 +450,23 @@ function taxonomy_browser_form() {
++$i;
}
}
-
+
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Search'),
// '#submit' => TRUE,
);
-
+
return $form;
}

/**
- * Implementation of hook_theme().
+ * Implements hook_theme().
*/
function taxonomy_browser_theme() {
return array(
'taxonomy_browser_page' => array(
- 'arguments' => array('form'),
+ 'variables' => array('form'),
),
);
}
@@ -452,21 +474,22 @@ function taxonomy_browser_theme() {
/**
* Themable form output for the category browser page.
*/
-function theme_taxonomy_browser_page($form) {
+function theme_taxonomy_browser_page($variables) {
+ $form = $variables['0'];
$output = '';
-
+
$vocabularies = variable_get('taxonomy_browser_vocabularies', array());
if (empty($vocabularies)) {
- form_set_error('taxonomy_browser_page', t('You must select the vocabularies to display from the taxonomy browser settings page.', array('%link' => url('admin/settings/taxonomy_browser'))));
+ form_set_error('taxonomy_browser_page', t('You must select the vocabularies to display from the taxonomy browser settings page.', array('%link' => url('admin/config/taxonomy_browser'))));
return ' ';
}
-
- $output .= drupal_render($form);
+
+ $output .= drupal_render_children($form);
return $output;
}

/**
- * Implementation of hook_form_validate().
+ * Implements hook_form_validate().
*/
function taxonomy_browser_form_validate($form, &$form_state) {

@@ -483,7 +506,7 @@ function taxonomy_browser_form_validate(
form_set_error('taxonomy', t('You must select at least one category in your search.'));
}
else {
-// $node_type = (isset($form_values['node_filter']) && $form_values['node_filter'] != 'all') ? $form_values['node_filter'] : NULL;
+ // $node_type = (isset($form_values['node_filter']) && $form_values['node_filter'] != 'all') ? $form_values['node_filter'] : NULL;
$node_type = str_replace(',0', '', implode(',', $form_state['values']['node_filter']));

if (!taxonomy_browser_count_nodes($tids, $operator, 0, $node_type)) {
@@ -493,24 +516,24 @@ function taxonomy_browser_form_validate(
}

/**
- * Implementation of hook_form_submit().
+ * Implements hook_form_submit().
*/
function taxonomy_browser_form_submit($form, &$form_state) {
$tids = _taxonomy_browser_get_tid_list();

$operator = $form_state['values']['operator'] ? 'or' : 'and';
$str_tids = ($operator == 'and') ? implode(',', $tids) : implode('+', $tids);
-
+
$types = array_filter($form_state['values']['node_filter']);
$node_type = str_replace(',0', '', implode(',', $types));
-
+
if ($types) {
- $redir = array('taxonomy/term/'. $str_tids, (isset($node_type) ? 'type='. $node_type : ''));
+ $redir = array('taxonomy/term/' . $str_tids, (isset($node_type) ? 'type=' . $node_type : ''));
}
else {
- $redir = 'taxonomy/term/'. $str_tids;
+ $redir = 'taxonomy/term/' . $str_tids;
}
-
+
$form_state['redirect'] = $redir;
}

@@ -550,21 +573,21 @@ function taxonomy_browser_count_nodes($t
$depth = NULL;
}
foreach ($tids as $index => $tid) {
- $term = taxonomy_get_term($tid);
- $tree = taxonomy_get_tree($term->vid, $tid, -1, $depth);
+ $term = taxonomy_term_load($tid);
+ $tree = taxonomy_get_tree($term->vid, $tid, $depth);
$descendant_tids[] = array_merge(array($tid), array_map('_taxonomy_get_tid_from_term', $tree));
}

$type_where = NULL;
if ($nodetype) {
-// $type_where = "n.type = '". db_escape_string($nodetype) ."'";
- $type_where = "n.type IN ('". implode("', '", explode(',', db_escape_string($nodetype))) ."')";
+ // $type_where = "n.type = '". db_escape_string($nodetype) ."'";
+ $type_where = "n.type IN ('" . implode("', '", explode(',', db_escape_string($nodetype))) . "')";
}

if ($operator == 'or') {
$str_tids = implode(',', call_user_func_array('array_merge', $descendant_tids));

- $sql_count = 'SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} tn USING(nid) WHERE '. ($type_where ? $type_where .' AND ' : NULL) ."tn.tid IN ($str_tids) ORDER BY n.sticky DESC, n.title ASC";
+ $sql_count = 'SELECT COUNT(n.nid) FROM {node} n INNER JOIN {taxonomy_term_node} tn USING(nid) WHERE ' . ($type_where ? $type_where . ' AND ' : NULL) . "tn.tid IN ($str_tids) ORDER BY n.sticky DESC, n.title ASC";
}
else {
$joins = '';
@@ -573,20 +596,21 @@ function taxonomy_browser_count_nodes($t
$wheres[] = $type_where;
}
foreach ($descendant_tids as $index => $tids) {
- $joins .= 'INNER JOIN {term_node} tn'. $index .' ON n.nid = tn'. $index .'.nid ';
- $wheres[] = 'tn'. $index .'.tid IN ('. implode(',', $tids) .')';
+ $joins .= 'INNER JOIN {taxonomy_term_node} tn' . $index . ' ON n.nid = tn' . $index . '.nid ';
+ $wheres[] = 'tn' . $index . '.tid IN (' . implode(',', $tids) . ')';
}
- $sql_count = 'SELECT COUNT(n.nid) FROM {node} n '. $joins .' WHERE '. implode(' AND ', $wheres);
+ $sql_count = 'SELECT COUNT(n.nid) FROM {node} n ' . $joins . ' WHERE ' . implode(' AND ', $wheres);
}

- return db_result(db_query(db_rewrite_sql($sql_count)));
+ // TODO Please convert this statement to the D7 database API syntax.
+ return db_query(db_rewrite_sql($sql_count))->fetchField();
}

return 0;
}

/**
- * Transforms an unpredictably and irregularly nested set of tids (as returned
+ * Transforms an unpredictably and irregularly nested set of tids (as returned
* from a taxonomy form) into a linear array of tids.
*/
function _taxonomy_browser_get_tid_list($tids = NULL, $include_children = FALSE) {
@@ -597,13 +621,13 @@ function _taxonomy_browser_get_tid_list(
foreach ($tids as $key => $tid) {
if (!empty($tid)) {
if (is_array($tid)) {
- foreach ($tid as $key2 => $tid2) {
+ foreach ($tid as $key2 => $tid2) {
if (!empty($tid2)) {
if (is_array($tid2)) {
foreach ($tid2 as $key3 => $tid3) {
if (!empty($tid3)) {
$tid_list[$tid3] = $tid3;
- }
+ }
}
}
else {
@@ -618,7 +642,7 @@ function _taxonomy_browser_get_tid_list(
}
}
}
-
+
if ($include_children) {
foreach ($tid_list as $tid) {
_taxonomy_browser_get_kids($tid_list, $tid);

#4

So it seems to be a good beginning....thx francky but we'll need to change the taxonomy_browser.js manually too ?

@nancydru : do u think we can try this patch in live environment ?

#5

+1 ;-)

#6

Subscribing.

#7

subscribing

nobody click here