123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- <?php
- function authorize_filetransfer_form($form, &$form_state) {
- global $base_url, $is_https;
- $form = array();
-
- $form['#https'] = TRUE;
-
-
- $form['#attached']['js'][] = $base_url . '/misc/authorize.js';
-
- if (empty($_SESSION['authorize_filetransfer_info'])) {
- drupal_set_message(t('Unable to continue, no available methods of file transfer'), 'error');
- return array();
- }
- $available_backends = $_SESSION['authorize_filetransfer_info'];
- if (!$is_https) {
- $form['information']['https_warning'] = array(
- '#prefix' => '<div class="messages error">',
- '#markup' => t('WARNING: You are not using an encrypted connection, so your password will be sent in plain text. <a href="@https-link">Learn more</a>.', array('@https-link' => 'http://drupal.org/https-information')),
- '#suffix' => '</div>',
- );
- }
-
- 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' => '<h3>',
- '#markup' => t('To continue, provide your server connection details'),
- '#suffix' => '</h3>',
- );
- $form['connection_settings']['#tree'] = TRUE;
- $form['connection_settings']['authorize_filetransfer_default'] = array(
- '#type' => 'select',
- '#title' => t('Connection method'),
- '#default_value' => $authorize_filetransfer_default,
- '#weight' => -10,
- );
-
- $form['submit_connection'] = array(
- '#prefix' => "<br style='clear:both'/>",
- '#name' => 'enter_connection_settings',
- '#type' => 'submit',
- '#value' => t('Enter connection settings'),
- '#weight' => 100,
- );
- $form['submit_process'] = array(
- '#name' => 'process_updates',
- '#type' => 'submit',
- '#value' => t('Continue'),
- '#weight' => 100,
- '#attributes' => array('style' => 'display:none'),
- );
-
- foreach ($available_backends as $name => $backend) {
- $form['connection_settings']['authorize_filetransfer_default']['#options'][$name] = $backend['title'];
- $form['connection_settings'][$name] = array(
- '#type' => 'container',
- '#attributes' => array('class' => array("filetransfer-$name", 'filetransfer')),
- );
-
-
- $form['connection_settings'][$name]['header'] = array(
- '#markup' => '<h4>' . t('@backend connection settings', array('@backend' => $backend['title'])) . '</h4>',
- );
- $form['connection_settings'][$name] += _authorize_filetransfer_connection_settings($name);
-
- if (isset($form_state['values']['connection_settings']['authorize_filetransfer_default']) && $form_state['values']['connection_settings']['authorize_filetransfer_default'] == $name) {
-
-
- setcookie('has_js', '', time() - 3600, '/');
- unset($_COOKIE['has_js']);
-
- $form['submit_process']['#attributes'] = array();
- unset($form['submit_connection']);
-
- $form['connection_settings'][$name]['#attributes']['style'] = 'display:block';
-
- $form['connection_settings']['authorize_filetransfer_default']['#disabled'] = TRUE;
-
- $form['connection_settings']['change_connection_type'] = array(
- '#name' => 'change_connection_type',
- '#type' => 'submit',
- '#value' => t('Change connection type'),
- '#weight' => -5,
- '#attributes' => array('class' => array('filetransfer-change-connection-type')),
- );
- }
-
- }
- return $form;
- }
- function _authorize_filetransfer_connection_settings($backend) {
- $defaults = variable_get('authorize_filetransfer_connection_settings_' . $backend, array());
- $form = array();
-
- $filetransfer = authorize_get_filetransfer($backend);
- if ($filetransfer) {
- $form = $filetransfer->getSettingsForm();
- }
-
- _authorize_filetransfer_connection_settings_set_defaults($form, NULL, $defaults);
- return $form;
- }
- function _authorize_filetransfer_connection_settings_set_defaults(&$element, $key, array $defaults) {
-
-
- if (!empty($key) && isset($defaults[$key]) && isset($element['#type']) && $element['#type'] != 'fieldset') {
- $element['#default_value'] = $defaults[$key];
- }
-
-
-
-
-
-
- foreach (element_children($element) as $child_key) {
- _authorize_filetransfer_connection_settings_set_defaults($element[$child_key], $child_key, ((isset($defaults[$key]) && is_array($defaults[$key])) ? $defaults[$key] : $defaults));
- }
- }
- function authorize_filetransfer_form_validate($form, &$form_state) {
-
-
- if ($form_state['triggering_element']['#name'] != 'process_updates') {
- return;
- }
- if (isset($form_state['values']['connection_settings'])) {
- $backend = $form_state['values']['connection_settings']['authorize_filetransfer_default'];
- $filetransfer = authorize_get_filetransfer($backend, $form_state['values']['connection_settings'][$backend]);
- try {
- if (!$filetransfer) {
- throw new Exception(t('Error, this type of connection protocol (%backend) does not exist.', array('%backend' => $backend)));
- }
- $filetransfer->connect();
- }
- catch (Exception $e) {
-
-
- form_set_error('connection_settings', t('Failed to connect to the server. The server reports the following message: !message For more help installing or updating code on your server, see the <a href="@handbook_url">handbook</a>.', array(
- '!message' => '<p class="error">' . $e->getMessage() . '</p>',
- '@handbook_url' => 'http://drupal.org/documentation/install/modules-themes',
- )));
- }
- }
- }
- function authorize_filetransfer_form_submit($form, &$form_state) {
- global $base_url;
- switch ($form_state['triggering_element']['#name']) {
- case 'process_updates':
-
- $filetransfer_backend = $form_state['values']['connection_settings']['authorize_filetransfer_default'];
-
-
-
-
- try {
- $connection_settings = array();
- foreach ($form_state['values']['connection_settings'][$filetransfer_backend] as $key => $value) {
-
-
-
-
- if (!isset($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save'])) {
- if ($form['connection_settings'][$filetransfer_backend][$key]['#type'] != 'password') {
- $connection_settings[$key] = $value;
- }
- }
-
- elseif ($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save']) {
- $connection_settings[$key] = $value;
- }
- }
-
- variable_set('authorize_filetransfer_default', $filetransfer_backend);
-
- variable_set('authorize_filetransfer_connection_settings_' . $filetransfer_backend, $connection_settings);
- $filetransfer = authorize_get_filetransfer($filetransfer_backend, $form_state['values']['connection_settings'][$filetransfer_backend]);
-
- authorize_run_operation($filetransfer);
- }
- catch (Exception $e) {
-
-
- }
- 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;
- }
- }
- 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']));
- }
- 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'])) {
-
-
- $filetransfer = call_user_func_array(array($backend_info['class'], 'factory'), array(DRUPAL_ROOT, $settings));
- }
- }
- return $filetransfer;
- }
|