Skip to content

Commit

Permalink
Fix trailing slash on CDN
Browse files Browse the repository at this point in the history
Add select option
  • Loading branch information
jawngee committed Jun 15, 2016
1 parent bec6f2a commit 28e8741
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
33 changes: 33 additions & 0 deletions classes/ilab-media-tool-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ abstract class ILabMediaToolBase {
*/
protected $options_group;

private $select_options = [];

/**
* Creates a new instance. Subclasses should do any setup dependent on being enabled in setup()
* @param $toolName
Expand Down Expand Up @@ -167,6 +169,9 @@ public function registerSettings()
case 'number':
$this->registerNumberFieldSetting($option,$optionInfo['title'],$group,(isset($optionInfo['description']) ? $optionInfo['description'] : null));
break;
case 'select':
$this->registerSelectSetting($option,$optionInfo['options'],$optionInfo['title'],$group,(isset($optionInfo['description']) ? $optionInfo['description'] : null));
break;
}
}
}
Expand Down Expand Up @@ -307,6 +312,34 @@ public function renderNumberFieldSetting($args)
echo "<p class='description'>".$args['description']."</p>";
}

protected function registerSelectSetting($option_name,$options,$title,$settings_slug,$description=null)
{
$this->select_options[$option_name] = $options;
add_settings_field($option_name,$title,[$this,'renderSelectSetting'],$this->options_page,$settings_slug,['option'=>$option_name,'description'=>$description]);
}

public function renderSelectSetting($args)
{
$option = $args['option'];
$options = $this->select_options[$option];

$value=get_option($args['option']);

echo "<select name=\"{$option}\">\n";
foreach($options as $val => $name) {
$opt = "\t<option value=\"{$val}\"";
if ($val == $value)
$opt .= " selected";
$opt .= ">{$name}</option>\n";

echo $opt;
}
echo "</select>\n";

if ($args['description'])
echo "<p class='description'>".$args['description']."</p>";
}

public function haveSettingsChanged() {
if (get_transient("settings_changed_".$this->toolName)) {
delete_transient("settings_changed_".$this->toolName);
Expand Down
3 changes: 3 additions & 0 deletions classes/tools/s3/ilab-media-s3-tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public function __construct($toolName, $toolInfo, $toolManager)
$this->cdn = "https://s3-{$this->region}.amazonaws.com/{$this->bucket}";
}

if ($this->cdn)
$this->cdn=trim($this->cdn,'/');

$this->docCdn = get_option('ilab-doc-s3-cdn-base', $this->cdn);

$this->settingsError = get_option('ilab-s3-settings-error', false);
Expand Down
14 changes: 13 additions & 1 deletion tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,19 @@
"ilab-media-s3-region": {
"title": "AWS Region",
"description": "If you are supplying this value through a .env file, or environment variables, the key is: <strong>ILAB_AWS_S3_REGION</strong>",
"type": "text-field",
"type": "select",
"options": {
"us-east-1": "US East (N. Virginia)",
"us-west-1": "US West (N. California)",
"us-west-2": "US West (Oregon)",
"eu-west-1": "EU (Ireland)",
"eu-central-1": "EU (Frankfurt)",
"ap-northeast-1": "Asia Pacific (Tokyo)",
"ap-northeast-2": "Asia Pacific (Seoul)",
"ap-southeast-1": "Asia Pacific (Singapore)",
"ap-southeast-2": "Asia Pacific (Sydney)",
"sa-east-1": "South America (São Paulo)"
},
"watch": true
}
}
Expand Down

0 comments on commit 28e8741

Please sign in to comment.