PageRenderTime 25ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/enfold/includes/helper-responsive-megamenu.php

https://gitlab.com/haque.mdmanzurul/soundkreationsfinal
PHP | 321 lines | 167 code | 70 blank | 84 comment | 47 complexity | 786a42ce222138ccb9f445864c919e72 MD5 | raw file
  1. <?php
  2. if( !class_exists( 'avia_responsive_mega_menu' ) )
  3. {
  4. /**
  5. * The avia walker is the frontend walker and necessary to display the menu, this is a advanced version of the wordpress menu walker
  6. * @package WordPress
  7. * @since 1.0.0
  8. * @uses Walker
  9. */
  10. class avia_responsive_mega_menu extends Walker {
  11. /**
  12. * @see Walker::$tree_type
  13. * @var string
  14. */
  15. var $tree_type = array( 'post_type', 'taxonomy', 'custom' );
  16. /**
  17. * @see Walker::$db_fields
  18. * @todo Decouple this.
  19. * @var array
  20. */
  21. var $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id' );
  22. /**
  23. * @var int $columns
  24. */
  25. var $columns = 0;
  26. /**
  27. * @var int $max_columns maximum number of columns within one mega menu
  28. */
  29. var $max_columns = 0;
  30. /**
  31. * @var int $rows holds the number of rows within the mega menu
  32. */
  33. var $rows = 1;
  34. /**
  35. * @var array $rowsCounter holds the number of columns for each row within a multidimensional array
  36. */
  37. var $rowsCounter = array();
  38. /**
  39. * @var string $mega_active hold information whetever we are currently rendering a mega menu or not
  40. */
  41. var $mega_active = 0;
  42. /**
  43. * @var array $grid_array holds the grid classes that get applied to the mega menu depending on the number of columns
  44. */
  45. var $grid_array = array();
  46. /**
  47. * @var stores if we already have an active first level main menu item.
  48. */
  49. var $active_item = false;
  50. /**
  51. * @var stores if we got a top or a sidebar main menu.
  52. */
  53. var $top_menu = true;
  54. /**
  55. * @var stores the number of first level menu items
  56. */
  57. var $first_level_count = 0;
  58. /**
  59. * @var stores if mega menu is active
  60. */
  61. var $mega_allowed = true;
  62. /**
  63. *
  64. * Constructor that sets the grid variables
  65. *
  66. */
  67. function avia_responsive_mega_menu($options = array())
  68. {
  69. $this->grid_array = array(
  70. 1 => "three units",
  71. 2 => "six units",
  72. 3 => "nine units",
  73. 4 => "twelve units",
  74. 5 => "twelve units",
  75. 6 => "twelve units"
  76. );
  77. $this->top_menu = avia_get_option('header_position','header_top') == 'header_top' ? true : false;
  78. if(isset($options['megamenu']) && $options['megamenu'] == "disabled") $this->mega_allowed = false;
  79. }
  80. /**
  81. * @see Walker::start_lvl()
  82. *
  83. * @param string $output Passed by reference. Used to append additional content.
  84. * @param int $depth Depth of page. Used for padding.
  85. */
  86. function start_lvl(&$output, $depth = 0, $args = array()) {
  87. $indent = str_repeat("\t", $depth);
  88. if($depth === 0) $output .= "\n{replace_one}\n";
  89. $output .= "\n$indent<ul class=\"sub-menu\">\n";
  90. }
  91. /**
  92. * @see Walker::end_lvl()
  93. *
  94. * @param string $output Passed by reference. Used to append additional content.
  95. * @param int $depth Depth of page. Used for padding.
  96. */
  97. function end_lvl(&$output, $depth = 0, $args = array()) {
  98. $indent = str_repeat("\t", $depth);
  99. $output .= "$indent</ul>\n";
  100. if($depth === 0)
  101. {
  102. if($this->mega_active && $this->mega_allowed)
  103. {
  104. $output .= "\n</div>\n";
  105. $output = str_replace("{replace_one}", "<div class='avia_mega_div avia_mega".$this->max_columns." ".$this->grid_array[$this->max_columns]."'>", $output);
  106. $output = str_replace("{last_item}", "avia_mega_menu_columns_last", $output);
  107. foreach($this->rowsCounter as $row => $columns)
  108. {
  109. $output = str_replace("{current_row_".$row."}", "avia_mega_menu_columns_".$columns." ".$this->grid_array[1], $output);
  110. }
  111. $this->columns = 0;
  112. $this->max_columns = 0;
  113. $this->rowsCounter = array();
  114. }
  115. else
  116. {
  117. $output = str_replace("{replace_one}", "", $output);
  118. }
  119. }
  120. }
  121. /**
  122. * @see Walker::start_el()
  123. *
  124. * @param string $output Passed by reference. Used to append additional content.
  125. * @param object $item Menu item data object.
  126. * @param int $depth Depth of menu item. Used for padding.
  127. * @param int $current_page Menu item ID.
  128. * @param object $args
  129. */
  130. function start_el(&$output, $item, $depth = 0, $args = array(), $current_object_id = 0 ) {
  131. global $wp_query;
  132. //set maxcolumns
  133. if(!isset($args->max_columns)) $args->max_columns = 6;
  134. $item_output = $li_text_block_class = $column_class = "";
  135. if($depth === 0)
  136. {
  137. $this->first_level_count ++;
  138. $this->mega_active = get_post_meta( $item->ID, '_menu-item-avia-megamenu', true);
  139. $style = get_post_meta( $item->ID, '_menu-item-avia-style', true);
  140. }
  141. if($depth === 1 && $this->mega_active && $this->mega_allowed)
  142. {
  143. $this->columns ++;
  144. //check if we have more than $args['max_columns'] columns or if the user wants to start a new row
  145. if($this->columns > $args->max_columns || (get_post_meta( $item->ID, '_menu-item-avia-division', true) && $this->columns != 1))
  146. {
  147. $this->columns = 1;
  148. $this->rows ++;
  149. $output .= "\n</ul><ul class=\"sub-menu avia_mega_hr\">\n";
  150. $output = str_replace("{last_item}", "avia_mega_menu_columns_last", $output);
  151. }
  152. else
  153. {
  154. $output = str_replace("{last_item}", "", $output);
  155. }
  156. $this->rowsCounter[$this->rows] = $this->columns;
  157. if($this->max_columns < $this->columns) $this->max_columns = $this->columns;
  158. $title = apply_filters( 'the_title', $item->title, $item->ID );
  159. if($title != "-" && $title != '"-"') //fallback for people who copy the description o_O
  160. {
  161. $heading_title = do_shortcode($title);
  162. if(!empty($item->url) && $item->url != "#" && $item->url != 'http://')
  163. {
  164. $heading_title = "<a href='".$item->url."'>{$title}</a>";
  165. }
  166. $item_output .= "<span class='mega_menu_title heading-color av-special-font'>".$heading_title."</span>";
  167. }
  168. $column_class = ' {current_row_'.$this->rows.'} {last_item}';
  169. if($this->columns == 1)
  170. {
  171. $column_class .= " avia_mega_menu_columns_first";
  172. }
  173. }
  174. else if($depth >= 2 && $this->mega_active && $this->mega_allowed && get_post_meta( $item->ID, '_menu-item-avia-textarea', true) )
  175. {
  176. $li_text_block_class = 'avia_mega_text_block ';
  177. $item_output.= do_shortcode($item->post_content);
  178. }
  179. else
  180. {
  181. $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
  182. $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
  183. $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
  184. $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
  185. $item_output .= $args->before;
  186. $item_output .= '<a'. $attributes .'><span class="avia-bullet"></span>';
  187. $item_output .= $args->link_before .'<span class="avia-menu-text">'. do_shortcode(apply_filters('the_title', $item->title, $item->ID)) ."</span>". $args->link_after;
  188. if($depth === 0)
  189. {
  190. if(!$this->top_menu && !empty($item->description))
  191. {
  192. $item_output .= '<span class="avia-menu-subtext">'. do_shortcode($item->description) ."</span>";
  193. }
  194. $item_output .= '<span class="avia-menu-fx"><span class="avia-arrow-wrap"><span class="avia-arrow"></span></span></span>';
  195. }
  196. $item_output .= '</a>';
  197. $item_output .= $args->after;
  198. }
  199. $class_names = $value = '';
  200. $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  201. $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  202. if(isset($style)) $classes[] = $style;
  203. if($depth === 0 && $key = array_search('current-menu-item', $classes))
  204. {
  205. if($this->active_item)
  206. {
  207. unset($classes[$key]);
  208. }
  209. else
  210. {
  211. $this->active_item = true;
  212. }
  213. }
  214. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
  215. if($depth === 0 && $this->mega_active && $this->mega_allowed) $class_names .= " menu-item-mega-parent ";
  216. if($depth === 0 ) $class_names .= " menu-item-top-level menu-item-top-level-".$this->first_level_count;
  217. $class_names = ' class="'.$li_text_block_class. esc_attr( $class_names ) . $column_class.'"';
  218. $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
  219. $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  220. }
  221. /**
  222. * @see Walker::end_el()
  223. *
  224. * @param string $output Passed by reference. Used to append additional content.
  225. * @param object $item Page data object. Not used.
  226. * @param int $depth Depth of page. Not Used.
  227. */
  228. function end_el(&$output, $item, $depth = 0, $args = array()) {
  229. $output .= "</li>\n";
  230. }
  231. }
  232. }
  233. if( !function_exists( 'avia_responsive_fallback_menu' ) )
  234. {
  235. /**
  236. * Create a navigation out of pages if the user didnt create a menu in the backend
  237. *
  238. */
  239. function avia_responsive_fallback_menu()
  240. {
  241. $current = "";
  242. $exclude = avia_get_option('frontpage');
  243. if (is_front_page()){$current = "class='current-menu-item'";}
  244. if ($exclude) $exclude ="&exclude=".$exclude;
  245. echo "<div class='fallback_menu'>";
  246. echo "<ul class='avia_mega menu'>";
  247. echo "<li $current><a href='".get_bloginfo('url')."'>Home</a></li>";
  248. wp_list_pages('title_li=&sort_column=menu_order'.$exclude);
  249. echo "</ul></div>";
  250. }
  251. }