/[drupal]/contributions/modules/taxonomy_theme/taxonomy_theme_admin.inc
ViewVC logotype

Diff of /contributions/modules/taxonomy_theme/taxonomy_theme_admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.9, Sun Jun 8 15:21:03 2008 UTC revision 1.9.2.1, Mon Jan 12 20:01:53 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: taxonomy_theme_admin.inc,v 1.8 2006/12/19 22:59:26 profix898 Exp $  // $Id: taxonomy_theme_admin.inc,v 1.10 2009/01/12 19:58:32 profix898 Exp $
3    
4  require_once(drupal_get_path('module', 'taxonomy_theme') .'/taxonomy_theme_helper.inc');  require_once(drupal_get_path('module', 'taxonomy_theme') .'/taxonomy_theme_helper.inc');
5    
# Line 17  function taxonomy_theme_admin_form() { Line 17  function taxonomy_theme_admin_form() {
17    $options = array();    $options = array();
18    $options[TAXONOMY_THEME_SKIP]      = t('Disabled');    $options[TAXONOMY_THEME_SKIP]      = t('Disabled');
19    $properties = array_keys(variable_get('themekey_properties', array()));    $properties = array_keys(variable_get('themekey_properties', array()));
20    if (in_array('tid', $properties)) {    if (in_array('taxonomy:tid', $properties)) {
21      $options[TAXONOMY_THEME_TERM]      = t('Term-based');      $options[TAXONOMY_THEME_TERM]      = t('Term-based');
22      $options[TAXONOMY_THEME_ALLTAXO]   = t('All Taxonomy');      $options[TAXONOMY_THEME_ALLTAXO]   = t('All Taxonomy');
23    }    }
24    if (in_array('vid', $properties)) {    if (in_array('taxonomy:vid', $properties)) {
25      $options[TAXONOMY_THEME_VOCAB]     = t('Vocab-based');      $options[TAXONOMY_THEME_VOCAB]     = t('Vocab-based');
26    }    }
27    ksort($options);    ksort($options);
28    //    //
29    $method = variable_get('taxonomy_theme_method', TAXONOMY_THEME_SKIP);    $method = variable_get('taxonomy_theme_method', TAXONOMY_THEME_SKIP);
30    if (count($options) < 4) {    if (count($options) < 4) {
31      $message = t('Either \'Taxonomy: Term (tid)\' or \'Taxonomy: Vocabulary (vid)\' is not enabled!<br />      $message = t('Property \'Taxonomy: Term (taxonomy:tid)\' or \'Taxonomy: Vocabulary (taxonomy:vid)\' is not
32                    Please visit the <a href="@url">ThemeKey settings</a> page and select both of these properties.',                    enabled!<br />You dont get all available options unless you enable both of these properties
33                      (visit the <a href="@url">ThemeKey settings</a> page).',
34                    array('@url' => url('admin/settings/themekey/settings', array('query' => drupal_get_destination())))                    array('@url' => url('admin/settings/themekey/settings', array('query' => drupal_get_destination())))
35                  );                  );
36      drupal_set_message($message, 'error');      drupal_set_message($message, 'error');
# Line 103  function _taxonomy_theme_admin_term_form Line 104  function _taxonomy_theme_admin_term_form
104      );      );
105    }    }
106    else {    else {
107      $form['taxonomy_theme_select']['text'] = array('#value' => t('<br /><strong>Your site currently has no categories.</strong><br /><br />Please create at least one category and add the terms you will map to themes and return to this page. For example, you might create a category called Sections that has two terms, <em>blue</em> to map to the bluebeach theme and <em>grey</em> to map to the <em>box_grey</em> theme.'));      $form['taxonomy_theme_select']['text'] = array(
108          '#value' => t('<br /><strong>Your site currently has no categories.</strong><br /><br />Please create at least one
109                         category, add the terms you will map to themes and return to this page. For example, you might create
110                         a category called Sections that has two terms, <em>blue</em> to map to the bluebeach theme and
111                         <em>grey</em> to map to the <em>box_grey</em> theme.')
112        );
113    }    }
114    
115    if ($selector) {    if ($selector) {
116      $terms = taxonomy_get_tree($selector);      $terms = taxonomy_get_tree($selector);
117      $form['taxonomy_theme_select'][] = _taxonomy_theme_admin_table_builder('tid', t('Term'), $terms);      $conditions = array(array('property' => 'taxonomy:vid', 'operator' => '=', 'value' => $selector));
118        $form['taxonomy_theme_select'][] = _taxonomy_theme_admin_table_builder('tid', t('Term'), $terms, $conditions);
119    }    }
120    
121    return $form;    return $form;
# Line 182  function _taxonomy_theme_admin_form_subm Line 189  function _taxonomy_theme_admin_form_subm
189      $selector = $form_state['values']['taxonomy_theme_selector'];      $selector = $form_state['values']['taxonomy_theme_selector'];
190    }    }
191    //    //
192    if (empty($form_state['redirect']) && isset($form_state['values']['table'])) {    if (empty($form_state['redirect'])) {
193      foreach ($form_state['values']['table'] as $key => $details) {      foreach ($form_state['values']['table'] as $key => $details) {
194        switch ($method) {        switch ($method) {
195          case TAXONOMY_THEME_TERM:          case TAXONOMY_THEME_TERM:
196            $conditions = array(array('property' => 'vid', 'value' => $selector));            $conditions = array(array('property' => 'taxonomy:vid', 'operator' => '=', 'value' => $selector));
197            taxonomy_theme_set_theme('tid', $key, $details['theme'], $conditions);            taxonomy_theme_set_theme('taxonomy:tid', $key, $details['theme'], $conditions);
198            break;            break;
199          case TAXONOMY_THEME_VOCAB:          case TAXONOMY_THEME_VOCAB:
200            taxonomy_theme_set_theme('vid', $key, $details['theme']);            taxonomy_theme_set_theme('taxonomy:vid', $key, $details['theme']);
201            break;            break;
202          case TAXONOMY_THEME_ALLTAXO:          case TAXONOMY_THEME_ALLTAXO:
203            taxonomy_theme_set_theme('tid', $key, $details['theme']);            taxonomy_theme_set_theme('taxonomy:tid', $key, $details['theme']);
204            break;            break;
205          default:          default:
206        }        }
207      }      }
     unset($form_state['values']['table']);  
208    }    }
209      unset($form_state['values']['table']);
210    //    //
211    foreach ($form_state['values'] as $key => $value) {    foreach ($form_state['values'] as $key => $value) {
212      $pos = strpos($key, 'taxonomy_theme_');      $pos = strpos($key, 'taxonomy_theme_');
# Line 215  function _taxonomy_theme_admin_form_subm Line 222  function _taxonomy_theme_admin_form_subm
222  function _taxonomy_theme_admin_form_reset($form, &$form_state) {  function _taxonomy_theme_admin_form_reset($form, &$form_state) {
223    switch ($form_state['values']['taxonomy_theme_method']) {    switch ($form_state['values']['taxonomy_theme_method']) {
224      case TAXONOMY_THEME_VOCAB:      case TAXONOMY_THEME_VOCAB:
225        taxonomy_theme_delall_theme('vid');        taxonomy_theme_delall_theme('taxonomy:vid');
226        break;        break;
227      case TAXONOMY_THEME_TERM:      case TAXONOMY_THEME_TERM:
228      case TAXONOMY_THEME_ALLTAXO:      case TAXONOMY_THEME_ALLTAXO:
229        taxonomy_theme_delall_theme('tid');        taxonomy_theme_delall_theme('taxonomy:tid');
230        break;        break;
231      default:      default:
232    }    }
# Line 242  function _taxonomy_theme_admin_form_conf Line 249  function _taxonomy_theme_admin_form_conf
249    
250    //    //
251    $vid = arg(6);    $vid = arg(6);
252    if ($vid && $method == TAXONOMY_THEME_TERM) {    if (is_numeric($vid) && $method == TAXONOMY_THEME_TERM
253          && variable_get('taxonomy_theme_method', TAXONOMY_THEME_SKIP) == TAXONOMY_THEME_TERM) {
254      $selector = variable_get('taxonomy_theme_selector', '');      $selector = variable_get('taxonomy_theme_selector', '');
255      $vocab_from = taxonomy_vocabulary_load($vid);      $vocab_from = taxonomy_vocabulary_load($vid);
256      $vocab_to = taxonomy_vocabulary_load($selector);      $vocab_to = taxonomy_vocabulary_load($selector);
# Line 258  function _taxonomy_theme_admin_form_conf Line 266  function _taxonomy_theme_admin_form_conf
266                        method should be removed to prevent interference with the new settings.<br />                        method should be removed to prevent interference with the new settings.<br />
267                        Click \'Remove\' to continue removing obsolete items.</p>');                        Click \'Remove\' to continue removing obsolete items.</p>');
268    }    }
269    
270    $form = array();    $form = array();
   $form['#submit'] = array('_taxonomy_theme_admin_form_confirm_submit');  
271    $params = array(    $params = array(
272      'key' => ($method == TAXONOMY_THEME_VOCAB) ? 'vid' : 'tid',      'key' => ($method == TAXONOMY_THEME_VOCAB) ? 'taxonomy:vid' : 'taxonomy:tid',
273      'vid' => isset($vid) ? $vid : NULL      'vid' => isset($vid) ? $vid : NULL
274    );    );
275    $form['taxonomy_theme_params'] = array('#type' => 'value', '#value' => $params);    $form['taxonomy_theme_params'] = array('#type' => 'value', '#value' => $params);
# Line 285  function _taxonomy_theme_admin_form_conf Line 292  function _taxonomy_theme_admin_form_conf
292    if (isset($form_state['values']['taxonomy_theme_params'])) {    if (isset($form_state['values']['taxonomy_theme_params'])) {
293      $conditions = array();      $conditions = array();
294      if (isset($form_state['values']['taxonomy_theme_params']['vid'])) {      if (isset($form_state['values']['taxonomy_theme_params']['vid'])) {
295        $conditions = array(array('property' => 'vid', 'value' => $form_state['values']['taxonomy_theme_params']['vid']));        $vid = $form_state['values']['taxonomy_theme_params']['vid'];
296          $conditions = array(array('property' => 'taxonomy:vid', 'operator' => '=', 'value' => $vid));
297      }      }
298      taxonomy_theme_delall_theme($form_state['values']['taxonomy_theme_params']['key'], $conditions);      taxonomy_theme_delall_theme($form_state['values']['taxonomy_theme_params']['key'], $conditions);
299    }    }
# Line 296  function _taxonomy_theme_admin_form_conf Line 304  function _taxonomy_theme_admin_form_conf
304   * Function _taxonomy_theme_admin_table_builder().   * Function _taxonomy_theme_admin_table_builder().
305   * (build list/table of taxonomy vocabs/terms)   * (build list/table of taxonomy vocabs/terms)
306   */   */
307  function _taxonomy_theme_admin_table_builder($key, $label, $data) {  function _taxonomy_theme_admin_table_builder($key, $label, $data, $conditions = array()) {
308    $form['table'] = array(    $form['table'] = array(
309      '#theme' => 'taxonomy_theme_table',      '#theme' => 'taxonomy_theme_table',
310      '#header' => array($label, t('Assigned to Theme')),      '#header' => array($label, t('Assigned to Theme')),
# Line 309  function _taxonomy_theme_admin_table_bui Line 317  function _taxonomy_theme_admin_table_bui
317      $form['table'][$item->$key]['name'] = array('#value' => $item->name);      $form['table'][$item->$key]['name'] = array('#value' => $item->name);
318      $form['table'][$item->$key]['theme'] = array(      $form['table'][$item->$key]['theme'] = array(
319        '#type' => 'select',        '#type' => 'select',
320        '#default_value' => taxonomy_theme_get_theme($key, $item->$key),        '#default_value' => taxonomy_theme_get_theme('taxonomy:'. $key, $item->$key, $conditions),
321        '#options' => $themes,        '#options' => $themes,
322      );      );
323    }    }
# Line 359  function _taxonomy_theme_form_alter(&$fo Line 367  function _taxonomy_theme_form_alter(&$fo
367        '#collapsible' => TRUE,        '#collapsible' => TRUE,
368        '#collapsed' => FALSE        '#collapsed' => FALSE
369      );      );
370        $conditions = array(array('property' => 'taxonomy:vid', 'operator' => '=', 'value' => $selector));
371        $conditions = ($method == TAXONOMY_THEME_TERM) ? $conditions : array();
372      $form_theme['taxonomy_theme_select']['theme'] = array(      $form_theme['taxonomy_theme_select']['theme'] = array(
373        '#type' => 'select',        '#type' => 'select',
374        '#default_value' => taxonomy_theme_get_theme('tid', $form['tid']['#value']),        '#default_value' => taxonomy_theme_get_theme('taxonomy:tid', $form['tid']['#value'], $conditions),
375        '#options' => $themes,        '#options' => $themes,
376        '#description' => t('Theme to be assigned to current term')        '#description' => t('Theme to be assigned to current term')
377      );      );
# Line 378  function _taxonomy_theme_form_alter(&$fo Line 388  function _taxonomy_theme_form_alter(&$fo
388      );      );
389      $form_theme['taxonomy_theme_select']['theme'] = array(      $form_theme['taxonomy_theme_select']['theme'] = array(
390        '#type' => 'select',        '#type' => 'select',
391        '#default_value' => taxonomy_theme_get_theme('vid', $form['vid']['#value']),        '#default_value' => taxonomy_theme_get_theme('taxonomy:vid', $form['vid']['#value']),
392        '#options' => $themes,        '#options' => $themes,
393        '#description' => t('Theme to be assigned to current vocabulary')        '#description' => t('Theme to be assigned to current vocabulary')
394      );      );
# Line 393  function _taxonomy_theme_form_alter(&$fo Line 403  function _taxonomy_theme_form_alter(&$fo
403  function _taxonomy_theme_form_alter_submit($form, &$form_state) {  function _taxonomy_theme_form_alter_submit($form, &$form_state) {
404    // Submit taxonomy term page    // Submit taxonomy term page
405    if ($form_state['values']['form_id'] == 'taxonomy_form_term') {    if ($form_state['values']['form_id'] == 'taxonomy_form_term') {
406      taxonomy_theme_set_theme('tid', $form_state['values']['tid'], $form_state['values']['theme']);      taxonomy_theme_set_theme('taxonomy:tid', $form_state['values']['tid'], $form_state['values']['theme']);
407    }    }
408    // Submit taxonomy vocabulary page    // Submit taxonomy vocabulary page
409    else if ($form_state['values']['form_id'] == 'taxonomy_form_vocabulary') {    else if ($form_state['values']['form_id'] == 'taxonomy_form_vocabulary') {
410      taxonomy_theme_set_theme('vid', $form_state['values']['vid'], $form_state['values']['theme']);      taxonomy_theme_set_theme('taxonomy:vid', $form_state['values']['vid'], $form_state['values']['theme']);
411    }    }
412  }  }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.9.2.1

  ViewVC Help
Powered by ViewVC 1.1.2