View source
<?php
function quicktabs_help($path, $arg) {
switch ($path) {
case 'admin/build/quicktabs':
return t('<p>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.</p>
<p>Once created, the Quick Tabs blocks show up in your block listing, ready to be configured and enabled like other blocks.</p>
<p>Multiple Quick Tabs blocks can be placed on a single page.</p>
<p>Visit the <a href="@configuration">Quick Tabs configuration page</a> to choose a style for your Quick Tabs blocks.</p>
<p>Click on the "New QT block" tab below to get started.</p>', array(
'@configuration' => url('admin/settings/quicktabs'),
));
case 'admin/build/quicktabs/add':
return '<p>' . t('Here you can create a new Quick Tabs block. Once you have created this block you will be taken to the <a href="@overview">blocks</a> page to configure and enable it.', array(
'@overview' => url('admin/build/block'),
)) . '</p>';
}
}
function quicktabs_theme() {
return array(
'quicktabs_settings' => array(
'arguments' => array(
'form' => NULL,
),
),
'quicktabs_preview_page' => array(
'arguments' => array(),
),
'qt_tabs' => array(
'arguments' => array(
'form' => NULL,
),
),
'quicktabs_block' => array(
'arguments' => array(
'block',
'title' => TRUE,
),
),
'quicktabs_tabs' => array(
'arguments' => array(
'tabs',
),
),
);
}
function quicktabs_menu() {
$items = array();
$items['admin/build/quicktabs'] = array(
'title' => 'Quick Tabs',
'description' => 'Create blocks of tabbed content - content for each tab can be a view or a block',
'page callback' => 'quicktabs_list',
'access arguments' => array(
'administer quicktabs blocks',
),
);
$items['admin/build/quicktabs/list'] = array(
'title' => 'List',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/build/quicktabs/add'] = array(
'title' => 'New QT block',
'access arguments' => array(
'create quicktabs block',
),
'page callback' => 'quicktabs_new',
'type' => MENU_LOCAL_TASK,
);
$items['admin/build/quicktabs/delete'] = array(
'title' => 'Delete QT block',
'access arguments' => array(
'administer blocks',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'quicktabs_block_delete',
),
'type' => MENU_CALLBACK,
);
$items['admin/build/quicktabs/edit'] = array(
'title' => 'Edit QT block',
'access arguments' => array(
'administer blocks',
),
'page callback' => 'quicktabs_block_edit',
'type' => MENU_CALLBACK,
);
$items['admin/settings/quicktabs'] = array(
'title' => 'Quick Tabs',
'description' => 'Select a style for your Quick Tabs blocks',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'quicktabs_settings',
),
'type' => MENU_NORMAL_ITEM,
'access arguments' => array(
'administer site configuration',
),
);
$items['quicktabs/preview'] = array(
'page callback' => 'quicktabs_preview_page',
'type' => MENU_CALLBACK,
'access arguments' => array(
'administer site configuration',
),
);
$items['quicktabs/ahah'] = array(
'page callback' => 'quicktabs_ahah',
'type' => MENU_CALLBACK,
'access arguments' => array(
'administer site configuration',
),
);
return $items;
}
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');
drupal_add_css(drupal_get_path('module', 'quicktabs') . '/quicktabs.css');
return drupal_get_form('quicktabs_form');
}
function quicktabs_form($form_state = NULL, $quicktabs = NULL) {
drupal_add_js(drupal_get_path('module', 'quicktabs') . '/js/quicktabs_ahah.js', 'footer');
$form = array(
'#cache' => TRUE,
);
if (isset($form_state['quicktabs'])) {
$quicktabs = $form_state['quicktabs'] + (array) $quicktabs;
}
$form['title'] = array(
'#title' => t('Block Title'),
'#type' => 'textfield',
'#description' => t('The title of the whole block'),
'#default_value' => $quicktabs['title'] ? $quicktabs['title'] : '',
'#weight' => -5,
);
$tabcontent = $quicktabs['tabs'];
$formtype = $quicktabs['formtype'];
if ($formtype == 'edit') {
$form['qtid'] = array(
'#type' => 'hidden',
'#value' => $quicktabs['qtid'],
);
}
if (isset($form_state['qt_count'])) {
$qt_count = $form_state['qt_count'];
}
else {
$qt_count = max(2, empty($tabcontent) ? 2 : count($tabcontent));
}
$form['qt_wrapper'] = array(
'#tree' => FALSE,
'#weight' => -4,
'#prefix' => '<div class="clear-block" id="quicktabs-tabs-wrapper">',
'#suffix' => '</div>',
);
$form['qt_wrapper']['tabs'] = array(
'#prefix' => '<div id="quicktabs-tabs">',
'#suffix' => '</div>',
'#theme' => 'qt_tabs',
);
for ($delta = 0; $delta < $qt_count; $delta++) {
$weight = isset($tabcontent[$delta]['tabweight']) ? $tabcontent[$delta]['tabweight'] : $delta - 10;
$title = isset($tabcontent[$delta]['tabtext']) ? $tabcontent[$delta]['tabtext'] : '';
$type = isset($tabcontent[$delta]['tabtype']) ? $tabcontent[$delta]['tabtype'] : 'block';
$bid = isset($tabcontent[$delta]['bid']) ? $tabcontent[$delta]['bid'] : NULL;
$hide_title = isset($tabcontent[$delta]['hide_title']) ? $tabcontent[$delta]['hide_title'] : 1;
$vid = isset($tabcontent[$delta]['vid']) ? $tabcontent[$delta]['vid'] : 'default';
$args = isset($tabcontent[$delta]['args']) ? $tabcontent[$delta]['args'] : NULL;
$display = isset($tabcontent[$delta]['display']) ? $tabcontent[$delta]['display'] : 'default';
$form['qt_wrapper']['tabs'][$delta] = _quicktabs_form($delta, $weight, $title, $type, $bid, $hide_title, $vid, $args, $display);
}
$form['qt_wrapper']['tabs_more'] = array(
'#type' => 'submit',
'#prefix' => '<div id="add-more-tabs-button">',
'#suffix' => '<label for="edit-tabs-more">' . t('Add tab') . '</label></div>',
'#value' => t('More tabs'),
'#description' => t("Click here to add more tabs."),
'#attributes' => array(
'class' => 'add-tab',
),
'#weight' => 1,
'#submit' => array(
'qt_more_tabs_submit',
),
'#ahah' => array(
'path' => 'quicktabs/ahah',
'wrapper' => 'quicktabs-tabs',
'method' => 'replace',
'effect' => 'fade',
),
);
$form['qt_wrapper']['remove'] = array(
'#type' => 'submit',
'#prefix' => '<div id="delete-tabs-button">',
'#suffix' => '<label for="edit-remove">' . t('Remove last tab') . '</label></div>',
'#value' => t('remove'),
'#attributes' => array(
'class' => 'delete-tab',
),
'#submit' => array(
'qt_remove_tab_submit',
),
'#ahah' => array(
'path' => 'quicktabs/ahah',
'wrapper' => 'quicktabs-tabs',
'method' => 'replace',
'effect' => 'fade',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function _quicktabs_form($delta, $weight = -10, $title = '', $type = 'block', $bid = 0, $hide_title = 1, $vid = 'default', $args = NULL, $display = 'default') {
$form = array(
'#tree' => TRUE,
);
$blocks = quicktabs_get_blocks();
$form['tabweight'] = array(
'#type' => 'weight',
'#default_value' => $weight,
'#parents' => array(
'tabs',
$delta,
'tabweight',
),
);
$form['tabtext'] = array(
'#type' => 'textfield',
'#size' => '10',
'#title' => t('Tab @n', array(
'@n' => $delta + 1,
)),
'#default_value' => $title,
'#parents' => array(
'tabs',
$delta,
'tabtext',
),
);
if (module_exists('views')) {
$views = quicktabs_get_views();
$form['type_options'] = array(
'#type' => 'value',
'#value' => array(
'block' => 'block',
'view' => 'view',
),
);
$form['tabtype'] = array(
'#type' => 'radios',
'#options' => $form['type_options']['#value'],
'#title' => t('Tab Content'),
'#default_value' => $type,
'#parents' => array(
'tabs',
$delta,
'tabtype',
),
);
$views_keys = array_keys($views);
$selected_view = $vid ? $vid == 'default' ? $views_keys[0] : ($type == 'block' ? $views_keys[0] : $vid) : $views_keys[0];
$form['vid'] = array(
'#type' => 'select',
'#options' => $views,
'#default_value' => $selected_view,
'#title' => t('Select a view'),
'#parents' => array(
'tabs',
$delta,
'vid',
),
'#ahah' => array(
'path' => 'quicktabs/ahah/',
'wrapper' => 'quicktabs-tabs',
'method' => 'replace',
'event' => 'change',
),
);
$form['args'] = array(
'#type' => 'textfield',
'#title' => 'arguments',
'#size' => '10',
'#required' => false,
'#default_value' => $args,
'#description' => t('Provide a comma separated list of arguments to pass to the view.'),
'#parents' => array(
'tabs',
$delta,
'args',
),
);
$form['display'] = array(
'#type' => 'select',
'#title' => 'display',
'#options' => _quicktabs_get_views_displays($selected_view),
'#default_value' => $display,
'#description' => t('Choose a display for your view.'),
'#parents' => array(
'tabs',
$delta,
'display',
),
);
$form['get_displays'] = array(
'#type' => 'submit',
'#value' => 'vdisp_' . $delta,
'#parents' => array(
'tabs',
$delta,
'get_displays',
),
'#submit' => array(
'qt_get_displays_submit',
),
);
}
else {
$form['tabtype'] = array(
'#type' => 'hidden',
'#title' => t('Type for tab @n', array(
'@n' => $delta + 1,
)),
'#value' => $type,
'#parents' => array(
'tabs',
$delta,
'tabtype',
),
);
}
$form['bid'] = array(
'#type' => 'select',
'#options' => $blocks,
'#default_value' => $bid,
'#title' => t('Select a block'),
'#parents' => array(
'tabs',
$delta,
'bid',
),
);
$form['hide_title'] = array(
'#type' => 'checkbox',
'#title' => t('Hide the title of this block'),
'#default_value' => $hide_title,
'#parents' => array(
'tabs',
$delta,
'hide_title',
),
);
return $form;
}
function theme_qt_tabs($form) {
drupal_add_tabledrag('qt-tablist-table', 'order', 'sibling', 'qt-tabs-weight');
$rows = array();
$headers = array(
t('Tab Title'),
t('Weight'),
module_exists('views') ? t('Tab type') : '',
t('Content'),
);
foreach (element_children($form) as $key) {
unset($form[$key]['tabtext']['#title'], $form[$key]['tabtype']['#title'], $form[$key]['bvid']['#title']);
$form[$key]['tabweight']['#attributes']['class'] = 'qt-tabs-weight';
$row = array(
'data' => array(
array(
'data' => drupal_render($form[$key]['tabtext']),
'class' => 'qt-tab-title',
),
array(
'data' => drupal_render($form[$key]['tabweight']),
'class' => 'qt-tab-weight',
),
module_exists('views') ? array(
'data' => drupal_render($form[$key]['tabtype']),
'class' => 'qt-tab-type',
) : array(
'data' => '',
'class' => 'qt-tabtype-hidden',
),
array(
'data' => drupal_render($form[$key]['bid']) . drupal_render($form[$key]['hide_title']) . (module_exists('views') ? drupal_render($form[$key]['vid']) . drupal_render($form[$key]['args']) . drupal_render($form[$key]['limit']) . drupal_render($form[$key]['display']) . drupal_render($form[$key]['get_displays']) : ''),
'class' => 'qt-tab-bvid',
),
),
'class' => 'draggable',
);
if (isset($form[$key]['#attributes'])) {
$row = array_merge($row, $form[$key]['#attributes']);
}
$rows[] = $row;
}
$output = theme('table', $headers, $rows, array(
'id' => 'qt-tablist-table',
));
$output .= drupal_render($form);
return $output;
}
function qt_more_tabs_submit($form, &$form_state) {
unset($form_state['submit_handlers']);
form_execute_handlers('submit', $form, $form_state);
$quicktabs = $form_state['values'];
$form_state['quicktabs'] = $quicktabs;
$form_state['rebuild'] = TRUE;
if ($form_state['values']['tabs_more']) {
$form_state['qt_count'] = count($form_state['values']['tabs']) + 1;
}
return $quicktabs;
}
function qt_remove_tab_submit($form, &$form_state) {
unset($form_state['submit_handlers']);
form_execute_handlers('submit', $form, $form_state);
$quicktabs = $form_state['values'];
$form_state['quicktabs'] = $quicktabs;
$form_state['rebuild'] = TRUE;
unset($form['qt_wrapper']['tabs'][0]);
$form_state['values']['tabs'] = array_values($form_state['values']['tabs']);
$form_state['qt_count'] = count($form_state['values']['tabs']) - 1;
return $quicktabs;
}
function qt_get_displays_submit($form, &$form_state) {
unset($form_state['submit_handlers']);
form_execute_handlers('submit', $form, $form_state);
$quicktabs = $form_state['values'];
$form_state['quicktabs'] = $quicktabs;
$form_state['rebuild'] = TRUE;
return $quicktabs;
}
function quicktabs_ahah() {
$form_state = array(
'storage' => NULL,
'submitted' => FALSE,
);
$form_build_id = $_POST['form_build_id'];
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);
$form['#post'] = $_POST;
$form['#redirect'] = FALSE;
$form['#programmed'] = FALSE;
$form_state['post'] = $_POST;
drupal_process_form($form_id, $form, $form_state);
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
$qt_form = $form['qt_wrapper']['tabs'];
unset($qt_form['#prefix'], $qt_form['#suffix']);
$javascript = drupal_add_js(NULL, NULL, 'header');
drupal_json(array(
'status' => TRUE,
'data' => theme('status_messages') . drupal_render($qt_form),
'settings' => call_user_func_array('array_merge_recursive', $javascript['setting']),
));
}
function quicktabs_form_validate($form, &$form_state) {
if ($form_state['values']['op'] == t('Save')) {
if (empty($form_state['values']['title'])) {
form_set_error('title', t('You must give your Quick Tabs block a title.'));
}
else {
foreach ($form_state['values']['tabs'] as $j => $tab) {
if (empty($tab['tabtext'])) {
form_set_error('tabs][' . $j . '][tabtext', t('You must give each tab a title.'));
}
}
}
}
}
function quicktabs_form_submit($form, $form_state) {
if ($form_state['values']['op'] == t('Save')) {
$formvalues_tabs = array();
foreach ($form_state['values']['tabs'] as $j => $tab) {
$formvalues_tabs[] = array(
'title' => $form_state['values']['tabs'][$j]['tabtext'],
'type' => $form_state['values']['tabs'][$j]['tabtype'],
'bvid' => $form_state['values']['tabs'][$j]['tabtype'] == 'block' ? $form_state['values']['tabs'][$j]['bid'] : $form_state['values']['tabs'][$j]['vid'],
'hide_title' => $form_state['values']['tabs'][$j]['tabtype'] == 'block' ? $form_state['values']['tabs'][$j]['hide_title'] : 0,
'weight' => $form_state['values']['tabs'][$j]['tabweight'],
'args' => $form_state['values']['tabs'][$j]['tabtype'] == 'block' ? '' : $form_state['values']['tabs'][$j]['args'],
'display' => $form_state['values']['tabs'][$j]['tabtype'] == 'block' ? '' : $form_state['values']['tabs'][$j]['display'],
);
}
$fullcontent = array(
'blocktitle' => $form_state['values']['title'],
'blockcontent' => $formvalues_tabs,
);
if ($form_state['values']['qtid']) {
$qtid = $form_state['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);
drupal_goto('admin/build/quicktabs');
}
}
function quicktabs_createblock($fullcontent) {
$qtid = db_last_insert_id('quicktabs', 'qtid');
$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;
}
function quicktabs_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$jqueryblocks = array();
$blocks = 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);
foreach ($tabs as $key => $tab) {
$weight[$key] = $tab['weight'];
}
array_multisort($weight, SORT_ASC, $tabs);
$tabtitles = array();
foreach ($tabs as $tab) {
$tabtitles[] = $tab['title'];
}
$output = '<div class="quicktabs_wrapper">';
$output .= theme('quicktabs_tabs', $tabtitles);
$output .= '<div class="quicktabs_main">';
foreach ($tabs as $j => $tab) {
$output .= '<div class="quicktabs">';
if ($tab['type'] == 'view') {
if (module_exists('views')) {
$args = array();
if ($tab['args'] != '') {
$args_array = explode(',', $tab['args']);
foreach ($args_array as $arg) {
$args[] = trim($arg);
}
}
$func_args = array_merge(array(
$tab['bvid'],
$tab['display'],
), $args);
$output .= call_user_func_array('views_embed_view', $func_args);
}
else {
$output .= 'Views module not enabled, cannot display tab content';
}
}
else {
$pos = strpos($tab['bvid'], '_delta_');
$blockmodule = substr($tab['bvid'], 0, $pos);
$blockdelta = substr($tab['bvid'], $pos + 7);
$block = (object) module_invoke($blockmodule, 'block', 'view', $blockdelta);
$block->module = $blockmodule;
$block->delta = $blockdelta;
if ($tab['hide_title'] != 1) {
$output .= $block->content ? theme('quicktabs_block', $block, TRUE) : '';
}
else {
$output .= $block->content ? theme('quicktabs_block', $block, FALSE) : '';
}
}
$output .= '</div>';
}
$output .= '</div></div>';
$mainblock['content'] = $output;
}
return $mainblock;
break;
}
}
function theme_quicktabs_block($block, $title = TRUE) {
$output = "<div class=\"block block-{$block->module}\" id=\"block-{$block->module}-{$block->delta}\">\n";
if ($title) {
$output .= " <h2 class=\"title\">{$block->subject}</h2>\n";
}
$output .= " <div class=\"content\">{$block->content}</div>\n";
$output .= "</div>\n";
return $output;
}
function theme_quicktabs_tabs($tabs) {
$output = '<ul class="quicktabs_tabs">';
foreach ($tabs as $i => $tab) {
$output .= '<li><a href="#">' . $tab . '</a></li>';
}
$output .= '</ul>';
return $output;
}
function quicktabs_block_get_name($qtid) {
$result = db_result(db_query('SELECT title FROM {quicktabs} WHERE qtid=%d', $qtid));
return $result;
}
function quicktabs_block_delete(&$form_state, $qtid = 0) {
$qt_name = quicktabs_block_get_name($qtid);
$form['qtid'] = array(
'#type' => 'hidden',
'#value' => $qtid,
);
$form['qt_name'] = array(
'#type' => 'hidden',
'#value' => $qt_name,
);
return confirm_form($form, t('Are you sure you want to delete the Quick Tabs block %name?', array(
'%name' => $qt_name,
)), 'admin/build/quicktabs', '', t('Delete'), t('Cancel'));
}
function quicktabs_block_edit($qtid) {
if ($qtblock = db_fetch_object(db_query('SELECT title, tabs FROM {quicktabs} WHERE qtid = %d', $qtid))) {
$tabs = unserialize($qtblock->tabs);
$formtabs = array();
foreach ($tabs as $key => $tab) {
$weight[$key] = $tab['weight'];
$formtabs[] = array(
'tabweight' => $tab['weight'],
'tabtext' => $tab['title'],
'tabtype' => $tab['type'],
'bid' => $tab['type'] == 'block' ? $tab['bvid'] : NULL,
'hide_title' => $tab['type'] == 'block' ? $tab['hide_title'] : NULL,
'vid' => $tab['type'] == 'view' ? $tab['bvid'] : NULL,
'args' => $tab['type'] == 'view' ? $tab['args'] : NULL,
'display' => $tab['type'] == 'view' ? $tab['display'] : NULL,
);
}
array_multisort($weight, SORT_ASC, $formtabs);
$quicktabs = array(
'qtid' => $qtid,
'title' => $qtblock->title,
'tabs' => $formtabs,
'formtype' => 'edit',
);
drupal_add_js(drupal_get_path('module', 'quicktabs') . '/js/quicktabs_form.js');
drupal_add_css(drupal_get_path('module', 'quicktabs') . '/quicktabs.css');
$output = drupal_get_form('quicktabs_form', $quicktabs);
return $output;
}
else {
drupal_goto('admin/build/quicktabs');
}
}
function quicktabs_block_delete_submit($form, $form_state) {
db_query('DELETE FROM {quicktabs} WHERE qtid = %d', $form_state['values']['qtid']);
drupal_set_message(t('The Quick Tabs block %name has been removed.', array(
'%name' => $form_state['values']['qt_name'],
)));
cache_clear_all();
drupal_goto('admin/build/quicktabs');
}
function quicktabs_settings() {
$form = array();
$form['quicktabs_tabstyle'] = array(
'#type' => 'radios',
'#title' => t('Tab Style'),
'#options' => array(
'default' => t('Default (no style)'),
) + module_invoke_all('quicktabs_tabstyles'),
'#default_value' => variable_get('quicktabs_tabstyle', 'default'),
'#description' => t('Choose a tab style for your Quick Tabs blocks.'),
'#attributes' => array(
'class' => 'quicktabs-tabstyles clear-block',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function quicktabs_settings_submit($form, $form_state) {
variable_set('quicktabs_tabstyle', $form_state['values']['quicktabs_tabstyle']);
variable_set('quicktabs_blocktitles', $form_state['values']['quicktabs_blocktitles']);
}
function theme_quicktabs_settings($form) {
quicktabs_add_css();
drupal_set_title(t('Quick Tabs Settings'));
$form['quicktabs_tabstyle']['default']['#description'] = 'Default ' . t('Preview') . ':<br /><iframe class="quicktabs-preview" scrolling="no" src="' . url('quicktabs/preview') . '"></iframe>';
$tabstyle_number = 0;
foreach (element_children($form['quicktabs_tabstyle']) as $tabstyle_key) {
if ($tabstyle_key != 'default') {
$form['quicktabs_tabstyle'][$tabstyle_key]['#description'] = $form['quicktabs_tabstyle'][$tabstyle_key]['#title'] . ' ' . t('Preview') . ':<br /><iframe class="quicktabs-preview" scrolling="no" src="' . url('quicktabs/preview/' . $tabstyle_number) . '"></iframe>';
$tabstyle_number++;
}
}
return drupal_render($form);
}
function quicktabs_preview_page($tabstyle_number = NULL) {
$tabstyles = module_invoke_all('quicktabs_tabstyles');
$css_files = array_keys($tabstyles);
if (isset($css_files[$tabstyle_number])) {
quicktabs_add_css($css_files[$tabstyle_number]);
}
else {
quicktabs_add_css('default');
}
drupal_add_js(drupal_get_path('module', 'quicktabs') . '/js/quicktabs.js');
print theme('quicktabs_preview_page');
exit;
}
function theme_quicktabs_preview_page() {
$output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$output .= '<html xmlns="http://www.w3.org/1999/xhtml">';
$output .= '<head>';
$output .= ' <title>' . t('Quick Tabs Preview') . '</title>';
$output .= drupal_get_html_head();
$output .= drupal_get_css();
$output .= drupal_get_js();
$output .= ' </head>';
$output .= ' <body style="background: none; background-color: #fff; color: #000;" class="quicktabs_iframe">';
$output .= '<div class="quicktabs_wrapper">';
$output .= '<ul class="quicktabs_tabs"><li><a href="#">One</a></li><li><a href="#">Two</a></li></ul>';
$output .= '<div class="quicktabs_main"><div class="quicktabs"></div><div class="quicktabs"></div></div></div>';
$output .= '</body></html>';
return $output;
}
function quicktabs_add_css($tabstyle_css = NULL) {
drupal_add_css(drupal_get_path('module', 'quicktabs') . '/quicktabs.css');
if (!isset($tabstyle_css)) {
$tabstyle_css = variable_get('quicktabs_tabstyle', 'default');
}
if ($tabstyle_css != 'default') {
drupal_add_css($tabstyle_css, 'module');
}
}
function quicktabs_quicktabs_tabstyles() {
$tabstyles_directory = drupal_get_path('module', 'quicktabs') . '/tabstyles';
$files = file_scan_directory($tabstyles_directory, '\\.css$');
$tabstyles = array();
foreach ($files as $file) {
$tabstyles[$file->filename] = drupal_ucfirst($file->name);
}
return $tabstyles;
}
function quicktabs_get_views() {
$result = db_query("SELECT v.name, v.description FROM {views_view} v");
$views = array();
while ($view = db_fetch_object($result)) {
$views[$view->name] = $view->name;
}
$status = variable_get('views_defaults', array());
foreach (_quicktabs_get_default_views_names() as $view) {
if (isset($status[$view['name']])) {
$view['disabled'] = $status[$view['name']];
}
if (empty($views[$view['name']]) && $view['disabled'] != 1) {
$views[$view['name']] = $view['name'];
}
}
return $views;
}
function _quicktabs_get_default_views() {
views_include('view');
views_include_default_views();
$defaults = module_invoke_all('views_default_views');
$views = array();
foreach ($defaults as $name => $view) {
if (isset($view->api_version) && $view->api_version >= 2) {
$views[$name] = $view;
}
}
return $views;
}
function _quicktabs_get_default_views_names() {
$views = array();
foreach (_quicktabs_get_default_views() as $name => $view) {
$views[] = array(
'name' => $name,
);
}
return $views;
}
function _quicktabs_get_default_view_displays($selected_view) {
$displays = array();
foreach (_quicktabs_get_default_views() as $name => $view) {
if ($name == $selected_view) {
$display_array = $view->display;
foreach ($display_array as $key => $display) {
$displays[$key] = $key;
}
break;
}
}
return $displays;
}
function quicktabs_get_blocks() {
static $blocksarray;
if (empty($blocksarray)) {
global $theme_key;
init_theme();
$result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key);
$old_blocks = array();
while ($old_block = db_fetch_array($result)) {
$old_blocks[$old_block['module']][$old_block['delta']] = $old_block;
}
$blocks = array();
foreach (module_list() as $module) {
$module_blocks = module_invoke($module, 'block', 'list');
if ($module_blocks) {
foreach ($module_blocks as $delta => $block) {
if (empty($old_blocks[$module][$delta])) {
$block['module'] = $module;
$block['delta'] = $delta;
$block['theme'] = $theme_key;
$blocks[] = $block;
}
else {
$old_blocks[$module][$delta]['info'] = $block['info'];
$blocks[] = $old_blocks[$module][$delta];
}
}
}
}
$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_get_views_displays($view) {
$displays = array();
$result = db_query("SELECT d.id FROM {views_view} v INNER JOIN {views_display} d ON v.vid = d.vid WHERE v.name = '%s' ORDER BY position ASC", $view);
while ($row = db_fetch_object($result)) {
$displays[$row->id] = $row->id;
}
if (empty($displays)) {
$displays = _quicktabs_get_default_view_displays($view);
}
return $displays;
}