Esempio n. 1
0
$output_page = function ($content, $title = 'Discover') use($uri, $legacy) {
    require __DIR__ . '/layout.php';
};
$load_template = function ($template, $args = array()) {
    ob_start();
    require __DIR__ . '/' . $template . '.php';
    return ob_get_clean();
};
$requested = $_SERVER['REQUEST_URI'];
if ($requested === '/style.css') {
    header('Content-Type: text/css; charset=utf-8');
    readfile(__DIR__ . '/style.css');
    return;
}
if (empty($_GET['uri'])) {
    $output_page('');
    return;
}
try {
    $site = Discovery\discover($uri, $legacy);
    if (empty($site)) {
        $error = "{$uri} does not appear to be a WordPress site (no API header found)";
        $output_page($load_template('error', array('error' => $error)));
        return;
    }
} catch (Exception $e) {
    $error = sprintf('Error occurred while trying to discover: %s (%d)', $e->getMessage(), $e->getCode());
    $output_page($load_template('error', array('error' => $error)));
    return;
}
$output_page($load_template('details', array('site' => $site, 'uri' => $uri)));
Esempio n. 2
0
// Work out where we are.
$here = get_requested_url();
// What should we show?
$step = isset($_GET['step']) ? $_GET['step'] : '';
switch ($step) {
    // Step 0: Pre-Discovery
    case '':
        return output_page(load_template('discovery-form'));
        // Step 1: Discovery
    // Step 1: Discovery
    case 'discover':
        if (empty($_GET['uri'])) {
            return output_page(load_template('discovery-form'));
        }
        try {
            $site = Discovery\discover($_GET['uri']);
        } catch (Exception $e) {
            $error = sprintf("Error while discovering: %s.", htmlspecialchars($e->getMessage()));
            return output_page(load_template('discovery-form'), 'Discover', $error);
        }
        if (empty($site)) {
            $error = sprintf("Couldn't find the API at <code>%s</code>.", htmlspecialchars($_GET['uri']));
            return output_page(load_template('discovery-form'), 'Discover', $error);
        }
        if (!$site->supportsAuthentication('oauth1')) {
            $error = "Site doesn't appear to support OAuth 1.0a authentication.";
            return output_page(load_template('discovery-form'), 'Discover', $error);
        }
        $_SESSION['site_base'] = $site->getIndexURL();
        $_SESSION['site_auth_urls'] = $site->getAuthenticationData('oauth1');
        return output_page(load_template('credential-form'));