回答編集履歴

6

修正

2016/08/01 07:32

投稿

退会済みユーザー
test CHANGED
@@ -12,6 +12,10 @@
12
12
 
13
13
 
14
14
 
15
+ 設置さえすれば動く。以上。
16
+
17
+
18
+
15
19
  ```php
16
20
 
17
21
  <?php
@@ -20,6 +24,144 @@
20
24
 
21
25
  /**
22
26
 
27
+ * global_functions.php
28
+
29
+ *
30
+
31
+ * @since 2016/08/01
32
+
33
+ */
34
+
35
+
36
+
37
+ /**
38
+
39
+ * エスケープ
40
+
41
+ * @param string $string
42
+
43
+ * @return string
44
+
45
+ */
46
+
47
+ function h($string)
48
+
49
+ {
50
+
51
+ return htmlspecialchars($string, ENT_QUOTES, 'utf-8');
52
+
53
+ }
54
+
55
+
56
+
57
+ /**
58
+
59
+ * ページネーション
60
+
61
+ * @param int $page
62
+
63
+ * @param int $total
64
+
65
+ * @return string
66
+
67
+ */
68
+
69
+ function pagination($page, $total)
70
+
71
+ {
72
+
73
+ $delta = 3;
74
+
75
+ if ($total < 1) {
76
+
77
+ return;
78
+
79
+ }
80
+
81
+ $query = (is_array(filter_input_array(INPUT_GET))) ?
82
+
83
+ filter_input_array(INPUT_GET) : [];
84
+
85
+ if (isset($query['offset_page'])) {
86
+
87
+ unset($query['offset_page']);
88
+
89
+ }
90
+
91
+ $querystring = http_build_query($query);
92
+
93
+ $limit = 10;
94
+
95
+ $placeholder = "<span%s><a href=\"?offset_page=%d&%s\">%s</a></span> ";
96
+
97
+
98
+
99
+ // 最大ページ数
100
+
101
+ $maxPage = ceil($total / $limit);
102
+
103
+
104
+
105
+ $min = max([$page - $delta, 1]);
106
+
107
+ $max = min([$page + $delta, $maxPage]);
108
+
109
+
110
+
111
+ $html = '';
112
+
113
+ if ($page > 1) {
114
+
115
+ $html .= sprintf($placeholder, '', 1, $querystring, '&laquo;');
116
+
117
+ $html .= sprintf($placeholder, '', $page, $querystring, '前へ');
118
+
119
+ }
120
+
121
+ for ($i = $max - 6; $i < $min + 7; $i++) {
122
+
123
+ if ($i > -1 && $i < $maxPage) {
124
+
125
+ $html .= sprintf($placeholder
126
+
127
+ , ($i == $page) ? ' class="active"' : ''
128
+
129
+ , $i + 1
130
+
131
+ , $querystring
132
+
133
+ , $i + 1
134
+
135
+ );
136
+
137
+ }
138
+
139
+ }
140
+
141
+ if ($page < $maxPage) {
142
+
143
+ $html .= sprintf($placeholder, '', $page + 1, $querystring, '次へ');
144
+
145
+ $html .= sprintf($placeholder, '', $maxPage, $querystring, '&raquo;');
146
+
147
+ }
148
+
149
+ return $html;
150
+
151
+ }
152
+
153
+ ```
154
+
155
+
156
+
157
+ ```php
158
+
159
+ <?php
160
+
161
+
162
+
163
+ /**
164
+
23
165
  * Gnavi.class.php
24
166
 
25
167
  *
@@ -134,7 +276,7 @@
134
276
 
135
277
 
136
278
 
137
- ```html
279
+ ```php
138
280
 
139
281
  <?php
140
282
 
@@ -148,125 +290,9 @@
148
290
 
149
291
  */
150
292
 
293
+ require_once './global_functions.php';
294
+
151
- require_once 'Gnavi.class.php';
295
+ require_once './Gnavi.class.php';
152
-
153
-
154
-
155
- /**
156
-
157
- * エスケープ
158
-
159
- * @param string $string
160
-
161
- * @return string
162
-
163
- */
164
-
165
- function h($string)
166
-
167
- {
168
-
169
- return htmlspecialchars($string, ENT_QUOTES, 'utf-8');
170
-
171
- }
172
-
173
-
174
-
175
- /**
176
-
177
- * ページネーション
178
-
179
- * @param int $page
180
-
181
- * @param int $total
182
-
183
- * @return string
184
-
185
- */
186
-
187
- function pagination($page, $total)
188
-
189
- {
190
-
191
- $delta = 3;
192
-
193
- if ($total < 1) {
194
-
195
- return;
196
-
197
- }
198
-
199
- $query = (is_array(filter_input_array(INPUT_GET))) ?
200
-
201
- filter_input_array(INPUT_GET) : [];
202
-
203
- if (isset($query['offset_page'])) {
204
-
205
- unset($query['offset_page']);
206
-
207
- }
208
-
209
- $querystring = http_build_query($query);
210
-
211
- $limit = 10;
212
-
213
- $placeholder = "<span%s><a href=\"?offset_page=%d&%s\">%s</a></span> ";
214
-
215
-
216
-
217
- // 最大ページ数
218
-
219
- $maxPage = ceil($total / $limit);
220
-
221
-
222
-
223
- $min = max([$page - $delta, 1]);
224
-
225
- $max = min([$page + $delta, $maxPage]);
226
-
227
-
228
-
229
- $html = '';
230
-
231
- if ($page > 1) {
232
-
233
- $html .= sprintf($placeholder, '', 1, $querystring, '&laquo;');
234
-
235
- $html .= sprintf($placeholder, '', $page, $querystring, '前へ');
236
-
237
- }
238
-
239
- for ($i = $max - 6; $i < $min + 7; $i++) {
240
-
241
- if ($i > -1 && $i < $maxPage) {
242
-
243
- $html .= sprintf($placeholder
244
-
245
- , ($i == $page) ? ' class="active"' : ''
246
-
247
- , $i + 1
248
-
249
- , $querystring
250
-
251
- , $i + 1
252
-
253
- );
254
-
255
- }
256
-
257
- }
258
-
259
- if ($page < $maxPage) {
260
-
261
- $html .= sprintf($placeholder, '', $page + 1, $querystring, '次へ');
262
-
263
- $html .= sprintf($placeholder, '', $maxPage, $querystring, '&raquo;');
264
-
265
- }
266
-
267
- return $html;
268
-
269
- }
270
296
 
271
297
 
272
298
 
@@ -274,6 +300,8 @@
274
300
 
275
301
  $prefs = Gnavi::getPref();
276
302
 
303
+
304
+
277
305
  // レストラン検索
278
306
 
279
307
  $restaurants = Gnavi::getRestaurants();
@@ -306,7 +334,15 @@
306
334
 
307
335
  <?php foreach ($prefs->pref as $pref) : ?>
308
336
 
337
+ <?php if ($pref->pref_code == filter_input(INPUT_GET, 'pref')): ?>
338
+
339
+ <option value="<?= h($pref->pref_code); ?>" selected="selected"><?= h($pref->pref_name); ?></option>
340
+
341
+ <?php else: ?>
342
+
309
- <option value="<?= h($pref->pref_code); ?>"><?= h($pref->pref_name); ?></option>
343
+ <option value="<?= h($pref->pref_code); ?>"><?= h($pref->pref_name); ?></option>
344
+
345
+ <?php endif; ?>
310
346
 
311
347
  <?php endforeach; ?>
312
348
 
@@ -318,7 +354,7 @@
318
354
 
319
355
  <label for="freeword">フリーワード</label>
320
356
 
321
- <input type="text" name="freeword" id="freeword" />
357
+ <input type="text" name="freeword" id="freeword" value="<?= h(filter_input(INPUT_GET, 'freeword')); ?>" />
322
358
 
323
359
  </p>
324
360
 
@@ -394,4 +430,6 @@
394
430
 
395
431
  </html>
396
432
 
433
+
434
+
397
435
  ```

