From 22676d39017c3a6c98e1ae89eaf6a2a9e9ded388 Mon Sep 17 00:00:00 2001 From: Lennart Nederstigt Date: Tue, 19 May 2015 17:15:24 +0200 Subject: [PATCH] added option to serve s3 output thumbnails via cloudfront --- _build/data/transport.settings.php | 19 ++++++++++++++++++- .../phpthumbof/lexicon/en/default.inc.php | 8 +++++++- .../phpthumbof/model/phpthumbof.class.php | 7 ++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/_build/data/transport.settings.php b/_build/data/transport.settings.php index 2cd6a52..004d20a 100644 --- a/_build/data/transport.settings.php +++ b/_build/data/transport.settings.php @@ -159,4 +159,21 @@ function stripPhpTags($filename) { 'area' => 'Amazon S3', ), '', true, true); -return $systemSettings; \ No newline at end of file +$systemSettings[$ssIdx] = $modx->newObject('modSystemSetting'); +$systemSettings[$ssIdx++]->fromArray(array ( + 'key' => 'pthumb.s3_output_cloudfront', + 'value' => FALSE, + 'xtype' => 'combo-boolean', + 'namespace' => 'phpthumbof', + 'area' => 'Amazon S3', +), '', true, true); + +$systemSettings[$ssIdx] = $modx->newObject('modSystemSetting'); +$systemSettings[$ssIdx++]->fromArray(array ( + 'key' => 'pthumb.s3_output_cloudfront_url', + 'xtype' => 'textfield', + 'namespace' => 'phpthumbof', + 'area' => 'Amazon S3', +), '', true, true); + +return $systemSettings; diff --git a/core/components/phpthumbof/lexicon/en/default.inc.php b/core/components/phpthumbof/lexicon/en/default.inc.php index 35f6e7e..e449ea1 100644 --- a/core/components/phpthumbof/lexicon/en/default.inc.php +++ b/core/components/phpthumbof/lexicon/en/default.inc.php @@ -76,5 +76,11 @@ $_lang['setting_pthumb.s3_cache_path'] = 'S3 Cache Path Prefix'; $_lang['setting_pthumb.s3_cache_path_desc'] = 'A subdirectory where all cached images will be stored in the S3 bucket(s).'; +$_lang['setting_pthumb.s3_output_cloudfront'] = 'S3 Output Via CloudFront'; +$_lang['setting_pthumb.s3_output_cloudfront_desc'] = 'Serve thumbnails via Amazon CloudFront instead of S3 bucket when using an S3 media source for output. Please also specify the CloudFront URL.'; -$_lang['prop_pthumb.debug_desc'] = 'Write debug messages to the MODX error log.'; \ No newline at end of file +$_lang['setting_pthumb.s3_output_cloudfront_url'] = 'CloudFront URL'; +$_lang['setting_pthumb.s3_output_cloudfront__url_desc'] = 'The CloudFront URL used for serving the thumbnails. Ex: http://d111111abcdef8.cloudfront.net/'; + + +$_lang['prop_pthumb.debug_desc'] = 'Write debug messages to the MODX error log.'; diff --git a/core/components/phpthumbof/model/phpthumbof.class.php b/core/components/phpthumbof/model/phpthumbof.class.php index 4e1141d..0bfbb53 100644 --- a/core/components/phpthumbof/model/phpthumbof.class.php +++ b/core/components/phpthumbof/model/phpthumbof.class.php @@ -93,7 +93,12 @@ function __construct(modX &$modx, &$settings_cache, $options, $s3info = 0) { else { // initialize MS $this->config["{$this->config['s3outKey']}_ok"] = true; $s3properties = $s3obj->getPropertyList(); - $this->config["{$this->config['s3outKey']}_url"] = $s3properties['url']; + $useCloudFront = $modx->getOption('pthumb.s3_output_cloudfront', null, false); + if ($useCloudFront) { + $this->config["{$this->config['s3outKey']}_url"] = $modx->getOption('pthumb.s3_output_cloudfront_url', null, $s3properties['url'], true); // fall-back to regular S3 url if CloudFront url is not set + } else { + $this->config["{$this->config['s3outKey']}_url"] = $s3properties['url']; + } $s3obj->bucket = $s3properties['bucket']; include_once MODX_CORE_PATH . 'model/aws/sdk.class.php'; define('AWS_KEY', $s3properties['key']);