@@ -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,40 +70,40 @@ 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 | 88 | $filter = new \MySociety\TheyWorkForYou\Utility\LibFilter; |
89 | 89 | |
90 | -include_once (INCLUDESPATH."easyparliament/user.php"); |
|
90 | +include_once (INCLUDESPATH . "easyparliament/user.php"); |
|
91 | 91 | |
92 | 92 | // Test to see if this is a new-style template using the renderer class. |
93 | -if (! isset($new_style_template) OR $new_style_template !== TRUE) { |
|
93 | +if (!isset($new_style_template) OR $new_style_template !== TRUE) { |
|
94 | 94 | |
95 | 95 | // This is an old-style page. Use the old page classes. |
96 | - include_once (INCLUDESPATH."easyparliament/page.php"); |
|
96 | + include_once (INCLUDESPATH . "easyparliament/page.php"); |
|
97 | 97 | |
98 | 98 | } |
99 | 99 | |
100 | -include_once (INCLUDESPATH."easyparliament/hansardlist.php"); |
|
101 | -include_once (INCLUDESPATH."dbtypes.php"); |
|
102 | -include_once (INCLUDESPATH."easyparliament/commentlist.php"); |
|
103 | -include_once (INCLUDESPATH."easyparliament/comment.php"); |
|
104 | -include_once (INCLUDESPATH."easyparliament/trackback.php"); |
|
100 | +include_once (INCLUDESPATH . "easyparliament/hansardlist.php"); |
|
101 | +include_once (INCLUDESPATH . "dbtypes.php"); |
|
102 | +include_once (INCLUDESPATH . "easyparliament/commentlist.php"); |
|
103 | +include_once (INCLUDESPATH . "easyparliament/comment.php"); |
|
104 | +include_once (INCLUDESPATH . "easyparliament/trackback.php"); |
|
105 | 105 | |
106 | 106 | // Added in as new module by Richard Allan MP |
107 | -include_once (INCLUDESPATH."easyparliament/alert.php"); |
|
107 | +include_once (INCLUDESPATH . "easyparliament/alert.php"); |
|
108 | 108 | |
109 | 109 | twfy_debug_timestamp("at end of init.php"); |
@@ -18,10 +18,13 @@ |
||
18 | 18 | # Content goes here |
19 | 19 | foreach ($data['dates'] as $date => $day_events) { |
20 | 20 | foreach ($order as $i => $chamber) { |
21 | - if (!array_key_exists($chamber, $day_events)) |
|
22 | - continue; |
|
21 | + if (!array_key_exists($chamber, $day_events)) { |
|
22 | + continue; |
|
23 | + } |
|
23 | 24 | $events = $day_events[$chamber]; |
24 | - if ($plural[$i]) $chamber .= 's'; |
|
25 | + if ($plural[$i]) { |
|
26 | + $chamber .= 's'; |
|
27 | + } |
|
25 | 28 | print "<h2 class='calendar'>$chamber"; |
26 | 29 | if (in_array($major[$i], $data['majors'])) { |
27 | 30 | $URL = new \MySociety\TheyWorkForYou\Url($hansardmajors[$major[$i]]['page_all']); |
@@ -25,7 +25,7 @@ |
||
25 | 25 | print "<h2 class='calendar'>$chamber"; |
26 | 26 | if (in_array($major[$i], $data['majors'])) { |
27 | 27 | $URL = new \MySociety\TheyWorkForYou\Url($hansardmajors[$major[$i]]['page_all']); |
28 | - $URL->insert( array( 'd' => $date ) ); |
|
28 | + $URL->insert(array('d' => $date)); |
|
29 | 29 | print ' <a href="' . $URL->generate() . '">See this day →</a>'; |
30 | 30 | } |
31 | 31 | print "</h2>\n"; |
@@ -18,7 +18,9 @@ discard block |
||
18 | 18 | } |
19 | 19 | $PAGE->block_start(array('id'=>'recentcomments', 'title'=>$title)); |
20 | 20 | |
21 | - if ($this_page != 'home') $PAGE->page_links($data); |
|
21 | + if ($this_page != 'home') { |
|
22 | + $PAGE->page_links($data); |
|
23 | + } |
|
22 | 24 | $USERURL = new \MySociety\TheyWorkForYou\Url('userview'); |
23 | 25 | ?> |
24 | 26 | <ul> |
@@ -50,7 +52,9 @@ discard block |
||
50 | 52 | <p><a href="<?php echo $MOREURL->generate(); ?>#c<?php echo count($data['comments'])+1; ?>">See more annotations posted recently</a></p> |
51 | 53 | <?php |
52 | 54 | } |
53 | - if ($this_page != 'home') $PAGE->page_links($data); |
|
55 | + if ($this_page != 'home') { |
|
56 | + $PAGE->page_links($data); |
|
57 | + } |
|
54 | 58 | $PAGE->block_end(); |
55 | 59 | } |
56 | 60 | ?> |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $date = format_date($date, SHORTDATEFORMAT); |
34 | 34 | $time = format_time($time, TIMEFORMAT); |
35 | 35 | |
36 | - $count = $n+1; |
|
36 | + $count = $n + 1; |
|
37 | 37 | |
38 | 38 | $USERURL->insert(array('u'=>$comment['user_id'])); |
39 | 39 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | if ($this_page == 'home') { |
48 | 48 | $MOREURL = new \MySociety\TheyWorkForYou\Url('comments_recent'); |
49 | 49 | ?> |
50 | - <p><a href="<?php echo $MOREURL->generate(); ?>#c<?php echo count($data['comments'])+1; ?>">See more annotations posted recently</a></p> |
|
50 | + <p><a href="<?php echo $MOREURL->generate(); ?>#c<?php echo count($data['comments']) + 1; ?>">See more annotations posted recently</a></p> |
|
51 | 51 | <?php |
52 | 52 | } |
53 | 53 | if ($this_page != 'home') $PAGE->page_links($data); |
@@ -188,6 +188,9 @@ |
||
188 | 188 | return $items; |
189 | 189 | } |
190 | 190 | |
191 | + /** |
|
192 | + * @param \MySociety\TheyWorkForYou\Url $url |
|
193 | + */ |
|
191 | 194 | private function generate_pagination_links($data, $url, $first, $last) { |
192 | 195 | $links = array(); |
193 | 196 |
@@ -12,12 +12,12 @@ discard block |
||
12 | 12 | } |
13 | 13 | |
14 | 14 | $o = get_http_var('o'); |
15 | - $args = array ( |
|
15 | + $args = array( |
|
16 | 16 | 's' => $this->searchstring, |
17 | 17 | 'p' => $pagenum, |
18 | 18 | 'num' => get_http_var('num'), |
19 | 19 | 'pop' => get_http_var('pop'), |
20 | - 'o' => ($o=='d' || $o=='r' || $o=='o') ? $o : 'd', |
|
20 | + 'o' => ($o == 'd' || $o == 'r' || $o == 'o') ? $o : 'd', |
|
21 | 21 | ); |
22 | 22 | |
23 | 23 | return $args; |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | } |
56 | 56 | |
57 | 57 | $sort_order = 'newest'; |
58 | - if ( $args['o'] == 'o' ) { |
|
58 | + if ($args['o'] == 'o') { |
|
59 | 59 | $sort_order = 'oldest'; |
60 | - } else if ( $args['o'] == 'r' ) { |
|
60 | + } else if ($args['o'] == 'r') { |
|
61 | 61 | $sort_order = 'relevance'; |
62 | 62 | } |
63 | 63 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | return array('error' => $SEARCHENGINE->error); |
74 | 74 | } else { |
75 | 75 | $LIST = new \HANSARDLIST(); |
76 | - $data = $LIST->display('search', $args , 'none'); |
|
76 | + $data = $LIST->display('search', $args, 'none'); |
|
77 | 77 | $data['search_type'] = 'normal'; |
78 | 78 | $data['sort_order'] = $sort_order; |
79 | 79 | $data['members'] = $members; |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | |
96 | - list ($constituencies, ) = \MySociety\TheyWorkForYou\Utility\Search::searchConstituenciesByQuery($searchterm); |
|
96 | + list ($constituencies,) = \MySociety\TheyWorkForYou\Utility\Search::searchConstituenciesByQuery($searchterm); |
|
97 | 97 | |
98 | 98 | $constituency = ""; |
99 | - if (count($constituencies)==1) { |
|
99 | + if (count($constituencies) == 1) { |
|
100 | 100 | $constituency = $constituencies[0]; |
101 | 101 | } |
102 | 102 | |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | |
113 | 113 | $MEMBER = new \MySociety\TheyWorkForYou\Member(array('constituency'=>$constituency, 'house' => 1)); |
114 | 114 | $cons[] = $MEMBER; |
115 | - if ( $MEMBER->current_member(1) ) { |
|
115 | + if ($MEMBER->current_member(1)) { |
|
116 | 116 | $mp_types['mp']++; |
117 | 117 | } else { |
118 | 118 | $mp_types['former']++; |
119 | 119 | } |
120 | - } catch ( \MySociety\TheyWorkForYou\MemberException $e ) { |
|
120 | + } catch (\MySociety\TheyWorkForYou\MemberException $e) { |
|
121 | 121 | $cons = array(); |
122 | 122 | } |
123 | 123 | } elseif (count($constituencies)) { |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | try { |
126 | 126 | $MEMBER = new \MySociety\TheyWorkForYou\Member(array('constituency'=>$constituency, 'house' => 1)); |
127 | 127 | $cons[] = $MEMBER; |
128 | - if ( $MEMBER->current_member(1) ) { |
|
128 | + if ($MEMBER->current_member(1)) { |
|
129 | 129 | $mp_types['mp']++; |
130 | 130 | } else { |
131 | 131 | $mp_types['former']++; |
132 | 132 | } |
133 | - } catch ( \MySociety\TheyWorkForYou\MemberException $e ) { |
|
133 | + } catch (\MySociety\TheyWorkForYou\MemberException $e) { |
|
134 | 134 | continue; |
135 | 135 | } |
136 | 136 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | |
148 | 148 | $q = \MySociety\TheyWorkForYou\Utility\Search::searchMemberDbLookup($searchstring); |
149 | 149 | $row_count = $q->rows(); |
150 | - for ($n=0; $n<$row_count; $n++) { |
|
150 | + for ($n = 0; $n < $row_count; $n++) { |
|
151 | 151 | $members[] = $q->field($n, 'person_id'); |
152 | 152 | } |
153 | 153 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $q = $db->query("SELECT person FROM moffice WHERE position LIKE :pos ORDER BY from_date DESC, moffice_id", |
156 | 156 | array('pos' => "%$searchstring%")); |
157 | 157 | $row_count = $q->rows(); |
158 | - for ($n=0; $n<$row_count; $n++) { |
|
158 | + for ($n = 0; $n < $row_count; $n++) { |
|
159 | 159 | $members[] = $q->field($n, 'person'); |
160 | 160 | } |
161 | 161 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | $link = array( |
204 | 204 | 'url' => $url->generate(), |
205 | 205 | 'page' => $n, |
206 | - 'current' => ( $n == $data['page'] ) |
|
206 | + 'current' => ($n == $data['page']) |
|
207 | 207 | ); |
208 | 208 | |
209 | 209 | $links[] = $link; |
@@ -244,27 +244,27 @@ discard block |
||
244 | 244 | $numlinks = $this->generate_pagination_links($data, $URL, $firstpage, $lastpage); |
245 | 245 | |
246 | 246 | $pagelinks['nums'] = $numlinks; |
247 | - $pagelinks['first_result'] = $page == 1 ? 1 : ( ( $page - 1 ) * $results_per_page ) + 1; |
|
248 | - $pagelinks['last_result'] = $page == $numpages ? $total_results : $pagelinks['first_result'] + ( $results_per_page - 1 ); |
|
247 | + $pagelinks['first_result'] = $page == 1 ? 1 : (($page - 1) * $results_per_page) + 1; |
|
248 | + $pagelinks['last_result'] = $page == $numpages ? $total_results : $pagelinks['first_result'] + ($results_per_page - 1); |
|
249 | 249 | |
250 | - if ( $page != 1 ) { |
|
250 | + if ($page != 1) { |
|
251 | 251 | $prev_page = $page - 1; |
252 | - $URL->insert(array( 'p' => $prev_page ) ); |
|
252 | + $URL->insert(array('p' => $prev_page)); |
|
253 | 253 | $pagelinks['prev'] = array( |
254 | 254 | 'url' => $URL->generate() |
255 | 255 | ); |
256 | - $URL->insert(array( 'p' => 1 ) ); |
|
256 | + $URL->insert(array('p' => 1)); |
|
257 | 257 | $pagelinks['firstpage'] = array( |
258 | 258 | 'url' => $URL->generate() |
259 | 259 | ); |
260 | 260 | } |
261 | 261 | if ($page != $numpages) { |
262 | 262 | $next_page = $page + 1; |
263 | - $URL->insert(array( 'p' => $next_page ) ); |
|
263 | + $URL->insert(array('p' => $next_page)); |
|
264 | 264 | $pagelinks['next'] = array( |
265 | 265 | 'url' => $URL->generate() |
266 | 266 | ); |
267 | - $URL->insert(array( 'p' => $numpages ) ); |
|
267 | + $URL->insert(array('p' => $numpages)); |
|
268 | 268 | $pagelinks['lastpage'] = array( |
269 | 269 | 'url' => $URL->generate() |
270 | 270 | ); |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | $links['rss'] = $DATA->page_metadata($this_page, 'rss'); |
282 | 282 | |
283 | 283 | if ($SEARCHENGINE) { |
284 | - $links['email'] = '/alert/?' . ($this->searchstring ? 'alertsearch='.urlencode($this->searchstring) : ''); |
|
284 | + $links['email'] = '/alert/?' . ($this->searchstring ? 'alertsearch=' . urlencode($this->searchstring) : ''); |
|
285 | 285 | $links['email_desc'] = $SEARCHENGINE->query_description_long(); |
286 | 286 | } |
287 | 287 | |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | $search_engine = new \SEARCHENGINE($filter_ss); |
296 | 296 | $links['email_section'] = $links['email']; |
297 | 297 | $links['email_desc_section'] = $links['email_desc']; |
298 | - $links['email'] = '/alert/?' . ($filter_ss ? 'alertsearch='.urlencode($filter_ss) : ''); |
|
298 | + $links['email'] = '/alert/?' . ($filter_ss ? 'alertsearch=' . urlencode($filter_ss) : ''); |
|
299 | 299 | $links['email_desc'] = $search_engine->query_description_long(); |
300 | 300 | } |
301 | 301 |
@@ -57,7 +57,8 @@ discard block |
||
57 | 57 | $sort_order = 'newest'; |
58 | 58 | if ( $args['o'] == 'o' ) { |
59 | 59 | $sort_order = 'oldest'; |
60 | - } else if ( $args['o'] == 'r' ) { |
|
60 | + } |
|
61 | + else if ( $args['o'] == 'r' ) { |
|
61 | 62 | $sort_order = 'relevance'; |
62 | 63 | } |
63 | 64 | |
@@ -71,7 +72,8 @@ discard block |
||
71 | 72 | |
72 | 73 | if (!$SEARCHENGINE->valid) { |
73 | 74 | return array('error' => $SEARCHENGINE->error); |
74 | - } else { |
|
75 | + } |
|
76 | + else { |
|
75 | 77 | $LIST = new \HANSARDLIST(); |
76 | 78 | $data = $LIST->display('search', $args , 'none'); |
77 | 79 | $data['search_type'] = 'normal'; |
@@ -89,7 +91,8 @@ discard block |
||
89 | 91 | private function find_constituency($args) { |
90 | 92 | if ($args['s'] != '') { |
91 | 93 | $searchterm = $args['s']; |
92 | - } else { |
|
94 | + } |
|
95 | + else { |
|
93 | 96 | return false; |
94 | 97 | } |
95 | 98 | |
@@ -114,20 +117,23 @@ discard block |
||
114 | 117 | $cons[] = $MEMBER; |
115 | 118 | if ( $MEMBER->current_member(1) ) { |
116 | 119 | $mp_types['mp']++; |
117 | - } else { |
|
120 | + } |
|
121 | + else { |
|
118 | 122 | $mp_types['former']++; |
119 | 123 | } |
120 | 124 | } catch ( \MySociety\TheyWorkForYou\MemberException $e ) { |
121 | 125 | $cons = array(); |
122 | 126 | } |
123 | - } elseif (count($constituencies)) { |
|
127 | + } |
|
128 | + elseif (count($constituencies)) { |
|
124 | 129 | foreach ($constituencies as $constituency) { |
125 | 130 | try { |
126 | 131 | $MEMBER = new \MySociety\TheyWorkForYou\Member(array('constituency'=>$constituency, 'house' => 1)); |
127 | 132 | $cons[] = $MEMBER; |
128 | 133 | if ( $MEMBER->current_member(1) ) { |
129 | 134 | $mp_types['mp']++; |
130 | - } else { |
|
135 | + } |
|
136 | + else { |
|
131 | 137 | $mp_types['former']++; |
132 | 138 | } |
133 | 139 | } catch ( \MySociety\TheyWorkForYou\MemberException $e ) { |
@@ -141,7 +147,9 @@ discard block |
||
141 | 147 | |
142 | 148 | private function find_members() { |
143 | 149 | $searchstring = trim(preg_replace('#-?[a-z]+:[a-z0-9]+#', '', $this->searchstring)); |
144 | - if (!$searchstring) return array(); |
|
150 | + if (!$searchstring) { |
|
151 | + return array(); |
|
152 | + } |
|
145 | 153 | |
146 | 154 | $members = array(); |
147 | 155 | |
@@ -195,7 +203,8 @@ discard block |
||
195 | 203 | |
196 | 204 | if ($n > 1) { |
197 | 205 | $url->insert(array('p'=>$n)); |
198 | - } else { |
|
206 | + } |
|
207 | + else { |
|
199 | 208 | // No page number for the first page. |
200 | 209 | $url->remove(array('p')); |
201 | 210 | } |
@@ -229,7 +238,8 @@ discard block |
||
229 | 238 | if ($page < 10) { |
230 | 239 | $firstpage = 1; |
231 | 240 | $lastpage = 10; |
232 | - } else { |
|
241 | + } |
|
242 | + else { |
|
233 | 243 | $firstpage = $page - 4; |
234 | 244 | $lastpage = $page + 5; |
235 | 245 | } |
@@ -114,7 +114,7 @@ |
||
114 | 114 | /** |
115 | 115 | * Remove Session Key/Value Pair |
116 | 116 | * |
117 | - * @param array $arr A list array of key names to remove |
|
117 | + * @param string[] $arr A list array of key names to remove |
|
118 | 118 | */ |
119 | 119 | |
120 | 120 | public function remove($arr) { |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | // These stores an associative array of key/value pairs that |
44 | 44 | // we'll want passed on to other pages. |
45 | - $this->session_vars = array (); |
|
45 | + $this->session_vars = array(); |
|
46 | 46 | |
47 | 47 | // Prevent things using $DATA running if it hasn't been set, ie in testing |
48 | 48 | if (isset($DATA)) { |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | |
94 | 94 | public function reset() { |
95 | 95 | // Call this to remove all the session_vars. |
96 | - $this->session_vars = array (); |
|
96 | + $this->session_vars = array(); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | * override just one or two of them. |
163 | 163 | */ |
164 | 164 | |
165 | - public function generate($encode = "html", $overrideVars=array()) { |
|
165 | + public function generate($encode = "html", $overrideVars = array()) { |
|
166 | 166 | |
167 | 167 | global $DATA; |
168 | 168 | |
169 | - $url_args = array (); |
|
169 | + $url_args = array(); |
|
170 | 170 | |
171 | 171 | foreach (array_merge($this->session_vars, $overrideVars) as $key => $var) { |
172 | 172 | if (is_array($var)) { |
@@ -173,18 +173,22 @@ |
||
173 | 173 | foreach ($var as $v) { |
174 | 174 | $url_args[] = "$key=" . urlencode(stripslashes($v)); |
175 | 175 | } |
176 | - } elseif ($var != null) |
|
177 | - $url_args[] = "$key=" . urlencode(stripslashes($var)); |
|
176 | + } |
|
177 | + elseif ($var != null) { |
|
178 | + $url_args[] = "$key=" . urlencode(stripslashes($var)); |
|
179 | + } |
|
178 | 180 | } |
179 | 181 | |
180 | 182 | $page_url = WEBPATH . $DATA->page_metadata($this->destinationpage, "url"); |
181 | 183 | |
182 | 184 | if (sizeof($url_args) == 0) { |
183 | 185 | return $page_url; |
184 | - } else { |
|
186 | + } |
|
187 | + else { |
|
185 | 188 | if ($encode == "html") { |
186 | 189 | return $page_url . "?" . implode("&", $url_args); |
187 | - } elseif ($encode == "none" || $encode == "url") { |
|
190 | + } |
|
191 | + elseif ($encode == "none" || $encode == "url") { |
|
188 | 192 | return $page_url . "?" . implode("&", $url_args); |
189 | 193 | } |
190 | 194 | } |
@@ -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 | } |