faq.new_page.inc 4.4 KB

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