Index: README.txt
===================================================================
RCS file: README.txt
diff -N README.txt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ README.txt	24 Oct 2008 20:37:03 -0000
@@ -0,0 +1,23 @@
+$Id$
+
+Description
+===========
+Allows users to display their latest location from Fire Eagle on their profile.
+
+Installation
+============
+1. Place the module in your module directory.
+2. Download OAuth.php and fireeagle.php from the following URL:
+
+    http://github.com/myelin/fireeagle-php-lib/tree/master/lib
+
+3. Place OAuth.php and fireeagle.php in this module's directory.
+4. Register your Fire Eagle application at the following URL:
+
+    https://fireeagle.yahoo.net/developer/create
+
+5. Set the callback URL on your application based on the following URL:
+
+    http://www.example.com/fireeagle/callback
+    
+6. Configure the module at admin/settings/fire-eagle
\ No newline at end of file
Index: fireeagle.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/fireeagle/fireeagle.module,v
retrieving revision 1.2
diff -u -r1.2 fireeagle.module
--- fireeagle.module	24 Aug 2008 04:16:40 -0000	1.2
+++ fireeagle.module	24 Oct 2008 20:37:04 -0000
@@ -1,9 +1,6 @@
 <?php
 // $Id: fireeagle.module,v 1.2 2008/08/24 04:16:40 walkah Exp $
 
-define('FIREEAGLE_KEY', 'JWm42d5LcsXL');
-define('FIREEAGLE_SECRET', 'vzSnGC2MaFYngAvo7hcXqqvLQ2xVHs5K');
-define('FIREEAGLE_CACHE', 3600);
 /**
  * Implementation of hook_menu().
  */
@@ -11,50 +8,99 @@
   $items = array();
   
   $items['fireeagle/start'] = array(
-    'title' => 'fire eagle',
     'page callback' => 'fireeagle_auth_start',
-    'access callback' => TRUE,
+    'access arguments' => array('set up fire eagle'),
     'file' => 'fireeagle.pages.inc',
     'type' => MENU_CALLBACK
   );
 
   $items['fireeagle/callback'] = array(
-    'title' => 'fire eagle',
     'page callback' => 'fireeagle_auth_callback',
-    'access callback' => TRUE,
+    'access arguments' => array('set up fire eagle'),
     'file' => 'fireeagle.pages.inc',
     'type' => MENU_CALLBACK
   );
   
+  $items['fireeagle/remove'] = array(
+    'page callback' => 'fireeagle_auth_remove',
+    'access arguments' => array('set up fire eagle'),
+    'file' => 'fireeagle.pages.inc',
+    'type' => MENU_CALLBACK
+  );
+  
+  $items['admin/settings/fire-eagle'] = array(
+    'title' => 'Fire Eagle',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('fireeagle_admin_form'),
+    'access arguments' => array('administer fire eagle'),
+    'file' => 'fireeagle.pages.inc',
+  );
+  
   return $items;
 }
 
