Project

General

Profile

Download (13.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
define("POLYFILL_TEST_URL", "/polyfills/box-sizing-polyfill/boxsizing.htc");
4

    
5
/**
6
 * Provides the image names which can be configured in the theme settings to all
7
 * theme setting functions.
8
 *
9
 * @return multitype:string
10
 *     the list of image names which can be configured in the theme settings
11
 */
12
function _zen_dataportal_imagenames() {
13
  static $image_list = array('banner', 'body_background', 'page_background');
14
  return $image_list;
15
}
16

    
17
/**
18
 * Implements hook_form_system_theme_settings_alter().
19
 *
20
 * @param $form
21
 *   Nested array of form elements that comprise the form.
22
 * @param $form_state
23
 *   A keyed array containing the current state of the form.
24
 */
25
function zen_dataportal_form_system_theme_settings_alter(&$form, &$form_state, $form_id = NULL)  {
26
  global $base_root;
27

    
28
  // Work-around for a core bug affecting admin themes. See issue #943212.
29
  if (isset($form_id)) {
30
    return;
31
  }
32

    
33
  if(!module_exists('cdm_dataportal')) {
34
    drupal_set_message('<strong>FATAL MISCONFIGURATION:</strong>The zen_dataportal theme requires the cdm_dataportal module to be installed and enabled.', 'error');
35
    return;
36
  }
37

    
38
  $path_to_theme = drupal_get_path('theme', 'zen_dataportal');
39

    
40
  // check browser compatibility requirements
41
  $browser_compatibility_issues = array();
42
  $response = drupal_http_request($base_root . POLYFILL_TEST_URL, array("method"=>"HEAD"));
43
  // preprocess-css
44
  if($response->code != 200){
45
    $browser_compatibility_issues[] = 'The ' . l('polyfills folder' ,'/polyfills/', array('external'=>TRUE))
46
        .' is not found.'
47
        . 'Please read the installation instructions in the ' .l('README', $path_to_theme . '/README.txt') .' of this theme.';
48
  }
49
  if(variable_get('preprocess_css', 0) !== 1) {
50
    $browser_compatibility_issues[] = 'The '
51
        . l(t('Aggregate and compress CSS files'), 'admin/config/development/performance', array('fragment'=>'edit-preprocess-css'))
52
        . ' option must be turned on.';
53
  }
54
  if(count($browser_compatibility_issues) > 0 ){
55
    drupal_set_message('<strong>Browser compatibility problems:</strong><ul><li>' . join('</li><li>', $browser_compatibility_issues) .
56
      '</li></ul>The theme will not be rendered correctly in InternetExplorer 8, 7 or 6 until these problems are solved.', 'error');
57
  }
58

    
59
  // the 'Toggle display' setting on top
60
  $form['theme_settings']['#weight'] = -11;
61

    
62
  // will be available in the page.tpl.php
63
   $form['zen_dataportal_misc'] = array(
64
          '#type' => 'fieldset',
65
          '#weight' => -10,
66
          '#title' => t('Miscellaneous settings'),
67
          '#description' => t('Miscellaneous settings for the DataPortal Zen theme.')
68
  );
69
  $form['zen_dataportal_misc']['site_name_position'] = array(
70
    '#type'          => 'select',
71
    '#title'         => t('Site name posistion'),
72
    '#description'   => t('The site name can be positioned over the banner or below the banner.'
73
        . '<br/><stong>NOTE:</strong> If your are choosing to position the site name below the banner you may also want to '
74
        . 'adapt the <em>site name color</em>.' ),
75
    '#options' => array(
76
      'hide' => t('Hidden'),
77
      'above_banner' => t('Above banner'),
78
      'below_banner' => t('Below banner'),
79
    ),
80
    '#default_value' => theme_get_setting('site_name_position'),
81
  );
82
  $form['zen_dataportal_misc']['header_margin_bottom'] = array(
83
      '#type'          => 'textfield',
84
      '#title'         => t('Header margin at bottom'),
85
      '#default_value' => theme_get_setting('header_margin_bottom'),
86
      '#disabled'      => theme_get_setting('site_name_position') == 'below_banner',
87
      '#description'   => t('This margin instroduces space between the header and the main menu. This setting not applies if !site-name-pos is set to !below-banner '
88
          . 'The entered value can be any css length measurement. It is a <number> immediately followed by a length unit (px, em, pc, in, mm, …). See !link for more information',
89
            array(
90
                '!site-name-pos' => '<b> '. t('Site name posistion') . '</b>',
91
                '!below-banner' =>  '<b> '. t('Below banner') . '</b>',
92
                '!link' => l('https://developer.mozilla.org/en-US/docs/CSS/length', 'https://developer.mozilla.org/en-US/docs/CSS/length'),
93
             )
94
          ),
95
  );
96

    
97
  $form['zen_dataportal_misc']['user_defined_styles'] = array(
98
      '#type'          => 'textarea',
99
      '#title'         => t('User defined styles'),
100
      '#default_value' => theme_get_setting('user_defined_styles'),
101
      '#description'   => t('Add any additional css style to overrride presets and customize the layout of your portal.')
102
  );
103

    
104

    
105
  // TODO : site-name shadow: text-shadow: black 0 10px 20px, black 0 5px
106
  drupal_add_css($path_to_theme . '/js/colorpicker/css/colorpicker.css', 'file');
107
  drupal_add_js($path_to_theme. '/js/colorpicker/js/colorpicker.js', 'file');
108
  drupal_add_js($path_to_theme . '/js/settings-ui.js', 'file');
109
  $form['zen_dataportal_colors'] = array(
110
          '#type' => 'fieldset',
111
          '#title' => t('Colors'),
112
          '#weight' => -9,
113
          '#description' => t('Configure colors where.'),
114
          '#attributes' => array('class' => array('theme-settings-bottom')),
115
  );
116
  zen_dataportal_form_widget_color(
117
      $form['zen_dataportal_colors'],
118
      'site-name_color',
119
      t('The color of the site name which is shown in the header.')
120
  );
121
  zen_dataportal_form_widget_color(
122
  $form['zen_dataportal_colors'],
123
  'main-menu_color',
124
  t('The font color of the main menu.')
125
  );
126

    
127
  zen_dataportal_form_widget_color(
128
      $form['zen_dataportal_colors'],
129
      'main-menu_background-color',
130
      t('The color of the main menu background.')
131
  );
132
  zen_dataportal_form_widget_color(
133
      $form['zen_dataportal_colors'],
134
      'main-menu_background-color-2',
135
      t('The second color of the main menu background. If this is also set the menu background will have a grandiend.')
136
  );
137
  zen_dataportal_form_widget_color(
138
      $form['zen_dataportal_colors'],
139
      'sub-header_background-color',
140
      t('The background color sub-header.')
141
  );
142

    
143

    
144
  // all image related settings in one section:
145
  $form['zen_dataportal_images'] =  array(
146
          '#type' => 'fieldset',
147
          '#weight' => -8,
148
          '#title' => t('Images and Icons'),
149
          '#description' => t('In this section you can define cutom banners, logos, and background images.')
150
  );
151
  // moving logo and favicon setting also into this field set
152
  $form['zen_dataportal_images']['logo'] = $form['logo'];
153
  unset($form['logo']);
154
  $form['zen_dataportal_images']['favicon'] = $form['favicon'];
155
  unset($form['favicon']);
156
  // custom images for banner, body and page backgrounds
157
  //
158
  $weight = 0;
159
  foreach(_zen_dataportal_imagenames() as $which_image) {
160
    zen_dataportal_form_widget_image($form['zen_dataportal_images'], $which_image, $weight++);
161
  }
162

    
163

    
164
  $form['#validate'][] = 'zen_dataportal_theme_settings_validate';
165
  $form['#submit'][] = 'zen_dataportal_theme_settings_submit';
166
  // We are editing the $form in place, so we don't need to return anything.
167
}
168

    
169
/**
170
 * Process zen_dataportal admin form submissions.
171
 * @param $form
172
 *   Nested array of form elements that comprise the form.
173
 * @param $form_state
174
 *   A keyed array containing the current state of the form.
175
 */
176
function zen_dataportal_theme_settings_submit($form, &$form_state) {
177

    
178
  foreach(_zen_dataportal_imagenames() as $which_image) {
179
    zen_dataportal_form_widget_image_submit($form_state, $which_image);
180
  }
181

    
182
  // update logo information like wich one to use and size, this is needed to
183
  // offset the banner and menu bar
184
  $values = &$form_state['values'];
185
  if($values['default_logo']) {
186
    $logo_file = path_to_theme() . '/logo.png';
187
  } else {
188
    $logo_file = 'public://' . $values['logo_path'];
189
  }
190
  $logo_file_info = image_get_info($logo_file);
191
  if(isset($logo_file_info['width'])) {
192
   $values['logo_size'] = array('width' => $logo_file_info['width'], 'height' => $logo_file_info['height']);
193
  }
194

    
195
  /*
196
   * Ok, we are done here the $values will be saved in the theme
197
   * variable by system_theme_settings_submit($form, &$form_state)
198
   * in modules/system/system.admin.inc
199
   */
200
}
201

    
202
/**
203
 * Validator for the system_theme_settings() form.
204
 *  @param $form
205
 *   Nested array of form elements that comprise the form.
206
 * @param $form_state
207
 *   A keyed array containing the current state of the form.
208
 */
209
function zen_dataportal_theme_settings_validate($form, &$form_state) {
210

    
211
  foreach(_zen_dataportal_imagenames() as $which_image) {
212
    zen_dataportal_form_widget_image_validate($form_state, $which_image);
213
  }
214
}
215

    
216
/*******************************************************************
217
 *                    form widget functions
218
 *******************************************************************/
219

    
220
/**
221
 *
222
 * Enter description here ...
223
 *  @param $form
224
 *   Nested array of form elements that comprise the form.
225
 * @param unknown_type $which_image
226
 */
227
function zen_dataportal_form_widget_image(&$form, $which_image, $weight = NULL){
228
  $label = str_replace('_', ' ', $which_image);
229
  $form['zen_dataportal_' .  $which_image] = array(
230
          '#type' => 'fieldset',
231
          '#title' => ucfirst(t($label)) . ' ' . t('image settings'),
232
          '#description' => t('If toggled on, the following image will be displayed.'),
233
          '#attributes' => array('class' => array('theme-settings-bottom')),
234
  );
235
  if($weight){
236
    $form['zen_dataportal_' .  $which_image]['#weight'] = $weight;
237
  }
238
  $form['zen_dataportal_' .  $which_image]['default_' . $which_image] = array(
239
          '#type' => 'checkbox',
240
          '#title' => t('Use the default') . t($which_image),
241
          '#default_value' => theme_get_setting('default_' . $which_image),
242
          '#tree' => FALSE,
243
          '#description' => t('Check here if you want the theme to use the image supplied with it.')
244
  );
245
  $form['zen_dataportal_' .  $which_image]['settings'] = array(
246
          '#type' => 'container',
247
          '#states' => array(
248
            // Hide the logo settings when using the default logo.
249
            'invisible' => array(
250
              'input[name="default_' . $which_image . '"]' => array('checked' => TRUE),
251
            ),
252
          ),
253
  );
254

    
255

    
256
  // If $path is a public:// URI, display the path relative to the files
257
  // directory; stream wrappers are not end-user friendly.
258
  $path = theme_get_setting($which_image . '_path');
259
  $image = '';
260
  if (file_uri_scheme($path) == 'public') {
261
    $url = file_create_url($path);
262
    $path = file_uri_target($path);
263
    $form['zen_dataportal_' .  $which_image]['settings'][$which_image . '_preview'] = array(
264
            '#type' => 'item',
265
            '#title' => t('Preview'),
266
            '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
267
    );
268
  } // FIXME manully entered files without scheme public: are omitted here
269
  $form['zen_dataportal_' .  $which_image]['settings'][$which_image . '_path'] = array(
270
          '#type' => 'textfield',
271
          '#title' => t('Path to custom') . ' ' . t($label),
272
          '#description' => t('The path to the file you would like to use as your') . ' ' . t($label),
273
          '#default_value' => $path,
274
  );
275
  $form['zen_dataportal_' .  $which_image]['settings'][$which_image . '_upload'] = array(
276
          '#type' => 'file',
277
          '#title' => t('Upload') . ' ' . t($label) . t(' image'),
278
          '#maxlength' => 40,
279
          '#description' => t("If you don't have direct file access to the server, use this field to upload your image.")
280
  );
281
}
282

    
283
/**
284
 *
285
 * Enter description here ...
286
 * @param $color_settings_key
287
 *
288
 */
289
function zen_dataportal_form_widget_color(&$form, $color_settings_key, $description) {
290
  $label = str_replace('_', ' ', $color_settings_key);
291
  $form['zen_dataportal_colors'][$color_settings_key] = array(
292
          '#type'          => 'textfield',
293
          '#title'         => ucfirst(t($label)),
294
          '#default_value' => theme_get_setting($color_settings_key),
295
          '#description'   => $description, //t('Set the color of the site name which is shown in the header. Must be a css color value like: #000000'),
296
          '#attributes' => array(
297
            'class' => array('color-picker'),
298
            'size' => '7',
299
          ),
300
  );
301
}
302

    
303
/**
304
 *
305
 * Enter description here ...
306
 * @param $form_state
307
 *   A keyed array containing the current state of the form.
308
 * @param unknown_type $which_image
309
 */
310
function zen_dataportal_form_widget_image_submit(&$form_state, $which_image){
311
  // If the user uploaded a new image, save it to a permanent location
312
  // and use it in place of the default theme-provided file.
313
  $values = &$form_state['values'];
314
  if ($file = $values[$which_image . '_upload']) {
315
    unset($values[$which_image . '_upload']);
316
    $filename = file_unmanaged_copy($file->uri);
317
    $values['default_' .$which_image ] = 0;
318
    $values[$which_image . '_path'] = $filename;
319
    $values['toggle_' . $which_image] = 1;
320
  }
321
  if (!empty($values[$which_image . '_path'])) {
322
    $values[$which_image . '_path'] = _system_theme_settings_validate_path($values[$which_image . '_path']);
323
  }
324
}
325

    
326
/**
327
*
328
* Enter description here ...
329
 * @param $form_state
330
 *   A keyed array containing the current state of the form.
331
* @param unknown_type $which_image
332
*/
333
function zen_dataportal_form_widget_image_validate(&$form_state, $which_image){
334
  $validators = array('file_validate_is_image' => array('gif', 'jpg', 'png'));
335
  // Check for a new uploaded logo.
336
  $file = file_save_upload($which_image . '_upload', $validators);
337
  if (isset($file)) {
338
    // File upload was attempted.
339
    if ($file) {
340
      // Put the temporary file in form_values so we can save it on submit.
341
      $form_state['values'][$which_image . '_upload'] = $file;
342
    }
343
    else {
344
      // File upload failed.
345
      form_set_error($which_image . '_upload', t('The image could not be uploaded.'));
346
    }
347
  }
348
}
(13-13/14)