Plugin Directory

Changeset 1317472


Ignore:
Timestamp:
12/28/2015 07:03:03 PM (10 years ago)
Author:
tcmccarthy1
Message:

Commits version 1.7. Users can now disable URL override and support for srcset is added

Location:
tcs3
Files:
1638 added
5 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • tcs3/trunk/readme.txt

    r1225351 r1317472  
    33Tags: Amazon, S3, upload, media, multisite, aws
    44Requires at least: 3.5
    5 Tested up to: 4.3
    6 Stable tag: 1.6
     5Tested up to: 4.4
     6Stable tag: 1.7
    77License: GPL, version 2
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6161== Changelog ==
    6262
    63 = 1.5 =
     63= 1.7 =
     64* Users have expressed use cases where the automated S3 push is needed but they wish to not modify the attachment URL. Adds this option
     65* WP 4.4 added functions for defining the srcset polyfill. This functionality is now supported by tcS3.
     66
     67= 1.6 =
    6468* Adds fallback option where users can opt to use the tcS3_media endpoint OR link directly to their S3 bucket
    6569* Increases hook priority to 20 to allow for various image editing plugins to have their work pushed to S3
  • tcs3/trunk/tcS3.php

    r1225373 r1317472  
    44 * Plugin URI: http://tcm.io
    55 * Description: Allows site admins to push uploads to S3
    6  * Version: 1.6
     6 * Version: 1.7
    77 * Author: TC McCarthy
    88 * Author URI: http://tcm.io
     
    9090            add_action('template_redirect', array($this, 'load_image'));
    9191            add_filter('wp_get_attachment_url', array($this, 'build_attachment_url'), 20, 1);
     92            add_filter('wp_get_attachment_image_src', array($this, 'get_attachment_image_src'), 20, 1);
     93            add_filter('wp_calculate_image_srcset', array($this, 'calculate_image_srcset'), 20, 1);
    9294
    9395            //if super admin has flagged marking all uploads as uploaded and it has been done on this site yet, do it.
     
    123125        });
    124126        </script>";
     127    }
     128
     129    public function get_attachment_image_src($image){
     130        $image["src"] = $this->build_attachment_url($image["src"]);
     131        return $image;
     132    }
     133
     134    public function calculate_image_srcset($sources, $size_array, $image_src, $image_meta, $attachment_id){
     135        foreach($sources as $key => $source){
     136            $sources[$key]['url'] = $this->build_attachment_url($source['url']);
     137        }
     138        return $sources;
    125139    }
    126140
     
    540554
    541555    public function build_attachment_url($url) {
     556        if(isset($this->options["tcS3_use_url"]) && $this->options["tcS3_use_url"] == 0){
     557            return $url;
     558        }
     559
    542560        preg_match("/\/([0-9]+\/[0-9]+\/[^\/]+)$/", $url, $matches);
    543561        $protocol = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] != "") ? "https" : "http";
     
    671689
    672690        add_settings_field(
     691            's3_use_url', 'Override default WP URL', array($this, 's3_use_url_callback'), 'tcS3-setting-admin', 'tcS3-settings'
     692            );
     693
     694        add_settings_field(
    673695            's3_url', 'Local URL', array($this, 'local_url_callback'), 'tcS3-setting-admin', 'tcS3-settings'
    674696            );
     
    919941    }
    920942
     943    public function s3_use_url_callback() {
     944        $optionKey = 'tcS3_use_url';
     945        $helperText = 'By default tcS3 overrides WP default URLs. You can disable this if you so desire.';
     946        if(!isset($this->options[$optionKey])){
     947            $this->options[$optionKey] = 1;
     948        }
     949
     950        printf(
     951            '<input type="radio" id="%s" name="tcS3_option[%s]" value="1" %s /> Yes
     952            <br /><input type="radio" id="%s" name="tcS3_option[%s]" value="0" %s /> No
     953            <div><small>%s</small></div>', $optionKey, $optionKey, ($this->options[$optionKey] == 1) ? "checked" : "", $optionKey, $optionKey, ($this->options[$optionKey] == 0) ? "checked" : "", $helperText
     954            );
     955    }
     956
    921957    public function s3_cache_time_callback() {
    922958        $optionKey = 's3_cache_time';
Note: See TracChangeset for help on using the changeset viewer.