? .DS_Store
Index: advanced_help.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advanced_help/advanced_help.info,v
retrieving revision 1.2
diff -u -p -r1.2 advanced_help.info
--- advanced_help.info	19 Apr 2008 16:45:57 -0000	1.2
+++ advanced_help.info	14 Nov 2009 16:57:29 -0000
@@ -1,4 +1,8 @@
-; $Id: advanced_help.info,v 1.2 2008/04/19 16:45:57 merlinofchaos Exp $
+; $Id: $
 name = Advanced help
 description = Allow advanced help and documentation.
-core = 6.x
+core = 7.x
+
+files[] = advanced-help-popup.tpl.php
+files[] = advanced_help.install
+files[] = advanced_help.module
Index: advanced_help.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advanced_help/advanced_help.install,v
retrieving revision 1.4
diff -u -p -r1.4 advanced_help.install
--- advanced_help.install	11 Oct 2009 05:47:49 -0000	1.4
+++ advanced_help.install	14 Nov 2009 16:57:29 -0000
@@ -16,6 +16,19 @@ function advanced_help_uninstall() {
 }
 
 /**
+ * Implementation of hook_enable.
+ *
+ * Make sure advanced_help is in the searchable modules by default.
+ */
+function advanced_help_enable() {
+  $search_modules = variable_get('search_active_modules', array('node', 'user'));
+  if (!in_array($search_modules, 'advanced_help')) {
+    $search_modules[] = 'advanced_help';
+    variable_set('advanced_help', $search_modules);
+  }
+}
+
+/**
  * advanced_help's initial schema.
  */
 function advanced_help_schema() {
Index: advanced_help.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advanced_help/advanced_help.module,v
retrieving revision 1.41
diff -u -p -r1.41 advanced_help.module
--- advanced_help.module	28 Oct 2008 17:33:47 -0000	1.41
+++ advanced_help.module	14 Nov 2009 16:57:29 -0000
@@ -88,11 +88,11 @@ function advanced_help_menu_alter(&$call
  */
 function advanced_help_theme() {
   $hooks['advanced_help_topic'] = array(
-    'arguments' => array('module' => NULL, 'topic' => NULL),
+    'variables' => array('module' => NULL, 'topic' => NULL, 'type' => 'icon'),
   );
 
   $hooks['advanced_help_popup'] = array(
-    'arguments' => array('content' => NULL),
+    'variables' => array('content' => NULL),
     'template' => 'advanced-help-popup',
   );
 
@@ -138,20 +138,21 @@ function advanced_help_search_view() {
       $results = search_data($keys, 'advanced_help');
 
       if ($results) {
-        $results = theme('box', t('Search results'), $results);
+        $results = '<h2>'. t('Search results') .'</h2>' . $results;
       }
       else {
-        $results = theme('box', t('Your search yielded no results'), search_help('search#noresults', drupal_help_arg()));
+        $results = '<h2>'. t('Your search yielded no results') .'</h2>';
+        $results .= search_help('search#noresults', drupal_help_arg());
       }
     }
 
     // Construct the search form.
-    $output = drupal_get_form('advanced_help_search_form', $keys);
+    $output = drupal_render(drupal_get_form('advanced_help_search_form', $keys));
     $output .= $results;
 
   }
   else {
-    $output = drupal_get_form('advanced_help_search_form', empty($keys) ? '' : $keys);
+    $output = drupal_render(drupal_get_form('advanced_help_search_form', empty($keys) ? '' : $keys));
   }
 
   $popup = !empty($_GET['popup']) && user_access('view advanced help popup');
@@ -159,7 +160,7 @@ function advanced_help_search_view() {
     $GLOBALS['devel_shutdown'] = FALSE; // Prevent devel module from spewing.
     module_invoke('admin_menu', 'suppress'); // Suppress admin_menu.
     drupal_set_breadcrumb(array_reverse($breadcrumb));
-    print theme('advanced_help_popup', $output);
+    print theme('advanced_help_popup', array('content' => $output));
     return;
   }
 
@@ -178,7 +179,7 @@ function advanced_help_index_page($modul
   // Print a search widget.
   $output = '';
   if (module_exists('search')) {
-    $output .= drupal_get_form('advanced_help_search_form');
+    $output .= drupal_render(drupal_get_form('advanced_help_search_form'));
   }
   else {
     $output .= t('Enable the search module to search help.');
@@ -196,13 +197,13 @@ function advanced_help_index_page($modul
     $breadcrumb[] = advanced_help_l(t('Help'), 'admin/advanced_help');
 
     drupal_set_title(t('@module help index', array('@module' => advanced_help_get_module_name($module))));
-    $output .= theme('item_list', $items);
+    $output .= theme('item_list', array('items' => $items));
   }
   else {
     // Print a module index.
     $modules = array();
     $result = db_query("SELECT * FROM {system}");
-    while ($info = db_fetch_object($result)) {
+    foreach ($result as $info) {
       $module_info = unserialize($info->info);
       $modules[$info->name] = $module_info['name'];
     }
@@ -226,7 +227,7 @@ function advanced_help_index_page($modul
     }
 
     drupal_set_title(t('Module help index'));
-    $output .= theme('item_list', $items);
+    $output .= theme('item_list', array('items' => $items));
   }
 
   $popup = !empty($_GET['popup']) && user_access('view advanced help popup');
@@ -234,7 +235,7 @@ function advanced_help_index_page($modul
     $GLOBALS['devel_shutdown'] = FALSE; // Prevent devel module from spewing.
     module_invoke('admin_menu', 'suppress'); // Suppress admin_menu.
     drupal_set_breadcrumb(array_reverse($breadcrumb));
-    print theme('advanced_help_popup', $output);
+    print theme('advanced_help_popup', array('content' =>  $output));
     return;
   }
 
@@ -254,7 +255,7 @@ function advanced_help_get_tree($topics,
     list($module, $topic) = $info;
     $item = advanced_help_l($topics[$module][$topic]['title'], "help/$module/$topic");
     if (!empty($topics[$module][$topic]['children']) && ($max_depth == -1 || $depth < $max_depth)) {
-      $item .= theme('item_list', advanced_help_get_tree($topics, $topics[$module][$topic]['children'], $max_depth, $depth + 1));
+      $item .= theme('item_list', array('items' => advanced_help_get_tree($topics, $topics[$module][$topic]['children'], $max_depth, $depth + 1)));
     }
 
     $items[] = $item;
@@ -306,8 +307,8 @@ function advanced_help_get_topic_hierarc
 /**
  * Form builder callback to build the search form.
  */
-function advanced_help_search_form(&$form_state, $keys = '') {
-  $form = search_form($form_state, advanced_help_url('admin/advanced_help'), $keys, 'advanced_help', t('Search help'));
+function advanced_help_search_form($form, &$form_state, $keys = '') {
+  $form = search_form($form, $form_state, advanced_help_url('admin/advanced_help'), $keys, 'advanced_help', t('Search help'));
   require_once './' . drupal_get_path('module', 'search') . '/search.pages.inc';
 
   $form['basic']['inline']['submit']['#validate'] = array('search_form_validate');
@@ -346,8 +347,11 @@ function advanced_help_get_module_name($
     $name = $settings[$module]['name'];
   }
   else {
-    $info = db_fetch_object(db_query("SELECT * FROM {system} WHERE name = '%s'", $module));
-    $info = unserialize($info->info);
+    $result = db_query("SELECT * FROM {system} WHERE name = :module", array(':module' => $module));
+    foreach($result as $record) {
+      $info = unserialize($record->info);
+      break;
+    }
     $name = t($info['name']);
   }
   return $name;
@@ -398,6 +402,7 @@ function advanced_help_topic_page($modul
   $breadcrumb[] = advanced_help_l(advanced_help_get_module_name($pmodule), "admin/advanced_help/$pmodule");
   $breadcrumb[] = advanced_help_l(t('Help'), "admin/advanced_help");
 
+
   $output = advanced_help_view_topic($module, $topic, $popup);
   if (empty($output)) {
     $output = t('Missing help topic.');
@@ -407,7 +412,7 @@ function advanced_help_topic_page($modul
     $GLOBALS['devel_shutdown'] = FALSE; // Prevent devel module from spewing.
     module_invoke('admin_menu', 'suppress'); // Suppress admin_menu.
     drupal_set_breadcrumb(array_reverse($breadcrumb));
-    print theme('advanced_help_popup', $output);
+    print theme('advanced_help_popup', array('content' => $output));
     return;
   }
 
@@ -436,7 +441,8 @@ function advanced_help_perm() {
  *   - 'title' to display the topic's title
  *   - any other text to display the text. Be sure to t() it!
  */
-function theme_advanced_help_topic($module, $topic, $type = 'icon') {
+function theme_advanced_help_topic($variables) {
+  extract($variables);
   $info = advanced_help_get_topic($module, $topic);
   if (!$info) {
     return;
@@ -493,7 +499,7 @@ function advanced_help_get_topic_filenam
  * Load and render a help topic.
  */
 function advanced_help_get_topic_file_info($module, $topic) {
-  init_theme();
+//  init_theme();
   global $language;
 
   $info = advanced_help_get_topic($module, $topic);
@@ -531,9 +537,9 @@ function advanced_help_view_topic($modul
 
     // Change 'topic:' to the URL for another help topic.
     if ($popup) {
-      $output = preg_replace('/href="topic:([^"]+)"/', 'href="' . strtr(url('help/$1', array('query' => 'popup=true')), array('%24' => '$')) . '"', $output);
-      $output = preg_replace('/src="topic:([^"]+)"/', 'src="' . strtr(url('help/$1', array('query' => 'popup=true')), array('%24' => '$')) . '"', $output);
-      $output = preg_replace('/&topic:([^"]+)&/', strtr(url('help/$1', array('query' => 'popup=true')), array('%24' => '$')), $output);
+      $output = preg_replace('/href="topic:([^"]+)"/', 'href="' . strtr(url('help/$1', array('query' => array('popup' => 'true'))), array('%24' => '$')) . '"', $output);
+      $output = preg_replace('/src="topic:([^"]+)"/', 'src="' . strtr(url('help/$1', array('query' => array('popup' => 'true'))), array('%24' => '$')) . '"', $output);
+      $output = preg_replace('/&topic:([^"]+)&/', strtr(url('help/$1', array('query' => array('popup' => 'true'))), array('%24' => '$')), $output);
     }
     else {
       $output = preg_replace('/href="topic:([^"]+)"/', 'href="' . strtr(url('help/$1'), array('%24' => '$')) . '"', $output);
@@ -571,7 +577,7 @@ function advanced_help_view_topic($modul
       advanced_help_get_topic_hierarchy($topics);
       if (!empty($topics[$module][$topic]['children'])) {
         $items = advanced_help_get_tree($topics, $topics[$module][$topic]['children']);
-        $output .= theme('item_list', $items);
+        $output .= theme('item_list', array('items' => $items));
       }
 
       list($parent_module, $parent_topic) = $topics[$module][$topic]['_parent'];
@@ -672,7 +678,7 @@ function _advanced_help_parse_ini() {
       }
       elseif (!file_exists("$module_path/help")) {
         // Look for one or more README files.
-        $files = file_scan_directory("./$module_path", '^(README|readme).*\.(txt|TXT)$', array('.', '..', 'CVS'), 0, FALSE);
+        $files = file_scan_directory("./$module_path", '/^(README|readme).*\.(txt|TXT)$/', array('.', '..', 'CVS'), 0, FALSE);
         $path = "./$module_path";
         foreach ($files as $name => $fileinfo) {
           $info[$fileinfo->basename] = array('line break' => TRUE, 'readme file' => TRUE, 'file' => $fileinfo->basename, 'title' => $fileinfo->name);
@@ -727,12 +733,70 @@ function _advanced_help_parse_ini() {
 }
 
 /**
- * Implementation of hook_search()
+ * Implementation of hook_search_info()
  */
+function advanced_help_search_info() {
+  return array(
+    'title' => 'Help',
+    'path' => 'advanced_help',
+  );
+}
+
+/**
+ * Implementation of hook_search_execute()
+ */
+function advanced_help_search_execute($keys) {
+  $topics = advanced_help_get_topics();
+  // Build matching conditions
+  $query = db_select('search_index', 'i', array('target' => 'slave'))->extend('SearchQuery')->extend('PagerDefault');
+  $query->searchExpression($keys, 'help')->join('advanced_help_index', 'a', 'a.sid = i.sid');
+
+  // Insert special keywords.
+  $query->setOption('language', 'a.language');
+  // Only continue if the first pass query matches.
+  if (!$query->executeFirstPass()) {
+    return array();
+  }
+
+  // Add a count query.
+  $inner_query = clone $query;
+  $count_query = db_select($inner_query->fields('i', array('sid')), NULL, array('target' => 'slave'));
+  $count_query->addExpression('COUNT(*)');
+  $query->setCountQuery($count_query);
+  $query->addField('a', 'module');
+  $query->addField('a', 'topic');
+  $find = $query->limit(10)->execute();
+
+  if (!$find) {
+    return;
+  }
+  
+  foreach($find as $sid) {
+    // Guard against removed help topics that are still indexed.
+    if (empty($topics[$sid->module][$sid->topic])) {
+      continue;
+    }
+    $info = $topics[$sid->module][$sid->topic];
+    $text = advanced_help_view_topic($sid->module, $sid->topic);
+    $results[] = array('link' => advanced_help_url("help/$sid->module/$sid->topic"),
+                       'title' => $info['title'],
+                       'snippet' => search_excerpt($keys, $text));
+  }
+  return $results;
+}
+
+/**
+ * Implementation of hook_search_reset()
+ */
+function advanced_help_search_reset() {
+  variable_del('advanced_help_last_cron');
+  return;
+}
+
+/*
 function advanced_help_search($op = 'search', $keys = null) {
   switch ($op) {
-    case 'name':
-      return t('Help');
+
     case 'reset':
       variable_del('advanced_help_last_cron');
       return;
@@ -743,15 +807,16 @@ function advanced_help_search($op = 'sea
         return;
       }
 
-      $results = array();
-
-      $placeholders = implode(', ', array_fill(0, count($find), '%d'));
+      $query = db_select('advanced_help_index', 'a', $options);
+      
       foreach ($find as $item) {
         $sids[] = $item->sid;
       }
+      $query->condition('sid', $sids, 'IN');
+      $result = $query->execute();
 
-      $result = db_query("SELECT * FROM {advanced_help_index} WHERE sid IN ($placeholders)", $sids);
-      while ($sid = db_fetch_object($result)) {
+      
+      foreach($result as $sid) {
         // Guard against removed help topics that are still indexed.
         if (empty($topics[$sid->module][$sid->topic])) {
           continue;
@@ -765,6 +830,7 @@ function advanced_help_search($op = 'sea
       return $results;
   }
 }
+*/
 
 /**
  * Get or create an sid (search id) that correllates to each topic for
@@ -772,10 +838,10 @@ function advanced_help_search($op = 'sea
  */
 function advanced_help_get_sids(&$topics) {
   global $language;
-  $result = db_query("SELECT * FROM {advanced_help_index} WHERE language = '%s'", $language->language);
-  while ($sid = db_fetch_object($result)) {
+  $result = db_query("SELECT * FROM {advanced_help_index} WHERE language = :language", array(':language' => $language->language));
+  foreach($result as $sid) {
     if (empty($topics[$sid->module][$sid->topic])) {
-      db_query("DELETE FROM {advanced_help_index} WHERE sid = %d", $sid->sid);
+      db_query("DELETE FROM {advanced_help_index} WHERE sid = :sid", array(':sid' => $sid->sid));
     }
     else {
       $topics[$sid->module][$sid->topic]['sid'] = $sid->sid;
@@ -797,7 +863,6 @@ function advanced_help_update_index() {
   advanced_help_get_sids($topics);
 
   $count = 0;
-
   foreach ($topics as $module => $module_topics) {
     // Fast forward if necessary.
     if (!empty($last['module']) && $last['module'] != $module) {
@@ -820,8 +885,7 @@ function advanced_help_update_index() {
       $file = advanced_help_get_topic_filename($module, $topic);
       if ($file && (empty($info['sid']) || filemtime($file) > $last['time'])) {
         if (empty($info['sid'])) {
-          db_query("INSERT INTO {advanced_help_index} (module, topic, language) VALUES ('%s', '%s', '%s')", $module, $topic, $language->language);
-          $info['sid'] = db_last_insert_id('advanced_help_index', 'sid');
+          $info['sid'] = db_query("INSERT INTO {advanced_help_index} (module, topic, language) VALUES (:module, :topic, :language)", array(':module' => $module, ':topic' => $topic, ':language' => $language->language), array('return' => Database::RETURN_INSERT_ID));
         }
 
         search_index($info['sid'], 'help', '<h1>' . $info['title'] . '</h1>' . file_get_contents($file));
@@ -845,7 +909,7 @@ function advanced_help_update_index() {
 function template_preprocess_advanced_help_popup(&$variables) {
   // Add favicon.
   if (theme_get_setting('toggle_favicon')) {
-    drupal_set_html_head('<link rel="shortcut icon" href="'. check_url(theme_get_setting('favicon')) .'" type="image/x-icon" />');
+    drupal_add_html_head('<link rel="shortcut icon" href="'. check_url(theme_get_setting('favicon')) .'" type="image/x-icon" />');
   }
 
   global $theme;
@@ -866,7 +930,7 @@ function template_preprocess_advanced_he
   $variables['head_title']        = implode(' | ', $head_title);
   $variables['base_path']         = base_path();
   $variables['front_page']        = url();
-  $variables['breadcrumb']        = theme('breadcrumb', drupal_get_breadcrumb());
+  $variables['breadcrumb']        = theme('breadcrumb', array('breadcrumb' => drupal_get_breadcrumb()));
   $variables['feed_icons']        = drupal_get_feeds();
   $variables['head']              = drupal_get_html_head();
   $variables['language']          = $GLOBALS['language'];
Index: help_example/help_example.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advanced_help/help_example/help_example.info,v
retrieving revision 1.3
diff -u -p -r1.3 help_example.info
--- help_example/help_example.info	10 May 2008 17:32:14 -0000	1.3
+++ help_example/help_example.info	14 Nov 2009 16:57:29 -0000
@@ -1,5 +1,6 @@
 ; $Id: help_example.info,v 1.3 2008/05/10 17:32:14 merlinofchaos Exp $
 name = Advanced help example
 description = A example help module to demonstrate the advanced help module.
-core = 6.x
-dependencies[] = advanced_help
\ No newline at end of file
+core = 7.x
+dependencies[] = advanced_help
+files[] = help_example.module
Index: help_example/help_example.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advanced_help/help_example/help_example.module,v
retrieving revision 1.2
diff -u -p -r1.2 help_example.module
--- help_example/help_example.module	19 Apr 2008 16:45:57 -0000	1.2
+++ help_example/help_example.module	14 Nov 2009 16:57:29 -0000
@@ -20,7 +20,7 @@ function help_example_menu() {
 }
 
 function help_example_index_page() {
-  $output = theme('advanced_help_topic', 'help_example', 'about-php');
+  $output = theme('advanced_help_topic', array('module' => 'help_example', 'topic' => 'about-php'));
   $output .= '&nbsp;' . t('Click the help icon to view some example help about the PHP programming language (from wikipedia.org). Be sure to run cron to update the index if you want to try out the search features.');
   return $output;
 }
