faq.questions_top.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php
  2. /**
  3. * @file
  4. * FAQ page callbacks for the "questions top" layouts.
  5. */
  6. /**
  7. * Create the structure of the page, when the questions are to be shown on top.
  8. *
  9. * @param &$variables
  10. * Array reference of arguments given to the theme() function.
  11. * @return
  12. * A variable holding the HTML formatted page.
  13. */
  14. function template_preprocess_faq_questions_top(&$variables) {
  15. $data = $variables['data'];
  16. // Fetch configuration.
  17. $teaser = variable_get('faq_use_teaser', FALSE);
  18. $links = variable_get('faq_show_node_links', FALSE);
  19. $disable_node_links = variable_get('faq_disable_node_links', FALSE);
  20. // Configure labels.
  21. $variables['question_label'] = '';
  22. $variables['answer_label'] = '';
  23. if (variable_get('faq_qa_mark', FALSE)) {
  24. $variables['question_label'] = check_plain(variable_get('faq_question_label', "Q:"));
  25. $variables['answer_label'] = check_plain(variable_get('faq_answer_label', "A:"));
  26. }
  27. // Configure "back to top" link.
  28. $this_page = $_GET['q'];
  29. $back_to_top = faq_init_back_to_top($this_page);
  30. // Loop through results.
  31. $questions = array();
  32. $answers = array();
  33. $key = 0;
  34. foreach ($data as $node) {
  35. $anchor = 'n' . $node->nid;
  36. $questions[$key] = l($node->title, $this_page, array('fragment' => $anchor));
  37. faq_view_question($answers[$key], $node, NULL, $anchor);
  38. faq_view_answer($answers[$key], $node, $back_to_top, $teaser, $links);
  39. $key++;
  40. }
  41. $variables['limit'] = $key;
  42. $list_style = variable_get('faq_question_listing', 'ul');
  43. $variables['list_style'] = $list_style;
  44. $variables['use_teaser'] = $teaser;
  45. $variables['questions'] = $questions;
  46. $variables['answers'] = $answers;
  47. $variables['questions_list'] = theme('item_list', array('items' => $questions, 'title' => NULL, 'type' => $list_style, 'attributes' => array("class" => "faq-ul-questions-top")));
  48. }
  49. /**
  50. * Create categorized questions for FAQ page if set to show questions on top.
  51. *
  52. * @param &$variables
  53. * Array reference of arguments given to the theme() function.
  54. */
  55. function template_preprocess_faq_category_questions_top(&$variables) {
  56. $data = $variables['data'];
  57. $category_display = $variables['category_display'];
  58. $term = $variables['term'];
  59. $parent_term = $variables['parent_term'];
  60. $class = $variables['class'];
  61. // Fetch configuration.
  62. $teaser = variable_get('faq_use_teaser', FALSE);
  63. $links = variable_get('faq_show_node_links', FALSE);
  64. $disable_node_links = variable_get('faq_disable_node_links', FALSE);
  65. $display_faq_count = variable_get('faq_count', FALSE);
  66. $hide_child_terms = variable_get('faq_hide_child_terms', FALSE);
  67. $show_term_page_children = variable_get('faq_show_term_page_children', FALSE);
  68. $group_questions_top = variable_get('faq_group_questions_top', FALSE);
  69. $default_sorting = variable_get('faq_default_sorting', 'DESC');
  70. // Configure labels.
  71. $variables['question_label'] = '';
  72. $variables['answer_label'] = '';
  73. if (variable_get('faq_qa_mark', FALSE)) {
  74. $variables['question_label'] = check_plain(variable_get('faq_question_label', "Q:"));
  75. $variables['answer_label'] = check_plain(variable_get('faq_answer_label', "A:"));
  76. }
  77. // Initialise some variables.
  78. $default_weight = 0;
  79. if ($default_sorting != 'DESC') {
  80. $default_weight = 1000000;
  81. }
  82. $this_page = $_GET['q'];
  83. $get_child_terms = 0;
  84. // Check if we're on a faq page.
  85. if (arg(0) == 'faq-page') {
  86. // Check if we're on a categorized faq page.
  87. if (is_numeric(arg(1))) {
  88. $get_child_terms = arg(1);
  89. }
  90. }
  91. // Force some settings in case we're processing a special faq question list
  92. // created by a custom call to faq_page().
  93. elseif (!empty($parent_term)) {
  94. $get_child_terms = $parent_term->tid;
  95. $show_term_page_children = TRUE;
  96. }
  97. // Configure "back to top" link.
  98. $back_to_top = faq_init_back_to_top($this_page);
  99. // Get number of questions, and account for hidden sub-categories.
  100. $count = 0;
  101. if ($display_faq_count && $hide_child_terms) {
  102. $count = faq_taxonomy_term_count_nodes($term->tid);
  103. }
  104. $variables['display_faq_count'] = $display_faq_count;
  105. // Get taxonomy image.
  106. $variables['term_image'] = '';
  107. if (module_exists('taxonomy_image')) {
  108. $variables['term_image'] = taxonomy_image_display($term->tid, array('class' => 'faq-tax-image'));
  109. }
  110. // Configure header.
  111. $variables['category_depth'] = $term->depth;
  112. $variables['category_name'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
  113. if ($category_display == 'hide_qa') {
  114. $variables['header_title'] = l(faq_tt("taxonomy:term:$term->tid:name", $term->name), "faq/$term->tid");
  115. }
  116. else {
  117. $variables['header_title'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
  118. }
  119. // Configure category description.
  120. $variables['description'] = check_markup(faq_tt("taxonomy:term:$term->tid:description", $term->description));
  121. // Get list of sub-categories if necessary.
  122. $child_categories = array();
  123. if (($show_term_page_children || $hide_child_terms) && $category_display == 'new_page') {
  124. $child_categories = faq_view_child_category_headers($term);
  125. }
  126. $variables['subcat_list'] = $child_categories;
  127. $variables['subcat_list_style'] = variable_get('faq_category_listing', 'ul');
  128. // Configure class (faq-qa or faq-qa-hide).
  129. if ($get_child_terms == $term->tid) {
  130. $variables['container_class'] = 'faq-qa';
  131. }
  132. else {
  133. $variables['container_class'] = $class;
  134. }
  135. // Configure sub-category bodies (theme recursively).
  136. $variables['subcat_body_list'] = array();
  137. if (($get_child_terms && $category_display == 'categories_inline') || ((($show_term_page_children && $this_page != 'faq-page') || $hide_child_terms) && $category_display == 'hide_qa')) {
  138. $variables['subcat_body_list'] = faq_get_child_categories_faqs($term, 'faq_category_questions_top', $default_weight, $default_sorting, $category_display, $variables['class'], $parent_term);
  139. }
  140. $variables['group_questions_top'] = $group_questions_top;
  141. if (!count($data)) {
  142. $variables['question_count'] = $count;
  143. $variables['nodes'] = array();
  144. $variables['answer_category_name'] = FALSE;
  145. return;
  146. }
  147. $questions = array();
  148. $nodes = array();
  149. foreach ($data as $node) {
  150. if (!$hide_child_terms) {
  151. $count++;
  152. }
  153. $node_var = array();
  154. $anchor = 't' . $term->tid . 'n' . $node->nid;
  155. faq_view_question($node_var, $node, NULL, $anchor);
  156. if ($group_questions_top || $category_display == 'hide_qa') {
  157. faq_view_answer($node_var, $node, $back_to_top, $teaser, $links);
  158. }
  159. $nodes[] = $node_var;
  160. $questions[] = l($node->title, $this_page, array('fragment' => $anchor));
  161. }
  162. $variables['question_count'] = $count;
  163. $variables['use_teaser'] = $teaser;
  164. $variables['question_list'] = $questions;
  165. $variables['question_list_style'] = variable_get('faq_question_listing', 'ul');
  166. if ($group_questions_top || $category_display == "hide_qa") {
  167. $variables['nodes'] = $nodes;
  168. $variables['answer_category_name'] = variable_get('faq_answer_category_name', FALSE);
  169. }
  170. else {
  171. $variables['nodes'] = array();
  172. $variables['answer_category_name'] = FALSE;
  173. }
  174. }
  175. /**
  176. * Create categorized answers for FAQ page if set to show the questions on top.
  177. *
  178. * @param &$variables
  179. * Array reference of arguments given to the theme() function.
  180. */
  181. function template_preprocess_faq_category_questions_top_answers(&$variables) {
  182. $data = $variables['data'];
  183. $category_display = $variables['category_display'];
  184. $term = $variables['term'];
  185. $parent_term = $variables['parent_term'];
  186. $class = $variables['class'];
  187. // Fetch configuration.
  188. $teaser = variable_get('faq_use_teaser', FALSE);
  189. $links = variable_get('faq_show_node_links', FALSE);
  190. $disable_node_links = variable_get('faq_disable_node_links', FALSE);
  191. $hide_child_terms = variable_get('faq_hide_child_terms', FALSE);
  192. $show_term_page_children = variable_get('faq_show_term_page_children', FALSE);
  193. $group_questions_top = variable_get('faq_group_questions_top', FALSE);
  194. $default_sorting = variable_get('faq_default_sorting', 'DESC');
  195. // Configure labels.
  196. $variables['question_label'] = '';
  197. $variables['answer_label'] = '';
  198. if (variable_get('faq_qa_mark', FALSE)) {
  199. $variables['question_label'] = check_plain(variable_get('faq_question_label', "Q:"));
  200. $variables['answer_label'] = check_plain(variable_get('faq_answer_label', "A:"));
  201. }
  202. // Initialise some variables.
  203. $default_weight = 0;
  204. if ($default_sorting != 'DESC') {
  205. $default_weight = 1000000;
  206. }
  207. $variables['group_questions_top'] = $group_questions_top;
  208. if ($group_questions_top || $category_display == "hide_qa") {
  209. $variables['display_answers'] = FALSE;
  210. $variables['category_depth'] = 0;
  211. return;
  212. }
  213. $variables['display_answers'] = TRUE;
  214. $this_page = $_GET['q'];
  215. $get_child_terms = 0;
  216. // Check if we're on a faq page.
  217. if (arg(0) == 'faq-page') {
  218. // Check if we're on a categorized faq page.
  219. if (is_numeric(arg(1))) {
  220. $get_child_terms = arg(1);
  221. }
  222. }
  223. // Force some settings in case we're processing a special faq question list
  224. // created by a custom call to faq_page().
  225. elseif (!empty($parent_term)) {
  226. $get_child_terms = $parent_term->tid;
  227. $show_term_page_children = TRUE;
  228. }
  229. // Configure "back to top" link.
  230. $back_to_top = faq_init_back_to_top($this_page);
  231. // Get taxonomy image.
  232. $variables['term_image'] = '';
  233. if (module_exists('taxonomy_image')) {
  234. $variables['term_image'] = taxonomy_image_display($term->tid, array('class' => 'faq-tax-image'));
  235. }
  236. // Configure sub-category bodies (theme recursively).
  237. $variables['subcat_body_list'] = array();
  238. if (($get_child_terms && $category_display == 'categories_inline') || ((($show_term_page_children && $this_page != 'faq-page') || $hide_child_terms) && $category_display == 'hide_qa')) {
  239. $variables['subcat_body_list'] = faq_get_child_categories_faqs($term, 'faq_category_questions_top_answers', $default_weight, $default_sorting, $category_display, $variables['class'], $parent_term);
  240. }
  241. $nodes = array();
  242. foreach ($data as $node) {
  243. $node_var = array();
  244. $anchor = 't' . $term->tid . 'n' . $node->nid;
  245. faq_view_question($node_var, $node, NULL, $anchor);
  246. faq_view_answer($node_var, $node, $back_to_top, $teaser, $links);
  247. $nodes[] = $node_var;
  248. }
  249. $variables['use_teaser'] = $teaser;
  250. $variables['nodes'] = $nodes;
  251. $variables['category_name'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
  252. $variables['category_depth'] = $term->depth;
  253. $variables['display_header'] = FALSE;
  254. $variables['answer_category_name'] = variable_get('faq_answer_category_name', FALSE);
  255. if ($variables['answer_category_name'] && faq_taxonomy_term_count_nodes($term->tid)) {
  256. $variables['display_header'] = TRUE;
  257. }
  258. }