id = $id;
$this->param = $param;
$this->title = $title;
$this->menus = [];
}
public function init(): string {
$menu = $this->wrapper();
$menu .= $this->main_button();
if ( $this->is_main() ) {
$menu .= $this->sub_buttons();
}
$menu .= '';
$menu .= $this->get_menu();
return $menu;
}
public function wrapper(): string {
$position = ! empty( $this->param['position'] ) ? ' ' . $this->param['position'] : ' flBtn-position-br';
$shape = ! empty( $this->param['shape'] ) ? ' ' . $this->param['shape'] : ' flBtn-shape-circle';
$size = ! empty( $this->param['size'] ) ? ' ' . $this->param['size'] : ' flBtn-size-medium';
$animation = ! empty( $this->param['animation'] ) ? ' ' . $this->param['animation'] : '';
$btn_animation = ! empty( $this->param['button_animation'] ) ? ' flBtn-animated ' . $this->param['button_animation'] : '';
$shadow = empty( $this->param['shadow'] ) ? ' -shadow' : '';
$classes = $position . $shape . $size . $shadow . $animation . $btn_animation;
return '
';
}
public function main_button(): string {
$param = $this->param;
$main_type = ! empty( $param['item_type'] ) ? $param['item_type'] : 'main';
$btn = '';
$link = ! empty( $param['item_link'] ) ? $param['item_link'] : '#';
switch ( $main_type ) {
case 'main':
$btn .= $this->create_checkbox();
$btn .= '
';
break;
case 'link':
$target = ! empty( $param['new_tab'] ) ? '_blank' : '_self';
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
break;
case 'share':
$share = mb_strtolower( $param['item_share'] );
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
break;
case 'translate':
$glang = $param['gtranslate'] ?? '';
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
break;
case 'print':
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
break;
case 'login':
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
break;
case 'logout':
$btn .= '
main_param() . '>' . $this->main_icon() . '';
break;
case 'register':
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
break;
case 'lostpassword':
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
break;
case 'totop':
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
break;
case 'tobottom':
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
break;
case 'smoothscroll':
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
break;
case 'goBack':
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
break;
case 'goForward':
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
break;
case 'next_post':
$next_post = get_next_post( true );
if ( ! empty( $next_post ) ) {
$link = get_permalink( $next_post );
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
}
break;
case 'previous_post':
$previous_post = get_previous_post( true );
if ( ! empty( $previous_post ) ) {
$link = get_permalink( $previous_post );
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
}
break;
case 'menu':
if ( ! empty( $param['item_menu'] ) ) {
$menu_order = $param['item_menu'];
$this->menus[] = $menu_order;
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
}
break;
case 'like':
if ( is_singular() ) {
$likes = get_post_meta( get_the_ID(), '_wowp_likes', true );
}
$likes = !empty($likes) ? $likes : 0;
$btn .= '
main_param( ' flBtn-label' ) . '>' . $this->main_icon() . '';
break;
}
return $btn;
}
public function main_param( $defClass = '' ): string {
$param = $this->param;
if ( ! empty( $param['item_tooltip_include'] ) ) {
$open = ! empty( $param['item_tooltip_open'] ) ? ' data-btn-tooltip="show"' : '';
$tooltip = ' data-tooltip="' . esc_attr( $param['item_tooltip'] ) . '"' . wp_kses( $open, [ 'data-btn-tooltip' => [] ] );
} else {
$tooltip = '';
}
$class = ! empty( $param['main_button_class'] ) ? $param['main_button_class'] : '';
$link_rel = ! empty( $param['link_rel'] ) ? ' rel="' . esc_attr( $param['link_rel'] ) . '"' : '';
return 'class="' . esc_attr( $class . $defClass ) . '"' . $tooltip . $link_rel;
}
public function main_icon(): string {
$param = $this->param;
$type = ! empty( $param['button_icon_type'] ) ? $param['button_icon_type'] : 'default';
$action = ! empty( $param['close_button_enable'] ) ? ' data-action="open"' : '';
switch ( $type ) {
case 'default':
$animate = ! empty( $param['button_icon_anomate'] ) ? ' ' . $param['button_icon_anomate'] : '';
$icon = '
[] ] ) . '>';
break;
case 'img':
$alt = ! empty( $param['custom_icon_alt'] ) ? $param['custom_icon_alt'] : '';
$url = $param['custom_icon_url'];
$icon = '
 . ')
