? faq.module.vmod
? faq.module.vtea
? po
Index: faq-category-questions-inline.tpl.php
===================================================================
RCS file: faq-category-questions-inline.tpl.php
diff -N faq-category-questions-inline.tpl.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ faq-category-questions-inline.tpl.php	19 Jan 2008 11:02:04 -0000
@@ -0,0 +1,126 @@
+<?php
+// $Id$
+
+/**
+ * Available variables:
+ *
+ * $display_header tells whether the category header should be displayed
+ * $header_title represents the category title (or a link with this title)
+ * $category_depth (greather than 0 when it's a subcategory)
+ * $description
+ * $question_count represents the number of questions in category
+ * $term_img represents the html for the category image. This is empty if the taxonomy image module is not enabled.
+ *
+ * $subcat_list represents an array of subcategories
+ * Each subcategory stored in the $subcat_list array has the following information:
+ *   $subcat['link'] represents the link to the subcategory
+ *   $subcat['description']
+ *   $subcat['count'] represents the number of question in subcategory
+ *   $subcat['img'] represents the subcategory (taxonomy) image
+ * $subcat_list_style represents the style of the list, either ol or ul (ordered or unordered)
+ * $subcat_body_list represents subcategories, recursively themed (by this template)
+ * $container_class is the class attribute of the element containing subcategories, either 'faq_qa' or 'faq_qa_hide'. This is used by javascript to open/hide categories.
+ *
+ * $display_faq_count tells whether the number of questions in (sub)categories should be displayed
+ * $use_teaser tells whether $node['body'] contains the full body or just the teaser
+ *
+ * $nodes represents an array of nodes with questions and answers.
+ * Each node stored in the $nodes array has the following information:
+ *   $node['link'] represents the question and a link to the node (question).
+ *   $node['body'] represents the body of the node (answer).
+ *   $node['more_link'] represents a "more" link. This may not be available, so check that it exists with isset().
+ *
+ * $question_label represents the question label.
+ * $answer_label represents the answer label.
+ * $back_to_top represents a link back to the top of the page.
+ */
+
+if ($category_depth > 0) {
+  $hdr = 'h6';
+}
+else {
+  $hdr = 'h5';
+}
+
+?><div class="faq_category_group">
+  <?php // category header with title, link, image, description, and count of questions inside ?>
+  <div class="faq_qa_header">
+  <?php if ($display_header): ?>
+    <<?php print $hdr; ?> class="faq_header">
+    <?php print $term_img; ?>
+    <?php print $header_title; ?>
+    <?php if ($display_faq_count): ?>
+      (<?php print $question_count; ?>)
+    <?php endif; ?>
+    </<?php print $hdr; ?>>
+  <?php else: ?>
+    <?php print $term_img; ?>
+  <?php endif; ?>
+  <?php if (!empty($description)): ?>
+    <div class="faq_qa_description"><p>
+    <?php print $description ?>
+    </p></div>
+  <?php endif; ?>
+  <div class="clear-block"></div>
+  </div>
+
+  <?php // list subcategories, with title, link, description, count ?>
+  <?php if(!empty($subcat_list)): ?>
+    <div class="item-list">
+    <<?php print $subcat_list_style; ?> class="faq_category_list">
+    <?php foreach ($subcat_list as $i => $subcat): ?>
+      <li>
+      <?php print $subcat['link']; ?>
+      <?php if ($display_faq_count): ?>
+        (<?php print $subcat['count']; ?>)
+      <?php endif; ?>
+      <?php if (!empty($subcat['description'])): ?>
+      <div class="faq_qa_description"><p>
+      <?php print $subcat['description']; ?>
+      </p></div>
+      <?php endif; ?>
+      <div class="clear-block"></div>
+      </li>
+    <?php endforeach; ?>
+    </<?php print $subcat_list_style; ?>>
+  </div>
+  <?php endif; ?>
+
+  <div class="<?php print $container_class; ?>">
+
+  <?php // include subcategories ?>
+  <?php foreach ($subcat_body_list as $i => $subcat_html): ?>
+    <div class="faq_category_indent">
+    <?php print $subcat_html; ?>
+    </div>
+  <?php endforeach; ?>
+
+  <?php // list questions (in title link) and answers (in body) ?>
+  <div>
+  <?php foreach ($nodes as $i => $node): ?>
+    <div class="faq_question">
+    <strong>
+    <?php print $question_label; ?>
+    </strong>
+    <?php print $node['link']; ?>
+    </div>
+    <div class="faq_answer">
+    <strong>
+    <?php print $answer_label; ?>
+    </strong>
+    <?php print $node['body']; ?>
+    <?php if (!empty($node['more_link'])): ?>
+      <p class="faq_more_link">
+      <?php print $node['more_link']; ?>
+      </p>
+    <?php endif; ?>
+    <p class="faq_top_link">
+    <?php print $back_to_top; ?>
+    </p>
+    </div>
+  <?php endforeach; ?>
+  </div>
+
+  </div>
+
+</div>
Index: faq.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/faq/faq.module,v
retrieving revision 1.1.4.52.2.27
diff -u -p -r1.1.4.52.2.27 faq.module
--- faq.module	9 Jan 2008 12:36:21 -0000	1.1.4.52.2.27
+++ faq.module	19 Jan 2008 11:02:09 -0000
@@ -818,6 +818,7 @@ function faq_theme() {
       'arguments' => array('result' => NULL, 'display_vars' => NULL),
       ),
     'faq_category_questions_inline' => array(
+      'template' => 'faq-category-questions-inline',
       'arguments' => array('result' => NULL, 'display_vars' => NULL, 'term' => NULL, 'class' => NULL),
       ),
     'faq_new_page' => array(
@@ -1370,10 +1371,14 @@ function template_preprocess_faq_questio
   $variables['nodes'] = $nodes;
 }
 
