Beispiel #1
0
function mm_image_card($args)
{
    $component = 'mm-image-card';
    // Set our defaults and use them as needed.
    $defaults = array('title' => '', 'image' => '', 'image_card_style' => 'button-bottom', 'image_size' => '', 'image_text' => '', 'image_text_color' => '', 'link_image' => '', 'link_title' => '', 'link_target' => '_self', 'content_align' => 'default', 'button_link' => '', 'button_link_target' => '_self', 'button_text' => '', 'button_style' => '', 'button_border_weight' => 'default', 'button_corner_style' => '', 'button_color' => '');
    $args = wp_parse_args((array) $args, $defaults);
    // Get clean param values.
    $title = $args['title'];
    $image = $args['image'];
    $image_card_style = $args['image_card_style'];
    $image_size = $args['image_size'];
    $image_text = $args['image_text'];
    $image_text_color = $args['image_text_color'];
    $link = $args['link'];
    $link_image = $args['link_image'];
    $link_title = $args['link_title'];
    $content_align = $args['content_align'];
    $button_link = $args['button_link'];
    $button_link_target = $args['button_link_target'];
    $button_text = $args['button_text'];
    $button_style = $args['button_style'];
    $button_border_weight = $args['button_border_weight'];
    $button_corner_style = $args['button_corner_style'];
    $button_color = $args['button_color'];
    $button_output = '';
    $image_text_output = '';
    // Get Mm classes.
    $mm_classes = apply_filters('mm_components_custom_classes', '', $component, $args);
    $mm_classes .= ' mm-text-align-' . $content_align;
    $link_url = $args['link'];
    $link_target = $args['link_target'];
    // Handle a VC link array.
    if ('url' === substr($args['link'], 0, 3) && function_exists('vc_build_link')) {
        $link_array = vc_build_link($args['link']);
        $link_url = $link_array['url'];
        $link_title = $link_array['title'];
        $link_target = $link_array['target'];
    } else {
        $link_target = $button_link_target;
    }
    if (!$image_size) {
        $image_size = 'full';
    }
    // Support the image being an ID or a URL.
    if (is_numeric($image)) {
        $image_array = wp_get_attachment_image_src($image, $image_size);
        $image_url = $image_array[0];
    } else {
        $image_url = esc_url($image);
    }
    if ($image_text) {
        $image_text_output = sprintf('<span class="%s %s">%s</span>', 'mm-image-card-text', esc_attr('mm-text-color-' . $image_text_color), esc_attr($image_text));
    }
    // Set container width to be the same as the image width.
    $image_data = wp_get_attachment_image_src($image, $image_size);
    $image_width = $image_data[1];
    if ($link_image) {
        $content_output = sprintf('%s<a href="%s" title="%s" target="%s"><img class="%s" src="%s"></a>', $image_text_output, esc_url($link_url), esc_attr($link_title), esc_attr($link_target), 'mm-image-card-image', esc_attr($image_url));
    } else {
        $content_output = sprintf('%s<img class="%s" src="%s">', $image_text_output, 'mm-image-card-image', esc_attr($image_url));
    }
    // Build the button output.
    if ($button_text) {
        $button_args = array('link' => $link, 'link_title' => $link_title, 'link_target' => $button_link_target, 'button_text' => $button_text, 'style' => $button_style, 'corner_style' => 'pointed', 'border_weight' => $button_border_weight, 'color' => $button_color, 'alignment' => $content_align);
        if ('button-bottom' === $image_card_style) {
            $button_output = mm_button($button_args);
        }
    }
    ob_start();
    ?>

    <div class="<?php 
    echo esc_attr($mm_classes);
    ?>
">

        <div class="mm-image-card-wrap" style="max-width:<?php 
    echo esc_attr($image_width);
    ?>
px">

        <?php 
    if (!empty($title)) {
        printf('<h2>%s</h2>', esc_html($title));
    }
    echo wp_kses_post($content_output);
    echo wp_kses_post($button_output);
    ?>

        </div>

    </div>

    <?php 
    return ob_get_clean();
}
/**
 * Output Expandable Content.
 *
 * @since   1.0.0
 *
 * @param   array   $args  The args.
 *
 * @return  string         The HTML.
 */
