#overlay <?php require __DIR__ . '/facebook_start.php'; $token = $_SESSION['facebook_access_token']; //$r = new HttpRequest('https://graph.facebook.com/me?access_token='.$r, HttpRequest::METH_POST); $output = curly($token); echo $output; $r = json_decode($output, true); $id = $r['id']; $path = "cache/" . $id . ".jpg"; $_SESSION['path'] = $path; // only create if not already exists in cache if (!file_exists($path)) { create($id, $path); } else { echo " \n already exitst : " . $path; } //override line 13. Always create for testing purposes //create($id, $path); //output as jpeg //header('Content-Type: image/jpg'); //readfile($path); //upload($path,$token,$fb); // HttpRequest for user profile image function curly($token) { // create curl resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/me?access_token=" . $token); //return the transfer as a string
$lastValidDataTimestamp = $now - 60; //1 minute $rows = $dbh->query("SELECT *\n\t\tFROM api_cache_data\n\t\tWHERE url = '{$url}'\n\t\tAND timestamp > {$lastValidDataTimestamp}\n\t"); $cache_data = current($rows->fetchAll(PDO::FETCH_ASSOC)); if (!empty($cache_data)) { $output = $cache_data['data']; } else { if (!function_exists('curl_init')) { die('Sorry cURL is not installed!'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, "SpawnKill"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $output = curl_exec($ch); curl_close($ch); $dbh->query("INSERT INTO api_cache_data(url, data, timestamp)\n\t \tVALUES(" . $dbh->quote($url) . ", " . $dbh->quote($output) . ", {$now})\n\t \tON DUPLICATE KEY UPDATE\n\t \t data = " . $dbh->quote($output) . ",\n\t \t timestamp = {$now}\n\t "); } return $output; } $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'); $dbh = new PDO("mysql:host=" . HOST . ";dbname=" . DATABASE . ";", LOGIN, PASS, $options); switch ($action) { //récupère les releases de SpawnKill case "releases": $releases_url = 'https://api.github.com/repos/dorian-marchal/spawnkill/releases?client_id=' . GITHUB_CLIENT_ID . '&client_secret=' . GITHUB_CLIENT_SECRET; echo curly($releases_url); break; }
function larry() { curly(); }
}); test('partial()', function () { $res = curly('GET', URL . '/partial/dispatch'); assert(preg_match('/dispatch is awesome/', $res)); }); test('render()', function () { $res = curly('GET', URL . '/template/dispatch'); assert(preg_match('/<!doctype html>/i', $res)); assert(preg_match('/dispatch is awesome/', $res)); }); test('inline()', function () { $res = curly('GET', URL . '/inline'); assert(preg_match('/inline content/i', $res)); }); test('inline() with locals', function () { $res = curly('GET', URL . '/inline/locals'); assert(preg_match('/name=dispatch/i', $res)); }); test('inline() with callback', function () { $res = curly('GET', URL . '/inline/callback'); assert(preg_match('/name=dispatch/i', $res)); }); test('prefix()', function () { $res1 = curly('GET', URL . '/books/list'); $res2 = curly('GET', URL . '/books/chapters/list'); $res3 = curly('GET', URL . '/list'); assert(preg_match('/book list/', $res1)); assert(preg_match('/chapter list/', $res2)); assert(preg_match('/different list/', $res3)); }); test_summary();