labels = $labels;
$this->position_type = $position_type;
$this->global_settings = $global_settings;
}
/*
* Generate label markup
*/
public function html() {
$label_container_classes = $this->label_container_classes();
$label_container_styles = $this->label_container_styles();
$html = '';
$html .= '
';
foreach( $this->labels as $label ) {
$this->label_num++;
$this->settings = $label;
$this->label_id = $label['id'];
$this->label_type = isset( $label['type'] ) ? $label['type'] : '';
$this->custom_styles = isset( $label['custom_styles'] ) && $label['custom_styles'] === 'true' ? true : false;
$label_wrap_styles = $this->label_wrap_styles();
$label_wrap_classes = $this->label_wrap_classes();
$label_styles = $this->label_styles();
$label_classes = $this->label_classes();
$html .= $this->label_custom_css();
$html .= '
';
$html .= '';
$html .= $this->label_side_block( 'before' );
$html .= $this->label_text();
$html .= $this->label_side_block( 'after' );
$html .= '';
$html .= '
';
}
$html .= '
';
/**
* Filter label markup
* @since 1.00
* @param string $html
* @param array $this->settings
*/
$html = apply_filters( 'awl_label_markup', $html, $this->position_type, $this->labels );
return $html;
}
/*
* Class names for label container
*/
private function label_container_classes() {
$class = '';
$class .= ' awl-position-type-' . sanitize_title( $this->position_type );
$class .= ' awl-label-type-' . AWL_Helpers::get_label_type();
$class .= ( $this->position_type === 'on_image' ) ? ' awl-align-' . $this->labels[0]['position'] : ' awl-align-' . sanitize_title( $this->labels[0]['position_x'] );
return str_replace( '_', '-', $class );
}
/*
* Class names for label wrapper
*/
private function label_wrap_classes() {
$class = '';
$class .= ' awl-label-id-' . strval( $this->label_id );
return str_replace( '_', '-', $class );
}
/*
* Class names for label
*/
private function label_classes() {
$class = '';
$class .= ( $this->label_type === 'image' ) ? ' awl-type-image' : ' awl-type-label';
$class .= ( $this->label_type !== 'image' ) ? ' awl-type-label-' . sanitize_title( $this->settings['template'] ) : '';
return str_replace( '_', '-', $class );
}
/*
* Custom css
*/
private function label_custom_css() {
$css = '';
if ( $this->custom_styles && isset( $this->settings['custom_css'] ) && $this->settings['custom_css'] ) {
$css .= '';
}
return $css;
}
/*
* Styles for label container
*/
private function label_container_styles() {
$position = $this->position_type === 'on_image' ? $this->labels[0]['position'] : $this->labels[0]['position_x'];
$direction = ( count( $this->labels ) > 1 && isset( $this->global_settings['labels_alignment'] ) && $this->global_settings['labels_alignment'] === 'vertical' ) ? 'column' : 'row';
$styles = array();
$styles['display'] = 'flex';
$styles['flex-wrap'] = 'wrap';
$styles['flex-direction'] = $direction;
$styles['text-align'] = 'left';
$styles['width'] = '100%';
$styles['position'] = $this->position_type === 'on_image' ? 'absolute' : 'relative';
$styles['z-index'] = $this->position_type === 'on_image' ? '9' : '1';
switch( $position ) {
case 'left_top':
$styles['left'] = '0px';
$styles['right'] = 'auto';
$styles['top'] = '0px';
$styles['bottom'] = 'auto';
$styles['transform'] = 'none';
$styles['justify-content'] = 'flex-start';
break;
case 'center_top':
$styles['left'] = '0px';
$styles['right'] = 'auto';
$styles['top'] = '0px';
$styles['bottom'] = 'auto';
$styles['transform'] = 'none';
$styles['justify-content'] = 'center';
break;
case 'right_top':
$styles['left'] = '0px';
$styles['right'] = 'auto';
$styles['top'] = '0px';
$styles['bottom'] = 'auto';
$styles['transform'] = 'none';
$styles['justify-content'] = 'flex-end';
break;
case 'left_center':
$styles['left'] = '0px';
$styles['right'] = 'auto';
$styles['top'] = '50%';
$styles['bottom'] = 'auto';
$styles['transform'] = 'translateY(-50%)';
$styles['justify-content'] = 'flex-start';
break;
case 'center_center':
$styles['left'] = '0px';
$styles['right'] = 'auto';
$styles['top'] = '50%';
$styles['bottom'] = 'auto';
$styles['transform'] = 'translateY(-50%)';
$styles['justify-content'] = 'center';
break;
case 'right_center':
$styles['left'] = '0px';
$styles['right'] = 'auto';
$styles['top'] = '50%';
$styles['bottom'] = 'auto';
$styles['transform'] = 'translateY(-50%)';
$styles['justify-content'] = 'flex-end';
break;
case 'left_bottom':
$styles['left'] = '0px';
$styles['right'] = 'auto';
$styles['top'] = 'auto';
$styles['bottom'] = '0px';
$styles['transform'] = 'none';
$styles['justify-content'] = 'flex-start';
break;
case 'center_bottom':
$styles['left'] = '0';
$styles['right'] = 'auto';
$styles['top'] = 'auto';
$styles['bottom'] = '0px';
$styles['transform'] = 'none';
$styles['justify-content'] = 'center';
break;
case 'right_bottom':
$styles['left'] = '0px';
$styles['right'] = 'auto';
$styles['top'] = 'auto';
$styles['bottom'] = '0px';
$styles['transform'] = 'none';
$styles['justify-content'] = 'flex-end';
break;
case 'left':
$styles['justify-content'] = 'flex-start';
break;
case 'center':
$styles['justify-content'] = 'center';
break;
case 'right':
$styles['justify-content'] = 'flex-end';
break;
}
/**
* Filter label container styles
* @since 1.00
* @param array $styles
* @param array $this->labels
*/
$styles = apply_filters( 'awl_label_container_styles', $styles, $this->position_type, $this->labels );
return $this->implode_styles( $styles );
}
/*
* Styles for label wrapper
*/
private function label_wrap_styles() {
$styles = array();
if ( count( $this->labels ) > 1 && $this->label_num < count( $this->labels ) ) {
$direction = ( isset( $this->global_settings['labels_alignment'] ) && $this->global_settings['labels_alignment'] === 'vertical' ) ? 'column' : 'row';
$margin = isset( $this->global_settings['labels_distance'] ) ? $this->global_settings['labels_distance'] : '0';
$styles['margin'] = $direction === 'row' ? '0 ' . $margin . 'px 0 0' : '0 0 ' . $margin . 'px 0';
}
/**
* Filter label wrapper styles
* @since 1.00
* @param array $styles
* @param array $this->settings
*/
$styles = apply_filters( 'awl_label_wrapper_styles', $styles, $this->position_type, $this->settings );
return $this->implode_styles( $styles );
}
/*
* Styles for label
*/
private function label_styles() {
$styles = array(
'display' => 'table',
'position' => 'relative',
'line-height' => '1',
'white-space' => 'nowrap',
'vertical-align' => 'baseline',
'font-size' => '14px',
'font-weight' => '400',
'font-style' => 'normal',
'color' => '#fff'
);
if ( $this->custom_styles && $this->label_type !== 'image' ) {
$styles['font-size'] = $this->settings['font_size'] . 'px;';
$styles['color'] = $this->settings['text_color'];
switch( $this->settings['font_style'] ) {
case 'normal':
$styles['font-weight'] = 'normal';
$styles['font-style'] = 'normal';
break;
case 'bold':
$styles['font-weight'] = 'bold';
$styles['font-style'] = 'normal';
break;
case 'italic':
$styles['font-weight'] = 'normal';
$styles['font-style'] = 'italic';
break;
case 'bold_italic':
$styles['font-weight'] = 'bold';
$styles['font-style'] = 'italic';
break;
}
}
$styles['opacity'] = '1';
$styles['margin'] = '0';
if ( $this->custom_styles ) {
$styles['opacity'] = $this->settings['opacity'];
$styles['margin'] = $this->settings['margin']['top'] . 'px ' . $this->settings['margin']['right'] . 'px ' . $this->settings['margin']['bottom'] . 'px ' . $this->settings['margin']['left'] . 'px';
}
/**
* Filter label styles
* @since 1.00
* @param array $styles
* @param array $this->settings
*/
$styles = apply_filters( 'awl_label_styles', $styles, $this->position_type, $this->settings );
return $this->implode_styles( $styles );
}
/*
* Label text block markup
*/
private function label_text() {
$styles = array(
'display' => 'table-cell',
'padding' => '0.3em 0.6em',
'z-index' => '1',
'background' => '#3986c6',
'position' => 'relative',
'line-height' => '1'
);
$styles['border-radius'] = $this->settings['template'] === 'rounded' ? '0.25em' : ( $this->settings['template'] === 'round' ? '1em' : '0' );
if ( $this->custom_styles ) {
$styles['background'] = $this->settings['bg_color'];
$styles['padding'] = $this->settings['padding']['top'] . 'em ' . $this->settings['padding']['right'] . 'em ' . $this->settings['padding']['bottom'] . 'em ' . $this->settings['padding']['left'] . 'em';
}
$html = '';
/**
* Filter label text styles
* @since 1.00
* @param array $styles
* @param array $this->settings
*/
$styles = apply_filters( 'awl_label_text_styles', $styles, $this->position_type, $this->settings );
$html .= '';
$html .= '' . AWL_Helpers::get_label_text( $this->settings ) . '';
$html .= '';
return $html;
}
/*
* Label 'after' block markup
*/
private function label_side_block( $name ) {
$html = '';
if ( $this->is_show_side( $name ) ) {
$block_styles = array(
'display' => 'table-cell',
'width' => '0',
'height' => '0',
'position' => 'relative',
'z-index' => '2',
'overflow' => 'hidden',
'padding' => '0 0.65em 0 0'
);
$svg_styles = array(
'position' => 'absolute',
'width' => '100%',
'height' => '100%',
'fill' => '#3986c6'
);
$svg_line_styles = array();
$svg_styles['fill'] = $this->settings['bg_color'];
$html .= '';
$html .= '';
$html .= '';
if ( ! empty( $svg_line_styles ) ) {
$html = str_replace( 'class="d-stroke"', 'class="d-stroke" style="' . $this->implode_styles( $svg_line_styles ) . '"', $html );
}
}
return $html;
}
/*
* Get svg shape
*/
private function get_svg( $name ) {
$icon = '';
$icon_arr = array(
'triangled-after' => '',
'angle-after' => '',
);
/**
* Filter the array of svg icons
* @since 1.00
* @param array $icon_arr Array of icons
*/
$icon_arr = apply_filters( 'awl_svg_icons', $icon_arr );
if ( $name && isset( $icon_arr[$name] ) ) {
$icon = $icon_arr[$name];
}
return $icon;
}
/*
* Check weather to show side block or not
*/
private function is_show_side( $name ) {
$temp = array(
'before' => array( 'arrow' ),
'after' => array( 'triangled', 'angle' )
);
if ( in_array( $this->settings['template'], $temp[$name] ) ) {
return true;
}
return false;
}
/*
* Implode style
*/
private function implode_styles( $styles ) {
$style_string = '';
if ( $styles && ! empty( $styles ) ) {
foreach( $styles as $style_name => $style ) {
$style_string .= $style_name . ':' . $style . ';';
}
}
return $style_string;
}
}
endif;