Location: PHPKode > scripts > Quick Navigation Panel > quick-navigation-panel/quick-navigation-panel.php
<?php
/*
Plugin Name: Quick Navigation Panel
Plugin URI: http://rubensargsyan.com/wordpress-plugin-quick-navigation-panel/
Description: This plugin helps the visitors to navigate more quickly. <a href="options-general.php?page=quick-navigation-panel.php">Settings</a>
Version: 1.0
Author: Ruben Sargsyan
Author URI: http://rubensargsyan.com/
*/

/*  Copyright 2010 Ruben Sargsyan (email: hide@address.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

$quick_navigation_panel_plugin_url = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
$quick_navigation_panel_plugin_title = "Quick Navigation Panel";
$quick_navigation_panel_plugin_prefix = "quick_navigation_panel_";
$quick_navigation_panel_version = "1.0";

function load_quick_navigation_panel(){
    $quick_navigation_panel_plugin_prefix = "quick_navigation_panel_";
    $quick_navigation_panel_version = "1.0";

    if(get_quick_navigation_panel_settings()===false){
        set_default_quick_navigation_panel_settings();
    }

    if(get_option("quick_navigation_panel_version")===false){
        add_option("quick_navigation_panel_version",$quick_navigation_panel_version);
    }elseif(get_option("quick_navigation_panel_version")<$quick_navigation_panel_version){
        update_option("quick_navigation_panel_version",$quick_navigation_panel_version);
    }
}

function set_quick_navigation_panel_settings($quick_navigation_panel_settings){
    $quick_navigation_panel_plugin_prefix = "quick_navigation_panel_";

    add_option($quick_navigation_panel_plugin_prefix."settings",$quick_navigation_panel_settings);
}

function set_default_quick_navigation_panel_settings(){
    $quick_navigation_panel_plugin_prefix = "quick_navigation_panel_";

    $quick_navigation_panel_blocks = array("quick_navigation_panel_pages"=>"yes","quick_navigation_panel_categories"=>"yes","quick_navigation_panel_archive"=>"yes","quick_navigation_panel_tags"=>"yes","quick_navigation_panel_search"=>"yes");
    $quick_navigation_panel_color = "#214579";
    $quick_navigation_panel_hover_color = "#750909";
    $quick_navigation_panel_border_size = "1px";
    $quick_navigation_panel_border_color = "#000000";
    $quick_navigation_panel_background = "#EEEEEE";

    $quick_navigation_panel_settings = array($quick_navigation_panel_plugin_prefix."blocks"=>$quick_navigation_panel_blocks,$quick_navigation_panel_plugin_prefix."color"=>$quick_navigation_panel_color,$quick_navigation_panel_plugin_prefix."hover_color"=>$quick_navigation_panel_hover_color,$quick_navigation_panel_plugin_prefix."border_size"=>$quick_navigation_panel_border_size,$quick_navigation_panel_plugin_prefix."border_color"=>$quick_navigation_panel_border_color,$quick_navigation_panel_plugin_prefix."background"=>$quick_navigation_panel_background);

    set_quick_navigation_panel_settings($quick_navigation_panel_settings);
}

function update_quick_navigation_panel_settings($quick_navigation_panel_settings){
    global $quick_navigation_panel_plugin_prefix;

    $current_quick_navigation_panel_settings = get_quick_navigation_panel_settings();

    $quick_navigation_panel_settings = array_merge($current_quick_navigation_panel_settings,$quick_navigation_panel_settings);

    update_option($quick_navigation_panel_plugin_prefix."settings",$quick_navigation_panel_settings);
}

function get_quick_navigation_panel_settings(){
    global $quick_navigation_panel_plugin_prefix;

    $quick_navigation_panel_settings = get_option($quick_navigation_panel_plugin_prefix."settings");

    return $quick_navigation_panel_settings;
}

function quick_navigation_panel_menu(){
    if(function_exists('add_options_page')){
        add_options_page('Quick Navigation Panel','Quick Navigation Panel', 'manage_options', basename(__FILE__), 'quick_navigation_panel_admin') ;
    }
}

function quick_navigation_panel_admin(){
    global $quick_navigation_panel_plugin_url, $quick_navigation_panel_plugin_title, $quick_navigation_panel_plugin_prefix;
    ?>
    <script src="<?php echo($quick_navigation_panel_plugin_url.'javascript/jscolor.js'); ?>" type="text/javascript"></script>
    <?php

    if($_GET["page"]==basename(__FILE__)){
        if($_POST["action"]=="save"){
            $quick_navigation_panel_settings = get_quick_navigation_panel_settings();

            $quick_navigation_panel_blocks = array();

            if(!empty($_POST[$quick_navigation_panel_plugin_prefix."blocks"])){
                foreach($_POST[$quick_navigation_panel_plugin_prefix."blocks"] as $block){
                    $quick_navigation_panel_blocks[$block] = "yes";
                }
            }else{
                $quick_navigation_panel_blocks = $quick_navigation_panel_settings[$quick_navigation_panel_plugin_prefix."blocks"];
            }

            $quick_navigation_panel_color = "#".trim(strip_tags(substr($_POST[$quick_navigation_panel_plugin_prefix."color"],0,6)));
            $quick_navigation_panel_hover_color = "#".trim(strip_tags(substr($_POST[$quick_navigation_panel_plugin_prefix."hover_color"],0,6)));
            $quick_navigation_panel_border_size = trim(strip_tags($_POST[$quick_navigation_panel_plugin_prefix."border_size"]));
            $quick_navigation_panel_border_color = "#".trim(strip_tags(substr($_POST[$quick_navigation_panel_plugin_prefix."border_color"],0,6)));
            $quick_navigation_panel_background = "#".trim(strip_tags(substr($_POST[$quick_navigation_panel_plugin_prefix."background"],0,6)));

            $quick_navigation_panel_settings_new = array($quick_navigation_panel_plugin_prefix."blocks"=>$quick_navigation_panel_blocks,$quick_navigation_panel_plugin_prefix."color"=>$quick_navigation_panel_color,$quick_navigation_panel_plugin_prefix."hover_color"=>$quick_navigation_panel_hover_color,$quick_navigation_panel_plugin_prefix."border_size"=>$quick_navigation_panel_border_size,$quick_navigation_panel_plugin_prefix."border_color"=>$quick_navigation_panel_border_color,$quick_navigation_panel_plugin_prefix."background"=>$quick_navigation_panel_background);

            foreach($quick_navigation_panel_settings_new as $quick_navigation_panel_option => $quick_navigation_panel_option_value){
                if(empty($quick_navigation_panel_option_value)){
                    unset($quick_navigation_panel_settings_new[$quick_navigation_panel_option]);
                }
            }

            update_quick_navigation_panel_settings($quick_navigation_panel_settings_new);

            echo('<div id="message" class="updated fade"><p><strong>'.$quick_navigation_panel_plugin_title.' Settings Saved.</strong></p></div>');
        }elseif($_POST["action"]=="reset"){
            delete_option($quick_navigation_panel_plugin_prefix."settings");

            echo('<div id="message" class="updated fade"><p><strong>'.$quick_navigation_panel_plugin_title.' Settings Reset.</strong></p></div>');
        }
    }

    if(get_quick_navigation_panel_settings()===false){
        set_default_quick_navigation_panel_settings();
    }

    $quick_navigation_panel_settings = get_quick_navigation_panel_settings();
    ?>
    <div class="wrap">
      <h2><?php echo $quick_navigation_panel_plugin_title; ?> Settings</h2>

      <form method="post">
        <table width="100%" border="0" id="quick_navigation_panel_settings_table">
          <tr>
            <td width="35%" rowspan="2" valign="middle"><strong>Set Quick Navigation Panel Blocks</strong></td>
            <td width="65%">
                <label for="<?php echo($quick_navigation_panel_plugin_prefix); ?>pages">Pages:</label> <input name="<?php echo($quick_navigation_panel_plugin_prefix); ?>blocks[]" id="<?php echo($quick_navigation_panel_plugin_prefix); ?>pages" value="<?php echo($quick_navigation_panel_plugin_prefix); ?>pages" type="checkbox" <?php if($quick_navigation_panel_settings[$quick_navigation_panel_plugin_prefix."blocks"]["quick_navigation_panel_pages"]=="yes"){ echo('checked="checked"'); } ?> />&nbsp;&nbsp;<label for="<?php echo($quick_navigation_panel_plugin_prefix); ?>categories">Categories:</label> <input name="<?php echo($quick_navigation_panel_plugin_prefix); ?>blocks[]" id="<?php echo($quick_navigation_panel_plugin_prefix); ?>categories" value="<?php echo($quick_navigation_panel_plugin_prefix); ?>categories" type="checkbox" <?php if($quick_navigation_panel_settings[$quick_navigation_panel_plugin_prefix."blocks"]["quick_navigation_panel_categories"]=="yes"){ echo('checked="checked"'); } ?> />&nbsp;&nbsp;<label for="<?php echo($quick_navigation_panel_plugin_prefix); ?>archive">Archive:</label> <input name="<?php echo($quick_navigation_panel_plugin_prefix); ?>blocks[]" id="<?php echo($quick_navigation_panel_plugin_prefix); ?>archive" value="<?php echo($quick_navigation_panel_plugin_prefix); ?>archive" type="checkbox" <?php if($quick_navigation_panel_settings[$quick_navigation_panel_plugin_prefix."blocks"]["quick_navigation_panel_archive"]=="yes"){ echo('checked="checked"'); } ?> />&nbsp;&nbsp;<label for="<?php echo($quick_navigation_panel_plugin_prefix); ?>authors">Authors:</label> <input name="<?php echo($quick_navigation_panel_plugin_prefix); ?>blocks[]" id="<?php echo($quick_navigation_panel_plugin_prefix); ?>authors" value="<?php echo($quick_navigation_panel_plugin_prefix); ?>authors" type="checkbox" <?php if($quick_navigation_panel_settings[$quick_navigation_panel_plugin_prefix."blocks"]["quick_navigation_panel_authors"]=="yes"){ echo('checked="checked"'); } ?> />&nbsp;&nbsp;<label for="<?php echo($quick_navigation_panel_plugin_prefix); ?>tags">Tags:</label> <input name="<?php echo($quick_navigation_panel_plugin_prefix); ?>blocks[]" id="<?php echo($quick_navigation_panel_plugin_prefix); ?>tags" value="<?php echo($quick_navigation_panel_plugin_prefix); ?>tags" type="checkbox" <?php if($quick_navigation_panel_settings[$quick_navigation_panel_plugin_prefix."blocks"]["quick_navigation_panel_tags"]=="yes"){ echo('checked="checked"'); } ?> />&nbsp;&nbsp;<label for="<?php echo($quick_navigation_panel_plugin_prefix); ?>search">Search:</label> <input name="<?php echo($quick_navigation_panel_plugin_prefix); ?>blocks[]" id="<?php echo($quick_navigation_panel_plugin_prefix); ?>search" value="<?php echo($quick_navigation_panel_plugin_prefix); ?>search" type="checkbox" <?php if($quick_navigation_panel_settings[$quick_navigation_panel_plugin_prefix."blocks"]["quick_navigation_panel_search"]=="yes"){ echo('checked="checked"'); } ?> />
            </td>
          </tr>
          <tr>
            <td><small>Check those, which will be shown on the quick navigation panel</small></td>
          </tr>
          <tr>
            <td width="35%" rowspan="2" valign="middle"><strong>Set Quick Navigation Panel Text Color</strong></td>
            <td width="65%">
                <input autocomplete="off" class="color" name="<?php echo($quick_navigation_panel_plugin_prefix); ?>color" id="<?php echo($quick_navigation_panel_plugin_prefix); ?>color" type="text" style="width:100px;" value="<?php echo($quick_navigation_panel_settings[$quick_navigation_panel_plugin_prefix."color"]); ?>" />
            </td>
          </tr>
          <tr>
            <td><small>Click on the text field to set another color.</small></td>
          </tr>
          <tr>
            <td width="35%" rowspan="2" valign="middle"><strong>Set Quick Navigation Panel Hover Text Color</strong></td>
            <td width="65%">
                <input autocomplete="off" class="color" name="<?php echo($quick_navigation_panel_plugin_prefix); ?>hover_color" id="<?php echo($quick_navigation_panel_plugin_prefix); ?>hover_color" type="text" style="width:100px;" value="<?php echo($quick_navigation_panel_settings[$quick_navigation_panel_plugin_prefix."hover_color"]); ?>" />
            </td>
          </tr>
          <tr>
            <td><small>Click on the text field to set another color.</small></td>
          </tr>
          <tr>
            <td width="35%" rowspan="2" valign="middle"><strong>Set Quick Navigation Panel Border Size</strong></td>
            <td width="65%">
                <input name="<?php echo($quick_navigation_panel_plugin_prefix); ?>border_size" id="<?php echo($quick_navigation_panel_plugin_prefix); ?>border_size" type="text" style="width:100px;" value="<?php echo($quick_navigation_panel_settings[$quick_navigation_panel_plugin_prefix."border_size"]); ?>" />
            </td>
          </tr>
          <tr>
            <td><small>This option sets the border size (Example: 1px, 0.8pt, 0.2em ... ) of the quick navigation panel.</small></td>
          </tr>
          <tr>
            <td width="35%" rowspan="2" valign="middle"><strong>Set Quick Navigation Panel Border Color</strong></td>
            <td width="65%">
                <input autocomplete="off" class="color" name="<?php echo($quick_navigation_panel_plugin_prefix); ?>border_color" id="<?php echo($quick_navigation_panel_plugin_prefix); ?>border_color" type="text" style="width:100px;" value="<?php echo($quick_navigation_panel_settings[$quick_navigation_panel_plugin_prefix."border_color"]); ?>" />
            </td>
          </tr>
          <tr>
            <td><small>Click on the text field to set another color.</small></td>
          </tr>
          <tr>
            <td width="35%" rowspan="2" valign="middle"><strong>Set Quick Navigation Panel Background Color</strong></td>
            <td width="65%">
                <input autocomplete="off" class="color" name="<?php echo($quick_navigation_panel_plugin_prefix); ?>background" id="<?php echo($quick_navigation_panel_plugin_prefix); ?>background" type="text" style="width:100px;" value="<?php echo($quick_navigation_panel_settings[$quick_navigation_panel_plugin_prefix."background"]); ?>" />
            </td>
          </tr>
          <tr>
            <td><small>Click on the text field to set another color.</small></td>
          </tr>
          <tr>
            <td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2">&nbsp;</td>
          </tr>
        </table>
        <p class="submit">
          <input name="save" type="submit" value="Save changes" />
          <input type="hidden" name="action" value="save" />
        </p>
      </form>
      <form method="post">
        <p class="submit">
          <input name="reset" type="submit" value="Reset" />
          <input type="hidden" name="action" value="reset" />
        </p>
      </form>
    </div>
    <?php
}

function quick_navigation_panel_header(){
    global $quick_navigation_panel_plugin_url;
?>
    <link rel="stylesheet" href="<?php echo($quick_navigation_panel_plugin_url); ?>css/quick-navigation-panel-style.php" type="text/css" />
    <!--[if lt IE 7]>
    <link rel="stylesheet" href="<?php echo($quick_navigation_panel_plugin_url); ?>css/quick-navigation-panel-iestyle.php" type="text/css" />

    <script type="text/javascript">

    quick_navigation_panel_hover = function() {
    	var quick_navigation_panel_lis = document.getElementById("quick_navigation_panel_menu").getElementsByTagName("li");
    	for (var i=0; i<quick_navigation_panel_lis.length; i++) {
    		quick_navigation_panel_lis[i].onmouseover=function() {
    			this.className+=" over";
    		}
    		quick_navigation_panel_lis[i].onmouseout=function() {
    			this.className=this.className.replace(new RegExp(" over\\b"), "");
    		}
    	}
    }
    if(window.attachEvent) window.attachEvent("onload", quick_navigation_panel_hover);

    </script>
    <![endif]-->
<?php
}

function quick_navigation_panel(){
    global $quick_navigation_panel_plugin_prefix, $quick_navigation_panel_plugin_url, $quick_navigation_panel_plugin_title;

    $quick_navigation_panel_settings = get_quick_navigation_panel_settings();
    $quick_navigation_panel_blocks = $quick_navigation_panel_settings[$quick_navigation_panel_plugin_prefix."blocks"];
?>
    <div id="quick_navigation_panel" class="quick_navigation_panel">
        <ul id="quick_navigation_panel_menu">
            <?php if($quick_navigation_panel_blocks["quick_navigation_panel_pages"]=="yes"){ ?>
            <li><a href="#">Pages</a>
                <ul>
                    <li><a href="<?php bloginfo('url'); ?>">Home</a></li>
                    <?php
                    $pages = get_pages("parent=0&sort_column=menu_order&sort_order=asc");

                    if(!empty($pages)){
                        foreach($pages as $page){
                            $subpages = get_pages("child_of=".$page->ID."&sort_column=menu_order&sort_order=asc");
                        ?>
                            <li><a href="<?php echo(get_page_link($page->ID)); ?>"><?php echo($page->post_title); ?><?php if(!empty($subpages)){ echo(" &raquo;"); } ?></a>
                        <?php
                            if(!empty($subpages)){
                                ?>
                                <ul>
                                <?php
                                foreach($subpages as $subpage){
                                ?>
                                    <li><a href="<?php echo(get_page_link($subpage->ID)); ?>"><?php echo($subpage->post_title); ?></a></li>
                                <?php
                                }
                                ?>
                                </ul>
                                <?php
                            }
                            ?>
                            </li>
                            <?php
                        }
                    }
                    ?>
                </ul>
            </li>
            <?php } ?>
            <?php if($quick_navigation_panel_blocks["quick_navigation_panel_categories"]=="yes"){ ?>
        	<li><a href="#">Categories</a>
                <ul>
                    <?php
                    $categories = get_categories("parent=0");

                    if(!empty($categories)){
                        foreach($categories as $category){
                            $subcategories = get_categories("child_of=".$category->term_id);
                        ?>
                            <li><a href="<?php echo(get_category_link($category->term_id)); ?>"><?php echo($category->name); ?><?php if(!empty($subcategories)){ echo(" &raquo;"); } ?></a>
                        <?php
                            if(!empty($subcategories)){
                                ?>
                                <ul>
                                <?php
                                foreach($subcategories as $subcategory){
                                ?>
                                    <li><a href="<?php echo(get_category_link($subcategory->term_id)); ?>"><?php echo($subcategory->name); ?></a></li>
                                <?php
                                }
                                ?>
                                </ul>
                                <?php
                            }
                            ?>
                            </li>
                            <?php
                        }
                    }
                    ?>
                </ul>
        	</li>
            <?php } ?>
            <?php if($quick_navigation_panel_blocks["quick_navigation_panel_archive"]=="yes"){ ?>
            <li><a href="#">Archive</a>
                <ul>
                    <?php wp_get_archives("type=monthly&limit=15"); ?>
                </ul>
        	</li>
            <?php } ?>
            <?php if($quick_navigation_panel_blocks["quick_navigation_panel_authors"]=="yes"){ ?>
            <li><a href="#">Authors</a>
                <ul>
                    <?php wp_list_authors("exclude_admin=0"); ?>
                </ul>
        	</li>
            <?php } ?>
            <?php if($quick_navigation_panel_blocks["quick_navigation_panel_tags"]=="yes"){ ?>
            <li><a href="#">Tags</a>
                <ul>
                    <?php
                    $tags = get_tags("number=15&orderby=count&order=desc");

                    if(!empty($tags)){
                        foreach($tags as $tag){
                        ?>
                        <li><a href="<?php echo(get_tag_link($tag->term_id)); ?>"><?php echo($tag->name); ?></a></li>
                        <?php
                        }
                    }
                    ?>
                </ul>
        	</li>
            <?php } ?>
        </ul>
        <?php if($quick_navigation_panel_blocks["quick_navigation_panel_search"]=="yes"){ ?>
        <div id="quick_navigation_panel_searchform">
        <form method="get" action="<?php bloginfo('url'); ?>/">
        	<input type="text" value="" name="s" id="s" />
        	<input type="submit" id="quick_navigation_panel_searchsubmit" value="Search" />
        </form>
        </div>
        <?php } ?>
        <div id="quick_navigation_panel_info"><div id="quick_navigation_panel_info_panel" style="display: none"><h1><?php echo($quick_navigation_panel_plugin_title); ?></h1><div><a href="http://rubensargsyan.com/wordpress-plugin-quick-navigation-panel/" target="_blank">Plugin Homepage</a></div><div><a href="http://rubensargsyan.com/" target="_blank">Author Homepage</a></div><div id="quick_navigation_panel_info_panel_close"><span onclick="document.getElementById('quick_navigation_panel_info_panel').style.display = 'none';">Close X</span></div></div><img src="<?php echo($quick_navigation_panel_plugin_url); ?>info.gif" alt="Info" onclick="document.getElementById('quick_navigation_panel_info_panel').style.display = 'block';"></div>
    </div>
<?php
}

add_action('plugins_loaded','load_quick_navigation_panel');
add_action('admin_menu', 'quick_navigation_panel_menu');
add_action('wp_head', 'quick_navigation_panel_header');
add_action('wp_footer', 'quick_navigation_panel');
?>
Return current item: Quick Navigation Panel