-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetvalue.php
More file actions
52 lines (40 loc) · 1.75 KB
/
getvalue.php
File metadata and controls
52 lines (40 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
//checks ifthe tag post is there and if its been a proper form post
// tagで検索
if(isset($_REQUEST['tag'])){
$isbn = $_REQUEST['tag'];
if (validateISBN($isbn)) ItemSearch("Books", $isbn);
}
function validateISBN($isbn) {
$isbn = str_replace('-', '', $isbn); // ハイフンを削除
if (!preg_match('/^\d{13}$/', $isbn)) { // 13桁の数字でない場合
return false;
}
$sum = 0;
for ($i = 0; $i < 12; $i++) {
$sum += intval($isbn[$i]) * (($i % 2 === 0) ? 1 : 3);
}
$check_digit = (10 - ($sum % 10)) % 10;
return intval($isbn[12]) === $check_digit;
}
//Set up the operation in the request
function ItemSearch($SearchIndex, $Keywords){
$tagName = intval($Keywords);
// openBD APIの仕様に沿ったリクエスト出力用のPHPスクリプト
$base_request = "https://api.openbd.jp/v1/get?isbn=$tagName";
$items = json_decode(file_get_contents($base_request), false);
foreach($items as $item){
$tagValue['isbn'] = $item->summary->isbn;
$tagValue['pubdate'] = $item->summary->pubdate;
$tagValue['title'] = $item->summary->title;
$tagValue['author'] = $item->summary->author;
$tagValue['cover'] = $item->summary->cover;
}
echo json_encode(array("VALUE", $tagName, $tagValue));
$fh = fopen("_data/" . $item->summary->isbn . ".txt", "w") or die("check file write permission.");
fwrite($fh, json_encode($tagValue));
fclose($fh);
$log_message = sprintf("%s:%s\n", date('Y-m-d H:i:s'), "openDB API: ($apiKey) $tagName:$tagValue -- $base_request");
$file_name = '_log/openBD_' . date('Y-m-d') . '.log';
error_log($log_message, 3, $file_name);
}