function renderRequest($url) { if (caching) { $cache = readCache($url); if ($cache) { list($contentType, $content) = $cache; return [true, [$contentType, base64_decode($content)]]; } } list($rBool, $rData, $bCache) = doRequest($url); if (!$rBool) { if (caching) { if ($bCache) { bulkCacheTimestampUpdate(); } $cache = readCache($url, true); if ($cache) { list($contentType, $content) = $cache; return [true, [$contentType, base64_decode($content)]]; } } return [false, $rData]; } if (caching) { if (!writeCache($url, $rData)) { error_log('could not write to cache'); } } list($contentType, $content) = $rData; return [true, [$contentType, base64_decode($content)]]; }
function search_bol($keyword, $server, $port, $apiKey) { // Build the request to the API $output = doRequest('GET', $server, $port, '/catalog/v4/search', '?q=' . urlencode($keyword) . '&apikey=' . $apiKey . '&offset=0&nrProducts=8includeattributes=true&dataoutput=categories,refinements,products&ids=0', '', null); // Check for the right http status in the API respons if (substr_count($output, "200 OK") > 0) { // Strip unneeded stuff from the json respons list($header, $body) = explode("\r\n\r\n", $output, 2); // decode the json sting $phpobject = json_decode($body); return $phpobject; } }
* all of the functionality webforms can provide. See https://wiki.majestic3.com/?post_type=api-sections&p=21 */ //set url $url = ""; //https://wiki.majestic3.com //set form id $fid = ""; //232 //set complete url $form_url = "{$url}/forms/bf/json/{$fid}"; //request form information $json = file_get_contents($form_url); $json = str_replace(array("'"), array("\\'"), $json); //process submit if ($_POST) { $result = doRequest($form_url, $_POST); $json = str_replace(array("'", "\\"), array("\\'", "\\\\"), $result); //return json to ajax request echo $json, exit; } //end if ?> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link type="text/css" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" /> <link type="text/css" href="//code.cloudcms.com/alpaca/1.5.14/bootstrap/alpaca.min.css" rel="stylesheet" /> <script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script> <script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.3/handlebars.js"></script> <script type="text/javascript" src="//code.cloudcms.com/alpaca/1.5.14/bootstrap/alpaca.min.js"></script>
$endpoint .= "?token=" . API_TOKEN . "&{$extra_params}"; } try { $resp = $client->get($endpoint)->send()->getBody(); return json_decode($resp); } catch (Exception $e) { return null; } } $resp = doRequest("v2/server/status"); if ($resp != null && $resp->status == 200) { $content = "{$resp->world}\nPlayers: {$resp->playercount}/{$resp->maxplayers}"; # Append the player list if there's anyone online and we have that option enabled if (API_GET_PLAYER_LIST && $resp->playercount > 0) { $playerList = doRequest("v2/players/list"); if ($playerList != null && $playerList->status == 200 && count($playerList->players) > 0) { $content .= "\n\nPlayers Online\n"; foreach ($playerList->players as $player) { $content .= "{$player->nickname}\n"; } } } # Append the MOTD if we want it if (API_GET_MOTD) { $motd = doRequest("v2/server/rawcmd", "cmd=/motd"); if ($motd != null && $motd->status == 200) { $content .= "\n\nMOTD\n{$motd->response}"; } } echo json_encode(array("content" => $content, "refresh_frequency" => API_REFRESH_FREQUENCY)); }
$response = simplexml_load_string(doRequest($user, $pw, $url, $calendars_request)); //To array $calendars = array(); foreach ($response->response as $cal) { $entry["href"] = $cal->href; if (isset($cal->propstat[0]->prop[0]->displayname)) { $entry["name"] = $cal->propstat[0]->prop[0]->displayname; } else { $entry["name"] = ""; } $calendars[] = $entry; } //CardDAV URL $cardserver = str_replace('caldav', 'contacts', $_POST['server']); $card_request = "<A:propfind xmlns:A='DAV:'>\n\t\t\t\t\t\t\t<A:prop>\n\t\t\t\t\t\t\t\t<A:addressbook-home-set xmlns:A='urn:ietf:params:xml:ns:carddav'/>\n\t\t\t\t\t\t\t</A:prop>\n\t\t\t\t\t\t</A:propfind>"; $response = simplexml_load_string(doRequest($user, $pw, $cardserver . $principal_url, $card_request)); $cardurl = $response->response[0]->propstat[0]->prop[0]->{'addressbook-home-set'}->href; //Output echo "<h1 style='color:darkred;'>Your principal settings</h1>"; echo "<table border='1' style='border-collapse:collapse;'>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><b style='color:blue;'>iCloud CalDAV server:</b></td>\n\t\t\t\t\t<td style='color:darkgreen;'>" . $_POST['server'] . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><b style='color:blue;'>User-ID: </b></td>\n\t\t\t\t\t<td style='color:darkgreen;'>" . $userID . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><b style='color:blue;'>Principal-URL: </b></td>\n\t\t\t\t\t<td style='color:darkgreen;'>" . $principal_url . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><b style='color:blue;'>Contacts-URL: </b></td>\n\t\t\t\t\t<td style='color:darkgreen;'>" . $cardurl . "</td>\n\t\t\t\t</tr>\n\t\t\t</table><br>"; echo "<h1 style='color:darkred;'>Your calendars</h1>"; echo "<table border='1' style='border-collapse:collapse;'>\n\t\t\t\t<tr>\n\t\t\t\t\t<td align='center'><b style='color:blue;'>Calendar</td>\n\t\t\t\t\t<td align='center'><b style='color:blue;'>Calendar href</td>\n\t\t\t\t\t<td align='center'><b style='color:blue;'>URL</td>\n\t\t\t\t</tr>"; foreach ($calendars as $calendar) { echo "<tr>\n\t\t\t\t\t<td style='color:darkgreen;'>" . $calendar["name"] . "</td>\n\t\t\t\t\t<td>" . $calendar["href"] . "</td>\n\t\t\t\t\t<td>" . $_POST['server'] . $calendar["href"] . "</td>\n\t\t\t\t</tr>"; } echo "</table><br>"; } else { ?> <br> <i>Please provide your login credentials first.</i><br><br> <b><u>Note:</u></b> if you are reaching this site publicly and are not the publisher, please send the corresponding URL to <a href="http://www.niftyside.com/cms/contact/" target="_blank">NiftySide</a>! <i>Thank you!</i>
} } else { echo doRequest($_GET['site']); } } else { $cache = @file_get_contents('./' . md5($steamapi) . '_requestcache.tmp'); if ($cache) { $data = unserialize($cache); if (time() - strtotime($data['time']) > 15) { // Cache is expired $res = doRequest($steamapi); echo $res ?: $data['data']; } else { echo $data['data']; } } else { echo doRequest($steamapi); } } function doRequest($site) { $fh = @fopen('./' . md5($site) . '_requestcache.tmp', 'w'); if (flock($fh, LOCK_EX)) { $response = file_get_contents($site); $data = array('data' => $response, 'time' => date('c')); fwrite($fh, serialize($data)); flock($fh, LOCK_UN); return $response; } return false; }
/** * baidu地图API的文档地址为: * http://developer.baidu.com/map/geocoding-api.htm * 实例链接: * http://api.map.baidu.com/geocoder?address=地址&output=json&key=1f9eda8f2585572ed2b1d45c37ecfd78&city=城市名 * * 通过地址和城市的名称获取该地址的坐标 * * @param string $address * 必填参数 * @param string $city * 可选参数 * @return array 返回的baidu的api的json格式为 * * { * "status":"OK", * "result":{ * "location":{ * "lng":121.591841, * "lat":29.880224 * }, * "precise":0, * "confidence":80, * "level":"\u8d2d\u7269" * } * } */ function addrToGeo($address, $city = '') { try { $params = array(); $params['address'] = $address; $params['output'] = 'json'; $params['key'] = '6d882b440c48d5e2d6cd11ab88a03eda'; // baidu地图api的密钥 $params['city'] = $city; $response = doRequest('http://api.map.baidu.com/geocoder', $params); $body = $response->getBody(); $rst = json_decode($body, true); return $rst; } catch (Exception $e) { fb(exceptionMsg($e), \FirePHP::LOG); return array(); } }