1,612 changes: 806 additions & 806 deletions lib/JSON.php

Large diffs are not rendered by default.

674 changes: 350 additions & 324 deletions lib/admin.php

Large diffs are not rendered by default.

190 changes: 93 additions & 97 deletions lib/api.php
Original file line number Diff line number Diff line change
@@ -1,97 +1,93 @@
<?php

/**
* Fastly API for PHP.
* @package Fastly
* @author Ryan Sandor Richards
* @copyright 2011 Fastly.com, All Rights Reserved
*/
class FastlyAPI {
/**
* Default constructor.
* @param $api_key Fastly API key.
* @param $host Hostname of the API server.
* @param $port Port for the API server.
*/
function FastlyAPI($api_key='', $host='https://app.fastly.com', $port=null) {
$this->api_key = $api_key;
$this->host = $host;
$this->port = $port;
$this->host_name = preg_replace('/^(ssl|https?):\/\//', '', $host);
}

/**
* Sends a purge request to the Fastly API.
* @param $uri URI to purge.
*/
function purge($uris) {
// TODO How can we handle this more elegantly?
if (!$this->api_key)
return;

if (!is_array($uris)) {
$uris = array($uris);
}
// TODO - change this to a curl_multi_exec at some point
$logPurges = (bool)get_option('fastly_log_purges');
foreach ($uris as $uri) {
#$uri = preg_replace("/^https?:\/\//", '', $uri);
if( $logPurges ) {
error_log("Purging " . $uri);
}
$this->post($uri);
}
}

/**
* Sends a purge all request to the Fastly API.
*/
function purgeAll($service_id) {
$url = $this->host;
if (!is_null($this->port) && is_numeric($this->port)) {
$url .= ":" . $this->port;
}
$url .= '/service/' . $service_id . '/purge_all';

return $this->post($url, true);
}

/**
* Sends a post request to the Fastly API.
* @param $path Path to call on the remote host.
* @param $data Data for the body for the post request.
* @return The response from the server or -1 if an error occurred.
*/
function post($url, $do_post = true) {

$headers = array();
if ($this->api_key) {
$headers[] = "Fastly-Key: " . $this->api_key;
}

$ch = curl_init();
# Temporary workaround to fix purging. Use POST instead of PURGE method.
# Strip off protocol
$url = get_option('fastly_api_hostname') . "/purge/" . preg_replace("/^http(s?):\/\//",'', $url);

if( (bool)get_option('fastly_log_purges') ) {
error_log("Purging using POST for " . $url);
}

curl_setopt($ch, CURLOPT_URL, $url );
if ($do_post) {
curl_setopt($ch, CURLOPT_POST, 1);
} else {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PURGE");
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return !!$response;

}
}

// "WHITE LIGHT, doo-doo doo-doo doo, WHITE LIGHT" -- Gorillaz
?>
<?php

/**
* Fastly API for PHP.
* @package Fastly
* @author Ryan Sandor Richards
* @copyright 2011 Fastly.com, All Rights Reserved
*/
class FastlyAPI {
/**
* Default constructor.
* @param $api_key Fastly API key.
* @param $host Hostname of the API server.
* @param $port Port for the API server.
*/
function FastlyAPI($api_key='', $host='https://app.fastly.com', $port=null) {
$this->api_key = $api_key;
$this->host = $host;
$this->port = $port;
$this->host_name = preg_replace('/^(ssl|https?):\/\//', '', $host);
}

/**
* Sends a purge request to the Fastly API.
* @param $uri URI to purge.
*/
function purge($uris) {
// TODO How can we handle this more elegantly?
if (!$this->api_key)
return;

if (!is_array($uris)) {
$uris = array($uris);
}
// TODO - change this to a curl_multi_exec at some point
$logPurges = (bool)get_option('fastly_log_purges');
foreach ($uris as $uri) {
#$uri = preg_replace("/^https?:\/\//", '', $uri);
if( $logPurges ) {
error_log("Purging " . $uri);
}
$this->post($uri);
}
}

/**
* Sends a purge all request to the Fastly API.
*/
function purgeAll($service_id) {
$url = $this->host;
if (!is_null($this->port) && is_numeric($this->port)) {
$url .= ":" . $this->port;
}
$url .= '/service/' . $service_id . '/purge_all';

return $this->post($url, true);
}

/**
* Sends a post request to the Fastly API.
* @param $path Path to call on the remote host.
* @param $data Data for the body for the post request.
* @return The response from the server or -1 if an error occurred.
*/
function post($url, $do_post = true) {

$headers = array();
if ($this->api_key) {
$headers[] = "Fastly-Key: " . $this->api_key;
}

$ch = curl_init();
# Temporary workaround to fix purging. Use POST instead of PURGE method.
# Strip off protocol
$url = get_option('fastly_api_hostname') . "/purge/" . preg_replace("/^http(s?):\/\//",'', $url);

if( (bool)get_option('fastly_log_purges') ) {
error_log("Purging using POST for " . esc_url($url));
}

$args = array(
'headers' => $headers,
'method' => (true === $do_post) ? 'POST' : 'PURGE',
);

$response = wp_remote_request($url, $args);

return ( is_wp_error( $response ) ) ? -1 : $response;
}
}

// "WHITE LIGHT, doo-doo doo-doo doo, WHITE LIGHT" -- Gorillaz
?>
440 changes: 220 additions & 220 deletions lib/purge.php

Large diffs are not rendered by default.

130 changes: 65 additions & 65 deletions static/fastly.css
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
/*
* Fastly Wordpress Plugin
* Admin Interface Styles
* @author Ryan Sandor Richards
*/
#fastly-admin h1 {
float: left;
}

