/[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.8, Tue Dec 19 22:59:26 2006 UTC revision 1.9, Sun Jun 8 15:21:03 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: taxonomy_theme_admin.inc,v 1.7 2006/10/23 06:50:50 profix898 Exp $  // $Id: taxonomy_theme_admin.inc,v 1.8 2006/12/19 22:59:26 profix898 Exp $
3    
4  require_once (drupal_get_path('module', 'taxonomy_theme').'/taxonomy_theme_pathes.inc');  require_once(drupal_get_path('module', 'taxonomy_theme') .'/taxonomy_theme_helper.inc');
 require_once (drupal_get_path('module', 'taxonomy_theme').'/taxonomy_theme_taxonomy.inc');  
5    
6  /**  define('TAXONOMY_THEME_SKIP',     0);
7   * function taxonomy_theme_admin_form().  define('TAXONOMY_THEME_TERM',     1);
8   * (main administration settings page)  define('TAXONOMY_THEME_VOCAB',    2);
9   */  define('TAXONOMY_THEME_ALLTAXO',  3);
10  function taxonomy_theme_admin_form() {  define('TAXONOMY_THEME_NODETYPE', 4);
   if (!variable_get('taxonomy_theme_enable', 0)) {  
     $form['taxonomy_theme_enable'] = array(  
       '#type' => 'radios',  
       '#title' => t('Enable Taxonomy-based templates'),  
       '#default_value' => variable_get('taxonomy_theme_enable', 0),  
       '#options' => array(t('Disabled'), t('Enabled')),  
     );  
     $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));  
     $form['#submit']['taxonomy_theme_admin_form_submit'] = array();  
     return $form;  
   }  
   
   $form['global'] = array(  
     '#type' => 'fieldset',  
     '#title' => t('Global Settings'),  
     '#collapsible' => FALSE,  
     '#collapsed' => FALSE,  
   );  
   $form['global']['taxonomy_theme_enable'] = array(  
     '#type' => 'checkbox',  
     '#title' => t('Enable Taxonomy-based templates'),  
     '#default_value' => variable_get('taxonomy_theme_enable', 0),  
     '#description' => t('You must check this to activate the taxonomy_theme module.'),  
   );  
   $form['global']['taxonomy_theme_allowall'] = array(  
     '#type' => 'checkbox',  
     '#title' => t('Allow all themes'),  
     '#default_value' => variable_get('taxonomy_theme_allowall', 0),  
     '#description' => t('Offers all installed themes for selection, not enabled ones only.'),  
   );  
   $extended_enabled = variable_get('taxonomy_theme_extended_enable', 0);  
   $form['global']['taxonomy_theme_extended_enable'] = array(  
     '#type' => 'checkbox',  
     '#title' => t('Enable \'Extended\' (path-based) assignment of themes'),  
     '#default_value' => $extended_enabled,  
     '#description' => t('Enables you to assign themes to pathes (e.g. node/21) and path aliases.'),  
   );  
   if (module_exists('views')) {  
     $form['global']['taxonomy_theme_viewspages'] = array(  
       '#type' => 'checkbox',  
       '#title' => t('Enable \'Themes for Views\''),  
       '#default_value' => variable_get('taxonomy_theme_viewspages', 0),  
       '#description' => t('Allows you to theme pages created by views.module. You need to have \'Extended\' option enabled to use this option. It will show a \'Theme\' option in the \'Page\' section of edit view pages.'),  
       '#disabled' => $extended_enabled ? FALSE : TRUE,  
     );  
   }  
   $form['global']['taxonomy_theme_alter_node'] = array(  
     '#type' => 'checkbox',  
     '#title' => t('Show theme option in create/edit node forms'),  
     '#default_value' => variable_get('taxonomy_theme_alter_node', 0),  
     '#description' => t('Assign themes directly from create/edit node forms. You need to have \'Extended\' option enabled to use this option. It will show a \'Theme\' section on create/edit node pages.'),  
     '#disabled' => $extended_enabled ? FALSE : TRUE,  
   );  
   if ($extended_enabled && variable_get('taxonomy_theme_alter_node', 0)) {  
     $nodetypes = node_get_types('names');  
     if (count($nodetypes)) {  
       $form['global']['alter_node_nodetypes'] = array(  
         '#type' => 'fieldset',  
         '#title' => t('Show \'Theme\' option for nodes of type'),  
         '#collapsible' => TRUE,  
         '#collapsed' => FALSE,  
       );  
       $rows = array();  
       $header = array(t('NodeType'), t('Enabled'));  
       $form['global']['alter_node_nodetypes']['table'] = array('#theme' => 'taxonomy_theme_table');  
       $form['global']['alter_node_nodetypes']['table']['header'] = array('#data' => $header);  
       $form['global']['alter_node_nodetypes']['table']['type'] = array('#value' => 'taxonomy_theme_alter_nodetype|');  
       foreach ($nodetypes as $type => $title) {  
         $form['global']['alter_node_nodetypes']['table'][$type]['title'] = array('#value' => $title);  
         $form['global']['alter_node_nodetypes']['table'][$type]['taxonomy_theme_alter_nodetype|'.$type] = array(  
           '#type' => 'checkbox',  
           '#default_value' => variable_get('taxonomy_theme_alter_nodetype|'.$type, 1),  
         );  
       }  
     }  
   }  
   $form['global']['taxonomy_theme_alter_forms'] = array(  
     '#type' => 'checkbox',  
     '#title' => t('Show theme option on term/vocab/content-types pages'),  
     '#default_value' => variable_get('taxonomy_theme_alter_forms', 1),  
     '#description' => t('Assign themes directly from term/vocab-pages in \'categories\' and/or content-type settings.'),  
   );  
   
   $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );  
   $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );  
   $form['#submit']['taxonomy_theme_admin_form_submit'] = array();  
   return $form;  
 }  
