public function PerformTest() { // Note that API::Sites does NOT return a paged // request object, but a derivitave of PagedResponse // Enumerate all Stack Exchange sites $sites = API::Sites(); $count = 0; // count the sites while ($site = $sites->Fetch()) { if (!isset($site['name'])) { throw new Exception('Site array returned is invalid.'); } ++$count; } if ($count < 100) { throw new Exception('Expected more than 100 Stack Exchange sites.'); } // the StackAuth /users/{GUID}/associated route $response = API::AssociatedUsers(1); if ($response->Total() < 50) { throw new Exception('Expected more than 50 associated accounts - only ' . $response->Total() . ' returned.'); } }
<?php // Simple example that demonstrates listing users from a // Stack Exchange site. Makes use of the output helper functions. require_once 'config.php'; require_once '../../src/output_helper.php'; // Generate the site combobox $combo = OutputHelper::CreateCombobox(API::Sites(), 'site'); $site_html = $combo->FetchMultiple()->SetIndices('name', 'api_site_parameter')->SetCurrentSelection()->GetHTML(); ?> <!DOCTYPE html> <html> <head> <title>Stack.PHP - User List</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel='stylesheet' type='text/css' href='../common/style.css' /> </head> <body> <form id='form'> <div id='site_selector'> <b>Select a Stack Exchange site:</b> <?php echo $site_html; ?> <input type="submit" value="Go" /> </div> <?php if (isset($_GET['site'])) { $site = API::Site($_GET['site']); $request = $site->Users(); if (isset($_GET['sort'])) {
$campaign = new stdClass(); } ?> <li class="type-text" id="container-autoposting_campaign_name"> <fieldset class="title"> <div class="inner"> <label for="autoposting_campaign_name">Campaign name</label> <kbd>Set autoposting campaign name</kbd> </div> </fieldset> <fieldset class="data"> <div class="inner"> <input type="text" name="autoposting_campaign_name" value="<?php echo isset($campaign->campaign_name) ? $campaign->campaign_name : ''; ?> " id="autoposting_campaign_name" /> </div> </fieldset> <div class="clear"></div> </li> <li class="type-text" id="container-autoposting_search_term"> <fieldset class="title"> <div class="inner"> <label for="autoposting_search_term">Search Term</label> <kbd>Set search term</kbd> </div> </fieldset>
<?php // Demonstrates how Stack.PHP's data retrieval methods can // be exposed to other clients, such as JavaScript code. require_once 'config.php'; // The very first thing we do is output CORS headers header('Access-Control-Allow-Methods: POST, GET'); header('Access-Control-Allow-Origin: *'); // Retrieve all Stack Exchange sites across all pages. $response = API::Sites(); // Build an array with the response $sites = array(); while ($site = $response->Fetch(TRUE)) { $sites[] = $site->Data(); } // Encode the data as JSON $json = json_encode(array('items' => $sites, 'has_more' => FALSE)); // Output the data according to the parameters specified if (isset($_GET['callback'])) { header('Content-type: application/javascript'); echo "{$_GET['callback']}({$json});"; } else { header('Content-type: application/json'); echo $json; }
public function index() { $this->SetPageInfo('Stack Exchange Sites', 'http://stackexchange.com/sites'); $this->SetViewVariable('response', API::Sites()); }