public static function get_tone_color(G1_Color $color, $delta = 10, $breakpoint = 50) { $out = clone $color; $lightness = $color->get_lightness(); if ($lightness <= $breakpoint) { $lightness += $lightness + $delta > 100 ? -$delta : $delta; } else { $lightness -= $lightness + $delta < 0 ? -$delta : $delta; } $out->set_lightness($lightness); return $out; }
/** * Shortcode callback function. * * @return string */ protected function do_shortcode() { extract($this->extract()); $step = 1; $delay = 0; $duration = 1500; // Compose final HTML id attribute $final_id = strlen($id) ? $id : 'duplicator-counter-' . $this->get_counter(); // Compose final HTML class attribute $final_class = array('g1-duplicator', 'g1-duplicator--' . $style, 'g1-duplicator--' . $direction); $final_class = array_merge($final_class, explode(' ', $class)); // Compose custom CSS rules $css = ''; if (strlen($color)) { $color = new G1_Color($color); $css .= '#' . esc_attr($final_id) . '.g1-duplicator .g1-duplicate--active i { color:#' . $color->get_hex() . '; }'; } $css = strlen($css) ? "\n" . '<style type="text/css" scoped="scoped">' . $css . '</style>' . "\n" : ''; $content = '<i class="icon-' . sanitize_html_class($icon) . '"></i>'; // Compose the template $data = array('data-g1-start="%start%"', 'data-g1-stop="%stop%"', 'data-g1-max="%max%"', 'data-g1-step="%step%"'); if (strlen($delay)) { $data[] = 'data-g1-delay="' . esc_attr($delay) . '"'; } $out = '%CSS%<span id="%id%" class="%class%" ' . implode(' ', $data) . '>%content%</span>'; // Fill in the template $out = str_replace(array('%CSS%', '%id%', '%class%', '%start%', '%stop%', '%max%', '%step%', '%duration%', '%content%'), array($css, esc_attr($final_id), sanitize_html_classes($final_class), esc_attr($start), esc_attr($stop), esc_attr($max), esc_attr($step), esc_attr($duration), do_shortcode(shortcode_unautop($content))), $out); return $out; }
/** * shortcode callback function. * * @param array $atts * @param string $content * @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-section-' . $this->get_counter(); // Compose final HTML class attribute $final_class = array('g1-section'); if ('standard' === $background_scroll) { $final_class[] = 'g1-section--scroll'; } $final_class = array_merge($final_class, explode(' ', $class)); // Compose custom CSS rules $css = ''; $css_rules = array(); if (strlen($background_color)) { $color = new G1_Color($background_color); $css_rules[] = 'background-color: #' . $color->get_hex() . ';'; } if (strlen($background_image)) { $css_rules[] = 'background-image:url(' . esc_url($background_image) . ');'; } if (strlen($background_repeat)) { $background_repeat = preg_replace('/[^a-zA-Z -]*/', '', $background_repeat); $css_rules[] = 'background-repeat:' . $background_repeat . ';'; } if (strlen($background_position)) { $background_position = preg_replace('/[^a-zA-Z -]*/', '', $background_position); $css_rules[] = 'background-position:' . $background_position . ';'; } if (strlen($background_attachment)) { $background_position = preg_replace('/[^a-zA-Z -]*/', '', $background_attachment); $css_rules[] = 'background-attachment:' . $background_attachment . ';'; } if (strlen($border_size)) { $css_rules[] = 'border-width:' . absint($border_size) . 'px 0;'; } if (strlen($padding_bottom)) { $css_rules[] = 'padding-bottom:' . absint($padding_bottom) . 'px;'; } if (strlen($padding_top)) { $css_rules[] = 'padding-top:' . absint($padding_top) . 'px;'; } if (count($css_rules)) { $css = '<style type="text/css" scoped="scoped">' . '#' . esc_attr($final_id) . '.g1-section {' . implode(' ', $css_rules) . '}' . '</style>'; } // Compose output $out = '%css%' . '<div id="%id%" class="%class%">' . '<div class="g1-layout-inner">' . '%content%' . '</div>' . '</div>'; $out = str_replace(array('%css%', '%id%', '%class%', '%content%'), array($css, esc_attr($final_id), sanitize_html_classes($final_class), do_shortcode(shortcode_unautop($content))), $out); return $out; }
/** * Shortcode callback function. * * @return string */ protected function do_shortcode() { extract($this->extract()); // Compose final HTML id attribute $final_id = strlen($id) ? $id : 'g1-gmap-counter-' . $this->get_counter(); // Compose final HTML class attribute $final_class = array('g1-gmap'); add_action('wp_footer', array($this, 'enqueue_scripts')); if (!$width) { $width = '100%'; } if (!$height) { return ''; } $inline_style = ' style="width: ' . esc_attr($width) . '; height: ' . esc_attr($height) . ';"'; $config = array('map_type' => !empty($map_type) ? $map_type : 'roadmap', 'invert_lightness' => $invert_lightness, 'latitude' => $latitude, 'longitude' => $longitude, 'zoom' => !empty($zoom) ? $zoom : 15, 'marker' => !empty($marker) ? $marker : 'none', 'marker_icon' => !empty($marker_icon) ? $marker_icon : '', 'type' => $type); if (!empty($color)) { $colorObj = new G1_Color($color); $colorConfig = array('color' => $color, 'color_hue' => '#' . $colorObj->get_hex(), 'color_saturation' => ($colorObj->get_saturation() - 50) * 2, 'color_lightness' => ($colorObj->get_lightness() - 50) * 2); $config = array_merge($config, $colorConfig); } $data_attr = ' data-g1-gmap-config="' . g1_data_capture($config) . '"'; // Compose output $out = '<div class="g1-gmap-wrapper">' . "\n"; $out .= '<div id="' . esc_attr($final_id) . '" class="' . sanitize_html_classes($final_class) . '"' . $data_attr . $inline_style . '>' . "\n"; $out .= '<div class="g1-gmap-content" style="display: none;">'; $out .= $content; $out .= '</div>'; $out .= '</div>'; $out .= '</div>' . "\n"; 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; }
/** * Shortcode callback function. * * @return string */ protected function do_shortcode() { extract($this->extract()); $value = absint($value); if ($value < 0) { $value = 0; } if ($value > 100) { $value = 100; } $final_id = strlen($id) ? $id : 'g1-progress-bar-' . $this->get_counter(); $final_class = array('g1-progress-bar', 'g1-progress-bar--' . $style, 'g1-progress-bar--' . $size, 'g1-progress-bar--' . $direction); $final_class = array_merge($final_class, explode(' ', $class)); $css_rules = array(); /* Compose CSS */ if (strlen($text_color)) { $color = new G1_Color($text_color); $css_rules[] = 'color: #' . $color->get_hex() . ';'; } if (strlen($bg_color)) { $color = new G1_Color($bg_color); $css_rules[] = 'background-color: #' . $color->get_hex() . ';'; $css_rules[] = 'border-color: #' . $color->get_hex() . ';'; } $css = ''; if (count($css_rules)) { $css = '<style type="text/css" scoped="scoped">' . '#' . esc_attr($final_id) . '.g1-progress-bar .g1-progress-bar__bar {' . implode(' ', $css_rules) . '}' . '</style>' . "\n"; } /* Compose icon */ if (strlen($icon)) { $icon = '<i class="icon-' . sanitize_html_class($icon) . ' g1-progress-bar__icon"></i>'; $final_class[] = 'g1-progress-bar--icon'; } else { $final_class[] = 'g1-progress-bar--noicon'; } /* Compose label */ if (strlen($content)) { $content = '<div class="g1-progress-bar__label">' . $content . '</div>'; } /* Compose output */ $out = '%css%' . '<div id="%id%" class="%class%">' . '%content%' . '<div class="g1-progress-bar__track">' . '<div class="g1-progress-bar__bar" style="width:%value%%;">' . '<span>%value%</span>' . '%icon%' . '</div>' . '</div>' . '</div>'; $out = str_replace(array('%css%', '%id%', '%class%', '%content%', '%value%', '%icon%'), array($css, esc_attr($final_id), sanitize_html_classes($final_class), $content, $value, $icon), $out); return $out; }
public function g1_gmaps_plugin_activate() { $migrated_map_id = get_option('g1_gmaps_migrated_map_id', false); if ($migrated_map_id) { return; } $options = get_option(G1_Theme()->get_id()); $color = $options['map_color']; // hex or empty string $invert_lightness = $options['map_invert_lightness'] === '1'; // bool $type = $options['map_type']; // roadmap | satellite | hybrid | terrain $center_lat = $options['map_latitude']; $center_long = $options['map_longitude']; $zoom = (int) $options['map_zoom']; // int $marker = $options['map_marker']; // none | standard | open-bubble $marker_icon = $options['map_marker_icon']; // image path $marker_content = $options['map_marker_content']; $marker_icon_id = null; if ($marker_icon) { $marker_icon_id = $this->get_image_id($marker_icon); } // create new map $defaults = G1_GMaps()->get_default_map_config(); $config = array('width' => '', 'height' => '380', 'full_width' => 'standard', 'parallax' => 'standard', 'street_view_control' => 'none', 'overview_control' => 'none', 'scroll_wheel_to_zoom' => 'none', 'double_click_to_zoom' => 'standard', 'draggable' => 'standard', 'type_control' => 'horizontal', 'pan_control' => 'standard', 'scale_control' => 'none', 'zoom_control' => 'small'); if ($center_lat) { $config['lat'] = $center_lat; } if ($center_long) { $config['long'] = $center_long; } if ($zoom) { $config['zoom'] = $zoom; } if ($type) { $config['type'] = $type; } if ($invert_lightness) { $config['invert_lightness'] = 'standard'; } if ($color) { $c = new G1_Color($color); $config['color_hue'] = $c->get_hue(); $config['color_saturation'] = $c->get_saturation() * 2 - 100; $config['color_lightness'] = $c->get_lightness() * 2 - 100; $config['custom_colors'] = 'standard'; } else { $config['custom_colors'] = 'none'; } $config = wp_parse_args($config, $defaults); $post = array('post_title' => 'Old map', 'post_status' => 'publish', 'post_type' => G1_GMaps()->get_post_type()); $post_id = wp_insert_post($post); if ($post_id > 0) { $data_to_save = array(); foreach ($config as $option_name => $option_value) { $data_to_save['map_' . $option_name] = $option_value; } update_post_meta($post_id, '_g1_gmap_lat', $data_to_save['map_lat']); update_post_meta($post_id, '_g1_gmap_long', $data_to_save['map_long']); update_post_meta($post_id, '_g1_gmap', $data_to_save); // create marker if ($marker !== 'none') { $marker_id = wp_insert_post(array('post_status' => 'publish', 'post_type' => G1_GMaps()->get_map_marker_post_type())); if ($marker_id > 0) { $marker_data_to_save = G1_GMaps()->get_default_map_marker_config(); $marker_data_to_save['lat'] = $data_to_save['map_lat']; $marker_data_to_save['long'] = $data_to_save['map_long']; $marker_data_to_save['label'] = 'Marker'; if ($marker_icon_id) { $marker_data_to_save['icon_id'] = $marker_icon_id; $marker_data_to_save['icon_path'] = $marker_icon; } $marker_data_to_save['info'] = $marker_content; $marker_data_to_save['info_state'] = $marker === 'open-bubble' ? 'standard' : 'none'; $marker_data_to_save['visibility'] = 'standard'; update_post_meta($marker_id, '_g1_gmap_id', $post_id); update_post_meta($marker_id, '_g1_gmap_marker_lat', $marker_data_to_save['lat']); update_post_meta($marker_id, '_g1_gmap_marker_long', $marker_data_to_save['long']); update_post_meta($marker_id, '_g1_gmap_marker', $marker_data_to_save); } } update_option('g1_gmaps_migrated_map_id', $post_id); $global_map_enabled = $options['ta_prefooter_gmap'] === 'standard'; // if map was enabled, we need to set it to new created map if ($global_map_enabled) { $options['ta_prefooter_gmap'] = $post_id; update_option(G1_Theme()->get_id(), $options); } } }