示例#1
0
/**
 * Prints the index with links to the examples.
 * @param array $actions supported actions
 */
function printIndex($actions)
{
    print '<ul class="nav">' . "\n";
    foreach ($actions as $action) {
        print '<li><a class="highlight" href=?action=' . $action . '>' . actionNameToWords($action) . '</a></li>' . "\n";
    }
    print '</ul>' . "\n";
}
示例#2
0
    $auth->authenticate('sample_user');
    // To get rid of the code in the URL after the authentication.
    if (isset($_GET['code'])) {
        header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
    }
    // If the action is set dispatch the action if supported
    if (isset($_GET["action"])) {
        $action = $_GET["action"];
        if (!in_array($action, $actions)) {
            die('Unsupported action:' . $action . "\n");
        }
        // Render the required action.
        require_once 'examples/' . $action . '.php';
        $class = ucfirst($action);
        $example = new $class($auth->getAdSenseService());
        $title = actionNameToWords($action) . ' example';
        printHtmlHeader($title);
        $example->render();
        printHtmlFooter();
        $auth->refreshToken();
    } else {
        // Show the list of links to supported actions.
        printHtmlHeader('AdSense Management API PHP usage examples.');
        printIndex($actions);
        printHtmlFooter();
    }
} catch (Exception $e) {
    die('Runtime error: ' . $e->getMessage() . "\n" . $e->getTraceAsString());
}
/**
 * Builds an array containing the supported actions.