00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010 function panels_term_panels_arguments() {
00011 $args['term'] = array(
00012 'title' => t("Taxonomy term"),
00013
00014 'keyword' => 'term',
00015 'description' => t('Restricts the argument to a taxonomy term.'),
00016 'context' => 'panels_term_context',
00017 'settings form' => 'panels_term_settings_form',
00018 'settings form submit' => 'panels_term_settings_form_submit',
00019 'title function' => 'panels_term_title',
00020 'displays' => 'panels_term_displays',
00021 'choose display' => 'panels_term_choose_display',
00022 );
00023 return $args;
00024 }
00025
00026
00027
00028
00029 function panels_term_context($arg = NULL, $conf = NULL, $empty = FALSE) {
00030
00031 if ($empty) {
00032 return panels_context_create_empty('term');
00033 }
00034
00035 switch ($conf['input_form']) {
00036 case 'tid':
00037 default:
00038 if (!is_numeric($arg)) {
00039 return FALSE;
00040 }
00041 $term = taxonomy_get_term($arg);
00042 break;
00043
00044 case 'term':
00045 $terms = taxonomy_get_term_by_name($arg);
00046 if (count($terms) != 1) {
00047 foreach ($terms as $potential) {
00048 foreach ($conf['vids'] as $vid => $active) {
00049 if ($active == 1 && $potential->vid == $vid) {
00050 $term = $potential;
00051
00052 break 3;
00053 }
00054 }
00055 }
00056 }
00057 $term = array_shift($terms);
00058 break;
00059 }
00060
00061 if (empty($term)) {
00062 return FALSE;
00063 }
00064
00065 if (!empty($conf['vids']) && array_filter($conf['vids']) && empty($conf['vids'][$term->vid])) {
00066 return FALSE;
00067 }
00068
00069 return panels_context_create('term', $term);
00070 }
00071
00072
00073
00074
00075 function panels_term_settings_form($conf) {
00076 if (empty($conf)) {
00077 $conf = array(
00078 'input_form' => 'tid',
00079 );
00080 }
00081
00082 $options = array();
00083 foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
00084 $options[$vid] = $vocabulary->name;
00085 }
00086
00087 $form['input_form'] = array(
00088 '#title' => t('Argument type'),
00089 '#type' => 'radios',
00090 '#options' => array('tid' => t('Term ID'), 'term' => t('Term name')),
00091 '#default_value' => $conf['input_form'],
00092 '#prefix' => '<div class="clear-block">',
00093 '#suffix' => '</div>',
00094 );
00095
00096
00097 $form['vids'] = array(
00098 '#title' => t('Vocabularies'),
00099 '#type' => 'checkboxes',
00100 '#options' => $options,
00101 '#description' => t('You can restrict this argument to use the checked vocabularies. Arguments from non-conforming vocabularies will be ignored, and Panels will behave as if no argument were given. Leave all unchecked to impose no restriction.'),
00102 '#default_value' => $conf['vids'],
00103 '#prefix' => '<div class="clear-block">',
00104 '#suffix' => '</div>',
00105 );
00106
00107 $form['own_default'] = array(
00108 '#title' => t('Use different default display'),
00109 '#type' => 'checkbox',
00110 '#description' => t('If checked, when this argument is present it will use its own display rather than the default. Vocabularies not selected in the "Own display" field will use this one.'),
00111 '#default_value' => $conf['own_default'],
00112 );
00113
00114 $form['displays'] = array(
00115 '#title' => t('Own display'),
00116 '#type' => 'checkboxes',
00117 '#options' => $options,
00118 '#default_value' => $conf['displays'],
00119 '#description' => t('Each checked vocabulary will get its own special display to layout its content. Only vocabularies set above should be set here. Vocabularies not set here will use the default display.'),
00120 '#prefix' => '<div class="clear-block">',
00121 '#suffix' => '</div>',
00122 );
00123
00124 return $form;
00125 }
00126
00127
00128
00129
00130
00131
00132 function panels_term_settings_form_submit(&$values) {
00133 $vocs = taxonomy_get_vocabularies();
00134 if (!empty($values['vids'])) {
00135 foreach ($values['vids'] as $vid => $value) {
00136 if (empty($vocs[$vid])) {
00137 unset($values['vids'][$vid]);
00138 }
00139 }
00140 }
00141 if (!empty($values['displays'])) {
00142 foreach ($values['displays'] as $vid => $value) {
00143 if (empty($vocs[$vid])) {
00144 unset($values['displays'][$vid]);
00145 }
00146 }
00147 }
00148 }
00149
00150
00151
00152
00153 function panels_term_displays($conf, $id) {
00154 $displays = array();
00155 if (!empty($conf['own_default'])) {
00156 $displays['default'] = array(
00157 'title' => t('Taxonomy term @id Default', array('@id' => $id)),
00158 'context' => 'term',
00159 );
00160 }
00161
00162 if (is_array($conf['displays'])) {
00163 $options = array();
00164 foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
00165 $options[$vid] = $vocabulary->name;
00166 }
00167 foreach (array_keys(array_filter($conf['displays'])) as $vid) {
00168 $displays[$vid] = array(
00169 'title' => t('Taxonomy term @id @vocabulary', array('@id' => $id, '@vocabulary' => $options[$vid])),
00170
00171 'default' => 'default',
00172 'context' => 'term',
00173 );
00174 }
00175 }
00176
00177 return $displays;
00178 }
00179
00180
00181
00182
00183 function panels_term_choose_display($conf, $context) {
00184 if (empty($context->data)) {
00185 return;
00186 }
00187
00188 if (!empty($conf['displays'][$context->data->vid])) {
00189 return $context->data->vid;
00190 }
00191
00192
00193 if (!empty($conf['own_default'])) {
00194 return 'default';
00195 }
00196
00197
00198 return;
00199 }
00200
00201
00202
00203
00204 function panels_term_title($context) {
00205 if (isset($context->data->name)) {
00206 return $context->data->name;
00207 }
00208
00209 if (isset($context->page_title)) {
00210 return $context->page_title;
00211 }
00212 }
00213