View source
<?php
function faq_help($section = '') {
$output = '';
switch ($section) {
case "admin/help#faq":
$output .= '<p>' . 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.") . '</p>' . '<p>' . 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.") . '</p>' . '<p>' . t("The 'Frequently Asked Questions' settings configuration screen will allow users with 'administer faq' permissions to specify different layouts of the questions and answers.") . '</p>' . '<p>' . t("All users with 'view faq' permissions will be able to view the generated FAQ page at 'www.example.com/faq'.") . '</p>';
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.");
}
}
function faq_perm() {
return array(
'administer faq',
'view faq',
'edit own faq',
'edit faq',
'create faq',
);
}
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');
}
}
}
}
function faq_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/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' => variable_get('faq_title', t('Frequently Asked Questions')),
'callback' => 'faq_page',
'access' => user_access('view faq'),
'weight' => 1,
);
$items[] = array(
'path' => 'admin/settings/faq/general',
'title' => t('General'),
'description' => t('Allows the user to configure the header and descriptive text for the FAQ page.'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'faq_general_settings_form',
),
'access' => user_access('administer faq'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items[] = array(
'path' => 'admin/settings/faq/questions',
'title' => t('Questions'),
'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_questions_settings_form',
),
'access' => user_access('administer faq'),
'type' => MENU_LOCAL_TASK,
'weight' => -9,
);
$items[] = array(
'path' => 'admin/settings/faq/categories',
'title' => t('Categories'),
'description' => t('Allows the user to configure the layout of questions and answers using categories on a FAQ page.'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'faq_categories_settings_form',
),
'access' => user_access('administer faq'),
'type' => MENU_LOCAL_TASK,
'weight' => -8,
);
$items[] = array(
'path' => 'admin/settings/faq/weight',
'title' => t('Weight'),
'description' => t('Allows the user to configure the order of questions and answers on a FAQ page.'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'faq_weight_settings_form',
),
'access' => user_access('administer faq'),
'type' => MENU_LOCAL_TASK,
'weight' => -8,
);
$items[] = array(
'path' => 'node/add/faq',
'title' => t('FAQ'),
'access' => user_access('create faq'),
);
$items[] = array(
'path' => 'faq',
'title' => variable_get('faq_title', t('Frequently Asked Questions')),
'callback' => 'faq_page',
'access' => user_access('view faq'),
'weight' => 1,
);
if (arg(0) == 'faq' && is_numeric(arg(1))) {
$items[] = array(
'path' => 'faq/' . arg(1),
'title' => variable_get('faq_title', t('Frequently Asked Questions')),
'callback' => 'faq_page',
'callback arguments' => array(
arg(1),
),
'access' => user_access('view faq'),
'type' => MENU_CALLBACK,
);
}
}
return $items;
}
function faq_node_info() {
return array(
'faq' => array(
'name' => t('FAQ'),
'module' => 'faq',
'description' => t('A frequently asked question and its answer.'),
),
);
}
function faq_node_name($node) {
return t('FAQ');
}
function faq_form(&$node) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Question'),
'#default_value' => $node->title,
'#required' => TRUE,
'#weight' => 0,
'#description' => t('Question to be answered'),
);
$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_delete(&$node) {
db_query('DELETE FROM {faq_weights} WHERE nid = %d', $node->nid);
}
function faq_view($node, $teaser = FALSE, $page = FALSE) {
if ($page) {
$breadcrumb = array();
$breadcrumb[] = array(
'path' => 'node/' . $node->nid,
);
if (module_exists("taxonomy") && $node->taxonomy) {
foreach ($node->taxonomy as $term) {
$current = $term;
continue;
}
$breadcrumb[] = array(
'path' => 'faq/' . $current->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', t('Frequently Asked Questions')),
);
$breadcrumb = array_reverse($breadcrumb);
menu_set_location($breadcrumb);
}
$node = node_prepare($node, $teaser);
return $node;
}
function faq_settings_page($op = NULL, $aid = NULL) {
$output .= drupal_get_form('faq_general_settings_form');
return $output;
}
function faq_general_settings_form() {
$form['faq_title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => variable_get('faq_title', t('Frequently Asked Questions')),
);
$form['body_filter']['faq_description'] = array(
'#type' => 'textarea',
'#title' => t('FAQ 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['body_filter']['faq_description_format'] = filter_form(variable_get('faq_description_format', ''));
$form['update'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#weight' => 3,
);
return $form;
}
function faq_general_settings_form_submit($form_id, $form_values) {
if ($form_values['op'] == t('Update')) {
variable_set('faq_title', $form_values['faq_title']);
variable_set('faq_description', $form_values['faq_description']);
variable_set('faq_description_format', $form_values['format']);
drupal_set_message(t('Configuration has been updated.'));
}
}
function faq_questions_settings_form() {
drupal_add_js(drupal_get_path('module', 'faq') . '/faq.js', 'module');
$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['faq_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['faq_questions_misc'] = array(
'#type' => 'fieldset',
'#title' => t('Miscellaneous layout settings'),
'#collapsible' => TRUE,
);
$form['faq_questions_misc']['faq_question_listing'] = array(
'#type' => 'select',
'#options' => array(
'ol' => 'Ordered list',
'ul' => 'Unordered list',
),
'#title' => t('Questions listing style'),
'#description' => t("This allows to select how the questions listing is presented. It only applies to the layouts: 'Clicking on question takes user to answer further down the page' and 'Clicking on question opens the answer in a new page'. An ordered listing would number the questions, whereas an unordered list will have a bullet to the left of each question."),
'#default_value' => variable_get('faq_question_listing', 'ul'),
);
$form['faq_questions_misc']['faq_qa_mark'] = array(
'#type' => 'checkbox',
'#title' => t('Label questions and answers'),
'#description' => t('This option is only valid for the "Questions Inline" layout. It labels all questions on the faq page with the "question label" setting and all answers with the "answer label" setting. For example these could be set to "Q:" and "A:".'),
'#default_value' => variable_get('faq_qa_mark', FALSE),
);
$form['faq_questions_misc']['faq_question_label'] = array(
'#type' => 'textfield',
'#title' => t('Question Label'),
'#description' => t('The label to pre-pend to the question text in the "Questions Inline" layout if labelling is enabled.'),
'#default_value' => variable_get('faq_question_label', 'Q:'),
);
$form['faq_questions_misc']['faq_answer_label'] = array(
'#type' => 'textfield',
'#title' => t('Answer Label'),
'#description' => t('The label to pre-pend to the answer text in the "Questions Inline" layout if labelling is enabled.'),
'#default_value' => variable_get('faq_answer_label', 'A:'),
);
$form['faq_questions_misc']['faq_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['faq_questions_misc']['faq_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', '>> more'),
);
$form['faq_questions_misc']['faq_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', 'Back to Top'),
);
return system_settings_form($form);
}
function faq_categories_settings_form() {
if (!module_exists("taxonomy")) {
drupal_set_message(t('Categorization of questions will not work without the "taxonomy" module being enabled.'), 'error');
}
drupal_add_js(drupal_get_path('module', 'faq') . '/faq.js', 'module');
$form['faq_display'] = array(
'#type' => 'hidden',
'#default_value' => variable_get('faq_display', 'questions_top'),
);
$form['faq_use_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['faq_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['faq_category_misc'] = array(
'#type' => 'fieldset',
'#title' => t('Miscellaneous layout settings'),
'#collapsible' => TRUE,
);
$form['faq_category_misc']['faq_category_listing'] = array(
'#type' => 'select',
'#options' => array(
'ol' => 'Ordered list',
'ul' => 'Unordered list',
),
'#title' => t('Categories listing style'),
'#description' => t("This allows to select how the categories listing is presented. It only applies to the 'Clicking on category opens the questions/answers in a new page' layout. An ordered listing would number the categories, whereas an unordered list will have a bullet to the left of each category."),
'#default_value' => variable_get('faq_category_listing', 'ul'),
);
$form['faq_category_misc']['faq_count'] = array(
'#type' => 'checkbox',
'#title' => t('Show FAQ count'),
'#description' => t('This displays the number of questions in a category after the category name.'),
'#default_value' => variable_get('faq_count', FALSE),
);
$form['faq_category_misc']['faq_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['faq_category_misc']['faq_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['faq_category_misc']['faq_hide_sub_categories'] = array(
'#type' => 'checkbox',
'#title' => t("Only show sub-categories when parent category is selected"),
'#description' => t("This allows the user more control over how and when sub-categories are displayed. It does not affect the 'Categories inline' display."),
'#default_value' => variable_get('faq_hide_sub_categories', FALSE),
);
$form['faq_category_misc']['faq_show_cat_sub_cats'] = array(
'#type' => 'checkbox',
'#title' => t("Show sub-categories on FAQ category pages"),
'#description' => t("Sub-categories with 'faq' nodes will be displayed on the per category FAQ page. This will also happen if 'Only show sub-categories when parent category is selected' is set."),
'#default_value' => variable_get('faq_show_cat_sub_cats', FALSE),
);
return system_settings_form($form);
}
function faq_weight_settings_form($form_values = NULL) {
drupal_add_js(drupal_get_path('module', 'faq') . '/faq.js', 'module');
drupal_add_css(drupal_get_path('module', 'faq') . '/faq.css');
$use_categories = variable_get('faq_use_categories', FALSE);
if (!$use_categories) {
$step = "order";
}
elseif (!isset($form_values)) {
$step = "categories";
}
else {
$step = "order";
}
$form['step'] = array(
'#type' => 'hidden',
'#value' => $step,
);
$form['#multistep'] = TRUE;
$form['#redirect'] = FALSE;
if ($step == "categories") {
$vocabularies = taxonomy_get_vocabularies("faq");
$options = array();
foreach ($vocabularies as $vid => $vobj) {
$tree = taxonomy_get_tree($vid);
foreach ($tree as $term) {
$options[$term->tid] = $term->name;
$form['choose_cat']['faq_category'] = array(
'#type' => 'select',
'#title' => t("Choose a category"),
'#description' => t("Choose a category that you wish to order the questions for."),
'#options' => $options,
'#multiple' => FALSE,
);
$form['choose_cat']['search'] = array(
'#type' => 'submit',
'#value' => t('Search'),
);
}
}
}
else {
$options = array();
$category = $form_values['faq_category'];
if (empty($category)) {
$category = 0;
$result = db_query(db_rewrite_sql("SELECT n.nid, n.title, if((w.weight IS NULL), 0, w.weight) as weight FROM {node} n LEFT JOIN {faq_weights} w ON n.nid = w.nid AND w.tid = %d WHERE n.type='faq' AND n.status = 1 ORDER BY weight ASC, n.sticky DESC, n.created DESC", "n", "nid"), $category);
$date_result = db_query(db_rewrite_sql("SELECT n.nid, n.title, if((w.weight IS NULL), 0, w.weight) as weight FROM {node} n LEFT JOIN {faq_weights} w ON n.nid = w.nid AND w.tid = %d WHERE n.type='faq' AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC", "n", "nid"), $category);
}
else {
$result = db_query(db_rewrite_sql("SELECT n.nid, n.title, if((w.weight IS NULL), 0, w.weight) as weight FROM {node} n LEFT JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {term_node} tn ON n.nid = tn.nid LEFT JOIN {faq_weights} w ON n.nid = w.nid AND w.tid = %d WHERE n.type='faq' AND n.status = 1 AND tn.tid = %d ORDER BY weight ASC, n.sticky DESC, n.created DESC", "n", "nid"), $category, $category);
$date_result = db_query(db_rewrite_sql("SELECT n.nid, n.title, if((w.weight IS NULL), 0, w.weight) as weight FROM {node} n LEFT JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.vid INNER JOIN {term_node} tn ON n.nid = tn.nid LEFT JOIN {faq_weights} w ON n.nid = w.nid AND w.tid = %d WHERE n.type='faq' AND n.status = 1 AND tn.tid = %d ORDER BY n.sticky DESC, n.created DESC", "n", "nid"), $category, $category);
}
while ($node = db_fetch_object($result)) {
$options[$node->nid] = $node->title;
$order .= "{$node->nid},";
}
$order = rtrim($order, ",");
while ($node = db_fetch_object($date_result)) {
$date_options[$node->nid] = $node->title;
$date_order .= "{$node->nid},";
}
$date_order = rtrim($date_order, ",");
$form['weight']['faq_node_order'] = array(
'#type' => 'hidden',
'#default_value' => $order,
);
$form['weight']['faq_node_date_order'] = array(
'#type' => 'hidden',
'#default_value' => $date_order,
);
$form['weight']['faq_category'] = array(
'#type' => 'hidden',
'#value' => $category,
);
$asc = '<a href="#" onclick="faq_order_by_date(\'ASC\');">ascending</a>';
$desc = '<a href="#" onclick="faq_order_by_date(\'DESC\');">descending</a>';
$form['weight']['order_no_cats'] = array(
'#type' => 'select',
'#title' => t("Question Order"),
'#description' => t("This determines the order of the questions and answers on the FAQ page. Just select one or more questions and use the arrows to change their position in the list. You can also order the list by the question creation date !desc or !asc.", array(
'!desc' => $desc,
'!asc' => $asc,
)),
'#options' => $options,
'#multiple' => TRUE,
'#size' => min(20, count($options)),
);
$form['weight']['move_up'] = array(
'#type' => 'markup',
'#value' => '<input type="button" onclick="faq_move_selected_item_up();"
value="↑" class="faq_arrow"/> ',
);
$form['weight']['move_down'] = array(
'#type' => 'markup',
'#value' => '<input type="button" onclick="faq_move_selected_item_down();"
value="↓" class="faq_arrow"/><br />',
);
$form['update']['attach'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#weight' => 3,
'#attributes' => array(
'onclick' => 'faq_update_order();',
),
);
$form['#redirect'] = "admin/settings/faq/weight";
}
return $form;
}
function faq_weight_settings_form_submit($form_id, $form_values) {
if ($form_values['op'] == t('Update')) {
$order = preg_split("/,/", $form_values['faq_node_order']);
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
foreach ($order as $index => $nid) {
$result = db_query("REPLACE INTO {faq_weights} (tid, nid, weight) VALUES(%d, %d, %d)", $form_values['faq_category'], $nid, $index);
}
break;
case 'pgsql':
foreach ($order as $index => $nid) {
$result = db_query("DELETE FROM {faq_weights} WHERE tid = %d AND nid = %d", $form_values['faq_category'], $nid);
$result = db_query("INSERT INTO {faq_weights} (tid, nid, weight) VALUES(%d, %d, %d)", $form_values['faq_category'], $nid, $index);
}
break;
}
drupal_set_message(t('Configuration has been updated.'));
}
else {
}
}
function faq_page($tid = 0) {
$default_values = array(
t('Frequently Asked Questions'),
t('Back to Top'),
t('>> more'),
t('Q:'),
t('A:'),
);
drupal_add_css(drupal_get_path('module', 'faq') . '/faq.css');
drupal_set_title(t(variable_get('faq_title', 'Frequently Asked Questions')));
if (!module_exists("taxonomy")) {
$tid = 0;
}
$breadcrumb = array();
if (!empty($tid)) {
$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', t('Frequently Asked Questions')),
);
$breadcrumb = array_reverse($breadcrumb);
menu_set_location($breadcrumb);
}
$faq_display = variable_get('faq_display', 'questions_top');
$display_vars['faq_qa_mark'] = variable_get('faq_qa_mark', FALSE);
$display_vars['faq_question_label'] = variable_get('faq_question_label', "Q:");
$display_vars['faq_answer_label'] = variable_get('faq_answer_label', "A:");
$display_vars['back_to_top'] = variable_get('faq_back_to_top', 'Back to Top');
$display_vars['use_teaser'] = variable_get('faq_use_teaser', FALSE);
$display_vars['more_link'] = variable_get('faq_more_link', '>> more');
$display_vars['faq_count'] = variable_get('faq_count', FALSE);
$display_vars['hide_sub_categories'] = variable_get('faq_hide_sub_categories', FALSE);
$display_vars['show_cat_sub_cats'] = variable_get('faq_show_cat_sub_cats', FALSE);
$use_categories = variable_get('faq_use_categories', FALSE);
if (!module_exists("taxonomy")) {
$use_categories = FALSE;
}
if (!$use_categories) {
$result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.body, r.teaser, r.format, if((w.weight IS NULL), 0, w.weight) as weight FROM {node} n LEFT JOIN {node_revisions} r ON n.nid = r.nid AND r.vid = n.vid 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"));
switch ($faq_display) {
case 'questions_top':
$output = theme('questions_top', $result, $display_vars);
break;
case 'hide_answer':
$output = theme('hide_answer', $result, $display_vars);
break;
case 'questions_inline':
$output = theme('questions_inline', $result, $display_vars);
break;
case 'new_page':
$output = theme('new_page', $result);
break;
}
}
else {
$category_display = variable_get('faq_category_display', 'categories_inline');
$hide_sub_categories = variable_get('faq_hide_sub_categories', FALSE);
$output .= "<br />";
if ($tid != 0) {
$term = taxonomy_get_term($tid);
$title = t(variable_get('faq_title', 'Frequently Asked Questions'));
drupal_set_title($title . ($title ? ' - ' : '') . check_plain($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;
}
$list_style = variable_get('faq_category_listing', 'ul');
$vocabularies = taxonomy_get_vocabularies("faq");
$items = array();
$vocab_items = array();
foreach ($vocabularies as $vid => $vobj) {
if ($category_display == "new_page") {
$vocab_items = _get_indented_faq_terms($vid, 0, $display_vars);
$items = array_merge($items, $vocab_items);
}
else {
if ($hide_sub_categories && $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;
}
}
}
}
if ($category_display == "new_page") {
$output = theme('item_list', $items, NULL, $list_style);
}
}
$desc = '';
$faq_description = t(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;
}
function _display_faq_by_category($faq_display, $category_display, $term, $display_header, &$output, &$output_answers) {
$result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.body, r.teaser, r.format, if((w.weight IS NULL), 0, w.weight) as weight FROM {node} n LEFT JOIN {node_revisions} r ON n.nid = r.nid AND r.vid = n.vid INNER JOIN {term_node} tn ON n.nid = tn.nid LEFT JOIN {faq_weights} w ON w.tid = tn.tid AND n.nid = w.nid WHERE n.type='faq' AND n.status = 1 AND tn.tid = '%d' ORDER BY weight, n.sticky DESC, n.created DESC", "n", "nid"), $term->tid);
$display_vars['display_header'] = $display_header;
$display_vars['faq_display'] = $faq_display;
$display_vars['category_display'] = $category_display;
$display_vars['faq_qa_mark'] = variable_get('faq_qa_mark', FALSE);
$display_vars['faq_question_label'] = variable_get('faq_question_label', "Q:");
$display_vars['faq_answer_label'] = variable_get('faq_answer_label', "A:");
$display_vars['use_teaser'] = variable_get('faq_use_teaser', FALSE);
$display_vars['more_link'] = variable_get('faq_more_link', '>> more');
$display_vars['back_to_top'] = variable_get('faq_back_to_top', 'Back to Top');
$display_vars['faq_count'] = variable_get('faq_count', FALSE);
$display_vars['group_questions_top'] = variable_get('faq_group_questions_top', FALSE);
$display_vars['hide_sub_categories'] = variable_get('faq_hide_sub_categories', FALSE);
$display_vars['show_cat_sub_cats'] = variable_get('faq_show_cat_sub_cats', FALSE);
$depth = 0;
while ($depth < $term->depth) {
$display_vars['display_header'] = 1;
$indent = '<div class="faq_category_indent">';
$output .= $indent;
$depth++;
}
$faq_class = "faq_qa";
if ($category_display == "hide_qa") {
$faq_class = "faq_qa_hide";
}
switch ($faq_display) {
case 'questions_top':
$data = theme('category_questions_top', $result, $display_vars, $term, $faq_class);
$output .= $data["output"];
$output_answers .= $data["output_answers"];
break;
case 'hide_answer':
$output .= theme('category_hide_answer', $result, $display_vars, $term, $faq_class);
break;
case 'questions_inline':
$output .= theme('category_questions_inline', $result, $display_vars, $term, $faq_class);
break;
case 'new_page':
$output .= theme('category_new_page', $result, $display_vars, $term, $faq_class);
break;
}
while ($depth > 0) {
$output .= '</div>';
$depth--;
}
}
function theme_questions_top($result, $display_vars) {
$back_to_top = '';
if (!empty($display_vars['back_to_top'])) {
$back_to_top = '<p class="faq_top_link">';
$back_to_top .= l(t($display_vars['back_to_top']), 'faq', array(), NULL, '') . '</p>';
}
$questions = array();
while ($node = db_fetch_object($result)) {
$node_obj = node_load($node->nid);
if (node_access("view", $node_obj)) {
$anchor = "n" . $node->nid;
$questions[] = l($node->title, 'faq', NULL, NULL, $anchor);
$answers .= '<div class="faq_question">' . l($node->title, "node/{$node->nid}", array(
"name" => "{$anchor}",
)) . "</div>\n";
if ($display_vars['use_teaser']) {
$more_link = '';
if (!empty($display_vars['more_link']) && strlen($node->teaser) < strlen($node->body)) {
$more_link = '<p class="faq_more_link">';
$more_link .= l(t($display_vars['more_link']), "node/{$node->nid}") . '</p>';
}
$answers .= '<div class="faq_answer">';
$answers .= check_markup($node->teaser, $node->format, FALSE);
$answers .= $more_link . $back_to_top . "</div>\n";
}
else {
$answers .= '<div class="faq_answer">';
$answers .= check_markup($node->body, $node->format, FALSE);
$answers .= $back_to_top . "</div>\n";
}
}
}
$list_style = variable_get('faq_question_listing', 'ul');
$output = theme('item_list', $questions, NULL, $list_style, array(
"class" => "faq_ul_questions_top",
));
$output .= "<div>\n" . $answers . "</div>\n";
return $output;
}
function theme_category_questions_top($result, $display_vars, $term, $class) {
$output = '';
$output_answers = '';
$this_page = 'faq';
$get_sub_terms = 0;
if (arg(0) == 'faq' && is_numeric(arg(1))) {
$this_page .= "/" . arg(1);
$get_sub_terms = arg(1);
}
$back_to_top = '';
if (!empty($display_vars['back_to_top'])) {
$back_to_top = '<p class="faq_top_link">';
$back_to_top .= l(t($display_vars['back_to_top']), $this_page, array(), NULL, '') . '</p>';
}
if ($display_vars['faq_count']) {
$count = db_num_rows($result);
if ($display_vars['hide_sub_categories']) {
$count = taxonomy_term_count_nodes($term->tid, 'faq');
}
}
$hdr = "h5";
if ($term->depth > 0) {
$hdr = "h6";
}
if ($display_vars['category_display'] == 'hide_qa') {
$header = "<{$hdr} class=\"faq_header\">";
$header .= l($term->name, "faq/{$term->tid}");
if ($display_vars['faq_count']) {
$header .= " (%d)";
}
$header .= "</{$hdr}>\n";
$ans_hdr = "<{$hdr} class=\"faq_header\">";
$ans_hdr .= check_plain($term->name) . "</{$hdr}>\n";
}
else {
$header = "<{$hdr} class=\"faq_header\">";
$header .= check_plain($term->name);
if ($display_vars['faq_count']) {
$header .= " (%d)";
}
$header .= "</{$hdr}>\n";
$ans_hdr = "<{$hdr} class=\"faq_header\">";
$ans_hdr .= check_plain($term->name) . "</{$hdr}>\n";
}
$answer_category_name = variable_get('faq_answer_category_name', FALSE);
$desc = '';
if (!empty($term->description)) {
$desc = '<div class="faq_qa_description"><p>';
$desc .= $term->description . "</p></div>\n";
}
$sub_cats = '';
if (($display_vars['show_cat_sub_cats'] || $display_vars['hide_sub_categories']) && $display_vars['category_display'] == 'new_page') {
$list = taxonomy_get_children($term->tid);
$scats = array();
foreach ($list as $tid => $sub_term) {
$sub_count = taxonomy_term_count_nodes($sub_term->tid, 'faq');
if ($sub_count) {
$sub_cat_desc = '';
if (!empty($sub_term->description)) {
$sub_cat_desc = '<div class="faq_qa_description"><p>';
$sub_cat_desc .= $sub_term->description . "</p></div>";
}
if ($display_vars['faq_count']) {
$scats[] = l($sub_term->name, "faq/{$sub_term->tid}") . " ({$sub_count}) {$sub_cat_desc}";
}
else {
$scats[] = l($sub_term->name, "faq/{$sub_term->tid}") . $sub_cat_desc;
}
}
}
$list_style = variable_get('faq_category_listing', 'ul');
$sub_cats .= theme('item_list', $scats, NULL, $list_style, array(
"class" => "faq_category_list",
));
}
$output .= '<div class="faq_category_group">' . "\n";
if ($display_vars['display_header'] == 1) {
$output .= '<div class="faq_qa_header">' . $header . $desc . "</div>\n";
}
else {
$output .= '<div class="faq_qa_header">' . $desc . "</div>\n";
}
$output .= $sub_cats;
$sub_cats = '';
if ($get_sub_terms == $term->tid) {
$output .= '<div class="faq_qa">' . "\n";
}
else {
$output .= '<div class="' . $class . '">' . "\n";
}
if ($get_sub_terms && $display_vars['category_display'] == 'categories_inline' || ($display_vars['show_cat_sub_cats'] || $display_vars['hide_sub_categories']) && $display_vars['category_display'] == 'hide_qa') {
$list = taxonomy_get_children($term->tid);
foreach ($list as $tid => $sub_term) {
if (taxonomy_term_count_nodes($sub_term->tid, 'faq')) {
$sub_result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.body, r.teaser, r.format, if((w.weight IS NULL), 0, w.weight) as weight FROM {node} n LEFT JOIN {node_revisions} r ON n.nid = r.nid AND r.vid = n.vid INNER JOIN {term_node} tn ON n.nid = tn.nid LEFT JOIN {faq_weights} w ON w.tid = tn.tid AND n.nid = w.nid WHERE n.type='faq' AND n.status = 1 AND tn.tid = '%d' ORDER BY weight, n.sticky DESC, n.created DESC", "n", "nid"), $sub_term->tid);
$display_vars['display_header'] = 1;
$sub_cats .= '<div class="faq_category_indent">';
$sub_cat_data = theme('category_questions_top', $sub_result, $display_vars, $sub_term, $class);
$sub_cats .= $sub_cata_data["output"];
$sub_cat_output_answers .= $sub_cata_data["output_answers"];
$sub_cats .= '</div>';
}
}
$output .= $sub_cats;
}
if (db_num_rows($result)) {
$questions = array();
while ($node = db_fetch_object($result)) {
$node = node_load($node->nid);
if (node_access("view", $node)) {
$anchor = $term->tid . "n" . $node->nid;
$questions[] = l($node->title, $this_page, NULL, NULL, $anchor);
$answers .= '<div class="faq_question">' . l($node->title, "node/{$node->nid}", array(
"name" => "{$anchor}",
)) . "</div>\n";
if ($display_vars['use_teaser']) {
$more_link = '';
if (!empty($display_vars['more_link']) && strlen($node->teaser) < strlen($node->body)) {
$more_link = '<p class="faq_more_link">';
$more_link .= l(t($display_vars['more_link']), "node/{$node->nid}") . '</p>';
}
$answers .= '<div class="faq_answer">';
$answers .= check_markup($node->teaser, $node->format, FALSE);
$answers .= $more_link . $back_to_top . "</div>\n";
}
else {
$answers .= '<div class="faq_answer">';
$answers .= check_markup($node->body, $node->format, FALSE);
$answers .= $back_to_top . "</div>\n";
}
}
else {
$count--;
}
}
$list_style = variable_get('faq_question_listing', 'ul');
$output .= theme('item_list', $questions, NULL, $list_style, array(
"class" => "faq_ul_questions_top",
));
}
if ($display_vars['group_questions_top'] || $display_vars['category_display'] == "hide_qa") {
if ($answer_category_name) {
if (db_num_rows($result)) {
$output .= $ans_hdr;
$output .= "<div>\n" . $answers . "\n</div>\n";
}
$output .= "</div>\n</div>\n";
}
else {
if (db_num_rows($result)) {
$output .= "<div>\n" . $answers . "\n</div>\n";
}
$output .= "</div>\n</div>\n";
}
}
else {
$output .= "</div>\n</div>\n";
$ans_depth = 0;
$indent = '<div class="faq_category_indent">' . "\n";
if ($answer_category_name) {
while ($ans_depth < $term->depth) {
$output_answers .= $indent;
$ans_depth++;
}
}
$output_answers .= '<div class="faq_category_group">' . "\n";
if ($answer_category_name) {
if (taxonomy_term_count_nodes($term->tid, 'faq')) {
if (!empty($sub_cat_output_answers)) {
$sub_cat_output_answers .= $answers;
$answers = $sub_cat_output_answers;
}
$output_answers .= $ans_hdr . "<div>\n" . $answers . "\n</div>\n";
}
}
else {
if (!empty($sub_cat_output_answers)) {
$output_answers .= $sub_cat_output_answers;
}
$output_answers .= "<div>\n" . $answers . "\n</div>\n";
}
$output_answers .= "</div>\n";
if ($answer_category_name) {
while ($ans_depth > 0) {
$output_answers .= "</div>\n";
$ans_depth--;
}
}
}
if ($display_vars['faq_count']) {
$output = sprintf($output, $count);
}
$data["output"] = $output;
$data["output_answers"] = $output_answers;
return $data;
}
function theme_hide_answer($result, $display_vars) {
drupal_add_js(drupal_get_path('module', 'faq') . '/faq.js', 'module');
$output = "<div>\n";
while ($node = db_fetch_object($result)) {
$node_obj = node_load($node->nid);
if (node_access("view", $node_obj)) {
$output .= '<div class="faq_question faq_dt_hide_answer">';
$output .= l($node->title, "node/{$node->nid}") . "</div>\n";
if ($display_vars['use_teaser']) {
$more_link = '';
if (!empty($display_vars['more_link']) && strlen($node->teaser) < strlen($node->body)) {
$more_link = '<p class="faq_more_link">';
$more_link .= l(t($display_vars['more_link']), "node/{$node->nid}") . '</p>';
}
$output .= '<div class="faq_answer faq_dd_hide_answer">';
$output .= check_markup($node->teaser, $node->format, FALSE);
$output .= $more_link . "</div>\n";
}
else {
$output .= '<div class="faq_answer faq_dd_hide_answer">';
$output .= check_markup($node->body, $node->format, FALSE) . "</div>\n";
}
}
}
$output .= "</div>\n";
return $output;
}
function theme_category_hide_answer($result, $display_vars, $term, $class) {
$get_sub_terms = 0;
if (arg(0) == 'faq' && is_numeric(arg(1))) {
$get_sub_terms = arg(1);
}
drupal_add_js(drupal_get_path('module', 'faq') . '/faq.js', 'module');
if ($display_vars['faq_count']) {
$count = db_num_rows($result);
if ($display_vars['hide_sub_categories']) {
$count = taxonomy_term_count_nodes($term->tid, 'faq');
}
}
$hdr = "h5";
if ($term->depth > 0) {
$hdr = "h6";
}
if ($display_vars['category_display'] == 'hide_qa') {
$header = "<{$hdr} class=\"faq_header\">";
$header .= l($term->name, "faq/{$term->tid}");
if ($display_vars['faq_count']) {
$header .= " (%d)";
}
$header .= "</{$hdr}>\n";
}
else {
$header = "<{$hdr} class=\"faq_header\">";
$header .= check_plain($term->name);
if ($display_vars['faq_count']) {
$header .= " (%d)";
}
$header .= "</{$hdr}>\n";
}
$desc = '';
if (!empty($term->description)) {
$desc = '<div class="faq_qa_description"><p>';
$desc .= $term->description . "</p></div>\n";
}
$sub_cats = '';
if (($display_vars['show_cat_sub_cats'] || $display_vars['hide_sub_categories']) && $display_vars['category_display'] == 'new_page') {
$list = taxonomy_get_children($term->tid);
$scats = array();
foreach ($list as $tid => $sub_term) {
$sub_count = taxonomy_term_count_nodes($sub_term->tid, 'faq');
if ($sub_count) {
$sub_cat_desc = '';
if (!empty($sub_term->description)) {
$sub_cat_desc = '<div class="faq_qa_description"><p>';
$sub_cat_desc .= $sub_term->description . "</p></div>";
}
if ($display_vars['faq_count']) {
$scats[] = l($sub_term->name, "faq/{$sub_term->tid}") . " ({$sub_count}) {$sub_cat_desc}";
}
else {
$scats[] = l($sub_term->name, "faq/{$sub_term->tid}") . $sub_cat_desc;
}
}
}
$list_style = variable_get('faq_category_listing', 'ul');
$sub_cats .= theme('item_list', $scats, NULL, $list_style, array(
"class" => "faq_category_list",
));
}
$output = '<div class="faq_category_group">' . "\n";
if ($display_vars['display_header'] == 1) {
$output .= '<div class="faq_qa_header">' . $header . $desc . "</div>\n";
}
else {
$output .= '<div class="faq_qa_header">' . $desc . "</div>\n";
}
$output .= $sub_cats;
$sub_cats = '';
if ($get_sub_terms == $term->tid) {
$output .= '<div class="faq_qa">' . "\n";
}
else {
$output .= '<div class="' . $class . '">' . "\n";
}
if ($get_sub_terms && $display_vars['category_display'] == 'categories_inline' || ($display_vars['show_cat_sub_cats'] || $display_vars['hide_sub_categories']) && $display_vars['category_display'] == 'hide_qa') {
$list = taxonomy_get_children($term->tid);
foreach ($list as $tid => $sub_term) {
if (taxonomy_term_count_nodes($sub_term->tid, 'faq')) {
$sub_result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.body, r.teaser, r.format, if((w.weight IS NULL), 0, w.weight) as weight FROM {node} n LEFT JOIN {node_revisions} r ON n.nid = r.nid AND r.vid = n.vid INNER JOIN {term_node} tn ON n.nid = tn.nid LEFT JOIN {faq_weights} w ON w.tid = tn.tid AND n.nid = w.nid WHERE n.type='faq' AND n.status = 1 AND tn.tid = '%d' ORDER BY weight, n.sticky DESC, n.created DESC", "n", "nid"), $sub_term->tid);
$display_vars['display_header'] = 1;
$sub_cats .= '<div class="faq_category_indent">';
$sub_cats .= theme('category_hide_answer', $sub_result, $display_vars, $sub_term, $class);
$sub_cats .= '</div>';
}
}
$output .= $sub_cats;
}
if (db_num_rows($result)) {
$output .= '<div class="faq_dl_hide_answer">' . "\n";
while ($node = db_fetch_object($result)) {
$node = node_load($node->nid);
if (node_access("view", $node)) {
$output .= '<div class="faq_question faq_dt_hide_answer">';
$output .= l($node->title, "node/{$node->nid}") . "</div>\n";
if ($display_vars['use_teaser']) {
$more_link = '';
if (!empty($display_vars['more_link']) && strlen($node->teaser) < strlen($node->body)) {
$more_link = '<p class="faq_more_link">';
$more_link .= l(t($display_vars['more_link']), "node/{$node->nid}") . '</p>';
}
$output .= '<div class="faq_answer faq_dd_hide_answer">';
$output .= check_markup($node->teaser, $node->format, FALSE);
$output .= $more_link . "</div>\n";
}
else {
$output .= '<div class="faq_answer faq_dd_hide_answer">';
$output .= check_markup($node->body, $node->format, FALSE) . "</div>\n";
}
}
else {
$count--;
}
}
$output .= "</div>\n";
}
$output .= "</div>\n</div>\n";
if ($display_vars['faq_count']) {
$output = sprintf($output, $count);
}
return $output;
}
function theme_questions_inline($result, $display_vars) {
$back_to_top = '';
if (!empty($display_vars['back_to_top'])) {
$back_to_top = '<p class="faq_top_link">';
$back_to_top .= l(t($display_vars['back_to_top']), 'faq', array(), NULL, '') . '</p>';
}
$que_label = '';
$ans_label = '';
if ($display_vars['faq_qa_mark']) {
$que_label = t($display_vars["faq_question_label"]) . ' ';
$ans_label = '<strong>' . t($display_vars["faq_answer_label"]) . '</strong> ';
}
$output = "<div>\n";
while ($node = db_fetch_object($result)) {
$node_obj = node_load($node->nid);
if (node_access("view", $node_obj)) {
$output .= '<div class="faq_question">';
$output .= l($que_label . $node->title, "node/{$node->nid}") . "</div>\n";
if ($display_vars['use_teaser']) {
$more_link = '';
if (!empty($display_vars['more_link']) && strlen($node->teaser) < strlen($node->body)) {
$more_link = '<p class="faq_more_link">';
$more_link .= l(t($display_vars['more_link']), "node/{$node->nid}") . '</p>';
}
$output .= '<div class="faq_answer">';
$output .= check_markup($ans_label . $node->teaser, $node->format, FALSE);
$output .= $more_link . $back_to_top . "</div>\n";
}
else {
$output .= '<div class="faq_answer">';
$output .= check_markup($ans_label . $node->body, $node->format, FALSE);
$output .= $back_to_top . "</div>\n";
}
}
}
$output .= "</div>\n";
return $output;
}
function theme_category_questions_inline($result, $display_vars, $term, $class) {
$this_page = 'faq';
$get_sub_terms = 0;
if (arg(0) == 'faq' && is_numeric(arg(1))) {
$this_page .= "/" . arg(1);
$get_sub_terms = arg(1);
}
$back_to_top = '';
if (!empty($display_vars['back_to_top'])) {
$back_to_top = '<p class="faq_top_link">';
$back_to_top .= l(t($display_vars['back_to_top']), $this_page, array(), NULL, '') . '</p>';
}
$que_label = '';
$ans_label = '';
if ($display_vars['faq_qa_mark']) {
$que_label = t($display_vars["faq_question_label"]) . ' ';
$ans_label = '<strong>' . t($display_vars["faq_answer_label"]) . '</strong> ';
}
if ($display_vars['faq_count']) {
$count = db_num_rows($result);
if ($display_vars['hide_sub_categories']) {
$count = taxonomy_term_count_nodes($term->tid, 'faq');
}
}
$hdr = "h5";
if ($term->depth > 0) {
$hdr = "h6";
}
if ($display_vars['category_display'] == 'hide_qa') {
$header = "<{$hdr} class=\"faq_header\">";
$header .= l($term->name, "faq/{$term->tid}");
if ($display_vars['faq_count']) {
$header .= " (%d)";
}
$header .= "</{$hdr}>\n";
}
else {
$header = "<{$hdr} class=\"faq_header\">";
$header .= check_plain($term->name);
if ($display_vars['faq_count']) {
$header .= " (%d)";
}
$header .= "</{$hdr}>\n";
}
$desc = '';
if (!empty($term->description)) {
$desc = '<div class="faq_qa_description"><p>';
$desc .= $term->description . "</p></div>\n";
}
$sub_cats = '';
if (($display_vars['show_cat_sub_cats'] || $display_vars['hide_sub_categories']) && $display_vars['category_display'] == 'new_page') {
$list = taxonomy_get_children($term->tid);
$scats = array();
foreach ($list as $tid => $sub_term) {
$sub_count = taxonomy_term_count_nodes($sub_term->tid, 'faq');
if ($sub_count) {
$sub_cat_desc = '';
if (!empty($sub_term->description)) {
$sub_cat_desc = '<div class="faq_qa_description"><p>';
$sub_cat_desc .= $sub_term->description . "</p></div>";
}
if ($display_vars['faq_count']) {
$scats[] = l($sub_term->name, "faq/{$sub_term->tid}") . " ({$sub_count}) {$sub_cat_desc}";
}
else {
$scats[] = l($sub_term->name, "faq/{$sub_term->tid}") . $sub_cat_desc;
}
}
}
$list_style = variable_get('faq_category_listing', 'ul');
$sub_cats .= theme('item_list', $scats, NULL, $list_style, array(
"class" => "faq_category_list",
));
}
$output = '<div class="faq_category_group">' . "\n";
if ($display_vars['display_header'] == 1) {
$output .= '<div class="faq_qa_header">' . $header . $desc . "</div>\n";
}
else {
$output .= '<div class="faq_qa_header">' . $desc . "</div>\n";
}
$output .= $sub_cats;
$sub_cats = '';
if ($get_sub_terms == $term->tid) {
$output .= '<div class="faq_qa">' . "\n";
}
else {
$output .= '<div class="' . $class . '">' . "\n";
}
if ($get_sub_terms && $display_vars['category_display'] == 'categories_inline' || ($display_vars['show_cat_sub_cats'] || $display_vars['hide_sub_categories']) && $display_vars['category_display'] == 'hide_qa') {
$list = taxonomy_get_children($term->tid);
foreach ($list as $tid => $sub_term) {
if (taxonomy_term_count_nodes($sub_term->tid, 'faq')) {
$sub_result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.body, r.teaser, r.format, if((w.weight IS NULL), 0, w.weight) as weight FROM {node} n LEFT JOIN {node_revisions} r ON n.nid = r.nid AND r.vid = n.vid INNER JOIN {term_node} tn ON n.nid = tn.nid LEFT JOIN {faq_weights} w ON w.tid = tn.tid AND n.nid = w.nid WHERE n.type='faq' AND n.status = 1 AND tn.tid = '%d' ORDER BY weight, n.sticky DESC, n.created DESC", "n", "nid"), $sub_term->tid);
$display_vars['display_header'] = 1;
$sub_cats .= '<div class="faq_category_indent">';
$sub_cats .= theme('category_questions_inline', $sub_result, $display_vars, $sub_term, $class);
$sub_cats .= '</div>';
}
}
$output .= $sub_cats;
}
if (db_num_rows($result)) {
$output .= "<div>\n";
while ($node = db_fetch_object($result)) {
$node = node_load($node->nid);
if (node_access("view", $node)) {
$output .= '<div class="faq_question">';
$output .= l($que_label . $node->title, "node/{$node->nid}") . "</div>\n";
if ($display_vars['use_teaser']) {
$more_link = '';
if (!empty($display_vars['more_link']) && strlen($node->teaser) < strlen($node->body)) {
$more_link = '<p class="faq_more_link">';
$more_link .= l(t($display_vars['more_link']), "node/{$node->nid}") . '</p>';
}
$output .= '<div class="faq_answer">';
$output .= check_markup($ans_label . $node->teaser, $node->format, FALSE);
$output .= $more_link . $back_to_top . "</div>\n";
}
else {
$output .= '<div class="faq_answer">';
$output .= check_markup($ans_label . $node->body, $node->format, FALSE);
$output .= $back_to_top . "</div>\n";
}
}
else {
$count--;
}
}
$output .= "</div>\n";
}
$output .= "</div>\n</div>\n";
if ($display_vars['faq_count']) {
$output = sprintf($output, $count);
}
return $output;
}
function theme_new_page($result) {
$items = array();
while ($node = db_fetch_object($result)) {
$node_obj = node_load($node->nid);
if (node_access("view", $node_obj)) {
$items[] = l($node->title, "node/{$node->nid}");
}
}
$list_style = variable_get('faq_question_listing', 'ul');
$output .= theme('item_list', $items, NULL, $list_style, array(
"class" => "faq_question_listing",
));
return $output;
}
function theme_category_new_page($result, $display_vars, $term, $class) {
$get_sub_terms = 0;
if (arg(0) == 'faq' && is_numeric(arg(1))) {
$get_sub_terms = arg(1);
}
if ($display_vars['faq_count']) {
$count = db_num_rows($result);
if ($display_vars['hide_sub_categories']) {
$count = taxonomy_term_count_nodes($term->tid, 'faq');
}
}
$hdr = "h5";
if ($term->depth > 0) {
$hdr = "h6";
}
if ($display_vars['category_display'] == 'hide_qa') {
$header = "<{$hdr} class=\"faq_header\">";
$header .= l($term->name, "faq/{$term->tid}");
if ($display_vars['faq_count']) {
$header .= " (%d)";
}
$header .= "</{$hdr}>\n";
}
else {
$header = "<{$hdr} class=\"faq_header\">";
$header .= check_plain($term->name);
if ($display_vars['faq_count']) {
$header .= " (%d)";
}
$header .= "</{$hdr}>\n";
}
$desc = '';
if (!empty($term->description)) {
$desc = '<div class="faq_qa_description"><p>';
$desc .= $term->description . "</p></div>\n";
}
$sub_cats = '';
if (($display_vars['show_cat_sub_cats'] || $display_vars['hide_sub_categories']) && $display_vars['category_display'] == 'new_page') {
$list = taxonomy_get_children($term->tid);
$scats = array();
foreach ($list as $tid => $sub_term) {
$sub_count = taxonomy_term_count_nodes($sub_term->tid, 'faq');
if ($sub_count) {
$sub_cat_desc = '';
if (!empty($sub_term->description)) {
$sub_cat_desc = '<div class="faq_qa_description"><p>';
$sub_cat_desc .= $sub_term->description . "</p></div>";
}
if ($display_vars['faq_count']) {
$scats[] = l($sub_term->name, "faq/{$sub_term->tid}") . " ({$sub_count}) {$sub_cat_desc}";
}
else {
$scats[] = l($sub_term->name, "faq/{$sub_term->tid}") . $sub_cat_desc;
}
}
}
$list_style = variable_get('faq_category_listing', 'ul');
$sub_cats .= theme('item_list', $scats, NULL, $list_style, array(
"class" => "faq_category_list",
));
}
$output = '<div class="faq_category_group">' . "\n";
if ($display_vars['display_header'] == 1) {
$output .= '<div class="faq_qa_header">' . $header . $desc . "</div>\n";
}
else {
$output .= '<div class="faq_qa_header">' . $desc . "</div>\n";
}
$output .= $sub_cats;
$sub_cats = '';
if ($get_sub_terms == $term->tid) {
$output .= '<div class="faq_qa">' . "\n";
}
else {
$output .= '<div class="' . $class . '">' . "\n";
}
if ($get_sub_terms && $display_vars['category_display'] == 'categories_inline' || ($display_vars['show_cat_sub_cats'] || $display_vars['hide_sub_categories']) && $display_vars['category_display'] == 'hide_qa') {
$list = taxonomy_get_children($term->tid);
foreach ($list as $tid => $sub_term) {
if (taxonomy_term_count_nodes($sub_term->tid, 'faq')) {
$sub_result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.body, r.teaser, r.format, if((w.weight IS NULL), 0, w.weight) as weight FROM {node} n LEFT JOIN {node_revisions} r ON n.nid = r.nid AND r.vid = n.vid INNER JOIN {term_node} tn ON n.nid = tn.nid LEFT JOIN {faq_weights} w ON w.tid = tn.tid AND n.nid = w.nid WHERE n.type='faq' AND n.status = 1 AND tn.tid = '%d' ORDER BY weight, n.sticky DESC, n.created DESC", "n", "nid"), $sub_term->tid);
$display_vars['display_header'] = 1;
$sub_cats .= '<div class="faq_category_indent">';
$sub_cats .= theme('category_new_page', $sub_result, $display_vars, $sub_term, $class);
$sub_cats .= '</div>';
}
}
$output .= $sub_cats;
}
if (db_num_rows($result)) {
$items = array();
while ($node = db_fetch_object($result)) {
$node = node_load($node->nid);
if (node_access("view", $node)) {
$items[] = l($node->title, "node/{$node->nid}");
}
else {
$count--;
}
}
$list_style = variable_get('faq_question_listing', 'ul');
$output .= theme('item_list', $items, NULL, $list_style, array(
"class" => "faq_ul_new_page",
));
}
$output .= "</div>\n</div>\n";
if ($display_vars['faq_count']) {
$output = sprintf($output, $count);
}
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');
$blocks[2]['info'] = t('Random FAQs');
return $blocks;
case 'view':
switch ($delta) {
case 0:
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;
}
}
if (sizeof($terms) > 0) {
$block['subject'] = t('FAQ Categories');
$items = array();
foreach ($terms as $name => $tid) {
$items[] = l($name, 'faq/' . $tid);
}
$list_style = variable_get('faq_category_listing', 'ul');
$block['content'] = theme('item_list', $items, NULL, $list_style);
}
}
break;
case 1:
$block['subject'] = t('Recent FAQs');
$block['content'] = theme('faq_highlights', variable_get('faq_block_recent_faq_count', 5));
break;
case 2:
$block['subject'] = t('Random FAQs');
$block['content'] = theme('faq_random_highlights', variable_get('faq_block_random_faq_count', 5));
break;
}
return $block;
case 'configure':
switch ($delta) {
case 0:
break;
case 1:
$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),
);
break;
case 2:
$form['faq_block_random_faq_count'] = array(
'#type' => 'textfield',
'#title' => t('Number of FAQs to show'),
'#description' => t("This controls the number of FAQs that appear in the 'Random FAQs' block"),
'#default_value' => variable_get('faq_block_random_faq_count', 5),
);
break;
}
return $form;
case 'save':
switch ($delta) {
case 0:
break;
case 1:
variable_set('faq_block_recent_faq_count', $edit['faq_block_recent_faq_count']);
break;
case 2:
variable_set('faq_block_random_faq_count', $edit['faq_block_random_faq_count']);
break;
}
return;
}
}
function theme_faq_highlights($num = 5) {
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title 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", "n", "nid"), 0, $num);
$items = array();
while ($node = db_fetch_object($result)) {
$node = node_load(array(
'nid' => $node->nid,
));
$node = node_prepare($node);
if (node_access("view", $node)) {
$items[] = l($node->title, 'node/' . $node->nid);
}
}
$list_style = variable_get('faq_question_listing', 'ul');
$output = theme('item_list', $items, NULL, $list_style);
$output .= l(t('All FAQs'), 'faq');
return $output;
}
function theme_faq_random_highlights($num = 5) {
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title 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 RAND()", "n", "nid"), 0, $num);
$items = array();
while ($node = db_fetch_object($result)) {
$node = node_load(array(
'nid' => $node->nid,
));
$node = node_prepare($node);
if (node_access("view", $node)) {
$items[] = l($node->title, 'node/' . $node->nid);
}
}
$list_style = variable_get('faq_question_listing', 'ul');
$output = theme('item_list', $items, NULL, $list_style);
$output .= l(t('All FAQs'), 'faq');
return $output;
}
function _get_indented_faq_terms($vid, $tid, $display_vars) {
$items = array();
$tree = taxonomy_get_tree($vid, $tid, -1, 1);
foreach ($tree as $term) {
$tree_count = taxonomy_term_count_nodes($term->tid, 'faq');
if ($tree_count) {
$desc = '';
if (!empty($term->description)) {
$desc = '<div class="faq_qa_description"><p>';
$desc .= $term->description . "</p></div>";
}
$result = db_query(db_rewrite_sql("SELECT COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid WHERE n.status = 1 AND n.type = 'faq' AND t.tid = '%d' ", "n", "nid"), $term->tid);
$term_count = db_fetch_object($result);
if ($term_count->c > 0) {
if ($display_vars["faq_count"]) {
$count = $term_count->c;
if ($display_vars['hide_sub_categories']) {
$count = $tree_count;
}
$cur_item = l($term->name, "faq/{$term->tid}") . " ({$count}) " . $desc;
}
else {
$cur_item = l($term->name, "faq/{$term->tid}") . $desc;
}
}
else {
$cur_item = check_plain($term->name) . $desc;
}
if (!$display_vars['hide_sub_categories']) {
$term_items = _get_indented_faq_terms($vid, $term->tid, $display_vars);
}
$items[] = array(
"data" => $cur_item,
"children" => $term_items,
);
}
}
return $items;
}
function faq_get_terms() {
$display_vars['faq_count'] = variable_get('faq_count', FALSE);
$display_vars['hide_sub_categories'] = variable_get('faq_hide_sub_categories', FALSE);
$items = array();
$vocabularies = taxonomy_get_vocabularies("faq");
foreach ($vocabularies as $vid => $vobj) {
$vocab_items = _get_indented_faq_terms($vid, 0, $display_vars);
$items = array_merge($items, $vocab_items);
}
return theme('item_list', $items);
}
function faq_get_faq_list() {
$use_categories = variable_get('faq_use_categories', FALSE);
if ($use_categories) {
return faq_get_terms();
}
$items = array();
$result = db_query(db_rewrite_sql("SELECT n.nid, n.title, if((w.weight IS NULL), 0, w.weight) as weight 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"));
while ($node = db_fetch_object($result)) {
$node_obj = node_load($node->nid);
if (node_access("view", $node_obj)) {
$items[] = l($node->title, "node/{$node->nid}");
}
}
return theme('item_list', $items);
}
function faq_site_map() {
$title = variable_get('faq_title', t('Frequently Asked Questions'));
$output = faq_get_faq_list();
return theme('box', $title, $output);
}