HEX
Server: nginx/1.28.1
System: Linux iZgw8b5bpgd4jyptfmmmxgZ 6.6.102-5.2.alnx4.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Nov 27 23:11:10 CST 2025 x86_64
User: www (1000)
PHP: 8.2.28
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.scdc-marine.com/wp-content/themes/heku-cms/HekuClass/View/NavMenu.php
<?php
namespace Heku\HekuClass\View;

/**
 * @package     Heku\HekuClass\View
 * @subpackage  Classes/NavMenu
 * @author      Heku Daleconan <http://www.daleconan.com>
 * @copyright   Copyright (c) 2022-2023, Heku Daleconan
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 */

class NavMenu extends \Walker_Nav_Menu {

	public $tree_type = array( 'post_type', 'taxonomy', 'custom' );
    public $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id' );
	/**
	 * 主列表包裹 li 标签 开始
	 * 	<li class=""> <span> </span>
	 */
	public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
		if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
			$t = '';
			$n = '';
		} else {
			$t = "\t";
			$n = "\n";
		}
		$indent = str_repeat( $t, $depth * 2 + $this->numtab() ) ;

		// 默认的 li 标签类。会被过滤器 过滤 apply_filters( 'nav_menu_css_class',"")
		$classes = empty( $item->classes ) ? array() : (array) $item->classes;
		$classes[] = 'menu-item-' . $item->ID;
		
        $current = array( "menu-item" , "current-menu-item" , "menu-item-has-children" );
        $classes = array_intersect( $classes , $current );

		//添加 第一层子菜单的类
        if($args->walker->has_children && $depth == 0){
			$child_item_type = heku_get_menu_option( $item->ID , 'menu_type' );
            if($child_item_type){
                $classes[] = 'heku-'.$child_item_type;
            }
		}

		//添加菜单深度的类
		$classes[] = 'depth-' . $depth;

		if( $depth == 1 ){
			$classes[] = 'wow fadeInDown';	
		}

		$args = apply_filters( 'nav_menu_item_args', $args, $item, $depth );
		$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
		$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';

		// 第一层 </t>(n)<li class="">
		if($item->menu_item_parent == 0 && $depth == 0){
			if($item->menu_order == 1){
				$output .= "{$n}{$indent}<li$class_names>";
			}else{
				$output .= "{$t}<li$class_names>";
			}
		}else{
			$output .= "{$indent}<li$class_names>";
		}

		$menu_type = heku_get_menu_option( $item->menu_item_parent , 'menu_type' );
		$menu_img = heku_get_menu_option( $item->ID , 'menu_img' );
		$cat_img = "";
		if(isset($item->_menu_item_object)) {
			$cat_img = get_term_meta( $item->object_id , 'menu_img' ,true );
		}
		// var_dump($item->object_id);
		// var_dump( $cat_img );
		$menu_img = $cat_img ? $cat_img : ( $menu_img ? $menu_img : '' );

		//var_dump($menu_img);		//var_dump($menu_type);
		// 生成 a 标签的 具体参数,标题等包裹参数
        $atts = array();
        $atts['title']  = ! empty( $item->attr_title ) ? $item->attr_title : '';
		$atts['target'] = ! empty( $item->target )     ? $item->target     : '';
		$atts['rel']    = ! empty( $item->xfn )        ? $item->xfn        : '';
		$atts['href']   = ! empty( $item->url )        ? $item->url        : '';
		if( $depth == 1 ){
			$atts['class']   = 'wow fadeInDown';
		}
		$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
		$attributes = '';
		foreach ( $atts as $attr => $value ) {
			if ( ! empty( $value ) ) {
				$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
				$attributes .= ' ' . $attr . '="' . $value . '"';
			}
		}
		/** This filter  标签 $title 内容 */
		$title = apply_filters( 'the_title', $item->title, $item->ID );
		$title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );

		$item_output = $args->before;
		if($depth == 0){
			//  <a 标签前段部分  <a title="" target="" rel="" href="">   $title </a>
			$item_output .= '<a'. $attributes .'>';
			$item_output .= $args->link_before . $title . $args->link_after;
			if($args->walker->has_children){
				$item_output .= "</a>{$n}";
			}else{
				$item_output .= "</a>";
			}
		}elseif($depth == 1){
			//  <a 标签前段部分  <a title="" target="" rel="" href=""> <img src="" alt=" " width=" "> <span> $title </span> <i class="" ></i></a>

			$item_output .= '<a'. $attributes .'>';
			if($menu_img){
				$item_output .= '<img class="catimg" src="'. $menu_img .'" alt="'.$title .'" >';
				$item_output .= $args->link_before . '<span class="sssa">'.$title .'</span>'. $args->link_after;
			}else{
				$item_output .= $args->link_before . $title . $args->link_after;
			}

			if($args->walker->has_children){
				//$item_output .= '<span class="icon iconfont icon-fangxiangjiantou-you"></span>'; 
				$item_output .= "</a>{$n}";
			}else{
				//$item_output .= '<span class="icon iconfont icon-fangxiangjiantou-you"></span>'; 
				$item_output .= "</a>";
			}
			// if($item->menu_item_parent == 0 && $depth == 0){
			// 	//$item_output .= $title;
			// }

			//var_dump($item);
			if($menu_type == 'menu-type2'){
				$item_output .= $this->menu_2($item) ;
			}

			//var_dump($item);
			if($menu_type == 'menu-type3'){
				$item_output .= $this->menu_3($item) ;
			}


		}elseif($depth == 2){
			//  <a 标签前段部分  <a title="" target="" rel="" href="">   $title </a>
			$item_output .= '<a'. $attributes .'>';
			$item_output .= $args->link_before . $title . $args->link_after;
			$item_output .= "</a>";
		}else{
			//  <a 标签前段部分  <a title="" target="" rel="" href="">   $title </a>
			$item_output .= '<a'. $attributes .'>';
			$item_output .= $args->link_before . $title . $args->link_after;
			$item_output .= "</a>";
		}

		$item_output .= $args->after;


		$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
	}

	/**
	 * 	主列表包裹 li 标签 结束
	 *  </li>
	 */
	public function end_el( &$output, $item, $depth = 0, $args = array() ) {
		if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
			$t = '';
			$n = '';
		}else{
			$t = "\t";
			$n = "\n";
		}
		$indent = str_repeat( $t, $depth * 2 + $this->numtab() - 1 ) ;
		$indent2 = str_repeat( $t, $depth * 2 + $this->numtab()  ) ;
		if( $item->menu_item_parent == 0 && $depth == 0){
			$output .= "</li>{$n}$indent";
		}elseif($depth > 0 ){
			
			if($args->walker->has_children){
				//var_dump($args);
				$output .= "$indent2</li>{$n}";
			}else{
				//var_dump($args);
				$output .= "</li>{$n}";
			}
		}else{
			$output .= "</li>{$n}";
		}
	}

	/**
	 * 	子分类的 包裹 ul 标签 开始
	 * 	<ul class ="sub-menu">
	 */
	public function start_lvl( &$output, $depth = 0, $args = array() ) {
		if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
			$t = '';
			$n = '';
		}else{
			$t = "\t";
			$n = "\n";
		}
		$indent = str_repeat( $t, $depth * 2 + $this->numtab() + 1 );
        $classes = array();
        // 第一层的 ul 层 的class类
        if( $args->walker->has_children ){
            $classes = array( 'sub-menu' , 'sub-menu-' . $depth);
        }
	
        $class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) );
		$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
		
		//var_dump($args);
		// $menu_type = heku_get_menu_option( $item->menu_item_parent , 'menu_type' );
		// $menu_img = heku_get_menu_option( $item->ID , 'menu_img' );

		$sss = ' class="container-2 clearfix "';


		if( $args->walker->has_children && $depth == 0){
			$output .= "{$indent}<ul$class_names>{$n}";
			$output .= "{$indent}<div$sss>{$n}";
		}elseif( $depth == 1){
			$output .= "{$indent}<ul$class_names>{$n}";
			$output .= "{$indent}<div$sss>{$n}";
		}else{
			$output .= "{$indent}<ul$class_names>{$n}";
		}

	}

	/**
	 * 	子分类的 包裹 ul 标签 结束
	 * 	</ul><!--  end ul 标签  -->
	 */
	public function end_lvl( &$output, $depth = 0, $args = array() ) {
		if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
			$t = '';
			$n = '';
		}else{
			$t = "\t";
			$n = "\n";
		}
		$indent  = str_repeat( $t, $depth * 2 + $this->numtab() + 1 );
		$indent2 = str_repeat( $t, $depth * 2 + $this->numtab() );
		//var_dump($args);
		if( $depth == 0){
			//$output .= "{$indent}<ul$class_names><div class='container clearfix'><div class='row no-gutters align-items-center justify-content-between'>{$n}";
			$output .= "{$indent}</div>{$n}";
			$output .= "{$indent}</ul>{$n}{$indent2}";
		}elseif( $depth == 1){
			//$output .= "{$indent}<ul$class_names><div class='container clearfix'><div class='row no-gutters align-items-center justify-content-between'>{$n}";
			$output .= "{$indent}</div>{$n}";
			$output .= "{$indent}</ul>{$n}{$indent2}";
		}else{
			$output .= "{$indent}</ul>{$n}{$indent2}";
		}


	}
	/**
	 * 	为了输出 美观,空格项目,或是制表隔数量
	 * 	(</t></t></t></t>)n 
	 */
	public function numtab(){
		$numtab = 6;
		return $numtab;
	}


	public function menu_2($item){
		$t = "\t";
		$n = "\n";
		$indent  = str_repeat( $t, 1 * 2 + $this->numtab() + 1 );
		$indent2  = str_repeat( $t, 1 * 2 + $this->numtab() + 2 );

		if(!isset($item->_menu_item_object)) return;

		$type = $this->get_post_type($item->_menu_item_object);
		$sub_menu_type = heku_get_menu_option( $item->ID , 'sub_menu_type' );
		$args = array(
			'post_type' => $type,
			'posts_per_page' => 2,
			'paged'	=> 0,
			'no_found_rows' => true
		);
		if($type == 'post' && isset($item->object_id)){
			$args['cat'] = $item->object_id;
		}
		$the_query = new \WP_Query( $args );
		
		$html = '';

		if($the_query->have_posts()){
			$class_names = ' class="sub-menu sub-menu-1 news—item-ul_1 no-gutters "';
			$sss = ' class="container clearfix list-style01 py-3 '. $sub_menu_type . ' "';

			$html .= "{$n}{$indent}<ul$class_names>";
			$html .= "<div$sss>{$n}";
			wp_reset_postdata();
			while( $the_query->have_posts() ){

				$the_query->the_post();
				$link = get_permalink();
				$title = get_the_title();
				$imgs = get_post_meta( get_the_ID(), 'product_imgs', true );


				$class_nameli = ' class="news-item row no-gutters align-items-center clear p-3  row wow fadeInUp"';
				//$thumb = b2_get_thumb(array('thumb'=>Post::get_post_thumb($the_query->post->ID),'type'=>'fill','width'=>$size['width'],'height'=>$size['height']));
				$html .= "{$indent2}<li$class_nameli>";
				$html .= '
												<div class="news-img col-sm-12 col-md-4 col-lg-4 col-xl-2 ">
													<img class="news-img" src="'. reset($imgs) .'" alt="'. $title . '">
												</div>
												<div class="news-comt col-sm-12 col-md-8 col-lg-8 col-xl-10">
													<a href="' . $link . '">
														<span>'. $title . '</span>
													</a>
													<div class="news-summary d-lg-block d-md-none d-sm-block ">
														<span>'. mb_strimwidth(preg_replace("/(\s|\ \;| |\xc2\xa0)/", "", strip_tags(get_the_content())), 0, 140,"...") . '</span>
													</div>
												</div>';
				$html .= "{$n}{$indent2}</li>{$n}";
			}

			$html12 = '<a class="more wow fadeInUp" href="'.get_permalink($item->object_id).'" target="_self"><span>查看更多产品</span> <i class="fa fa-chevron-right"></i></a>';
			$html .= "{$indent2}$html12{$n}{$indent}</div></ul>{$n}";
			
		}else{
			//$html .= '<div class="">'.__('没有文章','b2').'</div>';
		}
		wp_reset_postdata();
		return $html;
	}

	public function menu_3($item){
		$t = "\t";
		$n = "\n";
		$indent  = str_repeat( $t, 1 * 2 + $this->numtab() + 1 );
		$indent2  = str_repeat( $t, 1 * 2 + $this->numtab() + 2 );
		
		if(!isset($item->_menu_item_object)) return;

		$type = $this->get_post_type($item->_menu_item_object);
		$sub_menu_type = heku_get_menu_option( $item->ID , 'sub_menu_type' );
		$args = array(
			'post_type' => $type,
			'posts_per_page' => 4,
			'paged'	=> 0,
			'no_found_rows' => true
		);
		if($type == 'post' && isset($item->object_id)){
			$args['cat'] = $item->object_id;
		}
		$the_query = new \WP_Query( $args );
		
		$html = '';

		if($the_query->have_posts()){
			$class_names = ' class="sub-menu sub-menu-1 news—item-ul_1  "';
			$sss = ' class="container row clearfix list-style01 py-3 mx-2'. $sub_menu_type . ' "';

			$html .= "{$n}{$indent}<ul$class_names>";
			$html .= "<div$sss>{$n}";
			wp_reset_postdata();
			while( $the_query->have_posts() ){

				$the_query->the_post();
				$link = get_permalink();
				$title = get_the_title();
				$imgs = get_post_meta( get_the_ID(), 'product_imgs', true );


				$class_nameli = ' class="col-lg-6 row no-gutters22 align-items-center clear p3-3 row wow fadeInUp"';
				//$thumb = b2_get_thumb(array('thumb'=>Post::get_post_thumb($the_query->post->ID),'type'=>'fill','width'=>$size['width'],'height'=>$size['height']));
				$html .= "{$indent2}<li$class_nameli>";
				$html .= '<div class="news-item"> 
												<div class="news-img col-sm-12 col-md-4 col-lg-4 col-xl-2 ">
													<img class="news-img" src="'. reset($imgs) .'" alt="'. $title . '">
												</div>
												<div class="news-comt col-sm-12 col-md-8 col-lg-8 col-xl-10">
													<a href="' . $link . '">
														<span>'. $title . '</span>
													</a>
													<div class="news-summary d-lg-block d-md-none d-sm-block ">
														<span>'. mb_strimwidth( strip_tags(get_the_content()), 0, 140,"...") . '</span>
													</div>
												</div>
											</div>';
				$html .= "{$n}{$indent2}</li>{$n}";
			}

			//$html12 = '<a class="more wow fadeInUp" href="'.get_permalink($item->object_id).'" target="_self"><span>查看更多产品</span> <i class="fa fa-chevron-right"></i></a>';
			$html .= "{$indent2}{$n}{$indent}</div></ul>{$n}";		
		}else{
			//$html .= '<div class="">'.__('没有文章','b2').'</div>';
		}
		wp_reset_postdata();
		return $html;
	}

	public function get_post_type($item_boject){

		$type = 'post';
		switch($item_boject){
			case 'category';
				$type = 'post';
			break;
			case 'shoptype';
				$type = 'shop';
			break;
			case 'labtype';
				$type = 'labs';
			case 'mp';
				$type = 'pps';
			break;
		}

		return $type;
	}

}