#fastly-admin .content {
padding: 10px 0 0 20px;
margin: 10px 0 0 200px;
}

#fastly-admin .content .button-row {
margin: 20px 0;
line-height: 20px;
}

#fastly-admin .error {
background-color: #faa;
padding: 4px;
}

#fastly-admin .error-flash {
color: red;
font-weight: bold;
}

#fastly-admin a.disabled {
cursor: default !important;
}

#fastly-admin .loading {
display: none;
margin-bottom: -3px;
margin-left: 4px;
}

#fastly-admin a.advanced {
font-size: 9px;
}

#fastly-admin fieldset {
-moz-border-radius: 6px;
border-radius: 6px;
background: #efefef;
padding: 6px;
width: 500px;
}

#fastly-admin fieldset.advanced {
display: none;
}

#fastly-admin input.text {
font-size: 18px;
padding: 4px;
width: 300px;
}

#fastly-admin fieldset input.text {
width: 99%;
}
/*
* Fastly Wordpress Plugin
* Admin Interface Styles
* @author Ryan Sandor Richards
*/
#fastly-admin h1 {
float: left;
}

#fastly-admin .content {
padding: 10px 0 0 20px;
margin: 10px 0 0 200px;
}

#fastly-admin .content .button-row {
margin: 20px 0;
line-height: 20px;
}

#fastly-admin .error {
background-color: #faa;
padding: 4px;
}

#fastly-admin .error-flash {
color: red;
font-weight: bold;
}

#fastly-admin a.disabled {
cursor: default !important;
}

#fastly-admin .loading {
display: none;
margin-bottom: -3px;
margin-left: 4px;
}

#fastly-admin a.advanced {
font-size: 9px;
}

#fastly-admin fieldset {
-moz-border-radius: 6px;
border-radius: 6px;
background: #efefef;
padding: 6px;
width: 500px;
}

#fastly-admin fieldset.advanced {
display: none;
}

#fastly-admin input.text {
font-size: 18px;
padding: 4px;
width: 300px;
}

#fastly-admin fieldset input.text {
width: 99%;
}

407 changes: 207 additions & 200 deletions static/fastly.js

Large diffs are not rendered by default.

Binary file modified static/logo_white.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.