The Quick Tabs module allows you to create blocks of tabbed content. You can create a block on your site containing up to six tabs with corresponding content. Clicking on the tabs makes the corresponding content display instantly (it uses jQuery). The content for each tabbed section can be either a view or an existing block. It is an ideal way to do something like the Most Popular / Most Emailed stories tabs you see on many news websites.
Once created, the Quick Tabs blocks show up in your block listing, ready to be configured and enabled like other blocks.
Multiple Quick Tabs blocks can be placed on a single page.
Visit the Quick Tabs configuration page to choose a style for your Quick Tabs blocks.
Click on the "New QT block" tab below to get started.
', array('@configuration' => url('admin/settings/quicktabs'))); case 'admin/build/quicktabs/add': return ''. t('Here you can create a new Quick Tabs block. Once you have created this block you will be taken to the blocks page to configure and enable it.', array('@overview' => url('admin/build/block'))) .'
'; } } /** * Implementation of hook_menu(). */ function quicktabs_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array( 'path' => 'admin/build/quicktabs', 'title' => t('Quick Tabs'), 'description' => t('Create blocks of tabbed content - content for each tab can be a view or a block'), 'callback' => 'quicktabs_list', 'access' => user_access('administer quicktabs blocks'), ); $items[] = array('path' => 'admin/build/quicktabs/list', 'title' => t('List'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); $items[] = array( 'path' => 'admin/build/quicktabs/add', 'title' => t('New QT block'), 'access' => user_access('create quicktabs block'), 'callback' => 'quicktabs_new', 'type' => MENU_LOCAL_TASK); $items[] = array('path' => 'admin/build/quicktabs/delete', 'title' => t('Delete QT block'), 'access' => user_access('administer blocks'), 'callback' => 'drupal_get_form', 'callback arguments' => array('quicktabs_block_delete'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/build/quicktabs/edit', 'title' => t('Edit QT block'), 'access' => user_access('administer blocks'), 'callback' => 'quicktabs_block_edit', 'type' => MENU_CALLBACK); $items[] = array( 'path' => 'admin/settings/quicktabs', 'title' => t('Quick Tabs'), 'description' => t('Select a style for your Quick Tabs blocks'), 'callback' => 'drupal_get_form', 'callback arguments' => array('quicktabs_settings'), 'type' => MENU_NORMAL_ITEM, 'access' => user_access('administer site configuration'), ); $items[] = array( 'path' => 'quicktabs/preview', 'callback' => 'quicktabs_preview_page', 'type' => MENU_CALLBACK, 'access' => user_access('administer site configuration'), ); } return $items; } /** * Implementation of hook_perm(). */ function quicktabs_perm() { return array('create quicktabs block', 'administer quicktabs blocks'); } function quicktabs_list() { $result = db_query('SELECT * FROM {quicktabs}'); $header = array(t('Quick Tabs Block Name'), t('Delete')); $rows = array(); while ($row = db_fetch_object($result)) { $tablerow = array( array('data' => $row->title .' ('. l('edit', 'admin/build/quicktabs/edit/'. $row->qtid) .')'), array('data' => l(t('Delete'), 'admin/build/quicktabs/delete/'. $row->qtid)), ); $rows[] = $tablerow; } $output = theme('table', $header, $rows, array('id' => 'quicktabs')); return $output; } function quicktabs_new() { drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs_form.js'); $output = ''; if (module_exists('views')) { $views = quicktabs_get_views(); } else { $views = NULL; } $blocks = quicktabs_get_blocks(); $output .= drupal_get_form('quicktabs_form', $views, $blocks); return $output; } function quicktabs_get_views() { views_load_cache(); $result = db_query("SELECT v.name, v.description, f.field FROM {view_view} v LEFT JOIN {view_exposed_filter} f ON v.vid=f.vid"); $views = array(); while ($view = db_fetch_object($result)) { if (!($view->field)) { $views[$view->name] = $view->name .': '. $view->description; } } $default_views = _views_get_default_views(); $views_status = variable_get('views_defaults', array()); foreach ($default_views as $view) { if (!$views[$view->name] && ($views_status[$view->name] == 'enabled' || (!$views_status[$view->name] && !$view->disabled)) && empty($view->exposed_filter)) { $views[$view->name] = check_plain($view->name .': '. $view->description); } } return $views; } function quicktabs_get_blocks() { $blocks = _block_rehash(); $blocksarray = array(); foreach ($blocks as $i => $block) { if ($block['module'] != 'quicktabs') { $key = $block['module'] .'_delta_'. $block['delta']; $blocksarray[$key] = $block['info']; } } return $blocksarray; } function quicktabs_form($views, $blocks, $form_values=NULL) { $form = array(); $form['#multistep'] = TRUE; $step = isset($form_values) ? (int) $form_values['step'] : 1; $form['step'] = array( '#type' => 'hidden', '#value' => $step + 1 ); $form['indicator'] = array( '#type' => 'fieldset', '#title' => ($step == 1 ? t('QT: Basic Information') : t('QT: Tab contents')) ); switch ($step) { case 1: $form['formtype'] = array( '#type' => 'hidden', '#value' => 'new' ); $form['indicator']['title'] = array( '#title' => t('Block Title'), '#type' => 'textfield', '#description' => t('The title of the whole block'), '#weight' => 0 ); $form['indicator']['num_tabs_options'] = array( '#type' => 'value', '#value' => array( '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6 ) ); $form['indicator']['num_tabs'] = array( '#title' => t('Number of tabs'), '#type' => 'select', '#options' => $form['indicator']['num_tabs_options']['#value'], '#weight' => 1 ); break; case 2: $blocktitle = $form_values['title']; $form['indicator']['title'] = array( '#type' => 'hidden', '#value' => $blocktitle ); $form['indicator']['showtitle'] = array( '#type' => 'markup', '#value' => $blocktitle, ); $i=1; $tabs = $form_values['num_tabs']; $formtype = $form_values['formtype']; $form['formtype'] = array( '#type' => 'hidden', '#value' => $formtype ); if ($formtype == 'edit') { $tabcontent = $form_values['tabs']; $form['qtid'] = array( '#type' => 'hidden', '#value' => $form_values['qtid'] ); } while ($i <= $tabs) { $form['indicator']['tab_'. $i] = array( '#type' => 'fieldset', '#title' => t('Tab '. $i), '#weight' => $i ); $form['indicator']['tab_'. $i]['title_'. $i] = array( '#type' => 'textfield', '#title' => t('Tab title'), '#default_value' => $tabcontent[$i-1]['title'] ? $tabcontent[$i-1]['title'] : NULL, '#description' => t('The title to appear on the tab itself') ); if (module_exists('views')) { $form['indicator']['tab_'. $i]['type_options'] = array( '#type' => 'value', '#value' => array( 'block' => 'block', 'view' => 'view', ) ); $form['indicator']['tab_'. $i]['type_'. $i] = array( '#type' => 'radios', '#options' => $form['indicator']['tab_'. $i]['type_options']['#value'], '#title' => t('Tab Content'), '#default_value' => $tabcontent[$i-1]['type'] ? $tabcontent[$i-1]['type'] : 'block', '#description' => t('Will this tab contain a view or a block?') ); $form['indicator']['tab_'. $i]['vid_'. $i] = array( '#type' => 'select', '#options' => $views, '#default_value' => $tabcontent[$i-1]['type']=='view' ? $tabcontent[$i-1]['bvid'] : NULL, '#title' => t('Select a view') ); $form['indicator']['tab_'. $i]['args_'. $i] = array( '#type' => 'textfield', '#title' => 'arguments', '#required' => false, '#default_value' => $tabcontent[$i-1]['type']=='view' ? $tabcontent[$i-1]['args'] : NULL, '#description' => t('Provide a comma separated list of arguments to pass to the view.'), ); $form['indicator']['tab_'. $i]['limit_'. $i] = array( '#type' => 'textfield', '#title' => t('Limit'), '#default_value' => $tabcontent[$i-1]['type']=='view' ? $tabcontent[$i-1]['limit'] : NULL, '#description' => t('Limit the number of results') ); } else { $form['indicator']['tab_'. $i]['type_'. $i] = array( '#type' => 'hidden', '#value' => 'block' ); } $form['indicator']['tab_'. $i]['bid_'. $i] = array( '#type' => 'select', '#options' => $blocks, '#default_value' => $tabcontent[$i-1]['type']=='block' ? $tabcontent[$i-1]['bvid'] : NULL, '#title' => t('Select a block') ); $i++; } break; } if ($step < 2) { $form['submit'] = array( '#type' => 'submit', '#value' => t('Next') ); $form['#redirect'] = FALSE; } else { $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); } return $form; } function quicktabs_form_validate($form_id, $form_values) { if ($form_values['step'] < 3) { if (empty($form_values['title'])) { form_set_error('title', t('You must give your Quick Tabs block a title.')); } return; } else { $done = FALSE; $j=1; while (!$done) { if (!isset($form_values['title_'. $j])) { $done = TRUE; } else { if (empty($form_values['title_'. $j])) { form_set_error('title_'. $j, t('You must give each tab a title.')); } if ($form_values['type_'. $j] == 'view' && empty($form_values['limit_'. $j])) { form_set_error('limit_'. $j, t('You must enter a limit for each view.')); } } $j++; } } } function quicktabs_form_submit($form_id, $form_values) { if ($form_values['step'] < 3) { return; } $formvalues_tabs = array(); $done = FALSE; $j=1; while (!$done) { if (!isset($form_values['title_'. $j])) { $done = TRUE; } else { $formvalues_tabs[] = array( 'title' => $form_values['title_'. $j], 'type' => $form_values['type_'. $j], 'bvid' => ($form_values['type_'. $j]=='block' ? $form_values['bid_'. $j] : $form_values['vid_'. $j]), 'args' => ($form_values['type_'. $j]=='block' ? '' : $form_values['args_'. $j]), 'limit' => ($form_values['type_'. $j]=='block' ? '0' : $form_values['limit_'. $j]) ); } $j++; } $fullcontent = array( 'blocktitle' => $form_values['title'], 'blockcontent' => $formvalues_tabs, ); if ($form_values['formtype'] == 'edit') { $qtid = $form_values['qtid']; quicktabs_updateblock($qtid, $fullcontent); $msg = t('Your Quick Tabs block has been updated.'); } else { quicktabs_createblock($fullcontent); $msg = t('Your Quick Tabs block has been created and can now be enabled.'); } drupal_set_message($msg); return 'admin/build/block'; } function quicktabs_createblock($fullcontent) { $qtid = db_next_id('quicktabs'); $title = $fullcontent['blocktitle']; $tabs = serialize($fullcontent['blockcontent']); db_query('INSERT INTO {quicktabs} (qtid, title, tabs) VALUES(%d, "%s", "%s")', $qtid, $title, $tabs); return; } function quicktabs_updateblock($qtid, $fullcontent) { $title = $fullcontent['blocktitle']; $tabs = serialize($fullcontent['blockcontent']); db_query('UPDATE {quicktabs} SET title="%s", tabs="%s" WHERE qtid=%d', $title, $tabs, $qtid); return; } /** * Implementation of hook_block */ function quicktabs_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': $jqueryblocks = array(); $result = db_query('SELECT * FROM {quicktabs}'); while ($row = db_fetch_object($result)) { $jqueryblocks[$row->qtid] = $row->title; } foreach ($jqueryblocks as $key => $val) { $blocks[$key]['info'] = t($val); } return $blocks; break; case 'view': if ($jqueryblock = db_fetch_object(db_query('SELECT qtid, title, tabs FROM {quicktabs} WHERE qtid = %d', $delta))) { quicktabs_add_css(); drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs.js'); $mainblock['subject'] = $jqueryblock->title; $tabs = unserialize($jqueryblock->tabs); $output = '