示例#1
0
 /**
  * Flag menus (and menu items) that are set to open in a new window
  * so that they can be identified later. 
  * 
  * Adds a <span class="ws-new-window-please"></span> element to the title
  * of each detected menu.  
  * 
  * @param array $item
  * @return array
  */
 function flag_new_window_menus($item)
 {
     $open_in = ameMenuItem::get($item, 'open_in', 'same_window');
     if ($open_in == 'new_window') {
         $old_title = ameMenuItem::get($item, 'menu_title', '');
         $item['menu_title'] = $old_title . '<span class="ws-new-window-please" style="display:none;"></span>';
         //For compatibility with Ozh's Admin Drop Down menu, record the link ID that will be
         //assigned to this item. This lets us modify it later.
         if (function_exists('wp_ozh_adminmenu_sanitize_id')) {
             $subid = 'oamsub_' . wp_ozh_adminmenu_sanitize_id(ameMenuItem::get($item, 'file', ''));
             $this->ozhs_new_window_menus[] = '#' . str_replace(array(':', '&'), array('\\\\:', '\\\\&'), $subid);
         }
     }
     return $item;
 }
示例#2
0
<?php if ($hidebubble) { ?>
/* Hide "0" bubbles */
span.count-0 {display:none;}
<?php } ?>

<?php if ($icons) {
	require(dirname(__FILE__).'/icons.php');
?>
/* Icons */
#ozhmenu .ozhmenu_sublevel a {
	padding-<?php echo $dir; ?>:22px;
	background-repeat:no-repeat;
	background-position:<?php echo ($dir == 'left' ? '3px' : '97%'); ?> center;
}
.oam_plugin a {
	background-image:url(<?php echo $plugin; ?>/images/cog.png);
}
#ozhmumenu .ozhmenu_sublevel a {background-image:url(<?php echo $plugin; ?>/images/world_link.png);}
<?php
	foreach($wp_ozh_adminmenu['icon_names'] as $link=>$icon) {
		$link = wp_ozh_adminmenu_sanitize_id($link);
		$link = str_replace(array('.php','.','/'),array('','_','_'),$link);
		echo "#oamsub_$link a {background-image:url($plugin/images/$icon.png);}\n";
	}

} else { ?>
#ozhmenu .ozhmenu_sublevel a {padding-<?php echo $dir; ?>:5px;}
<?php } ?>