function mm_expandable_content($args)
{
    $component = 'mm-expandable-content';
    $defaults = array('link_style' => '', 'link_text' => '', 'link_alignment' => 'left', 'fade' => '', 'button_style' => '', 'button_border_weight' => '', 'button_corner_style' => '', 'button_color' => '', 'content' => '');
    $args = wp_parse_args((array) $args, $defaults);
    // Get clean param values.
    $link_style = $args['link_style'];
    $link_text = $args['link_text'];
    $link_alignment = $args['link_alignment'];
    $fade = $args['fade'];
    $button_style = $args['button_style'];
    $button_border_weight = $args['button_border_weight'];
    $button_corner_style = $args['button_corner_style'];
    $button_color = $args['button_color'];
    $content = $args['content'];
    // Fix wpautop issues in $content.
    if (function_exists('wpb_js_remove_wpautop')) {
        $content = wpb_js_remove_wpautop($content, true);
    }
    // Get Mm classes.
    $mm_classes = apply_filters('mm_components_custom_classes', '', $component, $args);
    // Build the trigger classes.
    $trigger_classes = 'mm-expandable-content-trigger mm-text-align-' . $link_alignment;
    $trigger_classes .= $fade ? ' ' . $fade : '';
    // Build the target classes.
    $target_classes = 'mm-expandable-content-target ' . $link_alignment;
    // Build the button or link trigger output.
    if ('button' === $link_style) {
        $button_args = array('button_text' => $link_text, 'class' => 'mm-expandable-content-trigger-button', 'style' => $button_style, 'corner_style' => $button_corner_style, 'border_weight' => $button_border_weight, 'color' => $button_color, 'alignment' => $link_alignment);
        $trigger_link_output = mm_button($button_args);
    } else {
        $trigger_link_output = sprintf('<a class="mm-expandable-content-trigger-link %s" title="%s">%s</a>', esc_attr($link_style), esc_attr($link_text), esc_html($link_text));
    }
    ob_start();
    ?>

	<div class="<?php 
    echo esc_attr($mm_classes);
    ?>
">
		<div class="<?php 
    echo esc_attr($trigger_classes);
    ?>
">
			<?php 
    echo $trigger_link_output;
    ?>
		</div>
		<div class="<?php 
    echo esc_attr($target_classes);
    ?>
">
			<?php 
    echo do_shortcode($content);
    ?>
		</div>
	</div>

	<?php 
    return ob_get_clean();
}
Beispiel #3
0
 /**
  * Output the Widgets settings form.
  *
  * @since 1.0.0
  *
  * @param  array  $instance  The options for the widget instance.
  */
 public function form($instance)
 {
     $defaults = array('title' => '', 'link' => '', 'button_text' => '', 'style' => '', 'corner_style' => '', 'border_weight' => '', 'color' => '', 'size' => '', 'full_width' => '', 'alignment' => '');
     // Use our instance args if they are there, otherwise use the defaults.
     $instance = wp_parse_args($instance, $defaults);
     $title = $instance['title'];
     $link = $instance['link'];
     $button_text = $instance['button_text'];
     $style = $instance['style'];
     $corner_style = $instance['corner_style'];
     $border_weight = $instance['border_weight'];
     $color = $instance['color'];
     $size = $instance['size'];
     $full_width = mm_true_or_false($instance['full_width']);
     $alignment = $instance['alignment'];
     $classname = $this->options['classname'];
     $colors = mm_get_colors('mm-button');
     $text_alignment = mm_get_text_alignment('mm-button');
     // Handle the case of a newly added widget that doesn't yet have button text set.
     $preview_instance = $instance;
     if ('' == $preview_instance['button_text']) {
         $preview_instance['button_text'] = __('Button Text', 'mm-components');
     }
     // Title.
     $this->field_text(__('Title', 'mm-components'), '', $classname . '-title widefat', 'title', $title);
     // Preview.
     $this->field_custom(__('Button Preview', 'mm-components'), '', '<div class="mm-button-preview-wrap">' . mm_button($preview_instance) . '</div>');
     // Button text.
     $this->field_text(__('Button Text', 'mm-components'), '', $classname . '-button-text widefat', 'button_text', $button_text);
     // Link.
     $this->field_text(__('Button Link', 'mm-components'), '', $classname . '-link widefat', 'link', $link);
     // Button style.
     $this->field_select(__('Button Style', 'mm-components'), '', $classname . '-style widefat', 'style', $style, array('default' => __('Default', 'mm-components'), 'ghost' => __('Ghost', 'mm-components'), 'solid-to-ghost' => __('Solid to Ghost', 'mm-components'), 'three-d' => __('3D', 'mm-components'), 'gradient' => __('Gradient', 'mm-components')));
     // Corner style.
     $this->field_select(__('Corner Style', 'mm-components'), '', $classname . '-corner-style widefat', 'corner_style', $corner_style, array('pointed' => __('Pointed', 'mm-components'), 'rounded' => __('Rounded', 'mm-components'), 'pill' => __('Pill', 'mm-components')));
     // Border weight.
     $this->field_select(__('Border Weight', 'mm-components'), '', $classname . 'border-weight widefat', 'border_weight', $border_weight, array('thin' => __('Thin', 'mm-components'), 'thick' => __('Thick', 'mm-components')));
     // Color.
     $this->field_select(__('Color', 'mm-components'), '', $classname . '-color widefat', 'color', $color, $colors);
     // Size.
     $this->field_select(__('Size', 'mm-components'), '', $classname . '-size widefat', 'size', $size, array('normal' => __('Normal', 'mm-components'), 'small' => __('Small', 'mm-components'), 'large' => __('Large', 'mm-components')));
     // Full width.
     $this->field_checkbox(__('Full Width', 'mm-components'), __('Choosing full-width will make the button take up the width of its container.', 'mm-components'), $classname . '-full-width widefat', 'full_width', $full_width);
     // Alignment.
     $this->field_select(__('Button Alignment', 'mm-components'), '', $classname . '-alignment widefat', 'alignment', $alignment, $text_alignment);
 }
