You are here

function quicktabs_block in Quick Tabs 6

Same name and namespace in other branches
  1. 5 quicktabs.module \quicktabs_block()
  2. 6.3 quicktabs.module \quicktabs_block()
  3. 6.2 quicktabs.module \quicktabs_block()

Implementation of hook_block

File

./quicktabs.module, line 507

Code

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;
  }
}