@@ -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 | ) |
@@ -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 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | public function escape_comments($data) { |
156 | 156 | |
157 | 157 | $data = preg_replace_callback("/<!--(.*?)-->/s", function($matches) { |
158 | - return '<!--' . HtmlSpecialChars($this->StripSingle($matches[1])) . '-->'; |
|
158 | + return '<!--'.HtmlSpecialChars($this->StripSingle($matches[1])).'-->'; |
|
159 | 159 | }, $data); |
160 | 160 | |
161 | 161 | return $data; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | }, $data); |
210 | 210 | |
211 | 211 | foreach (array_keys($this->tag_counts) as $tag) { |
212 | - for ($i=0; $i<$this->tag_counts[$tag]; $i++) { |
|
212 | + for ($i = 0; $i < $this->tag_counts[$tag]; $i++) { |
|
213 | 213 | $data .= "</$tag>"; |
214 | 214 | } |
215 | 215 | } |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | $ending = $matches[3]; |
245 | 245 | if (in_array($name, array_keys($this->allowed))) { |
246 | 246 | $params = ""; |
247 | - preg_match_all("/([a-z0-9]+)=([\"'])(.*?)\\2/si", $body, $matches_2, PREG_SET_ORDER); # <foo a="b" /> |
|
248 | - preg_match_all("/([a-z0-9]+)(=)([^\"\s']+)/si", $body, $matches_1, PREG_SET_ORDER); # <foo a=b /> |
|
249 | - preg_match_all("/([a-z0-9]+)=([\"'])([^\"']*?)\s*$/si", $body, $matches_3, PREG_SET_ORDER); # <foo a="b /> |
|
247 | + preg_match_all("/([a-z0-9]+)=([\"'])(.*?)\\2/si", $body, $matches_2, PREG_SET_ORDER); # <foo a="b" /> |
|
248 | + preg_match_all("/([a-z0-9]+)(=)([^\"\s']+)/si", $body, $matches_1, PREG_SET_ORDER); # <foo a=b /> |
|
249 | + preg_match_all("/([a-z0-9]+)=([\"'])([^\"']*?)\s*$/si", $body, $matches_3, PREG_SET_ORDER); # <foo a="b /> |
|
250 | 250 | $matches = array_merge($matches_1, $matches_2, $matches_3); |
251 | 251 | |
252 | 252 | foreach ($matches as $match) { |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | |
303 | 303 | if (preg_match("/^([^:]+)\:/si", $data, $matches)) { |
304 | 304 | if (!in_array($matches[1], $this->allowed_protocols)) { |
305 | - $data = '#'.substr($data, strlen($matches[1])+1); |
|
305 | + $data = '#'.substr($data, strlen($matches[1]) + 1); |
|
306 | 306 | } |
307 | 307 | } |
308 | 308 | |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | # if there are less than 5, just allow it as-is |
353 | 353 | # |
354 | 354 | |
355 | - if (strlen($data_notags)<5) { |
|
355 | + if (strlen($data_notags) < 5) { |
|
356 | 356 | return $data; |
357 | 357 | } |
358 | 358 | |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | # inside strings. within general text, we decode hex/dec entities. |
563 | 563 | # |
564 | 564 | |
565 | - public function decode_entities($data, $in_attribute=1) { |
|
565 | + public function decode_entities($data, $in_attribute = 1) { |
|
566 | 566 | |
567 | 567 | $data = preg_replace_callback('!(&)#(\d+);?!', array($this, 'decode_dec_entity'), $data); |
568 | 568 | $data = preg_replace_callback('!(&)#x([0-9a-f]+);?!i', array($this, 'decode_hex_entity'), $data); |
@@ -324,7 +324,9 @@ |
||
324 | 324 | while (1) { |
325 | 325 | $len = strlen($data); |
326 | 326 | $data = preg_replace("/<({$tags})(\s[^>]*)?(><\\/\\1>|\\/>)/", '', $data); |
327 | - if ($len == strlen($data)) break; |
|
327 | + if ($len == strlen($data)) { |
|
328 | + break; |
|
329 | + } |
|
328 | 330 | } |
329 | 331 | } |
330 | 332 |
@@ -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 | |
@@ -173,7 +173,7 @@ discard block |
||
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]; |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $debugtext = "No metadata found for key '$key'"; |
189 | 189 | } |
190 | 190 | |
191 | - twfy_debug("DATA", "$debugtext, returning '" . (is_scalar($return) ? $return : gettype($return)) . "'."); |
|
191 | + twfy_debug("DATA", "$debugtext, returning '".(is_scalar($return) ? $return : gettype($return))."'."); |
|
192 | 192 | |
193 | 193 | return $return; |
194 | 194 | } |
@@ -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 |
@@ -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 { |
@@ -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 |
@@ -128,12 +128,12 @@ discard block |
||
128 | 128 | |
129 | 129 | // Test the query actually worked |
130 | 130 | if (!$pdoStatement) { |
131 | - $this->error($this->conn->errorCode() . ': ' . $this->conn->errorInfo()[2]); |
|
131 | + $this->error($this->conn->errorCode().': '.$this->conn->errorInfo()[2]); |
|
132 | 132 | } |
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 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $html .= "<table border=\"1\">\n<tr>\n"; |
203 | 203 | |
204 | 204 | foreach (array_keys($this->data[0]) as $fieldname) { |
205 | - $html .= "<th>" . _htmlentities($fieldname) . "</th>"; |
|
205 | + $html .= "<th>"._htmlentities($fieldname)."</th>"; |
|
206 | 206 | } |
207 | 207 | $html .= "</tr>\n"; |
208 | 208 | |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | // Don't want to risk this data being displayed on any page. |
214 | 214 | $html .= "<td>**MASKED**</td>"; |
215 | 215 | } else { |
216 | - $html .= "<td>" . _htmlentities($field) . "</td>"; |
|
216 | + $html .= "<td>"._htmlentities($field)."</td>"; |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | $html .= "</tr>\n"; |
@@ -152,7 +152,9 @@ discard block |
||
152 | 152 | $this->error($this->conn->errorCode() . ': ' . $this->conn->errorInfo()[2]); |
153 | 153 | } |
154 | 154 | |
155 | - if (!$this->success) return; |
|
155 | + if (!$this->success) { |
|
156 | + return; |
|
157 | + } |
|
156 | 158 | |
157 | 159 | if ( (!$pdoStatement) or (empty($pdoStatement)) ) { |
158 | 160 | // A failed query. |
@@ -197,8 +199,9 @@ discard block |
||
197 | 199 | |
198 | 200 | // After SELECT. |
199 | 201 | public function field($row_index, $column_name) { |
200 | - if ($this->rows > 0) |
|
201 | - return $this->data[$row_index][$column_name]; |
|
202 | + if ($this->rows > 0) { |
|
203 | + return $this->data[$row_index][$column_name]; |
|
204 | + } |
|
202 | 205 | return ""; |
203 | 206 | } |
204 | 207 | |
@@ -209,8 +212,9 @@ discard block |
||
209 | 212 | |
210 | 213 | // After SELECT. |
211 | 214 | public function row($row_index) { |
212 | - if ($this->success && $this->rows > 0) |
|
213 | - return $this->data[$row_index]; |
|
215 | + if ($this->success && $this->rows > 0) { |
|
216 | + return $this->data[$row_index]; |
|
217 | + } |
|
214 | 218 | return array(); |
215 | 219 | } |
216 | 220 |
@@ -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 |
@@ -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) { |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | // These vars come from config.php. |
64 | 64 | |
65 | 65 | if (!$global_connection) { |
66 | - $dsn = 'mysql:charset=utf8;dbname=' . $db_name . ';host=' . $db_host; |
|
66 | + $dsn = 'mysql:charset=utf8;dbname='.$db_name.';host='.$db_host; |
|
67 | 67 | |
68 | 68 | try { |
69 | 69 | $conn = new \PDO($dsn, $db_user, $db_pass); |
@@ -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 | /** |
@@ -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); |