Skip to content

Commit 09ac7cf

Browse files
committed
First commit.
0 parents  commit 09ac7cf

File tree

1,253 files changed

+167975
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,253 files changed

+167975
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mirror
2+
.sass-cache

amazon-web-services.php

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/*
3+
Plugin Name: Amazon Web Services
4+
Plugin URI: http://wordpress.org/extend/plugins/amazon-web-services/
5+
Description: Includes the Amazon Web Services PHP libraries, stores access keys, and allows other plugins to hook into it
6+
Author: Brad Touesnard
7+
Version: 0.1b1
8+
Author URI: http://bradt.ca/
9+
*/
10+
11+
// Copyright (c) 2013 Brad Touesnard. All rights reserved.
12+
//
13+
// Released under the GPL license
14+
// http://www.opensource.org/licenses/gpl-license.php
15+
//
16+
// **********************************************************************
17+
// This program is distributed in the hope that it will be useful, but
18+
// WITHOUT ANY WARRANTY; without even the implied warranty of
19+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20+
// **********************************************************************
21+
22+
function amazon_web_services_incompatibile( $msg ) {
23+
require_once ABSPATH . '/wp-admin/includes/plugin.php';
24+
deactivate_plugins( __FILE__ );
25+
wp_die( $msg );
26+
}
27+
28+
if ( is_admin() && ( !defined( 'DOING_AJAX' ) || !DOING_AJAX ) ) {
29+
if ( version_compare( PHP_VERSION, '5.3.3', '<' ) ) {
30+
amazon_web_services_incompatibile( __( 'The official Amazon Web Services SDK requires PHP 5.3.3 or higher. The plugin has now disabled itself.', 'amazon-web-services' ) );
31+
}
32+
elseif ( !function_exists( 'curl_version' )
33+
|| !( $curl = curl_version() ) || empty( $curl['version'] ) || empty( $curl['features'] )
34+
|| version_compare( $curl['version'], '7.16.2', '<' ) )
35+
{
36+
amazon_web_services_incompatibile( __( 'The official Amazon Web Services SDK requires cURL 7.16.2+. The plugin has now disabled itself.', 'amazon-web-services' ) );
37+
}
38+
elseif ( !( $curl['features'] & CURL_VERSION_SSL ) ) {
39+
amazon_web_services_incompatibile( __( 'The official Amazon Web Services SDK requires that cURL is compiled with OpenSSL. The plugin has now disabled itself.', 'amazon-web-services' ) );
40+
}
41+
elseif ( !( $curl['features'] & CURL_VERSION_LIBZ ) ) {
42+
amazon_web_services_incompatibile( __( 'The official Amazon Web Services SDK requires that cURL is compiled with zlib. The plugin has now disabled itself.', 'amazon-web-services' ) );
43+
}
44+
}
45+
46+
require_once 'classes/aws-plugin-base.php';
47+
require_once 'classes/amazon-web-services.php';
48+
require_once 'vendor/aws/aws-autoloader.php';
49+
50+
function amazon_web_services_init() {
51+
global $amazon_web_services;
52+
$amazon_web_services = new Amazon_Web_Services( __FILE__ );
53+
}
54+
55+
add_action( 'init', 'amazon_web_services_init' );
56+
57+
function amazon_web_services_activation() {
58+
// Migrate keys over from old Amazon S3 and CloudFront plugin settings
59+
if ( !( $as3cf = get_option( 'tantan_wordpress_s3' ) ) ) {
60+
return;
61+
}
62+
63+
if ( !isset( $as3cf['key'] ) || !isset( $as3cf['secret'] ) ) {
64+
return;
65+
}
66+
67+
if ( !get_site_option( Amazon_Web_Services::SETTINGS_KEY ) ) {
68+
add_site_option( Amazon_Web_Services::SETTINGS_KEY, array(
69+
'access_key_id' => $as3cf['key'],
70+
'secret_access_key' => $as3cf['secret']
71+
) );
72+
}
73+
74+
unset( $as3cf['key'] );
75+
unset( $as3cf['secret'] );
76+
77+
update_option( 'tantan_wordpress_s3', $as3cf );
78+
}
79+
register_activation_hook( __FILE__, 'amazon_web_services_activation' );

assets/config.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Require any additional compass plugins here.
2+
3+
# Set this to the root of your project when deployed:
4+
http_path = "/"
5+
css_dir = "css"
6+
sass_dir = "sass"
7+
images_dir = "img"
8+
javascripts_dir = "js"
9+
10+
# You can select your preferred output style here (can be overridden via the command line):
11+
# output_style = :expanded or :nested or :compact or :compressed
12+
output_style = :compressed
13+
14+
# To enable relative paths to assets via compass helper functions. Uncomment:
15+
# relative_assets = true
16+
17+
# To disable debugging comments that display the original location of your selectors. Uncomment:
18+
line_comments = false
19+
20+
21+
# If you prefer the indented syntax, you might want to regenerate this
22+
# project again passing --syntax sass, or you can uncomment this:
23+
# preferred_syntax = :sass
24+
# and then run:
25+
# sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass

