diff options
Diffstat (limited to 'modules/system/system.module')
-rw-r--r-- | modules/system/system.module | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/modules/system/system.module b/modules/system/system.module index c4224423d..807b80015 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -828,6 +828,36 @@ function system_admin_menu_block_access($path, $permission) { } /** + * Implementation of hook_filetransfer_backends(). + */ +function system_filetransfer_backends() { + $backends = array(); + + // SSH2 lib connection is only available if the proper PHP extension is + // installed. + if (function_exists('ssh2_connect')) { + $backends['ssh'] = array( + 'title' => t('SSH'), + 'class' => 'FileTransferSSH', + ); + } + if (function_exists('ftp_connect')) { + $backends['ftp_extension'] = array( + 'title' => t('FTP Extension'), + 'class' => 'FileTransferFTPExtension', + ); + } + + if (ini_get('allow_url_fopen')) { + $backends['ftp_wrapper'] = array( + 'title' => t('FTP Wrapper'), + 'class' => 'FileTransferFTPWrapper', + ); + } + return $backends; +} + +/** * Implement hook_init(). */ function system_init() { @@ -2509,3 +2539,33 @@ function system_image_toolkits() { ), ); } + +/** + * Attempts to get a file using drupal_http_request and to store it locally. + * + * @param $path + * The URL of the file to grab. + * @return + * On success the address the files was saved to, FALSE on failure. + */ +function system_retrieve_file($path) { + // Get each of the specified files. + $parsed_url = parse_url($path); + $local = file_directory_temp() . '/update-cache/' . basename($parsed_url['path']); + if (!file_exists(file_directory_temp() . '/update-cache/')) { + mkdir(file_directory_temp() . '/update-cache/'); + } + + // Check the cache and download the file if needed. + if (!file_exists($local)) { + // $result->data is the actual contents of the downloaded file. This saves + // it into a local file, whose path is stored in $local. $local is stored + // relative to the Drupal installation. + $result = drupal_http_request($path); + if ($result->code != 200 || !file_save_data($result->data, $local)) { + drupal_set_message(t('@remote could not be saved.', array('@remote' => $path)), 'error'); + return FALSE; + } + } + return $local; +} |