11    
12  /**  /**
13   * function taxonomy_theme_admin_taxonomy_form().   * Function taxonomy_theme_admin_form().
  * (taxonomy selection method)  
14   */   */
15  function taxonomy_theme_admin_taxonomy_form() {  function taxonomy_theme_admin_form() {
   $form['taxonomy'] = array(  
     '#type' => 'fieldset',  
     '#title' => t('Taxonomy'),  
     '#collapsible' => FALSE,  
     '#collapsed' => FALSE,  
   );  
16    // TaxonomyTheme selection method    // TaxonomyTheme selection method
17    $options = array();    $options = array();
18    $options[TAXOTHEME_SKIP]      = t('Disabled');    $options[TAXONOMY_THEME_SKIP]      = t('Disabled');
19    $options[TAXOTHEME_TERM]      = t('Term-based');    $properties = array_keys(variable_get('themekey_properties', array()));
20    $options[TAXOTHEME_VOCAB]     = t('Vocab-based');    if (in_array('tid', $properties)) {
21    $options[TAXOTHEME_ALLTAXO]   = t('All Taxonomy');      $options[TAXONOMY_THEME_TERM]      = t('Term-based');
22    $options[TAXOTHEME_NODETYPE]  = t('NodeType-based');      $options[TAXONOMY_THEME_ALLTAXO]   = t('All Taxonomy');
23    $method = variable_get('taxonomy_theme_method', TAXOTHEME_SKIP);    }
24    $form['taxonomy']['taxonomy_theme_method'] = array(    if (in_array('vid', $properties)) {
25        $options[TAXONOMY_THEME_VOCAB]     = t('Vocab-based');
26      }
27      ksort($options);
28      //
29      $method = variable_get('taxonomy_theme_method', TAXONOMY_THEME_SKIP);
30      if (count($options) < 4) {
31        $message = t('Either \'Taxonomy: Term (tid)\' or \'Taxonomy: Vocabulary (vid)\' is not enabled!<br />
32                      Please visit the <a href="@url">ThemeKey settings</a> page and select both of these properties.',
33                      array('@url' => url('admin/settings/themekey/settings', array('query' => drupal_get_destination())))
34                    );
35        drupal_set_message($message, 'error');
36        $method = TAXONOMY_THEME_SKIP;
37      }
38      //
39      $form['taxonomy_theme_method'] = array(
40      '#type' => 'select',      '#type' => 'select',
41      '#title' => t('Template selection'),      '#title' => t('Template selection'),
42      '#default_value' => $method,      '#default_value' => $method,
43      '#options' => $options,      '#options' => $options,
44      '#description' => t('This value determines the method used for template selection.'),      '#description' => t('This value determines the method used for template selection.'),
45    );    );
46    $options_themes = _taxonomy_theme_options();  
47    switch(variable_get('taxonomy_theme_method', TAXOTHEME_SKIP)) {    //
48      case TAXOTHEME_TERM:    switch($method) {
49        $form['taxonomy'][] = _taxonomy_theme_admin_term_form($options_themes);      case TAXONOMY_THEME_TERM:
50        break;        $form[] = _taxonomy_theme_admin_term_form();
     case TAXOTHEME_VOCAB:  
       $form['taxonomy'][] = _taxonomy_theme_admin_vocab_form($options_themes);  
51        break;        break;
52      case TAXOTHEME_ALLTAXO:      case TAXONOMY_THEME_VOCAB:
53        $form['taxonomy'][] = _taxonomy_theme_admin_alltaxo_form($options_themes);        $form[] = _taxonomy_theme_admin_vocab_form();
54        break;        break;
55      case TAXOTHEME_NODETYPE:      case TAXONOMY_THEME_ALLTAXO:
56        $form['taxonomy'][] = _taxonomy_theme_admin_nodetype_form($options_themes);        $form[] = _taxonomy_theme_admin_alltaxo_form();
57        break;        break;
58      default:      default:
59    }    }
60    
61      $form['buttons']['submit'] = array(
62        '#type' => 'submit',
63        '#value' => t('Save configuration'),
64        '#submit' => array('_taxonomy_theme_admin_form_submit')
65      );
66      $form['buttons']['reset'] = array(
67        '#type' => 'submit',
68        '#value' => t('Reset to defaults'),
69        '#submit' => array('_taxonomy_theme_admin_form_reset')
70      );
71    
   $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );  
   $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );  
   $form['#submit']['taxonomy_theme_admin_form_submit'] = array();  
