示例#1
0
function main()
{
    if (!checkPrereqs())
    {
        return;
    }

    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        handlePost();
    } else {
        showForm();
    }
}
示例#2
0
// Setup the application
$app = new Application();
$app['debug'] = true;
$app['aws'] = new \Aws\Sdk(['region' => 'eu-west-1', 'version' => 'latest']);
$app['aws.s3'] = $app['aws']->createS3();
$app['aws.ddb'] = $app['aws']->createDynamoDb();
$app['env.orig'] = 'devday-source';
$app['env.trans'] = 'devday-thumbs';
$app['env.table'] = 'devday-items';
$app['imagine'] = new Imagine\Gd\Imagine();
$app->register(new TwigServiceProvider(), array('twig.path' => __DIR__ . '/template'));
// Handle the index page
$app->match('/', function (Request $request) use($app) {
    $alert = null;
    if ('POST' == $request->getMethod()) {
        $alert = handlePost($app, $request);
    }
    return $app['twig']->render('index.twig', handleGet($app, $request, $alert));
});
// Handles HTTP GET methods -- Displays the list of items
function handleGet($app, $request, $alert)
{
    $items = null;
    try {
        $items = $app['aws.ddb']->getIterator('Scan', ['TableName' => $app['env.table']]);
    } catch (Exception $e) {
        $alert = array('type' => 'error', 'message' => "Table scan error:" . $e);
    }
    return array('alert' => $alert, 'app' => $app, 'items' => $items);
}
// Handles HTTP POST requests -- Add the image to S3 + mata data to DynamoDB
 *  - 0: Showing the form for client ID, secret and callback URL
 *  - 1: Receiving the form data via POST, redirecting the user browser to CREST auth
 *  - 2: Receiving a code via redirected user browser from CREST, use it to retrieve refresh token
 *  - 3: Showing refresh token
 */
if (isset($_SESSION['refresh_token'])) {
    //we already have a refresh token
    $_SESSION['step'] = 3;
    renderHtml();
} elseif (isset($_GET['code']) and isset($_SESSION['auth_state']) and isset($_GET['state']) and $_SESSION['auth_state'] == $_GET['state']) {
    //we received a request with a code parameter
    retrieveToken();
    renderHtml();
} elseif (count($_POST) > 0) {
    //we received a post request
    handlePost();
} else {
    //default case
    $_SESSION['step'] = 0;
    renderHtml();
}
session_write_close();
/**
 * This function represents step 1, processing the form POST data and redirecting the user client browser to CREST auth.
 *
 * @return void
 */
function handlePost()
{
    unset($_SESSION['clientid']);
    unset($_SESSION['clientsecret']);
示例#4
0
<?php

require_once plugin_dir_path(__FILE__) . 'lib/functions.php';
/* Check for Podcast Playlists */
$podcasts = getSavedPodcasts();
/* Handle Adding New RSS */
if (!empty($_POST)) {
    handlePost($_POST);
}
?>

<style media="screen" type="text/css">
.code { font-family:'Courier New', Courier, monospace; }
.code-bold {
	font-family:'Courier New', Courier, monospace; 
	font-weight: bold;
}
</style>





<div class="wrap">
  <h2><?php 
_e("Libsyn Playlist Settings", LIBSYN_DIR);
?>
</h2>
  <form name="<?php 
echo LIBSYN_KEY . "form";
?>
input.text { width: 250px; }
form { margin: 0 auto; }
body { color: #fff; background-color: #252525; width: 100%; background-image: url(bg.jpg); }
</style></head><body><div style="text-align: center; padding: 20px; background-color: #252525;"><h2><?php 
echo $TITLE;
?>
</h2>
<?php 
if (empty($TOKEN) | empty($SUBDOMAIN) | empty($TITLE) | empty($NEXTSTEP)) {
    scold("This script is not fully configured. Oops!");
} else {
    if (empty($_POST)) {
        showForm();
        // Show a blank form
    } else {
        if (handlePost($SUBDOMAIN, $TOKEN)) {
            echo $NEXTSTEP;
        }
    }
}
// all functions below
function scold($m)
{
    // message
    echo '<p class="err" > ' . $m . " </p>\n";
}
function sendForm($f, $l, $e, $s, $t)
{
    // first, last, email, subdomain, token
    $slackInviteUrl = 'https://' . $s . '.slack.com/api/users.admin.invite?t=' . time();
    $fields = array('email' => urlencode($e), 'first_name' => urlencode($f), 'last_name' => urlencode($l), 'token' => $t, 'set_active' => urlencode('true'), '_attempts' => '1');