<?php
/**
 * @package MegaMain
 * @subpackage MegaMain
 * @since mm 1.0
 */

	/** 
	 * actions what we need for call all functions in this file.
	 * @return void
	 */
	global $mega_main_menu;
	if ( is_array( $mega_main_menu->get_option( 'coercive_styles' ) ) && in_array( 'true', $mega_main_menu->get_option( 'coercive_styles', array() ) ) ) {
		remove_all_filters( 'wp_nav_menu_items', 1900 ); 
		remove_all_filters( 'wp_nav_menu_args', 1900 ); 
	}
	add_filter( 'wp_nav_menu_items', 'mmm_nav_search', 2000, 8 );
	add_filter( 'wp_nav_menu_items', 'mmm_nav_woo_cart', 2010, 8 );
	add_filter( 'wp_nav_menu_items', 'mmm_nav_buddypress', 2020, 8 );
	add_filter( 'wp_nav_menu_items', 'mmm_nav_wpml_switcher', 2030, 8 );
	add_filter( 'wp_nav_menu_args', 'mmm_set_walkers', 3000000, 8 ); 

	if ( function_exists( 'theme_get_menu' ) && function_exists( 'theme_get_list_menu' ) ) {
		$mega_menu_locations = $mega_main_menu->get_option( 'mega_menu_locations' );
		static $mega_menu_location_id = 0;
		$mega_menu_location_id ++;
		$indefinite_location_mode = ( is_array( $mega_main_menu->get_option( 'indefinite_location_mode' ) ) && in_array( 'true', $mega_main_menu->get_option( 'indefinite_location_mode' ) ) ) ? true : false;
		if ( isset( $mega_menu_locations[ $mega_menu_location_id ] ) && ( $indefinite_location_mode === true ) ) {
			$args['theme_location'] = $mega_menu_locations[ $mega_menu_location_id ];
			$args['echo'] = false;
			$GLOBALS['wp_nav_menu_html'] = wp_nav_menu( $args );
			function artisteer_nav_menu () {
				global $wp_nav_menu_html;
				return $wp_nav_menu_html;
			}
			add_filter( 'wp_nav_menu', 'artisteer_nav_menu', 50 );
		}
	}
	/** 
	 * Check current location and set args.
	 * @return $items
	 */
	function mmm_set_walkers ( $args ){
		global $mega_main_menu;
		$args = (array)$args;
		$mega_menu_locations = $mega_main_menu->get_option( 'mega_menu_locations', array() );
		$indefinite_location_mode = ( is_array( $mega_main_menu->get_option( 'indefinite_location_mode' ) ) && in_array( 'true', $mega_main_menu->get_option( 'indefinite_location_mode' ) ) ) ? true : false;
		$theme_location_safe_name = str_replace( ' ', '-', $args['theme_location'] );

		static $mega_menu_location_id = 0;
		$mega_menu_location_id ++;
		if ( $indefinite_location_mode === true && isset( $args['theme_location'] ) && $args['theme_location'] == '' && isset( $mega_menu_locations[ 1 ] ) ) {
			$args['theme_location'] = $mega_menu_locations[ $mega_menu_location_id ];
			$theme_location_safe_name = $mega_menu_locations[ $mega_menu_location_id ];
			$container_class[] = $mega_menu_locations[ $mega_menu_location_id ];
		}

		if ( ( is_array( $mega_menu_locations ) && in_array( $theme_location_safe_name, $mega_menu_locations ) ) || ( $indefinite_location_mode === true ) || ( $args['theme_location'] == 'mega_main_sidebar_menu' ) || ( $args['theme_location'] == 'mega_main_flyout_menu' ) ) {

			// Default args
			$args['items_wrap'] = '<ul id="%1$s" class="%2$s" role="menubar" aria-label="' . $mega_main_menu->get_option( $theme_location_safe_name . '_mobile_label', 'Main Menu' ) . '">%3$s</ul>';
			$args['walker'] = new Mega_Main_Menu_Frontend_Walker;
			$args['container'] = false;
			$args['container_id'] = '';
			$args['container_class'] = '';
			$args['menu_id'] = 'main_ul-' . $theme_location_safe_name;
			$args['menu_class'] = 'mega_main_menu_ul';
			$args['before'] = '';
			$args['after'] = '';
			$args['link_before'] = '';
			$args['link_after'] = '';
			$args['depth'] = 9;

			// check container_class variables
			$container_class[] = $theme_location_safe_name;
			$container_class[] = 'primary_style-' . $mega_main_menu->get_option( $theme_location_safe_name . '_primary_style', 'flat' );
			$container_class[] = 'icons-' . $mega_main_menu->get_option( $theme_location_safe_name . '_first_level_icons_position', 'left' );
			$container_class[] = 'first-lvl-align-' . $mega_main_menu->get_option( $theme_location_safe_name . '_first_level_item_align', 'left' );
			$container_class[] = 'first-lvl-separator-' . $mega_main_menu->get_option( $theme_location_safe_name . '_first_level_separator', 'none' );
			$container_class[] = 'direction-' . $mega_main_menu->get_option( $theme_location_safe_name . '_direction', 'horizontal' );
			$container_class[] = 'fullwidth-' . ( ( is_array( $mega_main_menu->get_option( $theme_location_safe_name . '_fullwidth_container' ) ) && in_array( 'true', $mega_main_menu->get_option( $theme_location_safe_name . '_fullwidth_container' ) ) ) ? 'enable' : 'disable' );
			$container_class[] = 'pushing_content-' . ( ( is_array( $mega_main_menu->get_option( $theme_location_safe_name . '_pushing_content' ) ) && in_array( 'true', $mega_main_menu->get_option( $theme_location_safe_name . '_pushing_content' ) ) ) ? 'enable' : 'disable' );
			$container_class[] = 'mobile_minimized-' . ( ( ( is_array( $mega_main_menu->get_option( $theme_location_safe_name . '_mobile_minimized' ) ) && in_array( 'true', $mega_main_menu->get_option( $theme_location_safe_name . '_mobile_minimized' ) ) ) || ( $indefinite_location_mode === true ) ) ? 'enable' : 'disable' );
			$container_class[] = 'dropdowns_trigger-' . $mega_main_menu->get_option( $theme_location_safe_name . '_dropdowns_trigger', 'hover' ) ;
			$container_class[] = 'dropdowns_animation-' . $mega_main_menu->get_option( $theme_location_safe_name . '_dropdowns_animation', 'none' ) ;
/*
			$container_class[] = ( ( is_array( $mega_main_menu->get_option( $theme_location_safe_name . '_included_components' ) ) && in_array( 'company_logo', $mega_main_menu->get_option( $theme_location_safe_name . '_included_components' ) ) ) && $mega_main_menu->get_option( 'logo_src' ) ) ? 'include-logo' : 'no-logo';
*/
			$container_class[] = ( ( in_array( $theme_location_safe_name, $mega_menu_locations) ) && is_array( $mega_main_menu->get_option( $theme_location_safe_name . '_included_components' ) ) && in_array( 'search_box', $mega_main_menu->get_option( $theme_location_safe_name . '_included_components' ) ) ) ? 'include-search' : 'no-search';
			$container_class[] = ( ( in_array( $theme_location_safe_name, $mega_menu_locations) ) && is_array( $mega_main_menu->get_option( $theme_location_safe_name . '_included_components' ) ) && in_array( 'woo_cart', $mega_main_menu->get_option( $theme_location_safe_name . '_included_components' ) ) ) ? 'include-woo_cart' : 'no-woo_cart';
			$container_class[] = ( ( in_array( $theme_location_safe_name, $mega_menu_locations) ) && is_array( $mega_main_menu->get_option( $theme_location_safe_name . '_included_components' ) ) && in_array( 'buddypress', $mega_main_menu->get_option( $theme_location_safe_name . '_included_components' ) ) ) ? 'include-buddypress' : 'no-buddypress';
			$container_class[] = 'responsive-' . ( ( is_array( $mega_main_menu->get_option( 'responsive_styles' ) ) && in_array( 'true', $mega_main_menu->get_option( 'responsive_styles' ) ) ) ? 'enable' : 'disable' );
			$container_class[] = 'coercive_styles-' . ( ( is_array( $mega_main_menu->get_option( 'coercive_styles' ) ) && in_array( 'true', $mega_main_menu->get_option( 'coercive_styles' ) ) ) ? 'enable' : 'disable' );
			$container_class[] = 'indefinite_location_mode-' . ( ( $indefinite_location_mode === true ) ? 'enable' : 'disable' );
			$container_class[] = 'language_direction-' . $mega_main_menu->get_option( 'language_direction', 'ltr' );
			$container_class[] = 'version-' . str_replace('.', '-', $mega_main_menu->constant['MM_WARE_VERSION'] );
			if ( in_array( 'disable', $mega_main_menu->get_option( 'item_icon', array() ) ) ) {
				$container_class[] = 'structure_settings-no_icons icons-disable_globally';
				
			}
			foreach ( $mega_main_menu->get_option( $theme_location_safe_name . '_logo_positions', array( 'desktop', 'sticky', 'mobile', ) ) as $key => $value ) {
				if ( $value != 'is_checkbox' ) {
					$container_class[] = 'logo-' . $value;
				}
			}

			// implode container_class variables
			$container_class_imploded = implode( ' ', $container_class );

			// apply_filters container_class
			if ( has_filter( 'mmm_container_class' ) ) {
				$container_class_imploded .= ' ' . esc_attr( apply_filters( 'mmm_container_class', $container_class, $container_class ) );
			}

			// check sticky variables
			$data_sticky = ( (is_array( $mega_main_menu->get_option( $theme_location_safe_name . '_sticky_status' ) ) && in_array( 'true', $mega_main_menu->get_option( $theme_location_safe_name . '_sticky_status', array() ) ) ) /*|| ( $indefinite_location_mode === true )*/ ) 
				? ' data-sticky="1"' 
				: '';
			$data_sticky .= ( ( $mega_main_menu->get_option( $theme_location_safe_name . '_sticky_offset' ) !== false && is_array( $mega_main_menu->get_option( $theme_location_safe_name . '_sticky_status' ) ) && in_array( 'true', $mega_main_menu->get_option( $theme_location_safe_name . '_sticky_status', array() ) ) ) || ( $indefinite_location_mode === true ) ) 
				? ' data-stickyoffset="' . $mega_main_menu->get_option( $theme_location_safe_name . '_sticky_offset' ) . '"' 
				: '';

			// items_wrap (container) markup
			$items_wrap = '';
			$items_wrap .= mm_common::ntab(0) . '<!-- begin "mega_main_menu" -->';
			$items_wrap .= mm_common::ntab(0) . '<div id="' . $theme_location_safe_name . '" class="mega_main_menu ' . $container_class_imploded . ' mega_main">';
			$items_wrap .= mm_common::ntab(1) . '<div class="menu_holder"' . $data_sticky . '>';
			$items_wrap .= mm_common::ntab(1) . '<div class="mmm_fullwidth_container"></div><!-- class="fullwidth_container" -->';
			$items_wrap .= mm_common::ntab(2) . '<div class="menu_inner" role="navigation">';
			$items_wrap .= mm_common::ntab(3) . '<span class="nav_logo">';
			if( $mega_main_menu->get_option( $theme_location_safe_name . '_logo_src' ) ) {
					$items_wrap .= mm_common::ntab(4) . '<a class="logo_link" href="' . home_url() . '" title="' . get_bloginfo( 'name' ) . '">';
					$items_wrap .= mm_common::ntab(5) . '<img src="' . str_replace( array('%','$'), array('',''), $mega_main_menu->get_option( $theme_location_safe_name . '_logo_src' ) ) . '" alt="' . get_bloginfo( 'name' ) . '" />';
					$items_wrap .= mm_common::ntab(4) . '</a>';
			}
			$items_wrap .= mm_common::ntab(4) . '<span class="mobile_toggle" data-target="#' . $args['menu_id'] . '" aria-expanded="false" aria-controls="' . $args['menu_id'] . '">';
			$items_wrap .= mm_common::ntab(5) . '<span class="mobile_button">';
			$items_wrap .= mm_common::ntab(6) . $mega_main_menu->get_option( $theme_location_safe_name . '_mobile_label', 'Menu' ) . ' &nbsp;';
			$items_wrap .= mm_common::ntab(6) . '<span class="symbol_menu">&equiv;</span>'; // "Open menu" symbol
			$items_wrap .= mm_common::ntab(6) . '<span class="symbol_cross">&#x2573;</span>'; // "Close menu" symbol
			$items_wrap .= mm_common::ntab(5) . '</span><!-- class="mobile_button" -->';
			$items_wrap .= mm_common::ntab(4) . '</span><!-- /class="mobile_toggle" -->';
			$items_wrap .= mm_common::ntab(3) . '</span><!-- /class="nav_logo" -->';
			$items_wrap .= mm_common::ntab(4) . $args['items_wrap'];
			$items_wrap .= mm_common::ntab(2) . '</div><!-- /class="menu_inner" -->';
			$items_wrap .= mm_common::ntab(1) . '</div><!-- /class="menu_holder" -->';
			$items_wrap .= mm_common::ntab(0) . '</div><!-- /id="mega_main_menu" -->';

			// items_wrap (container) markup
			$args['items_wrap'] = $items_wrap;
			$args['container_class'] = $container_class_imploded;
		}
		return $args;
	}

	/** 
	 * Include search box in menu.
	 * @return $items
	 */
	function mmm_nav_search( $items, $args ) {
		global $mega_main_menu;
		$args = (object) $args;
		if( isset( $args->theme_location ) ) {
			$args->theme_location = str_replace( ' ', '-', $args->theme_location );
			$mega_menu_locations = is_array( $mega_main_menu->get_option( 'mega_menu_locations' ) ) ? $mega_main_menu->get_option( 'mega_menu_locations' ) : array();
			if( ( in_array( $args->theme_location, $mega_menu_locations) ) && is_array( $mega_main_menu->get_option( $args->theme_location . '_included_components' ) ) && in_array( 'search_box', $mega_main_menu->get_option( $args->theme_location . '_included_components' ) ) ) {
				$icon_sets = $mega_main_menu->get_option( 'icon_sets', array() );
				$icon = 'custom_icon_search';
				if ( in_array( 'icomoon', $icon_sets ) ) {
					$icon = 'im-icon-search-3';
				} elseif ( in_array( 'fontawesome', $icon_sets ) ) {
					$icon = 'fa-icon-search';
				} elseif ( in_array( 'glyphicons', $icon_sets ) ) {
					$icon = 'glyphicon-search';
				}
				$searchform = '';
				$searchform .= mm_common::ntab(1) . '<li class="nav_search_box">';
				$searchform .= mm_common::ntab(2) . '<form method="get" class="mega_main_menu_searchform" action="' . esc_url( home_url( '/' ) ) . '">';
				$searchform .= mm_common::ntab(3) . '<i class="' . $icon . ' icosearch"></i>';
				$searchform .= mm_common::ntab(3) . '<input type="text" class="field" name="s" id="s" />';
				$searchform .= mm_common::ntab(3) . '<input type="submit" class="submit" name="submit" id="searchsubmit" value="' . esc_attr__( 'Search', 'mega_main_menu' ) . '" />';
				$searchform .= mm_common::ntab(2) . '</form>';
				$searchform .= mm_common::ntab(1) . '</li><!-- class="nav_search_box" -->' . mm_common::ntab(0);
				$items = $items . $searchform;
			}
		}
		return $items;
	}

	/** 
	 * Include woo_cart in menu.
	 * @return $items
	 */
	function mmm_nav_woo_cart( $items, $args ) {
		global $mega_main_menu;
		$args = (object) $args;
		if( isset( $args->theme_location ) ) {
			$args->theme_location = str_replace( ' ', '-', $args->theme_location );
			$mega_menu_locations = is_array( $mega_main_menu->get_option( 'mega_menu_locations' ) ) ? $mega_main_menu->get_option( 'mega_menu_locations' ) : array();
			if( (in_array( $args->theme_location, $mega_menu_locations) ) && is_array( $mega_main_menu->get_option( $args->theme_location . '_included_components' ) ) && in_array( 'woo_cart', $mega_main_menu->get_option( $args->theme_location . '_included_components' ) ) ) {
				if ( class_exists( 'Woocommerce' ) ){
					global $woocommerce;
					$cart_contents_count = $woocommerce->cart->get_cart_contents_count();
					$drop_side = ( $mega_main_menu->get_option( 'language_direction', 'ltr' ) == 'ltr' ) ? 'drop_to_left' : 'drop_to_right';
					$icon_sets = $mega_main_menu->get_option( 'icon_sets', array() );
					$icon = 'custom_icon_cart';
					if ( in_array( 'icomoon', $icon_sets ) ) {
						$icon = 'im-icon-cart';
					} elseif ( in_array( 'fontawesome', $icon_sets ) ) {
						$icon = 'fa-icon-shopping-cart';
					} elseif ( in_array( 'glyphicons', $icon_sets ) ) {
						$icon = 'glyphicon-shopping-cart';
					}
					$woo_cart_item = mm_common::ntab(1) . '<li class="menu-item nav_woo_cart multicolumn_dropdown ' . $drop_side . ' submenu_default_width">';
					if ( $cart_contents_count > 0 ) {
						$woo_cart_item .= mm_common::ntab(2) . '<span tabindex="0" class="item_link with_icon">'; 
						$woo_cart_item .= mm_common::ntab(3) . '<i class="' . $icon . '"></i> '; 
						$woo_cart_item .= mm_common::ntab(3) . '<span class="link_content">'; 
						$woo_cart_item .= mm_common::ntab(4) . '<span class="link_text">'; 
						$woo_cart_item .= mm_common::ntab(5) . $cart_contents_count; 
						$woo_cart_item .= mm_common::ntab(3) . '</span>'; 
						$woo_cart_item .= mm_common::ntab(3) . '</span>'; 
						$woo_cart_item .= mm_common::ntab(2) . '</span><!-- class="item_link" -->'; 
					} else {
						$woo_cart_item .= mm_common::ntab(2) . '<span tabindex="0" class="item_link menu_item_without_text">'; 
						$woo_cart_item .= mm_common::ntab(3) . '<i class="' . $icon . '"></i> '; 
						$woo_cart_item .= mm_common::ntab(2) . '</span><!-- class="item_link" -->'; 
					}
					$woo_cart_item .= mm_common::ntab(2) . '<ul class="mega_dropdown">';
					$woo_cart_item .= mm_common::ntab(3) . '<div class="woocommerce">';
					$woo_cart_item .= mm_common::ntab(3) . '<div class="widget_shopping_cart_content"></div>';
					$woo_cart_item .= mm_common::ntab(3) . '</div><!-- class="woocommerce" -->';
					$woo_cart_item .= mm_common::ntab(2) . '</ul><!-- class="mega_dropdown" -->';
					$woo_cart_item .= mm_common::ntab(1) . '</li><!-- class="nav_woo_cart" -->';
					$items = $items . $woo_cart_item;
				}
			}
		}
		return $items;
	}

	/** 
	 * Include WPML switcher in menu.
	 * @return $items
	 */
	function mmm_nav_wpml_switcher ( $items, $args ) {
		global $mega_main_menu;
		$args = (object) $args;
		if( isset( $args->theme_location ) ) {
			$args->theme_location = str_replace( ' ', '-', $args->theme_location );
			$mega_menu_locations = is_array( $mega_main_menu->get_option( 'mega_menu_locations' ) ) ? $mega_main_menu->get_option( 'mega_menu_locations' ) : array();
			if( ( in_array( $args->theme_location, $mega_menu_locations) ) && is_array( $mega_main_menu->get_option( $args->theme_location . '_included_components' ) ) && in_array( 'wpml_switcher', $mega_main_menu->get_option( $args->theme_location . '_included_components' ) ) ) {
				if ( function_exists( 'icl_get_languages' ) ){
					$languages = icl_get_languages('skip_missing=0');
					if ( 1 < count( $languages ) ) {
						$wpml_switcher_dropdown = '';
						foreach( $languages as $l ){
							$wpml_switcher_dropdown .= mm_common::ntab(3) . '<li class="menu-item">';
							$wpml_switcher_dropdown .= mm_common::ntab(4) . '<a href="' . $l[ 'url' ] . '" title="' . $l[ 'translated_name' ] . '" tabindex="0" class="item_link with_icon">';
							$wpml_switcher_dropdown .= mm_common::ntab(3) . '<i class="ci-icon-' . $l[ 'language_code' ] . '"><style>.ci-icon-' . $l[ 'language_code' ] . ':before{ background-image: url("' . $l[ 'country_flag_url' ] . '"); }</style></i>';
							$wpml_switcher_dropdown .= mm_common::ntab(5) . '<span class="link_content">';
							$wpml_switcher_dropdown .= mm_common::ntab(6) . '<span class="link_text">' . $l[ 'native_name' ] . '</span>';
							$wpml_switcher_dropdown .= mm_common::ntab(5) . '</span>';
							$wpml_switcher_dropdown .= mm_common::ntab(4) . '</a><!-- class="item_link" -->';
							$wpml_switcher_dropdown .= mm_common::ntab(3) . '</li>';
							if ( $l[ 'active' ] == 1 ) {
								$primary_item[ 'language_code' ] = $l[ 'language_code' ];
								$primary_item[ 'translated_name' ] = $l[ 'translated_name' ];
								$primary_item[ 'country_flag_url' ] = $l[ 'country_flag_url' ];
							}
						}

						$drop_side = ( $mega_main_menu->get_option( 'language_direction', 'ltr' ) == 'ltr' ) ? 'drop_to_left' : 'drop_to_right';
						$wpml_switcher_item = mm_common::ntab(1) . '<li class="menu-item nav_wpml_switcher default_dropdown ' . $drop_side . ' submenu_default_width">';
						$wpml_switcher_item .= mm_common::ntab(2) . '<span class="item_link menu_item_without_text">'; 
						$wpml_switcher_item .= mm_common::ntab(3) . '<i class="ci-icon-' . $primary_item[ 'language_code' ] . '"><style>.ci-icon-' . $primary_item[ 'language_code' ] . ':before{ background-image: url("' . $primary_item[ 'country_flag_url' ] . '"); }</style></i>'; 
						$wpml_switcher_item .= mm_common::ntab(2) . '</span><!-- class="item_link" -->'; 
						$wpml_switcher_item .= mm_common::ntab(2) . '<ul class="mega_dropdown">';
						$wpml_switcher_item .= $wpml_switcher_dropdown;
						$wpml_switcher_item .= mm_common::ntab(2) . '</ul><!-- class="mega_dropdown" -->';
						$wpml_switcher_item .= mm_common::ntab(1) . '</li><!-- class="nav_wpml_switcher" -->';
						$items = $items . $wpml_switcher_item;
					}
				}
			}
		}
		return $items;
	}

	/** 
	 * Include buddypress in menu.
	 * @return $items
	 */
	function mmm_nav_buddypress( $items, $args ) {
		global $mega_main_menu;
		$args = (object) $args;
		if( isset( $args->theme_location ) ) {
			$args->theme_location = str_replace( ' ', '-', $args->theme_location );
			$mega_menu_locations = is_array( $mega_main_menu->get_option( 'mega_menu_locations' ) ) ? $mega_main_menu->get_option( 'mega_menu_locations' ) : array();
			if( (in_array( $args->theme_location, $mega_menu_locations) ) && is_array( $mega_main_menu->get_option( $args->theme_location . '_included_components' ) ) && in_array( 'buddypress', $mega_main_menu->get_option( $args->theme_location . '_included_components' ) ) ) {
				if ( class_exists( 'BuddyPress' ) ){
					global $bp;
					$bp_avatar = bp_core_fetch_avatar( array( 'item_id'=>$bp->loggedin_user->id, 'html'=>false ) );
					if ( strpos( $bp_avatar, 'gravatar' ) !== false ) {
						$bp_avatar = $bp->avatar->thumb->default;
					}
					$buddypress_item = '';
					$drop_side = ( $mega_main_menu->get_option( 'language_direction', 'ltr' ) == 'ltr' ) ? 'drop_to_left' : 'drop_to_right';
					if ( is_user_logged_in() ) {
						$notifications = bp_notifications_get_notifications_for_user( bp_loggedin_user_id(), 'object' );
						$count = ! empty( $notifications ) ? count( $notifications ) : 0;
						$menu_link = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() );
						$notification_class = (int) $count > 0 ? 'notification-yes' : 'notification-none';

						$buddypress_item .= mm_common::ntab(1) . '<li class="menu-item nav_buddypress default_dropdown ' . $drop_side . ' submenu_default_width">';
						$buddypress_item .= mm_common::ntab(2) . '<a href="' . $menu_link . '" tabindex="0" class="item_link ">';
						$buddypress_item .= mm_common::ntab(3) . '<i class="ci-icon-buddypress-user"><style>.ci-icon-buddypress-user:before{ background-image: url("' . $bp_avatar . '"); }</style><span class="mega_notifications ' . $notification_class . '">' . $count . '</span></i>';
						$buddypress_item .= mm_common::ntab(3) . '';
						$buddypress_item .= mm_common::ntab(2) . '</a><!--  class="item_link" -->';
						$buddypress_item .= mm_common::ntab(2) . '<ul class="mega_dropdown">';

						if ( version_compare( $bp->version, '2.6' ) ) {
							// for BuddyPress versions that later than 2.6
							$bp = buddypress();
							$list_of_icons_for_bp = array(
								'activity' => 'health',
								'just-me' => 'health',
								'activity-mentions' => 'health',
								'activity-favs' => 'health',
								'xprofile' => 'user',
								'public' => 'user',
								'edit' => 'user',
								'change-avatar' => 'user',
								'change-cover-image' => 'image',
								'notifications' => 'notification-2',
								'notifications-my-notifications' => 'notification-2',
								'read' => 'envelop-opened',
								'settings' => 'cog',
								'general' => 'cog',
								'profile' => 'cog',
								'capabilities' => 'cog',
							);
							// Get the item nav and build the menus.
							foreach ( $bp->members->nav->get_item_nav() as $nav_menu ) {
								// Get the correct menu link. See https://buddypress.trac.wordpress.org/ticket/4624.
								$link = bp_loggedin_user_domain() ? str_replace( bp_loggedin_user_domain(), bp_displayed_user_domain(), $nav_menu->link ) : trailingslashit( bp_displayed_user_domain() . $nav_menu->link );
								// Add this menu.
								$buddypress_item .= mm_common::ntab(3) . '<li class="menu-item default_dropdown ' . strtolower( str_replace( ' ', '-', $nav_menu->css_id ) ) . ' ' . $drop_side . '">';
								$buddypress_item .= mm_common::ntab(4) . '<a href="' . $link . '" tabindex="0" class="item_link with_icon">';
								$buddypress_item .= mm_common::ntab(5) . '<i class="' . ( isset( $list_of_icons_for_bp[ $nav_menu->css_id ] ) ? 'im-icon-' . $list_of_icons_for_bp[ $nav_menu->css_id ] : 'im-icon-cog' ) . '"></i>';
								$buddypress_item .= mm_common::ntab(5) . '<span class="link_content">';
								$buddypress_item .= mm_common::ntab(6) . '<span class="link_text">' . $nav_menu->name . '</span>';
								$buddypress_item .= mm_common::ntab(5) . '</span>';
								$buddypress_item .= mm_common::ntab(4) . '</a><!-- class="item_link" -->';
								if ( ! empty( $nav_menu->children ) ) {
									$buddypress_item .= mm_common::ntab(4) . '<ul class="mega_dropdown">';
									foreach( $nav_menu->children as $sub_menu ) {
										// If we're viewing this item's screen, record that we need to mark its parent menu to be selected.
										$submenu_class = '';
										if ( $sub_menu->slug == bp_current_action() ) {
											$submenu_class = ' current-menu-item';
										}
										$buddypress_item .= mm_common::ntab(5) . '<li class="menu-item default_dropdown ' . $drop_side . $submenu_class . '">';
										$buddypress_item .= mm_common::ntab(6) . '<a href="' . $sub_menu->link . '" tabindex="0" class="item_link">';
										$buddypress_item .= mm_common::ntab(7) . '<span class="link_content">';
										$buddypress_item .= mm_common::ntab(8) . '<span class="link_text">' . $sub_menu->name . '</span>';
										$buddypress_item .= mm_common::ntab(7) . '</span>';
										$buddypress_item .= mm_common::ntab(6) . '</a><!-- class="item_link" -->';
										$buddypress_item .= mm_common::ntab(5) . '</li>';
									}
									$buddypress_item .= mm_common::ntab(4) . '</ul><!-- class="mega_dropdown" -->';
								}
								$buddypress_item .= mm_common::ntab(3) . '</li>';
							}
						} else {
							// for BuddyPress versions that earlier than 2.6
							if ( version_compare( $bp->version, '2.5' ) ) {
								$bp_nav_items = (array) $bp->members->nav;
								$bp_nav_items = current($bp_nav_items);
								$bp_nav_items = current($bp_nav_items);
							} else {
								$bp_nav_items = $bp->bp_nav;
							}
							foreach ( $bp_nav_items as $key => $component ) {
								if ( isset( $component[ 'slug' ] ) ) {
									switch ( $component[ 'slug' ] ) {
										case 'activity':
											$icon = 'health';
											break;
										case 'profile':
											$icon = 'user';
											break;
										case 'notifications':
											$icon = 'notification-2';
											break;
										case 'messages':
											$icon = 'envelop-opened';
											break;
										case 'friends':
											$icon = 'users';
											break;
										case 'groups':
											$icon = 'tree-5';
											break;
										default:
											$icon = 'cog';
											break;
									}
									$buddypress_item .= mm_common::ntab(3) . '<li class="menu-item default_dropdown ' . strtolower( str_replace( ' ', '-', $component[ 'name' ] ) ) . ' ' . $drop_side . '">';
									$buddypress_item .= mm_common::ntab(4) . '<a href="' . $component[ 'link' ] . '" tabindex="0" class="item_link with_icon">';
									$buddypress_item .= mm_common::ntab(5) . '<i class="im-icon-' . $icon . '"></i>';
									$buddypress_item .= mm_common::ntab(5) . '<span class="link_content">';
									$buddypress_item .= mm_common::ntab(6) . '<span class="link_text">' . $component[ 'name' ] . '</span>';
									$buddypress_item .= mm_common::ntab(5) . '</span>';
									$buddypress_item .= mm_common::ntab(4) . '</a><!-- class="item_link" -->';
									if ( is_array( $bp->bp_options_nav[ $component[ 'slug' ] ] ) ) {
										$buddypress_item .= mm_common::ntab(4) . '<ul class="mega_dropdown">';
										foreach ( $bp->bp_options_nav[ $component[ 'slug' ] ] as $key => $sub_component ) {
											$buddypress_item .= mm_common::ntab(5) . '<li class="menu-item default_dropdown ' . $drop_side . '">';
											$buddypress_item .= mm_common::ntab(6) . '<a href="' . $sub_component[ 'link' ] . '" tabindex="0" class="item_link">';
											$buddypress_item .= mm_common::ntab(7) . '<span class="link_content">';
											$buddypress_item .= mm_common::ntab(8) . '<span class="link_text">' . $sub_component[ 'name' ] . '</span>';
											$buddypress_item .= mm_common::ntab(7) . '</span>';
											$buddypress_item .= mm_common::ntab(6) . '</a><!-- class="item_link" -->';
											$buddypress_item .= mm_common::ntab(5) . '</li>';
										}
										$buddypress_item .= mm_common::ntab(4) . '</ul><!-- class="mega_dropdown" -->';
									}
									$buddypress_item .= mm_common::ntab(3) . '</li>';
								}
							}
						}

						$buddypress_item .= mm_common::ntab(3) . '<li class="menu-item">';
						$buddypress_item .= mm_common::ntab(4) . '<a href="' . wp_logout_url() . '" title="' . __( 'Log Out' ) . '" tabindex="0" class="item_link with_icon">';
						$buddypress_item .= mm_common::ntab(5) . '<i class="im-icon-switch"></i>';
						$buddypress_item .= mm_common::ntab(5) . '<span class="link_content">';
						$buddypress_item .= mm_common::ntab(6) . '<span class="link_text">';
						$buddypress_item .= mm_common::ntab(7) . __( 'Log Out' );
						$buddypress_item .= mm_common::ntab(6) . '</span>';
						$buddypress_item .= mm_common::ntab(5) . '</span>';
						$buddypress_item .= mm_common::ntab(4) . '</a>';
						$buddypress_item .= mm_common::ntab(3) . '</li>';
						$buddypress_item .= mm_common::ntab(2) . '</ul><!-- class="mega_dropdown" -->';
						$buddypress_item .= mm_common::ntab(1) . '</li><!-- class="nav_buddypress" -->' . mm_common::ntab(0);
					} else {
						$icon_sets = $mega_main_menu->get_option( 'icon_sets', array() );
						$icon = 'custom_icon_cart';
						if ( in_array( 'icomoon', $icon_sets ) ) {
							$icon = 'im-icon-user';
						} elseif ( in_array( 'fontawesome', $icon_sets ) ) {
							$icon = 'fa-icon-user';
						} elseif ( in_array( 'glyphicons', $icon_sets ) ) {
							$icon = 'glyphicon-user';
						}
						$buddypress_item .= mm_common::ntab(1) . '<li class="nav_buddypress not_logged default_dropdown ' . $drop_side . ' submenu_default_width">';
						$buddypress_item .= mm_common::ntab(2) . '<span class="item_link">';
						$buddypress_item .= mm_common::ntab(3) . '<i class="im-icon-user"></i>';
						$buddypress_item .= mm_common::ntab(2) . '</span><!--  class="item_link" -->';
						$buddypress_item .= mm_common::ntab(2) . '<ul class="mega_dropdown">';
						ob_start();
							the_widget( 'BP_Core_Login_Widget', array( 'title' => '' ), false );
							$form .= ob_get_contents();
						ob_end_clean();
						$buddypress_item .= mm_common::ntab(3) . $form;
						$buddypress_item .= mm_common::ntab(2) . '</ul><!-- class="mega_dropdown" -->';
						$buddypress_item .= mm_common::ntab(1) . '</li><!-- class="nav_buddypress" -->' . mm_common::ntab(0);
					}
					$items = $items . $buddypress_item;
				}
			}
		}
		return $items;
	}
?>