function faq_page in Frequently Asked Questions 5.2
Same name and namespace in other branches
- 5 faq.module \faq_page()
- 6 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.
Return value
The output variable which contains an HTML formatted page with FAQ questions and answers.
1 string reference to 'faq_page'
- faq_menu in ./
faq.module - Implementation of hook_menu().
File
- ./
faq.module, line 777 - 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) {
if (module_exists('pathauto')) {
_pathauto_include();
}
// Things to provide translations for.
$default_values = array(
t('Frequently Asked Questions'),
t('Back to Top'),
t('Q:'),
t('A:'),
);
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.
$breadcrumb = array();
if (!empty($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);
}
}
$current = taxonomy_get_term($tid);
$breadcrumb[] = array(
'path' => 'faq/' . $tid,
'title' => $current->name,
);
while ($parents = taxonomy_get_parents($current->tid)) {
$current = array_shift($parents);
$breadcrumb[] = array(
'path' => 'faq/' . $current->tid,
'title' => $current->name,
);
}
$breadcrumb[] = array(
'path' => 'faq',
'title' => variable_get('faq_title', 'Frequently Asked Questions'),
);
$breadcrumb = array_reverse($breadcrumb);
menu_set_location($breadcrumb);
}
$faq_display = variable_get('faq_display', 'questions_top');
$use_categories = variable_get('faq_use_categories', FALSE);
if (!module_exists("taxonomy")) {
$use_categories = FALSE;
}
$faq_path = drupal_get_path('module', 'faq') . '/includes';
// Non-categorized questions and answers.
if (!$use_categories) {
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, if((w.weight IS NULL), %d, w.weight) as 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 weight, n.sticky DESC, n.created ASC", "n", "nid"), $default_weight);
}
else {
$result = db_query(db_rewrite_sql("SELECT n.nid, if((w.weight IS NULL), %d, w.weight) as 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 weight, n.sticky DESC, n.created DESC", "n", "nid"), $default_weight);
}
while ($row = db_fetch_object($result)) {
$node = node_load($row->nid);
if (node_access("view", $node)) {
$nodes[] = $node;
}
}
if (count($nodes)) {
switch ($faq_display) {
case 'questions_top':
include_once $faq_path . '/faq.questions_top.inc';
$output = theme('faq_questions_top', $nodes);
break;
case 'hide_answer':
include_once $faq_path . '/faq.hide_answer.inc';
$output = theme('faq_hide_answer', $nodes);
break;
case 'questions_inline':
include_once $faq_path . '/faq.questions_inline.inc';
$output = theme('faq_questions_inline', $nodes);
break;
case 'new_page':
include_once $faq_path . '/faq.new_page.inc';
$output = theme('faq_new_page', $nodes);
break;
}
// End of switch.
}
}
else {
$output = '<a name="top"></a>';
$category_display = variable_get('faq_category_display', 'categories_inline');
$hide_child_terms = variable_get('faq_hide_child_terms', FALSE);
$output .= "<br />";
// If we're viewing a specific category/term.
if ($tid != 0) {
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 ? ' - ' : '') . $term->name));
}
if ($category_display == 'hide_qa') {
drupal_add_js(drupal_get_path('module', 'faq') . '/faq.js', 'module');
}
_display_faq_by_category($faq_display, $category_display, $term, 0, $output, $output_answers);
$output = '<div class="content"><div class="faq">' . $output;
$output .= $output_answers . '</div></div>';
return $output;
}
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());
foreach ($vocab_omit as $vid => $set) {
if ($set) {
unset($vocab_omit[$vid]);
}
}
$vocabularies = array_diff_key($vocabularies, $vocab_omit);
$items = array();
$vocab_items = array();
foreach ($vocabularies as $vid => $vobj) {
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':
drupal_add_js(drupal_get_path('module', 'faq') . '/faq.js', 'module');
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 foreach vocab.
}
// End of if $category_display != new_page.
if ($category_display == "new_page") {
$output = theme('item_list', $items, NULL, $list_style);
}
}
$desc = '';
$faq_description = variable_get('faq_description', '');
$format = variable_get('faq_description_format', 0);
if ($format) {
$faq_description = check_markup($faq_description, $format, FALSE);
}
if (!empty($faq_description)) {
$desc = '<div class="faq-description">' . $faq_description . "</div>\n";
}
$output = '<div class="content"><div class="faq">' . $desc . $output;
$output .= $output_answers . "</div></div>\n";
return $output;
}