'. 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 'view faq' 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 'view faq' 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', 'view faq', 'edit own faq', 'edit faq', 'create faq'); } /** * Implementation of hook_access() */ function faq_access($op, $node) { global $user; if ($op == 'create') { if (user_access('create faq') || user_access('administer faq')) { return TRUE; } } else if ($op == 'update' || $op == 'delete') { if (user_access('edit faq') || user_access('administer faq')) { return TRUE; } else if (user_access('edit own faq') && $user->uid == $node->uid) { return TRUE; } } else if ($op == 'view') { return user_access('view faq'); } } /** * Implementation of hook_menu() */ function faq_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array('path' => 'admin/content/faq', 'title' => t('Frequently Asked Questions Settings'), 'callback' => 'faq_settings_page', 'access' => user_access('administer faq'), '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('view faq'), 'weight' => 1 ); } else { $items[] = array( 'path' => 'admin/content/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' => user_access('administer faq'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array('path' => 'node/add/faq', 'title' => t('FAQ'), 'access' => user_access('create faq'), ); $items[] = array('path' => 'faq', 'title' => t('Frequently Asked Questions'), 'callback' => t('faq_page'), 'access' => user_access('view faq'), '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('view faq'), '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 its 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' => 20, '#required' => TRUE, '#description' => t('This is that answer to the question. It will be filtered according to the input format.'), ); $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 takes 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 how 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['questions']['use_teaser'] = array('#type' => 'checkbox', '#title' => t('Use answer teaser'), '#description' => t("This enables the display of the answer teaser text instead of the full answer when using the 'Questions inline' or 'Clicking on question takes user to answer further down the page' display options. This is useful when you have long descriptive text. The user can see the full answer by clicking on the question."), '#default_value' => variable_get('faq_use_teaser', FALSE), ); $form['questions']['more_link'] = array('#type' => 'textfield', '#title' => t('">> more" link text'), '#description' => t('This allows the user to change the text displayed for the links to the full answer text when teasers are used. Leave blank to have no link.'), '#default_value' => variable_get('faq_more_link', t('>> more')), ); $form['questions']['body_filter']['description'] = array( '#type' => 'textarea', '#title' => t('Description'), '#default_value' => variable_get('faq_description', ''), '#description' => t('Your FAQ description. This will be placed at the top of the page, above the questions and can serve as an introductory text.'), '#rows' => 5, ); $form['questions']['body_filter']['format'] = filter_form(variable_get('faq_description_format', '')); $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. The Taxonomy module must be enabled.'), '#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['category']['answer_category_name'] = array('#type' => 'checkbox', '#title' => t('Display category name for answers'), '#description' => t("This allows the user to toggle the visibility of the category name above each answer section for the 'Clicking on question takes user to answer further down the page' question/answer display."), '#default_value' => variable_get('faq_answer_category_name', FALSE), ); $form['category']['group_questions_top'] = array('#type' => 'checkbox', '#title' => t("Group questions and answers for 'Categories inline'"), '#description' => t("This controls how categories are implemented with the 'Clicking on question takes user to answer further down the page' question/answer display."), '#default_value' => variable_get('faq_group_questions_top', FALSE), ); $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']); variable_set('faq_use_teaser', $form_values['use_teaser']); variable_set('faq_more_link', $form_values['more_link']); variable_set('faq_description', $form_values['description']); variable_set('faq_description_format', $form_values['format']); variable_set('faq_group_questions_top', $form_values['group_questions_top']); variable_set('faq_answer_category_name', $form_values['answer_category_name']); 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 $display_vars['back_to_top'] = variable_get('faq_back_to_top', t('Back to Top')); // get whether or not we should use teasers $display_vars['use_teaser'] = variable_get('faq_use_teaser', FALSE); // get ">> more" link text $display_vars['more_link'] = variable_get('faq_more_link', t('>> more')); // 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, r.teaser 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.sticky DESC, n.created DESC"); switch ($faq_display) { case 'questions_top': $output = theme_questions_top($result, $display_vars); break; case 'hide_answer': $output = theme_hide_answer($result); break; case 'questions_inline': $output = theme_questions_inline($result, $display_vars); break; case 'new_page': $output = theme_new_page($result); break; } // end of switch } // categorize questions else { $category_display=variable_get('faq_category_display', 'categories_inline'); $output .= "'. t($term->description) ."
'. t($faq_description). "
'. l(t($display_vars['back_to_top']), 'faq') .'
'; } while ($node = db_fetch_object($result)) { $anchor = "n". $node->nid; $questions .= ''. l($display_vars['more_link'], "node/$node->nid") .'
'; } $answers .= ''. l(t($display_vars['back_to_top']), $this_page) .'
'; } // configure header $header = ''. t($term->description) ."
'. l($display_vars['more_link'], "node/$node->nid") .'
'; } $answers .= ''. t($term->description) ."
'. l(t($display_vars['back_to_top']), 'faq') .'
'; } $output = "'. l($display_vars['more_link'], "node/$node->nid") .'
'; } $output .= ''. l(t($display_vars['back_to_top']), $this_page) .'
'; } // configure header $header = ''. t($term->description) ."
'. l($display_vars['more_link'], "node/$node->nid") .'
'; } $output .= ''. t($term->description) ."