00001 <?php
00002
00003
00004
00005
00006
00007
00008 function panels_term_list_panels_content_types() {
00009 $items['term_list'] = array(
00010 'title' => t('List of related terms'),
00011 'content_types' => 'panels_admin_content_types_term_list',
00012
00013 'single' => TRUE,
00014 'render callback' => 'panels_content_term_list',
00015 'add callback' => 'panels_admin_edit_term_list',
00016 'edit callback' => 'panels_admin_edit_term_list',
00017 'title callback' => 'panels_admin_title_term_list',
00018 );
00019 return $items;
00020 }
00021
00022
00023
00024
00025
00026 function panels_content_term_list($conf, $panel_args, $context) {
00027 $term = isset($context->data) ? drupal_clone($context->data) : NULL;
00028 $block = new stdClass();
00029 $block->module = 'term-list';
00030
00031 $options = panels_admin_term_list_options();
00032 if ($term) {
00033 $block->subject = $options[$conf['type']];
00034 $block->delta = $conf['type'];
00035 switch ($conf['type']) {
00036 case 'related':
00037 $terms = taxonomy_get_related($term->tid);
00038 break;
00039
00040 case 'child':
00041 default:
00042 $terms = taxonomy_get_children($term->tid);
00043 break;
00044
00045 case 'top':
00046 $terms = taxonomy_get_children(0, $term->vid);
00047 break;
00048
00049 case 'sibling':
00050 $parent = db_result(db_query("SELECT parent FROM {term_hierarchy} WHERE tid = %d", $term->tid));
00051 $terms = taxonomy_get_children($parent, $term->vid);
00052
00053 unset($terms[$term->tid]);
00054 break;
00055
00056 case 'synonyms':
00057 $terms = taxonomy_get_synonyms($term->tid);
00058 break;
00059 }
00060 if ($terms) {
00061 foreach ($terms as $related) {
00062 $items[$related->tid] = l($related->name, taxonomy_term_path($related), array('rel' => 'tag', 'title' => strip_tags($related->description)));
00063 }
00064
00065 $block->content = theme('item_list', $items, NULL, $conf['list_type']);
00066 }
00067 }
00068 else {
00069 $block->content = t('Term description goes here.');
00070 $block->delta = 'unknown';
00071 }
00072
00073 return $block;
00074 }
00075
00076
00077
00078
00079 function panels_admin_content_types_term_list() {
00080 return array(
00081 'description' => array(
00082 'title' => t('List of related terms'),
00083 'icon' => 'icon_node.png',
00084 'path' => panels_get_path('content_types/node'),
00085 'description' => t('Terms related to an existing term; may be child, siblings or top level.'),
00086 'required context' => new panels_required_context(t('Term'), 'term'),
00087 'category' => array(t('Term context'), -9),
00088 ),
00089 );
00090 }
00091
00092 function panels_admin_term_list_options() {
00093 return array(
00094 'child' => t('Child terms'),
00095 'related' => t('Related terms'),
00096 'sibling' => t('Sibling terms'),
00097 'top' => t('Top level terms'),
00098 'synonyms' => t('Term synonyms'),
00099 );
00100 }
00101
00102
00103
00104
00105 function panels_admin_edit_term_list($id, $parents, $conf = array()) {
00106
00107 if (empty($conf)) {
00108 $conf = array('title' => '', 'type' => 'child', 'list_type' => 'ul');
00109 }
00110
00111 $form['type'] = array(
00112 '#type' => 'radios',
00113 '#title' => t('Which terms'),
00114 '#options' => panels_admin_term_list_options(),
00115 '#default_value' => $conf['type'],
00116 '#prefix' => '<div class="clear-block no-float">',
00117 '#suffix' => '</div>',
00118 );
00119
00120 $form['list_type'] = array(
00121 '#type' => 'select',
00122 '#title' => t('List type'),
00123 '#options' => array('ul' => t('Unordered'), 'ol' => t('Ordered')),
00124 '#default_value' => $conf['list_type'],
00125 );
00126
00127 return $form;
00128 }
00129
00130 function panels_admin_title_term_list($conf, $context) {
00131 $options = panels_admin_term_list_options();
00132 return t('"@s" @type', array('@s' => $context->identifier, '@type' => drupal_strtolower($options[$conf['type']])));
00133 }
00134