tabselected, while unselected tabs have a class of tab. Version: 1.0.2b Author: David Burton Author URI: http://dynamictangentconceptions.dtcnet.co.uk */ /* Copyright 2005 dtcnet (email : info@dynamictangentconceptions.dtcnet.co.uk) 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ $dtabs_current_version = '1.0.2b'; // dtc_add_pages() is the sink function for the 'admin_menu' hook function dtab_add_pages() { if (function_exists('add_options_page')) { add_options_page('options-general.php', 'Tabs', 8, basename(__FILE__), 'dtab_option_page'); } if (function_exists('add_management_page')) { add_management_page('Manage Tabs', 'Tabs', 8, basename(__FILE__), 'dtab_manage_page'); } } function dtab_checked($option) { if ($option == true) { return ' checked'; } } // dtab_option_page outputs the tabs options preference pain function dtab_option_page() { add_option('dtabs_options', array('css' => '')); $dtabs_options = get_option('dtabs_options'); if ($_GET['action'] == 'save') { $dtabs_options = array( 'auto_css' => $_POST['auto_css'], 'css' => $_POST['css_code'], 'before' => $_POST['before'], 'after' => $_POST['after']); update_option('dtabs_options',$dtabs_options); ?>

Save successful.

« Go back to make changes

function hide(id){ eval("document.getElementById(\'"+id+"\').style.display=\'none\'"); } function show(id){ eval("document.getElementById(\'"+id+"\').style.display=\'inline\'"); } function more(contentid,titleid) { if (eval("document.getElementById(\'"+contentid+"\').style.display==\'inline\'")) { hide(contentid); eval("document.getElementById(\'"+titleid+"\').style.backgroundPosition=\'top right\'"); } else { show(contentid); eval("document.getElementById(\'"+titleid+"\').style.backgroundPosition=\'bottom right\'"); } } function extra(contentid,titleid) { if (eval("document.getElementById(\'"+titleid+"\').checked == true")) { eval("document.getElementById(\'"+contentid+"\').style.display=\'table-row\'"); } else { hide(contentid); } } function set_css(use_default_css) { default_css = "\n\ #tabbar ul li {\n\ display:inline;\n\ }\n\ #tabbar a {\n\ display: inline-table;\n\ text-align: center;\n\ vertical-align: middle;\n\ width: 100px;\n\ height: 25px;\n\ }\n\ .tab {\n\ background-color: white;\n\ display: inline;\n\ }\n\ .tabselected {\n\ background-color: grey;\n\ display: inline;\n\ }\n\ .dmenu {\n\ display: none;\n\ margin: 25px 0px 0px 2px;\n\ padding: 5px 5px 5px 5px;\n\ background-color: yellow;\n\ position: absolute;\n\ z-index: 100;\n\ filter:alpha(opacity=\'90\');\n\ opacity: .9;\n\ min-width: 88px;\n\ }\n\ "; '; if ($dtabs_options['css'] != NULL) { echo 'if (use_default_css) { document.getElementById(\'css_code\').value = default_css; } else { document.getElementById(\'css_code\').value = \''.str_replace('
','\n\\', nl2br($dtabs_options['css'])).'\'; } '; } else { echo 'document.getElementById(\'css_code\').value = default_css; '; } echo ' }

Tab Options

Automatic css generation:
css styling:
Use default Reset
html before:
html after:


Info
'; } } // dtab_manage_page outputs the tabs preference pain function dtab_manage_page() { global $wpdb; $default = array(1 => array('name' => 'NULL', 'label' => 'Home', 'url' => '/', 'title' => 'Back to the main page', 'type' => 'blog')); add_option('dtabs', $default); $dtab = get_option('dtabs'); $total_tabs = count($dtab); $title = 'Dynamic Tabs Management'; $complete_message = '

'; $success_message = 'Save successful.'; $error_message = 'Error
'; $delete_message = 'Tab successfully deleted.'; $save_message = 'Settings successfully saved.'; $reset_message = 'dTab settings successfully reset to defaults.'; if ($_GET['action'] == 'edit') { $title = $title.': Edit Tab'; $intro = '

Info
'; } else { $title = $title.': Overview'; $intro = ''; if ($_GET['action'] == 'save') { $message = true; $number = trim($_POST['number']); $label = trim($_POST['label']); $title = trim($_POST['title']); $type = trim($_POST['type']); $url = trim($_POST['url']); $name = trim($_POST['name']); $menu = $_POST['menu']; $menuid = trim($_POST['id']); if (!is_numeric($number) && empty($number)) { $number = $total_tabs+1; $success_message .= '
  • The tab number was set to '.$number.'.
  • '; } if (!is_numeric($number)) { $number = ($total_tabs+1); } if ($number != $_GET['otab']) { if ($number < 1) { $success_message .= '
  • The tab number should be at least 1 and so was changed to 1.
  • '; $number = 1; } elseif ($number > ($total_tabs+1)) { $success_message .= '
  • The tab number was changed to be only one higher than the previous total number of tabs
  • '; $number = ($total_tabs+1); } if ($number < $_GET["otab"]) { $temp = $dtab; foreach ($temp as $i => $v) { if (($i >= $number) && ($i < $_GET["otab"])) { $dtab[$i+1] = $v; } } } elseif ($number > $_GET["otab"]) { $temp = $dtab; foreach ($temp as $i => $v) { if (($i <= $number) && ($i > $_GET["otab"])) { $dtab[$i-1] = $v; } } } } if (empty($label)) { $success_message .= '
  • The tab name was also used for it\'s label.
  • '; $label = strtoupper(substr($name,0,1)).strtolower(substr($name,1)); } $dtab[$number] = array( 'name' => $name, 'label' => $label, 'url' => $url, 'title' => $title, 'type' => $type, 'menu' => $menu, 'id' => $menuid); $success = true; update_option('dtabs',$dtab); } elseif ($_GET['action'] == 'delete') { $message = true; $complete_message .= $delete_message; unset($dtab[$_GET['tab']]); $temp = array_values($dtab); $dtab = NULL; foreach ($temp as $i => $v) { $dtab[$i+1] = $v; } update_option('dtabs',$dtab); } elseif ($_GET['action'] == 'reset') { $message = true; $complete_message .= $reset_message; delete_option('dtabs',$default); } } if ( $message == true ) { if ( $error == true ) { $complete_message .= $error_message; } if ( $success == true ) { $complete_message .= $success_message; } $complete_message .= '

    '; if ( $error == true ) { $complete_message .= ' « Go back to make changes
    '; } $complete_message .= ' « Return to Tab List

    '; echo $complete_message; } else { echo '

    '.$title.'

    '.$intro.' '; if ($_GET['action'] == 'edit') { echo '
    Tab Number:
    Tab type: ';?>
    Tab name:
    '; ?>
    Tab Label: " size="50" />
    Tab URL/Path/Permalink: " size="50" />
    Tab Description: " size="50" />
    Menu: Show menu on hover? /> " />

    '; } else { echo '

    '; } echo '

    « Return to Tab List

    '; } else { echo ' '; ksort($dtab); if (is_array($dtab)) { foreach ($dtab as $i => $v ) { if ($i%2) { echo ''; } else { echo ''; } echo ' '; if ($dtab[$i]["name"] == "NULL") { echo ''; } else { echo ' '; } echo ' '; if (strlen($dtab[$i]["url"]) >= 44) { $short_url = substr($dtab[$i]["url"],0,20).'....'.substr($dtab[$i]["url"],strlen($dtab[$i]["url"])-20,20); echo ' '; } else { echo ''; } echo ' '; } } echo '
    Number Name Label URL/Path/Permalink Description
    '.$i.'blog/main page'.$dtab[$i]["name"].''.$dtab[$i]["label"].''.$short_url.''.$dtab[$i]["url"].''.$dtab[$i]["title"].' Edit Delete

    Create New Tab »
    Reset

    '; ?>
    Info
    get_results("SELECT id, post_parent FROM $wpdb->posts", ARRAY_A); $post = $wp_query->post; foreach ($page_list as $page) { $pages[$page['id']] = $page; } $id = $post->ID; $parents = true; while ($parents != false) { $page_parents[$id] = $id; $id = $pages[$id]['post_parent']; if ($id == 0) { $parents = false; } } } elseif (is_single() OR is_category()) { $cat_list = $wpdb->get_results("SELECT term_id, parent FROM $wpdb->term_taxonomy WHERE (taxonomy = 'category')", ARRAY_A); foreach ($cat_list as $cat) { $cats[$cat['term_id']] = $cat; } if (is_single()) { $categories = get_the_category(); foreach ($categories as $cat) { $id = $catid = $cat->cat_ID; $parents = true; while ($parents != false) { $category_parents[$catid][$id] = $id; $id = $cats[$id]['parent']; if ($id == 0) { $parents = false; } } } } else { $id = $catid = intval(get_query_var('cat')); $parents = true; while ($parents != false) { $category_parents[$catid][$id] = $id; $id = $cats[$id]['parent']; if ($id == 0) { $parents = false; } } } } $have_menus = NULL; foreach ($dtabs as $i => $tab) { if (is_page() AND $tab['type'] == 'page') { $i = 0; foreach ($page_parents as $page_id) { if ($tab['id'] == $page_id) { $current_tabs[] = array('name' => $tab['name'], 'level' => $i); } $i++; } } elseif ((is_single() AND ($tab['type'] == 'post' OR $tab['type'] == 'cat')) OR (is_category() AND $tab['type'] == 'cat')) { if (is_single() AND $tab['type'] == 'post' AND $tab['id'] == $post->ID) { $current_tabs[] = array('name' => $tab['name'], 'level' => 0); } foreach ($category_parents as $parents) { $i = 0; foreach ($parents as $cat_id) { if ($tab['id'] == $cat_id) { $current_tabs[] = array('name' => $tab['name'], 'level' => $i); } $i++; } } } if (isset($tab['menu']) AND $tab['menu']==true AND is_null($have_menus)) { $have_menus = true; } } if (is_archive() AND !is_category()) { $current_tabs[] = array('name' => 'archives', 'level' => 0); } if (is_home() OR !isset($current_tabs)) { $current_tab = 'NULL'; } else { $current_tab = array('name' => $current_tabs[0]['name'], 'level' => $current_tabs[0]['level']); foreach ($current_tabs as $ctab) { if ($ctab['level'] < $current_tab['level']) { $current_tab = $ctab; } } $current_tab = $current_tab['name']; } $tabs = NULL; foreach ($dtabs as $i => $tab) { if ($have_menus == true) { if (isset($tab['menu']) AND $tab['menu'] == true) { $onmouseover = ' onmouseover="showmenu(\''.$tab['name'].'_menu\',\''.$tab['name'].'_button\');"'; $onmouseout = ' onmouseout="hidemenu();"'; echo ' '; } else { $onmouseover = ' onmouseover="hidemenunow();"'; $onmouseout = ''; } } else { $onmouseover = ''; $onmouseout = ''; } if ($tab['archives'] == 'post' OR $tab['type'] == 'bookmarks') { $onclick = ' onclick="return false"'; } else { $onclick = ''; } if ($tab['type'] == 'blog') { $url = get_bloginfo("url"); } elseif ($tab['type'] == 'cat') { $url = get_category_link($tab['id']); } elseif ($tab['type'] == 'post' OR $tab['type'] == 'page') { $url = get_permalink($tab['id']); } else { $url = $tab['url']; } if ($current_tab == $tab['name']) { $class = 'tabselected'; } else { $class = 'tab'; } if (!is_null($have_menus)) { $id = ' id="'.$tab['name'].'_button"'; } else { $id = NULL; } $tabs .= '
  • '.$dtabs_options['before'].$before.''.stripslashes($tab['label']).''.$after.$dtabs_options['after'].'
  • '; } echo ' '; } } /*CSS Styling*/ function dtabs_css() { global $dtabs_options; echo ' '; } function dtabs_javascript() { echo ' '; } // Insert the dtc_add_pages() sink into the plugin hook list for 'admin_menu' add_action('admin_menu', 'dtab_add_pages'); // Add auto css if necessary if (is_array($dtabs_options = get_option('dtabs_options'))) { if ($dtabs_options['auto_css']) { add_filter('wp_head', 'dtabs_css', 2); } } if (is_array($dtabs = get_option('dtabs'))) { $outputjs = false; foreach ($dtabs as $dtab) { if ($dtab['menu'] == true) { $outputjs = true; } } if ($outputjs == true) { add_filter('wp_head', 'dtabs_javascript', 2); } } ?>