'. 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'); } /** * Implementation of hook_access() */ function faq_access($op, $node) { if ($op == 'create' || $op == 'update' || $op == 'delete') { return user_access('administer faq'); } else if ($op == 'view') { return user_access('view faq'); } } /** * Implementation of hook_menu() */ function faq_menu($may_cache) { $access = user_access('administer faq'); $items = array(); if ($may_cache) { $items[] = array('path' => 'admin/content/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('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' => $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('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 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 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['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']); variable_set('faq_use_teaser', $form_values['use_teaser']); variable_set('faq_more_link', $form_values['more_link']); 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.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 .= "
"; // 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 (db_num_rows($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 (db_num_rows($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 ."
\n"; return $output; } function _display_faq_by_category($faq_display, $category_display, $result, $term, &$output, &$output_answers) { // 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')); $depth = 0; while ($depth < $term->depth) { $indent = '
'; $output .= $indent; $depth++; } $faq_class = "faq_qa"; if ($category_display == "hide_qa") { $faq_class = "faq_qa_hide"; } switch ($faq_display) { case 'questions_top': theme_category_questions_top($result, $display_vars, $faq_class, $category_display, $term, $output, $output_answers); break; case 'hide_answer': $output .= theme_category_hide_answer($result, $term->name, $faq_class); break; case 'questions_inline': $output .= theme_category_questions_inline($result, $display_vars, $term->name, $faq_class); break; case 'new_page': $output .= theme_category_new_page($result, $term->name, $faq_class); break; } // end of switch (faq_display) while ($depth > 0) { $output .= '
'; $depth--; } } function theme_questions_top($result, $display_vars) { // configure "back to top" link $back_to_top = '
 '; if (isset($display_vars['back_to_top']) && $display_vars['back_to_top'] != '') { $back_to_top = ''; } while ($node = db_fetch_object($result)) { $anchor = "n". $node->nid; $questions .= "
  • ". l(t($node->title), 'faq', NULL, NULL, $anchor) ."
  • \n"; $answers .= "
    ". l(t($node->title), "node/$node->nid", array("name" => "$anchor")) ."
    \n"; // should we display teaser or full text if ($display_vars['use_teaser']) { $more_link = ''; if ($display_vars['more_link'] != '' && strlen($node->teaser) < strlen($node->body)) { $more_link = ''; } $answers .= "
    ". t($node->teaser). $more_link. $back_to_top ."
    \n"; } else { $answers .= "
    ". t($node->body). $back_to_top ."
    \n"; } } $output = "\n"; $output .= "
    \n". $answers ."
    \n"; return $output; } function theme_category_questions_top($result, $display_vars, $class, $category_display, $term, &$output, &$output_answers) { $this_page = 'faq'; if (arg(0) == 'faq' && is_numeric(arg(1))) { $this_page .= "/". arg(1); } // configure "back to top" link $back_to_top = '
     '; if (isset($display_vars['back_to_top']) && $display_vars['back_to_top'] != '') { $back_to_top = ''; } // configure header $header = '
    ' .check_plain(t($term->name)) ."
    \n"; if ($term->depth > 0) { $header = '
    ' .check_plain(t($term->name)) ."
    \n"; } $output .= $header; $output .= '
    ' ."\n"; while ($node = db_fetch_object($result)) { $full_node = node_load($node->nid); if ($full_node->type == "faq") { $anchor = $term->tid ."n". $node->nid; $questions .= "
  • ". l(t($node->title), $this_page, NULL, NULL, $anchor) ."
  • \n"; $answers .= "
    ". l(t($node->title), "node/$node->nid", array("name" => "$anchor")) ."
    \n"; // should we display teaser or full text if ($display_vars['use_teaser']) { $more_link = ''; if ($display_vars['more_link'] != '' && strlen($full_node->teaser) < strlen($full_node->body)) { $more_link = ''; } $answers .= "
    ". t($full_node->teaser). $more_link. $back_to_top ."
    \n"; } else { $answers .= "
    ". t($full_node->body). $back_to_top ."
    \n"; } } } $output .= "\n"; if ($category_display == "hide_qa") { $output .= "
    \n". $answers ."\n
    \n
    "; } else { $output .= "\n"; $ans_depth = 0; while ($ans_depth < $term->depth) { $indent = '
    ' ."\n"; $output_answers .= $indent; $ans_depth++; } $output_answers .= $header ."
    \n". $answers ."\n
    \n"; while ($ans_depth > 0) { $output_answers .= "
    \n"; $ans_depth--; } } } function theme_hide_answer($result) { drupal_add_js(drupal_get_path('module', 'faq') .'/faq.js', 'module'); $output = '
    ' ."\n"; while ($node = db_fetch_object($result)) { $output .= '
    '. check_plain(t($node->title)) ."
    \n"; $output .= '
    '. t($node->body) ."
    \n"; } $output .= "
    \n"; return $output; } function theme_category_hide_answer($result, $term_name, $class) { // configure header $header = '
    ' .check_plain(t($term_name)) ."
    \n"; if ($term->depth > 0) { $header = '
    '.check_plain(t($term_name))."
    \n"; } drupal_add_js(drupal_get_path('module','faq').'/faq.js','module'); $output = $header; $output .= '
    ' ."\n"; $output .= '
    ' ."\n"; while ($node = db_fetch_object($result)) { $full_node = node_load($node->nid); if ($full_node->type == "faq") { $output .= '
    '. check_plain(t($node->title)) ."
    \n"; $output .= '
    '. t($full_node->body) ."
    \n"; } } $output .= "
    \n
    \n"; return $output; } function theme_questions_inline($result, $display_vars) { // configure "back to top" link $back_to_top = '
     '; if (isset($display_vars['back_to_top']) && $display_vars['back_to_top'] != '') { $back_to_top = ''; } $output = "
    \n"; while ($node = db_fetch_object($result)) { $output .= "
    ". l(t($node->title), "node/$node->nid") ."
    \n"; // should we display teaser or full text if ($display_vars['use_teaser']) { $more_link = ''; if ($display_vars['more_link'] != '' && strlen($node->teaser) < strlen($node->body)) { $more_link = ''; } $output .= "
    ". t($node->teaser). $more_link. $back_to_top ."
    \n"; } else { $output .= "
    ". t($node->body). $back_to_top ."
    \n"; } } $output .= "
    \n"; return $output; } function theme_category_questions_inline($result, $display_vars, $term_name, $class) { $this_page = 'faq'; if (arg(0) == 'faq' && is_numeric(arg(1))) { $this_page .= "/". arg(1); } // configure "back to top" link $back_to_top = '
     '; if (isset($display_vars['back_to_top']) && $display_vars['back_to_top'] != '') { $back_to_top = ''; } // configure header $header = '
    ' .check_plain(t($term_name)) ."
    \n"; if ($term->depth > 0) { $header = '
    ' .check_plain(t($term_name)) ."
    \n"; } $output = $header; $output .= '
    ' ."\n"; $output .= "
    \n"; while ($node = db_fetch_object($result)) { $full_node = node_load($node->nid); if ($full_node->type == "faq") { $output .= "
    ". l(t($node->title), "node/$node->nid") ."
    \n"; // should we display teaser or full text if ($display_vars['use_teaser']) { $more_link = ''; if ($display_vars['more_link'] != '' && strlen($full_node->teaser) < strlen($full_node->body)) { $more_link = ''; } $output .= "
    ". t($full_node->teaser). $more_link. $back_to_top ."
    \n"; } else { $output .= "
    ". t($full_node->body). $back_to_top ."
    \n"; } } } $output .= "
    \n
    \n"; return $output; } function theme_new_page($result) { $output = "\n"; return $output; } function theme_category_new_page($result, $term_name, $class) { // configure header $header = '
    ' .check_plain(t($term_name)) ."
    \n"; if ($term->depth > 0) { $header = '
    ' .check_plain(t($term_name)) ."
    \n"; } $output = $header; $output .= '
    ' ."\n"; $output .= "\n
    \n"; return $output; } function faq_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': $blocks[0]['info'] = t('FAQ Categories'); $blocks[1]['info'] = t('Recent FAQs'); return $blocks; case 'view': switch ($delta) { case 0: // FAQ Categories if (module_exists("taxonomy")) { $terms = array(); foreach (taxonomy_get_vocabularies('FAQ') as $vocab) { foreach (taxonomy_get_tree($vocab->vid) as $term) { $terms[$term->name] = $term->tid; } } ksort($terms); if (sizeof($terms) > 0) { $block['subject'] = t('FAQ Categories'); $block['content'] = "\n"; } } break; case 1: // Recent FAQs $block['subject'] = t('Recent FAQs'); $block['content'] = theme_faq_highlights(variable_get('faq_block_recent_faq_count', 5)); break; } return $block; case 'configure': if ($delta == 1) { // Recent FAQs $form['faq_block_recent_faq_count'] = array( '#type' => 'textfield', '#title' => t('Number of FAQs to show'), '#description' => t("This controls the number of FAQs that appear in the 'Recent FAQs' block"), '#default_value' => variable_get('faq_block_recent_faq_count', 5), ); } return $form; case 'save': if ($delta == 1) { variable_set('faq_block_recent_faq_count', $edit['faq_block_recent_faq_count']); } return; } } function theme_faq_highlights($num = 5) { $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 LIMIT %d", $num); $output .= "\n"; $output .= l(t('All FAQs'), 'faq'); return $output; }