|
1
|
|
|
<?php |
|
2
|
|
|
# For displaying any debate calendar, day, debate, speech page or related. |
|
3
|
|
|
|
|
4
|
|
|
namespace MySociety\TheyWorkForYou\SectionView; |
|
5
|
|
|
|
|
6
|
|
|
class SectionView { |
|
7
|
|
|
protected $major; |
|
8
|
|
|
protected $class; |
|
9
|
|
|
protected $list; |
|
10
|
|
|
private $major_data; |
|
11
|
|
|
private $page_base; |
|
12
|
|
|
protected $index_template = ''; |
|
13
|
|
|
|
|
14
|
|
|
public function __construct() { |
|
15
|
|
|
global $hansardmajors; |
|
|
|
|
|
|
16
|
|
|
$this->major_data = $hansardmajors[$this->major]; |
|
17
|
|
|
$this->page_base = str_replace('year', '', $this->major_data['page_year']); |
|
18
|
|
|
if (!$this->list) { |
|
19
|
|
|
$this->class = "\\" . $this->class; |
|
20
|
|
|
$this->list = new $this->class(); |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function display() { |
|
25
|
|
|
if ($year = get_http_var('y')) { |
|
26
|
|
|
$data = $this->display_year($year); |
|
27
|
|
|
$data['year'] = $year; |
|
28
|
|
|
$data['template'] = 'section/year'; |
|
29
|
|
|
$data = $this->addCommonData($data); |
|
30
|
|
|
} elseif (($date = get_http_var('d')) && ($column = get_http_var('c'))) { |
|
31
|
|
|
$data = $this->display_column($date, $column); |
|
32
|
|
|
$data = $this->addCommonData($data); |
|
33
|
|
|
} elseif ($date = get_http_var('d')) { |
|
34
|
|
|
$data = $this->display_day($date); |
|
35
|
|
|
if ( !isset($data['template']) ) { |
|
36
|
|
|
$data['template'] = 'section/day'; |
|
37
|
|
|
} |
|
38
|
|
|
$data = $this->addCommonData($data); |
|
39
|
|
|
} elseif (get_http_var('id')) { |
|
40
|
|
|
$data = $this->display_section_or_speech(); |
|
41
|
|
|
} else { |
|
42
|
|
|
$data = $this->display_front(); |
|
43
|
|
|
if ( !isset($data['template']) ) { |
|
44
|
|
|
$data['template'] = 'section/recent'; |
|
45
|
|
|
} |
|
46
|
|
|
$data['search_sections'] = $this->getSearchSections(); |
|
47
|
|
|
$data = $this->addCommonData($data); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return $data; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function addCommonData($data) { |
|
54
|
|
|
global $DATA, $this_page; |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$common = new \MySociety\TheyWorkForYou\Common; |
|
57
|
|
|
$data['urls'] = $this->getURLs($data); |
|
58
|
|
|
$data['popular_searches'] = $common->getPopularSearches(); |
|
59
|
|
|
$data['recess_major'] = $this->getRecessMajor($data); |
|
60
|
|
|
|
|
61
|
|
|
$nextprev = $DATA->page_metadata($this_page, 'nextprev'); |
|
62
|
|
|
if ( isset($nextprev['next']['url']) ) { |
|
63
|
|
|
$data['next'] = $nextprev['next']; |
|
64
|
|
|
} |
|
65
|
|
|
if ( isset($nextprev['prev']['url']) ) { |
|
66
|
|
|
$data['prev'] = $nextprev['prev']; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$parent_page = $DATA->page_metadata($this_page, 'parent'); |
|
70
|
|
|
$data['title'] = $DATA->page_metadata($this_page, 'title'); |
|
71
|
|
|
if (!isset($data['title']) && $parent_page != '') { |
|
72
|
|
|
$data['title'] = $DATA->page_metadata($parent_page, 'title'); |
|
73
|
|
|
} |
|
74
|
|
|
if ( $parent_page ) { |
|
75
|
|
|
$data['parent_title'] = $DATA->page_metadata($parent_page, 'title'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$data['section'] = $this->pageToSection(); |
|
79
|
|
|
|
|
80
|
|
|
return $data; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
protected function getURLs($data) { |
|
84
|
|
|
global $DATA, $this_page; |
|
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
$urls = array(); |
|
87
|
|
|
|
|
88
|
|
|
$urls = array_merge($urls, $this->getViewUrls()); |
|
89
|
|
|
|
|
90
|
|
|
if ( isset($data['info']['page']) ) { |
|
91
|
|
|
$day = new \MySociety\TheyWorkForYou\Url($data['info']['page']); |
|
92
|
|
|
$urls['day'] = $day; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return $urls; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
protected function getViewUrls() { |
|
99
|
|
|
$urls = array(); |
|
100
|
|
|
$day = new \MySociety\TheyWorkForYou\Url('debates'); |
|
101
|
|
|
$urls['debatesday'] = $day; |
|
102
|
|
|
$urls['day'] = $day; |
|
103
|
|
|
$day = new \MySociety\TheyWorkForYou\Url('whall'); |
|
104
|
|
|
$urls['whallday'] = $day; |
|
105
|
|
|
$day = new \MySociety\TheyWorkForYou\Url('lordsdebates'); |
|
106
|
|
|
$urls['lordsday'] = $day; |
|
107
|
|
|
return $urls; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
protected function getSearchSections() { |
|
111
|
|
|
return array(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
protected function getRecessMajor($data) { |
|
|
|
|
|
|
115
|
|
|
global $hansardmajors; |
|
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
$recess_major = 1; # For all of UK Parliament |
|
118
|
|
|
if ($hansardmajors[$this->major]['location'] == 'NI') { |
|
119
|
|
|
$recess_major = 5; |
|
120
|
|
|
} elseif ($hansardmajors[$this->major]['location'] == 'Scotland') { |
|
121
|
|
|
$recess_major = 4; # For all of Scotland |
|
122
|
|
|
} elseif ($this->major == 101) { |
|
123
|
|
|
$recess_major = 101; # Lords slightly different |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
return $recess_major; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
protected function display_year($year) { |
|
130
|
|
|
global $this_page, $PAGE, $DATA; |
|
|
|
|
|
|
131
|
|
|
$this_page = $this->page_base . 'year'; |
|
132
|
|
|
if (is_numeric($year)) { |
|
133
|
|
|
$DATA->set_page_metadata($this_page, 'title', $year); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
$args = array ( 'year' => $year ); |
|
137
|
|
|
$data = $this->list->display('calendar', $args, 'none'); |
|
138
|
|
|
return $data; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
protected function display_column($date, $column) { |
|
142
|
|
|
global $this_page; |
|
|
|
|
|
|
143
|
|
|
$this_page = $this->page_base; |
|
144
|
|
|
$args = array( 'date' => $date, 'column' => $column ); |
|
145
|
|
|
$content = $this->list->display('column', $args, 'none'); |
|
146
|
|
|
|
|
147
|
|
|
$data = array(); |
|
148
|
|
|
$data['column'] = $column; |
|
149
|
|
|
$URL = new \MySociety\TheyWorkForYou\Url($this->list->listpage); |
|
150
|
|
|
$URL->insert(array('d' => $date)); |
|
151
|
|
|
$data['debate_day_link'] = $URL->generate(); |
|
152
|
|
|
$data['debate_day_human'] = format_date($date, LONGDATEFORMAT); |
|
153
|
|
|
|
|
154
|
|
|
$data['rows'] = $content; |
|
155
|
|
|
$data['info'] = array('major' => $this->major, 'date' => $date); |
|
156
|
|
|
|
|
157
|
|
|
list($country, $location, $assembly) = $this->getCountryDetails(); |
|
158
|
|
|
$data['col_country'] = $country; |
|
159
|
|
|
$data['location'] = $location; |
|
160
|
|
|
$data['current_assembly'] = $assembly; |
|
161
|
|
|
|
|
162
|
|
|
$data['template'] = 'section/column'; |
|
163
|
|
|
return $data; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
protected function display_day($date) { |
|
167
|
|
|
global $this_page; |
|
|
|
|
|
|
168
|
|
|
$this_page = $this->page_base . 'day'; |
|
169
|
|
|
$args = array ( 'date' => get_http_var('d') ); |
|
170
|
|
|
$data = $this->list->display('date', $args, 'none'); |
|
171
|
|
|
list($year, $month, $day) = explode('-', $date); |
|
172
|
|
|
$args = array( 'year' => $year, 'month' => $month, 'day' => $day); |
|
173
|
|
|
$calendar = $this->list->display('calendar', $args, 'none'); |
|
174
|
|
|
if ( isset($calendar['years']) ) { |
|
175
|
|
|
$data['calendar'] = $calendar['years']; |
|
176
|
|
|
} |
|
177
|
|
|
return $data; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
protected function display_section_or_speech($args = array()) { |
|
181
|
|
|
global $DATA, $this_page, $THEUSER; |
|
|
|
|
|
|
182
|
|
|
|
|
183
|
|
|
# += as we *don't* want to override any already supplied argument |
|
184
|
|
|
$args += array ( |
|
185
|
|
|
'gid' => get_http_var('id'), |
|
186
|
|
|
's' => get_http_var('s'), // Search terms to be highlighted. |
|
187
|
|
|
'member_id' => get_http_var('m'), // Member's speeches to be highlighted. |
|
188
|
|
|
); |
|
189
|
|
|
|
|
190
|
|
|
if (preg_match('/speaker:(\d+)/', get_http_var('s'), $mmm)) { |
|
191
|
|
|
$args['person_id'] = $mmm[1]; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
try { |
|
195
|
|
|
$data = $this->list->display('gid', $args, 'none'); |
|
196
|
|
|
} catch (\RedirectException $e) { |
|
197
|
|
|
$URL = new \MySociety\TheyWorkForYou\Url($this->major_data['page_all']); |
|
198
|
|
|
if ($this->major == 6) { |
|
199
|
|
|
# Magically (as in I can't remember quite why), pbc_clause will |
|
200
|
|
|
# contain the new URL without any change... |
|
201
|
|
|
$URL->remove( array('id') ); |
|
202
|
|
|
} else { |
|
203
|
|
|
$URL->insert( array('id'=>$e->getMessage()) ); |
|
204
|
|
|
} |
|
205
|
|
|
# put the search term back in so highlighting works. |
|
206
|
|
|
# NB: as we don't see the # part of the URL we lose this :( |
|
207
|
|
|
if ( $args['s'] !== '' ) { |
|
208
|
|
|
$URL->insert( array('s'=>$args['s']) ); |
|
209
|
|
|
} |
|
210
|
|
|
redirect($URL->generate('none')); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
$data['individual_item'] = ($this->list->commentspage == $this_page); |
|
214
|
|
|
|
|
215
|
|
|
if ($data['individual_item']) { |
|
216
|
|
|
$COMMENTLIST = new \COMMENTLIST; |
|
217
|
|
|
$args['user_id'] = get_http_var('u'); |
|
218
|
|
|
$args['epobject_id'] = $this->list->epobject_id(); |
|
219
|
|
|
$data['comments']['object'] = $COMMENTLIST; |
|
220
|
|
|
$data['comments']['args'] = $args; |
|
221
|
|
|
$data['comments']['commentdata'] = array( |
|
222
|
|
|
'epobject_id' => $this->list->epobject_id(), |
|
223
|
|
|
'gid' => get_http_var('id'), # wrans is LIST->gid? |
|
224
|
|
|
'return_page' => $this_page |
|
225
|
|
|
); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
if (!isset($data['info'])) { |
|
229
|
|
|
header("HTTP/1.0 404 Not Found"); |
|
230
|
|
|
$data['template'] = 'error'; |
|
231
|
|
|
return $data; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
# Okay, let's set up highlighting and glossarisation |
|
235
|
|
|
|
|
236
|
|
|
list($bodies, $speeches) = $this->highlightSpeeches($data); |
|
237
|
|
|
|
|
238
|
|
|
list($data, $first_speech, $subsection_title) = $this->annotateSpeeches($data, $bodies, $speeches); |
|
239
|
|
|
|
|
240
|
|
|
|
|
241
|
|
|
list($country, $location, $assembly) = $this->getCountryDetails(); |
|
242
|
|
|
$data['location'] = $location; |
|
243
|
|
|
$data['current_assembly'] = $assembly; |
|
244
|
|
|
|
|
245
|
|
|
$data = $this->setTitleAndAlertText($data, $subsection_title); |
|
246
|
|
|
|
|
247
|
|
|
$data['debate_time_human'] = format_time($first_speech['htime'], 'g:i a'); |
|
248
|
|
|
$data['debate_day_human'] = format_date($first_speech['hdate'], 'jS F Y'); |
|
249
|
|
|
|
|
250
|
|
|
$URL = new \MySociety\TheyWorkForYou\Url($this->list->listpage); |
|
251
|
|
|
$URL->insert(array('d' => $first_speech['hdate'])); |
|
252
|
|
|
$URL->remove(array('id')); |
|
253
|
|
|
$data['debate_day_link'] = $URL->generate(); |
|
254
|
|
|
|
|
255
|
|
|
$data['nextprev'] = $DATA->page_metadata($this_page, 'nextprev'); |
|
256
|
|
|
|
|
257
|
|
|
return $data; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
private function setTitleAndAlertText($data, $subsection_title) { |
|
261
|
|
|
if ($subsection_title) { |
|
262
|
|
|
$data['heading'] = $subsection_title; |
|
263
|
|
|
} else { |
|
264
|
|
|
$data['heading'] = $data['section_title']; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
if ($subsection_title) { |
|
268
|
|
|
$data['intro'] = "$data[section_title]"; |
|
269
|
|
|
} else { |
|
270
|
|
|
$data['intro'] = ""; |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
if (array_key_exists('text_heading', $data['info'])) { |
|
274
|
|
|
// avoid having Clause 1 etc as the alert text search string on PBC pages as it's |
|
275
|
|
|
// almost certainly not what the person wants |
|
276
|
|
|
if ( $this->major == 6 ) { |
|
277
|
|
|
$data['email_alert_text'] = $data['section_title']; |
|
278
|
|
|
} else { |
|
279
|
|
|
$data['email_alert_text'] = $data['info']['text_heading']; |
|
280
|
|
|
} |
|
281
|
|
|
} else { |
|
282
|
|
|
// The user has requested only part of a debate, so find a suitable title |
|
283
|
|
|
if ($subsection_title) { |
|
284
|
|
|
$data['intro'] = "Part of $data[section_title]"; |
|
285
|
|
|
} else { |
|
286
|
|
|
$data['intro'] = "Part of the debate"; |
|
287
|
|
|
} |
|
288
|
|
|
foreach ($data['rows'] as $row) { |
|
289
|
|
|
if ($row['htype'] == 10 || $row['htype'] == 11) { |
|
290
|
|
|
$data['email_alert_text'] = $row['body']; |
|
291
|
|
|
$data['full_debate_url'] = $row['listurl']; |
|
292
|
|
|
break; |
|
293
|
|
|
} |
|
294
|
|
|
} |
|
295
|
|
|
} |
|
296
|
|
|
// strip a couple of common characters that result in encode junk in the |
|
297
|
|
|
// search string |
|
298
|
|
|
$data['email_alert_text'] = preg_replace('/(?:[:()\[\]]|&#\d+;)/', '', $data['email_alert_text']); |
|
299
|
|
|
|
|
300
|
|
|
return $data; |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
private function highlightSpeeches($data) { |
|
304
|
|
|
$SEARCHENGINE = null; |
|
305
|
|
|
if (isset($data['info']['searchstring']) && $data['info']['searchstring'] != '') { |
|
306
|
|
|
$SEARCHENGINE = new \SEARCHENGINE($data['info']['searchstring']); |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
// Before we print the body text we need to insert glossary links |
|
310
|
|
|
// and highlight search string words. |
|
311
|
|
|
|
|
312
|
|
|
$speeches = 0; |
|
313
|
|
|
$bodies = array(); |
|
314
|
|
|
foreach ($data['rows'] as $row) { |
|
315
|
|
|
$htype = $row['htype']; |
|
316
|
|
|
if ($htype == 12 || $htype == 13) { |
|
317
|
|
|
$speeches++; |
|
318
|
|
|
} |
|
319
|
|
|
$body = $row['body']; |
|
320
|
|
|
$body = preg_replace('#<phrase class="honfriend" id="uk.org.publicwhip/member/(\d+)" name="([^"]*?)">(.*?\s*\((.*?)\))</phrase>#', '<a href="/mp/?m=$1" title="Our page on $2 - \'$3\'">$4</a>', $body); |
|
321
|
|
|
$body = preg_replace('#<phrase class="honfriend" name="([^"]*?)" person_id="uk.org.publicwhip/person/(\d+)">(.*?\s*\((.*?)\))</phrase>#', '<a href="/mp/?p=$2" title="Our page on $1 - \'$3\'">$4</a>', $body); |
|
322
|
|
|
$body = preg_replace_callback('#<phrase class="offrep" id="(.*?)/(\d+)-(\d+)-(\d+)\.(.*?)">(.*?)</phrase>#', function($matches) { |
|
323
|
|
|
return '<a href="/search/?pop=1&s=date:' . $matches[2] . $matches[3] . $matches[4] . '+column:' . $matches[5] . '+section:' . $matches[1] .'">' . str_replace("Official Report", "Hansard", $matches[6]) . '</a>'; |
|
324
|
|
|
}, $body); |
|
325
|
|
|
#$body = preg_replace('#<phrase class="offrep" id="((.*?)/(\d+)-(\d+)-(\d+)\.(.*?))">(.*?)</phrase>#e', "\"<a href='/search/?pop=1&s=date:$3$4$5+column:$6+section:$2&match=$1'>\" . str_replace('Official Report', 'Hansard', '$7') . '</a>'", $body); |
|
|
|
|
|
|
326
|
|
|
$bodies[] = $body; |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
if ($SEARCHENGINE) { |
|
330
|
|
|
// We have some search terms to highlight. |
|
331
|
|
|
twfy_debug_timestamp('Before highlight'); |
|
332
|
|
|
$bodies = $SEARCHENGINE->highlight($bodies); |
|
333
|
|
|
twfy_debug_timestamp('After highlight'); |
|
334
|
|
|
} |
|
335
|
|
|
// Do all this unless the glossary is turned off in the URL |
|
336
|
|
|
if (get_http_var('ug') != 1) { |
|
337
|
|
|
// And glossary phrases |
|
338
|
|
|
twfy_debug_timestamp('Before glossarise'); |
|
339
|
|
|
|
|
340
|
|
|
$args['sort'] = "regexp_replace"; |
|
|
|
|
|
|
341
|
|
|
$GLOSSARY = new \GLOSSARY($args); |
|
342
|
|
|
$bodies = $GLOSSARY->glossarise($bodies, 1); |
|
343
|
|
|
|
|
344
|
|
|
twfy_debug_timestamp('After glossarise'); |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
return array($bodies, $speeches); |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
private function annotateSpeeches($data, $bodies, $speeches) { |
|
351
|
|
|
global $THEUSER; |
|
|
|
|
|
|
352
|
|
|
$first_speech = null; |
|
353
|
|
|
$data['section_title'] = ''; |
|
354
|
|
|
$subsection_title = ''; |
|
355
|
|
|
for ($i=0; $i<count($data['rows']); $i++) { |
|
|
|
|
|
|
356
|
|
|
$row = $data['rows'][$i]; |
|
357
|
|
|
$htype = $row['htype']; |
|
358
|
|
|
// HPOS should be defined below if it's needed; otherwise default to 0 |
|
359
|
|
|
$heading_hpos = 0; |
|
360
|
|
|
if ($htype == 10) { |
|
361
|
|
|
$data['section_title'] = $row['body']; |
|
362
|
|
|
$heading_hpos = $row['hpos']; |
|
363
|
|
|
} elseif ($htype == 11) { |
|
364
|
|
|
$subsection_title = $row['body']; |
|
365
|
|
|
$heading_hpos = $row['hpos']; |
|
366
|
|
|
} elseif ($htype == 12) { |
|
367
|
|
|
# Splitting out highlighting results back into individual bits |
|
368
|
|
|
$data['rows'][$i]['body'] = $bodies[$i]; |
|
369
|
|
|
} |
|
370
|
|
|
if ($htype == 12 || $htype == 13) { |
|
371
|
|
|
if (!$first_speech) { |
|
372
|
|
|
$first_speech = $data['rows'][$i]; |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
# Voting links |
|
376
|
|
|
$data['rows'][$i]['voting_data'] = ''; |
|
377
|
|
|
if (isset($row['votes'])) { |
|
378
|
|
|
$data['rows'][$i]['voting_data'] = $this->generate_votes( $row['votes'], $row['epobject_id'], $row['gid'] ); |
|
|
|
|
|
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
# Annotation link |
|
382
|
|
|
if ($this->is_debate_section_page()) { |
|
383
|
|
|
$data['rows'][$i]['commentteaser'] = $this->generate_commentteaser($row); |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
if (isset($row['mentions'])) { |
|
387
|
|
|
$data['rows'][$i]['mentions'] = $this->get_question_mentions_html($row['mentions']); |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
if ($this->major == 1) { |
|
391
|
|
|
$data['rows'][$i]['video'] = $this->get_video_html($row, $heading_hpos, $speeches); |
|
|
|
|
|
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
if (array_key_exists('name', $data['rows'][$i]['speaker'])) { |
|
395
|
|
|
$data['rows'][$i]['socialteaser'] = sprintf( |
|
396
|
|
|
'%s on %s, at TheyWorkForYou', |
|
397
|
|
|
ucfirst($data['rows'][$i]['speaker']['name']), |
|
398
|
|
|
$data['section_title'] |
|
399
|
|
|
); |
|
400
|
|
|
} else { |
|
401
|
|
|
$data['rows'][$i]['socialteaser'] = sprintf( |
|
402
|
|
|
'%s on TheyWorkForYou', |
|
403
|
|
|
$data['section_title'] |
|
404
|
|
|
); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
$data['rows'][$i]['socialurl'] = sprintf( |
|
408
|
|
|
'https://www.theyworkforyou.com%s', |
|
409
|
|
|
$row['commentsurl'] |
|
410
|
|
|
); |
|
411
|
|
|
} |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
return array($data, $first_speech, $subsection_title); |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
private function getCountryDetails() { |
|
418
|
|
|
$details = array( |
|
419
|
|
|
1 => array ( |
|
420
|
|
|
'country' => 'UK', |
|
421
|
|
|
'assembly' => 'uk-commons', |
|
422
|
|
|
'location' => '– in the House of Commons' |
|
423
|
|
|
), |
|
424
|
|
|
2 => array ( |
|
425
|
|
|
'country' => 'UK', |
|
426
|
|
|
'assembly' => 'uk-commons', |
|
427
|
|
|
'location' => '– in Westminster Hall' |
|
428
|
|
|
), |
|
429
|
|
|
3 => array ( |
|
430
|
|
|
'country' => 'UK', |
|
431
|
|
|
'assembly' => 'uk-commons', |
|
432
|
|
|
'location' => 'written question – answered' |
|
433
|
|
|
), |
|
434
|
|
|
4 => array ( |
|
435
|
|
|
'country' => 'UK', |
|
436
|
|
|
'assembly' => 'uk-commons', |
|
437
|
|
|
'location' => 'written statement – made' |
|
438
|
|
|
), |
|
439
|
|
|
5 => array ( |
|
440
|
|
|
'country' => 'NORTHERN IRELAND', |
|
441
|
|
|
'assembly' => 'ni', |
|
442
|
|
|
'location' => '– in the Northern Ireland Assembly' |
|
443
|
|
|
), |
|
444
|
|
|
6 => array ( |
|
445
|
|
|
'country' => 'UK', |
|
446
|
|
|
'assembly' => 'uk-commons', |
|
447
|
|
|
'location' => '– in a Public Bill Committee' |
|
448
|
|
|
), |
|
449
|
|
|
7 => array ( |
|
450
|
|
|
'country' => 'SCOTLAND', |
|
451
|
|
|
'assembly' => 'scotland', |
|
452
|
|
|
'location' => '– in the Scottish Parliament' |
|
453
|
|
|
), |
|
454
|
|
|
8 => array ( |
|
455
|
|
|
'country' => 'SCOTLAND', |
|
456
|
|
|
'assembly' => 'scotland', |
|
457
|
|
|
'location' => '– Scottish Parliament written question – answered' |
|
458
|
|
|
), |
|
459
|
|
|
101 => array ( |
|
460
|
|
|
'country' => 'UK', |
|
461
|
|
|
'assembly' => 'uk-lords', |
|
462
|
|
|
'location' => '– in the House of Lords' |
|
463
|
|
|
) |
|
464
|
|
|
); |
|
465
|
|
|
|
|
466
|
|
|
$detail = $details[$this->major]; |
|
467
|
|
|
return array($detail['country'], $detail['location'], $detail['assembly']); |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
protected function display_front() { |
|
471
|
|
|
global $DATA, $this_page; |
|
|
|
|
|
|
472
|
|
|
$this_page = $this->page_base . 'front'; |
|
473
|
|
|
$data = array(); |
|
474
|
|
|
if ( $this->index_template ) { |
|
475
|
|
|
$data['template'] = $this->index_template; |
|
476
|
|
|
} |
|
477
|
|
|
|
|
478
|
|
|
$class = new $this->class; |
|
479
|
|
|
$content = array(); |
|
480
|
|
|
$content['data'] = $this->front_content(); |
|
|
|
|
|
|
481
|
|
|
|
|
482
|
|
|
$content['calendar'] = $class->display('calendar', array('months' => 1), 'none'); |
|
483
|
|
|
|
|
484
|
|
|
if ( $rssurl = $DATA->page_metadata($this_page, 'rss') ) { |
|
485
|
|
|
$content['rssurl'] = $rssurl; |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
$data['content'] = $content; |
|
489
|
|
|
return $this->addCommonData($data); |
|
490
|
|
|
|
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
public function is_debate_section_page() { |
|
494
|
|
|
global $this_page; |
|
|
|
|
|
|
495
|
|
|
return ($this->major_data['type'] == 'debate' && $this->major_data['page_all'] == $this_page); |
|
496
|
|
|
} |
|
497
|
|
|
|
|
498
|
|
|
//$totalcomments, $comment, $commenturl |
|
|
|
|
|
|
499
|
|
|
function generate_commentteaser ($row) { |
|
|
|
|
|
|
500
|
|
|
// Returns HTML for the one fragment of comment and link for the sidebar. |
|
501
|
|
|
// $totalcomments is the number of comments this item has on it. |
|
502
|
|
|
// $comment is an array like: |
|
503
|
|
|
/* $comment = array ( |
|
|
|
|
|
|
504
|
|
|
'comment_id' => 23, |
|
505
|
|
|
'user_id' => 34, |
|
506
|
|
|
'body' => 'Blah blah...', |
|
507
|
|
|
'posted' => '2004-02-24 23:45:30', |
|
508
|
|
|
'username' => 'phil' |
|
509
|
|
|
) |
|
510
|
|
|
*/ |
|
511
|
|
|
// $url is the URL of the item's page, which contains comments. |
|
512
|
|
|
|
|
513
|
|
|
if ($row['totalcomments'] == 0) { |
|
514
|
|
|
return; |
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
//Add existing annotations |
|
518
|
|
|
$comment = $row['comment']; |
|
519
|
|
|
|
|
520
|
|
|
// If the comment is longer than the speech body, we want to trim it |
|
521
|
|
|
// to be the same length so they fit next to each other. |
|
522
|
|
|
// But the comment typeface is smaller, so we scale things slightly too... |
|
523
|
|
|
$targetsize = round(strlen($row['body']) * 0.6); |
|
524
|
|
|
|
|
525
|
|
|
$linktext = ''; |
|
526
|
|
|
if ($targetsize > strlen($comment['body'])) { |
|
527
|
|
|
// This comment will fit in its entirety. |
|
528
|
|
|
$commentbody = $comment['body']; |
|
529
|
|
|
|
|
530
|
|
|
if ($row['totalcomments'] > 1) { |
|
531
|
|
|
$morecount = $row['totalcomments'] - 1; |
|
532
|
|
|
$plural = $morecount == 1 ? 'annotation' : 'annotations'; |
|
533
|
|
|
$linktext = "Read $morecount more $plural"; |
|
534
|
|
|
} |
|
535
|
|
|
|
|
536
|
|
|
} else { |
|
537
|
|
|
// This comment needs trimming. |
|
538
|
|
|
$commentbody = trim_characters($comment['body'], 0, $targetsize, 1000); |
|
539
|
|
|
if ($row['totalcomments'] > 1) { |
|
540
|
|
|
$morecount = $row['totalcomments'] - 1; |
|
541
|
|
|
$plural = $morecount == 1 ? 'annotation' : 'annotations'; |
|
542
|
|
|
$linktext = "Continue reading (and $morecount more $plural)"; |
|
543
|
|
|
} else { |
|
544
|
|
|
$linktext = 'Continue reading'; |
|
545
|
|
|
} |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
return array( |
|
549
|
|
|
'body' => prepare_comment_for_display($commentbody), |
|
550
|
|
|
'username' => _htmlentities($comment['username']), |
|
551
|
|
|
'linktext' => $linktext, |
|
552
|
|
|
'commentsurl' => $row['commentsurl'], |
|
553
|
|
|
'comment_id' => $comment['comment_id'], |
|
554
|
|
|
); |
|
555
|
|
|
} |
|
556
|
|
|
|
|
557
|
|
|
protected function get_question_mentions_html($row_data) { |
|
|
|
|
|
|
558
|
|
|
throw new \Exception('get_question_mentions_html called from class with no implementation'); |
|
559
|
|
|
} |
|
560
|
|
|
|
|
561
|
|
|
private function pageToSection() { |
|
562
|
|
|
$sections = array( |
|
563
|
|
|
1 => 'debates', |
|
564
|
|
|
2 => 'whall', |
|
565
|
|
|
3 => 'wrans', |
|
566
|
|
|
4 => 'wms', |
|
567
|
|
|
5 => 'ni', |
|
568
|
|
|
6 => 'standing', |
|
569
|
|
|
7 => 'sp', |
|
570
|
|
|
8 => 'spwrans', |
|
571
|
|
|
101 => 'lords' |
|
572
|
|
|
); |
|
573
|
|
|
|
|
574
|
|
|
return $sections[$this->major]; |
|
575
|
|
|
} |
|
576
|
|
|
|
|
577
|
|
|
} |
|
578
|
|
|
|
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state