You are here

function theme_category_questions_top in Frequently Asked Questions 5

1 theme call to theme_category_questions_top()
_display_faq_by_category in ./faq.module

File

./faq.module, line 857

Code

function theme_category_questions_top($result, $display_vars, $term, $class) {
  $output = '';
  $output_answers = '';
  $this_page = 'faq';
  $get_sub_terms = 0;
  if (arg(0) == 'faq' && is_numeric(arg(1))) {
    $this_page .= "/" . arg(1);
    $get_sub_terms = arg(1);
  }

  // configure "back to top" link
  $back_to_top = '';
  if (!empty($display_vars['back_to_top'])) {
    $back_to_top = '<p class="faq_top_link">';
    $back_to_top .= l(t($display_vars['back_to_top']), $this_page, array(), NULL, '') . '</p>';
  }

  // get number of questions, and account for hidden sub-cats
  if ($display_vars['faq_count']) {
    $count = db_num_rows($result);
    if ($display_vars['hide_sub_categories']) {
      $count = taxonomy_term_count_nodes($term->tid, 'faq');
    }
  }

  // configure header
  $hdr = "h5";
  if ($term->depth > 0) {
    $hdr = "h6";
  }
  if ($display_vars['category_display'] == 'hide_qa') {
    $header = "<{$hdr} class=\"faq_header\">";
    $header .= l($term->name, "faq/{$term->tid}");
    if ($display_vars['faq_count']) {
      $header .= " (%d)";
    }
    $header .= "</{$hdr}>\n";
    $ans_hdr = "<{$hdr} class=\"faq_header\">";
    $ans_hdr .= check_plain($term->name) . "</{$hdr}>\n";
  }
  else {
    $header = "<{$hdr} class=\"faq_header\">";
    $header .= check_plain($term->name);
    if ($display_vars['faq_count']) {
      $header .= " (%d)";
    }
    $header .= "</{$hdr}>\n";
    $ans_hdr = "<{$hdr} class=\"faq_header\">";
    $ans_hdr .= check_plain($term->name) . "</{$hdr}>\n";
  }
  $answer_category_name = variable_get('faq_answer_category_name', FALSE);
  $desc = '';
  if (!empty($term->description)) {
    $desc = '<div class="faq_qa_description"><p>';
    $desc .= $term->description . "</p></div>\n";
  }

  // get list of sub-categories if necessary
  $sub_cats = '';
  if (($display_vars['show_cat_sub_cats'] || $display_vars['hide_sub_categories']) && $display_vars['category_display'] == 'new_page') {
    $list = taxonomy_get_children($term->tid);
    $scats = array();
    foreach ($list as $tid => $sub_term) {
      $sub_count = taxonomy_term_count_nodes($sub_term->tid, 'faq');
      if ($sub_count) {
        $sub_cat_desc = '';
        if (!empty($sub_term->description)) {
          $sub_cat_desc = '<div class="faq_qa_description"><p>';
          $sub_cat_desc .= $sub_term->description . "</p></div>";
        }

        // get number of questions, and account for hidden sub-cats
        if ($display_vars['faq_count']) {
          $scats[] = l($sub_term->name, "faq/{$sub_term->tid}") . " ({$sub_count}) {$sub_cat_desc}";
        }
        else {
          $scats[] = l($sub_term->name, "faq/{$sub_term->tid}") . $sub_cat_desc;
        }
      }
    }
    $list_style = variable_get('faq_category_listing', 'ul');
    $sub_cats .= theme('item_list', $scats, NULL, $list_style, array(
      "class" => "faq_category_list",
    ));
  }
  $output .= '<div class="faq_category_group">' . "\n";
  if ($display_vars['display_header'] == 1) {
    $output .= '<div class="faq_qa_header">' . $header . $desc . "</div>\n";
  }
  else {
    $output .= '<div class="faq_qa_header">' . $desc . "</div>\n";
  }
  $output .= $sub_cats;
  $sub_cats = '';
  if ($get_sub_terms == $term->tid) {
    $output .= '<div class="faq_qa">' . "\n";
  }
  else {
    $output .= '<div class="' . $class . '">' . "\n";
  }
  if ($get_sub_terms && $display_vars['category_display'] == 'categories_inline' || ($display_vars['show_cat_sub_cats'] || $display_vars['hide_sub_categories']) && $display_vars['category_display'] == 'hide_qa') {
    $list = taxonomy_get_children($term->tid);
    foreach ($list as $tid => $sub_term) {
      if (taxonomy_term_count_nodes($sub_term->tid, 'faq')) {
        $sub_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 INNER JOIN {term_node} tn ON n.nid = tn.nid LEFT JOIN {faq_weights} w ON w.tid = tn.tid AND n.nid = w.nid WHERE n.type='faq' AND n.status = 1 AND tn.tid = '%d' ORDER BY weight, n.sticky DESC, n.created DESC", "n", "nid"), $sub_term->tid);
        $display_vars['display_header'] = 1;
        $sub_cats .= '<div class="faq_category_indent">';
        $sub_cat_data = theme('category_questions_top', $sub_result, $display_vars, $sub_term, $class);
        $sub_cats .= $sub_cata_data["output"];
        $sub_cat_output_answers .= $sub_cata_data["output_answers"];
        $sub_cats .= '</div>';
      }
    }
    $output .= $sub_cats;
  }
  if (db_num_rows($result)) {
    $questions = array();
    while ($node = db_fetch_object($result)) {
      $node = node_load($node->nid);
      if (node_access("view", $node)) {
        $anchor = $term->tid . "n" . $node->nid;
        $questions[] = l($node->title, $this_page, NULL, NULL, $anchor);
        $answers .= '<div class="faq_question">' . l($node->title, "node/{$node->nid}", array(
          "name" => "{$anchor}",
        )) . "</div>\n";

        // should we display teaser or full text
        if ($display_vars['use_teaser']) {
          $more_link = '';
          if (!empty($display_vars['more_link']) && strlen($node->teaser) < strlen($node->body)) {
            $more_link = '<p class="faq_more_link">';
            $more_link .= l(t($display_vars['more_link']), "node/{$node->nid}") . '</p>';
          }
          $answers .= '<div class="faq_answer">';
          $answers .= check_markup($node->teaser, $node->format, FALSE);
          $answers .= $more_link . $back_to_top . "</div>\n";
        }
        else {
          $answers .= '<div class="faq_answer">';
          $answers .= check_markup($node->body, $node->format, FALSE);
          $answers .= $back_to_top . "</div>\n";
        }
      }
      else {
        $count--;
      }
    }

    // end of while
    $list_style = variable_get('faq_question_listing', 'ul');
    $output .= theme('item_list', $questions, NULL, $list_style, array(
      "class" => "faq_ul_questions_top",
    ));
  }
  if ($display_vars['group_questions_top'] || $display_vars['category_display'] == "hide_qa") {
    if ($answer_category_name) {
      if (db_num_rows($result)) {
        $output .= $ans_hdr;
        $output .= "<div>\n" . $answers . "\n</div>\n";
      }
      $output .= "</div>\n</div>\n";
    }
    else {
      if (db_num_rows($result)) {
        $output .= "<div>\n" . $answers . "\n</div>\n";
      }
      $output .= "</div>\n</div>\n";
    }
  }
  else {
    $output .= "</div>\n</div>\n";
    $ans_depth = 0;
    $indent = '<div class="faq_category_indent">' . "\n";
    if ($answer_category_name) {
      while ($ans_depth < $term->depth) {
        $output_answers .= $indent;
        $ans_depth++;
      }
    }
    $output_answers .= '<div class="faq_category_group">' . "\n";
    if ($answer_category_name) {
      if (taxonomy_term_count_nodes($term->tid, 'faq')) {
        if (!empty($sub_cat_output_answers)) {
          $sub_cat_output_answers .= $answers;
          $answers = $sub_cat_output_answers;
        }
        $output_answers .= $ans_hdr . "<div>\n" . $answers . "\n</div>\n";
      }
    }
    else {
      if (!empty($sub_cat_output_answers)) {
        $output_answers .= $sub_cat_output_answers;
      }
      $output_answers .= "<div>\n" . $answers . "\n</div>\n";
    }
    $output_answers .= "</div>\n";
    if ($answer_category_name) {
      while ($ans_depth > 0) {
        $output_answers .= "</div>\n";
        $ans_depth--;
      }
    }
  }
  if ($display_vars['faq_count']) {
    $output = sprintf($output, $count);
  }
  $data["output"] = $output;
  $data["output_answers"] = $output_answers;
  return $data;
}