Index: page_title.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/page_title/page_title.install,v
retrieving revision 1.9
diff -u -p -r1.9 page_title.install
--- page_title.install	3 Aug 2007 05:22:19 -0000	1.9
+++ page_title.install	5 Feb 2008 21:55:41 -0000
@@ -68,3 +68,16 @@ function page_title_update_1() {
   }
   return $items;
 }
+
+function page_title_update_2() {
+  $items = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysqli':
+    case 'mysql':
+      $items[] = update_sql('ALTER TABLE {page_title} CHANGE nid pid INT;');
+      $items[] = update_sql('ALTER TABLE {page_title} ADD COLUMN type VARCHAR(32) NOT NULL DEFAULT "node" FIRST;');
+      $items[] = update_sql('ALTER TABLE {page_title} DROP PRIMARY KEY;');
+      $items[] = update_sql('ALTER TABLE {page_title} ADD PRIMARY KEY (type,pid);');
+  }
+  return $items;  
+}
\ No newline at end of file
Index: page_title.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/page_title/page_title.module,v
retrieving revision 1.12.2.11
diff -u -p -r1.12.2.11 page_title.module
--- page_title.module	18 Jan 2008 12:13:50 -0000	1.12.2.11
+++ page_title.module	5 Feb 2008 21:55:41 -0000
@@ -37,6 +37,7 @@ function page_title_help($section) {
   return $output;
 }
 
+
 /**
  * Implementation of hook_perm().
  */
@@ -44,6 +45,7 @@ function page_title_perm() {
   return array('set page title', 'administer page titles');
 }
 
+
 /**
  * Implementation of hook_menu().
  */
@@ -104,6 +106,12 @@ function page_title_admin_settings() {
 }
 
 
