Plugin Directory

Changeset 492045


Ignore:
Timestamp:
01/19/2012 12:04:55 PM (14 years ago)
Author:
atvdev
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • amazon-s3-uploads/trunk/asssu.php

    r491999 r492045  
    5555        $this->bucket_subdir = get_option('asssu_bucket_subdir');
    5656        $this->use_ssl = (bool) get_option('asssu_use_ssl', 0);
     57        $this->endpoint = get_option('asssu_endpoint');
    5758       
    5859        $this->cronScheduleTime = get_option('asssu_cron_interval', 300);
     
    9697        require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'asssu-options.php';
    9798    }
     99   
     100    function sss_adapter() {
     101        if (isset($this->adapter))
     102            return $this->adapter;
     103           
     104        require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'tpyo-amazon-s3-php-class'.DIRECTORY_SEPARATOR.'S3.php';
     105        $adapter = new S3($this->access_key, $this->secret_key, $this->use_ssl, $this->endpoint);
     106        $this->adapter = $adapter;
     107        return $adapter;
     108    }
    98109
    99110    function check_sss($access_key, $secret_key, $use_ssl, $bucket_name) {
    100111        require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'tpyo-amazon-s3-php-class'.DIRECTORY_SEPARATOR.'S3.php';
    101112        $adapter = new S3($access_key, $secret_key, $use_ssl);
    102         $buckets = S3::listBuckets();
    103         if (is_array($buckets) && in_array($bucket_name, $buckets))
     113        $buckets = @$adapter->listBuckets();
     114        if (is_array($buckets) && in_array($bucket_name, $buckets)) {
     115            $bucket_location = $adapter->getBucketLocation($bucket_name);
     116            if ($bucket_location === 'EU')
     117                $endpoint = 's3-eu-west-1.amazonaws.com';
     118            else if ($bucket_location === 'NC')
     119                $endpoint = 's3-us-west-1.amazonaws.com';
     120            else if ($bucket_location === 'US')
     121                $endpoint = 's3.amazonaws.com';
     122            else if ($bucket_location === 'SI')
     123                $endpoint = 's3-ap-southeast-1.amazonaws.com';
     124            else if ($bucket_location === 'TO')
     125                $endpoint = 's3-ap-northeast-1.amazonaws.com';
     126            else
     127                return false;
     128            if ($this->endpoint !== $endpoint) {
     129                $this->endpoint = $endpoint;
     130                update_option('asssu_endpoint', $this->endpoint);
     131            }
    104132            return true;
     133        }
    105134        return false;
    106135    }
    107136   
    108137    function check_htaccess() {
    109         require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'tpyo-amazon-s3-php-class'.DIRECTORY_SEPARATOR.'S3.php';
    110         $bucket_name = get_option('asssu_bucket_name');
    111         $location = S3::getBucketLocation($bucket_name);
    112        
    113138        $amazon_path = 'http://'.$this->bucket_name.'.s3.amazonaws.com/';
    114         if ($location === 'EU')
    115             $amazon_path_ssl = 'https://'.$this->bucket_name.'.s3.amazonaws.com/';
    116         else
    117             $amazon_path_ssl = 'https://s3.amazonaws.com/'.$this->bucket_name.'/';
     139        $amazon_path_ssl = 'https://'.$this->endpoint.'/'.$this->bucket_name.'/';
    118140        if (!empty($this->bucket_subdir)) {
    119141            $amazon_path .= $this->bucket_subdir.'/';
     
    179201        $this->find_contents($this->upload_basedir);
    180202       
    181         require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'s3-php5-curl'.DIRECTORY_SEPARATOR.'S3.php';
    182        
    183         $adapter = new S3($this->access_key, $this->secret_key, $this->use_ssl);
     203        $adapter = $this->sss_adapter();
    184204        $buckets = @$adapter->listBuckets();
    185205        if (is_array($buckets) && in_array($this->bucket_name, $buckets)) {
     
    193213                if (!empty($this->bucket_subdir))
    194214                    $amazon_path = $this->bucket_subdir.'/'.$amazon_path;
    195                 $info = $adapter->getObjectInfo($this->bucket_name, $amazon_path, true);
     215                $info = @$adapter->getObjectInfo($this->bucket_name, $amazon_path, true);
    196216                if (!empty($info)) {
    197217                    if ($info['size'] !== filesize($local_path)) {
Note: See TracChangeset for help on using the changeset viewer.