Пример #1
0
 /**
  * Get the HTML for the image attached to this menu item
  *
  * Any set img ID will override image src filtering
  * 
  * @return string img HTML
  */
 function get_image()
 {
     //Ignore mobile?
     if ($this->get_menu_op('disable_images_mobile') == 'on' && ubermenu_is_mobile('disable_images_mobile')) {
         return '';
     }
     //Image
     $img = apply_filters('ubermenu_item_image', '', $this);
     if ($img) {
         return $img;
     }
     //Allow ID filtering
     $img_id = apply_filters('ubermenu_item_image_id', $this->getSetting('item_image'), $this);
     //Allow src filtering
     $img_src = apply_filters('ubermenu_item_image_src', '', $this);
     //Inherit featured image dynamically
     if ($this->getSetting('inherit_featured_image') == 'on') {
         if ($this->item->type == 'post_type') {
             $thumb_id = get_post_thumbnail_id($this->item->object_id);
             if ($thumb_id) {
                 $img_id = $thumb_id;
             }
         }
     }
     if ($img_id || $img_src) {
         $atts = array();
         $atts['class'] = 'ubermenu-image';
         //Determine size of image to get
         $img_size = $this->getSetting('image_size');
         if ($img_size == 'inherit') {
             $img_size = $this->get_menu_op('image_size');
         }
         //echo '['.$img_size.']';
         $atts['class'] .= ' ubermenu-image-size-' . $img_size;
         //If the img_id is set, get the right image src file
         if ($img_id) {
             $img_src = wp_get_attachment_image_src($img_id, $img_size);
         }
         //Lazy Load
         if ($this->depth > 0 && $this->get_menu_op('lazy_load_images') == 'on') {
             $atts['class'] .= ' ubermenu-image-lazyload';
             $atts['data-src'] = $img_src[0];
         } else {
             $atts['src'] = $img_src[0];
         }
         //Determine dimensions
         $img_w = '';
         $img_h = '';
         $dimensions = $this->getSetting('image_dimensions');
         switch ($dimensions) {
             //Custom Dimensions use Menu Item Settings
             case 'custom':
                 $img_w = $this->getSetting('image_width_custom');
                 $img_h = $this->getSetting('image_height_custom');
                 break;
                 //Inherit settings from main Menu Settings
             //Inherit settings from main Menu Settings
             case 'inherit':
                 $img_w = $this->get_menu_op('image_width');
                 $img_h = $this->get_menu_op('image_height');
                 break;
                 //Add width and height atts for natural width
             //Add width and height atts for natural width
             case 'natural':
                 //Done below
                 break;
             default:
                 break;
         }
         //Apply natural dimensions if not already set
         if ($this->get_menu_op('image_set_dimensions')) {
             if ($img_w == '' && $img_h == '') {
                 $img_w = $img_src[1];
                 $img_h = $img_src[2];
             }
         }
         //Add dimensions as attributes, with pixel units if missing
         if ($img_w) {
             //if( is_numeric( $img_w ) ) $img_w.='px';	//Should always be numeric only, no units
             $atts['width'] = $img_w;
         }
         if ($img_h) {
             //if( is_numeric( $img_h ) ) $img_h.='px';	//Should always be numeric only, no units
             $atts['height'] = $img_h;
         }
         //Add 'alt' & 'title'
         if ($img_id) {
             $meta = get_post_custom($img_id);
             $alt = isset($meta['_wp_attachment_image_alt']) ? $meta['_wp_attachment_image_alt'][0] : '';
             //Alt field
             $title = '';
             if ($alt == '') {
                 $title = get_the_title($img_id);
                 $alt = $title;
             }
             $atts['alt'] = $alt;
             if ($this->get_menu_op('image_title_attribute') == 'on') {
                 if ($title == '') {
                     $title = get_the_title($img_id);
                 }
                 $atts['title'] = $title;
             }
         }
         //Build attributes string
         $atts = apply_filters('ubermenu_item_image_attributes', $atts, $this);
         $attributes = '';
         foreach ($atts as $name => $val) {
             $attributes .= $name . '="' . esc_attr($val) . '" ';
         }
         $img = "<img {$attributes} />";
         //$img = "<span class='ubermenu-image'><img $attributes /></span>";
     }
     return $img;
 }