72    return $form;    return $form;
73  }  }
74    
75  /**  /**
76   * function _taxonomy_theme_admin_term_form().   * Function _taxonomy_theme_admin_term_form().
77   * (term-based administration form)   * (term-based administration form)
78   */   */
79  function _taxonomy_theme_admin_term_form($options_themes) {  function _taxonomy_theme_admin_term_form() {
80    $form['taxonomy_theme_select'] = array(    $form['taxonomy_theme_select'] = array(
81      '#type' => 'fieldset',      '#type' => 'fieldset',
82      '#title' => t('Terms => Themes'),      '#title' => t('Terms => Themes'),
83      '#collapsible' => FALSE,      '#collapsible' => FALSE,
84      '#collapsed' => FALSE,      '#collapsed' => FALSE,
85    );    );
86    
87    $options = array();    $options = array();
88    $selector = variable_get('taxonomy_theme_selector', '');    $selector = variable_get('taxonomy_theme_selector', '');
89    if (!$selector) {    if (!$selector) {
90      $options[0] = t('Choose a category');      $options[0] = t('Choose a category');
91    }    }
92    $vocabs = taxonomy_get_vocabularies();    $vocabs = taxonomy_get_vocabularies();
   $forum_vid = variable_get('forum_nav_vocabulary', '');  
93    foreach ($vocabs as $vocab) {    foreach ($vocabs as $vocab) {
94      if ($vocab->vid != $forum_vid) {      $options[$vocab->vid] = $vocab->name;
       $options[$vocab->vid] = $vocab->name;  
     }  
95    }    }
96    if (!empty($vocabs)) {    if (!empty($vocabs)) {
97      $form['taxonomy_theme_select']['taxonomy_theme_selector'] = array(      $form['taxonomy_theme_select']['taxonomy_theme_selector'] = array(
# Line 180  function _taxonomy_theme_admin_term_form Line 103  function _taxonomy_theme_admin_term_form
103      );      );
104    }    }
105    else {    else {
106      $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('#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.'));
107    }    }
108    
109    if ($selector) {    if ($selector) {
110      $data['key'] = 'tid';      $terms = taxonomy_get_tree($selector);
111      $data['method'] = array('type' => 'term', 'label' => t('Term'));      $form['taxonomy_theme_select'][] = _taxonomy_theme_admin_table_builder('tid', t('Term'), $terms);
     $data['data'] = taxonomy_get_tree($selector);  
     $form['taxonomy_theme_select'][] = taxonomy_theme_admin_table_builder($options_themes, $data);  
112    }    }
113    
114    return $form;    return $form;
115  }  }
116    
117  /**  /**
118   * function _taxonomy_theme_admin_vocab_form().   * Function _taxonomy_theme_admin_vocab_form().
119   * (vocabulary-based administration form)   * (vocabulary-based administration form)
120   */   */
121  function _taxonomy_theme_admin_vocab_form($options_themes) {  function _taxonomy_theme_admin_vocab_form() {
122    $form['taxonomy_theme_select'] = array(    $form['taxonomy_theme_select'] = array(
123      '#type' => 'fieldset',      '#type' => 'fieldset',
124      '#title' => t('Vocabularies => Themes'),      '#title' => t('Vocabularies => Themes'),
125      '#collapsible' => FALSE,      '#collapsible' => FALSE,
126      '#collapsed' => FALSE,      '#collapsed' => FALSE,
127    );    );
   $data['key'] = 'vid';  
   $data['method'] = array('type' => 'vocab', 'label' => t('Vocabulary'));  
   $data['data'] = taxonomy_get_vocabularies();  
   $form['taxonomy_theme_select'][] = taxonomy_theme_admin_table_builder($options_themes, $data);  
128    
129      $vocabs = taxonomy_get_vocabularies();
130      $form['taxonomy_theme_select'][] = _taxonomy_theme_admin_table_builder('vid', t('Vocabulary'), $vocabs);
131    
132    return $form;    return $form;
133  }  }
134    
135  /**  /**
136   * function _taxonomy_theme_admin_alltaxo_form().   * Function _taxonomy_theme_admin_alltaxo_form().
137   * (all-taxonomy administration form)   * (all-taxonomy administration form)
138   */   */
139  function _taxonomy_theme_admin_alltaxo_form($options_themes) {  function _taxonomy_theme_admin_alltaxo_form() {
140    $form['taxonomy_theme_select'] = array(    $form['taxonomy_theme_select'] = array(
141      '#type' => 'fieldset',      '#type' => 'fieldset',
142      '#title' => t('All Taxonomy => Themes'),      '#title' => t('All Taxonomy => Themes'),
143      '#collapsible' => FALSE,      '#collapsible' => FALSE,
144      '#collapsed' => FALSE,      '#collapsed' => FALSE,
145    );    );
146    
147    $vocabs = taxonomy_get_vocabularies();    $vocabs = taxonomy_get_vocabularies();
   $forum_vid = variable_get('forum_nav_vocabulary', '');  
148    if (count($vocabs)) {    if (count($vocabs)) {
149      foreach ($vocabs as $vocab) {      foreach ($vocabs as $vocab) {
150        if ($vocab->vid != $forum_vid) {        $rows = array();
151          $terms = taxonomy_get_tree($vocab->vid);        $form['taxonomy_theme_select'][$vocab->vid] = array(
152          $rows = array();          '#type' => 'fieldset',
153          $form['taxonomy_theme_select'][$vocab->vid] = array(          '#title' => t('Vocabulary: ') . $vocab->name,
154            '#type' => 'fieldset',          '#collapsible' => TRUE,
155            '#title' => t('Vocabulary: ').$vocab->name,          '#collapsed' => TRUE,
156            '#collapsible' => TRUE,        );
157            '#collapsed' => TRUE,        $terms = taxonomy_get_tree($vocab->vid);
158          );        $form['taxonomy_theme_select'][$vocab->vid][] = _taxonomy_theme_admin_table_builder('tid', t('Term'), $terms);
         $data['key'] = 'tid';  
         $data['method'] = array('type' => 'all', 'label' => t('Term'));  
         $data['data'] = $terms;  
         $form['taxonomy_theme_select'][$vocab->vid][] = taxonomy_theme_admin_table_builder($options_themes, $data);  
       }  
159      }      }
160    }    }
161    else {    else {
162      $form['taxonomy_theme_select']['text'] = array('#value' => t('<strong>Your site currently has no vocabularies.</strong>'));      $form['taxonomy_theme_select']['text'] = array('#value' => t('<strong>Your site currently has no vocabularies.</strong>'));
163    }    }
164    
165    return $form;    return $form;
166  }  }
167    
168  /**  /**
169   * function _taxonomy_theme_admin_nodetype_form().   * Function taxonomy_theme_admin_form_submit().
  * (nodetype-based administration form)  
170   */   */
171  function _taxonomy_theme_admin_nodetype_form($options_themes) {  function _taxonomy_theme_admin_form_submit($form, &$form_state) {
172    $form['taxonomy_theme_select'] = array(    //
173      '#type' => 'fieldset',    $selector = variable_get('taxonomy_theme_selector', '');
174      '#title' => t('NodeType => Themes'),    $method = variable_get('taxonomy_theme_method', TAXONOMY_THEME_SKIP);
175      '#collapsible' => FALSE,    if ($form_state['values']['taxonomy_theme_method'] != $method) {
176      '#collapsed' => FALSE,      $form_state['redirect'] = 'admin/settings/themekey/taxonomy/confirm/'. $method;
   );  
   $nodetypes = node_get_types('names');  
   if (count($nodetypes)) {  
     $rows = array();  
     $header = array(t('NodeType'), t('Assigned to Theme'));  
     $form['taxonomy_theme_select']['table'] = array('#theme' => 'taxonomy_theme_table');  
     $form['taxonomy_theme_select']['table']['header'] = array('#data' => $header);  
     $form['taxonomy_theme_select']['table']['type'] = array('#value' => 'taxonomy_theme_nodetype|');  
     foreach ($nodetypes as $type => $title) {  
       $template_type = variable_get('taxonomy_theme_nodetype|'.$type, '');  
       $form['taxonomy_theme_select']['table'][$type]['title'] = array('#value' => $title);  
       $form['taxonomy_theme_select']['table'][$type]['taxonomy_theme_nodetype|'.$type] = array(  
         '#type' => 'select',  
         '#default_value' => $template_type,  
         '#options' => $options_themes,  
       );  
     }  
177    }    }
178    else {    if (isset($form_state['values']['taxonomy_theme_selector'])) {
179      $form['taxonomy_theme_select']['text'] = array('#value' => t('<strong>Your site currently has no node type defined.</strong>'));      if (!empty($form_state['redirect']) || $form_state['values']['taxonomy_theme_selector'] != $selector) {
180          $form_state['redirect'] = 'admin/settings/themekey/taxonomy/confirm/'. $method .'/'. $selector;
181        }
182        $selector = $form_state['values']['taxonomy_theme_selector'];
183    }    }
184      //
185    return $form;    if (empty($form_state['redirect']) && isset($form_state['values']['table'])) {
186  }      foreach ($form_state['values']['table'] as $key => $details) {
187          switch ($method) {
188  /**          case TAXONOMY_THEME_TERM:
189   * function taxonomy_theme_admin_forum_form().            $conditions = array(array('property' => 'vid', 'value' => $selector));
190   * (forum administration form)            taxonomy_theme_set_theme('tid', $key, $details['theme'], $conditions);
191   */            break;
192  function taxonomy_theme_admin_forum_form() {          case TAXONOMY_THEME_VOCAB:
193    $form['taxonomy_theme_forums'] = array(            taxonomy_theme_set_theme('vid', $key, $details['theme']);
194      '#type' => 'fieldset',            break;
195      '#title' => t('Forums => Themes'),          case TAXONOMY_THEME_ALLTAXO:
196      '#collapsible' => FALSE,            taxonomy_theme_set_theme('tid', $key, $details['theme']);
197      '#collapsed' => FALSE,            break;
198    );          default:
199    $form['taxonomy_theme_forums']['taxonomy_theme_forums_enable'] = array(        }
     '#type' => 'checkbox',  
     '#title' => t('Apply themes to forums'),  
     '#default_value' => variable_get('taxonomy_theme_forums_enable', 0),  
   );  
   $form['taxonomy_theme_forums']['taxonomy_theme_forum_dep'] = array(  
     '#type' => 'checkbox',  
     '#title' => t('Theme forum-dependent nodes/pages'),  
     '#default_value' => variable_get('taxonomy_theme_forum_dep', 1),  
     '#description' => t('Apply the forum\'s theme to (add/view/edit) comment pages also.'),  
   );  
   $forum_vid = variable_get('forum_nav_vocabulary', '');  
   if (variable_get('taxonomy_theme_forums_enable', 0)) {  
     $terms = taxonomy_get_tree($forum_vid);  
     $options_themes = _taxonomy_theme_options();  
     if (count($terms)) {  
       $data['key'] = 'tid';  
       $data['method'] = array('type' => 'forum', 'label' => t('Forum'));  
       $data['data'] = $terms;  
       $form['taxonomy_theme_forums'][] = taxonomy_theme_admin_table_builder($options_themes, $data);  
200      }      }
201      else {      unset($form_state['values']['table']);
202        $form['taxonomy_theme_forums']['text'] = array('#value' => t('<strong>Your site currently has no forums.</strong>'));    }
203      //
204      foreach ($form_state['values'] as $key => $value) {
205        $pos = strpos($key, 'taxonomy_theme_');
206        if ($pos !== FALSE && $pos == 0) {
207          variable_set($key, $value);
208      }      }
209    }    }
   
   $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );  
   $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );  
   $form['#submit']['taxonomy_theme_admin_form_submit'] = array();  
   return $form;  
