'. t("This module allows users with the 'administer faq' permission to create question and answer pairs which will be displayed on the 'faq' page. The 'faq' page is automatically generated from the FAQ nodes configured and the layout of this page can be modified on the settings page. Users will need the 'access content' permission in order to view the 'faq' page."). '

'. '

' .t("To create a question and answer, the user must create a 'FAQ' node (Create content >> FAQ). This screen allows the user to edit the question and answer text. If the 'Taxonomy' module is enabled and there are some terms configured for the FAQ node type, it will also be possible to put the questions into different categories when editing."). '

'. '

' .t("The 'Frequently Asked Questions' settings configuration screen will allow users with 'administer faq' permissions to specify different layouts of the questions and answers."). '

'. '

' .t("All users with 'access content' permissions will be able to view the generated FAQ page at 'www.example.com/faq'."). '

'; return $output; case "admin/modules#description": return t("Allows the user to configure the layout of questions and answers on a FAQ page."); case "node/add#faq": return t("Add a question and answer to a FAQ list."); } } /** * Implementation of hook_perm() * Define the permissions this module uses */ function faq_perm() { return array('administer faq'); } /** * Implementation of hook_access() */ function faq_access($op, $node) { if ($op == 'create' || $op == 'update' || $op == 'delete') { return user_access('administer faq'); } } /** * Implementation of hook_menu() */ function faq_menu($may_cache) { $access = user_access('administer faq'); $items = array(); if ($may_cache) { $items[] = array('path' => 'admin/settings/faq', 'title' => t('Frequently Asked Questions'), 'callback' => 'faq_settings_page', 'access' => $access, 'description' => t('Allows the user to configure the layout of questions and answers on a FAQ page.'), ); $items[] = array('path' => 'faq', 'title' => t('Frequently Asked Questions'), 'callback' => t('faq_page'), 'access' => user_access('access content'), 'weight' => 1 ); } else { $items[] = array( 'path' => 'admin/settings/faq/configure', 'title' => t('Configure'), 'description' => t('Allows the user to configure the layout of questions and answers on a FAQ page.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('faq_settings_form'), 'access' => $access, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array('path' => 'node/add/faq', 'title' => t('FAQ'), 'access' => $access, ); $items[] = array('path' => 'faq', 'title' => t('Frequently Asked Questions'), 'callback' => t('faq_page'), 'access' => user_access('access content'), 'weight' => 1 ); if (arg(0) == 'faq' && is_numeric(arg(1))) { $items[] = array('path' => 'faq/' . arg(1), 'title' => t('Frequently Asked Questions'), 'callback' => 'faq_page', 'callback arguments' => array(arg(1)), 'access' => user_access('access content'), 'type' => MENU_CALLBACK, ); } } return $items; } /** * Implementation of hook_node_info() */ function faq_node_info() { return array( 'faq' => array( 'name' => t('FAQ'), 'module' => 'faq', 'description' => t('A frequently asked question and the answer.'), ) ); } /** * Implementation of hook_node_name() */ function faq_node_name($node) { return t('FAQ'); } function faq_form(&$node) { // question $form['title'] = array( '#type' => 'textfield', '#title' => t('Question'), '#default_value' => $node->title, '#required' => TRUE, '#weight' => 0, '#description' => t('Question to be answered'), ); // answer $form['body_filter']['body'] = array( '#type' => 'textarea', '#title' => t('Answer'), '#default_value' => $node->body, '#rows' => 10, '#required' => TRUE, ); $form['body_filter']['format'] = filter_form($node->format); return $form; } function faq_settings_page($op = NULL, $aid = NULL) { switch ($op) { case 'edit': if (is_numeric($aid)) { $output = drupal_get_form('faq_settings_form'); } break; default: $form[] = array( '#type' => 'fieldset', '#title' => t('Add another'), ); $output .= drupal_get_form('faq_settings_form'); break; } return $output; } /** * Define a form to upload the avatar images. */ function faq_settings_form() { $form['questions'] = array('#type' => 'fieldset', '#title' => t('Questions and Answers'), '#weight' => -1, '#collapsible' => 1, '#collapsed' => 0, ); $display_options['questions_inline'] = t('Questions inline'); $display_options['questions_top'] = t('Clicking on question brings user to answer further down the page'); $display_options['hide_answer'] = t('Clicking on question opens/hides answer under question'); $display_options['new_page'] = t('Clicking on question opens the answer in a new page'); $form['questions']['display'] = array('#type' => 'radios', '#options' => $display_options, '#title' => t('Page layout'), '#description' => t('This controls now the questions and answers are displayed on the page and what happens when someone clicks on the question.'), '#default_value' => variable_get('faq_display', 'questions_top'), ); $form['questions']['back_to_top'] = array('#type' => 'textfield', '#title' => t('"Back to Top" link text'), '#description' => t('This allows the user to change the text displayed for the links which return the user to the top of the page on certain page layouts. Defaults to "Back to Top". Leave blank to have no link.'), '#default_value' => variable_get('faq_back_to_top', t('Back to Top')), ); $form['category'] = array('#type' => 'fieldset', '#title' => t('Categories'), '#weight' => 0, '#collapsible' => 1, '#collapsed' => 0, ); $form['category']['categories'] = array('#type' => 'checkbox', '#title' => t('Categorize questions'), '#description' => t('This allows the user to display the questions according to the categories configured on the add/edit FAQ page. Use of sub-categories is only recommended for large lists of questions.'), '#default_value' => variable_get('faq_use_categories', FALSE), ); $category_options['categories_inline'] = t('Categories inline'); $category_options['hide_qa'] = t('Clicking on category opens/hides questions and answers under category'); $category_options['new_page'] = t('Clicking on category opens the questions/answers in a new page'); $form['category']['category_display'] = array('#type' => 'radios', '#options' => $category_options, '#title' => t('Categories layout'), '#description' => t('This controls now the categories are displayed on the page and what happens when someone clicks on the category.'), '#default_value' => variable_get('faq_category_display', 'categories_inline'), ); $form['update']['attach'] = array( '#type' => 'submit', '#value' => t('Update'), '#weight' => 3, ); return $form; } /** * Validate the submission. * * Check whether: * if any of the settings have changed */ function faq_settings_form_validate($form_id, $form_values) { if ($form_values['op'] == t('Update')) { variable_set('faq_display', $form_values['display']); variable_set('faq_back_to_top', $form_values['back_to_top']); variable_set('faq_use_categories', $form_values['categories']); variable_set('faq_category_display', $form_values['category_display']); drupal_set_message(t('Configuration has been updated.')); if (variable_get('faq_use_categories', FALSE) && !module_exists("taxonomy")) { drupal_set_message(t("warning: Categorization of questions will not work without the 'taxonomy' module."), 'error'); } } } /** * Function to display the faq page */ function faq_page($tid = 0) { drupal_add_css(drupal_get_path('module', 'faq') .'/faq.css'); // get page layout $faq_display = variable_get('faq_display', 'questions_top'); // get "back to top" link text $back_to_top = variable_get('faq_back_to_top', t('Back to Top')); $back_to_top = '
' . l(check_plain(t($back_to_top)), 'faq') . ''; // find out if we should categorize the questions, if so get list of // categories $use_categories = variable_get('faq_use_categories', FALSE); if (!module_exists("taxonomy")) $use_categories = FALSE; // non-categorized questions and answers if (!$use_categories) { $result = db_query("SELECT n.title, n.nid, r.body FROM {node} n LEFT JOIN {node_revisions} r ON n.nid = r.nid AND r.vid = n.vid WHERE n.type='faq' AND n.status = 1 ORDER BY n.created DESC"); switch ($faq_display) { case 'questions_top': while ($node = db_fetch_object($result)) { _questions_top($node, $back_to_top, '', $questions, $answers); } $output .= ""; $output .= "
". $answers . "
"; break; case 'hide_answer': drupal_add_js(drupal_get_path('module', 'faq') .'/faq.js', 'module'); $output = '
'; while ($node = db_fetch_object($result)) { $output .= _hide_answer($node); } $output .= '
'; break; case 'questions_inline': $output = "
"; while ($node = db_fetch_object($result)) { $output .= _questions_inline($node, $back_to_top); } $output .= "
"; break; case 'new_page': $output = ""; break; } // end of switch } // categorize questions else { $category_display=variable_get('faq_category_display', 'categories_inline'); $output .= "
"; // if we're viewing a specific category/term if ($tid != 0) { $term = taxonomy_get_term($tid); $result = taxonomy_select_nodes(array($term->tid), 'or', 0, FALSE); if ($result) { _display_faq_by_category($faq_display, $category_display, $result, $term, $output, $output_answers); } $output = '
'.$output . $output_answers .'
'; return $output; } $vocabularies = taxonomy_get_vocabularies("FAQ"); $terms = array(); foreach ($vocabularies as $vid => $vobj) { $tree = taxonomy_get_tree($vid); foreach ($tree as $term) { switch ($category_display) { case 'new_page': $depth = 0; while ($depth < $term->depth) { $indent = ''; $depth--; } break; case 'hide_qa': drupal_add_js(drupal_get_path('module','faq').'/faq.js','module'); case 'categories_inline': $result = taxonomy_select_nodes(array($term->tid), 'or', 0, FALSE); if ($result) { _display_faq_by_category($faq_display, $category_display, $result, $term, $output, $output_answers); } break; } // end of switch (category_display) } // end of foreach term } // end of foreach vocab if ($category_display == "new_page") { $output = "\n\n"; } } $output = '
'. $output . $output_answers .'
'; return $output; } function _display_faq_by_category($faq_display, $category_display, $result, $term, &$output, &$output_answers) { $depth = 0; while ($depth < $term->depth) { $indent = '
'; $output .= $indent; $depth++; } $header = '
' . t($term->name) . '
'; if ($term->depth > 0) { $header = '
' .t($term->name). '
'; } if ($category_display == "hide_qa") { $faq_qa_div_class = "faq_qa_hide"; } else { $faq_qa_div_class = "faq_qa"; } switch ($faq_display) { case 'questions_top': $questions = NULL; $answers = NULL; $output .= $header; $output .= '
'; while ($node = db_fetch_object($result)) { $full_node = node_load($node->nid); if ($full_node->type == "faq") { _questions_top($full_node, $back_to_top, $term->tid, $questions, $answers); } } $output .= "\n"; if ($category_display == "hide_qa") { $output .= "
\n" .$answers. "\n
\n
"; } else { $output .= "
\n"; $ans_depth = 0; while ($ans_depth < $term->depth) { $indent = '
'; $output_answers .= $indent; $ans_depth++; } $output_answers .= $header . "
\n" .$answers. "\n
\n"; while ($ans_depth > 0) { $output_answers .= '
'; $ans_depth--; } } break; case 'hide_answer': drupal_add_js(drupal_get_path('module','faq').'/faq.js','module'); $output .= $header; $output .= '
'; $output .= '
'."\n"; while ($node = db_fetch_object($result)) { $full_node = node_load($node->nid); if ($full_node->type == "faq") { $output .= _hide_answer($full_node); } } $output .= "
\n
\n"; break; case 'questions_inline': $output .= $header; $output .= '
'; $output .= "
\n"; while ($node = db_fetch_object($result)) { $full_node = node_load($node->nid); if ($full_node->type == "faq") { $output .= _questions_inline($full_node, $back_to_top); } } $output .= "
\n
\n"; break; case 'new_page': $output .= $header; $output .= '
'; $output .= "\n
\n"; break; } // end of switch (faq_display) while ($depth > 0) { $output .= ''; $depth--; } } function _questions_top($node, $back_to_top, $tid, &$questions, &$answers) { $anchor = $tid . "n" . $node->nid; $this_page = ltrim(request_uri(), "/"); $questions .= "
  • " . l(t($node->title), $this_page, NULL, NULL, $anchor) . "
  • "; $answers .= "
    " . l(t($node->title), "node/$node->nid", array("name" => "$anchor")) . "
    "; $answers .= "
    " . t($node->body) . $back_to_top . "
    "; return; } function _hide_answer($node) { $output .= '
    ' . t($node->title) . '
    '; $output .= '
    ' . t($node->body) . '
    '; return $output; } function _questions_inline($node, $back_to_top) { $output .= "
    " . l(t($node->title), "node/$node->nid") . "
    "; $output .= "
    " . t($node->body) . $back_to_top . "
    "; return $output; } function _new_page($node) { $output .= "
  • " . l(t($node->title), "node/$node->nid") . "
  • "; return $output; }