Index: faq.install =================================================================== RCS file: faq.install diff -N faq.install --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ faq.install 1 Jul 2006 00:24:43 -0000 @@ -0,0 +1,20 @@ + array('name' => t('faq'), 'base' => 'faq')); } /** @@ -40,10 +38,22 @@ $items = array(); if($may_cache){ + $items[] = array( + 'path' => 'faq', + 'title' => t('FAQs'), + 'callback' => 'theme_faq_list', + 'access' => user_access('access content'), + 'type' => MENU_SUGGESTED_ITEM + ); + $items[] = array( + 'path' => 'faq/show', + 'title' => t('FAQs'), + 'callback' => 'theme_faq_show', + 'access' => user_access('access content'), + 'type' => MENU_SUGGESTED_ITEM + ); } - $items[] = array('path' => 'faq', 'title' => t('FAQs'), 'callback' => 'theme_faq_list', 'access' => user_access('access content'), 'type' => MENU_NORMAL_ITEM); - $items[] = array('path' => 'faq/show', 'title' => t('FAQs'), 'callback' => 'theme_faq_show', 'access' => user_access('access content'), 'type' => MENU_CALLBACK); return $items; @@ -53,17 +63,34 @@ * Implementation of hook_form() */ function faq_form(&$node){ - $ouptut = ''; $values = array(); for($i = -10; $i <= 10; $i++){ $values[$i] = $i; } - $output .= form_select(t('Weight'), 'weight', isset($node->weight) ? $node->weight : '0', $values); - foreach(taxonomy_node_form('faq', $node) as $vocab){ - $output .= $vocab; - } - $output .= form_textarea(t('Answer'), 'body', $node->body, 60, 20, 'Enter the answer to the question given in the title.', NULL, TRUE); - return $output; + $form = array(); + $form['title'] = array( + '#type' => 'textfield', + '#title'=> t('Question'), + '#default_value' => $node->title, + '#weight'=>'-1', + ); + $form['body'] = array( + '#type' => 'textarea', + '#title'=> t('Answer'), + '#default_value' => $node->body, + '#rows'=>20, + '#cols'=>20, + '#description'=>'Enter the answer to the question given in the title.', + '#weight'=>'-1', + ); + $form['weight'] = array( + '#type' => 'select', + '#title' => t('Weight'), + '#default_value' => isset($node->weight) ? $node->weight : '0', + '#options' => $values, + '#weight'=>'0', + ); + return $form; } /** @@ -104,7 +131,7 @@ $block['subject'] = t('FAQ Categories'); $block['content'] = '' . "\n"; } @@ -182,13 +209,13 @@ function theme_faq_highlights($order = 'created', $num = 5){ $output = ''; - $sql = 'SELECT n.nid, n.title, n.teaser FROM {node} n WHERE n.type = "faq" AND n.status = 1 ORDER BY n.created DESC LIMIT ' . intval($num); - if($order == 'rating' && function_exists('voting_get_vote')){ - $sql = 'SELECT v.content_id nid, SUM(v.vote) rating FROM {votes} v, {node} n WHERE v.content_id = n.nid AND n.type = "faq" GROUP BY v.content_id ORDER BY rating DESC LIMIT ' . intval($num); + $result = db_query('SELECT v.content_id nid, SUM(v.vote) rating FROM {votes} v, {node} n WHERE v.content_id = n.nid AND n.type = "faq" GROUP BY v.content_id ORDER BY rating DESC LIMIT ' . intval($num)); + } + else { + $result = db_query('SELECT n.nid, n.title, r.body FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid, {term_node} t, {faq} f WHERE t.nid = n.nid AND f.fid = n.nid AND n.type="faq" AND n.status=1 ORDER BY f.weight, n.title'); } - $result = db_query($sql); $output .= '' . "\n"; - $output .= '


All FAQs

' . "\n"; + $output .= '


' . l(t('All FAQs'), 'faq') .'

' . "\n"; return $output; } @@ -215,17 +245,17 @@ $found = false; $result = db_query('SELECT n.nid, n.title FROM {node} n, {term_node} t, {faq} f WHERE t.nid = n.nid AND f.fid = n.nid AND n.type="faq" AND n.status=1 AND t.tid = %d ORDER BY f.weight, n.title', $term->tid); - $output = '

' . $term->name . '

' . "\n"; + $output = '

' . l($term->name, 'faq/show/' . $term->tid) . '

' . "\n"; $output .= '' . "\n"; @@ -242,8 +272,10 @@ function theme_faq_get_faqs_for_term($term){ $found = false; $output = ''; - $title = '

' . $term->name . ' FAQ

' . "\n"; - $result = db_query('SELECT n.nid, n.title, n.body FROM {node} n, {term_node} t, {faq} f WHERE t.nid = n.nid AND f.fid = n.nid AND n.type="faq" AND n.status=1 AND t.tid = %d ORDER BY f.weight, n.title', $term->tid); + if (!$term->tid) { + return t('No terms defined'); + } + $result = db_query('SELECT n.nid, n.title, r.body FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid, {term_node} t, {faq} f WHERE t.nid = n.nid AND f.fid = n.nid AND n.type="faq" AND n.status=1 AND t.tid = %d ORDER BY f.weight, n.title', $term->tid); $links = '' . "\n"; - $output = $title . $links . $output; + $output = $links . $output; if(!$found){ - $output = $title; + return '

' . $term->name . ' FAQ

' . "\n"; } return $output; } -function faq_help(){ +function faq_help($section){ switch ($section) { - case 'admin/modules#help': + case 'admin/modules#faq': return t('Allows you to create FAQ nodes that are presented in a standard FAQ layout (questions up top, anchor links below, etc.).'); - case 'node/add#help': + case 'node/add#faq': return t('Be sure to create some categories prior to adding any FAQs so that they can be browsed easily.'); } }