diff --git a/modules/system.module b/modules/system.module index 0ea7f9c8c32a9c8233756c5e4391dfa29fb5602b..662a6cd7f584a960bd10d423a93b77c16afe89b1 100644 --- a/modules/system.module +++ b/modules/system.module @@ -167,32 +167,9 @@ function system_test_clean_url($form_id) { * Allows users to individually set their theme and time zone. */ function system_user($type, $edit, &$user, $category = NULL) { - if ($type == 'form' && $category == 'account') { - if (user_access('select different theme')) { - $themes = array_filter(list_themes(), create_function('$theme', 'return $theme->status;')); - - if (count($themes) > 1) { - ksort($themes); - - $form['themes'] = array( - '#type' => 'fieldset', '#title' => t('Theme configuration'), '#description' => t('Selecting a different theme will change the look and feel of the site.'), '#weight' => 2, '#collapsible' => TRUE, '#theme' => 'system_user'); - - foreach ($themes as $info) { - // For the default theme, revert to an empty string so the user's theme updates when the site theme is changed. - $info->key = $info->name == variable_get('theme_default', 'bluemarine') ? '' : $info->name; - - $info->screenshot = dirname($info->filename) . '/screenshot.png'; - $screenshot = file_exists($info->screenshot) ? theme('image', $info->screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), false) : t('no screenshot'); - - $form['themes'][$info->key]['screenshot'] = array('#type' => 'markup', '#value' => $screenshot); - $form['themes'][$info->key]['description'] = array('#type' => 'item', '#title' => $info->name, '#value' => dirname($info->filename) . ($info->name == variable_get('theme_default', 'bluemarine') ? t('<br /> <em>(site default theme)</em>') : '')); - $options[$info->key] = ''; - } - - $form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $edit['theme'] ? $edit['theme'] : ''); - } - } - + if ($type == 'form' && $category == 'account') { + $form['theme_select'] = system_theme_select_form(t('Selecting a different theme will change the look and feel of the site.'), $edit['theme'], 2); + if (variable_get('configurable_timezones', 1)) { $zones = _system_zonelist(); $form['timezone'] = array('#type'=>'fieldset', '#title' => t('Locale settings'), '#weight' => 6); @@ -201,11 +178,62 @@ function system_user($type, $edit, &$user, $category = NULL) { '#options' => $zones, '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.') ); } + return $form; } } -function theme_system_user($form) { +/* + * Returns a fieldset containing the theme select form. + * + * @param $description + * description of the fieldset + * @param $default_value + * default value of theme radios + * @param $weight + * weight of the fieldset + * @return + * a form array + */ +function system_theme_select_form($description = '', $default_value = '', $weight = 0) { + if (user_access('select different theme')) { + foreach (list_themes() as $theme) { + if ($theme->status) { + $enabled[] = $theme; + } + } + + if (count($enabled) > 1) { + ksort($enabled); + + $form['themes'] = array( + '#type' => 'fieldset', + '#title' => t('Theme configuration'), + '#description' => $description, + '#collapsible' => TRUE, + '#theme' => 'system_theme_select_form' + ); + + foreach ($enabled as $info) { + // For the default theme, revert to an empty string so the user's theme updates when the site theme is changed. + $info->key = $info->name == variable_get('theme_default', 'bluemarine') ? '' : $info->name; + + $info->screenshot = dirname($info->filename) . '/screenshot.png'; + $screenshot = file_exists($info->screenshot) ? theme('image', $info->screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), false) : t('no screenshot'); + + $form['themes'][$info->key]['screenshot'] = array('#type' => 'markup', '#value' => $screenshot); + $form['themes'][$info->key]['description'] = array('#type' => 'item', '#title' => $info->name, '#value' => dirname($info->filename) . ($info->name == variable_get('theme_default', 'bluemarine') ? t('<br /> <em>(site default theme)</em>') : '')); + $options[$info->key] = ''; + } + + $form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $default_value ? $default_value : ''); + $form['#weight'] = $weight; + return $form; + } + } +} + +function theme_system_theme_select_form($form) { foreach (element_children($form) as $key) { $row = array(); if (is_array($form[$key]['description'])) { diff --git a/modules/system/system.module b/modules/system/system.module index 0ea7f9c8c32a9c8233756c5e4391dfa29fb5602b..662a6cd7f584a960bd10d423a93b77c16afe89b1 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -167,32 +167,9 @@ function system_test_clean_url($form_id) { * Allows users to individually set their theme and time zone. */ function system_user($type, $edit, &$user, $category = NULL) { - if ($type == 'form' && $category == 'account') { - if (user_access('select different theme')) { - $themes = array_filter(list_themes(), create_function('$theme', 'return $theme->status;')); - - if (count($themes) > 1) { - ksort($themes); - - $form['themes'] = array( - '#type' => 'fieldset', '#title' => t('Theme configuration'), '#description' => t('Selecting a different theme will change the look and feel of the site.'), '#weight' => 2, '#collapsible' => TRUE, '#theme' => 'system_user'); - - foreach ($themes as $info) { - // For the default theme, revert to an empty string so the user's theme updates when the site theme is changed. - $info->key = $info->name == variable_get('theme_default', 'bluemarine') ? '' : $info->name; - - $info->screenshot = dirname($info->filename) . '/screenshot.png'; - $screenshot = file_exists($info->screenshot) ? theme('image', $info->screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), false) : t('no screenshot'); - - $form['themes'][$info->key]['screenshot'] = array('#type' => 'markup', '#value' => $screenshot); - $form['themes'][$info->key]['description'] = array('#type' => 'item', '#title' => $info->name, '#value' => dirname($info->filename) . ($info->name == variable_get('theme_default', 'bluemarine') ? t('<br /> <em>(site default theme)</em>') : '')); - $options[$info->key] = ''; - } - - $form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $edit['theme'] ? $edit['theme'] : ''); - } - } - + if ($type == 'form' && $category == 'account') { + $form['theme_select'] = system_theme_select_form(t('Selecting a different theme will change the look and feel of the site.'), $edit['theme'], 2); + if (variable_get('configurable_timezones', 1)) { $zones = _system_zonelist(); $form['timezone'] = array('#type'=>'fieldset', '#title' => t('Locale settings'), '#weight' => 6); @@ -201,11 +178,62 @@ function system_user($type, $edit, &$user, $category = NULL) { '#options' => $zones, '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.') ); } + return $form; } } -function theme_system_user($form) { +/* + * Returns a fieldset containing the theme select form. + * + * @param $description + * description of the fieldset + * @param $default_value + * default value of theme radios + * @param $weight + * weight of the fieldset + * @return + * a form array + */ +function system_theme_select_form($description = '', $default_value = '', $weight = 0) { + if (user_access('select different theme')) { + foreach (list_themes() as $theme) { + if ($theme->status) { + $enabled[] = $theme; + } + } + + if (count($enabled) > 1) { + ksort($enabled); + + $form['themes'] = array( + '#type' => 'fieldset', + '#title' => t('Theme configuration'), + '#description' => $description, + '#collapsible' => TRUE, + '#theme' => 'system_theme_select_form' + ); + + foreach ($enabled as $info) { + // For the default theme, revert to an empty string so the user's theme updates when the site theme is changed. + $info->key = $info->name == variable_get('theme_default', 'bluemarine') ? '' : $info->name; + + $info->screenshot = dirname($info->filename) . '/screenshot.png'; + $screenshot = file_exists($info->screenshot) ? theme('image', $info->screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), false) : t('no screenshot'); + + $form['themes'][$info->key]['screenshot'] = array('#type' => 'markup', '#value' => $screenshot); + $form['themes'][$info->key]['description'] = array('#type' => 'item', '#title' => $info->name, '#value' => dirname($info->filename) . ($info->name == variable_get('theme_default', 'bluemarine') ? t('<br /> <em>(site default theme)</em>') : '')); + $options[$info->key] = ''; + } + + $form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $default_value ? $default_value : ''); + $form['#weight'] = $weight; + return $form; + } + } +} + +function theme_system_theme_select_form($form) { foreach (element_children($form) as $key) { $row = array(); if (is_array($form[$key]['description'])) {