Index: faq.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/faq/faq.module,v
retrieving revision 1.1.4.52.2.24
diff -u -r1.1.4.52.2.24 faq.module
--- faq.module	21 Dec 2007 09:27:56 -0000	1.1.4.52.2.24
+++ faq.module	29 Dec 2007 19:46:14 -0000
@@ -797,24 +797,28 @@
 function faq_theme() {
   return array(
     'faq_questions_top' => array(
+      'template' => 'faq-questions-top',
       'arguments' => array('result' => NULL, 'display_vars' => NULL),
       ),
     'faq_category_questions_top' => array(
       'arguments' => array('result' => NULL, 'display_vars' => NULL, 'term' => NULL, 'class' => NULL),
       ),
     'faq_hide_answer' => array(
-      'arguments' => array('result' => NULL),
+      'template' => 'faq-hide-answer',
+      'arguments' => array('result' => NULL, 'display_vars' => NULL),
       ),
     'faq_category_hide_answer' => array(
       'arguments' => array('result' => NULL, 'display_vars' => NULL, 'term' => NULL, 'class' => NULL),
       ),
     'faq_questions_inline' => array(
+      'template' => 'faq-questions-inline',
       'arguments' => array('result' => NULL, 'display_vars' => NULL),
       ),
     'faq_category_questions_inline' => array(
       'arguments' => array('result' => NULL, 'display_vars' => NULL, 'term' => NULL, 'class' => NULL),
       ),
     'faq_new_page' => array(
+      'template' => 'faq-new-page',
       'arguments' => array('result' => NULL),
       ),
     'faq_category_new_page' => array(
@@ -829,16 +833,19 @@
   );
 }
 
-function theme_faq_questions_top($result, $display_vars) {
+function template_preprocess_faq_questions_top(&$variables) {
+  $result = $variables['result'];
+  $display_vars = $variables['display_vars'];
 
-  // configure "back to top" link
+  // Configure "back to top" link
   $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('attributes' => array(), 'query' => NULL, 'fragment' => '')) .'</p>';
   }
+  $variables['back_to_top'] = $back_to_top;
 
-  // loop through results
+  // Loop through results
   $questions = array();
   $answers = '';
   while ($node = db_fetch_object($result)) {
@@ -872,10 +879,10 @@
   }
 
   $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;
+  $variables['list_style'] = $list_style;
+  $variables['questions'] = $questions;
+  $variables['answers'] = $answers;
+  $variables['questions_list'] = theme('item_list', $questions, NULL, $list_style, array("class" => "faq_ul_questions_top"));
 }
 
 function theme_faq_category_questions_top($result, $display_vars, $term, $class) {
@@ -1119,15 +1126,18 @@
   return $data;
 }
 
-function theme_faq_hide_answer($result, $display_vars) {
+function template_preprocess_faq_hide_answer(&$variables) {
+  $result = $variables['result'];
+  $display_vars = $variables['display_vars'];
   drupal_add_js(drupal_get_path('module', 'faq') .'/faq.js', 'module');
 
-  $output = "<div>\n";
+  $nodes = array();
+  $count = 0;
   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";
+      $nodes[$count]['link'] = '<div class="faq_question faq_dt_hide_answer">';
+      $nodes[$count]['link'] .= l($node->title, "node/$node->nid") ."</div>\n";
       // should we display teaser or full text
       if ($display_vars['use_teaser']) {
         $more_link = '';
@@ -1135,21 +1145,26 @@
           $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";
+        $nodes[$count]['body'] = '<div class="faq_answer faq_dd_hide_answer">';
+        $nodes[$count]['body'] .= check_markup($node->teaser, $node->format, FALSE);
+        $nodes[$count]['body'] .= $more_link ."</div>\n";
       }
 
       // full text
       else {
-        $output .= '<div class="faq_answer faq_dd_hide_answer">';
-        $output .= check_markup($node->body, $node->format, FALSE) ."</div>\n";
+        $nodes[$count]['body'] = '<div class="faq_answer faq_dd_hide_answer">';
+        $nodes[$count]['body'] .= check_markup($node->body, $node->format, FALSE) ."</div>\n";
       }
     }
+    $count++;
   }
