/** * Description here. * */ function dt_stylesheet_color_hex2rgba($color, $opacity = 0) { if (!$color) { return ''; } $rgb_array = dt_stylesheet_color_hex2rgb($color, true); return sprintf('rgba(%d,%d,%d,%s)', $rgb_array[0], $rgb_array[1], $rgb_array[2], dt_stylesheet_get_opacity($opacity)); }
protected function get_inner_inline_style() { $banner_inner_style = array(); if ($this->atts['bg_color']) { if (false !== strpos($this->atts['bg_color'], 'rgba')) { $ie_color = dt_stylesheet_color_rgba2rgb($this->atts['bg_color']); } else { $ie_color = dt_stylesheet_color_hex2rgb($this->atts['bg_color']); } $banner_inner_style[] = 'background-color: ' . $ie_color; $banner_inner_style[] = 'background-color: ' . $this->atts['bg_color']; } $banner_inner_style[] = sprintf('border: solid %spx transparent', $this->atts['inner_padding']); $banner_inner_style[] = sprintf('outline: solid %spx', $this->atts['border_width']); if ($this->atts['text_color']) { $banner_inner_style[] = 'outline-color: ' . $this->atts['text_color']; } $banner_inner_height = $this->atts['min_height'] - $this->atts['inner_padding']; $banner_inner_style[] = 'height: ' . $banner_inner_height . 'px'; return 'style="' . esc_attr(implode(';', $banner_inner_style)) . '"'; }
/** * Compile less vars from theme options. * */ function presscore_compile_less_vars() { if (!class_exists('WPLessPlugin')) { return array(); } // $less = WPLessPlugin::getInstance(); $image_defaults = array('image' => '', 'repeat' => 'repeat', 'position_x' => 'center', 'position_y' => 'center'); $font_family_falloff = ', Helvetica, Arial, Verdana, sans-serif'; $font_family_defaults = array('family' => 'Open Sans'); $relative_base = '../../..'; do_action('presscore_before_compile_less_vars'); // main array $options = array(); $options_inteface = apply_filters('presscore_less_options_interface', array()); //---------------------------------------------------------------------------------------------------------------- // Process options //---------------------------------------------------------------------------------------------------------------- if ($options_inteface) { foreach ($options_inteface as $data) { if (empty($data) || empty($data['type']) || empty($data['less_vars']) || empty($data['php_vars'])) { continue; } $type = $data['type']; $less_vars = $data['less_vars']; $php_vars = $data['php_vars']; $wrap = isset($data['wrap']) ? $data['wrap'] : false; $interface = isset($data['interface']) ? $data['interface'] : false; extract($php_vars); switch ($type) { case 'rgba_color': if (isset($ie_color, $less_vars[1])) { $ie_color = of_get_option($ie_color[0], $ie_color[1]); } else { $ie_color = false; } $color_option = of_get_option($color[0], $color[1]); $opacity_option = of_get_option($opacity[0], $opacity[1]); if (!$color_option) { $color_option = $color[1]; } $computed_color = dt_stylesheet_make_ie_compat_rgba($color_option, $ie_color, $opacity_option); $options[current($less_vars)] = $computed_color['rgba']; if ($ie_color) { if (!empty($ie_color[2]) && function_exists($ie_color[2])) { $computed_color['ie_color'] = call_user_func($ie_color[2], $computed_color['ie_color']); } if (empty($computed_color['ie_color'])) { $computed_color['ie_color'] = '~"transparent"'; } $options[next($less_vars)] = $computed_color['ie_color']; } break; case 'rgb_color': $color_option = of_get_option($color[0], $color[1]); $computed_color = dt_stylesheet_color_hex2rgb($color_option ? $color_option : $color[1]); if ($computed_color && false !== $wrap) { if (is_array($wrap)) { $computed_color = current($wrap) . $computed_color . next($wrap); } else { $computed_color = $wrap . $computed_color . $wrap; } } $options[current($less_vars)] = $computed_color; break; case 'hex_color': $computed_color = of_get_option($color[0], $color[1]); if (!$computed_color) { $computed_color = $color[1]; } $options[current($less_vars)] = $computed_color; break; case 'image': if (!isset($image)) { break; } $computed_image = of_get_option($image[0], $image[1]); $computed_image['image'] = dt_stylesheet_get_image($computed_image['image']); if (false !== $wrap) { if (isset($wrap['image'])) { $computed_image['image'] = current($wrap['image']) . $computed_image['image'] . next($wrap['image']); } if (isset($wrap['repeat'])) { $computed_image['repeat'] = current($wrap['repeat']) . $computed_image['repeat'] . next($wrap['repeat']); } if (isset($wrap['position_x'])) { $computed_image['position_x'] = current($wrap['position_x']) . $computed_image['position_x'] . next($wrap['position_x']); } if (isset($wrap['position_y'])) { $computed_image['position_y'] = current($wrap['position_y']) . $computed_image['position_y'] . next($wrap['position_y']); } } // image $options[current($less_vars)] = $computed_image['image']; // repeat if (false != next($less_vars) && current($less_vars)) { $options[current($less_vars)] = $computed_image['repeat']; } // position x if (false != next($less_vars) && current($less_vars)) { $options[current($less_vars)] = $computed_image['position_x']; } // position y if (false != next($less_vars) && current($less_vars)) { $options[current($less_vars)] = $computed_image['position_y']; } break; case 'number': if (!isset($number)) { break; } $computed_number = intval(of_get_option($number[0], $number[1])); if (false !== $wrap) { if (is_array($wrap)) { $computed_number = current($wrap) . $computed_number . next($wrap); } else { $computed_number = $wrap . $computed_number . $wrap; } } $options[current($less_vars)] = $computed_number; break; case 'keyword': if (!isset($keyword)) { break; } $computed_keyword = (string) of_get_option($keyword[0], $keyword[1]); if (false !== $interface) { if (isset($interface[$computed_keyword])) { $computed_keyword = $interface[$computed_keyword]; } else { $computed_keyword = current($interface); } } $options[current($less_vars)] = $computed_keyword; break; case 'font': if (!isset($font)) { break; } $computed_font = dt_stylesheet_make_web_font_object(of_get_option($font[0]), $font[1]); if (!$computed_font) { break; } // TODO: refactor this if (false !== $wrap) { if (is_array($wrap)) { $computed_font->family = current($wrap) . $computed_font->family . next($wrap); } else { $computed_font->family = $wrap . $computed_font->family . $wrap; } } // font family $options[current($less_vars)] = $computed_font->family; // weight if (false != next($less_vars)) { $options[current($less_vars)] = $computed_font->weight; } // style if (false != next($less_vars)) { $options[current($less_vars)] = $computed_font->style; } break; } } } return apply_filters('presscore_compiled_less_vars', $options); }
public function shortcode($atts, $content = null) { $default_atts = array('bg_image' => '', 'bg_color' => '', 'bg_opacity' => '100', 'text_color' => '', 'text_size' => 'normal', 'border_width' => '1', 'outer_padding' => '10', 'inner_padding' => '10', 'min_height' => '150', 'link' => '', 'target_blank' => '1', 'animation' => 'none'); $attributes = shortcode_atts($default_atts, $atts); $attributes['animation'] = in_array($attributes['animation'], array('none', 'scale', 'fade', 'left', 'right', 'bottom', 'top')) ? $attributes['animation'] : $default_atts['animation']; $attributes['bg_image'] = esc_url($attributes['bg_image']); $attributes['bg_color'] = apply_filters('of_sanitize_color', $attributes['bg_color']); $attributes['bg_opacity'] = absint($attributes['bg_opacity']); $attributes['bg_opacity'] = $attributes['bg_opacity'] > 100 ? 100 : $attributes['bg_opacity']; $attributes['text_size'] = in_array($attributes['text_size'], array('normal', 'small', 'big')) ? $attributes['text_size'] : $default_atts['text_size']; $attributes['text_color'] = apply_filters('of_sanitize_color', $attributes['text_color']); $attributes['border_width'] = absint($attributes['border_width']); $attributes['outer_padding'] = absint($attributes['outer_padding']); $attributes['inner_padding'] = absint($attributes['inner_padding']); $attributes['min_height'] = absint($attributes['min_height']); $attributes['link'] = esc_url($attributes['link']); $attributes['target_blank'] = apply_filters('dt_sanitize_flag', $attributes['target_blank']); $banner_inner_height = $attributes['min_height'] - $attributes['inner_padding']; $banner_style = array(); $banner_bg_style = array(); $banner_inner_style = array(); $banner_classes = array('shortcode-banner'); $banner_more_inner_style = ''; if ($attributes['bg_color']) { $banner_inner_style[] = 'background-color: ' . dt_stylesheet_color_hex2rgb($attributes['bg_color']); $banner_inner_style[] = 'background-color: ' . dt_stylesheet_color_hex2rgba($attributes['bg_color'], $attributes['bg_opacity']); } $banner_inner_style[] = sprintf('border: solid %spx transparent', $attributes['inner_padding']); $banner_inner_style[] = sprintf('outline: solid %spx', $attributes['border_width']); if ($attributes['text_color']) { $banner_inner_style[] = 'color: ' . $attributes['text_color']; $banner_inner_style[] = 'outline-color: ' . $attributes['text_color']; } $banner_inner_style[] = 'height: ' . $banner_inner_height . 'px'; $banner_bg_style[] = 'padding: ' . ($attributes['outer_padding'] > $attributes['border_width'] ? $attributes['outer_padding'] : $attributes['border_width']) . 'px'; $banner_bg_style[] = 'min-height: ' . $attributes['min_height'] . 'px'; $banner_style[] = 'min-height: ' . $attributes['min_height'] . 'px'; if ($attributes['bg_image']) { $banner_style[] = sprintf('background-image: url(%s)', $attributes['bg_image']); } $text_size_class = ''; if ('small' == $attributes['text_size']) { $text_size_class = ' text-small'; } elseif ('big' == $attributes['text_size']) { $text_size_class = ' text-big'; } $link = ''; if ($attributes['link']) { if ($attributes['target_blank']) { $link = sprintf(' onclick="window.open(\'%s\');"', $attributes['link']); } else { $link = sprintf(' onclick="window.location.href=\'%s\';"', $attributes['link']); } } if ($link) { $banner_classes[] = 'shortcode-banner-link'; } if ('none' != $attributes['animation']) { switch ($attributes['animation']) { case 'scale': $banner_classes[] = 'scale-up'; break; case 'fade': $banner_classes[] = 'fade-in'; break; case 'left': $banner_classes[] = 'right-to-left'; break; case 'right': $banner_classes[] = 'left-to-right'; break; case 'bottom': $banner_classes[] = 'top-to-bottom'; break; case 'top': $banner_classes[] = 'bottom-to-top'; break; } $banner_classes[] = 'animate-element'; } $output = sprintf('<div class="%s" %s><div class="shortcode-banner-bg wf-table" %s><div class="shortcode-banner-inside wf-table%s" %s><div %s>%s</div></div></div></div>', esc_attr(implode(' ', $banner_classes)), 'style="' . esc_attr(implode(';', $banner_style)) . '"' . $link, 'style="' . esc_attr(implode(';', $banner_bg_style)) . '"', $text_size_class, 'style="' . esc_attr(implode(';', $banner_inner_style)) . '"', $banner_more_inner_style, do_shortcode($content)); return $output; }