+/**
+ * Theme function to theme the admin page form (puts the form into a table)
+ *
+ * @param array $form
+ * @return string
+ */
 function theme_page_title_admin_settings($form) {
   $output = '';
   $rows = array();
@@ -127,8 +135,7 @@ function theme_page_title_admin_settings
 /**
  * Displays the form for the "Content creation types" tab.
  *
- * @return
- *   array A structured form array for use with Forms API.
+ * @return array A structured form array for use with Forms API.
  */
 function page_title_admin_types() {
   $form['page_title_fieldset'] = array(
@@ -147,6 +154,7 @@ function page_title_admin_types() {
   return system_settings_form($form);
 }
 
+
 /**
  * Implementation of hook_node_type().
  *
@@ -185,12 +193,13 @@ function page_title_node_type($op, $info
   }
 }
 
+
 /**
  * Implementation of hook_form_alter().
  */
 function page_title_form_alter($form_id, &$form) {
   $display = variable_get('page_title_display', array());
-  
+
   if ($form['#id'] == 'node-form' && user_access('set page title') && $display[$form['type']['#value']]) {
     $form['page_title'] = array(
       '#type' => 'textfield',
@@ -202,75 +211,147 @@ function page_title_form_alter($form_id,
       '#weight' => -4,
     );
   }
+  elseif ($form_id == 'views_edit_view') {
+    $page = $form['page-info'];
+    $newPage = array();
+    
+    if ($form['vid']['#value']) {
+      $default_title = _page_title_get_view_title($form['vid']['#value']);
+    }
+    else {
+      $default_title = '';
+    }
+    
+    while (list($key, $val) = each($page)) {
+      $newPage[$key] = $val;
+      if ($key == 'page_title') {
+        $newPage['head_title'] = array(
+          '#type' => 'textfield',
+          '#title' => t('Head Title'),
+          '#description' => t('The title which appears in the &lt;head&gt; section, provided by Page Title module.'),
+          '#size' => 60,
+          '#maxlength' => 255,
+          '#default_value' => $default_title,
+        );
+        break;
+      }
+    }
+    $form['page-info'] = $newPage;
+    $form['#submit']['page_title_view_edit_view_submit'] = array();
+  }
+}
+
+
+/**
+ * Submit callback used by the form_alter on view edit/add pages.
+ *
+ * @param string $form_id
+ * @param array $form_values
+ */
+function page_title_view_edit_view_submit($form_id, $form_values) {
+  $vid = $form_values['vid'];
+  db_query('DELETE FROM {page_title} WHERE type="view" AND pid=%d', $vid);
+  db_query('INSERT INTO {page_title} VALUES ("view", %d, "%s")', $vid, $form_values['head_title']);
 }
 
+
 /**
  * Implementation of hook_nodeapi().
  */
 function page_title_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
   switch ($op) {
     case 'update':
-      db_query("DELETE FROM {page_title} WHERE nid = %d", $node->nid);
+      db_query('DELETE FROM {page_title} WHERE type = "node" AND pid = %d', $node->nid);
       // fallthrough to insert intentional!
     case 'insert':
       if (isset($node->page_title) && strlen(trim($node->page_title)) > 0) {
-        db_query("INSERT INTO {page_title} VALUES (%d, '%s')", $node->nid, $node->page_title);
+        db_query('INSERT INTO {page_title} VALUES ("node", %d, "%s")', $node->nid, $node->page_title);
       }
       break;
 
     case 'delete':
-      db_query('DELETE FROM {page_title} WHERE nid = %d', $node->nid);
+      db_query('DELETE FROM {page_title} WHERE type = "node" AND nid = %d', $node->nid);
       break;
 
     case 'load':
-      return array('page_title' => page_title_node_get_title($node->nid));
-
+      return array('page_title' => page_title_node_get_title('node', $node->nid));
+    
+    case 'prepare' :
+      page_title_cache_info(array(
+        'type' => 'node',
+        'node_type' => $node->type,
+        'page_title' => $node->page_title,
+      ));
+      break;
+      
     case 'view':
       if ($page && !$teaser) {
-        page_title_set_node($node);
+        page_title_cache_info(array(
+          'type' => 'node',
+          'node_type' => $node->type,
+          'page_title' => $node->page_title,
+        ));
       }
       break;
   }
 }
 
+
+/**
+ * Implementation of hook_views_pre_view (from views.module)
+ */
+function page_title_views_pre_view($view, $items) {
+  $page_title = page_title_node_get_title('view', $view->vid);
+
+  page_title_cache_info(array(
+    'type' => 'view',
+    'page_title' => $page_title,
+  ));
+}
+
+
 /**
- * Sets or retrieves the page title of the current page.
+ * Sets or retrieves the page title data of the current page.
  *
- * @param $settings
+ * @param $data
  *   array The page title to set and content type.
- * @return
- *   string The settings array.
+ * @return array The cached data array
  */
-function page_title_set_node($node = NULL) {
-  static $stored_node = NULL;
+function page_title_cache_info($data = NULL) {
+  static $cache = NULL;
 
-  if (isset($node)) {
-    $stored_node = $node;
+  if (isset($data)) {
+    $cache = $data;
   }
-  return $stored_node;
+  return $cache;
 }
 
+
 /**
  * Simple wrapper function to get the currently set title for a page
  *
- * @return unknown
+ * @return string
  */
 function page_title_get_title() {
   $display_options = variable_get('page_title_display', array());
-  $node = page_title_set_node();
+  $data = page_title_cache_info();
   
-  if ($display_options[$node->type] && !empty($node->page_title)) {
-    return check_plain(strip_tags($node->page_title));
+  if ($data['type'] == 'node' && $display_options[$data['node_type']] && !empty($data['page_title'])) {
+    return check_plain(strip_tags($data['page_title']));
+  }
+  elseif ($data['type'] == 'view' && !empty($data['page_title'])) {
+    return check_plain(strip_tags($data['page_title']));
   }
   else {
     return strip_tags(drupal_get_title());
   }
 }
 
+
 /**
  * Simple wrapper function to get the page type
  *
- * @return unknown
+ * @return string
  */
 function page_title_get_type() {
   $node = page_title_set_node();
@@ -278,8 +359,6 @@ function page_title_get_type() {
 }
 
 
-// Public API (every module's gotta have one =)
-
 /**
  * Gets the page title for a node id.
  *
@@ -288,18 +367,18 @@ function page_title_get_type() {
  * @return
  *   string The node's page title.
  */
-function page_title_node_get_title($nid) {
-  return db_result(db_query('SELECT page_title FROM {page_title} WHERE nid = %d', $nid));
+function page_title_node_get_title($type = 'node', $nid) {
+  return db_result(db_query('SELECT page_title FROM {page_title} WHERE type = "%s" AND pid = %d', $type, $nid));
 }
 
+
 /**
  * Determines what title should be sent to the page template.
  *
  * Call this function from the page hook of function _phptemplate_variables in
  * template.php.
  *
- * @return
- *   string The page's title.
+ * @return string The page's title.
  */
 function page_title_page_get_title() {
   static $title = NULL;
@@ -312,11 +391,18 @@ function page_title_page_get_title() {
     }
     //Otherwise this is a non-frontpage page title.
     else {
-      //Get the current type for the page being displayed
-      $type = page_title_get_type();
+      //Get cached data
+      $data = page_title_cache_info();
       
-      //Get the pattern for this type
-      $page_title_pattern = variable_get('page_title_type_' . $type, '');
+      //Do the specific page type patterns
+      if ($data['type'] == 'node') {
+        //Get the pattern for this type
+        $page_title_pattern = variable_get('page_title_type_' . $data['node_type'], '');
+        
+      }
+      elseif ($node['type'] == 'view') {
+        //No patterns for views yet... TODO
+      }
       
       //If pattern is emtpy (either if the type is not overridable or simply not set) fallback to the default pattern
       if (empty($page_title_pattern)) {
@@ -331,6 +417,7 @@ function page_title_page_get_title() {
   return $title;
 }
 
+
 /**
  * Implementation of hook_token_values
  *
@@ -350,6 +437,7 @@ function page_title_token_values($type) 
   return $values;
 }
 
+
 /**
  * Implementation of hook_token_list
  *
