/**
 * Implementation of THEMEHOOK_settings() function.
 *
 * @param $saved_settings
 *   array An array of saved settings for this theme.
 * @return
 *   array A form array.
 */
function phptemplate_settings($saved_settings)
{
    // Empty the cached css...
    cache_clear_all('abessive_custom_css', 'cache');
    $form = array();
    require_once path_to_theme() . '/abessive_settings.php';
    // Add Farbtastic color picker
    drupal_add_css('misc/farbtastic/farbtastic.css', 'module', 'all', FALSE);
    drupal_add_js('misc/farbtastic/farbtastic.js');
    drupal_add_js(path_to_theme() . '/theme-settings.js');
    $defaults = _abessive_default_settings();
    $settings = array_merge($defaults, $saved_settings);
    $form['abessive_picker'] = array('#type' => 'markup', '#value' => '<div id="picker"></div>');
    $form['abessive_background_color'] = array('#type' => 'textfield', '#title' => t('Background Color'), '#description' => t('What colour should the body background behind all the containers be? Default: %val', array('%val' => $defaults['abessive_background_color'])), '#default_value' => $settings['abessive_background_color'], '#size' => 7, '#maxlength' => 7, '#prefix' => '<div class="container-inline">', '#suffix' => '</div>', '#attributes' => array('class' => 'form-item-use-colorpicker'), '#element_validate' => array('abessive_validate_hex_field'));
    $form['abessive_border_color'] = array('#type' => 'textfield', '#title' => t('Border Color'), '#description' => t('What colour should the border around all the containers be? Default: %val', array('%val' => $defaults['abessive_border_color'])), '#default_value' => $settings['abessive_border_color'], '#size' => 7, '#maxlength' => 7, '#prefix' => '<div class="container-inline">', '#suffix' => '</div>', '#attributes' => array('class' => 'form-item-use-colorpicker'), '#element_validate' => array('abessive_validate_hex_field'));
    $form['abessive_content_background_color'] = array('#type' => 'textfield', '#title' => t('Content Background Color'), '#description' => t('What colour should the background of all the containers be? Default: %val', array('%val' => $defaults['abessive_content_background_color'])), '#default_value' => $settings['abessive_content_background_color'], '#size' => 7, '#maxlength' => 7, '#prefix' => '<div class="container-inline">', '#suffix' => '</div>', '#attributes' => array('class' => 'form-item-use-colorpicker'), '#element_validate' => array('abessive_validate_hex_field', 'abessive_calculate_gradient'));
    $form['abessive_content_background_color']['abessive_r5'] = $form['abessive_content_background_color']['abessive_r4'] = $form['abessive_content_background_color']['abessive_r3'] = $form['abessive_content_background_color']['abessive_r2'] = array('#type' => 'value', '#default_value' => 0);
    $form['abessive_text_color'] = array('#type' => 'textfield', '#title' => t('Text Color'), '#description' => t('What colour should the text be? Default: %val', array('%val' => $defaults['abessive_text_color'])), '#default_value' => $settings['abessive_text_color'], '#size' => 7, '#maxlength' => 7, '#prefix' => '<div class="container-inline">', '#suffix' => '</div>', '#attributes' => array('class' => 'form-item-use-colorpicker'), '#element_validate' => array('abessive_validate_hex_field'));
    $form['abessive_link_color'] = array('#type' => 'textfield', '#title' => t('Hyperlink Color'), '#description' => t('What colour should hyperlinks be? Default: %val', array('%val' => $defaults['abessive_link_color'])), '#default_value' => $settings['abessive_link_color'], '#size' => 7, '#maxlength' => 7, '#prefix' => '<div class="container-inline">', '#suffix' => '</div>', '#attributes' => array('class' => 'form-item-use-colorpicker'), '#element_validate' => array('abessive_validate_hex_field'));
    $form['abessive_link_hover_color'] = array('#type' => 'textfield', '#title' => t('Hyperlink Hover Color'), '#description' => t('What colour should hyperlinks be when hovered over? Default: %val', array('%val' => $defaults['abessive_link_hover_color'])), '#default_value' => $settings['abessive_link_hover_color'], '#size' => 7, '#maxlength' => 7, '#prefix' => '<div class="container-inline">', '#suffix' => '</div>', '#attributes' => array('class' => 'form-item-use-colorpicker'), '#element_validate' => array('abessive_validate_hex_field'));
    $form['abessive_link_active_color'] = array('#type' => 'textfield', '#title' => t('Hyperlink Active Color'), '#description' => t('What colour should active hyperlinks be? Default: %val', array('%val' => $defaults['abessive_link_active_color'])), '#default_value' => $settings['abessive_link_active_color'], '#size' => 7, '#maxlength' => 7, '#prefix' => '<div class="container-inline">', '#suffix' => '</div>', '#attributes' => array('class' => 'form-item-use-colorpicker'), '#element_validate' => array('abessive_validate_hex_field'));
    $form['abessive_left_width'] = array('#type' => 'textfield', '#title' => t('Left Column Width'), '#description' => t('How wide should the left column be? Default: %val', array('%val' => $defaults['abessive_left_width'])), '#default_value' => $settings['abessive_left_width'], '#size' => 3, '#maxlength' => 3, '#prefix' => '<div class="container-inline">', '#suffix' => '</div>', '#field_suffix' => 'px', '#element_validate' => array('abessive_validate_numeric_field'));
    $form['abessive_right_width'] = array('#type' => 'textfield', '#title' => t('Right Column Width'), '#description' => t('How wide should the right column be? Default: %val', array('%val' => $defaults['abessive_right_width'])), '#default_value' => $settings['abessive_right_width'], '#size' => 3, '#maxlength' => 3, '#prefix' => '<div class="container-inline">', '#suffix' => '</div>', '#field_suffix' => 'px', '#element_validate' => array('abessive_validate_numeric_field'));
    $form['#submit'][] = 'abessive_submit_settings';
    return $form;
}
Beispiel #2
0
/**
 * Private function to modify the styles section of the page variables.
 */
