| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* Implementation of hook_menu()
|
| 4 |
*/
|
| 5 |
function vocabulary_list_nodes_menu($may_cache) {
|
| 6 |
$items = array();
|
| 7 |
if ($may_cache) {
|
| 8 |
$items[] = array('title' => t('vocabulary list'),
|
| 9 |
'access' => user_access('access content'),
|
| 10 |
'path' => 'vocabulary/list',
|
| 11 |
'callback' => 'vocabulary_list_nodes_page',
|
| 12 |
'type' => MENU_CALLBACK);
|
| 13 |
}
|
| 14 |
return $items;
|
| 15 |
}
|
| 16 |
|
| 17 |
/**
|
| 18 |
* Implementation of hook_page();
|
| 19 |
*/
|
| 20 |
function vocabulary_list_nodes_page($str_vids = NULL) {
|
| 21 |
print theme('page', vocabulary_list_nodes_render($str_vids));
|
| 22 |
}
|
| 23 |
|
| 24 |
/**
|
| 25 |
* Render the node list. This function can be called
|
| 26 |
* from any page or block.
|
| 27 |
*
|
| 28 |
* @param $vid Vocabulary ID
|
| 29 |
* @return An HTML-formatted string ready for printing to the screen
|
| 30 |
*/
|
| 31 |
function vocabulary_list_nodes_render($str_vids = NULL) {
|
| 32 |
$terms = array();
|
| 33 |
// Explode $str_vids
|
| 34 |
$vids = vocabulary_list_nodes_vocabulary_parse_string($str_vids);
|
| 35 |
// Retrieve all terms for the vocabulary.
|
| 36 |
foreach($vids as $key=>$vid) {
|
| 37 |
$this_terms = array_map('_taxonomy_get_tid_from_term', taxonomy_get_tree($vid));
|
| 38 |
// Glue arrays
|
| 39 |
$terms = array_merge($terms, $this_terms);
|
| 40 |
}
|
| 41 |
// Set title
|
| 42 |
$title = vocabulary_list_nodes_get_title($str_vids);
|
| 43 |
drupal_set_title($title);
|
| 44 |
|
| 45 |
// Render all nodes in a pager.
|
| 46 |
$output = taxonomy_render_nodes(taxonomy_select_nodes($terms, 'or', 'all'));
|
| 47 |
return $output;
|
| 48 |
}
|
| 49 |
|
| 50 |
/**
|
| 51 |
* Parses a comma or plus separated string of vocabulary IDs.
|
| 52 |
* provides same functionality as taxonomy_terms_parse_string($str_tids) but for vocabulary IDs
|
| 53 |
*
|
| 54 |
* @param $str_vids
|
| 55 |
* A string of vocabulary IDs, separated by plus or comma.
|
| 56 |
*
|
| 57 |
* @return array
|
| 58 |
*/
|
| 59 |
function vocabulary_list_nodes_vocabulary_parse_string($str_vids) {
|
| 60 |
$vocabularys = array();
|
| 61 |
if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str_vids)) {
|
| 62 |
// The '+' character in a query string may be parsed as ' '.
|
| 63 |
$vocabularys = preg_split('/[+ ]/', $str_vids);
|
| 64 |
}
|
| 65 |
else if (preg_match('/^([0-9]+,)*[0-9]+$/', $str_vids)) {
|
| 66 |
$vocabularys = explode(',', $str_vids);
|
| 67 |
}
|
| 68 |
return $vocabularys;
|
| 69 |
}
|
| 70 |
|
| 71 |
/**
|
| 72 |
* helper function
|
| 73 |
* returns string title
|
| 74 |
**/
|
| 75 |
function vocabulary_list_nodes_get_title($str_vids) {
|
| 76 |
$names = array();
|
| 77 |
$vids = vocabulary_list_nodes_vocabulary_parse_string($str_vids);
|
| 78 |
if ($vids) {
|
| 79 |
$result = db_query('SELECT name FROM {vocabulary} WHERE vid IN (%s)', implode(',', $vids));
|
| 80 |
while ($row = db_fetch_object($result)) {
|
| 81 |
$names[] = $row->name;
|
| 82 |
}
|
| 83 |
if ($names) {
|
| 84 |
return check_plain(join(", ", $names));
|
| 85 |
}
|
| 86 |
}
|
| 87 |
}
|
| 88 |
?>
|