? openid_provider-DRUPAL-5.patch
Index: openid_provider.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openid_provider/openid_provider.inc,v
retrieving revision 1.2
diff -u -r1.2 openid_provider.inc
--- openid_provider.inc	26 May 2008 18:20:30 -0000	1.2
+++ openid_provider.inc	8 Jun 2008 16:09:05 -0000
@@ -7,7 +7,7 @@
  * @param array $request
  */
 function openid_provider_association_response($request) {
-  module_load_include('inc', 'openid');
+  include_once drupal_get_path('module', 'openid') .'/openid.inc';
   
   $session_type = $request['openid.session_type'];
   $assoc_type = $request['openid.assoc_type'];
@@ -95,11 +95,11 @@
 
   // Check for a directed identity request.
   if ($request['openid.identity'] == 'http://specs.openid.net/auth/2.0/identifier_select') {
-    $identity = url('user/' . $user->uid, array('absolute' => TRUE));
+    $identity = url('user/'. $user->uid, null, null, true);
   }
   else {
     $identity = $request['openid.identity'];
-    if ($identity != url('user/'. $user->uid, array('absolute' => TRUE))) {
+    if ($identity != url('user/'. $user->uid, null, null, true)) {
       $response = openid_provider_authentication_error($request['openid.mode']);
       openid_redirect($request['openid.return_to'], $response);
     }
@@ -108,7 +108,7 @@
   $response = array(
     'openid.ns' => OPENID_NS_2_0,
     'openid.mode' => 'id_res',
-    'openid.op_endpoint' => url('openid/provider', array('absolute' => TRUE)),
+    'openid.op_endpoint' => url('openid/provider', null, null, true),
     'openid.identity' => $identity,
     'openid.claimed_id' => $identity,
     'openid.return_to' => $request['openid.return_to'],
@@ -148,7 +148,7 @@
   if ($mode == 'checkid_immediate') {
     return array(
       'openid.mode' => 'id_res',
-      'openid.user_setup_url' => url('user/login', NULL, NULL, TRUE)
+      'openid.user_setup_url' => url('user/login', null, null, true)
     );
   }
   else { // checkid_setup
@@ -253,7 +253,7 @@
     $response = array(
       'openid.ns' => OPENID_NS_2_0,
       'openid.mode' => 'id_res',
-      'openid.user_setup_url' => url('user', NULL, NULL, TRUE)
+      'openid.user_setup_url' => url('user', null, null, true)
     );
   }
   else {
@@ -269,7 +269,7 @@
   else {
     $rps = array();
     $result = db_query("SELECT * FROM {openid_provider_relying_party} WHERE uid=%d ORDER BY last_time DESC", $uid);
-    while ($rp = db_fetch_object($result)){
+    while ($rp = db_fetch_object($result)) {
       $rps[] = $rp;
     }
     return $rps;
@@ -295,7 +295,7 @@
 }
 
 function _openid_provider_sign($response) {
-  module_load_include('inc', 'openid');
+  include_once drupal_get_path('module', 'openid') .'/openid.inc';
   
   $also_sign = array();
   $parts = parse_url($response['openid.return_to']);
Index: openid_provider.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openid_provider/openid_provider.info,v
retrieving revision 1.3
diff -u -r1.3 openid_provider.info
--- openid_provider.info	26 May 2008 18:20:30 -0000	1.3
+++ openid_provider.info	8 Jun 2008 16:09:05 -0000
@@ -1,5 +1,6 @@
 ; $Id: openid_provider.info,v 1.3 2008/05/26 18:20:30 walkah Exp $
 name = "Openid Provider"
 description = "OpenID Provider (or server) support allows you to login to other OpenID enabled sites using your local account."
-core = 6.x
-php = 5.2
\ No newline at end of file
+dependencies = openid
+core = 5.x
+php = 5.2
Index: openid_provider.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openid_provider/openid_provider.install,v
retrieving revision 1.2
diff -u -r1.2 openid_provider.install
--- openid_provider.install	1 Jun 2008 03:21:41 -0000	1.2
+++ openid_provider.install	8 Jun 2008 16:09:05 -0000
@@ -31,106 +31,33 @@
  * Implementation of hook_install().
  */
 function openid_provider_install() {
-  // Create tables.
-  drupal_install_schema('openid_provider');
+  db_query("CREATE TABLE {openid_provider_relying_party} (
+    rpid int unsigned not null auto_increment,
+    uid int unsigned not null default 0,
+    realm varchar(255) not null default '',
+    first_time int not null default 0,
+    last_time int not null default 0,
+    auto_release int not null default 0,
+    PRIMARY KEY (rpid),
+    INDEX uid (uid)
+  )");
+     
+
+  db_query("CREATE TABLE {openid_provider_association} (
+    assoc_handle varchar(255) not null default '',
+    assoc_type varchar(32) not null default '',
+    session_type varchar(32) not null default '',
+    mac_key varchar(255) not null default '',
+    created int not null default 0,
+    expires_in int not null default 0,
+    PRIMARY KEY (assoc_handle)
+  )");
 }
 
 /**
  * Implementation of hook_uninstall().
  */
 function openid_provider_uninstall() {
-  // Remove tables.
-  drupal_uninstall_schema('openid_provider');
+  db_query("DROP TABLE {openid_provider_relying_party}");
+  db_query("DROP TABLE {openid_provider_association}");
 }
-
-/**
- * Implementation of hook_schema().
- */
-function openid_provider_schema() {
-  $schema['openid_provider_relying_party'] = array(
-    'description' => t('Tracks relying parties a give user has authenticated.'),
-    'fields' => array(
-      'rpid' => array(
-        'type' => 'serial',
-        'unsigned' => TRUE,
-        'not null' => TRUE
-      ),
-      'uid' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
-        'description' => t('The {users}.uid that has authenticated this relying party.'),
-      ),
-      'realm' => array(
-        'type' => 'varchar',
-        'length' => 255,
-        'not null' => TRUE,
-        'default' => '',
-        'description' => t('The OpenID realm of the authenticated relying party.'),
-      ),
-      'first_time' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
-        'description' => t('Timestamp of the first time this relying party was accessed.')
-      ),
-      'last_time' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
-        'description' => t('Timestamp of the most recent access'),
-      ),
-      'auto_release' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
-        'description' => t('Whether or not to automatically release this relying party.')
-      ),
-    ),
-    'indexes' => array('uid' => array('uid')),
-    'primary key' => array('rpid')
-  );
-
-  $schema['openid_provider_association'] = array(
-    'description' => t('Stores current associaitons with relying parties.'),
-    'fields' => array(
-      'assoc_handle' => array(
-        'type' => 'varchar',
-        'length' => 255,
-        'not null' => TRUE,
-        'default' => ''
-      ),
-      'assoc_type' => array(
-        'type' => 'varchar',
-        'length' => 32,
-        'not null' => TRUE,
-        'default' => ''
-      ),
-      'session_type' => array(
-        'type' => 'varchar',
-        'length' => 32,
-        'not null' => TRUE,
-        'default' => ''
-      ),
-      'mac_key' => array(
-        'type' => 'varchar',
-        'length' => 255,
-        'not null' => TRUE,
-        'default' => ''
-      ),
-      'created' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,        
-      ),
-      'expires_in' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
-      )
-    ),
-    'primary key' => array('assoc_handle')
-  );
-
-  return $schema;
-}
\ No newline at end of file
Index: openid_provider.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openid_provider/openid_provider.module,v
retrieving revision 1.1
diff -u -r1.1 openid_provider.module
--- openid_provider.module	13 Apr 2008 11:53:04 -0000	1.1
+++ openid_provider.module	8 Jun 2008 16:09:05 -0000
@@ -4,6 +4,7 @@
 /**
  * OpenID 2.0 Provider implementation for Drupal.
  */
+include_once dirname(__FILE__) .'/openid_provider.pages.inc';
 
 /**
  * Implementation of hook_perm().
@@ -15,84 +16,82 @@
 /**
  * Implementation of hook_menu().
  */
-function openid_provider_menu() {
-  $items['admin/settings/openid_provider'] = array(
-    'title' => 'OpenID Provider',
-    'description' => 'Configre settings for the OpenID Provider.',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('openid_provider_admin_settings'),
-    'access arguments' => array('administer openid'),
-    'type' => MENU_NORMAL_ITEM,
-  );
-  
-  $items['openid/provider'] = array(
-    'title' => 'OpenID Login',
-    'page callback' => 'openid_provider_endpoint',
-    'access callback' => TRUE,
-    'type' => MENU_CALLBACK,
-    'file' => 'openid_provider.pages.inc'
-  );
-  
-  $items['openid/provider/send'] = array(
-    'title' => 'OpenID Login',
-    'page callback' => 'openid_provider_send',
-    'access callback' => TRUE,
-    'type' => MENU_CALLBACK,
-    'file' => 'openid_provider.pages.inc'
-  );
-
-  $items['openid/provider/continue'] = array(
-    'title' => 'OpenID Login',
-    'page callback' => 'openid_provider_continue',
-    'access callback' => TRUE,
-    'type' => MENU_CALLBACK,
-    'file' => 'openid_provider.pages.inc'
-  );
-  
-
-  $items['openid/xrds'] = array(
-    'page callback' => 'openid_provider_xrds',
-    'access callback' => TRUE,
-    'type' => MENU_CALLBACK
-  );
-
-  $items['user/%user/xrds'] = array(
-    'page callback' => 'openid_provider_xrds',
-    'page arguments' => array(1),
-    'access callback' => TRUE,
-    'type' => MENU_CALLBACK
-  );
-  
-  $items['user/%user/openid_sites'] = array(
-    'title' => 'OpenID Sites',
-    'page callback' => 'openid_provider_sites',
-    'page arguments' => array(1),
-    'access callback' => TRUE,
-    'type' => MENU_LOCAL_TASK,
-    'file' => 'openid_provider.pages.inc'
-  );
-
-  return $items;
-}
-
-/**
- * Implementation of hook_init()
- *
- * Add appropriate HTML headers for XRDS and Link discovery.
- */
-function openid_provider_init() {
-  // Not all OpenID clients may be smart enough to do XRDS.
-  drupal_add_link(array('rel' => 'openid2.provider', 'href' => url('openid/provider', array('absolute' => TRUE))));
-  drupal_add_link(array('rel' => 'openid.server', 'href' => url('openid/provider', array('absolute' => TRUE))));
-
-  if (arg(0) == 'user' && is_numeric(arg(1))) {
-    drupal_set_header('X-XRDS-Location: '. url('user/' . arg(1) . '/xrds', array('absolute' => TRUE)));
-    drupal_set_html_head('<meta http-equiv="X-XRDS-Location" content="' . url('user/' . arg(1) . '/xrds', array('absolute' => TRUE)) . '" />');
+function openid_provider_menu($may_cache) {
+  $items = array();
+  if ($may_cache) {
+    $items[] = array(
+      'path' => 'admin/settings/openid_provider',
+      'title' => 'OpenID Provider',
+      'description' => 'Configure settings for the OpenID Provider.',
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('openid_provider_admin_settings'),
+      'access' => array('administer openid'),
+      'type' => MENU_NORMAL_ITEM,
+    );
+  
+    $items[] = array(
+      'path' => 'openid/provider',
+      'title' => 'OpenID Login',
+      'callback' => 'openid_provider_endpoint',
+      'access' => TRUE,
+      'type' => MENU_CALLBACK,
+    );
+  
+    $items[] = array(
+      'path' => 'openid/provider/send',
+      'title' => 'OpenID Login',
+      'callback' => 'openid_provider_send',
+      'access' => TRUE,
+      'type' => MENU_CALLBACK,
+    );
+
+    $items[] = array(
+      'path' => 'openid/provider/continue',
+      'title' => 'OpenID Login',
+      'callback' => 'openid_provider_continue',
+      'access' => TRUE,
+      'type' => MENU_CALLBACK,
+    );
+  
+
+    $items[] = array(
+      'path' => 'openid/xrds',
+      'callback' => 'openid_provider_xrds',
+      'access' => TRUE,
+      'type' => MENU_CALLBACK
+    );
   }
   else {
-    drupal_set_header('X-XRDS-Location: '. url('openid/xrds', array('absolute' => TRUE)));
-    drupal_set_html_head('<meta http-equiv="X-XRDS-Location" content="' . url('openid/xrds', array('absolute' => TRUE)) . '" />');
-  }  
+    if (arg(0) == 'user' && is_numeric(arg(1)) && $account = user_load(array('uid' => arg(1)))) {
+      $items[] = array(
+        'path' => 'user/'. $account->uid .'/xrds',
+        'callback' => 'openid_provider_xrds',
+        'callback arguments' => array(1),
+        'access callback' => TRUE,
+        'type' => MENU_CALLBACK
+      );
+  
+      $items[] = array(
+        'path' => 'user/'. $account->uid .'/openid_sites',
+        'title' => 'OpenID Sites',
+        'callback' => 'openid_provider_sites',
+        'callback arguments' => array(1),
+        'access' => TRUE,
+        'type' => MENU_LOCAL_TASK,
+      );
+
+      drupal_set_header('X-XRDS-Location: '. url('user/'. arg(1) .'/xrds', null, null, true));
+      drupal_set_html_head('<meta http-equiv="X-XRDS-Location" content="'. url('user/'. arg(1) .'/xrds', null, null, true) .'" />');
+    }
+    else {
+      drupal_set_header('X-XRDS-Location: '. url('openid/xrds', null, null, true));
+      drupal_set_html_head('<meta http-equiv="X-XRDS-Location" content="'. url('openid/xrds', null, null, true) .'" />');
+    }
+    // Not all OpenID clients may be smart enough to do XRDS.
+    drupal_add_link(array('rel' => 'openid2.provider', 'href' => url('openid/provider', null, null, true)));
+    drupal_add_link(array('rel' => 'openid.server', 'href' => url('openid/provider', null, null, true)));
+  }
+  return $items;
 }
 
 /**
@@ -104,12 +103,14 @@
   switch ($op) {
     case 'view':
       if ($user->uid == $account->uid) {
-        $account->content['openid'] = array(
-          '#title' => t('OpenID'),
-          '#value' => t('You may login to other OpenID enabled sites using %url', array('%url' => url('user/' . $account->uid, array('absolute' => TRUE)))),
-          '#class' => 'openid',
-          '#weight' => 10
+        $items = array();
+        $items['openid'] = array(
+          'title' => t('OpenID'),
+          'value' => t('You may login to other OpenID enabled sites using %url', array('%url' => url('user/'. $account->uid, null, null, TRUE))),
+          'class' => 'openid',
+          'weight' => 10
         );
+        return array(t('Open ID') => $items);
       }
       break;
   }
@@ -133,7 +134,7 @@
  * Return a XRDS for this server to discover it based on the root url
  */
 function openid_provider_xrds($account = NULL) {
-  module_load_include('inc', 'openid');
+  include_once(drupal_get_path('module', 'openid') .'/openid.inc');
   
   if ($account) {
     $types = array(OPENID_NS_2_0 .'/signon');
@@ -150,9 +151,9 @@
   foreach ($types as $type) {
     $xrds .= '<Type>'. $type .'</Type>';
   }
-  $xrds .= '<URI>' . url('openid/provider', array('absolute'=> TRUE)) . '</URI>';
+  $xrds .= '<URI>'. url('openid/provider', NULL, NULL, TRUE) .'</URI>';
   if ($account->uid) {
-      $xrds .= '<LocalID>' . url('user/'. $account->uid, array('absolute' => TRUE)) . '</LocalID>';
+      $xrds .= '<LocalID>'. url('user/'. $account->uid, NULL, NULL, TRUE) .'</LocalID>';
   }
   $xrds .= '</Service>';
   $xrds .= '</XRD>';
@@ -165,29 +166,42 @@
 /**
  * Main OpenID Provider form
  */
-function openid_provider_form(&$form_state, &$response = array(), $realm = NULL) {
+function openid_provider_form(&$response = array(), $realm = NULL) {
   global $user;
 
-  // Use form_state to store the $response and $realm values 
-  if (count($response)) {
-    $form_state['storage']['response'] = $response;
-  }
-  else {
-    $response = $form_state['storage']['response'];
-  }
-  
-  if ($realm) {
-    $form_state['storage']['realm'] = $realm;
-  }
-  else {
-    $realm = $form_state['storage']['realm'];
-  }
-  
   $form = array();
+ 
+  // A dirty hack to persist variables for one form rebuilding.
+  // We can probably do something more sensible in #after_build using 
+  // the form token as an id for $_SESSION.
+  if (!empty($response)) {
+    $_SESSION['openid_provider_form']['response'] = $response;
+  }
+  elseif (isset($_SESSION['openid_provider_form']['response'])) {
+    $response = $_SESSION['openid_provider_form']['response'];
+    unset($_SESSION['openid_provider_form']['response']);
+  }
+
+  if (!empty($realm)) {
+    $_SESSION['openid_provider_form']['realm'] = $realm;
+  }
+  elseif (isset($_SESSION['openid_provider_form']['realm'])) {
+    $realm = $_SESSION['openid_provider_form']['realm'];
+    unset($_SESSION['openid_provider_form']['realm']);
+  }
+  // Use form_state to store the $response and $realm values 
+  $form['response'] = array(
+    '#type' => 'value', 
+    '#value' => $response,
+  );
   
+  $form['realm'] = array(
+    '#type' => 'value',
+    '#value' => $realm,
+  );
   $form['intro'] = array(
     '#type' => 'markup',
-    '#value' => '<p>'. t('You are being logged into %site, would you like to continue?', array('%site' => $realm)) . '</p>'
+    '#value' => '<p>'. t('You are being logged into %site, would you like to continue?', array('%site' => $realm)) .'</p>'
   );
   
   $form['#action'] = url('openid/provider/send');
@@ -206,39 +220,38 @@
     '#value' => t('Cancel'),
     '#submit' => array('openid_provider_form_submit_cancel')
   );
-
   return $form;
 }
 
 /**
  * Once submit handler
  */
-function openid_provider_form_submit(&$form, $form_state, $auto_release = FALSE) {
+function openid_provider_form_submit($id, &$values, $auto_release = FALSE) {
   global $user;
 
-  module_load_include('inc', 'openid');
-  module_load_include('inc', 'openid_provider');
+  include_once(drupal_get_path('module', 'openid') .'/openid.inc');
+  include_once(drupal_get_path('module', 'openid_provider') .'/openid_provider.inc');
   
-  $response = _openid_provider_sign($form_state['storage']['response']);
-  _openid_provider_rp_save($user->uid, $form_state['storage']['realm'], $auto_release);
+  $response = _openid_provider_sign($values['response']);
+  _openid_provider_rp_save($user->uid, $values['realm'], $auto_release);
   openid_redirect_http($response['openid.return_to'], $response);
 }
 
 /**
  * Always submit handler
  */
-function openid_provider_form_submit_always(&$form, $form_state) {
-  return openid_provider_form_submit($form, $form_state, TRUE);
+function openid_provider_form_submit_always($id, $values) {
+  return openid_provider_form_submit($id, $values, TRUE);
 }
  
 /**
  * Cancel submit handler
  */
-function openid_provider_form_submit_cancel(&$form, $form_state) {
-  module_load_include('inc', 'openid_provider');
-  module_load_include('inc', 'openid');
+function openid_provider_form_submit_cancel(&$id, $values) {
+  include_once(drupal_get_path('module', 'openid') .'/openid.inc');
+  include_once(drupal_get_path('module', 'openid_provider') .'/openid_provider.inc');
   
-  $return_to = $form_state['values']['openid.return_to'];
-  $response = openid_provider_cancel_authentication_response($form_state['openid.mode']);
+  $return_to = $values['openid.return_to'];
+  $response = openid_provider_cancel_authentication_response($values['openid.mode']);
   openid_redirect($return_to, $response);
 }
Index: openid_provider.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openid_provider/openid_provider.pages.inc,v
retrieving revision 1.1
diff -u -r1.1 openid_provider.pages.inc
--- openid_provider.pages.inc	13 Apr 2008 11:53:04 -0000	1.1
+++ openid_provider.pages.inc	8 Jun 2008 16:09:05 -0000
@@ -12,8 +12,8 @@
  * @param array $request (Optional) request parameters.
  */
 function openid_provider_endpoint($request = array()) {
-  module_load_include('inc', 'openid');
-  module_load_include('inc', 'openid_provider');
+  include_once(drupal_get_path('module', 'openid') .'/openid.inc');
+  include_once(drupal_get_path('module', 'openid_provider') .'/openid_provider.inc');
 
   if (count($request) == 0) {
     $request = _openid_response();
@@ -40,7 +40,7 @@
  * have a valid local session
  */
 function openid_provider_continue() {
-  module_load_include('inc', 'openid');
+  include_once(drupal_get_path('module', 'openid') .'/openid.inc');
   
   if (isset($_SESSION['openid_provider']['request'])) {
     $request = $_SESSION['openid_provider']['request'];
@@ -77,11 +77,13 @@
 function openid_provider_sites_form() {
   global $user;
   
-  module_load_include('inc', 'openid_provider');
+  include_once(drupal_get_path('module', 'openid_provider') .'/openid_provider.inc');
   
   $rps = _openid_provider_rp_load($user->uid);
   if (count($rps)) {
-    $form = array('#tree' => TRUE);
+    $form = array(
+      '#tree' => TRUE,
+    );
     foreach ($rps as $rp) {
       $form['rpid'][$rp->rpid] = array(
         '#type' => 'checkbox',
@@ -105,8 +107,8 @@
 /**
  * Form submit callback for openid_provider_sites.
  */
-function openid_provider_sites_form_submit(&$form, &$form_state) {
-  foreach ($form_state['values']['rpid'] as $key => $value) {
+function openid_provider_sites_form_submit(&$id, &$values) {
+  foreach ($values['rpid'] as $key => $value) {
     db_query("UPDATE {openid_provider_relying_party} SET auto_release=%d WHERE rpid=%d", $value, $key);
   }
   drupal_set_message(t('Settings saved.'));
