@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -$new_style_template = TRUE; |
|
3 | +$new_style_template = true; |
|
4 | 4 | |
5 | 5 | include_once '../../../includes/easyparliament/init.php'; |
6 | 6 | include_once INCLUDESPATH . 'easyparliament/member.php'; |
@@ -11,7 +11,7 @@ |
||
11 | 11 | namespace MySociety\TheyWorkForYou; |
12 | 12 | |
13 | 13 | // Disable the old PAGE class. |
14 | -$new_style_template = TRUE; |
|
14 | +$new_style_template = true; |
|
15 | 15 | |
16 | 16 | // Include all the things this page needs. |
17 | 17 | include_once '../../includes/easyparliament/init.php'; |
@@ -27,8 +27,7 @@ discard block |
||
27 | 27 | $this_page = 'topic'; |
28 | 28 | |
29 | 29 | // Make sure the requested topic actually exists, otherwise throw a 404. |
30 | -if ($topic = $topics->getTopic($topicname)) |
|
31 | -{ |
|
30 | +if ($topic = $topics->getTopic($topicname)) { |
|
32 | 31 | |
33 | 32 | $data = array(); |
34 | 33 | $data['topic'] = $topic; |
@@ -45,8 +44,7 @@ discard block |
||
45 | 44 | include_once INCLUDESPATH . 'easyparliament/member.php'; |
46 | 45 | |
47 | 46 | // Check to see if there's a submitted postcode to try determine policy positions. |
48 | - if (get_http_var('pc') != '') |
|
49 | - { |
|
47 | + if (get_http_var('pc') != '') { |
|
50 | 48 | |
51 | 49 | // Try all this, as it might go wrong. |
52 | 50 | try { |
@@ -81,8 +79,7 @@ discard block |
||
81 | 79 | |
82 | 80 | ///////////////////////////////////////////////////////// |
83 | 81 | // DOES THE USER HAVE A POSTCODE ALREADY SET? |
84 | - elseif ($THEUSER->postcode_is_set()) |
|
85 | - { |
|
82 | + elseif ($THEUSER->postcode_is_set()) { |
|
86 | 83 | $member = new Member(array('postcode' => $THEUSER->postcode(), 'house' => HOUSE_TYPE_COMMONS)); |
87 | 84 | } |
88 | 85 |
@@ -54,12 +54,12 @@ discard block |
||
54 | 54 | $pc = get_http_var('pc'); |
55 | 55 | $pc = preg_replace('#[^a-z0-9]#i', '', $pc); |
56 | 56 | if (validate_postcode($pc)) { |
57 | - twfy_debug ('MP', "MP lookup by postcode"); |
|
57 | + twfy_debug('MP', "MP lookup by postcode"); |
|
58 | 58 | $constituency = strtolower(Utility\Postcode::postcodeToConstituency($pc)); |
59 | 59 | if ($constituency == "connection_timed_out") { |
60 | 60 | throw new \Exception('Sorry, we couldn’t check your postcode right now, as our postcode lookup server is under quite a lot of load.'); |
61 | 61 | } elseif ($constituency == "") { |
62 | - twfy_debug ('MP', "Can't display an MP, as submitted postcode didn't match a constituency"); |
|
62 | + twfy_debug('MP', "Can't display an MP, as submitted postcode didn't match a constituency"); |
|
63 | 63 | throw new \Exception('Sorry, ' . _htmlentities($pc) . ' isn’t a known postcode'); |
64 | 64 | } else { |
65 | 65 | // Generate the Member object |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | } |
71 | 71 | } |
72 | 72 | } else { |
73 | - twfy_debug ('MP', "Can't display an MP because the submitted postcode wasn't of a valid form."); |
|
73 | + twfy_debug('MP', "Can't display an MP because the submitted postcode wasn't of a valid form."); |
|
74 | 74 | throw new \Exception('Sorry, ' . _htmlentities($pc) . ' isn’t a valid postcode'); |
75 | 75 | } |
76 | 76 | } catch (\Exception $e) { |
@@ -7,7 +7,7 @@ |
||
7 | 7 | namespace MySociety\TheyWorkForYou; |
8 | 8 | |
9 | 9 | // Disable the old PAGE class. |
10 | -$new_style_template = TRUE; |
|
10 | +$new_style_template = true; |
|
11 | 11 | global $this_page; |
12 | 12 | $this_page = 'topics'; |
13 | 13 |
@@ -8,7 +8,7 @@ |
||
8 | 8 | $topic = $topics->getTopic($slug); |
9 | 9 | } |
10 | 10 | |
11 | -if (!$slug || !isset($topic) || $topic === NULL) { |
|
11 | +if (!$slug || !isset($topic) || $topic === null) { |
|
12 | 12 | header('HTTP/1.0 404 Not Found'); |
13 | 13 | exit(); |
14 | 14 | } |
@@ -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']); |
@@ -28,8 +28,9 @@ discard block |
||
28 | 28 | $URL = new \MySociety\TheyWorkForYou\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; |
@@ -85,8 +88,9 @@ discard block |
||
85 | 88 | $out = _api_getPerson_row($row, $house == HOUSE_TYPE_ROYAL ? false : true); |
86 | 89 | $output[] = $out; |
87 | 90 | $time = strtotime($row['lastupdate']); |
88 | - if ($time > $last_mod) |
|
89 | - $last_mod = $time; |
|
91 | + if ($time > $last_mod) { |
|
92 | + $last_mod = $time; |
|
93 | + } |
|
90 | 94 | } |
91 | 95 | # Only one MP, not an array |
92 | 96 | if ($flatten && count($output) == 1 && $house == HOUSE_TYPE_COMMONS) { |
@@ -134,13 +138,18 @@ discard block |
||
134 | 138 | |
135 | 139 | $cons = array(); |
136 | 140 | foreach ($constituencies as $constituency) { |
137 | - if ($constituency == '') continue; |
|
138 | - if ($constituency == 'Orkney ') |
|
139 | - $constituency = 'Orkney & Shetland'; |
|
141 | + if ($constituency == '') { |
|
142 | + continue; |
|
143 | + } |
|
144 | + if ($constituency == 'Orkney ') { |
|
145 | + $constituency = 'Orkney & Shetland'; |
|
146 | + } |
|
140 | 147 | |
141 | 148 | if ($house == HOUSE_TYPE_COMMONS) { |
142 | 149 | $normalised = MySociety\TheyWorkForYou\Utility\Constituencies::normaliseConstituencyName($constituency); |
143 | - if ($normalised) $constituency = $normalised; |
|
150 | + if ($normalised) { |
|
151 | + $constituency = $normalised; |
|
152 | + } |
|
144 | 153 | } |
145 | 154 | |
146 | 155 | $cons[] = $constituency; |
@@ -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; |
@@ -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,7 +77,7 @@ 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 | 83 | $house = null; |
@@ -338,7 +338,7 @@ |
||
338 | 338 | // and then catch any errors in the conversion and just ignore |
339 | 339 | // them and return the unconverted results |
340 | 340 | $converted_out = @iconv('utf-8', 'iso-8859-1//TRANSLIT', $out); |
341 | - if ($converted_out !== FALSE) { |
|
341 | + if ($converted_out !== false) { |
|
342 | 342 | $out = $converted_out; |
343 | 343 | } |
344 | 344 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | # Key-related functions |
133 | 133 | |
134 | 134 | function api_log_call($key) { |
135 | - if ($key=='DOCS') return; |
|
135 | + if ($key == 'DOCS') return; |
|
136 | 136 | $ip = $_SERVER['REMOTE_ADDR']; |
137 | 137 | $query = !empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; |
138 | 138 | $query = preg_replace('#key=[A-Za-z0-9]+&?#', '', $query); |
@@ -197,14 +197,14 @@ discard block |
||
197 | 197 | |
198 | 198 | # Output functions |
199 | 199 | |
200 | -function api_output($arr, $last_mod=null) { |
|
200 | +function api_output($arr, $last_mod = null) { |
|
201 | 201 | $output = get_http_var('output'); |
202 | 202 | if (!get_http_var('docs')) { |
203 | 203 | $cond = api_header($output, $last_mod); |
204 | 204 | if ($cond) return; |
205 | 205 | } |
206 | 206 | if ($output == 'xml') { |
207 | - $out = '<?xml version="1.0" encoding="utf-8"?>'."\n"; |
|
207 | + $out = '<?xml version="1.0" encoding="utf-8"?>' . "\n"; |
|
208 | 208 | $out .= '<twfy>' . api_output_xml($arr) . '</twfy>'; |
209 | 209 | } elseif ($output == 'php') { |
210 | 210 | $out = api_output_php($arr); |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | print $out; |
223 | 223 | } |
224 | 224 | |
225 | -function api_header($o, $last_mod=null) { |
|
225 | +function api_header($o, $last_mod = null) { |
|
226 | 226 | if ($last_mod && array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) { |
227 | 227 | $t = cond_parse_http_date($_SERVER['HTTP_IF_MODIFIED_SINCE']); |
228 | 228 | if (isset($t) && $t >= $last_mod) { |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | } |
249 | 249 | #$type = 'text/plain'; |
250 | 250 | header("Content-Type: $type; charset=$charset"); |
251 | - if ($last_mod>0) |
|
251 | + if ($last_mod > 0) |
|
252 | 252 | header('Last-Modified: ' . date('r', $last_mod)); |
253 | 253 | return false; |
254 | 254 | } |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | global $api_xml_arr; |
276 | 276 | $verbose = get_http_var('verbose') ? "\n" : ''; |
277 | 277 | if (is_array($v)) { |
278 | - if (count($v) && array_keys($v) === range(0, count($v)-1)) { |
|
278 | + if (count($v) && array_keys($v) === range(0, count($v) - 1)) { |
|
279 | 279 | $elt = 'match'; |
280 | 280 | $api_xml_arr++; |
281 | 281 | $out = "<$elt>"; |
@@ -296,36 +296,36 @@ discard block |
||
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
299 | -function api_output_js($v, $level=0) { |
|
299 | +function api_output_js($v, $level = 0) { |
|
300 | 300 | $verbose = get_http_var('verbose') ? "\n" : ''; |
301 | 301 | $out = ''; |
302 | 302 | if (is_array($v)) { |
303 | 303 | # PHP arrays are both JS arrays and objects |
304 | - if (count($v) && array_keys($v) === range(0, count($v)-1)) { |
|
305 | - $out = '[' . join(",$verbose" , array_map('api_output_js', $v)) . ']'; |
|
304 | + if (count($v) && array_keys($v) === range(0, count($v) - 1)) { |
|
305 | + $out = '[' . join(",$verbose", array_map('api_output_js', $v)) . ']'; |
|
306 | 306 | } else { |
307 | 307 | $out = '{' . $verbose; |
308 | 308 | $b = false; |
309 | 309 | foreach ($v as $k => $vv) { |
310 | 310 | if ($b) $out .= ",$verbose"; |
311 | 311 | if ($verbose) { |
312 | - $out .= str_repeat(' ', ($level+1)*2); |
|
312 | + $out .= str_repeat(' ', ($level + 1) * 2); |
|
313 | 313 | $out .= '"' . $k . '" : '; |
314 | 314 | } else { |
315 | 315 | $out .= '"' . $k . '":'; |
316 | 316 | } |
317 | - $out .= api_output_js($vv, $level+1); |
|
317 | + $out .= api_output_js($vv, $level + 1); |
|
318 | 318 | $b = true; |
319 | 319 | } |
320 | - if ($verbose) $out .= "\n" . str_repeat(' ', $level*2); |
|
320 | + if ($verbose) $out .= "\n" . str_repeat(' ', $level * 2); |
|
321 | 321 | $out .= '}'; |
322 | 322 | } |
323 | 323 | } elseif (is_null($v)) { |
324 | 324 | $out = "null"; |
325 | 325 | } elseif (is_string($v)) { |
326 | 326 | $out = '"' . str_replace( |
327 | - array("\\",'"',"\n","\t","\r", "‶", "″", "“", "”"), |
|
328 | - array("\\\\",'\"','\n','\t','\r', '\"', '\"', '\"', '\"'), $v) . '"'; |
|
327 | + array("\\", '"', "\n", "\t", "\r", "‶", "″", "“", "”"), |
|
328 | + array("\\\\", '\"', '\n', '\t', '\r', '\"', '\"', '\"', '\"'), $v) . '"'; |
|
329 | 329 | } elseif (is_bool($v)) { |
330 | 330 | $out = $v ? 'true' : 'false'; |
331 | 331 | } elseif (is_int($v) || is_float($v)) { |
@@ -146,20 +146,20 @@ discard block |
||
146 | 146 | } |
147 | 147 | |
148 | 148 | function api_is_superuser_key($key) { |
149 | - $db = new ParlDB; |
|
150 | - $q = $db->query('SELECT api_key.user_id, users.status |
|
149 | + $db = new ParlDB; |
|
150 | + $q = $db->query('SELECT api_key.user_id, users.status |
|
151 | 151 | FROM api_key, users |
152 | 152 | WHERE users.user_id = api_key.user_id |
153 | 153 | AND api_key.api_key = :key', array( |
154 | 154 | ':key' => $key |
155 | 155 | ))->first(); |
156 | - if (!$q) { |
|
156 | + if (!$q) { |
|
157 | 157 | return false; |
158 | - } |
|
159 | - if ($q['status'] == 'Superuser') { |
|
158 | + } |
|
159 | + if ($q['status'] == 'Superuser') { |
|
160 | 160 | return true; |
161 | - } |
|
162 | - return false; |
|
161 | + } |
|
162 | + return false; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | function api_check_key($key) { |
@@ -338,12 +338,12 @@ discard block |
||
338 | 338 | // we only want to convert to iso if it's an actual API call |
339 | 339 | // so skip this if it's a documentation page |
340 | 340 | if (!get_http_var('docs')) { |
341 | - // and then catch any errors in the conversion and just ignore |
|
342 | - // them and return the unconverted results |
|
343 | - $converted_out = @iconv('utf-8', 'iso-8859-1//TRANSLIT', $out); |
|
344 | - if ($converted_out !== FALSE) { |
|
341 | + // and then catch any errors in the conversion and just ignore |
|
342 | + // them and return the unconverted results |
|
343 | + $converted_out = @iconv('utf-8', 'iso-8859-1//TRANSLIT', $out); |
|
344 | + if ($converted_out !== FALSE) { |
|
345 | 345 | $out = $converted_out; |
346 | - } |
|
346 | + } |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | return $out; |
@@ -132,7 +132,9 @@ discard block |
||
132 | 132 | # Key-related functions |
133 | 133 | |
134 | 134 | function api_log_call($key) { |
135 | - if ($key=='DOCS') return; |
|
135 | + if ($key=='DOCS') { |
|
136 | + return; |
|
137 | + } |
|
136 | 138 | $ip = $_SERVER['REMOTE_ADDR']; |
137 | 139 | $query = !empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; |
138 | 140 | $query = preg_replace('#key=[A-Za-z0-9]+&?#', '', $query); |
@@ -204,7 +206,9 @@ discard block |
||
204 | 206 | $output = get_http_var('output'); |
205 | 207 | if (!get_http_var('docs')) { |
206 | 208 | $cond = api_header($output, $last_mod); |
207 | - if ($cond) return; |
|
209 | + if ($cond) { |
|
210 | + return; |
|
211 | + } |
|
208 | 212 | } |
209 | 213 | if ($output == 'xml') { |
210 | 214 | $out = '<?xml version="1.0" encoding="utf-8"?>'."\n"; |
@@ -215,7 +219,8 @@ discard block |
||
215 | 219 | $out = api_output_rabx($arr); |
216 | 220 | } elseif ($output == 'json') { |
217 | 221 | $out = json_encode($arr, JSON_PRETTY_PRINT); |
218 | - } else { # JS |
|
222 | + } else { |
|
223 | +# JS |
|
219 | 224 | $out = api_output_js($arr); |
220 | 225 | $callback = get_http_var('callback'); |
221 | 226 | if (preg_match('#^[A-Za-z0-9._[\]]+$#', $callback)) { |
@@ -251,8 +256,9 @@ discard block |
||
251 | 256 | } |
252 | 257 | #$type = 'text/plain'; |
253 | 258 | header("Content-Type: $type; charset=$charset"); |
254 | - if ($last_mod>0) |
|
255 | - header('Last-Modified: ' . date('r', $last_mod)); |
|
259 | + if ($last_mod>0) { |
|
260 | + header('Last-Modified: ' . date('r', $last_mod)); |
|
261 | + } |
|
256 | 262 | return false; |
257 | 263 | } |
258 | 264 | |
@@ -262,14 +268,18 @@ discard block |
||
262 | 268 | |
263 | 269 | function api_output_php($arr) { |
264 | 270 | $out = serialize($arr); |
265 | - if (get_http_var('verbose')) $out = str_replace(';', ";\n", $out); |
|
271 | + if (get_http_var('verbose')) { |
|
272 | + $out = str_replace(';', ";\n", $out); |
|
273 | + } |
|
266 | 274 | return $out; |
267 | 275 | } |
268 | 276 | |
269 | 277 | function api_output_rabx($arr) { |
270 | 278 | $out = ''; |
271 | 279 | rabx_wire_wr($arr, $out); |
272 | - if (get_http_var('verbose')) $out = str_replace(',', ",\n", $out); |
|
280 | + if (get_http_var('verbose')) { |
|
281 | + $out = str_replace(',', ",\n", $out); |
|
282 | + } |
|
273 | 283 | return $out; |
274 | 284 | } |
275 | 285 | |
@@ -310,7 +320,9 @@ discard block |
||
310 | 320 | $out = '{' . $verbose; |
311 | 321 | $b = false; |
312 | 322 | foreach ($v as $k => $vv) { |
313 | - if ($b) $out .= ",$verbose"; |
|
323 | + if ($b) { |
|
324 | + $out .= ",$verbose"; |
|
325 | + } |
|
314 | 326 | if ($verbose) { |
315 | 327 | $out .= str_repeat(' ', ($level+1)*2); |
316 | 328 | $out .= '"' . $k . '" : '; |
@@ -320,7 +332,9 @@ discard block |
||
320 | 332 | $out .= api_output_js($vv, $level+1); |
321 | 333 | $b = true; |
322 | 334 | } |
323 | - if ($verbose) $out .= "\n" . str_repeat(' ', $level*2); |
|
335 | + if ($verbose) { |
|
336 | + $out .= "\n" . str_repeat(' ', $level*2); |
|
337 | + } |
|
324 | 338 | $out .= '}'; |
325 | 339 | } |
326 | 340 | } elseif (is_null($v)) { |
@@ -352,13 +366,14 @@ discard block |
||
352 | 366 | # Call an API function |
353 | 367 | |
354 | 368 | function api_call_user_func_or_error($function, $params, $error, $type) { |
355 | - if (function_exists($function)) |
|
356 | - call_user_func_array($function, $params); |
|
357 | - elseif ($type == 'api') |
|
358 | - api_error($error); |
|
359 | - else |
|
360 | - print "<p style='color:#cc0000'>$error</p>"; |
|
361 | -} |
|
369 | + if (function_exists($function)) { |
|
370 | + call_user_func_array($function, $params); |
|
371 | + } elseif ($type == 'api') { |
|
372 | + api_error($error); |
|
373 | + } else { |
|
374 | + print "<p style='color:#cc0000'>$error</p>"; |
|
375 | + } |
|
376 | + } |
|
362 | 377 | |
363 | 378 | # Used for testing for conditional responses |
364 | 379 |
@@ -107,13 +107,13 @@ discard block |
||
107 | 107 | $related2 = get_http_var('related2'); |
108 | 108 | $related3 = get_http_var('related3'); |
109 | 109 | |
110 | - $gid = $url ? get_gid_from_url($url) : NULL; |
|
111 | - $related_gid1 = $related1 ? get_gid_from_url($related1) : NULL; |
|
112 | - $related_gid2 = $related2 ? get_gid_from_url($related2) : NULL; |
|
113 | - $related_gid3 = $related3 ? get_gid_from_url($related3) : NULL; |
|
110 | + $gid = $url ? get_gid_from_url($url) : null; |
|
111 | + $related_gid1 = $related1 ? get_gid_from_url($related1) : null; |
|
112 | + $related_gid2 = $related2 ? get_gid_from_url($related2) : null; |
|
113 | + $related_gid3 = $related3 ? get_gid_from_url($related3) : null; |
|
114 | 114 | |
115 | 115 | print "<h2>Preview Content</h2>"; |
116 | - if ( $gid !== NULL ) { |
|
116 | + if ( $gid !== null ) { |
|
117 | 117 | $h = new MySociety\TheyWorkForYou\Homepage; |
118 | 118 | $featured = $h->getFeaturedDebate($gid, $title, $context, array( $related_gid1, $related_gid2, $related_gid3 )); |
119 | 119 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | } |
154 | 154 | |
155 | 155 | function get_gid_from_url($url) { |
156 | - $gid = NULL; |
|
156 | + $gid = null; |
|
157 | 157 | $parts = parse_url($url); |
158 | 158 | parse_str($parts['query'], $query); |
159 | 159 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | $out = ''; |
13 | 13 | if (get_http_var('preview')) { |
14 | 14 | preview_featured(); |
15 | -} else if ( get_http_var('confirm') ) { |
|
15 | +} else if (get_http_var('confirm')) { |
|
16 | 16 | $out = update_featured(); |
17 | 17 | } |
18 | 18 | |
@@ -23,13 +23,13 @@ discard block |
||
23 | 23 | print '</div>'; |
24 | 24 | |
25 | 25 | function gid_to_url($gid) { |
26 | - if ( !$gid ) { |
|
26 | + if (!$gid) { |
|
27 | 27 | return ''; |
28 | 28 | } |
29 | 29 | global $hansardmajors; |
30 | 30 | global $db; |
31 | 31 | |
32 | - $q = $db->query("SELECT major FROM hansard WHERE gid = :gid", array( ':gid' => $gid ))->first(); |
|
32 | + $q = $db->query("SELECT major FROM hansard WHERE gid = :gid", array(':gid' => $gid))->first(); |
|
33 | 33 | $url_gid = fix_gid_from_db($gid); |
34 | 34 | $url = new \MySociety\TheyWorkForYou\Url($hansardmajors[$q['major']]['page']); |
35 | 35 | $url->insert(array('id' => $url_gid)); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $related = $featured->get_related(); |
44 | 44 | $context = $featured->get_context(); |
45 | 45 | |
46 | - if ( get_http_var('url') ) { |
|
46 | + if (get_http_var('url')) { |
|
47 | 47 | $url = get_http_var('url'); |
48 | 48 | $title = get_http_var('title'); |
49 | 49 | $context = get_http_var('context'); |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | $related_gid3 = $related3 ? get_gid_from_url($related3) : NULL; |
114 | 114 | |
115 | 115 | print "<h2>Preview Content</h2>"; |
116 | - if ( $gid !== NULL ) { |
|
116 | + if ($gid !== NULL) { |
|
117 | 117 | $h = new MySociety\TheyWorkForYou\Homepage; |
118 | - $featured = $h->getFeaturedDebate($gid, $title, $context, array( $related_gid1, $related_gid2, $related_gid3 )); |
|
118 | + $featured = $h->getFeaturedDebate($gid, $title, $context, array($related_gid1, $related_gid2, $related_gid3)); |
|
119 | 119 | |
120 | 120 | include INCLUDESPATH . 'easyparliament/templates/html/homepage/featured.php'; |
121 | 121 | } else { |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $parts = parse_url($url); |
158 | 158 | parse_str($parts['query'], $query); |
159 | 159 | |
160 | - if ( $query['id'] ) { |
|
160 | + if ($query['id']) { |
|
161 | 161 | if (strpos($parts['path'], 'lords') !== false) { |
162 | 162 | $gid = 'uk.org.publicwhip/lords/'; |
163 | 163 | } elseif (strpos($parts['path'], 'whall') !== false) { |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | </form> |
140 | 140 | |
141 | 141 | <p style="clear:both; margin-top: 3em"><a href="/images/mps/photo-status.php">List MPs without photos</a></p> |
142 | -EOF; |
|
142 | +eof; |
|
143 | 143 | |
144 | 144 | return $out; |
145 | 145 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | <span class="formw"><input type="submit" name="submit" value="Update attribution"></span> |
194 | 194 | </div> |
195 | 195 | </form> |
196 | -EOF; |
|
196 | +eof; |
|
197 | 197 | |
198 | 198 | return $out; |
199 | 199 | } |
@@ -111,7 +111,7 @@ |
||
111 | 111 | } else { |
112 | 112 | $desc .= ' [no photo]'; |
113 | 113 | } |
114 | - $out .= '<option value="'.$p_id.'">'.$desc.'</option>' . "\n"; |
|
114 | + $out .= '<option value="' . $p_id . '">' . $desc . '</option>' . "\n"; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | $out .= ' </select></span> </div> '; |
@@ -35,28 +35,33 @@ discard block |
||
35 | 35 | $pid = intval(get_http_var('pid')); |
36 | 36 | $errors = array(); |
37 | 37 | |
38 | - if (!array_key_exists('photo', $_FILES)) |
|
39 | - array_push($errors, 'Not got the photo.'); |
|
40 | - elseif ($_FILES['photo']['error'] > 0) |
|
41 | - array_push($errors, 'There was an error uploading the photo.'); |
|
42 | - elseif (!is_uploaded_file($_FILES['photo']['tmp_name'])) |
|
43 | - array_push($errors, 'Did not get an uploaded file.'); |
|
44 | - else { |
|
38 | + if (!array_key_exists('photo', $_FILES)) { |
|
39 | + array_push($errors, 'Not got the photo.'); |
|
40 | + } elseif ($_FILES['photo']['error'] > 0) { |
|
41 | + array_push($errors, 'There was an error uploading the photo.'); |
|
42 | + } elseif (!is_uploaded_file($_FILES['photo']['tmp_name'])) { |
|
43 | + array_push($errors, 'Did not get an uploaded file.'); |
|
44 | + } else { |
|
45 | 45 | $tmp_name = $_FILES['photo']['tmp_name']; |
46 | 46 | |
47 | 47 | $image = new Imagick(); |
48 | 48 | $image->readImage($tmp_name); |
49 | - if (!$image) |
|
50 | - array_push($errors, 'Failed to read image from uploaded file'); |
|
49 | + if (!$image) { |
|
50 | + array_push($errors, 'Failed to read image from uploaded file'); |
|
51 | + } |
|
51 | 52 | $imageS = clone $image; |
52 | - if (!$image->scaleImage(0, 118)) |
|
53 | - array_push($errors, 'Scaling large failed'); |
|
54 | - if (!$imageS->scaleImage(0, 59)) |
|
55 | - array_push($errors, 'Scaling small failed'); |
|
56 | - if (!$image->writeImage("$dir/mpsL/$pid.jpeg")) |
|
57 | - array_push($errors, "Saving to $dir/mpsL/$pid.jpeg failed"); |
|
58 | - if (!$imageS->writeImage("$dir/mps/$pid.jpeg")) |
|
59 | - array_push($errors, "Saving to $dir/mps/$pid.jpeg failed"); |
|
53 | + if (!$image->scaleImage(0, 118)) { |
|
54 | + array_push($errors, 'Scaling large failed'); |
|
55 | + } |
|
56 | + if (!$imageS->scaleImage(0, 59)) { |
|
57 | + array_push($errors, 'Scaling small failed'); |
|
58 | + } |
|
59 | + if (!$image->writeImage("$dir/mpsL/$pid.jpeg")) { |
|
60 | + array_push($errors, "Saving to $dir/mpsL/$pid.jpeg failed"); |
|
61 | + } |
|
62 | + if (!$imageS->writeImage("$dir/mps/$pid.jpeg")) { |
|
63 | + array_push($errors, "Saving to $dir/mps/$pid.jpeg failed"); |
|
64 | + } |
|
60 | 65 | if (!$errors) { |
61 | 66 | print "<pre>"; |
62 | 67 | chdir($dir); |
@@ -69,8 +74,9 @@ discard block |
||
69 | 74 | } |
70 | 75 | } |
71 | 76 | |
72 | - if ($errors) |
|
73 | - return display_photo_form($errors); |
|
77 | + if ($errors) { |
|
78 | + return display_photo_form($errors); |
|
79 | + } |
|
74 | 80 | return "<p><em>Photo uploaded and resized for pid $pid</em> — check how it looks <a href=\"/mp?p=$pid\">on their page</a></p>" . display_photo_form(); |
75 | 81 | } |
76 | 82 | |
@@ -98,7 +104,9 @@ discard block |
||
98 | 104 | $house = $row['house']; |
99 | 105 | $desc = member_full_name($house, $row['title'], $row['given_name'], $row['family_name'], $row['lordofname']) . |
100 | 106 | " " . $houses[$house]; |
101 | - if ($row['party']) $desc .= ' (' . $row['party'] . ')'; |
|
107 | + if ($row['party']) { |
|
108 | + $desc .= ' (' . $row['party'] . ')'; |
|
109 | + } |
|
102 | 110 | if ($row['constituency']) { |
103 | 111 | $desc .= ', ' . $row['constituency']; |
104 | 112 | } |
@@ -149,13 +157,15 @@ discard block |
||
149 | 157 | $attr_link = get_http_var('attr_link'); |
150 | 158 | $errors = array(); |
151 | 159 | |
152 | - if (!$pid || !$attr_text) |
|
153 | - array_push($errors, 'Missing information'); |
|
154 | - elseif ($attr_link && substr($attr_link, 0, 4) != 'http') |
|
155 | - array_push($errors, 'Bad link'); |
|
160 | + if (!$pid || !$attr_text) { |
|
161 | + array_push($errors, 'Missing information'); |
|
162 | + } elseif ($attr_link && substr($attr_link, 0, 4) != 'http') { |
|
163 | + array_push($errors, 'Bad link'); |
|
164 | + } |
|
156 | 165 | |
157 | - if ($errors) |
|
158 | - return display_attribution_form($errors); |
|
166 | + if ($errors) { |
|
167 | + return display_attribution_form($errors); |
|
168 | + } |
|
159 | 169 | |
160 | 170 | # UPDATE |
161 | 171 | global $db; |
@@ -37,6 +37,6 @@ |
||
37 | 37 | if ($to) |
38 | 38 | $query .= " and hpos<=$hpos_to"; |
39 | 39 | |
40 | -print "Executing $query...\n"; |
|
40 | +print "executing $query...\n"; |
|
41 | 41 | $q = $db->query($query); |
42 | 42 | print ' ' . $q->affected_rows() . " rows have been marked as missing\n"; |
@@ -16,7 +16,9 @@ discard block |
||
16 | 16 | |
17 | 17 | $date = substr($from, 0, 10); |
18 | 18 | $from = 'uk.org.publicwhip/debate/' . $from; |
19 | -if ($to) $to = 'uk.org.publicwhip/debate/' . $to; |
|
19 | +if ($to) { |
|
20 | + $to = 'uk.org.publicwhip/debate/' . $to; |
|
21 | +} |
|
20 | 22 | |
21 | 23 | $q = $db->query('select hpos from hansard where gid="' . $from . '"')->first(); |
22 | 24 | $hpos_from = $q['hpos']; |
@@ -34,8 +36,9 @@ discard block |
||
34 | 36 | |
35 | 37 | $query = "update hansard set video_status = video_status | 8 |
36 | 38 | where major=1 and hdate='$date' and hpos>=$hpos_from"; |
37 | -if ($to) |
|
39 | +if ($to) { |
|
38 | 40 | $query .= " and hpos<=$hpos_to"; |
41 | +} |
|
39 | 42 | |
40 | 43 | print "Executing $query...\n"; |
41 | 44 | $q = $db->query($query); |