@@ -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); |
@@ -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 \URL('mlas'); |
|
738 | - break; |
|
739 | - case 'msp': |
|
740 | - $rep = 'MSP'; |
|
741 | - $SEARCHURL = '/postcode/'; |
|
742 | - $MPSURL = new \URL('msps'); |
|
743 | - break; |
|
744 | - case 'peer': |
|
745 | - $rep = 'Lord'; |
|
746 | - $SEARCHURL = ''; |
|
747 | - $MPSURL = new \URL('peers'); |
|
748 | - break; |
|
749 | - default: |
|
750 | - $rep = 'MP'; |
|
751 | - $SEARCHURL = new \URL('mp'); |
|
752 | - $SEARCHURL = $SEARCHURL->generate(); |
|
753 | - $MPSURL = new \URL('mps'); |
|
734 | + case 'mla': |
|
735 | + $rep = 'MLA'; |
|
736 | + $SEARCHURL = '/postcode/'; |
|
737 | + $MPSURL = new \URL('mlas'); |
|
738 | + break; |
|
739 | + case 'msp': |
|
740 | + $rep = 'MSP'; |
|
741 | + $SEARCHURL = '/postcode/'; |
|
742 | + $MPSURL = new \URL('msps'); |
|
743 | + break; |
|
744 | + case 'peer': |
|
745 | + $rep = 'Lord'; |
|
746 | + $SEARCHURL = ''; |
|
747 | + $MPSURL = new \URL('peers'); |
|
748 | + break; |
|
749 | + default: |
|
750 | + $rep = 'MP'; |
|
751 | + $SEARCHURL = new \URL('mp'); |
|
752 | + $SEARCHURL = $SEARCHURL->generate(); |
|
753 | + $MPSURL = new \URL('mps'); |
|
754 | 754 | } |
755 | 755 | |
756 | 756 | $data = array( |
@@ -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 |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | } |
119 | 119 | if ($pid) { |
120 | 120 | $URL = new 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 \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 \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 | } |
@@ -77,6 +77,9 @@ discard block |
||
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | +/** |
|
81 | + * @param MySQLQuery $q |
|
82 | + */ |
|
80 | 83 | function _api_getPerson_output($q, $flatten=false) { |
81 | 84 | $output = array(); |
82 | 85 | $last_mod = 0; |
@@ -95,10 +98,16 @@ discard block |
||
95 | 98 | api_output($output, $last_mod); |
96 | 99 | } |
97 | 100 | |
101 | +/** |
|
102 | + * @param integer $house |
|
103 | + */ |
|
98 | 104 | function api_getPerson_constituency($constituency, $house) { |
99 | 105 | _api_getPerson_constituency(array($constituency), $house); |
100 | 106 | } |
101 | 107 | |
108 | +/** |
|
109 | + * @param integer $house |
|
110 | + */ |
|
102 | 111 | function api_getPerson_postcode($pc, $house) { |
103 | 112 | $pc = preg_replace('#[^a-z0-9 ]#i', '', $pc); |
104 | 113 | $types = array(); |
@@ -17,7 +17,7 @@ |
||
17 | 17 | <?php |
18 | 18 | } |
19 | 19 | |
20 | -function _api_getPerson_row($row, $has_party=FALSE) { |
|
20 | +function _api_getPerson_row($row, $has_party=false) { |
|
21 | 21 | global $parties; |
22 | 22 | $row['full_name'] = member_full_name($row['house'], $row['title'], $row['given_name'], |
23 | 23 | $row['family_name'], $row['lordofname']); |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | <?php |
18 | 18 | } |
19 | 19 | |
20 | -function _api_getPerson_row($row, $has_party=FALSE) { |
|
20 | +function _api_getPerson_row($row, $has_party = FALSE) { |
|
21 | 21 | global $parties; |
22 | 22 | $row['full_name'] = member_full_name($row['house'], $row['title'], $row['given_name'], |
23 | 23 | $row['family_name'], $row['lordofname']); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | } |
31 | 31 | if ($has_party && isset($parties[$row['party']])) |
32 | 32 | $row['party'] = $parties[$row['party']]; |
33 | - list($image,$sz) = MySociety\TheyWorkForYou\Utility\Member::findMemberImage($row['person_id']); |
|
33 | + list($image, $sz) = MySociety\TheyWorkForYou\Utility\Member::findMemberImage($row['person_id']); |
|
34 | 34 | if ($image) { |
35 | 35 | list($width, $height) = getimagesize(str_replace(IMAGEPATH, BASEDIR . '/images/', $image)); |
36 | 36 | $row['image'] = $image; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | # Ministerialships and Select Committees |
44 | 44 | $db = new ParlDB; |
45 | 45 | $q = $db->query('SELECT * FROM moffice WHERE to_date="9999-12-31" and person=' . $row['person_id'] . ' ORDER BY from_date DESC'); |
46 | - for ($i=0; $i<$q->rows(); $i++) { |
|
46 | + for ($i = 0; $i < $q->rows(); $i++) { |
|
47 | 47 | $row['office'][] = $q->row($i); |
48 | 48 | } |
49 | 49 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | return $row; |
56 | 56 | } |
57 | 57 | |
58 | -function api_getPerson_id($id, $house='') { |
|
58 | +function api_getPerson_id($id, $house = '') { |
|
59 | 59 | $db = new ParlDB; |
60 | 60 | $params = array( |
61 | 61 | ':person_id' => $id |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | -function _api_getPerson_output($q, $flatten=false) { |
|
80 | +function _api_getPerson_output($q, $flatten = false) { |
|
81 | 81 | $output = array(); |
82 | 82 | $last_mod = 0; |
83 | - for ($i=0; $i<$q->rows(); $i++) { |
|
83 | + for ($i = 0; $i < $q->rows(); $i++) { |
|
84 | 84 | $house = $q->field($i, 'house'); |
85 | 85 | $out = _api_getPerson_row($q->row($i), $house == HOUSE_TYPE_ROYAL ? false : true); |
86 | 86 | $output[] = $out; |
@@ -28,8 +28,9 @@ discard block |
||
28 | 28 | $URL = new URL('mp'); |
29 | 29 | $row['url'] = $URL->generate('none') . make_member_url($row['full_name'], $row['constituency'], $row['house'], $row['person_id']); |
30 | 30 | } |
31 | - if ($has_party && isset($parties[$row['party']])) |
|
32 | - $row['party'] = $parties[$row['party']]; |
|
31 | + if ($has_party && isset($parties[$row['party']])) { |
|
32 | + $row['party'] = $parties[$row['party']]; |
|
33 | + } |
|
33 | 34 | list($image,$sz) = MySociety\TheyWorkForYou\Utility\Member::findMemberImage($row['person_id']); |
34 | 35 | if ($image) { |
35 | 36 | list($width, $height) = getimagesize(str_replace(IMAGEPATH, BASEDIR . '/images/', $image)); |
@@ -49,7 +50,9 @@ discard block |
||
49 | 50 | } |
50 | 51 | |
51 | 52 | foreach ($row as $k => $r) { |
52 | - if (is_string($r)) $row[$k] = html_entity_decode($r); |
|
53 | + if (is_string($r)) { |
|
54 | + $row[$k] = html_entity_decode($r); |
|
55 | + } |
|
53 | 56 | } |
54 | 57 | |
55 | 58 | return $row; |
@@ -72,7 +75,8 @@ discard block |
||
72 | 75 | order by left_house desc", $params); |
73 | 76 | if ($q->rows()) { |
74 | 77 | _api_getPerson_output($q); |
75 | - } else { |
|
78 | + } |
|
79 | + else { |
|
76 | 80 | api_error('Unknown person ID'); |
77 | 81 | } |
78 | 82 | } |
@@ -85,8 +89,9 @@ discard block |
||
85 | 89 | $out = _api_getPerson_row($q->row($i), $house == HOUSE_TYPE_ROYAL ? false : true); |
86 | 90 | $output[] = $out; |
87 | 91 | $time = strtotime($q->field($i, 'lastupdate')); |
88 | - if ($time > $last_mod) |
|
89 | - $last_mod = $time; |
|
92 | + if ($time > $last_mod) { |
|
93 | + $last_mod = $time; |
|
94 | + } |
|
90 | 95 | } |
91 | 96 | # Only one MP, not an array |
92 | 97 | if ($flatten && count($output) == 1 && $house == HOUSE_TYPE_COMMONS) { |
@@ -104,24 +109,30 @@ discard block |
||
104 | 109 | $types = array(); |
105 | 110 | if ($house == HOUSE_TYPE_NI) { |
106 | 111 | $types = array('NIE'); |
107 | - } elseif ($house == HOUSE_TYPE_SCOTLAND) { |
|
112 | + } |
|
113 | + elseif ($house == HOUSE_TYPE_SCOTLAND) { |
|
108 | 114 | $types = array('SPC', 'SPE'); |
109 | 115 | } |
110 | 116 | if (validate_postcode($pc)) { |
111 | 117 | $constituencies = MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($pc); |
112 | 118 | if ($constituencies == 'CONNECTION_TIMED_OUT') { |
113 | 119 | api_error('Connection timed out'); |
114 | - } elseif ($types && isset($constituencies[$types[0]])) { |
|
120 | + } |
|
121 | + elseif ($types && isset($constituencies[$types[0]])) { |
|
115 | 122 | $constituencies = array_map(function($c) use ($constituencies) { return $constituencies[$c]; }, $types); |
116 | 123 | _api_getPerson_constituency($constituencies, $house); |
117 | - } elseif ($types && isset($constituencies['WMC'])) { |
|
124 | + } |
|
125 | + elseif ($types && isset($constituencies['WMC'])) { |
|
118 | 126 | api_error('Postcode not in correct region'); |
119 | - } elseif (isset($constituencies['WMC'])) { |
|
127 | + } |
|
128 | + elseif (isset($constituencies['WMC'])) { |
|
120 | 129 | _api_getPerson_constituency(array($constituencies['WMC']), $house); |
121 | - } else { |
|
130 | + } |
|
131 | + else { |
|
122 | 132 | api_error('Unknown postcode'); |
123 | 133 | } |
124 | - } else { |
|
134 | + } |
|
135 | + else { |
|
125 | 136 | api_error('Invalid postcode'); |
126 | 137 | } |
127 | 138 | } |
@@ -134,13 +145,18 @@ discard block |
||
134 | 145 | |
135 | 146 | $cons = array(); |
136 | 147 | foreach ($constituencies as $constituency) { |
137 | - if ($constituency == '') continue; |
|
138 | - if ($constituency == 'Orkney ') |
|
139 | - $constituency = 'Orkney & Shetland'; |
|
148 | + if ($constituency == '') { |
|
149 | + continue; |
|
150 | + } |
|
151 | + if ($constituency == 'Orkney ') { |
|
152 | + $constituency = 'Orkney & Shetland'; |
|
153 | + } |
|
140 | 154 | |
141 | 155 | if ($house == HOUSE_TYPE_COMMONS) { |
142 | 156 | $normalised = MySociety\TheyWorkForYou\Utility\Constituencies::normaliseConstituencyName($constituency); |
143 | - if ($normalised) $constituency = $normalised; |
|
157 | + if ($normalised) { |
|
158 | + $constituency = $normalised; |
|
159 | + } |
|
144 | 160 | } |
145 | 161 | |
146 | 162 | $cons[] = $constituency; |
@@ -167,7 +183,8 @@ discard block |
||
167 | 183 | |
168 | 184 | if ($q->rows > 0) { |
169 | 185 | _api_getPerson_output($q, true); |
170 | - } else { |
|
186 | + } |
|
187 | + else { |
|
171 | 188 | api_error('Unknown constituency, or no results for that constituency'); |
172 | 189 | } |
173 | 190 | } |
@@ -318,6 +318,9 @@ discard block |
||
318 | 318 | $format_date_months = array('', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); |
319 | 319 | $format_date_months_short = array('', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); |
320 | 320 | |
321 | +/** |
|
322 | + * @param string $format |
|
323 | + */ |
|
321 | 324 | function format_date($date, $format) { |
322 | 325 | global $format_date_months, $format_date_months_short; |
323 | 326 | // Pass it a date (YYYY-MM-DD) and a |
@@ -342,6 +345,9 @@ discard block |
||
342 | 345 | } |
343 | 346 | |
344 | 347 | |
348 | +/** |
|
349 | + * @param string $format |
|
350 | + */ |
|
345 | 351 | function format_time($time, $format) { |
346 | 352 | // Pass it a time (HH:MM:SS) and a |
347 | 353 | // PHP date format string (eg, "H:i") |
@@ -486,6 +492,7 @@ discard block |
||
486 | 492 | |
487 | 493 | /** |
488 | 494 | * Filters user input to remove unwanted HTML tags etc |
495 | + * @param string $filter_type |
|
489 | 496 | */ |
490 | 497 | function filter_user_input($text, $filter_type) { |
491 | 498 | // We use this to filter any major user input, especially comments. |
@@ -735,12 +742,18 @@ discard block |
||
735 | 742 | /* verp_envelope_sender RECIPIENT |
736 | 743 | * Construct a VERP envelope sender for an email to RECIPIENT |
737 | 744 | */ |
745 | +/** |
|
746 | + * @return string|null |
|
747 | + */ |
|
738 | 748 | function twfy_verp_envelope_sender($recipient) { |
739 | 749 | $envelope_sender = verp_envelope_sender($recipient, 'twfy', EMAILDOMAIN); |
740 | 750 | |
741 | 751 | return $envelope_sender; |
742 | 752 | } |
743 | 753 | |
754 | +/** |
|
755 | + * @param string $message |
|
756 | + */ |
|
744 | 757 | function send_email($to, $subject, $message, $bulk = false, $from = '', $want_bounces = false) { |
745 | 758 | // Use this rather than PHP's mail() direct, so we can make alterations |
746 | 759 | // easily to all the emails we send out from the site. |
@@ -799,6 +812,9 @@ discard block |
||
799 | 812 | } |
800 | 813 | |
801 | 814 | // Call this with a key name to get a COOKIE variable. |
815 | +/** |
|
816 | + * @param string $name |
|
817 | + */ |
|
802 | 818 | function get_cookie_var($name, $default='') { |
803 | 819 | if (array_key_exists($name, $_COOKIE)) { |
804 | 820 | return clean_var($_COOKIE[$name]); |
@@ -1039,6 +1055,10 @@ discard block |
||
1039 | 1055 | } |
1040 | 1056 | } |
1041 | 1057 | |
1058 | +/** |
|
1059 | + * @param integer $major |
|
1060 | + * @param URL $LISTURL |
|
1061 | + */ |
|
1042 | 1062 | function _major_summary_title($major, $data, $LISTURL, $daytext) { |
1043 | 1063 | global $hansardmajors; |
1044 | 1064 | |
@@ -1088,6 +1108,9 @@ discard block |
||
1088 | 1108 | return $return; |
1089 | 1109 | } |
1090 | 1110 | |
1111 | +/** |
|
1112 | + * @param string|null $url |
|
1113 | + */ |
|
1091 | 1114 | function redirect($url) { |
1092 | 1115 | if (defined('TESTING')) { |
1093 | 1116 | print "Location: $url"; |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | # Ignore errors we've asked to ignore |
68 | 68 | if (error_reporting()==0) return; |
69 | 69 | |
70 | - // define an assoc array of error string |
|
71 | - // in reality the only entries we should |
|
72 | - // consider are E_WARNING, E_NOTICE, E_USER_ERROR, |
|
73 | - // E_USER_WARNING and E_USER_NOTICE |
|
74 | - # Commented out are ones that a user function cannot handle. |
|
70 | + // define an assoc array of error string |
|
71 | + // in reality the only entries we should |
|
72 | + // consider are E_WARNING, E_NOTICE, E_USER_ERROR, |
|
73 | + // E_USER_WARNING and E_USER_NOTICE |
|
74 | + # Commented out are ones that a user function cannot handle. |
|
75 | 75 | $errortype = array ( |
76 | 76 | #E_ERROR => "Error", |
77 | 77 | E_WARNING => "Warning", |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | // pretty prints the backtrace, copied from http://uk.php.net/manual/en/function.debug-backtrace.php |
201 | 201 | function adodb_backtrace($print=true) |
202 | 202 | { |
203 | - $s = ''; |
|
204 | - if (PHPVERSION() >= 4.3) { |
|
203 | + $s = ''; |
|
204 | + if (PHPVERSION() >= 4.3) { |
|
205 | 205 | |
206 | 206 | $MAXSTRLEN = 64; |
207 | 207 | |
@@ -209,33 +209,33 @@ discard block |
||
209 | 209 | array_shift($traceArr); |
210 | 210 | $tabs = sizeof($traceArr)-1; |
211 | 211 | foreach ($traceArr as $arr) { |
212 | - for ($i=0; $i < $tabs; $i++) $s .= ' '; |
|
213 | - $tabs -= 1; |
|
214 | - if (isset($arr['class'])) $s .= $arr['class'].'.'; |
|
215 | - $args = array(); |
|
216 | - if (isset($arr['args'])) foreach ($arr['args'] as $v) { |
|
212 | + for ($i=0; $i < $tabs; $i++) $s .= ' '; |
|
213 | + $tabs -= 1; |
|
214 | + if (isset($arr['class'])) $s .= $arr['class'].'.'; |
|
215 | + $args = array(); |
|
216 | + if (isset($arr['args'])) foreach ($arr['args'] as $v) { |
|
217 | 217 | if (is_null($v)) $args[] = 'null'; |
218 | 218 | elseif (is_array($v)) $args[] = 'Array['.sizeof($v).']'; |
219 | 219 | elseif (is_object($v)) $args[] = 'Object:'.get_class($v); |
220 | 220 | elseif (is_bool($v)) $args[] = $v ? 'true' : 'false'; |
221 | 221 | else { |
222 | - $v = (string) @$v; |
|
223 | - $str = _htmlspecialchars(substr($v,0,$MAXSTRLEN)); |
|
224 | - if (strlen($v) > $MAXSTRLEN) $str .= '...'; |
|
225 | - $args[] = $str; |
|
222 | + $v = (string) @$v; |
|
223 | + $str = _htmlspecialchars(substr($v,0,$MAXSTRLEN)); |
|
224 | + if (strlen($v) > $MAXSTRLEN) $str .= '...'; |
|
225 | + $args[] = $str; |
|
226 | 226 | } |
227 | - } |
|
227 | + } |
|
228 | 228 | |
229 | - $s .= $arr['function'].'('.implode(', ',$args).')'; |
|
230 | - // $s .= sprintf("</font><font color=#808080 size=-1> # line %4d,". |
|
231 | - // " file: <a href=\"file:/%s\">%s</a></font>", |
|
232 | - // $arr['line'],$arr['file'],$arr['file']); |
|
233 | - $s .= "\n"; |
|
229 | + $s .= $arr['function'].'('.implode(', ',$args).')'; |
|
230 | + // $s .= sprintf("</font><font color=#808080 size=-1> # line %4d,". |
|
231 | + // " file: <a href=\"file:/%s\">%s</a></font>", |
|
232 | + // $arr['line'],$arr['file'],$arr['file']); |
|
233 | + $s .= "\n"; |
|
234 | 234 | } |
235 | 235 | if ($print) print $s; |
236 | - } |
|
236 | + } |
|
237 | 237 | |
238 | - return $s; |
|
238 | + return $s; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | // Far from foolproof, but better than nothing. |
@@ -567,14 +567,14 @@ discard block |
||
567 | 567 | //$tbl["»"] = "»"; |
568 | 568 | //$tbl["«"] = "«"; |
569 | 569 | |
570 | - // lib_filter will replace unmatched < and > with entities so |
|
571 | - // we abuse strtr's only replace once behaviour to not double |
|
572 | - // encode them. May not be robust. |
|
573 | - // This does mean if anyone actually wants to put > or < |
|
574 | - // in a comment they can't but that's a lot less likely than |
|
575 | - // < or > for less than and greater than. |
|
576 | - $tbl['<'] = "<"; |
|
577 | - $tbl['>'] = ">"; |
|
570 | + // lib_filter will replace unmatched < and > with entities so |
|
571 | + // we abuse strtr's only replace once behaviour to not double |
|
572 | + // encode them. May not be robust. |
|
573 | + // This does mean if anyone actually wants to put > or < |
|
574 | + // in a comment they can't but that's a lot less likely than |
|
575 | + // < or > for less than and greater than. |
|
576 | + $tbl['<'] = "<"; |
|
577 | + $tbl['>'] = ">"; |
|
578 | 578 | |
579 | 579 | // Don't want to encode these things |
580 | 580 | unset ($tbl["<"]); |
@@ -764,16 +764,16 @@ discard block |
||
764 | 764 | if (!$from) $from = CONTACTEMAIL; |
765 | 765 | |
766 | 766 | $headers = |
767 | - "From: TheyWorkForYou <$from>\r\n" . |
|
768 | - "Content-Type: text/plain; charset=utf-8\r\n" . |
|
769 | - "MIME-Version: 1.0\r\n" . |
|
770 | - "Content-Transfer-Encoding: 8bit\r\n" . |
|
771 | - ($bulk ? "Precedence: bulk\r\nAuto-Submitted: auto-generated\r\n" : "" ). |
|
772 | - "X-Mailer: PHP/" . phpversion(); |
|
767 | + "From: TheyWorkForYou <$from>\r\n" . |
|
768 | + "Content-Type: text/plain; charset=utf-8\r\n" . |
|
769 | + "MIME-Version: 1.0\r\n" . |
|
770 | + "Content-Transfer-Encoding: 8bit\r\n" . |
|
771 | + ($bulk ? "Precedence: bulk\r\nAuto-Submitted: auto-generated\r\n" : "" ). |
|
772 | + "X-Mailer: PHP/" . phpversion(); |
|
773 | 773 | twfy_debug('EMAIL', "Sending email to $to with subject of '$subject'"); |
774 | 774 | |
775 | 775 | if ($want_bounces) { |
776 | - $envelope_sender = twfy_verp_envelope_sender($to); |
|
776 | + $envelope_sender = twfy_verp_envelope_sender($to); |
|
777 | 777 | $success = mail ($to, $subject, $message, $headers, '-f ' . $envelope_sender); |
778 | 778 | } else { |
779 | 779 | $success = mail ($to, $subject, $message, $headers); |
@@ -1063,7 +1063,7 @@ discard block |
||
1063 | 1063 | |
1064 | 1064 | $return = '<h4>'; |
1065 | 1065 | if (isset($daytext[$major])) { |
1066 | - $return .= $daytext[$major] . ' '; |
|
1066 | + $return .= $daytext[$major] . ' '; |
|
1067 | 1067 | } |
1068 | 1068 | |
1069 | 1069 | $return .= '<a href="'; |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | return $string; |
888 | 888 | } |
889 | 889 | |
890 | -function make_member_url($name, $const = '', $house = HOUSE_TYPE_COMMONS, $pid = NULL) { |
|
890 | +function make_member_url($name, $const = '', $house = HOUSE_TYPE_COMMONS, $pid = null) { |
|
891 | 891 | |
892 | 892 | // Case for Elizabeth II |
893 | 893 | if ($house == HOUSE_TYPE_ROYAL) |
@@ -903,7 +903,7 @@ discard block |
||
903 | 903 | $out = ''; |
904 | 904 | |
905 | 905 | // Insert the Person ID if known. |
906 | - if ($pid !== NULL) |
|
906 | + if ($pid !== null) |
|
907 | 907 | { |
908 | 908 | $out .= $pid . '/'; |
909 | 909 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | # Pass it a brief header word and some debug text and it'll be output. |
12 | 12 | # If TEXT is an array, call the user function, assuming it's a class. |
13 | -function twfy_debug($header, $text="") { |
|
13 | +function twfy_debug($header, $text = "") { |
|
14 | 14 | |
15 | 15 | // We set ?DEBUGTAG=n in the URL. |
16 | 16 | // (DEBUGTAG is set in config.php). |
@@ -27,10 +27,10 @@ discard block |
||
27 | 27 | if ($debug_level != '') { |
28 | 28 | |
29 | 29 | // Set which level shows which types of debug info. |
30 | - $levels = array ( |
|
31 | - 1 => array ('THEUSER', 'TIME', 'SQLERROR', 'PAGE', 'TEMPLATE', 'SEARCH', 'ALERTS', 'MP'), |
|
32 | - 2 => array ('SQL', 'EMAIL', 'WIKIPEDIA', 'hansardlist', 'debatelist', 'wranslist', 'whalllist'), |
|
33 | - 3 => array ('SQLRESULT') |
|
30 | + $levels = array( |
|
31 | + 1 => array('THEUSER', 'TIME', 'SQLERROR', 'PAGE', 'TEMPLATE', 'SEARCH', 'ALERTS', 'MP'), |
|
32 | + 2 => array('SQL', 'EMAIL', 'WIKIPEDIA', 'hansardlist', 'debatelist', 'wranslist', 'whalllist'), |
|
33 | + 3 => array('SQLRESULT') |
|
34 | 34 | // Higher than this: 'DATA', etc. |
35 | 35 | ); |
36 | 36 | |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | for ($n = 1; $n <= $max_level_to_show; $n++) { |
47 | - $allowed_headers = array_merge ($allowed_headers, $levels[$n] ); |
|
47 | + $allowed_headers = array_merge($allowed_headers, $levels[$n]); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | // If we can show this header, then, er, show it. |
51 | - if ( in_array($header, $allowed_headers) || $debug_level >= 4) { |
|
51 | + if (in_array($header, $allowed_headers) || $debug_level >= 4) { |
|
52 | 52 | if (is_array($text)) $text = call_user_func($text); |
53 | 53 | print "<p><span style=\"color:#039;\"><strong>$header</strong></span> $text</p>\n"; |
54 | 54 | } |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | global $PAGE; |
66 | 66 | |
67 | 67 | # Ignore errors we've asked to ignore |
68 | - if (error_reporting()==0) return; |
|
68 | + if (error_reporting() == 0) return; |
|
69 | 69 | |
70 | 70 | // define an assoc array of error string |
71 | 71 | // in reality the only entries we should |
72 | 72 | // consider are E_WARNING, E_NOTICE, E_USER_ERROR, |
73 | 73 | // E_USER_WARNING and E_USER_NOTICE |
74 | 74 | # Commented out are ones that a user function cannot handle. |
75 | - $errortype = array ( |
|
75 | + $errortype = array( |
|
76 | 76 | #E_ERROR => "Error", |
77 | 77 | E_WARNING => "Warning", |
78 | 78 | #E_PARSE => "Parsing Error", |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | $source = file($filename); |
132 | 132 | $err .= "\nSource:\n\n"; |
133 | 133 | // Show the line, plus prev and next, with line numbers. |
134 | - $err .= $linenum-2 . " " . $source[$linenum-3]; |
|
135 | - $err .= $linenum-1 . " " . $source[$linenum-2]; |
|
136 | - $err .= $linenum . " " . $source[$linenum-1]; |
|
137 | - $err .= $linenum+1 . " " . $source[$linenum]; |
|
138 | - $err .= $linenum+2 . " " . $source[$linenum+1]; |
|
134 | + $err .= $linenum - 2 . " " . $source[$linenum - 3]; |
|
135 | + $err .= $linenum - 1 . " " . $source[$linenum - 2]; |
|
136 | + $err .= $linenum . " " . $source[$linenum - 1]; |
|
137 | + $err .= $linenum + 1 . " " . $source[$linenum]; |
|
138 | + $err .= $linenum + 2 . " " . $source[$linenum + 1]; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | |
@@ -179,8 +179,8 @@ discard block |
||
179 | 179 | header('HTTP/1.0 500 Internal Server Error'); |
180 | 180 | print "<p>Oops, sorry, an error has occurred!</p>\n"; |
181 | 181 | } |
182 | - if (!($errno & E_USER_NOTICE) && strpos($errmsg, 'pg_connect')===false && strpos($errmsg, 'mysql_connect')===false) { |
|
183 | - mail(BUGSLIST, "[TWFYBUG]: $errmsg", $err, "From: Bug <" . CONTACTEMAIL . ">\n". "X-Mailer: PHP/" . phpversion() ); |
|
182 | + if (!($errno & E_USER_NOTICE) && strpos($errmsg, 'pg_connect') === false && strpos($errmsg, 'mysql_connect') === false) { |
|
183 | + mail(BUGSLIST, "[TWFYBUG]: $errmsg", $err, "From: Bug <" . CONTACTEMAIL . ">\n" . "X-Mailer: PHP/" . phpversion()); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | } |
199 | 199 | |
200 | 200 | // pretty prints the backtrace, copied from http://uk.php.net/manual/en/function.debug-backtrace.php |
201 | -function adodb_backtrace($print=true) |
|
201 | +function adodb_backtrace($print = true) |
|
202 | 202 | { |
203 | 203 | $s = ''; |
204 | 204 | if (PHPVERSION() >= 4.3) { |
@@ -207,26 +207,26 @@ discard block |
||
207 | 207 | |
208 | 208 | $traceArr = debug_backtrace(); |
209 | 209 | array_shift($traceArr); |
210 | - $tabs = sizeof($traceArr)-1; |
|
210 | + $tabs = sizeof($traceArr) - 1; |
|
211 | 211 | foreach ($traceArr as $arr) { |
212 | - for ($i=0; $i < $tabs; $i++) $s .= ' '; |
|
212 | + for ($i = 0; $i < $tabs; $i++) $s .= ' '; |
|
213 | 213 | $tabs -= 1; |
214 | - if (isset($arr['class'])) $s .= $arr['class'].'.'; |
|
214 | + if (isset($arr['class'])) $s .= $arr['class'] . '.'; |
|
215 | 215 | $args = array(); |
216 | 216 | if (isset($arr['args'])) foreach ($arr['args'] as $v) { |
217 | 217 | if (is_null($v)) $args[] = 'null'; |
218 | - elseif (is_array($v)) $args[] = 'Array['.sizeof($v).']'; |
|
219 | - elseif (is_object($v)) $args[] = 'Object:'.get_class($v); |
|
218 | + elseif (is_array($v)) $args[] = 'Array[' . sizeof($v) . ']'; |
|
219 | + elseif (is_object($v)) $args[] = 'Object:' . get_class($v); |
|
220 | 220 | elseif (is_bool($v)) $args[] = $v ? 'true' : 'false'; |
221 | 221 | else { |
222 | 222 | $v = (string) @$v; |
223 | - $str = _htmlspecialchars(substr($v,0,$MAXSTRLEN)); |
|
223 | + $str = _htmlspecialchars(substr($v, 0, $MAXSTRLEN)); |
|
224 | 224 | if (strlen($v) > $MAXSTRLEN) $str .= '...'; |
225 | 225 | $args[] = $str; |
226 | 226 | } |
227 | 227 | } |
228 | 228 | |
229 | - $s .= $arr['function'].'('.implode(', ',$args).')'; |
|
229 | + $s .= $arr['function'] . '(' . implode(', ', $args) . ')'; |
|
230 | 230 | // $s .= sprintf("</font><font color=#808080 size=-1> # line %4d,". |
231 | 231 | // " file: <a href=\"file:/%s\">%s</a></font>", |
232 | 232 | // $arr['line'],$arr['file'],$arr['file']); |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | |
241 | 241 | // Far from foolproof, but better than nothing. |
242 | 242 | function validate_email($string) { |
243 | - if (!preg_match('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`a-z{|}~]+'. |
|
244 | - '@'. |
|
245 | - '[-!#$%&\'*.\\+\/0-9=?A-Z^_`a-z{|}~]+\.'. |
|
243 | + if (!preg_match('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`a-z{|}~]+' . |
|
244 | + '@' . |
|
245 | + '[-!#$%&\'*.\\+\/0-9=?A-Z^_`a-z{|}~]+\.' . |
|
246 | 246 | '[-!#$%&\'*+\\.\/0-9=?A-Z^_`a-z{|}~]+$/', $string)) { |
247 | 247 | return false; |
248 | 248 | } else { |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | $nom = '0123456789'; |
265 | 265 | $gap = '\s\.'; |
266 | 266 | |
267 | - if ( preg_match("/^[$fst][$num][$gap]*[$nom][$in][$in]$/i", $postcode) || |
|
267 | + if (preg_match("/^[$fst][$num][$gap]*[$nom][$in][$in]$/i", $postcode) || |
|
268 | 268 | preg_match("/^[$fst][$num][$num][$gap]*[$nom][$in][$in]$/i", $postcode) || |
269 | 269 | preg_match("/^[$fst][$sec][$num][$gap]*[$nom][$in][$in]$/i", $postcode) || |
270 | 270 | preg_match("/^[$fst][$sec][$num][$num][$gap]*[$nom][$in][$in]$/i", $postcode) || |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | // Returns the unixtime in microseconds. |
281 | 281 | function getmicrotime() { |
282 | 282 | $mtime = microtime(); |
283 | - $mtime = explode(" ",$mtime); |
|
283 | + $mtime = explode(" ", $mtime); |
|
284 | 284 | $mtime = $mtime[1] + $mtime[0]; |
285 | 285 | |
286 | 286 | return $mtime; |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | global $timestamp_last, $timestamp_start; |
294 | 294 | $t = getmicrotime(); |
295 | 295 | twfy_debug("TIME", sprintf("%f msecs since start; %f msecs since last; %s", |
296 | - ($t - $timestamp_start)*1000.0, ($t - $timestamp_last)*1000.0, $label)); |
|
296 | + ($t - $timestamp_start) * 1000.0, ($t - $timestamp_last) * 1000.0, $label)); |
|
297 | 297 | $timestamp_last = $t; |
298 | 298 | } |
299 | 299 | |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | if (preg_match("/^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/", $timestamp, $matches)) { |
308 | 308 | list($string, $year, $month, $day, $hour, $min, $sec) = $matches; |
309 | 309 | |
310 | - return gmdate ($format, gmmktime($hour, $min, $sec, $month, $day, $year)); |
|
310 | + return gmdate($format, gmmktime($hour, $min, $sec, $month, $day, $year)); |
|
311 | 311 | } else { |
312 | 312 | return ""; |
313 | 313 | } |
@@ -328,13 +328,13 @@ discard block |
||
328 | 328 | list($string, $year, $month, $day) = $matches; |
329 | 329 | if ($year < 1902) { # gmdate fns only go back to Dec. 1901 |
330 | 330 | if ($format == SHORTDATEFORMAT) { |
331 | - return ($day+0) . ' ' . $format_date_months_short[$month+0] . " $year"; |
|
331 | + return ($day + 0) . ' ' . $format_date_months_short[$month + 0] . " $year"; |
|
332 | 332 | } else { |
333 | - return ($day+0) . ' ' . $format_date_months[$month+0] . " $year"; |
|
333 | + return ($day + 0) . ' ' . $format_date_months[$month + 0] . " $year"; |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
337 | - return gmdate ($format, gmmktime(0, 0, 0, $month, $day, $year)); |
|
337 | + return gmdate($format, gmmktime(0, 0, 0, $month, $day, $year)); |
|
338 | 338 | } else { |
339 | 339 | return ""; |
340 | 340 | } |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | if (preg_match("/^(\d\d):(\d\d):(\d\d)$/", $time, $matches)) { |
351 | 351 | list($string, $hour, $min, $sec) = $matches; |
352 | 352 | |
353 | - return gmdate ($format, gmmktime($hour, $min, $sec)); |
|
353 | + return gmdate($format, gmmktime($hour, $min, $sec)); |
|
354 | 354 | } else { |
355 | 355 | return ""; |
356 | 356 | } |
@@ -371,16 +371,16 @@ discard block |
||
371 | 371 | $in_seconds = strtotime($datetime); |
372 | 372 | $now = time(); |
373 | 373 | |
374 | - $diff = $now - $in_seconds; |
|
375 | - $months = floor($diff/2419200); |
|
374 | + $diff = $now - $in_seconds; |
|
375 | + $months = floor($diff / 2419200); |
|
376 | 376 | $diff -= $months * 2419200; |
377 | - $weeks = floor($diff/604800); |
|
378 | - $diff -= $weeks*604800; |
|
379 | - $days = floor($diff/86400); |
|
377 | + $weeks = floor($diff / 604800); |
|
378 | + $diff -= $weeks * 604800; |
|
379 | + $days = floor($diff / 86400); |
|
380 | 380 | $diff -= $days * 86400; |
381 | - $hours = floor($diff/3600); |
|
381 | + $hours = floor($diff / 3600); |
|
382 | 382 | $diff -= $hours * 3600; |
383 | - $minutes = floor($diff/60); |
|
383 | + $minutes = floor($diff / 60); |
|
384 | 384 | $diff -= $minutes * 60; |
385 | 385 | $seconds = $diff; |
386 | 386 | |
@@ -394,27 +394,27 @@ discard block |
||
394 | 394 | $relative_date = ''; |
395 | 395 | if ($weeks > 0) { |
396 | 396 | // Weeks and days |
397 | - $relative_date .= ($relative_date?', ':'').$weeks.' week'.($weeks>1?'s':''); |
|
398 | - $relative_date .= $days>0?($relative_date?', ':'').$days.' day'.($days>1?'s':''):''; |
|
397 | + $relative_date .= ($relative_date ? ', ' : '') . $weeks . ' week' . ($weeks > 1 ? 's' : ''); |
|
398 | + $relative_date .= $days > 0 ? ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : '') : ''; |
|
399 | 399 | } elseif ($days > 0) { |
400 | 400 | // days and hours |
401 | - $relative_date .= ($relative_date?', ':'').$days.' day'.($days>1?'s':''); |
|
402 | - $relative_date .= $hours>0?($relative_date?', ':'').$hours.' hour'.($hours>1?'s':''):''; |
|
401 | + $relative_date .= ($relative_date ? ', ' : '') . $days . ' day' . ($days > 1 ? 's' : ''); |
|
402 | + $relative_date .= $hours > 0 ? ($relative_date ? ', ' : '') . $hours . ' hour' . ($hours > 1 ? 's' : '') : ''; |
|
403 | 403 | } elseif ($hours > 0) { |
404 | 404 | // hours and minutes |
405 | - $relative_date .= ($relative_date?', ':'').$hours.' hour'.($hours>1?'s':''); |
|
406 | - $relative_date .= $minutes>0?($relative_date?', ':'').$minutes.' minute'.($minutes>1?'s':''):''; |
|
405 | + $relative_date .= ($relative_date ? ', ' : '') . $hours . ' hour' . ($hours > 1 ? 's' : ''); |
|
406 | + $relative_date .= $minutes > 0 ? ($relative_date ? ', ' : '') . $minutes . ' minute' . ($minutes > 1 ? 's' : '') : ''; |
|
407 | 407 | } elseif ($minutes > 0) { |
408 | 408 | // minutes only |
409 | - $relative_date .= ($relative_date?', ':'').$minutes.' minute'.($minutes>1?'s':''); |
|
409 | + $relative_date .= ($relative_date ? ', ' : '') . $minutes . ' minute' . ($minutes > 1 ? 's' : ''); |
|
410 | 410 | } else { |
411 | 411 | // seconds only |
412 | - $relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds>1?'s':''); |
|
412 | + $relative_date .= ($relative_date ? ', ' : '') . $seconds . ' second' . ($seconds > 1 ? 's' : ''); |
|
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
416 | 416 | // Return relative date and add proper verbiage |
417 | - return $relative_date.' ago'; |
|
417 | + return $relative_date . ' ago'; |
|
418 | 418 | |
419 | 419 | } |
420 | 420 | |
@@ -455,10 +455,10 @@ discard block |
||
455 | 455 | $text = substr($text, $start); |
456 | 456 | |
457 | 457 | // Word boundary. |
458 | - if (preg_match ("/.+?\b(.*)/", $text, $matches)) { |
|
458 | + if (preg_match("/.+?\b(.*)/", $text, $matches)) { |
|
459 | 459 | $text = $matches[1]; |
460 | 460 | // Strip spare space at the start. |
461 | - $text = preg_replace ("/^\s/", '', $text); |
|
461 | + $text = preg_replace("/^\s/", '', $text); |
|
462 | 462 | } |
463 | 463 | $text = '...' . $text; |
464 | 464 | } |
@@ -470,10 +470,10 @@ discard block |
||
470 | 470 | $text = substr($text, 0, $length - 3); |
471 | 471 | |
472 | 472 | // Word boundary. |
473 | - if (preg_match ("/(.*)\s.+/", $text, $matches)) { |
|
473 | + if (preg_match("/(.*)\s.+/", $text, $matches)) { |
|
474 | 474 | $text = $matches[1]; |
475 | 475 | // Strip spare space at the end. |
476 | - $text = preg_replace ("/\s$/", '', $text); |
|
476 | + $text = preg_replace("/\s$/", '', $text); |
|
477 | 477 | } |
478 | 478 | // We don't want to use the HTML entity for an ellipsis (…), because then |
479 | 479 | // it screws up when we subsequently use htmlentities() to print the returned |
@@ -505,11 +505,11 @@ discard block |
||
505 | 505 | |
506 | 506 | if ($filter_type == 'strict') { |
507 | 507 | // No tags allowed at all! |
508 | - $filter->allowed = array (); |
|
508 | + $filter->allowed = array(); |
|
509 | 509 | } else { |
510 | 510 | // Comment. |
511 | 511 | // Only allowing <a href>, <b>, <strong>, <i> and <em> |
512 | - $filter->allowed = array ( |
|
512 | + $filter->allowed = array( |
|
513 | 513 | 'a' => array('href'), |
514 | 514 | 'strong' => array(), |
515 | 515 | 'em' => array(), |
@@ -630,10 +630,10 @@ discard block |
||
630 | 630 | // This returns 'debate_2003-02-28.475.3'. |
631 | 631 | |
632 | 632 | if ($keepmajor) { |
633 | - $newgid = substr($gid, strpos($gid, '/')+1 ); |
|
633 | + $newgid = substr($gid, strpos($gid, '/') + 1); |
|
634 | 634 | $newgid = str_replace('/', '_', $newgid); |
635 | 635 | } else { |
636 | - $newgid = substr($gid, strrpos($gid, '/')+1 ); |
|
636 | + $newgid = substr($gid, strrpos($gid, '/') + 1); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | return $newgid; |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | // will be like 2003-11-20.966.0 |
648 | 648 | // This function returns 966.0 |
649 | 649 | |
650 | - return substr( $gid, (strpos($gid, '.') + 1) ); |
|
650 | + return substr($gid, (strpos($gid, '.') + 1)); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | function preg_replacement_quote($s) { |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | global $PAGE; |
692 | 692 | |
693 | 693 | if (!isset($data['to']) || $data['to'] == '') { |
694 | - $PAGE->error_message ("We need an email address to send to."); |
|
694 | + $PAGE->error_message("We need an email address to send to."); |
|
695 | 695 | return false; |
696 | 696 | } |
697 | 697 | |
@@ -715,7 +715,7 @@ discard block |
||
715 | 715 | if (isset($data['subject'])) { |
716 | 716 | $subject = trim($data['subject']); |
717 | 717 | } else { |
718 | - $subject = trim( substr($firstline, 8) ); |
|
718 | + $subject = trim(substr($firstline, 8)); |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | // Either way, remove this subject line from the template. |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | } elseif (isset($data['subject'])) { |
725 | 725 | $subject = $data['subject']; |
726 | 726 | } else { |
727 | - $PAGE->error_message ("We don't have a subject line for the email, so it wasn't sent."); |
|
727 | + $PAGE->error_message("We don't have a subject line for the email, so it wasn't sent."); |
|
728 | 728 | return false; |
729 | 729 | } |
730 | 730 | |
@@ -734,14 +734,14 @@ discard block |
||
734 | 734 | $replace = array(); |
735 | 735 | |
736 | 736 | foreach ($merge as $key => $val) { |
737 | - $search[] = '/{'.$key.'}/'; |
|
737 | + $search[] = '/{' . $key . '}/'; |
|
738 | 738 | $replace[] = preg_replacement_quote($val); |
739 | 739 | } |
740 | 740 | |
741 | 741 | $emailtext = preg_replace($search, $replace, $emailtext); |
742 | 742 | |
743 | 743 | // Send it! |
744 | - $success = send_email ($data['to'], $subject, $emailtext, $bulk, 'twfy-DO-NOT-REPLY@' . EMAILDOMAIN, $want_bounces); |
|
744 | + $success = send_email($data['to'], $subject, $emailtext, $bulk, 'twfy-DO-NOT-REPLY@' . EMAILDOMAIN, $want_bounces); |
|
745 | 745 | |
746 | 746 | return $success; |
747 | 747 | |
@@ -768,15 +768,15 @@ discard block |
||
768 | 768 | "Content-Type: text/plain; charset=utf-8\r\n" . |
769 | 769 | "MIME-Version: 1.0\r\n" . |
770 | 770 | "Content-Transfer-Encoding: 8bit\r\n" . |
771 | - ($bulk ? "Precedence: bulk\r\nAuto-Submitted: auto-generated\r\n" : "" ). |
|
771 | + ($bulk ? "Precedence: bulk\r\nAuto-Submitted: auto-generated\r\n" : "") . |
|
772 | 772 | "X-Mailer: PHP/" . phpversion(); |
773 | 773 | twfy_debug('EMAIL', "Sending email to $to with subject of '$subject'"); |
774 | 774 | |
775 | 775 | if ($want_bounces) { |
776 | 776 | $envelope_sender = twfy_verp_envelope_sender($to); |
777 | - $success = mail ($to, $subject, $message, $headers, '-f ' . $envelope_sender); |
|
777 | + $success = mail($to, $subject, $message, $headers, '-f ' . $envelope_sender); |
|
778 | 778 | } else { |
779 | - $success = mail ($to, $subject, $message, $headers); |
|
779 | + $success = mail($to, $subject, $message, $headers); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | return $success; |
@@ -788,7 +788,7 @@ discard block |
||
788 | 788 | // http://www.iamcal.com/publish/article.php?id=13 |
789 | 789 | |
790 | 790 | // Call this with a key name to get a GET or POST variable. |
791 | -function get_http_var($name, $default='') { |
|
791 | +function get_http_var($name, $default = '') { |
|
792 | 792 | if (array_key_exists($name, $_GET)) { |
793 | 793 | return clean_var($_GET[$name]); |
794 | 794 | } |
@@ -814,7 +814,7 @@ discard block |
||
814 | 814 | } |
815 | 815 | |
816 | 816 | // Call this with a key name to get a COOKIE variable. |
817 | -function get_cookie_var($name, $default='') { |
|
817 | +function get_cookie_var($name, $default = '') { |
|
818 | 818 | if (array_key_exists($name, $_COOKIE)) { |
819 | 819 | return clean_var($_COOKIE[$name]); |
820 | 820 | } |
@@ -825,7 +825,7 @@ discard block |
||
825 | 825 | // Pass it an array of key names that should not be generated as |
826 | 826 | // hidden form variables. It then outputs hidden form variables |
827 | 827 | // based on the session_vars for this page. |
828 | -function hidden_form_vars ($omit = array()) { |
|
828 | +function hidden_form_vars($omit = array()) { |
|
829 | 829 | global $DATA, $this_page; |
830 | 830 | |
831 | 831 | $session_vars = $DATA->page_metadata($this_page, "session_vars"); |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | } |
839 | 839 | |
840 | 840 | // Deprecated. Use hidden_form_vars, above, instead. |
841 | -function hidden_vars ($omit = array()) { |
|
841 | +function hidden_vars($omit = array()) { |
|
842 | 842 | global $DATA; |
843 | 843 | |
844 | 844 | foreach ($args as $key => $val) { |
@@ -881,7 +881,7 @@ discard block |
||
881 | 881 | function entities_to_numbers($string) { |
882 | 882 | $string = str_replace( |
883 | 883 | array('Ö', 'â', 'ú', 'á', 'í', 'ô', 'é'), |
884 | - array('Ö', 'â', 'ú', 'á', 'í', 'ô', 'é' ), |
|
884 | + array('Ö', 'â', 'ú', 'á', 'í', 'ô', 'é'), |
|
885 | 885 | $string |
886 | 886 | ); |
887 | 887 | return $string; |
@@ -895,9 +895,9 @@ discard block |
||
895 | 895 | return 'elizabeth_the_second'; |
896 | 896 | } |
897 | 897 | |
898 | - $s = array(' ', '&', 'ô', 'Ö', 'ö', 'â', 'í', 'á', 'ú', 'é', 'ó', 'Ó'); |
|
899 | - $s2 = array(" ", "&", "\xc3\xb4", "\xc3\96", "\xc3\xb6", "\xc3\xa5", "\xc3\xad", "\xc3\xa1", "\xc3\xba", "\xc3\xa9", "\xc3\xb3", "\xc3\x93"); |
|
900 | - $r = array('_', 'and', 'o', 'o', 'o', 'a', 'i', 'a', 'u', 'e', 'o', 'o'); |
|
898 | + $s = array(' ', '&', 'ô', 'Ö', 'ö', 'â', 'í', 'á', 'ú', 'é', 'ó', 'Ó'); |
|
899 | + $s2 = array(" ", "&", "\xc3\xb4", "\xc3\96", "\xc3\xb6", "\xc3\xa5", "\xc3\xad", "\xc3\xa1", "\xc3\xba", "\xc3\xa9", "\xc3\xb3", "\xc3\x93"); |
|
900 | + $r = array('_', 'and', 'o', 'o', 'o', 'a', 'i', 'a', 'u', 'e', 'o', 'o'); |
|
901 | 901 | $name = preg_replace('#^the #', '', strtolower($name)); |
902 | 902 | |
903 | 903 | $out = ''; |
@@ -1037,8 +1037,8 @@ discard block |
||
1037 | 1037 | } |
1038 | 1038 | $out .= '<li>' . $body . '<ul>'; |
1039 | 1039 | } else { |
1040 | - $LISTURL->insert( array( 'id' => $gid ) ); |
|
1041 | - $out .= '<li><a href="'.$LISTURL->generate().'">'; |
|
1040 | + $LISTURL->insert(array('id' => $gid)); |
|
1041 | + $out .= '<li><a href="' . $LISTURL->generate() . '">'; |
|
1042 | 1042 | $out .= $body . '</a>'; |
1043 | 1043 | } |
1044 | 1044 | } |
@@ -39,7 +39,8 @@ discard block |
||
39 | 39 | |
40 | 40 | if ($debug_level > count($levels)) { |
41 | 41 | $max_level_to_show = count($levels); |
42 | - } else { |
|
42 | + } |
|
43 | + else { |
|
43 | 44 | $max_level_to_show = $debug_level; |
44 | 45 | } |
45 | 46 | |
@@ -49,7 +50,9 @@ discard block |
||
49 | 50 | |
50 | 51 | // If we can show this header, then, er, show it. |
51 | 52 | if ( in_array($header, $allowed_headers) || $debug_level >= 4) { |
52 | - if (is_array($text)) $text = call_user_func($text); |
|
53 | + if (is_array($text)) { |
|
54 | + $text = call_user_func($text); |
|
55 | + } |
|
53 | 56 | print "<p><span style=\"color:#039;\"><strong>$header</strong></span> $text</p>\n"; |
54 | 57 | } |
55 | 58 | } |
@@ -65,7 +68,9 @@ discard block |
||
65 | 68 | global $PAGE; |
66 | 69 | |
67 | 70 | # Ignore errors we've asked to ignore |
68 | - if (error_reporting()==0) return; |
|
71 | + if (error_reporting()==0) { |
|
72 | + return; |
|
73 | + } |
|
69 | 74 | |
70 | 75 | // define an assoc array of error string |
71 | 76 | // in reality the only entries we should |
@@ -92,17 +97,20 @@ discard block |
||
92 | 97 | $err = ''; |
93 | 98 | if (isset($_SERVER['REQUEST_URI'])) { |
94 | 99 | $err .= "URL:\t\thttps://" . DOMAIN . $_SERVER['REQUEST_URI'] . "\n"; |
95 | - } else { |
|
100 | + } |
|
101 | + else { |
|
96 | 102 | $err .= "URL:\t\tNone - running from command line?\n"; |
97 | 103 | } |
98 | 104 | if (isset($_SERVER['HTTP_REFERER'])) { |
99 | 105 | $err .= "Referer:\t" . $_SERVER['HTTP_REFERER'] . "\n"; |
100 | - } else { |
|
106 | + } |
|
107 | + else { |
|
101 | 108 | $err .= "Referer:\tNone\n"; |
102 | 109 | } |
103 | 110 | if (isset($_SERVER['HTTP_USER_AGENT'])) { |
104 | 111 | $err .= "User-Agent:\t" . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
105 | - } else { |
|
112 | + } |
|
113 | + else { |
|
106 | 114 | $err .= "User-Agent:\tNone\n"; |
107 | 115 | } |
108 | 116 | $err .= "Number:\t\t$errno\n"; |
@@ -143,7 +151,8 @@ discard block |
||
143 | 151 | $fatal_errors = array(E_ERROR, E_USER_ERROR); |
144 | 152 | if (in_array($errno, $fatal_errors)) { |
145 | 153 | $fatal = true; |
146 | - } else { |
|
154 | + } |
|
155 | + else { |
|
147 | 156 | $fatal = false; |
148 | 157 | } |
149 | 158 | |
@@ -161,11 +170,13 @@ discard block |
||
161 | 170 | ); |
162 | 171 | if (is_object($PAGE)) { |
163 | 172 | $PAGE->error_message($message, $fatal); |
164 | - } else { |
|
173 | + } |
|
174 | + else { |
|
165 | 175 | vardump($message); |
166 | 176 | } |
167 | 177 | |
168 | - } else { |
|
178 | + } |
|
179 | + else { |
|
169 | 180 | // On live sites we display a nice message and email the problem. |
170 | 181 | |
171 | 182 | $message = array( |
@@ -175,7 +186,8 @@ discard block |
||
175 | 186 | |
176 | 187 | if (is_object($PAGE)) { |
177 | 188 | $PAGE->error_message($message, $fatal); |
178 | - } else { |
|
189 | + } |
|
190 | + else { |
|
179 | 191 | header('HTTP/1.0 500 Internal Server Error'); |
180 | 192 | print "<p>Oops, sorry, an error has occurred!</p>\n"; |
181 | 193 | } |
@@ -209,19 +221,33 @@ discard block |
||
209 | 221 | array_shift($traceArr); |
210 | 222 | $tabs = sizeof($traceArr)-1; |
211 | 223 | foreach ($traceArr as $arr) { |
212 | - for ($i=0; $i < $tabs; $i++) $s .= ' '; |
|
224 | + for ($i=0; $i < $tabs; $i++) { |
|
225 | + $s .= ' '; |
|
226 | + } |
|
213 | 227 | $tabs -= 1; |
214 | - if (isset($arr['class'])) $s .= $arr['class'].'.'; |
|
228 | + if (isset($arr['class'])) { |
|
229 | + $s .= $arr['class'].'.'; |
|
230 | + } |
|
215 | 231 | $args = array(); |
216 | - if (isset($arr['args'])) foreach ($arr['args'] as $v) { |
|
232 | + if (isset($arr['args'])) { |
|
233 | + foreach ($arr['args'] as $v) { |
|
217 | 234 | if (is_null($v)) $args[] = 'null'; |
218 | - elseif (is_array($v)) $args[] = 'Array['.sizeof($v).']'; |
|
219 | - elseif (is_object($v)) $args[] = 'Object:'.get_class($v); |
|
220 | - elseif (is_bool($v)) $args[] = $v ? 'true' : 'false'; |
|
235 | + } |
|
236 | + elseif (is_array($v)) { |
|
237 | + $args[] = 'Array['.sizeof($v).']'; |
|
238 | + } |
|
239 | + elseif (is_object($v)) { |
|
240 | + $args[] = 'Object:'.get_class($v); |
|
241 | + } |
|
242 | + elseif (is_bool($v)) { |
|
243 | + $args[] = $v ? 'true' : 'false'; |
|
244 | + } |
|
221 | 245 | else { |
222 | 246 | $v = (string) @$v; |
223 | 247 | $str = _htmlspecialchars(substr($v,0,$MAXSTRLEN)); |
224 | - if (strlen($v) > $MAXSTRLEN) $str .= '...'; |
|
248 | + if (strlen($v) > $MAXSTRLEN) { |
|
249 | + $str .= '...'; |
|
250 | + } |
|
225 | 251 | $args[] = $str; |
226 | 252 | } |
227 | 253 | } |
@@ -232,7 +258,9 @@ discard block |
||
232 | 258 | // $arr['line'],$arr['file'],$arr['file']); |
233 | 259 | $s .= "\n"; |
234 | 260 | } |
235 | - if ($print) print $s; |
|
261 | + if ($print) { |
|
262 | + print $s; |
|
263 | + } |
|
236 | 264 | } |
237 | 265 | |
238 | 266 | return $s; |
@@ -245,7 +273,8 @@ discard block |
||
245 | 273 | '[-!#$%&\'*.\\+\/0-9=?A-Z^_`a-z{|}~]+\.'. |
246 | 274 | '[-!#$%&\'*+\\.\/0-9=?A-Z^_`a-z{|}~]+$/', $string)) { |
247 | 275 | return false; |
248 | - } else { |
|
276 | + } |
|
277 | + else { |
|
249 | 278 | return true; |
250 | 279 | } |
251 | 280 | } |
@@ -272,7 +301,8 @@ discard block |
||
272 | 301 | preg_match("/^[$fst][$sec][$num][$fth][$gap]*[$nom][$in][$in]$/i", $postcode) |
273 | 302 | ) { |
274 | 303 | return true; |
275 | - } else { |
|
304 | + } |
|
305 | + else { |
|
276 | 306 | return false; |
277 | 307 | } |
278 | 308 | } |
@@ -308,7 +338,8 @@ discard block |
||
308 | 338 | list($string, $year, $month, $day, $hour, $min, $sec) = $matches; |
309 | 339 | |
310 | 340 | return gmdate ($format, gmmktime($hour, $min, $sec, $month, $day, $year)); |
311 | - } else { |
|
341 | + } |
|
342 | + else { |
|
312 | 343 | return ""; |
313 | 344 | } |
314 | 345 | |
@@ -326,16 +357,19 @@ discard block |
||
326 | 357 | |
327 | 358 | if (preg_match("/^(\d\d\d\d)-(\d\d?)-(\d\d?)$/", $date, $matches)) { |
328 | 359 | list($string, $year, $month, $day) = $matches; |
329 | - if ($year < 1902) { # gmdate fns only go back to Dec. 1901 |
|
360 | + if ($year < 1902) { |
|
361 | +# gmdate fns only go back to Dec. 1901 |
|
330 | 362 | if ($format == SHORTDATEFORMAT) { |
331 | 363 | return ($day+0) . ' ' . $format_date_months_short[$month+0] . " $year"; |
332 | - } else { |
|
364 | + } |
|
365 | + else { |
|
333 | 366 | return ($day+0) . ' ' . $format_date_months[$month+0] . " $year"; |
334 | 367 | } |
335 | 368 | } |
336 | 369 | |
337 | 370 | return gmdate ($format, gmmktime(0, 0, 0, $month, $day, $year)); |
338 | - } else { |
|
371 | + } |
|
372 | + else { |
|
339 | 373 | return ""; |
340 | 374 | } |
341 | 375 | |
@@ -351,7 +385,8 @@ discard block |
||
351 | 385 | list($string, $hour, $min, $sec) = $matches; |
352 | 386 | |
353 | 387 | return gmdate ($format, gmmktime($hour, $min, $sec)); |
354 | - } else { |
|
388 | + } |
|
389 | + else { |
|
355 | 390 | return ""; |
356 | 391 | } |
357 | 392 | } |
@@ -390,24 +425,29 @@ discard block |
||
390 | 425 | $date = substr($datetime, 0, 10); |
391 | 426 | return format_date($date, LONGDATEFORMAT); |
392 | 427 | |
393 | - } else { |
|
428 | + } |
|
429 | + else { |
|
394 | 430 | $relative_date = ''; |
395 | 431 | if ($weeks > 0) { |
396 | 432 | // Weeks and days |
397 | 433 | $relative_date .= ($relative_date?', ':'').$weeks.' week'.($weeks>1?'s':''); |
398 | 434 | $relative_date .= $days>0?($relative_date?', ':'').$days.' day'.($days>1?'s':''):''; |
399 | - } elseif ($days > 0) { |
|
435 | + } |
|
436 | + elseif ($days > 0) { |
|
400 | 437 | // days and hours |
401 | 438 | $relative_date .= ($relative_date?', ':'').$days.' day'.($days>1?'s':''); |
402 | 439 | $relative_date .= $hours>0?($relative_date?', ':'').$hours.' hour'.($hours>1?'s':''):''; |
403 | - } elseif ($hours > 0) { |
|
440 | + } |
|
441 | + elseif ($hours > 0) { |
|
404 | 442 | // hours and minutes |
405 | 443 | $relative_date .= ($relative_date?', ':'').$hours.' hour'.($hours>1?'s':''); |
406 | 444 | $relative_date .= $minutes>0?($relative_date?', ':'').$minutes.' minute'.($minutes>1?'s':''):''; |
407 | - } elseif ($minutes > 0) { |
|
445 | + } |
|
446 | + elseif ($minutes > 0) { |
|
408 | 447 | // minutes only |
409 | 448 | $relative_date .= ($relative_date?', ':'').$minutes.' minute'.($minutes>1?'s':''); |
410 | - } else { |
|
449 | + } |
|
450 | + else { |
|
411 | 451 | // seconds only |
412 | 452 | $relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds>1?'s':''); |
413 | 453 | } |
@@ -506,7 +546,8 @@ discard block |
||
506 | 546 | if ($filter_type == 'strict') { |
507 | 547 | // No tags allowed at all! |
508 | 548 | $filter->allowed = array (); |
509 | - } else { |
|
549 | + } |
|
550 | + else { |
|
510 | 551 | // Comment. |
511 | 552 | // Only allowing <a href>, <b>, <strong>, <i> and <em> |
512 | 553 | $filter->allowed = array ( |
@@ -541,7 +582,8 @@ discard block |
||
541 | 582 | function($matches) use ($link_length) { |
542 | 583 | if (strlen($matches[0]) > $link_length) { |
543 | 584 | return '<a href="' . $matches[0] . '" rel="nofollow">' . substr($matches[0], 0, $link_length) . "...</a>"; |
544 | - } else { |
|
585 | + } |
|
586 | + else { |
|
545 | 587 | return '<a href="' . $matches[0] . '" rel="nofollow">' . $matches[0] . '</a>'; |
546 | 588 | } |
547 | 589 | }, |
@@ -607,7 +649,8 @@ discard block |
||
607 | 649 | $q = $db->query("SELECT gid_to FROM gidredirect WHERE gid_from = :gid", array(':gid' => $gid)); |
608 | 650 | if ($q->rows() > 0) { |
609 | 651 | $gid = $q->field(0, 'gid_to'); |
610 | - } else { |
|
652 | + } |
|
653 | + else { |
|
611 | 654 | $might_be_redirected = false; |
612 | 655 | } |
613 | 656 | } |
@@ -632,7 +675,8 @@ discard block |
||
632 | 675 | if ($keepmajor) { |
633 | 676 | $newgid = substr($gid, strpos($gid, '/')+1 ); |
634 | 677 | $newgid = str_replace('/', '_', $newgid); |
635 | - } else { |
|
678 | + } |
|
679 | + else { |
|
636 | 680 | $newgid = substr($gid, strrpos($gid, '/')+1 ); |
637 | 681 | } |
638 | 682 | |
@@ -714,16 +758,19 @@ discard block |
||
714 | 758 | if (preg_match("/Subject:/", $firstline)) { |
715 | 759 | if (isset($data['subject'])) { |
716 | 760 | $subject = trim($data['subject']); |
717 | - } else { |
|
761 | + } |
|
762 | + else { |
|
718 | 763 | $subject = trim( substr($firstline, 8) ); |
719 | 764 | } |
720 | 765 | |
721 | 766 | // Either way, remove this subject line from the template. |
722 | 767 | $emailtext = substr($emailtext, strpos($emailtext, "\n")); |
723 | 768 | |
724 | - } elseif (isset($data['subject'])) { |
|
769 | + } |
|
770 | + elseif (isset($data['subject'])) { |
|
725 | 771 | $subject = $data['subject']; |
726 | - } else { |
|
772 | + } |
|
773 | + else { |
|
727 | 774 | $PAGE->error_message ("We don't have a subject line for the email, so it wasn't sent."); |
728 | 775 | return false; |
729 | 776 | } |
@@ -761,7 +808,9 @@ discard block |
||
761 | 808 | // easily to all the emails we send out from the site. |
762 | 809 | // eg, we might want to add a .sig to everything here... |
763 | 810 | |
764 | - if (!$from) $from = CONTACTEMAIL; |
|
811 | + if (!$from) { |
|
812 | + $from = CONTACTEMAIL; |
|
813 | + } |
|
765 | 814 | |
766 | 815 | $headers = |
767 | 816 | "From: TheyWorkForYou <$from>\r\n" . |
@@ -775,7 +824,8 @@ discard block |
||
775 | 824 | if ($want_bounces) { |
776 | 825 | $envelope_sender = twfy_verp_envelope_sender($to); |
777 | 826 | $success = mail ($to, $subject, $message, $headers, '-f ' . $envelope_sender); |
778 | - } else { |
|
827 | + } |
|
828 | + else { |
|
779 | 829 | $success = mail ($to, $subject, $message, $headers); |
780 | 830 | } |
781 | 831 | |
@@ -807,7 +857,8 @@ discard block |
||
807 | 857 | while (list($key, $val) = each($a)) { |
808 | 858 | $a[$key] = recursive_strip($val); |
809 | 859 | } |
810 | - } else { |
|
860 | + } |
|
861 | + else { |
|
811 | 862 | $a = StripSlashes($a); |
812 | 863 | } |
813 | 864 | return $a; |
@@ -853,17 +904,21 @@ discard block |
||
853 | 904 | $rank = $rank + 0; |
854 | 905 | |
855 | 906 | # 11th, 12th, 13th use "th" not "st", "nd", "rd" |
856 | - if (floor(($rank % 100) / 10) == 1) |
|
857 | - return $rank . "th"; |
|
907 | + if (floor(($rank % 100) / 10) == 1) { |
|
908 | + return $rank . "th"; |
|
909 | + } |
|
858 | 910 | # 1st |
859 | - if ($rank % 10 == 1) |
|
860 | - return $rank . "st"; |
|
911 | + if ($rank % 10 == 1) { |
|
912 | + return $rank . "st"; |
|
913 | + } |
|
861 | 914 | # 2nd |
862 | - if ($rank % 10 == 2) |
|
863 | - return $rank . "nd"; |
|
915 | + if ($rank % 10 == 2) { |
|
916 | + return $rank . "nd"; |
|
917 | + } |
|
864 | 918 | # 3rd |
865 | - if ($rank % 10 == 3) |
|
866 | - return $rank . "rd"; |
|
919 | + if ($rank % 10 == 3) { |
|
920 | + return $rank . "rd"; |
|
921 | + } |
|
867 | 922 | # Everything else use th |
868 | 923 | |
869 | 924 | return $rank . "th"; |
@@ -871,8 +926,9 @@ discard block |
||
871 | 926 | |
872 | 927 | function make_plural($word, $number) |
873 | 928 | { |
874 | - if ($number == 1) |
|
875 | - return $word; |
|
929 | + if ($number == 1) { |
|
930 | + return $word; |
|
931 | + } |
|
876 | 932 | return $word . "s"; |
877 | 933 | } |
878 | 934 | |
@@ -890,8 +946,7 @@ discard block |
||
890 | 946 | function make_member_url($name, $const = '', $house = HOUSE_TYPE_COMMONS, $pid = NULL) { |
891 | 947 | |
892 | 948 | // Case for Elizabeth II |
893 | - if ($house == HOUSE_TYPE_ROYAL) |
|
894 | - { |
|
949 | + if ($house == HOUSE_TYPE_ROYAL) { |
|
895 | 950 | return 'elizabeth_the_second'; |
896 | 951 | } |
897 | 952 | |
@@ -903,8 +958,7 @@ discard block |
||
903 | 958 | $out = ''; |
904 | 959 | |
905 | 960 | // Insert the Person ID if known. |
906 | - if ($pid !== NULL) |
|
907 | - { |
|
961 | + if ($pid !== NULL) { |
|
908 | 962 | $out .= $pid . '/'; |
909 | 963 | } |
910 | 964 | |
@@ -912,8 +966,7 @@ discard block |
||
912 | 966 | $out .= urlencode(str_replace($s2, $r, str_replace($s, $r, $name))); |
913 | 967 | |
914 | 968 | // If there is a constituency, inject that too |
915 | - if ($const && $house == HOUSE_TYPE_COMMONS) |
|
916 | - { |
|
969 | + if ($const && $house == HOUSE_TYPE_COMMONS) { |
|
917 | 970 | $out .= '/' . urlencode(str_replace($s2, $r, str_replace($s, $r, strtolower($const)))); |
918 | 971 | } |
919 | 972 | |
@@ -927,13 +980,22 @@ discard block |
||
927 | 980 | if ($title) { |
928 | 981 | $s = $title . ' ' . $s; |
929 | 982 | } |
930 | - } elseif ($house == HOUSE_TYPE_LORDS) { |
|
983 | + } |
|
984 | + elseif ($house == HOUSE_TYPE_LORDS) { |
|
931 | 985 | $s = ''; |
932 | - if (!$family_name) $s = 'the '; |
|
986 | + if (!$family_name) { |
|
987 | + $s = 'the '; |
|
988 | + } |
|
933 | 989 | $s .= $title; |
934 | - if ($family_name) $s .= ' ' . $family_name; |
|
935 | - if ($lordofname) $s .= ' of ' . $lordofname; |
|
936 | - } elseif ($house == HOUSE_TYPE_ROYAL) { # Queen |
|
990 | + if ($family_name) { |
|
991 | + $s .= ' ' . $family_name; |
|
992 | + } |
|
993 | + if ($lordofname) { |
|
994 | + $s .= ' of ' . $lordofname; |
|
995 | + } |
|
996 | + } |
|
997 | + elseif ($house == HOUSE_TYPE_ROYAL) { |
|
998 | +# Queen |
|
937 | 999 | $s = "$given_name $family_name"; |
938 | 1000 | } |
939 | 1001 | return $s; |
@@ -962,12 +1024,18 @@ discard block |
||
962 | 1024 | 'Lords in Waiting (HM Household)' => 'Government Whip', |
963 | 1025 | 'Baronesses in Waiting, HM Household' => 'Government Whip', |
964 | 1026 | ); |
965 | - if ($pos) { # Government post, or Chairman of Select Committee |
|
1027 | + if ($pos) { |
|
1028 | +# Government post, or Chairman of Select Committee |
|
966 | 1029 | $pretty = $pos; |
967 | - if ($dept && $dept != 'No Department') $pretty .= ", $dept"; |
|
968 | - if (array_key_exists($pretty, $lookup)) |
|
969 | - $pretty = $lookup[$pretty]; |
|
970 | - } else { # Member of Select Committee |
|
1030 | + if ($dept && $dept != 'No Department') { |
|
1031 | + $pretty .= ", $dept"; |
|
1032 | + } |
|
1033 | + if (array_key_exists($pretty, $lookup)) { |
|
1034 | + $pretty = $lookup[$pretty]; |
|
1035 | + } |
|
1036 | + } |
|
1037 | + else { |
|
1038 | +# Member of Select Committee |
|
971 | 1039 | $pretty = "Member, $dept"; |
972 | 1040 | } |
973 | 1041 | return $pretty; |
@@ -985,13 +1053,16 @@ discard block |
||
985 | 1053 | } |
986 | 1054 | |
987 | 1055 | // single date? |
988 | - if (isset($data['date'])) $one_date = true; |
|
1056 | + if (isset($data['date'])) { |
|
1057 | + $one_date = true; |
|
1058 | + } |
|
989 | 1059 | |
990 | 1060 | // remove empty entries, so they don't produce errors |
991 | 1061 | foreach (array_keys($hansardmajors) as $major) { |
992 | 1062 | if (array_key_exists($major, $data)) { |
993 | - if (count($data[$major]) == 0) |
|
994 | - unset($data[$major]); |
|
1063 | + if (count($data[$major]) == 0) { |
|
1064 | + unset($data[$major]); |
|
1065 | + } |
|
995 | 1066 | } |
996 | 1067 | } |
997 | 1068 | |
@@ -1000,22 +1071,33 @@ discard block |
||
1000 | 1071 | if (!$one_date) { |
1001 | 1072 | $todaystime = gmmktime(0, 0, 0, date('m'), date('d'), date('Y')); |
1002 | 1073 | foreach ($data as $major => $array) { |
1003 | - if (!in_array('timestamp', $array)) $daytext[$major] = "The most recent "; |
|
1004 | - elseif ($todaystime - $array['timestamp'] == 86400) $daytext[$major] = "Yesterday’s"; |
|
1005 | - elseif ($todaystime - $array['timestamp'] <= (6 * 86400)) $daytext[$major] = gmdate('l', $array['timestamp']) . "’s"; |
|
1006 | - else $daytext[$major] = "The most recent "; |
|
1074 | + if (!in_array('timestamp', $array)) { |
|
1075 | + $daytext[$major] = "The most recent "; |
|
1076 | + } |
|
1077 | + elseif ($todaystime - $array['timestamp'] == 86400) { |
|
1078 | + $daytext[$major] = "Yesterday’s"; |
|
1079 | + } |
|
1080 | + elseif ($todaystime - $array['timestamp'] <= (6 * 86400)) { |
|
1081 | + $daytext[$major] = gmdate('l', $array['timestamp']) . "’s"; |
|
1082 | + } |
|
1083 | + else { |
|
1084 | + $daytext[$major] = "The most recent "; |
|
1085 | + } |
|
1007 | 1086 | } |
1008 | 1087 | } |
1009 | 1088 | |
1010 | 1089 | //build html |
1011 | 1090 | foreach ($printed_majors as $p_major) { |
1012 | - if (!array_key_exists($p_major, $data)) |
|
1013 | - continue; |
|
1091 | + if (!array_key_exists($p_major, $data)) { |
|
1092 | + continue; |
|
1093 | + } |
|
1014 | 1094 | |
1015 | - if ($one_date) |
|
1016 | - $date = $data['date']; |
|
1017 | - else |
|
1018 | - $date = $data[$p_major]['hdate']; |
|
1095 | + if ($one_date) { |
|
1096 | + $date = $data['date']; |
|
1097 | + } |
|
1098 | + else { |
|
1099 | + $date = $data[$p_major]['hdate']; |
|
1100 | + } |
|
1019 | 1101 | $q = $db->query('SELECT section_id, body, gid |
1020 | 1102 | FROM hansard, epobject |
1021 | 1103 | WHERE hansard.epobject_id = epobject.epobject_id ' |
@@ -1036,7 +1118,8 @@ discard block |
||
1036 | 1118 | $out .= '</ul>'; |
1037 | 1119 | } |
1038 | 1120 | $out .= '<li>' . $body . '<ul>'; |
1039 | - } else { |
|
1121 | + } |
|
1122 | + else { |
|
1040 | 1123 | $LISTURL->insert( array( 'id' => $gid ) ); |
1041 | 1124 | $out .= '<li><a href="'.$LISTURL->generate().'">'; |
1042 | 1125 | $out .= $body . '</a>'; |
@@ -1053,7 +1136,8 @@ discard block |
||
1053 | 1136 | |
1054 | 1137 | if ($echo) { |
1055 | 1138 | print $html; |
1056 | - } else { |
|
1139 | + } |
|
1140 | + else { |
|
1057 | 1141 | return $html; |
1058 | 1142 | } |
1059 | 1143 | } |
@@ -1067,14 +1151,17 @@ discard block |
||
1067 | 1151 | } |
1068 | 1152 | |
1069 | 1153 | $return .= '<a href="'; |
1070 | - if (isset($data[$major]['listurl'])) |
|
1071 | - $return .= $data[$major]['listurl']; |
|
1154 | + if (isset($data[$major]['listurl'])) { |
|
1155 | + $return .= $data[$major]['listurl']; |
|
1156 | + } |
|
1072 | 1157 | else { |
1073 | 1158 | $LISTURL->reset(); |
1074 | 1159 | $return .= $LISTURL->generate(); |
1075 | 1160 | } |
1076 | 1161 | $return .= '">' . $hansardmajors[$major]['title'] . '</a>'; |
1077 | - if (isset($daytext[$major])) $return; |
|
1162 | + if (isset($daytext[$major])) { |
|
1163 | + $return; |
|
1164 | + } |
|
1078 | 1165 | $return .= '</h4>'; |
1079 | 1166 | |
1080 | 1167 | return $return; |
@@ -1082,20 +1169,27 @@ discard block |
||
1082 | 1169 | |
1083 | 1170 | function score_to_strongly($dmpscore) { |
1084 | 1171 | $dmpdesc = "unknown about"; |
1085 | - if ($dmpscore > 0.95 && $dmpscore <= 1.0) |
|
1086 | - $dmpdesc = "consistently voted against"; |
|
1087 | - elseif ($dmpscore > 0.85) |
|
1088 | - $dmpdesc = "almost always voted against"; |
|
1089 | - elseif ($dmpscore > 0.6) |
|
1090 | - $dmpdesc = "generally voted against"; |
|
1091 | - elseif ($dmpscore > 0.4) |
|
1092 | - $dmpdesc = "voted a mixture of for and against"; |
|
1093 | - elseif ($dmpscore > 0.15) |
|
1094 | - $dmpdesc = "generally voted for"; |
|
1095 | - elseif ($dmpscore > 0.05) |
|
1096 | - $dmpdesc = "almost always voted for"; |
|
1097 | - elseif ($dmpscore >= 0.0) |
|
1098 | - $dmpdesc = "consistently voted for"; |
|
1172 | + if ($dmpscore > 0.95 && $dmpscore <= 1.0) { |
|
1173 | + $dmpdesc = "consistently voted against"; |
|
1174 | + } |
|
1175 | + elseif ($dmpscore > 0.85) { |
|
1176 | + $dmpdesc = "almost always voted against"; |
|
1177 | + } |
|
1178 | + elseif ($dmpscore > 0.6) { |
|
1179 | + $dmpdesc = "generally voted against"; |
|
1180 | + } |
|
1181 | + elseif ($dmpscore > 0.4) { |
|
1182 | + $dmpdesc = "voted a mixture of for and against"; |
|
1183 | + } |
|
1184 | + elseif ($dmpscore > 0.15) { |
|
1185 | + $dmpdesc = "generally voted for"; |
|
1186 | + } |
|
1187 | + elseif ($dmpscore > 0.05) { |
|
1188 | + $dmpdesc = "almost always voted for"; |
|
1189 | + } |
|
1190 | + elseif ($dmpscore >= 0.0) { |
|
1191 | + $dmpdesc = "consistently voted for"; |
|
1192 | + } |
|
1099 | 1193 | return $dmpdesc; |
1100 | 1194 | } |
1101 | 1195 | |
@@ -1110,7 +1204,8 @@ discard block |
||
1110 | 1204 | function redirect($url) { |
1111 | 1205 | if (defined('TESTING')) { |
1112 | 1206 | print "Location: $url"; |
1113 | - } else { |
|
1207 | + } |
|
1208 | + else { |
|
1114 | 1209 | header("Location: $url", true, 301); |
1115 | 1210 | } |
1116 | 1211 | exit; |
@@ -53,7 +53,6 @@ |
||
53 | 53 | * |
54 | 54 | * @param Policies $policies The list of policies to get the positions for. |
55 | 55 | * @param Member $member The member to get positions for. |
56 | - * @param int $limit The number of policies to limit the list to. |
|
57 | 56 | */ |
58 | 57 | |
59 | 58 | public function __construct(Policies $policies, Member $member, $options = array()) |
@@ -121,7 +121,7 @@ |
||
121 | 121 | if (!empty($dream_info)) { |
122 | 122 | $summary = ''; |
123 | 123 | if (array_key_exists($policy[0], $this->summaries)) { |
124 | - $summary = $this->divisions->generateSummary($this->summaries[$policy[0]]); |
|
124 | + $summary = $this->divisions->generateSummary($this->summaries[$policy[0]]); |
|
125 | 125 | } |
126 | 126 | $this->positions[] = array( |
127 | 127 | 'policy_id' => $policy[0], |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $this->summaries = isset($options['summaries']) ? $options['summaries'] : array(); |
64 | 64 | $this->divisions = new \MySociety\TheyWorkForYou\Divisions($member); |
65 | 65 | |
66 | - $limit = isset($options['limit']) ? $options['limit'] : NULL; |
|
66 | + $limit = isset($options['limit']) ? $options['limit'] : null; |
|
67 | 67 | |
68 | 68 | // Do the actual getting of positions |
69 | 69 | $this->getMemberPolicyPositions($limit); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param int $limit The number of results to limit the output to. |
78 | 78 | */ |
79 | 79 | |
80 | - private function getMemberPolicyPositions ($limit = NULL) { |
|
80 | + private function getMemberPolicyPositions ($limit = null) { |
|
81 | 81 | |
82 | 82 | // Make sure member info has actually been set. |
83 | 83 | if (count($this->member->extra_info) === 0) { |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $member_houses = $this->member->houses(); |
90 | 90 | |
91 | 91 | // Determine the policy limit. |
92 | - if ($limit !== NULL AND is_int($limit)) |
|
92 | + if ($limit !== null and is_int($limit)) |
|
93 | 93 | { |
94 | 94 | $policy_limit = $limit; |
95 | 95 | } else { |
@@ -208,12 +208,12 @@ discard block |
||
208 | 208 | $current_member = $this->member->current_member(); |
209 | 209 | |
210 | 210 | if (count($this->policies) > 0) { |
211 | - if (in_array(HOUSE_TYPE_COMMONS, $member_houses) AND |
|
211 | + if (in_array(HOUSE_TYPE_COMMONS, $member_houses) and |
|
212 | 212 | $entered_house[HOUSE_TYPE_COMMONS]['date'] > '2001-06-07' |
213 | 213 | ) { |
214 | 214 | $since = ''; |
215 | - } elseif (!in_array(HOUSE_TYPE_COMMONS, $member_houses) AND |
|
216 | - in_array(HOUSE_TYPE_LORDS, $member_houses) AND |
|
215 | + } elseif (!in_array(HOUSE_TYPE_COMMONS, $member_houses) and |
|
216 | + in_array(HOUSE_TYPE_LORDS, $member_houses) and |
|
217 | 217 | $entered_house[HOUSE_TYPE_LORDS]['date'] > '2001-06-07' |
218 | 218 | ) { |
219 | 219 | $since = ''; |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | $since = ' since 2001'; |
224 | 224 | } |
225 | 225 | # If not current MP/Lord, but current MLA/MSP, need to say voting record is when MP |
226 | - if (!$current_member[HOUSE_TYPE_COMMONS] AND |
|
227 | - !$current_member[HOUSE_TYPE_LORDS] AND |
|
228 | - ( $current_member[HOUSE_TYPE_SCOTLAND] OR $current_member[HOUSE_TYPE_NI] ) |
|
226 | + if (!$current_member[HOUSE_TYPE_COMMONS] and |
|
227 | + !$current_member[HOUSE_TYPE_LORDS] and |
|
228 | + ( $current_member[HOUSE_TYPE_SCOTLAND] or $current_member[HOUSE_TYPE_NI] ) |
|
229 | 229 | ) { |
230 | 230 | $since .= ' whilst an MP'; |
231 | 231 | } |
@@ -246,10 +246,10 @@ discard block |
||
246 | 246 | '" title="At The Guardian">well-known issues</a> <small>(from the Guardian)</small>'; |
247 | 247 | } |
248 | 248 | if ( |
249 | - ( isset($extra_info['public_whip_division_attendance']) AND |
|
249 | + ( isset($extra_info['public_whip_division_attendance']) and |
|
250 | 250 | $extra_info['public_whip_division_attendance'] != 'n/a' ) |
251 | - OR |
|
252 | - ( isset($extra_info['Lpublic_whip_division_attendance']) AND |
|
251 | + or |
|
252 | + ( isset($extra_info['Lpublic_whip_division_attendance']) and |
|
253 | 253 | $extra_info['Lpublic_whip_division_attendance'] != 'n/a' ) |
254 | 254 | ) { |
255 | 255 | $record[] = '<a href="http://www.publicwhip.org.uk/mp.php?id=uk.org.publicwhip/member/' . |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param int $limit The number of results to limit the output to. |
78 | 78 | */ |
79 | 79 | |
80 | - private function getMemberPolicyPositions ($limit = NULL) { |
|
80 | + private function getMemberPolicyPositions($limit = NULL) { |
|
81 | 81 | |
82 | 82 | // Make sure member info has actually been set. |
83 | 83 | if (count($this->member->extra_info) === 0) { |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | |
113 | 113 | // don't return votes where they haven't voted on a strong division |
114 | 114 | // if we're limiting the number of votes |
115 | - if ( $limit && !empty($dream_info) && !$dream_info['has_strong'] ) { |
|
115 | + if ($limit && !empty($dream_info) && !$dream_info['has_strong']) { |
|
116 | 116 | continue; |
117 | 117 | } |
118 | 118 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | |
146 | 146 | } else { |
147 | 147 | // We're over the policy limit, no sense still going, break out of the foreach. |
148 | - break ; |
|
148 | + break; |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * |
175 | 175 | */ |
176 | 176 | |
177 | - private function displayDreamComparison($dreamid, $policy_description, $inverse=false) { |
|
177 | + private function displayDreamComparison($dreamid, $policy_description, $inverse = false) { |
|
178 | 178 | $out = array(); |
179 | 179 | |
180 | 180 | $extra_info = $this->member->extra_info(); |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $has_strong = 1; |
195 | 195 | } |
196 | 196 | $full_sentence = $consistency . ' ' . $policy_description; |
197 | - $out = array( 'full_sentence' => $full_sentence, 'score' => $dmpscore, 'position' => $consistency, 'has_strong' => $has_strong ); |
|
197 | + $out = array('full_sentence' => $full_sentence, 'score' => $dmpscore, 'position' => $consistency, 'has_strong' => $has_strong); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | return $out; |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | # If not current MP/Lord, but current MLA/MSP, need to say voting record is when MP |
226 | 226 | if (!$current_member[HOUSE_TYPE_COMMONS] AND |
227 | 227 | !$current_member[HOUSE_TYPE_LORDS] AND |
228 | - ( $current_member[HOUSE_TYPE_SCOTLAND] OR $current_member[HOUSE_TYPE_NI] ) |
|
228 | + ($current_member[HOUSE_TYPE_SCOTLAND] OR $current_member[HOUSE_TYPE_NI]) |
|
229 | 229 | ) { |
230 | 230 | $since .= ' whilst an MP'; |
231 | 231 | } |
@@ -246,11 +246,11 @@ discard block |
||
246 | 246 | '" title="At The Guardian">well-known issues</a> <small>(from the Guardian)</small>'; |
247 | 247 | } |
248 | 248 | if ( |
249 | - ( isset($extra_info['public_whip_division_attendance']) AND |
|
250 | - $extra_info['public_whip_division_attendance'] != 'n/a' ) |
|
249 | + (isset($extra_info['public_whip_division_attendance']) AND |
|
250 | + $extra_info['public_whip_division_attendance'] != 'n/a') |
|
251 | 251 | OR |
252 | - ( isset($extra_info['Lpublic_whip_division_attendance']) AND |
|
253 | - $extra_info['Lpublic_whip_division_attendance'] != 'n/a' ) |
|
252 | + (isset($extra_info['Lpublic_whip_division_attendance']) AND |
|
253 | + $extra_info['Lpublic_whip_division_attendance'] != 'n/a') |
|
254 | 254 | ) { |
255 | 255 | $record[] = '<a href="http://www.publicwhip.org.uk/mp.php?id=uk.org.publicwhip/member/' . |
256 | 256 | $this->member->member_id() . |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | $member_houses = $this->member->houses(); |
90 | 90 | |
91 | 91 | // Determine the policy limit. |
92 | - if ($limit !== NULL AND is_int($limit)) |
|
93 | - { |
|
92 | + if ($limit !== NULL AND is_int($limit)) { |
|
94 | 93 | $policy_limit = $limit; |
95 | - } else { |
|
94 | + } |
|
95 | + else { |
|
96 | 96 | $policy_limit = count($policies); |
97 | 97 | } |
98 | 98 | |
@@ -105,8 +105,9 @@ discard block |
||
105 | 105 | foreach ($policies as $policy) { |
106 | 106 | // Are we still within the policy limit? |
107 | 107 | if ($i < $policy_limit) { |
108 | - if (isset($policy[2]) && $policy[2] && !in_array(HOUSE_TYPE_COMMONS, $member_houses)) |
|
109 | - continue; |
|
108 | + if (isset($policy[2]) && $policy[2] && !in_array(HOUSE_TYPE_COMMONS, $member_houses)) { |
|
109 | + continue; |
|
110 | + } |
|
110 | 111 | |
111 | 112 | $dream_info = $this->displayDreamComparison($policy[0], $policy[1]); |
112 | 113 | |
@@ -143,7 +144,8 @@ discard block |
||
143 | 144 | $i++; |
144 | 145 | } |
145 | 146 | |
146 | - } else { |
|
147 | + } |
|
148 | + else { |
|
147 | 149 | // We're over the policy limit, no sense still going, break out of the foreach. |
148 | 150 | break ; |
149 | 151 | } |
@@ -183,10 +185,12 @@ discard block |
||
183 | 185 | if ($extra_info["public_whip_dreammp${dreamid}_both_voted"] == 0) { |
184 | 186 | $consistency = 'has never voted on'; |
185 | 187 | $dmpscore = -1; |
186 | - } else { |
|
188 | + } |
|
189 | + else { |
|
187 | 190 | $dmpscore = floatval($extra_info["public_whip_dreammp${dreamid}_distance"]); |
188 | - if ($inverse) |
|
189 | - $dmpscore = 1.0 - $dmpscore; |
|
191 | + if ($inverse) { |
|
192 | + $dmpscore = 1.0 - $dmpscore; |
|
193 | + } |
|
190 | 194 | $consistency = score_to_strongly($dmpscore); |
191 | 195 | } |
192 | 196 | $has_strong = 0; |
@@ -212,14 +216,17 @@ discard block |
||
212 | 216 | $entered_house[HOUSE_TYPE_COMMONS]['date'] > '2001-06-07' |
213 | 217 | ) { |
214 | 218 | $since = ''; |
215 | - } elseif (!in_array(HOUSE_TYPE_COMMONS, $member_houses) AND |
|
219 | + } |
|
220 | + elseif (!in_array(HOUSE_TYPE_COMMONS, $member_houses) AND |
|
216 | 221 | in_array(HOUSE_TYPE_LORDS, $member_houses) AND |
217 | 222 | $entered_house[HOUSE_TYPE_LORDS]['date'] > '2001-06-07' |
218 | 223 | ) { |
219 | 224 | $since = ''; |
220 | - } elseif ($this->member->isDead()) { |
|
225 | + } |
|
226 | + elseif ($this->member->isDead()) { |
|
221 | 227 | $since = ''; |
222 | - } else { |
|
228 | + } |
|
229 | + else { |
|
223 | 230 | $since = ' since 2001'; |
224 | 231 | } |
225 | 232 | # If not current MP/Lord, but current MLA/MSP, need to say voting record is when MP |
@@ -259,7 +266,8 @@ discard block |
||
259 | 266 | |
260 | 267 | if (count($record) > 0) { |
261 | 268 | return 'More on ' . implode(' & ', $record); |
262 | - } else { |
|
269 | + } |
|
270 | + else { |
|
263 | 271 | return ''; |
264 | 272 | } |
265 | 273 | } |
@@ -489,6 +489,10 @@ discard block |
||
489 | 489 | public function house_text($house) { |
490 | 490 | return $this->houses_pretty[$house]; |
491 | 491 | } |
492 | + |
|
493 | + /** |
|
494 | + * @return string |
|
495 | + */ |
|
492 | 496 | public function constituency() { return $this->constituency; } |
493 | 497 | public function party() { return $this->party; } |
494 | 498 | public function party_text($party = null) { |
@@ -607,6 +611,9 @@ discard block |
||
607 | 611 | } |
608 | 612 | } |
609 | 613 | |
614 | + /** |
|
615 | + * @param string $direction |
|
616 | + */ |
|
610 | 617 | private function _previous_future_mps_query($direction) { |
611 | 618 | $entered_house = $this->entered_house(HOUSE_TYPE_COMMONS); |
612 | 619 | if (is_null($entered_house)) return ''; |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | $this->extra_info = array(); |
363 | 363 | |
364 | 364 | $q = $this->db->query('SELECT * FROM moffice WHERE person=:person_id ORDER BY from_date DESC, moffice_id', |
365 | - array(':person_id' => $this->person_id)); |
|
365 | + array(':person_id' => $this->person_id)); |
|
366 | 366 | for ($row=0; $row<$q->rows(); $row++) { |
367 | 367 | $this->extra_info['office'][] = $q->row($row); |
368 | 368 | } |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | $q = $this->db->query('select bill_id,session,title,sum(attending) as a,sum(chairman) as c |
451 | 451 | from pbc_members, bills |
452 | 452 | where bill_id = bills.id and person_id = ' . $this->person_id() |
453 | - . ' group by bill_id order by session desc'); |
|
453 | + . ' group by bill_id order by session desc'); |
|
454 | 454 | $this->extra_info['pbc'] = array(); |
455 | 455 | for ($i=0; $i<$q->rows(); $i++) { |
456 | 456 | $bill_id = $q->field($i, 'bill_id'); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -include_once INCLUDESPATH."easyparliament/glossary.php"; |
|
3 | +include_once INCLUDESPATH . "easyparliament/glossary.php"; |
|
4 | 4 | |
5 | 5 | class MEMBER { |
6 | 6 | |
@@ -112,15 +112,15 @@ discard block |
||
112 | 112 | |
113 | 113 | $this->house_disp = 0; |
114 | 114 | $last_party = null; |
115 | - for ($row=0; $row<$q->rows(); $row++) { |
|
115 | + for ($row = 0; $row < $q->rows(); $row++) { |
|
116 | 116 | $house = $q->field($row, 'house'); |
117 | 117 | if (!in_array($house, $this->houses)) $this->houses[] = $house; |
118 | 118 | $const = $q->field($row, 'constituency'); |
119 | - $party = $q->field($row, 'party'); |
|
120 | - $entered_house = $q->field($row, 'entered_house'); |
|
121 | - $left_house = $q->field($row, 'left_house'); |
|
122 | - $entered_reason = $q->field($row, 'entered_reason'); |
|
123 | - $left_reason = $q->field($row, 'left_reason'); |
|
119 | + $party = $q->field($row, 'party'); |
|
120 | + $entered_house = $q->field($row, 'entered_house'); |
|
121 | + $left_house = $q->field($row, 'left_house'); |
|
122 | + $entered_reason = $q->field($row, 'entered_reason'); |
|
123 | + $left_reason = $q->field($row, 'left_reason'); |
|
124 | 124 | |
125 | 125 | if (!isset($this->entered_house[$house]) || $entered_house < $this->entered_house[$house]['date']) { |
126 | 126 | $this->entered_house[$house] = array( |
@@ -140,22 +140,22 @@ discard block |
||
140 | 140 | ); |
141 | 141 | } |
142 | 142 | |
143 | - if ( $house==HOUSE_TYPE_ROYAL # The Monarch |
|
144 | - || (!$this->house_disp && $house==HOUSE_TYPE_SCOTLAND) # MSPs and |
|
145 | - || (!$this->house_disp && $house==HOUSE_TYPE_NI) # MLAs have lowest priority |
|
146 | - || ($this->house_disp!=HOUSE_TYPE_LORDS && $house==HOUSE_TYPE_LORDS) # Lords have highest priority |
|
147 | - || (!$this->house_disp && $house==HOUSE_TYPE_COMMONS) # MPs |
|
143 | + if ($house == HOUSE_TYPE_ROYAL # The Monarch |
|
144 | + || (!$this->house_disp && $house == HOUSE_TYPE_SCOTLAND) # MSPs and |
|
145 | + || (!$this->house_disp && $house == HOUSE_TYPE_NI) # MLAs have lowest priority |
|
146 | + || ($this->house_disp != HOUSE_TYPE_LORDS && $house == HOUSE_TYPE_LORDS) # Lords have highest priority |
|
147 | + || (!$this->house_disp && $house == HOUSE_TYPE_COMMONS) # MPs |
|
148 | 148 | ) { |
149 | 149 | $this->house_disp = $house; |
150 | 150 | $this->constituency = $const; |
151 | 151 | $this->party = $party; |
152 | 152 | |
153 | - $this->member_id = $q->field($row, 'member_id'); |
|
154 | - $this->title = $q->field($row, 'title'); |
|
153 | + $this->member_id = $q->field($row, 'member_id'); |
|
154 | + $this->title = $q->field($row, 'title'); |
|
155 | 155 | $this->given_name = $q->field($row, 'given_name'); |
156 | 156 | $this->family_name = $q->field($row, 'family_name'); |
157 | 157 | $this->lordofname = $q->field($row, 'lordofname'); |
158 | - $this->person_id = $q->field($row, 'person_id'); |
|
158 | + $this->person_id = $q->field($row, 'person_id'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | if (($last_party && $party && $party != $last_party) || $left_reason == 'changed_party') { |
@@ -199,13 +199,13 @@ discard block |
||
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
202 | - public function postcode_to_person_id($postcode, $house=null) { |
|
203 | - twfy_debug ('MP', "postcode_to_person_id converting postcode to person"); |
|
202 | + public function postcode_to_person_id($postcode, $house = null) { |
|
203 | + twfy_debug('MP', "postcode_to_person_id converting postcode to person"); |
|
204 | 204 | $constituency = strtolower(MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituency($postcode)); |
205 | 205 | return $this->constituency_to_person_id($constituency, $house); |
206 | 206 | } |
207 | 207 | |
208 | - public function constituency_to_person_id($constituency, $house=null) { |
|
208 | + public function constituency_to_person_id($constituency, $house = null) { |
|
209 | 209 | if ($constituency == '') { |
210 | 210 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, no constituency was found.'); |
211 | 211 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
247 | - public function name_to_person_id($name, $const='') { |
|
247 | + public function name_to_person_id($name, $const = '') { |
|
248 | 248 | global $this_page; |
249 | 249 | if ($name == '') { |
250 | 250 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, no name was found.'); |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | |
295 | 295 | # More than one person ID matching the given name |
296 | 296 | $person_ids = array(); |
297 | - for ($i=0; $i<$q->rows; ++$i) { |
|
297 | + for ($i = 0; $i < $q->rows; ++$i) { |
|
298 | 298 | $pid = $q->field($i, 'person_id'); |
299 | 299 | $person_ids[$pid] = 1; |
300 | 300 | } |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | $q = $this->db->query($q, $params); |
325 | 325 | if ($q->rows > 1) { |
326 | 326 | $person_ids = array(); |
327 | - for ($i=0; $i<$q->rows(); ++$i) { |
|
327 | + for ($i = 0; $i < $q->rows(); ++$i) { |
|
328 | 328 | $person_ids[$q->field($i, 'person_id')] = $q->field($i, 'constituency'); |
329 | 329 | } |
330 | 330 | throw new MySociety\TheyWorkForYou\MemberMultipleException($person_ids); |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | global $THEUSER; |
343 | 343 | if (is_object($THEUSER) && $THEUSER->postcode_is_set() && $this->current_member(1)) { |
344 | 344 | $pc = $THEUSER->postcode(); |
345 | - twfy_debug ('MP', "set_users_mp converting postcode to person"); |
|
345 | + twfy_debug('MP', "set_users_mp converting postcode to person"); |
|
346 | 346 | $constituency = strtolower(MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituency($pc)); |
347 | 347 | if ($constituency == strtolower($this->constituency())) { |
348 | 348 | $this->the_users_mp = true; |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | |
364 | 364 | $q = $this->db->query('SELECT * FROM moffice WHERE person=:person_id ORDER BY from_date DESC, moffice_id', |
365 | 365 | array(':person_id' => $this->person_id)); |
366 | - for ($row=0; $row<$q->rows(); $row++) { |
|
366 | + for ($row = 0; $row < $q->rows(); $row++) { |
|
367 | 367 | $this->extra_info['office'][] = $q->row($row); |
368 | 368 | } |
369 | 369 | |
@@ -418,9 +418,9 @@ discard block |
||
418 | 418 | |
419 | 419 | if (isset($this->extra_info['public_whip_attendrank'])) { |
420 | 420 | $prefix = ($this->house(HOUSE_TYPE_LORDS) ? 'L' : ''); |
421 | - $this->extra_info[$prefix.'public_whip_division_attendance_rank'] = $this->extra_info['public_whip_attendrank']; |
|
422 | - $this->extra_info[$prefix.'public_whip_division_attendance_rank_outof'] = $this->extra_info['public_whip_attendrank_outof']; |
|
423 | - $this->extra_info[$prefix.'public_whip_division_attendance_quintile'] = floor($this->extra_info['public_whip_attendrank'] / ($this->extra_info['public_whip_attendrank_outof']+1) * 5); |
|
421 | + $this->extra_info[$prefix . 'public_whip_division_attendance_rank'] = $this->extra_info['public_whip_attendrank']; |
|
422 | + $this->extra_info[$prefix . 'public_whip_division_attendance_rank_outof'] = $this->extra_info['public_whip_attendrank_outof']; |
|
423 | + $this->extra_info[$prefix . 'public_whip_division_attendance_quintile'] = floor($this->extra_info['public_whip_attendrank'] / ($this->extra_info['public_whip_attendrank_outof'] + 1) * 5); |
|
424 | 424 | } |
425 | 425 | if ($this->house(HOUSE_TYPE_LORDS) && isset($this->extra_info['public_whip_division_attendance'])) { |
426 | 426 | $this->extra_info['Lpublic_whip_division_attendance'] = $this->extra_info['public_whip_division_attendance']; |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | } |
429 | 429 | |
430 | 430 | if ($display && array_key_exists('register_member_interests_html', $this->extra_info) && ($this->extra_info['register_member_interests_html'] != '')) { |
431 | - $args = array ( |
|
431 | + $args = array( |
|
432 | 432 | "sort" => "regexp_replace" |
433 | 433 | ); |
434 | 434 | $GLOSSARY = new GLOSSARY($args); |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | $GLOSSARY->glossarise($this->extra_info['register_member_interests_html']); |
437 | 437 | } |
438 | 438 | |
439 | - $q = $this->db->query('select count(*) as c from alerts where criteria like "%speaker:'.$this->person_id.'%" and confirmed and not deleted'); |
|
439 | + $q = $this->db->query('select count(*) as c from alerts where criteria like "%speaker:' . $this->person_id . '%" and confirmed and not deleted'); |
|
440 | 440 | $this->extra_info['number_of_alerts'] = $q->field(0, 'c'); |
441 | 441 | |
442 | 442 | if (isset($this->extra_info['reading_ease'])) { |
@@ -452,16 +452,16 @@ discard block |
||
452 | 452 | where bill_id = bills.id and person_id = ' . $this->person_id() |
453 | 453 | . ' group by bill_id order by session desc'); |
454 | 454 | $this->extra_info['pbc'] = array(); |
455 | - for ($i=0; $i<$q->rows(); $i++) { |
|
455 | + for ($i = 0; $i < $q->rows(); $i++) { |
|
456 | 456 | $bill_id = $q->field($i, 'bill_id'); |
457 | - $c = $this->db->query('select count(*) as c from hansard where major=6 and minor='.$bill_id.' and htype=10'); |
|
457 | + $c = $this->db->query('select count(*) as c from hansard where major=6 and minor=' . $bill_id . ' and htype=10'); |
|
458 | 458 | $c = $c->field(0, 'c'); |
459 | 459 | $title = $q->field($i, 'title'); |
460 | 460 | $attending = $q->field($i, 'a'); |
461 | 461 | $chairman = $q->field($i, 'c'); |
462 | 462 | $this->extra_info['pbc'][$bill_id] = array( |
463 | 463 | 'title' => $title, 'session' => $q->field($i, 'session'), |
464 | - 'attending'=>$attending, 'chairman'=>($chairman>0), 'outof' => $c |
|
464 | + 'attending'=>$attending, 'chairman'=>($chairman > 0), 'outof' => $c |
|
465 | 465 | ); |
466 | 466 | } |
467 | 467 | |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | public function family_name() { return $this->family_name; } |
477 | 477 | public function full_name($no_mp_title = false) { |
478 | 478 | $title = $this->title; |
479 | - if ($no_mp_title && ($this->house_disp==HOUSE_TYPE_COMMONS || $this->house_disp==HOUSE_TYPE_NI || $this->house_disp==HOUSE_TYPE_SCOTLAND)) |
|
479 | + if ($no_mp_title && ($this->house_disp == HOUSE_TYPE_COMMONS || $this->house_disp == HOUSE_TYPE_NI || $this->house_disp == HOUSE_TYPE_SCOTLAND)) |
|
480 | 480 | $title = ''; |
481 | 481 | return member_full_name($this->house_disp, $title, $this->given_name, $this->family_name, $this->lordofname); |
482 | 482 | } |
@@ -509,9 +509,9 @@ discard block |
||
509 | 509 | public function entered_house_text($entered_house) { |
510 | 510 | if (!$entered_house) return ''; |
511 | 511 | list($year, $month, $day) = explode('-', $entered_house); |
512 | - if ($month==1 && $day==1 && $this->house(HOUSE_TYPE_LORDS)) { |
|
512 | + if ($month == 1 && $day == 1 && $this->house(HOUSE_TYPE_LORDS)) { |
|
513 | 513 | return $year; |
514 | - } elseif ($month==0 && $day==0) { |
|
514 | + } elseif ($month == 0 && $day == 0) { |
|
515 | 515 | return $year; |
516 | 516 | } elseif (checkdate($month, $day, $year) && $year != '9999') { |
517 | 517 | return format_date($entered_house, LONGDATEFORMAT); |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | list($year, $month, $day) = explode('-', $left_house); |
532 | 532 | if (checkdate($month, $day, $year) && $year != '9999') { |
533 | 533 | return format_date($left_house, LONGDATEFORMAT); |
534 | - } elseif ($month==0 && $day==0) { |
|
534 | + } elseif ($month == 0 && $day == 0) { |
|
535 | 535 | # Left house date is stored as 1942-00-00 to mean "at some point in 1941" |
536 | 536 | return $year - 1; |
537 | 537 | } else { |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | $name = $q->field($r, 'given_name') . ' ' . $q->field($r, 'family_name'); |
634 | 634 | if ($last_pid != $pid) { |
635 | 635 | $mships[] = array( |
636 | - 'href' => WEBPATH . 'mp/?pid='.$pid, |
|
636 | + 'href' => WEBPATH . 'mp/?pid=' . $pid, |
|
637 | 637 | 'text' => $name |
638 | 638 | ); |
639 | 639 | $last_pid = $pid; |
@@ -71,15 +71,19 @@ discard block |
||
71 | 71 | $person_id = ''; |
72 | 72 | if (isset($args['member_id']) && is_numeric($args['member_id'])) { |
73 | 73 | $person_id = $this->member_id_to_person_id($args['member_id']); |
74 | - } elseif (isset($args['name'])) { |
|
74 | + } |
|
75 | + elseif (isset($args['name'])) { |
|
75 | 76 | $con = isset($args['constituency']) ? $args['constituency'] : ''; |
76 | 77 | $person_id = $this->name_to_person_id($args['name'], $con); |
77 | - } elseif (isset($args['constituency'])) { |
|
78 | + } |
|
79 | + elseif (isset($args['constituency'])) { |
|
78 | 80 | $still_in_office = isset($args['still_in_office']) ? $args['still_in_office'] : false; |
79 | 81 | $person_id = $this->constituency_to_person_id($args['constituency'], $house, $still_in_office); |
80 | - } elseif (isset($args['postcode'])) { |
|
82 | + } |
|
83 | + elseif (isset($args['postcode'])) { |
|
81 | 84 | $person_id = $this->postcode_to_person_id($args['postcode'], $house); |
82 | - } elseif (isset($args['person_id']) && is_numeric($args['person_id'])) { |
|
85 | + } |
|
86 | + elseif (isset($args['person_id']) && is_numeric($args['person_id'])) { |
|
83 | 87 | $person_id = $args['person_id']; |
84 | 88 | $q = $this->db->query("SELECT gid_to FROM gidredirect |
85 | 89 | WHERE gid_from = :gid_from", |
@@ -114,7 +118,9 @@ discard block |
||
114 | 118 | $last_party = null; |
115 | 119 | for ($row=0; $row<$q->rows(); $row++) { |
116 | 120 | $house = $q->field($row, 'house'); |
117 | - if (!in_array($house, $this->houses)) $this->houses[] = $house; |
|
121 | + if (!in_array($house, $this->houses)) { |
|
122 | + $this->houses[] = $house; |
|
123 | + } |
|
118 | 124 | $const = $q->field($row, 'constituency'); |
119 | 125 | $party = $q->field($row, 'party'); |
120 | 126 | $entered_house = $q->field($row, 'entered_house'); |
@@ -194,7 +200,8 @@ discard block |
||
194 | 200 | } |
195 | 201 | if ($q->rows > 0) { |
196 | 202 | return $q->field(0, 'person_id'); |
197 | - } else { |
|
203 | + } |
|
204 | + else { |
|
198 | 205 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, there is no member with a member ID of "' . _htmlentities($member_id) . '".'); |
199 | 206 | } |
200 | 207 | } |
@@ -215,7 +222,9 @@ discard block |
||
215 | 222 | } |
216 | 223 | |
217 | 224 | $normalised = MySociety\TheyWorkForYou\Utility\Constituencies::normaliseConstituencyName($constituency); |
218 | - if ($normalised) $constituency = $normalised; |
|
225 | + if ($normalised) { |
|
226 | + $constituency = $normalised; |
|
227 | + } |
|
219 | 228 | |
220 | 229 | $params = array(); |
221 | 230 | |
@@ -239,7 +248,8 @@ discard block |
||
239 | 248 | |
240 | 249 | if ($q->rows > 0) { |
241 | 250 | return $q->field(0, 'person_id'); |
242 | - } else { |
|
251 | + } |
|
252 | + else { |
|
243 | 253 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, there is no current member for the "' . _htmlentities(ucwords($constituency)) . '" constituency.'); |
244 | 254 | } |
245 | 255 | } |
@@ -254,10 +264,12 @@ discard block |
||
254 | 264 | $q = "SELECT person_id FROM person_names WHERE type = 'name' "; |
255 | 265 | if ($this_page == 'peer') { |
256 | 266 | $success = preg_match('#^(.*?) (.*?) of (.*?)$#', $name, $m); |
257 | - if (!$success) |
|
258 | - $success = preg_match('#^(.*?)() of (.*?)$#', $name, $m); |
|
259 | - if (!$success) |
|
260 | - $success = preg_match('#^(.*?) (.*?)()$#', $name, $m); |
|
267 | + if (!$success) { |
|
268 | + $success = preg_match('#^(.*?)() of (.*?)$#', $name, $m); |
|
269 | + } |
|
270 | + if (!$success) { |
|
271 | + $success = preg_match('#^(.*?) (.*?)()$#', $name, $m); |
|
272 | + } |
|
261 | 273 | if (!$success) { |
262 | 274 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, that name was not recognised.'); |
263 | 275 | } |
@@ -265,10 +277,12 @@ discard block |
||
265 | 277 | $params[':family_name'] = $m[2]; |
266 | 278 | $params[':lordofname'] = $m[3]; |
267 | 279 | $q .= "AND title = :title AND family_name = :family_name AND lordofname = :lordofname"; |
268 | - } elseif ($this_page == 'msp' || $this_page == 'mla' || strstr($this_page, 'mp')) { |
|
280 | + } |
|
281 | + elseif ($this_page == 'msp' || $this_page == 'mla' || strstr($this_page, 'mp')) { |
|
269 | 282 | $success = preg_match('#^(.*?) (.*?) (.*?)$#', $name, $m); |
270 | - if (!$success) |
|
271 | - $success = preg_match('#^(.*?)() (.*)$#', $name, $m); |
|
283 | + if (!$success) { |
|
284 | + $success = preg_match('#^(.*?)() (.*)$#', $name, $m); |
|
285 | + } |
|
272 | 286 | if (!$success) { |
273 | 287 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, that name was not recognised.'); |
274 | 288 | } |
@@ -288,7 +302,8 @@ discard block |
||
288 | 302 | $q = $this->db->query($q, $params); |
289 | 303 | if (!$q->rows) { |
290 | 304 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, we could not find anyone with that name.'); |
291 | - } elseif ($q->rows == 1) { |
|
305 | + } |
|
306 | + elseif ($q->rows == 1) { |
|
292 | 307 | return $q->field(0, 'person_id'); |
293 | 308 | } |
294 | 309 | |
@@ -303,13 +318,17 @@ discard block |
||
303 | 318 | $params = array(); |
304 | 319 | if ($this_page == 'peer') { |
305 | 320 | $params[':house'] = HOUSE_TYPE_LORDS; |
306 | - } elseif ($this_page == 'msp') { |
|
321 | + } |
|
322 | + elseif ($this_page == 'msp') { |
|
307 | 323 | $params[':house'] = HOUSE_TYPE_SCOTLAND; |
308 | - } elseif ($this_page == 'mla') { |
|
324 | + } |
|
325 | + elseif ($this_page == 'mla') { |
|
309 | 326 | $params[':house'] = HOUSE_TYPE_NI; |
310 | - } elseif ($this_page == 'royal') { |
|
327 | + } |
|
328 | + elseif ($this_page == 'royal') { |
|
311 | 329 | $params[':house'] = HOUSE_TYPE_ROYAL; |
312 | - } else { |
|
330 | + } |
|
331 | + else { |
|
313 | 332 | $params[':house'] = HOUSE_TYPE_COMMONS; |
314 | 333 | } |
315 | 334 | |
@@ -328,11 +347,14 @@ discard block |
||
328 | 347 | $person_ids[$q->field($i, 'person_id')] = $q->field($i, 'constituency'); |
329 | 348 | } |
330 | 349 | throw new MySociety\TheyWorkForYou\MemberMultipleException($person_ids); |
331 | - } elseif ($q->rows > 0) { |
|
350 | + } |
|
351 | + elseif ($q->rows > 0) { |
|
332 | 352 | return $q->field(0, 'person_id'); |
333 | - } elseif ($const) { |
|
353 | + } |
|
354 | + elseif ($const) { |
|
334 | 355 | return $this->name_to_person_id($name); |
335 | - } else { |
|
356 | + } |
|
357 | + else { |
|
336 | 358 | throw new MySociety\TheyWorkForYou\MemberException('Sorry, there is no current member with that name.'); |
337 | 359 | } |
338 | 360 | } |
@@ -403,16 +425,21 @@ discard block |
||
403 | 425 | if (array_key_exists('public_whip_rebellions', $this->extra_info)) { |
404 | 426 | $rebellions = $this->extra_info['public_whip_rebellions']; |
405 | 427 | $rebel_desc = "<unknown>"; |
406 | - if ($rebellions == 0) |
|
407 | - $rebel_desc = "never"; |
|
408 | - elseif ($rebellions <= 1) |
|
409 | - $rebel_desc = "hardly ever"; |
|
410 | - elseif ($rebellions <= 3) |
|
411 | - $rebel_desc = "occasionally"; |
|
412 | - elseif ($rebellions <= 5) |
|
413 | - $rebel_desc = "sometimes"; |
|
414 | - elseif ($rebellions > 5) |
|
415 | - $rebel_desc = "quite often"; |
|
428 | + if ($rebellions == 0) { |
|
429 | + $rebel_desc = "never"; |
|
430 | + } |
|
431 | + elseif ($rebellions <= 1) { |
|
432 | + $rebel_desc = "hardly ever"; |
|
433 | + } |
|
434 | + elseif ($rebellions <= 3) { |
|
435 | + $rebel_desc = "occasionally"; |
|
436 | + } |
|
437 | + elseif ($rebellions <= 5) { |
|
438 | + $rebel_desc = "sometimes"; |
|
439 | + } |
|
440 | + elseif ($rebellions > 5) { |
|
441 | + $rebel_desc = "quite often"; |
|
442 | + } |
|
416 | 443 | $this->extra_info['public_whip_rebel_description'] = $rebel_desc; |
417 | 444 | } |
418 | 445 | |
@@ -476,8 +503,9 @@ discard block |
||
476 | 503 | public function family_name() { return $this->family_name; } |
477 | 504 | public function full_name($no_mp_title = false) { |
478 | 505 | $title = $this->title; |
479 | - if ($no_mp_title && ($this->house_disp==HOUSE_TYPE_COMMONS || $this->house_disp==HOUSE_TYPE_NI || $this->house_disp==HOUSE_TYPE_SCOTLAND)) |
|
480 | - $title = ''; |
|
506 | + if ($no_mp_title && ($this->house_disp==HOUSE_TYPE_COMMONS || $this->house_disp==HOUSE_TYPE_NI || $this->house_disp==HOUSE_TYPE_SCOTLAND)) { |
|
507 | + $title = ''; |
|
508 | + } |
|
481 | 509 | return member_full_name($this->house_disp, $title, $this->given_name, $this->family_name, $this->lordofname); |
482 | 510 | } |
483 | 511 | public function houses() { |
@@ -493,48 +521,62 @@ discard block |
||
493 | 521 | public function party() { return $this->party; } |
494 | 522 | public function party_text($party = null) { |
495 | 523 | global $parties; |
496 | - if (!$party) |
|
497 | - $party = $this->party; |
|
524 | + if (!$party) { |
|
525 | + $party = $this->party; |
|
526 | + } |
|
498 | 527 | if (isset($parties[$party])) { |
499 | 528 | return $parties[$party]; |
500 | - } else { |
|
529 | + } |
|
530 | + else { |
|
501 | 531 | return $party; |
502 | 532 | } |
503 | 533 | } |
504 | 534 | |
505 | 535 | public function entered_house($house = 0) { |
506 | - if ($house) return array_key_exists($house, $this->entered_house) ? $this->entered_house[$house] : null; |
|
536 | + if ($house) { |
|
537 | + return array_key_exists($house, $this->entered_house) ? $this->entered_house[$house] : null; |
|
538 | + } |
|
507 | 539 | return $this->entered_house; |
508 | 540 | } |
509 | 541 | public function entered_house_text($entered_house) { |
510 | - if (!$entered_house) return ''; |
|
542 | + if (!$entered_house) { |
|
543 | + return ''; |
|
544 | + } |
|
511 | 545 | list($year, $month, $day) = explode('-', $entered_house); |
512 | 546 | if ($month==1 && $day==1 && $this->house(HOUSE_TYPE_LORDS)) { |
513 | 547 | return $year; |
514 | - } elseif ($month==0 && $day==0) { |
|
548 | + } |
|
549 | + elseif ($month==0 && $day==0) { |
|
515 | 550 | return $year; |
516 | - } elseif (checkdate($month, $day, $year) && $year != '9999') { |
|
551 | + } |
|
552 | + elseif (checkdate($month, $day, $year) && $year != '9999') { |
|
517 | 553 | return format_date($entered_house, LONGDATEFORMAT); |
518 | - } else { |
|
554 | + } |
|
555 | + else { |
|
519 | 556 | return "n/a"; |
520 | 557 | } |
521 | 558 | } |
522 | 559 | |
523 | 560 | public function left_house($house = null) { |
524 | - if (!is_null($house)) |
|
525 | - return array_key_exists($house, $this->left_house) ? $this->left_house[$house] : null; |
|
561 | + if (!is_null($house)) { |
|
562 | + return array_key_exists($house, $this->left_house) ? $this->left_house[$house] : null; |
|
563 | + } |
|
526 | 564 | return $this->left_house; |
527 | 565 | } |
528 | 566 | |
529 | 567 | public function left_house_text($left_house) { |
530 | - if (!$left_house) return ''; |
|
568 | + if (!$left_house) { |
|
569 | + return ''; |
|
570 | + } |
|
531 | 571 | list($year, $month, $day) = explode('-', $left_house); |
532 | 572 | if (checkdate($month, $day, $year) && $year != '9999') { |
533 | 573 | return format_date($left_house, LONGDATEFORMAT); |
534 | - } elseif ($month==0 && $day==0) { |
|
574 | + } |
|
575 | + elseif ($month==0 && $day==0) { |
|
535 | 576 | # Left house date is stored as 1942-00-00 to mean "at some point in 1941" |
536 | 577 | return $year - 1; |
537 | - } else { |
|
578 | + } |
|
579 | + else { |
|
538 | 580 | return "n/a"; |
539 | 581 | } |
540 | 582 | } |
@@ -543,7 +585,8 @@ discard block |
||
543 | 585 | public function entered_reason_text($entered_reason) { |
544 | 586 | if (isset($this->reasons[$entered_reason])) { |
545 | 587 | return $this->reasons[$entered_reason]; |
546 | - } else { |
|
588 | + } |
|
589 | + else { |
|
547 | 590 | return $entered_reason; |
548 | 591 | } |
549 | 592 | } |
@@ -557,13 +600,16 @@ discard block |
||
557 | 600 | $max = $q->field(0, 'max'); |
558 | 601 | if ($max == $left_house) { |
559 | 602 | return $left_reason[0]; |
560 | - } else { |
|
603 | + } |
|
604 | + else { |
|
561 | 605 | return $left_reason[1]; |
562 | 606 | } |
563 | - } else { |
|
607 | + } |
|
608 | + else { |
|
564 | 609 | return $left_reason; |
565 | 610 | } |
566 | - } else { |
|
611 | + } |
|
612 | + else { |
|
567 | 613 | return $left_reason; |
568 | 614 | } |
569 | 615 | } |
@@ -576,7 +622,9 @@ discard block |
||
576 | 622 | $lh = $this->left_house($h); |
577 | 623 | $current[$h] = ($lh['date'] == '9999-12-31'); |
578 | 624 | } |
579 | - if ($house) return $current[$house]; |
|
625 | + if ($house) { |
|
626 | + return $current[$house]; |
|
627 | + } |
|
580 | 628 | return $current; |
581 | 629 | } |
582 | 630 | |
@@ -586,13 +634,17 @@ discard block |
||
586 | 634 | $house = $this->house_disp; |
587 | 635 | if ($house == HOUSE_TYPE_COMMONS) { |
588 | 636 | $URL = new URL('mp'); |
589 | - } elseif ($house == HOUSE_TYPE_LORDS) { |
|
637 | + } |
|
638 | + elseif ($house == HOUSE_TYPE_LORDS) { |
|
590 | 639 | $URL = new URL('peer'); |
591 | - } elseif ($house == HOUSE_TYPE_NI) { |
|
640 | + } |
|
641 | + elseif ($house == HOUSE_TYPE_NI) { |
|
592 | 642 | $URL = new URL('mla'); |
593 | - } elseif ($house == HOUSE_TYPE_SCOTLAND) { |
|
643 | + } |
|
644 | + elseif ($house == HOUSE_TYPE_SCOTLAND) { |
|
594 | 645 | $URL = new URL('msp'); |
595 | - } elseif ($house == HOUSE_TYPE_ROYAL) { |
|
646 | + } |
|
647 | + elseif ($house == HOUSE_TYPE_ROYAL) { |
|
596 | 648 | $URL = new URL('royal'); |
597 | 649 | } |
598 | 650 | $member_url = make_member_url($this->full_name(true), $this->constituency(), $house, $this->person_id()); |
@@ -602,17 +654,21 @@ discard block |
||
602 | 654 | $protocol = 'http://'; |
603 | 655 | } |
604 | 656 | return $protocol . DOMAIN . $URL->generate('none') . $member_url; |
605 | - } else { |
|
657 | + } |
|
658 | + else { |
|
606 | 659 | return $URL->generate('none') . $member_url; |
607 | 660 | } |
608 | 661 | } |
609 | 662 | |
610 | 663 | private function _previous_future_mps_query($direction) { |
611 | 664 | $entered_house = $this->entered_house(HOUSE_TYPE_COMMONS); |
612 | - if (is_null($entered_house)) return ''; |
|
665 | + if (is_null($entered_house)) { |
|
666 | + return ''; |
|
667 | + } |
|
613 | 668 | if ($direction == '>') { |
614 | 669 | $order = ''; |
615 | - } else { |
|
670 | + } |
|
671 | + else { |
|
616 | 672 | $order = 'DESC'; |
617 | 673 | } |
618 | 674 | $q = $this->db->query('SELECT * |
@@ -23,6 +23,9 @@ |
||
23 | 23 | return $this->fb; |
24 | 24 | } |
25 | 25 | |
26 | + /** |
|
27 | + * @return string |
|
28 | + */ |
|
26 | 29 | public function getLoginURL() { |
27 | 30 | $helper = $this->getFacebookObject()->getRedirectLoginHelper(); |
28 | 31 | $permissions = ['email']; |
@@ -13,11 +13,11 @@ discard block |
||
13 | 13 | |
14 | 14 | public function getFacebookObject() { |
15 | 15 | if (!isset($this->fb)) { |
16 | - $this->fb = new \Facebook\Facebook([ |
|
16 | + $this->fb = new \Facebook\Facebook([ |
|
17 | 17 | 'app_id' => FACEBOOK_APP_ID, |
18 | 18 | 'app_secret' => FACEBOOK_APP_SECRET, |
19 | 19 | 'default_graph_version' => 'v2.2', |
20 | - ]); |
|
20 | + ]); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | return $this->fb; |
@@ -30,46 +30,46 @@ discard block |
||
30 | 30 | } |
31 | 31 | |
32 | 32 | public function handleFacebookRedirect() { |
33 | - $helper = $this->getFacebookObject()->getRedirectLoginHelper(); |
|
33 | + $helper = $this->getFacebookObject()->getRedirectLoginHelper(); |
|
34 | 34 | |
35 | - $data = array('login_url' => $this->getLoginURL()); |
|
35 | + $data = array('login_url' => $this->getLoginURL()); |
|
36 | 36 | |
37 | - try { |
|
37 | + try { |
|
38 | 38 | $accessToken = $helper->getAccessToken(); |
39 | - } catch(\Facebook\Exceptions\FacebookResponseException $e) { |
|
39 | + } catch(\Facebook\Exceptions\FacebookResponseException $e) { |
|
40 | 40 | $data['error'] = 'Graph returned an error: ' . $e->getMessage(); |
41 | 41 | return $data; |
42 | - } catch(\Facebook\Exceptions\FacebookSDKException $e) { |
|
42 | + } catch(\Facebook\Exceptions\FacebookSDKException $e) { |
|
43 | 43 | $data['error'] = 'Facebook SDK returned an error: ' . $e->getMessage(); |
44 | 44 | return $data; |
45 | - } |
|
45 | + } |
|
46 | 46 | |
47 | - $token = $this->checkAccessToken($accessToken); |
|
47 | + $token = $this->checkAccessToken($accessToken); |
|
48 | 48 | |
49 | - if ($token) { |
|
50 | - return array('token' => $token); |
|
51 | - } else { |
|
52 | - $data['error'] = 'Problem getting Facebook token'; |
|
53 | - return $data; |
|
54 | - } |
|
49 | + if ($token) { |
|
50 | + return array('token' => $token); |
|
51 | + } else { |
|
52 | + $data['error'] = 'Problem getting Facebook token'; |
|
53 | + return $data; |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
58 | 58 | private function checkAccessToken($accessToken) { |
59 | - if (!isset($accessToken)) { |
|
60 | - return False; |
|
61 | - } |
|
59 | + if (!isset($accessToken)) { |
|
60 | + return False; |
|
61 | + } |
|
62 | 62 | |
63 | - if (! $accessToken->isLongLived()) { |
|
63 | + if (! $accessToken->isLongLived()) { |
|
64 | 64 | $oAuth2Client = $this->getFacebookObject()->getOAuth2Client(); |
65 | 65 | try { |
66 | - $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken); |
|
66 | + $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken); |
|
67 | 67 | } catch (\Facebook\Exceptions\FacebookSDKException $e) { |
68 | - return False; |
|
68 | + return False; |
|
69 | + } |
|
69 | 70 | } |
70 | - } |
|
71 | 71 | |
72 | - return $accessToken; |
|
72 | + return $accessToken; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | public function loginUser($accessToken) { |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | 'optin' => $THEUSER->optin(), |
159 | 159 | 'emailpublic' => False, |
160 | 160 | 'password' => '', |
161 | - ); |
|
161 | + ); |
|
162 | 162 | |
163 | 163 | $THEUSER->update_self_no_confirm($details); |
164 | 164 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | |
58 | 58 | private function checkAccessToken($accessToken) { |
59 | 59 | if (!isset($accessToken)) { |
60 | - return False; |
|
60 | + return false; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | if (! $accessToken->isLongLived()) { |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | try { |
66 | 66 | $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken); |
67 | 67 | } catch (\Facebook\Exceptions\FacebookSDKException $e) { |
68 | - return False; |
|
68 | + return false; |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $expires = intval($accessToken->getExpiresAt()->format('U')); |
87 | 87 | twfy_debug("THEUSER", "Facebook access token expires at " . $expires); |
88 | 88 | |
89 | - $success = False; |
|
89 | + $success = false; |
|
90 | 90 | if ($user_id) { |
91 | 91 | twfy_debug("THEUSER", "Faceook user exists in the database: " . $user_id); |
92 | 92 | $success = $THEUSER->init($user_id); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | return $logged_in; |
113 | 113 | } |
114 | 114 | |
115 | - return False; |
|
115 | + return false; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | public function createUser($accessToken, $user) { |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | 'url' => '', |
129 | 129 | 'status' => '', |
130 | 130 | 'password' => '', |
131 | - 'optin' => False, |
|
132 | - 'emailpublic' => False, |
|
133 | - 'mp_alert' => False, |
|
131 | + 'optin' => false, |
|
132 | + 'emailpublic' => false, |
|
133 | + 'mp_alert' => false, |
|
134 | 134 | 'facebook_id' => $user['id'] |
135 | 135 | ); |
136 | 136 | $added = $THEUSER->add($details, false); |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | 'postcode' => $THEUSER->postcode(), |
157 | 157 | 'url' => $THEUSER->url(), |
158 | 158 | 'optin' => $THEUSER->optin(), |
159 | - 'emailpublic' => False, |
|
159 | + 'emailpublic' => false, |
|
160 | 160 | 'password' => '', |
161 | 161 | ); |
162 | 162 |
@@ -36,10 +36,10 @@ discard block |
||
36 | 36 | |
37 | 37 | try { |
38 | 38 | $accessToken = $helper->getAccessToken(); |
39 | - } catch(\Facebook\Exceptions\FacebookResponseException $e) { |
|
39 | + } catch (\Facebook\Exceptions\FacebookResponseException $e) { |
|
40 | 40 | $data['error'] = 'Graph returned an error: ' . $e->getMessage(); |
41 | 41 | return $data; |
42 | - } catch(\Facebook\Exceptions\FacebookSDKException $e) { |
|
42 | + } catch (\Facebook\Exceptions\FacebookSDKException $e) { |
|
43 | 43 | $data['error'] = 'Facebook SDK returned an error: ' . $e->getMessage(); |
44 | 44 | return $data; |
45 | 45 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | return False; |
61 | 61 | } |
62 | 62 | |
63 | - if (! $accessToken->isLongLived()) { |
|
63 | + if (!$accessToken->isLongLived()) { |
|
64 | 64 | $oAuth2Client = $this->getFacebookObject()->getOAuth2Client(); |
65 | 65 | try { |
66 | 66 | $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken); |
@@ -48,7 +48,8 @@ discard block |
||
48 | 48 | |
49 | 49 | if ($token) { |
50 | 50 | return array('token' => $token); |
51 | - } else { |
|
51 | + } |
|
52 | + else { |
|
52 | 53 | $data['error'] = 'Problem getting Facebook token'; |
53 | 54 | return $data; |
54 | 55 | } |
@@ -95,7 +96,8 @@ discard block |
||
95 | 96 | $THEUSER->add_facebook_id($user['id']); |
96 | 97 | } |
97 | 98 | twfy_debug("THEUSER", "inited user has id : " . $THEUSER->user_id()); |
98 | - } else { |
|
99 | + } |
|
100 | + else { |
|
99 | 101 | twfy_debug("THEUSER", "Faceook user does not exist in the database"); |
100 | 102 | $success = $this->createUser($accessToken, $user); |
101 | 103 | } |
@@ -52,6 +52,11 @@ discard block |
||
52 | 52 | $this->_set('featured_related', $related); |
53 | 53 | } |
54 | 54 | |
55 | + /** |
|
56 | + * @param string $key |
|
57 | + * |
|
58 | + * @return string |
|
59 | + */ |
|
55 | 60 | private function _get($key) { |
56 | 61 | $text = NULL; |
57 | 62 | |
@@ -72,6 +77,9 @@ discard block |
||
72 | 77 | return $text; |
73 | 78 | } |
74 | 79 | |
80 | + /** |
|
81 | + * @param string $key |
|
82 | + */ |
|
75 | 83 | private function _set($key, $value) { |
76 | 84 | if ( trim($value) == '' ) { |
77 | 85 | $value = NULL; |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | |
65 | 65 | if ($q->rows) { |
66 | 66 | $text = $q->field(0, 'value'); |
67 | - if ( trim($text) == '' ) { |
|
67 | + if (trim($text) == '') { |
|
68 | 68 | $text = NULL; |
69 | 69 | } |
70 | 70 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | private function _set($key, $value) { |
76 | - if ( trim($value) == '' ) { |
|
76 | + if (trim($value) == '') { |
|
77 | 77 | $value = NULL; |
78 | 78 | } |
79 | 79 | $check_q = $this->db->query( |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | ':key' => $key |
83 | 83 | ) |
84 | 84 | ); |
85 | - if ( $check_q->rows ) { |
|
85 | + if ($check_q->rows) { |
|
86 | 86 | $set_q = $this->db->query("UPDATE editorial set value = :value WHERE item = :key", |
87 | 87 | array( |
88 | 88 | ':key' => $key, |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | ); |
99 | 99 | } |
100 | 100 | |
101 | - if ( $set_q->success() ) { |
|
101 | + if ($set_q->success()) { |
|
102 | 102 | return true; |
103 | 103 | } |
104 | 104 | return false; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | private function _get($key) { |
56 | - $text = NULL; |
|
56 | + $text = null; |
|
57 | 57 | |
58 | 58 | $q = $this->db->query( |
59 | 59 | "SELECT value FROM editorial WHERE item = :key", |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | if ($q->rows) { |
66 | 66 | $text = $q->field(0, 'value'); |
67 | 67 | if ( trim($text) == '' ) { |
68 | - $text = NULL; |
|
68 | + $text = null; |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | private function _set($key, $value) { |
76 | 76 | if ( trim($value) == '' ) { |
77 | - $value = NULL; |
|
77 | + $value = null; |
|
78 | 78 | } |
79 | 79 | $check_q = $this->db->query( |
80 | 80 | "SELECT value FROM editorial WHERE item = :key", |
@@ -89,7 +89,8 @@ |
||
89 | 89 | ':value' => $value |
90 | 90 | ) |
91 | 91 | ); |
92 | - } else { |
|
92 | + } |
|
93 | + else { |
|
93 | 94 | $set_q = $this->db->query("INSERT INTO editorial (item, value ) VALUES (:key, :value)", |
94 | 95 | array( |
95 | 96 | ':key' => $key, |
@@ -12,11 +12,11 @@ |
||
12 | 12 | |
13 | 13 | class UtilityTest extends UnitTestCase{ |
14 | 14 | |
15 | - public function testVerpEnvelopeSenderCanCreateStandardSender() { |
|
15 | + public function testVerpEnvelopeSenderCanCreateStandardSender() { |
|
16 | 16 | $sender = twfy_verp_envelope_sender('[email protected]'); |
17 | 17 | $expected_sender = 'twfy+aperson=a.nother.dom@' + EMAILDOMAIN; |
18 | 18 | $this->assertEqual($sender, $expected_sender, 'verp_envelope_sender can create a sender for a standard address'); |
19 | - } |
|
19 | + } |
|
20 | 20 | |
21 | 21 | } |
22 | 22 |
@@ -3,18 +3,18 @@ |
||
3 | 3 | * SimpleTest tests for the functions in utility.php |
4 | 4 | * $Id: utility_test.php,v 1.3 2009-06-25 12:23:58 louise Exp $ |
5 | 5 | */ |
6 | -error_reporting (E_ALL); |
|
6 | +error_reporting(E_ALL); |
|
7 | 7 | ini_set("display_errors", 1); |
8 | 8 | include_once dirname(__FILE__) . '/../../../conf/general'; |
9 | 9 | include_once '../utility.php'; |
10 | 10 | include_once 'simpletest/unit_tester.php'; |
11 | 11 | include_once 'simpletest/reporter.php'; |
12 | 12 | |
13 | -class UtilityTest extends UnitTestCase{ |
|
13 | +class UtilityTest extends UnitTestCase { |
|
14 | 14 | |
15 | 15 | public function testVerpEnvelopeSenderCanCreateStandardSender() { |
16 | 16 | $sender = twfy_verp_envelope_sender('[email protected]'); |
17 | - $expected_sender = 'twfy+aperson=a.nother.dom@' + EMAILDOMAIN; |
|
17 | + $expected_sender = 'twfy+aperson=a.nother.dom@' +EMAILDOMAIN; |
|
18 | 18 | $this->assertEqual($sender, $expected_sender, 'verp_envelope_sender can create a sender for a standard address'); |
19 | 19 | } |
20 | 20 |