Exemplo n.º 1
0
$params = $_GET;
$params["access_token"] = $config["token"];
//for private access token. if public, comment this line so access token from js will be used
//doing some magic here. read about Jquery.Ajax callback here http://stackoverflow.com/questions/12864096/
//web app client sends unique callback string for each call. it's not good for our json caching (because it's based on md5 of url)
//solution: save original callback string, replace with unique string in url, replace saved one with original in response.
if (isset($params["callback"])) {
    $originalJsonCallback = $params["callback"];
    $params["callback"] = "63kfn61Ikx90Nw";
    //just a unique random string
}
$fullUrl = $apiUrl . http_build_query($params);
if ($config["isNoCache"]) {
    removeCacheForUrl($fullUrl);
}
$result = file_get_contents_with_cache($fullUrl, true);
if (isset($originalJsonCallback)) {
    $resultJson = json_decode(preg_replace('/.+?({.+}).+/', "\$1", $result), true);
} else {
    $resultJson = json_decode($result, true);
}
//if response has errors or has no response
if (!empty($resultJson["error"]) || empty($resultJson["response"])) {
    removeCacheForUrl($fullUrl);
} else {
    logSuccessQuery($_GET["q"]);
}
if (isset($originalJsonCallback)) {
    //replacing callback string back
    $result = str_replace($params["callback"], $originalJsonCallback, $result);
}
Exemplo n.º 2
0
    }
    $audioId .= decode($ownerId) . "_" . decode($aid);
}
if (strlen($audioId) <= 1) {
    notFound();
}
$audioGetUrl = "https://api.vk.com/method/audio.getById?audios={$audioId}&access_token={$config['token']}";
$captcha_sid = $_REQUEST["sid"];
$captcha_key = $_REQUEST["key"];
if (isset($captcha_sid) && isset($captcha_key)) {
    $audioGetUrl .= "&captcha_sid={$captcha_sid}&captcha_key={$captcha_key}";
}
if ($config["isNoCache"]) {
    removeCacheForUrl($audioGetUrl);
}
$response = file_get_contents_with_cache($audioGetUrl);
//print response and die if debugging
if ($config["isDebug"]) {
    die($response);
}
$json = json_decode($response, true);
if (empty($json['response'])) {
    //clear cache if no result in json
    removeCacheForUrl($audioGetUrl);
    $error = $json['error'];
    //notEmpty & isCaptcha
    if (!empty($error) && intval($error["error_code"]) == 14) {
        header('HTTP/1.0 404 Not Found');
        ?>
       <meta charset="utf-8">
       <meta name="theme-color" content="#C0392B">