Browse files

Ran all the files through WordPress flavored phpTidy.

  • Loading branch information...
1 parent 9ad4f8e commit c23f5980453ad7e9b0d45845dfb95d3b43f28ef7 @bradt bradt committed Jan 30, 2013
View
193 lib/curl.php
@@ -1,6 +1,6 @@
<?php
/*
-This is a clone of the PEAR HTTP/Request class object. It uses libcurl to do the networking stuff.
+This is a clone of the PEAR HTTP/Request class object. It uses libcurl to do the networking stuff.
Should also work with the HTTPS protocol
Important: Not every method has been ported, just the ones that were needed.
@@ -18,148 +18,148 @@ class TanTanHTTPRequestCurl {
var $response;
var $headers;
var $url;
-
- function TanTanHTTPRequestCurl($url = '', $params = array()) {
+
+ function TanTanHTTPRequestCurl( $url = '', $params = array() ) {
$this->curl = curl_init();
$this->postData = array();
$this->cookies = array();
$this->headers = array();
- if (!empty($url)) {
- $this->setURL($url);
- } else {
- $this->setURL(false);
+ if ( !empty( $url ) ) {
+ $this->setURL( $url );
+ } else {
+ $this->setURL( false );
}
- foreach ($params as $key => $value) {
+ foreach ( $params as $key => $value ) {
$this->{'_' . $key} = $value;
}
-
- $this->addHeader('Connection', 'close');
-
+
+ $this->addHeader( 'Connection', 'close' );
+
// We don't do keep-alives by default
- $this->addHeader('Connection', 'close');
+ $this->addHeader( 'Connection', 'close' );
// Basic authentication
- if (!empty($this->_user)) {
- $this->addHeader('Authorization', 'Basic ' . base64_encode($this->_user . ':' . $this->_pass));
+ 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));
+ if ( !empty( $this->_proxy_user ) ) {
+ $this->addHeader( 'Proxy-Authorization', 'Basic ' . base64_encode( $this->_proxy_user . ':' . $this->_proxy_pass ) );
}
}
-
- function addHeader($header, $value) {
+
+ function addHeader( $header, $value ) {
$this->headers[$header] = $value;
}
-
- function setMethod($method) {
+
+ 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);
+ 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');
+ 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
+ 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);
+ 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);
+ default:
+ case 'GET':
+ curl_setopt( $this->curl, CURLOPT_HTTPGET, true );
break;
- case 'HEAD':
- curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'HEAD');
+ case 'HEAD':
+ curl_setopt( $this->curl, CURLOPT_CUSTOMREQUEST, 'HEAD' );
break;
}
}
- function setURL($url) {
+ function setURL( $url ) {
$this->url = $url;
}
- function addPostData($name, $value) {
+ function addPostData( $name, $value ) {
$this->postData[$name] = $value;
}
- function addCookie($name, $value) {
- $this->cookies[$name] = array('name' => $name, 'value' => $value);
+ function addCookie( $name, $value ) {
+ $this->cookies[$name] = array( 'name' => $name, 'value' => $value );
}
function sendRequest() {
$headers = array(
- "Accept: *.*",
+ "Accept: *.*",
);
-
- foreach ($this->headers as $k=>$h) {
+
+ foreach ( $this->headers as $k=>$h ) {
$headers[] = "$k: $h";
}
- if (count($this->cookies) > 0) {
+ if ( count( $this->cookies ) > 0 ) {
$cookieVars = '';
- foreach ($this->cookies as $cookie) {
+ foreach ( $this->cookies as $cookie ) {
//$headers[] = "Cookie: ".$cookie['name'].'='.$cookie['value'];
$cookieVars .= ''.$cookie['name'].'='.$cookie['value'].'; ';
}
- curl_setopt($this->curl, CURLOPT_COOKIE, $cookieVars);
+ curl_setopt( $this->curl, CURLOPT_COOKIE, $cookieVars );
//print_r($cookieVars);
}
-
- if (count($this->postData) > 0) { // if a POST
+
+ if ( count( $this->postData ) > 0 ) { // if a POST
$postVars = '';
- foreach ($this->postData as $key=>$value) {
- $postVars .= $key.'='.urlencode($value).'&';
+ 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_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_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);
+ 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) {
+
+ 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));
+ 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);
+
+ 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;
@@ -173,39 +173,38 @@ function getResponseCode() {
function getResponseRaw() {
return $this->raw;
}
- function clearPostData($var=false) {
- if (!$var) {
+ function clearPostData( $var=false ) {
+ if ( !$var ) {
$this->postData = array();
} else {
- unset($this->postData[$var]);
+ 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;
+
+ 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];
- }
+
+ 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);
+ 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);
+ return array( "code" => $response_code, "header" => $response_header_array, "body" => $response_body );
}
}
-?>
View
25 wordpress-s3.php
@@ -18,31 +18,30 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// **********************************************************************
//
-// Forked Amazon S3 for WordPress with CloudFront (http://wordpress.org/extend/plugins/tantan-s3-cloudfront/)
+// Forked Amazon S3 for WordPress with CloudFront (http://wordpress.org/extend/plugins/tantan-s3-cloudfront/)
// which is a fork of Amazon S3 for WordPress (http://wordpress.org/extend/plugins/tantan-s3/).
*/
-if (class_exists('TanTanWordPressS3Plugin')) return;
+if ( class_exists( 'TanTanWordPressS3Plugin' ) ) return;
// s3 lib requires php5
-if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/') >= 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');
+if ( strpos( $_SERVER['REQUEST_URI'], '/wp-admin/' ) >= 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 (ereg('wordpress-mu-', $ver)) {
- require_once(dirname(__FILE__).'/wordpress-s3/class-plugin.php');
+ } elseif ( ereg( '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.html');}
+ 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.html';}
}
$error = new TanTanWordPressS3Error();
}
} else {
- require_once(dirname(__FILE__).'/wordpress-s3/class-plugin-public.php');
+ require_once dirname( __FILE__ ).'/wordpress-s3/class-plugin-public.php';
$TanTanWordPressS3Plugin = new TanTanWordPressS3PluginPublic();
}
-?>
View
40 wordpress-s3/admin-options.html
@@ -1,6 +1,6 @@
-<?php if ( isset($error) && $error ):?>
+<?php if ( isset( $error ) && $error ):?>
<div id="message" class="error fade"><p><strong><?php echo $error?></strong></p></div>
-<?php elseif ( isset($message) && $message ):?>
+<?php elseif ( isset( $message ) && $message ):?>
<div id="message" class="updated fade"><p><strong><?php echo $message?></strong></p></div>
<?php endif;?>
<script type="text/javascript">
@@ -82,8 +82,8 @@
<div id="icon-options-general" class="icon32"><br></div>
<h2 id="write-post">Amazon S3 and CloudFront</h2>
<?php
-global $TanTanVersionCheck;
-if (is_object($TanTanVersionCheck)):?>
+ global $TanTanVersionCheck;
+if ( is_object( $TanTanVersionCheck ) ):?>
<div style="width:200px; border:1px solid #ccc;padding:10px; float:right; margin:0 0 10px 10px;">
<strong>Plugin Updates:</strong><br />
<a href="plugins.php?page=tantan/version-check.php">Check for updates to this plugin &gt;</a>
@@ -97,24 +97,24 @@ <h2 id="write-post">Amazon S3 and CloudFront</h2>
<td colspan="2">
<h3>AWS Access Credentials</h3>
<p>
- If you don't have an Amazon S3 account yet, you need to
+ If you don't have an Amazon S3 account yet, you need to
<a href="http://aws.amazon.com/s3/">sign up</a>.<br />
- Once you've signed up, you can retrieve your access credentials from the
+ Once you've signed up, you can retrieve your access credentials from the
<a href="https://portal.aws.amazon.com/gp/aws/securityCredentials">Security Credentials</a>
page of your Amazon Web Services account.
</p>
</td>
</tr>
<tr valign="top">
-<th width="33%" scope="row">Access Key ID:</th>
-<td><input type="text" name="options[key]" value="<?php echo $options['key'];?>" size="50" /></td>
+<th width="33%" scope="row">Access Key ID:</th>
+<td><input type="text" name="options[key]" value="<?php echo $options['key'];?>" size="50" /></td>
</tr>
<tr valign="top">
-<th width="33%" scope="row">Secret Access Key:</th>
-<td><input type="text" name="options[secret]" value="<?php echo ($options['secret'] ? '-- not shown --' : '');?>" size="50" /></td>
+<th width="33%" scope="row">Secret Access Key:</th>
+<td><input type="text" name="options[secret]" value="<?php echo $options['secret'] ? '-- not shown --' : '';?>" size="50" /></td>
</tr>
-<?php if (!isset($buckets) || !$buckets):?>
+<?php if ( !isset( $buckets ) || !$buckets ):?>
<tr valign="top">
<td colspan="2">
<p class="submit">
@@ -129,11 +129,11 @@ <h2 id="write-post">Amazon S3 and CloudFront</h2>
</td>
</tr>
<tr valign="top">
- <th width="33%" scope="row">&nbsp;</th>
+ <th width="33%" scope="row">&nbsp;</th>
<td>
<select name="options[bucket]" size="1" onchange="return s3_selectBucket(this)" style="margin-bottom: 5px; width: 380px;">
<option value="">-- Select an S3 Bucket --</option>
- <?php if (is_array($buckets)) foreach ($buckets as $bucket):?>
+ <?php if ( is_array( $buckets ) ) foreach ( $buckets as $bucket ):?>
<option value="<?php echo $bucket?>" <?php echo ( isset( $options['bucket'] ) && $bucket == $options['bucket'] ) ? 'selected="selected"' : ''; ?>><?php echo $bucket?></option>
<?php endforeach;?>
<option value="new">Create a new bucket...</option>
@@ -150,16 +150,16 @@ <h2 id="write-post">Amazon S3 and CloudFront</h2>
<input type="checkbox" name="options[permissions]" value="public" id="permissions" <?php echo ( isset( $options['permissions'] ) && $options['permissions'] == 'public' ) ? 'checked="checked" ' : ''; ?> />
<label for="permissions"> Force set the permissions on all files in the bucket to public</label>
- </td>
+ </td>
</tr>
-
+
<tr valign="top">
<td colspan="2">
<h3>CloudFront Settings</h3>
</td>
</tr>
<tr valign="top">
- <th width="33%" scope="row">Domain Name</th>
+ <th width="33%" scope="row">Domain Name</th>
<td>
<input type="text" name="options[cloudfront]" value="<?php echo isset( $options['cloudfront'] ) ? $options['cloudfront'] : ''; ?>" size="50" />
<p class="description">Leave blank if you aren't using CloudFront.</p>
@@ -170,15 +170,15 @@ <h2 id="write-post">Amazon S3 and CloudFront</h2>
<td colspan="2">
<h3>Plugin Settings</h3>
</td>
- </tr>
+ </tr>
<tr valign="top">
- <th width="33%" scope="row">&nbsp;</th>
+ <th width="33%" scope="row">&nbsp;</th>
<td>
<input type="checkbox" name="options[wp-uploads]" value="1" id="wp-uploads" <?php echo ( isset( $options['wp-uploads'] ) && $options['wp-uploads'] ) ? 'checked="checked" ' : ''; ?> />
<label for="wp-uploads"> Enable copying of media files to S3 and serving media files from S3/CloudFront</label>
<p class="description">Uncheck this to revert back to using your own web host for storage and delivery at anytime.</p>
- </td>
+ </td>
</tr>
<tr>
@@ -215,4 +215,4 @@ <h2 id="write-post">Amazon S3 and CloudFront</h2>
-</div>
+</div>
View
6 wordpress-s3/admin-tab-head.html
@@ -1,7 +1,7 @@
<?php
-$dir = dirname(__FILE__);
+$dir = dirname( __FILE__ );
$pluginRootURL = plugins_url( '', __FILE__ );
-if (!ereg('media-upload.php', $_SERVER['REQUEST_URI'])): // WP < 2.5
+if ( !ereg( 'media-upload.php', $_SERVER['REQUEST_URI'] ) ): // WP < 2.5
?>
<script type="text/javascript">
@@ -14,7 +14,7 @@
as[i].innerHTML = '<span style="padding:0 20px 0 0;background:url(<?php echo $pluginRootURL;?>/database.png) no-repeat right;">' + as[i].innerHTML + '</span>';
}
}
- <?php if ($this->options['wp-uploads'] && $this->options['bucket']):?>
+ <?php if ( $this->options['wp-uploads'] && $this->options['bucket'] ):?>
var upload = document.getElementById('upload');
if (upload && upload.name == 'image') {
var span = document.createElement('span');
View
68 wordpress-s3/admin-tab.html
@@ -1,9 +1,9 @@
<?php
-function print_file_type($contentType, $file) {
- if (ereg('octet-stream', $contentType)) {
- return ereg_replace('(.*)\.([a-zA-Z0-9]*)$', '\\2', $file);
+function print_file_type( $contentType, $file ) {
+ if ( ereg( 'octet-stream', $contentType ) ) {
+ return ereg_replace( '(.*)\.([a-zA-Z0-9]*)$', '\\2', $file );
} else {
- return ereg_replace('vnd.', '', ereg_replace('/', ' ', $contentType));
+ return ereg_replace( 'vnd.', '', ereg_replace( '/', ' ', $contentType ) );
}
}
?>
@@ -13,7 +13,7 @@
<div class="infobar">
<span class="nav-controls">
-<?php if (true || $_SERVER['HTTP_REFERER']):?>
+<?php if ( true || $_SERVER['HTTP_REFERER'] ):?>
<a href="javascript:history.back()" onclick="" id="btn-back" title="back">back</a>
<a href="javascript:history.forward()" onclick="" id="btn-forward" title="forward">forward</a>
<?php endif; ?>
@@ -22,26 +22,26 @@
<a href="#" onclick="return s3_toggleCreateFolder();" id="btn-folder" title="create new folder">new folder</a>
</span>
<span class="path">
-<?php
+<?php
$tree = $keys;
-echo '<a href="'.add_query_arg('prefix', urlencode(''), $_SERVER['REQUEST_URI']).'" class="home">home</a> / ';
+echo '<a href="'.add_query_arg( 'prefix', urlencode( '' ), $_SERVER['REQUEST_URI'] ).'" class="home">home</a> / ';
$path = '';
-$paths = preg_split('/\//', $prefix, 100, PREG_SPLIT_NO_EMPTY);
-$numPaths = count($paths);
+$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 '<a class="'.( $isLast ? 'last' : '').'" href="'.add_query_arg('prefix', urlencode($path), $_SERVER['REQUEST_URI']).'">'.$name.'</a> '.(!$isLast ? ' / ' : ' ');
-}
+foreach ( $paths as $name ) if ( $name ) {
+ $path .= $name .'/';
+ $isLast = ( ++$i ) >= $numPaths;
+ echo '<a class="'.( $isLast ? 'last' : '' ).'" href="'.add_query_arg( 'prefix', urlencode( $path ), $_SERVER['REQUEST_URI'] ).'">'.$name.'</a> '.( !$isLast ? ' / ' : ' ' );
+ }
?>
</span>
<span class="options">
<input type="checkbox" name="useBittorrent" id="useBittorrent" value="1" /><label for="useBittorrent"> create links as torrents</label>
</span>
<div id="create-form">
<form method="post">
- <input type="hidden" name="prefix" value="<?php echo htmlentities($_GET['prefix']);?>">
+ <input type="hidden" name="prefix" value="<?php echo htmlentities( $_GET['prefix'] );?>">
<input type="text" name="newfolder" id="newfolder" />
<input type="submit" value="create" />
</form>
@@ -57,35 +57,35 @@
<div class="folders">
<form method="post">
<ul id="prefixes">
-<?php
-if (is_array($prefixes)) foreach ($prefixes as $prefix):
-$label = substr($prefix, strrpos(trim($prefix, '/'), '/')+1);
-$label = ($path ? ereg_replace($path, "", '/'.$prefix) : $prefix);
-$label = trim($prefix, '/');
-if (ereg('/', $label)) $label = substr($label, strrpos($label, '/')+1);
+<?php
+if ( is_array( $prefixes ) ) foreach ( $prefixes as $prefix ):
+ $label = substr( $prefix, strrpos( trim( $prefix, '/' ), '/' )+1 );
+ $label = ( $path ? ereg_replace( $path, "", '/'.$prefix ) : $prefix );
+$label = trim( $prefix, '/' );
+if ( ereg( '/', $label ) ) $label = substr( $label, strrpos( $label, '/' )+1 );
?>
-<li><a href="<?php echo add_query_arg('prefix', urlencode($prefix), $_SERVER['REQUEST_URI']);?>" title="<?php echo $label;?>"><?php echo $label;?></a></li>
-<?php
+<li><a href="<?php echo add_query_arg( 'prefix', urlencode( $prefix ), $_SERVER['REQUEST_URI'] );?>" title="<?php echo $label;?>"><?php echo $label;?></a></li>
+<?php
endforeach;
?>
</ul>
</form>
</div>
<div class="files">
<ul id="keys">
-<?php if (count($keys)): foreach ($keys as $i => $file):
- $file = '/'.$file;
- $url = 'http://'.$accessDomain.$file;
- $label = substr($file, strrpos($file, '/')+1);
+<?php if ( count( $keys ) ): foreach ( $keys as $i => $file ):
+ $file = '/'.$file;
+ $url = 'http://'.$accessDomain.$file;
+$label = substr( $file, strrpos( $file, '/' )+1 );
?>
-<li class="<?php echo print_file_type($meta[$i]['content-type'], $file);?>"><a
-<?php if (ereg("^image/.*", $meta[$i]['content-type'])):?>
-onclick="return s3_insertImage('<?php echo $url;?>', '<?php echo basename($url);?>')"
+<li class="<?php echo print_file_type( $meta[$i]['content-type'], $file );?>"><a
+<?php if ( ereg( "^image/.*", $meta[$i]['content-type'] ) ):?>
+onclick="return s3_insertImage('<?php echo $url;?>', '<?php echo basename( $url );?>')"
<?php else:?>
-onclick="return s3_insertLink('<?php echo addslashes($label);?>', '<?php echo $url;?>')"
+onclick="return s3_insertLink('<?php echo addslashes( $label );?>', '<?php echo $url;?>')"
<?php endif;?>
-href="<?php echo $url;?>"
-class="file <?php echo ereg_replace('/', ' ', $meta[$i]['content-type']);?>"
+href="<?php echo $url;?>"
+class="file <?php echo ereg_replace( '/', ' ', $meta[$i]['content-type'] );?>"
title="<?php echo $meta[$i]['date'];?> - <?php echo $meta[$i]['content-length'];?> bytes"><?php echo $label;?></a>
</li>
<?php endforeach;?>
@@ -95,4 +95,4 @@
</ul>
</div>
</div>
-<br clear="both" />
+<br clear="both" />
View
16 wordpress-s3/admin-version-error.html
@@ -1,6 +1,6 @@
-<?php if ($error):?>
+<?php if ( $error ):?>
<div id="message" class="error fade"><p><strong><?php echo $error?></strong></p></div>
-<?php elseif ($message):?>
+<?php elseif ( $message ):?>
<div id="message" class="updated fade"><p><strong><?php echo $message?></strong></p></div>
<?php endif;?>
@@ -36,23 +36,23 @@ <h2 id="write-post">Amazon S3 Plugin for WordPress</h2>
Use the coupon code
<b>TANTAN50COUPON</b>
when you signup to get a $50 discount, and you'll
- help support this plugin in the process.
+ help support this plugin in the process.
That works out to be less than $6.00 per month for the first year.
-
+
</div>
<h3>Error</h3>
<p>
-Sorry, this plugin requires at least PHP <strong>5.0</strong> and WordPress <strong>2.1</strong> in order to work correctly.
+Sorry, this plugin requires at least PHP <strong>5.0</strong> and WordPress <strong>2.1</strong> in order to work correctly.
Please contact your systems administrator about getting your version of PHP and/or WordPress upgraded.
</p>
<p>
-Your PHP version: <strong style="<?php echo (version_compare(phpversion(), '5.0.0', '<') ? 'color:red;' : '');?>"><?php echo phpversion();?></strong><br />
-Your WordPress version: <strong style="<?php echo (version_compare(get_bloginfo('version'), '2.1', '<') ? 'color:red;' : '');?>"><?php bloginfo('version'); ?></strong>
+Your PHP version: <strong style="<?php echo version_compare( phpversion(), '5.0.0', '<' ) ? 'color:red;' : '';?>"><?php echo phpversion();?></strong><br />
+Your WordPress version: <strong style="<?php echo version_compare( get_bloginfo( 'version' ), '2.1', '<' ) ? 'color:red;' : '';?>"><?php bloginfo( 'version' ); ?></strong>
<br />
</p>
<p>
<a href="http://www.php.net/downloads.php">Download PHP</a><br />
<a href="http://wordpress.org/download/">Download WordPress</a><br />
</p>
-</div>
+</div>
View
116 wordpress-s3/class-plugin-public.php
@@ -1,94 +1,94 @@
<?php
class TanTanWordPressS3PluginPublic {
- var $options;
- var $s3;
+ var $options;
+ var $s3;
var $meta;
function TanTanWordPressS3PluginPublic() {
$this->options = array();
- if (file_exists(dirname(__FILE__).'/config.php')) {
- require_once(dirname(__FILE__).'/config.php');
- if ($TanTanWordPressS3Config) $this->options = $TanTanWordPressS3Config;
+ 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'));
+ add_action( 'plugins_loaded', array( &$this, 'addhooks' ) );
}
- function addhooks() {
- add_filter('wp_get_attachment_url', array(&$this, 'wp_get_attachment_url'), 9, 2);
+ 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 ($this->options['wp-uploads'] && ($amazon = get_post_meta($postID, 'amazonS3_info', true))) {
- if ( isset($this->options['cloudfront']) && $this->options['cloudfront'] ) {
- $accessDomain = $this->options['cloudfront'];
+ function wp_get_attachment_url( $url, $postID ) {
+ if ( !$this->options ) $this->options = get_option( 'tantan_wordpress_s3' );
+
+ if ( $this->options['wp-uploads'] && ( $amazon = get_post_meta( $postID, 'amazonS3_info', true ) ) ) {
+ 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 ( isset($this->options['virtual-host']) && $this->options['virtual-host'] ) {
- $accessDomain = $this->options['bucket'];
- }
- else {
+ else {
$accessDomain = $amazon['bucket'] . '.s3.amazonaws.com';
- }
+ }
- $url = 'http://'.$accessDomain.'/'.$amazon['key'];
+ $url = 'http://'.$accessDomain.'/'.$amazon['key'];
- $url = apply_filters( 'wps3_get_attachment_url', $url, $postID, $this );
- }
+ $url = apply_filters( 'wps3_get_attachment_url', $url, $postID, $this );
+ }
- return $url;
- }
+ 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 $bucket The name of the bucket in which the file is stored.
- * @param $filekey The key of the file, excluding the leading slash.
- * @param $expires The amount of time the link is valid (in seconds).
- * @param $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');
+ * 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 (
+ if (
!$this->options['wp-uploads'] || !$this->options['key'] || !$this->options['secret']
- || !$this->options['bucket'] || !($amazon = get_post_meta($postID, 'amazonS3_info', true))
+ || !$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);
+ $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 = 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 /
+ "\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 ) );
- 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);
+ 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') {
+function wps3_get_secure_attachment_url( $postID, $expires = 900, $operation = 'GET' ) {
global $TanTanWordPressS3Plugin;
- return $TanTanWordPressS3Plugin->get_secure_attachment_url($postID, $expires, $operation);
+ return $TanTanWordPressS3Plugin->get_secure_attachment_url( $postID, $expires, $operation );
}
View
699 wordpress-s3/class-plugin.php
@@ -1,22 +1,22 @@
<?php
-require_once(dirname(__FILE__).'/class-plugin-public.php');
+require_once dirname( __FILE__ ).'/class-plugin-public.php';
class TanTanWordPressS3Plugin extends TanTanWordPressS3PluginPublic {
-
+
function TanTanWordPressS3Plugin() {
- parent::TanTanWordPressS3PluginPublic();
- if (!file_exists(dirname(__FILE__).'/config.php')) {
- add_action('admin_menu', array(&$this, 'settings'));
- }
- if (!isset($this->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') {
+ parent::TanTanWordPressS3PluginPublic();
+ if ( !file_exists( dirname( __FILE__ ).'/config.php' ) ) {
+ add_action( 'admin_menu', array( &$this, 'settings' ) );
+ }
+ if ( !isset( $this->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();
@@ -25,64 +25,64 @@ function TanTanWordPressS3Plugin() {
}
-
+
// this should install the javascripts onto the user's s3.amazonaws.com account
-
+
function installAjax() {
- $js = array('S3Ajax.js');
+ $js = array( 'S3Ajax.js' );
}
-
+
function activate() {
- wp_redirect('plugins.php?tantanActivate=wordpress-s3');
+ wp_redirect( 'plugins.php?tantanActivate=wordpress-s3' );
exit;
}
function deactivate() {}
-
+
function showConfigNotice() {
- add_action('admin_notices', create_function('', 'echo \'<div id="message" class="updated fade"><p>Amazon S3 Plugin for WordPress <strong>activated</strong>. <a href="options-general.php?page=tantan/wordpress-s3/class-plugin.php">Configure the plugin &gt;</a></p></div>\';'));
+ add_action( 'admin_notices', create_function( '', 'echo \'<div id="message" class="updated fade"><p>Amazon S3 Plugin for WordPress <strong>activated</strong>. <a href="options-general.php?page=tantan/wordpress-s3/class-plugin.php">Configure the plugin &gt;</a></p></div>\';' ) );
}
- function settings() {
- add_options_page('Amazon S3', 'Amazon S3', 10, __FILE__, array(&$this, 'admin'));
- $this->version_check();
- }
+ function settings() {
+ add_options_page( 'Amazon S3', 'Amazon S3', 10, __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'));
+ 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']);
+ 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'] || ereg('not shown', $_POST['options']['secret'])) {
+ 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'] || ereg( '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')) {
+
+ 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'];
@@ -93,334 +93,334 @@ function admin() {
} 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')) {
+ 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 <em>".$_POST['options']['bucket']."</em>. ".
- "Double check and make sure the following entry is added to your DNS. ".
- "<a href='http://docs.amazonwebservices.com/AmazonS3/2006-03-01/VirtualHosting.html'>More info &gt;</a>".
- "<br /><br />".
+ "Double check and make sure the following entry is added to your DNS. ".
+ "<a href='http://docs.amazonwebservices.com/AmazonS3/2006-03-01/VirtualHosting.html'>More info &gt;</a>".
+ "<br /><br />".
"<code>".$_POST['options']['bucket']." CNAME ".$_POST['options']['bucket'].".s3.amazonaws.com.</code>".
- "<br /><br />".
- "<small>You can ignore this message if you're sure everything is setup correctly.</small>";
+ "<br /><br />".
+ "<small>You can ignore this message if you're sure everything is setup correctly.</small>";
}
}
}
- $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']);
- if (!($buckets = $s3->listBuckets())) {
- $error = $this->getErrorMessage($s3->parsed_xml, $s3->responseCode);
+ $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'] );
+ if ( !( $buckets = $s3->listBuckets() ) ) {
+ $error = $this->getErrorMessage( $s3->parsed_xml, $s3->responseCode );
}
-
+
$s3->initCacheTables();
-
- } elseif ($options['key']) {
+
+ } elseif ( $options['key'] ) {
$error = "Please enter your Secret Access Key.";
- } elseif ($options['secret']) {
+ } elseif ( $options['secret'] ) {
$error = "Please enter your Access Key ID.";
}
-
-
- include(dirname(__FILE__).'/admin-options.html');
+
+
+ include dirname( __FILE__ ).'/admin-options.html';
}
-
-
- /*
- Delete corresponding files from Amazon S3
- */
- function delete_attachment( $post_id ) {
- if (!$this->options) $this->options = get_option('tantan_wordpress_s3');
-
- if (!$this->options['wp-uploads'] || !$this->options['bucket'] || !$this->options['secret']) {
+
+
+ /*
+ Delete corresponding files from Amazon S3
+ */
+ function delete_attachment( $post_id ) {
+ if ( !$this->options ) $this->options = get_option( 'tantan_wordpress_s3' );
+
+ if ( !$this->options['wp-uploads'] || !$this->options['bucket'] || !$this->options['secret'] ) {
return;
}
- $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
+ $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;
- }
+ $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;
- }
+ if ( !( $amazon = get_post_meta( $post_id, 'amazonS3_info', true ) ) ) {
+ return;
+ }
- $amazon_path = dirname( $amazon['key'] );
+ $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);
+ 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'] ) );
- }
+ // 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 ) );
- }
- }
+ 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'] );
- }
+ $this->s3->deleteObject( $amazon['bucket'], $amazon['key'] );
+ }
- function wp_get_attachment_metadata($data=false, $postID=false) {
- if (is_numeric($postID)) $this->meta = get_post_meta($postID, 'amazonS3_info', true);
- return $data;
- }
+ 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 (!$this->options['wp-uploads'] || !$this->options['bucket'] || !$this->options['secret']) {
+ function wp_update_attachment_metadata( $data, $postID ) {
+ if ( !$this->options ) $this->options = get_option( 'tantan_wordpress_s3' );
+
+ if ( !$this->options['wp-uploads'] || !$this->options['bucket'] || !$this->options['secret'] ) {
return $data;
}
-
- add_filter('option_siteurl', array(&$this, 'upload_path'));
+
+ 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(
+ 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 {
-
- }
- }
+ '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) {
+ 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 = ' <a href="'.$media_upload_iframe_src.'&tab=tantan-wordpress-s3&TB_iframe=true&height=500&width=640" class="thickbox" title="'.$image_title.'"><img src="'.$image_btn.'" alt="'.$image_title.'" /></a>';
- return $context.$out;
- }
- function media_upload_tabs( $tabs ) {
- $tabs['tantan-wordpress-s3'] = 'Amazon S3';
- return $tabs;
- }
- function media_upload_content() {
+ // 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 = ' <a href="'.$media_upload_iframe_src.'&tab=tantan-wordpress-s3&TB_iframe=true&height=500&width=640" class="thickbox" title="'.$image_title.'"><img src="'.$image_btn.'" alt="'.$image_title.'" /></a>';
+ 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);
+
+ 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'));
- }
+
+ 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'));
+ 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),
+ 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 ) $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']) {
+
+ 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
+ $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' => 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);
+ 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'];
- }
+ 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';
+ 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');
+ if ( !$this->options ) $this->options = get_option( 'tantan_wordpress_s3' );
$accessDomain = $this->get_access_domain();
- include(dirname(__FILE__).'/admin-tab-head.html');
+ include dirname( __FILE__ ).'/admin-tab-head.html';
}
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 (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 ($_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']);
- }
+ 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 ( 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 ( $_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/', '/');
- }
+ 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) $_GET['paged'];
- if (!$offsetpage) $offsetpage = 1;
-
- if (!$this->options['key'] || !$this->options['secret']) {
+ if ( !$offsetpage ) $offsetpage = 1;
+
+ if ( !$this->options['key'] || !$this->options['secret'] ) {
return;
}
$bucket = $this->options['bucket'];
$accessDomain = $this->get_access_domain();
-
+
$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.html');
+ 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.html';
}
-
- function getErrorMessage($parsed_xml, $responseCode){
- $message = 'Error '.$responseCode.': ' . $parsed_xml->Message;
- if(isset($parsed_xml->StringToSignBytes)) $message .= "<br>Hex-endcoded string to sign: " . $parsed_xml->StringToSignBytes;
- return $message;
+
+ function getErrorMessage( $parsed_xml, $responseCode ) {
+ $message = 'Error '.$responseCode.': ' . $parsed_xml->Message;
+ if ( isset( $parsed_xml->StringToSignBytes ) ) $message .= "<br>Hex-endcoded string to sign: " . $parsed_xml->StringToSignBytes;
+ return $message;
}
// turns array('a', 'b', 'c') into $array['a']['b']['c']
- function mapKey($keys, $path) {
+ function mapKey( $keys, $path ) {
$k =& $keys;
- $size = count($path) - 1;
+ $size = count( $path ) - 1;
$workingPath = '/';
- foreach ($path as $i => $p) {
- if ($i === $size) {
- $k['_size'] = isset($k['_size']) ? $k['_size'] + 1 : 1;
+ 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 {
@@ -430,67 +430,66 @@ function mapKey($keys, $path) {
}
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) {
+ 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 = ereg('^\.', $key)) &&
- !($p2 = ereg('_\$folder\$$', $key)) &&
- !($p3 = ereg('placeholder.ns3', $key))) {
- $privateKeys[] = $key;
- } elseif ($p2) {
- $prefix = ereg_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;
- }
- }
-
- foreach ($keys as $i => $key) {
- $meta[$i] = $this->s3->getMetadata($this->options['bucket'], $key);
- }
- natcasesort($keys);
- natcasesort($prefixes);
-
- return array($prefixes, $keys, $meta, $privateKeys);
+ $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 = ereg( '^\.', $key ) ) &&
+ !( $p2 = ereg( '_\$folder\$$', $key ) ) &&
+ !( $p3 = ereg( 'placeholder.ns3', $key ) ) ) {
+ $privateKeys[] = $key;
+ } elseif ( $p2 ) {
+ $prefix = ereg_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;
+ }
+ }
+
+ foreach ( $keys as $i => $key ) {
+ $meta[$i] = $this->s3->getMetadata( $this->options['bucket'], $key );
+ }
+ natcasesort( $keys );
+ natcasesort( $prefixes );
+
+ return array( $prefixes, $keys, $meta, $privateKeys );
}
-
- function isPublic($key) {
+
+ function isPublic( $key ) {
$everyone = 'http://acs.amazonaws.com/groups/global/AllUsers';
- $this->s3->getObjectACL($this->options['bucket'], $key);
+ $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'] && (ereg('AllUsers', (string) $grant['Grantee']->URI))) {
- $perm = (string) $grant['Permission'];
- if ($perm == 'READ' || $perm == 'FULL_CONTROL') return true;
+ if ( is_array( $acl['Grant'] ) ) foreach ( $acl['Grant'] as $grant ) {
+ $grant = (array) $grant;
+ if ( $grant['Grantee'] && ( ereg( 'AllUsers', (string) $grant['Grantee']->URI ) ) ) {
+ $perm = (string) $grant['Permission'];
+ if ( $perm == 'READ' || $perm == 'FULL_CONTROL' ) return true;
+ }
}
- }
-
+
}
}
-?>
View
3 wordpress-s3/config-sample.php
@@ -11,5 +11,4 @@
'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
- );
-?>
+);
View
417 wordpress-s3/lib.s3.php
@@ -2,22 +2,22 @@
/*
Calculates RFC 2104 compliant HMACs.
Based on code from http://pear.php.net/package/Crypt_HMAC
-*/
+*/
class TanTanCrypt_HMAC {
-var $_func;var $_ipad;var $_opad;var $_pack;
-function TanTanCrypt_HMAC($key, $func = 'md5'){$this->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)));}
+ var $_func;var $_ipad;var $_opad;var $_pack;
+ function TanTanCrypt_HMAC( $key, $func = 'md5' ) {$this->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');
+if ( !class_exists( 'TanTanHTTPRequestCurl' ) ) require_once dirname( __FILE__ ).'/../lib/curl.php';
/*
based on code provided by Amazon
@@ -42,7 +42,7 @@ class TanTanS3 {
var $req;
var $fp;
var $options;
-
+
/**
* Constructor
*
@@ -52,42 +52,42 @@ class TanTanS3 {
* - [str] $secretKey: Your AWS Secret Access Key
* - [str] $serviceUrl: OPTIONAL: defaults: http://s3.amazonaws.com/
*
- */
- function TanTanS3($accessKeyId, $secretKey, $serviceUrl="http://s3.amazonaws.com/") {