Removing translation directories
[project/ctools.git] / plugins / content_types / vocabulary_context / vocabulary_terms.inc
1 <?php
2
3 if (module_exists('taxonomy')) {
4 /**
5 * Plugins are described by creating a $plugin array which will be used
6 * by the system that includes this file.
7 */
8 $plugin = array(
9 'single' => TRUE,
10 'title' => t('Vocabulary terms'),
11 'icon' => 'icon_vocabulary.png',
12 'description' => t('All the terms in a vocabulary.'),
13 'required context' => new ctools_context_required(t('Vocabulary'), 'vocabulary'),
14 'category' => t('Vocabulary'),
15 'defaults' => array('max_depth' => 0, 'tree' => 1),
16 );
17 }
18
19 /**
20 * Output function for the 'vocabulary terms' content type. Outputs a
21 * list of terms for the input vocabulary.
22 */
23 function ctools_vocabulary_terms_content_type_render($subtype, $conf, $panel_args, $context) {
24 $vocab = isset($context->data) ? clone($context->data) : NULL;
25 $max_depth = (!empty($conf['max_depth']) ? (int)$conf['max_depth'] : NULL);
26 if ($conf['tree'] == FALSE) {
27 $terms = taxonomy_get_tree($vocab->vid, 0, -1, $max_depth);
28 $items = array();
29 foreach ($terms as $term) {
30 $items[] = l($term->name, 'taxonomy/term/' . $term->tid);
31 }
32 $output = theme('item_list', $items);
33 }
34 else {
35 $output = theme('item_list', _ctools_content_vocabulary_terms($vocab->vid, $max_depth));
36 }
37
38 $block = new stdClass();
39 $block->module = 'node_type';
40 $block->title = check_plain($vocab->name);
41 $block->content = $output;
42 $block->delta = $vocab->vid;
43
44 return $block;
45 }
46
47 function _ctools_content_vocabulary_terms($vid, $max_depth, $depth = -1, $tid = 0) {
48 $depth++;
49 if ($max_depth != NULL && $depth == $max_depth) {
50 return array();
51 }
52 $return = array();
53 $result = db_query('SELECT t.name, t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} h ON t.tid = h.tid WHERE t.vid = :vid AND h.parent = :parent ORDER BY t.weight ASC, t.name ASC', array(':vid' => $vid, ':parent' => $tid));
54 foreach ($result as $term) {
55 $return[] = array(
56 'data' => l($term->name, 'taxonomy/term/'. $term->tid),
57 'children' => _ctools_content_vocabulary_terms($vid, $max_depth, $depth, $term->tid),
58 );
59 }
60 return $return;
61 }
62
63 function ctools_vocabulary_terms_content_type_admin_title($subtype, $conf, $context) {
64 return t('"@s" terms', array('@s' => $context->identifier));
65 }
66
67 function ctools_vocabulary_terms_content_type_edit_form($form, &$form_state) {
68 $conf = $form_state['conf'];
69 $form['max_depth'] = array(
70 '#type' => 'select',
71 '#title' => t('Maximum depth'),
72 '#options' => array_merge(array(t('unlimited')), range(1, 9)),
73 '#default_value' => $conf['max_depth'],
74 '#description' => t('Define the maximum depth of terms being displayed.'),
75 );
76
77 $form['tree'] = array(
78 '#type' => 'checkbox',
79 '#title' => t('Display as tree'),
80 '#default_value' => $conf['tree'],
81 '#description' => t('If checked, the terms are displayed in a tree, otherwise in a flat list.'),
82 );
83
84 return $form;
85 }
86
87 function ctools_vocabulary_terms_content_type_edit_form_submit($form, &$form_state) {
88 // Copy everything from our defaults.
89 foreach (array_keys($form_state['plugin']['defaults']) as $key) {
90 $form_state['conf'][$key] = $form_state['values'][$key];
91 }
92 }
93