faq.questions_inline.inc 5.7 KB

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