Ejemplo n.º 1
0
function enlightenment_print_font_options($selector, $option, $echo = true)
{
    $defaults = enlightenment_default_theme_options();
    $fonts = enlightenment_available_fonts();
    $family = enlightenment_theme_option($option . '_font_family');
    $size = enlightenment_theme_option($option . '_font_size');
    $variant = enlightenment_theme_option($option . '_font_style');
    $color = enlightenment_theme_option($option . '_font_color');
    $output = '';
    if ($family != $defaults[$option . '_font_family'] || $size != $defaults[$option . '_font_size'] || $variant != $defaults[$option . '_font_style'] || $color != $defaults[$option . '_font_color']) {
        $output .= "{$selector} {\n";
        if ($family != $defaults[$option . '_font_family']) {
            $output .= sprintf("\tfont-family: %1s, %2s;\n", $fonts[$family]['family'], $fonts[$family]['category']);
        }
        if ($size != $defaults[$option . '_font_size']) {
            $output .= sprintf("\tfont-size: %1s%2s;\n", $size, apply_filters('enlightenment_font_size_unit', 'px'));
        }
        if ($variant != $defaults[$option . '_font_style']) {
            if (false !== strpos($variant, 'italic')) {
                $output .= "\tfont-style: italic;\n";
            } else {
                $output .= "\tfont-style: normal;\n";
            }
            switch ($variant) {
                case '300':
                case '300italic':
                    $output .= "\tfont-weight: 300;\n";
                    break;
                case '400':
                case 'italic':
                    $output .= "\tfont-weight: 400;\n";
                    break;
                case '500':
                case '500italic':
                    $output .= "\tfont-weight: 500;\n";
                    break;
                case '600':
                case '600italic':
                    $output .= "\tfont-weight: 600;\n";
                    break;
                case '700':
                case '700italic':
                    $output .= "\tfont-weight: 700;\n";
                    break;
            }
        }
        if ($color != $defaults[$option . '_font_color']) {
            $output .= "\tcolor: {$color};\n";
        }
        $output .= "}\n";
    }
    $output = apply_filters('enlightenment_print_font_options', $output);
    if (!$echo) {
        return $output;
    }
    echo $output;
}
Ejemplo n.º 2
0
function enlightenment_font_options($args, $echo = true)
{
    $defaults = array('class' => '', 'id' => '', 'description' => '');
    $args = wp_parse_args($args, $defaults);
    if (!isset($args['name']) || empty($args['name'])) {
        _doing_it_wrong(__FUNCTION__, __('Please specify a name attribute for your font options.', 'enlightenment'), '');
        return;
    }
    $fonts = enlightenment_available_fonts();
    $font_family_args = array('name' => $args['name'] . '_font_family', 'class' => 'font_family' . (!empty($args['class']) ? ' ' . $args['class'] . '_font_family' : ''), 'id' => !empty($args['id']) ? $args['id'] . '_font_family' : '', 'options' => array());
    foreach ($fonts as $name => $font) {
        // $font_family_args['options'][$name] = ( isset( $font['family'] ) ? str_replace( '"', '', $font['family'] ) : $name ) . ', ' . $font['category'];
        $font_family_args['options'][$name] = str_replace('"', '', $font['family']) . ', ' . $font['category'];
    }
    $font_size_args = array('name' => $args['name'] . '_font_size', 'class' => 'font_size' . (!empty($args['class']) ? ' ' . $args['class'] . '_font_size' : ''), 'id' => !empty($args['id']) ? $args['id'] . '_font_size' : '', 'options' => array());
    $min_font_size = apply_filters('enlightenment_min_font_size', 10);
    $max_font_size = apply_filters('enlightenment_max_font_size', 48);
    $font_size_inc = apply_filters('enlightenment_font_size_inc', 1);
    $font_size_unit = apply_filters('enlightenment_font_size_unit', 'px');
    for ($i = $min_font_size; $i <= $max_font_size; $i = $i + $font_size_inc) {
        $font_size_args['options'][$i] = intval($i) . ' ' . esc_attr($font_size_unit);
    }
    $font_style_args = array('name' => $args['name'] . '_font_style', 'class' => 'font_style' . (!empty($args['class']) ? ' ' . $args['class'] . '_font_style' : ''), 'id' => !empty($args['id']) ? $args['id'] . '_font_style' : '', 'options' => enlightenment_font_styles());
    $color_picker_args = array('name' => $args['name'] . '_font_color', 'class' => 'font_color' . (!empty($args['class']) ? ' ' . $args['class'] . '_font_color' : ''), 'id' => !empty($args['id']) ? $args['id'] . '_font_color' : '');
    $output = enlightenment_open_tag('fieldset', 'font-options');
    $output .= enlightenment_select_box($font_family_args, false);
    $output .= enlightenment_select_box($font_size_args, false);
    $output .= enlightenment_select_box($font_style_args, false);
    $output .= enlightenment_color_picker($color_picker_args, false);
    $output .= enlightenment_close_tag('fieldset');
    $output .= empty($args['description']) ? '' : '<p class="description">' . strip_tags($args['description'], '<a><abbr><img>') . '</p>';
    $output = apply_filters('enlightenment_font_options', $output, $args);
    if (!$echo) {
        return $output;
    }
    echo $output;
}
Ejemplo n.º 3
0
function enlightenment_validate_font_family($input, $default = false)
{
    if (array_key_exists($input, enlightenment_available_fonts())) {
        return $input;
    }
    return $default;
}