die('Failed to find WordPress return URL. Please report this error to the item author.');
}
if (isset($_REQUEST['get_token'])) {
    header("Content-type: text/javascript");
    if (!empty($_SESSION['oauth_token']) && $_REQUEST['oauth_nonce'] == $_SESSION['oauth_nonce']) {
        $token_to_send = $_SESSION['oauth_token'];
        unset($token_to_send['refresh_token']);
        unset($token_to_send['token_type']);
        echo json_encode($token_to_send);
    } else {
        echo '-1';
    }
    exit;
}
$envato = new envato_api_basic();
$envato->set_client_id(_ENVATO_APP_ID);
$envato->set_client_secret(_ENVATO_APP_SECRET);
$envato->set_redirect_url(_ENVATO_APP_URL);
if (isset($_REQUEST['refresh_token'])) {
    header("Content-type: text/javascript");
    if (!empty($_SESSION['oauth_token']['refresh_token']) && $_REQUEST['oauth_nonce'] == $_SESSION['oauth_nonce']) {
        $envato->set_manual_token($_SESSION['oauth_token']);
        $new_access = $envato->refresh_token();
        if ($new_access) {
            $_SESSION['oauth_token']['access_token'] = $new_access;
        }
        echo json_encode(array('new_token' => $new_access));
    } else {
        echo '-1';
    }
    exit;
Ejemplo n.º 2
0
<?php

if (!file_exists('config.php')) {
    die('Copy the config.sample.php to config.php');
}
require 'config.php';
if (defined('REDIRECT_URL')) {
    $redirect_uri = REDIRECT_URL;
} else {
    //try to guess the redirect urL
    $redirect_uri = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . "://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . '/';
}
//load the API (thanks Dave!)
require 'envato-api.class.php';
$api = new envato_api_basic();
$api->set_client_id(CLIENT_ID);
$api->set_client_secret(SECRET_APP_KEY);
$api->set_redirect_url($redirect_uri);
//list items
if (isset($_GET['items'])) {
    $return = array();
    foreach ($_GET['items'] as $slug => $item_id) {
        if (isset($items[$item_id])) {
            $return[] = $items[$item_id];
        }
    }
    @header('Content-type: application/json');
    echo json_encode($return);
    exit;
    //redirect to Envato authorization page
} elseif (isset($_GET['auth'])) {