[] ] ) . ' alt="' . esc_attr( $alt ) . '"' . ' class="notranslate">';
break;
case 'emoji':
$icon = '
[] ] ) . '>' . esc_html( $param['custom_icon_emoji'] ) . '';
break;
case 'class':
$icon = '
[] ] ) . '>';
break;
default:
$icon = '';
break;
}
return $icon;
}
public function close_icon(): string {
$param = $this->param;
$icon_class = ! empty( $param['close_button_icon'] ) ? $param['close_button_icon'] : 'fas fa-xmark';
if ( ! empty( $param['close_button_enable'] ) ) {
return '
';
}
return '';
}
public function create_checkbox(): string {
$param = $this->param;
$checked = ! empty( $param['hold_buttons_open'] ) ? ' checked="checked"' : '';
$class = ! empty( $param['extra_checkbox_class'] ) ? ' class="' . esc_attr( $param['extra_checkbox_class'] ) . ' checkbox"' : 'class="checkbox"';
$attr = $checked . $class;
return '
[],
'class' => []
] ) . '>';
}
public function sub_buttons() {
$param = $this->param;
$btns = [
'flBtn-first' => $param['menu_1'] ?? [],
'flBtn-second' => $param['menu_2'] ?? [],
];
$btn = '';
foreach ( $btns as $key => $val ) {
if ( empty( $val['item_type'] ) ) {
continue;
}
$btn .= '
';
$count = count( $val['item_type'] );
for ( $i = 0; $i < $count; $i ++ ) {
$sub_btn = $this->create_subbtn( $val, $i );
if ( empty( $sub_btn ) ) {
continue;
}
$btn .= '- ';
$btn .= $sub_btn;
$btn .= '
';
}
$btn .= '
';
}
return $btn;
}
public function create_subbtn( $arr, $i ) {
$type = ! empty( $arr['item_type'][ $i ] ) ? $arr['item_type'][ $i ] : '';
$icon = $this->subbtn_icon( $arr, $i );
$link_param = $this->subbtn_param( $arr, $i );
$link = ! empty( $arr['item_link'][ $i ] ) ? $arr['item_link'][ $i ] : '#';
$btn = '';
switch ( $type ) {
case 'link':
$target = ! empty( $arr['new_tab'][ $i ] ) ? '_blank' : '_self';
$btn .= '
' . $icon . '';
break;
case 'share':
$share = mb_strtolower( $arr['item_share'][ $i ] );
$btn .= '
' . $icon . '';
break;
case 'translate':
$link = '#';
$glang = $arr['gtranslate'][ $i ] ?? '';
$btn .= '
' . $icon . '';
break;
case 'print':
$btn .= '
' . $icon . '';
break;
case 'login':
$btn .= '
' . $icon . '';
break;
case 'logout':
$btn .= '
' . $icon . '';
break;
case 'register':
$btn .= '
' . $icon . '';
break;
case 'lostpassword':
$btn .= '
' . $icon . '';
break;
case 'totop':
$btn .= '
' . $icon . '';
break;
case 'tobottom':
$btn .= '
' . $icon . '';
break;
case 'smoothscroll':
$btn .= '
' . $icon . '';
break;
case 'goBack':
$btn .= '
' . $icon . '';
break;
case 'goForward':
$btn .= '
' . $icon . '';
break;
case 'menu':
if ( ! empty( $arr['item_menu'][ $i ] ) ) {
$menu_order = $arr['item_menu'][ $i ];
$this->menus[] = $menu_order;
$btn .= '
' . $icon . '';
}
break;
case 'next_post':
$next_post = get_next_post( true );
if ( ! empty( $next_post ) ) {
$link = get_permalink( $next_post );
$btn .= '
' . $icon . '';
}
break;
case 'previous_post':
$previous_post = get_previous_post( true );
if ( ! empty( $previous_post ) ) {
$link = get_permalink( $previous_post );
$btn .= '
' . $icon . '';
}
break;
case 'like':
if ( is_singular() ) {
$likes = get_post_meta( get_the_ID(), '_wowp_likes', true );
}
$likes = !empty($likes) ? $likes : 0;
$btn .= '
' . $icon . '';
break;
}
return $btn;
}
public function subbtn_icon( $arr, $i ): string {
$type = ! empty( $arr['icon_type'][ $i ] ) ? $arr['icon_type'][ $i ] : 'default';
switch ( $type ) {
case 'default':
$animate = ! empty( $arr['item_icon_anomate'][ $i ] ) ? ' ' . $arr['item_icon_anomate'][ $i ] : '';
$icon = '
';
break;
case 'img':
$alt = ! empty( $arr['custom_icon_alt'][ $i ] ) ? $arr['custom_icon_alt'][ $i ] : '';
$url = $arr['custom_icon_url'][ $i ];
$icon = '
 . ')
';
break;
case 'emoji':
$icon = '
' . esc_html( $arr['custom_icon_emoji'][ $i ] ) . '';
break;
case 'class':
$icon = '
';
break;
default:
$icon = '';
break;
}
return $icon;
}
public function subbtn_param( $arr, $i ) {
$params = '';
if ( ! empty( $arr['item_tooltip_include'][ $i ] ) ) {
$open = ! empty( $arr['item_tooltip_open'][ $i ] ) ? ' data-btn-tooltip="show"' : '';
$params .= 'data-tooltip="' . esc_attr( $arr['item_tooltip'][ $i ] ) . '"' . wp_kses( $open, [ 'data-btn-tooltip' => [] ] );
}
$params .= ! empty( $arr['button_class'][ $i ] ) ? ' class="' . esc_attr( $arr['button_class'][ $i ] ) . '"' : '';
$params .= ! empty( $arr['button_id'][ $i ] ) ? ' id="' . esc_attr( $arr['button_id'][ $i ] ) . '"' : '';
$params .= ! empty( $arr['link_rel'][ $i ] ) ? ' rel="' . esc_attr( $arr['link_rel'][ $i ] ) . '"' : '';
return $params;
}
public function get_menu(): string {
$menus = '';
if ( empty( $this->menus ) ) {
return $menus;
}
foreach ( $this->menus as $menu ) {
$menus_obj = wp_get_nav_menu_object( absint( $menu ) );
$menu_items = wp_get_nav_menu_items( $menu );
$menus .= '';
}
return $menus;
}
public function is_main(): bool {
return $this->param['item_type'] === 'main';
}
}