diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..16a2f110
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+mirror
+.sass-cache
diff --git a/assets/config.rb b/assets/config.rb
new file mode 100644
index 00000000..f286c0f4
--- /dev/null
+++ b/assets/config.rb
@@ -0,0 +1,25 @@
+# Require any additional compass plugins here.
+
+# Set this to the root of your project when deployed:
+http_path = "/"
+css_dir = "css"
+sass_dir = "sass"
+images_dir = "img"
+javascripts_dir = "js"
+
+# You can select your preferred output style here (can be overridden via the command line):
+# output_style = :expanded or :nested or :compact or :compressed
+output_style = :compressed
+
+# To enable relative paths to assets via compass helper functions. Uncomment:
+# relative_assets = true
+
+# To disable debugging comments that display the original location of your selectors. Uncomment:
+line_comments = false
+
+
+# If you prefer the indented syntax, you might want to regenerate this
+# project again passing --syntax sass, or you can uncomment this:
+# preferred_syntax = :sass
+# and then run:
+# sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass
diff --git a/assets/css/styles.css b/assets/css/styles.css
new file mode 100644
index 00000000..e1bb704f
--- /dev/null
+++ b/assets/css/styles.css
@@ -0,0 +1 @@
+.as3cf-settings select.bucket{margin-bottom:5px;width:380px}
diff --git a/assets/js/script.js b/assets/js/script.js
new file mode 100644
index 00000000..463256df
--- /dev/null
+++ b/assets/js/script.js
@@ -0,0 +1,78 @@
+(function($) {
+
+ $(document).ready(function() {
+
+ $('.as3cf-settings').each(function() {
+ var $container = $(this);
+
+ $('select.bucket', $container).change(function() {
+ var $select = $(this);
+
+ if ($select.val() !== 'new') {
+ return;
+ }
+
+ var error_func = function(jqXHR, textStatus, errorThrown) {
+ alert(as3cf_i18n.create_bucket_error + errorThrown);
+ $select[0].selectedIndex = 0;
+ console.log( jqXHR );
+ console.log( textStatus );
+ console.log( errorThrown );
+ };
+
+ var success_func = function(data, textStatus, jqXHR) {
+ if (typeof data['success'] !== 'undefined') {
+ var opt = document.createElement('option');
+ opt.value = opt.innerHTML = bucket_name;
+ var inserted_at_position = 0;
+ $('option', $select).each(function() {
+ // For some reason, no error occurs when
+ // adding a bucket you've already added
+ if ($(this).val() == bucket_name) {
+ return false;
+ }
+ if ($(this).val() > bucket_name) {
+ $(opt).insertBefore($(this));
+ return false;
+ }
+ inserted_at_position = inserted_at_position + 1;
+ });
+ $select[0].selectedIndex = inserted_at_position;
+
+ // If they decided to create a new bucket before refreshing
+ // the page, we need another nonce
+ as3cf_i18n.create_bucket_nonce = data['_nonce'];
+ }
+ else {
+ alert(as3cf_i18n.create_bucket_error + data['error']);
+ $select[0].selectedIndex = 0;
+ }
+ };
+
+ var bucket_name = window.prompt(as3cf_i18n.create_bucket_prompt);
+ if (!bucket_name) {
+ $select[0].selectedIndex = 0;
+ return;
+ }
+
+ var data = {
+ action: 'as3cf-create-bucket',
+ bucket_name: bucket_name,
+ _nonce: as3cf_i18n.create_bucket_nonce
+ };
+
+ $.ajax({
+ url: ajaxurl,
+ type: 'POST',
+ dataType: 'JSON',
+ success: success_func,
+ error: error_func,
+ data: data
+ });
+ });
+
+ });
+
+ });
+
+})(jQuery);
\ No newline at end of file
diff --git a/assets/js/script.min.js b/assets/js/script.min.js
new file mode 100644
index 00000000..84e687d7
--- /dev/null
+++ b/assets/js/script.min.js
@@ -0,0 +1 @@
+(function(e){e(document).ready(function(){e(".as3cf-settings").each(function(){var t=e(this);e("select.bucket",t).change(function(){var t=e(this);if(t.val()!=="new")return;var n=function(e,n,r){alert(as3cf_i18n.create_bucket_error+r);t[0].selectedIndex=0;console.log(e);console.log(n);console.log(r)},r=function(n,r,s){if(typeof n["success"]!="undefined"){var o=document.createElement("option");o.value=o.innerHTML=i;var u=0;e("option",t).each(function(){if(e(this).val()==i)return!1;if(e(this).val()>i){e(o).insertBefore(e(this));return!1}u+=1});t[0].selectedIndex=u;as3cf_i18n.create_bucket_nonce=n._nonce}else{alert(as3cf_i18n.create_bucket_error+n.error);t[0].selectedIndex=0}},i=window.prompt(as3cf_i18n.create_bucket_prompt);if(!i){t[0].selectedIndex=0;return}var s={action:"as3cf-create-bucket",bucket_name:i,_nonce:as3cf_i18n.create_bucket_nonce};e.ajax({url:ajaxurl,type:"POST",dataType:"JSON",success:r,error:n,data:s})})})})})(jQuery);
\ No newline at end of file
diff --git a/assets/sass/styles.scss b/assets/sass/styles.scss
new file mode 100644
index 00000000..ec1e77ba
--- /dev/null
+++ b/assets/sass/styles.scss
@@ -0,0 +1,6 @@
+.as3cf-settings {
+ select.bucket {
+ margin-bottom: 5px;
+ width: 380px;
+ }
+}
\ No newline at end of file
diff --git a/classes/amazon-s3-and-cloudfront.php b/classes/amazon-s3-and-cloudfront.php
new file mode 100644
index 00000000..84b1b327
--- /dev/null
+++ b/classes/amazon-s3-and-cloudfront.php
@@ -0,0 +1,359 @@
+aws = $aws;
+
+ add_action( 'aws_admin_menu', array( $this, 'admin_menu' ) );
+
+ $this->plugin_title = __( 'Amazon S3 and CloudFront', 'as3cf' );
+ $this->plugin_menu_title = __( 'S3 and CloudFront', 'as3cf' );
+
+ add_action( 'wp_ajax_as3cf-create-bucket', array( $this, 'ajax_create_bucket' ) );
+
+ add_filter( 'wp_get_attachment_url', array( $this, 'wp_get_attachment_url' ), 9, 2 );
+ add_filter( 'wp_update_attachment_metadata', array( $this, 'wp_update_attachment_metadata' ), 9, 2 );
+ add_filter( 'delete_attachment', array( $this, 'delete_attachment' ) );
+ }
+
+ function delete_attachment( $post_id ) {
+ if ( !$this->is_plugin_enabled() || !$this->is_plugin_setup() ) {
+ return;
+ }
+
+ $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
+
+ $intermediate_sizes = array();
+ foreach ( get_intermediate_image_sizes() as $size ) {
+ if ( $intermediate = image_get_intermediate_size( $post_id, $size ) )
+ $intermediate_sizes[] = $intermediate;
+ }
+
+ if ( !( $s3object = $this->get_attachment_s3_info( $post_id ) ) ) {
+ return;
+ }
+
+ $amazon_path = dirname( $s3object['key'] );
+ $objects = array();
+
+ // remove intermediate and backup images if there are any
+ foreach ( $intermediate_sizes as $intermediate ) {
+ $objects[] = array(
+ 'Key' => path_join( $amazon_path, $intermediate['file'] )
+ );
+ }
+
+ if ( is_array( $backup_sizes ) ) {
+ foreach ( $backup_sizes as $size ) {
+ $objects[] = array(
+ 'Key' => path_join( $amazon_path, $del_file )
+ );
+ }
+ }
+
+ $objects[] = array(
+ 'Key' => $s3object['key']
+ );
+
+ try {
+ $this->get_s3client()->deleteObjects( array(
+ 'Bucket' => $s3object['bucket'],
+ 'Objects' => $objects
+ ) );
+ }
+ catch ( Exception $e ) {
+ error_log( 'Error removing files from S3: ' . $e->getMessage() );
+ return;
+ }
+
+ delete_post_meta( $post_id, 'amazonS3_info' );
+ }
+
+ function wp_update_attachment_metadata( $data, $post_id ) {
+ if ( !$this->is_plugin_enabled() || !$this->is_plugin_setup() ) {
+ return $data;
+ }
+
+ $uploads = wp_upload_dir();
+ $parts = parse_url( $uploads['url'] );
+
+ $prefix = substr( $parts['path'], 1 ) .'/';
+ $type = get_post_mime_type( $post_id );
+
+ $file_path = get_attached_file( $post_id, true );
+
+ $acl = apply_filters( 'wps3_upload_acl', 'public-read', $type, $data, $post_id, $this ); // Old naming convention, will be deprecated soon
+ $acl = apply_filters( 'as3cf_upload_acl', $acl, $type, $data, $post_id, $this );
+
+ if ( !file_exists( $file_path ) ) {
+ return $data;
+ }
+
+ $file_name = basename( $file_path );
+
+ $s3client = $this->get_s3client();
+
+ $bucket = $this->get_setting( 'bucket' );
+
+ $args = array(
+ 'Bucket' => $bucket,
+ 'Key' => $prefix . $file_name,
+ 'SourceFile' => $file_path,
+ 'ACL' => $acl
+ );
+
+ // If far future expiration checked (10 years)
+ if ( $this->get_setting( 'expires' ) ) {
+ $args['Expires'] = date( 'D, d M Y H:i:s O', time()+315360000 );
+ }
+
+ try {
+ $s3client->putObject( $args );
+ }
+ catch ( Exception $e ) {
+ error_log( 'Error uploading ' . $file_path . ' to S3: ' . $e->getMessage() );
+ return $data;
+ }
+
+ delete_post_meta( $post_id, 'amazonS3_info' );
+
+ add_post_meta( $post_id, 'amazonS3_info', array(
+ 'bucket' => $bucket,
+ 'key' => $prefix . $file_name
+ ) );
+
+ $additional_images = array();
+
+ if ( isset( $data['thumb'] ) && $data['thumb'] ) {
+ $path = str_replace( $file_name, $data['thumb'], $file_path );
+ $additional_images[] = array(
+ 'Key' => $prefix . $data['thumb'],
+ 'SourceFile' => $path
+ );
+ }
+ elseif ( count( $data['sizes'] ) ) {
+ foreach ( $data['sizes'] as $size ) {
+ $path = str_replace( $file_name, $size['file'], $file_path );
+ $additional_images[] = array(
+ 'Key' => $prefix . $size['file'],
+ 'SourceFile' => $path
+ );
+ }
+ }
+
+ foreach ( $additional_images as $image ) {
+ try {
+ $args = array_merge( $args, $image );
+ $s3client->putObject( $args );
+ }
+ catch ( Exception $e ) {
+ error_log( 'Error uploading ' . $args['SourceFile'] . ' to S3: ' . $e->getMessage() );
+ }
+ }
+
+ return $data;
+ }
+
+ function wp_get_attachment_url( $url, $post_id ) {
+ $new_url = $this->get_attachment_url( $post_id );
+ if ( false === $new_url ) {
+ return $url;
+ }
+
+ $new_url = apply_filters( 'wps3_get_attachment_url', $new_url, $post_id, $this ); // Old naming convention, will be deprecated soon
+ $new_url = apply_filters( 'as3cf_wp_get_attachment_url', $new_url, $post_id, $this );
+
+ return $new_url;
+ }
+
+ function get_attachment_s3_info( $post_id ) {
+ return get_post_meta( $post_id, 'amazonS3_info', true );
+ }
+
+ function is_plugin_enabled() {
+ return (bool) $this->get_setting( 'wp-uploads' );
+ }
+
+ function is_plugin_setup() {
+ return (bool) $this->get_setting( 'bucket' ) && !is_wp_error( $this->aws->get_client() );
+ }
+
+ /**
+ * Generate a link to download a file from Amazon S3 using query string
+ * authentication. This link is only valid for a limited amount of time.
+ *
+ * @param mixed $post_id Post ID of the attachment or null to use the loop
+ * @param int $expires Seconds for the link to live
+ */
+ function get_secure_attachment_url( $post_id, $expires = 900 ) {
+ return $this->get_attachment_url( $post_id, $expires );
+ }
+
+ function get_attachment_url( $post_id, $expires = null ) {
+ if ( !$this->is_plugin_enabled() || !( $s3object = $this->get_attachment_s3_info( $post_id ) ) ) {
+ return false;
+ }
+
+ if ( is_ssl() ) {
+ $scheme = 'https';
+ }
+ else {
+ $scheme = 'http';
+ }
+
+ if ( is_null( $expires ) && $this->get_setting( 'cloudfront' ) ) {
+ $domain_bucket = $this->get_setting( 'cloudfront' );
+ }
+ elseif ( $this->get_setting( 'virtual-host' ) ) {
+ $domain_bucket = $s3object['bucket'];
+ }
+ elseif ( is_ssl() ) {
+ $domain_bucket = 's3.amazonaws.com/' . $s3object['bucket'];
+ }
+ else {
+ $domain_bucket = $s3object['bucket'] . '.s3.amazonaws.com';
+ }
+
+ $url = $scheme . '://' . $domain_bucket . '/' . $s3object['key'];
+
+ if ( !is_null( $expires ) ) {
+ try {
+ $expires = time() + $expires;
+ $secure_url = $this->get_s3client()->getObjectUrl( $s3object['bucket'], $s3object['key'], $expires );
+ $url .= substr( $secure_url, strpos( $secure_url, '?' ) );
+ }
+ catch ( Exception $e ) {
+ return new WP_Error( 'exception', $e->getMessage() );
+ }
+ }
+
+ return apply_filters( 'as3cf_get_attachment_url', $url, $s3object, $post_id, $expires );
+ }
+
+ function verify_ajax_request() {
+ if ( !is_admin() || !wp_verify_nonce( $_POST['_nonce'], $_POST['action'] ) ) {
+ wp_die( __( 'Cheatin’ eh?', 'as3cf' ) );
+ }
+
+ if ( !current_user_can( 'manage_options' ) ) {
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'as3cf' ) );
+ }
+ }
+
+ function ajax_create_bucket() {
+ $this->verify_ajax_request();
+
+ if ( !isset( $_POST['bucket_name'] ) || !$_POST['bucket_name'] ) {
+ wp_die( __( 'No bucket name provided.', 'as3cf' ) );
+ }
+
+ $result = $this->create_bucket( $_POST['bucket_name'] );
+ if ( is_wp_error( $result ) ) {
+ $out = array( 'error' => $result->get_error_message() );
+ }
+ else {
+ $out = array( 'success' => '1', '_nonce' => wp_create_nonce( 'as3cf-create-bucket' ) );
+ }
+
+ echo json_encode( $out );
+ exit;
+ }
+
+ function create_bucket( $bucket_name ) {
+ try {
+ $this->get_s3client()->createBucket( array( 'Bucket' => $bucket_name ) );
+ }
+ catch ( Exception $e ) {
+ return new WP_Error( 'exception', $e->getMessage() );
+ }
+
+ return true;
+ }
+
+ function admin_menu( $aws ) {
+ $hook_suffix = $aws->add_page( $this->plugin_title, $this->plugin_menu_title, 'manage_options', $this->plugin_slug, array( $this, 'render_page' ) );
+ add_action( 'load-' . $hook_suffix , array( $this, 'plugin_load' ) );
+ }
+
+ function get_s3client() {
+ if ( is_null( $this->s3client ) ) {
+ $this->s3client = $this->aws->get_client()->get( 's3' );
+ }
+
+ return $this->s3client;
+ }
+
+ function get_buckets() {
+ try {
+ $result = $this->get_s3client()->listBuckets();
+ }
+ catch ( Exception $e ) {
+ return new WP_Error( 'exception', $e->getMessage() );
+ }
+
+ return $result['Buckets'];
+ }
+
+ function plugin_load() {
+ $src = plugins_url( 'assets/css/styles.css', $this->plugin_file_path );
+ wp_enqueue_style( 'as3cf-styles', $src, array(), $this->get_installed_version() );
+
+ $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
+
+ $src = plugins_url( 'assets/js/script' . $suffix . '.js', $this->plugin_file_path );
+ wp_enqueue_script( 'as3cf-script', $src, array( 'jquery' ), $this->get_installed_version(), true );
+
+ wp_localize_script( 'as3cf-script', 'as3cf_i18n', array(
+ 'create_bucket_prompt' => __( 'Bucket Name:', 'as3cf' ),
+ 'create_bucket_error' => __( 'Error creating bucket: ', 'as3cf' ),
+ 'create_bucket_nonce' => wp_create_nonce( 'as3cf-create-bucket' )
+ ) );
+
+ $this->handle_post_request();
+ }
+
+ function handle_post_request() {
+ if ( empty( $_POST['action'] ) || 'save' != $_POST['action'] ) {
+ return;
+ }
+
+ if ( empty( $_POST['_wpnonce'] ) || !wp_verify_nonce( $_POST['_wpnonce'], 'as3cf-save-settings' ) ) {
+ die( __( "Cheatin' eh?", 'amazon-web-services' ) );
+ }
+
+ $this->set_settings( array() );
+
+ $post_vars = array( 'bucket', 'virtual-host', 'expires', 'permissions', 'cloudfront', 'wp-uploads' );
+ foreach ( $post_vars as $var ) {
+ if ( !isset( $_POST[$var] ) ) {
+ continue;
+ }
+
+ $this->set_setting( $var, $_POST[$var] );
+ }
+
+ $this->save_settings();
+ }
+
+ function render_page() {
+ $this->aws->render_view( 'header', array( 'page_title' => $this->plugin_title ) );
+
+ $aws_client = $this->aws->get_client();
+
+ if ( is_wp_error( $aws_client ) ) {
+ $this->render_view( 'error', array( 'error' => $aws_client ) );
+ }
+ else {
+ $this->render_view( 'settings' );
+ }
+
+ $this->aws->render_view( 'footer' );
+ }
+}
diff --git a/include/functions.php b/include/functions.php
new file mode 100644
index 00000000..347e44d3
--- /dev/null
+++ b/include/functions.php
@@ -0,0 +1,18 @@
+curl = curl_init();
- $this->postData = array();
- $this->cookies = array();
- $this->headers = array();
- if ( !empty( $url ) ) {
- $this->setURL( $url );
- } else {
- $this->setURL( false );
- }
- foreach ( $params as $key => $value ) {
- $this->{'_' . $key} = $value;
- }
-
- $this->addHeader( 'Connection', 'close' );
-
- // We don't do keep-alives by default
- $this->addHeader( 'Connection', 'close' );
-
- // Basic authentication
- if ( !empty( $this->_user ) ) {
- $this->addHeader( 'Authorization', 'Basic ' . base64_encode( $this->_user . ':' . $this->_pass ) );
- }
-
- // Proxy authentication (see bug #5913)
- if ( !empty( $this->_proxy_user ) ) {
- $this->addHeader( 'Proxy-Authorization', 'Basic ' . base64_encode( $this->_proxy_user . ':' . $this->_proxy_pass ) );
- }
-
- }
-
- function addHeader( $header, $value ) {
- $this->headers[$header] = $value;
- }
-
- function setMethod( $method ) {
-
- // setting default values for constants if they're not present
- if ( !defined( 'HTTP_REQUEST_METHOD_PUT' ) ) define( 'HTTP_REQUEST_METHOD_PUT', null );
- if ( !defined( 'HTTP_REQUEST_METHOD_POST' ) ) define( 'HTTP_REQUEST_METHOD_POST', null );
-
- switch ( $method ) {
- case 'DELETE':
- curl_setopt( $this->curl, CURLOPT_CUSTOMREQUEST, 'DELETE' );
- break;
- case HTTP_REQUEST_METHOD_PUT:
- case 'PUT':
- curl_setopt( $this->curl, CURLOPT_PUT, true );
- //CURLOPT_INFILE CURLOPT_INFILESIZE
- break;
- case HTTP_REQUEST_METHOD_POST:
- case 'POST':
- curl_setopt( $this->curl, CURLOPT_POST, true );
- break;
- default:
- case 'GET':
- curl_setopt( $this->curl, CURLOPT_HTTPGET, true );
- break;
- case 'HEAD':
- curl_setopt( $this->curl, CURLOPT_CUSTOMREQUEST, 'HEAD' );
- break;
- }
- }
- function setURL( $url ) {
- $this->url = $url;
- }
- function addPostData( $name, $value ) {
- $this->postData[$name] = $value;
- }
- function addCookie( $name, $value ) {
- $this->cookies[$name] = array( 'name' => $name, 'value' => $value );
- }
- function sendRequest() {
- $headers = array(
- "Accept: *.*",
- );
-
- foreach ( $this->headers as $k=>$h ) {
- $headers[] = "$k: $h";
- }
-
- if ( count( $this->cookies ) > 0 ) {
- $cookieVars = '';
- foreach ( $this->cookies as $cookie ) {
- //$headers[] = "Cookie: ".$cookie['name'].'='.$cookie['value'];
- $cookieVars .= ''.$cookie['name'].'='.$cookie['value'].'; ';
- }
- curl_setopt( $this->curl, CURLOPT_COOKIE, $cookieVars );
- //print_r($cookieVars);
- }
-
- if ( count( $this->postData ) > 0 ) { // if a POST
- $postVars = '';
- foreach ( $this->postData as $key=>$value ) {
- $postVars .= $key.'='.urlencode( $value ).'&';
- }
- // *** TODO ***
- // weird, libcurl doesnt seem to POST correctly
- curl_setopt( $this->curl, CURLOPT_POST, true );
- curl_setopt( $this->curl, CURLOPT_POSTFIELDS, $postVars );
-
- //curl_setopt($this->curl, CURLOPT_HTTPGET, true);
- //$this->url .= '?'.$postVars;
-
-
- } else {
- curl_setopt( $this->curl, CURLOPT_HTTPGET, true );
- }
- curl_setopt( $this->curl, CURLOPT_URL, $this->url );
- curl_setopt( $this->curl, CURLOPT_FOLLOWLOCATION, false );
- curl_setopt( $this->curl, CURLOPT_HEADER, true );
- curl_setopt( $this->curl, CURLOPT_HTTPHEADER, $headers );
- curl_setopt( $this->curl, CURLOPT_RETURNTRANSFER, true );
- curl_setopt( $this->curl, CURLOPT_SSL_VERIFYPEER, false );
- $this->raw = curl_exec( $this->curl );
- $this->response = $this->_parseResponse( $this->raw );
- return true; // hmm no error checking for now
- }
-
- function getResponseHeader( $header=false ) {
- if ( $header ) {
- return $this->response['header'][$header];
- } else {
- return $this->response['header'];
- }
- }
- function getResponseCookies() {
- $hdrCookies = array();
- foreach ( $this->response['header'] as $key => $value ) {
- if ( strtolower( $key ) == 'set-cookie' ) {
- $hdrCookies = array_merge( $hdrCookies, explode( "\n", $value ) );
- }
- }
- //$hdrCookies = explode("\n", $this->response['header']['Set-Cookie']);
- $cookies = array();
-
- foreach ( $hdrCookies as $cookie ) {
- if ( $cookie ) {
- list( $name, $value ) = explode( '=', $cookie, 2 );
- list( $value, $domain, $path, $expires ) = explode( ';', $value );
- $cookies[$name] = array( 'name' => $name, 'value' => $value );
- }
- }
- return $cookies;
- }
- function getResponseBody() {
- return $this->response['body'];
- }
- function getResponseCode() {
- return $this->response['code'];
- }
- function getResponseRaw() {
- return $this->raw;
- }
- function clearPostData( $var=false ) {
- if ( !$var ) {
- $this->postData = array();
- } else {
- unset( $this->postData[$var] );
- }
- }
-
- function _parseResponse( $this_response ) {
- if ( substr_count( $this_response, 'HTTP/1.' ) > 1 ) { // yet another weird bug. CURL seems to be appending response bodies together
- $chunks = preg_split( '@(HTTP/[0-9]\.[0-9] [0-9]{3}.*\n)@', $this_response, -1, PREG_SPLIT_DELIM_CAPTURE );
- $this_response = array_pop( $chunks );
- $this_response = array_pop( $chunks ) . $this_response;
-
- }
-
- list( $response_headers, $response_body ) = explode( "\r\n\r\n", $this_response, 2 );
- $response_header_lines = explode( "\r\n", $response_headers );
-
- $http_response_line = array_shift( $response_header_lines );
- if ( preg_match( '@^HTTP/[0-9]\.[0-9] 100@', $http_response_line, $matches ) ) {
- return $this->_parseResponse( $response_body );
- } else if ( preg_match( '@^HTTP/[0-9]\.[0-9] ([0-9]{3})@', $http_response_line, $matches ) ) {
- $response_code = $matches[1];
- }
- $response_header_array = array();
- foreach ( $response_header_lines as $header_line ) {
- list( $header, $value ) = explode( ': ', $header_line, 2 );
- if ( isset( $response_header_array[$header] ) ) {
- $response_header_array[$header] .= $value."\n";
- }
- }
- return array( "code" => $response_code, "header" => $response_header_array, "body" => $response_body );
- }
-}
diff --git a/view/error.php b/view/error.php
new file mode 100644
index 00000000..d8224a1c
--- /dev/null
+++ b/view/error.php
@@ -0,0 +1,7 @@
+
+
+
+
get_error_message(); ?>
+
+
+
\ No newline at end of file
diff --git a/view/settings.php b/view/settings.php
new file mode 100644
index 00000000..f4820c71
--- /dev/null
+++ b/view/settings.php
@@ -0,0 +1,74 @@
+
+
+get_buckets();
+
+if ( is_wp_error( $buckets ) ) :
+ ?>
+
+
+
+ get_error_message(); ?>
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/wordpress-s3.php b/wordpress-s3.php
index 60af4d6f..77d95a77 100644
--- a/wordpress-s3.php
+++ b/wordpress-s3.php
@@ -1,10 +1,10 @@
= 0 ) { // just load in admin
- $ver = get_bloginfo( 'version' );
- if ( version_compare( phpversion(), '5.0', '>=' ) && version_compare( $ver, '2.1', '>=' ) ) {
- require_once dirname( __FILE__ ).'/wordpress-s3/class-plugin.php';
- $TanTanWordPressS3Plugin = new TanTanWordPressS3Plugin();
- } elseif ( preg_match( '!wordpress-mu-!', $ver ) ) {
- require_once dirname( __FILE__ ).'/wordpress-s3/class-plugin.php';
- $TanTanWordPressS3Plugin = new TanTanWordPressS3Plugin();
- } else {
- class TanTanWordPressS3Error {
- function TanTanWordPressS3Error() {add_action( 'admin_menu', array( &$this, 'addhooks' ) );}
- function addhooks() {add_options_page( 'Amazon S3', 'Amazon S3', 10, __FILE__, array( &$this, 'admin' ) );}
- function admin() {include dirname( __FILE__ ).'/wordpress-s3/admin-version-error.php';}
- }
- $error = new TanTanWordPressS3Error();
+
+function as3cf_check_required_plugin() {
+ if ( class_exists( 'Amazon_Web_Services' ) || !is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
+ return;
+ }
+
+ require_once ABSPATH . '/wp-admin/includes/plugin.php';
+ deactivate_plugins( __FILE__ );
+
+ $msg = sprintf( __( 'Amazon S3 and CloudFront has been deactivated as it requires the Amazon Web Services plugin.', 'as3cf' ), 'http://wordpress.org/extend/plugins/amazon-web-services/' ) . ' ';
+
+ if ( file_exists( WP_PLUGIN_DIR . '/amazon-web-services/amazon-web-services.php' ) ) {
+ $activate_url = wp_nonce_url( 'plugins.php?action=activate&plugin=amazon-web-services/amazon-web-services.php', 'activate-plugin_amazon-web-services/amazon-web-services.php' );
+ $msg .= sprintf( __( 'It appears to already be installed. Click here to activate it. ', 'as3cf' ), $activate_url );
+ }
+ else {
+ $install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=amazon-web-services' ), 'install-plugin_amazon-web-services' );
+ $msg .= sprintf( __( 'Click here to install it automatically. Then activate it. ', 'as3cf' ), $install_url );
}
-} else {
- require_once dirname( __FILE__ ).'/wordpress-s3/class-plugin-public.php';
- $TanTanWordPressS3Plugin = new TanTanWordPressS3PluginPublic();
+
+ $msg .= ' ' . __( 'Once it has been activated, you can activate Amazon S3 and CloudFront.', 'as3cf' );
+
+ wp_die( $msg );
+}
+
+add_action( 'plugins_loaded', 'as3cf_check_required_plugin' );
+
+function as3cf_init( $aws ) {
+ global $as3cf;
+ require_once 'classes/amazon-s3-and-cloudfront.php';
+ $as3cf = new Amazon_S3_And_CloudFront( __FILE__, $aws );
}
+
+add_action( 'aws_init', 'as3cf_init' );
\ No newline at end of file
diff --git a/wordpress-s3/admin-options.php b/wordpress-s3/admin-options.php
deleted file mode 100644
index 382c4fae..00000000
--- a/wordpress-s3/admin-options.php
+++ /dev/null
@@ -1,218 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
Amazon S3 and CloudFront
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/wordpress-s3/admin-tab-head.php b/wordpress-s3/admin-tab-head.php
deleted file mode 100644
index 684114de..00000000
--- a/wordpress-s3/admin-tab-head.php
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
-
-
diff --git a/wordpress-s3/admin-tab.js b/wordpress-s3/admin-tab.js
deleted file mode 100644
index 7da85395..00000000
--- a/wordpress-s3/admin-tab.js
+++ /dev/null
@@ -1,59 +0,0 @@
-
-function s3_insertImage(imgURL, title) {
- if (!title) title = '';
- return s3_insert(' ');
-}
-
-function s3_insertLink(label, url) {
- var useBittorrent = document.getElementById('useBittorrent').checked
- return s3_insert('' + label + ' ');
-}
-function s3_insert(h) {
- var win = window.dialogArguments || opener || parent || top;
-
- if (typeof win.send_to_editor == 'function') {
- win.send_to_editor(h);
- if (typeof win.tb_remove == 'function')
- win.tb_remove();
- return false;
- }
- tinyMCE = win.tinyMCE;
- if ( typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content') ) {
- tinyMCE.selectedInstance.getWin().focus();
- tinyMCE.execCommand('mceInsertContent', false, h);
- } else win.edInsertContent(win.edCanvas, h);
-
- return false;
-}
-function s3_toggleUpload() {
- document.getElementById('create-form').style.display='none';
-
- var div = document.getElementById('upload-form');
- if (div.style.display == 'block') {
- div.style.display = 'none';
- } else {
- div.style.display = 'block';
- }
- return false;
-}
-function s3_toggleCreateFolder() {
- document.getElementById('upload-form').style.display='none';
-
- var div = document.getElementById('create-form');
- if (div.style.display == 'block') {
- div.style.display = 'none';
- } else {
- div.style.display = 'block';
- document.getElementById('newfolder').focus();
- }
- return false;
-
-
- var div = document.getElementById('createFolder');
- if (div.className != 'create') {
- div.className = 'create';
- document.getElementById('newfolder').focus();
- } else {
- div.className = '';
- }
-}
diff --git a/wordpress-s3/admin-tab.php b/wordpress-s3/admin-tab.php
deleted file mode 100644
index 7e5a2f8c..00000000
--- a/wordpress-s3/admin-tab.php
+++ /dev/null
@@ -1,98 +0,0 @@
-
-
-
-
-
-
-
-
-back
-forward
-
-refresh
-upload
-new folder
-
-
-home / ';
-$path = '';
-$paths = preg_split( '/\//', $prefix, 100, PREG_SPLIT_NO_EMPTY );
-$numPaths = count( $paths );
-$i=0;
-foreach ( $paths as $name ) if ( $name ) {
- $path .= $name .'/';
- $isLast = ( ++$i ) >= $numPaths;
- echo ''.$name.' '.( !$isLast ? ' / ' : ' ' );
- }
-?>
-
-
- create links as torrents
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/wordpress-s3/admin-version-error.php b/wordpress-s3/admin-version-error.php
deleted file mode 100644
index 1994235f..00000000
--- a/wordpress-s3/admin-version-error.php
+++ /dev/null
@@ -1,58 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
Amazon S3 Plugin for WordPress
-
-
Switch to a better web host!
- Use the coupon code
-
TANTAN50COUPON
- when you signup to get a $50 discount, and you'll
- help support this plugin in the process.
- That works out to be less than $6.00 per month for the first year.
-
-
-
Error
-
-Sorry, this plugin requires at least PHP 5.0 and WordPress 2.1 in order to work correctly.
-Please contact your systems administrator about getting your version of PHP and/or WordPress upgraded.
-
-
-Your PHP version:
-Your WordPress version:
-
-
-
-
-Download PHP
-Download WordPress
-
-
diff --git a/wordpress-s3/class-plugin-public.php b/wordpress-s3/class-plugin-public.php
deleted file mode 100644
index e16d0a98..00000000
--- a/wordpress-s3/class-plugin-public.php
+++ /dev/null
@@ -1,104 +0,0 @@
-options = array();
- if ( file_exists( dirname( __FILE__ ).'/config.php' ) ) {
- require_once dirname( __FILE__ ).'/config.php';
- if ( $TanTanWordPressS3Config ) $this->options = $TanTanWordPressS3Config;
- }
- add_action( 'plugins_loaded', array( &$this, 'addhooks' ) );
- }
- function addhooks() {
- add_filter( 'wp_get_attachment_url', array( &$this, 'wp_get_attachment_url' ), 9, 2 );
- }
- function wp_get_attachment_url( $url, $postID ) {
- if ( !$this->options ) $this->options = get_option( 'tantan_wordpress_s3' );
-
- if ( isset($this->options['wp-uploads']) && $this->options['wp-uploads'] && ( $amazon = get_post_meta( $postID, 'amazonS3_info', true ) ) ) {
- if ( is_ssl() ) {
- $url = 'https://';
- }
- else {
- $url = 'http://';
- }
-
- if ( isset( $this->options['cloudfront'] ) && $this->options['cloudfront'] ) {
- $accessDomain = $this->options['cloudfront'];
- }
- elseif ( isset( $this->options['virtual-host'] ) && $this->options['virtual-host'] ) {
- $accessDomain = $this->options['bucket'];
- }
- elseif ( is_ssl() ) {
- $accessDomain = 's3.amazonaws.com/' . $amazon['bucket'];
- }
- else {
- $accessDomain = $amazon['bucket'] . '.s3.amazonaws.com';
- }
-
- $url .= $accessDomain.'/'.$amazon['key'];
-
- $url = apply_filters( 'wps3_get_attachment_url', $url, $postID, $this );
- }
-
- return $url;
- }
-
-
- /**
- * Generate a link to download a file from Amazon S3 using query string
- * authentication. This link is only valid for a limited amount of time.
- *
- * @param unknown $bucket The name of the bucket in which the file is stored.
- * @param unknown $filekey The key of the file, excluding the leading slash.
- * @param unknown $expires The amount of time the link is valid (in seconds).
- * @param unknown $operation The type of HTTP operation. Either GET or HEAD.
- */
- function get_secure_attachment_url( $postID, $expires = 900, $operation = 'GET' ) {
- if ( !$this->options ) $this->options = get_option( 'tantan_wordpress_s3' );
-
- if (
- !isset($this->options['wp-uploads']) || !$this->options['wp-uploads'] || !$this->options['key'] || !$this->options['secret']
- || !$this->options['bucket'] || !( $amazon = get_post_meta( $postID, 'amazonS3_info', true ) )
- ) {
- return false;
- }
-
- $accessDomain = $this->options['virtual-host'] ? $amazon['bucket'] : $amazon['bucket'].'.s3.amazonaws.com';
-
- $expire_time = time() + $expires;
- $filekey = rawurlencode( $amazon['key'] );
- $filekey = str_replace( '%2F', '/', $filekey );
- $path = $amazon['bucket'] .'/'. $filekey;
-
- /**
- * StringToSign = HTTP-VERB + "\n" +
- * Content-MD5 + "\n" +
- * Content-Type + "\n" +
- * Expires + "\n" +
- * CanonicalizedAmzHeaders +
- * CanonicalizedResource;
- */
-
- $stringtosign =
- $operation ."\n". // type of HTTP request (GET/HEAD)
- "\n". // Content-MD5 is meaningless for GET
- "\n". // Content-Type is meaningless for GET
- $expire_time ."\n". // set the expire date of this link
- "/$path"; // full path (incl bucket), starting with a /
-
- require_once dirname( __FILE__ ).'/lib.s3.php';
- $s3 = new TanTanS3( $this->options['key'], $this->options['secret'] );
- $signature = urlencode( $s3->constructSig( $stringtosign ) );
-
- return sprintf( 'http://%s/%s?AWSAccessKeyId=%s&Expires=%u&Signature=%s', $accessDomain, $filekey, $this->options['key'], $expire_time, $signature );
- }
-}
-
-function wps3_get_secure_attachment_url( $postID, $expires = 900, $operation = 'GET' ) {
- global $TanTanWordPressS3Plugin;
- return $TanTanWordPressS3Plugin->get_secure_attachment_url( $postID, $expires, $operation );
-}
diff --git a/wordpress-s3/class-plugin.php b/wordpress-s3/class-plugin.php
deleted file mode 100644
index 88654861..00000000
--- a/wordpress-s3/class-plugin.php
+++ /dev/null
@@ -1,507 +0,0 @@
-options['hideAmazonS3UploadTab'] ) || !$this->options['hideAmazonS3UploadTab'] ) {
- add_action( 'load-upload.php', array( &$this, 'addPhotosTab' ) ); // WP < 2.5
-
- // WP >= 2.5
- add_action( 'media_buttons_context', array( &$this, 'media_buttons' ) );
- add_action( 'media_upload_tabs', array( &$this, 'media_upload_tabs' ) );
- add_action( 'media_upload_tantan-wordpress-s3', array( &$this, 'media_upload_content' ) );
- }
- add_action( 'activate_tantan/wordpress-s3.php', array( &$this, 'activate' ) );
- if ( isset( $_GET['tantanActivate'] ) && $_GET['tantanActivate'] == 'wordpress-s3' ) {
- $this->showConfigNotice();
- }
- $this->photos = array();
- $this->albums = array();
- $this->perPage = 1000;
-
-
- }
-
- // this should install the javascripts onto the user's s3.amazonaws.com account
-
- function installAjax() {
- $js = array( 'S3Ajax.js' );
- }
-
- function activate() {
- wp_redirect( 'plugins.php?tantanActivate=wordpress-s3' );
- exit;
- }
- function deactivate() {}
-
- function showConfigNotice() {
- add_action( 'admin_notices', create_function( '', 'echo \'\';' ) );
- }
-
- function settings() {
- add_options_page( 'Amazon S3', 'Amazon S3', 'manage_options', __FILE__, array( &$this, 'admin' ) );
- $this->version_check();
- }
- function addhooks() {
- parent::addhooks();
- if ( !isset( $_POST['disable_amazonS3'] ) || !$_POST['disable_amazonS3'] ) {
- add_filter( 'wp_update_attachment_metadata', array( &$this, 'wp_update_attachment_metadata' ), 9, 2 );
- //can't delete mirrored files just yet
- //add_filter('wp_get_attachment_metadata', array(&$this, 'wp_get_attachment_metadata'));
- add_filter( 'delete_attachment', array( &$this, 'delete_attachment' ) );
- }
- }
- function version_check() {
- global $TanTanVersionCheck;
- if ( is_object( $TanTanVersionCheck ) ) {
- $data = get_plugin_data( dirname( __FILE__ ).'/../wordpress-s3.php' );
- $TanTanVersionCheck->versionCheck( 668, $data['Version'] );
- }
- }
- function admin() {
- if ( isset( $_POST['action'] ) && $_POST['action'] == 'save' ) {
- if ( !is_array( $_POST['options'] ) ) $_POST['options'] = array();
- $options = get_option( 'tantan_wordpress_s3' );
-
- $_POST['options']['key'] = trim( $_POST['options']['key'] );
- $_POST['options']['secret'] = trim( $_POST['options']['secret'] );
-
- if ( !$_POST['options']['secret'] || preg_match( '!not shown!', $_POST['options']['secret'] ) ) {
- $_POST['options']['secret'] = $options['secret'];
- }
-
- update_option( 'tantan_wordpress_s3', $_POST['options'] );
-
- if ( isset( $_POST['options']['bucket'] ) && $_POST['options']['bucket'] ) {
- $options = get_option( 'tantan_wordpress_s3' );
- require_once dirname( __FILE__ ).'/lib.s3.php';
- $s3 = new TanTanS3( $options['key'], $options['secret'] );
-
- if ( !in_array( $_POST['options']['bucket'], $s3->listBuckets() ) ) {
- if ( $s3->createBucket( $_POST['options']['bucket'], 'public-read' ) ) {
- $message = "Saved settings and created a new bucket: ".$_POST['options']['bucket'];
- } else {
- $error = "There was an error creating the bucket: ".$_POST['options']['bucket'];
- }
- } else {
- $message = "Saved settings.";
- }
- } else {
- $message = "Saved Amazon S3 authentication information. ";
- }
- if ( function_exists( 'dns_get_record' ) && isset( $_POST['options']['virtual-host'] ) && $_POST['options']['virtual-host'] ) {
- $record = dns_get_record( $_POST['options']['bucket'] );
- if ( ( $record[0]['type'] != 'CNAME' ) || ( $record[0]['target'] != $_POST['options']['bucket'].'s3.amazonaws.com' ) ) {
- $error = "Warning: Your DNS doesn't seem to be setup correctly to virtually host the domain ".$_POST['options']['bucket']." . ".
- "Double check and make sure the following entry is added to your DNS. ".
- "More info > ".
- " ".
- "".$_POST['options']['bucket']." CNAME ".$_POST['options']['bucket'].".s3.amazonaws.com.
".
- " ".
- "You can ignore this message if you're sure everything is setup correctly. ";
- }
- }
- }
- $options = get_option( 'tantan_wordpress_s3' );
- if ( $options['key'] && $options['secret'] ) {
- require_once dirname( __FILE__ ).'/lib.s3.php';
- $s3 = new TanTanS3( $options['key'], $options['secret'] );
- $buckets = $s3->listBuckets();
- if ( !is_array( $buckets ) ) {
- $error = $this->getErrorMessage( $s3->parsed_xml, $s3->responseCode );
- }
-
- $s3->initCacheTables();
-
- } elseif ( $options['key'] ) {
- $error = "Please enter your Secret Access Key.";
- } elseif ( $options['secret'] ) {
- $error = "Please enter your Access Key ID.";
- }
-
-
- include dirname( __FILE__ ).'/admin-options.php';
- }
-
-
- /*
- Delete corresponding files from Amazon S3
- */
- function delete_attachment( $post_id ) {
- if ( !$this->options ) $this->options = get_option( 'tantan_wordpress_s3' );
-
- if ( !isset($this->options['wp-uploads']) || !$this->options['wp-uploads'] || !$this->options['bucket'] || !$this->options['secret'] ) {
- return;
- }
-
- $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
-
- $intermediate_sizes = array();
- foreach ( get_intermediate_image_sizes() as $size ) {
- if ( $intermediate = image_get_intermediate_size( $post_id, $size ) )
- $intermediate_sizes[] = $intermediate;
- }
-
- if ( !( $amazon = get_post_meta( $post_id, 'amazonS3_info', true ) ) ) {
- return;
- }
-
- $amazon_path = dirname( $amazon['key'] );
-
- require_once dirname( __FILE__ ).'/lib.s3.php';
- $this->s3 = new TanTanS3( $this->options['key'], $this->options['secret'] );
- $this->s3->setOptions( $this->options );
-
- // remove intermediate and backup images if there are any
- foreach ( $intermediate_sizes as $intermediate ) {
- $this->s3->deleteObject( $amazon['bucket'], path_join( $amazon_path, $intermediate['file'] ) );
- }
-
- if ( is_array( $backup_sizes ) ) {
- foreach ( $backup_sizes as $size ) {
- $this->s3->deleteObject( $amazon['bucket'], path_join( $amazon_path, $del_file ) );
- }
- }
-
- $this->s3->deleteObject( $amazon['bucket'], $amazon['key'] );
- // IOK 2013-03-15 Ensure this is called when attachment deleted from S3
- delete_post_meta($post_id,'amazonS3_info');
- }
-
- function wp_get_attachment_metadata( $data=false, $postID=false ) {
- if ( is_numeric( $postID ) ) $this->meta = get_post_meta( $postID, 'amazonS3_info', true );
- return $data;
- }
- /*
- Handle uploads through default WordPress upload handler
- */
- function wp_update_attachment_metadata( $data, $postID ) {
- if ( !$this->options ) $this->options = get_option( 'tantan_wordpress_s3' );
-
- if ( !isset($this->options['wp-uploads']) || !$this->options['wp-uploads'] || !$this->options['bucket'] || !$this->options['secret'] ) {
- return $data;
- }
-
- add_filter( 'option_siteurl', array( &$this, 'upload_path' ) );
- $uploadDir = wp_upload_dir();
- remove_filter( 'option_siteurl', array( &$this, 'upload_path' ) );
- $parts = parse_url( $uploadDir['url'] );
-
- $prefix = substr( $parts['path'], 1 ) .'/';
- $type = get_post_mime_type( $postID );
-
- $data['file'] = get_attached_file( $postID, true );
-
- $acl = apply_filters( 'wps3_upload_acl', 'public-read', $type, $data, $postID, $this );
-
- if ( file_exists( $data['file'] ) ) {
- $file = array(
- 'name' => basename( $data['file'] ),
- 'type' => $type,
- 'tmp_name' => $data['file'],
- 'error' => 0,
- 'size' => filesize( $data['file'] ),
- );
-
- require_once dirname( __FILE__ ).'/lib.s3.php';
- $this->s3 = new TanTanS3( $this->options['key'], $this->options['secret'] );
- $this->s3->setOptions( $this->options );
-
- if ( $this->s3->putObjectStream( $this->options['bucket'], $prefix.$file['name'], $file, $acl ) ) {
-
- if ( isset( $data['thumb'] ) && $data['thumb'] ) {
- $thumbpath = str_replace( basename( $data['file'] ), $data['thumb'], $data['file'] );
- $filethumb = array(
- 'name' => $data['thumb'],
- 'type' => $type,
- 'tmp_name' => $thumbpath,
- 'size' => filesize( $thumbpath ),
- );
-
- $this->s3->putObjectStream( $this->options['bucket'], $prefix.$filethumb['name'], $filethumb );
- } elseif ( count( $data['sizes'] ) ) foreach ( $data['sizes'] as $altName => $altSize ) {
- $altPath = str_replace( basename( $data['file'] ), $altSize['file'], $data['file'] );
- $altMeta = array(
- 'name' => $altSize['file'],
- 'type' => $type,
- 'tmp_name' => $altPath,
- 'size' => filesize( $altPath ),
- );
- $this->s3->putObjectStream( $this->options['bucket'], $prefix.$altMeta['name'], $altMeta );
-
- }
-
-
- delete_post_meta( $postID, 'amazonS3_info' );
- add_post_meta( $postID, 'amazonS3_info', array(
- 'bucket' => $this->options['bucket'],
- 'key' => $prefix.$file['name']
- ) );
- } else {
-
- }
- }
- return $data;
- }
- function wp_handle_upload( $info ) {
- return $info;
- }
-
- // figure out the correct path to upload to, for wordpress mu installs
- function upload_path( $path='' ) {
- global $current_blog;
- if ( !$current_blog ) return $path;
- if ( $current_blog->path == '/' && ( $current_blog->blog_id != 1 ) ) {
- $dir = substr( $current_blog->domain, 0, strpos( $current_blog->domain, '.' ) );
- } else {
- // prepend a directory onto the path for vhosted blogs
- if ( constant( "VHOST" ) != 'yes' ) {
- $dir = '';
- } else {
- $dir = $current_blog->path;
- }
- }
- //echo trim($path.'/'.$dir, '/');
- if ( $path == '' ) {
- $path = $current_blog->path;
- }
- return trim( $path.'/'.$dir, '/' );
- }
- function media_buttons( $context ) {
- global $post_ID, $temp_ID;
- $pluginRootURL = plugins_url( '', __FILE__ );
- $image_btn = $pluginRootURL.'/database.png';
- $image_title = 'Amazon S3';
-
- $uploading_iframe_ID = (int) ( 0 == $post_ID ? $temp_ID : $post_ID );
-
- $media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
- $out = ' ';
- return $context.$out;
- }
- function media_upload_tabs( $tabs ) {
- $tabs['tantan-wordpress-s3'] = 'Amazon S3';
- return $tabs;
- }
- function media_upload_content() {
- $this->upload_files_tantan_amazons3(); // process any uploaded files or new folders
-
- if ( !$this->options ) $this->options = get_option( 'tantan_wordpress_s3' );
- //if (!is_object($this->s3)) {
- require_once dirname( __FILE__ ).'/lib.s3.php';
- $this->s3 = new TanTanS3( $this->options['key'], $this->options['secret'] );
- $this->s3->setOptions( $this->options );
- //}
-
- add_action( 'admin_print_scripts', array( &$this, 'upload_tabs_scripts' ) );
- wp_iframe( array( &$this, 'tab' ) );
- }
- /*
- Display tabs
- */
- function addPhotosTab() {
- add_filter( 'wp_upload_tabs', array( &$this, 'wp_upload_tabs' ) );
- add_action( 'upload_files_tantan_amazons3', array( &$this, 'upload_files_tantan_amazons3' ) );
- add_action( 'upload_files_upload', array( &$this, 'upload_files_upload' ) );
- add_action( 'admin_print_scripts', array( &$this, 'upload_tabs_scripts' ) );
- }
- function wp_upload_tabs( $array ) {
- /*
- 0 => tab display name,
- 1 => required cap,
- 2 => function that produces tab content,
- 3 => total number objects OR array(total, objects per page),
- 4 => add_query_args
- */
- if ( !$this->options ) $this->options = get_option( 'tantan_wordpress_s3' );
- require_once dirname( __FILE__ ).'/lib.s3.php';
- $this->s3 = new TanTanS3( $this->options['key'], $this->options['secret'] );
-
-
- if ( $this->options['key'] && $this->options['secret'] && $this->options['bucket'] ) {
- $paged = array();
- $args = array( 'prefix' => '' ); // this doesn't do anything in WP 2.1.2
- $tab = array(
- 'tantan_amazons3' => array( 'Amazon S3', 'upload_files', array( &$this, 'tab' ), $paged, $args ),
- //'tantan_amazons3_upload' => array('Upload S3', 'upload_files', array(&$this, 'upload'), $paged, $args),
- );
-
- return array_merge( $array, $tab );
- } else {
- return $array;
- }
- }
-
- function get_access_domain() {
- if ( !$this->options ) $this->options = get_option( 'tantan_wordpress_s3' );
-
- if ( isset( $this->options['cloudfront'] ) && $this->options['cloudfront'] ) {
- return $this->options['cloudfront'];
- }
- elseif ( isset( $this->options['virtual-host'] ) && $this->options['virtual-host'] ) {
- return $this->options['bucket'];
- }
- else {
- return $this->options['bucket'].'.s3.amazonaws.com';
- }
- }
-
- function upload_tabs_scripts() {
- //wp_enqueue_script('prototype');
- if ( !$this->options ) $this->options = get_option( 'tantan_wordpress_s3' );
-
- $accessDomain = $this->get_access_domain();
-
- include dirname( __FILE__ ).'/admin-tab-head.php';
- }
- function upload_files_upload() {
- // javascript here to inject javascript and allow the upload from to post to amazon s3 instead
- }
- function upload_files_tantan_amazons3() {
- global $current_blog;
- $restrictPrefix = ''; // restrict to a selected prefix in current bucket
- if ( $current_blog ) { // if wordpress mu
- $restrictPrefix = ltrim( $this->upload_path().'/files/', '/' );
- }
-
- if ( isset($_FILES['newfile']) && is_array( $_FILES['newfile'] ) ) {
- $file = $_FILES['newfile'];
- if ( !$this->options ) $this->options = get_option( 'tantan_wordpress_s3' );
- require_once dirname( __FILE__ ).'/lib.s3.php';
- $this->s3 = new TanTanS3( $this->options['key'], $this->options['secret'] );
- $this->s3->setOptions( $this->options );
- $this->s3->putObjectStream( $this->options['bucket'], $restrictPrefix.$_GET['prefix'].$file['name'], $file );
- }
- if ( isset($_POST['newfolder']) && $_POST['newfolder'] ) {
- if ( !$this->options ) $this->options = get_option( 'tantan_wordpress_s3' );
- require_once dirname( __FILE__ ).'/lib.s3.php';
- $this->s3 = new TanTanS3( $this->options['key'], $this->options['secret'] );
-
- $this->s3->putPrefix( $this->options['bucket'], $restrictPrefix.$_POST['prefix'].$_POST['newfolder'] );
- }
- }
- function tab() {
- global $current_blog;
- $restrictPrefix = ''; // restrict to a selected prefix in current bucket
- if ( $current_blog ) { // if wordpress mu
- $restrictPrefix = ltrim( $this->upload_path().'/files/', '/' );
- }
-
- $offsetpage = (int) isset($_GET['paged']) ? $_GET['paged'] : 0;
- if ( !$offsetpage ) $offsetpage = 1;
-
- if ( !$this->options['key'] || !$this->options['secret'] ) {
- return;
- }
- $bucket = $this->options['bucket'];
- $accessDomain = $this->get_access_domain();
-
- $prefix = (isset($_GET['prefix']) && $_GET['prefix']) ? $_GET['prefix'] : '';
- list( $prefixes, $keys, $meta, $privateKeys ) = $this->getKeys( $restrictPrefix.$prefix );
- if ( $restrictPrefix ) {
- foreach ( $prefixes as $k=>$v ) {
- $prefixes[$k] = str_replace( $restrictPrefix, '', $v );
- }
- }
- include dirname( __FILE__ ).'/admin-tab.php';
- }
-
- function getErrorMessage( $parsed_xml, $responseCode ) {
- $message = 'Error '.$responseCode.': ' . $parsed_xml->Message;
- if ( isset( $parsed_xml->StringToSignBytes ) ) $message .= " Hex-endcoded string to sign: " . $parsed_xml->StringToSignBytes;
- return $message;
- }
-
- // turns array('a', 'b', 'c') into $array['a']['b']['c']
- function mapKey( $keys, $path ) {
- $k =& $keys;
- $size = count( $path ) - 1;
- $workingPath = '/';
- foreach ( $path as $i => $p ) {
- if ( $i === $size ) {
- $k['_size'] = isset( $k['_size'] ) ? $k['_size'] + 1 : 1;
- $k['_path'] = $workingPath;
- $k['_objects'][$k['_size']] = $p;
- } else {
- $k =& $k[$p]; // traverse the tree
- $workingPath .= $p . '/';
- }
- }
- return $keys;
- }
-
- // should probably figgure out a way to cache these results to make things more speedy
- function getKeys( $prefix ) {
- $ret = $this->s3->listKeys( $this->options['bucket'], false, urlencode( $prefix ), '/' );//, false, 's3/', '/');
-
- if ( $this->s3->responseCode >= 400 ) {
- return array();
- }
- $keys = array();
- $privateKeys = array();
- $prefixes = array();
- $meta = array();
- if ( $this->s3->parsed_xml->CommonPrefixes ) foreach ( $this->s3->parsed_xml->CommonPrefixes as $content ) {
- $prefixes[] = (string) $content->Prefix;
- }
-
- if ( $this->s3->parsed_xml->Contents ) foreach ( $this->s3->parsed_xml->Contents as $content ) {
- $key = (string) $content->Key;
- if ( $this->isPublic( $key ) ) $keys[] = $key;
- else {
- if ( !( $p1 = preg_match( '!^\.!', $key ) ) &&
- !( $p2 = preg_match( '!_\$folder\$$!', $key ) ) &&
- !( $p3 = preg_match( '!placeholder.ns3!', $key ) ) ) {
- $privateKeys[] = $key;
- } elseif ( $p2 ) {
- $prefix = preg_replace( '!(_\$folder\$$)!', '/', $key );
- if ( !in_array( $prefix, $prefixes ) ) $prefixes[] = $prefix;
- } else {
-
- }
- }
- }
- if ( $this->options['permissions'] == 'public' ) {
- foreach ( $privateKeys as $key ) {
- $this->s3->setObjectACL( $this->options['bucket'], $key, 'public-read' );
- $keys[] = $key;
- }
- }
-
- $defaultkeys = array('content-length','content-type','date');
- foreach ($keys as $i => $key) {
- $meta[$i] = $this->s3->getMetadata($this->options['bucket'], $key);
- // IOK 2013-08-14 for some reason, this can happen, that is, no metadata. So fake it.
- foreach($defaultkeys as $dk) {
- if (!isset($meta[$i][$dk])) {
- $meta[$i][$dk] = null;
- }
- }
- }
-
-
- natcasesort( $keys );
- natcasesort( $prefixes );
-
- return array( $prefixes, $keys, $meta, $privateKeys );
- }
-
- function isPublic( $key ) {
- $everyone = 'http://acs.amazonaws.com/groups/global/AllUsers';
- $this->s3->getObjectACL( $this->options['bucket'], $key );
- $acl = (array) $this->s3->parsed_xml->AccessControlList;
- if ( is_array( $acl['Grant'] ) ) foreach ( $acl['Grant'] as $grant ) {
- $grant = (array) $grant;
- if ( $grant['Grantee'] && ( preg_match( '!AllUsers!', (string) $grant['Grantee']->URI ) ) ) {
- $perm = (string) $grant['Permission'];
- if ( $perm == 'READ' || $perm == 'FULL_CONTROL' ) return true;
- }
- }
-
-
- }
-}
diff --git a/wordpress-s3/config-sample.php b/wordpress-s3/config-sample.php
deleted file mode 100644
index e667d5dd..00000000
--- a/wordpress-s3/config-sample.php
+++ /dev/null
@@ -1,14 +0,0 @@
- '', // AWS Access Key ID
- 'secret' => '', // AWS Secret Key
- 'bucket' => '', // S3 Bucket
- 'virtual-host' => false, // Bucket is configured for virtual hosting
- 'wp-uploads' => true, // mirror all WordPress uploads into Amazon S3 bucket
- 'permissions' => '', // set to "public" to have the plugin force all files in the specified bucket to "public" (sometimes third party upload utilities don't do this)
- 'hideAmazonS3UploadTab' => false, // hide the Amazon S3 tab in the WordPress upload widget
- 'expires' => 315360000, // set http expires header 10 years into the future
- 'cloudfront' => '', //this can be your cloudfront DNS name (*.cloudfront.net) or a CNAME alias
-);
diff --git a/wordpress-s3/database.png b/wordpress-s3/database.png
deleted file mode 100644
index 3d09261a..00000000
Binary files a/wordpress-s3/database.png and /dev/null differ
diff --git a/wordpress-s3/index.php b/wordpress-s3/index.php
deleted file mode 100644
index 559d87ba..00000000
--- a/wordpress-s3/index.php
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/wordpress-s3/lib.s3.php b/wordpress-s3/lib.s3.php
deleted file mode 100644
index acbdd8e1..00000000
--- a/wordpress-s3/lib.s3.php
+++ /dev/null
@@ -1,396 +0,0 @@
-setFunction( $func );$this->setKey( $key );}
- function setFunction( $func ) {if ( !$this->_pack = $this->_getPackFormat( $func ) ) { die( 'Unsupported hash function' ); }$this->_func = $func;}
- function setKey( $key ) {$func = $this->_func;if ( strlen( $key ) > 64 ) {$key = pack( $this->_pack, $func( $key ) );}if ( strlen( $key ) < 64 ) {$key = str_pad( $key, 64, chr( 0 ) );}$this->_ipad = ( substr( $key, 0, 64 ) ^ str_repeat( chr( 0x36 ), 64 ) );$this->_opad = ( substr( $key, 0, 64 ) ^ str_repeat( chr( 0x5C ), 64 ) );}
- function _getPackFormat( $func ) {$packs = array( 'md5' => 'H32', 'sha1' => 'H40' );return isset( $packs[$func] ) ? $packs[$func] : false;}
- function hash( $data ) {$func = $this->_func;return $func( $this->_opad . pack( $this->_pack, $func( $this->_ipad . $data ) ) );}
-}
-/*
-class Stream{
-var $data;
-function stream_function($handle, $fd, $length){return fread($this->data, $length);}
-}
-*/
-if ( !class_exists( 'TanTanHTTPRequestCurl' ) ) require_once dirname( __FILE__ ).'/../lib/curl.php';
-
-/*
- based on code provided by Amazon
-*/
-// This software code is made available "AS IS" without warranties of any
-// kind. You may copy, display, modify and redistribute the software
-// code either by itself or as incorporated into your code; provided that
-// you do not remove any proprietary notices. Your use of this software
-// code is at your own risk and you waive any claim against Amazon
-// Digital Services, Inc. or its affiliates with respect to your use of
-// this software code. (c) 2006 Amazon Digital Services, Inc. or its
-// affiliates.
-
-class TanTanS3 {
-
- var $serviceUrl;
- var $accessKeyId;
- var $secretKey;
- var $responseString;
- var $responseCode;
- var $parsed_xml;
- var $req;
- var $fp;
- var $options;
-
- /**
- * Constructor
- *
- * Takes ($accessKeyId, $secretKey, $serviceUrl)
- *
- * - [str] $accessKeyId: Your AWS Access Key Id
- * - [str] $secretKey: Your AWS Secret Access Key
- * - [str] $serviceUrl: OPTIONAL: defaults: http://s3.amazonaws.com/
- *
- */
- function TanTanS3( $accessKeyId, $secretKey, $serviceUrl="http://s3.amazonaws.com/" ) {
- global $wpdb;
- $this->serviceUrl=$serviceUrl;
- $this->accessKeyId=$accessKeyId;
- $this->secretKey=$secretKey;
- $this->req = new TanTanHTTPRequestCurl( $this->serviceUrl );
- $this->options = array();
- $this->options['cache_table'] = $wpdb->prefix . 'tantan_wordpress_s3_cache';
- //$this->req = new HTTP_Request($this->serviceUrl);
- }
-
- function setOptions( $options ) {
- if ( is_array( $options ) ) {
- $this->options = array_merge( $this->options, $options );
- }
- }
- /**
- * listBuckets -- Lists all buckets.
- */
- function listBuckets() {
- $ret = $this->send( '', '' );
- if ( $ret == 200 ) {
- $return = array();
- if ( count( $this->parsed_xml->Buckets->Bucket ) > 0 ) {
- foreach ( $this->parsed_xml->Buckets->Bucket as $bucket ) {
- $return[] = (string) $bucket->Name;
- }
- }
- return $return;
-
- }
- else {
- return false;
- }
- }
- /**
- * listKeys -- Lists keys in a bucket.
- *
- * Takes ($bucket [,$marker][,$prefix][,$delimiter][,$maxKeys]) -- $marker, $prefix, $delimeter, $maxKeys are independently optional
- *
- * - [str] $bucket: the bucket whose keys are to be listed
- * - [str] $marker: keys returned will occur lexicographically after $marker (OPTIONAL: defaults to false)
- * - [str] $prefix: keys returned will start with $prefix (OPTIONAL: defaults to false)
- * - [str] $delimiter: keys returned will be of the form "$prefix[some string]$delimeter" (OPTIONAL: defaults to false)
- * - [str] $maxKeys: number of keys to be returned (OPTIONAL: defaults to 1000 - maximum allowed by service)
- */
- function listKeys( $bucket, $marker=FALSE, $prefix=FALSE, $delimiter=FALSE, $maxKeys='1000' ) {
- $ret = $this->send( $bucket, '/', "max-keys={$maxKeys}&marker={$marker}&prefix={$prefix}&delimiter={$delimiter}" );
- if ( $ret == 200 ) {
- return true;
- } else {
- return false;
- }
- }
- function createBucket( $bucket, $acl = 'private' ) {
- $httpDate = gmdate( "D, d M Y G:i:s T" );
- $stringToSign = "PUT\n\n\n$httpDate\nx-amz-acl:$acl\n/$bucket";
- $signature = $this->constructSig( $stringToSign );
- //$req =& new HTTP_Request($this->serviceUrl . $bucket);
- $this->req->setURL( $this->serviceUrl . $bucket );
- $this->req->setMethod( "PUT" );
- $this->req->addHeader( "Date", $httpDate );
- $this->req->addHeader( "Authorization", "AWS " . $this->accessKeyId . ":" . $signature );
- $this->req->addHeader( "x-amz-acl", $acl );
- $this->req->sendRequest();
- $this->responseCode=$this->req->getResponseCode();
- $this->responseString = $this->req->getResponseBody();
- $this->parsed_xml = simplexml_load_string( $this->responseString );
- if ( $this->responseCode == 200 ) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * getBucketACL -- Gets bucket access control policy.
- *
- * Takes ($bucket)
- *
- * - [str] $bucket: the bucket whose acl you want
- */
- function getBucketACL( $bucket ) {
- $ret = $this->send( $bucket, '/?acl' );
- if ( $ret == 200 ) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * getObjectACL -- gets an objects access control policy.
- *
- * Takes ($bucket, $key)
- *
- * - [str] $bucket
- * - [str] $key
- */
- function getObjectACL( $bucket, $key ) {
- $ret = $this->send( $bucket, "/".urlencode( $key ).'?acl' );
- if ( $ret == 200 ) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * setObjectACL -- sets objects access control policy to one of Amazon S3 canned policies.
- *
- * Takes ($bucket, $key, $acl)
- *
- * - [str] $bucket
- * - [str] $key
- * - [str] $acl -- One of canned access control policies.
- */
- function setObjectACL( $bucket, $key, $acl ) {
- $serviceUrl = 'http://'.$bucket.'.s3.amazonaws.com/';
-
- $httpDate = gmdate( "D, d M Y G:i:s T" );
- $resource = urlencode( $key );
- $stringToSign = "PUT\n\n\n$httpDate\nx-amz-acl:$acl\n/$bucket/$resource?acl";
- $signature = $this->constructSig( $stringToSign );
- //$req =& new HTTP_Request($this->serviceUrl.$resource.'?acl');
- $this->req->setURL( $serviceUrl.$resource.'?acl' );
- $this->req->setMethod( "PUT" );
- $this->req->addHeader( "Date", $httpDate );
- $this->req->addHeader( "Authorization", "AWS " . $this->accessKeyId . ":" . $signature );
- $this->req->addHeader( "x-amz-acl", $acl );
- $this->req->sendRequest();
- if ( $this->req->getResponseCode() == 200 ) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * getMetadata -- Gets the metadata associated with an object.
- *
- * Takes ($bucket, $key)
- *
- * - [str] $bucket
- * - [str] $key
- */
- function getMetadata( $bucket, $key ) {
- if ( $data = $this->getCache( $bucket."/".$key ) ) {
- return $data;
- }
- $ret = $this->send( $bucket, "/".urlencode( $key ), '', 'HEAD' );
- if ( $ret == 200 ) {
- $data = $this->req->getResponseHeader();
- foreach ( $data as $k => $d ) $data[strtolower( $k )] = trim( $d );
- $this->setCache( $bucket."/".$key, $data );
- return $data;
- } else {
- return array();
- }
- }
-
-
- /**
- * putObjectStream -- Streams data to a bucket.
- *
- * Takes ($bucket, $key, $streamFunction, $contentType, $contentLength [,$acl, $metadataArray, $md5])
- * http://www.missiondata.com/blog/linux/49/s3-streaming-with-php/
- *
- * - [str] $bucket: the bucket into which file will be written
- * - [str] $key: key of written file
- * - [str] $fileName: path to file
- * - [str] $contentType: file content type
- * - [str] $contentLength: file content length
- * - [str] $acl: access control policy of file (OPTIONAL: defaults to 'private')
- * - [str] $metadataArray: associative array containing user-defined metadata (name=>value) (OPTIONAL)
- * - [bool] $md5: the MD5 hash of the object (OPTIONAL)
- */
- function putObjectStream( $bucket, $key, $fileInfo, $acl='public-read', $metadataArray=array(), $md5=false ) {
- $serviceUrl = 'http://'.$bucket.'.s3.amazonaws.com/';
-
- sort( $metadataArray );
- $fileName = $fileInfo['tmp_name'];
- $contentLength = $fileInfo['size'];
- $contentType = $fileInfo['type'];
- if ( !file_exists( $fileName ) ) {
- return false;
- }
- $this->fp = fopen( $fileName, 'r' );
- $resource = urlencode( $key );
- $httpDate = gmdate( "D, d M Y G:i:s T" );
-
- $curl_inst = curl_init();
-
- curl_setopt( $curl_inst, CURLOPT_CONNECTTIMEOUT, 30 );
- curl_setopt( $curl_inst, CURLOPT_LOW_SPEED_LIMIT, 1 );
- curl_setopt( $curl_inst, CURLOPT_LOW_SPEED_TIME, 180 );
- curl_setopt( $curl_inst, CURLOPT_NOSIGNAL, 1 );
- curl_setopt( $curl_inst, CURLOPT_READFUNCTION, array( &$this, 'stream_function' ) );
- curl_setopt( $curl_inst, CURLOPT_URL, $serviceUrl . $resource );
- curl_setopt( $curl_inst, CURLOPT_UPLOAD, true );
- curl_setopt( $curl_inst, CURLINFO_CONTENT_LENGTH_UPLOAD, $contentLength );
-
- $header[] = "Date: $httpDate";
- $header[] = "Content-Type: $contentType";
- $header[] = "Content-Length: $contentLength";
- $header[] = "Expect: ";
- if ( isset( $this->options['expires'] ) && is_numeric( $this->options['expires'] ) ) {
- $header[] = "Expires: ".date( 'D, d M Y H:i:s O', time()+$this->options['expires'] );
- }
- $header[] = "Transfer-Encoding: ";
- $header[] = "x-amz-acl: $acl";
-
- $MD5 = "";
- if ( $md5 ) {
- $MD5 = $this->hex2b64( md5_file( $filePath ) );
- $header[] = "Content-MD5: $MD5";
- }
-
- $stringToSign="PUT\n$MD5\n$contentType\n$httpDate\nx-amz-acl:$acl\n";
- foreach ( $metadataArray as $current ) {
- if ( $current!="" ) {
- $stringToSign.="x-amz-meta-$currentn";
- $header = substr( $current, 0, strpos( $current, ':' ) );
- $meta = substr( $current, strpos( $current, ':' )+1, strlen( $current ) );
- $header[] = "x-amz-meta-$header: $meta";
- }
- }
-
- $stringToSign.="/$bucket/$resource";
-
- $signature = $this->constructSig( $stringToSign );
-
- $header[] = "Authorization: AWS $this->accessKeyId:$signature";
-
- curl_setopt( $curl_inst, CURLOPT_HTTPHEADER, $header );
- curl_setopt( $curl_inst, CURLOPT_RETURNTRANSFER, 1 );
-
- $result = curl_exec( $curl_inst );
-
- $this->responseString = $result;
- $this->responseCode = curl_getinfo( $curl_inst, CURLINFO_HTTP_CODE );
-
- fclose( $this->fp );
- curl_close( $curl_inst );
- return true;
- }
- function stream_function( $handle, $fd, $length ) {return fread( $this->fp, $length );}
-
- function putPrefix( $bucket, $prefix ) {
- $ret = $this->send( $bucket, "/".urlencode( $prefix.'_$folder$' ), '', 'PUT', array( 'Content-Type' => '', 'Content-Length' => 0 ) );
- if ( $ret == 200 ) {
- return true;
- } else {
- return false;
- }
- }
-
- function deleteObject( $bucket, $key ) {
- $ret = $this->send( $bucket, "/".urlencode( $key ), '', 'DELETE' );
- if ( $ret == 204 ) {
- return true;
- } else {
- return false;
- }
- }
-
- function send( $bucket, $resource, $args='', $method='GET', $headers=false ) {
- if ( $bucket != '' ) {
- $serviceUrl = 'http://'.$bucket.'.s3.amazonaws.com';
- } else {
- $serviceUrl = 'http://s3.amazonaws.com/';
- }
-
- $method=strtoupper( $method );
- $httpDate = gmdate( "D, d M Y G:i:s T" );
- $signature = $this->constructSig( "$method\n\n\n$httpDate\n/".( $bucket ? ( $bucket.$resource ) : $resource ) );
-
- $this->req->setURL( $serviceUrl.$resource.( $args ? '?'.$args : '' ) );
- $this->req->setMethod( $method );
- $this->req->addHeader( "Date", $httpDate );
- $this->req->addHeader( "Authorization", "AWS " . $this->accessKeyId . ":" . $signature );
- if ( is_array( $headers ) ) foreach ( $headers as $key => $header ) $this->req->addHeader( $key, $header );
- $this->req->sendRequest();
- if ( $method=='GET' ) {
- $this->parsed_xml = simplexml_load_string( $this->req->getResponseBody() );
- }
-
- return $this->req->getResponseCode();
- }
- function hex2b64( $str ) {
- $raw = '';
- for ( $i=0; $i < strlen( $str ); $i+=2 ) {
- $raw .= chr( hexdec( substr( $str, $i, 2 ) ) );
- }
- return base64_encode( $raw );
- }
-
- function constructSig( $str ) {
- $hasher = new TanTanCrypt_HMAC( $this->secretKey, "sha1" );
- $signature = $this->hex2b64( $hasher->hash( $str ) );
- return $signature;
- }
-
- function initCacheTables() {
- global $wpdb;
- if ( !is_object( $wpdb ) ) return;
-
- $wpdb->query( "CREATE TABLE IF NOT EXISTS `".$this->options['cache_table']."` (
- `request` VARCHAR( 255 ) NOT NULL ,
- `response` TEXT NOT NULL ,
- `timestamp` DATETIME NOT NULL ,
- PRIMARY KEY ( `request` )
- )" );
- }
- function setCache( $key, $data ) {
- global $wpdb;
- if ( !is_object( $wpdb ) ) return false;
- $key = addslashes( trim( $key ) );
- if ( $wpdb->query( "DELETE FROM ".$this->options['cache_table']." WHERE request = '".$key."'" ) !== false ) {
- $sql = "INSERT INTO ".$this->options['cache_table']." (request, response, timestamp) VALUES ('".$key."', '" . addslashes( serialize( $data ) ) . "', '" . strftime( "%Y-%m-%d %H:%M:%S" ) . "')";
- $wpdb->query( $sql );
- } else { // tables might not be setup, so just try to do that
- $this->initCacheTables();
- }
- return $data;
- }
- function getCache( $key ) {
- global $wpdb;
- if ( !is_object( $wpdb ) ) return false;
- $key = trim( $key );
- $result = @$wpdb->get_var( "SELECT response FROM ".$this->options['cache_table']." WHERE request = '" . $key . "' LIMIT 1" );
-
- if ( !empty( $result ) ) {
- return unserialize( $result );
- }
- return false;
- }
- function clearCache() {
- global $wpdb;
- if ( !is_object( $wpdb ) ) return false;
- $result = @$wpdb->query( "DELETE FROM ".$this->options['cache_table'].";" );
- }
-}
diff --git a/wordpress-s3/styles/add.png b/wordpress-s3/styles/add.png
deleted file mode 100644
index 6332fefe..00000000
Binary files a/wordpress-s3/styles/add.png and /dev/null differ
diff --git a/wordpress-s3/styles/arrow_left.png b/wordpress-s3/styles/arrow_left.png
deleted file mode 100644
index 5dc69678..00000000
Binary files a/wordpress-s3/styles/arrow_left.png and /dev/null differ
diff --git a/wordpress-s3/styles/arrow_refresh.png b/wordpress-s3/styles/arrow_refresh.png
deleted file mode 100644
index 0de26566..00000000
Binary files a/wordpress-s3/styles/arrow_refresh.png and /dev/null differ
diff --git a/wordpress-s3/styles/arrow_right.png b/wordpress-s3/styles/arrow_right.png
deleted file mode 100644
index b1a18192..00000000
Binary files a/wordpress-s3/styles/arrow_right.png and /dev/null differ
diff --git a/wordpress-s3/styles/cancel.png b/wordpress-s3/styles/cancel.png
deleted file mode 100644
index c149c2bc..00000000
Binary files a/wordpress-s3/styles/cancel.png and /dev/null differ
diff --git a/wordpress-s3/styles/compress.png b/wordpress-s3/styles/compress.png
deleted file mode 100644
index 8606ff0f..00000000
Binary files a/wordpress-s3/styles/compress.png and /dev/null differ
diff --git a/wordpress-s3/styles/film.png b/wordpress-s3/styles/film.png
deleted file mode 100644
index b0ce7bb1..00000000
Binary files a/wordpress-s3/styles/film.png and /dev/null differ
diff --git a/wordpress-s3/styles/folder.gif b/wordpress-s3/styles/folder.gif
deleted file mode 100644
index 8dc04c49..00000000
Binary files a/wordpress-s3/styles/folder.gif and /dev/null differ
diff --git a/wordpress-s3/styles/folder_add.png b/wordpress-s3/styles/folder_add.png
deleted file mode 100644
index 529fe8fe..00000000
Binary files a/wordpress-s3/styles/folder_add.png and /dev/null differ
diff --git a/wordpress-s3/styles/page.png b/wordpress-s3/styles/page.png
deleted file mode 100644
index 03ddd799..00000000
Binary files a/wordpress-s3/styles/page.png and /dev/null differ
diff --git a/wordpress-s3/styles/page_code.png b/wordpress-s3/styles/page_code.png
deleted file mode 100644
index f7ea9041..00000000
Binary files a/wordpress-s3/styles/page_code.png and /dev/null differ
diff --git a/wordpress-s3/styles/page_excel.png b/wordpress-s3/styles/page_excel.png
deleted file mode 100644
index eb6158eb..00000000
Binary files a/wordpress-s3/styles/page_excel.png and /dev/null differ
diff --git a/wordpress-s3/styles/page_white.png b/wordpress-s3/styles/page_white.png
deleted file mode 100644
index 8b8b1ca0..00000000
Binary files a/wordpress-s3/styles/page_white.png and /dev/null differ
diff --git a/wordpress-s3/styles/page_white_acrobat.png b/wordpress-s3/styles/page_white_acrobat.png
deleted file mode 100644
index 8f8095e4..00000000
Binary files a/wordpress-s3/styles/page_white_acrobat.png and /dev/null differ
diff --git a/wordpress-s3/styles/page_white_excel.png b/wordpress-s3/styles/page_white_excel.png
deleted file mode 100644
index b977d7e5..00000000
Binary files a/wordpress-s3/styles/page_white_excel.png and /dev/null differ
diff --git a/wordpress-s3/styles/page_white_php.png b/wordpress-s3/styles/page_white_php.png
deleted file mode 100644
index 7868a259..00000000
Binary files a/wordpress-s3/styles/page_white_php.png and /dev/null differ
diff --git a/wordpress-s3/styles/page_white_powerpoint.png b/wordpress-s3/styles/page_white_powerpoint.png
deleted file mode 100644
index c4eff038..00000000
Binary files a/wordpress-s3/styles/page_white_powerpoint.png and /dev/null differ
diff --git a/wordpress-s3/styles/page_white_text.png b/wordpress-s3/styles/page_white_text.png
deleted file mode 100644
index 813f712f..00000000
Binary files a/wordpress-s3/styles/page_white_text.png and /dev/null differ
diff --git a/wordpress-s3/styles/page_white_word.png b/wordpress-s3/styles/page_white_word.png
deleted file mode 100644
index ae8ecbf4..00000000
Binary files a/wordpress-s3/styles/page_white_word.png and /dev/null differ
diff --git a/wordpress-s3/styles/page_white_zip.png b/wordpress-s3/styles/page_white_zip.png
deleted file mode 100644
index fd4bbccd..00000000
Binary files a/wordpress-s3/styles/page_white_zip.png and /dev/null differ
diff --git a/wordpress-s3/styles/page_word.png b/wordpress-s3/styles/page_word.png
deleted file mode 100644
index 834cdfaf..00000000
Binary files a/wordpress-s3/styles/page_word.png and /dev/null differ
diff --git a/wordpress-s3/styles/photo.png b/wordpress-s3/styles/photo.png
deleted file mode 100644
index 6c2aaaaa..00000000
Binary files a/wordpress-s3/styles/photo.png and /dev/null differ
diff --git a/wordpress-s3/styles/picture.png b/wordpress-s3/styles/picture.png
deleted file mode 100644
index 4a158fef..00000000
Binary files a/wordpress-s3/styles/picture.png and /dev/null differ
diff --git a/wordpress-s3/styles/sound.png b/wordpress-s3/styles/sound.png
deleted file mode 100644
index 6056d234..00000000
Binary files a/wordpress-s3/styles/sound.png and /dev/null differ
diff --git a/wordpress-s3/styles/styles.css b/wordpress-s3/styles/styles.css
deleted file mode 100644
index fb7641d9..00000000
--- a/wordpress-s3/styles/styles.css
+++ /dev/null
@@ -1,189 +0,0 @@
-#disable_amazonS3_span {
-
-}
-form#upload-file #disable_amazonS3_span input {
- width:auto !important;
-}
-#amazon-s3-wrap {
- padding:10px;
-}
-.infobar {
- position:relative;
- padding:0 0 6px 0;
- margin:0 0 5px 0;
- font-size:0.9em;
- border-bottom:1px solid #ddd;
-}
-.infobar a {
- border:0;
- color:black;
- text-decoration:none;
-}
-.infobar a:hover {
- text-decoration:underline;
-}
-
-.infobar .nav-controls {
- position:absolute;
- top:0px;
- left:0px;
-}
-.infobar .nav-controls a {
- display:block;
- float:left;
- margin-right:10px;
- height:18px;
- line-height:18px;
- padding-left:20px;
- background:url(arrow_left.png) no-repeat left;
- border:0;
- color:#888;
-}
-.infobar .nav-controls a#btn-upload,
-.infobar .nav-controls a#btn-folder,
-.infobar .nav-controls a#btn-forward,
-.infobar .nav-controls a#btn-refresh {
- padding-left:0px;
- padding-right:20px;
- text-indent:-10000px;
- background:url(arrow_right.png) no-repeat left;
-}
-.infobar .nav-controls a#btn-refresh {
- background-image:url(arrow_refresh.png);
-}
-.infobar .nav-controls a#btn-upload {
- background-image:url(add.png);
-}
-.infobar .nav-controls a#btn-folder {
- background-image:url(folder_add.png);
-}
-.infobar .path {
- margin-left:195px;
- line-height:18px;
-}
-.infobar .path,
-.infobar .path a{
- color:#888;
-}
-.infobar .path a.last {
- font-weight:bold;
- color:#000;
-}
-.infobar .options {
- position:absolute;
- top:0px;
- right:10px;
-}
-.infobar #upload-form, .infobar #create-form {
- display:none;
- padding:5px;
-}
-.folders {
- position:relative;
- margin:10px 0 0 0;
-}
-.folders form {
- padding:0;
-}
-.folders ul {
- list-style:none;
- margin:0;
- padding:0 0 0 0px;
-}
-.folders li {
- display:block;
- float:left;
- width:100px;
- height:18px;
- overflow:hidden;
- margin:0 10px 5px 0;
- font-size:11px;
- line-height:16px;
-}
-.folders li a {
- border:0;
- color:#555;
- text-decoration:none;
- background:white url(folder.gif) no-repeat 0px -3px;
- padding:0 0 0 20px;
-}
-.folders li a:hover {
- text-decoration:underline;
-}
-.folders li a.add {
- background-image:url(folder_add.png);
-}
-.folders li#createFolder div.form {
- display:none;
-}
-.folders li#createFolder.create div.form {
- display:inline;
-}
-.folders li#createFolder.create a.add {
- display:none;
-}
-.folders li#createFolder input {
- font-size:9px;
- padding:0;
-}
-.files {
- clear:both;
-}
-.files ul {
- list-style:none;
- margin:0;
- padding:0;
-}
-.files ul li {
- display:block;
- float:left;
- width:175px;
- height:18px;
- overflow:hidden;
- margin:0 10px 5px 0;
- font-size:11px;
- line-height:16px;
-
- padding-left:20px;
- background:url(page_white.png) no-repeat left;
-}
-.files ul li a {
- border:0;
- color:#555;
- text-decoration:none;
-}
-.files ul li a:hover {
- text-decoration:underline;
-}
-.files ul li.empty {
- color:#888;
- letter-spacing:1px;
- font-style:italic;
- background-image:none;
- padding-left:0;
-}
-.files ul li.image { background-image:url(photo.png);}
-
-.files ul li.text { background-image:url(page_white_text.png);}
-
-.files ul li.video { background-image:url(film.png);}
-.files ul li.audio,
-.files ul li.ogg { background-image:url(sound.png);}
-
-.files ul li.pdf { background-image:url(page_white_acrobat.png);}
-.files ul li.msword,
-.files ul li.doc { background-image:url(page_white_word.png);}
-.files ul li.ms-excel,
-.files ul li.xls { background-image:url(page_white_excel.png);}
-.files ul li.ms-powerpoint,
-.files ul li.ppt { background-image:url(page_white_powerpoint.png);}
-
-
-.files ul li.javascript,
-.files ul li.js,
-.files ul li.html,
-.files ul li.php,
-.files ul li.css { background-image:url(page_code.png);}
-
-.files ul li.zip { background-image:url(page_white_zip.png);}
-