/** * Hex darker/lighter/contrast functions for colours * * @param mixed $color * @param int $factor (default: 30) * @return string */ function layers_hex_lighter($color, $factor = 30) { $base = layers_hex2rgb($color); $color = '#'; foreach ($base as $k => $v) { $amount = 255 - $v; $amount = $amount / 100; $amount = round($amount * $factor); $new_decimal = $v + $amount; $new_hex_component = dechex($new_decimal); if (strlen($new_hex_component) < 2) { $new_hex_component = "0" . $new_hex_component; } $color .= $new_hex_component; } return $color; }
function layers_inline_styles($arg1 = NULL, $arg2 = NULL, $arg3 = NULL) { if (3 == func_num_args()) { // layers_inline_styles( '#element', 'background', array( 'selectors' => '.element', 'background' => array( 'color' => '#FFF' ) ) ); $container_id = $arg1; $type = $arg2; $args = $arg3; } elseif (2 == func_num_args()) { // layers_inline_styles( '#element', array( 'selectors' => array( '.element' ), 'css' => array( 'color' => '#FFF' ) ) ); $container_id = $arg1; $type = 'css'; $args = $arg2; } elseif (1 == func_num_args()) { // layers_inline_styles( array( 'selectors' => array( '.element' ), 'css' => array( 'color' => '#FFF' ) ) ); // layers_inline_styles( '.element { color: #FFF; }' ); $container_id = ''; $type = 'css'; $args = $arg1; } // Get the generated CSS global $layers_inline_css; $css = ''; if (empty($args) || !is_array($args) && '' == $args) { return; } switch ($type) { case 'background': // Set the background array $bg_args = $args['background']; if (isset($bg_args['color']) && '' != $bg_args['color']) { $css .= 'background-color: ' . $bg_args['color'] . '; '; } if (isset($bg_args['repeat']) && '' != $bg_args['repeat']) { $css .= 'background-repeat: ' . $bg_args['repeat'] . ';'; } if (isset($bg_args['position']) && '' != $bg_args['position']) { $css .= 'background-position: ' . $bg_args['position'] . ';'; } if (isset($bg_args['stretch']) && '' != $bg_args['stretch']) { $css .= 'background-size: cover;'; } if (isset($bg_args['fixed']) && '' != $bg_args['fixed']) { $css .= 'background-attachment: fixed;'; } if (isset($bg_args['image']) && '' != $bg_args['image']) { $image = wp_get_attachment_image_src($bg_args['image'], 'full'); $css .= 'background-image: url(\'' . $image[0] . '\');'; } break; case 'button': // Set the background array $button_args = $args['button']; if (isset($button_args['background-color']) && '' != $button_args['background-color']) { $css .= 'background-color: ' . $button_args['background-color'] . '; '; } if (isset($button_args['color']) && '' != $button_args['color']) { $css .= 'color: ' . $button_args['color'] . '; '; } break; case 'margin': case 'padding': // Set the Margin or Padding array $trbl_args = $args[$type]; if (isset($trbl_args['top']) && '' != $trbl_args['top']) { $css .= $type . '-top: ' . $trbl_args['top'] . '; '; } if (isset($trbl_args['right']) && '' != $trbl_args['right']) { $css .= $type . '-right: ' . $trbl_args['right'] . '; '; } if (isset($trbl_args['bottom']) && '' != $trbl_args['bottom']) { $css .= $type . '-bottom: ' . $trbl_args['bottom'] . '; '; } if (isset($trbl_args['left']) && '' != $trbl_args['left']) { $css .= $type . '-left: ' . $trbl_args['left'] . '; '; } break; case 'border': // Set the background array $border_args = $args['border']; if (isset($border_args['color']) && '' != $border_args['color']) { $css .= 'border-color: ' . $border_args['color'] . ';'; } if (isset($border_args['width']) && '' != $border_args['width']) { $css .= 'border-width: ' . $border_args['width'] . 'px;'; } break; case 'color': if ('' == $args['color']) { return; } $css .= 'color: ' . $args['color'] . ';'; break; case 'font-family': if ('' == $args['font-family']) { return; } $css .= 'font-family: ' . $args['font-family'] . ', "Helvetica Neue", Helvetica, sans-serif;'; break; case 'text-shadow': if ('' == $args['text-shadow']) { return; } $css .= 'text-shadow: 0px 0px 10px rgba(' . implode(', ', layers_hex2rgb($args['text-shadow'])) . ', 0.75);'; break; case 'css': default: if (is_array($args)) { if (isset($args['css'])) { if (is_array($args['css'])) { foreach ($args['css'] as $css_atribute => $css_value) { $css .= "{$css_atribute}: {$css_value};"; } } else { $css .= $args['css']; } } } else { if (is_string($args)) { $css .= $args; } } break; } $css = apply_filters('layers_inline_' . $type . '_css', $css, $args); // Bail if no css is generated if ('' == trim($css)) { return false; } $inline_css = ''; // If there is a container ID specified, append it to the beginning of the declaration if (NULL != $container_id) { $inline_css = ' ' . $container_id . ' ' . $inline_css; } if (isset($args['selectors'])) { if (is_string($args['selectors']) && '' != $args['selectors']) { $inline_css .= $args['selectors']; } else { if (is_array($args['selectors']) && !empty($args['selectors'])) { $inline_css .= implode(', ' . $inline_css . ' ', $args['selectors']); } } } // Apply inline CSS if ('' == $inline_css) { $inline_css .= $css; } else { $inline_css .= '{ ' . $css . '} '; } // Add the new CSS to the existing CSS $layers_inline_css .= $inline_css; }
function layers_inline_styles($container_id = NULL, $type = 'background', $args = array()) { // Get the generated CSS global $layers_inline_css; $css = ''; if (empty($args) || !is_array($args) && '' == $args) { return; } switch ($type) { case 'background': // Set the background array $bg_args = $args['background']; if (isset($bg_args['color']) && '' != $bg_args['color']) { $css .= 'background-color: ' . $bg_args['color'] . '; '; } if (isset($bg_args['repeat']) && '' != $bg_args['repeat']) { $css .= 'background-repeat: ' . $bg_args['repeat'] . ';'; } if (isset($bg_args['position']) && '' != $bg_args['position']) { $css .= 'background-position: ' . $bg_args['position'] . ';'; } if (isset($bg_args['stretch']) && '' != $bg_args['stretch']) { $css .= 'background-size: cover;'; } if (isset($bg_args['fixed']) && '' != $bg_args['fixed']) { $css .= 'background-attachment: fixed;'; } if (isset($bg_args['image']) && '' != $bg_args['image']) { $image = wp_get_attachment_image_src($bg_args['image'], 'full'); $css .= 'background-image: url(\'' . $image[0] . '\');'; } break; case 'margin': case 'padding': // Set the Margin or Padding array $trbl_args = $args[$type]; if (isset($trbl_args['top']) && '' != $trbl_args['top']) { $css .= $type . '-top: ' . $trbl_args['top'] . '; '; } if (isset($trbl_args['right']) && '' != $trbl_args['right']) { $css .= $type . '-right: ' . $trbl_args['right'] . '; '; } if (isset($trbl_args['bottom']) && '' != $trbl_args['bottom']) { $css .= $type . '-bottom: ' . $trbl_args['bottom'] . '; '; } if (isset($trbl_args['left']) && '' != $trbl_args['left']) { $css .= $type . '-left: ' . $trbl_args['left'] . '; '; } break; case 'color': if ('' == $args['color']) { return; } $css .= 'color: ' . $args['color'] . ';'; break; case 'font-family': if ('' == $args['font-family']) { return; } $css .= 'font-family: ' . $args['font-family'] . ', "Helvetica Neue", Helvetica, sans-serif;'; break; case 'text-shadow': if ('' == $args['text-shadow']) { return; } $css .= 'text-shadow: 0px 0px 10px rgba(' . implode(', ', layers_hex2rgb($args['text-shadow'])) . ', 0.75);'; break; case 'css': $css .= $args['css']; break; default: $css .= $args['css']; break; } $inline_css = ''; // If there is a container ID specified, append it to the beginning of the declaration if (NULL != $container_id) { $inline_css = ' ' . $container_id . ' ' . $inline_css; } if (isset($args['selectors'])) { if (is_string($args['selectors']) && '' != $args['selectors']) { $inline_css .= $args['selectors']; } else { if (!empty($args['selectors'])) { $inline_css .= implode(', ' . $inline_css . ' ', $args['selectors']); } } } if ('' == $inline_css) { $inline_css .= $css; } else { $inline_css .= '{' . $css . '} '; } $layers_inline_css .= $inline_css; return apply_filters('layers_inline_css', $layers_inline_css); }