faq.new_page.inc 4.5 KB

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