assets/css/global.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/css/styles.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/img/icon16.png

1.47 KB
Loading

assets/img/[email protected]

1.92 KB
Loading

assets/img/icon32.png

1.92 KB
Loading

assets/img/[email protected]

1.94 KB
Loading

assets/js/script.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(function($) {
2+
3+
$(document).ready(function() {
4+
5+
$('.aws-settings').each(function() {
6+
var $container = $(this);
7+
8+
$('.reveal-form a', $container).click(function() {
9+
$('form', $container).show();
10+
return false;
11+
});
12+
});
13+
14+
});
15+
16+
})(jQuery);

assets/js/script.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/sass/global.scss

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#adminmenu .toplevel_page_amazon-web-services {
2+
div.wp-menu-image {
3+
background: url("../img/icon16.png") no-repeat 7px 5px;
4+
}
5+
6+
&.wp-has-current-submenu, &.current, &:hover {
7+
div.wp-menu-image {
8+
background-position: 7px -79px;
9+
}
10+
}
11+
12+
img {
13+
display: none;
14+
}
15+
16+
@media only screen and (-webkit-min-device-pixel-ratio: 2),
17+
only screen and (-moz-min-device-pixel-ratio: 2),
18+
only screen and (-o-min-device-pixel-ratio: 2/1),
19+
only screen and (min-device-pixel-ratio: 2) {
20+
21+
div.wp-menu-image {
22+
background-image: url("../img/[email protected]");
23+
background-size: 16px 100px;
24+
}
25+
}
26+
}
27+
28+
#icon-amazon-web-services {
29+
background: url(../img/icon32.png) no-repeat;
30+
31+
@media only screen and (-webkit-min-device-pixel-ratio: 2),
32+
only screen and (-moz-min-device-pixel-ratio: 2),
33+
only screen and (-o-min-device-pixel-ratio: 2/1),
34+
only screen and (min-device-pixel-ratio: 2) {
35+
36+
background: url(../img/[email protected]) no-repeat;
37+
background-size: 32px 32px;
38+
}
39+
}

assets/sass/styles.scss

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.aws-content {
2+
max-width: 800px;
3+
}
4+
5+
.aws-updated {
6+
background-color: #ffffe0;
7+
border: 1px solid #e6db55;
8+
border-radius: 3px;
9+
padding: 0 0.6em;
10+
color: #333;
11+
12+
p {
13+
margin: 0.5em 0;
14+
padding: 2px;
15+
}
16+
}
17+
18+
.addon {
19+
margin-top: 10px;
20+
21+
h1 {
22+
font-size: 14px;
23+
margin: 0;
24+
}
25+
}

classes/amazon-web-services.php

