You are here

function faq_page in Frequently Asked Questions 5

Same name and namespace in other branches
  1. 5.2 faq.module \faq_page()
  2. 6 faq.module \faq_page()
  3. 7 faq.module \faq_page()

Function to display the faq page

1 string reference to 'faq_page'
faq_menu in ./faq.module
Implementation of hook_menu()

File

./faq.module, line 580

Code

function faq_page($tid = 0) {

  // things to provide translations for
  $default_values = array(
    t('Frequently Asked Questions'),
    t('Back to Top'),
    t('>> more'),
    t('Q:'),
    t('A:'),
  );
  drupal_add_css(drupal_get_path('module', 'faq') . '/faq.css');
  drupal_set_title(t(variable_get('faq_title', 'Frequently Asked Questions')));
  if (!module_exists("taxonomy")) {
    $tid = 0;
  }

  // configure the breadcrumb trail
  $breadcrumb = array();
  if (!empty($tid)) {
    $current = taxonomy_get_term($tid);
    $breadcrumb[] = array(
      'path' => 'faq/' . $tid,
      'title' => $current->name,
    );
    while ($parents = taxonomy_get_parents($current->tid)) {
      $current = array_shift($parents);
      $breadcrumb[] = array(
        'path' => 'faq/' . $current->tid,
        'title' => $current->name,
      );
    }
    $breadcrumb[] = array(
      'path' => 'faq',
      'title' => variable_get('faq_title', t('Frequently Asked Questions')),
    );
    $breadcrumb = array_reverse($breadcrumb);
    menu_set_location($breadcrumb);
  }
  $faq_display = variable_get('faq_display', 'questions_top');
  $display_vars['faq_qa_mark'] = variable_get('faq_qa_mark', FALSE);
  $display_vars['faq_question_label'] = variable_get('faq_question_label', "Q:");
  $display_vars['faq_answer_label'] = variable_get('faq_answer_label', "A:");
  $display_vars['back_to_top'] = variable_get('faq_back_to_top', 'Back to Top');
  $display_vars['use_teaser'] = variable_get('faq_use_teaser', FALSE);
  $display_vars['more_link'] = variable_get('faq_more_link', '>> more');
  $display_vars['faq_count'] = variable_get('faq_count', FALSE);
  $display_vars['hide_sub_categories'] = variable_get('faq_hide_sub_categories', FALSE);
  $display_vars['show_cat_sub_cats'] = variable_get('faq_show_cat_sub_cats', FALSE);
  $use_categories = variable_get('faq_use_categories', FALSE);
  if (!module_exists("taxonomy")) {
    $use_categories = FALSE;
  }

  // non-categorized questions and answers
  if (!$use_categories) {
    $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.body, r.teaser, r.format, if((w.weight IS NULL), 0, w.weight) as weight FROM {node} n LEFT JOIN {node_revisions} r ON n.nid = r.nid AND r.vid = n.vid LEFT JOIN {faq_weights} w ON w.nid = n.nid WHERE n.type='faq' AND n.status = 1 AND (w.tid = 0 OR w.tid IS NULL) ORDER BY weight, n.sticky DESC, n.created DESC", "n", "nid"));
    switch ($faq_display) {
      case 'questions_top':
        $output = theme('questions_top', $result, $display_vars);
        break;
      case 'hide_answer':
        $output = theme('hide_answer', $result, $display_vars);
        break;
      case 'questions_inline':
        $output = theme('questions_inline', $result, $display_vars);
        break;
      case 'new_page':
        $output = theme('new_page', $result);
        break;
    }

    // end of switch
  }
  else {
    $category_display = variable_get('faq_category_display', 'categories_inline');
    $hide_sub_categories = variable_get('faq_hide_sub_categories', FALSE);
    $output .= "<br />";

    // if we're viewing a specific category/term
    if ($tid != 0) {
      $term = taxonomy_get_term($tid);
      $title = t(variable_get('faq_title', 'Frequently Asked Questions'));
      drupal_set_title($title . ($title ? ' - ' : '') . check_plain($term->name));
      if ($category_display == 'hide_qa') {
        drupal_add_js(drupal_get_path('module', 'faq') . '/faq.js', 'module');
      }
      _display_faq_by_category($faq_display, $category_display, $term, 0, $output, $output_answers);
      $output = '<div class="content"><div class="faq">' . $output;
      $output .= $output_answers . '</div></div>';
      return $output;
    }
    $list_style = variable_get('faq_category_listing', 'ul');
    $vocabularies = taxonomy_get_vocabularies("faq");
    $items = array();
    $vocab_items = array();
    foreach ($vocabularies as $vid => $vobj) {
      if ($category_display == "new_page") {
        $vocab_items = _get_indented_faq_terms($vid, 0, $display_vars);
        $items = array_merge($items, $vocab_items);
      }
      else {
        if ($hide_sub_categories && $category_display == 'hide_qa') {
          $tree = taxonomy_get_tree($vid, 0, -1, 1);
        }
        else {
          $tree = taxonomy_get_tree($vid);
        }
        foreach ($tree as $term) {
          switch ($category_display) {
            case 'hide_qa':
              drupal_add_js(drupal_get_path('module', 'faq') . '/faq.js', 'module');
            case 'categories_inline':
              if (taxonomy_term_count_nodes($term->tid, 'faq')) {
                _display_faq_by_category($faq_display, $category_display, $term, 1, $output, $output_answers);
              }
              break;
          }

          // end of switch (category_display)
        }

        // end of foreach term
      }

      // end of foreach vocab
    }

    // end of if $category_display != new_page
    if ($category_display == "new_page") {
      $output = theme('item_list', $items, NULL, $list_style);
    }
  }
  $desc = '';
  $faq_description = t(variable_get('faq_description', ''));
  $format = variable_get('faq_description_format', 0);
  if ($format) {
    $faq_description = check_markup($faq_description, $format, FALSE);
  }
  if (!empty($faq_description)) {
    $desc = '<div class="faq_description">' . $faq_description . "</div>\n";
  }
  $output = '<div class="content"><div class="faq">' . $desc . $output;
  $output .= $output_answers . "</div></div>\n";
  return $output;
}