-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
243 lines (218 loc) · 9.19 KB
/
index.php
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
$book_list = array();
array_push($book_list, '9791185400525'); //독서만담
array_push($book_list, '9788925561158'); //최고의 설득
array_push($book_list, '9788954641548'); //너무 시끄러운 고독
array_push($book_list, '9788932029863'); //타자의 추방
array_push($book_list, '9788925560854'); //이 슬픔이 슬픈 채로 끝나지 않기를
array_push($book_list, '9788958628224'); //시를 잊은 그대에게
array_push($book_list, '9788982813986');
array_push($book_list, '9788970754079');
array_push($book_list, '9788954603904');
array_push($book_list, '9788993964219');
//array_push($book_list, '9791157841509'); //400억
array_push($book_list, '9788970754710'); //왕자의특권
//array_push($book_list, '9788932027173'); //그것이나만은아니기를
//array_push($book_list, '9788954606837'); //흐르는강물처럼
//array_push($book_list, '9788954612999'); //브리다
array_push($book_list, '9788956055466'); //책은도끼다
array_push($book_list, '9788965702047'); //내가미친8주간의기록
//array_push($book_list, '9788954610971'); //어두운상점들의거리
array_push($book_list, '9788932915708'); //한여자
array_push($book_list, '9788932915678'); //남자의자리
array_push($book_list, '9788961570121'); //어머니의죽음
//array_push($book_list, '9788954625173'); //불륜
//array_push($book_list, '9788994120997'); //지적대화를위한넓고얕은지식
//array_push($book_list, '9791195677108'); //시민의교양
//array_push($book_list, '9788954620970'); //아크라문서
//array_push($book_list, '9788954616126'); //알레프
//array_push($book_list, '9791186560204'); //명견만리1
//array_push($book_list, '9791186560167'); //명견만리2
array_push($book_list, '9788954642019'); //스파이
array_push($book_list, '9788937489327'); //무의미의축제
//array_push($book_list, '9788965745280'); //카인
//array_push($book_list, '9788954640190'); //2016젊은작가상수상작품집
array_push($book_list, '9788932916194'); //창문넘어도망친100세노인
//array_push($book_list, '9788954637756'); //개인주의자선언
//array_push($book_list, '9788956056609'); //다시책은도끼다
array_push($book_list, '9788954432160'); //마크툽
//array_push($book_list, '9791156756552'); //죽여마땅한사람들
//array_push($book_list, '9788952235268'); //편의점인간
// print_r($book_list);
$book_shelf = array();
foreach ($book_list as $book) {
$file = './log/'.$book.'.log';
//책 정보가 로그로 저장되어있는지 체크
if (file_exists($file)) {
$response = file_get_contents($file);
}
//책 정보가 없으면 네이버 api를 통해 정보를 가져와서 저장한다.
else {
$client_id = "b4Gwe6rfZFvZRqIhDwx3";
$client_secret = "qKpwtXPDFj";
$isbn = $book;
$url = "https://openapi.naver.com/v1/search/book_adv.json?d_isbn=".$isbn;
$is_post = false;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, $is_post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = "X-Naver-Client-Id: ".$client_id;
$headers[] = "X-Naver-Client-Secret: ".$client_secret;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
if ($status_code == 200) {
file_put_contents($file, $response);
} else {
// echo "Error 내용:".$response;
continue;
}
}
$obj = json_decode($response);
$items = $obj->items;
$image = $items[0]->image;
$arr = array('isbn'=>$book, 'image'=>$image);
array_push($book_shelf, $arr);
}
?>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<!-- 부트스트랩 -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- IE8 에서 HTML5 요소와 미디어 쿼리를 위한 HTML5 shim 와 Respond.js -->
<!-- WARNING: Respond.js 는 당신이 file:// 을 통해 페이지를 볼 때는 동작하지 않습니다. -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
.title {line-height:50px;}
.book {
padding: 10px 0 0 0;
margin: auto;
-webkit-box-shadow: 2px 2px 5px rgba(0,0,0,.6);
box-shadow: 2px 2px 5px rgba(0,0,0,.6);
}
.shelf {
background: url('bookshelf.png');
background-size: 100% 100%;
height: 90px;
top: -15px;
z-index: -1;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<h4 class="col-xs-12 title">책나눔</h4>
<h6 class="col-xs-12">책을 선택하면 상세정보 및 신청화면이 뜹니다 :)</h6>
</div>
<div class="row">
<?php
$hidden_num = 0;
$shelf_num = 0;
foreach ($book_shelf as $book) {
?>
<div class="col-xs-4 col-md-2">
<a href="#;" data-toggle="modal" data-target="#bookModal" data-whatever="<?= $book['isbn'];?>"><img src="<?= $book['image'];?>" class="img-responsive book"></a>
</div>
<?php
$hidden_num ++;
$shelf_num++;
if ($hidden_num == 3) {
echo '<div class="col-xs-12 shelf hidden-md hidden-lg"></div>';
}
if ($shelf_num == 6) {
echo '<div class="col-xs-12 shelf"></div>';
$hidden_num = 0; $shelf_num = 0;
}
}
if ($shelf_num < 6) echo '<div class="col-xs-12 shelf"></div>';
?>
</div>
</div>
<div class="modal fade" id="bookModal" tabindex="-1" role="dialog" aria-labelledby="bookModalIsbn">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel"></h4>
</div>
<div class="modal-body">
<form>
<!-- <div class="form-group">
<label for="recipient-name" class="control-label">제목</label>
<div class="info-title"></div>
</div> -->
<div class="form-group">
<label for="" class="control-label">작가</label>
<div class="info-author"></div>
</div>
<div class="form-group">
<label for="" class="control-label">설명</label>
<div class="info-description"></div>
</div>
<div class="form-group">
<label for="" class="control-label"><a href='' target='_blank' class='info-link'>네이버에서 정보 더 보기</a></label>
</div>
<div class="form-group">
<label for="" class="control-label">이 책을 받아 보고 싶다면...받는이/주소를 입력해주세요.</label>
<textarea class="form-control info-msg" rows="3"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">닫기</button>
<button type="button" class="btn btn-primary">예약</button>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
$('#bookModal').on('show.bs.modal', function (e) {
var button = $(e.relatedTarget)
var isbn = button.data('whatever')
var modal = $(this);
var title = '', author = '', description = '', link = '';
$.getJSON("./log/"+isbn+".log", function(data) {
title = data['items'][0]['title'];
author = data['items'][0]['author'];
description = data['items'][0]['description'];
link = data['items'][0]['link'];
modal.find('.modal-title').text(title);
// modal.find('.modal-body .info-title').html(title);
modal.find('.modal-body .info-author').html(author);
modal.find('.modal-body .info-description').html(description);
modal.find('.modal-body .info-link').attr('href',link);
});
});
$('.btn-primary').on('click', function(e) {
var t = $('.modal-title').html();
var m = $('.info-msg').val();
$.post('book.php', {t:t,m:m}, function(data) {
alert('신청되었습니다');
$('#bookModal').modal('hide')
});
});
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-18031811-9', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>