function faq_page in Frequently Asked Questions 6
Same name and namespace in other branches
- 5.2 faq.module \faq_page()
- 5 faq.module \faq_page()
- 7 faq.module \faq_page()
Function to display the faq page.
Parameters
$tid: Default is 0, determines if the questions and answers on the page will be shown according to a category or non-categorized.
$faq_display: Optional parameter to override default question layout setting.
$category_display: Optional parameter to override default category layout setting.
Return value
The output variable which contains an HTML formatted page with FAQ questions and answers.
1 call to faq_page()
- _faq_faq_page_filter_replacer in ./
faq.module - Helper function for faq input filter.
1 string reference to 'faq_page'
- faq_menu in ./
faq.module - Implements hook_menu().
File
- ./
faq.module, line 382 - The FAQ module allows users to create a FAQ page, with questions and answers displayed in different styles, according to the settings.
Code
function faq_page($tid = 0, $faq_display = '', $category_display = '') {
if (module_exists('pathauto')) {
module_load_include('inc', 'pathauto');
}
// Things to provide translations for.
$default_values = array(
t('Frequently Asked Questions'),
t('Back to Top'),
t('Q:'),
t('A:'),
);
$output = $output_answers = '';
drupal_add_css(drupal_get_path('module', 'faq') . '/faq.css');
if (arg(0) == 'faq') {
drupal_set_title(check_plain(variable_get('faq_title', 'Frequently Asked Questions')));
}
if (!module_exists("taxonomy")) {
$tid = 0;
}
// Configure the breadcrumb trail.
if (!empty($tid) && ($current_term = taxonomy_get_term($tid))) {
if (!drupal_lookup_path('alias', arg(0) . '/' . arg(1)) && module_exists('pathauto')) {
$placeholders = pathauto_get_placeholders('taxonomy', taxonomy_get_term($tid));
if ($alias = pathauto_create_alias('faq', 'insert', $placeholders, arg(0) . '/' . arg(1), arg(1))) {
drupal_goto($alias);
}
}
if (drupal_match_path($_GET['q'], 'faq/*')) {
faq_set_breadcrumb($current_term);
}
}
if (empty($faq_display)) {
$faq_display = variable_get('faq_display', 'questions_top');
}
$use_categories = variable_get('faq_use_categories', FALSE);
if (!empty($category_display)) {
$use_categories = TRUE;
}
else {
$category_display = variable_get('faq_category_display', 'categories_inline');
}
if (!module_exists("taxonomy")) {
$use_categories = FALSE;
}
$faq_path = drupal_get_path('module', 'faq') . '/includes';
if ($use_categories && $category_display == 'hide_qa' || $faq_display == 'hide_answer') {
drupal_add_js(array(
'faq' => array(
'faq_hide_qa_accordion' => variable_get('faq_hide_qa_accordion', FALSE),
),
), 'setting');
drupal_add_js(array(
'faq' => array(
'faq_category_hide_qa_accordion' => variable_get('faq_category_hide_qa_accordion', FALSE),
),
), 'setting');
drupal_add_js(drupal_get_path('module', 'faq') . '/faq.js', 'module');
}
// Non-categorized questions and answers.
if (!$use_categories || $category_display == 'none' && empty($tid)) {
if (!empty($tid)) {
drupal_not_found();
return;
}
$default_sorting = variable_get('faq_default_sorting', 'DESC');
$default_weight = 0;
if ($default_sorting != 'DESC') {
$default_weight = 1000000;
$result = db_query(db_rewrite_sql("SELECT n.nid, COALESCE(w.weight, %d) as effective_weight, n.sticky, n.created FROM {node} n LEFT JOIN {faq_weights} w ON w.nid = n.nid WHERE n.type='faq' AND n.status = 1 AND (w.tid = 0 OR w.tid IS NULL) ORDER BY effective_weight, n.sticky DESC, n.created ASC", "n", "nid"), $default_weight);
}
else {
$result = db_query(db_rewrite_sql("SELECT n.nid, COALESCE(w.weight, %d) as effective_weight, n.sticky, n.created FROM {node} n LEFT JOIN {faq_weights} w ON w.nid = n.nid WHERE n.type='faq' AND n.status = 1 AND (w.tid = 0 OR w.tid IS NULL) ORDER BY effective_weight, n.sticky DESC, n.created DESC", "n", "nid"), $default_weight);
}
$data = array();
while ($row = db_fetch_object($result)) {
$node = node_load($row->nid);
if (node_access('view', $node)) {
$data[] = $node;
}
}
switch ($faq_display) {
case 'questions_top':
include_once $faq_path . '/faq.questions_top.inc';
$output = theme('faq_questions_top', $data);
break;
case 'hide_answer':
include_once $faq_path . '/faq.hide_answer.inc';
$output = theme('faq_hide_answer', $data);
break;
case 'questions_inline':
include_once $faq_path . '/faq.questions_inline.inc';
$output = theme('faq_questions_inline', $data);
break;
case 'new_page':
include_once $faq_path . '/faq.new_page.inc';
$output = theme('faq_new_page', $data);
break;
}
// End of switch.
}
else {
$hide_child_terms = variable_get('faq_hide_child_terms', FALSE);
// If we're viewing a specific category/term.
if (!empty($tid)) {
if ($term = taxonomy_get_term($tid)) {
$title = variable_get('faq_title', 'Frequently Asked Questions');
if (arg(0) == 'faq' && is_numeric(arg(1))) {
drupal_set_title(check_plain($title . ($title ? ' - ' : '') . faq_tt("taxonomy:term:{$term->tid}:name", $term->name)));
}
_display_faq_by_category($faq_display, $category_display, $term, 0, $output, $output_answers);
return theme('faq_page', $output, $output_answers);
}
else {
drupal_not_found();
return;
}
}
$list_style = variable_get('faq_category_listing', 'ul');
$vocabularies = taxonomy_get_vocabularies('faq');
$vocab_omit = variable_get('faq_omit_vocabulary', array());
$items = array();
$vocab_items = array();
$valid_vocab = FALSE;
foreach ($vocabularies as $vid => $vobj) {
if (isset($vocab_omit[$vid]) && $vocab_omit[$vid] != 0) {
continue;
}
$valid_vocab = TRUE;
if ($category_display == "new_page") {
$vocab_items = _get_indented_faq_terms($vid, 0);
$items = array_merge($items, $vocab_items);
}
else {
if ($hide_child_terms && $category_display == 'hide_qa') {
$tree = taxonomy_get_tree($vid, 0, -1, 1);
}
else {
$tree = taxonomy_get_tree($vid);
}
foreach ($tree as $term) {
switch ($category_display) {
case 'hide_qa':
case 'categories_inline':
if (taxonomy_term_count_nodes($term->tid, 'faq')) {
_display_faq_by_category($faq_display, $category_display, $term, 1, $output, $output_answers);
}
break;
}
// End of switch (category_display).
}
// End of foreach term.
}
// End of if $category_display != new_page.
}
// End of foreach vocab.
if ($category_display == "new_page") {
$output = theme('item_list', $items, NULL, $list_style);
}
if (!$valid_vocab) {
drupal_set_message(t('Categories are enabled but no vocabulary is associated with the FAQ content type. Either create a vocabulary or disable categorization in order for questions to appear.'), 'error');
}
}
$faq_description = variable_get('faq_description', '');
$format = variable_get('faq_description_format', 0);
if ($format) {
$faq_description = check_markup($faq_description, $format, FALSE);
}
return theme('faq_page', $output, $output_answers, $faq_description);
}