Index: opensearchplugin.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/opensearchplugin/Attic/opensearchplugin.module,v
retrieving revision 1.2.2.1.2.2
diff -u -r1.2.2.1.2.2 opensearchplugin.module
--- opensearchplugin.module	16 Feb 2008 19:49:04 -0000	1.2.2.1.2.2
+++ opensearchplugin.module	5 Jun 2008 07:17:55 -0000
@@ -29,6 +29,17 @@
   ));
 }
 
+/**
+ * Implementation of hook_theme().
+ */
+function opensearchplugin_theme() {
+  return array(
+    'opensearchplugin_output' => array(
+      'arguments' => array('info' => NULL),
+    ),
+  );
+}
+
 /*
  * Implementation of hook_menu().
  */ 
@@ -84,65 +95,79 @@
   return system_settings_form($form);
 }
 
-/*
- * Outputs the definition of the OpenSearch plugin
+/**
+ * Outputs the definition of the OpenSearch plugin.
  */
 function opensearchplugin_output() {
-  // Farm the variables
-  $shortname = variable_get('site_name', 'Drupal');
-  $longname = variable_get('site_name', 'Drupal');
-  $description = variable_get('site_slogan', '');
-  $tags = ''; // associated meta tags
-  $contact = ''; // contact email address
-  $htmlsearch = url("search/node/", array('absolute' => TRUE)); // search query
-  $language = '*'; // website language
-  $adultcontent = 'false'; // if website contains adult material
-  $syndicationright = 'open';  // open, limited, private or closed
-  $attribution = ''; // copyright information
-  $developer = ''; // who developed the website
-  $searchform = url('search', array('absolute' => TRUE)); // search page url
-  $icon = variable_get('opensearchplugin_image', '');
-  $iconwidth = variable_get('opensearchplugin_image_width', 16);
-  $iconheight = variable_get('opensearchplugin_image_height', 16);
-  
+  // Farm the variables.
+  $info['short_name'] = variable_get('site_name', 'Drupal');
+  $info['long_name'] = variable_get('site_name', 'Drupal');
+  $info['description'] = variable_get('site_slogan', '');
+  $info['tags'] = ''; // Associated meta tags.
+  $info['contact'] = variable_get('site_mail', ini_get('sendmail_from')); // Contact email address.
+  $info['html_search'] = url("search/node/", array('absolute' => TRUE)); // search query.
+  $info['language'] = '*'; // Website language
+  $info['adult_content'] = 'false'; // If website contains adult material.
+  $info['syndication_right'] = 'open';  // Open, limited, private or closed.
+  $info['attribution'] = ''; // Copyright information.
+  $info['developer'] = ''; // Who developed the website.
+  $info['search_form'] = url('search', array('absolute' => TRUE)); // Search page URL.
+  $info['icon'] = variable_get('opensearchplugin_image', '');
+  $info['icon_width'] = variable_get('opensearchplugin_image_width', 16);
+  $info['icon_height'] = variable_get('opensearchplugin_image_height', 16);
+
+  return theme('opensearchplugin_output', $info);
+}
+
+/**
+ * Theme the Open Search Description output.
+ *
+ * @param $info
+ *   An array.
+ * @ingroup themeable
+ */
+function theme_opensearchplugin_output($info) {
+  extract($info, EXTR_SKIP);  // Extract the variables to the local namespace.
+
   if (empty($icon)) {
-    theme(); // prepare the theme
-    $icon = theme_get_setting('favicon'); // the icon to use
+    $icon = theme_get_setting('favicon'); // The icon to use.
     if (!empty($icon)) {
       global $base_url;
       $url = parse_url($base_url);
       $icon = $url['scheme'] .'://'. $url['host'] . $icon;
     }
   }
-  // Check if the icon is choosen
+  // Check if the icon is choosen.
   if (!empty($icon)) {
-    $iconwidth = empty($iconwidth) ? '' : " width=\"$iconwidth\"";
-    $iconheight = empty($iconheight) ? '' : " height=\"$iconheight\"";
-    $icon = '<Image'. $iconwidth . $iconheight .'>'. $icon .'</Image>';
+    $icon_width = empty($icon_width) ? '' : " width=\"$icon_width\"";
+    $icon_height = empty($icon_height) ? '' : " height=\"$icon_height\"";
+    $icon = '<Image'. $icon_width . $icon_height .'>'. $icon .'</Image>';
   }
-  
+
   // Output specification based on
   // http://www.opensearch.org/Specifications/OpenSearch/1.1
-  $output = '<?xml version="1.0" encoding="UTF-8"?'.">
- <OpenSearchDescription xmlns=\"http://a9.com/-/spec/opensearch/1.1/\">
-   <ShortName>$shortname</ShortName>
-   <Description>$description</Description>
-   <Tags>$tags</Tags>
-   <Contact>$contact</Contact>
-   <Url type=\"text/html\" method=\"get\" template=\"$htmlsearch{searchTerms}\"/>
-   <SearchForm>$searchform</SearchForm>
-   <LongName>$longname</LongName>
-   $icon
-   <Developer>$developer</Developer>
-   <Attribution>$attribution</Attribution>
-   <SyndicationRight>$syndicationright</SyndicationRight>
-   <AdultContent>$adultcontent</AdultContent>
-   <Language>$language</Language>
-   <OutputEncoding>UTF-8</OutputEncoding>
-   <InputEncoding>UTF-8</InputEncoding>
- </OpenSearchDescription>";
-  drupal_set_header('Content-Type: text/xml');
-  echo $output;
-  module_invoke_all('exit');
-  exit;
+  $output = <<<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
+  <ShortName>$short_name</ShortName>
+  <Description>$description</Description>
+  <Tags>$tags</Tags>
+  <Contact>$contact</Contact>
+  <Url type="text/html" method="get" template="$html_search{searchTerms}"/>
+  <SearchForm>$search_form</SearchForm>
+  <LongName>$long_name</LongName>
+  $icon
+  <Developer>$developer</Developer>
+  <Attribution>$attribution</Attribution>
+  <SyndicationRight>$syndication_right</SyndicationRight>
+  <AdultContent>$adult_content</AdultContent>
+  <Language>$language</Language>
+  <OutputEncoding>UTF-8</OutputEncoding>
+  <InputEncoding>UTF-8</InputEncoding>
+  <Query role="example" searchTerms="cat"/>
+</OpenSearchDescription>
+EOT;
+
+  drupal_set_header('Content-Type: text/xml; charset=utf-8');
+  print $output;
 }