Пример #2
0
function ubermenu_display_retractors()
{
    //echo ubermenu_op( 'retractor_display_strategy' , 'general' );
    switch (ubermenu_op('retractor_display_strategy', 'general')) {
        case 'responsive':
            return true;
        case 'mobile':
            return ubermenu_is_mobile('display_retractors');
        case 'touch':
            return true;
        default:
            return true;
    }
    return true;
}
Пример #3
0
 function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output)
 {
     if (!$element) {
         return;
     }
     //Offset Depth
     $original_depth = $depth;
     $depth = $depth + $this->offset_depth;
     $id_field = $this->db_fields['id'];
     if ($this->get_ignore($element->{$id_field})) {
         unset($children_elements[$element->{$id_field}]);
         return;
     }
     //Automatically add rows!
     if (isset($children_elements[$element->{$id_field}]) && count($children_elements[$element->{$id_field}]) > 0) {
         $has_row = false;
         $has_nonrow = false;
         foreach ($children_elements[$element->{$id_field}] as $child_el) {
             if ($child_el->type_label == '[UberMenu Row]') {
                 $has_row = true;
                 //break;
             } else {
                 $has_nonrow = true;
             }
         }
         if ($has_row) {
             $element->classes[] = 'advanced-sub';
             //If user hasn't added rows, we need to add them
             if ($has_nonrow) {
                 $row_count = 0;
                 $current_row = false;
                 $current_row_id = 0;
                 $id = $element->{$id_field};
                 $my_children = $children_elements[$id];
                 $children_elements[$id] = array();
                 //Loop through items, wrap in rows
                 foreach ($my_children as $k => $child_el) {
                     //If this is a row, reset current vals
                     if ($child_el->type_label == '[UberMenu Row]') {
                         $current_row = false;
                         $current_row_id = 0;
                         $children_elements[$id][] = $child_el;
                     } else {
                         //If we don't have a current row, make one
                         if (!$current_row_id) {
                             $row_count++;
                             $current_row_id = $element->{$id_field} . '_auto_' . $row_count;
                             $current_row = new UberMenu_dummy_item($current_row_id, 'row', 'Dummy Row', $element->{$id_field});
                             $children_elements[$current_row_id] = array();
                             //Insert row in appropriate spot.
                             $children_elements[$id][] = $current_row;
                         }
                         //Add Children to Row
                         $children_elements[$current_row_id][] = $child_el;
                         //Remove Children from Sub?
                         //unset( $children_elements[$id][$k] );  // No because we reset array above
                     }
                 }
             }
         }
     }
     //Walker_Nav_Menu::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
     //display this element - wp-includes/class-wp-walker.php
     $has_children = !empty($children_elements[$element->{$id_field}]);
     if (isset($args[0]) && is_array($args[0])) {
         $args[0]['has_children'] = $has_children;
     }
     $cb_args = array_merge(array(&$output, $element, $depth), $args);
     $id = $element->{$id_field};
     // Moved up
     // Setup UberMenuItem object
     $umitem_obect_class = apply_filters('ubermenu_item_object_class', 'UberMenuItemDefault', $element, $id, $this->auto_child);
     //echo '<br/><br/>'.str_repeat("&nbsp;", $depth*5).'['. $id .'] '. $umitem_obect_class . ' :: <strong>' . $element->title.'</strong>';
     //echo $element->$id_field . ' :: ' .$umitem_obect_class.'<br/>';
     $umitem = new $umitem_obect_class($output, $element, $depth, $cb_args[3], $id, $this, $has_children);
     //The $args that get passed to start_el are $cb[3] -- i.e. the 4the element in the array merged above
     //Ignoring? Check again after initialization so that item can disable itself
     if ($this->get_ignore($element->{$id_field})) {
         unset($children_elements[$element->{$id_field}]);
         return;
     }
     //Disabled?
     $display_on = $umitem->display_on();
     //If this item is not yet disabled, allow its status to be filtered
     if ($display_on) {
         $display_on = apply_filters('ubermenu_display_item', true, $this, $element, $max_depth, $depth, $args, $umitem);
     }
     //If the item is disabled, kill its children, Lannister-style
     if (!$display_on) {
         $this->clear_children($children_elements, $id);
         return;
     }
     //If submenu disabled, clear children but don't return
     if ($umitem->getSetting('disable_submenu_on_mobile') == 'on') {
         if (ubermenu_is_mobile('disable_submenu_on_mobile')) {
             $this->clear_children($children_elements, $id);
             $umitem->disable_children();
         }
     }
     //Filter
     // Manipulate Structure
     if ($umitem->alter_structure()) {
         $umitem->alter($children_elements);
     }
     $this->push_item($umitem);
     call_user_func_array(array($this, 'start_el'), $cb_args);
     //Check if we are ignoring children
     if (!$this->get_ignore_children($id)) {
         // descend only when the depth is right and there are childrens for this element
         if (($max_depth == 0 || $max_depth > $depth + 1) && isset($children_elements[$id])) {
             foreach ($children_elements[$id] as $child) {
                 $this->auto_child = $umitem->getAutoChild();
                 if (!isset($newlevel)) {
                     $newlevel = true;
                     //start the child delimiter
                     $cb_args = array_merge(array(&$output, $depth), $args);
                     call_user_func_array(array($this, 'start_lvl'), $cb_args);
                 }
                 $this->display_element($child, $children_elements, $max_depth, $depth + 1, $args, $output);
                 $this->auto_child = '';
             }
             //Unset this item's children elements
             unset($children_elements[$id]);
             //TODO!!!
         }
     }
     if (isset($newlevel) && $newlevel) {
         //end the child delimiter
         $cb_args = array_merge(array(&$output, $depth), $args);
         call_user_func_array(array($this, 'end_lvl'), $cb_args);
     }
     //end this element
     $cb_args = array_merge(array(&$output, $element, $depth), $args);
     call_user_func_array(array($this, 'end_el'), $cb_args);
     //Cleanup when we hit top level items (original depth/without offset matters for menu segments)
     if ($depth == 0 || $original_depth == 0) {
         //Make sure we don't print trash - actually, these elements don't exist, just child indexes
         foreach ($this->trashbin as $_trash_id => $on) {
             //echo '<br/>$$unset '.$_trash_id.'<br/>';
             unset($children_elements[$_trash_id]);
         }
         if ($depth == 0) {
             $this->trashbin = array();
         }
         //reset trashbin only at very top
     }
 }