added new wp-s3 repo

This commit is contained in:
Kenneth Reitz
2010-04-07 02:18:53 -04:00
parent 8f75fe67c4
commit 02ca15aaad
43 changed files with 4 additions and 1861 deletions
+3
View File
@@ -13,3 +13,6 @@
[submodule "blog/wp-content/plugins/wp-async-google-analytics"]
path = blog/wp-content/plugins/wp-async-google-analytics
url = git://github.com/kennethreitz/wp-async-google-analytics.git
[submodule "blog/wp-content/plugins/wp-s3"]
path = blog/wp-content/plugins/wp-s3
url = git://github.com/kennethreitz/wp-s3.git
@@ -1,204 +0,0 @@
<?php
/*
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.
$Revision: 66280 $
$Date: 2008-09-25 15:28:23 +0000 (Thu, 25 Sep 2008) $
$URL: https://photo-album.googlecode.com/svn/trunk/tantan-flickr/lib/curl.php $
*/
class TanTanHTTPRequestCurl {
var $curl;
var $postData;
var $cookies;
var $raw;
var $response;
var $headers;
var $url;
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);
}
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) {
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);
$response_header_array[$header] .= $value."\n";
}
return array("code" => $response_code, "header" => $response_header_array, "body" => $response_body);
}
}
?>
@@ -1,30 +0,0 @@
=== Plugin Name ===
Contributors: joetan
Tags: uploads, amazon, s3, mirror, admin, media
Requires at least: 2.3
Tested up to: 2.7
Stable tag: 0.3.4
Allows you to mirror your WordPress media uploads over to Amazon S3 for storage and delivery.
== Description ==
This WordPress plugin allows you to use Amazon's Simple Storage Service to host your media for your WordPress powered blog.
Amazon S3 is a cheap and cost effective way to scale your site to easily handle large spikes in traffic (such as from Digg) without having to go through the expense of setting up the infrastructure for a content delivery network.
Once setup, this plugin transparently integrates with your WordPress blog. File uploads are automatically saved into your Amazon S3 bucket without any extra steps. Once saved, these files will be delivered by Amazon S3, instead of your web host. Any image thumbnails that get created are saved to Amazon S3 too. You'll also find an "Amazon S3" tab next to your regular "Upload" tab, which allows you to easily browse and manage files that were not upload via WordPress.
== Installation ==
1. Upload `tantan-s3` to the `/wp-content/plugins/` directory
1. Activate the plugin through the 'Plugins' menu in WordPress
1. Configure the plugin in the 'Options' (or 'Settings') screen by following the onscreen prompts.
## Documentation
If you need more help installing and configuring the plugin, [see here for more information](http://code.google.com/p/wordpress-s3/wiki/Documentation).
== Screenshots ==
1. The settings screen for the plugin
2. Browse files in a Amazon S3 bucket
Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

@@ -1,63 +0,0 @@
<?php
/*
Plugin Name: Amazon S3 for WordPress
Plugin URI: http://tantannoodles.com/toolkit/wordpress-s3/
Description: Allows you to retrieves objects stored in Amazon S3 and post them in WordPress.
Author: Joe Tan
Version: 0.4
Author URI: http://tantannoodles.com/
Copyright (C) 2008 Joe Tan
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Release Page:
http://tantannoodles.com/toolkit/wordpress-s3/
Project Page:
http://code.google.com/p/wordpress-s3/
Changlog:
http://code.google.com/p/wordpress-s3/wiki/ChangeLog
$Revision: 89650 $
$Date: 2009-01-27 02:01:33 +0000 (Tue, 27 Jan 2009) $
$Author: joetan $
*/
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');
$TanTanWordPressS3Plugin = new TanTanWordPressS3Plugin();
} 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');}
}
$error = new TanTanWordPressS3Error();
}
} else {
require_once(dirname(__FILE__).'/wordpress-s3/class-plugin-public.php');
$TanTanWordPressS3Plugin = new TanTanWordPressS3PluginPublic();
}
?>
@@ -1,217 +0,0 @@
<?php if ($error):?>
<div id="message" class="error fade"><p><strong><?php echo $error?></strong></p></div>
<?php elseif ($message):?>
<div id="message" class="updated fade"><p><strong><?php echo $message?></strong></p></div>
<?php endif;?>
<script type="text/javascript">
function s3_selectBucket(obj) {
if (obj.options[obj.selectedIndex].value == 'new') {
var bucket = prompt("Bucket name: ");
if (bucket) {
var len = obj.options.length
obj.options[len] = new Option("New bucket: " + bucket, bucket);
obj.options[len].selected = true;
}
}
}
</script>
<style type="text/css">
fieldset.options {
clear:both;
border:1px solid #ccc;
}
fieldset.options legend {
font-family: Georgia,"Times New Roman",Times,serif;
font-size: 22px;
}
div.album {
float:left;
width:200px;
height:150px;
margin-right:15px;
}
div.album td {
font-size:0.9em;
}
div.album-hidden img {
opacity:0.5;
}
</style>
<div class="wrap">
<h2 id="write-post">Amazon S3 Plugin for WordPress</h2>
<?php
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>
</div>
<?php endif;?>
<p>
This plugin allows you to easily upload, retrieve, and link to files stored on Amazon's S3 web service from within WordPress.
</p>
<p><strong>Amazon S3 Setup:</strong> If you don't have an Amazon S3 account yet, here's a <a href="http://www.brightcove.com/title.jsp?title=769277068&channel=770166766">quick video tutorial</a> that'll show
you how to set one up. <a href="http://www.amazon.com/s3/">Sign up for Amazon S3 &gt;</a>
</p>
<p><strong>Plugin Installation and Usage:</strong> Just follow the onscreen prompts to link this plugin to your Amazon S3 account. </p>
<div style="float:right;width:250px;background:#eee;padding:10px;font-size:0.9em;">
If you find this plugin helpful, please consider donating a few dollars to support this plugin. Thanks!
<br /><br />
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_donations" />
<input type="hidden" name="business" value="joetan54@gmail.com" />
<input type="hidden" name="item_name" value="TanTanNoodles Plugin Donation" />
<input type="hidden" name="item_number" value="WordPress S3" />
<input type="hidden" name="page_style" value="Primary" />
<input type="hidden" name="no_shipping" value="1" />
<input type="hidden" name="return" value="http://tantannoodles.com/donation-thankyou/" />
<input type="hidden" name="cancel_return" value="http://tantannoodles.com/" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="tax" value="0" />
<input type="hidden" name="cn" value="Message / Note" />
<input type="hidden" name="lc" value="US" />
<input type="hidden" name="bn" value="PP-DonationsBF" />
<div style="float:left;width:150px;padding-top:10px">
Amount: $<input type="text" name="amount" value="" style="width:50px;" /> <br />
</div>
<div style="float:right;width:100px">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-butcc-donate.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" />
</div>
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" style="clear:both;" />
</form>
</div>
<p>
This plugin is provided by <a href="http://www.tantannoodles.com">TanTanNoodles</a>
and licensed free of charge for you to use under the GPL.
This plugin is <em>unsupported</em> and comes with no official technical support.
</p>
<p>
You can check the following pages for the latest updates to this plugin, along with any unofficial technical support:<br />
<br />
<strong>Release Page:</strong> <a href="http://tantannoodles.com/toolkit/wordpress-s3/">tantannoodles.com/toolkit/wordpress-s3/</a><br />
<strong>Project Page:</strong> <a href="http://code.google.com/p/wordpress-s3/">code.google.com/p/wordpress-s3/</a><br />
</p>
<p>
<strong>RSS Updates:</strong> Subscribe to the <a href="http://feeds.feedburner.com/TanTanToolkit">TanTanToolkit feed</a> and get notified when there's an update to this plugin.
</p>
<fieldset class="options">
<legend>Amazon S3 Settings</legend>
<table width="100%" cellspacing="2" cellpadding="5" class="editform">
<form method="post">
<input type="hidden" name="action" value="save" />
<tr valign="top">
<th width="33%" scope="row">AWS 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 Key:</th>
<td><input type="text" name="options[secret]" value="<?php echo ($options['secret'] ? '-- not shown --' : '');?>" size="50" /><br />
<small><a href="http://aws-portal.amazon.com/gp/aws/developer/account/index.html/?ie=UTF8&action=access-key">Login to Amazon.com to retrieve your Secret Key &gt;</a></small></td>
</tr>
<?php if (!$buckets):?>
<tr valign="top">
<td colspan="2">
<p class="submit">
<input type="submit" value="Authenticate Account &gt;" />
</p>
</td>
</tr>
<?php else:?>
<tr valign="top">
<th width="33%" scope="row">Use this bucket:</th>
<td>
<select name="options[bucket]" size="1" onchange="return s3_selectBucket(this)">
<option value="">Please select a bucket...</option>
<?php if (is_array($buckets)) foreach ($buckets as $bucket):?>
<option value="<?php echo $bucket?>" <?php echo ($bucket == $options['bucket'] ? 'selected="selected"' : '')?>>&nbsp; &nbsp; <?php echo $bucket?></option>
<?php endforeach;?>
<option></option>
<option value="new">Create a new bucket...</option>
</select><br />
</td>
</tr>
<tr valign="top">
<th width="33%" scope="row">Host name settings:</th>
<td>
<input type="checkbox" name="options[virtual-host]" value="1" id="virtual-host" <?php echo ($options['virtual-host'] ? 'checked="checked" ' : '');?> />
<label for="virtual-host"> Bucket is setup for virtual hosting.</label> (<a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/VirtualHosting.html">more info</a>)
</td>
</tr>
<tr valign="top">
<th width="33%" scope="row">File Uploads:</th>
<td>
<input type="checkbox" name="options[wp-uploads]" value="1" id="wp-uploads" <?php echo ($options['wp-uploads'] ? 'checked="checked" ' : '');?> />
<label for="wp-uploads"> Use Amazon S3 for storage when uploading via WordPress' upload tab.</label>
<br /><small>Note: Uncheck this to revert back to using your own web host for storage at anytime.</small>
</td>
</tr>
<tr valign="top">
<th width="33%" scope="row">Expires Header:</th>
<td>
<input type="checkbox" name="options[expires]" value="315360000" id="expires" <?php echo ($options['expires']? 'checked="checked" ' : '');?> />
<label for="expires"> Set a <a href="http://developer.yahoo.com/performance/rules.html#expires" target="_blank">far future HTTP expiration header</a> for uploaded files <em>(recommended)</em>.</label>
</td>
</tr>
<tr valign="top">
<th width="33%" scope="row">File Permissions:</th>
<td>
<input type="checkbox" name="options[permissions]" value="public" id="permissions" <?php echo ($options['permissions']=='public' ? 'checked="checked" ' : '');?> />
<label for="permissions"> Make sure all files in the selected bucket are publicly accessible.</label>
</td>
</tr>
<tr valign="top">
<th width="33%" scope="row">&nbsp;</th>
<td>
Uploading files <em>directly</em> to your Amazon S3 account is not currently supported by this plugin (uploads must temporarily pass through your blog).
But, there are a some free tools to help you upload and manage your files on directly on Amazon S3. <a href="http://code.google.com/p/wordpress-s3/wiki/S3Tools">See this page for some suggested tools</a>.
</td>
</tr>
<tr>
<td colspan="2">
<p class="submit">
<input type="submit" value="Save &gt;" />
</p>
</td>
</tr>
<?php endif;?>
</form>
</table>
</fieldset>
</div>
@@ -1,32 +0,0 @@
<?php
$dir = dirname(__FILE__);
$pluginRootURL = get_option('siteurl').substr($dir, strpos($dir, '/wp-content'));
if (!ereg('media-upload.php', $_SERVER['REQUEST_URI'])): // WP < 2.5
?>
<script type="text/javascript">
addLoadEvent(function () {
var div = document.getElementById('upload-menu');
var as = div.getElementsByTagName('a')
for (var i=0;i<as.length;i++) {
var pos = as[i].innerHTML.indexOf('S3');
if (pos >= 0) {
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']):?>
var upload = document.getElementById('upload');
if (upload && upload.name == 'image') {
var span = document.createElement('span');
span.id = 'disable_amazonS3_span';
span.innerHTML = '<label for="disable_amazonS3"> don\'t upload to amazon s3 </label><input type="checkbox" name="disable_amazonS3" id="disable_amazonS3" value="1" />';
var btns = document.getElementById('buttons')
var tds = btns.getElementsByTagName('td')
tds[0].appendChild(span);
}
<?php endif;?>
});
</script>
<?php endif;?>
<script type="text/javascript" src="<?php echo $pluginRootURL;?>/admin-tab.js"></script>
<link rel='stylesheet' href='<?php echo $pluginRootURL;?>/styles/styles.css' type='text/css' />
@@ -1,98 +0,0 @@
<?php
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));
}
}
?>
<div id="amazon-s3-wrap">
<div class="infobar">
<span class="nav-controls">
<?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; ?>
<a href="javascript:window.location.reload()" onclick="" id="btn-refresh" title="refresh view">refresh</a>
<a href="#" onclick="return s3_toggleUpload();" id="btn-upload" title="upload">upload</a>
<a href="#" onclick="return s3_toggleCreateFolder();" id="btn-folder" title="create new folder">new folder</a>
</span>
<span class="path">
<?php
$tree = $keys;
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);
$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 ? ' / ' : ' ');
}
?>
</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="text" name="newfolder" id="newfolder" />
<input type="submit" value="create" />
</form>
</div>
<div id="upload-form">
<form method="post" enctype="multipart/form-data">
<input type="file" name="newfile" />
<input type="submit" value="upload" />
</form>
</div>
</div>
<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);
?>
<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);
?>
<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;?>')"
<?php endif;?>
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;?>
<?php else:?>
<li class="empty">no files in this folder</li>
<?php endif;?>
</ul>
</div>
</div>
<br clear="both" />
@@ -1,59 +0,0 @@
function s3_insertImage(imgURL, title) {
if (!title) title = '';
return s3_insert('<img src="'+imgURL+'" class="s3-img" border="0" alt="'+title+'" /> ');
}
function s3_insertLink(label, url) {
var useBittorrent = document.getElementById('useBittorrent').checked
return s3_insert('<a href="'+url+(useBittorrent ? '?torrent' : '')+'" class="s3-link'+(useBittorrent ? ' torrent' : '')+'">' + label + '</a> ');
}
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 = '';
}
}
@@ -1,58 +0,0 @@
<?php if ($error):?>
<div id="message" class="error fade"><p><strong><?php echo $error?></strong></p></div>
<?php elseif ($message):?>
<div id="message" class="updated fade"><p><strong><?php echo $message?></strong></p></div>
<?php endif;?>
<style>
fieldset.options {
clear:both;
border:1px solid #ccc;
}
fieldset.options legend {
font-family: Georgia,"Times New Roman",Times,serif;
font-size: 22px;
}
div.album {
float:left;
width:200px;
height:150px;
margin-right:15px;
}
div.album td {
font-size:0.9em;
}
div.album-hidden img {
opacity:0.5;
}
</style>
<div class="wrap">
<h2 id="write-post">Amazon S3 Plugin for WordPress</h2>
<div style="width:250px;border:1px solid #ccc;float:right;padding:10px;margin:0 0 10px 10px;">
<strong><a href="http://www.dreamhost.com/r.cgi?156998" target="_blank">Switch to a better web host!</a></strong><br />
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.
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.
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>
<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>
@@ -1,29 +0,0 @@
<?php
class TanTanWordPressS3PluginPublic {
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;
}
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 ($this->options['wp-uploads'] && ($amazon = get_post_meta($postID, 'amazonS3_info', true))) {
$accessDomain = $this->options['virtual-host'] ? $amazon['bucket'] : $amazon['bucket'].'.s3.amazonaws.com';
return 'http://'.$accessDomain.'/'.$amazon['key'];
} else {
return $url;
}
}
}
?>
@@ -1,464 +0,0 @@
<?php
/*
$Revision: 89650 $
$Date: 2009-01-27 02:01:33 +0000 (Tue, 27 Jan 2009) $
$Author: joetan $
*/
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 (!$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_tantan-wordpress-s3', array(&$this, 'media_upload_content'));
}
add_action('activate_tantan/wordpress-s3.php', array(&$this, 'activate'));
if ($_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 \'<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 addhooks() {
parent::addhooks();
if (!$_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('wp_delete_file', array(&$this, 'wp_delete_file'));
}
}
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 ($_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'])) {
$_POST['options']['secret'] = $options['secret'];
}
update_option('tantan_wordpress_s3', $_POST['options']);
if ($_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') && $_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 />".
"<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>";
}
}
}
$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']) {
$error = "Please enter your Secret Access Key.";
} elseif ($options['secret']) {
$error = "Please enter your Access Key ID.";
}
include(dirname(__FILE__).'/admin-options.html');
}
/*
Delete corresponding file from Amazon S3
*/
function wp_delete_file($file) {
return $file;
if (!$this->options) $this->options = get_option('tantan_wordpress_s3');
if (!$this->options['wp-uploads'] || !$this->options['bucket'] || !$this->options['secret']) {
return $file;
}
if (is_array($this->meta)) {
require_once(dirname(__FILE__).'/lib.s3.php');
$this->s3 = new TanTanS3($this->options['key'], $this->options['secret']);
$this->s3->setOptions($this->options);
if (deleteObject($this->meta['bucket'], $this->meta['key'])) {
}
$accessDomain = $this->options['virtual-host'] ? $this->meta['bucket'] : $this->meta['bucket'].'.s3.amazonaws.com';
return $file;
//return 'http://'.$accessDomain.'/'.$amazon['key'];
}
return $file;
}
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']) {
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);
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)) {
if ($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;
$dir = dirname(__FILE__);
$pluginRootURL = get_option('siteurl').substr($dir, strpos($dir, '/wp-content'));
$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_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 upload_tabs_scripts() {
//wp_enqueue_script('prototype');
if (!$this->options) $this->options = get_option('tantan_wordpress_s3');
$accessDomain = $this->options['virtual-host'] ? $this->options['bucket'] : $this->options['bucket'].'.s3.amazonaws.com';
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']);
}
}
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) $_GET['paged'];
if (!$offsetpage) $offsetpage = 1;
if (!$this->options['key'] || !$this->options['secret']) {
return;
}
$bucket = $this->options['bucket'];
$accessDomain = $this->options['virtual-host'] ? $this->options['bucket'] : $this->options['bucket'].'.s3.amazonaws.com';
$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');
}
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) {
$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 = 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) {
$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'] && (ereg('AllUsers', (string) $grant['Grantee']->URI))) {
$perm = (string) $grant['Permission'];
if ($perm == 'READ' || $perm == 'FULL_CONTROL') return true;
}
}
}
}
?>
@@ -1,20 +0,0 @@
<?php
/*
$Revision: 66280 $
$Date: 2008-09-25 15:28:23 +0000 (Thu, 25 Sep 2008) $
$Author: joetan $
*/
// rename this file to "config.php" to use the settings below, instead of settings saved in the database through the dashboard admin
// this can be used to automatically configure the plugin in a WordPress MU environment, or if you have automated scripts to deploy WordPress installs
$TanTanWordPressS3Config = array(
'key' => '', // 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
);
?>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 390 B

@@ -1 +0,0 @@
<?php /* empty */ ?>
@@ -1,397 +0,0 @@
<?php
/*
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)));}
}
/*
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 (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` )
) TYPE = MYISAM");
}
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'].";");
}
}
?>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 733 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 349 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 587 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 653 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 668 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 635 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 818 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 817 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 591 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 588 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 651 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 386 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 777 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 589 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 606 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 610 B

@@ -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);}