/**/
function wp_ozh_adminmenu()
{
    global $menu, $submenu, $self, $parent_file, $submenu_file, $plugin_page, $pagenow, $wp_ozh_adminmenu;
    // echo "<pre>";print_r($menu);print_r($submenu);echo "</pre>";
    // Plugins: hack $menu & $submenu before I butcher them
    $menu = apply_filters('pre_ozh_adminmenu_menu', $menu);
    $submenu = apply_filters('pre_ozh_adminmenu_submenu', $submenu);
    $ozh_menu = '<div id="ozhmenu_wrap"><ul id="ozhmenu">';
    // Plugins: hack $ozh_menu before I start adding stuff to it
    $ozh_menu = apply_filters('pre_ozh_adminmenu_ozh_menu', $ozh_menu);
    if ($wp_ozh_adminmenu['minimode']) {
        $ozh_menu .= '<li id="oam_bloglink" class="ozhmenu_toplevel">' . wp_ozh_adminmenu_blogtitle() . '</li>';
    }
    $first = true;
    // 0 = name, 1 = capability, 2 = file, 3 = class, 4 = id, 5 = icon src
    foreach ($_menu = $menu as $key => $item) {
        // Top level menu
        if (strpos($item[4], 'wp-menu-separator') !== false) {
            continue;
        }
        $admin_is_parent = false;
        $class = array();
        if ($first) {
            $class[] = 'wp-first-item';
            $first = false;
        }
        if (!empty($submenu[$item[2]])) {
            $class[] = 'wp-has-submenu';
        }
        if ($parent_file && $item[2] == $parent_file || strcmp($self, $item[2]) == 0) {
            if (!empty($submenu[$item[2]])) {
                $class[] = 'wp-has-current-submenu current wp-menu-open';
            } else {
                $class[] = 'current';
            }
        }
        if (isset($item[4]) && !empty($item[4])) {
            $class[] = $item[4];
        }
        $class = $class ? ' class="' . join(' ', $class) . '"' : '';
        $id = isset($item[5]) && !empty($item[5]) ? 'oam_' . $item[5] : '';
        $anchor = $item[0];
        if ($wp_ozh_adminmenu['compact']) {
            $compactstyle = 'inline';
            $fullstyle = 'none';
        } else {
            $compactstyle = 'none';
            $fullstyle = 'inline';
        }
        if (isset($submenu_as_parent) && !empty($submenu[$item[2]])) {
            $submenu[$item[2]] = array_values($submenu[$item[2]]);
            // Re-index.
            $menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]);
            if ('index.php' != $submenu[$item[2]][0][2] && file_exists(WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}") || !empty($menu_hook)) {
                $admin_is_parent = true;
                $href = "admin.php?page={$submenu[$item[2]][0][2]}";
            } else {
                $href = $submenu[$item[2]][0][2];
            }
        } else {
            if (current_user_can($item[1])) {
                $menu_hook = get_plugin_page_hook($item[2], 'admin.php');
                if ('index.php' != $item[2] && file_exists(WP_PLUGIN_DIR . "/{$item[2]}") || !empty($menu_hook)) {
                    $admin_is_parent = true;
                    $href = "admin.php?page={$item[2]}";
                } else {
                    $href = $item[2];
                }
            }
        }
        $imgstyle = $wp_ozh_adminmenu['wpicons'] ? '' : 'style="display:none"';
        $img = '';
        if (isset($item[6]) && !empty($item[6])) {
            preg_match('/^dashicons/', $item[6], $matches);
            if ('none' === $item[6] || 'div' === $item[6]) {
                $img = '<div ' . $imgstyle . ' class="wp-menu-image"><br /></div>';
            } elseif (!empty($matches)) {
                $img = '<div ' . $imgstyle . ' class="wp-menu-image dashicons-before ' . $item[6] . '"><br /></div>';
            } else {
                $img = '<img ' . $imgstyle . ' class="wp-menu-image" src="' . $item[6] . '" alt="" />';
            }
        }
        if ($wp_ozh_adminmenu['toplinks']) {
            $href = "href='{$href}'";
        } else {
            $href = !empty($submenu[$item[2]]) ? '' : "href='{$href}'";
        }
        $ozh_menu .= "\t<li class='ozhmenu_toplevel' id='{$id}'><a {$href} {$class}>{$img}<span class='compact' style='display:{$compactstyle}'>&nbsp;</span><span class='full' style='display:{$fullstyle}'>{$anchor}</span></a>";
        // Sub level menus
        if (!empty($submenu[$item[2]])) {
            if (!isset($ulclass)) {
                $ulclass = '';
            }
            $ozh_menu .= "\n\t\t<ul{$ulclass}><li class='toplevel_label'>{$anchor}</li>\n";
            $first = true;
            foreach ($submenu[$item[2]] as $sub_key => $sub_item) {
                if (!current_user_can($sub_item[1])) {
                    continue;
                }
                $class = array();
                if ($first) {
                    $class[] = 'wp-first-item';
                    $first = false;
                }
                if (isset($submenu_file)) {
                    if ($submenu_file == $sub_item[2]) {
                        $class[] = 'current';
                    }
                    // If plugin_page is set the parent must either match the current page or not physically exist.
                    // This allows plugin pages with the same hook to exist under different parents.
                } else {
                    if (isset($plugin_page) && $plugin_page == $sub_item[2] && (!file_exists($item[2]) || $item[2] == $self) || !isset($plugin_page) && $self == $sub_item[2]) {
                        $class[] = 'current';
                    }
                }
                $subclass = $class ? ' class="' . join(' ', $class) . '"' : '';
                $menu_hook = get_plugin_page_hook($sub_item[2], $item[2]);
                if ('index.php' != $sub_item[2] && file_exists(WP_PLUGIN_DIR . "/{$sub_item[2]}") || !empty($menu_hook)) {
                    // If admin.php is the current page or if the parent exists as a file in the plugins or admin dir
                    $parent_exists = !$admin_is_parent && file_exists(WP_PLUGIN_DIR . "/{$item[2]}") && !is_dir(WP_PLUGIN_DIR . "/{$item[2]}") || file_exists($item[2]);
                    if ($parent_exists) {
                        $suburl = "{$item[2]}?page={$sub_item[2]}";
                    } elseif ('admin.php' == $pagenow || !$parent_exists) {
                        $suburl = "admin.php?page={$sub_item[2]}";
                    } else {
                        $suburl = "{$item[2]}?page={$sub_item[2]}";
                    }
                    // Get icons?
                    if ($wp_ozh_adminmenu['icons']) {
                        $plugin_icon = apply_filters('ozh_adminmenu_icon', $sub_item[2]);
                        $plugin_icon = apply_filters('ozh_adminmenu_icon_' . $sub_item[2], $sub_item[2]);
                        if ($plugin_icon != $sub_item[2]) {
                            // we have an icon: no default plugin class & we store the icon location
                            $plugin_icons[wp_ozh_adminmenu_sanitize_id($sub_item[2])] = $plugin_icon;
                            $icon = '';
                        } else {
                            // no icon: default plugin class
                            $icon = 'oam_plugin';
                        }
                    }
                } else {
                    $suburl = $sub_item[2];
                }
                // Custom logout menu?
                if ($sub_item[2] == 'ozh_admin_menu_logout') {
                    $suburl = wp_logout_url();
                }
                $subid = 'oamsub_' . wp_ozh_adminmenu_sanitize_id($sub_item[2]);
                $subanchor = strip_tags($sub_item[0]);
                if (!isset($icon)) {
                    $icon = '';
                }
                $ozh_menu .= "\t\t\t<li class='ozhmenu_sublevel {$icon}' id='{$subid}'><a href='{$suburl}'{$subclass}>{$subanchor}</a></li>\n";
            }
            $ozh_menu .= "</ul>";
        }
        $ozh_menu .= "</li>";
    }
    $ozh_menu .= "</ul></div>";
    // Plugins: hack $ozh_menu now it's complete
    $ozh_menu = apply_filters('post_ozh_adminmenu_ozh_menu', $ozh_menu);
    if (isset($plugin_icons)) {
        global $text_direction;
        $align = $text_direction == 'rtl' ? 'right' : 'left';
        echo "\n" . '<style type="text/css">' . "\n";
        foreach ($plugin_icons as $hook => $icon) {
            $hook = plugin_basename($hook);
            //echo "#oamsub_$hook a {background-image:url($icon);}\n";
            echo "#oamsub_{$hook} a {background:url({$icon}) center {$align} no-repeat;}\n";
        }
        echo "</style>\n";
    }
    echo $ozh_menu;
}