/**
 * MIGHTYminnow Components
 *
 * Component: Hero Banner
 *
 * @package mm-components
 * @since   1.0.0
 */
function mm_hero_banner($args)
{
    $component = 'mm-hero-banner';
    // Set our defaults and use them as needed.
    $defaults = array('background_image' => '', 'background_position' => 'center center', 'full_height' => 0, 'min_height' => 360, 'overlay_color' => '', 'overlay_opacity' => '0.1', 'text_color' => 'default', 'heading_level' => 'h2', 'heading_text' => '', 'content' => '', 'secondary_content' => '', 'content_align' => 'left', 'button_link' => '', 'button_link_target' => '_self', 'button_text' => '', 'button_style' => '', 'button_border_weight' => 'default', 'button_corner_style' => '', 'button_color' => '');
    $args = wp_parse_args((array) $args, $defaults);
    // Get clean param values.
    $background_image = $args['background_image'];
    $background_position = $args['background_position'];
    $full_height = $args['full_height'];
    $min_height = $args['min_height'];
    $overlay_color = $args['overlay_color'];
    $overlay_opacity = $args['overlay_opacity'];
    $text_color = $args['text_color'];
    $heading_level = $args['heading_level'];
    $heading_text = $args['heading_text'];
    $content = $args['content'];
    $secondary_content = $args['secondary_content'];
    $content_align = $args['content_align'];
    $button_link = $args['button_link'];
    $button_link_target = $args['button_link_target'];
    $button_text = $args['button_text'];
    $button_style = $args['button_style'];
    $button_border_weight = $args['button_border_weight'];
    $button_corner_style = $args['button_corner_style'];
    $button_color = $args['button_color'];
    $heading_output = '';
    $content_output = '';
    $overlay_output = '';
    $button_output = '';
    $secondary_content_output = '';
    // Get Mm classes.
    $mm_classes = apply_filters('mm_components_custom_classes', '', $component, $args);
    $mm_classes .= ' mm-text-align-' . $content_align;
    if (mm_true_or_false($full_height)) {
        $mm_classes .= ' mm-full-window-height';
    }
    // Support the background image being an ID or a URL.
    if (is_numeric($background_image)) {
        $image_size = apply_filters('mm_hero_banner_image_size', 'full');
        $image_array = wp_get_attachment_image_src($background_image, $image_size);
        $image_url = $image_array[0];
    } else {
        $image_url = esc_url($background_image);
    }
    // Build wrapper styles.
    $wrap_styles = array();
    if ($image_url) {
        $wrap_styles[] = "background-image: url({$image_url});";
    }
    if ($background_position) {
        $wrap_styles[] = "background-position: {$background_position};";
    }
    if (1 < (int) $min_height) {
        $wrap_styles[] = 'min-height: ' . (int) $min_height . 'px;';
    }
    $wrap_styles = implode(' ', $wrap_styles);
    // Build background overlay.
    if ($overlay_color) {
        $overlay_styles = array();
        $overlay_styles[] = 'background-color: ' . $overlay_color . ';';
        $overlay_styles[] = 'opacity: ' . (double) $overlay_opacity . ';';
        $overlay_styles[] = 'filter: alpha(opacity=' . (double) $overlay_opacity * 100 . ');';
        $overlay_styles = implode(' ', $overlay_styles);
        $overlay_output = '<div class="hero-overlay" style="' . esc_attr($overlay_styles) . '"></div>';
    }
    // Build the heading.
    if ($heading_text) {
        $heading_output = sprintf('<%s class="hero-heading %s">%s</%s>', esc_html($heading_level), esc_attr('mm-text-color-' . $text_color), esc_html($heading_text), esc_html($heading_level));
    }
    // Build the content.
    if (strpos($content, '<')) {
        /* We have HTML */
        $content_output = function_exists('wpb_js_remove_wpautop') ? wpb_js_remove_wpautop($content, true) : $content;
    } elseif (mm_is_base64($content)) {
        /* We have a base64 encoded string */
        $content_output = rawurldecode(base64_decode($content));
    } else {
        /* We have a non-HTML string */
        $content_output = $content;
    }
    if ($content) {
        $content_output = sprintf('<div class="hero-content %s">%s</div>', esc_attr('mm-text-color-' . $text_color), do_shortcode($content_output));
    }
    // Build the button output.
    if ($button_text) {
        $button_args = array('link' => $button_link, 'link_title' => $button_text, 'link_target' => $button_link_target, 'button_text' => $button_text, 'style' => $button_style, 'corner_style' => $button_corner_style, 'border_weight' => $button_border_weight, 'color' => $button_color, 'alignment' => $content_align);
        $button_output = mm_button($button_args);
    }
    // Handle $secondary_content being HTML, plain text, or a base64 encoded string.
    if (strpos($secondary_content, '<')) {
        /* We have HTML */
        $secondary_content_output = function_exists('wpb_js_remove_wpautop') ? wpb_js_remove_wpautop($secondary_content, true) : $secondary_content;
    } elseif (mm_is_base64($secondary_content)) {
        /* We have a base64 encoded string */
        $secondary_content_output = rawurldecode(base64_decode($secondary_content));
    } else {
        /* We have a non-HTML string */
        $secondary_content_output = $secondary_content;
    }
    if ($secondary_content) {
        $secondary_content_output = sprintf('<div class="hero-secondary-content %s">%s</div>', esc_attr('mm-text-color-' . $text_color), do_shortcode($secondary_content_output));
    }
    ob_start();
    ?>

	<div class="<?php 
    echo esc_attr($mm_classes);
    ?>
" style="<?php 
    echo esc_attr($wrap_styles);
    ?>
">

		<?php 
    echo $overlay_output;
    ?>

		<div class="hero-content-wrap">

			<?php 
    echo wp_kses_post($heading_output);
    ?>

			<?php 
    echo wp_kses_post($content_output);
    ?>

			<?php 
    echo wp_kses_post($button_output);
    ?>

			<?php 
    echo wp_kses_post($secondary_content_output);
    ?>

		</div>
	</div>

	<?php 
    return ob_get_clean();
}