t('Rackspace Cloud Files'), 'dynamic' => TRUE, //I have no idea what this really means. 'local' => FALSE, 'direct' => FALSE, 'can_copy' => FALSE ); return $info; } function _storage_rackspacecloud_init($container) { require_once('cloudfiles.php'); // Create the authentication instance $auth = new CF_Authentication($container['settings']['username'], $container['settings']['api_key']); // NOTE: Some versions of cURL include an outdated certificate authority (CA) // file. This API ships with a newer version obtained directly from // cURL's web site (http://curl.haxx.se). To use the newer CA bundle, // call the CF_Authentication instance's 'ssl_use_cabundle()' method. # $auth->ssl_use_cabundle(); # bypass cURL's old CA bundle // Perform authentication request & return container object if successful if ($auth->authenticate()) { //Create a connection to the storage/cdn system(s) and pass in the //validated CF_Authentication instance. $conn = new CF_Connection($auth); # $conn->ssl_use_cabundle(); # bypass cURL's old CA bundle //Get the container $RSCFcontainer = $conn->get_container($container['settings']['RSCFcontainer']); if ($RSCFcontainer->name) { return $RSCFcontainer; } else{ if (user_access('administer site configuration')) drupal_set_message('Failed to retrieve Cloud Files Container.', 'error'); return FALSE; } } else { if (user_access('administer site configuration')) drupal_set_message('Failed to authenticate with Rackspace Cloud Files Container.', 'error'); return FALSE; } } /** * Implement hook_storage_container_settings_form() . */ function storage_rackspacecloud_storage_container_settings_form($settings, $serving, $edit) { $items['username'] = array( '#type' => 'textfield', '#title' => t('Username'), '#required' => TRUE, '#validated' => TRUE, '#default_value' => $settings['username'] ); $items['api_key'] = array( '#type' => 'textfield', '#title' => t('API Key'), '#required' => TRUE, '#validated' => TRUE, '#default_value' => $settings['api_key'] ); if(!$edit) { $items['RSCFcontainer'] = array( '#type' => 'textfield', '#title' => t('Cloud Files Container name'), '#required' => TRUE, '#validated' => TRUE, '#default_value' => $settings['RSCFcontainer'] ); } return $items; } /** * Implement hook_storage_container_validate() . */ function storage_rackspacecloud_storage_container_validate($container, $edit) { if(!$container['settings']['username']) { form_set_error('settings][username', t('Username field is required.')); } if(!$container['settings']['api_key']) { form_set_error('settings][api_key', t('API key Key field is required.')); } if(!$container['settings']['RSCFcontainer']) { form_set_error('settings][bucket', t('Container name field is required.')); } if(form_get_errors()) return; if(!_storage_rackspacecloud_init($container)) { form_set_error('settings', t('Connection failure.')); return; } } /** * Implement hook_storage_container_info() . */ function storage_rackspacecloud_storage_container_info($container) { $info = array( t('Container') => $container['settings']['RSCFcontainer'], ); return $info; } /** * Implement hook_storage_container_create() . * * @TODO For now, we'll assume the container already exists. */ function storage_rackspacecloud_storage_container_create($container) { return $container; } /** * Implement hook_storage_object_instance_create() . */ function storage_rackspacecloud_storage_object_instance_create($container, $file) { $cn = _storage_rackspacecloud_init($container); $name = 'object-'. $file['object_id']; $object = $cn->create_object($name); $fname = $file['filepath']; $size = (float) sprintf("%u", filesize($fname)); $fp = fopen($fname, "r"); $object->content_type = $file['mimetype']; $result = $object->write($fp, $size); if ($result) { $object->metadata = array( 'file_id' => $file['file_id'], 'object_id' => $file['object_id'], 'filename' => $file['filename'], 'source_filepath' => $file['filepath'], 'source_server' => $_SERVER['SERVER_NAME'], 'source_server_ip' => $_SERVER['SERVER_ADDR'], ); $object->sync_metadata(); return TRUE; } else { return FALSE; } } /** * Implement hook_storage_object_instance_destroy() . */ function storage_rackspacecloud_storage_object_instance_destroy($container, $file) { $cn = _storage_rackspacecloud_init($container); return $cn->delete_object('object-'. $file['object_id']); } /** * Implement hook_storage_object_instance_get_filepath() . */ /* TODO function storage_rackspacecloud_storage_object_instance_get_filepath($container, $file) { } /**/ /** * Implement hook_storage_object_instance_serve() . */ function storage_rackspacecloud_storage_object_instance_serve($container, $file) { $cn = _storage_rackspacecloud_init($container); $object = $cn->get_object('object-'.$file['object_id']); return $object->public_uri(); } /** * As I understand it, everything below is only required if the service * is not 'dynamic'... * Whatever that means. */ /** * Implement hook_storage_file_instance_create() . * function storage_rackspacecloud_storage_file_instance_create($container, $file) { } /**/ /** * Implement hook_storage_file_instance_copy() . * function storage_rackspacecloud_storage_file_instance_copy($container, $file, $source_container) { } /**/ /** * Implement hook_storage_file_instance_destroy() . * function storage_rackspacecloud_storage_file_instance_destroy($container, $file) { } /**/ /** * Implement hook_storage_file_instance_get_filepath() . * function storage_rackspacecloud_storage_file_instance_get_filepath($container, $file) { } /**/ /** * Implement hook_storage_file_instance_serve() . * function storage_rackspacecloud_storage_file_instance_serve($container, $file) { } /**/