Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../includes
File: S3.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* $Id$
[2] Fix | Delete
*
[3] Fix | Delete
* Copyright (c) 2011, Donovan Schönknecht. All rights reserved.
[4] Fix | Delete
* Portions copyright (c) 2012-2021, David Anderson (https://david.dw-perspective.org.uk). All rights reserved.
[5] Fix | Delete
*
[6] Fix | Delete
* Redistribution and use in source and binary forms, with or without
[7] Fix | Delete
* modification, are permitted provided that the following conditions are met:
[8] Fix | Delete
*
[9] Fix | Delete
* - Redistributions of source code must retain the above copyright notice,
[10] Fix | Delete
* this list of conditions and the following disclaimer.
[11] Fix | Delete
* - Redistributions in binary form must reproduce the above copyright
[12] Fix | Delete
* notice, this list of conditions and the following disclaimer in the
[13] Fix | Delete
* documentation and/or other materials provided with the distribution.
[14] Fix | Delete
*
[15] Fix | Delete
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
[16] Fix | Delete
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
[17] Fix | Delete
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
[18] Fix | Delete
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
[19] Fix | Delete
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
[20] Fix | Delete
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
[21] Fix | Delete
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
[22] Fix | Delete
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
[23] Fix | Delete
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
[24] Fix | Delete
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
[25] Fix | Delete
* POSSIBILITY OF SUCH DAMAGE.
[26] Fix | Delete
*
[27] Fix | Delete
* Amazon S3 is a trademark of Amazon.com, Inc. or its affiliates.
[28] Fix | Delete
*/
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Amazon S3 PHP class
[32] Fix | Delete
*
[33] Fix | Delete
* Forked originally from:
[34] Fix | Delete
* @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class
[35] Fix | Delete
* @version 0.5.0-dev
[36] Fix | Delete
*/
[37] Fix | Delete
class UpdraftPlus_S3 {
[38] Fix | Delete
// ACL flags
[39] Fix | Delete
const ACL_PRIVATE = 'private';
[40] Fix | Delete
const ACL_PUBLIC_READ = 'public-read';
[41] Fix | Delete
const ACL_PUBLIC_READ_WRITE = 'public-read-write';
[42] Fix | Delete
const ACL_AUTHENTICATED_READ = 'authenticated-read';
[43] Fix | Delete
[44] Fix | Delete
const STORAGE_CLASS_STANDARD = 'STANDARD';
[45] Fix | Delete
[46] Fix | Delete
private $__accessKey = null; // AWS Access key
[47] Fix | Delete
private $__secretKey = null; // AWS Secret key
[48] Fix | Delete
private $__sslKey = null;
[49] Fix | Delete
private $__session_token = null; //For Vault temporary users
[50] Fix | Delete
private $_serverSideEncryption = false;
[51] Fix | Delete
[52] Fix | Delete
public $endpoint = 's3.amazonaws.com';
[53] Fix | Delete
public $region = 'us-east-1';
[54] Fix | Delete
public $proxy = null;
[55] Fix | Delete
[56] Fix | Delete
// Added to cope with a particular situation where the user had no permission to check the bucket location, which necessitated using DNS-based endpoints.
[57] Fix | Delete
public $use_dns_bucket_name = false;
[58] Fix | Delete
[59] Fix | Delete
public $useSSL = false;
[60] Fix | Delete
public $useSSLValidation = true;
[61] Fix | Delete
public $useExceptions = false;
[62] Fix | Delete
[63] Fix | Delete
// Added at request of a user using a non-default port.
[64] Fix | Delete
public $port = false;
[65] Fix | Delete
[66] Fix | Delete
// SSL CURL SSL options - only needed if you are experiencing problems with your OpenSSL configuration
[67] Fix | Delete
public $sslKey = null;
[68] Fix | Delete
public $sslCert = null;
[69] Fix | Delete
public $sslCACert = null;
[70] Fix | Delete
[71] Fix | Delete
private $__signingKeyPairId = null; // AWS Key Pair ID
[72] Fix | Delete
private $__signingKeyResource = false; // Key resource, freeSigningKey() must be called to clear it from memory
[73] Fix | Delete
[74] Fix | Delete
public $signVer = 'v2';
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Constructor - if you're not using the class statically
[78] Fix | Delete
*
[79] Fix | Delete
* @param string $accessKey Access key
[80] Fix | Delete
* @param string $secretKey Secret key
[81] Fix | Delete
* @param boolean $useSSL Enable SSL
[82] Fix | Delete
* @param boolean $sslCACert SSL Certificate
[83] Fix | Delete
* @param string|null $endpoint Endpoint
[84] Fix | Delete
* @param string $session_token The session token returned by AWS for temporary credentials access
[85] Fix | Delete
* @param string $region Region
[86] Fix | Delete
[87] Fix | Delete
* @throws Exception If cURL extension is not present
[88] Fix | Delete
*
[89] Fix | Delete
* @return self
[90] Fix | Delete
*/
[91] Fix | Delete
public function __construct($accessKey = null, $secretKey = null, $useSSL = true, $sslCACert = true, $endpoint = null, $session_token = null, $region = 'us-east-1') {
[92] Fix | Delete
if (null !== $accessKey && null !== $secretKey) {
[93] Fix | Delete
$this->setAuth($accessKey, $secretKey, $session_token);
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
$this->setSSL($useSSL, !empty($sslCACert));
[97] Fix | Delete
[98] Fix | Delete
$this->sslCACert = $sslCACert;
[99] Fix | Delete
if (!empty($endpoint)) {
[100] Fix | Delete
$this->endpoint = $endpoint;
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
$this->region = $region;
[104] Fix | Delete
[105] Fix | Delete
if (!function_exists('curl_init')) {
[106] Fix | Delete
global $updraftplus;
[107] Fix | Delete
$updraftplus->log('The PHP cURL extension must be installed and enabled to use this remote storage method');
[108] Fix | Delete
throw new Exception('The PHP cURL extension must be installed and enabled to use this remote storage method');
[109] Fix | Delete
}
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Set the service endpoint
[114] Fix | Delete
*
[115] Fix | Delete
* @param string $host Hostname
[116] Fix | Delete
*
[117] Fix | Delete
* @return void
[118] Fix | Delete
*/
[119] Fix | Delete
public function setEndpoint($host) {
[120] Fix | Delete
$this->endpoint = $host;
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
/**
[124] Fix | Delete
* Set Server Side Encryption
[125] Fix | Delete
* Example value: 'AES256'. See: https://docs.aws.amazon.com/AmazonS3/latest/dev/SSEUsingPHPSDK.html
[126] Fix | Delete
*
[127] Fix | Delete
* @param string|boolean $sse Server side encryption standard; or false for none
[128] Fix | Delete
* @return void
[129] Fix | Delete
*/
[130] Fix | Delete
public function setServerSideEncryption($value) {
[131] Fix | Delete
$this->_serverSideEncryption = $value;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* Set the service region
[136] Fix | Delete
*
[137] Fix | Delete
* @param string $region Region
[138] Fix | Delete
* @return void
[139] Fix | Delete
*/
[140] Fix | Delete
public function setRegion($region) {
[141] Fix | Delete
$this->region = $region;
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Get the service region
[146] Fix | Delete
* Note: Region calculation will be done in methods/s3.php file
[147] Fix | Delete
*
[148] Fix | Delete
* @return string Region
[149] Fix | Delete
*/
[150] Fix | Delete
public function getRegion() {
[151] Fix | Delete
return $this->region;
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
/**
[155] Fix | Delete
* Set the service port
[156] Fix | Delete
*
[157] Fix | Delete
* @param Integer $port Port number
[158] Fix | Delete
*
[159] Fix | Delete
* @return void
[160] Fix | Delete
*/
[161] Fix | Delete
public function setPort($port) {
[162] Fix | Delete
$this->port = $port;
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
/**
[166] Fix | Delete
* Set AWS access key and secret key
[167] Fix | Delete
*
[168] Fix | Delete
* @param string $accessKey Access key
[169] Fix | Delete
* @param string $secretKey Secret key
[170] Fix | Delete
*
[171] Fix | Delete
* @return void
[172] Fix | Delete
*/
[173] Fix | Delete
public function setAuth($accessKey, $secretKey, $session_token = null) {
[174] Fix | Delete
$this->__accessKey = $accessKey;
[175] Fix | Delete
$this->__secretKey = $secretKey;
[176] Fix | Delete
$this->__session_token = $session_token;
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Check if AWS keys have been set
[181] Fix | Delete
*
[182] Fix | Delete
* @return boolean
[183] Fix | Delete
*/
[184] Fix | Delete
public function hasAuth() {
[185] Fix | Delete
return (null !== $this->__accessKey && null !== $this->__secretKey);
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* Set SSL on or off
[191] Fix | Delete
*
[192] Fix | Delete
* @param boolean $enabled SSL enabled
[193] Fix | Delete
* @param boolean $validate SSL certificate validation
[194] Fix | Delete
*
[195] Fix | Delete
* @return void
[196] Fix | Delete
*/
[197] Fix | Delete
public function setSSL($enabled, $validate = true) {
[198] Fix | Delete
$this->useSSL = $enabled;
[199] Fix | Delete
$this->useSSLValidation = $validate;
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
/**
[203] Fix | Delete
* Get SSL value. Determines whether use it or not.
[204] Fix | Delete
*
[205] Fix | Delete
* @return bool
[206] Fix | Delete
*/
[207] Fix | Delete
public function getuseSSL() {
[208] Fix | Delete
return $this->useSSL;
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
/**
[212] Fix | Delete
* Set SSL client certificates (experimental)
[213] Fix | Delete
*
[214] Fix | Delete
* @param string $sslCert SSL client certificate
[215] Fix | Delete
* @param string $sslKey SSL client key
[216] Fix | Delete
* @param string $sslCACert SSL CA cert (only required if you are having problems with your system CA cert)
[217] Fix | Delete
*
[218] Fix | Delete
* @return void
[219] Fix | Delete
*/
[220] Fix | Delete
public function setSSLAuth($sslCert = null, $sslKey = null, $sslCACert = null) {
[221] Fix | Delete
$this->sslCert = $sslCert;
[222] Fix | Delete
$this->sslKey = $sslKey;
[223] Fix | Delete
$this->sslCACert = $sslCACert;
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
[227] Fix | Delete
/**
[228] Fix | Delete
* Set proxy information
[229] Fix | Delete
*
[230] Fix | Delete
* @param string $host Proxy hostname and port (localhost:1234)
[231] Fix | Delete
* @param string $user Proxy username
[232] Fix | Delete
* @param string $pass Proxy password
[233] Fix | Delete
* @param integer $type CURL proxy type
[234] Fix | Delete
*
[235] Fix | Delete
* @return void
[236] Fix | Delete
*/
[237] Fix | Delete
public function setProxy($host, $user = null, $pass = null, $type = CURLPROXY_SOCKS5, $port = null) {
[238] Fix | Delete
$this->proxy = array('host' => $host, 'type' => $type, 'user' => $user, 'pass' => $pass, 'port' => $port);
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
[242] Fix | Delete
/**
[243] Fix | Delete
* Set the error mode to exceptions
[244] Fix | Delete
*
[245] Fix | Delete
* @param boolean $enabled Enable exceptions
[246] Fix | Delete
*
[247] Fix | Delete
* @return void
[248] Fix | Delete
*/
[249] Fix | Delete
public function setExceptions($enabled = true) {
[250] Fix | Delete
$this->useExceptions = $enabled;
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
[254] Fix | Delete
/**
[255] Fix | Delete
* Set signing key
[256] Fix | Delete
*
[257] Fix | Delete
* @param string $keyPairId AWS Key Pair ID
[258] Fix | Delete
* @param string $signingKey Private Key
[259] Fix | Delete
* @param boolean $isFile Load private key from file, set to false to load string
[260] Fix | Delete
*
[261] Fix | Delete
* @return boolean
[262] Fix | Delete
*/
[263] Fix | Delete
public function setSigningKey($keyPairId, $signingKey, $isFile = true) {
[264] Fix | Delete
$this->__signingKeyPairId = $keyPairId;
[265] Fix | Delete
if (($this->__signingKeyResource = openssl_pkey_get_private($isFile ?
[266] Fix | Delete
file_get_contents($signingKey) : $signingKey)) !== false) return true;
[267] Fix | Delete
$this->__triggerError('UpdraftPlus_S3::setSigningKey(): Unable to open load private key: '.$signingKey, __FILE__, __LINE__);
[268] Fix | Delete
return false;
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
[272] Fix | Delete
/**
[273] Fix | Delete
* Free signing key from memory, MUST be called if you are using setSigningKey()
[274] Fix | Delete
*
[275] Fix | Delete
* @return void
[276] Fix | Delete
*/
[277] Fix | Delete
public function freeSigningKey() {
[278] Fix | Delete
if (false !== $this->__signingKeyResource) {
[279] Fix | Delete
openssl_free_key($this->__signingKeyResource);
[280] Fix | Delete
}
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
/**
[284] Fix | Delete
* Set Signature Version
[285] Fix | Delete
*
[286] Fix | Delete
* @param string $version
[287] Fix | Delete
* @return void
[288] Fix | Delete
*/
[289] Fix | Delete
public function setSignatureVersion($version = 'v2') {
[290] Fix | Delete
$this->signVer = $version;
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
/**
[294] Fix | Delete
* Internal error handler
[295] Fix | Delete
*
[296] Fix | Delete
* @param string $message Error message
[297] Fix | Delete
* @param string $file Filename
[298] Fix | Delete
* @param integer $line Line number
[299] Fix | Delete
* @param integer $code Error code
[300] Fix | Delete
*
[301] Fix | Delete
* @internal Internal error handler
[302] Fix | Delete
* @throws UpdraftPlus_S3Exception
[303] Fix | Delete
*
[304] Fix | Delete
* @return void
[305] Fix | Delete
*/
[306] Fix | Delete
private function __triggerError($message, $file, $line, $code = 0) {// phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore -- Method name "UpdraftPlus_S3Request::__responseHeaderCallback" is discouraged; PHP has reserved all method names with a double underscore prefix for future use.
[307] Fix | Delete
if ($this->useExceptions) {
[308] Fix | Delete
throw new UpdraftPlus_S3Exception($message, $file, $line, $code);
[309] Fix | Delete
} else {
[310] Fix | Delete
trigger_error($message, E_USER_WARNING);
[311] Fix | Delete
}
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
[315] Fix | Delete
/**
[316] Fix | Delete
* Get a list of buckets
[317] Fix | Delete
*
[318] Fix | Delete
* @param boolean $detailed Returns detailed bucket list when true
[319] Fix | Delete
*
[320] Fix | Delete
* @return array | false
[321] Fix | Delete
*/
[322] Fix | Delete
public function listBuckets($detailed = false) {
[323] Fix | Delete
$rest = new UpdraftPlus_S3Request('GET', '', '', $this->endpoint, $this->use_dns_bucket_name, $this);
[324] Fix | Delete
$rest = $rest->getResponse();
[325] Fix | Delete
if (false === $rest->error && 200 !== $rest->code) {
[326] Fix | Delete
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
[327] Fix | Delete
}
[328] Fix | Delete
if (false !== $rest->error) {
[329] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::listBuckets(): [%s] %s", $rest->error['code'],
[330] Fix | Delete
$rest->error['message']), __FILE__, __LINE__);
[331] Fix | Delete
return false;
[332] Fix | Delete
}
[333] Fix | Delete
$results = array();
[334] Fix | Delete
if (!isset($rest->body->Buckets)) return $results;
[335] Fix | Delete
[336] Fix | Delete
if ($detailed) {
[337] Fix | Delete
if (isset($rest->body->Owner, $rest->body->Owner->ID, $rest->body->Owner->DisplayName))
[338] Fix | Delete
$results['owner'] = array(
[339] Fix | Delete
'id' => (string)$rest->body->Owner->ID, 'name' => (string)$rest->body->Owner->ID
[340] Fix | Delete
);
[341] Fix | Delete
$results['buckets'] = array();
[342] Fix | Delete
foreach ($rest->body->Buckets->Bucket as $b) {
[343] Fix | Delete
$results['buckets'][] = array(
[344] Fix | Delete
'name' => (string)$b->Name, 'time' => strtotime((string)$b->CreationDate)
[345] Fix | Delete
);
[346] Fix | Delete
}
[347] Fix | Delete
} else {
[348] Fix | Delete
foreach ($rest->body->Buckets->Bucket as $b) $results[] = (string)$b->Name;
[349] Fix | Delete
}
[350] Fix | Delete
[351] Fix | Delete
return $results;
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
public function useDNSBucketName($use = true, $bucket = '') {
[355] Fix | Delete
$this->use_dns_bucket_name = $use;
[356] Fix | Delete
return true;
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
/**
[360] Fix | Delete
* Get contents for a bucket
[361] Fix | Delete
*
[362] Fix | Delete
* If maxKeys is null this method will loop through truncated result sets
[363] Fix | Delete
*
[364] Fix | Delete
* @param string $bucket Bucket name
[365] Fix | Delete
* @param string $prefix Prefix
[366] Fix | Delete
* @param string $marker Marker (last file listed)
[367] Fix | Delete
* @param string $maxKeys Max keys (maximum number of keys to return)
[368] Fix | Delete
* @param string $delimiter Delimiter
[369] Fix | Delete
* @param boolean $returnCommonPrefixes Set to true to return CommonPrefixes
[370] Fix | Delete
*
[371] Fix | Delete
* @return array | false
[372] Fix | Delete
*/
[373] Fix | Delete
public function getBucket($bucket, $prefix = null, $marker = null, $maxKeys = null, $delimiter = null, $returnCommonPrefixes = false) {
[374] Fix | Delete
$rest = new UpdraftPlus_S3Request('GET', $bucket, '', $this->endpoint, $this->use_dns_bucket_name, $this);
[375] Fix | Delete
if (0 == $maxKeys) $maxKeys = null;
[376] Fix | Delete
if (!empty($prefix)) $rest->setParameter('prefix', $prefix);
[377] Fix | Delete
if (!empty($marker)) $rest->setParameter('marker', $marker);
[378] Fix | Delete
if (!empty($maxKeys)) $rest->setParameter('max-keys', $maxKeys);
[379] Fix | Delete
if (!empty($delimiter)) $rest->setParameter('delimiter', $delimiter);
[380] Fix | Delete
$response = $rest->getResponse();
[381] Fix | Delete
if (false === $response->error && 200 !== $response->code) {
[382] Fix | Delete
$response->error = array('code' => $response->code, 'message' => 'Unexpected HTTP status');
[383] Fix | Delete
}
[384] Fix | Delete
if (false !== $response->error) {
[385] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::getBucket(): [%s] %s",
[386] Fix | Delete
$response->error['code'], $response->error['message']), __FILE__, __LINE__);
[387] Fix | Delete
return false;
[388] Fix | Delete
}
[389] Fix | Delete
[390] Fix | Delete
$results = array();
[391] Fix | Delete
[392] Fix | Delete
$nextMarker = null;
[393] Fix | Delete
if (isset($response->body, $response->body->Contents))
[394] Fix | Delete
foreach ($response->body->Contents as $c) {
[395] Fix | Delete
$results[(string)$c->Key] = array(
[396] Fix | Delete
'name' => (string)$c->Key,
[397] Fix | Delete
'time' => strtotime((string)$c->LastModified),
[398] Fix | Delete
'size' => (int)$c->Size,
[399] Fix | Delete
'hash' => substr((string)$c->ETag, 1, -1)
[400] Fix | Delete
);
[401] Fix | Delete
$nextMarker = (string)$c->Key;
[402] Fix | Delete
}
[403] Fix | Delete
[404] Fix | Delete
if ($returnCommonPrefixes && isset($response->body, $response->body->CommonPrefixes))
[405] Fix | Delete
foreach ($response->body->CommonPrefixes as $c)
[406] Fix | Delete
$results[(string)$c->Prefix] = array('prefix' => (string)$c->Prefix);
[407] Fix | Delete
[408] Fix | Delete
if (isset($response->body, $response->body->IsTruncated) &&
[409] Fix | Delete
(string)$response->body->IsTruncated == 'false') return $results;
[410] Fix | Delete
[411] Fix | Delete
if (isset($response->body, $response->body->NextMarker))
[412] Fix | Delete
$nextMarker = (string)$response->body->NextMarker;
[413] Fix | Delete
[414] Fix | Delete
// Loop through truncated results if maxKeys isn't specified
[415] Fix | Delete
if (null == $maxKeys && null !== $nextMarker && 'true' == (string)$response->body->IsTruncated)
[416] Fix | Delete
do
[417] Fix | Delete
{
[418] Fix | Delete
$rest = new UpdraftPlus_S3Request('GET', $bucket, '', $this->endpoint, $this->use_dns_bucket_name, $this);
[419] Fix | Delete
if (!empty($prefix)) $rest->setParameter('prefix', $prefix);
[420] Fix | Delete
$rest->setParameter('marker', $nextMarker);
[421] Fix | Delete
if (!empty($delimiter)) $rest->setParameter('delimiter', $delimiter);
[422] Fix | Delete
[423] Fix | Delete
if (false == ($response = $rest->getResponse()) || 200 !== $response->code) break;
[424] Fix | Delete
[425] Fix | Delete
if (isset($response->body, $response->body->Contents))
[426] Fix | Delete
foreach ($response->body->Contents as $c)
[427] Fix | Delete
{
[428] Fix | Delete
$results[(string)$c->Key] = array(
[429] Fix | Delete
'name' => (string)$c->Key,
[430] Fix | Delete
'time' => strtotime((string)$c->LastModified),
[431] Fix | Delete
'size' => (int)$c->Size,
[432] Fix | Delete
'hash' => substr((string)$c->ETag, 1, -1)
[433] Fix | Delete
);
[434] Fix | Delete
$nextMarker = (string)$c->Key;
[435] Fix | Delete
}
[436] Fix | Delete
[437] Fix | Delete
if ($returnCommonPrefixes && isset($response->body, $response->body->CommonPrefixes))
[438] Fix | Delete
foreach ($response->body->CommonPrefixes as $c)
[439] Fix | Delete
$results[(string)$c->Prefix] = array('prefix' => (string)$c->Prefix);
[440] Fix | Delete
[441] Fix | Delete
if (isset($response->body, $response->body->NextMarker))
[442] Fix | Delete
$nextMarker = (string)$response->body->NextMarker;
[443] Fix | Delete
[444] Fix | Delete
} while (false !== $response && 'true' == (string)$response->body->IsTruncated);
[445] Fix | Delete
[446] Fix | Delete
return $results;
[447] Fix | Delete
}
[448] Fix | Delete
[449] Fix | Delete
[450] Fix | Delete
/**
[451] Fix | Delete
* Put a bucket
[452] Fix | Delete
*
[453] Fix | Delete
* @param string $bucket Bucket name
[454] Fix | Delete
* @param string ACL_PRIVATE ACL flag
[455] Fix | Delete
* @param mixed $location Set as "EU" to create buckets hosted in Europe
[456] Fix | Delete
* @return boolean
[457] Fix | Delete
*/
[458] Fix | Delete
public function putBucket($bucket, $acl = self::ACL_PRIVATE, $location = false) {
[459] Fix | Delete
$rest = new UpdraftPlus_S3Request('PUT', $bucket, '', $this->endpoint, $this->use_dns_bucket_name, $this);
[460] Fix | Delete
$rest->setAmzHeader('x-amz-acl', $acl);
[461] Fix | Delete
[462] Fix | Delete
if (false === $location) $location = $this->getRegion();
[463] Fix | Delete
[464] Fix | Delete
if (false !== $location && 'us-east-1' !== $location) {
[465] Fix | Delete
$dom = new DOMDocument;
[466] Fix | Delete
$createBucketConfiguration = $dom->createElement('CreateBucketConfiguration');
[467] Fix | Delete
$locationConstraint = $dom->createElement('LocationConstraint', $location);
[468] Fix | Delete
$createBucketConfiguration->appendChild($locationConstraint);
[469] Fix | Delete
$dom->appendChild($createBucketConfiguration);
[470] Fix | Delete
$rest->data = $dom->saveXML();
[471] Fix | Delete
$rest->size = strlen($rest->data);
[472] Fix | Delete
$rest->setHeader('Content-Type', 'application/xml');
[473] Fix | Delete
}
[474] Fix | Delete
$rest = $rest->getResponse();
[475] Fix | Delete
[476] Fix | Delete
if (false === $rest->error && 200 !== $rest->code) {
[477] Fix | Delete
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
[478] Fix | Delete
}
[479] Fix | Delete
[480] Fix | Delete
if (false !== $rest->error) {
[481] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::putBucket({$bucket}, {$acl}, {$location}): [%s] %s",
[482] Fix | Delete
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
[483] Fix | Delete
return false;
[484] Fix | Delete
}
[485] Fix | Delete
return true;
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
[489] Fix | Delete
/**
[490] Fix | Delete
* Delete an empty bucket
[491] Fix | Delete
*
[492] Fix | Delete
* @param string $bucket Bucket name
[493] Fix | Delete
*
[494] Fix | Delete
* @return boolean
[495] Fix | Delete
*/
[496] Fix | Delete
public function deleteBucket($bucket) {
[497] Fix | Delete
$rest = new UpdraftPlus_S3Request('DELETE', $bucket, '', $this->endpoint, $this->use_dns_bucket_name, $this);
[498] Fix | Delete
$rest = $rest->getResponse();
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function