5

修正

2016/08/01 07:32

投稿

退会済みユーザー
test CHANGED
@@ -306,7 +306,7 @@
306
306
 
307
307
  <?php foreach ($prefs->pref as $pref) : ?>
308
308
 
309
- <option value="<?= $pref->pref_code; ?>"><?= $pref->pref_name; ?></option>
309
+ <option value="<?= h($pref->pref_code); ?>"><?= h($pref->pref_name); ?></option>
310
310
 
311
311
  <?php endforeach; ?>
312
312
 

4

修正

2016/08/01 01:21

投稿

退会済みユーザー
test CHANGED
@@ -134,7 +134,7 @@
134
134
 
135
135
 
136
136
 
137
- ```php
137
+ ```html
138
138
 
139
139
  <?php
140
140
 
@@ -156,9 +156,9 @@
156
156
 
157
157
  * エスケープ
158
158
 
159
- * @param type $string
159
+ * @param string $string
160
-
160
+
161
- * @return type
161
+ * @return string
162
162
 
163
163
  */
164
164
 
@@ -176,11 +176,11 @@
176
176
 
177
177
  * ページネーション
178
178
 
179
- * @param type $page
179
+ * @param int $page
180
-
180
+
181
- * @param type $total
181
+ * @param int $total
182
-
182
+
183
- * @return type
183
+ * @return string
184
184
 
185
185
  */
186
186
 
@@ -288,7 +288,7 @@
288
288
 
289
289
  <meta charset="UTF-8">
290
290
 
291
- <title>ぐるなびAPIテスト</title>
291
+ <title>ぐるなびAPIテスト(アホでも設置するだけで動く)</title>
292
292
 
293
293
  </head>
294
294
 

3

修正

2016/08/01 01:02

投稿

退会済みユーザー
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
 
10
10
 
11
- 上記の2ページを参照するだけで以下の機能は実装可能。
11
+ 上記のページを参照するだけで以下の機能は実装可能。
12
12
 
13
13
 
14
14
 

2

追記

2016/07/31 16:24

投稿

退会済みユーザー
test CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  [http://api.gnavi.co.jp/api/manual/prefmaster/](http://api.gnavi.co.jp/api/manual/prefmaster/)
6
6
 
7
+ [http://api.gnavi.co.jp/api/manual/restsearch/](http://api.gnavi.co.jp/api/manual/restsearch/)
8
+
7
9
 
8
10
 
9
11
  上記の2ページを参照するだけで以下の機能は実装可能。

1

追記

2016/07/31 16:24

投稿

退会済みユーザー
test CHANGED
@@ -1,3 +1,15 @@
1
+ 以下のソースを書くために参照したページ
2
+
3
+ [http://api.gnavi.co.jp/api/manual/](http://api.gnavi.co.jp/api/manual/)
4
+
5
+ [http://api.gnavi.co.jp/api/manual/prefmaster/](http://api.gnavi.co.jp/api/manual/prefmaster/)
6
+
7
+
8
+
9
+ 上記の2ページを参照するだけで以下の機能は実装可能。
10
+
11
+
12
+
1
13
  ```php
2
14
 
3
15
  <?php