faq.questions_top.inc 11 KB

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