210  }  }
211    
212  /**  /**
213   * function taxonomy_theme_admin_extended_form().   * Function taxonomy_theme_admin_form_reset().
  * (extended (path-based) administration form)  
214   */   */
215  function taxonomy_theme_admin_extended_form() {  function _taxonomy_theme_admin_form_reset($form, &$form_state) {
216    $form['taxonomy_theme_extended'] = array(    switch ($form_state['values']['taxonomy_theme_method']) {
217      '#type' => 'fieldset',      case TAXONOMY_THEME_VOCAB:
218      '#title' => t('Extended'),        taxonomy_theme_delall_theme('vid');
219      '#collapsible' => FALSE,        break;
220      '#collapsed' => FALSE,      case TAXONOMY_THEME_TERM:
221    );      case TAXONOMY_THEME_ALLTAXO:
222    if (variable_get('taxonomy_theme_extended_enable', 0)) {        taxonomy_theme_delall_theme('tid');
223      $form['taxonomy_theme_extended']['help'] = array('#value' => t('<p>To assign a theme for a particular path enter the path into according textarea.<br />Enter one path per line as Drupal paths (or path aliases). Character \'*\' is a wildcard.<br /><i>Adding \'node/6\' to the \'bluemarine\' field will assign bluemarine theme to node 6.</i></p>'));        break;
224      $form['taxonomy_theme_extended']['theme_pathes'] = array('#tree' => TRUE);      default:
     $options_admin_themes = _taxonomy_theme_options(TRUE, FALSE);  
     foreach($options_admin_themes as $themex) {  
       $form['taxonomy_theme_extended']['theme_pathes'][$themex] = array(  
         '#type' => 'fieldset',  
         '#title' => $themex,  
         '#collapsible' => TRUE,  
         '#collapsed' => TRUE,  
       );  
       unset($pathes);  
       $result = db_query("SELECT path FROM {theme_pathes} WHERE theme = '%s'", $themex);  
       while ($path = db_fetch_object($result)) {  
         $pathes .= $path->path."\r\n";  
       }  
       $form['taxonomy_theme_extended']['theme_pathes'][$themex]['pathes'] = array(  
         '#type' => 'textarea',  
         '#rows' => 10,  
         '#default_value' => $pathes,  
       );  
     }  
225    }    }
226    else {    //
227      $form['taxonomy_theme_extended']['text'] = array('#value' => t('<strong>\'Extended\' assignment of themes is currently disabled.</strong>'));    foreach ($form_state['values'] as $key => $value) {
228        $pos = strpos($key, 'taxonomy_theme_');
229        if ($pos !== FALSE && $pos == 0) {
230          variable_del($key);
231        }
232    }    }
   
   $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );  
   $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );  
   $form['#submit']['taxonomy_theme_admin_extended_form_submit'] = array();  
   return $form;  
