Current File : /home/kelaby89/babyl0n.restaurant/wp-content/plugins/restar-core/addons/header/header.php
<?php

use \Elementor\Widget_Base;
use \Elementor\Controls_Manager;
use \Elementor\Group_Control_Typography;
use \Elementor\Repeater;
use \Elementor\Utils;
use \Elementor\Group_Control_Background;
use \Elementor\Group_Control_Text_Shadow;
use \Elementor\Group_Control_Border;
use \Elementor\Group_Control_Box_Shadow;
/**
 *
 * Header Widget . 
 *
 */
class Restar_Header extends Widget_Base {

	public function get_name() {
		return 'restarheader';
	}
	public function get_title() {
		return __( 'Header', 'restar' );
	}
	public function get_icon() {
		return 'th-icon';
    }
	public function get_categories() {
		return [ 'restar_header_elements' ];
	}

	protected function register_controls() {

		$this->start_controls_section(
			'layout_section',
			[
				'label' 	=> __( 'Header', 'restar' ),
				'tab' 		=> Controls_Manager::TAB_CONTENT,
			]
        );

		restar_select_field( $this, 'layout_style', 'Layout Style', ['Style One', 'Style Two'] );

		$this->add_control(
			'phone',
			[
				'label' 	=> __( 'Phone Number', 'restar' ),
				'type' 		=> Controls_Manager::TEXT,
				'default' 	=> __( '+987-82-18015', 'restar' ),
				'label_block' => true,
				'separator'		=> 'after',
				'condition'		=> [ 
					'layout_style' => ['1', '2']
				],
			]
		);
		$this->add_control(
			'phone_label',
			[
				'label' 	=> __( 'Phone Label', 'restar' ),
				'type' 		=> Controls_Manager::TEXT,
				'default' 	=> __( 'Contact us for reservation', 'restar' ),
				'label_block' => true,
				'separator'		=> 'after',
				'condition'		=> [ 
					'layout_style' => ['1', '2']
				],
			]
		);

		$this->add_control(
			'logo_image',

			[
				'label' 		=> __( 'Upload Logo', 'restar' ),
				'type' 			=> Controls_Manager::MEDIA,
			]
		);				

		$menus = $this->restar_menu_select();

		if( !empty( $menus ) ){
	        $this->add_control(
				'restar_menu_select',
				[
					'label'     	=> __( 'Select restar Menu', 'restar' ),
					'type'      	=> Controls_Manager::SELECT,
					'options'   	=> $menus,
					'description' 	=> sprintf( __( 'Go to the <a href="%s" target="_blank">Menus screen</a> to manage your menus.', 'restar' ), admin_url( 'nav-menus.php' ) ),
				]
			);
		}else {
			$this->add_control(
				'no_menu',
				[
					'type' 				=> Controls_Manager::RAW_HTML,
					'raw' 				=> '<strong>' . __( 'There are no menus in your site.', 'restar' ) . '</strong><br>' . sprintf( __( 'Go to the <a href="%s" target="_blank">Menus screen</a> to create one.', 'restar' ), admin_url( 'nav-menus.php?action=edit&menu=0' ) ),
					'separator' 		=> 'after',
					'content_classes' 	=> 'elementor-panel-alert elementor-panel-alert-info',
				]
			);
		}

		$this->add_control(
			'show_search_btn',
			[
				'label' 		=> __( 'Show Search Button?', 'restar' ),
				'type' 			=> Controls_Manager::SWITCHER,
				'label_on' 		=> __( 'Show', 'restar' ),
				'label_off' 	=> __( 'Hide', 'restar' ),
				'return_value' 	=> 'yes',
				'default' 		=> 'yes',
			]
		);		

		$this->add_control(
			'show_cart_btn',
			[
				'label' 		=> __( 'Show Cart Button?', 'restar' ),
				'type' 			=> Controls_Manager::SWITCHER,
				'label_on' 		=> __( 'Show', 'restar' ),
				'label_off' 	=> __( 'Hide', 'restar' ),
				'return_value' 	=> 'yes',
				'default' 		=> 'yes',
			]
		);

		$this->add_control(
			'show_offcanvas_btn',
			[
				'label' 		=> __( 'Show Offcanvas Button?', 'restar' ),
				'type' 			=> Controls_Manager::SWITCHER,
				'label_on' 		=> __( 'Show', 'restar' ),
				'label_off' 	=> __( 'Hide', 'restar' ),
				'return_value' 	=> 'yes',
				'default' 		=> 'yes',
			]
		);

		$this->add_control(
			'button_text',
			[
				'label' 		=> __( 'Button Text', 'restar' ),
				'type' 			=> Controls_Manager::TEXT,
				'label_block' 	=> true,
				'default' 	=> __( 'Contact Us', 'restar' ),
				'condition'		=> [ 
					'layout_style' => ['1']
				],
			]
		);

		$this->add_control(
			'button_url',
			[
				'label' 		=> esc_html__( 'Button Link', 'restar' ),
				'type' 			=> Controls_Manager::URL,
				'placeholder' 	=> esc_html__( 'https://your-link.com', 'restar' ),
				'show_external' => true,
				'default' 		=> [
					'url' 			=> '#',
					'is_external' 	=> false,
					'nofollow' 		=> false,
				],
				'condition'		=> [ 
					'layout_style' => ['1']
				],
			]
		);

        $this->end_controls_section();

		//---------------------------------------
			//Style Section Start
		//---------------------------------------

		//-------General Style-------
		 $this->start_controls_section(
			'general_styling',
			[
				'label'     => __( 'Background Styling', 'restar' ),
				'tab'       => Controls_Manager::TAB_STYLE,
			]
        );

		restar_color_fields( $this, 'menu_bg', 'Background', 'background', '{{WRAPPER}} .menu-area', ['1'] );                      

		$this->end_controls_section();

		//------Menu Bar Style-------
        $this->start_controls_section(
			'menubar_styling2',
			[
				'label'     => __( 'Menu Styling', 'restar' ),
				'tab'       => Controls_Manager::TAB_STYLE,
			]
        );

		restar_color_fields( $this, 'menu_color1', 'Color', 'color', '{{WRAPPER}} .main-menu>ul>li>a', ['1'] );
		restar_color_fields( $this, 'menu_color2', 'Hover Color', 'color', '{{WRAPPER}} .main-menu>ul>li>a:hover', ['1'] );
		restar_color_fields( $this, 'menu_color3', 'Dropdown Color', 'color', '{{WRAPPER}} .main-menu ul.sub-menu li a' );
		restar_color_fields( $this, 'menu_color4', 'Dropdown Hover Color', 'color', '{{WRAPPER}} .main-menu ul.sub-menu li a:hover' );
		restar_color_fields( $this, 'menu_color5', 'Menu Icon Color', 'color', '{{WRAPPER}} .main-menu ul.sub-menu li a:before, {{WRAPPER}} .main-menu ul li.menu-item-has-children > a:after' );

		restar_typography_fields( $this, 'menu_font', 'Menu Trpography', '{{WRAPPER}} .main-menu>ul>li>a, {{WRAPPER}} .main-menu ul.sub-menu li a' );

		restar_dimensions_fields( $this, 'menu_margin', 'Menu Margin', 'margin', '{{WRAPPER}} .main-menu>ul>li>a' );
		restar_dimensions_fields( $this, 'menu_padding', 'Menu Padding', 'padding', '{{WRAPPER}} .main-menu>ul>li>a' );

		$this->end_controls_section();

		//------Button Style-------
		restar_button_style_fields( $this, '12', 'Button Styling', '{{WRAPPER}} .th_btn' );

    }

