| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
die('-1'); |
| 4 |
} |
| 5 |
|
| 6 |
class QuadMenuWalker extends Walker_Nav_Menu { |
| 7 |
|
| 8 |
var $item_stack = array(); |
| 9 |
var $current_umitem; |
| 10 |
var $auto_child = ''; |
| 11 |
|
| 12 |
function __construct() { |
| 13 |
|
| 14 |
} |
| 15 |
|
| 16 |
function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output) { |
| 17 |
|
| 18 |
if (!$element) |
| 19 |
return; |
| 20 |
|
| 21 |
$id_field = $this->db_fields['id']; |
| 22 |
|
| 23 |
$has_children = !empty($children_elements[$element->{$id_field}]); |
| 24 |
|
| 25 |
if (isset($args[0]) && is_array($args[0])) { |
| 26 |
$args[0]['has_children'] = $has_children; |
| 27 |
} |
| 28 |
|
| 29 |
$cb_args = array_merge(array(&$output, $element, $depth), $args); |
| 30 |
|
| 31 |
$id = $element->{$id_field}; // Moved up |
| 32 |
|
| 33 |
if (!class_exists($umitem_obect_class = apply_filters('quadmenu_item_object_class', 'QuadMenuItemDefault', $element, $id, $this->auto_child))) { |
| 34 |
$umitem_obect_class = 'QuadMenuItemDefault'; |
| 35 |
} |
| 36 |
|
| 37 |
$umitem = new $umitem_obect_class($output, $element, $depth, $cb_args[3], $id, $this, $has_children, $children_elements); //The $args that get passed to start_el are $cb[3] -- i.e. the 4the element in the array merged above |
| 38 |
|
| 39 |
$this->push_item($umitem); |
| 40 |
|
| 41 |
call_user_func_array(array($this, 'start_el'), $cb_args); |
| 42 |
|
| 43 |
// descend only when the depth is right and there are childrens for this element |
| 44 |
if (($max_depth == 0 || $max_depth > $depth + 1 ) && isset($children_elements[$id])) { |
| 45 |
|
| 46 |
foreach ($children_elements[$id] as $child) { |
| 47 |
|
| 48 |
if (!isset($newlevel)) { |
| 49 |
$newlevel = true; |
| 50 |
//start the child delimiter |
| 51 |
$cb_args = array_merge(array(&$output, $depth), $args); |
| 52 |
call_user_func_array(array($this, 'start_lvl'), $cb_args); |
| 53 |
} |
| 54 |
$this->display_element($child, $children_elements, $max_depth, $depth + 1, $args, $output); |
| 55 |
} |
| 56 |
|
| 57 |
//Unset this item's children elements |
| 58 |
unset($children_elements[$id]); //TODO!!! |
| 59 |
} |
| 60 |
|
| 61 |
if (isset($newlevel) && $newlevel) { |
| 62 |
//end the child delimiter |
| 63 |
$cb_args = array_merge(array(&$output, $depth), $args); |
| 64 |
call_user_func_array(array($this, 'end_lvl'), $cb_args); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
$cb_args = array_merge(array(&$output, $element, $depth), $args); |
| 69 |
|
| 70 |
call_user_func_array(array($this, 'end_el'), $cb_args); |
| 71 |
} |
| 72 |
|
| 73 |
function start_lvl(&$output, $depth = 0, $args = array()) { |
| 74 |
//$indent = str_repeat("\t", $depth); |
| 75 |
$this->current_umitem->start_lvl(); |
| 76 |
} |
| 77 |
|
| 78 |
function end_lvl(&$output, $depth = 0, $args = array()) { |
| 79 |
//$indent = str_repeat("\t", $depth); |
| 80 |
$this->current_umitem->end_lvl(); |
| 81 |
} |
| 82 |
|
| 83 |
function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { |
| 84 |
|
| 85 |
$this->current_umitem->start_el(); |
| 86 |
} |
| 87 |
|
| 88 |
function end_el(&$output, $item, $depth = 0, $args = array()) { |
| 89 |
$this->current_umitem->end_el(); |
| 90 |
$this->pop_item(); |
| 91 |
} |
| 92 |
|
| 93 |
function push_item($umitem) { |
| 94 |
$this->item_stack[] = $umitem; |
| 95 |
$this->current_umitem = $umitem; |
| 96 |
} |
| 97 |
|
| 98 |
function pop_item() { |
| 99 |
$umitem = array_pop($this->item_stack); |
| 100 |
$this->current_umitem = $this->current_item(); |
| 101 |
} |
| 102 |
|
| 103 |
function current_item() { |
| 104 |
return end($this->item_stack); |
| 105 |
} |
| 106 |
|
| 107 |
public static function fallback($args) { |
| 108 |
|
| 109 |
global $_wp_registered_nav_menus; |
| 110 |
|
| 111 |
if (!current_user_can('manage_options')) |
| 112 |
return; |
| 113 |
|
| 114 |
extract($args); |
| 115 |
|
| 116 |
ob_start(); |
| 117 |
?> |
| 118 |
<li class="quadmenu-item quadmenu-item-object-custom quadmenu-item-level-0 quadmenu-item-type-default quadmenu-has-title quadmenu-has-icon quadmenu-has-link"> |
| 119 |
<a title="<?php printf(esc_html__('Add a menu to %1$s', 'quadmenu'), $_wp_registered_nav_menus[$theme_location]); ?>" href="<?php echo admin_url('nav-menus.php'); ?>"> |
| 120 |
<span class="quadmenu-item-content"> |
| 121 |
<span class="quadmenu-text"><?php printf(esc_html__('Add a menu to %1$s', 'quadmenu'), $_wp_registered_nav_menus[$theme_location]); ?></span> |
| 122 |
</span> |
| 123 |
</a> |
| 124 |
</li> |
| 125 |
<li class="quadmenu-item quadmenu-item-object-custom quadmenu-item-level-0 quadmenu-item-type-default quadmenu-has-title quadmenu-has-icon quadmenu-has-link"> |
| 126 |
<a title="<?php esc_html_e('Documentation', 'quadmenu'); ?>" href="<?php echo esc_url(QUADMENU_DOCUMENTATION_URL); ?>"> |
| 127 |
<span class="quadmenu-item-content"> |
| 128 |
<span class="quadmenu-text"><?php esc_html_e('Documentation', 'quadmenu'); ?></span> |
| 129 |
</span> |
| 130 |
</a> |
| 131 |
</li> |
| 132 |
<li class="quadmenu-item quadmenu-item-object-custom quadmenu-item-level-0 quadmenu-item-type-default quadmenu-has-title quadmenu-has-icon quadmenu-has-link"> |
| 133 |
<a title="<?php esc_html_e('Demo', 'quadmenu'); ?>" href="<?php echo esc_url(QUADMENU_DEMO_URL); ?>"> |
| 134 |
<span class="quadmenu-item-content"> |
| 135 |
<span class="quadmenu-text"><?php esc_html_e('Demo', 'quadmenu'); ?></span> |
| 136 |
</span> |
| 137 |
</a> |
| 138 |
</li> |
| 139 |
<?php |
| 140 |
$menu = ob_get_clean(); |
| 141 |
|
| 142 |
$nav_menu = sprintf($items_wrap, esc_attr($menu_id), esc_attr($menu_class), $menu); |
| 143 |
|
| 144 |
return quadmenu_layout($nav_menu, (object) $args); |
| 145 |
} |
| 146 |
|
| 147 |
} |
| 148 |
|