233  }  }
234    
235  /**  /**
236   * function taxonomy_theme_admin_table_builder().   * Function _taxonomy_theme_admin_form_confirm().
  * (build list/table of taxonomy vocabs/terms)  
237   */   */
238  function taxonomy_theme_admin_table_builder($options_themes, $data) {  function _taxonomy_theme_admin_form_confirm() {
239    if (count($data['data'])) {    if (!($method = arg(5))) {
240      $rows = array();      drupal_goto('admin/settings/themekey/taxonomy');
241      $header = array($data['method']['label'], t('Assigned to Theme'));    }
242      $form['table'] = array('#theme' => 'taxonomy_theme_table');  
243      $form['table']['header'] = array('#data' => $header);    //
244      $form['table']['type'] = array('#value' => 'taxonomy_theme_'.$data['method']['type'].'|');    $vid = arg(6);
245      foreach ($data['data'] as $item) {    if ($vid && $method == TAXONOMY_THEME_TERM) {
246        $template_item = variable_get('taxonomy_theme_'.$data['method']['type'].'|'.$item->$data['key'], '');      $selector = variable_get('taxonomy_theme_selector', '');
247        $form['table'][$item->$data['key']]['title'] = array('#value' => $item->name);      $vocab_from = taxonomy_vocabulary_load($vid);
248        $form['table'][$item->$data['key']]['taxonomy_theme_'.$data['method']['type'].'|'.$item->$data['key']] = array(      $vocab_to = taxonomy_vocabulary_load($selector);
249          '#type' => 'select',      $description = t('<p>The category used for template selection has changed (from %from to %to).
250          '#default_value' => $template_item,                        Items associated with the previous selected category should be removed to
251          '#options' => $options_themes,                        prevent interference with the new settings.<br />
252        );                        Click \'Remove\' to continue removing obsolete items.</p>',
253      }                        array('%from' => $vocab_from->name, '%to' => $vocab_to->name)
254                        );
255    }    }
256    else {    else {
257      $form['noitems'] = array('#value' => t('<strong>No items</strong>'));      $description = t('<p>The template selection method has changed. Items associated with the previous
258                          method should be removed to prevent interference with the new settings.<br />
259                          Click \'Remove\' to continue removing obsolete items.</p>');
260    }    }
261    
262    return $form;    $form = array();
263      $form['#submit'] = array('_taxonomy_theme_admin_form_confirm_submit');
264      $params = array(
265        'key' => ($method == TAXONOMY_THEME_VOCAB) ? 'vid' : 'tid',
266        'vid' => isset($vid) ? $vid : NULL
267      );
268      $form['taxonomy_theme_params'] = array('#type' => 'value', '#value' => $params);
269      $form['#submit'] = array('_taxonomy_theme_admin_form_confirm_submit');
270    
271      return confirm_form(
272        $form,
273        t('Do you want to remove obsolete items?'),
274        'admin/settings/themekey/taxonomy',
275        $description,
276        t('Remove'),
277        t('Keep')
278      );
279  }  }
280    
281  /**  /**
282   * function theme_taxonomy_theme_table().   * Function _taxonomy_theme_admin_form_confirm_submit().
283   */   */
284  function theme_taxonomy_theme_table($form) {  function _taxonomy_theme_admin_form_confirm_submit($form, &$form_state) {
285    foreach (element_children($form) as $key) {    if (isset($form_state['values']['taxonomy_theme_params'])) {
286      if (isset($form[$key]['title'])) {      $conditions = array();
287        $row = array();      if (isset($form_state['values']['taxonomy_theme_params']['vid'])) {
288        $row[] = drupal_render($form[$key]['title']);        $conditions = array(array('property' => 'vid', 'value' => $form_state['values']['taxonomy_theme_params']['vid']));
       $row[] = drupal_render($form[$key][$form['type']['#value'].$form[$key]['#parents'][0]]);  
       $rows[] = $row;  
289      }      }
290        taxonomy_theme_delall_theme($form_state['values']['taxonomy_theme_params']['key'], $conditions);
291    }    }
292    $header = array($form['header']['#data'][0], $form['header']['#data'][1]);    $form_state['redirect'] = 'admin/settings/themekey/taxonomy';
   return theme('table', $header, $rows);  
293  }  }
294    
295  /**  /**
296   * function taxonomy_theme_admin_form_submit().   * Function _taxonomy_theme_admin_table_builder().
297     * (build list/table of taxonomy vocabs/terms)
298   */   */
299  function taxonomy_theme_admin_form_submit($form_id, $form_data) {  function _taxonomy_theme_admin_table_builder($key, $label, $data) {
300    if ($form_data['op'] == t('Save configuration')) {    $form['table'] = array(
301      // save settings      '#theme' => 'taxonomy_theme_table',
302      unset($form_data['op'], $form_data['submit'], $form_data['reset'], $form_data['form_id']);      '#header' => array($label, t('Assigned to Theme')),
303      foreach ($form_data as $key => $value) {      '#tree' => TRUE
304        _taxonomy_theme_variable_set($key, $value);    );
305      }    //
306      menu_rebuild();    $rows = array();
307      drupal_set_message(t('The configuration options have been saved.'));    $themes = _themekey_theme_options();
308    }    foreach ($data as $item) {
309    else {      $form['table'][$item->$key]['name'] = array('#value' => $item->name);
310      // reset settings      $form['table'][$item->$key]['theme'] = array(
311      db_query("DELETE FROM {variable} WHERE name LIKE 'taxonomy_theme_%'");        '#type' => 'select',
312      db_query("UPDATE {system} SET weight = '-10' WHERE filename LIKE '%taxonomy_theme.module' LIMIT 1");        '#default_value' => taxonomy_theme_get_theme($key, $item->$key),
313      variable_set('taxonomy_theme_enable', 1);        '#options' => $themes,
314      drupal_set_message(t('All configuration options have been set to default values.'));      );
315    }    }
316    
317      return $form;
318  }  }
319    
320  /**  /**
321   * function taxonomy_theme_admin_extended_form_submit().   * Function theme_taxonomy_theme_table().
322   */   */
323  function taxonomy_theme_admin_extended_form_submit($form_id, $form_data) {  function theme_taxonomy_theme_table($form) {
324    if ($form_data['op'] == t('Save configuration')) {    $header = isset($form['#header']) ? $form['#header'] : array();
325      // save settings    $attributes = isset($form['#attributes']) ? $form['#attributes'] : array();
326      db_query("DELETE FROM {theme_pathes}");  
327      foreach ($form_data['theme_pathes'] as $theme => $data) {    $rows = array();
328        $pathes = preg_split('/(\r\n?|\n)/', $data['pathes'], -1, PREG_SPLIT_NO_EMPTY);    foreach (element_children($form) as $key) {
329        foreach ($pathes as $path) {      $row = array();
330          while ($path{0} == '/') {      foreach (element_children($form[$key]) as $item) {
331            $path = substr($path, 1);        $row[] = drupal_render($form[$key][$item]);
         }  
         db_query("INSERT INTO {theme_pathes} (path, theme) VALUES ('%s', '%s')", $path, $theme);  
       }  
332      }      }
333      _taxonomy_theme_expcache(); // reset pathes cache      $rows[] = $row;
     drupal_set_message(t('The configuration options have been saved.'));  
   }  
   else {  
     // reset settings  
     db_query("DELETE FROM {theme_pathes}");  
     _taxonomy_theme_expcache(); // reset pathes cache  
     drupal_set_message(t('All configuration options have been set to default values.'));  
334    }    }
 }  
335    
336  /**    if (empty($rows)) {
337   * function _taxonomy_theme_form_alter().      $message = check_plain(isset($form['#empty']) ? $form['#empty'] : t('There are no items in the table.'));
338   * (hook into various form to add a theme selector field)      $rows[] = array(array('data' => $message, 'colspan' => count($header), 'align' => 'center', 'class' => 'message'));
  */  
 function _taxonomy_theme_form_alter($form_id, &$form) {  
   $options_themes = _taxonomy_theme_options();  
   if (variable_get('taxonomy_theme_alter_forms', 1) && user_access('administer taxonomy_theme')) {  
     _taxonomy_theme_alter_taxonomy($options_themes, $form_id, $form);  
   }  
   if (variable_get('taxonomy_theme_alter_node', 0)  
           && ($form_id == $form['type']['#value'].'_node_form')  
           && variable_get('taxonomy_theme_alter_nodetype|'.$form['type']['#value'], 1)  
           && (user_access('administer taxonomy_theme') || user_access('assign node themes'))  
         ) {  
     _taxonomy_theme_alter_nodeform($options_themes, $form_id, $form);  
   }  
   if (variable_get('taxonomy_theme_viewspages', 0) && ($form_id == 'views_edit_view')  
           && (user_access('administer taxonomy_theme') || user_access('assign node themes'))  
         ) {  
     _taxonomy_theme_alter_views($options_themes, $form_id, $form);  
339    }    }
340    
341      return count($rows) ? theme('table', $header, $rows, $attributes) : '';
342  }  }
343    
344  /**  /**
345   * function _taxonomy_theme_alter_taxonomy().   * Function _taxonomy_theme_form_alter().
  * (hook into taxonomy-related administration forms)  
346   */   */
347  function _taxonomy_theme_alter_taxonomy($options_themes, $form_id, &$form) {  function _taxonomy_theme_form_alter(&$form, $form_state, $form_id) {
348    $forum_vid = variable_get('forum_nav_vocabulary', '');    $themes = _themekey_theme_options();
349    $theme_forums = (module_exists('forum') && variable_get('taxonomy_theme_forums_enable', 0));    $method = variable_get('taxonomy_theme_method', TAXONOMY_THEME_SKIP);
350    $method = variable_get('taxonomy_theme_method', TAXOTHEME_SKIP);    // Alter taxonomy term page
351    // alter taxonomy term page    if ($form_id == 'taxonomy_form_term' && ($method == TAXONOMY_THEME_TERM || $method == TAXONOMY_THEME_ALLTAXO)) {
352    if ($form_id == 'taxonomy_form_term' && ($method == TAXOTHEME_TERM || $method == TAXOTHEME_ALLTAXO)) {      $selector = variable_get('taxonomy_theme_selector', '');
353      if ($form['vid']['#value'] == $forum_vid) {      if ($method == TAXONOMY_THEME_TERM && $selector && $form['#vocabulary']['vid'] != $selector) {
354        if (!$theme_forums) {        return;
         return;  
       }  
       $default_value = variable_get('taxonomy_theme_forum|'.$form['tid']['#value'], 'default');  
     }  
     else {  
       if ($method == TAXOTHEME_TERM) {  
         $default_value = variable_get('taxonomy_theme_term|'.$form['tid']['#value'], 'default');  
       }  
       else {  
         $default_value = variable_get('taxonomy_theme_all|'.$form['tid']['#value'], 'default');  
       }  
355      }      }
356      $form_insert['term_theme']['theme'] = array(      $form_theme['taxonomy_theme_select'] = array(
357        '#type' => 'select',        '#type' => 'fieldset',
       '#title' => t('Theme'),  
       '#default_value' => $default_value,  
       '#options' => $options_themes,  
       '#description' => t('Theme to be assigned to current term (by taxonomy_theme)'),  
     );  
     array_splice($form, 5, 0, $form_insert);  
     $form['#submit']['taxonomy_theme_form_alter_submit'] = array();  
   }  
   // alter taxonomy vocabulary page  
   else if (($form_id == 'taxonomy_form_vocabulary') && ($method == TAXOTHEME_VOCAB)) {  
     $form_insert['vocab_theme']['theme'] = array(  
       '#type' => 'select',  
358        '#title' => t('Theme'),        '#title' => t('Theme'),
359        '#default_value' => variable_get('taxonomy_theme_vocab|'.$form['vid']['#value'], 'default'),        '#collapsible' => TRUE,
360        '#options' => $options_themes,        '#collapsed' => FALSE
       '#description' => t('Theme to be assigned to current vocabulary (by taxonomy_theme)'),  
361      );      );
362      array_splice($form, 10, 0, $form_insert);      $form_theme['taxonomy_theme_select']['theme'] = array(
     $form['#submit']['taxonomy_theme_form_alter_submit'] = array();  
   }  
   // alter edit forum page  
   else if (($form_id == 'forum_form_forum') && $theme_forums) {  
     $form_insert['forum_theme']['theme'] = array(  
363        '#type' => 'select',        '#type' => 'select',
364        '#title' => t('Theme'),        '#default_value' => taxonomy_theme_get_theme('tid', $form['tid']['#value']),
365        '#default_value' => variable_get('taxonomy_theme_forum|'.$form['tid']['#value'], 'default'),        '#options' => $themes,
366        '#options' => $options_themes,        '#description' => t('Theme to be assigned to current term')
       '#description' => t('Theme to be assigned to current forum (by taxonomy_theme)'),  
367      );      );
368      array_splice($form, 4, 0, $form_insert);      array_splice($form, 4, 0, $form_theme);
369      $form['#submit']['taxonomy_theme_form_alter_submit'] = array();      $form['#submit'][] = 'taxonomy_theme_form_alter_submit';
370    }    }
371    // alter node settings pages    // Alter taxonomy vocabulary page
372    else if (($form_id == 'node_type_form') && ($method == TAXOTHEME_NODETYPE)) {    else if (($form_id == 'taxonomy_form_vocabulary') && ($method == TAXONOMY_THEME_VOCAB)) {
373      $form_insert['node_settings_theme'] = array(      $form_theme['taxonomy_theme_select'] = array(
374        '#type' => 'fieldset',        '#type' => 'fieldset',
375        '#title' => t('Theme'),        '#title' => t('Theme'),
376        '#collapsible' => FALSE,        '#collapsible' => TRUE,
377        '#collapsed' => FALSE,        '#collapsed' => FALSE
378      );      );
379      $form_insert['node_settings_theme']['theme'] = array(      $form_theme['taxonomy_theme_select']['theme'] = array(
380        '#type' => 'select',        '#type' => 'select',
381        '#default_value' => variable_get('taxonomy_theme_nodetype|'.$form['old_type']['#value'], 'default'),        '#default_value' => taxonomy_theme_get_theme('vid', $form['vid']['#value']),
382        '#options' => $options_themes,        '#options' => $themes,
383        '#description' => t('Theme to be assigned to current node type (by taxonomy_theme)'),        '#description' => t('Theme to be assigned to current vocabulary')
384      );      );
385      array_splice($form, 3, 0, $form_insert);      array_splice($form, 3, 0, $form_theme);
386      $form['#submit']['taxonomy_theme_form_alter_submit'] = array();      $form['#submit'][] = 'taxonomy_theme_form_alter_submit';
   }  
 }  
   
 /**  
  * function _taxonomy_theme_alter_nodeform().  
  * (hook into node administration form)  
  */  
 function _taxonomy_theme_alter_nodeform($options_themes, $form_id, &$form) {  
   $node_path = drupal_get_path_alias('node/'.$form['nid']['#value']);  
   if (module_exists('i18n')) {  
     i18n_get_lang_prefix($node_path, true);  
   }  
   $node_theme = db_result(db_query("SELECT theme FROM {theme_pathes} WHERE path = '%s'", $node_path));  
   if (!$node_theme) {  
     $node_theme = 'default';  
   }  
   $form['node_form_theme'] = array(  
     '#type' => 'fieldset',  
     '#title' => t('Theme'),  
     '#collapsible' => TRUE,  
     '#collapsed' => TRUE,  
   );  
   $form['node_form_theme']['theme'] = array(  
     '#type' => 'select',  
     '#default_value' => $node_theme,  
     '#options' => $options_themes,  
     '#description' => t('Theme to be assigned to current path/node (by taxonomy_theme)'),  
   );  
   $form['#submit']['taxonomy_theme_form_alter_submit'] = array();  
 }  
   
 /**  
  * function _taxonomy_theme_alter_views().  
  * (hook into views administration form)  
  */  
 function _taxonomy_theme_alter_views($options_themes, $form_id, &$form) {  
   $view_theme = db_result(db_query("SELECT theme FROM {theme_pathes} WHERE path = '%s'", $form['page-info']['url']['#default_value']));  
   if (!$view_theme) {  
     $view_theme = 'default';  
   }  
   $form['page-info']['theme'] = array(  
     '#type' => 'select',  
     '#title' => t('Theme'),  
     '#default_value' => $view_theme,  
     '#options' => $options_themes,  
     '#description' => t('Theme to be assigned to current view (by taxonomy_theme)'),  
   );  
   $form['#submit']['taxonomy_theme_form_alter_submit'] = array();  
 }  
   
 /**  
  * function taxonomy_theme_form_alter_submit().  
  */  
 function taxonomy_theme_form_alter_submit($form_id, $form_data) {  
   // does the form contain a 'theme' field  
   if (!isset($form_data['theme'])) {  
     return;  
   }  
   // submit taxonomy term page  
   if ($form_id == 'taxonomy_form_term') {  
     if ($form_data['vid'] == variable_get('forum_nav_vocabulary', '')) {  
       _taxonomy_theme_variable_set('taxonomy_theme_forum|'.$form_data['tid'], $form_data['theme']);  
     }  
     else {  
       if (variable_get('taxonomy_theme_method', TAXOTHEME_SKIP) == TAXOTHEME_TERM) {  
         _taxonomy_theme_variable_set('taxonomy_theme_term|'.$form_data['tid'], $form_data['theme']);  
       }  
       else {  
         _taxonomy_theme_variable_set('taxonomy_theme_all|'.$form_data['tid'], $form_data['theme']);  
       }  
     }  
   }  
   // submit taxonomy vocabulary page  
   else if ($form_id == 'taxonomy_form_vocabulary') {  
     _taxonomy_theme_variable_set('taxonomy_theme_vocab|'.$form_data['vid'], $form_data['theme']);  
   }  
   // submit edit forum page  
   else if ($form_id == 'forum_form_forum') {  
     _taxonomy_theme_variable_set('taxonomy_theme_forum|'.$form_data['tid'], $form_data['theme']);  
   }  
   // submit node settings pages  
   else if ($form_id == 'node_type_form') {  
     _taxonomy_theme_variable_set('taxonomy_theme_nodetype|'.$form_data['type'], $form_data['theme']);  
   }  
   // submit node form pages  
   else if ($form_id == $form_data['type'].'_node_form') {  
     db_query("DELETE FROM {theme_pathes} WHERE path = '%s'", 'node/'.$form_data['nid']);  
     if (isset($form_data['path']) && !empty($form_data['path'])) {  
       db_query("DELETE FROM {theme_pathes} WHERE path = '%s'", $form_data['path']);  
     }  
     if ($form_data['theme'] != 'default') {  
       if (isset($form_data['path']) && !empty($form_data['path'])) {  
         db_query("INSERT INTO {theme_pathes} (path, theme) VALUES ('%s', '%s')", $form_data['path'], $form_data['theme']);  
       }  
       else {  
         db_query("INSERT INTO {theme_pathes} (path, theme) VALUES ('%s', '%s')", 'node/'.$form_data['nid'], $form_data['theme']);  
       }  
     }  
     _taxonomy_theme_expcache(); // reset pathes cache  
   }  
   // submit edit view page  
   else if (($form_id == 'views_edit_view') && !empty($form_data['url'])) {  
     db_query("DELETE FROM {theme_pathes} WHERE path = '%s'", drupal_get_normal_path($form_data['url']));  
     if ($form_data['theme'] != 'default') {  
       db_query("INSERT INTO {theme_pathes} (path, theme) VALUES ('%s', '%s')", drupal_get_normal_path($form_data['url']), $form_data['theme']);  
     }  
     _taxonomy_theme_expcache(); // reset pathes cache  
387    }    }
388  }  }
389    
390  /**  /**
391   * function _taxonomy_theme_options().   * function _taxonomy_theme_alter_submit().
  * (create a list of available themes)  
392   */   */
393  function _taxonomy_theme_options($admin_themes = FALSE, $default = TRUE) {  function _taxonomy_theme_form_alter_submit($form, &$form_state) {
394    $themes = system_theme_data();    // Submit taxonomy term page
395    $options_themes = array();    if ($form_state['values']['form_id'] == 'taxonomy_form_term') {
396    if ($default) {      taxonomy_theme_set_theme('tid', $form_state['values']['tid'], $form_state['values']['theme']);
     $options_themes['default'] = t('System default');  
397    }    }
398    foreach ($themes as $themex) {    // Submit taxonomy vocabulary page
399      if ($admin_themes || $themex->status || variable_get('taxonomy_theme_allowall', 0)) {    else if ($form_state['values']['form_id'] == 'taxonomy_form_vocabulary') {
400        $options_themes[$themex->name] = $themex->name;      taxonomy_theme_set_theme('vid', $form_state['values']['vid'], $form_state['values']['theme']);
     }  
401    }    }
   
   return $options_themes;  
402  }  }
   
 /**  
  * function _taxonomy_theme_variable_set().  
  * (set variable if theme != 'default' else remove variable)  
  */  
 function _taxonomy_theme_variable_set($key, $value) {  
   if ($value == 'default') {  
     variable_del($key);  
   }  
   else {  
     variable_set($key, $value);  
   }  
 }  
   
 ?>  

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

  ViewVC Help
Powered by ViewVC 1.1.2