diff --git a/jiraconnect.info b/jiraconnect.info index ab29045..4d36b5b 100644 --- a/jiraconnect.info +++ b/jiraconnect.info @@ -1,6 +1,5 @@ name = JIRA Connect description = Connects JIRA user base to Drupal core = 6.x -project = jiraconnect package = Authentication -php = 5.0 \ No newline at end of file +php = 5.0 diff --git a/jiraconnect.module b/jiraconnect.module index e26ec4f..672f90a 100644 --- a/jiraconnect.module +++ b/jiraconnect.module @@ -1,16 +1,22 @@ 'JIRA Connect', - 'description' => 'Configures the JIRA Connect module.', + 'description' => 'Configures the JIRA Connect module.', 'page callback' => 'drupal_get_form', 'page arguments' => array('jiraconnect_admin_settings'), 'access arguments' => array('administer site configuration'), @@ -20,21 +26,25 @@ function jiraconnect_menu() { } /** - * Implementation of hook_user() + * Implementation of hook user() * * @param string $op + * Output of the given content. * @param array $edit + * Edit for the user. * @param array $account + * Account of the current user. * @param string $category + * Category of all types. */ -function jiraconnect_user($op, &$edit, &$account, $category = NULL) { - global $jiraconnect_auth, $jira_user; +function jiraconnect_user($op, array &$edit, array &$account, $category = NULL) { + global $_jiraconnect_auth, $_jira_user; - switch($op) { + switch ($op) { case 'insert': - if($jiraconnect_auth){ + if ($_jiraconnect_auth) { $edit['jiraconnect'] = TRUE; - db_query('UPDATE {users} SET mail = "%s" WHERE uid = %d', $jira_user->email, $account->uid); + db_query('UPDATE {users} SET mail = "%s" WHERE uid = %d', $_jira_user->email, $account->uid); $edit['mail'] = NULL; } } @@ -42,28 +52,24 @@ function jiraconnect_user($op, &$edit, &$account, $category = NULL) { } /** - * Implementation of hook_form_later(). + * Implementation of hook form later(). * * Overrides validation for the login form. - * - * @param unknown_type $form - * @param unknown_type $form_state - * @param unknown_type $form_id */ function jiraconnect_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'user_login_block' || $form_id == 'user_login') { - // Looking for the original user authentication funct + // Looking for the original user authentication funct. $array_key = array_search('user_login_authenticate_validate', $form['#validate']); // Can't find it. I'll rebuild the #validate array with my - // function called just before the final validator - if($array_key === FALSE){ + // function called just before the final validator. + if ($array_key === FALSE) { $final_validator = array_pop($form['#validate']); $form['#validate'][] = 'jiraconnect_login_validate'; $form['#validate'][] = $final_validator; } else { - // Found it, now to do the swap + // Found it, now to do the swap. $form['#validate'][$array_key] = 'jiraconnect_login_validate'; } } @@ -85,7 +91,8 @@ function jiraconnect_form_alter(&$form, $form_state, $form_id) { /** * Renders the JIRAConnect settings form. * - * @return array The settings form. + * @return array + * The settings form. */ function jiraconnect_admin_settings() { $form['jiraconnect_jiraurl'] = array( @@ -102,46 +109,53 @@ function jiraconnect_admin_settings() { * Validation hook for the login form. * * @param string $form + * The form. * @param array $form_state + * The current state of the form. */ -function jiraconnect_login_validate($form, &$form_state) { - global $jiraconnect_auth; +function jiraconnect_login_validate($form, array &$form_state) { + global $_jiraconnect_auth; $result = jiraconnect_login($form_state['values']['name'], $form_state['values']['pass']); if ($result !== TRUE) { - $jiraconnect_auth = FALSE; + $_jiraconnect_auth = FALSE; user_authenticate($form_state['values']); } else { - $jiraconnect_auth = TRUE; + $_jiraconnect_auth = TRUE; user_external_login_register($form_state['values']['name'], 'jiraconnect'); - user_authenticate_finalize($form_state['values']); + user_authenticate_finalize($form_state['values']); } } /** * Logs a user in via JIRA SOAP interface. * - * @param string $username The JIRA username. - * @param string $password The JIRA password. - * @return boolean TRUE if the login was successful. + * @param string $username + * The JIRA username. + * @param string $password + * The JIRA password. + * + * @return bool + * TRUE if the login was successful. */ function jiraconnect_login($username, $password) { - global $jira_user; + global $_jira_user; - $wsdl_file = file_directory_temp().DIRECTORY_SEPARATOR."jirasoapservice-v2.wsdl"; + $wsdl_file = file_directory_temp() . DIRECTORY_SEPARATOR . "jirasoapservice-v2.wsdl"; if (!file_exists($wsdl_file)) { watchdog('jiraconnect', 'The JIRA url is empty!', array(), WATCHDOG_WARNING, 'admin/settings/jiraconnect'); return FALSE; } try { - $jira = new SoapClient('file://'.$wsdl_file); + $jira = new SoapClient('file://' . $wsdl_file); $auth = $jira->login($username, $password); - $jira_user = $jira->getUser($auth, $username); + $_jira_user = $jira->getUser($auth, $username); return TRUE; - } catch(SoapFault $fault) { + } + catch (SoapFault $fault) { watchdog('jiraconnect', 'SOAP call failed: !response', array('!response' => $fault->getMessage()), WATCHDOG_ERROR); } @@ -150,15 +164,16 @@ function jiraconnect_login($username, $password) { /** * Custom validator for the admin settings. - * HACK: We need to cache the WSDL manually (see http://bugs.php.net/bug.php?id=48216) * * @param string $form + * The form. * @param array $form_state + * The current state of the form. */ -function jiraconnect_check_wsdl($form, &$form_state) { - $jira_url = $form_state['values']['jiraconnect_jiraurl'].'/rpc/soap/jirasoapservice-v2?wsdl'; +function jiraconnect_check_wsdl($form, array &$form_state) { + $jira_url = $form_state['values']['jiraconnect_jiraurl'] . '/rpc/soap/jirasoapservice-v2?wsdl'; - $wsdl_file = file_directory_temp().DIRECTORY_SEPARATOR."jirasoapservice-v2.wsdl"; + $wsdl_file = file_directory_temp() . DIRECTORY_SEPARATOR . "jirasoapservice-v2.wsdl"; $jira_handler = curl_init($jira_url); $wsdl_handler = fopen($wsdl_file, 'w'); curl_setopt($jira_handler, CURLOPT_FILE, $wsdl_handler); @@ -166,4 +181,4 @@ function jiraconnect_check_wsdl($form, &$form_state) { curl_exec($jira_handler); curl_close($jira_handler); fclose($wsdl_handler); -} \ No newline at end of file +}