Пример #1
0
function storeInCache($datasetName, $data)
{
    if (isset($_SESSION['do-not-cache'])) {
        if ($_SESSION['do-not-cache'] == 1) {
            unset($_SESSION['do-not-cache']);
        } else {
            $_SESSION['do-not-cache'] -= 1;
        }
        return false;
    }
    $sql = getSql();
    $now = date("Y-m-d H:i:s");
    if ($sql != null) {
        $dsn = $sql->real_escape_string($datasetName);
        $data = $sql->real_escape_string($data);
        if (cacheExists($datasetName)) {
            //Update
            if ($sql->query("UPDATE datacache SET data = '{$data}', updated = '{$now}'  WHERE dataset = '{$dsn}'") == TRUE) {
                return true;
            }
        } else {
            //Insert
            if ($sql->query("INSERT into datacache (dataset, data, updated) values ('{$dsn}', '{$data}', '{$now}')") == TRUE) {
                return true;
            }
        }
    }
    return false;
}
Пример #2
0
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}
function parseData($result)
{
    $json = array();
    foreach ($result->data as $post) {
        $d = array('id' => $post->id, 'tags' => $post->tags, 'images' => $post->images, 'type' => $post->type, 'location' => $post->location->name, 'link' => $post->link, 'timestamp' => $post->created_time);
        array_push($json, $d);
    }
    return $json;
}
$filename = "./data/" . date("mdY") . "_insta.json";
function cacheExists()
{
    $filename = "./data/" . date("mdY") . "_instacache.json";
    return file_exists($filename);
}
if (cacheExists()) {
    $json = file_get_contents($filename);
} else {
    $result = fetchData("https://api.instagram.com/v1/users/233559774/media/recent/?access_token=1471.2529a78.f57268a06ada4272a64c98c3a70803da");
    $result = json_decode($result);
    $json = parseData($result);
    file_put_contents($filename, json_encode($json));
}
header('Content-Type: application/json');
echo json_encode($json);
 private function getRequestCache($request, $login, $optionsArray)
 {
     $r = makeRequestPath($request, $login, $optionsArray);
     if (cacheExists($r)) {
         return unserialize(getCache($r));
     } else {
         return null;
     }
 }
{
    global $outfit_colors;
    if ($color < count($outfit_colors)) {
        $value = $outfit_colors[$color];
    } else {
        $value = 0;
    }
    $ro = ($value & 0xff0000) >> 16;
    $go = ($value & 0xff00) >> 8;
    $bo = $value & 0xff;
    $r = (int) ($r * ($ro / 255));
    $g = (int) ($g * ($go / 255));
    $b = (int) ($b * ($bo / 255));
}
if (in_array($outfit_id, $colorableOutfits)) {
    if (!cacheExists($outfit_id, $addons, $head, $body, $legs, $feet)) {
        // check if outfit with that ID exists
        if (file_exists('outfit_colors/' . $outfit_id . '_' . $addons . '.png')) {
            // let's paint that outfit!
            $image_color = imagecreatefrompng('outfit_colors/' . $outfit_id . '_' . $addons . '.png');
            $image_outfit = imagecreatefrompng('outfit_images/' . $outfit_id . '_' . $addons . '.png');
            imagealphablending($image_outfit, false);
            imagesavealpha($image_outfit, true);
            for ($i = 0; $i < imagesy($image_color); $i++) {
                for ($j = 0; $j < imagesx($image_color); $j++) {
                    $templatepixel = imagecolorat($image_color, $j, $i);
                    $outfit = imagecolorat($image_outfit, $j, $i);
                    if ($templatepixel == $outfit) {
                        continue;
                    }
                    $rt = $templatepixel >> 16 & 0xff;