-
-
Save dovy/8528233 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* The page core options for the Shoestrap theme | |
*/ | |
if ( !function_exists( 'shoestrap_module_coulourlovers_options' ) ) : | |
function shoestrap_module_coulourlovers_options( $sections ) { | |
// Page Options | |
$section = array( | |
'title' => __( 'ColourLovers', 'shoestrap' ), | |
'icon' => 'el-icon-file icon-large', | |
); | |
/** | |
This will calculate the values of many Bootstrap variables based on a 5-color palette. | |
- Background: The lightest and less intense color. | |
- Text: The darkest and less intense color. If the difference in brightess between the text and background is not big enough, then pick another color. | |
- Primary branding: The most intense color | |
- Navbar background: the 3rd color in intensity | |
- Navbar text: The color that has the most difference with the background in brightess. | |
**/ | |
$feed_xml = simplexml_load_file( 'http://www.colourlovers.com/api/palettes/top?numResults=100' ); | |
foreach($feed_xml->palette as $result) { | |
$id = $result->id; | |
$content = $result->content; | |
$title = $result->title; | |
$badgeurl = $result->badgeUrl; | |
$imageurl = $result->imageUrl; | |
$colors = array( | |
0 => $result->colors->hex[0], | |
1 => $result->colors->hex[1], | |
2 => $result->colors->hex[2], | |
3 => $result->colors->hex[3], | |
4 => $result->colors->hex[4] | |
); | |
// Get the ligtness of all the colors in our palette and arrange them according to it. | |
$colors_array_0b = $colors; | |
$brightest_0_key = shoestrap_brightest_color( $colors_array_0b, 'key' ); | |
$brightest_0_val = shoestrap_brightest_color( $colors_array_0b, 'value' ); | |
$colors_array_1b = shoestrap_array_delete( $brightest_0_key, $colors_array_0b ); | |
$brightest_1_key = shoestrap_brightest_color( $colors_array_1b, 'key' ); | |
$brightest_1_val = shoestrap_brightest_color( $colors_array_1b, 'value' ); | |
$colors_array_2b = shoestrap_array_delete( $brightest_1_key, $colors_array_1b ); | |
$brightest_2_key = shoestrap_brightest_color( $colors_array_2b, 'key' ); | |
$brightest_2_val = shoestrap_brightest_color( $colors_array_2b, 'value' ); | |
$colors_array_3b = shoestrap_array_delete( $brightest_2_key, $colors_array_2b ); | |
$brightest_3_key = shoestrap_brightest_color( $colors_array_3b, 'key' ); | |
$brightest_3_val = shoestrap_brightest_color( $colors_array_3b, 'value' ); | |
$colors_array_4b = shoestrap_array_delete( $brightest_3_key, $colors_array_3b ); | |
$brightest_4_key = shoestrap_brightest_color( $colors_array_4b, 'key' ); | |
$brightest_4_val = shoestrap_brightest_color( $colors_array_4b, 'value' ); | |
// Get the saturation of all the colors in our palette and arrange them according to it. | |
$colors_array_0s = $colors; | |
$most_saturated_0_key = shoestrap_most_saturated_color( $colors_array_0s, 'key' ); | |
$most_saturated_0_val = shoestrap_most_saturated_color( $colors_array_0s, 'value' ); | |
$colors_array_1s = shoestrap_array_delete( $most_saturated_0_key, $colors_array_0s ); | |
$most_saturated_1_key = shoestrap_most_saturated_color( $colors_array_1s, 'key' ); | |
$most_saturated_1_val = shoestrap_most_saturated_color( $colors_array_1s, 'value' ); | |
$colors_array_2s = shoestrap_array_delete( $most_saturated_1_key, $colors_array_1s ); | |
$most_saturated_2_key = shoestrap_most_saturated_color( $colors_array_2s, 'key' ); | |
$most_saturated_2_val = shoestrap_most_saturated_color( $colors_array_2s, 'value' ); | |
$colors_array_3s = shoestrap_array_delete( $most_saturated_2_key, $colors_array_2s ); | |
$most_saturated_3_key = shoestrap_most_saturated_color( $colors_array_3s, 'key' ); | |
$most_saturated_3_val = shoestrap_most_saturated_color( $colors_array_3s, 'value' ); | |
$colors_array_4s = shoestrap_array_delete( $most_saturated_3_key, $colors_array_3s ); | |
$most_saturated_3_key = shoestrap_most_saturated_color( $colors_array_4s, 'key' ); | |
$most_saturated_4_val = shoestrap_most_saturated_color( $colors_array_4s, 'value' ); | |
// Get the intensity of all the colors in our palette and arrange them according to it. | |
$colors_array_0i = $colors; | |
$most_intense_0_key = shoestrap_most_intense_color( $colors_array_0i, 'key' ); | |
$most_intense_0_val = shoestrap_most_intense_color( $colors_array_0i, 'value' ); | |
$colors_array_1i = shoestrap_array_delete( $most_intense_0_key, $colors_array_0i ); | |
$most_intense_1_key = shoestrap_most_intense_color( $colors_array_1i, 'key' ); | |
$most_intense_1_val = shoestrap_most_intense_color( $colors_array_1i, 'value' ); | |
$colors_array_2i = shoestrap_array_delete( $most_intense_1_key, $colors_array_1i ); | |
$most_intense_2_key = shoestrap_most_intense_color( $colors_array_2i, 'key' ); | |
$most_intense_2_val = shoestrap_most_intense_color( $colors_array_2i, 'value' ); | |
$colors_array_3i = shoestrap_array_delete( $most_intense_2_key, $colors_array_2i ); | |
$most_intense_3_key = shoestrap_most_intense_color( $colors_array_3i, 'key' ); | |
$most_intense_3_val = shoestrap_most_intense_color( $colors_array_3i, 'value' ); | |
$colors_array_4i = shoestrap_array_delete( $most_intense_3_key, $colors_array_3i ); | |
$most_intense_3_key = shoestrap_most_intense_color( $colors_array_4i, 'key' ); | |
$most_intense_4_val = shoestrap_most_intense_color( $colors_array_4i, 'value' ); | |
// Get the lightness and "dullness" of all the colors in our palette and arrange them according to it. | |
$colors_array_0d = $colors; | |
$bright_dull_0_key = shoestrap_brightest_dull_color( $colors_array_0d, 'key' ); | |
$bright_dull_0_val = shoestrap_brightest_dull_color( $colors_array_0d, 'value' ); | |
$colors_array_1d = shoestrap_array_delete( $bright_dull_0_key, $colors_array_0d ); | |
$bright_dull_1_key = shoestrap_brightest_dull_color( $colors_array_1d, 'key' ); | |
$bright_dull_1_val = shoestrap_brightest_dull_color( $colors_array_1d, 'value' ); | |
$colors_array_2d = shoestrap_array_delete( $bright_dull_1_key, $colors_array_1d ); | |
$bright_dull_2_key = shoestrap_brightest_dull_color( $colors_array_2d, 'key' ); | |
$bright_dull_2_val = shoestrap_brightest_dull_color( $colors_array_2d, 'value' ); | |
$colors_array_3d = shoestrap_array_delete( $bright_dull_2_key, $colors_array_2d ); | |
$bright_dull_3_key = shoestrap_brightest_dull_color( $colors_array_3d, 'key' ); | |
$bright_dull_3_val = shoestrap_brightest_dull_color( $colors_array_3d, 'value' ); | |
$colors_array_4d = shoestrap_array_delete( $bright_dull_3_key, $colors_array_3d ); | |
$bright_dull_3_key = shoestrap_brightest_dull_color( $colors_array_4d, 'key' ); | |
$bright_dull_4_val = shoestrap_brightest_dull_color( $colors_array_4d, 'value' ); | |
// The Background color. | |
// If all colors are dark-ish, then assume a dark palette and make background the darkest instead of the lightest color. | |
$background = $bright_dull_0_val; | |
// Only display suitable templates | |
$display = ( shoestrap_get_brightness( $bright_dull_0_val ) > 200 ) ? true : false; | |
if ( $display ) | |
$display = ( shoestrap_get_brightness( $bright_dull_4_val ) < 100 ) ? true : false; | |
// The text color | |
if ( shoestrap_get_brightness( $background ) - shoestrap_get_brightness( $brightest_4_val ) > 200 ) { | |
// If the brightest and darkest colors in the palette have a big difference, then use the darkest color as text. | |
$text_color = $brightest_4_val; | |
} else { | |
// Are all colors dark-ish? | |
// If they are, then use white text. | |
if ( shoestrap_get_brightness( $background ) < 100 ) { | |
$text_color = '#ffffff'; | |
} else { | |
if ( shoestrap_get_brightness( $background ) - shoestrap_get_brightness( '#222222' ) > 200 ) { | |
$text_color = '#222222'; | |
} else { | |
$text_color = '#000000'; | |
} | |
} | |
} | |
$defaults = array( | |
'font-family' => '', | |
'font-size' => '', | |
'color' => '', | |
'google' => '', | |
'font-weight' => '', | |
); | |
$font_base = shoestrap_process_font( shoestrap_getVariable( 'font_base', true ) ); | |
$font_base = wp_parse_args($defaults, $font_base); | |
if ( $display ) { | |
$preset_options[] = array( | |
'alt' => $title, | |
'img' => $imageurl, | |
'presets' => array( | |
'color_brand_primary' => '#' . str_replace( '#', '', $most_saturated_0_val ), | |
'color_brand_success' => '#' . str_replace( '#', '', $most_saturated_1_val ), | |
'color_brand_warning' => '#' . str_replace( '#', '', $most_saturated_2_val ), | |
'color_brand_danger' => '#' . str_replace( '#', '', $most_saturated_3_val ), | |
'color_brand_info' => '#' . str_replace( '#', '', $most_saturated_4_val ), | |
'navbar_bg' => '#' . str_replace( '#', '', $brightest_1_val ), | |
'html_color_bg' => '#' . str_replace( '#', '', $background ), | |
'color_body_bg' => '#' . str_replace( '#', '', $background ), | |
'font_base' => array( | |
'font-family' => $font_base['font-family'], | |
'font-size' => $font_base['font-size'], | |
'color' => '#222222', | |
'google' => $font_base['google'], | |
'font-weight' => $font_base['font-weight'], | |
), | |
) | |
); | |
} | |
} | |
$fields[] = array( | |
'id' =>'palette_presets', | |
'type' => 'image_select', | |
'presets' => true, | |
'title' => __('Preset', 'redux-framework'), | |
'subtitle'=> __('This allows you to set a json string or array to override multiple preferences in your theme.', 'redux-framework'), | |
'default' => 0, | |
'desc' => __('This allows you to set a json string or array to override multiple preferences in your theme.', 'redux-framework'), | |
'options' => $preset_options | |
); | |
$section['fields'] = $fields; | |
$section = apply_filters( 'shoestrap_module_coulourlovers_options_modifier', $section ); | |
$sections[] = $section; | |
return $sections; | |
} | |
endif; | |
add_filter( 'redux/options/'.REDUX_OPT_NAME.'/sections', 'shoestrap_module_coulourlovers_options', 76 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment