Ejemplo n.º 1
0
 /**
  * Return the HTML to display in the 'Mega Menu' tab
  *
  * @since 1.7
  * @return string
  */
 public function add_mega_menu_tab($tabs, $menu_item_id, $menu_id, $menu_item_depth, $menu_item_meta)
 {
     if ($menu_item_depth > 0) {
         $tabs['mega_menu'] = array('title' => __('Mega Menu', 'megamenu'), 'content' => '<em>' . __("Mega Menus can only be created on top level menu items.", "megamenu") . '</em>');
         return $tabs;
     }
     $widget_manager = new Mega_Menu_Widget_Manager();
     $all_widgets = $widget_manager->get_available_widgets();
     $return = "<label for='mm_enable_mega_menu'>" . __("Sub menu display mode", "megamenu") . "</label>";
     $return .= "<select id='mm_enable_mega_menu' name='settings[type]'>";
     $return .= "    <option value='flyout'>" . __("Flyout Menu", "megamenu") . "</option>";
     $return .= "    <option id='megamenu' value='megamenu' " . selected($menu_item_meta['type'], 'megamenu', false) . ">" . __("Mega Menu", "megamenu") . "</option>";
     $return .= "</select>";
     $return .= "<select id='mm_number_of_columns' name='settings[panel_columns]'>";
     $return .= "    <option value='1' " . selected($menu_item_meta['panel_columns'], 1, false) . ">1 " . __("column", "megamenu") . "</option>";
     $return .= "    <option value='2' " . selected($menu_item_meta['panel_columns'], 2, false) . ">2 " . __("columns", "megamenu") . "</option>";
     $return .= "    <option value='3' " . selected($menu_item_meta['panel_columns'], 3, false) . ">3 " . __("columns", "megamenu") . "</option>";
     $return .= "    <option value='4' " . selected($menu_item_meta['panel_columns'], 4, false) . ">4 " . __("columns", "megamenu") . "</option>";
     $return .= "    <option value='5' " . selected($menu_item_meta['panel_columns'], 5, false) . ">5 " . __("columns", "megamenu") . "</option>";
     $return .= "    <option value='6' " . selected($menu_item_meta['panel_columns'], 6, false) . ">6 " . __("columns", "megamenu") . "</option>";
     $return .= "    <option value='7' " . selected($menu_item_meta['panel_columns'], 7, false) . ">7 " . __("columns", "megamenu") . "</option>";
     $return .= "    <option value='8' " . selected($menu_item_meta['panel_columns'], 8, false) . ">8 " . __("columns", "megamenu") . "</option>";
     $return .= "</select>";
     $return .= "<select id='mm_widget_selector'>";
     $return .= "    <option value='disabled'>" . __("Select a Widget to add to the panel", "megamenu") . "</option>";
     foreach ($all_widgets as $widget) {
         $return .= "<option value='" . $widget['value'] . "'>" . $widget['text'] . "</option>";
     }
     $return .= "</select>";
     $class = $menu_item_meta['type'] == 'megamenu' ? 'enabled' : 'disabled';
     $return .= "<div id='widgets' class='{$class}' data-columns='{$this->menu_item_meta['panel_columns']}'>";
     $second_level_items = $this->get_second_level_menu_items();
     $panel_widgets = $widget_manager->get_widgets_for_menu_id($menu_item_id);
     if (count($second_level_items)) {
         $return .= "<h5>" . __("Sub menu items", "megamenu") . "</h5>";
         foreach ($second_level_items as $item) {
             $return .= '<div class="widget sub_menu" data-columns="' . esc_attr($item['mega_columns']) . '" data-menu-item-id="' . esc_attr($item['id']) . '">';
             $return .= '    <div class="widget-top">';
             $return .= '        <div class="widget-title-action">';
             $return .= '            <a class="widget-option widget-contract"></a>';
             $return .= '            <a class="widget-option widget-expand"></a>';
             $return .= '        </div>';
             $return .= '        <div class="widget-title">';
             $return .= '            <h4>' . esc_html($item['title']) . '</h4>';
             $return .= '        </div>';
             $return .= '    </div>';
             $return .= '</div>';
         }
     }
     $return .= "<h5>" . __("Widgets", "megamenu") . "</h5>";
     if (count($panel_widgets)) {
         foreach ($panel_widgets as $widget) {
             $return .= '<div class="widget" data-columns="' . esc_attr($widget['mega_columns']) . '" id="' . esc_attr($widget['widget_id']) . '" data-widget-id="' . esc_attr($widget['widget_id']) . '">';
             $return .= '    <div class="widget-top">';
             $return .= '        <div class="widget-title-action">';
             $return .= '            <a class="widget-option widget-contract"></a>';
             $return .= '            <a class="widget-option widget-expand"></a>';
             $return .= '            <a class="widget-option widget-action"></a>';
             $return .= '        </div>';
             $return .= '        <div class="widget-title">';
             $return .= '            <h4>' . esc_html($widget['title']) . '</h4>';
             $return .= '        </div>';
             $return .= '    </div>';
             $return .= '    <div class="widget-inner"></div>';
             $return .= '</div>';
         }
     } else {
         $return .= "<p class='no_widgets'>" . __("No widgets found. Add a widget to this area using the Widget Selector (top right)") . "</p>";
     }
     $return .= "</div>";
     $tabs['mega_menu'] = array('title' => __('Mega Menu', 'megamenu'), 'content' => $return);
     return $tabs;
 }
Ejemplo n.º 2
0
 /**
  * Append the widget objects to the menu array before the
  * menu is processed by the walker.
  *
  * @since 1.0
  * @param array $items - All menu item objects
  * @param object $args
  * @return array - Menu objects including widgets
  */
 public function add_widgets_to_menu($items, $args)
 {
     // make sure we're working with a Mega Menu
     if (!is_a($args->walker, 'Mega_Menu_Walker')) {
         return $items;
     }
     $items = apply_filters("megamenu_nav_menu_objects_before", $items, $args);
     $widget_manager = new Mega_Menu_Widget_Manager();
     $default_columns = apply_filters("megamenu_default_columns", 1);
     foreach ($items as $item) {
         // only look for widgets on top level items
         if ($item->depth == 0 && $item->megamenu_settings['type'] == 'megamenu') {
             $panel_widgets = $widget_manager->get_widgets_for_menu_id($item->ID);
             if (count($panel_widgets)) {
                 if (!in_array('menu-item-has-children', $item->classes)) {
                     $item->classes[] = 'menu-item-has-children';
                 }
                 $cols = 0;
                 foreach ($panel_widgets as $widget) {
                     $menu_item = array('type' => 'widget', 'title' => '', 'content' => $widget_manager->show_widget($widget['widget_id']), 'menu_item_parent' => $item->ID, 'db_id' => 0, 'ID' => $widget['widget_id'], 'menu_order' => $item->menu_order + 1, 'classes' => array("menu-item", "menu-item-type-widget", "menu-columns-{$widget['mega_columns']}-of-{$item->megamenu_settings['panel_columns']}", "menu-widget-class-" . $widget_manager->get_widget_class($widget['widget_id'])));
                     if ($cols == 0) {
                         $menu_item['classes'][] = "menu-clear";
                     }
                     $cols = $cols + $widget['mega_columns'];
                     if ($cols > $item->megamenu_settings['panel_columns']) {
                         $menu_item['classes'][] = "menu-clear";
                         $cols = $widget['mega_columns'];
                     }
                     $items[] = (object) $menu_item;
                 }
             }
         }
     }
     $items = apply_filters("megamenu_nav_menu_objects_after", $items, $args);
     return $items;
 }
Ejemplo n.º 3
0
 /**
  * Append the widget objects to the menu array before the
  * menu is processed by the walker.
  *
  * @since 1.0
  * @param array $items - All menu item objects
  * @param object $args
  * @return array - Menu objects including widgets
  */
 public function add_widgets_to_menu($items, $args)
 {
     // make sure we're working with a Mega Menu
     if (!is_a($args->walker, 'Mega_Menu_Walker')) {
         return $items;
     }
     $items = apply_filters("megamenu_nav_menu_objects_before", $items, $args);
     $widget_manager = new Mega_Menu_Widget_Manager();
     foreach ($items as $item) {
         // only look for widgets on top level items
         if ($item->depth === 0 && $item->megamenu_settings['type'] == 'megamenu') {
             $panel_widgets = $widget_manager->get_widgets_for_menu_id($item->ID, $args->menu);
             if (count($panel_widgets)) {
                 $widget_position = 0;
                 $total_widgets_in_menu = count($panel_widgets);
                 $next_order = $this->menu_order_of_next_top_level_item($item->ID, $items);
                 if (!in_array('menu-item-has-children', $item->classes)) {
                     $item->classes[] = 'menu-item-has-children';
                 }
                 foreach ($panel_widgets as $widget) {
                     $widget_settings = array_merge(Mega_Menu_Nav_Menus::get_menu_item_defaults(), array('mega_menu_columns' => absint($widget['columns'])));
                     $menu_item = array('type' => 'widget', 'in_megamenu' => true, 'title' => $widget['id'], 'content' => $widget_manager->show_widget($widget['id']), 'menu_item_parent' => $item->ID, 'db_id' => 0, 'ID' => $widget['id'], 'menu_order' => $next_order - $total_widgets_in_menu + $widget_position, 'megamenu_order' => $widget['order'], 'megamenu_settings' => $widget_settings, 'depth' => 1, 'classes' => array("menu-item", "menu-item-type-widget", "menu-widget-class-" . $widget_manager->get_widget_class($widget['id'])));
                     $items[] = (object) $menu_item;
                     $widget_position++;
                 }
             }
         }
     }
     $items = apply_filters("megamenu_nav_menu_objects_after", $items, $args);
     return $items;
 }
