'
', ); } // Decide on a default backend. if (isset($form_state['values']['connection_settings']['authorize_filetransfer_default'])) { $authorize_filetransfer_default = $form_state['values']['connection_settings']['authorize_filetransfer_default']; } elseif ($authorize_filetransfer_default = variable_get('authorize_filetransfer_default', NULL)); else { $authorize_filetransfer_default = key($available_backends); } $form['information']['main_header'] = array( '#prefix' => '' . $e->getMessage() . '
', '@handbook_url' => 'http://drupal.org/documentation/install/modules-themes', ))); } } } /** * Form submission handler for authorize_filetransfer_form(). * * @see authorize_filetransfer_form() * @see authorize_filetransfer_validate() */ function authorize_filetransfer_form_submit($form, &$form_state) { global $base_url; switch ($form_state['triggering_element']['#name']) { case 'process_updates': // Save the connection settings to the DB. $filetransfer_backend = $form_state['values']['connection_settings']['authorize_filetransfer_default']; // If the database is available then try to save our settings. We have // to make sure it is available since this code could potentially (will // likely) be called during the installation process, before the // database is set up. try { $connection_settings = array(); foreach ($form_state['values']['connection_settings'][$filetransfer_backend] as $key => $value) { // We do *not* want to store passwords in the database, unless the // backend explicitly says so via the magic #filetransfer_save form // property. Otherwise, we store everything that's not explicitly // marked with #filetransfer_save set to FALSE. if (!isset($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save'])) { if ($form['connection_settings'][$filetransfer_backend][$key]['#type'] != 'password') { $connection_settings[$key] = $value; } } // The attribute is defined, so only save if set to TRUE. elseif ($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save']) { $connection_settings[$key] = $value; } } // Set this one as the default authorize method. variable_set('authorize_filetransfer_default', $filetransfer_backend); // Save the connection settings minus the password. variable_set('authorize_filetransfer_connection_settings_' . $filetransfer_backend, $connection_settings); $filetransfer = authorize_get_filetransfer($filetransfer_backend, $form_state['values']['connection_settings'][$filetransfer_backend]); // Now run the operation. authorize_run_operation($filetransfer); } catch (Exception $e) { // If there is no database available, we don't care and just skip // this part entirely. } break; case 'enter_connection_settings': $form_state['rebuild'] = TRUE; break; case 'change_connection_type': $form_state['rebuild'] = TRUE; unset($form_state['values']['connection_settings']['authorize_filetransfer_default']); break; } } /** * Runs the operation specified in $_SESSION['authorize_operation']. * * @param $filetransfer * The FileTransfer object to use for running the operation. */ function authorize_run_operation($filetransfer) { $operation = $_SESSION['authorize_operation']; unset($_SESSION['authorize_operation']); if (!empty($operation['page_title'])) { drupal_set_title($operation['page_title']); } require_once DRUPAL_ROOT . '/' . $operation['file']; call_user_func_array($operation['callback'], array_merge(array($filetransfer), $operation['arguments'])); } /** * Gets a FileTransfer class for a specific transfer method and settings. * * @param $backend * The FileTransfer backend to get the class for. * @param $settings * Array of settings for the FileTransfer. * * @return * An instantiated FileTransfer object for the requested method and settings, * or FALSE if there was an error finding or instantiating it. */ function authorize_get_filetransfer($backend, $settings = array()) { $filetransfer = FALSE; if (!empty($_SESSION['authorize_filetransfer_info'][$backend])) { $backend_info = $_SESSION['authorize_filetransfer_info'][$backend]; if (!empty($backend_info['file'])) { $file = $backend_info['file path'] . '/' . $backend_info['file']; require_once $file; } if (class_exists($backend_info['class'])) { // PHP 5.2 doesn't support $class::factory() syntax, so we have to // use call_user_func_array() until we can require PHP 5.3. $filetransfer = call_user_func_array(array($backend_info['class'], 'factory'), array(DRUPAL_ROOT, $settings)); } } return $filetransfer; }