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/scdc-marine/HekuClass/View/SidebarNavMenu.php
<?php
namespace Heku\HekuClass\View;

/**
 * @package     Heku\HekuClass\SidebarNavMenu
 * @subpackage  Classes/SEO
 * @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 SidebarNavMenu 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[] = 'sidebar-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;
		$classes[] = 'sidebar-item-' . $item->ID;

		if( $depth == 0 ){
			$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>";
		}

		//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 );

		$menu_img = heku_get_menu_option( $item->ID , 'sidebar_menu_img' );

		if(isset($item->_menu_item_object)) {
			$cat_img = heku_get_menu_option( $item->ID , 'menu_img' );
		}
		$menu_img = $menu_img ? $menu_img : ( $cat_img ? $cat_img : '' );



		$item_output = $args->before;


		if( $depth == 0 ){
			//  <a 标签前段部分  <a title="" target="" rel="" href="">   $title </a>
			$item_output .= "{$n}{$indent}{$t}<div class='sidebar-menu-li'>";
			$item_output .= '<img class="sidebar-cat-img" src="'. $menu_img .'" alt="倾角传感器" width="100%">';
			$item_output .= '<a'. $attributes .'>';
			$item_output .= $args->link_before . '<span class="sssa">'.$title .'</span>'. $args->link_after;
			if($args->walker->has_children){
				$item_output .= "</a>";
				$item_output .= '<span class="icon font_family"></span>';
				$item_output .= "</div>{$n}";
			}else{
				$item_output .= "</a>";
				$item_output .= "</div>{$n}";
			}

		}elseif( $menu_img ){
			//  <a 标签前段部分  <a title="" target="" rel="" href="">   $title </a>
			$item_output .= '<a'. $attributes .'>';
			$item_output .= '<img class="sidebar-cat-img" src="'. $menu_img .'" alt="倾角传感器" width="100%">';
			$item_output .= $args->link_before . '<span class="sssa">'.$title .'</span>'. $args->link_after;
			if($args->walker->has_children){
				$item_output .= "</a>{$n}";
			}else{
				$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;
			if($args->walker->has_children){
				$item_output .= "</a>{$n}";
			}else{
				$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{
				// 
				$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 ) . '"' : '';

		$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() );

		$output .= "{$indent}</ul>{$n}{$indent2}";

	}
	/**
	 * 	为了输出 美观,空格项目,或是制表隔数量
	 * 	(</t></t></t></t>)n 
	 */
	public function numtab(){
		$numtab = 8;
		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"';
			$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(), 'banner_fliter_group2', true );

				$class_nameli = ' class="news-item row no-gutters align-items-center clear px-2 px-3 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="list-img col-sm-12 col-md-4 col-lg-3 col-xl-2 p-2">
													<a href="/news/news-2589">
														<img class="news-img" src="'.$imgs[0]['banner_primg1'].'" alt="直川科技入选闵行区科技小巨人工程! " width="100%" height="100%">
													</a>
												</div>
												<div class="list-comt col-sm-12 col-md-8 col-lg-9 col-xl-10 p-2">
													<div class="list-tit py-2">
														<a href="'.$link.'">
															<span>'. $title . '</span>
														</a>
													</div>
													<div class="list-summary d-lg-block d-md-none d-sm-block py-2">
														<span>直川科技入选闵行区科技小巨人工程!继获得上海市专精特新企业认定之后,直川科技又成功通过2022年度闵行区科技小巨人工程的认定!一直以来,直川...</span>
													</div>
												</div>';
				$html .= "{$n}{$indent2}</li>{$n}";
			}

			$html12 = '<a class="more" href="support/productmanual/pushbutton/" 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 );

		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"';
			$sss = ' class="container clearfix list-style01 py-3 '. $sub_menu_type . ' "';

			$html .= "{$n}{$indent}<ul$class_names>{$n}";
			$html .= "{$indent}<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(), 'banner_fliter_group2', true );

				$class_nameli = ' class="news-item row no-gutters align-items-center clear px-2 px-3 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 .= "{$indent}<li$class_nameli>";
				$html .= '
							<div class="list-img col-sm-12 col-md-4 col-lg-3 col-xl-2 p-2">
								<a href="/news/news-2589">
									<img class="news-img" src="'.$imgs[0]['banner_primg1'].'" alt="直川科技入选闵行区科技小巨人工程! " width="100%" height="100%">
								</a>
							</div>
							<div class="list-comt col-sm-12 col-md-8 col-lg-9 col-xl-10 p-2">
								<div class="list-tit py-2">
									<a href="'.$link.'">
										<span>'. $title . '</span>
									</a>
								</div>
								<div class="list-summary d-lg-block d-md-none d-sm-block py-2">
									<span>直川科技入选闵行区科技小巨人工程!继获得上海市专精特新企业认定之后,直川科技又成功通过2022年度闵行区科技小巨人工程的认定!一直以来,直川...</span>
								</div>
							</div>';
				$html .= "{$n}{$indent}</li>{$n}";
			}
			$html .= '<a class="more" href="support/productmanual/pushbutton/" target="_self" class="more"><span>查看详情</span> <i class="fa fa-chevron-right"></i></a></ul>';
			
		}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;
	}

}