'tabs', 'description' => _a("Group arbitrary widgets into tabs")); $this->WP_Widget('atom-tabs', _a('Tabbed Widgets'), $widget_ops); } function widget($args, $instance){ if(!atom_get_options('jquery')) return atom_add_debug_message("jQuery required by {$args['widget_id']} ({$args['widget_name']}). Widget marked as inactive"); extract($args); $instance = wp_parse_args($instance, $this->defaults()); $active_tabs = is_array($instance['widgets']) ? $instance['widgets'] : array(); $all_widgets = $this->get_arbitrary_widgets(); $cookie = isset($_COOKIE["tabs-$this->id"]) ? $_COOKIE["tabs-$this->id"] : false; // build fx class $instance['effect'] = ' '.str_replace(',', '', $instance['effect']); $instance['effect'] = str_replace(' ', ' fx-', $instance['effect']); $output = array(); $count = 0; foreach($active_tabs as $w) foreach($all_widgets as $a) if(($a['id'] == $w) && ($widget = atom_get_widget($a['id']))): $count++; $classes = "nav-".implode(' ', $a['class']); if($count == 1) $classes .= " first"; elseif($count == count($active_tabs)) $classes .= " last"; if(($cookie == "nav-{$a['id']}") || (!$cookie && $count == 1)) $classes .= " active"; $title = apply_filters('atom_widget_tabs_title', ($a['title'] ? $a['title'] : ' '), $a, $instance); $hidden = (($cookie == $classes) || (!$cookie && $count == 1)) ? '' : "hidden"; $output[$count]['tab'] = "
  • {$title}
  • \n"; $output[$count]['content'] = "
    \n{$widget}\n
    \n"; endif; if(empty($active_tabs) || empty($output)) return atom_add_debug_message("Tabbed widgets are not configured or missing content in {$args['widget_id']} ({$args['widget_name']}). Widget marked as inactive"); echo $before_widget; ?>
    defaults()); } function defaults(){ // default settings return apply_filters('atom_widget_tabs_defaults', array( 'widgets' => array(), 'effect' => 'fade', 'easing' => 'easeOutExpo', ), $this); } function form($instance){ if(!atom_get_options('jquery')): ?>

    defaults()); $active_tabs = is_array($instance['widgets']) ? $instance['widgets'] : array(); ?>
    > number)): $all_widgets = $this->get_arbitrary_widgets(); if(empty($all_widgets)): echo '

    '._a("To add tabs, you must have at least one active arbitrary widget. Click save to refresh...").'

    '; else: // sort $ordered_widgets = array(); foreach($active_tabs as $w) foreach($all_widgets as $i => $a) if($w == $a['id']): $ordered_widgets[] = $a; unset($all_widgets[$i]); endif; $ordered_widgets = array_merge($ordered_widgets, $all_widgets); $sidebars_widgets = wp_get_sidebars_widgets(); echo '

    '._a("Create Tabs for:").'

    '; echo "\n
    "; endif; ?>

    $widget_id): // get the widget instance settings $options = atom_get_options($wp_registered_widgets[$widget_id]['callback'][0]->option_name); $options = $options[$wp_registered_widgets[$widget_id]['params'][0]['number']]; // generate css classes, that can be used for styling the tabs with things like icons $id_base = $wp_registered_widgets[$widget_id]['callback'][0]->id_base; if($id_base == 'atom-splitter') continue; // no splitters here $classes = array(); $classes[] = str_replace('atom-', '', $id_base); // first class (the widget id_base without "atom-") // add extra classes based on widget options for certain widgets // this is to allow different styling for widgets of the same type inside the tabs (for eg. recent/popular/random posts) switch($id_base): // order + post type if different than "post", + related if checked case 'posts': $classes[] = "posts-{$options['order_by']}"; if($options['post_type'] != 'post') $classes[] = "posts-{$options['post_type']}"; if($options['related']) $classes[] = "posts-related"; break; // menu id case 'menu': $classes[] = "posts-{$options['nav_menu']}"; break; // term taxonomy case 'tag_cloud': $classes[] = "tag_cloud-{$options['taxonomy']}"; break; // term taxonomy case 'terms': $classes[] = "terms-{$options['taxonomy']}"; break; // link category ID case 'links': if($options['category']) $classes[] = "links-{$options['category']}"; break; // archives case 'archives': $classes[] = "archives-{$options['type']}"; break; // blogs, sort order case 'blogs': $classes[] = "blogs-{$options['order_by']}"; break; endswitch; $matches[$count]['id'] = $widget_id; $matches[$count]['number'] = $count; $matches[$count]['name'] = $wp_registered_widgets[$widget_id]['name']; $matches[$count]['title'] = isset($options['title']) ? $options['title'] : $matches[$count]['name']; $matches[$count]['class'] = apply_filters('atom_widget_tabs_classes', $classes, $options, $count); // use first class as slug (needed by the cookie to identify active tab class) $matches[$count]['slug'] = $id_base; $count++; endforeach; return $matches; endif; return array(); } }