@@ -342,6 +342,9 @@ discard block |
||
342 | 342 | echo '</ul></div>'; |
343 | 343 | } |
344 | 344 | |
345 | +/** |
|
346 | + * @param integer $limit |
|
347 | + */ |
|
345 | 348 | function display_league($limit, $q = '') { |
346 | 349 | global $THEUSER; |
347 | 350 | $db = new ParlDB; |
@@ -468,6 +471,9 @@ discard block |
||
468 | 471 | echo '</ol>'; |
469 | 472 | } |
470 | 473 | |
474 | +/** |
|
475 | + * @param integer $count |
|
476 | + */ |
|
471 | 477 | function disp_speech($row, $count) { |
472 | 478 | echo '<li'; |
473 | 479 | if ($row['htype']==13) echo ' class="unspoken"'; |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | $parent_body = $q->field(0, 'parent_body'); |
55 | 55 | $parent_epid = $q->field(0, 'subsection_id'); |
56 | 56 | |
57 | -if (!($video_status&1) || ($video_status&8)) { |
|
57 | +if (!($video_status & 1) || ($video_status & 8)) { |
|
58 | 58 | $PAGE->error_message('That GID does not appear to have any video. Please visit the <a href="/video/">video front page</a>.', true, 404); |
59 | 59 | exit; |
60 | 60 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $gids_previous = array(); |
88 | 88 | $gids_following = array(); |
89 | 89 | $gid_actual = array(); |
90 | -for ($i=0; $i<$q->rows(); $i++) { |
|
90 | +for ($i = 0; $i < $q->rows(); $i++) { |
|
91 | 91 | $row = $q->row($i); |
92 | 92 | if ($row['adate']) $row['hdate'] = $row['adate']; |
93 | 93 | if ($row['atime']) $row['htime'] = $row['atime']; |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | <?php |
180 | 180 | $hidden_int = (isset($_COOKIE['hideVideoInt']) && $_COOKIE['hideVideoInt']); |
181 | 181 | echo '<table id="video_table" border="0" cellspacing="0" cellpadding="5"><tr valign="top"><td width="50%">'; |
182 | - if ($gid_actual['video_status']&4) { |
|
182 | + if ($gid_actual['video_status'] & 4) { |
|
183 | 183 | $q = $db->query("select timediff(current_timestamp,max(whenstamped)) as ws from video_timestamps where gid='$q_gid' and (user_id is null or user_id != -1) and deleted=0"); |
184 | 184 | $max = $q->field(0, 'ws'); |
185 | 185 | echo '<p class="informational">Thanks, but this speech has <strong>already been stamped</strong>'; |
@@ -240,12 +240,12 @@ discard block |
||
240 | 240 | $q = $db->query('select video_status&4 as checked,count(*) as c from hansard |
241 | 241 | where major=1 and video_status>0 and video_status<8 and video_status!=2 and htype in (12,13) group by video_status&4'); |
242 | 242 | $totaliser = array(0=>0, 4=>0); |
243 | - for ($i=0; $i<$q->rows(); $i++) { |
|
243 | + for ($i = 0; $i < $q->rows(); $i++) { |
|
244 | 244 | $status = $q->field($i, 'checked'); |
245 | 245 | $count = $q->field($i, 'c'); |
246 | 246 | $totaliser[$status] = $count; |
247 | 247 | } |
248 | - $percentage = round($totaliser[4] / ($totaliser[0]+$totaliser[4]) * 10000) / 100; |
|
248 | + $percentage = round($totaliser[4] / ($totaliser[0] + $totaliser[4]) * 10000) / 100; |
|
249 | 249 | $out = "$totaliser[4] timestamped out of " . ($totaliser[0] + $totaliser[4]) . " ($percentage%)" |
250 | 250 | ?> |
251 | 251 | |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | and hdate=(select max(hdate) from hansard where major=1) |
302 | 302 | group by video_status&4'); |
303 | 303 | $totaliser = array(0=>0, 4=>0); |
304 | - for ($i=0; $i<$q->rows(); $i++) { |
|
304 | + for ($i = 0; $i < $q->rows(); $i++) { |
|
305 | 305 | $status = $q->field($i, 'checked'); |
306 | 306 | $count = $q->field($i, 'c'); |
307 | 307 | $totaliser[$status] = $count; |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | where (user_id != -1 or user_id is null) and video_timestamps.deleted=0 |
329 | 329 | and video_timestamps.gid = hansard.gid and hansard.subsection_id = epobject.epobject_id |
330 | 330 | order by whenstamped desc limit 20'); |
331 | - for ($i=0; $i<$q->rows(); $i++) { |
|
331 | + for ($i = 0; $i < $q->rows(); $i++) { |
|
332 | 332 | $gid = $q->field($i, 'gid'); |
333 | 333 | $body = $q->field($i, 'body'); |
334 | 334 | if ($q->field($i, 'major') == 101) { |
@@ -348,18 +348,18 @@ discard block |
||
348 | 348 | $q = $db->query('select firstname,lastname,video_timestamps.user_id,count(*) as c |
349 | 349 | from video_timestamps left join users on video_timestamps.user_id=users.user_id |
350 | 350 | where video_timestamps.deleted=0 and (video_timestamps.user_id is null or video_timestamps.user_id!=-1) ' |
351 | - . $q . ' group by user_id order by c desc' . ($THEUSER->user_id() ? '' : " limit $limit") ); |
|
351 | + . $q . ' group by user_id order by c desc' . ($THEUSER->user_id() ? '' : " limit $limit")); |
|
352 | 352 | $out = ''; $rank = 0; |
353 | - for ($i=0; $i<$q->rows(); $i++) { |
|
353 | + for ($i = 0; $i < $q->rows(); $i++) { |
|
354 | 354 | $name = $q->field($i, 'firstname') . ' ' . $q->field($i, 'lastname'); |
355 | 355 | $user_id = $q->field($i, 'user_id'); |
356 | 356 | #if ($user_id == -1) continue; # $name = 'CaptionerBot'; |
357 | 357 | if ($user_id == 0) $name = 'Anonymous'; |
358 | 358 | $count = $q->field($i, 'c'); |
359 | 359 | if ($THEUSER->user_id() == $user_id) { |
360 | - $rank = $i+1; |
|
360 | + $rank = $i + 1; |
|
361 | 361 | } |
362 | - if ($i>=$limit) continue; |
|
362 | + if ($i >= $limit) continue; |
|
363 | 363 | $out .= '<li>'; |
364 | 364 | if ($THEUSER->user_id() == $user_id) |
365 | 365 | $out .= '<strong>'; |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | <?php } ?> |
413 | 413 | <li>If the video suddenly <strong>jumps</strong> a couple of hours, or otherwise appears broken, <a href="mailto:<?=str_replace('@', '@', CONTACTEMAIL) ?>?subject=Video%20<?=$file?>%20for%20ID%20<?=$gid_safe?>%20broken">let us know</a>. |
414 | 414 | <li>If the speech you're looking for is <strong>beyond the end</strong> of the video, |
415 | -<a href="/video/?gid=<?=$gid_safe?>&file=<?=$file+1?>&start=1<?=$pid_url?>">move on to the next video chunk</a>. |
|
415 | +<a href="/video/?gid=<?=$gid_safe?>&file=<?=$file + 1?>&start=1<?=$pid_url?>">move on to the next video chunk</a>. |
|
416 | 416 | <li>If you're right at the start of a day, it's quite possible the start of the video |
417 | 417 | will be the end of the previous programme on BBC Parliament, skip ahead some minutes |
418 | 418 | to check :) |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | <a href="/user/login/?ret=/video/">Log in</a> | |
444 | 444 | <?php } ?> |
445 | 445 | <a href="mailto:<?=str_replace('@', '@', CONTACTEMAIL) ?>?subject=Video%20<?=$file?>%20for%20ID%20<?=$gid_safe?>%20broken">Broken video</a> | |
446 | -<a href="/video/?gid=<?=$gid_safe?>&file=<?=$file+1?>&start=1<?=$pid_url?>" title="Loads the next video chunk">Speech past end of video</a> |
|
446 | +<a href="/video/?gid=<?=$gid_safe?>&file=<?=$file + 1?>&start=1<?=$pid_url?>" title="Loads the next video chunk">Speech past end of video</a> |
|
447 | 447 | </p> |
448 | 448 | |
449 | 449 | <p align="right"><small><!-- <b>Credits:</b> Video from <a href='http://www.bbc.co.uk/parliament/'>BBC Parliament</a> and mySociety. --> |
@@ -470,13 +470,13 @@ discard block |
||
470 | 470 | |
471 | 471 | function disp_speech($row, $count) { |
472 | 472 | echo '<li'; |
473 | - if ($row['htype']==13) echo ' class="unspoken"'; |
|
474 | - elseif ($row['htype']<12) echo ' class="heading"'; |
|
475 | - if (!($count%2)) echo ' style="background-color: #F5FDEA;"'; |
|
473 | + if ($row['htype'] == 13) echo ' class="unspoken"'; |
|
474 | + elseif ($row['htype'] < 12) echo ' class="heading"'; |
|
475 | + if (!($count % 2)) echo ' style="background-color: #F5FDEA;"'; |
|
476 | 476 | else echo ' style="background-color: #E8FDCB;"'; |
477 | 477 | echo '>'; |
478 | 478 | if ($count) echo "<em>$count earlier:</em> "; |
479 | - if ($row['htype']==12) |
|
479 | + if ($row['htype'] == 12) |
|
480 | 480 | echo '<span class="video_name">' . $row['given_name'] . ' ' . $row['family_name'] . '</span> '; |
481 | 481 | echo $row['body']; |
482 | 482 | echo '</li>'; |
@@ -47,8 +47,12 @@ discard block |
||
47 | 47 | $htime = $q->field(0, 'htime'); |
48 | 48 | $atime = $q->field(0, 'atime'); |
49 | 49 | $adate = $q->field(0, 'adate'); |
50 | -if ($atime) $htime = $atime; |
|
51 | -if ($adate) $hdate = $adate; |
|
50 | +if ($atime) { |
|
51 | + $htime = $atime; |
|
52 | +} |
|
53 | +if ($adate) { |
|
54 | + $hdate = $adate; |
|
55 | +} |
|
52 | 56 | $parent_gid = str_replace('uk.org.publicwhip/debate/', '/debates/?id=', $q->field(0, 'parent_gid')); |
53 | 57 | $parent_gid = str_replace('uk.org.publicwhip/lords/', '/lords/?gid=', $parent_gid); |
54 | 58 | $parent_body = $q->field(0, 'parent_body'); |
@@ -89,14 +93,20 @@ discard block |
||
89 | 93 | $gid_actual = array(); |
90 | 94 | for ($i=0; $i<$q->rows(); $i++) { |
91 | 95 | $row = $q->row($i); |
92 | - if ($row['adate']) $row['hdate'] = $row['adate']; |
|
93 | - if ($row['atime']) $row['htime'] = $row['atime']; |
|
96 | + if ($row['adate']) { |
|
97 | + $row['hdate'] = $row['adate']; |
|
98 | + } |
|
99 | + if ($row['atime']) { |
|
100 | + $row['htime'] = $row['atime']; |
|
101 | + } |
|
94 | 102 | if ($row['hpos'] < $hpos) { |
95 | 103 | $gids_previous[] = $row; |
96 | - } elseif ($row['hpos'] > $hpos) { |
|
104 | + } |
|
105 | + elseif ($row['hpos'] > $hpos) { |
|
97 | 106 | $gids_following[] = $row; |
98 | 107 | |
99 | - } else { |
|
108 | + } |
|
109 | + else { |
|
100 | 110 | $gid_actual = $row; |
101 | 111 | } |
102 | 112 | } |
@@ -134,14 +144,20 @@ discard block |
||
134 | 144 | } |
135 | 145 | $video = \MySociety\TheyWorkForYou\Utility\Video::fromTimestamp($videodb, $hdate, $htime); |
136 | 146 | |
137 | -if (!$start) |
|
147 | +if (!$start) { |
|
138 | 148 | $start = $video['offset'] - $offset; |
139 | -if ($start < 0) $start = 0; |
|
149 | +} |
|
150 | +if ($start < 0) { |
|
151 | + $start = 0; |
|
152 | +} |
|
140 | 153 | |
141 | -if (get_http_var('barcamp')) |
|
154 | +if (get_http_var('barcamp')) { |
|
142 | 155 | $video['id'] -= 4000; |
156 | +} |
|
143 | 157 | |
144 | -if (!$file) $file = $video['id']; |
|
158 | +if (!$file) { |
|
159 | + $file = $video['id']; |
|
160 | +} |
|
145 | 161 | |
146 | 162 | # Start displaying |
147 | 163 | |
@@ -186,7 +202,8 @@ discard block |
||
186 | 202 | if ($max < '00:15:00') { |
187 | 203 | echo ' <strong>within the last 15 minutes</strong>, so it\'s possible you and someone |
188 | 204 | else are timestamping the same debate at the same time'; |
189 | - } elseif ($from == 'next') { |
|
205 | + } |
|
206 | + elseif ($from == 'next') { |
|
190 | 207 | echo ' (probably by someone coming by at random when you\'ve been clicking Next)'; |
191 | 208 | } |
192 | 209 | echo '. You can <a href="/video/next.php?action=nextneeded&gid=', |
@@ -219,7 +236,8 @@ discard block |
||
219 | 236 | echo '</div>'; |
220 | 237 | if (get_http_var('from') == 'next' && $hidden_int) { |
221 | 238 | previous_speeches($surrounding_speeches, $gids_previous); |
222 | - } else { |
|
239 | + } |
|
240 | + else { |
|
223 | 241 | iframe_search($gid_safe, $file); |
224 | 242 | } |
225 | 243 | echo '</td>'; |
@@ -264,7 +282,8 @@ discard block |
||
264 | 282 | <p id="video_attract"><?php |
265 | 283 | if ($totaliser[0]) { |
266 | 284 | echo '<a href="next.php?action=random">Give me a random speech that needs timestamping</a>'; |
267 | - } else { |
|
285 | + } |
|
286 | + else { |
|
268 | 287 | echo 'Wow, everything that can currently be timestamped appears to have been, thanks!'; |
269 | 288 | } |
270 | 289 | ?></p> |
@@ -280,14 +299,26 @@ discard block |
||
280 | 299 | global $THEUSER; |
281 | 300 | if ($THEUSER->user_id() && ($rank_today || $rank_week || $rank_overall)) { |
282 | 301 | echo '<p align="center"><big>You are '; |
283 | - if ($rank_today) echo make_ranking($rank_today), ' today, '; |
|
284 | - if ($rank_week) echo make_ranking($rank_week), ' last 4 weeks, '; |
|
285 | - if ($rank_overall) echo make_ranking($rank_overall), ' overall'; |
|
302 | + if ($rank_today) { |
|
303 | + echo make_ranking($rank_today), ' today, '; |
|
304 | + } |
|
305 | + if ($rank_week) { |
|
306 | + echo make_ranking($rank_week), ' last 4 weeks, '; |
|
307 | + } |
|
308 | + if ($rank_overall) { |
|
309 | + echo make_ranking($rank_overall), ' overall'; |
|
310 | + } |
|
286 | 311 | echo '</big></p>'; |
287 | 312 | } |
288 | - if ($out_today) echo "<h3>Top timestampers (today)</h3> <ol>$out_today</ol>"; |
|
289 | - if ($out_week) echo "<h3>Top timestampers (last 4 weeks)</h3> <ol>$out_week</ol>"; |
|
290 | - if ($out_overall) echo "<h3>Top timestampers (overall)</h3> <ol>$out_overall</ol>"; |
|
313 | + if ($out_today) { |
|
314 | + echo "<h3>Top timestampers (today)</h3> <ol>$out_today</ol>"; |
|
315 | + } |
|
316 | + if ($out_week) { |
|
317 | + echo "<h3>Top timestampers (last 4 weeks)</h3> <ol>$out_week</ol>"; |
|
318 | + } |
|
319 | + if ($out_overall) { |
|
320 | + echo "<h3>Top timestampers (overall)</h3> <ol>$out_overall</ol>"; |
|
321 | + } |
|
291 | 322 | echo '</div>'; |
292 | 323 | ?> |
293 | 324 | <div style="float: right; width: 50%"> |
@@ -310,7 +341,8 @@ discard block |
||
310 | 341 | if ($total_possible == 0) { |
311 | 342 | $percentage = 0; |
312 | 343 | $out = 'Nothing possible to timestamp on most recent day'; |
313 | - } else { |
|
344 | + } |
|
345 | + else { |
|
314 | 346 | $percentage = round($totaliser[4] / $total_possible * 10000) / 100; |
315 | 347 | $out = "$totaliser[4] timestamped out of $total_possible ($percentage%)"; |
316 | 348 | } |
@@ -333,7 +365,8 @@ discard block |
||
333 | 365 | $body = $q->field($i, 'body'); |
334 | 366 | if ($q->field($i, 'major') == 101) { |
335 | 367 | $url = '/lords/?gid='; |
336 | - } else { |
|
368 | + } |
|
369 | + else { |
|
337 | 370 | $url = '/debate/?id='; |
338 | 371 | } |
339 | 372 | echo '<li><a href="', $url, fix_gid_from_db($gid) . '">' . $body . '</a>'; |
@@ -354,18 +387,24 @@ discard block |
||
354 | 387 | $name = $q->field($i, 'firstname') . ' ' . $q->field($i, 'lastname'); |
355 | 388 | $user_id = $q->field($i, 'user_id'); |
356 | 389 | #if ($user_id == -1) continue; # $name = 'CaptionerBot'; |
357 | - if ($user_id == 0) $name = 'Anonymous'; |
|
390 | + if ($user_id == 0) { |
|
391 | + $name = 'Anonymous'; |
|
392 | + } |
|
358 | 393 | $count = $q->field($i, 'c'); |
359 | 394 | if ($THEUSER->user_id() == $user_id) { |
360 | 395 | $rank = $i+1; |
361 | 396 | } |
362 | - if ($i>=$limit) continue; |
|
397 | + if ($i>=$limit) { |
|
398 | + continue; |
|
399 | + } |
|
363 | 400 | $out .= '<li>'; |
364 | - if ($THEUSER->user_id() == $user_id) |
|
365 | - $out .= '<strong>'; |
|
401 | + if ($THEUSER->user_id() == $user_id) { |
|
402 | + $out .= '<strong>'; |
|
403 | + } |
|
366 | 404 | $out .= "$name : $count"; |
367 | - if ($THEUSER->user_id() == $user_id) |
|
368 | - $out .= '</strong>'; |
|
405 | + if ($THEUSER->user_id() == $user_id) { |
|
406 | + $out .= '</strong>'; |
|
407 | + } |
|
369 | 408 | #if ($user_id == -1) { |
370 | 409 | # echo ' <small>(initial run program that tries to guess timestamp from captions, wildly variable)</small>'; |
371 | 410 | #} |
@@ -384,8 +423,10 @@ discard block |
||
384 | 423 | |
385 | 424 | function basic_instructions($pid) { |
386 | 425 | $pid_url = ''; |
387 | - if ($pid) $pid_url = "&pid=$pid"; |
|
388 | -?> |
|
426 | + if ($pid) { |
|
427 | + $pid_url = "&pid=$pid"; |
|
428 | + } |
|
429 | + ?> |
|
389 | 430 | <ol style="font-size: 150%;"> |
390 | 431 | <li>Have a quick scan of the speech under the video, then press “Play”. |
391 | 432 | <li>When you hear the start of that speech, press “Now!”. |
@@ -403,8 +444,10 @@ discard block |
||
403 | 444 | function basic_hints($gid_safe, $file, $pid) { |
404 | 445 | global $THEUSER; |
405 | 446 | $pid_url = ''; |
406 | - if ($pid) $pid_url = "&pid=$pid"; |
|
407 | -?> |
|
447 | + if ($pid) { |
|
448 | + $pid_url = "&pid=$pid"; |
|
449 | + } |
|
450 | + ?> |
|
408 | 451 | |
409 | 452 | <ul> |
410 | 453 | <?php if (!$THEUSER->loggedin()) { ?> |
@@ -434,8 +477,10 @@ discard block |
||
434 | 477 | function advanced_hints($gid_safe, $file, $pid) { |
435 | 478 | global $THEUSER; |
436 | 479 | $pid_url = ''; |
437 | - if ($pid) $pid_url = "&pid=$pid"; |
|
438 | -?> |
|
480 | + if ($pid) { |
|
481 | + $pid_url = "&pid=$pid"; |
|
482 | + } |
|
483 | + ?> |
|
439 | 484 | |
440 | 485 | <p align="center">Actions: |
441 | 486 | <a href="/video/next.php?action=random">Skip</a> | |
@@ -470,14 +515,25 @@ discard block |
||
470 | 515 | |
471 | 516 | function disp_speech($row, $count) { |
472 | 517 | echo '<li'; |
473 | - if ($row['htype']==13) echo ' class="unspoken"'; |
|
474 | - elseif ($row['htype']<12) echo ' class="heading"'; |
|
475 | - if (!($count%2)) echo ' style="background-color: #F5FDEA;"'; |
|
476 | - else echo ' style="background-color: #E8FDCB;"'; |
|
518 | + if ($row['htype']==13) { |
|
519 | + echo ' class="unspoken"'; |
|
520 | + } |
|
521 | + elseif ($row['htype']<12) { |
|
522 | + echo ' class="heading"'; |
|
523 | + } |
|
524 | + if (!($count%2)) { |
|
525 | + echo ' style="background-color: #F5FDEA;"'; |
|
526 | + } |
|
527 | + else { |
|
528 | + echo ' style="background-color: #E8FDCB;"'; |
|
529 | + } |
|
477 | 530 | echo '>'; |
478 | - if ($count) echo "<em>$count earlier:</em> "; |
|
479 | - if ($row['htype']==12) |
|
480 | - echo '<span class="video_name">' . $row['given_name'] . ' ' . $row['family_name'] . '</span> '; |
|
531 | + if ($count) { |
|
532 | + echo "<em>$count earlier:</em> "; |
|
533 | + } |
|
534 | + if ($row['htype']==12) { |
|
535 | + echo '<span class="video_name">' . $row['given_name'] . ' ' . $row['family_name'] . '</span> '; |
|
536 | + } |
|
481 | 537 | echo $row['body']; |
482 | 538 | echo '</li>'; |
483 | 539 | } |
@@ -51,6 +51,10 @@ discard block |
||
51 | 51 | |
52 | 52 | // FUNCTION: fetch_between |
53 | 53 | |
54 | + /** |
|
55 | + * @param integer $confirmed |
|
56 | + * @param integer $deleted |
|
57 | + */ |
|
54 | 58 | public function fetch_between($confirmed, $deleted, $start_date, $end_date) { |
55 | 59 | // Return summary data on all the alerts that were created between $start_date |
56 | 60 | // and $end_date (inclusive) and whose confirmed and deleted values match the booleans |
@@ -79,6 +83,10 @@ discard block |
||
79 | 83 | |
80 | 84 | // FUNCTION: fetch |
81 | 85 | |
86 | + /** |
|
87 | + * @param integer $confirmed |
|
88 | + * @param integer $deleted |
|
89 | + */ |
|
82 | 90 | public function fetch($confirmed, $deleted) { |
83 | 91 | // Pass it an alert id and it will fetch data about alerts from the db |
84 | 92 | // and put it all in the appropriate variables. |
@@ -320,6 +328,9 @@ discard block |
||
320 | 328 | } |
321 | 329 | } |
322 | 330 | |
331 | + /** |
|
332 | + * @param string $email |
|
333 | + */ |
|
323 | 334 | public function email_exists($email) { |
324 | 335 | // Returns true if there's a user with this email address. |
325 | 336 |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | // FUNCTION: fetch_between |
53 | 53 | |
54 | 54 | public function fetch_between($confirmed, $deleted, $start_date, $end_date) { |
55 | - // Return summary data on all the alerts that were created between $start_date |
|
56 | - // and $end_date (inclusive) and whose confirmed and deleted values match the booleans |
|
57 | - // passed in $confirmed and $deleted |
|
55 | + // Return summary data on all the alerts that were created between $start_date |
|
56 | + // and $end_date (inclusive) and whose confirmed and deleted values match the booleans |
|
57 | + // passed in $confirmed and $deleted |
|
58 | 58 | $q = $this->db->query("SELECT criteria, count(*) as cnt |
59 | 59 | FROM alerts |
60 | 60 | WHERE confirmed = :confirmed |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | )); |
70 | 70 | $data = array(); |
71 | 71 | for ($row=0; $row<$q->rows(); $row++) { |
72 | - $contents = array('criteria' => $q->field($row, 'criteria'), 'count' => $q->field($row, 'cnt')); |
|
73 | - $data[] = $contents; |
|
72 | + $contents = array('criteria' => $q->field($row, 'criteria'), 'count' => $q->field($row, 'cnt')); |
|
73 | + $data[] = $contents; |
|
74 | 74 | } |
75 | 75 | $data = array ('alerts' => $data); |
76 | 76 |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | public $token_checked = null; |
42 | 42 | private $alert_id = ""; |
43 | 43 | public $email = ""; |
44 | - public $criteria = ""; // Sets the terms that are used to produce the search results. |
|
44 | + public $criteria = ""; // Sets the terms that are used to produce the search results. |
|
45 | 45 | |
46 | 46 | private $db; |
47 | 47 | |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | ':end_date' => $end_date |
69 | 69 | )); |
70 | 70 | $data = array(); |
71 | - for ($row=0; $row<$q->rows(); $row++) { |
|
71 | + for ($row = 0; $row < $q->rows(); $row++) { |
|
72 | 72 | $contents = array('criteria' => $q->field($row, 'criteria'), 'count' => $q->field($row, 'cnt')); |
73 | 73 | $data[] = $contents; |
74 | 74 | } |
75 | - $data = array ('alerts' => $data); |
|
75 | + $data = array('alerts' => $data); |
|
76 | 76 | |
77 | 77 | return $data; |
78 | 78 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | |
101 | 101 | $data = array(); |
102 | 102 | |
103 | - for ($row=0; $row<$q->rows(); $row++) { |
|
103 | + for ($row = 0; $row < $q->rows(); $row++) { |
|
104 | 104 | $contents = array( |
105 | 105 | 'alert_id' => $q->field($row, 'alert_id'), |
106 | 106 | 'email' => $q->field($row, 'email'), |
@@ -112,13 +112,13 @@ discard block |
||
112 | 112 | $data[] = $contents; |
113 | 113 | } |
114 | 114 | $info = "Alert"; |
115 | - $data = array ('info' => $info, 'data' => $data); |
|
115 | + $data = array('info' => $info, 'data' => $data); |
|
116 | 116 | |
117 | 117 | |
118 | 118 | return $data; |
119 | 119 | } |
120 | 120 | |
121 | - public function add($details, $confirmation_email=false, $instantly_confirm=true) { |
|
121 | + public function add($details, $confirmation_email = false, $instantly_confirm = true) { |
|
122 | 122 | |
123 | 123 | // Adds a new alert's info into the database. |
124 | 124 | // Then calls another function to send them a confirmation email. |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | // This gives a code for their email address which is then joined |
183 | 183 | // to the timestamp so as to provide a unique ID for each alert. |
184 | 184 | |
185 | - $token = substr( password_hash($details["email"] . microtime(), PASSWORD_BCRYPT), 29, 16 ); |
|
185 | + $token = substr(password_hash($details["email"] . microtime(), PASSWORD_BCRYPT), 29, 16); |
|
186 | 186 | |
187 | 187 | // Full stops don't work well at the end of URLs in emails, |
188 | 188 | // so replace them. We won't be doing anything clever with the hash |
@@ -255,19 +255,19 @@ discard block |
||
255 | 255 | |
256 | 256 | $urltoken = $this->alert_id . '-' . $this->registrationtoken; |
257 | 257 | |
258 | - if ( isset($details['confirm_base']) && $details['confirm_base'] !== '' ) { |
|
258 | + if (isset($details['confirm_base']) && $details['confirm_base'] !== '') { |
|
259 | 259 | $confirmurl = $details['confirm_base'] . $urltoken; |
260 | 260 | } else { |
261 | 261 | $confirmurl = 'https://' . DOMAIN . '/A/' . $urltoken; |
262 | 262 | } |
263 | 263 | |
264 | 264 | // Arrays we need to send a templated email. |
265 | - $data = array ( |
|
265 | + $data = array( |
|
266 | 266 | 'to' => $details['email'], |
267 | 267 | 'template' => 'alert_confirmation' |
268 | 268 | ); |
269 | 269 | |
270 | - $merge = array ( |
|
270 | + $merge = array( |
|
271 | 271 | 'FIRSTNAME' => 'THEY WORK FOR YOU', |
272 | 272 | 'LASTNAME' => ' ALERT CONFIRMATION', |
273 | 273 | 'CONFIRMURL' => $confirmurl, |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | } |
284 | 284 | |
285 | 285 | public function send_already_signedup_email($details) { |
286 | - $data = array ( |
|
286 | + $data = array( |
|
287 | 287 | 'to' => $details['email'], |
288 | 288 | 'template' => 'alert_already_signedup' |
289 | 289 | ); |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | $criteria = \MySociety\TheyWorkForYou\Utility\Alert::detailsToCriteria($details); |
292 | 292 | $this->criteria = $criteria; |
293 | 293 | |
294 | - $merge = array ( |
|
294 | + $merge = array( |
|
295 | 295 | 'FIRSTNAME' => 'THEY WORK FOR YOU', |
296 | 296 | 'LASTNAME' => ' ALERT ALREADY SIGNED UP', |
297 | 297 | 'CRITERIA' => $this->criteria_pretty() |
@@ -442,17 +442,17 @@ discard block |
||
442 | 442 | public function email() { return $this->email; } |
443 | 443 | public function criteria() { return $this->criteria; } |
444 | 444 | public function criteria_pretty($html = false) { |
445 | - $criteria = explode(' ',$this->criteria); |
|
445 | + $criteria = explode(' ', $this->criteria); |
|
446 | 446 | $spokenby = array_values(\MySociety\TheyWorkForYou\Utility\Search::speakerNamesForIDs($this->criteria)); |
447 | 447 | $words = array(); |
448 | 448 | foreach ($criteria as $c) { |
449 | - if (!preg_match('#^speaker:(\d+)#',$c,$m)) { |
|
449 | + if (!preg_match('#^speaker:(\d+)#', $c, $m)) { |
|
450 | 450 | $words[] = $c; |
451 | 451 | } |
452 | 452 | } |
453 | 453 | $criteria = ''; |
454 | - if (count($words)) $criteria .= ($html?'<li>':'* ') . 'Mentions of [' . implode(' ', $words) . ']' . ($html?'</li>':'') . "\n"; |
|
455 | - if ($spokenby) $criteria .= ($html?'<li>':'* ') . "Things by " . implode(' or ', $spokenby) . ($html?'</li>':'') . "\n"; |
|
454 | + if (count($words)) $criteria .= ($html ? '<li>' : '* ') . 'Mentions of [' . implode(' ', $words) . ']' . ($html ? '</li>' : '') . "\n"; |
|
455 | + if ($spokenby) $criteria .= ($html ? '<li>' : '* ') . "Things by " . implode(' or ', $spokenby) . ($html ? '</li>' : '') . "\n"; |
|
456 | 456 | return $criteria; |
457 | 457 | } |
458 | 458 |
@@ -149,7 +149,8 @@ discard block |
||
149 | 149 | ':criteria' => $criteria |
150 | 150 | )); |
151 | 151 | return 1; |
152 | - } else { |
|
152 | + } |
|
153 | + else { |
|
153 | 154 | return -2; |
154 | 155 | } |
155 | 156 | } |
@@ -210,11 +211,13 @@ discard block |
||
210 | 211 | if ($success) { |
211 | 212 | // Email sent OK |
212 | 213 | return 1; |
213 | - } else { |
|
214 | + } |
|
215 | + else { |
|
214 | 216 | // Couldn't send the email. |
215 | 217 | return -1; |
216 | 218 | } |
217 | - } elseif ($instantly_confirm) { |
|
219 | + } |
|
220 | + elseif ($instantly_confirm) { |
|
218 | 221 | // No confirmation email needed. |
219 | 222 | $s = $this->db->query("UPDATE alerts |
220 | 223 | SET confirmed = '1' |
@@ -224,12 +227,14 @@ discard block |
||
224 | 227 | )); |
225 | 228 | return 1; |
226 | 229 | } |
227 | - } else { |
|
230 | + } |
|
231 | + else { |
|
228 | 232 | // Couldn't add the registration token to the DB. |
229 | 233 | return -1; |
230 | 234 | } |
231 | 235 | |
232 | - } else { |
|
236 | + } |
|
237 | + else { |
|
233 | 238 | // Couldn't add the user's data to the DB. |
234 | 239 | return -1; |
235 | 240 | } |
@@ -257,7 +262,8 @@ discard block |
||
257 | 262 | |
258 | 263 | if ( isset($details['confirm_base']) && $details['confirm_base'] !== '' ) { |
259 | 264 | $confirmurl = $details['confirm_base'] . $urltoken; |
260 | - } else { |
|
265 | + } |
|
266 | + else { |
|
261 | 267 | $confirmurl = 'https://' . DOMAIN . '/A/' . $urltoken; |
262 | 268 | } |
263 | 269 | |
@@ -277,7 +283,8 @@ discard block |
||
277 | 283 | $success = send_template_email($data, $merge); |
278 | 284 | if ($success) { |
279 | 285 | return true; |
280 | - } else { |
|
286 | + } |
|
287 | + else { |
|
281 | 288 | return false; |
282 | 289 | } |
283 | 290 | } |
@@ -300,7 +307,8 @@ discard block |
||
300 | 307 | $success = send_template_email($data, $merge); |
301 | 308 | if ($success) { |
302 | 309 | return true; |
303 | - } else { |
|
310 | + } |
|
311 | + else { |
|
304 | 312 | return false; |
305 | 313 | } |
306 | 314 | } |
@@ -315,7 +323,8 @@ discard block |
||
315 | 323 | )); |
316 | 324 | if ($q->rows() > 0) { |
317 | 325 | return true; |
318 | - } else { |
|
326 | + } |
|
327 | + else { |
|
319 | 328 | return false; |
320 | 329 | } |
321 | 330 | } |
@@ -330,27 +339,32 @@ discard block |
||
330 | 339 | )); |
331 | 340 | if ($q->rows() > 0) { |
332 | 341 | return true; |
333 | - } else { |
|
342 | + } |
|
343 | + else { |
|
334 | 344 | return false; |
335 | 345 | } |
336 | - } else { |
|
346 | + } |
|
347 | + else { |
|
337 | 348 | return false; |
338 | 349 | } |
339 | 350 | |
340 | 351 | } |
341 | 352 | |
342 | 353 | public function check_token($token) { |
343 | - if (!is_null($this->token_checked)) |
|
344 | - return $this->token_checked; |
|
354 | + if (!is_null($this->token_checked)) { |
|
355 | + return $this->token_checked; |
|
356 | + } |
|
345 | 357 | |
346 | 358 | $arg = strstr($token, '::') ? '::' : '-'; |
347 | 359 | $token_parts = explode($arg, $token); |
348 | - if (count($token_parts) != 2) |
|
349 | - return false; |
|
360 | + if (count($token_parts) != 2) { |
|
361 | + return false; |
|
362 | + } |
|
350 | 363 | |
351 | 364 | list($alert_id, $registrationtoken) = $token_parts; |
352 | - if (!is_numeric($alert_id) || !$registrationtoken) |
|
353 | - return false; |
|
365 | + if (!is_numeric($alert_id) || !$registrationtoken) { |
|
366 | + return false; |
|
367 | + } |
|
354 | 368 | |
355 | 369 | $q = $this->db->query("SELECT alert_id, email, criteria |
356 | 370 | FROM alerts |
@@ -362,7 +376,8 @@ discard block |
||
362 | 376 | )); |
363 | 377 | if (!$q->rows()) { |
364 | 378 | $this->token_checked = false; |
365 | - } else { |
|
379 | + } |
|
380 | + else { |
|
366 | 381 | $this->token_checked = array( |
367 | 382 | 'id' => $q->field(0, 'alert_id'), |
368 | 383 | 'email' => $q->field(0, 'email'), |
@@ -384,7 +399,8 @@ discard block |
||
384 | 399 | |
385 | 400 | if (!$q->rows()) { |
386 | 401 | return false; |
387 | - } else { |
|
402 | + } |
|
403 | + else { |
|
388 | 404 | return array( |
389 | 405 | 'id' => $q->field(0, 'alert_id'), |
390 | 406 | 'email' => $q->field(0, 'email'), |
@@ -398,7 +414,9 @@ discard block |
||
398 | 414 | // If all goes well the alert will be confirmed. |
399 | 415 | // The alert will be active when scripts run each day to send the actual emails. |
400 | 416 | public function confirm($token) { |
401 | - if (!($alert = $this->check_token($token))) return false; |
|
417 | + if (!($alert = $this->check_token($token))) { |
|
418 | + return false; |
|
419 | + } |
|
402 | 420 | $this->criteria = $alert['criteria']; |
403 | 421 | $this->email = $alert['email']; |
404 | 422 | $r = $this->db->query("UPDATE alerts SET confirmed = 1, deleted = 0 WHERE alert_id = :alert_id", array( |
@@ -412,7 +430,9 @@ discard block |
||
412 | 430 | // and the deletion page has passed the token from the URL to here. |
413 | 431 | // If all goes well the alert will be flagged as deleted. |
414 | 432 | public function delete($token) { |
415 | - if (!($alert = $this->check_token($token))) return false; |
|
433 | + if (!($alert = $this->check_token($token))) { |
|
434 | + return false; |
|
435 | + } |
|
416 | 436 | $r = $this->db->query("UPDATE alerts SET deleted = 1 WHERE alert_id = :alert_id", array( |
417 | 437 | ':alert_id' => $alert['id'] |
418 | 438 | )); |
@@ -421,7 +441,9 @@ discard block |
||
421 | 441 | } |
422 | 442 | |
423 | 443 | public function suspend($token) { |
424 | - if (!($alert = $this->check_token($token))) return false; |
|
444 | + if (!($alert = $this->check_token($token))) { |
|
445 | + return false; |
|
446 | + } |
|
425 | 447 | $r = $this->db->query("UPDATE alerts SET deleted = 2 WHERE alert_id = :alert_id", array( |
426 | 448 | ':alert_id' => $alert['id'] |
427 | 449 | )); |
@@ -430,7 +452,9 @@ discard block |
||
430 | 452 | } |
431 | 453 | |
432 | 454 | public function resume($token) { |
433 | - if (!($alert = $this->check_token($token))) return false; |
|
455 | + if (!($alert = $this->check_token($token))) { |
|
456 | + return false; |
|
457 | + } |
|
434 | 458 | $r = $this->db->query("UPDATE alerts SET deleted = 0 WHERE alert_id = :alert_id", array( |
435 | 459 | ':alert_id' => $alert['id'] |
436 | 460 | )); |
@@ -451,8 +475,12 @@ discard block |
||
451 | 475 | } |
452 | 476 | } |
453 | 477 | $criteria = ''; |
454 | - if (count($words)) $criteria .= ($html?'<li>':'* ') . 'Mentions of [' . implode(' ', $words) . ']' . ($html?'</li>':'') . "\n"; |
|
455 | - if ($spokenby) $criteria .= ($html?'<li>':'* ') . "Things by " . implode(' or ', $spokenby) . ($html?'</li>':'') . "\n"; |
|
478 | + if (count($words)) { |
|
479 | + $criteria .= ($html?'<li>':'* ') . 'Mentions of [' . implode(' ', $words) . ']' . ($html?'</li>':'') . "\n"; |
|
480 | + } |
|
481 | + if ($spokenby) { |
|
482 | + $criteria .= ($html?'<li>':'* ') . "Things by " . implode(' or ', $spokenby) . ($html?'</li>':'') . "\n"; |
|
483 | + } |
|
456 | 484 | return $criteria; |
457 | 485 | } |
458 | 486 |
@@ -44,6 +44,9 @@ |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | |
47 | + /** |
|
48 | + * @param string $view |
|
49 | + */ |
|
47 | 50 | public function display ($view, $args=array(), $format='html') { |
48 | 51 | // $view is what we're viewing by: |
49 | 52 | // 'ep' is all the comments attached to an epobject. |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | return $data; |
319 | 319 | } |
320 | 320 | |
321 | - public function _get_data_by_dates($args) { |
|
321 | + public function _get_data_by_dates($args) { |
|
322 | 322 | // $args should contain start_date and end_date |
323 | 323 | |
324 | 324 | twfy_debug (get_class($this), "getting data by recent"); |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | $commentsdata = $this->_get_comment_data($input); |
339 | 339 | $data['comments'] = $commentsdata; |
340 | 340 | return $data; |
341 | - } |
|
341 | + } |
|
342 | 342 | |
343 | 343 | public function _get_data_by_search($args) { |
344 | 344 | // $args should contain 'num', indicating how many to get. |
@@ -542,11 +542,11 @@ |
||
542 | 542 | } |
543 | 543 | if ($limit != '') { |
544 | 544 | # Can't use parameter as >1 argument |
545 | - $limit = "LIMIT $limit"; |
|
545 | + $limit = "limit $limit"; |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | // Finally, do the query! |
549 | - $q = $this->db->query ("SELECT $fields |
|
549 | + $q = $this->db->query ("select $fields |
|
550 | 550 | FROM comments |
551 | 551 | $join |
552 | 552 | WHERE $where |
@@ -66,7 +66,8 @@ discard block |
||
66 | 66 | // Get all the dta that's to be rendered. |
67 | 67 | $data = $this->$function($args); |
68 | 68 | |
69 | - } else { |
|
69 | + } |
|
70 | + else { |
|
70 | 71 | // Don't have a valid $view; |
71 | 72 | $PAGE->error_message ("You haven't specified a view type."); |
72 | 73 | return false; |
@@ -74,11 +75,14 @@ discard block |
||
74 | 75 | |
75 | 76 | if ($view == 'user') { |
76 | 77 | $template = 'comments_user'; |
77 | - } elseif ($view == 'recent' or $view == 'dates') { |
|
78 | + } |
|
79 | + elseif ($view == 'recent' or $view == 'dates') { |
|
78 | 80 | $template = 'comments_recent'; |
79 | - } elseif ($view == 'search') { |
|
81 | + } |
|
82 | + elseif ($view == 'search') { |
|
80 | 83 | $template = 'comments_search'; |
81 | - } else { |
|
84 | + } |
|
85 | + else { |
|
82 | 86 | $template = 'comments'; |
83 | 87 | } |
84 | 88 | |
@@ -149,13 +153,15 @@ discard block |
||
149 | 153 | |
150 | 154 | if (isset($args['num']) && is_numeric($args['num'])) { |
151 | 155 | $num = $args['num']; |
152 | - } else { |
|
156 | + } |
|
157 | + else { |
|
153 | 158 | $num = 10; |
154 | 159 | } |
155 | 160 | |
156 | 161 | if (isset($args['page']) && is_numeric($args['page']) && $args['page']>1) { |
157 | 162 | $page = $args['page']; |
158 | - } else { |
|
163 | + } |
|
164 | + else { |
|
159 | 165 | $page = 1; |
160 | 166 | } |
161 | 167 | |
@@ -270,13 +276,15 @@ discard block |
||
270 | 276 | |
271 | 277 | if (isset($args['num']) && is_numeric($args['num'])) { |
272 | 278 | $num = $args['num']; |
273 | - } else { |
|
279 | + } |
|
280 | + else { |
|
274 | 281 | $num = 25; |
275 | 282 | } |
276 | 283 | |
277 | 284 | if (isset($args['page']) && is_numeric($args['page'])) { |
278 | 285 | $page = $args['page']; |
279 | - } else { |
|
286 | + } |
|
287 | + else { |
|
280 | 288 | $page = 1; |
281 | 289 | } |
282 | 290 | |
@@ -310,7 +318,8 @@ discard block |
||
310 | 318 | $data['full_name'] = member_full_name($q->field(0, 'house'), $q->field(0, 'title'), $q->field(0, 'given_name'), $q->field(0, 'family_name'), $q->field(0,'lordofname')); |
311 | 319 | $q = 'SELECT COUNT(*) AS count FROM comments,hansard WHERE visible=1 AND comments.epobject_id = hansard.epobject_id and hansard.person_id = :pid'; |
312 | 320 | $params[':pid'] = $args['pid']; |
313 | - } else { |
|
321 | + } |
|
322 | + else { |
|
314 | 323 | $q = 'SELECT COUNT(*) AS count FROM comments WHERE visible=1'; |
315 | 324 | } |
316 | 325 | $q = $this->db->query($q, $params); |
@@ -350,13 +359,15 @@ discard block |
||
350 | 359 | |
351 | 360 | if (isset($args['num']) && is_numeric($args['num'])) { |
352 | 361 | $num = $args['num']; |
353 | - } else { |
|
362 | + } |
|
363 | + else { |
|
354 | 364 | $num = 10; |
355 | 365 | } |
356 | 366 | |
357 | 367 | if (isset($args['page']) && is_numeric($args['page'])) { |
358 | 368 | $page = $args['page']; |
359 | - } else { |
|
369 | + } |
|
370 | + else { |
|
360 | 371 | $page = 1; |
361 | 372 | } |
362 | 373 |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | |
45 | - public function display ($view, $args=array(), $format='html') { |
|
45 | + public function display($view, $args = array(), $format = 'html') { |
|
46 | 46 | // $view is what we're viewing by: |
47 | 47 | // 'ep' is all the comments attached to an epobject. |
48 | 48 | // 'user' is all the comments written by a user. |
@@ -60,13 +60,13 @@ discard block |
||
60 | 60 | |
61 | 61 | if ($view == 'ep' || $view == 'user' || $view == 'recent' || $view == 'search' || $view == 'dates') { |
62 | 62 | // What function do we call for this view? |
63 | - $function = '_get_data_by_'.$view; |
|
63 | + $function = '_get_data_by_' . $view; |
|
64 | 64 | // Get all the dta that's to be rendered. |
65 | 65 | $data = $this->$function($args); |
66 | 66 | |
67 | 67 | } else { |
68 | 68 | // Don't have a valid $view; |
69 | - $PAGE->error_message ("You haven't specified a view type."); |
|
69 | + $PAGE->error_message("You haven't specified a view type."); |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | |
@@ -85,29 +85,29 @@ discard block |
||
85 | 85 | return true; |
86 | 86 | } |
87 | 87 | |
88 | - public function render($data, $format='html', $template='comments') { |
|
89 | - include (INCLUDESPATH."easyparliament/templates/$format/$template.php"); |
|
88 | + public function render($data, $format = 'html', $template = 'comments') { |
|
89 | + include (INCLUDESPATH . "easyparliament/templates/$format/$template.php"); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | public function _get_data_by_ep($args) { |
93 | 93 | // Get all the data attached to an epobject. |
94 | 94 | global $PAGE; |
95 | 95 | |
96 | - twfy_debug (get_class($this), "getting data by epobject"); |
|
96 | + twfy_debug(get_class($this), "getting data by epobject"); |
|
97 | 97 | |
98 | 98 | // What we return. |
99 | 99 | $data = array(); |
100 | 100 | if (!is_numeric($args['epobject_id'])) { |
101 | - $PAGE->error_message ("Sorry, we don't have a valid epobject id"); |
|
101 | + $PAGE->error_message("Sorry, we don't have a valid epobject id"); |
|
102 | 102 | return $data; |
103 | 103 | } |
104 | 104 | |
105 | 105 | // For getting the data. |
106 | - $input = array ( |
|
107 | - 'amount' => array ( |
|
106 | + $input = array( |
|
107 | + 'amount' => array( |
|
108 | 108 | 'user' => true |
109 | 109 | ), |
110 | - 'where' => array ( |
|
110 | + 'where' => array( |
|
111 | 111 | 'comments.epobject_id=' => $args['epobject_id'], |
112 | 112 | #'visible=' => '1' |
113 | 113 | ), |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | // comments by things in $args? |
136 | 136 | global $PAGE; |
137 | 137 | |
138 | - twfy_debug (get_class($this), "getting data by user"); |
|
138 | + twfy_debug(get_class($this), "getting data by user"); |
|
139 | 139 | |
140 | 140 | // What we return. |
141 | 141 | $data = array(); |
142 | 142 | |
143 | 143 | if (!is_numeric($args['user_id'])) { |
144 | - $PAGE->error_message ("Sorry, we don't have a valid user id"); |
|
144 | + $PAGE->error_message("Sorry, we don't have a valid user id"); |
|
145 | 145 | return $data; |
146 | 146 | } |
147 | 147 | |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | $num = 10; |
152 | 152 | } |
153 | 153 | |
154 | - if (isset($args['page']) && is_numeric($args['page']) && $args['page']>1) { |
|
154 | + if (isset($args['page']) && is_numeric($args['page']) && $args['page'] > 1) { |
|
155 | 155 | $page = $args['page']; |
156 | 156 | } else { |
157 | 157 | $page = 1; |
158 | 158 | } |
159 | 159 | |
160 | - $limit = $num*($page-1) . ',' . $num; |
|
160 | + $limit = $num * ($page - 1) . ',' . $num; |
|
161 | 161 | |
162 | 162 | // We're getting the most recent comments posted to epobjects. |
163 | 163 | // We're grouping them by epobject so we can just link to each hansard thing once. |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | |
194 | 194 | if ($q->rows() > 0) { |
195 | 195 | |
196 | - for ($n=0; $n<$q->rows(); $n++) { |
|
196 | + for ($n = 0; $n < $q->rows(); $n++) { |
|
197 | 197 | |
198 | 198 | // All the basic stuff... |
199 | - $comments[$n] = array ( |
|
199 | + $comments[$n] = array( |
|
200 | 200 | 'comment_id' => $q->field($n, 'comment_id'), |
201 | 201 | 'posted' => $q->field($n, 'posted'), |
202 | 202 | 'total_comments' => $q->field($n, 'total_comments'), |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | ); |
209 | 209 | |
210 | 210 | // Add the URL... |
211 | - $urldata = array ( |
|
211 | + $urldata = array( |
|
212 | 212 | 'major' => $q->field($n, 'major'), |
213 | 213 | 'gid' => $q->field($n, 'gid'), |
214 | 214 | 'comment_id' => $q->field($n, 'comment_id'), |
@@ -234,14 +234,14 @@ discard block |
||
234 | 234 | |
235 | 235 | $commentbodies = array(); |
236 | 236 | |
237 | - for ($n=0; $n<$r->rows(); $n++) { |
|
238 | - $commentbodies[ $r->field($n, 'comment_id') ] = $r->field($n, 'body'); |
|
237 | + for ($n = 0; $n < $r->rows(); $n++) { |
|
238 | + $commentbodies[$r->field($n, 'comment_id')] = $r->field($n, 'body'); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | // This does rely on both this and the previous query returning |
242 | 242 | // stuff in the same order... |
243 | 243 | foreach ($comments as $n => $commentdata) { |
244 | - $comments[$n]['body'] = $commentbodies[ $comments[$n]['comment_id'] ]; |
|
244 | + $comments[$n]['body'] = $commentbodies[$comments[$n]['comment_id']]; |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | } |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | // $args should contain 'num', indicating how many to get. |
262 | 262 | // and perhaps pid too, for a particular person |
263 | 263 | |
264 | - twfy_debug (get_class($this), "getting data by recent"); |
|
264 | + twfy_debug(get_class($this), "getting data by recent"); |
|
265 | 265 | |
266 | 266 | // What we return. |
267 | 267 | $data = array(); |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | $page = 1; |
279 | 279 | } |
280 | 280 | |
281 | - $limit = $num*($page-1) . ',' . $num; |
|
281 | + $limit = $num * ($page - 1) . ',' . $num; |
|
282 | 282 | |
283 | 283 | $where = array( |
284 | 284 | 'visible=' => '1' |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | if (isset($args['pid']) && is_numeric($args['pid'])) { |
287 | 287 | $where['person_id='] = $args['pid']; |
288 | 288 | } |
289 | - $input = array ( |
|
290 | - 'amount' => array ( |
|
289 | + $input = array( |
|
290 | + 'amount' => array( |
|
291 | 291 | 'user' => true |
292 | 292 | ), |
293 | 293 | 'where' => $where, |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | $data['pid'] = $args['pid']; |
306 | 306 | $q = 'SELECT title, given_name, family_name, lordofname, house FROM member m, person_names p WHERE m.person_id=p.person_id AND p.type="name" AND left_house="9999-12-31" AND m.person_id = :pid'; |
307 | 307 | $q = $this->db->query($q, array(':pid' => $args['pid'])); |
308 | - $data['full_name'] = member_full_name($q->field(0, 'house'), $q->field(0, 'title'), $q->field(0, 'given_name'), $q->field(0, 'family_name'), $q->field(0,'lordofname')); |
|
308 | + $data['full_name'] = member_full_name($q->field(0, 'house'), $q->field(0, 'title'), $q->field(0, 'given_name'), $q->field(0, 'family_name'), $q->field(0, 'lordofname')); |
|
309 | 309 | $q = 'SELECT COUNT(*) AS count FROM comments,hansard WHERE visible=1 AND comments.epobject_id = hansard.epobject_id and hansard.person_id = :pid'; |
310 | 310 | $params[':pid'] = $args['pid']; |
311 | 311 | } else { |
@@ -319,15 +319,15 @@ discard block |
||
319 | 319 | public function _get_data_by_dates($args) { |
320 | 320 | // $args should contain start_date and end_date |
321 | 321 | |
322 | - twfy_debug (get_class($this), "getting data by recent"); |
|
322 | + twfy_debug(get_class($this), "getting data by recent"); |
|
323 | 323 | $data = array(); |
324 | 324 | $where = array( |
325 | 325 | 'visible=' => '1', |
326 | 326 | 'date(posted)>=' => $args['start_date'], |
327 | 327 | 'date(posted)<=' => $args['end_date'] |
328 | 328 | ); |
329 | - $input = array ( |
|
330 | - 'amount' => array ( |
|
329 | + $input = array( |
|
330 | + 'amount' => array( |
|
331 | 331 | 'user' => true |
332 | 332 | ), |
333 | 333 | 'where' => $where, |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | public function _get_data_by_search($args) { |
342 | 342 | // $args should contain 'num', indicating how many to get. |
343 | 343 | |
344 | - twfy_debug (get_class($this), "getting data by search"); |
|
344 | + twfy_debug(get_class($this), "getting data by search"); |
|
345 | 345 | |
346 | 346 | // What we return. |
347 | 347 | $data = array(); |
@@ -358,13 +358,13 @@ discard block |
||
358 | 358 | $page = 1; |
359 | 359 | } |
360 | 360 | |
361 | - $limit = $num*($page-1) . ',' . $num; |
|
361 | + $limit = $num * ($page - 1) . ',' . $num; |
|
362 | 362 | |
363 | - $input = array ( |
|
364 | - 'amount' => array ( |
|
363 | + $input = array( |
|
364 | + 'amount' => array( |
|
365 | 365 | 'user'=> true |
366 | 366 | ), |
367 | - 'where' => array ( |
|
367 | + 'where' => array( |
|
368 | 368 | 'comments.body LIKE' => "%$args[s]%" |
369 | 369 | ), |
370 | 370 | 'order' => 'posted DESC', |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | // It returns the URL for the comment. |
392 | 392 | |
393 | 393 | $major = $urldata['major']; |
394 | - $gid = $urldata['gid']; |
|
394 | + $gid = $urldata['gid']; |
|
395 | 395 | $comment_id = $urldata['comment_id']; |
396 | 396 | $user_id = isset($urldata['user_id']) ? $urldata['user_id'] : false; |
397 | 397 | |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | $URL = new \MySociety\TheyWorkForYou\Url($page); |
406 | 406 | |
407 | 407 | $gid = fix_gid_from_db($gid); // In includes/utility.php |
408 | - $URL->insert(array('id' => $gid )); |
|
408 | + $URL->insert(array('id' => $gid)); |
|
409 | 409 | if ($user_id) { |
410 | 410 | $URL->insert(array('u' => $user_id)); |
411 | 411 | } |
@@ -483,9 +483,9 @@ discard block |
||
483 | 483 | $limit = isset($input['limit']) ? $input['limit'] : ''; |
484 | 484 | |
485 | 485 | // The fields to fetch from db. 'table' => array ('field1', 'field2'). |
486 | - $fieldsarr = array ( |
|
487 | - 'comments' => array ('comment_id', 'user_id', 'epobject_id', 'body', 'posted', 'modflagged', 'visible'), |
|
488 | - 'hansard' => array ('major', 'gid') |
|
486 | + $fieldsarr = array( |
|
487 | + 'comments' => array('comment_id', 'user_id', 'epobject_id', 'body', 'posted', 'modflagged', 'visible'), |
|
488 | + 'hansard' => array('major', 'gid') |
|
489 | 489 | ); |
490 | 490 | |
491 | 491 | // Yes, we need the gid of a comment's associated hansard object |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | |
497 | 497 | // Add on the stuff for getting a user's details. |
498 | 498 | if (isset($amount['user']) && $amount['user'] == true) { |
499 | - $fieldsarr['users'] = array ('firstname', 'lastname', 'user_id'); |
|
499 | + $fieldsarr['users'] = array('firstname', 'lastname', 'user_id'); |
|
500 | 500 | // Like doing "FROM comments, users" but it's easier to add |
501 | 501 | // an "INNER JOIN..." automatically to the query. |
502 | 502 | $join .= ' INNER JOIN users ON comments.user_id = users.user_id '; |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | $fieldsarr['epobject'] = array('body'); |
508 | 508 | } |
509 | 509 | |
510 | - $fieldsarr2 = array (); |
|
510 | + $fieldsarr2 = array(); |
|
511 | 511 | // Construct the $fields clause. |
512 | 512 | foreach ($fieldsarr as $table => $tablesfields) { |
513 | 513 | foreach ($tablesfields as $n => $field) { |
@@ -518,13 +518,13 @@ discard block |
||
518 | 518 | if ($table == 'epobject' && $field == 'body') { |
519 | 519 | $field .= ' AS hbody'; |
520 | 520 | } |
521 | - $fieldsarr2[] = $table.'.'.$field; |
|
521 | + $fieldsarr2[] = $table . '.' . $field; |
|
522 | 522 | } |
523 | 523 | } |
524 | 524 | $fields = implode(', ', $fieldsarr2); |
525 | 525 | |
526 | 526 | |
527 | - $wherearr2 = array (); |
|
527 | + $wherearr2 = array(); |
|
528 | 528 | $params = array(); |
529 | 529 | $i = 0; |
530 | 530 | // Construct the $where clause. |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | $params[":where$i"] = $val; |
534 | 534 | $i++; |
535 | 535 | } |
536 | - $where = implode (" AND ", $wherearr2); |
|
536 | + $where = implode(" AND ", $wherearr2); |
|
537 | 537 | |
538 | 538 | if ($order != '') { |
539 | 539 | $order = "ORDER BY $order"; |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | } |
545 | 545 | |
546 | 546 | // Finally, do the query! |
547 | - $q = $this->db->query ("SELECT $fields |
|
547 | + $q = $this->db->query("SELECT $fields |
|
548 | 548 | FROM comments |
549 | 549 | $join |
550 | 550 | WHERE $where |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | ", $params); |
554 | 554 | |
555 | 555 | // Format the data into an array for returning. |
556 | - $data = array (); |
|
556 | + $data = array(); |
|
557 | 557 | |
558 | 558 | if ($q->rows() > 0) { |
559 | 559 | |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | // We'll generate permalinks for each comment. |
564 | 564 | // Assuming every comment is from the same major... |
565 | 565 | |
566 | - for ($n=0; $n<$q->rows(); $n++) { |
|
566 | + for ($n = 0; $n < $q->rows(); $n++) { |
|
567 | 567 | |
568 | 568 | // Put each row returned into its own array in $data. |
569 | 569 | foreach ($fieldsarr as $table => $tablesfields) { |
@@ -114,6 +114,9 @@ discard block |
||
114 | 114 | |
115 | 115 | |
116 | 116 | |
117 | + /** |
|
118 | + * @param string $view |
|
119 | + */ |
|
117 | 120 | public function display ($view, $args=array(), $format='html') { |
118 | 121 | |
119 | 122 | // $view is what we're viewing by: |
@@ -726,6 +729,10 @@ discard block |
||
726 | 729 | |
727 | 730 | } |
728 | 731 | |
732 | + /** |
|
733 | + * @param string $from |
|
734 | + * @param string $to |
|
735 | + */ |
|
729 | 736 | private function check_gid_change($gid, $from, $to) { |
730 | 737 | $input = array ( |
731 | 738 | 'amount' => array ( |
@@ -1610,6 +1617,9 @@ discard block |
||
1610 | 1617 | |
1611 | 1618 | } |
1612 | 1619 | |
1620 | + /** |
|
1621 | + * @param string $spid |
|
1622 | + */ |
|
1613 | 1623 | public function _get_mentions($spid) { |
1614 | 1624 | $result = array(); |
1615 | 1625 | $q = $this->db->query("select gid, type, date, url, mentioned_gid |
@@ -2622,6 +2632,9 @@ discard block |
||
2622 | 2632 | public $commentspage = 'spwrans'; |
2623 | 2633 | public $gidprefix = 'uk.org.publicwhip/spwa/'; |
2624 | 2634 | |
2635 | + /** |
|
2636 | + * @return string |
|
2637 | + */ |
|
2625 | 2638 | public function get_gid_from_spid($spid) { |
2626 | 2639 | // Fix the common errors of S.0 instead of S.O and leading |
2627 | 2640 | // zeros in the numbers: |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | // Linking to the prev (sub)section. |
431 | 431 | $thing = $hansardmajors[$this->major]['singular']; |
432 | 432 | $nextprevdata['prev'] = array ( |
433 | - 'body' => "Previous $thing", |
|
433 | + 'body' => "previous $thing", |
|
434 | 434 | 'url' => $prevdata[0]['listurl'], |
435 | 435 | 'title' => $prevdata[0]['body'] |
436 | 436 | ); |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | // Linking to the next (sub)section. |
475 | 475 | $thing = $hansardmajors[$this->major]['singular']; |
476 | 476 | $nextprevdata['next'] = array ( |
477 | - 'body' => "Next $thing", |
|
477 | + 'body' => "next $thing", |
|
478 | 478 | 'url' => $nextdata[0]['listurl'], |
479 | 479 | 'title' => $nextdata[0]['body'] |
480 | 480 | ); |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | $URL->remove(array('id')); |
511 | 511 | $things = $hansardmajors[$itemdata['major']]['title']; |
512 | 512 | $nextprevdata['up'] = array( |
513 | - 'body' => "All $things on " . format_date($itemdata['hdate'], SHORTDATEFORMAT), |
|
513 | + 'body' => "all $things on " . format_date($itemdata['hdate'], SHORTDATEFORMAT), |
|
514 | 514 | 'title' => '', |
515 | 515 | 'url' => $URL->generate() |
516 | 516 | ); |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | |
560 | 560 | // The '!= NULL' bit is needed otherwise I was getting errors |
561 | 561 | // when displaying the first day of debates. |
562 | - if ($q->rows() > 0 && $q->field(0, 'hdate') != NULL) { |
|
562 | + if ($q->rows() > 0 && $q->field(0, 'hdate') != null) { |
|
563 | 563 | |
564 | 564 | $URL->insert( array( 'd'=>$q->field(0, 'hdate') ) ); |
565 | 565 | |
@@ -1403,7 +1403,7 @@ discard block |
||
1403 | 1403 | WHERE major = :major", |
1404 | 1404 | array(':major' => $this->major)); |
1405 | 1405 | |
1406 | - if ($q->field(0, 'hdate') != NULL) { |
|
1406 | + if ($q->field(0, 'hdate') != null) { |
|
1407 | 1407 | $recentdate = $q->field(0, 'hdate'); |
1408 | 1408 | } else { |
1409 | 1409 | $PAGE->error_message("Couldn't find the most recent date"); |
@@ -1724,7 +1724,7 @@ discard block |
||
1724 | 1724 | } |
1725 | 1725 | |
1726 | 1726 | // Finally, do the query! |
1727 | - $q = $this->db->query ("SELECT $fields |
|
1727 | + $q = $this->db->query ("select $fields |
|
1728 | 1728 | FROM hansard |
1729 | 1729 | $join |
1730 | 1730 | WHERE $where |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -include_once INCLUDESPATH."easyparliament/searchengine.php"; |
|
4 | -include_once INCLUDESPATH."easyparliament/searchlog.php"; |
|
3 | +include_once INCLUDESPATH . "easyparliament/searchengine.php"; |
|
4 | +include_once INCLUDESPATH . "easyparliament/searchlog.php"; |
|
5 | 5 | |
6 | 6 | /* |
7 | 7 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | class HANSARDLIST { |
54 | 54 | // This will be used to cache information about speakers on this page |
55 | 55 | // so we don't have to keep fetching the same data from the DB. |
56 | - public $speakers = array (); |
|
56 | + public $speakers = array(); |
|
57 | 57 | /* |
58 | 58 | $this->speakers[ $person_id ] = array ( |
59 | 59 | "name" => $name, |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | |
67 | 67 | // This will be used to cache mappings from epobject_id to gid, |
68 | 68 | // so we don't have to continually fetch the same data in get_hansard_data(). |
69 | - public $epobjectid_to_gid = array (); |
|
69 | + public $epobjectid_to_gid = array(); |
|
70 | 70 | /* |
71 | 71 | $this->epobjectid_to_gid[ $epobject_id ] => $gid; |
72 | 72 | */ |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | |
115 | 115 | |
116 | 116 | |
117 | - public function display ($view, $args=array(), $format='html') { |
|
117 | + public function display($view, $args = array(), $format = 'html') { |
|
118 | 118 | |
119 | 119 | // $view is what we're viewing by: |
120 | 120 | // 'gid' is the gid of a hansard object, |
@@ -141,17 +141,17 @@ discard block |
||
141 | 141 | if ($view == 'search' && (!defined('FRONT_END_SEARCH') || !FRONT_END_SEARCH)) |
142 | 142 | return false; |
143 | 143 | |
144 | - $validviews = array ('calendar', 'date', 'gid', 'person', 'search', 'search_min', 'search_video', 'recent', 'recent_mostvotes', 'biggest_debates', 'recent_wrans', 'recent_wms', 'column', 'mp', 'bill', 'session', 'recent_debates', 'recent_pbc_debates', 'featured_gid'); |
|
144 | + $validviews = array('calendar', 'date', 'gid', 'person', 'search', 'search_min', 'search_video', 'recent', 'recent_mostvotes', 'biggest_debates', 'recent_wrans', 'recent_wms', 'column', 'mp', 'bill', 'session', 'recent_debates', 'recent_pbc_debates', 'featured_gid'); |
|
145 | 145 | if (in_array($view, $validviews)) { |
146 | 146 | |
147 | 147 | // What function do we call for this view? |
148 | - $function = '_get_data_by_'.$view; |
|
148 | + $function = '_get_data_by_' . $view; |
|
149 | 149 | // Get all the data that's to be rendered. |
150 | 150 | $data = $this->$function($args); |
151 | 151 | |
152 | 152 | } else { |
153 | 153 | // Don't have a valid $view. |
154 | - $PAGE->error_message ("You haven't specified a view type."); |
|
154 | + $PAGE->error_message("You haven't specified a view type."); |
|
155 | 155 | return false; |
156 | 156 | } |
157 | 157 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | |
173 | 173 | |
174 | 174 | |
175 | - public function render($view, $data, $format='html') { |
|
175 | + public function render($view, $data, $format = 'html') { |
|
176 | 176 | // Once we have the data that's to be rendered, |
177 | 177 | // include the template. |
178 | 178 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | return $data; |
182 | 182 | } |
183 | 183 | |
184 | - include (INCLUDESPATH."easyparliament/templates/$format/hansard_$view" . ".php"); |
|
184 | + include (INCLUDESPATH . "easyparliament/templates/$format/hansard_$view" . ".php"); |
|
185 | 185 | return true; |
186 | 186 | |
187 | 187 | } |
@@ -226,13 +226,13 @@ discard block |
||
226 | 226 | $hdate = $q->field(0, 'hdate'); |
227 | 227 | if ($hdate) { |
228 | 228 | $URL = new \MySociety\TheyWorkForYou\Url($this->listpage); |
229 | - $URL->insert( array('d'=>$hdate) ); |
|
229 | + $URL->insert(array('d'=>$hdate)); |
|
230 | 230 | |
231 | 231 | // Work out a timestamp which is handy for comparing to now. |
232 | 232 | list($year, $month, $date) = explode('-', $hdate); |
233 | - $timestamp = gmmktime (0, 0, 0, $month, $date, $year); |
|
233 | + $timestamp = gmmktime(0, 0, 0, $month, $date, $year); |
|
234 | 234 | |
235 | - $data = array ( |
|
235 | + $data = array( |
|
236 | 236 | 'hdate' => $hdate, |
237 | 237 | 'timestamp' => $timestamp, |
238 | 238 | 'listurl' => $URL->generate() |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | // Pass it an array of data about an item and it will return an |
267 | 267 | // array of data about the item's section heading. |
268 | 268 | |
269 | - twfy_debug (get_class($this), "getting an item's section"); |
|
269 | + twfy_debug(get_class($this), "getting an item's section"); |
|
270 | 270 | |
271 | 271 | if ($itemdata['htype'] != '10') { |
272 | 272 | |
@@ -275,11 +275,11 @@ discard block |
||
275 | 275 | // so get the section info above this item. |
276 | 276 | |
277 | 277 | // For getting hansard data. |
278 | - $input = array ( |
|
279 | - 'amount' => array ( |
|
278 | + $input = array( |
|
279 | + 'amount' => array( |
|
280 | 280 | 'body' => true |
281 | 281 | ), |
282 | - 'where' => array ( |
|
282 | + 'where' => array( |
|
283 | 283 | 'hansard.epobject_id=' => $itemdata['section_id'] |
284 | 284 | ) |
285 | 285 | ); |
@@ -306,21 +306,21 @@ discard block |
||
306 | 306 | // Pass it an array of data about an item and it will return an |
307 | 307 | // array of data about the item's subsection heading. |
308 | 308 | |
309 | - twfy_debug (get_class($this), "getting an item's subsection"); |
|
309 | + twfy_debug(get_class($this), "getting an item's subsection"); |
|
310 | 310 | |
311 | 311 | // What we return. |
312 | - $subsectiondata = array (); |
|
312 | + $subsectiondata = array(); |
|
313 | 313 | |
314 | 314 | if ($itemdata['htype'] == '12' || $itemdata['htype'] == '13') { |
315 | 315 | // This item is a speech or procedural, so get the |
316 | 316 | // subsection info above this item. |
317 | 317 | |
318 | 318 | // For getting hansard data. |
319 | - $input = array ( |
|
320 | - 'amount' => array ( |
|
319 | + $input = array( |
|
320 | + 'amount' => array( |
|
321 | 321 | 'body' => true |
322 | 322 | ), |
323 | - 'where' => array ( |
|
323 | + 'where' => array( |
|
324 | 324 | 'hansard.epobject_id=' => $itemdata['subsection_id'] |
325 | 325 | ) |
326 | 326 | ); |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | // Pass it an array of item info, of a section/subsection, and this will return |
348 | 348 | // data for the next/prev items. |
349 | 349 | |
350 | - twfy_debug (get_class($this), "getting next/prev items"); |
|
350 | + twfy_debug(get_class($this), "getting next/prev items"); |
|
351 | 351 | |
352 | 352 | // What we return. |
353 | 353 | $nextprevdata = array(); |
@@ -413,8 +413,8 @@ discard block |
||
413 | 413 | $wherearr['hansard.epobject_id='] = $prev_item_id; |
414 | 414 | |
415 | 415 | // For getting hansard data. |
416 | - $input = array ( |
|
417 | - 'amount' => array ( |
|
416 | + $input = array( |
|
417 | + 'amount' => array( |
|
418 | 418 | 'body' => true, |
419 | 419 | 'speaker' => true |
420 | 420 | ), |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | if ($itemdata['htype'] == '10' || $itemdata['htype'] == '11') { |
430 | 430 | // Linking to the prev (sub)section. |
431 | 431 | $thing = $hansardmajors[$this->major]['singular']; |
432 | - $nextprevdata['prev'] = array ( |
|
432 | + $nextprevdata['prev'] = array( |
|
433 | 433 | 'body' => "Previous $thing", |
434 | 434 | 'url' => $prevdata[0]['listurl'], |
435 | 435 | 'title' => $prevdata[0]['body'] |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | } else { |
443 | 443 | $title = ''; |
444 | 444 | } |
445 | - $nextprevdata['prev'] = array ( |
|
445 | + $nextprevdata['prev'] = array( |
|
446 | 446 | 'body' => 'Previous speaker', |
447 | 447 | 'url' => $prevdata[0]['commentsurl'], |
448 | 448 | 'title' => $title |
@@ -458,8 +458,8 @@ discard block |
||
458 | 458 | $wherearr['hansard.epobject_id='] = $next_item_id; |
459 | 459 | |
460 | 460 | // For getting hansard data. |
461 | - $input = array ( |
|
462 | - 'amount' => array ( |
|
461 | + $input = array( |
|
462 | + 'amount' => array( |
|
463 | 463 | 'body' => true, |
464 | 464 | 'speaker' => true |
465 | 465 | ), |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | if ($itemdata['htype'] == '10' || $itemdata['htype'] == '11') { |
474 | 474 | // Linking to the next (sub)section. |
475 | 475 | $thing = $hansardmajors[$this->major]['singular']; |
476 | - $nextprevdata['next'] = array ( |
|
476 | + $nextprevdata['next'] = array( |
|
477 | 477 | 'body' => "Next $thing", |
478 | 478 | 'url' => $nextdata[0]['listurl'], |
479 | 479 | 'title' => $nextdata[0]['body'] |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | } else { |
487 | 487 | $title = ''; |
488 | 488 | } |
489 | - $nextprevdata['next'] = array ( |
|
489 | + $nextprevdata['next'] = array( |
|
490 | 490 | 'body' => 'Next speaker', |
491 | 491 | 'url' => $nextdata[0]['commentsurl'], |
492 | 492 | 'title' => $title |
@@ -530,14 +530,14 @@ discard block |
||
530 | 530 | // containing the next/prev dates that contain items from |
531 | 531 | // $this->major of hansard object. |
532 | 532 | |
533 | - twfy_debug (get_class($this), "getting next/prev dates"); |
|
533 | + twfy_debug(get_class($this), "getting next/prev dates"); |
|
534 | 534 | |
535 | 535 | // What we return. |
536 | - $nextprevdata = array (); |
|
536 | + $nextprevdata = array(); |
|
537 | 537 | |
538 | 538 | $URL = new \MySociety\TheyWorkForYou\Url($this->listpage); |
539 | 539 | |
540 | - $looper = array ("next", "prev"); |
|
540 | + $looper = array("next", "prev"); |
|
541 | 541 | |
542 | 542 | foreach ($looper as $n => $nextorprev) { |
543 | 543 | |
@@ -561,7 +561,7 @@ discard block |
||
561 | 561 | // when displaying the first day of debates. |
562 | 562 | if ($q->rows() > 0 && $q->field(0, 'hdate') != NULL) { |
563 | 563 | |
564 | - $URL->insert( array( 'd'=>$q->field(0, 'hdate') ) ); |
|
564 | + $URL->insert(array('d'=>$q->field(0, 'hdate'))); |
|
565 | 565 | |
566 | 566 | if ($nextorprev == 'next') { |
567 | 567 | $body = 'Next day'; |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | |
572 | 572 | $title = format_date($q->field(0, 'hdate'), SHORTDATEFORMAT); |
573 | 573 | |
574 | - $nextprevdata[$nextorprev] = array ( |
|
574 | + $nextprevdata[$nextorprev] = array( |
|
575 | 575 | 'hdate' => $q->field(0, 'hdate'), |
576 | 576 | 'url' => $URL->generate(), |
577 | 577 | 'body' => $body, |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | $thing = $hansardmajors[$this->major]['plural']; |
586 | 586 | $URL->insert(array('y'=>$year)); |
587 | 587 | |
588 | - $nextprevdata['up'] = array ( |
|
588 | + $nextprevdata['up'] = array( |
|
589 | 589 | 'body' => "All of $year's $thing", |
590 | 590 | 'title' => '', |
591 | 591 | 'url' => $URL->generate() |
@@ -606,19 +606,19 @@ discard block |
||
606 | 606 | if (isset($args['date'])) { |
607 | 607 | $date = $args['date']; |
608 | 608 | } else { |
609 | - $PAGE->error_message ("Sorry, we don't have a date."); |
|
609 | + $PAGE->error_message("Sorry, we don't have a date."); |
|
610 | 610 | return false; |
611 | 611 | } |
612 | 612 | |
613 | 613 | if (!preg_match("/^(\d\d\d\d)-(\d{1,2})-(\d{1,2})$/", $date, $matches)) { |
614 | - $PAGE->error_message ("Sorry, '" . _htmlentities($date) . "' isn't of the right format (YYYY-MM-DD)."); |
|
614 | + $PAGE->error_message("Sorry, '" . _htmlentities($date) . "' isn't of the right format (YYYY-MM-DD)."); |
|
615 | 615 | return false; |
616 | 616 | } |
617 | 617 | |
618 | 618 | list(, $year, $month, $day) = $matches; |
619 | 619 | |
620 | 620 | if (!checkdate($month, $day, $year)) { |
621 | - $PAGE->error_message ("Sorry, '" . _htmlentities($date) . "' isn't a valid date."); |
|
621 | + $PAGE->error_message("Sorry, '" . _htmlentities($date) . "' isn't a valid date."); |
|
622 | 622 | return false; |
623 | 623 | } |
624 | 624 | |
@@ -636,29 +636,29 @@ discard block |
||
636 | 636 | global $PAGE; |
637 | 637 | |
638 | 638 | if (!isset($args['gid']) && $args['gid'] == '') { |
639 | - $PAGE->error_message ("Sorry, we don't have an item gid."); |
|
639 | + $PAGE->error_message("Sorry, we don't have an item gid."); |
|
640 | 640 | return false; |
641 | 641 | } |
642 | 642 | |
643 | 643 | |
644 | 644 | // Get all the data just for this epobject_id. |
645 | - $input = array ( |
|
646 | - 'amount' => array ( |
|
645 | + $input = array( |
|
646 | + 'amount' => array( |
|
647 | 647 | 'body' => true, |
648 | 648 | 'speaker' => true, |
649 | 649 | 'comment' => true, |
650 | 650 | 'votes' => true |
651 | 651 | ), |
652 | - 'where' => array ( |
|
652 | + 'where' => array( |
|
653 | 653 | // Need to add the 'uk.org.publicwhip/debate/' or whatever on before |
654 | 654 | // looking in the DB. |
655 | 655 | 'gid=' => $this->gidprefix . $args['gid'] |
656 | 656 | ) |
657 | 657 | ); |
658 | 658 | |
659 | - twfy_debug (get_class($this), "looking for redirected gid"); |
|
659 | + twfy_debug(get_class($this), "looking for redirected gid"); |
|
660 | 660 | $gid = $this->gidprefix . $args['gid']; |
661 | - $q = $this->db->query ("SELECT gid_to FROM gidredirect WHERE gid_from = :gid", array(':gid' => $gid)); |
|
661 | + $q = $this->db->query("SELECT gid_to FROM gidredirect WHERE gid_from = :gid", array(':gid' => $gid)); |
|
662 | 662 | if ($q->rows() == 0) { |
663 | 663 | $itemdata = $this->_get_hansard_data($input); |
664 | 664 | } else { |
@@ -666,10 +666,10 @@ discard block |
||
666 | 666 | $gid = $q->field(0, 'gid_to'); |
667 | 667 | $q = $this->db->query("SELECT gid_to FROM gidredirect WHERE gid_from = :gid", array(':gid' => $gid)); |
668 | 668 | } while ($q->rows() > 0); |
669 | - twfy_debug (get_class($this), "found redirected gid $gid" ); |
|
669 | + twfy_debug(get_class($this), "found redirected gid $gid"); |
|
670 | 670 | $input['where'] = array('gid=' => $gid); |
671 | 671 | $itemdata = $this->_get_hansard_data($input); |
672 | - if (count($itemdata) > 0 ) { |
|
672 | + if (count($itemdata) > 0) { |
|
673 | 673 | throw new RedirectException(fix_gid_from_db($gid)); |
674 | 674 | } |
675 | 675 | } |
@@ -683,9 +683,9 @@ discard block |
||
683 | 683 | $this->check_gid_change($args['gid'], 'a', ''); |
684 | 684 | |
685 | 685 | if (substr($args['gid'], -1) == 'L') { |
686 | - $letts = array('a','b','c','d','e'); |
|
687 | - for ($i=0; $i<4; $i++) { |
|
688 | - $this->check_gid_change($args['gid'], $letts[$i], $letts[$i+1]); |
|
686 | + $letts = array('a', 'b', 'c', 'd', 'e'); |
|
687 | + for ($i = 0; $i < 4; $i++) { |
|
688 | + $this->check_gid_change($args['gid'], $letts[$i], $letts[$i + 1]); |
|
689 | 689 | } |
690 | 690 | } |
691 | 691 | |
@@ -718,7 +718,7 @@ discard block |
||
718 | 718 | # $u = $q->field(0, 'source_url'); |
719 | 719 | # $u = '<br><a href="'. $u . '">' . $u . '</a>'; |
720 | 720 | #} |
721 | - $PAGE->error_message ("Sorry, there is no Hansard object with a gid of '" . _htmlentities($args['gid']) . "'."); |
|
721 | + $PAGE->error_message("Sorry, there is no Hansard object with a gid of '" . _htmlentities($args['gid']) . "'."); |
|
722 | 722 | return false; |
723 | 723 | } |
724 | 724 | |
@@ -727,8 +727,8 @@ discard block |
||
727 | 727 | } |
728 | 728 | |
729 | 729 | private function check_gid_change($gid, $from, $to) { |
730 | - $input = array ( |
|
731 | - 'amount' => array ( |
|
730 | + $input = array( |
|
731 | + 'amount' => array( |
|
732 | 732 | 'body' => true, |
733 | 733 | 'speaker' => true, |
734 | 734 | 'comment' => true, |
@@ -752,10 +752,10 @@ discard block |
||
752 | 752 | |
753 | 753 | global $DATA, $this_page; |
754 | 754 | |
755 | - twfy_debug (get_class($this), "getting data by date"); |
|
755 | + twfy_debug(get_class($this), "getting data by date"); |
|
756 | 756 | |
757 | 757 | // Where we'll put all the data we want to render. |
758 | - $data = array (); |
|
758 | + $data = array(); |
|
759 | 759 | |
760 | 760 | $date = $this->_validate_date($args); |
761 | 761 | |
@@ -769,13 +769,13 @@ discard block |
||
769 | 769 | |
770 | 770 | // Get all the sections for this date. |
771 | 771 | // Then for each of those we'll get the subsections and rows. |
772 | - $input = array ( |
|
773 | - 'amount' => array ( |
|
772 | + $input = array( |
|
773 | + 'amount' => array( |
|
774 | 774 | 'body' => true, |
775 | 775 | 'comment' => true, |
776 | 776 | 'excerpt' => true |
777 | 777 | ), |
778 | - 'where' => array ( |
|
778 | + 'where' => array( |
|
779 | 779 | 'hdate=' => "$date", |
780 | 780 | 'htype=' => '10', |
781 | 781 | 'major=' => $this->major |
@@ -791,20 +791,20 @@ discard block |
||
791 | 791 | $data['rows'] = array(); |
792 | 792 | |
793 | 793 | $num_sections = count($sections); |
794 | - for ($n=0; $n<$num_sections; $n++) { |
|
794 | + for ($n = 0; $n < $num_sections; $n++) { |
|
795 | 795 | // For each section on this date, get the subsections within it. |
796 | 796 | |
797 | 797 | // Get all the section data. |
798 | 798 | $sectionrow = $this->_get_section($sections[$n]); |
799 | 799 | |
800 | 800 | // Get the subsections within the section. |
801 | - $input = array ( |
|
802 | - 'amount' => array ( |
|
801 | + $input = array( |
|
802 | + 'amount' => array( |
|
803 | 803 | 'body' => true, |
804 | 804 | 'comment' => true, |
805 | 805 | 'excerpt' => true |
806 | 806 | ), |
807 | - 'where' => array ( |
|
807 | + 'where' => array( |
|
808 | 808 | 'section_id=' => $sections[$n]['epobject_id'], |
809 | 809 | 'htype=' => '11', |
810 | 810 | 'major=' => $this->major |
@@ -815,10 +815,10 @@ discard block |
||
815 | 815 | $rows = $this->_get_hansard_data($input); |
816 | 816 | |
817 | 817 | // Put the section at the top of the rows array. |
818 | - array_unshift ($rows, $sectionrow); |
|
818 | + array_unshift($rows, $sectionrow); |
|
819 | 819 | |
820 | 820 | // Add the section heading and the subsections to the full list. |
821 | - $data['rows'] = array_merge ($data['rows'], $rows); |
|
821 | + $data['rows'] = array_merge($data['rows'], $rows); |
|
822 | 822 | } |
823 | 823 | } |
824 | 824 | |
@@ -854,9 +854,9 @@ discard block |
||
854 | 854 | $major = ''; |
855 | 855 | } |
856 | 856 | |
857 | - $data = array (); |
|
857 | + $data = array(); |
|
858 | 858 | |
859 | - $q = $this->db->query ("SELECT DISTINCT(hdate) |
|
859 | + $q = $this->db->query("SELECT DISTINCT(hdate) |
|
860 | 860 | FROM hansard |
861 | 861 | $major |
862 | 862 | ORDER BY hdate DESC |
@@ -867,7 +867,7 @@ discard block |
||
867 | 867 | |
868 | 868 | $URL = new \MySociety\TheyWorkForYou\Url($this->listpage); |
869 | 869 | |
870 | - for ($n=0; $n<$q->rows(); $n++) { |
|
870 | + for ($n = 0; $n < $q->rows(); $n++) { |
|
871 | 871 | $rowdata = array(); |
872 | 872 | |
873 | 873 | $rowdata['body'] = format_date($q->field($n, 'hdate'), SHORTDATEFORMAT); |
@@ -896,7 +896,7 @@ discard block |
||
896 | 896 | $data = array(); |
897 | 897 | |
898 | 898 | if (!isset($args['person_id'])) { |
899 | - $PAGE->error_message ("Sorry, we need a valid person ID."); |
|
899 | + $PAGE->error_message("Sorry, we need a valid person ID."); |
|
900 | 900 | return $data; |
901 | 901 | } |
902 | 902 | |
@@ -936,8 +936,8 @@ discard block |
||
936 | 936 | |
937 | 937 | $speeches = array(); |
938 | 938 | if ($q->rows() > 0) { |
939 | - for ($n=0; $n<$q->rows(); $n++) { |
|
940 | - $speech = array ( |
|
939 | + for ($n = 0; $n < $q->rows(); $n++) { |
|
940 | + $speech = array( |
|
941 | 941 | 'subsection_id' => $q->field($n, 'subsection_id'), |
942 | 942 | 'section_id' => $q->field($n, 'section_id'), |
943 | 943 | 'htype' => $q->field($n, 'htype'), |
@@ -952,9 +952,9 @@ discard block |
||
952 | 952 | 'gid' => fix_gid_from_db($q->field($n, 'gid')), |
953 | 953 | ); |
954 | 954 | // Cache parent id to speed up _get_listurl |
955 | - $this->epobjectid_to_gid[$q->field($n, 'subsection_id') ] = fix_gid_from_db( $q->field($n, 'gid_subsection') ); |
|
955 | + $this->epobjectid_to_gid[$q->field($n, 'subsection_id')] = fix_gid_from_db($q->field($n, 'gid_subsection')); |
|
956 | 956 | |
957 | - $url_args = array ('p'=>$q->field($n, 'person_id')); |
|
957 | + $url_args = array('p'=>$q->field($n, 'person_id')); |
|
958 | 958 | $speech['listurl'] = $this->_get_listurl($speech, $url_args); |
959 | 959 | $speeches[] = $speech; |
960 | 960 | } |
@@ -963,7 +963,7 @@ discard block |
||
963 | 963 | if (count($speeches) > 0) { |
964 | 964 | // Get the subsection texts. |
965 | 965 | $num_speeches = count($speeches); |
966 | - for ($n=0; $n<$num_speeches; $n++) { |
|
966 | + for ($n = 0; $n < $num_speeches; $n++) { |
|
967 | 967 | $thing = $hansardmajors[$speeches[$n]['major']]['title']; |
968 | 968 | // Add the parent's body on... |
969 | 969 | $speeches[$n]['parent']['body'] = $speeches[$n]['body_section'] . ' | ' . $thing; |
@@ -1001,7 +1001,7 @@ discard block |
||
1001 | 1001 | // eg, by doing filter_user_input($s, 'strict'); |
1002 | 1002 | $searchstring = $args['s']; |
1003 | 1003 | } else { |
1004 | - if ( isset($args['exceptions']) ) { |
|
1004 | + if (isset($args['exceptions'])) { |
|
1005 | 1005 | throw new \Exception('No search string provided.'); |
1006 | 1006 | } else { |
1007 | 1007 | $PAGE->error_message("No search string"); |
@@ -1010,14 +1010,14 @@ discard block |
||
1010 | 1010 | } |
1011 | 1011 | |
1012 | 1012 | // What we'll return. |
1013 | - $data = array (); |
|
1013 | + $data = array(); |
|
1014 | 1014 | |
1015 | 1015 | $data['info']['s'] = $args['s']; |
1016 | 1016 | |
1017 | 1017 | // Allows us to specify how many results we want |
1018 | 1018 | // Mainly for glossary term adding |
1019 | 1019 | if (isset($args['num']) && $args['num']) { |
1020 | - $results_per_page = $args['num']+0; |
|
1020 | + $results_per_page = $args['num'] + 0; |
|
1021 | 1021 | } |
1022 | 1022 | else { |
1023 | 1023 | $results_per_page = 20; |
@@ -1045,16 +1045,16 @@ discard block |
||
1045 | 1045 | global $SEARCHENGINE; |
1046 | 1046 | |
1047 | 1047 | // For Xapian's equivalent of an SQL LIMIT clause. |
1048 | - $first_result = ($page-1) * $results_per_page; |
|
1048 | + $first_result = ($page - 1) * $results_per_page; |
|
1049 | 1049 | $data['info']['first_result'] = $first_result + 1; // Take account of LIMIT's 0 base. |
1050 | 1050 | |
1051 | 1051 | // Get the gids from Xapian |
1052 | 1052 | $sort_order = 'date'; |
1053 | 1053 | if (isset($args['o'])) { |
1054 | - if ($args['o']=='d') $sort_order = 'newest'; |
|
1055 | - if ($args['o']=='o') $sort_order = 'oldest'; |
|
1056 | - elseif ($args['o']=='c') $sort_order = 'created'; |
|
1057 | - elseif ($args['o']=='r') $sort_order = 'relevance'; |
|
1054 | + if ($args['o'] == 'd') $sort_order = 'newest'; |
|
1055 | + if ($args['o'] == 'o') $sort_order = 'oldest'; |
|
1056 | + elseif ($args['o'] == 'c') $sort_order = 'created'; |
|
1057 | + elseif ($args['o'] == 'r') $sort_order = 'relevance'; |
|
1058 | 1058 | } |
1059 | 1059 | |
1060 | 1060 | $data['searchdescription'] = $SEARCHENGINE->query_description_long(); |
@@ -1064,7 +1064,7 @@ discard block |
||
1064 | 1064 | |
1065 | 1065 | // Log this query so we can improve them - if it wasn't a "popular |
1066 | 1066 | // query" link |
1067 | - if (! isset($args['pop']) or $args['pop'] != 1) { |
|
1067 | + if (!isset($args['pop']) or $args['pop'] != 1) { |
|
1068 | 1068 | global $SEARCHLOG; |
1069 | 1069 | $SEARCHLOG->add( |
1070 | 1070 | array('query' => $searchstring, |
@@ -1079,7 +1079,7 @@ discard block |
||
1079 | 1079 | |
1080 | 1080 | $SEARCHENGINE->run_search($first_result, $results_per_page, $sort_order); |
1081 | 1081 | $gids = $SEARCHENGINE->get_gids(); |
1082 | - if ($sort_order=='created') { |
|
1082 | + if ($sort_order == 'created') { |
|
1083 | 1083 | $createds = $SEARCHENGINE->get_createds(); |
1084 | 1084 | } |
1085 | 1085 | $relevances = $SEARCHENGINE->get_relevances(); |
@@ -1095,13 +1095,13 @@ discard block |
||
1095 | 1095 | |
1096 | 1096 | // Cycle through each result, munge the data, get more, and put it all in $data. |
1097 | 1097 | $num_gids = count($gids); |
1098 | - for ($n=0; $n<$num_gids; $n++) { |
|
1098 | + for ($n = 0; $n < $num_gids; $n++) { |
|
1099 | 1099 | $gid = $gids[$n]; |
1100 | 1100 | $relevancy = $relevances[$n]; |
1101 | 1101 | $collapsed = $SEARCHENGINE->collapsed[$n]; |
1102 | - if ($sort_order=='created') { |
|
1102 | + if ($sort_order == 'created') { |
|
1103 | 1103 | #$created = substr($createds[$n], 0, strpos($createds[$n], ':')); |
1104 | - if ($createds[$n]<$args['threshold']) { |
|
1104 | + if ($createds[$n] < $args['threshold']) { |
|
1105 | 1105 | $data['info']['total_results'] = $n; |
1106 | 1106 | break; |
1107 | 1107 | } |
@@ -1163,7 +1163,7 @@ discard block |
||
1163 | 1163 | , array(':gid' => $gid)); |
1164 | 1164 | |
1165 | 1165 | if ($q->rows() > 1) { |
1166 | - if ( $isset($args['exceptions']) ) { |
|
1166 | + if ($isset($args['exceptions'])) { |
|
1167 | 1167 | throw new \Exception("Got more than one row getting data for $gid."); |
1168 | 1168 | } else { |
1169 | 1169 | $PAGE->error_message("Got more than one row getting data for $gid"); |
@@ -1177,14 +1177,14 @@ discard block |
||
1177 | 1177 | |
1178 | 1178 | $itemdata = $q->row(0); |
1179 | 1179 | $itemdata['collapsed'] = $collapsed; |
1180 | - $itemdata['gid'] = fix_gid_from_db( $q->field(0, 'gid') ); |
|
1180 | + $itemdata['gid'] = fix_gid_from_db($q->field(0, 'gid')); |
|
1181 | 1181 | $itemdata['relevance'] = $relevancy; |
1182 | 1182 | $itemdata['extract'] = $this->prepare_search_result_for_display($q->field(0, 'body')); |
1183 | 1183 | |
1184 | 1184 | ////////////////////////// |
1185 | 1185 | // 2. Create the URL to link to this bit of text. |
1186 | 1186 | |
1187 | - $id_data = array ( |
|
1187 | + $id_data = array( |
|
1188 | 1188 | 'major' => $itemdata['major'], |
1189 | 1189 | 'minor' => $itemdata['minor'], |
1190 | 1190 | 'htype' => $itemdata['htype'], |
@@ -1195,7 +1195,7 @@ discard block |
||
1195 | 1195 | |
1196 | 1196 | // We append the query onto the end of the URL as variable 's' |
1197 | 1197 | // so we can highlight them on the debate/wrans list page. |
1198 | - $url_args = array ('s' => $searchstring); |
|
1198 | + $url_args = array('s' => $searchstring); |
|
1199 | 1199 | |
1200 | 1200 | $itemdata['listurl'] = $this->_get_listurl($id_data, $url_args, $encode); |
1201 | 1201 | |
@@ -1241,14 +1241,14 @@ discard block |
||
1241 | 1241 | if (isset($subsection['body'])) $body .= ': ' . $subsection['body']; |
1242 | 1242 | if (isset($subsection['listurl'])) $listurl = $subsection['listurl']; |
1243 | 1243 | else $listurl = ''; |
1244 | - $itemdata['parent'] = array ( |
|
1244 | + $itemdata['parent'] = array( |
|
1245 | 1245 | 'body' => $body, |
1246 | 1246 | 'listurl' => $listurl |
1247 | 1247 | ); |
1248 | 1248 | if ($itemdata['htype'] == 11) { |
1249 | 1249 | # Search result was a subsection heading; fetch the first entry |
1250 | 1250 | # from the wrans/wms to show under the heading |
1251 | - $input = array ( |
|
1251 | + $input = array( |
|
1252 | 1252 | 'amount' => array( |
1253 | 1253 | 'body' => true, |
1254 | 1254 | 'speaker' => true |
@@ -1303,7 +1303,7 @@ discard block |
||
1303 | 1303 | } |
1304 | 1304 | |
1305 | 1305 | // Trim it to length and position, adding ellipses. |
1306 | - $extract = trim_characters ($extract, $startpos, $length_of_extract); |
|
1306 | + $extract = trim_characters($extract, $startpos, $length_of_extract); |
|
1307 | 1307 | |
1308 | 1308 | // Highlight search words |
1309 | 1309 | $extract = $SEARCHENGINE->highlight($extract); |
@@ -1490,7 +1490,7 @@ discard block |
||
1490 | 1490 | |
1491 | 1491 | $params[':major'] = $this->major; |
1492 | 1492 | $params[':firstdate'] = $firstyear . '-' . $firstmonth . '-01'; |
1493 | - $q = $this->db->query("SELECT DISTINCT(hdate) AS hdate |
|
1493 | + $q = $this->db->query("SELECT DISTINCT(hdate) AS hdate |
|
1494 | 1494 | FROM hansard |
1495 | 1495 | WHERE major = :major |
1496 | 1496 | AND hdate >= :firstdate |
@@ -1503,7 +1503,7 @@ discard block |
||
1503 | 1503 | // We put the data in this array. See top of function for the structure. |
1504 | 1504 | $years = array(); |
1505 | 1505 | |
1506 | - for ($row=0; $row<$q->rows(); $row++) { |
|
1506 | + for ($row = 0; $row < $q->rows(); $row++) { |
|
1507 | 1507 | |
1508 | 1508 | list($year, $month, $day) = explode('-', $q->field($row, 'hdate')); |
1509 | 1509 | |
@@ -1557,9 +1557,9 @@ discard block |
||
1557 | 1557 | if ($action == 'recentyear') { |
1558 | 1558 | // Assuming there will be a previous year! |
1559 | 1559 | |
1560 | - $YEARURL->insert(array('y'=> $firstyear-1)); |
|
1560 | + $YEARURL->insert(array('y'=> $firstyear - 1)); |
|
1561 | 1561 | |
1562 | - $nextprev['prev'] = array ( |
|
1562 | + $nextprev['prev'] = array( |
|
1563 | 1563 | 'body' => 'Previous year', |
1564 | 1564 | 'title' => $firstyear - 1, |
1565 | 1565 | 'url' => $YEARURL->generate() |
@@ -1567,8 +1567,8 @@ discard block |
||
1567 | 1567 | |
1568 | 1568 | } else { // action is 'year'. |
1569 | 1569 | |
1570 | - $nextprev['prev'] = array ('body' => 'Previous year'); |
|
1571 | - $nextprev['next'] = array ('body' => 'Next year'); |
|
1570 | + $nextprev['prev'] = array('body' => 'Previous year'); |
|
1571 | + $nextprev['next'] = array('body' => 'Next year'); |
|
1572 | 1572 | |
1573 | 1573 | $q = $this->db->query("SELECT DATE_FORMAT(hdate, '%Y') AS year |
1574 | 1574 | FROM hansard WHERE major = :major |
@@ -1616,7 +1616,7 @@ discard block |
||
1616 | 1616 | from mentions where gid like 'uk.org.publicwhip/spq/$spid' |
1617 | 1617 | order by date, type"); |
1618 | 1618 | $nrows = $q->rows(); |
1619 | - for ($i=0; $i < $nrows; $i++) { |
|
1619 | + for ($i = 0; $i < $nrows; $i++) { |
|
1620 | 1620 | $result[$i] = $q->row($i); |
1621 | 1621 | } |
1622 | 1622 | return $result; |
@@ -1663,14 +1663,14 @@ discard block |
||
1663 | 1663 | // $input['limit'] as a string for the $limit clause, eg '21,20'. |
1664 | 1664 | |
1665 | 1665 | $amount = isset($input['amount']) ? $input['amount'] : array(); |
1666 | - $wherearr = isset($input['where']) ? $input['where'] : array(); |
|
1666 | + $wherearr = isset($input['where']) ? $input['where'] : array(); |
|
1667 | 1667 | $order = isset($input['order']) ? $input['order'] : ''; |
1668 | 1668 | $limit = isset($input['limit']) ? $input['limit'] : ''; |
1669 | 1669 | |
1670 | 1670 | |
1671 | 1671 | // The fields to fetch from db. 'table' => array ('field1', 'field2'). |
1672 | - $fieldsarr = array ( |
|
1673 | - 'hansard' => array ('epobject_id', 'htype', 'gid', 'hpos', 'section_id', 'subsection_id', 'hdate', 'htime', 'source_url', 'major', 'minor', 'video_status', 'colnum') |
|
1672 | + $fieldsarr = array( |
|
1673 | + 'hansard' => array('epobject_id', 'htype', 'gid', 'hpos', 'section_id', 'subsection_id', 'hdate', 'htime', 'source_url', 'major', 'minor', 'video_status', 'colnum') |
|
1674 | 1674 | ); |
1675 | 1675 | |
1676 | 1676 | $params = array(); |
@@ -1682,23 +1682,23 @@ discard block |
||
1682 | 1682 | if ((isset($amount['body']) && $amount['body'] == true) || |
1683 | 1683 | (isset($amount['comment']) && $amount['comment'] == true) |
1684 | 1684 | ) { |
1685 | - $fieldsarr['epobject'] = array ('body'); |
|
1685 | + $fieldsarr['epobject'] = array('body'); |
|
1686 | 1686 | $join = 'LEFT OUTER JOIN epobject ON hansard.epobject_id = epobject.epobject_id'; |
1687 | 1687 | } else { |
1688 | 1688 | $join = ''; |
1689 | 1689 | } |
1690 | 1690 | |
1691 | 1691 | |
1692 | - $fieldsarr2 = array (); |
|
1692 | + $fieldsarr2 = array(); |
|
1693 | 1693 | // Construct the $fields clause. |
1694 | 1694 | foreach ($fieldsarr as $table => $tablesfields) { |
1695 | 1695 | foreach ($tablesfields as $n => $field) { |
1696 | - $fieldsarr2[] = $table.'.'.$field; |
|
1696 | + $fieldsarr2[] = $table . '.' . $field; |
|
1697 | 1697 | } |
1698 | 1698 | } |
1699 | 1699 | $fields = implode(', ', $fieldsarr2); |
1700 | 1700 | |
1701 | - $wherearr2 = array (); |
|
1701 | + $wherearr2 = array(); |
|
1702 | 1702 | // Construct the $where clause. |
1703 | 1703 | $i = 0; |
1704 | 1704 | foreach ($wherearr as $key => $val) { |
@@ -1706,7 +1706,7 @@ discard block |
||
1706 | 1706 | $wherearr2[] = "$key :where$i"; |
1707 | 1707 | $i++; |
1708 | 1708 | } |
1709 | - $where = implode (" AND ", $wherearr2); |
|
1709 | + $where = implode(" AND ", $wherearr2); |
|
1710 | 1710 | |
1711 | 1711 | |
1712 | 1712 | if ($order != '') { |
@@ -1724,7 +1724,7 @@ discard block |
||
1724 | 1724 | } |
1725 | 1725 | |
1726 | 1726 | // Finally, do the query! |
1727 | - $q = $this->db->query ("SELECT $fields |
|
1727 | + $q = $this->db->query("SELECT $fields |
|
1728 | 1728 | FROM hansard |
1729 | 1729 | $join |
1730 | 1730 | WHERE $where |
@@ -1733,11 +1733,11 @@ discard block |
||
1733 | 1733 | ", $params); |
1734 | 1734 | |
1735 | 1735 | // Format the data into an array for returning. |
1736 | - $data = array (); |
|
1736 | + $data = array(); |
|
1737 | 1737 | |
1738 | 1738 | if ($q->rows() > 0) { |
1739 | 1739 | |
1740 | - for ($n=0; $n<$q->rows(); $n++) { |
|
1740 | + for ($n = 0; $n < $q->rows(); $n++) { |
|
1741 | 1741 | |
1742 | 1742 | // Where we'll store the data for this item before adding |
1743 | 1743 | // it to $data. |
@@ -1753,23 +1753,23 @@ discard block |
||
1753 | 1753 | if (isset($item['gid'])) { |
1754 | 1754 | // Remove the "uk.org.publicwhip/blah/" from the gid: |
1755 | 1755 | // (In includes/utility.php) |
1756 | - $item['gid'] = fix_gid_from_db( $item['gid'] ); |
|
1756 | + $item['gid'] = fix_gid_from_db($item['gid']); |
|
1757 | 1757 | } |
1758 | 1758 | |
1759 | 1759 | // Add mentions if (a) it's a question in the written |
1760 | 1760 | // answer section or (b) it's in the official reports |
1761 | 1761 | // and the body text ends in a bracketed SPID. |
1762 | - if (($this->major && $hansardmajors[$this->major]['page']=='spwrans') && ($item['htype'] == '12' && $item['minor'] == '1')) { |
|
1762 | + if (($this->major && $hansardmajors[$this->major]['page'] == 'spwrans') && ($item['htype'] == '12' && $item['minor'] == '1')) { |
|
1763 | 1763 | // Get out the SPID: |
1764 | - if ( preg_match('#\d{4}-\d\d-\d\d\.(.*?)\.q#', $item['gid'], $m) ) { |
|
1764 | + if (preg_match('#\d{4}-\d\d-\d\d\.(.*?)\.q#', $item['gid'], $m)) { |
|
1765 | 1765 | $item['mentions'] = $this->_get_mentions($m[1]); |
1766 | 1766 | } |
1767 | 1767 | } |
1768 | 1768 | |
1769 | 1769 | // The second case (b): |
1770 | - if (($this->major && $hansardmajors[$this->major]['page']=='spdebates') && isset($item['body'])) { |
|
1771 | - $stripped_body = preg_replace('/<[^>]+>/ms','',$item['body']); |
|
1772 | - if ( preg_match('/\((S\d+\w+-\d+)\)/ms',$stripped_body,$m) ) { |
|
1770 | + if (($this->major && $hansardmajors[$this->major]['page'] == 'spdebates') && isset($item['body'])) { |
|
1771 | + $stripped_body = preg_replace('/<[^>]+>/ms', '', $item['body']); |
|
1772 | + if (preg_match('/\((S\d+\w+-\d+)\)/ms', $stripped_body, $m)) { |
|
1773 | 1773 | $item['mentions'] = $this->_get_mentions($m[1]); |
1774 | 1774 | } |
1775 | 1775 | } |
@@ -1782,7 +1782,7 @@ discard block |
||
1782 | 1782 | // Get the number of items within a section or subsection. |
1783 | 1783 | // It could be that we can do this in the main query? |
1784 | 1784 | // Not sure. |
1785 | - if ( ($this->major && $hansardmajors[$this->major]['type']=='debate') && ($item['htype'] == '10' || $item['htype'] == '11') ) { |
|
1785 | + if (($this->major && $hansardmajors[$this->major]['type'] == 'debate') && ($item['htype'] == '10' || $item['htype'] == '11')) { |
|
1786 | 1786 | |
1787 | 1787 | if ($item['htype'] == '10') { |
1788 | 1788 | // Section - get a count of items within this section that |
@@ -1843,7 +1843,7 @@ discard block |
||
1843 | 1843 | // 'commentsurl' is the URL of the item on its own page, with comments. |
1844 | 1844 | |
1845 | 1845 | // All the things we need to work out a listurl! |
1846 | - $item_data = array ( |
|
1846 | + $item_data = array( |
|
1847 | 1847 | 'major' => $this->major, |
1848 | 1848 | 'minor' => $item['minor'], |
1849 | 1849 | 'htype' => $item['htype'], |
@@ -1876,11 +1876,11 @@ discard block |
||
1876 | 1876 | $item['htype'] == '12') { |
1877 | 1877 | // Debate speech or written answers (not questions). |
1878 | 1878 | |
1879 | - $item['votes'] = $this->_get_votes( $item['epobject_id'] ); |
|
1879 | + $item['votes'] = $this->_get_votes($item['epobject_id']); |
|
1880 | 1880 | } |
1881 | 1881 | |
1882 | 1882 | // Get the speaker for this item, if applicable. |
1883 | - if ( (isset($amount['speaker']) && $amount['speaker'] == true) && |
|
1883 | + if ((isset($amount['speaker']) && $amount['speaker'] == true) && |
|
1884 | 1884 | $item['person_id'] != '') { |
1885 | 1885 | |
1886 | 1886 | $item['speaker'] = $this->_get_speaker($item['person_id'], $item['hdate'], $item['htime'], $item['major']); |
@@ -1891,7 +1891,7 @@ discard block |
||
1891 | 1891 | if (isset($amount['comment']) && $amount['comment'] == true) { |
1892 | 1892 | |
1893 | 1893 | // All the things we need to get the comment data. |
1894 | - $item_data = array ( |
|
1894 | + $item_data = array( |
|
1895 | 1895 | 'htype' => $item['htype'], |
1896 | 1896 | 'epobject_id' => $item['epobject_id'] |
1897 | 1897 | ); |
@@ -1965,7 +1965,7 @@ discard block |
||
1965 | 1965 | } |
1966 | 1966 | |
1967 | 1967 | |
1968 | - public function _get_listurl ($id_data, $url_args=array(), $encode='html') { |
|
1968 | + public function _get_listurl($id_data, $url_args = array(), $encode = 'html') { |
|
1969 | 1969 | global $hansardmajors; |
1970 | 1970 | // Generates an item's listurl - this is the 'contextual' url |
1971 | 1971 | // for an item, in the full list view with an anchor (if appropriate). |
@@ -1994,7 +1994,7 @@ discard block |
||
1994 | 1994 | $DATA->set_page_metadata('pbc_clause', 'url', 'pbc/' . $this->url . $id); |
1995 | 1995 | $LISTURL->remove(array('id')); |
1996 | 1996 | } else { |
1997 | - $LISTURL->insert( array( 'id' => $id_data['gid'] ) ); |
|
1997 | + $LISTURL->insert(array('id' => $id_data['gid'])); |
|
1998 | 1998 | } |
1999 | 1999 | } else { |
2000 | 2000 | // A debate speech or question/answer, etc. |
@@ -2007,10 +2007,10 @@ discard block |
||
2007 | 2007 | // Find the gid of this item's (sub)section. |
2008 | 2008 | $parent_gid = ''; |
2009 | 2009 | |
2010 | - if (isset($this->epobjectid_to_gid[ $parent_epobject_id ])) { |
|
2010 | + if (isset($this->epobjectid_to_gid[$parent_epobject_id])) { |
|
2011 | 2011 | // We've previously cached the gid for this epobject_id, so use that. |
2012 | 2012 | |
2013 | - $parent_gid = $this->epobjectid_to_gid[ $parent_epobject_id ]; |
|
2013 | + $parent_gid = $this->epobjectid_to_gid[$parent_epobject_id]; |
|
2014 | 2014 | |
2015 | 2015 | } else { |
2016 | 2016 | // We haven't cached the gid, so fetch from db. |
@@ -2023,10 +2023,10 @@ discard block |
||
2023 | 2023 | if ($r->rows() > 0) { |
2024 | 2024 | // Remove the "uk.org.publicwhip/blah/" from the gid: |
2025 | 2025 | // (In includes/utility.php) |
2026 | - $parent_gid = fix_gid_from_db( $r->field(0, 'gid') ); |
|
2026 | + $parent_gid = fix_gid_from_db($r->field(0, 'gid')); |
|
2027 | 2027 | |
2028 | 2028 | // Cache it for if we need it again: |
2029 | - $this->epobjectid_to_gid[ $parent_epobject_id ] = $parent_gid; |
|
2029 | + $this->epobjectid_to_gid[$parent_epobject_id] = $parent_gid; |
|
2030 | 2030 | } |
2031 | 2031 | } |
2032 | 2032 | |
@@ -2036,18 +2036,18 @@ discard block |
||
2036 | 2036 | if (isset($this->bill_lookup[$minor])) { |
2037 | 2037 | list($title, $session) = $this->bill_lookup[$minor]; |
2038 | 2038 | } else { |
2039 | - $qq = $this->db->query('select title, session from bills where id='.$minor); |
|
2039 | + $qq = $this->db->query('select title, session from bills where id=' . $minor); |
|
2040 | 2040 | $title = $qq->field(0, 'title'); |
2041 | 2041 | $session = $qq->field(0, 'session'); |
2042 | 2042 | $this->bill_lookup[$minor] = array($title, $session); |
2043 | 2043 | } |
2044 | - $url = "$session/" . urlencode(str_replace(' ','_',$title)); |
|
2044 | + $url = "$session/" . urlencode(str_replace(' ', '_', $title)); |
|
2045 | 2045 | $parent_gid = preg_replace('#^.*?_.*?_#', '', $parent_gid); |
2046 | 2046 | global $DATA; |
2047 | 2047 | $DATA->set_page_metadata('pbc_clause', 'url', "pbc/$url/$parent_gid"); |
2048 | 2048 | $LISTURL->remove(array('id')); |
2049 | 2049 | } else { |
2050 | - $LISTURL->insert( array( 'id' => $parent_gid ) ); |
|
2050 | + $LISTURL->insert(array('id' => $parent_gid)); |
|
2051 | 2051 | } |
2052 | 2052 | // Use a truncated form of this item's gid for the anchor. |
2053 | 2053 | $fragment = '#g' . gid_to_anchor($id_data['gid']); |
@@ -2055,7 +2055,7 @@ discard block |
||
2055 | 2055 | } |
2056 | 2056 | |
2057 | 2057 | if (count($url_args) > 0) { |
2058 | - $LISTURL->insert( $url_args); |
|
2058 | + $LISTURL->insert($url_args); |
|
2059 | 2059 | } |
2060 | 2060 | |
2061 | 2061 | return $LISTURL->generate($encode) . $fragment; |
@@ -2118,10 +2118,10 @@ discard block |
||
2118 | 2118 | $member = $this->_get_speaker_alone($q->data, $person_id, $hdate, $htime, $major); |
2119 | 2119 | |
2120 | 2120 | $URL = $this->_get_speaker_url($member['house']); |
2121 | - $URL->insert( array ('p' => $person_id) ); |
|
2121 | + $URL->insert(array('p' => $person_id)); |
|
2122 | 2122 | |
2123 | 2123 | $name = member_full_name($member['house'], $member['title'], $member['given_name'], $member['family_name'], $member['lordofname']); |
2124 | - $speaker = array ( |
|
2124 | + $speaker = array( |
|
2125 | 2125 | 'member_id' => $member['member_id'], |
2126 | 2126 | "name" => $name, |
2127 | 2127 | 'house' => $member['house'], |
@@ -2168,13 +2168,13 @@ discard block |
||
2168 | 2168 | |
2169 | 2169 | private function _get_speaker_url($house) { |
2170 | 2170 | $URL = new \MySociety\TheyWorkForYou\Url('mp'); # Default, house=1 |
2171 | - if ($house==2) { |
|
2171 | + if ($house == 2) { |
|
2172 | 2172 | $URL = new \MySociety\TheyWorkForYou\Url('peer'); |
2173 | - } elseif ($house==3) { |
|
2173 | + } elseif ($house == 3) { |
|
2174 | 2174 | $URL = new \MySociety\TheyWorkForYou\Url('mla'); |
2175 | - } elseif ($house==4) { |
|
2175 | + } elseif ($house == 4) { |
|
2176 | 2176 | $URL = new \MySociety\TheyWorkForYou\Url('msp'); |
2177 | - } elseif ($house==0) { |
|
2177 | + } elseif ($house == 0) { |
|
2178 | 2178 | $URL = new \MySociety\TheyWorkForYou\Url('royal'); |
2179 | 2179 | } |
2180 | 2180 | return $URL; |
@@ -2190,7 +2190,7 @@ discard block |
||
2190 | 2190 | if (!$rows) { |
2191 | 2191 | return $offices; |
2192 | 2192 | } |
2193 | - for ($row=0; $row<$rows; $row++) { |
|
2193 | + for ($row = 0; $row < $rows; $row++) { |
|
2194 | 2194 | $dept = $q->field($row, 'dept'); |
2195 | 2195 | $pos = $q->field($row, 'position'); |
2196 | 2196 | $source = $q->field($row, 'source'); |
@@ -2249,12 +2249,12 @@ discard block |
||
2249 | 2249 | array(':epobject_id' => $item_data['epobject_id'])); |
2250 | 2250 | |
2251 | 2251 | // Add this comment to the data structure. |
2252 | - $comment = array ( |
|
2252 | + $comment = array( |
|
2253 | 2253 | 'comment_id' => $q->field(0, 'comment_id'), |
2254 | 2254 | 'user_id' => $q->field(0, 'user_id'), |
2255 | 2255 | 'body' => $q->field(0, 'body'), |
2256 | 2256 | 'posted' => $q->field(0, 'posted'), |
2257 | - 'username' => $q->field(0, 'firstname') .' '. $q->field(0, 'lastname') |
|
2257 | + 'username' => $q->field(0, 'firstname') . ' ' . $q->field(0, 'lastname') |
|
2258 | 2258 | ); |
2259 | 2259 | } |
2260 | 2260 | |
@@ -2264,7 +2264,7 @@ discard block |
||
2264 | 2264 | // or subsection itself, only the items within them. So |
2265 | 2265 | // we don't get the most recent comment. Because there isn't one. |
2266 | 2266 | |
2267 | - $return = array ( |
|
2267 | + $return = array( |
|
2268 | 2268 | 'totalcomments' => $totalcomments, |
2269 | 2269 | 'comment' => $comment |
2270 | 2270 | ); |
@@ -2278,7 +2278,7 @@ discard block |
||
2278 | 2278 | // What it says on the tin. |
2279 | 2279 | // $item_data must have 'htype' and 'epobject_id' elements. TODO: Check for major==4 |
2280 | 2280 | |
2281 | - if (($hansardmajors[$this->major]['type']=='debate') && |
|
2281 | + if (($hansardmajors[$this->major]['type'] == 'debate') && |
|
2282 | 2282 | ($item_data['htype'] == '10' || $item_data['htype'] == '11') |
2283 | 2283 | ) { |
2284 | 2284 | // We'll be getting a count of the comments on all items |
@@ -2362,7 +2362,7 @@ discard block |
||
2362 | 2362 | // Then depending on what htype it is, we get the data for other items too. |
2363 | 2363 | global $DATA, $this_page, $hansardmajors; |
2364 | 2364 | |
2365 | - twfy_debug (get_class($this), "getting data by gid"); |
|
2365 | + twfy_debug(get_class($this), "getting data by gid"); |
|
2366 | 2366 | |
2367 | 2367 | // Get the information about the item this URL refers to. |
2368 | 2368 | $itemdata = $this->_get_item($args); |
@@ -2371,25 +2371,25 @@ discard block |
||
2371 | 2371 | } |
2372 | 2372 | |
2373 | 2373 | // If part of a Written Answer (just question or just answer), select the whole thing |
2374 | - if (isset($itemdata['major']) && $hansardmajors[$itemdata['major']]['type']=='other' and ($itemdata['htype'] == '12' or $itemdata['htype'] == '13')) { |
|
2374 | + if (isset($itemdata['major']) && $hansardmajors[$itemdata['major']]['type'] == 'other' and ($itemdata['htype'] == '12' or $itemdata['htype'] == '13')) { |
|
2375 | 2375 | // find the gid of the subheading which holds this part |
2376 | - $input = array ( |
|
2376 | + $input = array( |
|
2377 | 2377 | 'amount' => array('gid' => true), |
2378 | - 'where' => array ( |
|
2378 | + 'where' => array( |
|
2379 | 2379 | 'epobject_id=' => $itemdata['subsection_id'], |
2380 | 2380 | ), |
2381 | 2381 | ); |
2382 | 2382 | $parent = $this->_get_hansard_data($input); |
2383 | 2383 | // display that item, i.e. the whole of the Written Answer |
2384 | - twfy_debug (get_class($this), "instead of " . $args['gid'] . " selecting subheading gid " . $parent[0]['gid'] . " to get whole wrans"); |
|
2384 | + twfy_debug(get_class($this), "instead of " . $args['gid'] . " selecting subheading gid " . $parent[0]['gid'] . " to get whole wrans"); |
|
2385 | 2385 | $args['gid'] = $parent[0]['gid']; |
2386 | 2386 | $this->_get_item($args); |
2387 | 2387 | throw new RedirectException($args['gid']); |
2388 | 2388 | } |
2389 | 2389 | |
2390 | 2390 | # If a WMS main heading, go to next gid |
2391 | - if (isset($itemdata['major']) && $itemdata['major']==4 && $itemdata['htype'] == '10') { |
|
2392 | - $input = array ( |
|
2391 | + if (isset($itemdata['major']) && $itemdata['major'] == 4 && $itemdata['htype'] == '10') { |
|
2392 | + $input = array( |
|
2393 | 2393 | 'amount' => array('gid' => true), |
2394 | 2394 | 'where' => array( |
2395 | 2395 | 'section_id=' => $itemdata['epobject_id'], |
@@ -2399,7 +2399,7 @@ discard block |
||
2399 | 2399 | ); |
2400 | 2400 | $next = $this->_get_hansard_data($input); |
2401 | 2401 | if (!empty($next)) { |
2402 | - twfy_debug (get_class($this), 'instead of ' . $args['gid'] . ' moving to ' . $next[0]['gid']); |
|
2402 | + twfy_debug(get_class($this), 'instead of ' . $args['gid'] . ' moving to ' . $next[0]['gid']); |
|
2403 | 2403 | $args['gid'] = $next[0]['gid']; |
2404 | 2404 | $this->_get_item($args); |
2405 | 2405 | throw new RedirectException($args['gid']); |
@@ -2451,16 +2451,16 @@ discard block |
||
2451 | 2451 | // Get the nextprev links for this item, to link to next/prev pages. |
2452 | 2452 | // Duh. |
2453 | 2453 | if ($itemdata['htype'] == '10') { |
2454 | - $nextprev = $this->_get_nextprev_items( $sectionrow ); |
|
2454 | + $nextprev = $this->_get_nextprev_items($sectionrow); |
|
2455 | 2455 | $data['info']['text_heading'] = $itemdata['body']; |
2456 | 2456 | |
2457 | 2457 | } elseif ($itemdata['htype'] == '11') { |
2458 | - $nextprev = $this->_get_nextprev_items( $subsectionrow ); |
|
2458 | + $nextprev = $this->_get_nextprev_items($subsectionrow); |
|
2459 | 2459 | $data['info']['text_heading'] = $itemdata['body']; |
2460 | 2460 | |
2461 | 2461 | } else { |
2462 | 2462 | // Ordinary lowly item. |
2463 | - $nextprev = $this->_get_nextprev_items( $itemdata ); |
|
2463 | + $nextprev = $this->_get_nextprev_items($itemdata); |
|
2464 | 2464 | |
2465 | 2465 | if (isset($subsectionrow['gid'])) { |
2466 | 2466 | $nextprev['up']['url'] = $subsectionrow['listurl']; |
@@ -2469,7 +2469,7 @@ discard block |
||
2469 | 2469 | $nextprev['up']['url'] = $sectionrow['listurl']; |
2470 | 2470 | $nextprev['up']['title'] = $sectionrow['body']; |
2471 | 2471 | } |
2472 | - $nextprev['up']['body'] = 'See the whole debate'; |
|
2472 | + $nextprev['up']['body'] = 'See the whole debate'; |
|
2473 | 2473 | } |
2474 | 2474 | |
2475 | 2475 | // We can then access this from $PAGE and the templates. |
@@ -2478,7 +2478,7 @@ discard block |
||
2478 | 2478 | // Now get all the non-heading rows. |
2479 | 2479 | |
2480 | 2480 | // What data do we want for each item? |
2481 | - $amount = array ( |
|
2481 | + $amount = array( |
|
2482 | 2482 | 'body' => true, |
2483 | 2483 | 'speaker' => true, |
2484 | 2484 | 'comment' => true, |
@@ -2491,9 +2491,9 @@ discard block |
||
2491 | 2491 | |
2492 | 2492 | # $sectionrow['trackback'] = $this->_get_trackback_data($sectionrow); |
2493 | 2493 | |
2494 | - $input = array ( |
|
2494 | + $input = array( |
|
2495 | 2495 | 'amount' => $amount, |
2496 | - 'where' => array ( |
|
2496 | + 'where' => array( |
|
2497 | 2497 | 'section_id=' => $itemdata['epobject_id'], |
2498 | 2498 | 'subsection_id=' => $itemdata['epobject_id'] |
2499 | 2499 | ), |
@@ -2501,15 +2501,15 @@ discard block |
||
2501 | 2501 | ); |
2502 | 2502 | |
2503 | 2503 | $data['rows'] = $this->_get_hansard_data($input); |
2504 | - if (!count($data['rows']) || (count($data['rows'])==1 && strstr($data['rows'][0]['body'], 'was asked'))) { |
|
2504 | + if (!count($data['rows']) || (count($data['rows']) == 1 && strstr($data['rows'][0]['body'], 'was asked'))) { |
|
2505 | 2505 | |
2506 | - $input = array ( |
|
2507 | - 'amount' => array ( |
|
2506 | + $input = array( |
|
2507 | + 'amount' => array( |
|
2508 | 2508 | 'body' => true, |
2509 | 2509 | 'comment' => true, |
2510 | 2510 | 'excerpt' => true |
2511 | 2511 | ), |
2512 | - 'where' => array ( |
|
2512 | + 'where' => array( |
|
2513 | 2513 | 'section_id=' => $sectionrow['epobject_id'], |
2514 | 2514 | 'htype=' => '11', |
2515 | 2515 | 'major=' => $this->major |
@@ -2527,9 +2527,9 @@ discard block |
||
2527 | 2527 | |
2528 | 2528 | # $subsectionrow['trackback'] = $this->_get_trackback_data($subsectionrow); |
2529 | 2529 | |
2530 | - $input = array ( |
|
2530 | + $input = array( |
|
2531 | 2531 | 'amount' => $amount, |
2532 | - 'where' => array ( |
|
2532 | + 'where' => array( |
|
2533 | 2533 | 'subsection_id=' => $itemdata['epobject_id'] |
2534 | 2534 | ), |
2535 | 2535 | 'order' => 'hpos ASC' |
@@ -2552,10 +2552,10 @@ discard block |
||
2552 | 2552 | $subsectionrow['gid'] != $sectionrow['gid']) { |
2553 | 2553 | // If we're looking at a section, there may not be a subsection. |
2554 | 2554 | // And if the subsectionrow and sectionrow aren't the same. |
2555 | - array_unshift ($data['rows'], $subsectionrow); |
|
2555 | + array_unshift($data['rows'], $subsectionrow); |
|
2556 | 2556 | } |
2557 | 2557 | |
2558 | - array_unshift ($data['rows'], $sectionrow); |
|
2558 | + array_unshift($data['rows'], $sectionrow); |
|
2559 | 2559 | |
2560 | 2560 | return $data; |
2561 | 2561 | |
@@ -2564,10 +2564,10 @@ discard block |
||
2564 | 2564 | public function _get_data_by_column($args) { |
2565 | 2565 | global $this_page; |
2566 | 2566 | |
2567 | - twfy_debug (get_class($this), "getting data by column"); |
|
2567 | + twfy_debug(get_class($this), "getting data by column"); |
|
2568 | 2568 | |
2569 | - $input = array( 'amount' => array('body'=>true, 'comment'=>true, 'speaker'=>true), |
|
2570 | - 'where' => array( 'hdate='=>$args['date'], 'major=' => $this->major, 'gid LIKE ' =>'%.'.$args['column'].'.%' ), |
|
2569 | + $input = array('amount' => array('body'=>true, 'comment'=>true, 'speaker'=>true), |
|
2570 | + 'where' => array('hdate='=>$args['date'], 'major=' => $this->major, 'gid LIKE ' =>'%.' . $args['column'] . '.%'), |
|
2571 | 2571 | 'order' => 'hpos' |
2572 | 2572 | ); |
2573 | 2573 | $data = $this->_get_hansard_data($input); |
@@ -2626,8 +2626,8 @@ discard block |
||
2626 | 2626 | public function get_gid_from_spid($spid) { |
2627 | 2627 | // Fix the common errors of S.0 instead of S.O and leading |
2628 | 2628 | // zeros in the numbers: |
2629 | - $fixed_spid = preg_replace('/(S[0-9]+)0-([0-9]+)/','${1}O-${2}',$spid); |
|
2630 | - $fixed_spid = preg_replace('/(S[0-9]+\w+)-0*([0-9]+)/','${1}-${2}',$fixed_spid); |
|
2629 | + $fixed_spid = preg_replace('/(S[0-9]+)0-([0-9]+)/', '${1}O-${2}', $spid); |
|
2630 | + $fixed_spid = preg_replace('/(S[0-9]+\w+)-0*([0-9]+)/', '${1}-${2}', $fixed_spid); |
|
2631 | 2631 | $q = $this->db->query( |
2632 | 2632 | "select mentioned_gid from mentions where gid = :gid_from_spid and (type = 4 or type = 6)", |
2633 | 2633 | array(':gid_from_spid' => 'uk.org.publicwhip/spq/' . $fixed_spid) |
@@ -2702,14 +2702,14 @@ discard block |
||
2702 | 2702 | ", array(':major' => $this->major)); |
2703 | 2703 | |
2704 | 2704 | // What we return. |
2705 | - $data = array (); |
|
2705 | + $data = array(); |
|
2706 | 2706 | $speeches = array(); |
2707 | 2707 | |
2708 | 2708 | if ($q->rows() > 0) { |
2709 | 2709 | |
2710 | - for ($n=0; $n<$q->rows(); $n++) { |
|
2710 | + for ($n = 0; $n < $q->rows(); $n++) { |
|
2711 | 2711 | |
2712 | - $speech = array ( |
|
2712 | + $speech = array( |
|
2713 | 2713 | 'subsection_id' => $q->field($n, 'subsection_id'), |
2714 | 2714 | 'section_id' => $q->field($n, 'section_id'), |
2715 | 2715 | 'htype' => $q->field($n, 'htype'), |
@@ -2722,11 +2722,11 @@ discard block |
||
2722 | 2722 | |
2723 | 2723 | // Remove the "uk.org.publicwhip/blah/" from the gid: |
2724 | 2724 | // (In includes/utility.php) |
2725 | - $speech['gid'] = fix_gid_from_db( $q->field($n, 'gid') ); |
|
2725 | + $speech['gid'] = fix_gid_from_db($q->field($n, 'gid')); |
|
2726 | 2726 | |
2727 | 2727 | $speech['listurl'] = $this->_get_listurl($speech); |
2728 | 2728 | |
2729 | - $speech['speaker'] = $this->_get_speaker($q->field($n, 'person_id'), $q->field($n, 'hdate'), $q->field($n, 'htime'), $this->major ); |
|
2729 | + $speech['speaker'] = $this->_get_speaker($q->field($n, 'person_id'), $q->field($n, 'hdate'), $q->field($n, 'htime'), $this->major); |
|
2730 | 2730 | |
2731 | 2731 | $speeches[] = $speech; |
2732 | 2732 | } |
@@ -2736,10 +2736,10 @@ discard block |
||
2736 | 2736 | // Get the subsection texts. |
2737 | 2737 | |
2738 | 2738 | $num_speeches = count($speeches); |
2739 | - for ($n=0; $n<$num_speeches; $n++) { |
|
2739 | + for ($n = 0; $n < $num_speeches; $n++) { |
|
2740 | 2740 | //if ($this->major == 1) { |
2741 | 2741 | // Debate. |
2742 | - $parent = $this->_get_subsection ($speeches[$n]); |
|
2742 | + $parent = $this->_get_subsection($speeches[$n]); |
|
2743 | 2743 | |
2744 | 2744 | //} elseif ($this->major == 3) { |
2745 | 2745 | // Wrans. |
@@ -2758,7 +2758,7 @@ discard block |
||
2758 | 2758 | $data['rows'] = $speeches; |
2759 | 2759 | |
2760 | 2760 | } else { |
2761 | - $data['rows'] = array (); |
|
2761 | + $data['rows'] = array(); |
|
2762 | 2762 | } |
2763 | 2763 | |
2764 | 2764 | $data['info']['days'] = $days; |
@@ -2775,13 +2775,13 @@ discard block |
||
2775 | 2775 | } |
2776 | 2776 | |
2777 | 2777 | |
2778 | - public function biggest_debates($args=array()) { |
|
2778 | + public function biggest_debates($args = array()) { |
|
2779 | 2779 | // So we can just get the data back for special formatting |
2780 | 2780 | // on the front page, without doing the whole display() thing. |
2781 | 2781 | return $this->_get_data_by_biggest_debates($args); |
2782 | 2782 | } |
2783 | 2783 | |
2784 | - public function _get_data_by_featured_gid($args=array()) { |
|
2784 | + public function _get_data_by_featured_gid($args = array()) { |
|
2785 | 2785 | $params = array(); |
2786 | 2786 | $data = array(); |
2787 | 2787 | |
@@ -2807,21 +2807,21 @@ discard block |
||
2807 | 2807 | |
2808 | 2808 | $q = $this->db->query($query, $params); |
2809 | 2809 | |
2810 | - if ( $q->rows ) { |
|
2810 | + if ($q->rows) { |
|
2811 | 2811 | |
2812 | 2812 | // This array just used for getting further data about this debate. |
2813 | - $item_data = array ( |
|
2813 | + $item_data = array( |
|
2814 | 2814 | 'major' => $this->major, |
2815 | 2815 | 'minor' => $q->field(0, 'minor'), |
2816 | - 'gid' => fix_gid_from_db( $q->field(0, 'gid') ), |
|
2816 | + 'gid' => fix_gid_from_db($q->field(0, 'gid')), |
|
2817 | 2817 | 'htype' => $q->field(0, 'htype'), |
2818 | 2818 | 'section_id' => $q->field(0, 'section_id'), |
2819 | 2819 | 'subsection_id' => $q->field(0, 'subsection_id'), |
2820 | 2820 | 'epobject_id' => $q->field(0, 'epobject_id') |
2821 | 2821 | ); |
2822 | 2822 | |
2823 | - $list_url = $this->_get_listurl( $item_data ); |
|
2824 | - $totalcomments = $this->_get_comment_count_for_epobject( $item_data ); |
|
2823 | + $list_url = $this->_get_listurl($item_data); |
|
2824 | + $totalcomments = $this->_get_comment_count_for_epobject($item_data); |
|
2825 | 2825 | |
2826 | 2826 | $body = $q->field(0, 'body'); |
2827 | 2827 | $hdate = $q->field(0, 'hdate'); |
@@ -2841,21 +2841,21 @@ discard block |
||
2841 | 2841 | ':subsection_id' => $item_data['subsection_id'], |
2842 | 2842 | ) |
2843 | 2843 | ); |
2844 | - $section_body = $r->field(0, 'sec_body'); |
|
2844 | + $section_body = $r->field(0, 'sec_body'); |
|
2845 | 2845 | $subsection_body = $r->field(0, 'sub_body'); |
2846 | - if ( $section_body && $subsection_body ) { |
|
2846 | + if ($section_body && $subsection_body) { |
|
2847 | 2847 | $parentbody = "$section_body : $subsection_body"; |
2848 | 2848 | } else { |
2849 | 2849 | $parentbody = "$section_body$subsection_body"; |
2850 | 2850 | } |
2851 | - } else if ( $item_data['htype'] == 10 ) { |
|
2851 | + } else if ($item_data['htype'] == 10) { |
|
2852 | 2852 | $parentbody = $body; |
2853 | 2853 | } |
2854 | 2854 | |
2855 | 2855 | // Get the question for this item. |
2856 | - if ( $item_data['htype'] == 12 ) { |
|
2856 | + if ($item_data['htype'] == 12) { |
|
2857 | 2857 | $childbody = $body; |
2858 | - $speaker = $this->_get_speaker($q->field(0, 'person_id'), $q->field(0, 'hdate'), $q->field(0, 'htime'), $this->major ); |
|
2858 | + $speaker = $this->_get_speaker($q->field(0, 'person_id'), $q->field(0, 'hdate'), $q->field(0, 'htime'), $this->major); |
|
2859 | 2859 | } else { |
2860 | 2860 | $r = $this->db->query("SELECT e.body, e.title, |
2861 | 2861 | h.person_id, h.hdate, h.htime |
@@ -2865,10 +2865,10 @@ discard block |
||
2865 | 2865 | ORDER BY hpos |
2866 | 2866 | LIMIT 1 |
2867 | 2867 | ", |
2868 | - array( ':object_id' => $item_data['epobject_id'] ) |
|
2868 | + array(':object_id' => $item_data['epobject_id']) |
|
2869 | 2869 | ); |
2870 | 2870 | $childbody = $r->field(0, 'body'); |
2871 | - $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major ); |
|
2871 | + $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major); |
|
2872 | 2872 | } |
2873 | 2873 | |
2874 | 2874 | $contentcount = 0; |
@@ -2884,7 +2884,7 @@ discard block |
||
2884 | 2884 | } |
2885 | 2885 | |
2886 | 2886 | global $hansardmajors; |
2887 | - $more_url = new \MySociety\TheyWorkForYou\Url( $hansardmajors[$this->major]['page_all'] ); |
|
2887 | + $more_url = new \MySociety\TheyWorkForYou\Url($hansardmajors[$this->major]['page_all']); |
|
2888 | 2888 | $details = array( |
2889 | 2889 | 'body' => $body, |
2890 | 2890 | 'contentcount' => $contentcount, |
@@ -2903,7 +2903,7 @@ discard block |
||
2903 | 2903 | 'more_url' => $more_url->generate() |
2904 | 2904 | ); |
2905 | 2905 | |
2906 | - $data = array ( |
|
2906 | + $data = array( |
|
2907 | 2907 | 'gid' => $args['gid'], |
2908 | 2908 | 'major' => $this->major, |
2909 | 2909 | 'info' => array(), |
@@ -2914,7 +2914,7 @@ discard block |
||
2914 | 2914 | return $data; |
2915 | 2915 | |
2916 | 2916 | } |
2917 | - public function _get_data_by_recent_debates($args=array()) { |
|
2917 | + public function _get_data_by_recent_debates($args = array()) { |
|
2918 | 2918 | // Returns an array of some random recent debates from a set number of |
2919 | 2919 | // recent days (that's recent days starting from the most recent day |
2920 | 2920 | // that had any debates on). |
@@ -2972,20 +2972,20 @@ discard block |
||
2972 | 2972 | |
2973 | 2973 | $q = $this->db->query($query, $params); |
2974 | 2974 | |
2975 | - for ($row=0; $row<$q->rows; $row++) { |
|
2975 | + for ($row = 0; $row < $q->rows; $row++) { |
|
2976 | 2976 | |
2977 | 2977 | // This array just used for getting further data about this debate. |
2978 | - $item_data = array ( |
|
2978 | + $item_data = array( |
|
2979 | 2979 | 'major' => $this->major, |
2980 | - 'gid' => fix_gid_from_db( $q->field($row, 'gid') ), |
|
2980 | + 'gid' => fix_gid_from_db($q->field($row, 'gid')), |
|
2981 | 2981 | 'htype' => $q->field($row, 'htype'), |
2982 | 2982 | 'section_id' => $q->field($row, 'section_id'), |
2983 | 2983 | 'subsection_id' => $q->field($row, 'subsection_id'), |
2984 | 2984 | 'epobject_id' => $q->field($row, 'epobject_id') |
2985 | 2985 | ); |
2986 | 2986 | |
2987 | - $list_url = $this->_get_listurl( $item_data ); |
|
2988 | - $totalcomments = $this->_get_comment_count_for_epobject( $item_data ); |
|
2987 | + $list_url = $this->_get_listurl($item_data); |
|
2988 | + $totalcomments = $this->_get_comment_count_for_epobject($item_data); |
|
2989 | 2989 | |
2990 | 2990 | $contentcount = $q->field($row, 'count'); |
2991 | 2991 | $body = $q->field($row, 'body'); |
@@ -3013,7 +3013,7 @@ discard block |
||
3013 | 3013 | LIMIT 1 |
3014 | 3014 | "); |
3015 | 3015 | $childbody = $r->field(0, 'body'); |
3016 | - $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major ); |
|
3016 | + $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major); |
|
3017 | 3017 | |
3018 | 3018 | $data[] = array( |
3019 | 3019 | 'contentcount' => $contentcount, |
@@ -3033,7 +3033,7 @@ discard block |
||
3033 | 3033 | |
3034 | 3034 | } |
3035 | 3035 | |
3036 | - $data = array ( |
|
3036 | + $data = array( |
|
3037 | 3037 | 'info' => array(), |
3038 | 3038 | 'data' => $data |
3039 | 3039 | ); |
@@ -3042,7 +3042,7 @@ discard block |
||
3042 | 3042 | |
3043 | 3043 | } |
3044 | 3044 | |
3045 | - public function _get_data_by_biggest_debates($args=array()) { |
|
3045 | + public function _get_data_by_biggest_debates($args = array()) { |
|
3046 | 3046 | // Returns an array of the debates with most speeches in from |
3047 | 3047 | // a set number of recent days (that's recent days starting from the |
3048 | 3048 | // most recent day that had any debates on). |
@@ -3094,28 +3094,28 @@ discard block |
||
3094 | 3094 | LIMIT :limit", $params); |
3095 | 3095 | |
3096 | 3096 | |
3097 | - for ($row=0; $row<$q->rows; $row++) { |
|
3097 | + for ($row = 0; $row < $q->rows; $row++) { |
|
3098 | 3098 | |
3099 | 3099 | // This array just used for getting further data about this debate. |
3100 | - $item_data = array ( |
|
3100 | + $item_data = array( |
|
3101 | 3101 | 'major' => $this->major, |
3102 | - 'gid' => fix_gid_from_db( $q->field($row, 'gid') ), |
|
3102 | + 'gid' => fix_gid_from_db($q->field($row, 'gid')), |
|
3103 | 3103 | 'htype' => $q->field($row, 'htype'), |
3104 | 3104 | 'section_id' => $q->field($row, 'section_id'), |
3105 | 3105 | 'subsection_id' => $q->field($row, 'subsection_id'), |
3106 | 3106 | 'epobject_id' => $q->field($row, 'epobject_id') |
3107 | 3107 | ); |
3108 | 3108 | |
3109 | - $list_url = $this->_get_listurl( $item_data ); |
|
3110 | - $totalcomments = $this->_get_comment_count_for_epobject( $item_data ); |
|
3109 | + $list_url = $this->_get_listurl($item_data); |
|
3110 | + $totalcomments = $this->_get_comment_count_for_epobject($item_data); |
|
3111 | 3111 | |
3112 | - $contentcount = $q->field($row, 'count'); |
|
3112 | + $contentcount = $q->field($row, 'count'); |
|
3113 | 3113 | $body = $q->field($row, 'body'); |
3114 | 3114 | $hdate = $q->field($row, 'hdate'); |
3115 | 3115 | |
3116 | 3116 | |
3117 | 3117 | // This array will be added to $data, which is what gets returned. |
3118 | - $debate = array ( |
|
3118 | + $debate = array( |
|
3119 | 3119 | 'contentcount' => $contentcount, |
3120 | 3120 | 'body' => $body, |
3121 | 3121 | 'hdate' => $hdate, |
@@ -3143,7 +3143,7 @@ discard block |
||
3143 | 3143 | LIMIT 1 |
3144 | 3144 | "); |
3145 | 3145 | $childbody = $r->field(0, 'body'); |
3146 | - $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major ); |
|
3146 | + $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major); |
|
3147 | 3147 | |
3148 | 3148 | $debate['child'] = array( |
3149 | 3149 | 'body' => $childbody, |
@@ -3153,7 +3153,7 @@ discard block |
||
3153 | 3153 | $data[] = $debate; |
3154 | 3154 | } |
3155 | 3155 | |
3156 | - $data = array ( |
|
3156 | + $data = array( |
|
3157 | 3157 | 'info' => array(), |
3158 | 3158 | 'data' => $data |
3159 | 3159 | ); |
@@ -3176,7 +3176,7 @@ discard block |
||
3176 | 3176 | return $q->field(0, 'count'); |
3177 | 3177 | } |
3178 | 3178 | |
3179 | - public function _get_data_by_recent_wrans ($args=array()) { |
|
3179 | + public function _get_data_by_recent_wrans($args = array()) { |
|
3180 | 3180 | global $hansardmajors; |
3181 | 3181 | |
3182 | 3182 | // $args['days'] is the number of days back to look for biggest debates. |
@@ -3238,19 +3238,19 @@ discard block |
||
3238 | 3238 | |
3239 | 3239 | $q = $this->db->query($query, $params); |
3240 | 3240 | |
3241 | - for ($row=0; $row<$q->rows; $row++) { |
|
3241 | + for ($row = 0; $row < $q->rows; $row++) { |
|
3242 | 3242 | // This array just used for getting further data about this debate. |
3243 | - $item_data = array ( |
|
3243 | + $item_data = array( |
|
3244 | 3244 | 'major' => $this->major, |
3245 | - 'gid' => fix_gid_from_db( $q->field($row, 'gid') ), |
|
3245 | + 'gid' => fix_gid_from_db($q->field($row, 'gid')), |
|
3246 | 3246 | 'htype' => $q->field($row, 'htype'), |
3247 | 3247 | 'section_id' => $q->field($row, 'section_id'), |
3248 | 3248 | 'subsection_id' => $q->field($row, 'subsection_id'), |
3249 | 3249 | 'epobject_id' => $q->field($row, 'epobject_id') |
3250 | 3250 | ); |
3251 | 3251 | |
3252 | - $list_url = $this->_get_listurl( $item_data ); |
|
3253 | - $totalcomments = $this->_get_comment_count_for_epobject( $item_data ); |
|
3252 | + $list_url = $this->_get_listurl($item_data); |
|
3253 | + $totalcomments = $this->_get_comment_count_for_epobject($item_data); |
|
3254 | 3254 | |
3255 | 3255 | $body = $q->field($row, 'body'); |
3256 | 3256 | $hdate = $q->field($row, 'hdate'); |
@@ -3276,25 +3276,25 @@ discard block |
||
3276 | 3276 | LIMIT 1 |
3277 | 3277 | "); |
3278 | 3278 | $childbody = $r->field(0, 'body'); |
3279 | - $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major ); |
|
3279 | + $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major); |
|
3280 | 3280 | |
3281 | - $data[] = array ( |
|
3281 | + $data[] = array( |
|
3282 | 3282 | 'body' => $body, |
3283 | 3283 | 'hdate' => $hdate, |
3284 | 3284 | 'list_url' => $list_url, |
3285 | 3285 | 'totalcomments' => $totalcomments, |
3286 | - 'child' => array ( |
|
3286 | + 'child' => array( |
|
3287 | 3287 | 'body' => $childbody, |
3288 | 3288 | 'speaker' => $speaker |
3289 | 3289 | ), |
3290 | - 'parent' => array ( |
|
3290 | + 'parent' => array( |
|
3291 | 3291 | 'body' => $parentbody |
3292 | 3292 | ) |
3293 | 3293 | ); |
3294 | 3294 | |
3295 | 3295 | } |
3296 | 3296 | |
3297 | - $data = array ( |
|
3297 | + $data = array( |
|
3298 | 3298 | 'info' => array(), |
3299 | 3299 | 'data' => $data |
3300 | 3300 | ); |
@@ -3311,7 +3311,7 @@ discard block |
||
3311 | 3311 | public $commentspage = 'pbc_speech'; |
3312 | 3312 | public $gidprefix = 'uk.org.publicwhip/standing/'; |
3313 | 3313 | |
3314 | - public function __construct($session='', $title='') { |
|
3314 | + public function __construct($session = '', $title = '') { |
|
3315 | 3315 | parent::__construct(); |
3316 | 3316 | $this->bill_title = $title; |
3317 | 3317 | $title = str_replace(' ', '_', $title); |
@@ -3319,7 +3319,7 @@ discard block |
||
3319 | 3319 | } |
3320 | 3320 | |
3321 | 3321 | public function _get_committee($bill_id) { |
3322 | - include_once INCLUDESPATH."easyparliament/member.php"; |
|
3322 | + include_once INCLUDESPATH . "easyparliament/member.php"; |
|
3323 | 3323 | $q = $this->db->query( |
3324 | 3324 | 'select count(*) as c from hansard |
3325 | 3325 | where major=6 and minor=:bill_id and htype=10', |
@@ -3332,7 +3332,7 @@ discard block |
||
3332 | 3332 | where bill_id = :bill_id group by person_id', |
3333 | 3333 | array(':bill_id' => $bill_id)); |
3334 | 3334 | $comm = array('sittings' => $sittings, 'chairmen' => array(), 'members' => array()); |
3335 | - for ($i=0; $i<$q->rows(); $i++) { |
|
3335 | + for ($i = 0; $i < $q->rows(); $i++) { |
|
3336 | 3336 | $person_id = $q->field($i, 'person_id'); |
3337 | 3337 | $mp = new MEMBER(array('person_id'=>$person_id)); |
3338 | 3338 | $attending = $q->field($i, 'attending'); |
@@ -3353,13 +3353,13 @@ discard block |
||
3353 | 3353 | public function _get_data_by_bill($args) { |
3354 | 3354 | global $DATA, $this_page; |
3355 | 3355 | $data = array(); |
3356 | - $input = array ( |
|
3357 | - 'amount' => array ( |
|
3356 | + $input = array( |
|
3357 | + 'amount' => array( |
|
3358 | 3358 | 'body' => true, |
3359 | 3359 | 'comment' => true, |
3360 | 3360 | 'excerpt' => true |
3361 | 3361 | ), |
3362 | - 'where' => array ( |
|
3362 | + 'where' => array( |
|
3363 | 3363 | 'htype=' => '10', |
3364 | 3364 | 'major=' => $this->major, |
3365 | 3365 | 'minor=' => $args['id'], |
@@ -3370,18 +3370,18 @@ discard block |
||
3370 | 3370 | if (count($sections) > 0) { |
3371 | 3371 | $data['rows'] = array(); |
3372 | 3372 | $num_sections = count($sections); |
3373 | - for ($n=0; $n<$num_sections; $n++) { |
|
3373 | + for ($n = 0; $n < $num_sections; $n++) { |
|
3374 | 3374 | $sectionrow = $sections[$n]; |
3375 | 3375 | list($sitting, $part) = $this->_get_sitting($sectionrow['gid']); |
3376 | 3376 | $sectionrow['sitting'] = $sitting; |
3377 | 3377 | $sectionrow['part'] = $part; |
3378 | - $input = array ( |
|
3379 | - 'amount' => array ( |
|
3378 | + $input = array( |
|
3379 | + 'amount' => array( |
|
3380 | 3380 | 'body' => true, |
3381 | 3381 | 'comment' => true, |
3382 | 3382 | 'excerpt' => true |
3383 | 3383 | ), |
3384 | - 'where' => array ( |
|
3384 | + 'where' => array( |
|
3385 | 3385 | 'section_id=' => $sectionrow['epobject_id'], |
3386 | 3386 | 'htype=' => '11', |
3387 | 3387 | 'major=' => $this->major |
@@ -3389,8 +3389,8 @@ discard block |
||
3389 | 3389 | 'order' => 'hpos' |
3390 | 3390 | ); |
3391 | 3391 | $rows = $this->_get_hansard_data($input); |
3392 | - array_unshift ($rows, $sectionrow); |
|
3393 | - $data['rows'] = array_merge ($data['rows'], $rows); |
|
3392 | + array_unshift($rows, $sectionrow); |
|
3393 | + $data['rows'] = array_merge($data['rows'], $rows); |
|
3394 | 3394 | } |
3395 | 3395 | } |
3396 | 3396 | $data['info']['bill'] = $args['title']; |
@@ -3408,7 +3408,7 @@ discard block |
||
3408 | 3408 | array(':session' => $session) |
3409 | 3409 | ); |
3410 | 3410 | $bills = array(); |
3411 | - for ($i=0; $i<$q->rows(); $i++) { |
|
3411 | + for ($i = 0; $i < $q->rows(); $i++) { |
|
3412 | 3412 | $bills[$q->field($i, 'id')] = $q->field($i, 'title'); |
3413 | 3413 | } |
3414 | 3414 | if (!count($bills)) { |
@@ -3419,7 +3419,7 @@ discard block |
||
3419 | 3419 | group by minor'); |
3420 | 3420 | $counts = array(); |
3421 | 3421 | # $comments = array(); |
3422 | - for ($i=0; $i<$q->rows(); $i++) { |
|
3422 | + for ($i = 0; $i < $q->rows(); $i++) { |
|
3423 | 3423 | $minor = $q->field($i, 'minor'); |
3424 | 3424 | $counts[$minor] = $q->field($i, 'c'); |
3425 | 3425 | # $comments[$minor] = 0; |
@@ -3446,8 +3446,8 @@ discard block |
||
3446 | 3446 | |
3447 | 3447 | $YEARURL = new \MySociety\TheyWorkForYou\Url('pbc_session'); |
3448 | 3448 | $nextprev = array(); |
3449 | - $nextprev['prev'] = array ('body' => 'Previous session', 'title'=>''); |
|
3450 | - $nextprev['next'] = array ('body' => 'Next session', 'title'=>''); |
|
3449 | + $nextprev['prev'] = array('body' => 'Previous session', 'title'=>''); |
|
3450 | + $nextprev['next'] = array('body' => 'Next session', 'title'=>''); |
|
3451 | 3451 | $q = $this->db->query( |
3452 | 3452 | "SELECT session FROM bills WHERE session < :session ORDER BY session DESC LIMIT 1", |
3453 | 3453 | array(':session' => $session) |
@@ -3475,20 +3475,20 @@ discard block |
||
3475 | 3475 | where htype=10 and major=6 |
3476 | 3476 | order by hdate desc limit ' . $args['num']); |
3477 | 3477 | $data = array(); |
3478 | - for ($i=0; $i<$q->rows(); $i++) { |
|
3478 | + for ($i = 0; $i < $q->rows(); $i++) { |
|
3479 | 3479 | $minor = $q->field($i, 'minor'); |
3480 | 3480 | $gid = $q->field($i, 'gid'); |
3481 | 3481 | $hdate = format_date($q->field($i, 'hdate'), LONGDATEFORMAT); |
3482 | - $qq = $this->db->query('select title, session from bills where id='.$minor); |
|
3482 | + $qq = $this->db->query('select title, session from bills where id=' . $minor); |
|
3483 | 3483 | $title = $qq->field(0, 'title'); |
3484 | 3484 | $session = $qq->field(0, 'session'); |
3485 | 3485 | list($sitting, $part) = $this->_get_sitting($gid); |
3486 | 3486 | $sitting_txt = make_ranking($sitting) . ' sitting'; |
3487 | - if ($part>0) $sitting .= ", part $part"; |
|
3487 | + if ($part > 0) $sitting .= ", part $part"; |
|
3488 | 3488 | $data[$hdate][] = array( |
3489 | 3489 | 'bill'=> $title, |
3490 | 3490 | 'sitting' => $sitting_txt, |
3491 | - 'url' => "/pbc/$session/" . urlencode(str_replace(' ','_',$title)) . '/#sitting' . $sitting, |
|
3491 | + 'url' => "/pbc/$session/" . urlencode(str_replace(' ', '_', $title)) . '/#sitting' . $sitting, |
|
3492 | 3492 | ); |
3493 | 3493 | } |
3494 | 3494 | return $data; |
@@ -3497,7 +3497,7 @@ discard block |
||
3497 | 3497 | # Given a GID, parse out the sitting number and optional part from it |
3498 | 3498 | public function _get_sitting($gid) { |
3499 | 3499 | if (preg_match('#_(\d\d)-(\d)_#', $gid, $m)) |
3500 | - return array($m[1]+0, $m[2]); |
|
3500 | + return array($m[1] + 0, $m[2]); |
|
3501 | 3501 | return array(0, 0); |
3502 | 3502 | } |
3503 | 3503 | } |
@@ -138,8 +138,9 @@ discard block |
||
138 | 138 | |
139 | 139 | global $PAGE; |
140 | 140 | |
141 | - if ($view == 'search' && (!defined('FRONT_END_SEARCH') || !FRONT_END_SEARCH)) |
|
142 | - return false; |
|
141 | + if ($view == 'search' && (!defined('FRONT_END_SEARCH') || !FRONT_END_SEARCH)) { |
|
142 | + return false; |
|
143 | + } |
|
143 | 144 | |
144 | 145 | $validviews = array ('calendar', 'date', 'gid', 'person', 'search', 'search_min', 'search_video', 'recent', 'recent_mostvotes', 'biggest_debates', 'recent_wrans', 'recent_wms', 'column', 'mp', 'bill', 'session', 'recent_debates', 'recent_pbc_debates', 'featured_gid'); |
145 | 146 | if (in_array($view, $validviews)) { |
@@ -149,7 +150,8 @@ discard block |
||
149 | 150 | // Get all the data that's to be rendered. |
150 | 151 | $data = $this->$function($args); |
151 | 152 | |
152 | - } else { |
|
153 | + } |
|
154 | + else { |
|
153 | 155 | // Don't have a valid $view. |
154 | 156 | $PAGE->error_message ("You haven't specified a view type."); |
155 | 157 | return false; |
@@ -290,7 +292,8 @@ discard block |
||
290 | 292 | $sectiondata = $sectiondata[0]; |
291 | 293 | } |
292 | 294 | |
293 | - } else { |
|
295 | + } |
|
296 | + else { |
|
294 | 297 | // This item *is* a section, so just return that. |
295 | 298 | |
296 | 299 | $sectiondata = $itemdata; |
@@ -326,12 +329,15 @@ discard block |
||
326 | 329 | ); |
327 | 330 | |
328 | 331 | $subsectiondata = $this->_get_hansard_data($input); |
329 | - if (count($subsectiondata) == 0) |
|
330 | - $subsectiondata = null; |
|
331 | - else |
|
332 | - $subsectiondata = $subsectiondata[0]; |
|
332 | + if (count($subsectiondata) == 0) { |
|
333 | + $subsectiondata = null; |
|
334 | + } |
|
335 | + else { |
|
336 | + $subsectiondata = $subsectiondata[0]; |
|
337 | + } |
|
333 | 338 | |
334 | - } elseif ($itemdata['htype'] == '11') { |
|
339 | + } |
|
340 | + elseif ($itemdata['htype'] == '11') { |
|
335 | 341 | // It's a subsection, so use the item itself. |
336 | 342 | $subsectiondata = $itemdata; |
337 | 343 | } |
@@ -359,10 +365,12 @@ discard block |
||
359 | 365 | // Debate subsection or section - get the next one. |
360 | 366 | if ($hansardmajors[$itemdata['major']]['type'] == 'other' && $hansardmajors[$itemdata['major']]['location'] == 'UK') { |
361 | 367 | $where = 'htype = 11'; |
362 | - } else { |
|
368 | + } |
|
369 | + else { |
|
363 | 370 | $where = "(htype = 10 OR htype = 11)"; |
364 | 371 | } |
365 | - } else { |
|
372 | + } |
|
373 | + else { |
|
366 | 374 | // Anything else in debates - get the next element that isn't |
367 | 375 | // a subsection or section, and is within THIS subsection. |
368 | 376 | $where = "subsection_id = '" . $itemdata['subsection_id'] . "' AND (htype != 10 AND htype != 11)"; |
@@ -434,12 +442,14 @@ discard block |
||
434 | 442 | 'url' => $prevdata[0]['listurl'], |
435 | 443 | 'title' => $prevdata[0]['body'] |
436 | 444 | ); |
437 | - } else { |
|
445 | + } |
|
446 | + else { |
|
438 | 447 | // Linking to the prev speaker. |
439 | 448 | |
440 | 449 | if (isset($prevdata[0]['speaker']) && count($prevdata[0]['speaker']) > 0) { |
441 | 450 | $title = $prevdata[0]['speaker']['name']; |
442 | - } else { |
|
451 | + } |
|
452 | + else { |
|
443 | 453 | $title = ''; |
444 | 454 | } |
445 | 455 | $nextprevdata['prev'] = array ( |
@@ -478,12 +488,14 @@ discard block |
||
478 | 488 | 'url' => $nextdata[0]['listurl'], |
479 | 489 | 'title' => $nextdata[0]['body'] |
480 | 490 | ); |
481 | - } else { |
|
491 | + } |
|
492 | + else { |
|
482 | 493 | // Linking to the next speaker. |
483 | 494 | |
484 | 495 | if (isset($nextdata[0]['speaker']) && count($nextdata[0]['speaker']) > 0) { |
485 | 496 | $title = $nextdata[0]['speaker']['name']; |
486 | - } else { |
|
497 | + } |
|
498 | + else { |
|
487 | 499 | $title = ''; |
488 | 500 | } |
489 | 501 | $nextprevdata['next'] = array ( |
@@ -503,7 +515,8 @@ discard block |
||
503 | 515 | 'title' => '', |
504 | 516 | 'url' => $URL->generate() . $this->url, |
505 | 517 | ); |
506 | - } elseif ($itemdata['htype'] == '10' || $itemdata['htype'] == '11') { |
|
518 | + } |
|
519 | + elseif ($itemdata['htype'] == '10' || $itemdata['htype'] == '11') { |
|
507 | 520 | $URL = new \MySociety\TheyWorkForYou\Url($this->listpage); |
508 | 521 | // Create URL for this (sub)section's date. |
509 | 522 | $URL->insert(array('d' => $itemdata['hdate'])); |
@@ -514,7 +527,8 @@ discard block |
||
514 | 527 | 'title' => '', |
515 | 528 | 'url' => $URL->generate() |
516 | 529 | ); |
517 | - } else { |
|
530 | + } |
|
531 | + else { |
|
518 | 532 | // We'll be setting $nextprevdata['up'] within $this->get_data_by_gid() |
519 | 533 | // because we need to know the name and url of the parent item, which |
520 | 534 | // we don't have here. Life sucks. |
@@ -550,7 +564,8 @@ discard block |
||
550 | 564 | FROM hansard |
551 | 565 | WHERE major = :major |
552 | 566 | AND hdate > :date", $params); |
553 | - } else { |
|
567 | + } |
|
568 | + else { |
|
554 | 569 | $q = $this->db->query("SELECT MAX(hdate) AS hdate |
555 | 570 | FROM hansard |
556 | 571 | WHERE major = :major |
@@ -565,7 +580,8 @@ discard block |
||
565 | 580 | |
566 | 581 | if ($nextorprev == 'next') { |
567 | 582 | $body = 'Next day'; |
568 | - } else { |
|
583 | + } |
|
584 | + else { |
|
569 | 585 | $body = 'Previous day'; |
570 | 586 | } |
571 | 587 | |
@@ -605,7 +621,8 @@ discard block |
||
605 | 621 | |
606 | 622 | if (isset($args['date'])) { |
607 | 623 | $date = $args['date']; |
608 | - } else { |
|
624 | + } |
|
625 | + else { |
|
609 | 626 | $PAGE->error_message ("Sorry, we don't have a date."); |
610 | 627 | return false; |
611 | 628 | } |
@@ -661,7 +678,8 @@ discard block |
||
661 | 678 | $q = $this->db->query ("SELECT gid_to FROM gidredirect WHERE gid_from = :gid", array(':gid' => $gid)); |
662 | 679 | if ($q->rows() == 0) { |
663 | 680 | $itemdata = $this->_get_hansard_data($input); |
664 | - } else { |
|
681 | + } |
|
682 | + else { |
|
665 | 683 | do { |
666 | 684 | $gid = $q->field(0, 'gid_to'); |
667 | 685 | $q = $this->db->query("SELECT gid_to FROM gidredirect WHERE gid_from = :gid", array(':gid' => $gid)); |
@@ -841,7 +859,8 @@ discard block |
||
841 | 859 | if (isset($args['days']) && is_numeric($args['days'])) { |
842 | 860 | $limit = 'LIMIT :limit'; |
843 | 861 | $params[':limit'] = $args['days']; |
844 | - } else { |
|
862 | + } |
|
863 | + else { |
|
845 | 864 | $limit = ''; |
846 | 865 | } |
847 | 866 | |
@@ -850,7 +869,8 @@ discard block |
||
850 | 869 | |
851 | 870 | $major = 'WHERE major = :major'; |
852 | 871 | $params[':major'] = $this->major; |
853 | - } else { |
|
872 | + } |
|
873 | + else { |
|
854 | 874 | $major = ''; |
855 | 875 | } |
856 | 876 | |
@@ -908,7 +928,8 @@ discard block |
||
908 | 928 | if (isset($this->major)) { |
909 | 929 | $majorwhere = "AND hansard.major = :hansard_major "; |
910 | 930 | $params[':hansard_major'] = $this->major; |
911 | - } else { |
|
931 | + } |
|
932 | + else { |
|
912 | 933 | // We're getting results for all debates/wrans/etc. |
913 | 934 | $majorwhere = ''; |
914 | 935 | } |
@@ -973,7 +994,8 @@ discard block |
||
973 | 994 | } |
974 | 995 | } |
975 | 996 | $data['rows'] = $speeches; |
976 | - } else { |
|
997 | + } |
|
998 | + else { |
|
977 | 999 | $data['rows'] = array(); |
978 | 1000 | } |
979 | 1001 | return $data; |
@@ -1000,10 +1022,12 @@ discard block |
||
1000 | 1022 | // $args['s'] should have been tidied up by the time we get here. |
1001 | 1023 | // eg, by doing filter_user_input($s, 'strict'); |
1002 | 1024 | $searchstring = $args['s']; |
1003 | - } else { |
|
1025 | + } |
|
1026 | + else { |
|
1004 | 1027 | if ( isset($args['exceptions']) ) { |
1005 | 1028 | throw new \Exception('No search string provided.'); |
1006 | - } else { |
|
1029 | + } |
|
1030 | + else { |
|
1007 | 1031 | $PAGE->error_message("No search string"); |
1008 | 1032 | return false; |
1009 | 1033 | } |
@@ -1022,22 +1046,25 @@ discard block |
||
1022 | 1046 | else { |
1023 | 1047 | $results_per_page = 20; |
1024 | 1048 | } |
1025 | - if ($results_per_page > 1000) |
|
1026 | - $results_per_page = 1000; |
|
1049 | + if ($results_per_page > 1000) { |
|
1050 | + $results_per_page = 1000; |
|
1051 | + } |
|
1027 | 1052 | |
1028 | 1053 | $data['info']['results_per_page'] = $results_per_page; |
1029 | 1054 | |
1030 | 1055 | // What page are we on? |
1031 | 1056 | if (isset($args['p']) && is_numeric($args['p'])) { |
1032 | 1057 | $page = $args['p']; |
1033 | - } else { |
|
1058 | + } |
|
1059 | + else { |
|
1034 | 1060 | $page = 1; |
1035 | 1061 | } |
1036 | 1062 | $data['info']['page'] = $page; |
1037 | 1063 | |
1038 | 1064 | if (isset($args['e'])) { |
1039 | 1065 | $encode = 'url'; |
1040 | - } else { |
|
1066 | + } |
|
1067 | + else { |
|
1041 | 1068 | $encode = 'html'; |
1042 | 1069 | } |
1043 | 1070 | |
@@ -1051,10 +1078,18 @@ discard block |
||
1051 | 1078 | // Get the gids from Xapian |
1052 | 1079 | $sort_order = 'date'; |
1053 | 1080 | if (isset($args['o'])) { |
1054 | - if ($args['o']=='d') $sort_order = 'newest'; |
|
1055 | - if ($args['o']=='o') $sort_order = 'oldest'; |
|
1056 | - elseif ($args['o']=='c') $sort_order = 'created'; |
|
1057 | - elseif ($args['o']=='r') $sort_order = 'relevance'; |
|
1081 | + if ($args['o']=='d') { |
|
1082 | + $sort_order = 'newest'; |
|
1083 | + } |
|
1084 | + if ($args['o']=='o') { |
|
1085 | + $sort_order = 'oldest'; |
|
1086 | + } |
|
1087 | + elseif ($args['o']=='c') { |
|
1088 | + $sort_order = 'created'; |
|
1089 | + } |
|
1090 | + elseif ($args['o']=='r') { |
|
1091 | + $sort_order = 'relevance'; |
|
1092 | + } |
|
1058 | 1093 | } |
1059 | 1094 | |
1060 | 1095 | $data['searchdescription'] = $SEARCHENGINE->query_description_long(); |
@@ -1114,7 +1149,9 @@ discard block |
||
1114 | 1149 | FROM future |
1115 | 1150 | LEFT JOIN future_people ON id=calendar_id AND witness=0 |
1116 | 1151 | WHERE id = $id AND deleted=0"); |
1117 | - if ($q->rows() == 0) continue; |
|
1152 | + if ($q->rows() == 0) { |
|
1153 | + continue; |
|
1154 | + } |
|
1118 | 1155 | |
1119 | 1156 | $itemdata = $q->row(0); |
1120 | 1157 | |
@@ -1123,8 +1160,9 @@ discard block |
||
1123 | 1160 | in_array($itemdata['chamber'], array( |
1124 | 1161 | 'Commons: Main Chamber', 'Lords: Main Chamber', |
1125 | 1162 | 'Commons: Westminster Hall', |
1126 | - ))) |
|
1127 | - continue; |
|
1163 | + ))) { |
|
1164 | + continue; |
|
1165 | + } |
|
1128 | 1166 | |
1129 | 1167 | list($cal_item, $cal_meta) = \MySociety\TheyWorkForYou\Utility\Calendar::meta($itemdata); |
1130 | 1168 | $body = $this->prepare_search_result_for_display($cal_item) . '.'; |
@@ -1139,7 +1177,8 @@ discard block |
||
1139 | 1177 | |
1140 | 1178 | if ($itemdata['event_date'] >= date('Y-m-d')) { |
1141 | 1179 | $title = 'Upcoming Business'; |
1142 | - } else { |
|
1180 | + } |
|
1181 | + else { |
|
1143 | 1182 | $title = 'Previous Business'; |
1144 | 1183 | } |
1145 | 1184 | $itemdata['gid'] = $id; |
@@ -1149,7 +1188,8 @@ discard block |
||
1149 | 1188 | $itemdata['listurl'] = '/calendar/?d=' . $itemdata['event_date'] . '#cal' . $itemdata['id']; |
1150 | 1189 | $itemdata['major'] = 'F'; |
1151 | 1190 | |
1152 | - } else { |
|
1191 | + } |
|
1192 | + else { |
|
1153 | 1193 | |
1154 | 1194 | // Get the data for the gid from the database |
1155 | 1195 | $q = $this->db->query("SELECT hansard.gid, hansard.hdate, |
@@ -1165,7 +1205,8 @@ discard block |
||
1165 | 1205 | if ($q->rows() > 1) { |
1166 | 1206 | if ( $isset($args['exceptions']) ) { |
1167 | 1207 | throw new \Exception("Got more than one row getting data for $gid."); |
1168 | - } else { |
|
1208 | + } |
|
1209 | + else { |
|
1169 | 1210 | $PAGE->error_message("Got more than one row getting data for $gid"); |
1170 | 1211 | } |
1171 | 1212 | } |
@@ -1220,27 +1261,39 @@ discard block |
||
1220 | 1261 | } |
1221 | 1262 | if ($itemdata['major'] == 5) { |
1222 | 1263 | $itemdata['parent']['body'] = 'Northern Ireland Assembly: ' . $itemdata['parent']['body']; |
1223 | - } elseif ($itemdata['major'] == 6) { |
|
1264 | + } |
|
1265 | + elseif ($itemdata['major'] == 6) { |
|
1224 | 1266 | $itemdata['parent']['body'] = 'Public Bill Committee: ' . $itemdata['parent']['body']; |
1225 | - } elseif ($itemdata['major'] == 7) { |
|
1267 | + } |
|
1268 | + elseif ($itemdata['major'] == 7) { |
|
1226 | 1269 | $itemdata['parent']['body'] = 'Scottish Parliament: ' . $itemdata['parent']['body']; |
1227 | 1270 | } |
1228 | 1271 | |
1229 | - } else { |
|
1272 | + } |
|
1273 | + else { |
|
1230 | 1274 | // It's a section, so it will be its own title. |
1231 | 1275 | $itemdata['parent']['body'] = $itemdata['body']; |
1232 | 1276 | $itemdata['body'] = ''; |
1233 | 1277 | } |
1234 | 1278 | |
1235 | - } else { |
|
1279 | + } |
|
1280 | + else { |
|
1236 | 1281 | // Wrans or WMS |
1237 | 1282 | $section = $this->_get_section($itemdata); |
1238 | 1283 | $subsection = $this->_get_subsection($itemdata); |
1239 | 1284 | $body = $hansardmajors[$itemdata['major']]['title'] . ' — '; |
1240 | - if (isset($section['body'])) $body .= $section['body']; |
|
1241 | - if (isset($subsection['body'])) $body .= ': ' . $subsection['body']; |
|
1242 | - if (isset($subsection['listurl'])) $listurl = $subsection['listurl']; |
|
1243 | - else $listurl = ''; |
|
1285 | + if (isset($section['body'])) { |
|
1286 | + $body .= $section['body']; |
|
1287 | + } |
|
1288 | + if (isset($subsection['body'])) { |
|
1289 | + $body .= ': ' . $subsection['body']; |
|
1290 | + } |
|
1291 | + if (isset($subsection['listurl'])) { |
|
1292 | + $listurl = $subsection['listurl']; |
|
1293 | + } |
|
1294 | + else { |
|
1295 | + $listurl = ''; |
|
1296 | + } |
|
1244 | 1297 | $itemdata['parent'] = array ( |
1245 | 1298 | 'body' => $body, |
1246 | 1299 | 'listurl' => $listurl |
@@ -1268,7 +1321,8 @@ discard block |
||
1268 | 1321 | $itemdata['speaker'] = $this->_get_speaker($itemdata['person_id'], $itemdata['hdate'], $itemdata['htime'], $itemdata['major']); |
1269 | 1322 | } |
1270 | 1323 | } |
1271 | - } elseif ($itemdata['htype'] == 10) { |
|
1324 | + } |
|
1325 | + elseif ($itemdata['htype'] == 10) { |
|
1272 | 1326 | $itemdata['body'] = ''; |
1273 | 1327 | $itemdata['extract'] = ''; |
1274 | 1328 | } |
@@ -1367,17 +1421,20 @@ discard block |
||
1367 | 1421 | return $data; |
1368 | 1422 | } |
1369 | 1423 | |
1370 | - } elseif (isset($args['year']) && is_numeric($args['year'])) { |
|
1424 | + } |
|
1425 | + elseif (isset($args['year']) && is_numeric($args['year'])) { |
|
1371 | 1426 | |
1372 | 1427 | if (isset($args['month']) && is_numeric($args['month'])) { |
1373 | 1428 | // A particular month. |
1374 | 1429 | $action = 'month'; |
1375 | - } else { |
|
1430 | + } |
|
1431 | + else { |
|
1376 | 1432 | // A single year. |
1377 | 1433 | $action = 'year'; |
1378 | 1434 | } |
1379 | 1435 | |
1380 | - } else { |
|
1436 | + } |
|
1437 | + else { |
|
1381 | 1438 | // The year to date so far. |
1382 | 1439 | $action = 'recentyear'; |
1383 | 1440 | } |
@@ -1405,7 +1462,8 @@ discard block |
||
1405 | 1462 | |
1406 | 1463 | if ($q->field(0, 'hdate') != NULL) { |
1407 | 1464 | $recentdate = $q->field(0, 'hdate'); |
1408 | - } else { |
|
1465 | + } |
|
1466 | + else { |
|
1409 | 1467 | $PAGE->error_message("Couldn't find the most recent date"); |
1410 | 1468 | return $data; |
1411 | 1469 | } |
@@ -1433,7 +1491,8 @@ discard block |
||
1433 | 1491 | $firstmonth = 12 + $firstmonth; // () |
1434 | 1492 | }; |
1435 | 1493 | |
1436 | - } else { |
|
1494 | + } |
|
1495 | + else { |
|
1437 | 1496 | // $action == 'recentyear' |
1438 | 1497 | |
1439 | 1498 | // Get the most recent year's results. |
@@ -1443,7 +1502,8 @@ discard block |
||
1443 | 1502 | |
1444 | 1503 | |
1445 | 1504 | |
1446 | - } else { |
|
1505 | + } |
|
1506 | + else { |
|
1447 | 1507 | // $action == 'year' or 'month'. |
1448 | 1508 | |
1449 | 1509 | $firstyear = $args['year']; |
@@ -1452,7 +1512,8 @@ discard block |
||
1452 | 1512 | if ($action == 'month') { |
1453 | 1513 | $firstmonth = intval($args['month']); |
1454 | 1514 | $finalmonth = intval($args['month']); |
1455 | - } else { |
|
1515 | + } |
|
1516 | + else { |
|
1456 | 1517 | $firstmonth = 1; |
1457 | 1518 | $finalmonth = 12; |
1458 | 1519 | } |
@@ -1524,7 +1585,8 @@ discard block |
||
1524 | 1585 | |
1525 | 1586 | if (!isset($years[$y])) { |
1526 | 1587 | $years[$y] = array(1=>array(), 2=>array(), 3=>array(), 4=>array(), 5=>array(), 6=>array(), 7=>array(), 8=>array(), 9=>array(), 10=>array(), 11=>array(), 12=>array()); |
1527 | - } else { |
|
1588 | + } |
|
1589 | + else { |
|
1528 | 1590 | |
1529 | 1591 | // This year is set. Check it has all the months... |
1530 | 1592 | |
@@ -1565,7 +1627,9 @@ discard block |
||
1565 | 1627 | 'url' => $YEARURL->generate() |
1566 | 1628 | ); |
1567 | 1629 | |
1568 | - } else { // action is 'year'. |
|
1630 | + } |
|
1631 | + else { |
|
1632 | +// action is 'year'. |
|
1569 | 1633 | |
1570 | 1634 | $nextprev['prev'] = array ('body' => 'Previous year'); |
1571 | 1635 | $nextprev['next'] = array ('body' => 'Next year'); |
@@ -1684,7 +1748,8 @@ discard block |
||
1684 | 1748 | ) { |
1685 | 1749 | $fieldsarr['epobject'] = array ('body'); |
1686 | 1750 | $join = 'LEFT OUTER JOIN epobject ON hansard.epobject_id = epobject.epobject_id'; |
1687 | - } else { |
|
1751 | + } |
|
1752 | + else { |
|
1688 | 1753 | $join = ''; |
1689 | 1754 | } |
1690 | 1755 | |
@@ -1712,14 +1777,16 @@ discard block |
||
1712 | 1777 | if ($order != '') { |
1713 | 1778 | # You can't use parameters for order by clauses |
1714 | 1779 | $order_by_clause = "ORDER BY $order"; |
1715 | - } else { |
|
1780 | + } |
|
1781 | + else { |
|
1716 | 1782 | $order_by_clause = ''; |
1717 | 1783 | } |
1718 | 1784 | |
1719 | 1785 | if ($limit != '') { |
1720 | 1786 | $params[':limit'] = $limit; |
1721 | 1787 | $limit = "LIMIT :limit"; |
1722 | - } else { |
|
1788 | + } |
|
1789 | + else { |
|
1723 | 1790 | $limit = ''; |
1724 | 1791 | } |
1725 | 1792 | |
@@ -1790,7 +1857,8 @@ discard block |
||
1790 | 1857 | $where = "section_id = '" . $item['epobject_id'] . "' |
1791 | 1858 | AND subsection_id = '" . $item['epobject_id'] . "'"; |
1792 | 1859 | |
1793 | - } else { |
|
1860 | + } |
|
1861 | + else { |
|
1794 | 1862 | // Subsection - get a count of items within this subsection. |
1795 | 1863 | $where = "subsection_id = '" . $item['epobject_id'] . "'"; |
1796 | 1864 | } |
@@ -1803,7 +1871,8 @@ discard block |
||
1803 | 1871 | |
1804 | 1872 | if ($r->rows() > 0) { |
1805 | 1873 | $item['contentcount'] = $r->field(0, 'count'); |
1806 | - } else { |
|
1874 | + } |
|
1875 | + else { |
|
1807 | 1876 | $item['contentcount'] = '0'; |
1808 | 1877 | } |
1809 | 1878 | } |
@@ -1820,7 +1889,8 @@ discard block |
||
1820 | 1889 | if ($item['htype'] == '10') { |
1821 | 1890 | $where = 'hansard.section_id = :epobject_id |
1822 | 1891 | AND hansard.subsection_id = :epobject_id'; |
1823 | - } elseif ($item['htype'] == '11') { |
|
1892 | + } |
|
1893 | + elseif ($item['htype'] == '11') { |
|
1824 | 1894 | $where = 'hansard.subsection_id = :epobject_id'; |
1825 | 1895 | } |
1826 | 1896 | |
@@ -1865,7 +1935,8 @@ discard block |
||
1865 | 1935 | $id = preg_replace('#^.*?_.*?_#', '', $item['gid']); |
1866 | 1936 | $fragment = $this->url . $id; |
1867 | 1937 | $item['commentsurl'] = $COMMENTSURL->generate() . $fragment; |
1868 | - } else { |
|
1938 | + } |
|
1939 | + else { |
|
1869 | 1940 | $COMMENTSURL->insert(array('id' => $item['gid'])); |
1870 | 1941 | $item['commentsurl'] = $COMMENTSURL->generate(); |
1871 | 1942 | } |
@@ -1927,7 +1998,8 @@ discard block |
||
1927 | 1998 | |
1928 | 1999 | if ($q->rows() > 0) { |
1929 | 2000 | $votes['user']['yes'] = $q->field(0, 'totalvotes'); |
1930 | - } else { |
|
2001 | + } |
|
2002 | + else { |
|
1931 | 2003 | $votes['user']['yes'] = '0'; |
1932 | 2004 | } |
1933 | 2005 | |
@@ -1940,7 +2012,8 @@ discard block |
||
1940 | 2012 | |
1941 | 2013 | if ($q->rows() > 0) { |
1942 | 2014 | $votes['user']['no'] = $q->field(0, 'totalvotes'); |
1943 | - } else { |
|
2015 | + } |
|
2016 | + else { |
|
1944 | 2017 | $votes['user']['no'] = '0'; |
1945 | 2018 | } |
1946 | 2019 | |
@@ -1956,7 +2029,8 @@ discard block |
||
1956 | 2029 | if ($q->rows() > 0) { |
1957 | 2030 | $votes['anon']['yes'] = $q->field(0, 'yes_votes'); |
1958 | 2031 | $votes['anon']['no'] = $q->field(0, 'no_votes'); |
1959 | - } else { |
|
2032 | + } |
|
2033 | + else { |
|
1960 | 2034 | $votes['anon']['yes'] = '0'; |
1961 | 2035 | $votes['anon']['no'] = '0'; |
1962 | 2036 | } |
@@ -1980,10 +2054,12 @@ discard block |
||
1980 | 2054 | // ); |
1981 | 2055 | |
1982 | 2056 | // $url_args is an array of other key/value pairs to be appended in the GET string. |
1983 | - if ($id_data['major']) |
|
1984 | - $LISTURL = new \MySociety\TheyWorkForYou\Url($hansardmajors[$id_data['major']]['page_all']); |
|
1985 | - else |
|
1986 | - $LISTURL = new \MySociety\TheyWorkForYou\Url('wrans'); |
|
2057 | + if ($id_data['major']) { |
|
2058 | + $LISTURL = new \MySociety\TheyWorkForYou\Url($hansardmajors[$id_data['major']]['page_all']); |
|
2059 | + } |
|
2060 | + else { |
|
2061 | + $LISTURL = new \MySociety\TheyWorkForYou\Url('wrans'); |
|
2062 | + } |
|
1987 | 2063 | |
1988 | 2064 | $fragment = ''; |
1989 | 2065 | |
@@ -1993,10 +2069,12 @@ discard block |
||
1993 | 2069 | global $DATA; |
1994 | 2070 | $DATA->set_page_metadata('pbc_clause', 'url', 'pbc/' . $this->url . $id); |
1995 | 2071 | $LISTURL->remove(array('id')); |
1996 | - } else { |
|
2072 | + } |
|
2073 | + else { |
|
1997 | 2074 | $LISTURL->insert( array( 'id' => $id_data['gid'] ) ); |
1998 | 2075 | } |
1999 | - } else { |
|
2076 | + } |
|
2077 | + else { |
|
2000 | 2078 | // A debate speech or question/answer, etc. |
2001 | 2079 | // We need to get the gid of the parent (sub)section for this item. |
2002 | 2080 | // We use this with the gid of the item itself as an #anchor. |
@@ -2012,7 +2090,8 @@ discard block |
||
2012 | 2090 | |
2013 | 2091 | $parent_gid = $this->epobjectid_to_gid[ $parent_epobject_id ]; |
2014 | 2092 | |
2015 | - } else { |
|
2093 | + } |
|
2094 | + else { |
|
2016 | 2095 | // We haven't cached the gid, so fetch from db. |
2017 | 2096 | |
2018 | 2097 | $r = $this->db->query("SELECT gid |
@@ -2035,7 +2114,8 @@ discard block |
||
2035 | 2114 | if ($id_data['major'] == 6) { |
2036 | 2115 | if (isset($this->bill_lookup[$minor])) { |
2037 | 2116 | list($title, $session) = $this->bill_lookup[$minor]; |
2038 | - } else { |
|
2117 | + } |
|
2118 | + else { |
|
2039 | 2119 | $qq = $this->db->query('select title, session from bills where id='.$minor); |
2040 | 2120 | $title = $qq->field(0, 'title'); |
2041 | 2121 | $session = $qq->field(0, 'session'); |
@@ -2046,7 +2126,8 @@ discard block |
||
2046 | 2126 | global $DATA; |
2047 | 2127 | $DATA->set_page_metadata('pbc_clause', 'url', "pbc/$url/$parent_gid"); |
2048 | 2128 | $LISTURL->remove(array('id')); |
2049 | - } else { |
|
2129 | + } |
|
2130 | + else { |
|
2050 | 2131 | $LISTURL->insert( array( 'id' => $parent_gid ) ); |
2051 | 2132 | } |
2052 | 2133 | // Use a truncated form of this item's gid for the anchor. |
@@ -2088,9 +2169,11 @@ discard block |
||
2088 | 2169 | # Note identical code to this in search/index.pl |
2089 | 2170 | if ($person_id == 10170 && $hdate == '2014-09-08') { |
2090 | 2171 | $hdate = '2014-09-07'; |
2091 | - } elseif ($person_id == 11068 && substr($hdate, 0, 7) == '2008-09') { |
|
2172 | + } |
|
2173 | + elseif ($person_id == 11068 && substr($hdate, 0, 7) == '2008-09') { |
|
2092 | 2174 | $hdate = '2008-08-13'; |
2093 | - } elseif ($person_id == 25394 && $hdate == '2016-07-01') { |
|
2175 | + } |
|
2176 | + elseif ($person_id == 25394 && $hdate == '2016-07-01') { |
|
2094 | 2177 | $hdate = '2016-06-16'; |
2095 | 2178 | } |
2096 | 2179 | |
@@ -2155,7 +2238,8 @@ discard block |
||
2155 | 2238 | # Couple of special cases for the election of the NI Speaker |
2156 | 2239 | if ($person_id == 13799 && $hdate == '2007-05-08') { |
2157 | 2240 | $members = array($members[$htime < '11:00' ? 0 : 1]); |
2158 | - } elseif ($person_id == 13831 && $hdate == '2015-01-12') { |
|
2241 | + } |
|
2242 | + elseif ($person_id == 13831 && $hdate == '2015-01-12') { |
|
2159 | 2243 | $members = array($members[$htime < '13:00' ? 0 : 1]); |
2160 | 2244 | } |
2161 | 2245 | } |
@@ -2170,11 +2254,14 @@ discard block |
||
2170 | 2254 | $URL = new \MySociety\TheyWorkForYou\Url('mp'); # Default, house=1 |
2171 | 2255 | if ($house==2) { |
2172 | 2256 | $URL = new \MySociety\TheyWorkForYou\Url('peer'); |
2173 | - } elseif ($house==3) { |
|
2257 | + } |
|
2258 | + elseif ($house==3) { |
|
2174 | 2259 | $URL = new \MySociety\TheyWorkForYou\Url('mla'); |
2175 | - } elseif ($house==4) { |
|
2260 | + } |
|
2261 | + elseif ($house==4) { |
|
2176 | 2262 | $URL = new \MySociety\TheyWorkForYou\Url('msp'); |
2177 | - } elseif ($house==0) { |
|
2263 | + } |
|
2264 | + elseif ($house==0) { |
|
2178 | 2265 | $URL = new \MySociety\TheyWorkForYou\Url('royal'); |
2179 | 2266 | } |
2180 | 2267 | return $URL; |
@@ -2293,7 +2380,8 @@ discard block |
||
2293 | 2380 | $where .= " AND section_id = :epobject_id"; |
2294 | 2381 | } |
2295 | 2382 | |
2296 | - } else { |
|
2383 | + } |
|
2384 | + else { |
|
2297 | 2385 | // Just getting a count of the comments on this item. |
2298 | 2386 | $from = "comments"; |
2299 | 2387 | $where = 'epobject_id = :epobject_id'; |
@@ -2413,7 +2501,8 @@ discard block |
||
2413 | 2501 | $this->htype = $itemdata['htype']; |
2414 | 2502 | if ($this->htype >= 12) { |
2415 | 2503 | $this_page = $this->commentspage; |
2416 | - } else { |
|
2504 | + } |
|
2505 | + else { |
|
2417 | 2506 | $this_page = $this->listpage; |
2418 | 2507 | } |
2419 | 2508 | } |
@@ -2454,18 +2543,21 @@ discard block |
||
2454 | 2543 | $nextprev = $this->_get_nextprev_items( $sectionrow ); |
2455 | 2544 | $data['info']['text_heading'] = $itemdata['body']; |
2456 | 2545 | |
2457 | - } elseif ($itemdata['htype'] == '11') { |
|
2546 | + } |
|
2547 | + elseif ($itemdata['htype'] == '11') { |
|
2458 | 2548 | $nextprev = $this->_get_nextprev_items( $subsectionrow ); |
2459 | 2549 | $data['info']['text_heading'] = $itemdata['body']; |
2460 | 2550 | |
2461 | - } else { |
|
2551 | + } |
|
2552 | + else { |
|
2462 | 2553 | // Ordinary lowly item. |
2463 | 2554 | $nextprev = $this->_get_nextprev_items( $itemdata ); |
2464 | 2555 | |
2465 | 2556 | if (isset($subsectionrow['gid'])) { |
2466 | 2557 | $nextprev['up']['url'] = $subsectionrow['listurl']; |
2467 | 2558 | $nextprev['up']['title'] = $subsectionrow['body']; |
2468 | - } else { |
|
2559 | + } |
|
2560 | + else { |
|
2469 | 2561 | $nextprev['up']['url'] = $sectionrow['listurl']; |
2470 | 2562 | $nextprev['up']['title'] = $sectionrow['body']; |
2471 | 2563 | } |
@@ -2522,7 +2614,8 @@ discard block |
||
2522 | 2614 | throw new RedirectException($data['subrows'][0]['gid']); |
2523 | 2615 | } |
2524 | 2616 | } |
2525 | - } elseif ($itemdata['htype'] == '11') { |
|
2617 | + } |
|
2618 | + elseif ($itemdata['htype'] == '11') { |
|
2526 | 2619 | // This item is a subsection, so we're displaying everything within it. |
2527 | 2620 | |
2528 | 2621 | # $subsectionrow['trackback'] = $this->_get_trackback_data($subsectionrow); |
@@ -2538,7 +2631,8 @@ discard block |
||
2538 | 2631 | $data['rows'] = $this->_get_hansard_data($input); |
2539 | 2632 | |
2540 | 2633 | |
2541 | - } elseif ($itemdata['htype'] == '12' || $itemdata['htype'] == '13') { |
|
2634 | + } |
|
2635 | + elseif ($itemdata['htype'] == '12' || $itemdata['htype'] == '13') { |
|
2542 | 2636 | // Debate speech or procedural, so we're just displaying this one item. |
2543 | 2637 | |
2544 | 2638 | # $itemdata['trackback'] = $this->_get_trackback_data($itemdata); |
@@ -2633,7 +2727,9 @@ discard block |
||
2633 | 2727 | array(':gid_from_spid' => 'uk.org.publicwhip/spq/' . $fixed_spid) |
2634 | 2728 | ); |
2635 | 2729 | $gid = $q->field(0, 'mentioned_gid'); |
2636 | - if ($gid) return $gid; |
|
2730 | + if ($gid) { |
|
2731 | + return $gid; |
|
2732 | + } |
|
2637 | 2733 | return null; |
2638 | 2734 | } |
2639 | 2735 | public function old_get_gid_from_spid($spid) { |
@@ -2642,7 +2738,9 @@ discard block |
||
2642 | 2738 | array(':gid_like' => 'uk.org.publicwhip/spwa/%.' . $spid . '.h') |
2643 | 2739 | ); |
2644 | 2740 | $gid = $q->field(0, 'gid'); |
2645 | - if ($gid) return str_replace('uk.org.publicwhip/spwa/', '', $gid); |
|
2741 | + if ($gid) { |
|
2742 | + return str_replace('uk.org.publicwhip/spwa/', '', $gid); |
|
2743 | + } |
|
2646 | 2744 | return null; |
2647 | 2745 | } |
2648 | 2746 | } |
@@ -2668,14 +2766,16 @@ discard block |
||
2668 | 2766 | // The most voted on things during how many recent days? |
2669 | 2767 | if (isset($args['days']) && is_numeric($args['days'])) { |
2670 | 2768 | $days = $args['days']; |
2671 | - } else { |
|
2769 | + } |
|
2770 | + else { |
|
2672 | 2771 | $days = 7; |
2673 | 2772 | } |
2674 | 2773 | |
2675 | 2774 | // How many results? |
2676 | 2775 | if (isset($args['num']) && is_numeric($args['num'])) { |
2677 | 2776 | $items_to_list = $args['num']; |
2678 | - } else { |
|
2777 | + } |
|
2778 | + else { |
|
2679 | 2779 | $items_to_list = 5; |
2680 | 2780 | } |
2681 | 2781 | |
@@ -2757,7 +2857,8 @@ discard block |
||
2757 | 2857 | |
2758 | 2858 | $data['rows'] = $speeches; |
2759 | 2859 | |
2760 | - } else { |
|
2860 | + } |
|
2861 | + else { |
|
2761 | 2862 | $data['rows'] = array (); |
2762 | 2863 | } |
2763 | 2864 | |
@@ -2845,10 +2946,12 @@ discard block |
||
2845 | 2946 | $subsection_body = $r->field(0, 'sub_body'); |
2846 | 2947 | if ( $section_body && $subsection_body ) { |
2847 | 2948 | $parentbody = "$section_body : $subsection_body"; |
2848 | - } else { |
|
2949 | + } |
|
2950 | + else { |
|
2849 | 2951 | $parentbody = "$section_body$subsection_body"; |
2850 | 2952 | } |
2851 | - } else if ( $item_data['htype'] == 10 ) { |
|
2953 | + } |
|
2954 | + else if ( $item_data['htype'] == 10 ) { |
|
2852 | 2955 | $parentbody = $body; |
2853 | 2956 | } |
2854 | 2957 | |
@@ -2856,7 +2959,8 @@ discard block |
||
2856 | 2959 | if ( $item_data['htype'] == 12 ) { |
2857 | 2960 | $childbody = $body; |
2858 | 2961 | $speaker = $this->_get_speaker($q->field(0, 'person_id'), $q->field(0, 'hdate'), $q->field(0, 'htime'), $this->major ); |
2859 | - } else { |
|
2962 | + } |
|
2963 | + else { |
|
2860 | 2964 | $r = $this->db->query("SELECT e.body, e.title, |
2861 | 2965 | h.person_id, h.hdate, h.htime |
2862 | 2966 | FROM hansard h, epobject e |
@@ -2928,7 +3032,9 @@ discard block |
||
2928 | 3032 | |
2929 | 3033 | // Get the most recent day on which we have a debate. |
2930 | 3034 | $recentday = $this->most_recent_day(); |
2931 | - if (!count($recentday)) return $data; |
|
3035 | + if (!count($recentday)) { |
|
3036 | + return $data; |
|
3037 | + } |
|
2932 | 3038 | |
2933 | 3039 | if (!isset($args['days']) || !is_numeric($args['days'])) { |
2934 | 3040 | $args['days'] = 1; |
@@ -2940,7 +3046,8 @@ discard block |
||
2940 | 3046 | if ($args['num'] == 1) { |
2941 | 3047 | $datewhere = "h.hdate = :hdate"; |
2942 | 3048 | $params[':hdate'] = $recentday['hdate']; |
2943 | - } else { |
|
3049 | + } |
|
3050 | + else { |
|
2944 | 3051 | $firstdate = gmdate('Y-m-d', $recentday['timestamp'] - (86400 * $args['days'])); |
2945 | 3052 | $datewhere = "h.hdate >= :firstdate |
2946 | 3053 | AND h.hdate <= :hdate"; |
@@ -3055,8 +3162,9 @@ discard block |
||
3055 | 3162 | |
3056 | 3163 | // Get the most recent day on which we have a debate. |
3057 | 3164 | $recentday = $this->most_recent_day(); |
3058 | - if (!count($recentday)) |
|
3059 | - return array(); |
|
3165 | + if (!count($recentday)) { |
|
3166 | + return array(); |
|
3167 | + } |
|
3060 | 3168 | |
3061 | 3169 | if (!isset($args['days']) || !is_numeric($args['days'])) { |
3062 | 3170 | $args['days'] = 1; |
@@ -3068,7 +3176,8 @@ discard block |
||
3068 | 3176 | $params = array(':recentdate' => $recentday['hdate']); |
3069 | 3177 | if ($args['num'] == 1) { |
3070 | 3178 | $datewhere = "h.hdate = :recentdate"; |
3071 | - } else { |
|
3179 | + } |
|
3180 | + else { |
|
3072 | 3181 | $params[':firstdate'] = gmdate('Y-m-d', $recentday['timestamp'] - (86400 * $args['days'])); |
3073 | 3182 | $datewhere = "h.hdate >= :firstdate AND h.hdate <= :recentdate"; |
3074 | 3183 | } |
@@ -3189,8 +3298,9 @@ discard block |
||
3189 | 3298 | |
3190 | 3299 | // Get the most recent day on which we have wrans. |
3191 | 3300 | $recentday = $this->most_recent_day(); |
3192 | - if (!count($recentday)) |
|
3193 | - return $data; |
|
3301 | + if (!count($recentday)) { |
|
3302 | + return $data; |
|
3303 | + } |
|
3194 | 3304 | |
3195 | 3305 | if (!isset($args['days']) || !is_numeric($args['days'])) { |
3196 | 3306 | $args['days'] = 1; |
@@ -3202,7 +3312,8 @@ discard block |
||
3202 | 3312 | if ($args['num'] == 1) { |
3203 | 3313 | $datewhere = "h.hdate = :datewhere"; |
3204 | 3314 | $params[':datewhere'] = $recentday['hdate']; |
3205 | - } else { |
|
3315 | + } |
|
3316 | + else { |
|
3206 | 3317 | $firstdate = gmdate('Y-m-d', $recentday['timestamp'] - (86400 * $args['days'])); |
3207 | 3318 | $datewhere = "h.hdate >= :firstdate AND h.hdate <= :hdate"; |
3208 | 3319 | $params[':firstdate'] = $firstdate; |
@@ -3213,7 +3324,8 @@ discard block |
||
3213 | 3324 | // Get a random selection of subsections in wrans. |
3214 | 3325 | if ($hansardmajors[$this->major]['location'] == 'Scotland') { |
3215 | 3326 | $htype = 'htype = 10 and section_id = 0'; |
3216 | - } else { |
|
3327 | + } |
|
3328 | + else { |
|
3217 | 3329 | $htype = 'htype = 11 and section_id != 0'; |
3218 | 3330 | } |
3219 | 3331 | |
@@ -3343,7 +3455,8 @@ discard block |
||
3343 | 3455 | ); |
3344 | 3456 | if ($chairman) { |
3345 | 3457 | $comm['chairmen'][$person_id] = $arr; |
3346 | - } else { |
|
3458 | + } |
|
3459 | + else { |
|
3347 | 3460 | $comm['members'][$person_id] = $arr; |
3348 | 3461 | } |
3349 | 3462 | } |
@@ -3470,7 +3583,9 @@ discard block |
||
3470 | 3583 | } |
3471 | 3584 | |
3472 | 3585 | public function _get_data_by_recent_pbc_debates($args) { |
3473 | - if (!isset($args['num'])) $args['num'] = 20; |
|
3586 | + if (!isset($args['num'])) { |
|
3587 | + $args['num'] = 20; |
|
3588 | + } |
|
3474 | 3589 | $q = $this->db->query('select gid, minor, hdate from hansard |
3475 | 3590 | where htype=10 and major=6 |
3476 | 3591 | order by hdate desc limit ' . $args['num']); |
@@ -3484,7 +3599,9 @@ discard block |
||
3484 | 3599 | $session = $qq->field(0, 'session'); |
3485 | 3600 | list($sitting, $part) = $this->_get_sitting($gid); |
3486 | 3601 | $sitting_txt = make_ranking($sitting) . ' sitting'; |
3487 | - if ($part>0) $sitting .= ", part $part"; |
|
3602 | + if ($part>0) { |
|
3603 | + $sitting .= ", part $part"; |
|
3604 | + } |
|
3488 | 3605 | $data[$hdate][] = array( |
3489 | 3606 | 'bill'=> $title, |
3490 | 3607 | 'sitting' => $sitting_txt, |
@@ -3496,8 +3613,9 @@ discard block |
||
3496 | 3613 | |
3497 | 3614 | # Given a GID, parse out the sitting number and optional part from it |
3498 | 3615 | public function _get_sitting($gid) { |
3499 | - if (preg_match('#_(\d\d)-(\d)_#', $gid, $m)) |
|
3500 | - return array($m[1]+0, $m[2]); |
|
3616 | + if (preg_match('#_(\d\d)-(\d)_#', $gid, $m)) { |
|
3617 | + return array($m[1]+0, $m[2]); |
|
3618 | + } |
|
3501 | 3619 | return array(0, 0); |
3502 | 3620 | } |
3503 | 3621 | } |
@@ -307,6 +307,9 @@ discard block |
||
307 | 307 | $this->valid = true; |
308 | 308 | } |
309 | 309 | |
310 | + /** |
|
311 | + * @param boolean $long |
|
312 | + */ |
|
310 | 313 | public function query_description_internal($long) { |
311 | 314 | if (!defined('XAPIANDB') || !XAPIANDB) { |
312 | 315 | return ''; |
@@ -341,6 +344,11 @@ discard block |
||
341 | 344 | } |
342 | 345 | |
343 | 346 | // Perform partial query to get a count of number of matches |
347 | + |
|
348 | + /** |
|
349 | + * @param integer $first_result |
|
350 | + * @param integer $results_per_page |
|
351 | + */ |
|
344 | 352 | public function run_count($first_result, $results_per_page, $sort_order='relevance') { |
345 | 353 | if (!defined('XAPIANDB') || !XAPIANDB) |
346 | 354 | return null; |
@@ -420,6 +428,11 @@ discard block |
||
420 | 428 | } |
421 | 429 | |
422 | 430 | // Perform the full search... |
431 | + |
|
432 | + /** |
|
433 | + * @param integer $first_result |
|
434 | + * @param integer $results_per_page |
|
435 | + */ |
|
423 | 436 | public function run_search($first_result, $results_per_page, $sort_order='relevance') { |
424 | 437 | $start = getmicrotime(); |
425 | 438 |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | } |
334 | 334 | |
335 | 335 | public function get_spelling_correction() { |
336 | - if (!defined('XAPIANDB') || !XAPIANDB) |
|
336 | + if (!defined('XAPIANDB') || !XAPIANDB) |
|
337 | 337 | return null; |
338 | 338 | |
339 | 339 | $qd = $this->queryparser->get_corrected_query_string(); |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | { |
560 | 560 | $wordpos = strpos( $lcbody, $matches[0] ); |
561 | 561 | if ($wordpos) { |
562 | - if ( ($wordpos < $pos) || ($pos==-1) ) { |
|
562 | + if ( ($wordpos < $pos) || ($pos==-1) ) { |
|
563 | 563 | $pos = $wordpos; |
564 | 564 | } |
565 | 565 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | */ |
27 | 27 | |
28 | -if (defined('XAPIANDB') AND XAPIANDB != '') { |
|
28 | +if (defined('XAPIANDB') and XAPIANDB != '') { |
|
29 | 29 | if (file_exists('/usr/share/php/xapian.php')) { |
30 | 30 | include_once '/usr/share/php/xapian.php'; |
31 | 31 | } else { |
@@ -263,15 +263,15 @@ discard block |
||
263 | 263 | for ($n=0; $n<$merged->rows(); $n++) { |
264 | 264 | $from_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_from')); |
265 | 265 | $to_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_to')); |
266 | - $qd = str_replace("(S$from_id OR S$to_id)", "S$to_id", $qd); |
|
267 | - $qd = str_replace("S$from_id OR S$to_id", "S$to_id", $qd); |
|
266 | + $qd = str_replace("(S$from_id OR S$to_id)", "s$to_id", $qd); |
|
267 | + $qd = str_replace("s$from_id OR S$to_id", "s$to_id", $qd); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | preg_match_all('#S(\d+)#', $qd, $m); |
271 | 271 | foreach ($m[1] as $mm) { |
272 | 272 | $member = new MEMBER(array('person_id' => $mm)); |
273 | 273 | $name = $member->full_name(); |
274 | - $qd = str_replace("S$mm", "speaker:$name", $qd); |
|
274 | + $qd = str_replace("s$mm", "speaker:$name", $qd); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | # Simplify display of excluded words |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | // Split words up into individual words, and quoted phrases |
97 | 97 | preg_match_all('/(' . |
98 | 98 | '"|' . # match either a quote, or... |
99 | - '(?:(?<![' .$this->wordchars. '])-)?' . # optionally a - (exclude) |
|
99 | + '(?:(?<![' . $this->wordchars . '])-)?' . # optionally a - (exclude) |
|
100 | 100 | # if at start of word (i.e. not preceded by a word character, in |
101 | 101 | # which case it is probably a hyphenated-word) |
102 | - '['.$this->wordchars.']+' . # followed by a string of word-characters |
|
102 | + '[' . $this->wordchars . ']+' . # followed by a string of word-characters |
|
103 | 103 | ')/', $this->query, $all_words); |
104 | 104 | if ($all_words) { |
105 | 105 | $all_words = $all_words[0]; |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | if (strpos($word, ':') !== false) { |
125 | 125 | $items = explode(":", strtolower($word)); |
126 | 126 | $type = $items[0]; |
127 | - if (substr($type, 0, 1)=='-') $type = substr($type, 1); |
|
128 | - $value = strtolower(join(":", array_slice($items,1))); |
|
127 | + if (substr($type, 0, 1) == '-') $type = substr($type, 1); |
|
128 | + $value = strtolower(join(":", array_slice($items, 1))); |
|
129 | 129 | if ($type == 'section') { |
130 | 130 | $newv = $value; |
131 | 131 | if ($value == 'debates' || $value == 'debate') $newv = 1; |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | elseif ($value == 'pbc' || $value == 'standing') $newv = 6; |
138 | 138 | elseif ($value == 'sp') $newv = 7; |
139 | 139 | elseif ($value == 'spwrans' || $value == 'spwran') $newv = 8; |
140 | - elseif ($value == 'uk') $newv = array(1,2,3,4,6,101); |
|
141 | - elseif ($value == 'scotland') $newv = array(7,8); |
|
140 | + elseif ($value == 'uk') $newv = array(1, 2, 3, 4, 6, 101); |
|
141 | + elseif ($value == 'scotland') $newv = array(7, 8); |
|
142 | 142 | elseif ($value == 'future') $newv = 'F'; |
143 | 143 | if (is_array($newv)) { |
144 | 144 | $newv = 'major:' . join(' major:', $newv); |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | $this->query .= " $from..$to"; |
173 | 173 | } elseif ($from) { |
174 | 174 | $this->query = str_ireplace("from:$from", '', $this->query); |
175 | - $this->query .= " $from..".date('Ymd'); |
|
175 | + $this->query .= " $from.." . date('Ymd'); |
|
176 | 176 | } elseif ($to) { |
177 | 177 | $this->query = str_ireplace("to:$to", '', $this->query); |
178 | 178 | $this->query .= " 19990101..$to"; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | # Merged people |
182 | 182 | $db = new ParlDB; |
183 | 183 | $merged = $db->query('SELECT * FROM gidredirect WHERE gid_from LIKE :gid_from', array(':gid_from' => "uk.org.publicwhip/person/%")); |
184 | - for ($n=0; $n<$merged->rows(); $n++) { |
|
184 | + for ($n = 0; $n < $merged->rows(); $n++) { |
|
185 | 185 | $from_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_from')); |
186 | 186 | $to_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_to')); |
187 | 187 | $this->query = preg_replace("#speaker:($from_id|$to_id)#i", "(speaker:$from_id OR speaker:$to_id)", $this->query); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | |
190 | 190 | twfy_debug("SEARCH", "prefixed: " . var_export($this->prefixed, true)); |
191 | 191 | |
192 | - twfy_debug("SEARCH", "query -- ". $this->query); |
|
192 | + twfy_debug("SEARCH", "query -- " . $this->query); |
|
193 | 193 | $flags = XapianQueryParser::FLAG_BOOLEAN | XapianQueryParser::FLAG_LOVEHATE | |
194 | 194 | XapianQueryParser::FLAG_WILDCARD | XapianQueryParser::FLAG_SPELLING_CORRECTION; |
195 | 195 | $flags = $flags | XapianQueryParser::FLAG_PHRASE; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | foreach ($m[1] as $phrase) { |
219 | 219 | $phrase_new = preg_replace('# PHRASE \d+#', '', $phrase); |
220 | 220 | #$this->phrases[] = preg_split('#\s+#', $phrase_new); |
221 | - $qd = str_replace("($phrase)", '"'.$phrase_new.'"', $qd); |
|
221 | + $qd = str_replace("($phrase)", '"' . $phrase_new . '"', $qd); |
|
222 | 222 | } |
223 | 223 | preg_match_all('#\(([^(]*? NEAR [^(]*?)\)#', $qd, $m); |
224 | 224 | foreach ($m[1] as $mm) { |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | } |
263 | 263 | |
264 | 264 | # Speakers |
265 | - for ($n=0; $n<$merged->rows(); $n++) { |
|
265 | + for ($n = 0; $n < $merged->rows(); $n++) { |
|
266 | 266 | $from_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_from')); |
267 | 267 | $to_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_to')); |
268 | 268 | $qd = str_replace("(S$from_id OR S$to_id)", "S$to_id", $qd); |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | } |
342 | 342 | |
343 | 343 | // Perform partial query to get a count of number of matches |
344 | - public function run_count($first_result, $results_per_page, $sort_order='relevance') { |
|
344 | + public function run_count($first_result, $results_per_page, $sort_order = 'relevance') { |
|
345 | 345 | if (!defined('XAPIANDB') || !XAPIANDB) |
346 | 346 | return null; |
347 | 347 | |
@@ -414,13 +414,13 @@ discard block |
||
414 | 414 | #} |
415 | 415 | |
416 | 416 | $duration = getmicrotime() - $start; |
417 | - twfy_debug ("SEARCH", "Search count took $duration seconds."); |
|
417 | + twfy_debug("SEARCH", "Search count took $duration seconds."); |
|
418 | 418 | |
419 | 419 | return $count; |
420 | 420 | } |
421 | 421 | |
422 | 422 | // Perform the full search... |
423 | - public function run_search($first_result, $results_per_page, $sort_order='relevance') { |
|
423 | + public function run_search($first_result, $results_per_page, $sort_order = 'relevance') { |
|
424 | 424 | $start = getmicrotime(); |
425 | 425 | |
426 | 426 | #$matches = $this->enquire->get_mset($first_result, $results_per_page); |
@@ -441,13 +441,13 @@ discard block |
||
441 | 441 | array_push($this->created, join('', unpack('N', $doc->get_value(2)))); # XXX Needs fixing |
442 | 442 | } |
443 | 443 | twfy_debug("SEARCH", "gid: $gid relevancy: $relevancy% weight: $weight"); |
444 | - array_push($this->gids, "uk.org.publicwhip/".$gid); |
|
444 | + array_push($this->gids, "uk.org.publicwhip/" . $gid); |
|
445 | 445 | array_push($this->collapsed, $collapsed); |
446 | 446 | array_push($this->relevances, $relevancy); |
447 | 447 | $iter->next(); |
448 | 448 | } |
449 | 449 | $duration = getmicrotime() - $start; |
450 | - twfy_debug ("SEARCH", "Run search took $duration seconds."); |
|
450 | + twfy_debug("SEARCH", "Run search took $duration seconds."); |
|
451 | 451 | } |
452 | 452 | // ... use these to get the results |
453 | 453 | public function get_gids() { |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | $body = str_replace($this->specialchars, $this->specialchars_upper, $body); |
489 | 489 | $body = mb_convert_encoding($body, "UTF-8", "HTML-ENTITIES"); |
490 | 490 | $body = str_replace($this->specialchars_upper, $this->specialchars, $body); |
491 | - $splitextract = preg_split('/(<[^>]*>|[0-9,.]+|['.$this->wordcharsnodigit.']+)/', $body, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
491 | + $splitextract = preg_split('/(<[^>]*>|[0-9,.]+|[' . $this->wordcharsnodigit . ']+)/', $body, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
492 | 492 | $hlextract = ""; |
493 | 493 | foreach ($splitextract as $extractword) { |
494 | 494 | if (preg_match('/^<[^>]*>$/', $extractword)) { |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | */ |
537 | 537 | |
538 | 538 | foreach ($this->phrases as $phrase) { |
539 | - $phrasematch = join($phrase, '[^'.$this->wordchars.']+'); |
|
539 | + $phrasematch = join($phrase, '[^' . $this->wordchars . ']+'); |
|
540 | 540 | array_push($findwords, "/\b($phrasematch)\b(?!(?>[^<>]*>))/i"); |
541 | 541 | $replacewords[] = "<span class=\"hi\">\\1</span>"; |
542 | 542 | } |
@@ -554,12 +554,12 @@ discard block |
||
554 | 554 | |
555 | 555 | // look for phrases |
556 | 556 | foreach ($this->phrases as $phrase) { |
557 | - $phrasematch = join($phrase, '[^'.$this->wordchars.']+'); |
|
558 | - if (preg_match('/([^'.$this->wordchars.']' . $phrasematch . '[^A-Za-z0-9])/', $lcbody, $matches)) |
|
557 | + $phrasematch = join($phrase, '[^' . $this->wordchars . ']+'); |
|
558 | + if (preg_match('/([^' . $this->wordchars . ']' . $phrasematch . '[^A-Za-z0-9])/', $lcbody, $matches)) |
|
559 | 559 | { |
560 | - $wordpos = strpos( $lcbody, $matches[0] ); |
|
560 | + $wordpos = strpos($lcbody, $matches[0]); |
|
561 | 561 | if ($wordpos) { |
562 | - if ( ($wordpos < $pos) || ($pos==-1) ) { |
|
562 | + if (($wordpos < $pos) || ($pos == -1)) { |
|
563 | 563 | $pos = $wordpos; |
564 | 564 | } |
565 | 565 | } |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | } |
568 | 568 | if ($pos != -1) return $pos; |
569 | 569 | |
570 | - $splitextract = preg_split('/([0-9,.]+|['.$this->wordcharsnodigit.']+)/', $lcbody, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
570 | + $splitextract = preg_split('/([0-9,.]+|[' . $this->wordcharsnodigit . ']+)/', $lcbody, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
571 | 571 | $stemmed_words = array_map(array($this, 'stem'), $this->words); |
572 | 572 | foreach ($splitextract as $extractword) { |
573 | 573 | $extractword = preg_replace('/&$/', '', $extractword); |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | foreach ($stemmed_words as $word) { |
578 | 578 | if ($word == '') continue; |
579 | 579 | $matchword = $this->stem($extractword); |
580 | - if ($matchword == $word && ($wordpos < $pos || $pos==-1)) { |
|
580 | + if ($matchword == $word && ($wordpos < $pos || $pos == -1)) { |
|
581 | 581 | $pos = $wordpos; |
582 | 582 | } |
583 | 583 | } |
@@ -586,11 +586,11 @@ discard block |
||
586 | 586 | if ($pos != -1) return $pos; |
587 | 587 | |
588 | 588 | foreach ($this->words as $word) { |
589 | - if (ctype_digit($word)) $word = '(?:'.$word.'|'.number_format($word).')'; |
|
590 | - if (preg_match('/([^'.$this->wordchars.']' . $word . '[^'.$this->wordchars. '])/', $lcbody, $matches)) { |
|
591 | - $wordpos = strpos( $lcbody, $matches[0] ); |
|
589 | + if (ctype_digit($word)) $word = '(?:' . $word . '|' . number_format($word) . ')'; |
|
590 | + if (preg_match('/([^' . $this->wordchars . ']' . $word . '[^' . $this->wordchars . '])/', $lcbody, $matches)) { |
|
591 | + $wordpos = strpos($lcbody, $matches[0]); |
|
592 | 592 | if ($wordpos) { |
593 | - if ( ($wordpos < $pos) || ($pos==-1) ) { |
|
593 | + if (($wordpos < $pos) || ($pos == -1)) { |
|
594 | 594 | $pos = $wordpos; |
595 | 595 | } |
596 | 596 | } |
@@ -600,11 +600,11 @@ discard block |
||
600 | 600 | if ($pos != -1) return $pos; |
601 | 601 | |
602 | 602 | foreach ($this->words as $word) { |
603 | - if (ctype_digit($word)) $word = '(?:'.$word.'|'.number_format($word).')'; |
|
603 | + if (ctype_digit($word)) $word = '(?:' . $word . '|' . number_format($word) . ')'; |
|
604 | 604 | if (preg_match('/(' . $word . ')/', $lcbody, $matches)) { |
605 | - $wordpos = strpos( $lcbody, $matches[0] ); |
|
605 | + $wordpos = strpos($lcbody, $matches[0]); |
|
606 | 606 | if ($wordpos) { |
607 | - if ( ($wordpos < $pos) || ($pos==-1) ) { |
|
607 | + if (($wordpos < $pos) || ($pos == -1)) { |
|
608 | 608 | $pos = $wordpos; |
609 | 609 | } |
610 | 610 | } |
@@ -30,7 +30,8 @@ discard block |
||
30 | 30 | if (defined('XAPIANDB') AND XAPIANDB != '') { |
31 | 31 | if (file_exists('/usr/share/php/xapian.php')) { |
32 | 32 | include_once '/usr/share/php/xapian.php'; |
33 | - } else { |
|
33 | + } |
|
34 | + else { |
|
34 | 35 | twfy_debug('SEARCH', '/usr/share/php/xapian.php does not exist'); |
35 | 36 | } |
36 | 37 | } |
@@ -40,8 +41,9 @@ discard block |
||
40 | 41 | public $error; |
41 | 42 | |
42 | 43 | public function __construct($query) { |
43 | - if (!defined('XAPIANDB') || !XAPIANDB) |
|
44 | - return null; |
|
44 | + if (!defined('XAPIANDB') || !XAPIANDB) { |
|
45 | + return null; |
|
46 | + } |
|
45 | 47 | |
46 | 48 | global $xapiandb, $PAGE, $hansardmajors, $parties; |
47 | 49 | if (!$xapiandb) { |
@@ -51,13 +53,18 @@ discard block |
||
51 | 53 | twfy_debug("SEARCH", "Using Xapian remote backend: " . $xapian_host . " port " . $xapian_port); |
52 | 54 | $xapiandb_remote = remote_open($xapian_host, intval($xapian_port)); |
53 | 55 | $xapiandb = new XapianDatabase($xapiandb_remote); |
54 | - } else { |
|
56 | + } |
|
57 | + else { |
|
55 | 58 | $xapiandb = new XapianDatabase(XAPIANDB); |
56 | 59 | } |
57 | 60 | } |
58 | 61 | $this->query = $query; |
59 | - if (!isset($this->stemmer)) $this->stemmer = new XapianStem('english'); |
|
60 | - if (!isset($this->enquire)) $this->enquire = new XapianEnquire($xapiandb); |
|
62 | + if (!isset($this->stemmer)) { |
|
63 | + $this->stemmer = new XapianStem('english'); |
|
64 | + } |
|
65 | + if (!isset($this->enquire)) { |
|
66 | + $this->enquire = new XapianEnquire($xapiandb); |
|
67 | + } |
|
61 | 68 | if (!isset($this->queryparser)) { |
62 | 69 | $this->queryparser = new XapianQueryParser(); |
63 | 70 | $this->datevaluerange = new XapianDateValueRangeProcessor(1); |
@@ -103,7 +110,8 @@ discard block |
||
103 | 110 | ')/', $this->query, $all_words); |
104 | 111 | if ($all_words) { |
105 | 112 | $all_words = $all_words[0]; |
106 | - } else { |
|
113 | + } |
|
114 | + else { |
|
107 | 115 | $all_words = array(); |
108 | 116 | } |
109 | 117 | $in_quote = false; |
@@ -111,7 +119,9 @@ discard block |
||
111 | 119 | foreach ($all_words as $word) { |
112 | 120 | if ($word == '"') { |
113 | 121 | $in_quote = !$in_quote; |
114 | - if ($in_quote) array_push($this->phrases, array()); |
|
122 | + if ($in_quote) { |
|
123 | + array_push($this->phrases, array()); |
|
124 | + } |
|
115 | 125 | if (!$in_quote && !count($this->phrases[count($this->phrases) - 1])) { |
116 | 126 | array_pop($this->phrases); |
117 | 127 | } |
@@ -124,45 +134,84 @@ discard block |
||
124 | 134 | if (strpos($word, ':') !== false) { |
125 | 135 | $items = explode(":", strtolower($word)); |
126 | 136 | $type = $items[0]; |
127 | - if (substr($type, 0, 1)=='-') $type = substr($type, 1); |
|
137 | + if (substr($type, 0, 1)=='-') { |
|
138 | + $type = substr($type, 1); |
|
139 | + } |
|
128 | 140 | $value = strtolower(join(":", array_slice($items,1))); |
129 | 141 | if ($type == 'section') { |
130 | 142 | $newv = $value; |
131 | - if ($value == 'debates' || $value == 'debate') $newv = 1; |
|
132 | - elseif ($value == 'whall' || $value == 'westminster' || $value == 'westminhall') $newv = 2; |
|
133 | - elseif ($value == 'wrans' || $value == 'wran') $newv = 3; |
|
134 | - elseif ($value == 'wms' || $value == 'statements' || $value == 'statement') $newv = 4; |
|
135 | - elseif ($value == 'lordsdebates' || $value == 'lords') $newv = 101; |
|
136 | - elseif ($value == 'ni' || $value == 'nidebates') $newv = 5; |
|
137 | - elseif ($value == 'pbc' || $value == 'standing') $newv = 6; |
|
138 | - elseif ($value == 'sp') $newv = 7; |
|
139 | - elseif ($value == 'spwrans' || $value == 'spwran') $newv = 8; |
|
140 | - elseif ($value == 'uk') $newv = array(1,2,3,4,6,101); |
|
141 | - elseif ($value == 'scotland') $newv = array(7,8); |
|
142 | - elseif ($value == 'future') $newv = 'F'; |
|
143 | + if ($value == 'debates' || $value == 'debate') { |
|
144 | + $newv = 1; |
|
145 | + } |
|
146 | + elseif ($value == 'whall' || $value == 'westminster' || $value == 'westminhall') { |
|
147 | + $newv = 2; |
|
148 | + } |
|
149 | + elseif ($value == 'wrans' || $value == 'wran') { |
|
150 | + $newv = 3; |
|
151 | + } |
|
152 | + elseif ($value == 'wms' || $value == 'statements' || $value == 'statement') { |
|
153 | + $newv = 4; |
|
154 | + } |
|
155 | + elseif ($value == 'lordsdebates' || $value == 'lords') { |
|
156 | + $newv = 101; |
|
157 | + } |
|
158 | + elseif ($value == 'ni' || $value == 'nidebates') { |
|
159 | + $newv = 5; |
|
160 | + } |
|
161 | + elseif ($value == 'pbc' || $value == 'standing') { |
|
162 | + $newv = 6; |
|
163 | + } |
|
164 | + elseif ($value == 'sp') { |
|
165 | + $newv = 7; |
|
166 | + } |
|
167 | + elseif ($value == 'spwrans' || $value == 'spwran') { |
|
168 | + $newv = 8; |
|
169 | + } |
|
170 | + elseif ($value == 'uk') { |
|
171 | + $newv = array(1,2,3,4,6,101); |
|
172 | + } |
|
173 | + elseif ($value == 'scotland') { |
|
174 | + $newv = array(7,8); |
|
175 | + } |
|
176 | + elseif ($value == 'future') { |
|
177 | + $newv = 'F'; |
|
178 | + } |
|
143 | 179 | if (is_array($newv)) { |
144 | 180 | $newv = 'major:' . join(' major:', $newv); |
145 | - } else { |
|
181 | + } |
|
182 | + else { |
|
146 | 183 | $newv = "major:$newv"; |
147 | 184 | } |
148 | 185 | $this->query = str_ireplace("$type:$value", $newv, $this->query); |
149 | - } elseif ($type == 'groupby') { |
|
186 | + } |
|
187 | + elseif ($type == 'groupby') { |
|
150 | 188 | $newv = $value; |
151 | - if ($value == 'debates' || $value == 'debate') $newv = 'debate'; |
|
152 | - if ($value == 'speech' || $value == 'speeches') $newv = 'speech'; |
|
189 | + if ($value == 'debates' || $value == 'debate') { |
|
190 | + $newv = 'debate'; |
|
191 | + } |
|
192 | + if ($value == 'speech' || $value == 'speeches') { |
|
193 | + $newv = 'speech'; |
|
194 | + } |
|
153 | 195 | $this->query = str_ireplace("$type:$value", '', $this->query); |
154 | 196 | array_push($this->prefixed, array($type, $newv)); |
155 | - } elseif ($type == 'from') { |
|
197 | + } |
|
198 | + elseif ($type == 'from') { |
|
156 | 199 | $from = $value; |
157 | - } elseif ($type == 'to') { |
|
200 | + } |
|
201 | + elseif ($type == 'to') { |
|
158 | 202 | $to = $value; |
159 | 203 | } |
160 | - } elseif (strpos($word, '-') !== false) { |
|
161 | - } elseif ($in_quote) { |
|
204 | + } |
|
205 | + elseif (strpos($word, '-') !== false) { |
|
206 | + } |
|
207 | + elseif ($in_quote) { |
|
162 | 208 | array_push($this->phrases[count($this->phrases) - 1], strtolower($word)); |
163 | - } elseif (strpos($word, '..') !== false) { |
|
164 | - } elseif ($word == 'OR' || $word == 'AND' || $word == 'XOR' || $word == 'NEAR') { |
|
165 | - } else { |
|
209 | + } |
|
210 | + elseif (strpos($word, '..') !== false) { |
|
211 | + } |
|
212 | + elseif ($word == 'OR' || $word == 'AND' || $word == 'XOR' || $word == 'NEAR') { |
|
213 | + } |
|
214 | + else { |
|
166 | 215 | array_push($this->words, strtolower($word)); |
167 | 216 | } |
168 | 217 | } |
@@ -170,10 +219,12 @@ discard block |
||
170 | 219 | $this->query = str_ireplace("from:$from", '', $this->query); |
171 | 220 | $this->query = str_ireplace("to:$to", '', $this->query); |
172 | 221 | $this->query .= " $from..$to"; |
173 | - } elseif ($from) { |
|
222 | + } |
|
223 | + elseif ($from) { |
|
174 | 224 | $this->query = str_ireplace("from:$from", '', $this->query); |
175 | 225 | $this->query .= " $from..".date('Ymd'); |
176 | - } elseif ($to) { |
|
226 | + } |
|
227 | + elseif ($to) { |
|
177 | 228 | $this->query = str_ireplace("to:$to", '', $this->query); |
178 | 229 | $this->query .= " 19990101..$to"; |
179 | 230 | } |
@@ -240,7 +291,8 @@ discard block |
||
240 | 291 | $qd = preg_replace('#\bG(.*?)\b#', 'department:$1', $qd); # XXX Lookup to show proper name of dept |
241 | 292 | if (strstr($qd, 'M1 OR M2 OR M3 OR M4 OR M6 OR M101')) { |
242 | 293 | $qd = str_replace('M1 OR M2 OR M3 OR M4 OR M6 OR M101', 'section:uk', $qd); |
243 | - } elseif (strstr($qd, 'M7 OR M8')) { |
|
294 | + } |
|
295 | + elseif (strstr($qd, 'M7 OR M8')) { |
|
244 | 296 | $qd = str_replace('M7 OR M8', 'section:scotland', $qd); |
245 | 297 | } |
246 | 298 | $qd = preg_replace('#\bM(\d+)\b#e', '"in the \'" . (isset($hansardmajors[$1]["title"]) ? $hansardmajors[$1]["title"] . "\'" : "$1")', $qd); |
@@ -254,7 +306,9 @@ discard block |
||
254 | 306 | $end = $this->queryparser->unstem_end($mm); |
255 | 307 | while (!$iter->equals($end)) { |
256 | 308 | $tt = $iter->get_term(); |
257 | - if (!in_array($tt, $used)) break; |
|
309 | + if (!in_array($tt, $used)) { |
|
310 | + break; |
|
311 | + } |
|
258 | 312 | $iter->next(); |
259 | 313 | } |
260 | 314 | $used[] = $tt; |
@@ -288,9 +342,11 @@ discard block |
||
288 | 342 | if ($items[0] == 'groupby') { |
289 | 343 | if ($items[1] == 'debate') { |
290 | 344 | $qd .= ' grouped by debate'; |
291 | - } elseif ($items[1] == 'speech') { |
|
345 | + } |
|
346 | + elseif ($items[1] == 'speech') { |
|
292 | 347 | $qd .= ' showing all speeches'; |
293 | - } else { |
|
348 | + } |
|
349 | + else { |
|
294 | 350 | $PAGE->error_message("Unknown group by '$items[1]' ignored"); |
295 | 351 | } |
296 | 352 | } |
@@ -333,8 +389,9 @@ discard block |
||
333 | 389 | } |
334 | 390 | |
335 | 391 | public function get_spelling_correction() { |
336 | - if (!defined('XAPIANDB') || !XAPIANDB) |
|
337 | - return null; |
|
392 | + if (!defined('XAPIANDB') || !XAPIANDB) { |
|
393 | + return null; |
|
394 | + } |
|
338 | 395 | |
339 | 396 | $qd = $this->queryparser->get_corrected_query_string(); |
340 | 397 | return $qd; |
@@ -342,8 +399,9 @@ discard block |
||
342 | 399 | |
343 | 400 | // Perform partial query to get a count of number of matches |
344 | 401 | public function run_count($first_result, $results_per_page, $sort_order='relevance') { |
345 | - if (!defined('XAPIANDB') || !XAPIANDB) |
|
346 | - return null; |
|
402 | + if (!defined('XAPIANDB') || !XAPIANDB) { |
|
403 | + return null; |
|
404 | + } |
|
347 | 405 | |
348 | 406 | $start = getmicrotime(); |
349 | 407 | |
@@ -373,16 +431,19 @@ discard block |
||
373 | 431 | $collapsed = true; |
374 | 432 | if ($items[1] == 'speech') |
375 | 433 | ; // no collapse key |
376 | - elseif ($items[1] == 'debate') |
|
377 | - $this->enquire->set_collapse_key(3); |
|
378 | - else |
|
379 | - $PAGE->error_message("Unknown group by '$items[1]' ignored"); |
|
434 | + elseif ($items[1] == 'debate') { |
|
435 | + $this->enquire->set_collapse_key(3); |
|
436 | + } |
|
437 | + else { |
|
438 | + $PAGE->error_message("Unknown group by '$items[1]' ignored"); |
|
439 | + } |
|
380 | 440 | } |
381 | 441 | } |
382 | 442 | |
383 | 443 | // default to grouping by subdebate, i.e. by page |
384 | - if (!$collapsed) |
|
385 | - $this->enquire->set_collapse_key(3); |
|
444 | + if (!$collapsed) { |
|
445 | + $this->enquire->set_collapse_key(3); |
|
446 | + } |
|
386 | 447 | |
387 | 448 | /* |
388 | 449 | XXX Helping to debug possible Xapian bug |
@@ -462,8 +523,9 @@ discard block |
||
462 | 523 | |
463 | 524 | // Puts HTML highlighting round all the matching words in the text |
464 | 525 | public function highlight($body) { |
465 | - if (!defined('XAPIANDB') || !XAPIANDB) |
|
466 | - return $body; |
|
526 | + if (!defined('XAPIANDB') || !XAPIANDB) { |
|
527 | + return $body; |
|
528 | + } |
|
467 | 529 | |
468 | 530 | $stemmed_words = array_map(array($this, 'stem'), $this->words); |
469 | 531 | if (is_array($body)) { |
@@ -472,7 +534,8 @@ discard block |
||
472 | 534 | } |
473 | 535 | |
474 | 536 | return $body; |
475 | - } else { |
|
537 | + } |
|
538 | + else { |
|
476 | 539 | return $this->highlight_internal($body, $stemmed_words); |
477 | 540 | } |
478 | 541 | } |
@@ -481,8 +544,9 @@ discard block |
||
481 | 544 | private $specialchars_upper = array('<', '>', '"', '&'); |
482 | 545 | |
483 | 546 | public function highlight_internal($body, $stemmed_words) { |
484 | - if (!defined('XAPIANDB') || !XAPIANDB) |
|
485 | - return $body; |
|
547 | + if (!defined('XAPIANDB') || !XAPIANDB) { |
|
548 | + return $body; |
|
549 | + } |
|
486 | 550 | |
487 | 551 | # Does html_entity_decode without the htmlspecialchars |
488 | 552 | $body = str_replace($this->specialchars, $this->specialchars_upper, $body); |
@@ -503,7 +567,9 @@ discard block |
||
503 | 567 | $hl = false; |
504 | 568 | $matchword = $this->stem($extractword); |
505 | 569 | foreach ($stemmed_words as $word) { |
506 | - if ($word == '') continue; |
|
570 | + if ($word == '') { |
|
571 | + continue; |
|
572 | + } |
|
507 | 573 | if ($matchword == $word) { |
508 | 574 | $hl = true; |
509 | 575 | break; |
@@ -511,7 +577,8 @@ discard block |
||
511 | 577 | } |
512 | 578 | if ($hl) { |
513 | 579 | $hlextract .= "<span class=\"hi\">$extractword</span>$endswithamp"; |
514 | - } else { |
|
580 | + } |
|
581 | + else { |
|
515 | 582 | $hlextract .= $extractword . $endswithamp; |
516 | 583 | } |
517 | 584 | } |
@@ -555,8 +622,7 @@ discard block |
||
555 | 622 | // look for phrases |
556 | 623 | foreach ($this->phrases as $phrase) { |
557 | 624 | $phrasematch = join($phrase, '[^'.$this->wordchars.']+'); |
558 | - if (preg_match('/([^'.$this->wordchars.']' . $phrasematch . '[^A-Za-z0-9])/', $lcbody, $matches)) |
|
559 | - { |
|
625 | + if (preg_match('/([^'.$this->wordchars.']' . $phrasematch . '[^A-Za-z0-9])/', $lcbody, $matches)) { |
|
560 | 626 | $wordpos = strpos( $lcbody, $matches[0] ); |
561 | 627 | if ($wordpos) { |
562 | 628 | if ( ($wordpos < $pos) || ($pos==-1) ) { |
@@ -565,17 +631,25 @@ discard block |
||
565 | 631 | } |
566 | 632 | } |
567 | 633 | } |
568 | - if ($pos != -1) return $pos; |
|
634 | + if ($pos != -1) { |
|
635 | + return $pos; |
|
636 | + } |
|
569 | 637 | |
570 | 638 | $splitextract = preg_split('/([0-9,.]+|['.$this->wordcharsnodigit.']+)/', $lcbody, -1, PREG_SPLIT_DELIM_CAPTURE); |
571 | 639 | $stemmed_words = array_map(array($this, 'stem'), $this->words); |
572 | 640 | foreach ($splitextract as $extractword) { |
573 | 641 | $extractword = preg_replace('/&$/', '', $extractword); |
574 | - if (!$extractword) continue; |
|
642 | + if (!$extractword) { |
|
643 | + continue; |
|
644 | + } |
|
575 | 645 | $wordpos = strpos($lcbody, $extractword); |
576 | - if (!$wordpos) continue; |
|
646 | + if (!$wordpos) { |
|
647 | + continue; |
|
648 | + } |
|
577 | 649 | foreach ($stemmed_words as $word) { |
578 | - if ($word == '') continue; |
|
650 | + if ($word == '') { |
|
651 | + continue; |
|
652 | + } |
|
579 | 653 | $matchword = $this->stem($extractword); |
580 | 654 | if ($matchword == $word && ($wordpos < $pos || $pos==-1)) { |
581 | 655 | $pos = $wordpos; |
@@ -583,10 +657,14 @@ discard block |
||
583 | 657 | } |
584 | 658 | } |
585 | 659 | // only look for earlier words if phrases weren't found |
586 | - if ($pos != -1) return $pos; |
|
660 | + if ($pos != -1) { |
|
661 | + return $pos; |
|
662 | + } |
|
587 | 663 | |
588 | 664 | foreach ($this->words as $word) { |
589 | - if (ctype_digit($word)) $word = '(?:'.$word.'|'.number_format($word).')'; |
|
665 | + if (ctype_digit($word)) { |
|
666 | + $word = '(?:'.$word.'|'.number_format($word).')'; |
|
667 | + } |
|
590 | 668 | if (preg_match('/([^'.$this->wordchars.']' . $word . '[^'.$this->wordchars. '])/', $lcbody, $matches)) { |
591 | 669 | $wordpos = strpos( $lcbody, $matches[0] ); |
592 | 670 | if ($wordpos) { |
@@ -597,10 +675,14 @@ discard block |
||
597 | 675 | } |
598 | 676 | } |
599 | 677 | // only look for something containing the word (ie. something stemmed, but doesn't work all the time) if no whole word was found |
600 | - if ($pos != -1) return $pos; |
|
678 | + if ($pos != -1) { |
|
679 | + return $pos; |
|
680 | + } |
|
601 | 681 | |
602 | 682 | foreach ($this->words as $word) { |
603 | - if (ctype_digit($word)) $word = '(?:'.$word.'|'.number_format($word).')'; |
|
683 | + if (ctype_digit($word)) { |
|
684 | + $word = '(?:'.$word.'|'.number_format($word).')'; |
|
685 | + } |
|
604 | 686 | if (preg_match('/(' . $word . ')/', $lcbody, $matches)) { |
605 | 687 | $wordpos = strpos( $lcbody, $matches[0] ); |
606 | 688 | if ($wordpos) { |
@@ -611,8 +693,9 @@ discard block |
||
611 | 693 | } |
612 | 694 | } |
613 | 695 | |
614 | - if ($pos == -1) |
|
615 | - $pos = 0; |
|
696 | + if ($pos == -1) { |
|
697 | + $pos = 0; |
|
698 | + } |
|
616 | 699 | |
617 | 700 | return $pos; |
618 | 701 | } |
@@ -99,6 +99,9 @@ |
||
99 | 99 | return $popular_searches; |
100 | 100 | } |
101 | 101 | |
102 | + /** |
|
103 | + * @param integer $row |
|
104 | + */ |
|
102 | 105 | public function _db_row_to_array($q, $row) { |
103 | 106 | $query = $q->field($row, 'query_string'); |
104 | 107 | $this->SEARCHURL->insert(array('s'=>$query, 'pop'=>1)); |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | // Select popular queries |
70 | 70 | public function popular_recent($count, $max_chars = null) { |
71 | 71 | |
72 | - $q = $this->db->query("SELECT *, count(*) AS c FROM search_query_log |
|
72 | + $q = $this->db->query("SELECT *, count(*) AS c FROM search_query_log |
|
73 | 73 | WHERE count_hits != 0 AND query_string != 'twat' |
74 | 74 | AND query_string != 'suffragettes' AND page_number=1 |
75 | 75 | AND query_time > date_sub(NOW(), INTERVAL 1 DAY) |
76 | 76 | GROUP BY query_string ORDER BY c desc LIMIT $count;"); |
77 | 77 | |
78 | 78 | $popular_searches = array(); |
79 | - for ($row=0; $row<$q->rows(); $row++) { |
|
79 | + for ($row = 0; $row < $q->rows(); $row++) { |
|
80 | 80 | array_push($popular_searches, $this->_db_row_to_array($q, $row)); |
81 | 81 | } |
82 | 82 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $rowarray['query'] = $query; |
123 | 123 | $rowarray['visible_name'] = $visible_name; |
124 | 124 | $rowarray['url'] = $url; |
125 | - $rowarray['display'] = '<a href="' . $url . '">' . ($htmlescape ? _htmlentities($visible_name) : $visible_name). '</a>'; |
|
125 | + $rowarray['display'] = '<a href="' . $url . '">' . ($htmlescape ? _htmlentities($visible_name) : $visible_name) . '</a>'; |
|
126 | 126 | |
127 | 127 | return $rowarray; |
128 | 128 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | $q = $this->db->query("SELECT query_string, page_number, count_hits, ip_address, query_time |
133 | 133 | FROM search_query_log ORDER BY query_time desc LIMIT $count"); |
134 | 134 | $searches_array = array(); |
135 | - for ($row=0; $row<$q->rows(); $row++) { |
|
135 | + for ($row = 0; $row < $q->rows(); $row++) { |
|
136 | 136 | array_push($searches_array, $this->_db_row_to_array($q, $row)); |
137 | 137 | } |
138 | 138 | |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | |
142 | 142 | public function admin_popular_searches($count) { |
143 | 143 | |
144 | - $q = $this->db->query("SELECT *, count(*) AS c FROM search_query_log |
|
144 | + $q = $this->db->query("SELECT *, count(*) AS c FROM search_query_log |
|
145 | 145 | WHERE count_hits != 0 AND query_string NOT LIKE '%speaker:%' |
146 | 146 | AND query_time > date_sub(NOW(), INTERVAL 30 DAY) |
147 | 147 | GROUP BY query_string ORDER BY c desc LIMIT $count;"); |
148 | 148 | |
149 | 149 | $popular_searches = array(); |
150 | - for ($row=0; $row<$q->rows(); $row++) { |
|
150 | + for ($row = 0; $row < $q->rows(); $row++) { |
|
151 | 151 | array_push($popular_searches, $this->_db_row_to_array($q, $row)); |
152 | 152 | } |
153 | 153 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | FROM search_query_log GROUP BY query_string HAVING count_hits = 0 |
164 | 164 | ORDER BY count_ips DESC, max_time DESC"); |
165 | 165 | $searches_array = array(); |
166 | - for ($row=0; $row<$q->rows(); $row++) { |
|
166 | + for ($row = 0; $row < $q->rows(); $row++) { |
|
167 | 167 | array_push($searches_array, $this->_db_row_to_array($q, $row)); |
168 | 168 | } |
169 | 169 |
@@ -36,7 +36,8 @@ |
||
36 | 36 | public function add($searchlogdata) { |
37 | 37 | |
38 | 38 | $ip = getenv('REMOTE_ADDR'); |
39 | - if (preg_match('#66\.249\.(6[4-9]|[78]\d|9[0-5])\.#', $ip)) { # Googlebot |
|
39 | + if (preg_match('#66\.249\.(6[4-9]|[78]\d|9[0-5])\.#', $ip)) { |
|
40 | +# Googlebot |
|
40 | 41 | return; |
41 | 42 | } |
42 | 43 | if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('#simplepie|bot#i', $_SERVER['HTTP_USER_AGENT'])) { |
@@ -29,6 +29,9 @@ |
||
29 | 29 | public $xPermalink; |
30 | 30 | } |
31 | 31 | |
32 | +/** |
|
33 | + * @param string $url |
|
34 | + */ |
|
32 | 35 | function technorati($url) { |
33 | 36 | global $arItems, $itemCount; |
34 | 37 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - /* |
|
2 | + /* |
|
3 | 3 | |
4 | 4 | mysql> load data infile '/home/stefan/whitelabel.org/wp/convertedtitles' ignore into table titles; |
5 | 5 | */ |
@@ -24,21 +24,21 @@ discard block |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | class xItem { |
27 | - public $xTitle; |
|
28 | - public $xLink; |
|
29 | - public $xPermalink; |
|
27 | + public $xTitle; |
|
28 | + public $xLink; |
|
29 | + public $xPermalink; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | function technorati($url) { |
33 | - global $arItems, $itemCount; |
|
33 | + global $arItems, $itemCount; |
|
34 | 34 | |
35 | 35 | # array of technorati links |
36 | - $arItems = array(); |
|
36 | + $arItems = array(); |
|
37 | 37 | |
38 | - $itemCount = 0; |
|
38 | + $itemCount = 0; |
|
39 | 39 | |
40 | 40 | # right. now get the technorati links. |
41 | - doCosmos($url); |
|
41 | + doCosmos($url); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | ## functions/classes bits and pieces from elsewhere below |
@@ -50,16 +50,16 @@ discard block |
||
50 | 50 | |
51 | 51 | function doCosmos($urlstring) { |
52 | 52 | |
53 | - $techRati = "http://api.technorati.com/cosmos?format=xml&url=$urlstring&key=7e64960cc7e9b1cb4315e56a6544fce7" ; |
|
53 | + $techRati = "http://api.technorati.com/cosmos?format=xml&url=$urlstring&key=7e64960cc7e9b1cb4315e56a6544fce7" ; |
|
54 | 54 | |
55 | - /* No caching for now */ |
|
55 | + /* No caching for now */ |
|
56 | 56 | #generate cachefilename |
57 | 57 | // preg_match ("/\d{7}/", $urlstring, $nums) ; |
58 | 58 | |
59 | 59 | // $cacheFilename= $nums[0]; |
60 | 60 | |
61 | - // cache for 30 mins only |
|
62 | - // if (!file_exists("cache/{$cacheFilename}.xml")|| (time() - filemtime("cache/{$cacheFilename}.xml") > 1800)||filesize ("cache/{$cacheFilename}.xml")==0 ) { |
|
61 | + // cache for 30 mins only |
|
62 | + // if (!file_exists("cache/{$cacheFilename}.xml")|| (time() - filemtime("cache/{$cacheFilename}.xml") > 1800)||filesize ("cache/{$cacheFilename}.xml")==0 ) { |
|
63 | 63 | |
64 | 64 | #echo "cache miss!"; |
65 | 65 | |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | // fwrite($cachefp, $contents); |
72 | 72 | // fclose($cachefp); |
73 | 73 | |
74 | - $xml_parser = xml_parser_create(); |
|
75 | - xml_set_element_handler($xml_parser, "start1Element", "end1Element"); |
|
76 | - xml_set_character_data_handler($xml_parser, "character1Data"); |
|
77 | - //character1Data = fopen("cache/$cacheFilename.xml", "r") |
|
78 | - # $fp = fopen($a, "r") |
|
79 | - # or die("Error reading XML data."); |
|
80 | - #while ($data = fread($fp, 16384)) { |
|
74 | + $xml_parser = xml_parser_create(); |
|
75 | + xml_set_element_handler($xml_parser, "start1Element", "end1Element"); |
|
76 | + xml_set_character_data_handler($xml_parser, "character1Data"); |
|
77 | + //character1Data = fopen("cache/$cacheFilename.xml", "r") |
|
78 | + # $fp = fopen($a, "r") |
|
79 | + # or die("Error reading XML data."); |
|
80 | + #while ($data = fread($fp, 16384)) { |
|
81 | 81 | // Parse each 4KB chunk with the XML parser created above |
82 | 82 | xml_parse($xml_parser, $contents, TRUE); |
83 | 83 | |
@@ -85,52 +85,52 @@ discard block |
||
85 | 85 | |
86 | 86 | # } |
87 | 87 | # fclose($fp); |
88 | - xml_parser_free($xml_parser); |
|
88 | + xml_parser_free($xml_parser); |
|
89 | 89 | |
90 | 90 | #echo "parsing complete"; |
91 | 91 | # global $arItems; |
92 | 92 | # global $itemCount; |
93 | - // write out the items |
|
93 | + // write out the items |
|
94 | 94 | |
95 | 95 | #echo count($arItems); |
96 | 96 | |
97 | 97 | } |
98 | 98 | |
99 | 99 | function start1Element($parser, $tagName, $attrs) { |
100 | - global $curTag; |
|
101 | - $curTag .= "^$tagName"; |
|
102 | - // echo $counter." ".$curTag."<br> "; |
|
100 | + global $curTag; |
|
101 | + $curTag .= "^$tagName"; |
|
102 | + // echo $counter." ".$curTag."<br> "; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | function end1Element($parser, $tagName) { |
106 | - global $curTag; |
|
107 | - $caret_pos = strrpos($curTag,'^'); |
|
108 | - $curTag = substr($curTag,0,$caret_pos); |
|
109 | - // echo $counter." ".$curTag."<br> "; |
|
106 | + global $curTag; |
|
107 | + $caret_pos = strrpos($curTag,'^'); |
|
108 | + $curTag = substr($curTag,0,$caret_pos); |
|
109 | + // echo $counter." ".$curTag."<br> "; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | function character1Data($parser, $data) { |
113 | - global $itemCount, $curTag, $arItems; |
|
114 | - $titleKey = "^TAPI^DOCUMENT^ITEM^WEBLOG^NAME"; |
|
115 | - $permalinkKey = "^TAPI^DOCUMENT^ITEM^NEARESTPERMALINK"; |
|
116 | - $linkKey = "^TAPI^DOCUMENT^ITEM^WEBLOG^URL"; |
|
117 | - $createdKey = "^TAPI^DOCUMENT^ITEM^LINKCREATED"; |
|
118 | - if ($curTag == $titleKey) { |
|
113 | + global $itemCount, $curTag, $arItems; |
|
114 | + $titleKey = "^TAPI^DOCUMENT^ITEM^WEBLOG^NAME"; |
|
115 | + $permalinkKey = "^TAPI^DOCUMENT^ITEM^NEARESTPERMALINK"; |
|
116 | + $linkKey = "^TAPI^DOCUMENT^ITEM^WEBLOG^URL"; |
|
117 | + $createdKey = "^TAPI^DOCUMENT^ITEM^LINKCREATED"; |
|
118 | + if ($curTag == $titleKey) { |
|
119 | 119 | // make new xItem |
120 | 120 | |
121 | 121 | $arItems[$itemCount] = new xItem(); |
122 | 122 | // set new item object's properties |
123 | 123 | $arItems[$itemCount]->xTitle = $data; |
124 | - } |
|
125 | - elseif ($curTag == $permalinkKey) { |
|
124 | + } |
|
125 | + elseif ($curTag == $permalinkKey) { |
|
126 | 126 | $arItems[$itemCount]->xPermalink = $data; |
127 | 127 | # $itemCount++; |
128 | - } |
|
129 | - elseif ($curTag == $linkKey) { |
|
128 | + } |
|
129 | + elseif ($curTag == $linkKey) { |
|
130 | 130 | $arItems[$itemCount]->xLink = $data; |
131 | 131 | #$itemCount++; |
132 | - } elseif ($curTag == $createdKey) { |
|
133 | - $arItems[$itemCount]->xCreated = $data; |
|
134 | - $itemCount++; |
|
132 | + } elseif ($curTag == $createdKey) { |
|
133 | + $arItems[$itemCount]->xCreated = $data; |
|
134 | + $itemCount++; |
|
135 | 135 | } |
136 | 136 | } |
@@ -79,7 +79,7 @@ |
||
79 | 79 | # or die("Error reading XML data."); |
80 | 80 | #while ($data = fread($fp, 16384)) { |
81 | 81 | // Parse each 4KB chunk with the XML parser created above |
82 | - xml_parse($xml_parser, $contents, TRUE); |
|
82 | + xml_parse($xml_parser, $contents, true); |
|
83 | 83 | |
84 | 84 | #echo "reading..."; |
85 | 85 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | if ($string == 'hour' && $ago > 23) { $ago /= 24; $string = 'day'; } |
16 | 16 | if ($string == 'day' && $ago > 13) { $ago /= 7; $string = 'week'; } |
17 | 17 | $ago = round($ago); if ($ago != 1) $string .= 's'; |
18 | - $body .= '<li><a href="' . $item->xLink . '">' . $item->xTitle . '</a> ('.$ago.' '.$string.' ago)</li>'; |
|
18 | + $body .= '<li><a href="' . $item->xLink . '">' . $item->xTitle . '</a> (' . $ago . ' ' . $string . ' ago)</li>'; |
|
19 | 19 | } |
20 | 20 | if ($body) { |
21 | 21 | $body = "<ul>$body</ul>"; |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | function doCosmos($urlstring) { |
52 | 52 | |
53 | - $techRati = "http://api.technorati.com/cosmos?format=xml&url=$urlstring&key=7e64960cc7e9b1cb4315e56a6544fce7" ; |
|
53 | + $techRati = "http://api.technorati.com/cosmos?format=xml&url=$urlstring&key=7e64960cc7e9b1cb4315e56a6544fce7"; |
|
54 | 54 | |
55 | 55 | /* No caching for now */ |
56 | 56 | #generate cachefilename |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | |
66 | 66 | $a = file($techRati); |
67 | 67 | if (!$a) return false; |
68 | - set_time_limit (10); |
|
68 | + set_time_limit(10); |
|
69 | 69 | $contents = implode('', $a); |
70 | 70 | // $cachefp = fopen("cache/{$cacheFilename}.xml", "w"); |
71 | 71 | // fwrite($cachefp, $contents); |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | |
105 | 105 | function end1Element($parser, $tagName) { |
106 | 106 | global $curTag; |
107 | - $caret_pos = strrpos($curTag,'^'); |
|
108 | - $curTag = substr($curTag,0,$caret_pos); |
|
107 | + $caret_pos = strrpos($curTag, '^'); |
|
108 | + $curTag = substr($curTag, 0, $caret_pos); |
|
109 | 109 | // echo $counter." ".$curTag."<br> "; |
110 | 110 | } |
111 | 111 |
@@ -14,7 +14,9 @@ discard block |
||
14 | 14 | if ($string == 'minute' && $ago > 59) { $ago /= 60; $string = 'hour'; } |
15 | 15 | if ($string == 'hour' && $ago > 23) { $ago /= 24; $string = 'day'; } |
16 | 16 | if ($string == 'day' && $ago > 13) { $ago /= 7; $string = 'week'; } |
17 | - $ago = round($ago); if ($ago != 1) $string .= 's'; |
|
17 | + $ago = round($ago); if ($ago != 1) { |
|
18 | + $string .= 's'; |
|
19 | + } |
|
18 | 20 | $body .= '<li><a href="' . $item->xLink . '">' . $item->xTitle . '</a> ('.$ago.' '.$string.' ago)</li>'; |
19 | 21 | } |
20 | 22 | if ($body) { |
@@ -64,7 +66,9 @@ discard block |
||
64 | 66 | #echo "cache miss!"; |
65 | 67 | |
66 | 68 | $a = file($techRati); |
67 | - if (!$a) return false; |
|
69 | + if (!$a) { |
|
70 | + return false; |
|
71 | + } |
|
68 | 72 | set_time_limit (10); |
69 | 73 | $contents = implode('', $a); |
70 | 74 | // $cachefp = fopen("cache/{$cacheFilename}.xml", "w"); |
@@ -129,7 +133,8 @@ discard block |
||
129 | 133 | elseif ($curTag == $linkKey) { |
130 | 134 | $arItems[$itemCount]->xLink = $data; |
131 | 135 | #$itemCount++; |
132 | - } elseif ($curTag == $createdKey) { |
|
136 | + } |
|
137 | + elseif ($curTag == $createdKey) { |
|
133 | 138 | $arItems[$itemCount]->xCreated = $data; |
134 | 139 | $itemCount++; |
135 | 140 | } |
@@ -207,6 +207,10 @@ discard block |
||
207 | 207 | |
208 | 208 | } |
209 | 209 | |
210 | + /** |
|
211 | + * @param string|null $include_only |
|
212 | + * @param boolean $ignore_committees |
|
213 | + */ |
|
210 | 214 | private function getOfficeObject($include_only, $ignore_committees, $row) { |
211 | 215 | if (!$this->includeOffice($include_only, $row['to_date'])) { |
212 | 216 | return null; |
@@ -338,6 +342,10 @@ discard block |
||
338 | 342 | return $output; |
339 | 343 | } |
340 | 344 | |
345 | + /** |
|
346 | + * @param integer $house |
|
347 | + * @param string $house_name |
|
348 | + */ |
|
341 | 349 | private function entered_house_line($house, $house_name) { |
342 | 350 | if (isset($this->entered_house[$house]['date'])) { |
343 | 351 | $string = "<strong>Entered the $house_name "; |
@@ -350,6 +358,10 @@ discard block |
||
350 | 358 | } |
351 | 359 | } |
352 | 360 | |
361 | + /** |
|
362 | + * @param integer $house |
|
363 | + * @param string $house_name |
|
364 | + */ |
|
353 | 365 | private function left_house_line($house, $house_name) { |
354 | 366 | if ($this->house($house) && !$this->current_member($house)) { |
355 | 367 | $string = "<strong>Left the $house_name "; |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | - * Image |
|
137 | - * |
|
138 | - * Return a URL for the member's image. |
|
139 | - * |
|
140 | - * @return string The URL of the member's image. |
|
141 | - */ |
|
136 | + * Image |
|
137 | + * |
|
138 | + * Return a URL for the member's image. |
|
139 | + * |
|
140 | + * @return string The URL of the member's image. |
|
141 | + */ |
|
142 | 142 | |
143 | 143 | public function image() { |
144 | 144 | |
@@ -207,15 +207,15 @@ discard block |
||
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
210 | - * Offices |
|
211 | - * |
|
212 | - * Return an array of Office objects held (or previously held) by the member. |
|
213 | - * |
|
214 | - * @param string $include_only Restrict the list to include only "previous" or "current" offices. |
|
215 | - * @param bool $ignore_committees Ignore offices that appear to be committee memberships. |
|
216 | - * |
|
217 | - * @return array An array of Office objects. |
|
218 | - */ |
|
210 | + * Offices |
|
211 | + * |
|
212 | + * Return an array of Office objects held (or previously held) by the member. |
|
213 | + * |
|
214 | + * @param string $include_only Restrict the list to include only "previous" or "current" offices. |
|
215 | + * @param bool $ignore_committees Ignore offices that appear to be committee memberships. |
|
216 | + * |
|
217 | + * @return array An array of Office objects. |
|
218 | + */ |
|
219 | 219 | |
220 | 220 | public function offices($include_only = NULL, $ignore_committees = FALSE) { |
221 | 221 | |
@@ -269,12 +269,12 @@ discard block |
||
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
272 | - * Get Other Parties String |
|
273 | - * |
|
274 | - * Return a readable list of party changes for this member. |
|
275 | - * |
|
276 | - * @return string|null A readable list of the party changes for this member. |
|
277 | - */ |
|
272 | + * Get Other Parties String |
|
273 | + * |
|
274 | + * Return a readable list of party changes for this member. |
|
275 | + * |
|
276 | + * @return string|null A readable list of the party changes for this member. |
|
277 | + */ |
|
278 | 278 | |
279 | 279 | public function getOtherPartiesString() { |
280 | 280 | |
@@ -302,12 +302,12 @@ discard block |
||
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
305 | - * Get Other Constituencies String |
|
306 | - * |
|
307 | - * Return a readable list of other constituencies for this member. |
|
308 | - * |
|
309 | - * @return string|null A readable list of the other constituencies for this member. |
|
310 | - */ |
|
305 | + * Get Other Constituencies String |
|
306 | + * |
|
307 | + * Return a readable list of other constituencies for this member. |
|
308 | + * |
|
309 | + * @return string|null A readable list of the other constituencies for this member. |
|
310 | + */ |
|
311 | 311 | |
312 | 312 | public function getOtherConstituenciesString() { |
313 | 313 | |
@@ -320,14 +320,14 @@ discard block |
||
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
323 | - * Get Entered/Left Strings |
|
324 | - * |
|
325 | - * Return an array of readable strings covering when people entered or left |
|
326 | - * various houses. Returns an array since it's possible for a member to have |
|
327 | - * done several of these things. |
|
328 | - * |
|
329 | - * @return array An array of strings of when this member entered or left houses. |
|
330 | - */ |
|
323 | + * Get Entered/Left Strings |
|
324 | + * |
|
325 | + * Return an array of readable strings covering when people entered or left |
|
326 | + * various houses. Returns an array since it's possible for a member to have |
|
327 | + * done several of these things. |
|
328 | + * |
|
329 | + * @return array An array of strings of when this member entered or left houses. |
|
330 | + */ |
|
331 | 331 | public function getEnterLeaveStrings() { |
332 | 332 | $output = array(); |
333 | 333 |
@@ -488,20 +488,20 @@ |
||
488 | 488 | |
489 | 489 | public static function getRepNameForHouse($house) { |
490 | 490 | switch ( $house ) { |
491 | - case 1: |
|
492 | - $name = 'MP'; |
|
493 | - break; |
|
494 | - case 2: |
|
495 | - $name = 'Peer'; |
|
496 | - break; |
|
497 | - case 3: |
|
498 | - $name = 'MLA'; |
|
499 | - break; |
|
500 | - case 4: |
|
501 | - $name = 'MSP'; |
|
502 | - break; |
|
503 | - default: |
|
504 | - $name = ''; |
|
491 | + case 1: |
|
492 | + $name = 'MP'; |
|
493 | + break; |
|
494 | + case 2: |
|
495 | + $name = 'Peer'; |
|
496 | + break; |
|
497 | + case 3: |
|
498 | + $name = 'MLA'; |
|
499 | + break; |
|
500 | + case 4: |
|
501 | + $name = 'MSP'; |
|
502 | + break; |
|
503 | + default: |
|
504 | + $name = ''; |
|
505 | 505 | } |
506 | 506 | return $name; |
507 | 507 | } |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | |
40 | 40 | foreach ($house_types as $house_type) { |
41 | 41 | |
42 | - if (in_array($house_type, $left_house) AND |
|
43 | - $left_house[$house_type]['reason'] AND |
|
42 | + if (in_array($house_type, $left_house) and |
|
43 | + $left_house[$house_type]['reason'] and |
|
44 | 44 | $left_house[$house_type]['reason'] == 'Died' |
45 | 45 | ) { |
46 | 46 | |
47 | 47 | // This member has left a house because of death. |
48 | - return TRUE; |
|
48 | + return true; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | // If we get this far the member hasn't left a house due to death, and |
56 | 56 | // is presumably alive. |
57 | - return FALSE; |
|
57 | + return false; |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | |
77 | 77 | $diff = $date_entered->diff($now); |
78 | 78 | if ( $diff->y == 0 && $diff->m <= 6 ) { |
79 | - return TRUE; |
|
79 | + return true; |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
83 | - return FALSE; |
|
83 | + return false; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /* |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | return $this->extra_info()['eu_ref_stance']; |
130 | 130 | } |
131 | 131 | |
132 | - return FALSE; |
|
132 | + return false; |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -150,10 +150,10 @@ discard block |
||
150 | 150 | } |
151 | 151 | |
152 | 152 | // We can determine if the image exists or not by testing if size is set |
153 | - if ($size !== NULL) { |
|
154 | - $exists = TRUE; |
|
153 | + if ($size !== null) { |
|
154 | + $exists = true; |
|
155 | 155 | } else { |
156 | - $exists = FALSE; |
|
156 | + $exists = false; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | return array( |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @return array An array of Office objects. |
218 | 218 | */ |
219 | 219 | |
220 | - public function offices($include_only = NULL, $ignore_committees = FALSE) { |
|
220 | + public function offices($include_only = null, $ignore_committees = false) { |
|
221 | 221 | |
222 | 222 | $out = array(); |
223 | 223 | |
@@ -253,16 +253,16 @@ discard block |
||
253 | 253 | } |
254 | 254 | |
255 | 255 | private function includeOffice($include_only, $to_date) { |
256 | - $include_office = TRUE; |
|
256 | + $include_office = true; |
|
257 | 257 | |
258 | 258 | // If we should only include previous offices, and the to date is in the future, suppress this office. |
259 | - if ($include_only == 'previous' AND $to_date == '9999-12-31') { |
|
260 | - $include_office = FALSE; |
|
259 | + if ($include_only == 'previous' and $to_date == '9999-12-31') { |
|
260 | + $include_office = false; |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | // If we should only include previous offices, and the to date is in the past, suppress this office. |
264 | - if ($include_only == 'current' AND $to_date != '9999-12-31') { |
|
265 | - $include_office = FALSE; |
|
264 | + if ($include_only == 'current' and $to_date != '9999-12-31') { |
|
265 | + $include_office = false; |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | return $include_office; |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | $output .= join('; ', $other_parties); |
288 | 288 | return $output; |
289 | 289 | } else { |
290 | - return NULL; |
|
290 | + return null; |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | } |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | if ($this->other_constituencies) { |
315 | 315 | return 'Also represented ' . join('; ', array_keys($this->other_constituencies)); |
316 | 316 | } else { |
317 | - return NULL; |
|
317 | + return null; |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $now = new \DateTime(); |
76 | 76 | |
77 | 77 | $diff = $date_entered->diff($now); |
78 | - if ( $diff->y == 0 && $diff->m <= 6 ) { |
|
78 | + if ($diff->y == 0 && $diff->m <= 6) { |
|
79 | 79 | return TRUE; |
80 | 80 | } |
81 | 81 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | $entered_house = $this->entered_house($house); |
98 | 98 | |
99 | - if ( $entered_house ) { |
|
99 | + if ($entered_house) { |
|
100 | 100 | $date_entered = $entered_house['date']; |
101 | 101 | } |
102 | 102 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | $left_house = $this->left_house($house); |
118 | 118 | |
119 | - if ( $left_house ) { |
|
119 | + if ($left_house) { |
|
120 | 120 | $date_left = $left_house['date']; |
121 | 121 | } |
122 | 122 | |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | |
145 | 145 | $is_lord = $this->house(HOUSE_TYPE_LORDS); |
146 | 146 | if ($is_lord) { |
147 | - list($image,$size) = Utility\Member::findMemberImage($this->person_id(), false, 'lord'); |
|
147 | + list($image, $size) = Utility\Member::findMemberImage($this->person_id(), false, 'lord'); |
|
148 | 148 | } else { |
149 | - list($image,$size) = Utility\Member::findMemberImage($this->person_id(), false, true); |
|
149 | + list($image, $size) = Utility\Member::findMemberImage($this->person_id(), false, true); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | // We can determine if the image exists or not by testing if size is set |
@@ -169,15 +169,15 @@ discard block |
||
169 | 169 | $last_cons = ''; |
170 | 170 | $last_house = null; |
171 | 171 | $last_party = null; |
172 | - if ( $this->current_member_anywhere() ) { |
|
172 | + if ($this->current_member_anywhere()) { |
|
173 | 173 | $houses = array_keys(array_filter($this->current_member(), 'strlen')); |
174 | 174 | $last_cons = $this->constituency; |
175 | 175 | $last_party = $this->party; |
176 | 176 | $last_house = $this->house_disp; |
177 | 177 | } else { |
178 | 178 | $max_date = null; |
179 | - foreach ( array_keys($this->left_house) as $house ) { |
|
180 | - if ($this->left_house[$house]['date'] > $max_date ) { |
|
179 | + foreach (array_keys($this->left_house) as $house) { |
|
180 | + if ($this->left_house[$house]['date'] > $max_date) { |
|
181 | 181 | $max_date = $this->left_house[$house]['date']; |
182 | 182 | $last_cons = $this->left_house[$house]['constituency']; |
183 | 183 | $last_party = $this->left_house[$house]['party']; |
@@ -196,10 +196,10 @@ discard block |
||
196 | 196 | |
197 | 197 | $entered_house = $this->entered_house($last_house); |
198 | 198 | $left_house = $this->left_house($last_house); |
199 | - if ( isset($entered_house['date']) ) { |
|
199 | + if (isset($entered_house['date'])) { |
|
200 | 200 | $details['entered_house'] = $entered_house['date']; |
201 | 201 | } |
202 | - if ( isset($left_house['date']) ) { |
|
202 | + if (isset($left_house['date'])) { |
|
203 | 203 | $details['left_house'] = $left_house['date']; |
204 | 204 | } |
205 | 205 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $office = $office['office']; |
227 | 227 | |
228 | 228 | foreach ($office as $row) { |
229 | - if ( $officeObject = $this->getOfficeObject($include_only, $ignore_committees, $row) ) { |
|
229 | + if ($officeObject = $this->getOfficeObject($include_only, $ignore_committees, $row)) { |
|
230 | 230 | $out[] = $officeObject; |
231 | 231 | } |
232 | 232 | } |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | private function entered_house_line($house, $house_name) { |
371 | 371 | if (isset($this->entered_house[$house]['date'])) { |
372 | 372 | $string = "<strong>Entered the $house_name "; |
373 | - $string .= strlen($this->entered_house[$house]['date_pretty'])==4 ? 'in ' : 'on '; |
|
373 | + $string .= strlen($this->entered_house[$house]['date_pretty']) == 4 ? 'in ' : 'on '; |
|
374 | 374 | $string .= $this->entered_house[$house]['date_pretty'] . '</strong>'; |
375 | 375 | if ($this->entered_house[$house]['reason']) { |
376 | 376 | $string .= ' — ' . $this->entered_house[$house]['reason']; |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | private function left_house_line($house, $house_name) { |
383 | 383 | if ($this->house($house) && !$this->current_member($house)) { |
384 | 384 | $string = "<strong>Left the $house_name "; |
385 | - $string .= strlen($this->left_house[$house]['date_pretty'])==4 ? 'in ' : 'on '; |
|
385 | + $string .= strlen($this->left_house[$house]['date_pretty']) == 4 ? 'in ' : 'on '; |
|
386 | 386 | $string .= $this->left_house[$house]['date_pretty'] . '</strong>'; |
387 | 387 | if ($this->left_house[$house]['reason']) { |
388 | 388 | $string .= ' — ' . $this->left_house[$house]['reason']; |
@@ -395,19 +395,19 @@ discard block |
||
395 | 395 | $policy_diffs = array(); |
396 | 396 | $party_positions = $party->getAllPolicyPositions($policiesList); |
397 | 397 | |
398 | - if ( !$party_positions ) { |
|
398 | + if (!$party_positions) { |
|
399 | 399 | return $policy_diffs; |
400 | 400 | } |
401 | 401 | |
402 | - foreach ( $positions->positionsById as $policy_id => $details ) { |
|
403 | - if ( $details['has_strong'] && $details['score'] != -1 && isset($party_positions[$policy_id])) { |
|
402 | + foreach ($positions->positionsById as $policy_id => $details) { |
|
403 | + if ($details['has_strong'] && $details['score'] != -1 && isset($party_positions[$policy_id])) { |
|
404 | 404 | $mp_score = $details['score']; |
405 | 405 | $party_score = $party_positions[$policy_id]['score']; |
406 | 406 | |
407 | 407 | $score_diff = $this->calculatePolicyDiffScore($mp_score, $party_score); |
408 | 408 | |
409 | 409 | // skip anything that isn't a yes vs no diff |
410 | - if ( $only_diffs && $score_diff < 2 ) { |
|
410 | + if ($only_diffs && $score_diff < 2) { |
|
411 | 411 | continue; |
412 | 412 | } |
413 | 413 | $policy_diffs[$policy_id] = $score_diff; |
@@ -419,18 +419,18 @@ discard block |
||
419 | 419 | return $policy_diffs; |
420 | 420 | } |
421 | 421 | |
422 | - private function calculatePolicyDiffScore( $mp_score, $party_score ) { |
|
422 | + private function calculatePolicyDiffScore($mp_score, $party_score) { |
|
423 | 423 | $score_diff = abs($mp_score - $party_score); |
424 | 424 | // if they are on opposite sides of mixture of for and against |
425 | 425 | if ( |
426 | - ( $mp_score < 0.4 && $party_score > 0.6 ) || |
|
427 | - ( $mp_score > 0.6 && $party_score < 0.4 ) |
|
426 | + ($mp_score < 0.4 && $party_score > 0.6) || |
|
427 | + ($mp_score > 0.6 && $party_score < 0.4) |
|
428 | 428 | ) { |
429 | 429 | $score_diff += 2; |
430 | 430 | // if on is mixture of for and against and one is for/against |
431 | 431 | } else if ( |
432 | - ( $mp_score > 0.4 && $mp_score < 0.6 && ( $party_score > 0.6 || $party_score < 0.4 ) ) || |
|
433 | - ( $party_score > 0.4 && $party_score < 0.6 && ( $mp_score > 0.6 || $mp_score < 0.4 ) ) |
|
432 | + ($mp_score > 0.4 && $mp_score < 0.6 && ($party_score > 0.6 || $party_score < 0.4)) || |
|
433 | + ($party_score > 0.4 && $party_score < 0.6 && ($mp_score > 0.6 || $mp_score < 0.4)) |
|
434 | 434 | ) { |
435 | 435 | $score_diff += 1; |
436 | 436 | } |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | |
444 | 444 | $mreg = array(); |
445 | 445 | $constituencies = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($postcode); |
446 | - if ( isset($constituencies[$type]) ) { |
|
446 | + if (isset($constituencies[$type])) { |
|
447 | 447 | $cons_name = $constituencies[$type]; |
448 | 448 | $query_base = "SELECT member.person_id, title, lordofname, given_name, family_name, constituency, house |
449 | 449 | FROM member, person_names |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | ':cons_name' => $cons_name |
461 | 461 | ) |
462 | 462 | ); |
463 | - if ( !$q->rows() && ($dissolution = Dissolution::db()) ) { |
|
463 | + if (!$q->rows() && ($dissolution = Dissolution::db())) { |
|
464 | 464 | $q = $db->query("$query_base AND $dissolution[query]", |
465 | 465 | array( |
466 | 466 | ':house' => $house, |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | } |
488 | 488 | |
489 | 489 | public static function getRepNameForHouse($house) { |
490 | - switch ( $house ) { |
|
490 | + switch ($house) { |
|
491 | 491 | case 1: |
492 | 492 | $name = 'MP'; |
493 | 493 | break; |
@@ -145,14 +145,16 @@ discard block |
||
145 | 145 | $is_lord = $this->house(HOUSE_TYPE_LORDS); |
146 | 146 | if ($is_lord) { |
147 | 147 | list($image,$size) = Utility\Member::findMemberImage($this->person_id(), false, 'lord'); |
148 | - } else { |
|
148 | + } |
|
149 | + else { |
|
149 | 150 | list($image,$size) = Utility\Member::findMemberImage($this->person_id(), false, true); |
150 | 151 | } |
151 | 152 | |
152 | 153 | // We can determine if the image exists or not by testing if size is set |
153 | 154 | if ($size !== NULL) { |
154 | 155 | $exists = TRUE; |
155 | - } else { |
|
156 | + } |
|
157 | + else { |
|
156 | 158 | $exists = FALSE; |
157 | 159 | } |
158 | 160 | |
@@ -174,7 +176,8 @@ discard block |
||
174 | 176 | $last_cons = $this->constituency; |
175 | 177 | $last_party = $this->party; |
176 | 178 | $last_house = $this->house_disp; |
177 | - } else { |
|
179 | + } |
|
180 | + else { |
|
178 | 181 | $max_date = null; |
179 | 182 | foreach ( array_keys($this->left_house) as $house ) { |
180 | 183 | if ($this->left_house[$house]['date'] > $max_date ) { |
@@ -286,7 +289,8 @@ discard block |
||
286 | 289 | } |
287 | 290 | $output .= join('; ', $other_parties); |
288 | 291 | return $output; |
289 | - } else { |
|
292 | + } |
|
293 | + else { |
|
290 | 294 | return NULL; |
291 | 295 | } |
292 | 296 | |
@@ -313,7 +317,8 @@ discard block |
||
313 | 317 | |
314 | 318 | if ($this->other_constituencies) { |
315 | 319 | return 'Also represented ' . join('; ', array_keys($this->other_constituencies)); |
316 | - } else { |
|
320 | + } |
|
321 | + else { |
|
317 | 322 | return NULL; |
318 | 323 | } |
319 | 324 | |
@@ -428,7 +433,8 @@ discard block |
||
428 | 433 | ) { |
429 | 434 | $score_diff += 2; |
430 | 435 | // if on is mixture of for and against and one is for/against |
431 | - } else if ( |
|
436 | + } |
|
437 | + else if ( |
|
432 | 438 | ( $mp_score > 0.4 && $mp_score < 0.6 && ( $party_score > 0.6 || $party_score < 0.4 ) ) || |
433 | 439 | ( $party_score > 0.4 && $party_score < 0.6 && ( $mp_score > 0.6 || $mp_score < 0.4 ) ) |
434 | 440 | ) { |
@@ -590,6 +590,7 @@ discard block |
||
590 | 590 | * Member Redirect |
591 | 591 | * |
592 | 592 | * Redirect to the canonical page for a member. |
593 | + * @param MySociety\TheyWorkForYou\Member $MEMBER |
|
593 | 594 | */ |
594 | 595 | |
595 | 596 | function member_redirect (&$MEMBER, $code = 301, $pagetype = NULL) { |
@@ -1056,6 +1057,12 @@ discard block |
||
1056 | 1057 | |
1057 | 1058 | } |
1058 | 1059 | |
1060 | +/** |
|
1061 | + * @param string $blurb |
|
1062 | + * @param string $type |
|
1063 | + * @param string $inwhat |
|
1064 | + * @param string $afterstuff |
|
1065 | + */ |
|
1059 | 1066 | function display_stats_line($category, $blurb, $type, $inwhat, $afterstuff, $extra_info, $minister = false, $Lminister = false) { |
1060 | 1067 | $return = false; |
1061 | 1068 | if (isset($extra_info[$category])) |
@@ -1065,6 +1072,10 @@ discard block |
||
1065 | 1072 | return $return; |
1066 | 1073 | } |
1067 | 1074 | |
1075 | +/** |
|
1076 | + * @param integer $house |
|
1077 | + * @param boolean $minister |
|
1078 | + */ |
|
1068 | 1079 | function display_stats_line_house($house, $category, $blurb, $type, $inwhat, $extra_info, $minister, $afterstuff) { |
1069 | 1080 | if ($category == 'wrans_asked_inlastyear' || $category == 'debate_sectionsspoken_inlastyear' || $category =='comments_on_speeches' || |
1070 | 1081 | $category == 'Lwrans_asked_inlastyear' || $category == 'Ldebate_sectionsspoken_inlastyear' || $category =='Lcomments_on_speeches') { |
@@ -1163,6 +1174,9 @@ discard block |
||
1163 | 1174 | return $reg; |
1164 | 1175 | } |
1165 | 1176 | |
1177 | +/** |
|
1178 | + * @param string $area_type |
|
1179 | + */ |
|
1166 | 1180 | function regional_list($pc, $area_type, $rep_type) { |
1167 | 1181 | $constituencies = MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($pc); |
1168 | 1182 | if ($constituencies == 'CONNECTION_TIMED_OUT') { |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | // Finally, if this is a Votes page, replace the page description with |
256 | 256 | // something more descriptive of the actual data on the page. |
257 | 257 | if ($pagetype == 'votes') { |
258 | - $title = "Voting record - " . $title; |
|
259 | - $desc = 'See how ' . $member_name . ' voted on topics like Employment, Social Issues, Foreign Policy, and more.'; |
|
258 | + $title = "Voting record - " . $title; |
|
259 | + $desc = 'See how ' . $member_name . ' voted on topics like Employment, Social Issues, Foreign Policy, and more.'; |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | // Set page metadata |
@@ -359,19 +359,19 @@ discard block |
||
359 | 359 | // Generate voting segments |
360 | 360 | $set_descriptions = $policiesList->getSetDescriptions(); |
361 | 361 | if ( $policy_set && array_key_exists($policy_set, $set_descriptions) ) { |
362 | - $data['key_votes_segments'] = array( |
|
363 | - array( |
|
364 | - 'key' => $policy_set, |
|
365 | - 'title' => $set_descriptions[$policy_set], |
|
366 | - 'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
367 | - $policiesList->limitToSet($policy_set), $MEMBER, $policyOptions |
|
368 | - ) |
|
369 | - ) |
|
370 | - ); |
|
371 | - $data['og_image'] = $MEMBER->url(true) . "/policy_set_png?policy_set=" . $policy_set; |
|
372 | - $data['page_title'] = $policiesList->getSetDescriptions()[$policy_set] . ' ' . $title . ' - TheyWorkForYou'; |
|
373 | - $data['meta_description'] = 'See how ' . $data['full_name'] . ' voted on ' . $policiesList->getSetDescriptions()[$policy_set]; |
|
374 | - $data['single_policy_page'] = true; |
|
362 | + $data['key_votes_segments'] = array( |
|
363 | + array( |
|
364 | + 'key' => $policy_set, |
|
365 | + 'title' => $set_descriptions[$policy_set], |
|
366 | + 'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
367 | + $policiesList->limitToSet($policy_set), $MEMBER, $policyOptions |
|
368 | + ) |
|
369 | + ) |
|
370 | + ); |
|
371 | + $data['og_image'] = $MEMBER->url(true) . "/policy_set_png?policy_set=" . $policy_set; |
|
372 | + $data['page_title'] = $policiesList->getSetDescriptions()[$policy_set] . ' ' . $title . ' - TheyWorkForYou'; |
|
373 | + $data['meta_description'] = 'See how ' . $data['full_name'] . ' voted on ' . $policiesList->getSetDescriptions()[$policy_set]; |
|
374 | + $data['single_policy_page'] = true; |
|
375 | 375 | } else { |
376 | 376 | $data['single_policy_page'] = false; |
377 | 377 | $data['key_votes_segments'] = array( |
@@ -519,11 +519,11 @@ discard block |
||
519 | 519 | |
520 | 520 | // Generate voting segments |
521 | 521 | $data['segment'] = array( |
522 | - 'key' => $policy_set, |
|
523 | - 'title' => $policiesList->getSetDescriptions()[$policy_set], |
|
524 | - 'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
525 | - $policiesList->limitToSet($policy_set), $MEMBER |
|
526 | - ) |
|
522 | + 'key' => $policy_set, |
|
523 | + 'title' => $policiesList->getSetDescriptions()[$policy_set], |
|
524 | + 'votes' => new MySociety\TheyWorkForYou\PolicyPositions( |
|
525 | + $policiesList->limitToSet($policy_set), $MEMBER |
|
526 | + ) |
|
527 | 527 | ); |
528 | 528 | |
529 | 529 | MySociety\TheyWorkForYou\Renderer::output('mp/votes_svg', $data, true); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | |
31 | 31 | // Disable the old PAGE class. |
32 | -$new_style_template = TRUE; |
|
32 | +$new_style_template = true; |
|
33 | 33 | |
34 | 34 | // Include all the things this page needs. |
35 | 35 | include_once '../../includes/easyparliament/init.php'; |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | // Basic name, title and description |
177 | 177 | $member_name = ucfirst($MEMBER->full_name()); |
178 | 178 | $title = $member_name; |
179 | -$desc = "Read $member_name's contributions to Parliament, including speeches and questions"; |
|
179 | +$desc = "read $member_name's contributions to Parliament, including speeches and questions"; |
|
180 | 180 | |
181 | 181 | // Enhance description if this is a current member |
182 | 182 | if ($MEMBER->current_member_anywhere()) |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | |
245 | 245 | $position = implode('; ', $positions); |
246 | 246 | |
247 | -$current_offices = $MEMBER->offices('current', TRUE); |
|
248 | -$former_offices = $MEMBER->offices('previous', TRUE); |
|
247 | +$current_offices = $MEMBER->offices('current', true); |
|
248 | +$former_offices = $MEMBER->offices('previous', true); |
|
249 | 249 | |
250 | 250 | // If this person has named non-committee offices, they override the default |
251 | 251 | if (count($current_offices) > 0) { |
@@ -315,11 +315,11 @@ discard block |
||
315 | 315 | $data['has_email_alerts'] = ($MEMBER->current_member_anywhere() && !($MEMBER->current_member(HOUSE_TYPE_COMMONS) && $MEMBER->party() == 'Sinn Féin' && !$MEMBER->current_member(HOUSE_TYPE_NI))); |
316 | 316 | $data['has_expenses'] = $data['leave_date'] > '2004-01-01'; |
317 | 317 | |
318 | -$data['pre_2010_expenses'] = False; |
|
318 | +$data['pre_2010_expenses'] = false; |
|
319 | 319 | $data['post_2010_expenses'] = $data['leave_date'] > '2010-05-05'; |
320 | 320 | |
321 | 321 | if ($data['entry_date'] < '2010-05-05') { |
322 | - $data['pre_2010_expenses'] = True; |
|
322 | + $data['pre_2010_expenses'] = true; |
|
323 | 323 | // Set the expenses URL if we know it |
324 | 324 | if (isset($MEMBER->extra_info['expenses_url'])) { |
325 | 325 | $data['expenses_url_2004'] = $MEMBER->extra_info['expenses_url']; |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | * Redirect to the canonical page for a member. |
686 | 686 | */ |
687 | 687 | |
688 | -function member_redirect (&$MEMBER, $code = 301, $pagetype = NULL) { |
|
688 | +function member_redirect (&$MEMBER, $code = 301, $pagetype = null) { |
|
689 | 689 | // We come here after creating a MEMBER object by various methods. |
690 | 690 | // Now we redirect to the canonical MP page, with a person_id. |
691 | 691 | if ($MEMBER->person_id()) { |
@@ -1171,8 +1171,8 @@ discard block |
||
1171 | 1171 | $return = false; |
1172 | 1172 | if (isset($extra_info[$category])) |
1173 | 1173 | $return = display_stats_line_house(HOUSE_TYPE_COMMONS, $category, $blurb, $type, $inwhat, $extra_info, $minister, $afterstuff); |
1174 | - if (isset($extra_info["L$category"])) |
|
1175 | - $return = display_stats_line_house(HOUSE_TYPE_LORDS, "L$category", $blurb, $type, $inwhat, $extra_info, $Lminister, $afterstuff); |
|
1174 | + if (isset($extra_info["l$category"])) |
|
1175 | + $return = display_stats_line_house(HOUSE_TYPE_LORDS, "l$category", $blurb, $type, $inwhat, $extra_info, $Lminister, $afterstuff); |
|
1176 | 1176 | return $return; |
1177 | 1177 | } |
1178 | 1178 |
@@ -731,26 +731,26 @@ |
||
731 | 731 | function person_error_page($message) { |
732 | 732 | global $this_page; |
733 | 733 | switch($this_page) { |
734 | - case 'mla': |
|
735 | - $rep = 'MLA'; |
|
736 | - $SEARCHURL = '/postcode/'; |
|
737 | - $MPSURL = new \MySociety\TheyWorkForYou\Url('mlas'); |
|
738 | - break; |
|
739 | - case 'msp': |
|
740 | - $rep = 'MSP'; |
|
741 | - $SEARCHURL = '/postcode/'; |
|
742 | - $MPSURL = new \MySociety\TheyWorkForYou\Url('msps'); |
|
743 | - break; |
|
744 | - case 'peer': |
|
745 | - $rep = 'Lord'; |
|
746 | - $SEARCHURL = ''; |
|
747 | - $MPSURL = new \MySociety\TheyWorkForYou\Url('peers'); |
|
748 | - break; |
|
749 | - default: |
|
750 | - $rep = 'MP'; |
|
751 | - $SEARCHURL = new \MySociety\TheyWorkForYou\Url('mp'); |
|
752 | - $SEARCHURL = $SEARCHURL->generate(); |
|
753 | - $MPSURL = new \MySociety\TheyWorkForYou\Url('mps'); |
|
734 | + case 'mla': |
|
735 | + $rep = 'MLA'; |
|
736 | + $SEARCHURL = '/postcode/'; |
|
737 | + $MPSURL = new \MySociety\TheyWorkForYou\Url('mlas'); |
|
738 | + break; |
|
739 | + case 'msp': |
|
740 | + $rep = 'MSP'; |
|
741 | + $SEARCHURL = '/postcode/'; |
|
742 | + $MPSURL = new \MySociety\TheyWorkForYou\Url('msps'); |
|
743 | + break; |
|
744 | + case 'peer': |
|
745 | + $rep = 'Lord'; |
|
746 | + $SEARCHURL = ''; |
|
747 | + $MPSURL = new \MySociety\TheyWorkForYou\Url('peers'); |
|
748 | + break; |
|
749 | + default: |
|
750 | + $rep = 'MP'; |
|
751 | + $SEARCHURL = new \MySociety\TheyWorkForYou\Url('mp'); |
|
752 | + $SEARCHURL = $SEARCHURL->generate(); |
|
753 | + $MPSURL = new \MySociety\TheyWorkForYou\Url('mps'); |
|
754 | 754 | } |
755 | 755 | |
756 | 756 | $data = array( |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | } |
119 | 119 | if ($pid) { |
120 | 120 | $URL = new \MySociety\TheyWorkForYou\Url('search'); |
121 | - $URL->insert( array('pid'=>$pid, 'pop'=>1) ); |
|
121 | + $URL->insert(array('pid'=>$pid, 'pop'=>1)); |
|
122 | 122 | header('Location: ' . $URL->generate('none')); |
123 | 123 | exit; |
124 | 124 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | } elseif ($THEUSER->postcode_is_set()) { |
150 | 150 | get_mp_by_user_postcode($THEUSER->postcode()); |
151 | 151 | } else { |
152 | - twfy_debug ('MP', "We don't have any way of telling what MP to display"); |
|
152 | + twfy_debug('MP', "We don't have any way of telling what MP to display"); |
|
153 | 153 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, but we can’t tell which representative to display.'); |
154 | 154 | } |
155 | 155 | if (!isset($MEMBER) || !$MEMBER->valid) { |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | if (!$MEMBER->current_member(HOUSE_TYPE_SCOTLAND)) { |
217 | 217 | $title .= ', former'; |
218 | 218 | } |
219 | - $title .= ' MSP, '.$MEMBER->constituency(); |
|
219 | + $title .= ' MSP, ' . $MEMBER->constituency(); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | $positions = array(); |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | $data['eu_stance'] = $MEMBER->getEUStance(); |
311 | 311 | |
312 | 312 | # People who are or were MPs and Lords potentially have voting records, except Sinn Fein MPs |
313 | -$data['has_voting_record'] = ( ($MEMBER->house(HOUSE_TYPE_COMMONS) && $MEMBER->party() != 'Sinn Féin') || $MEMBER->house(HOUSE_TYPE_LORDS) ); |
|
313 | +$data['has_voting_record'] = (($MEMBER->house(HOUSE_TYPE_COMMONS) && $MEMBER->party() != 'Sinn Féin') || $MEMBER->house(HOUSE_TYPE_LORDS)); |
|
314 | 314 | # Everyone who is currently somewhere has email alert signup, apart from current Sinn Fein MPs who are not MLAs |
315 | 315 | $data['has_email_alerts'] = ($MEMBER->current_member_anywhere() && !($MEMBER->current_member(HOUSE_TYPE_COMMONS) && $MEMBER->party() == 'Sinn Féin' && !$MEMBER->current_member(HOUSE_TYPE_NI))); |
316 | 316 | $data['has_expenses'] = $data['leave_date'] > '2004-01-01'; |
@@ -336,9 +336,9 @@ discard block |
||
336 | 336 | |
337 | 337 | $data['this_page'] = $this_page; |
338 | 338 | $data['current_assembly'] = 'westminster'; |
339 | -if ( $this_page == 'msp' || $this_page == 'yourmsp' ) { |
|
339 | +if ($this_page == 'msp' || $this_page == 'yourmsp') { |
|
340 | 340 | $data['current_assembly'] = 'scotland'; |
341 | -} else if ( $this_page == 'mla' || $this_page == 'yourmla' ) { |
|
341 | +} else if ($this_page == 'mla' || $this_page == 'yourmla') { |
|
342 | 342 | $data['current_assembly'] = 'ni'; |
343 | 343 | } |
344 | 344 | |
@@ -354,11 +354,11 @@ discard block |
||
354 | 354 | $divisions = new MySociety\TheyWorkForYou\Divisions($MEMBER); |
355 | 355 | $policySummaries = $divisions->getMemberDivisionDetails(); |
356 | 356 | |
357 | - $policyOptions = array( 'summaries' => $policySummaries); |
|
357 | + $policyOptions = array('summaries' => $policySummaries); |
|
358 | 358 | |
359 | 359 | // Generate voting segments |
360 | 360 | $set_descriptions = $policiesList->getSetDescriptions(); |
361 | - if ( $policy_set && array_key_exists($policy_set, $set_descriptions) ) { |
|
361 | + if ($policy_set && array_key_exists($policy_set, $set_descriptions)) { |
|
362 | 362 | $data['key_votes_segments'] = array( |
363 | 363 | array( |
364 | 364 | 'key' => $policy_set, |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | |
477 | 477 | case 'recent': |
478 | 478 | $policiesList = new MySociety\TheyWorkForYou\Policies; |
479 | - $positions = new MySociety\TheyWorkForYou\PolicyPositions( $policiesList, $MEMBER ); |
|
479 | + $positions = new MySociety\TheyWorkForYou\PolicyPositions($policiesList, $MEMBER); |
|
480 | 480 | $divisions = new MySociety\TheyWorkForYou\Divisions($MEMBER, $positions, $policiesList); |
481 | 481 | |
482 | 482 | $data['divisions'] = $divisions->getRecentMemberDivisions(); |
@@ -487,15 +487,15 @@ discard block |
||
487 | 487 | |
488 | 488 | case 'divisions': |
489 | 489 | $policyID = get_http_var('policy'); |
490 | - if ( $policyID ) { |
|
491 | - $policiesList = new MySociety\TheyWorkForYou\Policies( $policyID ); |
|
490 | + if ($policyID) { |
|
491 | + $policiesList = new MySociety\TheyWorkForYou\Policies($policyID); |
|
492 | 492 | } else { |
493 | 493 | $policiesList = new MySociety\TheyWorkForYou\Policies; |
494 | 494 | } |
495 | - $positions = new MySociety\TheyWorkForYou\PolicyPositions( $policiesList, $MEMBER ); |
|
495 | + $positions = new MySociety\TheyWorkForYou\PolicyPositions($policiesList, $MEMBER); |
|
496 | 496 | $divisions = new MySociety\TheyWorkForYou\Divisions($MEMBER, $positions, $policiesList); |
497 | 497 | |
498 | - if ( $policyID ) { |
|
498 | + if ($policyID) { |
|
499 | 499 | $data['policydivisions'] = $divisions->getMemberDivisionsForPolicy($policyID); |
500 | 500 | } else { |
501 | 501 | $data['policydivisions'] = $divisions->getAllMemberDivisionsByPolicy(); |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | |
573 | 573 | // generate party policy diffs |
574 | 574 | $party = new MySociety\TheyWorkForYou\Party($MEMBER->party()); |
575 | - $positions = new MySociety\TheyWorkForYou\PolicyPositions( $policiesList, $MEMBER ); |
|
575 | + $positions = new MySociety\TheyWorkForYou\PolicyPositions($policiesList, $MEMBER); |
|
576 | 576 | $party_positions = $party->getAllPolicyPositions($policiesList); |
577 | 577 | $policy_diffs = $MEMBER->getPartyPolicyDiffs($party, $policiesList, $positions, true); |
578 | 578 | |
@@ -626,16 +626,16 @@ discard block |
||
626 | 626 | global $THEUSER; |
627 | 627 | $pc = preg_replace('#[^a-z0-9]#i', '', $pc); |
628 | 628 | if (!validate_postcode($pc)) { |
629 | - twfy_debug ('MP', "Can't display an MP because the submitted postcode wasn't of a valid form."); |
|
630 | - throw new MySociety\TheyWorkForYou\MemberException('Sorry, '._htmlentities($pc) .' isn’t a valid postcode'); |
|
629 | + twfy_debug('MP', "Can't display an MP because the submitted postcode wasn't of a valid form."); |
|
630 | + throw new MySociety\TheyWorkForYou\MemberException('Sorry, ' . _htmlentities($pc) . ' isn’t a valid postcode'); |
|
631 | 631 | } |
632 | - twfy_debug ('MP', "MP lookup by postcode"); |
|
632 | + twfy_debug('MP', "MP lookup by postcode"); |
|
633 | 633 | $constituency = strtolower(MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituency($pc)); |
634 | 634 | if ($constituency == "connection_timed_out") { |
635 | 635 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, we couldn’t check your postcode right now, as our postcode lookup server is under quite a lot of load.'); |
636 | 636 | } elseif ($constituency == "") { |
637 | - twfy_debug ('MP', "Can't display an MP, as submitted postcode didn't match a constituency"); |
|
638 | - throw new MySociety\TheyWorkForYou\MemberException('Sorry, '._htmlentities($pc) .' isn’t a known postcode'); |
|
637 | + twfy_debug('MP', "Can't display an MP, as submitted postcode didn't match a constituency"); |
|
638 | + throw new MySociety\TheyWorkForYou\MemberException('Sorry, ' . _htmlentities($pc) . ' isn’t a known postcode'); |
|
639 | 639 | } else { |
640 | 640 | // Redirect to the canonical MP page, with a person id. |
641 | 641 | $MEMBER = new MySociety\TheyWorkForYou\Member(array('constituency' => $constituency, 'house' => HOUSE_TYPE_COMMONS)); |
@@ -647,11 +647,11 @@ discard block |
||
647 | 647 | } |
648 | 648 | } |
649 | 649 | |
650 | -function get_person_by_name($name, $const='') { |
|
650 | +function get_person_by_name($name, $const = '') { |
|
651 | 651 | $MEMBER = new MySociety\TheyWorkForYou\Member(array('name' => $name, 'constituency' => $const)); |
652 | 652 | // Edge case, only attempt further detection if this isn't the Queen. |
653 | 653 | if ($name !== 'elizabeth the second' || $const) { |
654 | - twfy_debug ('MP', 'Redirecting for MP found by name/constituency'); |
|
654 | + twfy_debug('MP', 'Redirecting for MP found by name/constituency'); |
|
655 | 655 | member_redirect($MEMBER); |
656 | 656 | } |
657 | 657 | return $MEMBER; |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | * Redirect to the canonical page for a member. |
686 | 686 | */ |
687 | 687 | |
688 | -function member_redirect (&$MEMBER, $code = 301, $pagetype = NULL) { |
|
688 | +function member_redirect(&$MEMBER, $code = 301, $pagetype = NULL) { |
|
689 | 689 | // We come here after creating a MEMBER object by various methods. |
690 | 690 | // Now we redirect to the canonical MP page, with a person_id. |
691 | 691 | if ($MEMBER->person_id()) { |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | } else { |
703 | 703 | $pagetype = ''; |
704 | 704 | } |
705 | - header('Location: ' . $url . $pagetype, true, $code ); |
|
705 | + header('Location: ' . $url . $pagetype, true, $code); |
|
706 | 706 | exit; |
707 | 707 | } |
708 | 708 | } |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | |
731 | 731 | function person_error_page($message) { |
732 | 732 | global $this_page; |
733 | - switch($this_page) { |
|
733 | + switch ($this_page) { |
|
734 | 734 | case 'mla': |
735 | 735 | $rep = 'MLA'; |
736 | 736 | $SEARCHURL = '/postcode/'; |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | * Generate the summary of this person's held positions. |
769 | 769 | */ |
770 | 770 | |
771 | -function person_summary_description ($MEMBER) { |
|
771 | +function person_summary_description($MEMBER) { |
|
772 | 772 | $entered_house = $MEMBER->entered_house(); |
773 | 773 | $current_member = $MEMBER->current_member(); |
774 | 774 | $left_house = $MEMBER->left_house(); |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | } |
780 | 780 | $desc = ''; |
781 | 781 | foreach ($MEMBER->houses() as $house) { |
782 | - if ($house==HOUSE_TYPE_COMMONS && isset($entered_house[HOUSE_TYPE_LORDS])) |
|
782 | + if ($house == HOUSE_TYPE_COMMONS && isset($entered_house[HOUSE_TYPE_LORDS])) |
|
783 | 783 | continue; # Same info is printed further down |
784 | 784 | |
785 | 785 | if (!$current_member[$house]) $desc .= 'Former '; |
@@ -800,17 +800,17 @@ discard block |
||
800 | 800 | $desc .= $last['from'] . ' '; |
801 | 801 | } |
802 | 802 | } |
803 | - if ($house==HOUSE_TYPE_COMMONS || $house==HOUSE_TYPE_NI || $house==HOUSE_TYPE_SCOTLAND) { |
|
803 | + if ($house == HOUSE_TYPE_COMMONS || $house == HOUSE_TYPE_NI || $house == HOUSE_TYPE_SCOTLAND) { |
|
804 | 804 | $desc .= ' '; |
805 | - if ($house==HOUSE_TYPE_COMMONS) $desc .= '<abbr title="Member of Parliament">MP</abbr>'; |
|
806 | - if ($house==HOUSE_TYPE_NI) $desc .= '<abbr title="Member of the Legislative Assembly">MLA</abbr>'; |
|
807 | - if ($house==HOUSE_TYPE_SCOTLAND) $desc .= '<abbr title="Member of the Scottish Parliament">MSP</abbr>'; |
|
805 | + if ($house == HOUSE_TYPE_COMMONS) $desc .= '<abbr title="Member of Parliament">MP</abbr>'; |
|
806 | + if ($house == HOUSE_TYPE_NI) $desc .= '<abbr title="Member of the Legislative Assembly">MLA</abbr>'; |
|
807 | + if ($house == HOUSE_TYPE_SCOTLAND) $desc .= '<abbr title="Member of the Scottish Parliament">MSP</abbr>'; |
|
808 | 808 | if ($party_br) { |
809 | 809 | $desc .= " ($party_br)"; |
810 | 810 | } |
811 | 811 | $desc .= ' for ' . $left_house[$house]['constituency']; |
812 | 812 | } |
813 | - if ($house==HOUSE_TYPE_LORDS && $party != 'Bishop') $desc .= ' Peer'; |
|
813 | + if ($house == HOUSE_TYPE_LORDS && $party != 'Bishop') $desc .= ' Peer'; |
|
814 | 814 | $desc .= ', '; |
815 | 815 | } |
816 | 816 | $desc = preg_replace('#, $#', '', $desc); |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | * @return string A HTML summary of this person's rebellion rate. |
828 | 828 | */ |
829 | 829 | |
830 | -function person_rebellion_rate ($member) { |
|
830 | +function person_rebellion_rate($member) { |
|
831 | 831 | |
832 | 832 | // Rebellion string may be empty. |
833 | 833 | $rebellion_string = ''; |
@@ -866,7 +866,7 @@ discard block |
||
866 | 866 | // benefit unfortunately. |
867 | 867 | twfy_debug_timestamp(); |
868 | 868 | |
869 | - $person_id= $member->person_id(); |
|
869 | + $person_id = $member->person_id(); |
|
870 | 870 | |
871 | 871 | $memcache = new MySociety\TheyWorkForYou\Memcache; |
872 | 872 | $recent = $memcache->get('recent_appear:' . $person_id); |
@@ -877,7 +877,7 @@ discard block |
||
877 | 877 | $SEARCHENGINE = new \SEARCHENGINE($searchstring); |
878 | 878 | |
879 | 879 | $hansard = new MySociety\TheyWorkForYou\Hansard(); |
880 | - $args = array ( |
|
880 | + $args = array( |
|
881 | 881 | 's' => $searchstring, |
882 | 882 | 'p' => 1, |
883 | 883 | 'num' => 3, |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | twfy_debug_timestamp(); |
893 | 893 | |
894 | 894 | $MOREURL = new \MySociety\TheyWorkForYou\Url('search'); |
895 | - $MOREURL->insert( array('pid'=>$person_id, 'pop'=>1) ); |
|
895 | + $MOREURL->insert(array('pid'=>$person_id, 'pop'=>1)); |
|
896 | 896 | |
897 | 897 | $out['more_href'] = $MOREURL->generate() . '#n4'; |
898 | 898 | $out['more_text'] = 'More of ' . ucfirst($member->full_name()) . '’s recent appearances'; |
@@ -1101,7 +1101,7 @@ discard block |
||
1101 | 1101 | } |
1102 | 1102 | } |
1103 | 1103 | |
1104 | - foreach ( $wtt_stats_years as $year ) { |
|
1104 | + foreach ($wtt_stats_years as $year) { |
|
1105 | 1105 | $wtt_displayed = display_writetothem_numbers($year, $extra_info); |
1106 | 1106 | if ($wtt_displayed) { |
1107 | 1107 | $out[] = $wtt_displayed; |
@@ -1131,23 +1131,23 @@ discard block |
||
1131 | 1131 | } |
1132 | 1132 | */ |
1133 | 1133 | |
1134 | - if (display_stats_line('comments_on_speeches', 'People have made <a href="' . WEBPATH . 'comments/recent/?pid='.$member->person_id().'">', 'annotation', "</a> on this MP’s speeches", '', $extra_info)) { |
|
1135 | - $out[] = display_stats_line('comments_on_speeches', 'People have made <a href="' . WEBPATH . 'comments/recent/?pid='.$member->person_id().'">', 'annotation', "</a> on this MP’s speeches", '', $extra_info); |
|
1134 | + if (display_stats_line('comments_on_speeches', 'People have made <a href="' . WEBPATH . 'comments/recent/?pid=' . $member->person_id() . '">', 'annotation', "</a> on this MP’s speeches", '', $extra_info)) { |
|
1135 | + $out[] = display_stats_line('comments_on_speeches', 'People have made <a href="' . WEBPATH . 'comments/recent/?pid=' . $member->person_id() . '">', 'annotation', "</a> on this MP’s speeches", '', $extra_info); |
|
1136 | 1136 | } |
1137 | 1137 | if (display_stats_line('reading_age', 'This MP’s speeches, in Hansard, are readable by an average ', '', ' year old, going by the <a href="https://en.wikipedia.org/wiki/Flesch-Kincaid_Readability_Test">Flesch-Kincaid Grade Level</a> score', '', $extra_info)) { |
1138 | 1138 | $out[] = display_stats_line('reading_age', 'This MP’s speeches, in Hansard, are readable by an average ', '', ' year old, going by the <a href="https://en.wikipedia.org/wiki/Flesch-Kincaid_Readability_Test">Flesch-Kincaid Grade Level</a> score', '', $extra_info); |
1139 | 1139 | } |
1140 | 1140 | } |
1141 | 1141 | |
1142 | - if (isset($extra_info['number_of_alerts']) && ($extra_info['number_of_alerts']>0 || $has_email_alerts)) { |
|
1143 | - $line = '<strong>' . _htmlentities($extra_info['number_of_alerts']) . '</strong> ' . ($extra_info['number_of_alerts']==1?'person is':'people are') . ' tracking '; |
|
1142 | + if (isset($extra_info['number_of_alerts']) && ($extra_info['number_of_alerts'] > 0 || $has_email_alerts)) { |
|
1143 | + $line = '<strong>' . _htmlentities($extra_info['number_of_alerts']) . '</strong> ' . ($extra_info['number_of_alerts'] == 1 ? 'person is' : 'people are') . ' tracking '; |
|
1144 | 1144 | if ($member->house_disp == HOUSE_TYPE_COMMONS) $line .= 'this MP'; |
1145 | 1145 | elseif ($member->house_disp == HOUSE_TYPE_LORDS) $line .= 'this peer'; |
1146 | 1146 | elseif ($member->house_disp == HOUSE_TYPE_NI) $line .= 'this MLA'; |
1147 | 1147 | elseif ($member->house_disp == HOUSE_TYPE_SCOTLAND) $line .= 'this MSP'; |
1148 | 1148 | elseif ($member->house_disp == HOUSE_TYPE_ROYAL) $line .= $member->full_name(); |
1149 | 1149 | if ($has_email_alerts) { |
1150 | - $line .= ' — <a href="' . WEBPATH . 'alert/?pid='.$member->person_id().'">email me updates on '. $member->full_name(). '’s activity</a>'; |
|
1150 | + $line .= ' — <a href="' . WEBPATH . 'alert/?pid=' . $member->person_id() . '">email me updates on ' . $member->full_name() . '’s activity</a>'; |
|
1151 | 1151 | } |
1152 | 1152 | |
1153 | 1153 | $out[] = $line; |
@@ -1177,25 +1177,25 @@ discard block |
||
1177 | 1177 | } |
1178 | 1178 | |
1179 | 1179 | function display_stats_line_house($house, $category, $blurb, $type, $inwhat, $extra_info, $minister, $afterstuff) { |
1180 | - if ($category == 'wrans_asked_inlastyear' || $category == 'debate_sectionsspoken_inlastyear' || $category =='comments_on_speeches' || |
|
1181 | - $category == 'Lwrans_asked_inlastyear' || $category == 'Ldebate_sectionsspoken_inlastyear' || $category =='Lcomments_on_speeches') { |
|
1182 | - if ($extra_info[$category]==0) { |
|
1180 | + if ($category == 'wrans_asked_inlastyear' || $category == 'debate_sectionsspoken_inlastyear' || $category == 'comments_on_speeches' || |
|
1181 | + $category == 'Lwrans_asked_inlastyear' || $category == 'Ldebate_sectionsspoken_inlastyear' || $category == 'Lcomments_on_speeches') { |
|
1182 | + if ($extra_info[$category] == 0) { |
|
1183 | 1183 | $blurb = preg_replace('#<a.*?>#', '', $blurb); |
1184 | 1184 | $inwhat = preg_replace('#<\/a>#', '', $inwhat); |
1185 | 1185 | } |
1186 | 1186 | } |
1187 | - if ($house==HOUSE_TYPE_LORDS) $inwhat = str_replace('MP', 'Lord', $inwhat); |
|
1187 | + if ($house == HOUSE_TYPE_LORDS) $inwhat = str_replace('MP', 'Lord', $inwhat); |
|
1188 | 1188 | $line = $blurb; |
1189 | 1189 | $line .= '<strong>' . $extra_info[$category]; |
1190 | 1190 | if ($type) $line .= ' ' . make_plural($type, $extra_info[$category]); |
1191 | 1191 | $line .= '</strong>'; |
1192 | 1192 | $line .= $inwhat; |
1193 | - if ($minister===2) { |
|
1193 | + if ($minister === 2) { |
|
1194 | 1194 | $line .= ' — Speakers/ deputy speakers do not ask written questions'; |
1195 | 1195 | } elseif ($minister) |
1196 | 1196 | $line .= ' — Ministers do not ask written questions'; |
1197 | 1197 | else { |
1198 | - $type = ($house==HOUSE_TYPE_COMMONS?'MP':($house==HOUSE_TYPE_LORDS?'Lord':'MLA')); |
|
1198 | + $type = ($house == HOUSE_TYPE_COMMONS ? 'MP' : ($house == HOUSE_TYPE_LORDS ? 'Lord' : 'MLA')); |
|
1199 | 1199 | if (!get_http_var('rem') && isset($extra_info[$category . '_quintile'])) { |
1200 | 1200 | $line .= ' — '; |
1201 | 1201 | $q = $extra_info[$category . '_quintile']; |
@@ -1240,7 +1240,7 @@ discard block |
||
1240 | 1240 | if ($a == 'very high') $a = 'a very high'; |
1241 | 1241 | $extra_info["writetothem_responsiveness_fuzzy_response_description_$year"] = $a; |
1242 | 1242 | |
1243 | - return display_stats_line("writetothem_responsiveness_fuzzy_response_description_$year", 'Replied within 2 or 3 weeks to <a href="https://www.writetothem.com/stats/'.$year.'/mps" title="From WriteToThem.com">', "", "</a> <!-- Mean: " . $mean . " --> number of messages sent via WriteToThem.com during ".$year.", according to constituents", "", $extra_info); |
|
1243 | + return display_stats_line("writetothem_responsiveness_fuzzy_response_description_$year", 'Replied within 2 or 3 weeks to <a href="https://www.writetothem.com/stats/' . $year . '/mps" title="From WriteToThem.com">', "", "</a> <!-- Mean: " . $mean . " --> number of messages sent via WriteToThem.com during " . $year . ", according to constituents", "", $extra_info); |
|
1244 | 1244 | } |
1245 | 1245 | |
1246 | 1246 | } |
@@ -1248,7 +1248,7 @@ discard block |
||
1248 | 1248 | function get_all_writetothem_strings($member, $wtt_stats_years) { |
1249 | 1249 | $extra_info = $member->extra_info(); |
1250 | 1250 | $strings = array(); |
1251 | - foreach ( $wtt_stats_years as $year ) { |
|
1251 | + foreach ($wtt_stats_years as $year) { |
|
1252 | 1252 | |
1253 | 1253 | if (isset($extra_info["writetothem_responsiveness_mean_$year"])) { |
1254 | 1254 | $a = $extra_info["writetothem_responsiveness_fuzzy_response_description_$year"]; |
@@ -1264,7 +1264,7 @@ discard block |
||
1264 | 1264 | return; |
1265 | 1265 | } |
1266 | 1266 | |
1267 | - $reg = array( 'date' => '', 'data' => '<p>Nil</p>' ); |
|
1267 | + $reg = array('date' => '', 'data' => '<p>Nil</p>'); |
|
1268 | 1268 | if (isset($extra_info['register_member_interests_date'])) { |
1269 | 1269 | $reg['date'] = format_date($extra_info['register_member_interests_date'], SHORTDATEFORMAT); |
1270 | 1270 | } |
@@ -1299,7 +1299,7 @@ discard block |
||
1299 | 1299 | $dissolution['params']); |
1300 | 1300 | } |
1301 | 1301 | $mcon = array(); $mreg = array(); |
1302 | - for ($i=0; $i<$q->rows(); $i++) { |
|
1302 | + for ($i = 0; $i < $q->rows(); $i++) { |
|
1303 | 1303 | $house = $q->field($i, 'house'); |
1304 | 1304 | $pid = $q->field($i, 'person_id'); |
1305 | 1305 | $cons = $q->field($i, 'constituency'); |
@@ -1337,8 +1337,8 @@ discard block |
||
1337 | 1337 | } |
1338 | 1338 | } |
1339 | 1339 | |
1340 | - foreach($mreg as $reg) { |
|
1341 | - $data['members'][] = array ( |
|
1340 | + foreach ($mreg as $reg) { |
|
1341 | + $data['members'][] = array( |
|
1342 | 1342 | 'url' => '/' . $rep_type . '/?p=' . $reg['person_id'], |
1343 | 1343 | 'name' => $reg['given_name'] . ' ' . $reg['family_name'] |
1344 | 1344 | ); |
@@ -43,7 +43,8 @@ discard block |
||
43 | 43 | // Ensure that page type is set |
44 | 44 | if (get_http_var('pagetype')) { |
45 | 45 | $pagetype = get_http_var('pagetype'); |
46 | -} else { |
|
46 | +} |
|
47 | +else { |
|
47 | 48 | $pagetype = 'profile'; |
48 | 49 | } |
49 | 50 | if ($pagetype == 'profile') { |
@@ -62,16 +63,36 @@ discard block |
||
62 | 63 | $constituency = strtolower(str_replace('_', ' ', get_http_var('c'))); |
63 | 64 | |
64 | 65 | // Fix for names with non-ASCII characters |
65 | -if ($name == 'sion simon') $name = 'si\xf4n simon'; |
|
66 | -if ($name == 'sian james') $name = 'si\xe2n james'; |
|
67 | -if ($name == 'lembit opik') $name = 'lembit \xf6pik'; |
|
68 | -if ($name == 'bairbre de brun') $name = 'bairbre de br\xfan'; |
|
69 | -if ($name == 'daithi mckay') $name = 'daith\xed mckay'; |
|
70 | -if ($name == 'caral ni chuilin') $name = 'car\xe1l n\xed chuil\xedn'; |
|
71 | -if ($name == 'caledon du pre') $name = 'caledon du pr\xe9'; |
|
72 | -if ($name == 'sean etchingham') $name = 'se\xe1n etchingham'; |
|
73 | -if ($name == 'john tinne') $name = 'john tinn\xe9'; |
|
74 | -if ($name == 'renee short') $name = 'ren\xe9e short'; |
|
66 | +if ($name == 'sion simon') { |
|
67 | + $name = 'si\xf4n simon'; |
|
68 | +} |
|
69 | +if ($name == 'sian james') { |
|
70 | + $name = 'si\xe2n james'; |
|
71 | +} |
|
72 | +if ($name == 'lembit opik') { |
|
73 | + $name = 'lembit \xf6pik'; |
|
74 | +} |
|
75 | +if ($name == 'bairbre de brun') { |
|
76 | + $name = 'bairbre de br\xfan'; |
|
77 | +} |
|
78 | +if ($name == 'daithi mckay') { |
|
79 | + $name = 'daith\xed mckay'; |
|
80 | +} |
|
81 | +if ($name == 'caral ni chuilin') { |
|
82 | + $name = 'car\xe1l n\xed chuil\xedn'; |
|
83 | +} |
|
84 | +if ($name == 'caledon du pre') { |
|
85 | + $name = 'caledon du pr\xe9'; |
|
86 | +} |
|
87 | +if ($name == 'sean etchingham') { |
|
88 | + $name = 'se\xe1n etchingham'; |
|
89 | +} |
|
90 | +if ($name == 'john tinne') { |
|
91 | + $name = 'john tinn\xe9'; |
|
92 | +} |
|
93 | +if ($name == 'renee short') { |
|
94 | + $name = 'ren\xe9e short'; |
|
95 | +} |
|
75 | 96 | |
76 | 97 | // Fix for common misspellings, name changes etc |
77 | 98 | $name_fix = array( |
@@ -97,13 +118,16 @@ discard block |
||
97 | 118 | if ($constituency == $name_fix[$name][1]) { |
98 | 119 | $name = $name_fix[$name][0]; |
99 | 120 | } |
100 | - } else { |
|
121 | + } |
|
122 | + else { |
|
101 | 123 | $name = $name_fix[$name]; |
102 | 124 | } |
103 | 125 | } |
104 | 126 | |
105 | 127 | // Fixes for Ynys Mon, and a Unicode URL |
106 | -if ($constituency == 'ynys mon') $constituency = "ynys m\xf4n"; |
|
128 | +if ($constituency == 'ynys mon') { |
|
129 | + $constituency = "ynys m\xf4n"; |
|
130 | +} |
|
107 | 131 | if (preg_match("#^ynys m\xc3\xb4n#i", $constituency)) { |
108 | 132 | $constituency = "ynys m\xf4n"; |
109 | 133 | } |
@@ -126,29 +150,46 @@ discard block |
||
126 | 150 | |
127 | 151 | ///////////////////////////////////////////////////////// |
128 | 152 | // DETERMINE TYPE OF REPRESENTITIVE |
129 | -if (get_http_var('peer')) $this_page = 'peer'; |
|
130 | -elseif (get_http_var('royal')) $this_page = 'royal'; |
|
131 | -elseif (get_http_var('mla')) $this_page = 'mla'; |
|
132 | -elseif (get_http_var('msp')) $this_page = 'msp'; |
|
133 | -else $this_page = 'mp'; |
|
153 | +if (get_http_var('peer')) { |
|
154 | + $this_page = 'peer'; |
|
155 | +} |
|
156 | +elseif (get_http_var('royal')) { |
|
157 | + $this_page = 'royal'; |
|
158 | +} |
|
159 | +elseif (get_http_var('mla')) { |
|
160 | + $this_page = 'mla'; |
|
161 | +} |
|
162 | +elseif (get_http_var('msp')) { |
|
163 | + $this_page = 'msp'; |
|
164 | +} |
|
165 | +else { |
|
166 | + $this_page = 'mp'; |
|
167 | +} |
|
134 | 168 | |
135 | 169 | try { |
136 | 170 | if (is_numeric($pid)) { |
137 | 171 | $MEMBER = get_person_by_id($pid); |
138 | - } elseif (is_numeric(get_http_var('m'))) { |
|
172 | + } |
|
173 | + elseif (is_numeric(get_http_var('m'))) { |
|
139 | 174 | get_person_by_member_id(get_http_var('m')); |
140 | - } elseif (get_http_var('pc')) { |
|
175 | + } |
|
176 | + elseif (get_http_var('pc')) { |
|
141 | 177 | get_person_by_postcode(get_http_var('pc')); |
142 | - } elseif ($name) { |
|
178 | + } |
|
179 | + elseif ($name) { |
|
143 | 180 | $MEMBER = get_person_by_name($name, $constituency); |
144 | - } elseif ($constituency) { |
|
181 | + } |
|
182 | + elseif ($constituency) { |
|
145 | 183 | get_mp_by_constituency($constituency); |
146 | - } elseif (($this_page == 'msp' || $this_page == 'mla') && $THEUSER->postcode_is_set()) { |
|
184 | + } |
|
185 | + elseif (($this_page == 'msp' || $this_page == 'mla') && $THEUSER->postcode_is_set()) { |
|
147 | 186 | get_regional_by_user_postcode($THEUSER->postcode(), $this_page); |
148 | 187 | exit; |
149 | - } elseif ($THEUSER->postcode_is_set()) { |
|
188 | + } |
|
189 | + elseif ($THEUSER->postcode_is_set()) { |
|
150 | 190 | get_mp_by_user_postcode($THEUSER->postcode()); |
151 | - } else { |
|
191 | + } |
|
192 | + else { |
|
152 | 193 | twfy_debug ('MP', "We don't have any way of telling what MP to display"); |
153 | 194 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, but we can’t tell which representative to display.'); |
154 | 195 | } |
@@ -179,8 +220,9 @@ discard block |
||
179 | 220 | $desc = "Read $member_name's contributions to Parliament, including speeches and questions"; |
180 | 221 | |
181 | 222 | // Enhance description if this is a current member |
182 | -if ($MEMBER->current_member_anywhere()) |
|
223 | +if ($MEMBER->current_member_anywhere()) { |
|
183 | 224 | $desc .= ', investigate their voting record, and get email alerts on their activity'; |
225 | +} |
|
184 | 226 | |
185 | 227 | // Enhance title if this is a member of the Commons |
186 | 228 | if ($MEMBER->house(HOUSE_TYPE_COMMONS)) { |
@@ -188,28 +230,34 @@ discard block |
||
188 | 230 | $title .= ', former'; |
189 | 231 | } |
190 | 232 | $title .= ' MP'; |
191 | - if ($MEMBER->constituency()) $title .= ', ' . $MEMBER->constituency(); |
|
192 | -} |
|
233 | + if ($MEMBER->constituency()) { |
|
234 | + $title .= ', ' . $MEMBER->constituency(); |
|
235 | + } |
|
236 | + } |
|
193 | 237 | |
194 | 238 | // Enhance title if this is a member of NIA |
195 | 239 | if ($MEMBER->house(HOUSE_TYPE_NI)) { |
196 | 240 | if ($MEMBER->house(HOUSE_TYPE_COMMONS) || $MEMBER->house(HOUSE_TYPE_LORDS)) { |
197 | 241 | $desc = str_replace('Parliament', 'Parliament and the Northern Ireland Assembly', $desc); |
198 | - } else { |
|
242 | + } |
|
243 | + else { |
|
199 | 244 | $desc = str_replace('Parliament', 'the Northern Ireland Assembly', $desc); |
200 | 245 | } |
201 | 246 | if (!$MEMBER->current_member(HOUSE_TYPE_NI)) { |
202 | 247 | $title .= ', former'; |
203 | 248 | } |
204 | 249 | $title .= ' MLA'; |
205 | - if ($MEMBER->constituency()) $title .= ', ' . $MEMBER->constituency(); |
|
206 | -} |
|
250 | + if ($MEMBER->constituency()) { |
|
251 | + $title .= ', ' . $MEMBER->constituency(); |
|
252 | + } |
|
253 | + } |
|
207 | 254 | |
208 | 255 | // Enhance title if this is a member of Scottish Parliament |
209 | 256 | if ($MEMBER->house(HOUSE_TYPE_SCOTLAND)) { |
210 | 257 | if ($MEMBER->house(HOUSE_TYPE_COMMONS) || $MEMBER->house(HOUSE_TYPE_LORDS)) { |
211 | 258 | $desc = str_replace('Parliament', 'the UK and Scottish Parliaments', $desc); |
212 | - } else { |
|
259 | + } |
|
260 | + else { |
|
213 | 261 | $desc = str_replace('Parliament', 'the Scottish Parliament', $desc); |
214 | 262 | } |
215 | 263 | $desc = str_replace(', and get email alerts on their activity', '', $desc); |
@@ -224,14 +272,18 @@ discard block |
||
224 | 272 | // Position if this is a member of the Commons |
225 | 273 | if ($MEMBER->house(HOUSE_TYPE_COMMONS)) { |
226 | 274 | $position = $MEMBER->current_member(HOUSE_TYPE_COMMONS) ? 'MP' : 'Former MP'; |
227 | - if ($MEMBER->constituency()) $position .= ', ' . $MEMBER->constituency(); |
|
275 | + if ($MEMBER->constituency()) { |
|
276 | + $position .= ', ' . $MEMBER->constituency(); |
|
277 | + } |
|
228 | 278 | $positions[] = $position; |
229 | 279 | } |
230 | 280 | |
231 | 281 | // Position if this is a member of NIA |
232 | 282 | if ($MEMBER->house(HOUSE_TYPE_NI)) { |
233 | 283 | $position = $MEMBER->current_member(HOUSE_TYPE_NI) ? 'MLA' : 'Former MLA'; |
234 | - if ($MEMBER->constituency()) $position .= ', ' . $MEMBER->constituency(); |
|
284 | + if ($MEMBER->constituency()) { |
|
285 | + $position .= ', ' . $MEMBER->constituency(); |
|
286 | + } |
|
235 | 287 | $positions[] = $position; |
236 | 288 | } |
237 | 289 | |
@@ -265,8 +317,9 @@ discard block |
||
265 | 317 | |
266 | 318 | // Build the RSS link and add it to page data. |
267 | 319 | $feedurl = $DATA->page_metadata('mp_rss', 'url') . $MEMBER->person_id() . '.rdf'; |
268 | -if (file_exists(BASEDIR . '/' . $feedurl)) |
|
320 | +if (file_exists(BASEDIR . '/' . $feedurl)) { |
|
269 | 321 | $DATA->set_page_metadata($this_page, 'rss', $feedurl); |
322 | +} |
|
270 | 323 | |
271 | 324 | // Prepare data for the template |
272 | 325 | $data['full_name'] = $MEMBER->full_name(); |
@@ -323,7 +376,8 @@ discard block |
||
323 | 376 | // Set the expenses URL if we know it |
324 | 377 | if (isset($MEMBER->extra_info['expenses_url'])) { |
325 | 378 | $data['expenses_url_2004'] = $MEMBER->extra_info['expenses_url']; |
326 | - } else { |
|
379 | + } |
|
380 | + else { |
|
327 | 381 | $data['expenses_url_2004'] = 'http://mpsallowances.parliament.uk/mpslordsandoffices/hocallowances/allowances%2Dby%2Dmp/'; |
328 | 382 | } |
329 | 383 | } |
@@ -338,7 +392,8 @@ discard block |
||
338 | 392 | $data['current_assembly'] = 'westminster'; |
339 | 393 | if ( $this_page == 'msp' || $this_page == 'yourmsp' ) { |
340 | 394 | $data['current_assembly'] = 'scotland'; |
341 | -} else if ( $this_page == 'mla' || $this_page == 'yourmla' ) { |
|
395 | +} |
|
396 | +else if ( $this_page == 'mla' || $this_page == 'yourmla' ) { |
|
342 | 397 | $data['current_assembly'] = 'ni'; |
343 | 398 | } |
344 | 399 | |
@@ -372,7 +427,8 @@ discard block |
||
372 | 427 | $data['page_title'] = $policiesList->getSetDescriptions()[$policy_set] . ' ' . $title . ' - TheyWorkForYou'; |
373 | 428 | $data['meta_description'] = 'See how ' . $data['full_name'] . ' voted on ' . $policiesList->getSetDescriptions()[$policy_set]; |
374 | 429 | $data['single_policy_page'] = true; |
375 | - } else { |
|
430 | + } |
|
431 | + else { |
|
376 | 432 | $data['single_policy_page'] = false; |
377 | 433 | $data['key_votes_segments'] = array( |
378 | 434 | array( |
@@ -489,7 +545,8 @@ discard block |
||
489 | 545 | $policyID = get_http_var('policy'); |
490 | 546 | if ( $policyID ) { |
491 | 547 | $policiesList = new MySociety\TheyWorkForYou\Policies( $policyID ); |
492 | - } else { |
|
548 | + } |
|
549 | + else { |
|
493 | 550 | $policiesList = new MySociety\TheyWorkForYou\Policies; |
494 | 551 | } |
495 | 552 | $positions = new MySociety\TheyWorkForYou\PolicyPositions( $policiesList, $MEMBER ); |
@@ -497,7 +554,8 @@ discard block |
||
497 | 554 | |
498 | 555 | if ( $policyID ) { |
499 | 556 | $data['policydivisions'] = $divisions->getMemberDivisionsForPolicy($policyID); |
500 | - } else { |
|
557 | + } |
|
558 | + else { |
|
501 | 559 | $data['policydivisions'] = $divisions->getAllMemberDivisionsByPolicy(); |
502 | 560 | } |
503 | 561 | |
@@ -633,10 +691,12 @@ discard block |
||
633 | 691 | $constituency = strtolower(MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituency($pc)); |
634 | 692 | if ($constituency == "connection_timed_out") { |
635 | 693 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, we couldn’t check your postcode right now, as our postcode lookup server is under quite a lot of load.'); |
636 | - } elseif ($constituency == "") { |
|
694 | + } |
|
695 | + elseif ($constituency == "") { |
|
637 | 696 | twfy_debug ('MP', "Can't display an MP, as submitted postcode didn't match a constituency"); |
638 | 697 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, '._htmlentities($pc) .' isn’t a known postcode'); |
639 | - } else { |
|
698 | + } |
|
699 | + else { |
|
640 | 700 | // Redirect to the canonical MP page, with a person id. |
641 | 701 | $MEMBER = new MySociety\TheyWorkForYou\Member(array('constituency' => $constituency, 'house' => HOUSE_TYPE_COMMONS)); |
642 | 702 | if ($MEMBER->person_id()) { |
@@ -667,9 +727,11 @@ discard block |
||
667 | 727 | $this_page = "your$page"; |
668 | 728 | if ($page == 'msp' && \MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsScottish($pc)) { |
669 | 729 | regional_list($pc, 'SPC', $page); |
670 | - } elseif ($page == 'mla' && \MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsNi($pc)) { |
|
730 | + } |
|
731 | + elseif ($page == 'mla' && \MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsNi($pc)) { |
|
671 | 732 | regional_list($pc, 'NIE', $page); |
672 | - } else { |
|
733 | + } |
|
734 | + else { |
|
673 | 735 | throw new MySociety\TheyWorkForYou\MemberException('Your set postcode is not in the right region.'); |
674 | 736 | } |
675 | 737 | } |
@@ -692,14 +754,17 @@ discard block |
||
692 | 754 | $url = $MEMBER->url(); |
693 | 755 | $params = array(); |
694 | 756 | foreach ($_GET as $key => $value) { |
695 | - if (substr($key, 0, 4) == 'utm_' || $key == 'gclid') |
|
696 | - $params[] = "$key=$value"; |
|
757 | + if (substr($key, 0, 4) == 'utm_' || $key == 'gclid') { |
|
758 | + $params[] = "$key=$value"; |
|
759 | + } |
|
760 | + } |
|
761 | + if (count($params)) { |
|
762 | + $url .= '?' . join('&', $params); |
|
697 | 763 | } |
698 | - if (count($params)) |
|
699 | - $url .= '?' . join('&', $params); |
|
700 | 764 | if ($pagetype) { |
701 | 765 | $pagetype = '/' . $pagetype; |
702 | - } else { |
|
766 | + } |
|
767 | + else { |
|
703 | 768 | $pagetype = ''; |
704 | 769 | } |
705 | 770 | header('Location: ' . $url . $pagetype, true, $code ); |
@@ -773,16 +838,21 @@ discard block |
||
773 | 838 | $current_member = $MEMBER->current_member(); |
774 | 839 | $left_house = $MEMBER->left_house(); |
775 | 840 | |
776 | - if (in_array(HOUSE_TYPE_ROYAL, $MEMBER->houses())) { # Royal short-circuit |
|
841 | + if (in_array(HOUSE_TYPE_ROYAL, $MEMBER->houses())) { |
|
842 | +# Royal short-circuit |
|
777 | 843 | return '<strong>Acceded on ' . $entered_house[HOUSE_TYPE_ROYAL]['date_pretty'] |
778 | 844 | . '<br>Coronated on 2 June 1953</strong></li>'; |
779 | 845 | } |
780 | 846 | $desc = ''; |
781 | 847 | foreach ($MEMBER->houses() as $house) { |
782 | - if ($house==HOUSE_TYPE_COMMONS && isset($entered_house[HOUSE_TYPE_LORDS])) |
|
783 | - continue; # Same info is printed further down |
|
848 | + if ($house==HOUSE_TYPE_COMMONS && isset($entered_house[HOUSE_TYPE_LORDS])) { |
|
849 | + continue; |
|
850 | + } |
|
851 | + # Same info is printed further down |
|
784 | 852 | |
785 | - if (!$current_member[$house]) $desc .= 'Former '; |
|
853 | + if (!$current_member[$house]) { |
|
854 | + $desc .= 'Former '; |
|
855 | + } |
|
786 | 856 | |
787 | 857 | $party = $left_house[$house]['party']; |
788 | 858 | $party_br = ''; |
@@ -790,8 +860,9 @@ discard block |
||
790 | 860 | $party_br = $m[2]; |
791 | 861 | $party = $m[1]; |
792 | 862 | } |
793 | - if ($party != 'unknown') |
|
794 | - $desc .= _htmlentities($party); |
|
863 | + if ($party != 'unknown') { |
|
864 | + $desc .= _htmlentities($party); |
|
865 | + } |
|
795 | 866 | if ($party == 'Speaker' || $party == 'Deputy Speaker') { |
796 | 867 | $desc .= ', and '; |
797 | 868 | # XXX: Might go horribly wrong if something odd happens |
@@ -802,15 +873,23 @@ discard block |
||
802 | 873 | } |
803 | 874 | if ($house==HOUSE_TYPE_COMMONS || $house==HOUSE_TYPE_NI || $house==HOUSE_TYPE_SCOTLAND) { |
804 | 875 | $desc .= ' '; |
805 | - if ($house==HOUSE_TYPE_COMMONS) $desc .= '<abbr title="Member of Parliament">MP</abbr>'; |
|
806 | - if ($house==HOUSE_TYPE_NI) $desc .= '<abbr title="Member of the Legislative Assembly">MLA</abbr>'; |
|
807 | - if ($house==HOUSE_TYPE_SCOTLAND) $desc .= '<abbr title="Member of the Scottish Parliament">MSP</abbr>'; |
|
876 | + if ($house==HOUSE_TYPE_COMMONS) { |
|
877 | + $desc .= '<abbr title="Member of Parliament">MP</abbr>'; |
|
878 | + } |
|
879 | + if ($house==HOUSE_TYPE_NI) { |
|
880 | + $desc .= '<abbr title="Member of the Legislative Assembly">MLA</abbr>'; |
|
881 | + } |
|
882 | + if ($house==HOUSE_TYPE_SCOTLAND) { |
|
883 | + $desc .= '<abbr title="Member of the Scottish Parliament">MSP</abbr>'; |
|
884 | + } |
|
808 | 885 | if ($party_br) { |
809 | 886 | $desc .= " ($party_br)"; |
810 | 887 | } |
811 | 888 | $desc .= ' for ' . $left_house[$house]['constituency']; |
812 | 889 | } |
813 | - if ($house==HOUSE_TYPE_LORDS && $party != 'Bishop') $desc .= ' Peer'; |
|
890 | + if ($house==HOUSE_TYPE_LORDS && $party != 'Bishop') { |
|
891 | + $desc .= ' Peer'; |
|
892 | + } |
|
814 | 893 | $desc .= ', '; |
815 | 894 | } |
816 | 895 | $desc = preg_replace('#, $#', '', $desc); |
@@ -841,7 +920,8 @@ discard block |
||
841 | 920 | if (isset($member->extra_info['public_whip_rebelrank'])) { |
842 | 921 | if ($member->extra_info['public_whip_data_date'] == 'complete') { |
843 | 922 | $rebellion_string .= ' in their last parliament.'; |
844 | - } else { |
|
923 | + } |
|
924 | + else { |
|
845 | 925 | $rebellion_string .= ' in the current parliament.'; |
846 | 926 | } |
847 | 927 | } |
@@ -1021,7 +1101,8 @@ discard block |
||
1021 | 1101 | function constituency_previous_mps($member) { |
1022 | 1102 | if ($member->house(HOUSE_TYPE_COMMONS)) { |
1023 | 1103 | return $member->previous_mps(); |
1024 | - } else { |
|
1104 | + } |
|
1105 | + else { |
|
1025 | 1106 | return array(); |
1026 | 1107 | } |
1027 | 1108 | } |
@@ -1029,7 +1110,8 @@ discard block |
||
1029 | 1110 | function constituency_future_mps($member) { |
1030 | 1111 | if ($member->house(HOUSE_TYPE_COMMONS)) { |
1031 | 1112 | return $member->future_mps(); |
1032 | - } else { |
|
1113 | + } |
|
1114 | + else { |
|
1033 | 1115 | return array(); |
1034 | 1116 | } |
1035 | 1117 | } |
@@ -1073,10 +1155,13 @@ discard block |
||
1073 | 1155 | # Find latest entered house |
1074 | 1156 | $entered_house = null; |
1075 | 1157 | foreach ($member->entered_house() as $h => $eh) { |
1076 | - if (!$entered_house || $eh['date'] > $entered_house) $entered_house = $eh['date']; |
|
1158 | + if (!$entered_house || $eh['date'] > $entered_house) { |
|
1159 | + $entered_house = $eh['date']; |
|
1160 | + } |
|
1161 | + } |
|
1162 | + if ($entered_house > $year_ago) { |
|
1163 | + $since_text = 'since joining Parliament'; |
|
1077 | 1164 | } |
1078 | - if ($entered_house > $year_ago) |
|
1079 | - $since_text = 'since joining Parliament'; |
|
1080 | 1165 | |
1081 | 1166 | $MOREURL = new \MySociety\TheyWorkForYou\Url('search'); |
1082 | 1167 | $section = 'section:debates section:whall section:lords section:ni'; |
@@ -1089,10 +1174,12 @@ discard block |
||
1089 | 1174 | $MOREURL->insert(array('pid'=>$member->person_id(), 's'=>'section:wrans', 'pop'=>1)); |
1090 | 1175 | // We assume that if they've answered a question, they're a minister |
1091 | 1176 | $minister = 0; $Lminister = false; |
1092 | - if (isset($extra_info['wrans_answered_inlastyear']) && $extra_info['wrans_answered_inlastyear'] > 0 && $extra_info['wrans_asked_inlastyear'] == 0) |
|
1093 | - $minister = 1; |
|
1094 | - if (isset($extra_info['Lwrans_answered_inlastyear']) && $extra_info['Lwrans_answered_inlastyear'] > 0 && $extra_info['Lwrans_asked_inlastyear'] == 0) |
|
1095 | - $Lminister = true; |
|
1177 | + if (isset($extra_info['wrans_answered_inlastyear']) && $extra_info['wrans_answered_inlastyear'] > 0 && $extra_info['wrans_asked_inlastyear'] == 0) { |
|
1178 | + $minister = 1; |
|
1179 | + } |
|
1180 | + if (isset($extra_info['Lwrans_answered_inlastyear']) && $extra_info['Lwrans_answered_inlastyear'] > 0 && $extra_info['Lwrans_asked_inlastyear'] == 0) { |
|
1181 | + $Lminister = true; |
|
1182 | + } |
|
1096 | 1183 | if ($member->party() == 'SPK' || $member->party() == 'CWM' || $member->party() == 'DCWM') { |
1097 | 1184 | $minister = 2; |
1098 | 1185 | } |
@@ -1112,7 +1199,8 @@ discard block |
||
1112 | 1199 | $after_stuff = ' <small>(From Public Whip)</small>'; |
1113 | 1200 | if ($member->party() == 'SNP') { |
1114 | 1201 | $after_stuff .= '<br><em>Note SNP MPs do not vote on legislation not affecting Scotland.</em>'; |
1115 | - } elseif ($member->party() == 'SPK' || $member->party() == 'CWM' || $member->party() == 'DCWM') { |
|
1202 | + } |
|
1203 | + elseif ($member->party() == 'SPK' || $member->party() == 'CWM' || $member->party() == 'DCWM') { |
|
1116 | 1204 | $after_stuff .= '<br><em>Speakers and deputy speakers cannot vote except to break a tie.</em>'; |
1117 | 1205 | } |
1118 | 1206 | if ($member->party() != 'Sinn Féin') { |
@@ -1141,11 +1229,21 @@ discard block |
||
1141 | 1229 | |
1142 | 1230 | if (isset($extra_info['number_of_alerts']) && ($extra_info['number_of_alerts']>0 || $has_email_alerts)) { |
1143 | 1231 | $line = '<strong>' . _htmlentities($extra_info['number_of_alerts']) . '</strong> ' . ($extra_info['number_of_alerts']==1?'person is':'people are') . ' tracking '; |
1144 | - if ($member->house_disp == HOUSE_TYPE_COMMONS) $line .= 'this MP'; |
|
1145 | - elseif ($member->house_disp == HOUSE_TYPE_LORDS) $line .= 'this peer'; |
|
1146 | - elseif ($member->house_disp == HOUSE_TYPE_NI) $line .= 'this MLA'; |
|
1147 | - elseif ($member->house_disp == HOUSE_TYPE_SCOTLAND) $line .= 'this MSP'; |
|
1148 | - elseif ($member->house_disp == HOUSE_TYPE_ROYAL) $line .= $member->full_name(); |
|
1232 | + if ($member->house_disp == HOUSE_TYPE_COMMONS) { |
|
1233 | + $line .= 'this MP'; |
|
1234 | + } |
|
1235 | + elseif ($member->house_disp == HOUSE_TYPE_LORDS) { |
|
1236 | + $line .= 'this peer'; |
|
1237 | + } |
|
1238 | + elseif ($member->house_disp == HOUSE_TYPE_NI) { |
|
1239 | + $line .= 'this MLA'; |
|
1240 | + } |
|
1241 | + elseif ($member->house_disp == HOUSE_TYPE_SCOTLAND) { |
|
1242 | + $line .= 'this MSP'; |
|
1243 | + } |
|
1244 | + elseif ($member->house_disp == HOUSE_TYPE_ROYAL) { |
|
1245 | + $line .= $member->full_name(); |
|
1246 | + } |
|
1149 | 1247 | if ($has_email_alerts) { |
1150 | 1248 | $line .= ' — <a href="' . WEBPATH . 'alert/?pid='.$member->person_id().'">email me updates on '. $member->full_name(). '’s activity</a>'; |
1151 | 1249 | } |
@@ -1169,10 +1267,12 @@ discard block |
||
1169 | 1267 | |
1170 | 1268 | function display_stats_line($category, $blurb, $type, $inwhat, $afterstuff, $extra_info, $minister = false, $Lminister = false) { |
1171 | 1269 | $return = false; |
1172 | - if (isset($extra_info[$category])) |
|
1173 | - $return = display_stats_line_house(HOUSE_TYPE_COMMONS, $category, $blurb, $type, $inwhat, $extra_info, $minister, $afterstuff); |
|
1174 | - if (isset($extra_info["L$category"])) |
|
1175 | - $return = display_stats_line_house(HOUSE_TYPE_LORDS, "L$category", $blurb, $type, $inwhat, $extra_info, $Lminister, $afterstuff); |
|
1270 | + if (isset($extra_info[$category])) { |
|
1271 | + $return = display_stats_line_house(HOUSE_TYPE_COMMONS, $category, $blurb, $type, $inwhat, $extra_info, $minister, $afterstuff); |
|
1272 | + } |
|
1273 | + if (isset($extra_info["L$category"])) { |
|
1274 | + $return = display_stats_line_house(HOUSE_TYPE_LORDS, "L$category", $blurb, $type, $inwhat, $extra_info, $Lminister, $afterstuff); |
|
1275 | + } |
|
1176 | 1276 | return $return; |
1177 | 1277 | } |
1178 | 1278 | |
@@ -1184,16 +1284,22 @@ discard block |
||
1184 | 1284 | $inwhat = preg_replace('#<\/a>#', '', $inwhat); |
1185 | 1285 | } |
1186 | 1286 | } |
1187 | - if ($house==HOUSE_TYPE_LORDS) $inwhat = str_replace('MP', 'Lord', $inwhat); |
|
1287 | + if ($house==HOUSE_TYPE_LORDS) { |
|
1288 | + $inwhat = str_replace('MP', 'Lord', $inwhat); |
|
1289 | + } |
|
1188 | 1290 | $line = $blurb; |
1189 | 1291 | $line .= '<strong>' . $extra_info[$category]; |
1190 | - if ($type) $line .= ' ' . make_plural($type, $extra_info[$category]); |
|
1292 | + if ($type) { |
|
1293 | + $line .= ' ' . make_plural($type, $extra_info[$category]); |
|
1294 | + } |
|
1191 | 1295 | $line .= '</strong>'; |
1192 | 1296 | $line .= $inwhat; |
1193 | 1297 | if ($minister===2) { |
1194 | 1298 | $line .= ' — Speakers/ deputy speakers do not ask written questions'; |
1195 | - } elseif ($minister) |
|
1196 | - $line .= ' — Ministers do not ask written questions'; |
|
1299 | + } |
|
1300 | + elseif ($minister) { |
|
1301 | + $line .= ' — Ministers do not ask written questions'; |
|
1302 | + } |
|
1197 | 1303 | else { |
1198 | 1304 | $type = ($house==HOUSE_TYPE_COMMONS?'MP':($house==HOUSE_TYPE_LORDS?'Lord':'MLA')); |
1199 | 1305 | if (!get_http_var('rem') && isset($extra_info[$category . '_quintile'])) { |
@@ -1201,20 +1307,26 @@ discard block |
||
1201 | 1307 | $q = $extra_info[$category . '_quintile']; |
1202 | 1308 | if ($q == 0) { |
1203 | 1309 | $line .= 'well above average'; |
1204 | - } elseif ($q == 1) { |
|
1310 | + } |
|
1311 | + elseif ($q == 1) { |
|
1205 | 1312 | $line .= 'above average'; |
1206 | - } elseif ($q == 2) { |
|
1313 | + } |
|
1314 | + elseif ($q == 2) { |
|
1207 | 1315 | $line .= 'average'; |
1208 | - } elseif ($q == 3) { |
|
1316 | + } |
|
1317 | + elseif ($q == 3) { |
|
1209 | 1318 | $line .= 'below average'; |
1210 | - } elseif ($q == 4) { |
|
1319 | + } |
|
1320 | + elseif ($q == 4) { |
|
1211 | 1321 | $line .= 'well below average'; |
1212 | - } else { |
|
1322 | + } |
|
1323 | + else { |
|
1213 | 1324 | $line .= '[Impossible quintile!]'; |
1214 | 1325 | } |
1215 | 1326 | $line .= ' amongst '; |
1216 | 1327 | $line .= $type . 's'; |
1217 | - } elseif (!get_http_var('rem') && isset($extra_info[$category . '_rank'])) { |
|
1328 | + } |
|
1329 | + elseif (!get_http_var('rem') && isset($extra_info[$category . '_rank'])) { |
|
1218 | 1330 | $line .= ' — '; |
1219 | 1331 | #if (isset($extra_info[$category . '_rank_joint'])) |
1220 | 1332 | # print 'joint '; |
@@ -1229,15 +1341,26 @@ discard block |
||
1229 | 1341 | function display_writetothem_numbers($year, $extra_info) { |
1230 | 1342 | if (isset($extra_info["writetothem_responsiveness_notes_$year"])) { |
1231 | 1343 | return '<li>Responsiveness to messages sent via <a href="https://www.writetothem.com/stats/' . $year . '/mps">WriteToThem.com</a> in ' . $year . ': ' . $extra_info["writetothem_responsiveness_notes_$year"] . '.</li>'; |
1232 | - } elseif (isset($extra_info["writetothem_responsiveness_mean_$year"])) { |
|
1344 | + } |
|
1345 | + elseif (isset($extra_info["writetothem_responsiveness_mean_$year"])) { |
|
1233 | 1346 | $mean = $extra_info["writetothem_responsiveness_mean_$year"]; |
1234 | 1347 | |
1235 | 1348 | $a = $extra_info["writetothem_responsiveness_fuzzy_response_description_$year"]; |
1236 | - if ($a == 'very low') $a = 'a very low'; |
|
1237 | - if ($a == 'low') $a = 'a low'; |
|
1238 | - if ($a == 'medium') $a = 'a medium'; |
|
1239 | - if ($a == 'high') $a = 'a high'; |
|
1240 | - if ($a == 'very high') $a = 'a very high'; |
|
1349 | + if ($a == 'very low') { |
|
1350 | + $a = 'a very low'; |
|
1351 | + } |
|
1352 | + if ($a == 'low') { |
|
1353 | + $a = 'a low'; |
|
1354 | + } |
|
1355 | + if ($a == 'medium') { |
|
1356 | + $a = 'a medium'; |
|
1357 | + } |
|
1358 | + if ($a == 'high') { |
|
1359 | + $a = 'a high'; |
|
1360 | + } |
|
1361 | + if ($a == 'very high') { |
|
1362 | + $a = 'a very high'; |
|
1363 | + } |
|
1241 | 1364 | $extra_info["writetothem_responsiveness_fuzzy_response_description_$year"] = $a; |
1242 | 1365 | |
1243 | 1366 | return display_stats_line("writetothem_responsiveness_fuzzy_response_description_$year", 'Replied within 2 or 3 weeks to <a href="https://www.writetothem.com/stats/'.$year.'/mps" title="From WriteToThem.com">', "", "</a> <!-- Mean: " . $mean . " --> number of messages sent via WriteToThem.com during ".$year.", according to constituents", "", $extra_info); |
@@ -1278,9 +1401,11 @@ discard block |
||
1278 | 1401 | $constituencies = MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($pc); |
1279 | 1402 | if ($constituencies == 'CONNECTION_TIMED_OUT') { |
1280 | 1403 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, we couldn’t check your postcode right now, as our postcode lookup server is under quite a lot of load.'); |
1281 | - } elseif (!$constituencies) { |
|
1404 | + } |
|
1405 | + elseif (!$constituencies) { |
|
1282 | 1406 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, ' . htmlentities($pc) . ' isn’t a known postcode'); |
1283 | - } elseif (!isset($constituencies[$area_type])) { |
|
1407 | + } |
|
1408 | + elseif (!isset($constituencies[$area_type])) { |
|
1284 | 1409 | throw new MySociety\TheyWorkForYou\MemberException(htmlentities($pc) . ' does not appear to be a valid postcode'); |
1285 | 1410 | } |
1286 | 1411 | global $PAGE; |
@@ -1305,15 +1430,19 @@ discard block |
||
1305 | 1430 | $cons = $q->field($i, 'constituency'); |
1306 | 1431 | if ($house == HOUSE_TYPE_COMMONS) { |
1307 | 1432 | continue; |
1308 | - } elseif ($house == HOUSE_TYPE_NI) { |
|
1433 | + } |
|
1434 | + elseif ($house == HOUSE_TYPE_NI) { |
|
1309 | 1435 | $mreg[] = $q->row($i); |
1310 | - } elseif ($house == HOUSE_TYPE_SCOTLAND) { |
|
1436 | + } |
|
1437 | + elseif ($house == HOUSE_TYPE_SCOTLAND) { |
|
1311 | 1438 | if ($cons == $constituencies['SPC']) { |
1312 | 1439 | $mcon = $q->row($i); |
1313 | - } elseif ($cons == $constituencies['SPE']) { |
|
1440 | + } |
|
1441 | + elseif ($cons == $constituencies['SPE']) { |
|
1314 | 1442 | $mreg[] = $q->row($i); |
1315 | 1443 | } |
1316 | - } else { |
|
1444 | + } |
|
1445 | + else { |
|
1317 | 1446 | throw new MySociety\TheyWorkForYou\MemberException('Odd result returned!' . $house); |
1318 | 1447 | } |
1319 | 1448 | } |
@@ -1323,16 +1452,19 @@ discard block |
||
1323 | 1452 | $data['members_statement'] .= '<p>Your <strong>constituency MSP</strong> is <a href="/msp/?p=' . $mcon['person_id'] . '">'; |
1324 | 1453 | $data['members_statement'] .= $mcon['given_name'] . ' ' . $mcon['family_name'] . '</a>, MSP for ' . $mcon['constituency']; |
1325 | 1454 | $data['members_statement'] .= '.</p> <p>Your <strong>' . $constituencies['SPE'] . ' region MSPs</strong> are:</p>'; |
1326 | - } else { |
|
1455 | + } |
|
1456 | + else { |
|
1327 | 1457 | $data['members_statement'] = '<p>You had one constituency MSP (Member of the Scottish Parliament) and multiple region MSPs.</p>'; |
1328 | 1458 | $data['members_statement'] .= '<p>Your <strong>constituency MSP</strong> was <a href="/msp/?p=' . $mcon['person_id'] . '">'; |
1329 | 1459 | $data['members_statement'] .= $mcon['given_name'] . ' ' . $mcon['family_name'] . '</a>, MSP for ' . $mcon['constituency']; |
1330 | 1460 | $data['members_statement'] .= '.</p> <p>Your <strong>' . $constituencies['SPE'] . ' region MSPs</strong> were:</p>'; |
1331 | 1461 | } |
1332 | - } else { |
|
1462 | + } |
|
1463 | + else { |
|
1333 | 1464 | if ($current) { |
1334 | 1465 | $data['members_statement'] = '<p>You have multiple MLAs (Members of the Legislative Assembly) who represent you in ' . $constituencies['NIE'] . '. They are:</p>'; |
1335 | - } else { |
|
1466 | + } |
|
1467 | + else { |
|
1336 | 1468 | $data['members_statement'] = '<p>You had multiple MLAs (Members of the Legislative Assembly) who represented you in ' . $constituencies['NIE'] . '. They were:</p>'; |
1337 | 1469 | } |
1338 | 1470 | } |