    public function restar_menu_select(){
	    $restar_menu = wp_get_nav_menus();
	    $menu_array  = array();
		$menu_array[''] = __( 'Select A Menu', 'restar' );
	    foreach( $restar_menu as $menu ){
	        $menu_array[ $menu->slug ] = $menu->name;
	    }
	    return $menu_array;
	}

	protected function render() {

        $settings = $this->get_settings_for_display();

		global $woocommerce;

        //Menu by menu select
        $restar_avaiable_menu   = $this->restar_menu_select();
		if( ! $restar_avaiable_menu ){
			return;
		}
		$args = [
			'menu' 			=> $settings['restar_menu_select'],
			'menu_class' 	=> 'restar-menu',
			'container' 	=> '',
		];

		//Mobile menu, Offcanvas, Search
        echo restar_mobile_menu();
		echo restar_header_cart_offcanvas();
		if(!empty( $settings['show_offcanvas_btn'])){
			echo restar_header_offcanvas();
		}
		if(!empty( $settings['show_search_btn'])){
			echo restar_search_box();
		}
		// Header sub-menu icon
		if( class_exists( 'ReduxFramework' ) ){ 
			if(restar_opt('restar_header_sticky')){
                $sticky = '';
            }else{
                $sticky = '-no';
            }

			if(restar_opt('restar_menu_icon')){
				$menu_icon = '';
			}else{
				$menu_icon = 'hide-icon';
			}
		}

		$phone = $settings['phone'] ? $settings['phone'] : '';    
		$replace        = array(' ','-',' - ');
		$replace_phone  = array(' ','-',' - ', '(', ')');
		$with           = array('','','');
		$phoneurl       = str_replace( $replace_phone, $with, $phone );	

		if( $settings['layout_style'] == '1' ){
			echo '<div class="th-header header-layout2">';
				echo '<div class="sticky-wrapper'.esc_attr($sticky).'">';
					echo '<!-- Main Menu Area -->';
					echo '<div class="menu-area">';
						echo '<div class="container">';
							echo '<div class="row align-items-center justify-content-between">';
								echo '<div class="col-auto">';
									echo '<div class="header-logo">';
										echo '<a href="'.esc_url( home_url( '/' ) ).'">';
											echo restar_img_tag( array(
												'url'   => esc_url( $settings['logo_image']['url'] ),
											));
										echo '</a>';
									echo '</div>';
								echo '</div>';
								echo '<div class="col-auto">';
									echo '<nav class="main-menu d-none d-lg-inline-block '.esc_attr($menu_icon).'">';
										if( ! empty( $settings['restar_menu_select'] ) ){
											wp_nav_menu( $args );
										} else {
											wp_nav_menu( array(
												"theme_location"    => 'primary-menu',
												"container"         => '',
												"menu_class"        => ''
											) );
										}
									echo '</nav>';
								echo '</div>';
								echo '<div class="col-auto">';
									echo '<div class="header-button">';
										if (!empty( $settings['show_search_btn'])) {
											echo '<button type="button" class="icon-btn searchBoxToggler d-none d-xl-block"><i class="far fa-search"></i></button>';
										}
										if (!empty( $settings['show_cart_btn'])) {
											if( class_exists( 'woocommerce' ) ){
												global $woocommerce;
												if( ! empty( $woocommerce->cart->cart_contents_count ) ){
													$count = $woocommerce->cart->cart_contents_count;
												}else{
													$count = "0";
												}
												echo '<button type="button" class="icon-btn sideMenuToggler">';
													echo '<span class="badge cart_badge">'.esc_html( $count ).'</span>';
													echo '<i class="far fa-cart-shopping"></i>';
												echo '</button>'; 
											}
										}

										if(!empty($phone)){
											echo '<div class="header-call">';
												echo '<h3 class="box-title"><a href="'.esc_attr('tel:' . $phoneurl).'"><span class="icon"></span> '.esc_html($phone).'</a></h3>';
												echo '<p class="box-text">'.wp_kses_post($settings['phone_label']).'</p>';
											echo '</div>';
										}
										

										if(!empty( $settings['button_text'])){
											echo '<a href="'.esc_url($settings['button_url']['url']).'" class="th-btn  d-none d-xl-block th_btn">'.wp_kses_post($settings['button_text']).'</a>';
										}
										echo '<button type="button" class="th-menu-toggle d-block d-lg-none"><i class="far fa-bars"></i></button>';
									echo '</div>';
								echo '</div>';
							echo '</div>';
						echo '</div>';
					echo '</div>';
				echo '</div>';
			echo '</div>';
			
		} elseif( $settings['layout_style'] == '2' ) {
			echo '<div class="th-header header-layout3">';
				echo '<div class="sticky-wrapper'.esc_attr($sticky).'">';
					echo '<!-- Main Menu Area -->';
					echo '<div class="menu-area">';
						echo '<div class="w-100">';
							echo '<div class="row align-items-center justify-content-between">';
								echo '<div class="col-auto">';
									echo '<div class="header-logo">';
										echo '<a href="'.esc_url( home_url( '/' ) ).'">';
											echo restar_img_tag( array(
												'url'   => esc_url( $settings['logo_image']['url'] ),
											));
										echo '</a>';
									echo '</div>';
								echo '</div>';
								echo '<div class="col-auto">';
									echo '<nav class="main-menu d-none d-lg-inline-block '.esc_attr($menu_icon).'">';
										if( ! empty( $settings['restar_menu_select'] ) ){
											wp_nav_menu( $args );
										} else {
											wp_nav_menu( array(
												"theme_location"    => 'primary-menu',
												"container"         => '',
												"menu_class"        => ''
											) );
										}
									echo '</nav>';
								echo '</div>';
								echo '<div class="col-auto">';
									echo '<div class="header-button">';
										if (!empty( $settings['show_search_btn'])) {
											echo '<form role="search" method="get" action="'.esc_url( home_url( '/' ) ).'" class="header-search">';
												echo '<input value="'.esc_html( get_search_query() ).'" name="s" required type="search" placeholder="'.esc_attr__('Enter Keyword', 'restar').'">';
												echo '<button type="submit"><i class="far fa-search"></i></button>';
											echo '</form>';
										}
										if (!empty( $settings['show_cart_btn'])) {
											if( class_exists( 'woocommerce' ) ){
												global $woocommerce;
												if( ! empty( $woocommerce->cart->cart_contents_count ) ){
													$count = $woocommerce->cart->cart_contents_count;
												}else{
													$count = "0";
												}
												echo '<button type="button" class="icon-btn sideMenuToggler">';
													echo '<span class="badge cart_badge">'.esc_html( $count ).'</span>';
													echo '<i class="far fa-cart-shopping"></i>';
												echo '</button>'; 
											}
										}

										if(!empty($phone)){
											echo '<div class="header-call">';
												echo '<h3 class="box-title"><a href="'.esc_attr('tel:' . $phoneurl).'"><span class="icon"></span> '.esc_html($phone).'</a></h3>';
												echo '<p class="box-text">'.wp_kses_post($settings['phone_label']).'</p>';
											echo '</div>';
										}
										
										if (!empty( $settings['show_offcanvas_btn'])) {
											echo '<button type="button" class="square-btn sideMenuInfo">';
												echo '<i class="fal fa-bars"></i>';
											echo '</button>';
										}
										
										echo '<button type="button" class="th-menu-toggle d-block d-lg-none"><i class="far fa-bars"></i></button>';
									echo '</div>';
								echo '</div>';
							echo '</div>';
						echo '</div>';
					echo '</div>';
				echo '</div>';
			echo '</div>';

		}


	}
}
Page not found – Hello World !