+189
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
<?php
2+
use Aws\Common\Aws;
3+
4+
class Amazon_Web_Services extends AWS_Plugin_Base {
5+
6+
private $plugin_title, $plugin_menu_title, $client;
7+
8+
const SETTINGS_KEY = 'aws_settings';
9+
10+
function __construct( $plugin_file_path ) {
11+
parent::__construct( $plugin_file_path );
12+
13+
do_action( 'aws_init', $this );
14+
15+
if ( is_admin() ) {
16+
do_action( 'aws_admin_init', $this );
17+
}
18+
19+
if ( is_multisite() ) {
20+
add_action( 'network_admin_menu', array( $this, 'admin_menu' ) );
21+
$this->plugin_permission = 'manage_network_options';
22+
}
23+
else {
24+
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
25+
$this->plugin_permission = 'manage_options';
26+
}
27+
28+
$this->plugin_title = __( 'Amazon Web Services', 'amazon-web-services' );
29+
$this->plugin_menu_title = __( 'AWS', 'amazon-web-services' );
30+
}
31+
32+
function admin_menu() {
33+
$hook_suffixes[] = add_menu_page( $this->plugin_title, $this->plugin_menu_title, $this->plugin_permission, $this->plugin_slug, array( $this, 'render_page' ) );
34+
35+
$title = __( 'Addons', 'amazon-web-services' );
36+
$hook_suffixes[] = $this->add_page( $title, $title, $this->plugin_permission, 'aws-addons', array( $this, 'render_page' ) );
37+
38+
global $submenu;
39+
if ( isset( $submenu[$this->plugin_slug][0][0] ) ) {
40+
$submenu[$this->plugin_slug][0][0] = __( 'Settings', 'amazon-web-services' );
41+
}
42+
43+
do_action( 'aws_admin_menu', $this );
44+
45+
foreach ( $hook_suffixes as $hook_suffix ) {
46+
add_action( 'load-' . $hook_suffix , array( $this, 'plugin_load' ) );
47+
}
48+
49+
add_action( 'admin_print_styles', array( $this, 'enqueue_menu_styles' ) );
50+
}
51+
52+
function add_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
53+
return add_submenu_page( $this->plugin_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
54+
}
55+
56+
function enqueue_menu_styles() {
57+
$src = plugins_url( 'assets/css/global.css', $this->plugin_file_path );
58+
wp_enqueue_style( 'aws-global-styles', $src, array(), $this->get_installed_version() );
59+
}
60+
61+
function plugin_load() {
62+
$src = plugins_url( 'assets/css/styles.css', $this->plugin_file_path );
63+
wp_enqueue_style( 'aws-styles', $src, array(), $this->get_installed_version() );
64+
65+
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
66+
67+
$src = plugins_url( 'assets/js/script' . $suffix . '.js', $this->plugin_file_path );
68+
wp_enqueue_script( 'aws-script', $src, array( 'jquery' ), $this->get_installed_version(), true );
69+
70+
if ( isset( $_GET['page'] ) && 'aws-addons' == $_GET['page'] ) {
71+
add_thickbox();
72+
}
73+
74+
$this->handle_post_request();
75+
76+
do_action( 'aws_plugin_load', $this );
77+
}
78+
79+
function handle_post_request() {
80+
if ( empty( $_POST['action'] ) || 'save' != $_POST['action'] ) {
81+
return;
82+
}
83+
84+
if ( empty( $_POST['_wpnonce'] ) || !wp_verify_nonce( $_POST['_wpnonce'], 'aws-save-settings' ) ) {
85+
die( __( "Cheatin' eh?", 'amazon-web-services' ) );
86+
}
87+
88+
// Make sure $this->settings has been loaded
89+
$this->get_settings();
90+
91+
$post_vars = array( 'access_key_id', 'secret_access_key' );
92+
foreach ( $post_vars as $var ) {
93+
if ( !isset( $_POST[$var] ) ) {
94+
continue;
95+
}
96+
97+
if ( 'secret_access_key' == $var && '-- not shown --' == $_POST[$var] ) {
98+
continue;
99+
}
100+
101+
$this->set_setting( $var, $_POST[$var] );
102+
}
103+
104+
$this->save_settings();
105+
}
106+
107+
function render_page() {
108+
if ( empty( $_GET['page'] ) ) {
109+
// Not sure why we'd ever end up here, but just in case
110+
wp_die( 'What the heck are we doin here?' );
111+
}
112+
113+
$view = 'settings';
114+
if ( preg_match( '@^aws-(.*)$@', $_GET['page'], $matches ) ) {
115+
$allowed = array( 'addons' );
116+
if ( in_array( $matches[1], $allowed ) ) {
117+
$view = $matches[1];
118+
}
119+
}
120+
121+
$this->render_view( 'header' );
122+
$this->render_view( $view );
123+
$this->render_view( 'footer' );
124+
}
125+
126+
function are_key_constants_set() {
127+
return defined( 'AWS_ACCESS_KEY_ID' ) && defined( 'AWS_SECRET_ACCESS_KEY' );
128+
}
129+
130+
function get_access_key_id() {
131+
if ( $this->are_key_constants_set() ) {
132+
return AWS_ACCESS_KEY_ID;
133+
}
134+
135+
return $this->get_setting( 'access_key_id' );
136+
}
137+
138+
function get_secret_access_key() {
139+
if ( $this->are_key_constants_set() ) {
140+
return AWS_SECRET_ACCESS_KEY;
141+
}
142+
143+
return $this->get_setting( 'secret_access_key' );
144+
}
145+
146+
function get_client() {
147+
if ( !$this->get_access_key_id() || !$this->get_secret_access_key() ) {
148+
return new WP_Error( 'access_keys_missing', sprintf( __( 'You must first <a href="%s">set your AWS access keys</a> to use this addon.', 'amazon-web-services' ), 'admin.php?page=' . $this->plugin_slug ) );
149+
}
150+
151+
if ( is_null( $this->client ) ) {
152+
$args = array(
153+
'key' => $this->get_access_key_id(),
154+
'secret' => $this->get_secret_access_key()
155+
);
156+
$args = apply_filters( 'aws_get_client_args', $args );
157+
$this->client = Aws::factory( $args );
158+
}
159+
160+
return $this->client;
161+
}
162+
163+
/*
164+
function get_tabs() {
165+
$tabs = array( 'addons' => 'Addons', 'settings' => 'Settings', 'about' => 'About' );
166+
return apply_filters( 'aws_get_tabs', $tabs, $this );
167+
}
168+
169+
function get_active_tab() {
170+
if ( isset( $_GET['tab'] ) ) {
171+
$tab = $_GET['tab'];
172+
$tabs = $this->get_tabs();
173+
if ( isset( $tabs[$tab] ) ) {
174+
return $tab;
175+
}
176+
}
177+
178+
if ( !$this->get_access_key_id() ) {
179+
return 'settings';
180+
}
181+
182+
return 'addons'; // Default
183+
}
184+
*/
185+
186+
function get_plugin_install_url( $slug ) {
187+
return wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug );
188+
}
189+
}

0 commit comments

Comments
 (0)