--- /Users/dburns/Desktop/nodewords/nodewords.module	2008-01-11 07:40:43.000000000 -0500
+++ nodewords.module	2008-01-23 12:17:43.000000000 -0500
@@ -78,7 +78,11 @@
     $tags = nodewords_get();
     foreach ($tags as $name => $content) {
       if (!empty($content)) {
-        drupal_set_html_head('<meta name="'. $name .'" content="'. $content .'" />');
+        $argument = nodewords_get_arguments();
+        foreach ($argument as $key => $phrase) {
+          $content = str_replace('%'.$key, ucwords($argument[$key]), $content);
+        }
+        drupal_set_html_head('<meta name="' . $name . '" content="' . $content . '" />');
       }
     }
   }
@@ -159,7 +163,17 @@
   elseif ($form_id == 'panels_delete_confirm') {
     $form['#submit']['nodewords_panels_handler'] = array();
   }
-  elseif ($form_id == 'views_edit_view') {
+  else if ($form_id == 'panels_page_edit_form') {
+    $panels_page = panels_page_get_current($form);
+    $type = 'panels';
+    $id = $panels_page['panel_page']['#value']->did;
+    $form['submit']['#weight'] = 45;
+    $form['#submit']['nodewords_panels_page_handler'] = array();
+  }
+  else if ($form_id == 'panels_page_delete_confirm') {
+    $form['#submit']['nodewords_panels_page_handler'] = array();
+  }
+  else if ($form_id == 'views_edit_view') {
     $type = 'views';
     $id = $form['vid']['#value'];
     $form['save']['#weight'] = 40;
@@ -413,6 +427,25 @@
 }
 
 /**
+ * Handling of edit/delete form for panels 2.
+ */
+function nodewords_panels_page_handler($form_id, $form_values) {
+  switch ($_POST['op']) {
+    case t('Save'):
+      if (isset($form_values['nodewords']) && user_access('administer meta tags')) {
+        _nodewords_set('panels', $form_values['panel_page']->did, $form_values['nodewords']);
+      }
+      break;
+
+    case t('Delete'):
+      if ($form_values['confirm']) {
+        _nodewords_delete('panels', $form_values['panel_page']->did);
+      }
+      break;
+  }
+}
+
+/**
  * Handling of edit/delete form for views.
  */
 function nodewords_views_handler($form_id, $form_values) {
@@ -497,8 +530,14 @@
  *   An associative array of the defined meta tags.
  */
 function nodewords_get($type = NULL, $ids = NULL, $filtered = TRUE) {
-  // Autodetect if $type and/or $ids is not set
-  if ($type == NULL || $ids == NULL) {
+  /* Panels are tricky so lets do this */
+  if ($type = 'panels' && isset($ids)) {
+    $result = _nodewords_panels_load($ids);
+    $type = $result['type'];
+    $ids = $result['ids'];
+  }
+  /* Autodetect if $type and/or $ids is not set */
+  elseif ($type == NULL || $ids == NULL) {
     $result = _nodewords_detect_type_and_ids();
     $type = $result['type'];
     $ids = $result['ids'];
@@ -777,7 +816,7 @@
     }
     unset($tags['geourl']);
   }
-  
+
   // Check 'content' of each tag
   $tags = array_map(_nodewords_check_content, $tags);
 
@@ -918,3 +957,31 @@
 
   return array('type' => 'none', 'ids' => array());
 }
+
+function nodewords_get_arguments () {
+  $args = array();
+  $args = explode("/",str_replace("-", " ",$_GET['q']));
+
+  return $args;
+}
+
+function nodewords_panels_pre_render($panel_id = NULL) {
+  $tags = nodewords_get('panels', $panel_id->did, TRUE);
+  foreach ($tags as $name => $content) {
+    if (!empty($content)) {
+      $argument = nodewords_get_arguments();
+      foreach ($argument as $key => $phrase) {
+        $content = str_replace('%'.$key, ucwords($argument[$key]), $content);
+      }
+      if($name != 'robots'){
+        drupal_set_html_head('<meta name="' . $name . '" content="' . $content . '" />');
+      }
+    }
+  }
+}
+
+function _nodewords_panels_load($panel_id) {
+    if ($result = db_fetch_array(db_query("SELECT * FROM {panels_page} WHERE did = '%d'", $panel_id))) {
+      return array('type' => 'panels', 'ids' => array($result['did']));
+    }
+}
\ No newline at end of file
