-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
580 lines (570 loc) · 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
<?php
$domain = 'ly.govapi.tw';
if (file_exists(__DIR__ . '/config.php')) {
include(__DIR__ . '/config.php');
if (getenv('API_URL')) {
$domain = getenv('API_URL');
}
}
$doc_id = $_GET['doc_id'] ?? '1133001_00006';
$url = sprintf("https://%s/gazette_agenda/%s/html?parse=1", $domain, $doc_id);
$data = file_get_contents($url);
$agenda_obj = json_decode($data);
if (!$agenda_obj->blocks ?? false) {
echo "No data found";
printf("<a href=\"%s\">API</a>", htmlspecialchars($url));
exit;
}
$legislators = [];
$voters = [];
if (preg_match('#第(\d+)屆#', $agenda_obj->title, $matches)) {
$url = sprintf("https://%s/legislator?term=%d&limit=200", $domain, $matches[1]);
$legislator_obj = json_decode(file_get_contents($url));
foreach ($legislator_obj->legislators as $legislator) {
if ($legislator->leaveDate and strtotime($legislator->leaveDate) < strtotime($agenda_obj->date)) {
continue;
}
$voter = new StdClass;
$voter->name = $legislator->name;
$voter->party = $legislator->party;
$voter->caucus = $legislator->partyGroup;
$voter->photo = $legislator->picUrl;
$voters[] = $voter;
$legislators[$legislator->name] = $legislator;
}
}
$messages = [];
$showed_speakers = [];
$sections = [];
$votes = [];
foreach ($agenda_obj->votes as $vote) {
$votes[$vote->line_no] = $vote;
}
foreach ($agenda_obj->blocks as $idx => $blocks) {
$text = $blocks[0];
$lineno = $agenda_obj->block_lines[$idx];
if (strpos($text, ':') === false) {
$messages[] = [
'type' => 'info',
'content' => implode("\n", $blocks),
'class' => '',
'photo' => '',
'lineno' => $lineno,
];
continue;
}
$default_photo = 'https://bootdey.com/img/Content/avatar/avatar6.png';
$content = implode("\n", $blocks);
list($speaker, $content) = explode(':', $content, 2);
if ($speaker == '主席' or strpos($speaker, '委員') !== false) {
$class = "ks-self";
if ($speaker == '主席') {
$name = $agenda_obj->{'主席'};
} else {
$name = $speaker;
}
$name = str_replace('委員', '', $name);
$name = str_replace('院長', '', $name);
if (isset($legislators[$name])) {
$photo = $legislators[$name]->picUrl;
$bioId = $legislators[$name]->bioId;
if (!array_key_exists($name, $showed_speakers)) {
$showed_speakers[$name] = count($showed_speakers);
}
} else {
$photo = $default_photo;
$bioId = '';
}
} elseif ($speaker == '表決結果名單') {
if (isset($votes[$lineno])) {
$vote = $votes[$lineno];
$sections[] = [
'title' => '表決結果名單:' . $vote->{'表決議題'},
'description' => sprintf("出席人數:%d 贊成人數:%d 反對人數:%d",
$vote->{'表決結果'}->{'出席人數'},
$vote->{'表決結果'}->{'贊成人數'},
$vote->{'表決結果'}->{'反對人數'}),
'lineno' => $lineno,
];
$messages[] = [
'type' => 'vote',
'content' => $vote,
'lineno' => $lineno,
];
continue;
}
} elseif ($speaker == '段落') {
if (strpos($content, '議事錄:') === 0) {
$sections[] = [
'title' => explode("\n", $content)[0],
'description' => '',
'lineno' => $lineno,
];
$messages[] = [
'type' => 'info',
'content' => $content,
'class' => '',
'photo' => '',
'lineno' => $lineno,
];
} else {
$sections[] = [
'title' => $content,
'description' => '',
'lineno' => $lineno,
];
$messages[] = [
'type' => 'section',
'content' => $content,
'class' => '',
'photo' => '',
'lineno' => $lineno,
];
}
continue;
} else {
$class = "ks-from";
$photo = $default_photo;
$bioId = '';
}
$messages[] = [
'type' => 'message',
'speaker' => $speaker,
'content' => $content,
'class' => $class,
'photo' => $photo,
'bioId' => $bioId,
'lineno' => $lineno,
];
}
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<title><?= htmlspecialchars($agenda_obj->title) ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-v4-rtl/4.1.1-1/css/bootstrap.min.css" integrity="sha512-iqRdf+0KMFmNZgdsA+8bz1MWIIXQBUCavPYVSVI83fcVfH2Y2PnNooLN04bgTNoUiQvIzidiIHJAcIP/uAEV9w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js" integrity="sha512-a+SUDuwNzXDvz4XrIcXHuCf089/iJAoN4lmrXJg18XnduKK6YlDHNRalv4yd1N40OKI80tFidF+rqTFKGPoWFQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/md5.min.js" integrity="sha512-ENWhXy+lET8kWcArT6ijA6HpVEALRmvzYBayGL6oFWl96exmq8Fjgxe2K6TAblHLP75Sa/a1YjHpIZRt+9hGOQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="lyvote.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="ks-page-content">
<div class="ks-page-content-body">
<div class="ks-messenger">
<div class="ks-discussions">
<div class="ks-search">
<div class="input-icon icon-right icon icon-lg icon-color-primary">
<span class="icon-addon">
<span class="la la-search"></span>
</span>
</div>
</div>
<div class="ks-body" data-auto-height style="overflow-y: auto; padding: 0px; width: 339px;" tabindex="0">
<div class="jspContainer" style="width: 339px; height: 550px;">
<div class="jspPane" style="padding: 0px; top: 0px; width: 329px;">
<ul class="ks-items">
<!--
<li class="ks-item ks-active">
<a href="#">
<span class="ks-group-amount">3</span>
<div class="ks-body">
<div class="ks-name">
Group Chat
<span class="ks-datetime">just now</span>
</div>
<div class="ks-message">
<img src="https://bootdey.com/img/Content/avatar/avatar1.png" width="18" height="18" class="rounded-circle"> The weird future of movie theater food
</div>
</div>
</a>
</li>
<li class="ks-item ks-unread">
<a href="#">
<span class="ks-group-amount">5</span>
<div class="ks-body">
<div class="ks-name">
Eric George
<span class="ks-datetime">just now</span>
</div>
<div class="ks-message">
<img src="https://bootdey.com/img/Content/avatar/avatar2.png" width="18" height="18" class="rounded-circle"> Why didn't he come and talk to me...
</div>
</div>
</a>
</li>
<li class="ks-item">
<a href="#">
<span class="ks-avatar">
<img src="https://bootdey.com/img/Content/avatar/avatar3.png" width="36" height="36">
</span>
<div class="ks-body">
<div class="ks-name">
Eric George
<span class="ks-datetime">just now</span>
</div>
<div class="ks-message">Why didn't he come and talk to me himse...</div>
</div>
</a>
</li>
<li class="ks-item">
<a href="#">
<span class="ks-avatar">
<img src="https://bootdey.com/img/Content/avatar/avatar4.png" width="36" height="36">
<span class="badge badge-pill badge-danger ks-badge ks-notify">7</span>
</span>
<div class="ks-body">
<div class="ks-name">
Eric George
<span class="ks-datetime">just now</span>
</div>
<div class="ks-message">Why didn't he come and talk to me himse...</div>
</div>
</a>
</li>
<li class="ks-item">
<a href="#">
<span class="ks-avatar">
<img src="https://bootdey.com/img/Content/avatar/avatar5.png" width="36" height="36">
</span>
<div class="ks-body">
<div class="ks-name">
Eric George
<span class="ks-datetime">just now</span>
</div>
<div class="ks-message">Why didn't he come and talk to me himse...</div>
</div>
</a>
</li>
<li class="ks-item">
<a href="#">
<span class="ks-avatar">
<img src="https://bootdey.com/img/Content/avatar/avatar6.png" width="36" height="36">
</span>
<div class="ks-body">
<div class="ks-name">
Eric George
<span class="ks-datetime">just now</span>
</div>
<div class="ks-message">Why didn't he come and talk to me himse...</div>
</div>
</a>
</li>
<li class="ks-item">
<a href="#">
<span class="ks-avatar">
<img src="https://bootdey.com/img/Content/avatar/avatar7.png" width="36" height="36">
</span>
<div class="ks-body">
<div class="ks-name">
Eric George
<span class="ks-datetime">just now</span>
</div>
<div class="ks-message">Why didn't he come and talk to me himse...</div>
</div>
</a>
</li>
<li class="ks-item">
<a href="#">
<span class="ks-avatar ks-online">
<img src="https://bootdey.com/img/Content/avatar/avatar1.png" width="36" height="36">
</span>
<div class="ks-body">
<div class="ks-name">
Brian Diaz
<span class="ks-datetime">just now</span>
</div>
<div class="ks-message">The weird future of movie theater food</div>
</div>
</a>
</li>
<li class="ks-item">
<a href="#">
<span class="ks-group-amount">3 <span class="badge badge-pill badge-danger ks-badge ks-notify">7</span></span>
<div class="ks-body">
<div class="ks-name">
Eric George
<span class="ks-datetime">just now</span>
</div>
<div class="ks-message">Why didn't he come and talk to me himse...</div>
</div>
</a>
</li>
<li class="ks-item">
<a href="#">
<span class="ks-avatar ks-offline">
<img src="https://bootdey.com/img/Content/avatar/avatar2.png" width="36" height="36">
</span>
<div class="ks-body">
<div class="ks-name">
Eric George
<span class="ks-datetime">just now</span>
</div>
<div class="ks-message">Why didn't he come and talk to me himse...</div>
</div>
</a>
</li>
<li class="ks-item">
<a href="#">
<span class="ks-avatar">
<img src="https://bootdey.com/img/Content/avatar/avatar3.png" width="36" height="36">
</span>
<div class="ks-body">
<div class="ks-name">
Eric George
<span class="ks-datetime">just now</span>
</div>
<div class="ks-message">Why didn't he come and talk to me himse...</div>
</div>
</a>
</li>
<li class="ks-item">
<a href="#">
<span class="ks-avatar">
<img src="https://bootdey.com/img/Content/avatar/avatar4.png" width="36" height="36">
</span>
<div class="ks-body">
<div class="ks-name">
Eric George
<span class="ks-datetime">just now</span>
</div>
<div class="ks-message">Why didn't he come and talk to me himse...</div>
</div>
</a>
</li>
<li class="ks-item">
<a href="#">
<span class="ks-avatar">
<img src="https://bootdey.com/img/Content/avatar/avatar5.png" width="36" height="36">
</span>
<div class="ks-body">
<div class="ks-name">
Lauren Sandoval
<span class="ks-datetime">just now</span>
</div>
<div class="ks-message">The weird future of movie theater food</div>
</div>
</a>
</li>
<li class="ks-item ks-closed">
<a href="#">
<span class="ks-avatar">
<img src="https://bootdey.com/img/Content/avatar/avatar6.png" width="36" height="36">
</span>
<div class="ks-body">
<div class="ks-name">
Brian Diaz
<span class="ks-datetime">just now</span>
</div>
<div class="ks-message">The weird future of movie theater food</div>
</div>
</a>
</li>
-->
<?php foreach ($sections as $section) { ?>
<li class="ks-item ks-closed">
<a href="#message-<?= $section['lineno'] ?>">
<!--<span class="ks-avatar">
<img src="https://bootdey.com/img/Content/avatar/avatar6.png" width="36" height="36">
</span>-->
<div class="ks-body">
<div class="ks-name">
<?= htmlspecialchars($section['title']) ?>
<!--<span class="ks-datetime">just now</span>-->
</div>
<div class="ks-message"><?= htmlspecialchars($section['description']) ?></div>
</div>
</a>
</li>
<?php } ?>
</ul>
</div>
<div class="jspVerticalBar">
<div class="jspCap jspCapTop"></div>
<div class="jspTrack" style="height: 550px;">
<div class="jspDrag" style="height: 261px;">
<div class="jspDragTop"></div>
<div class="jspDragBottom"></div>
</div>
</div>
<div class="jspCap jspCapBottom"></div>
</div>
</div>
</div>
</div>
<div class="ks-messages ks-messenger__messages">
<div class="ks-header">
<div class="ks-description">
<div class="ks-name"><?= htmlspecialchars($agenda_obj->title) ?></div>
<div class="ks-amount">
<?= htmlspecialchars($agenda_obj->{'時間'}) ?>
@ <?= htmlspecialchars($agenda_obj->{'地點'}) ?>
(主席:<?= htmlspecialchars($agenda_obj->{'主席'}) ?>)
</div>
</div>
<div class="ks-controls">
<div class="dropdown">
<button class="btn btn-primary-outline ks-light ks-no-text ks-no-arrow" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="la la-ellipsis-h ks-icon"></span>
</button>
<div class="dropdown-menu dropdown-menu-right ks-simple" aria-labelledby="dropdownMenuButton">
<!--
<a class="dropdown-item" href="#">
<span class="la la-user-plus ks-icon"></span>
<span class="ks-text">Add members</span>
</a>
<a class="dropdown-item" href="#">
<span class="la la-eye-slash ks-icon"></span>
<span class="ks-text">Mark as unread</span>
</a>
<a class="dropdown-item" href="#">
<span class="la la-bell-slash-o ks-icon"></span>
<span class="ks-text">Mute notifications</span>
</a>
<a class="dropdown-item" href="#">
<span class="la la-mail-forward ks-icon"></span>
<span class="ks-text">Forward</span>
</a>
<a class="dropdown-item" href="#">
<span class="la la-ban ks-icon"></span>
<span class="ks-text">Spam</span>
</a>
<a class="dropdown-item" href="#">
<span class="la la-trash-o ks-icon"></span>
<span class="ks-text">Delete</span>
</a>
-->
這裡放一些可以連回去原資料的功能
</div>
</div>
</div>
</div>
<div class="ks-body" data-auto-height data-reduce-height=".ks-footer" data-fix-height="32" style="height: 480px; overflow-y: auto; padding: 0px; width: 701px;" tabindex="0">
<div class="jspContainer" style="width: 701px">
<div class="jspPane" style="padding: 0px; top: 0px; width: 691px;">
<ul class="ks-items">
<?php foreach ($messages as $message) { ?>
<?php if ($message['type'] == 'info') { ?>
<li class="ks-item" id="message-<?= $message['lineno'] ?>"><!-- message -->
<div class="ks-body">
<div class="ks-header">
<span class="ks-datetime"><!-- TODO: time --></span>
</div>
<div class="ks-message"><?= nl2br(htmlspecialchars($message['content'])) ?></div>
</div>
</li>
<?php } elseif ($message['type'] == 'section') { ?>
<li class="ks-item" id="message-<?= $message['lineno'] ?>"><!-- message -->
<h3><?= nl2br(htmlspecialchars($message['content'])) ?></h3>
</li>
<?php } elseif ($message['type'] == 'vote') { ?>
<?php $vote = $message['content']; ?>
<li class="ks-item" id="message-<?= $message['lineno'] ?>"><!-- message -->
<h4><?= htmlspecialchars($vote->{'表決議題'}) ?></h4>
</li>
<li>
<div class="ks-message">
<p>表決時間:<?= htmlspecialchars($vote->{'表決時間'}) ?></p>
<p>表決型態:<?= htmlspecialchars($vote->{'表決型態'}) ?></p>
<p>
<?= htmlspecialchars($vote->{'表決結果'}->{'出席人數'}) ?>人出席
,贊成<?= htmlspecialchars($vote->{'表決結果'}->{'贊成人數'}) ?>人
,反對<?= htmlspecialchars($vote->{'表決結果'}->{'反對人數'}) ?>人
,棄權<?= htmlspecialchars($vote->{'表決結果'}->{'棄權人數'}) ?>人
</p>
</div>
</li>
<li>
<div id="vote-result-<?= $message['lineno'] ?>" class="twlyvote ad-8 session-2 sitting-13" style="width: 100%; height: 400px">
<span class="approval"><?= implode(';', $vote->{'贊成'} ?? []) ?></span>
<span class="veto"><?= implode(';', $vote->{'反對'} ?? []) ?></span>
<span class="abstention"><?= implode(';', $vote->{'棄權'} ?? []) ?></span>
</div>
<script>
lyvote.render({
transform: "scale(0.65)",
seatMapping: lyvote.map.linear,
node: '#vote-result-<?= $message['lineno'] ?>',
voter: <?= json_encode($voters) ?>,
});
</script>
</li>
<?php } elseif ($message['type'] == 'message') { ?>
<li class="ks-item <?= $message['class'] ?>" id="message-<?= $message['lineno'] ?>"><!-- message -->
<?php if ($message['photo']) { ?>
<span class="ks-avatar ks-offline speaker-photo" data-bioid="<?= $message['bioId'] ?>">
<img src="<?= htmlspecialchars($message['photo']) ?>" width="36" height="36" class="rounded-circle">
</span>
<?php } ?>
<div class="ks-body">
<div class="ks-header">
<span class="ks-name"><?= htmlspecialchars($message['speaker']) ?></span>
<span class="ks-datetime"><!-- TODO: time --></span>
</div>
<div class="ks-message"><?= nl2br(htmlspecialchars($message['content'])) ?></div>
</div>
</li>
<?php } ?>
<?php } ?>
</ul>
</div>
<div class="jspVerticalBar">
<div class="jspCap jspCapTop"></div>
<div class="jspTrack" style="height: 481px;">
<div class="jspDrag" style="height: 206px;">
<div class="jspDragTop"></div>
<div class="jspDragBottom"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="ks-info ks-messenger__info">
<div class="ks-header">
User Info
</div>
<?php foreach ($showed_speakers as $name => $seq) { ?>
<?php $legislator = $legislators[$name]; ?>
<div class="ks-body speaker-list" id="bioinfo-<?= $legislator->bioId ?>"
<?php if ($seq) { ?> style="display: none;" <?php } ?>
>
<div class="ks-item ks-user">
<span class="ks-avatar ks-online">
<img src="<?= htmlspecialchars($legislator->picUrl) ?>" width="36" height="36" class="rounded-circle">
</span>
<span class="ks-name"><?= htmlspecialchars($legislator->name) ?></span>
</div>
<?php foreach ([
'sex' => '性別',
'party' => '黨籍',
'areaName' => '選區',
] as $key => $label) { ?>
<div class="ks-item">
<div class="ks-name"><?= $label ?></div>
<div class="ks-text"><?= htmlspecialchars($legislator->$key) ?></div>
</div>
<?php } ?>
</div>
<?php } ?>
<div class="ks-footer"></div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-v4-rtl/4.1.1-1/js/bootstrap.bundle.min.js" integrity="sha512-5LQcfkpkY3H6HduPyJ9ogeSCnwucwzTdYC/cFvk+SHdFrsfIXtlhaJRwf3G551XNHW+WTUEIWDgGX+a4kchU2w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="text/javascript">
$('.speaker-photo').click(function() {
var bioId = $(this).data('bioid');
$('.speaker-list').hide();
$('#bioinfo-' + bioId).show();
});
</script>
</body>
</html>