@@ -19,14 +19,14 @@ discard block |
||
19 | 19 | if (get_http_var("submitted") == "true") { |
20 | 20 | // Form has been submitted, so check input. |
21 | 21 | |
22 | - $email = get_http_var("email"); |
|
22 | + $email = get_http_var("email"); |
|
23 | 23 | $password = get_http_var("password"); |
24 | 24 | $remember = get_http_var("remember"); |
25 | 25 | |
26 | 26 | // The user may have tried to do something that requires being logged in. |
27 | 27 | // In which case we should arrive here with that page's URL in 'ret'. |
28 | 28 | // We can then send the user there after log in. |
29 | - $returnurl = get_http_var("ret"); |
|
29 | + $returnurl = get_http_var("ret"); |
|
30 | 30 | |
31 | 31 | $errors = array(); |
32 | 32 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | if ($remember == "true") { |
54 | 54 | $expire = "never"; |
55 | 55 | } else { |
56 | - $expire ="session"; |
|
56 | + $expire = "session"; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | // $returnurl is the url of where we'll send the user after login. |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | |
99 | -function display_page( $errors=array() ) { |
|
99 | +function display_page($errors = array()) { |
|
100 | 100 | global $PAGE, $this_page, $THEUSER; |
101 | 101 | |
102 | 102 | $PAGE->page_start(); |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | <?php |
128 | 128 | |
129 | 129 | $PAGE->stripe_end(array( |
130 | - array ( |
|
130 | + array( |
|
131 | 131 | 'type' => 'include', |
132 | 132 | 'content' => 'userlogin' |
133 | 133 | ) |
@@ -32,7 +32,8 @@ discard block |
||
32 | 32 | |
33 | 33 | if ($email == "") { |
34 | 34 | $errors["email"] = "Please enter your email address"; |
35 | - } elseif (!validate_email($email)) { |
|
35 | + } |
|
36 | + elseif (!validate_email($email)) { |
|
36 | 37 | $errors["email"] = "Please enter a valid email address"; |
37 | 38 | } |
38 | 39 | if ($password == "") { |
@@ -43,7 +44,8 @@ discard block |
||
43 | 44 | // Validation errors. Print form again. |
44 | 45 | display_page($errors); |
45 | 46 | |
46 | - } else { |
|
47 | + } |
|
48 | + else { |
|
47 | 49 | // No errors so far, so try to log in. |
48 | 50 | |
49 | 51 | $valid = $THEUSER->isvalid($email, $password); |
@@ -52,14 +54,16 @@ discard block |
||
52 | 54 | // No validation errors. |
53 | 55 | if ($remember == "true") { |
54 | 56 | $expire = "never"; |
55 | - } else { |
|
57 | + } |
|
58 | + else { |
|
56 | 59 | $expire ="session"; |
57 | 60 | } |
58 | 61 | |
59 | 62 | // $returnurl is the url of where we'll send the user after login. |
60 | 63 | $THEUSER->login($returnurl, $expire); |
61 | 64 | |
62 | - } else { |
|
65 | + } |
|
66 | + else { |
|
63 | 67 | |
64 | 68 | // Merge the validation errors with any we already have. |
65 | 69 | $errors = array_merge($errors, $valid); |
@@ -69,7 +73,8 @@ discard block |
||
69 | 73 | |
70 | 74 | } |
71 | 75 | |
72 | -} elseif ($resend = get_http_var('resend')) { |
|
76 | +} |
|
77 | +elseif ($resend = get_http_var('resend')) { |
|
73 | 78 | $USER = new USER(); |
74 | 79 | $USER->init($resend); |
75 | 80 | if (!$USER->confirmed()) { |
@@ -90,7 +95,8 @@ discard block |
||
90 | 95 | $PAGE->stripe_end(); |
91 | 96 | $PAGE->page_end(); |
92 | 97 | } |
93 | -} else { |
|
98 | +} |
|
99 | +else { |
|
94 | 100 | // First time to the page... |
95 | 101 | display_page(); |
96 | 102 | } |
@@ -25,7 +25,7 @@ |
||
25 | 25 | |
26 | 26 | public function tearDown() |
27 | 27 | { |
28 | - $this->db = NULL; |
|
28 | + $this->db = null; |
|
29 | 29 | |
30 | 30 | parent::tearDown(); |
31 | 31 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | /** |
10 | 10 | * Test that the Royal edge-case house is correctly defined. |
11 | 11 | */ |
12 | - public function testRoyalHouseDefined() |
|
12 | + public function testRoyalHouseDefined() |
|
13 | 13 | { |
14 | 14 | $this->assertEquals(0, HOUSE_TYPE_ROYAL); |
15 | 15 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * Test that the House of Commons is correctly defined. |
19 | 19 | */ |
20 | - public function testCommonsHouseDefined() |
|
20 | + public function testCommonsHouseDefined() |
|
21 | 21 | { |
22 | 22 | $this->assertEquals(1, HOUSE_TYPE_COMMONS); |
23 | 23 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * Test that the House of Lords is correctly defined. |
27 | 27 | */ |
28 | - public function testLordsHouseDefined() |
|
28 | + public function testLordsHouseDefined() |
|
29 | 29 | { |
30 | 30 | $this->assertEquals(2, HOUSE_TYPE_LORDS); |
31 | 31 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * Test that the Northern Ireland Assembly is correctly defined. |
35 | 35 | */ |
36 | - public function testNIHouseDefined() |
|
36 | + public function testNIHouseDefined() |
|
37 | 37 | { |
38 | 38 | $this->assertEquals(3, HOUSE_TYPE_NI); |
39 | 39 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * Test that the Scottish Parliament is correctly defined. |
43 | 43 | */ |
44 | - public function testScotlandHouseDefined() |
|
44 | + public function testScotlandHouseDefined() |
|
45 | 45 | { |
46 | 46 | $this->assertEquals(4, HOUSE_TYPE_SCOTLAND); |
47 | 47 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | /** |
50 | 50 | * Test that the Assembly for Wales is correctly defined. |
51 | 51 | */ |
52 | - public function testWalesHouseDefined() |
|
52 | + public function testWalesHouseDefined() |
|
53 | 53 | { |
54 | 54 | $this->assertEquals(5, HOUSE_TYPE_WALES); |
55 | 55 | } |
@@ -159,6 +159,9 @@ |
||
159 | 159 | } |
160 | 160 | } |
161 | 161 | |
162 | + /** |
|
163 | + * @param string $type |
|
164 | + */ |
|
162 | 165 | private function getMetadata($args="", $type) { |
163 | 166 | // $type is either 'page' or 'section' |
164 | 167 | global $this_page, $this_section; |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | public function __construct() { |
56 | 56 | |
57 | - include_once METADATAPATH; // defined in config.php |
|
57 | + include_once METADATAPATH; // defined in config.php |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | |
116 | 116 | public function set_page_metadata($page, $key, $value) { |
117 | - $this->setMetadata(array("page"=>$page,"key"=>$key,"value"=>$value)); |
|
117 | + $this->setMetadata(array("page"=>$page, "key"=>$key, "value"=>$value)); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | |
128 | 128 | public function set_section_metadata($section, $key, $value) { |
129 | - $this->setMetadata(array("section"=>$section,"key"=>$key,"value"=>$value)); |
|
129 | + $this->setMetadata(array("section"=>$section, "key"=>$key, "value"=>$value)); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | |
152 | 152 | public function test_for_metadata($type, $item, $key) { |
153 | - $dataarray =& $this->$type; |
|
153 | + $dataarray = & $this->$type; |
|
154 | 154 | |
155 | 155 | if (isset($dataarray[$item][$key])) { |
156 | 156 | return true; |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | } |
160 | 160 | } |
161 | 161 | |
162 | - private function getMetadata($args="", $type) { |
|
162 | + private function getMetadata($args = "", $type) { |
|
163 | 163 | // $type is either 'page' or 'section' |
164 | 164 | global $this_page, $this_section; |
165 | 165 | |
@@ -167,21 +167,21 @@ discard block |
||
167 | 167 | $item = $args[$type]; |
168 | 168 | $key = $args['key']; |
169 | 169 | } else { |
170 | - $var = "this_".$type; |
|
170 | + $var = "this_" . $type; |
|
171 | 171 | $item = $$var; // $this_page or $this_section. |
172 | 172 | $key = $args; |
173 | 173 | } |
174 | 174 | |
175 | 175 | twfy_debug("DATA", "$type: $item, $key"); |
176 | - $dataarray =& $this->$type; |
|
176 | + $dataarray = & $this->$type; |
|
177 | 177 | |
178 | 178 | if ($this->test_for_metadata($type, $item, $key)) { |
179 | 179 | $return = $dataarray[$item][$key]; |
180 | - $debugtext = "Key: ".$type."[".$item."][".$key."]"; |
|
180 | + $debugtext = "Key: " . $type . "[" . $item . "][" . $key . "]"; |
|
181 | 181 | |
182 | 182 | } elseif ($this->test_for_metadata($type, "default", $key)) { |
183 | 183 | $return = $dataarray["default"][$key]; |
184 | - $debugtext = "Key: ".$type."['default'][".$key."]"; |
|
184 | + $debugtext = "Key: " . $type . "['default'][" . $key . "]"; |
|
185 | 185 | |
186 | 186 | } else { |
187 | 187 | $return = false; |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | $key = $args["key"]; |
207 | 207 | $value = $args["value"]; |
208 | 208 | |
209 | - twfy_debug("DATA", "Setting: ".$type."[".$item."][".$key."] = '" . print_r($value, 1) . "'"); |
|
209 | + twfy_debug("DATA", "Setting: " . $type . "[" . $item . "][" . $key . "] = '" . print_r($value, 1) . "'"); |
|
210 | 210 | |
211 | - $dataarray =& $this->$type; |
|
211 | + $dataarray = & $this->$type; |
|
212 | 212 | $dataarray[$item][$key] = $value; |
213 | 213 | } |
214 | 214 |
@@ -121,7 +121,8 @@ discard block |
||
121 | 121 | public function metadata($type, $item, $key) { |
122 | 122 | if ($this->test_for_metadata($type, $item, $key)) { |
123 | 123 | return $this->$type[$item][$key]; |
124 | - } else { |
|
124 | + } |
|
125 | + else { |
|
125 | 126 | return "INVALID METADATA: $type[$item][$key]"; |
126 | 127 | } |
127 | 128 | } |
@@ -135,7 +136,8 @@ discard block |
||
135 | 136 | |
136 | 137 | if (isset($dataarray[$item][$key])) { |
137 | 138 | return true; |
138 | - } else { |
|
139 | + } |
|
140 | + else { |
|
139 | 141 | return false; |
140 | 142 | } |
141 | 143 | } |
@@ -152,7 +154,8 @@ discard block |
||
152 | 154 | if (is_array($args)) { |
153 | 155 | $item = $args[$type]; |
154 | 156 | $key = $args['key']; |
155 | - } else { |
|
157 | + } |
|
158 | + else { |
|
156 | 159 | $var = "this_".$type; |
157 | 160 | $item = $$var; // $this_page or $this_section. |
158 | 161 | $key = $args; |
@@ -165,11 +168,13 @@ discard block |
||
165 | 168 | $return = $dataarray[$item][$key]; |
166 | 169 | $debugtext = "Key: ".$type."[".$item."][".$key."]"; |
167 | 170 | |
168 | - } elseif ($this->test_for_metadata($type, "default", $key)) { |
|
171 | + } |
|
172 | + elseif ($this->test_for_metadata($type, "default", $key)) { |
|
169 | 173 | $return = $dataarray["default"][$key]; |
170 | 174 | $debugtext = "Key: ".$type."['default'][".$key."]"; |
171 | 175 | |
172 | - } else { |
|
176 | + } |
|
177 | + else { |
|
173 | 178 | $return = false; |
174 | 179 | $debugtext = "No metadata found for key '$key'"; |
175 | 180 | } |
@@ -184,7 +189,8 @@ discard block |
||
184 | 189 | if (isset($args["section"])) { |
185 | 190 | $type = "section"; |
186 | 191 | $item = $args["section"]; |
187 | - } else { |
|
192 | + } |
|
193 | + else { |
|
188 | 194 | $type = "page"; |
189 | 195 | $item = $args["page"]; |
190 | 196 | } |
@@ -175,6 +175,11 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | // After SELECT. |
178 | + |
|
179 | + /** |
|
180 | + * @param integer $row_index |
|
181 | + * @param string $column_name |
|
182 | + */ |
|
178 | 183 | public function field($row_index, $column_name) { |
179 | 184 | if ($this->rows > 0) |
180 | 185 | return $this->data[$row_index][$column_name]; |
@@ -187,6 +192,10 @@ discard block |
||
187 | 192 | } |
188 | 193 | |
189 | 194 | // After SELECT. |
195 | + |
|
196 | + /** |
|
197 | + * @param integer $row_index |
|
198 | + */ |
|
190 | 199 | public function row($row_index) { |
191 | 200 | if ($this->success && $this->rows > 0) |
192 | 201 | return $this->data[$row_index]; |
@@ -224,6 +233,9 @@ discard block |
||
224 | 233 | return $html; |
225 | 234 | } |
226 | 235 | |
236 | + /** |
|
237 | + * @param string $errormsg |
|
238 | + */ |
|
227 | 239 | public function error($errormsg) { |
228 | 240 | // When a query goes wrong... |
229 | 241 | $this->success = false; |
@@ -72,7 +72,6 @@ |
||
72 | 72 | * - `$this->field(n,col)` returns an empty string. |
73 | 73 | * - `$this->insert_id()` returns `null`. |
74 | 74 | * - `$this->affected_rows()` returns `null`. |
75 | - |
|
76 | 75 | */ |
77 | 76 | |
78 | 77 | class Query { |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | class Query { |
79 | 79 | |
80 | 80 | public $success = true; |
81 | - public $rows = NULL; |
|
81 | + public $rows = null; |
|
82 | 82 | public $data = array(); |
83 | - public $insert_id = NULL; |
|
84 | - public $affected_rows = NULL; |
|
83 | + public $insert_id = null; |
|
84 | + public $affected_rows = null; |
|
85 | 85 | |
86 | 86 | public function __construct($conn) { |
87 | 87 | $this->conn = $conn; |
88 | 88 | } |
89 | 89 | |
90 | - public function query($sql="", $params = NULL) { |
|
90 | + public function query($sql="", $params = null) { |
|
91 | 91 | |
92 | 92 | if (empty($sql)) { |
93 | 93 | $this->success = false; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | twfy_debug ("SQL", $sql); |
105 | 105 | twfy_debug ("SQL", print_r($params, 1)); |
106 | 106 | |
107 | - if ($params !== NULL) { |
|
107 | + if ($params !== null) { |
|
108 | 108 | // Prepare and execute a statement |
109 | 109 | $pdoStatement = $this->conn->prepare($sql); |
110 | 110 |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $this->conn = $conn; |
88 | 88 | } |
89 | 89 | |
90 | - public function query($sql="", $params = NULL) { |
|
90 | + public function query($sql = "", $params = NULL) { |
|
91 | 91 | |
92 | 92 | if (empty($sql)) { |
93 | 93 | $this->success = false; |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | return; |
102 | 102 | } |
103 | 103 | |
104 | - twfy_debug ("SQL", $sql); |
|
105 | - twfy_debug ("SQL", print_r($params, 1)); |
|
104 | + twfy_debug("SQL", $sql); |
|
105 | + twfy_debug("SQL", print_r($params, 1)); |
|
106 | 106 | |
107 | 107 | if ($params !== NULL) { |
108 | 108 | // Prepare and execute a statement |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | |
134 | 134 | if (!$this->success) return; |
135 | 135 | |
136 | - if ( (!$pdoStatement) or (empty($pdoStatement)) ) { |
|
136 | + if ((!$pdoStatement) or (empty($pdoStatement))) { |
|
137 | 137 | // A failed query. |
138 | 138 | $this->success = false; |
139 | 139 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | } |
156 | 156 | $this->affected_rows = $pdoStatement->rowCount(); |
157 | 157 | |
158 | - twfy_debug ("SQLRESULT", array($this, 'displayResult')); |
|
158 | + twfy_debug("SQLRESULT", array($this, 'displayResult')); |
|
159 | 159 | // mysql_free_result($q); |
160 | 160 | } |
161 | 161 | } |
@@ -112,7 +112,8 @@ discard block |
||
112 | 112 | |
113 | 113 | if (is_int($paramValue)) { |
114 | 114 | $paramType = \PDO::PARAM_INT; |
115 | - } else { |
|
115 | + } |
|
116 | + else { |
|
116 | 117 | $paramType = \PDO::PARAM_STR; |
117 | 118 | } |
118 | 119 | |
@@ -121,7 +122,8 @@ discard block |
||
121 | 122 | |
122 | 123 | $pdoStatement->execute(); |
123 | 124 | |
124 | - } else { |
|
125 | + } |
|
126 | + else { |
|
125 | 127 | // Execute the raw query |
126 | 128 | $pdoStatement = $this->conn->query($sql); |
127 | 129 | } |
@@ -131,13 +133,16 @@ discard block |
||
131 | 133 | $this->error($this->conn->errorCode() . ': ' . $this->conn->errorInfo()[2]); |
132 | 134 | } |
133 | 135 | |
134 | - if (!$this->success) return; |
|
136 | + if (!$this->success) { |
|
137 | + return; |
|
138 | + } |
|
135 | 139 | |
136 | 140 | if ( (!$pdoStatement) or (empty($pdoStatement)) ) { |
137 | 141 | // A failed query. |
138 | 142 | $this->success = false; |
139 | 143 | |
140 | - } else { |
|
144 | + } |
|
145 | + else { |
|
141 | 146 | |
142 | 147 | // A successful SELECT, SHOW, EXPLAIN or DESCRIBE query. |
143 | 148 | $this->success = true; |
@@ -150,7 +155,8 @@ discard block |
||
150 | 155 | // Sanity check that lastInsertId() is actually a number, otherwise panic |
151 | 156 | if (is_numeric($this->conn->lastInsertId())) { |
152 | 157 | $this->insert_id = (int) $this->conn->lastInsertId(); |
153 | - } else { |
|
158 | + } |
|
159 | + else { |
|
154 | 160 | throw new Exception('Last connection ID was not numeric!'); |
155 | 161 | } |
156 | 162 | $this->affected_rows = $pdoStatement->rowCount(); |
@@ -176,8 +182,9 @@ discard block |
||
176 | 182 | |
177 | 183 | // After SELECT. |
178 | 184 | public function field($row_index, $column_name) { |
179 | - if ($this->rows > 0) |
|
180 | - return $this->data[$row_index][$column_name]; |
|
185 | + if ($this->rows > 0) { |
|
186 | + return $this->data[$row_index][$column_name]; |
|
187 | + } |
|
181 | 188 | return ""; |
182 | 189 | } |
183 | 190 | |
@@ -188,8 +195,9 @@ discard block |
||
188 | 195 | |
189 | 196 | // After SELECT. |
190 | 197 | public function row($row_index) { |
191 | - if ($this->success && $this->rows > 0) |
|
192 | - return $this->data[$row_index]; |
|
198 | + if ($this->success && $this->rows > 0) { |
|
199 | + return $this->data[$row_index]; |
|
200 | + } |
|
193 | 201 | return array(); |
194 | 202 | } |
195 | 203 | |
@@ -212,7 +220,8 @@ discard block |
||
212 | 220 | if ($n == "email" || $n == "password" || $n == "postcode") { |
213 | 221 | // Don't want to risk this data being displayed on any page. |
214 | 222 | $html .= "<td>**MASKED**</td>"; |
215 | - } else { |
|
223 | + } |
|
224 | + else { |
|
216 | 225 | $html .= "<td>" . _htmlentities($field) . "</td>"; |
217 | 226 | } |
218 | 227 | } |
@@ -55,7 +55,7 @@ |
||
55 | 55 | * @param string $db_pass The password for the database user |
56 | 56 | * @param string $db_name The name of the database |
57 | 57 | * |
58 | - * @return true If the connection has been created successfully. |
|
58 | + * @return boolean If the connection has been created successfully. |
|
59 | 59 | */ |
60 | 60 | |
61 | 61 | public function init($db_host, $db_user, $db_pass, $db_name) { |
@@ -102,7 +102,7 @@ |
||
102 | 102 | * @return Query An object containing the results of the query. |
103 | 103 | */ |
104 | 104 | |
105 | - public function query($sql, $params = NULL) { |
|
105 | + public function query($sql, $params = null) { |
|
106 | 106 | |
107 | 107 | $start = getmicrotime(); |
108 | 108 | $q = new \MySociety\TheyWorkForYou\Db\Query($this->conn); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $duration = getmicrotime() - $start; |
112 | 112 | global $mysqltotalduration; |
113 | 113 | $mysqltotalduration += $duration; |
114 | - twfy_debug ("SQL", "Complete after $duration seconds."); |
|
114 | + twfy_debug("SQL", "Complete after $duration seconds."); |
|
115 | 115 | // We could also output $q->mysql_info() here, but that's for |
116 | 116 | // PHP >= 4.3.0. |
117 | 117 | return $q; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | |
127 | 127 | public function display_total_duration() { |
128 | 128 | global $mysqltotalduration; |
129 | - twfy_debug ("TIME", "Total time for MySQL queries on this page: " . $mysqltotalduration . " seconds."); |
|
129 | + twfy_debug("TIME", "Total time for MySQL queries on this page: " . $mysqltotalduration . " seconds."); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -92,7 +92,7 @@ |
||
92 | 92 | include_once (INCLUDESPATH."easyparliament/user.php"); |
93 | 93 | |
94 | 94 | // Test to see if this is a new-style template using the renderer class. |
95 | -if (! isset($new_style_template) OR $new_style_template !== TRUE) { |
|
95 | +if (! isset($new_style_template) or $new_style_template !== true) { |
|
96 | 96 | |
97 | 97 | // This is an old-style page. Use the old page classes. |
98 | 98 | include_once (INCLUDESPATH."easyparliament/page.php"); |
@@ -41,7 +41,9 @@ discard block |
||
41 | 41 | twfy_debug_timestamp("after including utility.php"); |
42 | 42 | |
43 | 43 | // Set the default timezone |
44 | -if(function_exists('date_default_timezone_set')) date_default_timezone_set(TIMEZONE); |
|
44 | +if(function_exists('date_default_timezone_set')) { |
|
45 | + date_default_timezone_set(TIMEZONE); |
|
46 | +} |
|
45 | 47 | |
46 | 48 | // Only do clever things with errors if we're not testing, otherwise show as default |
47 | 49 | |
@@ -51,7 +53,8 @@ discard block |
||
51 | 53 | $error_level = E_ALL & ~E_NOTICE; |
52 | 54 | if (DEVSITE) { |
53 | 55 | $error_level = E_ALL | E_STRICT; |
54 | - } elseif (version_compare(phpversion(), "5.3") >= 0) { |
|
56 | + } |
|
57 | + elseif (version_compare(phpversion(), "5.3") >= 0) { |
|
55 | 58 | $error_level = $error_level & ~E_DEPRECATED; |
56 | 59 | } |
57 | 60 | |
@@ -62,7 +65,8 @@ discard block |
||
62 | 65 | $whoops = new \Whoops\Run; |
63 | 66 | $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler); |
64 | 67 | $whoops->register(); |
65 | - } else { |
|
68 | + } |
|
69 | + else { |
|
66 | 70 | set_exception_handler("exception_handler"); |
67 | 71 | } |
68 | 72 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | First some things to help make our PHP nicer and betterer |
5 | 5 | ********************************************************************************/ |
6 | 6 | |
7 | -error_reporting (E_ALL); |
|
7 | +error_reporting(E_ALL); |
|
8 | 8 | |
9 | 9 | /******************************************************************************** |
10 | 10 | Now some constants that are the same for live and dev versions |
@@ -12,22 +12,22 @@ discard block |
||
12 | 12 | ********************************************************************************/ |
13 | 13 | |
14 | 14 | // In case we need to switch these off globally at some point... |
15 | -define ("ALLOWCOMMENTS", true); |
|
16 | -define ("ALLOWTRACKBACKS", true); |
|
15 | +define("ALLOWCOMMENTS", true); |
|
16 | +define("ALLOWTRACKBACKS", true); |
|
17 | 17 | |
18 | 18 | // These variables are so we can keep date/time formats consistent across the site |
19 | 19 | // and change them easily. |
20 | 20 | // Formats here: http://www.php.net/manual/en/function.date.php |
21 | -define ("LONGERDATEFORMAT", "l, j F Y");// Monday, 31 December 2003 |
|
22 | -define ("LONGDATEFORMAT", "j F Y"); // 31 December 2003 |
|
23 | -define ("SHORTDATEFORMAT", "j M Y"); // 31 Dec 2003 |
|
24 | -define ("TIMEFORMAT", "g:i a"); // 11:59 pm |
|
21 | +define("LONGERDATEFORMAT", "l, j F Y"); // Monday, 31 December 2003 |
|
22 | +define("LONGDATEFORMAT", "j F Y"); // 31 December 2003 |
|
23 | +define("SHORTDATEFORMAT", "j M Y"); // 31 Dec 2003 |
|
24 | +define("TIMEFORMAT", "g:i a"); // 11:59 pm |
|
25 | 25 | |
26 | -define ("SHORTDATEFORMAT_SQL", "%e %b %Y"); // 31 Dec 2003 |
|
27 | -define ("TIMEFORMAT_SQL", "%l:%i %p"); // 11:59 PM |
|
26 | +define("SHORTDATEFORMAT_SQL", "%e %b %Y"); // 31 Dec 2003 |
|
27 | +define("TIMEFORMAT_SQL", "%l:%i %p"); // 11:59 PM |
|
28 | 28 | |
29 | 29 | // Where we store the postcode of users if they search for an MP by postcode. |
30 | -define ('POSTCODE_COOKIE', 'eppc'); |
|
30 | +define('POSTCODE_COOKIE', 'eppc'); |
|
31 | 31 | |
32 | 32 | /******************************************************************************** |
33 | 33 | And now all the files we'll include on every page. |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | twfy_debug_timestamp("after including utility.php"); |
42 | 42 | |
43 | 43 | // Set the default timezone |
44 | -if(function_exists('date_default_timezone_set')) date_default_timezone_set(TIMEZONE); |
|
44 | +if (function_exists('date_default_timezone_set')) date_default_timezone_set(TIMEZONE); |
|
45 | 45 | |
46 | 46 | // Only do clever things with errors if we're not testing, otherwise show as default |
47 | 47 | |
@@ -70,42 +70,42 @@ discard block |
||
70 | 70 | |
71 | 71 | // The time the page starts, so we can display the total at the end. |
72 | 72 | // getmicrotime() is in utiltity.php. |
73 | -define ("STARTTIME", getmicrotime()); |
|
73 | +define("STARTTIME", getmicrotime()); |
|
74 | 74 | if (!isset($_SERVER['WINDIR'])) { |
75 | 75 | $rusage = getrusage(); |
76 | - define ('STARTTIMES', $rusage['ru_stime.tv_sec']*1000000 + $rusage['ru_stime.tv_usec']); |
|
77 | - define ('STARTTIMEU', $rusage['ru_utime.tv_sec']*1000000 + $rusage['ru_utime.tv_usec']); |
|
76 | + define('STARTTIMES', $rusage['ru_stime.tv_sec'] * 1000000 + $rusage['ru_stime.tv_usec']); |
|
77 | + define('STARTTIMEU', $rusage['ru_utime.tv_sec'] * 1000000 + $rusage['ru_utime.tv_usec']); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | $DATA = new \MySociety\TheyWorkForYou\Data; |
81 | 81 | |
82 | 82 | class ParlDB extends \MySociety\TheyWorkForYou\Db\Connection { |
83 | 83 | public function __construct() { |
84 | - $this->init (OPTION_TWFY_DB_HOST, OPTION_TWFY_DB_USER, OPTION_TWFY_DB_PASS, OPTION_TWFY_DB_NAME); |
|
84 | + $this->init(OPTION_TWFY_DB_HOST, OPTION_TWFY_DB_USER, OPTION_TWFY_DB_PASS, OPTION_TWFY_DB_NAME); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | -include_once (INCLUDESPATH."url.php"); |
|
88 | +include_once (INCLUDESPATH . "url.php"); |
|
89 | 89 | |
90 | 90 | $filter = new \MySociety\TheyWorkForYou\Utility\LibFilter; |
91 | 91 | |
92 | -include_once (INCLUDESPATH."easyparliament/user.php"); |
|
92 | +include_once (INCLUDESPATH . "easyparliament/user.php"); |
|
93 | 93 | |
94 | 94 | // Test to see if this is a new-style template using the renderer class. |
95 | -if (! isset($new_style_template) OR $new_style_template !== TRUE) { |
|
95 | +if (!isset($new_style_template) OR $new_style_template !== TRUE) { |
|
96 | 96 | |
97 | 97 | // This is an old-style page. Use the old page classes. |
98 | - include_once (INCLUDESPATH."easyparliament/page.php"); |
|
98 | + include_once (INCLUDESPATH . "easyparliament/page.php"); |
|
99 | 99 | |
100 | 100 | } |
101 | 101 | |
102 | -include_once (INCLUDESPATH."easyparliament/hansardlist.php"); |
|
103 | -include_once (INCLUDESPATH."dbtypes.php"); |
|
104 | -include_once (INCLUDESPATH."easyparliament/commentlist.php"); |
|
105 | -include_once (INCLUDESPATH."easyparliament/comment.php"); |
|
106 | -include_once (INCLUDESPATH."easyparliament/trackback.php"); |
|
102 | +include_once (INCLUDESPATH . "easyparliament/hansardlist.php"); |
|
103 | +include_once (INCLUDESPATH . "dbtypes.php"); |
|
104 | +include_once (INCLUDESPATH . "easyparliament/commentlist.php"); |
|
105 | +include_once (INCLUDESPATH . "easyparliament/comment.php"); |
|
106 | +include_once (INCLUDESPATH . "easyparliament/trackback.php"); |
|
107 | 107 | |
108 | 108 | // Added in as new module by Richard Allan MP |
109 | -include_once (INCLUDESPATH."easyparliament/alert.php"); |
|
109 | +include_once (INCLUDESPATH . "easyparliament/alert.php"); |
|
110 | 110 | |
111 | 111 | twfy_debug_timestamp("at end of init.php"); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $edittext = $menudata['text']; |
50 | 50 | $edittitle = $menudata['title']; |
51 | 51 | $EDITURL = new \URL('userviewself'); |
52 | - if ($this->page == 'userviewself' || $this->page == 'useredit' ) { |
|
52 | + if ($this->page == 'userviewself' || $this->page == 'useredit') { |
|
53 | 53 | $editclass = 'on'; |
54 | 54 | } else { |
55 | 55 | $editclass = ''; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | // The 'Log out' link. |
59 | 59 | $menudata = $this->pagedata->page_metadata('userlogout', 'menu'); |
60 | 60 | $logouttext = $menudata['text']; |
61 | - $logouttitle= $menudata['title']; |
|
61 | + $logouttitle = $menudata['title']; |
|
62 | 62 | |
63 | 63 | $LOGOUTURL = new \URL('userlogout'); |
64 | 64 | if ($this->page != 'userlogout') { |
@@ -38,7 +38,8 @@ discard block |
||
38 | 38 | //user logged in |
39 | 39 | if ($this->user->isloggedin()) { |
40 | 40 | $this->addLoggedInLinks(); |
41 | - } else { |
|
41 | + } |
|
42 | + else { |
|
42 | 43 | $this->addLoggedOutLinks(); |
43 | 44 | } |
44 | 45 | } |
@@ -51,7 +52,8 @@ discard block |
||
51 | 52 | $EDITURL = new \URL('userviewself'); |
52 | 53 | if ($this->page == 'userviewself' || $this->page == 'useredit' ) { |
53 | 54 | $editclass = 'on'; |
54 | - } else { |
|
55 | + } |
|
56 | + else { |
|
55 | 57 | $editclass = ''; |
56 | 58 | } |
57 | 59 | |
@@ -64,7 +66,8 @@ discard block |
||
64 | 66 | if ($this->page != 'userlogout') { |
65 | 67 | $LOGOUTURL->insert(array("ret"=>$this->returl)); |
66 | 68 | $logoutclass = ''; |
67 | - } else { |
|
69 | + } |
|
70 | + else { |
|
68 | 71 | $logoutclass = 'on'; |
69 | 72 | } |
70 | 73 | |
@@ -105,7 +108,8 @@ discard block |
||
105 | 108 | $JOINURL->insert(array("ret"=>$this->returl)); |
106 | 109 | } |
107 | 110 | $joinclass = ''; |
108 | - } else { |
|
111 | + } |
|
112 | + else { |
|
109 | 113 | $joinclass = 'on'; |
110 | 114 | } |
111 | 115 | |
@@ -127,7 +131,8 @@ discard block |
||
127 | 131 | $LOGINURL->insert(array("ret"=>$this->returl)); |
128 | 132 | } |
129 | 133 | $loginclass = ''; |
130 | - } else { |
|
134 | + } |
|
135 | + else { |
|
131 | 136 | $loginclass = 'on'; |
132 | 137 | } |
133 | 138 | |
@@ -153,7 +158,8 @@ discard block |
||
153 | 158 | $items = array('yourmp'); |
154 | 159 | if (\MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsScottish($this->user->postcode())) { |
155 | 160 | $items[] = 'yourmsp'; |
156 | - } elseif (\MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsNi($this->user->postcode())) { |
|
161 | + } |
|
162 | + elseif (\MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsNi($this->user->postcode())) { |
|
157 | 163 | $items[] = 'yourmla'; |
158 | 164 | } |
159 | 165 |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | |
27 | 27 | public function set($key, $value, $timeout = 3600) { |
28 | 28 | if (class_exists('\Memcached')) { |
29 | - self::$memcache->set(OPTION_TWFY_DB_NAME.':'.$key, $value, $timeout); |
|
29 | + self::$memcache->set(OPTION_TWFY_DB_NAME . ':' . $key, $value, $timeout); |
|
30 | 30 | } else { |
31 | - self::$memcache->set(OPTION_TWFY_DB_NAME.':'.$key, $value, MEMCACHE_COMPRESSED, $timeout); |
|
31 | + self::$memcache->set(OPTION_TWFY_DB_NAME . ':' . $key, $value, MEMCACHE_COMPRESSED, $timeout); |
|
32 | 32 | } |
33 | 33 | } |
34 | 34 | |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | // see http://php.net/manual/en/memcache.get.php#112056 for explanation of this |
37 | 37 | $was_found = false; |
38 | 38 | if (class_exists('\Memcached')) { |
39 | - $value = self::$memcache->get(OPTION_TWFY_DB_NAME.':'.$key, null, $was_found); |
|
39 | + $value = self::$memcache->get(OPTION_TWFY_DB_NAME . ':' . $key, null, $was_found); |
|
40 | 40 | } else { |
41 | - $value = self::$memcache->get(OPTION_TWFY_DB_NAME.':'.$key, $was_found); |
|
41 | + $value = self::$memcache->get(OPTION_TWFY_DB_NAME . ':' . $key, $was_found); |
|
42 | 42 | } |
43 | 43 | if ($was_found === false) { |
44 | 44 | return false; // mmmmm |
@@ -17,7 +17,8 @@ discard block |
||
17 | 17 | if (class_exists('\Memcached')) { |
18 | 18 | self::$memcache = new \Memcached; |
19 | 19 | self::$memcache->addServer('localhost', 11211); |
20 | - } else { |
|
20 | + } |
|
21 | + else { |
|
21 | 22 | self::$memcache = new \Memcache; |
22 | 23 | self::$memcache->connect('localhost', 11211); |
23 | 24 | } |
@@ -27,7 +28,8 @@ discard block |
||
27 | 28 | public function set($key, $value, $timeout = 3600) { |
28 | 29 | if (class_exists('\Memcached')) { |
29 | 30 | self::$memcache->set(OPTION_TWFY_DB_NAME.':'.$key, $value, $timeout); |
30 | - } else { |
|
31 | + } |
|
32 | + else { |
|
31 | 33 | self::$memcache->set(OPTION_TWFY_DB_NAME.':'.$key, $value, MEMCACHE_COMPRESSED, $timeout); |
32 | 34 | } |
33 | 35 | } |
@@ -37,12 +39,14 @@ discard block |
||
37 | 39 | $was_found = false; |
38 | 40 | if (class_exists('\Memcached')) { |
39 | 41 | $value = self::$memcache->get(OPTION_TWFY_DB_NAME.':'.$key, null, $was_found); |
40 | - } else { |
|
42 | + } |
|
43 | + else { |
|
41 | 44 | $value = self::$memcache->get(OPTION_TWFY_DB_NAME.':'.$key, $was_found); |
42 | 45 | } |
43 | 46 | if ($was_found === false) { |
44 | 47 | return false; // mmmmm |
45 | - } else { |
|
48 | + } |
|
49 | + else { |
|
46 | 50 | return $value; |
47 | 51 | } |
48 | 52 | } |