View source
<?php
define('QUICKTABS_DELTA_NONE', 999999);
function quicktabs_help($path, $arg) {
switch ($path) {
case 'admin/help#quicktabs':
$output = '<p>' . t('The Quicktabs module allows you to create blocks of tabbed content. Clicking on the tabs makes the corresponding content display instantly (it uses jQuery). The content for each tabbed section can be a node, view, block or another Quicktabs instance. You can create an unlimited number of Quicktabs instances, each of which will automatically have an associated block.') . '</p>';
$output .= '<p>' . t('The <a href="@quicktabs">quicktabs page</a> displays all quicktabs currently available on your site. Create new quicktabs using the <a href="@add-quicktab">add quicktab page</a> (the block containing a new quicktab must also be enabled on the <a href="@blocks">blocks administration page</a>).', array(
'@quicktabs' => url('admin/structure/quicktabs'),
'@add-quicktab' => url('admin/structure/quicktab/add'),
'@blocks' => url('admin/structure/block'),
)) . '</p>';
return $output;
}
if ($path == 'admin/structure/quicktabs' && module_exists('block')) {
return '<p>' . t('Each Quicktabs instance has a corresponding block that is managed on the <a href="@blocks">blocks administration page</a>.', array(
'@blocks' => url('admin/structure/block'),
)) . '</p>';
}
}
function quicktabs_menu() {
$items['admin/structure/quicktabs'] = array(
'title' => 'Quicktabs',
'description' => 'Create blocks of tabbed content.',
'page callback' => 'quicktabs_list',
'access callback' => 'user_access',
'access arguments' => array(
'administer quicktabs',
),
'type' => MENU_NORMAL_ITEM,
'file' => 'quicktabs.admin.inc',
);
$items['admin/structure/quicktabs/list'] = array(
'title' => 'List quicktabs',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/structure/quicktabs/add'] = array(
'title' => 'Add Quicktabs Instance',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'quicktabs_form',
'add',
),
'access arguments' => array(
'administer quicktabs',
),
'type' => MENU_LOCAL_ACTION,
'file' => 'quicktabs.admin.inc',
);
$items['admin/structure/quicktabs/manage/%quicktabs'] = array(
'title' => 'Edit quicktab',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'quicktabs_form',
'edit',
4,
),
'access arguments' => array(
'administer quicktabs',
),
'file' => 'quicktabs.admin.inc',
);
$items['admin/structure/quicktabs/manage/%quicktabs/edit'] = array(
'title' => 'Edit quicktab',
'type' => MENU_DEFAULT_LOCAL_TASK,
'context' => MENU_CONTEXT_INLINE,
);
$items['admin/structure/quicktabs/manage/%quicktabs/delete'] = array(
'title' => 'Delete quicktab',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'quicktabs_block_delete',
4,
),
'access arguments' => array(
'administer quicktabs',
),
'type' => MENU_LOCAL_TASK,
'file' => 'quicktabs.admin.inc',
);
$items['admin/structure/quicktabs/manage/%quicktabs/clone'] = array(
'title' => 'Clone quicktab',
'page callback' => 'quicktabs_clone',
'page arguments' => array(
4,
),
'access arguments' => array(
'administer quicktabs',
),
'type' => MENU_LOCAL_TASK,
'file' => 'quicktabs.admin.inc',
);
$items['admin/structure/quicktabs/manage/%quicktabs/export'] = array(
'title' => 'Export',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'quicktabs_export_form',
4,
),
'access arguments' => array(
'administer quicktabs',
),
'type' => MENU_LOCAL_TASK,
'file' => 'quicktabs.admin.inc',
);
$items['quicktabs/ajax'] = array(
'page callback' => 'quicktabs_ajax',
'access callback' => 'user_access',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
);
return $items;
}
function quicktabs_permission() {
return array(
'administer quicktabs' => array(
'title' => t('Administer Quicktabs'),
),
);
}
function quicktabs_theme() {
return array(
'quicktabs_admin_form_tabs' => array(
'render element' => 'tabs',
'file' => 'quicktabs.admin.inc',
),
'qt_ui_tabs' => array(
'render element' => 'element',
),
'qt_ui_tabs_tabset' => array(
'render element' => 'tabset',
),
'qt_quicktabs' => array(
'render element' => 'element',
),
'qt_quicktabs_tabset' => array(
'render element' => 'tabset',
),
'qt_accordion' => array(
'render element' => 'element',
),
'quicktabs_tab_access_denied' => array(
'variables' => array(
'tab',
),
),
);
}
function quicktabs_block_info() {
$blocks = array();
foreach (quicktabs_load_multiple() as $qt_name => $quicktabs) {
$blocks[$qt_name]['info'] = $quicktabs->title;
$blocks[$qt_name]['cache'] = DRUPAL_NO_CACHE;
}
return $blocks;
}
function quicktabs_block_view($delta = '') {
$block = array();
if ($qt = quicktabs_build_quicktabs($delta)) {
if (isset($qt['content']) && !empty($qt['content'])) {
$block['content'] = $qt['content'];
$block['content']['#contextual_links']['quicktabs'] = array(
'admin/structure/quicktabs/manage',
array(
$delta,
),
);
$block['subject'] = check_plain($qt['#title']);
}
}
return $block;
}
function quicktabs_build_quicktabs($name, $settings = array(), $custom_tabs = array()) {
if ($info = quicktabs_load($name)) {
drupal_alter('quicktabs', $info);
$info = (array) $info;
$settings = array_merge($info, $settings);
$contents = $settings['tabs'];
unset($settings['tabs'], $settings['machine_name']);
}
elseif (!empty($custom_tabs)) {
$name = preg_replace('/[^[a-zA-Z]_]/', '_', $name);
$contents = array();
}
else {
return array();
}
$renderer = isset($settings['renderer']) ? $settings['renderer'] : 'quicktabs';
unset($settings['renderer']);
$needs_sorting = FALSE;
$weight = 0;
foreach ($custom_tabs as &$tab) {
$needs_sorting = $needs_sorting || isset($tab['weight']);
$tab += array(
'type' => 'prerendered',
'weight' => $weight++,
);
}
$contents = array_merge($custom_tabs, $contents);
$weight = array();
foreach ($contents as $key => $item) {
if ($item['type'] != 'prerendered') {
ctools_plugin_load_class('quicktabs', 'contents', $item['type'], 'handler');
}
$weight[$key] = $item['weight'];
if ($item['type'] == 'qtabs' && $item['machine_name'] == $name) {
unset($contents[$key]);
unset($weight[$key]);
}
}
if ($needs_sorting && (!isset($settings['sorted']) || !$settings['sorted'])) {
array_multisort($weight, SORT_ASC, $contents);
}
else {
unset($settings['sorted']);
}
if ($qt = quickset_renderer_factory($name, $contents, $renderer, $settings)) {
$renderable_qt = array(
'#title' => $qt
->getTitle(),
'content' => $qt
->render(),
);
return $renderable_qt;
}
return array();
}
function quicktabs_ajax($name, $index, $type) {
$args = func_get_args();
$variable_args = array_slice($args, 3);
array_unshift($variable_args, $name);
$data = QuickSet::ajaxRenderContent($type, $variable_args);
$commands = array();
$tabpage_id = 'quicktabs-tabpage-' . $name . '-' . $index;
$commands[] = ajax_command_append('#quicktabs-container-' . $name, '<div id="' . $tabpage_id . '" class="quicktabs-tabpage">' . $data . '</div>');
$page = array(
'#type' => 'ajax',
'#commands' => $commands,
);
ajax_deliver($page);
}
function quicktabs_load($name) {
$qts = quicktabs_load_multiple(array(
$name,
));
return isset($qts[$name]) ? $qts[$name] : NULL;
}
function quicktabs_load_multiple($names = array()) {
ctools_include('export');
$defaults = empty($names) ? ctools_export_load_object('quicktabs', 'all') : ctools_export_load_object('quicktabs', 'names', $names);
return $defaults;
}
function quicktabs_save($quicktab) {
module_invoke_all('quicktabs_presave', $quicktab);
$exists = quicktabs_load($quicktab->machine_name);
if ($exists && empty($exists->in_code_only)) {
$ret = drupal_write_record('quicktabs', $quicktab, 'machine_name');
if ($ret == SAVED_UPDATED) {
quicktabs_i18n_update_strings(array(
$quicktab->machine_name,
));
}
else {
return FALSE;
}
}
else {
$ret = drupal_write_record('quicktabs', $quicktab);
if ($ret == SAVED_NEW) {
quicktabs_i18n_update_strings(array(
$quicktab->machine_name,
));
module_invoke_all('quicktabs_insert', $quicktab);
}
else {
return FALSE;
}
}
module_invoke_all('quicktabs_save', $quicktab);
return $quicktab;
}
function quicktabs_update($quicktab) {
quicktabs_save($quicktab);
module_invoke_all('quicktabs_update', $quicktab);
return $quicktab;
}
function quicktabs_delete($machine_name) {
db_query('DELETE FROM {quicktabs} WHERE machine_name = :machine_name', array(
':machine_name' => $machine_name,
));
module_invoke_all('quicktabs_delete', $machine_name);
}
function quicktabs_export($qt, $indent = '') {
$output = ctools_export_object('quicktabs', $qt, $indent);
$translatables = array();
if (!empty($qt->title)) {
$translatables[] = $qt->title;
}
foreach ($qt->tabs as $tab) {
$translatables[] = $tab['title'];
}
$translatables = array_filter(array_unique($translatables));
if (!empty($translatables)) {
$output .= "\n";
$output .= "{$indent}// Translatables\n";
$output .= "{$indent}// Included for use with string extractors like potx.\n";
sort($translatables);
foreach ($translatables as $string) {
$output .= "{$indent}t(" . ctools_var_export($string) . ");\n";
}
$output .= "\n";
}
return $output;
}
function quicktabs_i18n_string_info() {
$groups['quicktabs'] = array(
'title' => t('Quicktabs'),
'description' => t('Vocabulary titles and term names for localizable quicktabs.'),
'format' => FALSE,
'list' => TRUE,
);
return $groups;
}
function quicktabs_translate($name, $string, $langcode = NULL, $textgroup = 'quicktabs') {
return function_exists('i18n_string') ? i18n_string($textgroup . ':' . $name, $string, array(
'langcode' => $langcode,
)) : $string;
}
function quicktabs_i18n_update_strings($names = array()) {
if (!function_exists('i18n_string_update')) {
return;
}
$qts = quicktabs_load_multiple($names);
foreach ($qts as $name => $quicktabs) {
i18n_string_update("quicktabs:title:{$name}", $quicktabs->title);
foreach ($quicktabs->tabs as $tabkey => $tab) {
i18n_string_update("quicktabs:tab:{$name}:title:" . md5($tab['title']), $tab['title']);
}
}
}
function quicktabs_i18n_string_refresh($group) {
if ($group === 'quicktabs') {
quicktabs_i18n_update_strings();
}
return TRUE;
}
function quicktabs_ctools_plugin_type() {
return array(
'renderers' => array(
'cache' => TRUE,
'use hooks' => TRUE,
'classes' => array(
'handler',
),
),
'contents' => array(
'cache' => TRUE,
'use hooks' => TRUE,
'classes' => array(
'handler',
),
),
);
}
function quicktabs_quicktabs_renderers() {
$info = array();
$path = drupal_get_path('module', 'quicktabs') . '/plugins';
$info['quicktabs'] = array(
'path' => $path,
'handler' => array(
'file' => 'QuickQuicktabs.inc',
'class' => 'QuickQuicktabs',
),
);
$info['ui_tabs'] = array(
'path' => $path,
'handler' => array(
'file' => 'QuickUiTabs.inc',
'class' => 'QuickUitabs',
),
);
$info['accordion'] = array(
'path' => $path,
'handler' => array(
'file' => 'QuickAccordion.inc',
'class' => 'QuickAccordion',
),
);
return $info;
}
function quicktabs_quicktabs_contents() {
$info = array();
$path = drupal_get_path('module', 'quicktabs') . '/plugins';
$info['block'] = array(
'path' => $path,
'handler' => array(
'file' => 'QuickBlockContent.inc',
'class' => 'QuickBlockContent',
),
'dependencies' => array(
'block',
),
);
$info['view'] = array(
'path' => $path,
'handler' => array(
'file' => 'QuickViewContent.inc',
'class' => 'QuickViewContent',
),
'dependencies' => array(
'views',
),
);
$info['node'] = array(
'path' => $path,
'handler' => array(
'file' => 'QuickNodeContent.inc',
'class' => 'QuickNodeContent',
),
);
$info['qtabs'] = array(
'path' => $path,
'handler' => array(
'file' => 'QuickQtabsContent.inc',
'class' => 'QuickQtabsContent',
),
);
$info['callback'] = array(
'path' => $path,
'handler' => array(
'file' => 'QuickCallbackContent.inc',
'class' => 'QuickCallbackContent',
),
);
return $info;
}
function quickset_renderer_factory($name, $contents, $renderer, $settings) {
return QuickSet::QuickSetRendererFactory($name, $contents, $renderer, $settings);
}
function quick_content_factory($name, $item) {
return QuickContent::factory($name, $item);
}
function quicktabs_machine_name_exists($machine_name) {
$qt_exists = db_query_range('SELECT 1 FROM {quicktabs} WHERE machine_name = :name', 0, 1, array(
':name' => $machine_name,
))
->fetchField();
return $qt_exists;
}
function quicktabs_views_api() {
return array(
'api' => 3,
);
}
function theme_quicktabs_tab_access_denied($variables) {
return t('You are not authorized to access this content.');
}
function quicktabs_get_css($style) {
if ($style == 'default') {
$style = variable_get('quicktabs_tabstyle', 'nostyle');
}
if ($style == 'nostyle') {
return array();
}
$style_css = _quicktabs_get_style_css($style);
return $style_css;
}
function _quicktabs_get_style_css($style) {
$tabstyles =& drupal_static(__FUNCTION__);
if (empty($tabstyles)) {
$cid = 'quicktabs_tabstyles';
$cache = cache_get($cid);
if (!$cache) {
$tabstyles = module_invoke_all('quicktabs_tabstyles');
cache_set($cid, $tabstyles);
}
else {
$tabstyles = $cache->data;
}
}
if ($css_file = array_search($style, $tabstyles)) {
return array(
'data' => $css_file,
);
}
return array();
}
function theme_qt_ui_tabs_tabset($vars) {
$output = '<ul>';
foreach ($vars['tabset']['tablinks'] as $i => $tab) {
if (is_array($tab)) {
$output .= '<li>' . drupal_render($tab) . '</li>';
}
}
$output .= '</ul>';
return $output;
}
function theme_qt_ui_tabs($variables) {
$element = $variables['element'];
$output = '<div ' . drupal_attributes($element['#options']['attributes']) . '>';
$output .= drupal_render($element['tabs']);
if (isset($element['active'])) {
$output .= drupal_render($element['active']);
}
else {
foreach ($element['divs'] as $div) {
$output .= drupal_render($div);
}
}
$output .= '</div>';
return $output;
}
function theme_qt_quicktabs_tabset($vars) {
$variables = array(
'attributes' => array(
'class' => 'quicktabs-tabs quicktabs-style-' . $vars['tabset']['#options']['style'],
),
'items' => array(),
);
foreach (element_children($vars['tabset']['tablinks']) as $key) {
$item = array();
if (is_array($vars['tabset']['tablinks'][$key])) {
$tab = $vars['tabset']['tablinks'][$key];
if ($key == $vars['tabset']['#options']['active']) {
$item['class'] = array(
'active',
);
}
$item['class'][] = drupal_html_class($tab['#title']);
$item['data'] = drupal_render($tab);
$variables['items'][] = $item;
}
}
return theme('item_list', $variables);
}
function theme_qt_quicktabs($variables) {
$element = $variables['element'];
$output = '<div ' . drupal_attributes($element['#options']['attributes']) . '>';
$output .= drupal_render($element['tabs']);
$output .= drupal_render($element['container']);
$output .= '</div>';
return $output;
}
function theme_qt_accordion($variables) {
$element = $variables['element'];
$output = '<div ' . drupal_attributes($element['#options']['attributes']) . '>';
foreach ($element['divs'] as $div) {
$output .= drupal_render($div);
}
$output .= '</div>';
return $output;
}