function _abessive_custom_css_settings(&$styles)
{
    if ($css = cache_get('abessive_custom_css')) {
        $css = $css->data;
    } else {
        // Declare the $css variable to be added.
        $css = '';
        $left_width = $right_width = FALSE;
        // Get the default settings
        require_once path_to_theme() . '/abessive_settings.php';
        $defaults = _abessive_default_settings();
        // Loop over over all the default settings and try to get the cutom settings for it. If the custom settings differ to the default, append it onto the custom $css variable.
        foreach ($defaults as $key => $default_setting) {
            if (($custom_setting = theme_get_setting($key)) && $custom_setting != $default_setting) {
                switch ($key) {
                    case 'abessive_background_color':
                        $css .= 'body { background-color:' . $custom_setting . ';} ';
                        break;
                    case 'abessive_border_color':
                        $css .= '.block .content, #center .content, #header .content, #footer .content, div.r2, div.r3, div.r4, div.r5 { border-color:' . $custom_setting . ';} div.r1 { background-color:' . $custom_setting . ';} ';
                        break;
                    case 'abessive_content_background_color':
                        $css .= '.block .content, #center .content, #header .content, #footer .content { background-color:' . $custom_setting . '} ';
                        break;
                    case 'abessive_r2':
                        $css .= 'div.r2 { background-color:' . $custom_setting . '; }';
                        break;
                    case 'abessive_r3':
                        $css .= 'div.r3 { background-color:' . $custom_setting . '; }';
                        break;
                    case 'abessive_r4':
                        $css .= 'div.r4 { background-color:' . $custom_setting . '; }';
                        break;
                    case 'abessive_r5':
                        $css .= 'div.r5 { background-color:' . $custom_setting . '; }';
                        break;
                    case 'abessive_text_color':
                        $css .= 'body, p, td { color:' . $custom_setting . '} ';
                        break;
                    case 'abessive_link_color':
                        $css .= 'a:link, a:visited { color:' . $custom_setting . '} ';
                        break;
                    case 'abessive_link_hover_color':
                        $css .= 'a:hover { color:' . $custom_setting . '} ';
                        break;
                    case 'abessive_link_active_color':
                        $css .= 'a:active, a.active, li a.active { color:' . $custom_setting . '} ';
                        break;
                    case 'abessive_left_width':
                        $left_width = $custom_setting;
                        break;
                    case 'abessive_right_width':
                        $right_width = $custom_setting;
                        break;
                    default:
                        break;
                }
            }
        }
        // If Left or Right widths are not set, set them to default
        if (!$left_width) {
            $left_width = $defaults['abessive_left_width'];
        }
        if (!$right_width) {
            $right_width = $defaults['abessive_right_width'];
        }
        // For sanity, cast them to int's
        $left_width = (int) $left_width;
        $right_width = (int) $right_width;
        // Changed picks up what's changed.
        // 0 = default/no change, 1 = left changed, 2 = right changed, 3 = both changed
        $changed = 0;
        $changed += $left_width == $defaults['abessive_left_width'] ? 0 : 1;
        $changed += $right_width == $defaults['abessive_right_width'] ? 0 : 2;
        // CSS to apply if either cols have changed...
        if ($changed > 0) {
            $css .= 'body.sidebars { padding:0 ' . ($right_width + 20) . 'px 0 ' . ($left_width + 20) . 'px; } .sidebars #header, .sidebars #footer { margin-left:-' . ($left_width + 10) . 'px; margin-right:-' . ($right_width + 10) . 'px; } #left { width:' . $left_width . 'px; right:' . ($left_width + 20) . 'px; } #right { width:' . $right_width . 'px; margin-right:-' . ($right_width + 20) . 'px; } ';
        }
        // CSS to apply if left changed
        if ($changed & 1) {
            $css .= 'body.sidebar-left { padding:0  15px 0 ' . ($left_width + 20) . 'px; } .sidebar-left  #header, .sidebar-left  #footer { margin-left:-' . ($left_width + 10) . 'px; } ';
        }
        // CSS to apply if right changed
        if ($changed & 2) {
            $css .= 'body.sidebar-right { padding:0 ' . ($right_width + 20) . 'px 0  10px; } .sidebar-right #header, .sidebar-right #footer { margin-right:-' . ($right_width + 10) . 'px; } ';
        }
        cache_set('abessive_custom_css', $css);
    }
    // If $css isn't empty them we need to add a little inline CSS to the head.
    if (!empty($css)) {
        $styles .= "\n<style type=\"text/css\">{$css}</style>\n";
    }
}