function plugin_isbn_cache_image_fetch($target, &$info, $check = true, $img_size = "M")
{
    $filename = MOD_PUKI_UPLOAD_DIR . PukiWikiFunc::encode("ISBN" . $target . $img_size . ".jpg");
    if (!is_readable($filename) || is_readable($filename) && $check && MOD_PUKI_ISBN_AMAZON_EXPIRE_IMG * 3600 * 24 < time() - filemtime($filename)) {
        $url = "http://images-jp.amazon.com/images/P/" . strtoupper($target) . ".09." . $img_size . "ZZZZZZZ.jpg";
        if (!PukiWikiFunc::is_url($url)) {
            return false;
        }
        // URL 形式チェック
        $result = PukiWikiFunc::http_request($url);
        if ($result['rc'] !== 200) {
            $data = '';
            $info[0] = 0;
        } else {
            $data = $result['data'];
            plugin_isbn_cache_image_save($data, $filename);
            $info = @getimagesize($filename);
        }
        if ($info[0] <= 1) {
            $url = "http://images-jp.amazon.com/images/P/" . strtoupper($target) . ".01." . $img_size . "ZZZZZZZ.jpg";
            $result = PukiWikiFunc::http_request($url);
            if ($result['rc'] !== 200) {
                $data = '';
                $info[0] = 0;
            } else {
                $data = $result['data'];
                plugin_isbn_cache_image_save($data, $filename);
                $info = @getimagesize($filename);
            }
            if ($info[0] <= 1) {
                $url = $noimage = $img_size == "M" ? MOD_PUKI_NOIMAGE : MOD_PUKI_NOIMAGE_S;
                $result = PukiWikiFunc::http_request($url);
                if ($result['rc'] === 200) {
                    $data = $result['data'];
                    plugin_isbn_cache_image_save($data, $filename);
                    $info = @getimagesize($filename);
                }
            }
        }
    } else {
        $info = @getimagesize($filename);
    }
    return MOD_PUKI_UPLOAD_URL . PukiWikiFunc::encode("ISBN" . $target . $img_size . ".jpg");
}
function plugin_isbn_cache_image_fetch($target, $dir, $check = true, $img_size = "M")
{
    $filename = MOD_PUKI_UPLOAD_DIR . PukiWikiFunc::encode("ISBN" . $target . $img_size . ".jpg");
    if (!is_readable($filename) || is_readable($filename) && $check && MOD_PUKI_ISBN_AMAZON_EXPIRE_IMG * 3600 * 24 < time() - filemtime($filename)) {
        $url = "http://images-jp.amazon.com/images/P/" . strtoupper($target) . ".09." . $img_size . "ZZZZZZZ.jpg";
        if (!PukiWikiFunc::is_url($url)) {
            return false;
        }
        // URL 形式チェック
        $size = @getimagesize($url);
        if ($size[0] <= 1) {
            $url = "http://images-jp.amazon.com/images/P/" . strtoupper($target) . ".01." . $img_size . "ZZZZZZZ.jpg";
            $size = @getimagesize($url);
            if ($size[0] <= 1) {
                $url = $noimage = $img_size == "M" ? MOD_PUKI_NOIMAGE : MOD_PUKI_NOIMAGE_S;
            }
        }
        if ($url != $noimage) {
            $file = fopen($url, "rb");
            // リモートファイルのパケット有効後対策
            // http://search.net-newbie.com/php/function.fread.html
            $contents = "";
            do {
                $data = fread($file, 8192);
                if (strlen($data) == 0) {
                    break;
                }
                $contents .= $data;
            } while (true);
            fclose($file);
            $data = $contents;
            unset($contents);
            $url = $filename;
        } else {
            // キャッシュを NOIMAGE のコピーとする
            $file = fopen($url, "rb");
            if (!$file) {
                return false;
            }
            $data = fread($file, 100000);
            fclose($file);
        }
        plugin_isbn_cache_image_save($data, $target . $img_size, MOD_PUKI_UPLOAD_DIR);
        return MOD_PUKI_UPLOAD_URL . PukiWikiFunc::encode("ISBN" . $target . $img_size . ".jpg");
    } else {
        return MOD_PUKI_UPLOAD_URL . PukiWikiFunc::encode("ISBN" . $target . $img_size . ".jpg");
    }
}