/** * Shortcode callback function. * * @return string */ protected function do_shortcode() { extract($this->extract()); $content = preg_replace('#^<\\/p>|<p>$#', '', $content); // Compose final HTML id attribute $final_id = strlen($id) ? $id : 'g1-dropcap-' . $this->get_counter(); // Compose final HTML class attribute $final_class = array('g1-dropcap', 'g1-dropcap--' . $style); $final_class = array_merge($final_class, explode(' ', $class)); // Compose CSS $css = ''; if (strlen($text_color)) { $color = new G1_Color($text_color); $css .= '#' . esc_attr($final_id) . '.g1-dropcap--simple,' . "\n" . '#' . esc_attr($final_id) . '.g1-dropcap--solid {' . "\n" . 'color: #' . $color->get_hex() . ';' . "\n" . '}' . "\n"; } if (strlen($bg_color)) { $color = new G1_Color($bg_color); $hex = $color->get_hex(); list($from, $to) = G1_Color_Generator::get_warm_gradient($color); $from_hex = $from->get_hex(); $to_hex = $to->get_hex(); $css .= '#' . esc_attr($final_id) . '.g1-dropcap--solid {' . "\n" . 'background-color: #' . $hex . ';' . "\n" . '}' . "\n"; } //$css = str_replace(array("\n", "\r"), '', $css); // Compose output $out = ''; $out .= strlen($css) ? "\n" . '<style type="text/css">' . $css . '</style>' . "\n" : ''; $out .= '<span id="' . esc_attr($final_id) . '" '; $out .= 'class="' . sanitize_html_classes($final_class) . '" '; $out .= '><span>'; $out .= $content; $out .= '</span></span>'; return $out; }
/** * Generates color variations based on a single color * * @param $color * @return array */ public function get_color_variations($color) { $result = array(); $color = new G1_Color($color); $color_rgb = $color->get_rgb(); $color_rgb = array_map('round', $color_rgb); $result['hex'] = $color->get_hex(); $result['r'] = $color_rgb[0]; $result['g'] = $color_rgb[1]; $result['b'] = $color_rgb[2]; $result['from_hex'] = $color->get_hex(); $result['from_r'] = $color_rgb[0]; $result['from_g'] = $color_rgb[1]; $result['from_b'] = $color_rgb[2]; $result['to_hex'] = $color->get_hex(); $result['to_r'] = $color_rgb[0]; $result['to_g'] = $color_rgb[1]; $result['to_b'] = $color_rgb[2]; $border2 = G1_Color_Generator::get_tone_color($color, 20); $border2_rgb = $border2->get_rgb(); $border2_rgb = array_map('round', $border2_rgb); $border1 = clone $color; $border1->set_lightness(round(($border1->get_lightness() + $border2->get_lightness()) / 2)); $border1_rgb = $border1->get_rgb(); $border1_rgb = array_map('round', $border1_rgb); $result['border2_hex'] = $border2->get_hex(); $result['border2_r'] = $border2_rgb[0]; $result['border2_g'] = $border2_rgb[1]; $result['border2_b'] = $border2_rgb[2]; $result['border1_hex'] = $border1->get_hex(); $result['border1_r'] = $border1_rgb[0]; $result['border1_g'] = $border1_rgb[1]; $result['border1_b'] = $border1_rgb[2]; if ($color->get_lightness() >= 50) { $result['border1_start'] = 0; $result['border1_end'] = 0.66; } else { $result['border1_start'] = 0.66; $result['border1_end'] = 0; } $tone_20_20 = G1_Color_Generator::get_tone_color($color, 20, 20); $tone_20_20_rgb = $tone_20_20->get_rgb(); $tone_20_20_rgb = array_map('round', $tone_20_20_rgb); $result['tone_20_20_hex'] = $tone_20_20->get_hex(); $result['tone_20_20_r'] = $tone_20_20_rgb[0]; $result['tone_20_20_g'] = $tone_20_20_rgb[1]; $result['tone_20_20_b'] = $tone_20_20_rgb[2]; $tone_5_90 = G1_Color_Generator::get_tone_color($color, 5, 90); $tone_5_90_rgb = $tone_5_90->get_rgb(); $tone_5_90_rgb = array_map('round', $tone_5_90_rgb); $result['tone_5_90_hex'] = $tone_5_90->get_hex(); $result['tone_5_90_r'] = $tone_5_90_rgb[0]; $result['tone_5_90_g'] = $tone_5_90_rgb[1]; $result['tone_5_90_b'] = $tone_5_90_rgb[2]; return $result; }