-  $output .= "</div>\n";
 
-  return $output;
+  $variables['output'] = '';
+  foreach ($nodes as $key => $node) {
+    $nodes[$key]['themed'] = $node['link'] . $node['body'];
+    $variables['output'] .= $nodes[$key]['themed'];
+  }
+  $variables['nodes'] = $nodes;
 }
 
 function theme_faq_category_hide_answer($result, $display_vars, $term, $class) {
@@ -1310,7 +1325,9 @@
   return $output;
 }
 
-function theme_faq_questions_inline($result, $display_vars) {
+function template_preprocess_faq_questions_inline(&$variables) {
+  $result = $variables['result'];
+  $display_vars = $variables['display_vars'];
 
   // configure "back to top" link
   $back_to_top = '';
@@ -1318,6 +1335,7 @@
     $back_to_top = '<p class="faq_top_link">';
     $back_to_top .= l(t($display_vars['back_to_top']), 'faq', array('attributes' => array(), 'query' => NULL, 'fragment' => '')) .'</p>';
   }
+  $variables['back_to_top'] = $back_to_top;
 
   // configure labels
   $que_label = '';
@@ -1326,37 +1344,44 @@
     $que_label = t($display_vars["faq_question_label"]) .' ';
     $ans_label = '<strong>'. t($display_vars["faq_answer_label"]) .'</strong> ';
   }
+  $variables['que_label'] = $que_label;
+  $variables['ans_label'] = $ans_label;
 
-  $output = "<div>\n";
+  $nodes = array();
+  $count = 0;
   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";
+      $nodes[$count]['link'] = '<div class="faq_question">';
+      $nodes[$count]['link'] .= l($que_label . $node->title, "node/$node->nid") ."</div>\n";
 
-      // should we display teaser or full text
+      // Should we display teaser or full text?
       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";
+        $nodes[$count]['body'] = '<div class="faq_answer">';
+        $nodes[$count]['body']  .= check_markup($ans_label . $node->teaser, $node->format, FALSE);
+        $nodes[$count]['body']  .= $more_link . $back_to_top ."</div>\n";
       }
 
-      // full text
+      // Full text.
       else {
-        $output .= '<div class="faq_answer">';
-        $output .= check_markup($ans_label . $node->body, $node->format, FALSE);
-        $output .= $back_to_top ."</div>\n";
+        $nodes[$count]['body'] = '<div class="faq_answer">';
+        $nodes[$count]['body'] .= check_markup($ans_label . $node->body, $node->format, FALSE);
+        $nodes[$count]['body'] .= $back_to_top ."</div>\n";
       }
     }
+    $count++;
   }
-  $output .= "</div>\n";
-
-  return $output;
+  $variables['output'] = '';
+  foreach ($nodes as $key => $node) {
+    $nodes[$key]['themed'] = $node['link'] . $node['body'];
+    $variables['output'] .= $nodes[$key]['themed'];
+  }
+  $variables['nodes'] = $nodes;
 }
 
 function theme_faq_category_questions_inline($result, $display_vars, $term, $class) {
@@ -1536,18 +1561,20 @@
   return $output;
 }
 
-function theme_faq_new_page($result) {
+function template_preprocess_faq_new_page(&$variables) {
   $items = array();
-  while ($node = db_fetch_object($result)) {
+  while ($node = db_fetch_object($variables['result'])) {
     $node_obj = node_load($node->nid);
     if (node_access("view", $node_obj)) {
+      // The l() function is considered to be safe for user input.
       $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"));
+  $variables['list_style'] = $list_style;
+  $variables['list_items'] = $items;
 
-  return $output;
+  $variables['list'] = theme('item_list', $items, NULL, $list_style, array("class" => "faq_question_listing"));
 }
 
 
