@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | |
45 | - public function display ($view, $args=array(), $format='html') { |
|
45 | + public function display($view, $args = array(), $format = 'html') { |
|
46 | 46 | // $view is what we're viewing by: |
47 | 47 | // 'ep' is all the comments attached to an epobject. |
48 | 48 | // 'user' is all the comments written by a user. |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | |
67 | 67 | } else { |
68 | 68 | // Don't have a valid $view; |
69 | - $PAGE->error_message ("You haven't specified a view type."); |
|
69 | + $PAGE->error_message("You haven't specified a view type."); |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | return true; |
86 | 86 | } |
87 | 87 | |
88 | - public function render($data, $format='html', $template='comments') { |
|
88 | + public function render($data, $format = 'html', $template = 'comments') { |
|
89 | 89 | include (INCLUDESPATH."easyparliament/templates/$format/$template.php"); |
90 | 90 | } |
91 | 91 | |
@@ -93,21 +93,21 @@ discard block |
||
93 | 93 | // Get all the data attached to an epobject. |
94 | 94 | global $PAGE; |
95 | 95 | |
96 | - twfy_debug (get_class($this), "getting data by epobject"); |
|
96 | + twfy_debug(get_class($this), "getting data by epobject"); |
|
97 | 97 | |
98 | 98 | // What we return. |
99 | 99 | $data = array(); |
100 | 100 | if (!is_numeric($args['epobject_id'])) { |
101 | - $PAGE->error_message ("Sorry, we don't have a valid epobject id"); |
|
101 | + $PAGE->error_message("Sorry, we don't have a valid epobject id"); |
|
102 | 102 | return $data; |
103 | 103 | } |
104 | 104 | |
105 | 105 | // For getting the data. |
106 | - $input = array ( |
|
107 | - 'amount' => array ( |
|
106 | + $input = array( |
|
107 | + 'amount' => array( |
|
108 | 108 | 'user' => true |
109 | 109 | ), |
110 | - 'where' => array ( |
|
110 | + 'where' => array( |
|
111 | 111 | 'comments.epobject_id=' => $args['epobject_id'], |
112 | 112 | #'visible=' => '1' |
113 | 113 | ), |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | // comments by things in $args? |
136 | 136 | global $PAGE; |
137 | 137 | |
138 | - twfy_debug (get_class($this), "getting data by user"); |
|
138 | + twfy_debug(get_class($this), "getting data by user"); |
|
139 | 139 | |
140 | 140 | // What we return. |
141 | 141 | $data = array(); |
142 | 142 | |
143 | 143 | if (!is_numeric($args['user_id'])) { |
144 | - $PAGE->error_message ("Sorry, we don't have a valid user id"); |
|
144 | + $PAGE->error_message("Sorry, we don't have a valid user id"); |
|
145 | 145 | return $data; |
146 | 146 | } |
147 | 147 | |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | $num = 10; |
152 | 152 | } |
153 | 153 | |
154 | - if (isset($args['page']) && is_numeric($args['page']) && $args['page']>1) { |
|
154 | + if (isset($args['page']) && is_numeric($args['page']) && $args['page'] > 1) { |
|
155 | 155 | $page = $args['page']; |
156 | 156 | } else { |
157 | 157 | $page = 1; |
158 | 158 | } |
159 | 159 | |
160 | - $limit = $num*($page-1) . ',' . $num; |
|
160 | + $limit = $num * ($page - 1).','.$num; |
|
161 | 161 | |
162 | 162 | // We're getting the most recent comments posted to epobjects. |
163 | 163 | // We're grouping them by epobject so we can just link to each hansard thing once. |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | |
194 | 194 | if ($q->rows() > 0) { |
195 | 195 | |
196 | - for ($n=0; $n<$q->rows(); $n++) { |
|
196 | + for ($n = 0; $n < $q->rows(); $n++) { |
|
197 | 197 | |
198 | 198 | // All the basic stuff... |
199 | - $comments[$n] = array ( |
|
199 | + $comments[$n] = array( |
|
200 | 200 | 'comment_id' => $q->field($n, 'comment_id'), |
201 | 201 | 'posted' => $q->field($n, 'posted'), |
202 | 202 | 'total_comments' => $q->field($n, 'total_comments'), |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | ); |
209 | 209 | |
210 | 210 | // Add the URL... |
211 | - $urldata = array ( |
|
211 | + $urldata = array( |
|
212 | 212 | 'major' => $q->field($n, 'major'), |
213 | 213 | 'gid' => $q->field($n, 'gid'), |
214 | 214 | 'comment_id' => $q->field($n, 'comment_id'), |
@@ -234,14 +234,14 @@ discard block |
||
234 | 234 | |
235 | 235 | $commentbodies = array(); |
236 | 236 | |
237 | - for ($n=0; $n<$r->rows(); $n++) { |
|
238 | - $commentbodies[ $r->field($n, 'comment_id') ] = $r->field($n, 'body'); |
|
237 | + for ($n = 0; $n < $r->rows(); $n++) { |
|
238 | + $commentbodies[$r->field($n, 'comment_id')] = $r->field($n, 'body'); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | // This does rely on both this and the previous query returning |
242 | 242 | // stuff in the same order... |
243 | 243 | foreach ($comments as $n => $commentdata) { |
244 | - $comments[$n]['body'] = $commentbodies[ $comments[$n]['comment_id'] ]; |
|
244 | + $comments[$n]['body'] = $commentbodies[$comments[$n]['comment_id']]; |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | $data['comments'] = $comments; |
250 | 250 | $data['results_per_page'] = $num; |
251 | 251 | $data['page'] = $page; |
252 | - $q = $this->db->query('SELECT COUNT(DISTINCT(epobject_id)) AS count FROM comments WHERE visible=1 AND user_id=' . $args['user_id']); |
|
252 | + $q = $this->db->query('SELECT COUNT(DISTINCT(epobject_id)) AS count FROM comments WHERE visible=1 AND user_id='.$args['user_id']); |
|
253 | 253 | $data['total_results'] = $q->field(0, 'count'); |
254 | 254 | return $data; |
255 | 255 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | // $args should contain 'num', indicating how many to get. |
262 | 262 | // and perhaps pid too, for a particular person |
263 | 263 | |
264 | - twfy_debug (get_class($this), "getting data by recent"); |
|
264 | + twfy_debug(get_class($this), "getting data by recent"); |
|
265 | 265 | |
266 | 266 | // What we return. |
267 | 267 | $data = array(); |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | $page = 1; |
279 | 279 | } |
280 | 280 | |
281 | - $limit = $num*($page-1) . ',' . $num; |
|
281 | + $limit = $num * ($page - 1).','.$num; |
|
282 | 282 | |
283 | 283 | $where = array( |
284 | 284 | 'visible=' => '1' |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | if (isset($args['pid']) && is_numeric($args['pid'])) { |
287 | 287 | $where['person_id='] = $args['pid']; |
288 | 288 | } |
289 | - $input = array ( |
|
290 | - 'amount' => array ( |
|
289 | + $input = array( |
|
290 | + 'amount' => array( |
|
291 | 291 | 'user' => true |
292 | 292 | ), |
293 | 293 | 'where' => $where, |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | $data['pid'] = $args['pid']; |
306 | 306 | $q = 'SELECT title, given_name, family_name, lordofname, house FROM member m, person_names p WHERE m.person_id=p.person_id AND p.type="name" AND left_house="9999-12-31" AND m.person_id = :pid'; |
307 | 307 | $q = $this->db->query($q, array(':pid' => $args['pid'])); |
308 | - $data['full_name'] = member_full_name($q->field(0, 'house'), $q->field(0, 'title'), $q->field(0, 'given_name'), $q->field(0, 'family_name'), $q->field(0,'lordofname')); |
|
308 | + $data['full_name'] = member_full_name($q->field(0, 'house'), $q->field(0, 'title'), $q->field(0, 'given_name'), $q->field(0, 'family_name'), $q->field(0, 'lordofname')); |
|
309 | 309 | $q = 'SELECT COUNT(*) AS count FROM comments,hansard WHERE visible=1 AND comments.epobject_id = hansard.epobject_id and hansard.person_id = :pid'; |
310 | 310 | $params[':pid'] = $args['pid']; |
311 | 311 | } else { |
@@ -319,15 +319,15 @@ discard block |
||
319 | 319 | public function _get_data_by_dates($args) { |
320 | 320 | // $args should contain start_date and end_date |
321 | 321 | |
322 | - twfy_debug (get_class($this), "getting data by recent"); |
|
322 | + twfy_debug(get_class($this), "getting data by recent"); |
|
323 | 323 | $data = array(); |
324 | 324 | $where = array( |
325 | 325 | 'visible=' => '1', |
326 | 326 | 'date(posted)>=' => $args['start_date'], |
327 | 327 | 'date(posted)<=' => $args['end_date'] |
328 | 328 | ); |
329 | - $input = array ( |
|
330 | - 'amount' => array ( |
|
329 | + $input = array( |
|
330 | + 'amount' => array( |
|
331 | 331 | 'user' => true |
332 | 332 | ), |
333 | 333 | 'where' => $where, |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | public function _get_data_by_search($args) { |
342 | 342 | // $args should contain 'num', indicating how many to get. |
343 | 343 | |
344 | - twfy_debug (get_class($this), "getting data by search"); |
|
344 | + twfy_debug(get_class($this), "getting data by search"); |
|
345 | 345 | |
346 | 346 | // What we return. |
347 | 347 | $data = array(); |
@@ -358,13 +358,13 @@ discard block |
||
358 | 358 | $page = 1; |
359 | 359 | } |
360 | 360 | |
361 | - $limit = $num*($page-1) . ',' . $num; |
|
361 | + $limit = $num * ($page - 1).','.$num; |
|
362 | 362 | |
363 | - $input = array ( |
|
364 | - 'amount' => array ( |
|
363 | + $input = array( |
|
364 | + 'amount' => array( |
|
365 | 365 | 'user'=> true |
366 | 366 | ), |
367 | - 'where' => array ( |
|
367 | + 'where' => array( |
|
368 | 368 | 'comments.body LIKE' => "%$args[s]%" |
369 | 369 | ), |
370 | 370 | 'order' => 'posted DESC', |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | // It returns the URL for the comment. |
392 | 392 | |
393 | 393 | $major = $urldata['major']; |
394 | - $gid = $urldata['gid']; |
|
394 | + $gid = $urldata['gid']; |
|
395 | 395 | $comment_id = $urldata['comment_id']; |
396 | 396 | $user_id = isset($urldata['user_id']) ? $urldata['user_id'] : false; |
397 | 397 | |
@@ -405,11 +405,11 @@ discard block |
||
405 | 405 | $URL = new URL($page); |
406 | 406 | |
407 | 407 | $gid = fix_gid_from_db($gid); // In includes/utility.php |
408 | - $URL->insert(array('id' => $gid )); |
|
408 | + $URL->insert(array('id' => $gid)); |
|
409 | 409 | if ($user_id) { |
410 | 410 | $URL->insert(array('u' => $user_id)); |
411 | 411 | } |
412 | - $url = $URL->generate() . '#c' . $comment_id; |
|
412 | + $url = $URL->generate().'#c'.$comment_id; |
|
413 | 413 | |
414 | 414 | return $url; |
415 | 415 | } |
@@ -483,9 +483,9 @@ discard block |
||
483 | 483 | $limit = isset($input['limit']) ? $input['limit'] : ''; |
484 | 484 | |
485 | 485 | // The fields to fetch from db. 'table' => array ('field1', 'field2'). |
486 | - $fieldsarr = array ( |
|
487 | - 'comments' => array ('comment_id', 'user_id', 'epobject_id', 'body', 'posted', 'modflagged', 'visible'), |
|
488 | - 'hansard' => array ('major', 'gid') |
|
486 | + $fieldsarr = array( |
|
487 | + 'comments' => array('comment_id', 'user_id', 'epobject_id', 'body', 'posted', 'modflagged', 'visible'), |
|
488 | + 'hansard' => array('major', 'gid') |
|
489 | 489 | ); |
490 | 490 | |
491 | 491 | // Yes, we need the gid of a comment's associated hansard object |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | |
497 | 497 | // Add on the stuff for getting a user's details. |
498 | 498 | if (isset($amount['user']) && $amount['user'] == true) { |
499 | - $fieldsarr['users'] = array ('firstname', 'lastname', 'user_id'); |
|
499 | + $fieldsarr['users'] = array('firstname', 'lastname', 'user_id'); |
|
500 | 500 | // Like doing "FROM comments, users" but it's easier to add |
501 | 501 | // an "INNER JOIN..." automatically to the query. |
502 | 502 | $join .= ' INNER JOIN users ON comments.user_id = users.user_id '; |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | $fieldsarr['epobject'] = array('body'); |
508 | 508 | } |
509 | 509 | |
510 | - $fieldsarr2 = array (); |
|
510 | + $fieldsarr2 = array(); |
|
511 | 511 | // Construct the $fields clause. |
512 | 512 | foreach ($fieldsarr as $table => $tablesfields) { |
513 | 513 | foreach ($tablesfields as $n => $field) { |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | $fields = implode(', ', $fieldsarr2); |
525 | 525 | |
526 | 526 | |
527 | - $wherearr2 = array (); |
|
527 | + $wherearr2 = array(); |
|
528 | 528 | $params = array(); |
529 | 529 | $i = 0; |
530 | 530 | // Construct the $where clause. |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | $params[":where$i"] = $val; |
534 | 534 | $i++; |
535 | 535 | } |
536 | - $where = implode (" AND ", $wherearr2); |
|
536 | + $where = implode(" AND ", $wherearr2); |
|
537 | 537 | |
538 | 538 | if ($order != '') { |
539 | 539 | $order = "ORDER BY $order"; |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | } |
545 | 545 | |
546 | 546 | // Finally, do the query! |
547 | - $q = $this->db->query ("SELECT $fields |
|
547 | + $q = $this->db->query("SELECT $fields |
|
548 | 548 | FROM comments |
549 | 549 | $join |
550 | 550 | WHERE $where |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | ", $params); |
554 | 554 | |
555 | 555 | // Format the data into an array for returning. |
556 | - $data = array (); |
|
556 | + $data = array(); |
|
557 | 557 | |
558 | 558 | if ($q->rows() > 0) { |
559 | 559 | |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | // We'll generate permalinks for each comment. |
564 | 564 | // Assuming every comment is from the same major... |
565 | 565 | |
566 | - for ($n=0; $n<$q->rows(); $n++) { |
|
566 | + for ($n = 0; $n < $q->rows(); $n++) { |
|
567 | 567 | |
568 | 568 | // Put each row returned into its own array in $data. |
569 | 569 | foreach ($fieldsarr as $table => $tablesfields) { |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | if (strstr(XAPIANDB, ":")) { |
47 | 47 | //ini_set('display_errors', 'On'); |
48 | 48 | list ($xapian_host, $xapian_port) = explode(":", XAPIANDB); |
49 | - twfy_debug("SEARCH", "Using Xapian remote backend: " . $xapian_host . " port " . $xapian_port); |
|
49 | + twfy_debug("SEARCH", "Using Xapian remote backend: ".$xapian_host." port ".$xapian_port); |
|
50 | 50 | $xapiandb_remote = remote_open($xapian_host, intval($xapian_port)); |
51 | 51 | $xapiandb = new XapianDatabase($xapiandb_remote); |
52 | 52 | } else { |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | $this->prefixed = array(); |
93 | 93 | |
94 | 94 | // Split words up into individual words, and quoted phrases |
95 | - preg_match_all('/(' . |
|
96 | - '"|' . # match either a quote, or... |
|
97 | - '(?:(?<![' .$this->wordchars. '])-)?' . # optionally a - (exclude) |
|
95 | + preg_match_all('/('. |
|
96 | + '"|'.# match either a quote, or... |
|
97 | + '(?:(?<!['.$this->wordchars.'])-)?'.# optionally a - (exclude) |
|
98 | 98 | # if at start of word (i.e. not preceded by a word character, in |
99 | 99 | # which case it is probably a hyphenated-word) |
100 | - '['.$this->wordchars.']+' . # followed by a string of word-characters |
|
100 | + '['.$this->wordchars.']+'.# followed by a string of word-characters |
|
101 | 101 | ')/', $this->query, $all_words); |
102 | 102 | if ($all_words) { |
103 | 103 | $all_words = $all_words[0]; |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | if (strpos($word, ':') !== false) { |
123 | 123 | $items = explode(":", strtolower($word)); |
124 | 124 | $type = $items[0]; |
125 | - if (substr($type, 0, 1)=='-') $type = substr($type, 1); |
|
126 | - $value = strtolower(join(":", array_slice($items,1))); |
|
125 | + if (substr($type, 0, 1) == '-') $type = substr($type, 1); |
|
126 | + $value = strtolower(join(":", array_slice($items, 1))); |
|
127 | 127 | if ($type == 'section') { |
128 | 128 | $newv = $value; |
129 | 129 | if ($value == 'debates' || $value == 'debate') $newv = 1; |
@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | elseif ($value == 'pbc' || $value == 'standing') $newv = 6; |
136 | 136 | elseif ($value == 'sp') $newv = 7; |
137 | 137 | elseif ($value == 'spwrans' || $value == 'spwran') $newv = 8; |
138 | - elseif ($value == 'uk') $newv = array(1,2,3,4,6,101); |
|
139 | - elseif ($value == 'scotland') $newv = array(7,8); |
|
138 | + elseif ($value == 'uk') $newv = array(1, 2, 3, 4, 6, 101); |
|
139 | + elseif ($value == 'scotland') $newv = array(7, 8); |
|
140 | 140 | elseif ($value == 'future') $newv = 'F'; |
141 | 141 | if (is_array($newv)) { |
142 | - $newv = 'major:' . join(' major:', $newv); |
|
142 | + $newv = 'major:'.join(' major:', $newv); |
|
143 | 143 | } else { |
144 | 144 | $newv = "major:$newv"; |
145 | 145 | } |
@@ -179,15 +179,15 @@ discard block |
||
179 | 179 | # Merged people |
180 | 180 | $db = new ParlDB; |
181 | 181 | $merged = $db->query('SELECT * FROM gidredirect WHERE gid_from LIKE :gid_from', array(':gid_from' => "uk.org.publicwhip/person/%")); |
182 | - for ($n=0; $n<$merged->rows(); $n++) { |
|
182 | + for ($n = 0; $n < $merged->rows(); $n++) { |
|
183 | 183 | $from_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_from')); |
184 | 184 | $to_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_to')); |
185 | 185 | $this->query = preg_replace("#speaker:($from_id|$to_id)#i", "(speaker:$from_id OR speaker:$to_id)", $this->query); |
186 | 186 | } |
187 | 187 | |
188 | - twfy_debug("SEARCH", "prefixed: " . var_export($this->prefixed, true)); |
|
188 | + twfy_debug("SEARCH", "prefixed: ".var_export($this->prefixed, true)); |
|
189 | 189 | |
190 | - twfy_debug("SEARCH", "query -- ". $this->query); |
|
190 | + twfy_debug("SEARCH", "query -- ".$this->query); |
|
191 | 191 | $flags = XapianQueryParser::FLAG_BOOLEAN | XapianQueryParser::FLAG_LOVEHATE | |
192 | 192 | XapianQueryParser::FLAG_WILDCARD | XapianQueryParser::FLAG_SPELLING_CORRECTION; |
193 | 193 | $flags = $flags | XapianQueryParser::FLAG_PHRASE; |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | # Now parse the parsed query back into a query string, yummy |
206 | 206 | |
207 | 207 | $qd = $query->get_description(); |
208 | - twfy_debug("SEARCH", "queryparser original description -- " . $qd); |
|
208 | + twfy_debug("SEARCH", "queryparser original description -- ".$qd); |
|
209 | 209 | $qd = substr($qd, 14, -1); # Strip Xapian::Query() |
210 | 210 | $qd = preg_replace('#:\(.*?\)#', '', $qd); # Don't need pos or weight |
211 | 211 | # Date range |
@@ -256,11 +256,11 @@ discard block |
||
256 | 256 | $iter->next(); |
257 | 257 | } |
258 | 258 | $used[] = $tt; |
259 | - $qd = preg_replace('#' . preg_quote($mm, '#') . '#', $tt, $qd, 1); |
|
259 | + $qd = preg_replace('#'.preg_quote($mm, '#').'#', $tt, $qd, 1); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | # Speakers |
263 | - for ($n=0; $n<$merged->rows(); $n++) { |
|
263 | + for ($n = 0; $n < $merged->rows(); $n++) { |
|
264 | 264 | $from_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_from')); |
265 | 265 | $to_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_to')); |
266 | 266 | $qd = str_replace("(S$from_id OR S$to_id)", "S$to_id", $qd); |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | $qd = preg_replace('#AND_NOT ([a-z0-9"]+)#', '-$1', $qd); |
279 | 279 | preg_match_all('#AND_NOT \((.*?)\)#', $qd, $m); |
280 | 280 | foreach ($m[1] as $mm) { |
281 | - $mmn = '-' . join(' -', explode(' OR ', $mm)); |
|
281 | + $mmn = '-'.join(' -', explode(' OR ', $mm)); |
|
282 | 282 | $qd = str_replace("AND_NOT ($mm)", $mmn, $qd); |
283 | 283 | } |
284 | 284 | |
@@ -297,9 +297,9 @@ discard block |
||
297 | 297 | $this->query_desc = trim($qd); |
298 | 298 | |
299 | 299 | #print 'DEBUG: ' . $query->get_description(); |
300 | - twfy_debug("SEARCH", "words: " . var_export($this->words, true)); |
|
301 | - twfy_debug("SEARCH", "phrases: " . var_export($this->phrases, true)); |
|
302 | - twfy_debug("SEARCH", "queryparser description -- " . $this->query_desc); |
|
300 | + twfy_debug("SEARCH", "words: ".var_export($this->words, true)); |
|
301 | + twfy_debug("SEARCH", "phrases: ".var_export($this->phrases, true)); |
|
302 | + twfy_debug("SEARCH", "queryparser description -- ".$this->query_desc); |
|
303 | 303 | |
304 | 304 | $this->valid = true; |
305 | 305 | } |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | } |
340 | 340 | |
341 | 341 | // Perform partial query to get a count of number of matches |
342 | - public function run_count($first_result, $results_per_page, $sort_order='relevance') { |
|
342 | + public function run_count($first_result, $results_per_page, $sort_order = 'relevance') { |
|
343 | 343 | if (!defined('XAPIANDB') || !XAPIANDB) |
344 | 344 | return null; |
345 | 345 | |
@@ -412,13 +412,13 @@ discard block |
||
412 | 412 | #} |
413 | 413 | |
414 | 414 | $duration = getmicrotime() - $start; |
415 | - twfy_debug ("SEARCH", "Search count took $duration seconds."); |
|
415 | + twfy_debug("SEARCH", "Search count took $duration seconds."); |
|
416 | 416 | |
417 | 417 | return $count; |
418 | 418 | } |
419 | 419 | |
420 | 420 | // Perform the full search... |
421 | - public function run_search($first_result, $results_per_page, $sort_order='relevance') { |
|
421 | + public function run_search($first_result, $results_per_page, $sort_order = 'relevance') { |
|
422 | 422 | $start = getmicrotime(); |
423 | 423 | |
424 | 424 | #$matches = $this->enquire->get_mset($first_result, $results_per_page); |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | $iter->next(); |
446 | 446 | } |
447 | 447 | $duration = getmicrotime() - $start; |
448 | - twfy_debug ("SEARCH", "Run search took $duration seconds."); |
|
448 | + twfy_debug("SEARCH", "Run search took $duration seconds."); |
|
449 | 449 | } |
450 | 450 | // ... use these to get the results |
451 | 451 | public function get_gids() { |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | if ($hl) { |
511 | 511 | $hlextract .= "<span class=\"hi\">$extractword</span>$endswithamp"; |
512 | 512 | } else { |
513 | - $hlextract .= $extractword . $endswithamp; |
|
513 | + $hlextract .= $extractword.$endswithamp; |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | $body = preg_replace("#</span>\s+<span class=\"hi\">#", " ", $hlextract); |
@@ -547,17 +547,17 @@ discard block |
||
547 | 547 | |
548 | 548 | // Find the position of the first of the search words/phrases in $body. |
549 | 549 | public function position_of_first_word($body) { |
550 | - $lcbody = ' ' . html_entity_decode(strtolower($body)) . ' '; // spaces to make regexp mapping easier |
|
550 | + $lcbody = ' '.html_entity_decode(strtolower($body)).' '; // spaces to make regexp mapping easier |
|
551 | 551 | $pos = -1; |
552 | 552 | |
553 | 553 | // look for phrases |
554 | 554 | foreach ($this->phrases as $phrase) { |
555 | 555 | $phrasematch = join($phrase, '[^'.$this->wordchars.']+'); |
556 | - if (preg_match('/([^'.$this->wordchars.']' . $phrasematch . '[^A-Za-z0-9])/', $lcbody, $matches)) |
|
556 | + if (preg_match('/([^'.$this->wordchars.']'.$phrasematch.'[^A-Za-z0-9])/', $lcbody, $matches)) |
|
557 | 557 | { |
558 | - $wordpos = strpos( $lcbody, $matches[0] ); |
|
558 | + $wordpos = strpos($lcbody, $matches[0]); |
|
559 | 559 | if ($wordpos) { |
560 | - if ( ($wordpos < $pos) || ($pos==-1) ) { |
|
560 | + if (($wordpos < $pos) || ($pos == -1)) { |
|
561 | 561 | $pos = $wordpos; |
562 | 562 | } |
563 | 563 | } |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | foreach ($stemmed_words as $word) { |
576 | 576 | if ($word == '') continue; |
577 | 577 | $matchword = $this->stem($extractword); |
578 | - if ($matchword == $word && ($wordpos < $pos || $pos==-1)) { |
|
578 | + if ($matchword == $word && ($wordpos < $pos || $pos == -1)) { |
|
579 | 579 | $pos = $wordpos; |
580 | 580 | } |
581 | 581 | } |
@@ -585,10 +585,10 @@ discard block |
||
585 | 585 | |
586 | 586 | foreach ($this->words as $word) { |
587 | 587 | if (ctype_digit($word)) $word = '(?:'.$word.'|'.number_format($word).')'; |
588 | - if (preg_match('/([^'.$this->wordchars.']' . $word . '[^'.$this->wordchars. '])/', $lcbody, $matches)) { |
|
589 | - $wordpos = strpos( $lcbody, $matches[0] ); |
|
588 | + if (preg_match('/([^'.$this->wordchars.']'.$word.'[^'.$this->wordchars.'])/', $lcbody, $matches)) { |
|
589 | + $wordpos = strpos($lcbody, $matches[0]); |
|
590 | 590 | if ($wordpos) { |
591 | - if ( ($wordpos < $pos) || ($pos==-1) ) { |
|
591 | + if (($wordpos < $pos) || ($pos == -1)) { |
|
592 | 592 | $pos = $wordpos; |
593 | 593 | } |
594 | 594 | } |
@@ -599,10 +599,10 @@ discard block |
||
599 | 599 | |
600 | 600 | foreach ($this->words as $word) { |
601 | 601 | if (ctype_digit($word)) $word = '(?:'.$word.'|'.number_format($word).')'; |
602 | - if (preg_match('/(' . $word . ')/', $lcbody, $matches)) { |
|
603 | - $wordpos = strpos( $lcbody, $matches[0] ); |
|
602 | + if (preg_match('/('.$word.')/', $lcbody, $matches)) { |
|
603 | + $wordpos = strpos($lcbody, $matches[0]); |
|
604 | 604 | if ($wordpos) { |
605 | - if ( ($wordpos < $pos) || ($pos==-1) ) { |
|
605 | + if (($wordpos < $pos) || ($pos == -1)) { |
|
606 | 606 | $pos = $wordpos; |
607 | 607 | } |
608 | 608 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | */ |
27 | 27 | |
28 | -if (defined('XAPIANDB') AND XAPIANDB != '') { |
|
28 | +if (defined('XAPIANDB') and XAPIANDB != '') { |
|
29 | 29 | if (file_exists('/usr/share/php/xapian.php')) { |
30 | 30 | include_once '/usr/share/php/xapian.php'; |
31 | 31 | } else { |
@@ -263,15 +263,15 @@ discard block |
||
263 | 263 | for ($n=0; $n<$merged->rows(); $n++) { |
264 | 264 | $from_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_from')); |
265 | 265 | $to_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_to')); |
266 | - $qd = str_replace("(S$from_id OR S$to_id)", "S$to_id", $qd); |
|
267 | - $qd = str_replace("S$from_id OR S$to_id", "S$to_id", $qd); |
|
266 | + $qd = str_replace("(S$from_id OR S$to_id)", "s$to_id", $qd); |
|
267 | + $qd = str_replace("s$from_id OR S$to_id", "s$to_id", $qd); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | preg_match_all('#S(\d+)#', $qd, $m); |
271 | 271 | foreach ($m[1] as $mm) { |
272 | 272 | $member = new MEMBER(array('person_id' => $mm)); |
273 | 273 | $name = $member->full_name(); |
274 | - $qd = str_replace("S$mm", "speaker:$name", $qd); |
|
274 | + $qd = str_replace("s$mm", "speaker:$name", $qd); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | # Simplify display of excluded words |
@@ -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"; |
@@ -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); |
@@ -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,36 +12,36 @@ 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. |
34 | 34 | ********************************************************************************/ |
35 | 35 | |
36 | 36 | // The Composer autoloader, which also handles our internal autoloading magic. |
37 | -require_once dirname(__FILE__) . '/../../../vendor/autoload.php'; |
|
37 | +require_once dirname(__FILE__).'/../../../vendor/autoload.php'; |
|
38 | 38 | |
39 | -include_once dirname(__FILE__) . '/../../../conf/general'; |
|
40 | -include_once INCLUDESPATH . 'utility.php'; |
|
39 | +include_once dirname(__FILE__).'/../../../conf/general'; |
|
40 | +include_once INCLUDESPATH.'utility.php'; |
|
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,18 +70,18 @@ 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 | |
@@ -92,7 +92,7 @@ discard block |
||
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"); |
@@ -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"); |