Ejemplo n.º 4
0
 /**
  * Deletes all Max Mega Menu data from the database
  *
  * @since 1.5
  */
 public function delete_data()
 {
     check_admin_referer('megamenu_delete_data');
     // delete menu settings
     delete_option("megamenu_settings");
     // delete menu locations
     delete_option("megamenu_locations");
     // delete all widgets assigned to menus
     $widget_manager = new Mega_Menu_Widget_Manager();
     if ($mega_menu_widgets = $widget_manager->get_mega_menu_sidebar_widgets()) {
         foreach ($mega_menu_widgets as $widget_id) {
             $widget_manager->delete_widget($widget_id);
         }
     }
     // delete all mega menu metadata stored against menu items
     delete_metadata('post', 0, '_megamenu', '', true);
     // clear cache
     delete_transient("megamenu_css");
     // delete custom themes
     delete_site_option("megamenu_themes");
     $this->redirect(admin_url("admin.php?page=maxmegamenu&tab=tools&delete_data=true"));
 }
Ejemplo n.º 5
0
 /**
  * Append the widget objects to the menu array before the 
  * menu is processed by the walker.
  *
  * @since 1.0
  * @param array $items - All menu item objects
  * @param object $args
  * @return array - Menu objects including widgets
  */
 public function add_widgets_to_menu($items, $args)
 {
     // make sure we're working with a Mega Menu
     if (!is_a($args->walker, 'Mega_Menu_Walker')) {
         return $items;
     }
     $widget_manager = new Mega_Menu_Widget_Manager();
     $default_columns = apply_filters("megamenu_default_columns", 1);
     foreach ($items as $item) {
         // only look for widgets on top level items
         if ($item->menu_item_parent == 0) {
             $settings = get_post_meta($item->ID, '_megamenu', true);
             $align_class = isset($settings['align']) ? 'align-' . $settings['align'] : 'align-bottom-left';
             $type_class = isset($settings['type']) ? 'menu-' . $settings['type'] : 'menu-flyout';
             $item->classes[] = $align_class;
             $item->classes[] = $type_class;
             if ($type_class == 'menu-megamenu') {
                 $panel_widgets = $widget_manager->get_widgets_for_menu_id($item->ID);
                 if (count($panel_widgets)) {
                     if (!in_array('menu-item-has-children', $item->classes)) {
                         $item->classes[] = 'menu-item-has-children';
                     }
                     $cols = 0;
                     foreach ($panel_widgets as $widget) {
                         $menu_item = array('type' => 'widget', 'title' => '', 'content' => $widget_manager->show_widget($widget['widget_id']), 'menu_item_parent' => $item->ID, 'db_id' => 0, 'ID' => $widget['widget_id'], 'classes' => array("menu-item", "menu-item-type-widget", "menu-columns-{$widget['mega_columns']}"));
                         if ($cols == 0) {
                             $menu_item['classes'][] = "menu-clear";
                         }
                         $cols = $cols + $widget['mega_columns'];
                         if ($cols > 6) {
                             $menu_item['classes'][] = "menu-clear";
                             $cols = $widget['mega_columns'];
                         }
                         $items[] = (object) $menu_item;
                     }
                 }
             }
         } else {
             $item->classes[] = "menu-columns-{$default_columns}";
         }
     }
     return $items;
 }