faq.hide_answer.inc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * @file
  4. * FAQ page callbacks for the "hide answer" layouts.
  5. */
  6. /**
  7. * Create FAQ page if set to show/hide answer when question is clicked.
  8. *
  9. * @param array &$variables
  10. * Array reference of arguments given to the theme() function.
  11. */
  12. function template_preprocess_faq_hide_answer(&$variables) {
  13. $data = $variables['data'];
  14. $this_page = $_GET['q'];
  15. // Fetch configuration.
  16. $teaser = variable_get('faq_use_teaser', FALSE);
  17. $links = variable_get('faq_show_node_links', FALSE);
  18. $disable_node_links = variable_get('faq_disable_node_links', FALSE);
  19. $nodes = array();
  20. $count = 0;
  21. foreach ($data as $node) {
  22. $anchor = 'n' . $node->nid;
  23. faq_view_question($nodes[$count], $node, $this_page, $anchor);
  24. faq_view_answer($nodes[$count], $node, array(), $teaser, $links);
  25. $count++;
  26. }
  27. $variables['use_teaser'] = $teaser;
  28. $variables['nodes'] = $nodes;
  29. }
  30. /**
  31. * Create categorized FAQ page if set to show answer when question is clicked.
  32. *
  33. * @param array &$variables
  34. * Array reference of arguments given to the theme() function.
  35. */
  36. function template_preprocess_faq_category_hide_answer(&$variables) {
  37. $data = $variables['data'];
  38. $category_display = $variables['category_display'];
  39. $term = $variables['term'];
  40. $parent_term = $variables['parent_term'];
  41. $class = $variables['class'];
  42. // Fetch configuration.
  43. $teaser = variable_get('faq_use_teaser', FALSE);
  44. $variables['use_teaser'] = $teaser;
  45. $links = variable_get('faq_show_node_links', FALSE);
  46. $disable_node_links = variable_get('faq_disable_node_links', FALSE);
  47. $display_faq_count = variable_get('faq_count', FALSE);
  48. $hide_child_terms = variable_get('faq_hide_child_terms', FALSE);
  49. $show_term_page_children = variable_get('faq_show_term_page_children', FALSE);
  50. $default_sorting = variable_get('faq_default_sorting', 'DESC');
  51. // Initialise some variables.
  52. $default_weight = 0;
  53. if ($default_sorting != 'DESC') {
  54. $default_weight = 1000000;
  55. }
  56. $this_page = $_GET['q'];
  57. $get_child_terms = 0;
  58. // Check if we're on a faq page.
  59. if (arg(0) == _faq_path()) {
  60. // Check if we're on a categorized faq page.
  61. if (is_numeric(arg(1))) {
  62. $get_child_terms = arg(1);
  63. }
  64. }
  65. // Force some settings in case we're processing a special faq question list
  66. // created by a custom call to faq_page().
  67. elseif (!empty($parent_term)) {
  68. $get_child_terms = $parent_term->tid;
  69. $show_term_page_children = TRUE;
  70. }
  71. // Get number of questions, and account for hidden sub-categories.
  72. $count = 0;
  73. if ($display_faq_count && $hide_child_terms) {
  74. $count = faq_taxonomy_term_count_nodes($term->tid);
  75. }
  76. $variables['display_faq_count'] = $display_faq_count;
  77. // Get taxonomy image.
  78. $variables['term_image'] = '';
  79. if (module_exists('taxonomy_image') && function_exists('taxonomy_image_display')) {
  80. $variables['term_image'] = taxonomy_image_display($term->tid, array('class' => 'faq-tax-image'));
  81. }
  82. // Configure header.
  83. $variables['category_depth'] = $term->depth;
  84. $variables['category_name'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
  85. if ($category_display == 'hide_qa') {
  86. $variables['header_title'] = l(faq_tt("taxonomy:term:$term->tid:name", $term->name), "faq-page/$term->tid");
  87. }
  88. else {
  89. $variables['header_title'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
  90. }
  91. // Configure category description.
  92. $variables['description'] = check_markup(faq_tt("taxonomy:term:$term->tid:description", $term->description));
  93. // Get list of sub-categories if necessary.
  94. $child_categories = array();
  95. if (($show_term_page_children || $hide_child_terms) && $category_display == 'new_page') {
  96. $child_categories = faq_view_child_category_headers($term);
  97. }
  98. $variables['subcat_list'] = $child_categories;
  99. $variables['subcat_list_style'] = variable_get('faq_category_listing', 'ul');
  100. // Configure class (faq-qa or faq-qa-hide).
  101. if ($get_child_terms == $term->tid) {
  102. $variables['container_class'] = 'faq-qa';
  103. }
  104. else {
  105. $variables['container_class'] = $class;
  106. }
  107. // Configure sub-category bodies (theme recursively).
  108. $variables['subcat_body_list'] = array();
  109. if (($get_child_terms && $category_display == 'categories_inline') || ((($show_term_page_children && $this_page != _faq_path()) || $hide_child_terms) && $category_display == 'hide_qa')) {
  110. $variables['subcat_body_list'] = faq_get_child_categories_faqs($term, 'faq_category_hide_answer', $default_weight, $default_sorting, $category_display, $variables['class'], $parent_term);
  111. }
  112. if (!count($data)) {
  113. $variables['question_count'] = $count;
  114. $variables['nodes'] = array();
  115. return;
  116. }
  117. $nodes = array();
  118. foreach ($data as $node) {
  119. if (!$hide_child_terms) {
  120. $count++;
  121. }
  122. $node_var = array();
  123. $anchor = 't' . $term->tid . 'n' . $node->nid;
  124. faq_view_question($node_var, $node, $this_page, $anchor);
  125. faq_view_answer($node_var, $node, array(), $teaser, $links);
  126. $nodes[] = $node_var;
  127. }
  128. $variables['nodes'] = $nodes;
  129. $variables['question_count'] = $count;
  130. }