+/**
+ * Implementation of hook_perm().
+ */
+function fireeagle_perm() {
+  return array('set up fire eagle', 'administer fire eagle');
+}
+
+/**
+ * Implementation of hook_help().
+ */
+function fireeagle_help($path, $arg) {
+  switch ($path) {
+    case 'admin/settings/fire-eagle':
+      $output = '<p>' . t('Enter the keys that Fire Eagle issued for your application. You must !register_link in order to receive these keys.', array('!register_link' => l('register your application', 'https://fireeagle.yahoo.net/developer/create'))) . '</p>';
+  }
+  
+  return $output;
+}
+
+/**
+ * Implementation of hook_user().
+ */
 function fireeagle_user($op, &$edit, &$account) {
   switch ($op) {
-    case 'view':
-      $location = fireeagle_get_user_location($account);
-      if (!$location) {
-        drupal_add_js(drupal_get_path('module', 'fireeagle'). '/fireeagle.js');
-        $value = l(t('Connect to Fire Eagle'), 'fireeagle/start', array('attributes' => array('id' => 'fireeagle-start')));
-        $value .= l(t('Complete connection Fire Eagle'), 'fireeagle/callback', array('query' => 'destination=user/'. $account->uid,
-                                                                                     'attributes' => array('id' => 'fireeagle-callback')));
+    case 'form':
+      $form = array();
+      
+      $form['fireeagle'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Fire Eagle'),
+        '#description' => t('Display your Fire Eagle location on your profile.'),
+        '#collapsible' => TRUE,
+        '#access' => user_access('set up fire eagle'),
+      );
+      
+      $form['fireeagle']['fireeagle_setup'] = array(
+        '#value' => l(t('Setup Fire Eagle'), 'fireeagle/start'),
+      );
+      
+      if ($location = fireeagle_get_user_location($account)) {
+        $form['fireeagle']['fireeagle_remove'] = array(
+          '#value' => l(t('Delete & start over'), 'fireeagle/remove'),
+        );
       }
-      else {
-        $value = theme('fireeagle_location', $location);
+      
+      return $form;
+    case 'view':
+      if ($location = fireeagle_get_user_location($account)) {
+        $account->content['summary']['fireeagle'] = array(
+          '#type' => 'user_profile_item',
+          '#title' => t('Current location'),
+          '#value' => theme('fireeagle_location', $location),
+          '#class' => 'fireeagle',
+          '#weight' => 10,
+        );
       }
-      $account->content['summary']['fireeagle'] = array(
-        '#type' => 'user_profile_item',
-        '#title' => t('Current location'),
-        '#value' => $value,
-        '#class' => 'fireeagle',
-        '#weight' => 10
-      );
       break;
   }
 }
 
 function fireeagle_get_user_location($account) {
-  $location = db_fetch_object(db_query("SELECT * FROM {fireeagle_user} fu LEFT JOIN {fireeagle} f ON f.place_id=fu.place_id WHERE uid=%d AND fu.last_update > %d", $account->uid, time() - FIREEAGLE_CACHE));
+  $location = db_fetch_object(db_query("SELECT * FROM {fireeagle_user} fu LEFT JOIN {fireeagle} f ON f.place_id=fu.place_id WHERE uid=%d AND fu.last_update > %d", $account->uid, time() - variable_get('fireeagle_cache_lifetime', 3600)));
   if ($location->place_id) {
     return $location;
   }
@@ -69,7 +115,7 @@
   $auth = db_fetch_object(db_query("SELECT * FROM {fireeagle_user} WHERE uid=%d", $account->uid));
 
   if ($auth->uid) {
-    $fe = new FireEagle(FIREEAGLE_KEY, FIREEAGLE_SECRET, $auth->oauth_token, $auth->oauth_token_secret);
+    $fe = new FireEagle(variable_get('fireeagle_consumer_key', ''), variable_get('fireeagle_secret_key', ''), $auth->oauth_token, $auth->oauth_token_secret);
     $loc = $fe->user();
     
     $location =  $loc->user->best_guess;
@@ -107,5 +153,4 @@
   $output .= ' ('. t('@time ago', array('@time' => format_interval(time() - strtotime($location->located_at)))) .')';
   
   return $output;
-}
-
+}
\ No newline at end of file
Index: fireeagle.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/fireeagle/fireeagle.pages.inc,v
retrieving revision 1.2
diff -u -r1.2 fireeagle.pages.inc
--- fireeagle.pages.inc	24 Aug 2008 04:16:40 -0000	1.2
+++ fireeagle.pages.inc	24 Oct 2008 20:37:04 -0000
@@ -5,42 +5,82 @@
   global $user;
   module_load_include('php', 'fireeagle');
 
-  $fe = new FireEagle(FIREEAGLE_KEY, FIREEAGLE_SECRET);
+  $fe = new FireEagle(variable_get('fireeagle_consumer_key', ''), variable_get('fireeagle_secret_key', ''));
   $tok = $fe->getRequestToken();
   if (!isset($tok['oauth_token'])
       || !is_string($tok['oauth_token'])
       || !isset($tok['oauth_token_secret'])
       || !is_string($tok['oauth_token_secret'])) {
     watchdog('error', t('ERROR! FireEagle::getRequestToken() returned an invalid response.  Giving up.'));
-    drupal_goto();
+    drupal_set_message(t('An error occured while connecting to Fire Eagle.'), 'error');
+    drupal_goto('user');
   }
-  $_SESSION['fireeagle']['auth_state'] = "start";
+
   $_SESSION['fireeagle']['request_token'] = $token = $tok['oauth_token'];
   $_SESSION['fireeagle']['request_secret'] = $tok['oauth_token_secret'];
-  drupal_set_header("Location: ".$fe->getAuthorizeURL($token));
+  drupal_goto($fe->getAuthorizeURL($token));
 }
 
 function fireeagle_auth_callback() {
   global $user;
   module_load_include('php', 'fireeagle');
 
-  if (empty($_SESSION['fireeagle']['auth_state']) || $_SESSION['fireeagle']['auth_state'] != "start") {
-    drupal_set_message(t('Fire eagle authentication request out of sequence.'), 'error');
-    return;
+  if ($_GET['oauth_token'] && ($_GET['oauth_token'] == $_SESSION['fireeagle']['request_token'])) {
+    $fe = new FireEagle(variable_get('fireeagle_consumer_key', ''), variable_get('fireeagle_secret_key', ''), $_SESSION['fireeagle']['request_token'], $_SESSION['fireeagle']['request_secret']);
+    $tok = $fe->getAccessToken();
+    if (!isset($tok['oauth_token']) || !is_string($tok['oauth_token'])
+        || !isset($tok['oauth_token_secret']) || !is_string($tok['oauth_token_secret'])) {
+      watchdog('error', t('Bad token from FireEagle::getAccessToken().'));
+      drupal_set_message(t('Fire eagle returned an invaled response.'), 'error');
+      return;
+    }
+  
+    unset($_SESSION['fireeagle']);
+    db_query("DELETE FROM {fireeagle_user} WHERE uid=%d", $user->uid);
+    db_query("INSERT INTO {fireeagle_user} (uid, oauth_token, oauth_token_secret) VALUES (%d, '%s', '%s')",
+             $user->uid, $tok['oauth_token'], $tok['oauth_token_secret']);
+    fireeagle_fetch_user_location($user);
+    drupal_goto('user');
   }
-  $fe = new FireEagle(FIREEAGLE_KEY, FIREEAGLE_SECRET, $_SESSION['fireeagle']['request_token'], $_SESSION['fireeagle']['request_secret']);
-  $tok = $fe->getAccessToken();
-  if (!isset($tok['oauth_token']) || !is_string($tok['oauth_token'])
-      || !isset($tok['oauth_token_secret']) || !is_string($tok['oauth_token_secret'])) {
-    watchdog('error', t('Bad token from FireEagle::getAccessToken().'));
-    drupal_set_message(t('Fire eagle returned an invaled response.'), 'error');
-    return;
+  else {
+    drupal_not_found();
   }
+}
+
+function fireeagle_auth_remove() {
+  global $user;
+  module_load_include('php', 'fireeagle');
   
-  unset($_SESSION['fireeagle']);
   db_query("DELETE FROM {fireeagle_user} WHERE uid=%d", $user->uid);
-  db_query("INSERT INTO {fireeagle_user} (uid, oauth_token, oauth_token_secret) VALUES (%d, '%s', '%s')",
-           $user->uid, $tok['oauth_token'], $tok['oauth_token_secret']);
-  fireeagle_fetch_user_location($user);
-  drupal_goto();
+  drupal_goto('user');
+}
+
+function fireeagle_admin_form() {
+  $form = array();
+  $form['fireeagle_consumer_key'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Consumer Key'),
+    '#size' => 40,
+    '#maxlength' => 255,
+    '#default_value' => variable_get('fireeagle_consumer_key', ''),
+  );
+  
+  $form['fireeagle_secret_key'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Consumer Secret'),
+    '#size' => 40,
+    '#maxlength' => 255,
+    '#default_value' => variable_get('fireeagle_secret_key', ''),    
+  );
+  
+  $form['fireeagle_cache_lifetime'] = array(
+    '#type' => 'select',
+    '#title' => t('Cache lifetime'),
+    '#description' => t('Specify how frequently location information should be updated from Fire Eagle.'),
+    '#options' => array(900 => t('15 mins'), 1800 => t('30 mins'), 3600 => t('1 hour'), 7200 => t('2 hours')),
+    '#default_value' => variable_get('fireeagle_cache_lifetime', 3600),
+  );
+  
+  
+  return system_settings_form($form);
 }
\ No newline at end of file