-function theme_faq_category_questions_inline($result, $display_vars, $term, $class) {
+function template_preprocess_faq_category_questions_inline(&$variables) {
+  $result = $variables['result'];
+  $display_vars = $variables['display_vars'];
+  $term = $variables['term'];
+  $class = $variables['class'];
+
   $this_page = 'faq';
   $get_sub_terms = 0;
-  $count = 0;
   if (arg(0) == 'faq' && is_numeric(arg(1))) {
     $this_page .= "/". arg(1);
     $get_sub_terms = arg(1);
@@ -1382,114 +1387,82 @@ function theme_faq_category_questions_in
   // 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']), $this_page, array('attributes' => array(), 'query' => NULL, 'fragment' => '')) .'</p>';
+    $back_to_top = l(t($display_vars['back_to_top']), $this_page, array('attributes' => array(), 'query' => NULL, 'fragment' => ''));
   }
+  $variables['back_to_top'] = $back_to_top;
 
   // configure labels
-  $que_label = '';
-  $ans_label = '';
+  $question_label = '';
+  $answer_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> ';
+    $question_label = t($display_vars["faq_question_label"]) .' ';
+    $answer_label = t($display_vars["faq_answer_label"]) .' ';
   }
+  $variables['question_label'] = $question_label;
+  $variables['answer_label'] = $answer_label;
 
   // get number of questions, and account for hidden sub-cats
+  $count = 0;
   if ($display_vars['faq_count'] && $display_vars['hide_sub_categories']) {
     $count = taxonomy_term_count_nodes($term->tid, 'faq');
   }
+  $variables['display_faq_count'] = $display_vars['faq_count'];
 
   // get taxonomy image
-  $term_img = '';
+  $variables['term_img'] = '';
   if (module_exists('taxonomy_image')) {
-    $term_img = taxonomy_image_display($term->tid, 'class="faq_tax_image"');
+    $variables['term_img'] = taxonomy_image_display($term->tid, 'class="faq_tax_image"');
   }
 
   // configure header
-  $hdr = "h5";
-  if ($term->depth > 0) $hdr = "h6";
-  $header = "<$hdr class=\"faq_header\">";
-  $header .= $term_img;
+  $variables['display_header'] = $display_vars['display_header'];
+  $variables['category_depth'] = $term->depth;
   if ($display_vars['category_display'] == 'hide_qa') {
-    $header .= l($term->name, "faq/$term->tid");
+    $variables['header_title'] = l($term->name, "faq/$term->tid");
   }
   else {
-    $header .= check_plain($term->name);
+    $variables['header_title'] = check_plain($term->name);
   }
-  if ($display_vars['faq_count']) $header .= " (%%FAQ_COUNT%%)";
-  $header .= "</$hdr>\n";
 
   // configure category description
-  $desc = '';
-  if (!empty($term->description)) {
-    $desc = '<div class="faq_qa_description"><p>';
-    $desc .= $term->description ."</p></div>\n";
-  }
-  $desc .= '<div class="clear-block"></div>';
-
+  $variables['description'] = $term->description;
 
   // get list of sub-categories if necessary
-  $sub_cats = '';
+  $scats = array();
   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) {
-
-        // configure sub cat description
-        $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>";
-        }
-
         // get taxonomy image
         $sub_term_img = '';
         if (module_exists('taxonomy_image')) {
           $sub_term_img = taxonomy_image_display($sub_term->tid, 'class="faq_tax_image"');
-
         }
 
