Index: flag_friend_access/flag_friend_access.install
===================================================================
RCS file: flag_friend_access/flag_friend_access.install
diff -N flag_friend_access/flag_friend_access.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ flag_friend_access/flag_friend_access.install	11 Jan 2010 17:30:51 -0000
@@ -0,0 +1,45 @@
+<?php
+// $Id: $
+
+/**
+ * @file flag_friend_access.install
+ */
+
+/**
+ * Implementation of hook_install().
+ */
+function flag_friend_access_install() {
+  drupal_install_schema('flag_friend_access');
+  drupal_set_message(t('The flag_friend_access module was successfully installed.'));
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function flag_friend_access_uninstall() {
+  drupal_uninstall_schema('flag_friend_access');
+  drupal_set_message(t('The flag_friend_access module was successfully uninstalled.'));
+}
+
+/**
+ * schema
+ */
+function flag_friend_access_schema() {
+  $schema['flag_friend_access'] = array(
+    'fields' => array(
+      'uid' => array(
+        'type' => 'int', 
+        'unsigned' => TRUE, 
+        'not null' => TRUE, 
+        'disp-width' => '10'
+      ),
+      'nid' => array(
+        'type' => 'int', 
+        'unsigned' => TRUE, 
+        'not null' => TRUE, 
+        'disp-width' => '10'
+      ),
+    ),
+  );
+  return $schema;
+}
\ No newline at end of file
Index: flag_friend_access/flag_friend_access.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag_friend/flag_friend_access/Attic/flag_friend_access.module,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 flag_friend_access.module
--- flag_friend_access/flag_friend_access.module	3 Jan 2010 21:19:33 -0000	1.1.2.3
+++ flag_friend_access/flag_friend_access.module	11 Jan 2010 17:30:51 -0000
@@ -13,11 +13,10 @@ function flag_friend_access_node_grants(
   // module only controls view operations
   if ($op == 'view') {
     $friends = flag_friend_get_friends($account->uid);
-    $grants['flag_friend'][] = $account->uid;
     if (!empty($friends)) {
       $grants['flag_friend'] = array_keys($friends);
     }
-    $grants['flag_friend'][] = $GLOBALS['user']->uid;
+    $grants['flag_friend'][] = $account->uid;
     return $grants;
   }
 }
@@ -45,7 +44,7 @@ function flag_friend_access_node_access_
  */
 function flag_friend_access_form_alter(&$form, &$form_state, $form_id) {
   // add in a checkbox only if the 
-  if ($form['#node']->type . '_node_form' == $form_id && empty($form['#node']->nid)) {
+  if ($form['#node']->type . '_node_form' == $form_id) {
     // we have a node form alter in our stuff
     $form['flag_friend_control'] = array(
       '#type' => 'fieldset',
@@ -55,6 +54,56 @@ function flag_friend_access_form_alter(&
     $form['flag_friend_control']['flag_friend_access'] = array(
       '#type' => 'checkbox',
       '#title' => t('Only My Friends'),
+      '#default_value' => flag_friend_access_default($form['#node']->nid, 0),
     );
   }
+}
+
+/**
+ * Determine if we have an access entry already recorded.
+ *
+ * @param $nid
+ *   Node id of the node to check.
+ * @param $type
+ *   Integer, either 0 or 1 to determine what is returned.
+ * @return
+ *   Either a user id or boolean.
+ *
+ * @see flag_friend_access_form_alter()
+ * @see flag_friend_access_nodeapi()
+ */
+function flag_friend_access_default($nid, $type) {
+  static $uid;
+  if (!$uid) {
+    $uid = db_result(db_query('SELECT uid FROM {flag_friend_access} WHERE nid = %d', $nid));
+  }
+  switch ($type) {
+    case 0: // boolean
+      return $uid ? TRUE : FALSE;
+      break;
+    case 1: // value
+      return $uid ? $uid : FALSE;
+      break;
+  }
+}
+
+/**
+ * Implementation of hook_nodeapi().
+ */
+function flag_friend_access_nodeapi(&$node, $op) {
+  $access = flag_friend_access_default($node->nid, 1);
+  switch ($op) {
+    case 'load':
+      $node->flag_friend_access = $access;
+      break;
+    case 'update':
+    case 'insert':
+      if ($node->flag_friend_access && !$access) {
+        db_query('INSERT INTO {flag_friend_access} VALUE(%d, %d)', $node->uid, $node->nid);
+      }
+      if (!$node->flag_friend_access && $access) {
+        db_query('DELETE FROM {flag_friend_access} WHERE nid = %d', $node->nid);
+      }
+      break;
+  }
 }
\ No newline at end of file
