回答編集履歴
6
修正
answer
CHANGED
@@ -5,10 +5,81 @@
|
|
5
5
|
|
6
6
|
上記のページを参照するだけで以下の機能は実装可能。
|
7
7
|
|
8
|
+
設置さえすれば動く。以上。
|
9
|
+
|
8
10
|
```php
|
9
11
|
<?php
|
10
12
|
|
11
13
|
/**
|
14
|
+
* global_functions.php
|
15
|
+
*
|
16
|
+
* @since 2016/08/01
|
17
|
+
*/
|
18
|
+
|
19
|
+
/**
|
20
|
+
* エスケープ
|
21
|
+
* @param string $string
|
22
|
+
* @return string
|
23
|
+
*/
|
24
|
+
function h($string)
|
25
|
+
{
|
26
|
+
return htmlspecialchars($string, ENT_QUOTES, 'utf-8');
|
27
|
+
}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* ページネーション
|
31
|
+
* @param int $page
|
32
|
+
* @param int $total
|
33
|
+
* @return string
|
34
|
+
*/
|
35
|
+
function pagination($page, $total)
|
36
|
+
{
|
37
|
+
$delta = 3;
|
38
|
+
if ($total < 1) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
$query = (is_array(filter_input_array(INPUT_GET))) ?
|
42
|
+
filter_input_array(INPUT_GET) : [];
|
43
|
+
if (isset($query['offset_page'])) {
|
44
|
+
unset($query['offset_page']);
|
45
|
+
}
|
46
|
+
$querystring = http_build_query($query);
|
47
|
+
$limit = 10;
|
48
|
+
$placeholder = "<span%s><a href=\"?offset_page=%d&%s\">%s</a></span> ";
|
49
|
+
|
50
|
+
// 最大ページ数
|
51
|
+
$maxPage = ceil($total / $limit);
|
52
|
+
|
53
|
+
$min = max([$page - $delta, 1]);
|
54
|
+
$max = min([$page + $delta, $maxPage]);
|
55
|
+
|
56
|
+
$html = '';
|
57
|
+
if ($page > 1) {
|
58
|
+
$html .= sprintf($placeholder, '', 1, $querystring, '«');
|
59
|
+
$html .= sprintf($placeholder, '', $page, $querystring, '前へ');
|
60
|
+
}
|
61
|
+
for ($i = $max - 6; $i < $min + 7; $i++) {
|
62
|
+
if ($i > -1 && $i < $maxPage) {
|
63
|
+
$html .= sprintf($placeholder
|
64
|
+
, ($i == $page) ? ' class="active"' : ''
|
65
|
+
, $i + 1
|
66
|
+
, $querystring
|
67
|
+
, $i + 1
|
68
|
+
);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
if ($page < $maxPage) {
|
72
|
+
$html .= sprintf($placeholder, '', $page + 1, $querystring, '次へ');
|
73
|
+
$html .= sprintf($placeholder, '', $maxPage, $querystring, '»');
|
74
|
+
}
|
75
|
+
return $html;
|
76
|
+
}
|
77
|
+
```
|
78
|
+
|
79
|
+
```php
|
80
|
+
<?php
|
81
|
+
|
82
|
+
/**
|
12
83
|
* Gnavi.class.php
|
13
84
|
*
|
14
85
|
* @since 2016/08/01
|
@@ -66,76 +137,19 @@
|
|
66
137
|
}
|
67
138
|
```
|
68
139
|
|
69
|
-
```
|
140
|
+
```php
|
70
141
|
<?php
|
71
142
|
/**
|
72
143
|
* index.php
|
73
144
|
*
|
74
145
|
* @since 2016/08/01
|
75
146
|
*/
|
147
|
+
require_once './global_functions.php';
|
76
|
-
require_once 'Gnavi.class.php';
|
148
|
+
require_once './Gnavi.class.php';
|
77
149
|
|
78
|
-
/**
|
79
|
-
* エスケープ
|
80
|
-
* @param string $string
|
81
|
-
* @return string
|
82
|
-
*/
|
83
|
-
function h($string)
|
84
|
-
{
|
85
|
-
return htmlspecialchars($string, ENT_QUOTES, 'utf-8');
|
86
|
-
}
|
87
|
-
|
88
|
-
/**
|
89
|
-
* ページネーション
|
90
|
-
* @param int $page
|
91
|
-
* @param int $total
|
92
|
-
* @return string
|
93
|
-
*/
|
94
|
-
function pagination($page, $total)
|
95
|
-
{
|
96
|
-
$delta = 3;
|
97
|
-
if ($total < 1) {
|
98
|
-
return;
|
99
|
-
}
|
100
|
-
$query = (is_array(filter_input_array(INPUT_GET))) ?
|
101
|
-
filter_input_array(INPUT_GET) : [];
|
102
|
-
if (isset($query['offset_page'])) {
|
103
|
-
unset($query['offset_page']);
|
104
|
-
}
|
105
|
-
$querystring = http_build_query($query);
|
106
|
-
$limit = 10;
|
107
|
-
$placeholder = "<span%s><a href=\"?offset_page=%d&%s\">%s</a></span> ";
|
108
|
-
|
109
|
-
// 最大ページ数
|
110
|
-
$maxPage = ceil($total / $limit);
|
111
|
-
|
112
|
-
$min = max([$page - $delta, 1]);
|
113
|
-
$max = min([$page + $delta, $maxPage]);
|
114
|
-
|
115
|
-
$html = '';
|
116
|
-
if ($page > 1) {
|
117
|
-
$html .= sprintf($placeholder, '', 1, $querystring, '«');
|
118
|
-
$html .= sprintf($placeholder, '', $page, $querystring, '前へ');
|
119
|
-
}
|
120
|
-
for ($i = $max - 6; $i < $min + 7; $i++) {
|
121
|
-
if ($i > -1 && $i < $maxPage) {
|
122
|
-
$html .= sprintf($placeholder
|
123
|
-
, ($i == $page) ? ' class="active"' : ''
|
124
|
-
, $i + 1
|
125
|
-
, $querystring
|
126
|
-
, $i + 1
|
127
|
-
);
|
128
|
-
}
|
129
|
-
}
|
130
|
-
if ($page < $maxPage) {
|
131
|
-
$html .= sprintf($placeholder, '', $page + 1, $querystring, '次へ');
|
132
|
-
$html .= sprintf($placeholder, '', $maxPage, $querystring, '»');
|
133
|
-
}
|
134
|
-
return $html;
|
135
|
-
}
|
136
|
-
|
137
150
|
// 都道府県取得
|
138
151
|
$prefs = Gnavi::getPref();
|
152
|
+
|
139
153
|
// レストラン検索
|
140
154
|
$restaurants = Gnavi::getRestaurants();
|
141
155
|
?>
|
@@ -152,13 +166,17 @@
|
|
152
166
|
<select name="pref" id="pref">
|
153
167
|
<option value="">都道府県</option>
|
154
168
|
<?php foreach ($prefs->pref as $pref) : ?>
|
169
|
+
<?php if ($pref->pref_code == filter_input(INPUT_GET, 'pref')): ?>
|
170
|
+
<option value="<?= h($pref->pref_code); ?>" selected="selected"><?= h($pref->pref_name); ?></option>
|
171
|
+
<?php else: ?>
|
155
|
-
|
172
|
+
<option value="<?= h($pref->pref_code); ?>"><?= h($pref->pref_name); ?></option>
|
173
|
+
<?php endif; ?>
|
156
174
|
<?php endforeach; ?>
|
157
175
|
</select>
|
158
176
|
</p>
|
159
177
|
<p>
|
160
178
|
<label for="freeword">フリーワード</label>
|
161
|
-
<input type="text" name="freeword" id="freeword" />
|
179
|
+
<input type="text" name="freeword" id="freeword" value="<?= h(filter_input(INPUT_GET, 'freeword')); ?>" />
|
162
180
|
</p>
|
163
181
|
<p>
|
164
182
|
<button type="submit">検索</button>
|
@@ -196,4 +214,5 @@
|
|
196
214
|
</div>
|
197
215
|
</body>
|
198
216
|
</html>
|
217
|
+
|
199
218
|
```
|
5
修正
answer
CHANGED
@@ -152,7 +152,7 @@
|
|
152
152
|
<select name="pref" id="pref">
|
153
153
|
<option value="">都道府県</option>
|
154
154
|
<?php foreach ($prefs->pref as $pref) : ?>
|
155
|
-
<option value="<?= $pref->pref_code; ?>"><?= $pref->pref_name; ?></option>
|
155
|
+
<option value="<?= h($pref->pref_code); ?>"><?= h($pref->pref_name); ?></option>
|
156
156
|
<?php endforeach; ?>
|
157
157
|
</select>
|
158
158
|
</p>
|
4
修正
answer
CHANGED
@@ -66,7 +66,7 @@
|
|
66
66
|
}
|
67
67
|
```
|
68
68
|
|
69
|
-
```
|
69
|
+
```html
|
70
70
|
<?php
|
71
71
|
/**
|
72
72
|
* index.php
|
@@ -77,8 +77,8 @@
|
|
77
77
|
|
78
78
|
/**
|
79
79
|
* エスケープ
|
80
|
-
* @param
|
80
|
+
* @param string $string
|
81
|
-
* @return
|
81
|
+
* @return string
|
82
82
|
*/
|
83
83
|
function h($string)
|
84
84
|
{
|
@@ -87,9 +87,9 @@
|
|
87
87
|
|
88
88
|
/**
|
89
89
|
* ページネーション
|
90
|
-
* @param
|
90
|
+
* @param int $page
|
91
|
-
* @param
|
91
|
+
* @param int $total
|
92
|
-
* @return
|
92
|
+
* @return string
|
93
93
|
*/
|
94
94
|
function pagination($page, $total)
|
95
95
|
{
|
@@ -143,7 +143,7 @@
|
|
143
143
|
<html lang="ja">
|
144
144
|
<head>
|
145
145
|
<meta charset="UTF-8">
|
146
|
-
<title>ぐるなびAPIテスト</title>
|
146
|
+
<title>ぐるなびAPIテスト(アホでも設置するだけで動く)</title>
|
147
147
|
</head>
|
148
148
|
<body>
|
149
149
|
<form action="" method="get">
|
3
修正
answer
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[http://api.gnavi.co.jp/api/manual/prefmaster/](http://api.gnavi.co.jp/api/manual/prefmaster/)
|
4
4
|
[http://api.gnavi.co.jp/api/manual/restsearch/](http://api.gnavi.co.jp/api/manual/restsearch/)
|
5
5
|
|
6
|
-
上記の
|
6
|
+
上記のページを参照するだけで以下の機能は実装可能。
|
7
7
|
|
8
8
|
```php
|
9
9
|
<?php
|
2
追記
answer
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
以下のソースを書くために参照したページ
|
2
2
|
[http://api.gnavi.co.jp/api/manual/](http://api.gnavi.co.jp/api/manual/)
|
3
3
|
[http://api.gnavi.co.jp/api/manual/prefmaster/](http://api.gnavi.co.jp/api/manual/prefmaster/)
|
4
|
+
[http://api.gnavi.co.jp/api/manual/restsearch/](http://api.gnavi.co.jp/api/manual/restsearch/)
|
4
5
|
|
5
6
|
上記の2ページを参照するだけで以下の機能は実装可能。
|
6
7
|
|
1
追記
answer
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
以下のソースを書くために参照したページ
|
2
|
+
[http://api.gnavi.co.jp/api/manual/](http://api.gnavi.co.jp/api/manual/)
|
3
|
+
[http://api.gnavi.co.jp/api/manual/prefmaster/](http://api.gnavi.co.jp/api/manual/prefmaster/)
|
4
|
+
|
5
|
+
上記の2ページを参照するだけで以下の機能は実装可能。
|
6
|
+
|
1
7
|
```php
|
2
8
|
<?php
|
3
9
|
|