-        // configure sub cat header
-        if ($display_vars['faq_count']) {
-          $scats_hdr = l($sub_term->name, "faq/$sub_term->tid") ." ($sub_count) $sub_cat_desc";
-          $scats_hdr .= '<div class="clear-block"></div>';
-        }
-        else {
-          $scats_hdr = l($sub_term->name, "faq/$sub_term->tid") . $sub_cat_desc;
-          $scats_hdr .= '<div class="clear-block"></div>';
-        }
-
-        $scats[] = $scats_hdr;
+        $scat_vars['link'] = l($sub_term->name, "faq/$sub_term->tid");
+        $scat_vars['description'] = $sub_term->description;
+        $scat_vars['count'] = $sub_count;
+        $scat_vars['img'] = $sub_term_img;
+        $scats[] = $scat_vars;
       }
     }
-    $list_style = variable_get('faq_category_listing', 'ul');
-    $sub_cats .= theme('item_list', $scats, NULL, $list_style, array("class" => "faq_category_list"));
   }
 
+  $variables['subcat_list'] = $scats;
+  $variables['subcat_list_style'] = variable_get('faq_category_listing', 'ul');
 
-
-  $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">'. $term_img . $desc ."</div>\n";
-  }
-  $output .= $sub_cats;
-  $sub_cats = '';
-
-
+  // configure class (faq_qa or faq_qa_hide)
   if ($get_sub_terms == $term->tid) {
-    $output .= '<div class="faq_qa">'."\n";
+    $variables['container_class'] = 'faq_qa';
   }
   else {
-    $output .= '<div class="'. $class .'">'."\n";
+    $variables['container_class'] = $class;
   }
 
-
+  // configure subcategory bodies (theme recursively)
+  $sub_cat_htmls = array();
   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);
 
@@ -1498,53 +1471,47 @@ function theme_faq_category_questions_in
       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('faq_category_questions_inline', $sub_result, $display_vars, $sub_term, $class);
-        $sub_cats .= '</div>';
+        $sub_cat_htmls[] = theme('faq_category_questions_inline', $sub_result, $display_vars, $sub_term, $variables['class']);
       }
     }
-    $output .= $sub_cats;
   }
+  $variables['subcat_body_list'] = $sub_cat_htmls;
 
 
-  if ($result) {
-    $output .= "<div>\n";
+  if (!$result) {
+    $variables['question_count'] = 0;
+    return;
+  }
 
-    while ($node = db_fetch_object($result)) {
-      $node = node_load($node->nid);
-      if (node_access("view", $node)) {
-        if (!$display_vars['hide_sub_categories']) {
-          $count++;
-        }
-        $output .= '<div class="faq_question">';
-        $output .= l($que_label . $node->title, "node/$node->nid") ."</div>\n";
+  $nodes = array();
+  while ($node = db_fetch_object($result)) {
+    $node = node_load($node->nid);
+    if (node_access("view", $node)) {
+      if (!$display_vars['hide_sub_categories']) {
+        $count++;
+      }
+      $node_var = array();
+      $node_var['link'] = l($node->title, "node/$node->nid");
 
-        // 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";
+      // Should we display teaser or full text?
+      if ($display_vars['use_teaser']) {
+        if (!empty($display_vars['more_link']) && strlen($node->teaser) < strlen($node->body)) {
+          $node_var['more_link'] = l(t($display_vars['more_link']), "node/$node->nid");
         }
+        $node_var['body'] = check_markup($node->teaser, $node->format, FALSE);
+      }
 
-        // full text
-        else {
-          $output .= '<div class="faq_answer">';
-          $output .= check_markup($ans_label . $node->body, $node->format, FALSE);
-          $output .= $back_to_top ."</div>\n";
-        }
+      // Full text.
+      else {
+        $node_var['body'] = check_markup($node->body, $node->format, FALSE);
       }
+
+      $nodes[] = $node_var;
     }
-    $output .= "</div>\n";
   }
-  $output .= "</div>\n</div>\n";
-
-  if ($display_vars['faq_count']) $output = str_replace('%%FAQ_COUNT%%', $count, $output);
-  return $output;
+  $variables['nodes']=$nodes;
+  $variables['question_count'] = $count;
+  $variables['use_teaser'] = $display_vars['use_teaser'];
 }
 
 function template_preprocess_faq_new_page(&$variables) {
