@@ -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 | } |
@@ -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); |
@@ -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 |
@@ -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"; |
@@ -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"); |
@@ -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 | /** |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -include_once INCLUDESPATH . '../../commonlib/phplib/gaze.php'; |
|
4 | -include_once INCLUDESPATH . 'easyparliament/member.php'; |
|
3 | +include_once INCLUDESPATH.'../../commonlib/phplib/gaze.php'; |
|
4 | +include_once INCLUDESPATH.'easyparliament/member.php'; |
|
5 | 5 | |
6 | 6 | class PAGE { |
7 | 7 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | public $within_stripe_sidebar = false; |
20 | 20 | |
21 | 21 | public function page_start() { |
22 | - if ( !$this->page_started() ) { |
|
22 | + if (!$this->page_started()) { |
|
23 | 23 | $this->checkForAdmin(); |
24 | 24 | $this->displayHeader(); |
25 | 25 | } |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | |
33 | 33 | $data = $h->data; |
34 | 34 | $data = array_merge($u->data, $data); |
35 | - if ( isset($page_errors) ) { |
|
35 | + if (isset($page_errors)) { |
|
36 | 36 | $data['page_errors'] = $page_errors; |
37 | 37 | } |
38 | 38 | $data['banner_text'] = ''; |
39 | 39 | extract($data); |
40 | - require_once INCLUDESPATH . 'easyparliament/templates/html/header.php'; |
|
40 | + require_once INCLUDESPATH.'easyparliament/templates/html/header.php'; |
|
41 | 41 | |
42 | 42 | echo '<div class="full-page legacy-page static-page"> <div class="full-page__row"> <div class="panel">'; |
43 | 43 | |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | $THISPAGE = new \MySociety\TheyWorkForYou\Url($this_page); |
53 | 53 | |
54 | 54 | $LOGINURL = new \MySociety\TheyWorkForYou\Url('userlogin'); |
55 | - $LOGINURL->insert(array('ret' => $THISPAGE->generate('none') )); |
|
55 | + $LOGINURL->insert(array('ret' => $THISPAGE->generate('none'))); |
|
56 | 56 | |
57 | - $text = "<a href=\"" . $LOGINURL->generate() . "\">You'd better sign in!</a>"; |
|
57 | + $text = "<a href=\"".$LOGINURL->generate()."\">You'd better sign in!</a>"; |
|
58 | 58 | } else { |
59 | 59 | $text = "That's all folks!"; |
60 | 60 | } |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | public function page_end() { |
70 | - if ( !$this->page_started() ) { |
|
70 | + if (!$this->page_started()) { |
|
71 | 71 | $this->page_start(); |
72 | 72 | } |
73 | 73 | |
74 | 74 | echo '</div></div></div>'; |
75 | 75 | $footer = new MySociety\TheyWorkForYou\Renderer\Footer(); |
76 | 76 | $footer_links = $footer->data; |
77 | - require_once INCLUDESPATH . 'easyparliament/templates/html/footer.php'; |
|
77 | + require_once INCLUDESPATH.'easyparliament/templates/html/footer.php'; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | public function page_started() { |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | - public function stripe_start($type='side', $id='', $extra_class = '') { |
|
104 | + public function stripe_start($type = 'side', $id = '', $extra_class = '') { |
|
105 | 105 | // $type is one of: |
106 | 106 | // 'full' - a full width div |
107 | 107 | // 'side' - a white stripe with a coloured sidebar. |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | // 'foot' - For the bottom stripe on hansard debates/wrans listings. |
115 | 115 | // $id is the value of an id for this div (if blank, not used). |
116 | 116 | ?> |
117 | - <div class="stripe-<?php echo $type; ?><?php if ($extra_class != '') echo ' ' . $extra_class; ?>"<?php |
|
117 | + <div class="stripe-<?php echo $type; ?><?php if ($extra_class != '') echo ' '.$extra_class; ?>"<?php |
|
118 | 118 | if ($id != '') { |
119 | - print ' id="' . $id . '"'; |
|
119 | + print ' id="'.$id.'"'; |
|
120 | 120 | } |
121 | 121 | ?>> |
122 | 122 | <div class="main"> |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | |
134 | - public function stripe_end ($contents = array(), $extra = '') { |
|
134 | + public function stripe_end($contents = array(), $extra = '') { |
|
135 | 135 | // $contents is an array containing 0 or more hashes. |
136 | 136 | // Each hash has two values, 'type' and 'content'. |
137 | 137 | // 'Type' could be one of these: |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | } |
243 | 243 | |
244 | 244 | |
245 | - public function block_start($data=array()) { |
|
245 | + public function block_start($data = array()) { |
|
246 | 246 | // Starts a 'block' div, used mostly on the home page, |
247 | 247 | // on the MP page, and in the sidebars. |
248 | 248 | // $data is a hash like this: |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | $this->blockbody_open = false; |
256 | 256 | |
257 | 257 | if (isset($data['id']) && $data['id'] != '') { |
258 | - $id = ' id="' . $data['id'] . '"'; |
|
258 | + $id = ' id="'.$data['id'].'"'; |
|
259 | 259 | } else { |
260 | 260 | $id = ''; |
261 | 261 | } |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | $title = isset($data['title']) ? $data['title'] : ''; |
264 | 264 | |
265 | 265 | if (isset($data['url'])) { |
266 | - $title = '<a href="' . $data['url'] . '">' . $title . '</a>'; |
|
266 | + $title = '<a href="'.$data['url'].'">'.$title.'</a>'; |
|
267 | 267 | } |
268 | 268 | ?> |
269 | 269 | <div class="block"<?php echo $id; ?>> |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | if (is_string($message)) { |
390 | 390 | // Sometimes we're just sending a single line to this function |
391 | 391 | // rather like the bigger array... |
392 | - $message = array ( |
|
392 | + $message = array( |
|
393 | 393 | 'text' => $message |
394 | 394 | ); |
395 | 395 | } |
@@ -397,13 +397,13 @@ discard block |
||
397 | 397 | // if the page has started then we're most likely in an old school page |
398 | 398 | // so we should just print out the error, otherwise stick it in the error |
399 | 399 | // global which will then be displayed by the header template |
400 | - if ( $this->page_started() ) { |
|
400 | + if ($this->page_started()) { |
|
401 | 401 | $this->message($message, 'error'); |
402 | 402 | } else { |
403 | - if ( !isset($page_errors) ) { |
|
403 | + if (!isset($page_errors)) { |
|
404 | 404 | $page_errors = array(); |
405 | 405 | } |
406 | - $page_errors[] = $message; |
|
406 | + $page_errors[] = $message; |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | if ($fatal) { |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | } |
421 | 421 | |
422 | 422 | |
423 | - public function message($message, $class='') { |
|
423 | + public function message($message, $class = '') { |
|
424 | 424 | // Generates a very simple but common page content. |
425 | 425 | // Used for when a user logs out, or votes, or any simple thing |
426 | 426 | // where there's a little message and probably a link elsewhere. |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | // $class is a class name that will be applied to the message's HTML elements. |
435 | 435 | |
436 | 436 | if ($class != '') { |
437 | - $class = ' class="' . $class . '"'; |
|
437 | + $class = ' class="'.$class.'"'; |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | $need_to_close_stripe = false; |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | } |
469 | 469 | |
470 | 470 | public function informational($text) { |
471 | - print '<div class="informational left">' . $text . '</div>'; |
|
471 | + print '<div class="informational left">'.$text.'</div>'; |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | public function set_hansard_headings($info) { |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | if ($page_title != '') { |
499 | 499 | $page_title .= ': '; |
500 | 500 | } |
501 | - $page_title .= format_date ($info['date'], SHORTDATEFORMAT); |
|
501 | + $page_title .= format_date($info['date'], SHORTDATEFORMAT); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | if ($page_title != '') { |
@@ -537,15 +537,15 @@ discard block |
||
537 | 537 | $prev = $nextprev['prev']; |
538 | 538 | |
539 | 539 | if (isset($prev['url'])) { |
540 | - $prevlink = '<a href="' . $prev['url'] . '" title="' . $prev['title'] . '" class="linkbutton">« ' . $prev['body'] . '</a>'; |
|
540 | + $prevlink = '<a href="'.$prev['url'].'" title="'.$prev['title'].'" class="linkbutton">« '.$prev['body'].'</a>'; |
|
541 | 541 | |
542 | 542 | } else { |
543 | - $prevlink = '« ' . $prev['body']; |
|
543 | + $prevlink = '« '.$prev['body']; |
|
544 | 544 | } |
545 | 545 | } |
546 | 546 | |
547 | 547 | if ($prevlink != '') { |
548 | - $prevlink = '<span class="prev">' . $prevlink . '</span>'; |
|
548 | + $prevlink = '<span class="prev">'.$prevlink.'</span>'; |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | |
@@ -553,10 +553,10 @@ discard block |
||
553 | 553 | |
554 | 554 | if (isset($nextprev['up'])) { |
555 | 555 | |
556 | - $uplink = '<span class="up"><a href="' . $nextprev['up']['url'] . '" title="' . $nextprev['up']['title'] . '">' . $nextprev['up']['body'] . '</a>'; |
|
556 | + $uplink = '<span class="up"><a href="'.$nextprev['up']['url'].'" title="'.$nextprev['up']['title'].'">'.$nextprev['up']['body'].'</a>'; |
|
557 | 557 | if (get_http_var('s')) { |
558 | 558 | $URL = new \MySociety\TheyWorkForYou\Url($this_page); |
559 | - $uplink .= '<br><a href="' . $URL->generate() . '">Remove highlighting</a>'; |
|
559 | + $uplink .= '<br><a href="'.$URL->generate().'">Remove highlighting</a>'; |
|
560 | 560 | } |
561 | 561 | $uplink .= '</span>'; |
562 | 562 | } |
@@ -568,14 +568,14 @@ discard block |
||
568 | 568 | $next = $nextprev['next']; |
569 | 569 | |
570 | 570 | if (isset($next['url'])) { |
571 | - $nextlink = '<a href="' . $next['url'] . '" title="' . $next['title'] . '" class="linkbutton">' . $next['body'] . ' »</a>'; |
|
571 | + $nextlink = '<a href="'.$next['url'].'" title="'.$next['title'].'" class="linkbutton">'.$next['body'].' »</a>'; |
|
572 | 572 | } else { |
573 | - $nextlink = $next['body'] . ' »'; |
|
573 | + $nextlink = $next['body'].' »'; |
|
574 | 574 | } |
575 | 575 | } |
576 | 576 | |
577 | 577 | if ($nextlink != '') { |
578 | - $nextlink = '<span class="next">' . $nextlink . '</span>'; |
|
578 | + $nextlink = '<span class="next">'.$nextlink.'</span>'; |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | } |
586 | 586 | |
587 | 587 | |
588 | - public function search_form($value='') { |
|
588 | + public function search_form($value = '') { |
|
589 | 589 | global $SEARCHENGINE; |
590 | 590 | // Search box on the search page. |
591 | 591 | // If $value is set then it will be displayed in the form. |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | } |
616 | 616 | |
617 | 617 | echo '<div class="mainsearchbox">'; |
618 | - if ($wtt<2) { |
|
618 | + if ($wtt < 2) { |
|
619 | 619 | echo '<form action="', $URL->generate(), '" method="get">'; |
620 | 620 | if (get_http_var('o')) { |
621 | 621 | echo '<input type="hidden" name="o" value="', _htmlentities(get_http_var('o')), '">'; |
@@ -624,10 +624,10 @@ discard block |
||
624 | 624 | echo '<input type="hidden" name="house" value="', _htmlentities(get_http_var('house')), '">'; |
625 | 625 | } |
626 | 626 | echo '<input type="text" name="q" value="', _htmlentities($value), '" size="50"> '; |
627 | - echo '<input type="submit" value=" ', ($wtt?'Modify search':'Search'), ' ">'; |
|
627 | + echo '<input type="submit" value=" ', ($wtt ? 'Modify search' : 'Search'), ' ">'; |
|
628 | 628 | $URL = new \MySociety\TheyWorkForYou\Url('search'); |
629 | 629 | $URL->insert(array('adv' => 1)); |
630 | - echo ' <a href="' . $URL->generate() . '">More options</a>'; |
|
630 | + echo ' <a href="'.$URL->generate().'">More options</a>'; |
|
631 | 631 | echo '<br>'; |
632 | 632 | if ($wtt) print '<input type="hidden" name="wtt" value="1">'; |
633 | 633 | } else { ?> |
@@ -646,24 +646,24 @@ discard block |
||
646 | 646 | $ordering = 'd'; |
647 | 647 | } |
648 | 648 | |
649 | - if ($ordering=='r') { |
|
649 | + if ($ordering == 'r') { |
|
650 | 650 | print '<strong>Sorted by relevance</strong>'; |
651 | 651 | } else { |
652 | 652 | printf("<a href='%s'>Sort by relevance</a>", $orderUrl->generate('html', array('o'=>'r'))); |
653 | 653 | } |
654 | 654 | |
655 | 655 | print " | "; |
656 | - if ($ordering=='d') { |
|
657 | - print '<strong>Sorted by date: newest</strong> / <a href="' . $orderUrl->generate('html', array('o'=>'o')) . '">oldest</a>'; |
|
658 | - } elseif ($ordering=='o') { |
|
659 | - print '<strong>Sorted by date:</strong> <a href="' . $orderUrl->generate('html', array('o'=>'d')) . '">newest</a> / <strong>oldest</strong>'; |
|
656 | + if ($ordering == 'd') { |
|
657 | + print '<strong>Sorted by date: newest</strong> / <a href="'.$orderUrl->generate('html', array('o'=>'o')).'">oldest</a>'; |
|
658 | + } elseif ($ordering == 'o') { |
|
659 | + print '<strong>Sorted by date:</strong> <a href="'.$orderUrl->generate('html', array('o'=>'d')).'">newest</a> / <strong>oldest</strong>'; |
|
660 | 660 | } else { |
661 | 661 | printf("Sort by date: <a href='%s'>newest</a> / <a href='%s'>oldest</a>", |
662 | 662 | $orderUrl->generate('html', array('o'=>'d')), $orderUrl->generate('html', array('o'=>'o'))); |
663 | 663 | } |
664 | 664 | |
665 | 665 | print " | "; |
666 | - if ($ordering=='p') { |
|
666 | + if ($ordering == 'p') { |
|
667 | 667 | print '<strong>Use by person</strong>'; |
668 | 668 | } else { |
669 | 669 | printf('<a href="%s">Show use by person</a>', $orderUrl->generate('html', array('o'=>'p'))); |
@@ -684,10 +684,10 @@ discard block |
||
684 | 684 | } |
685 | 685 | |
686 | 686 | public function advanced_search_form() { |
687 | - include_once INCLUDESPATH . 'easyparliament/templates/html/search_advanced.php'; |
|
687 | + include_once INCLUDESPATH.'easyparliament/templates/html/search_advanced.php'; |
|
688 | 688 | } |
689 | 689 | |
690 | - public function login_form ($errors = array()) { |
|
690 | + public function login_form($errors = array()) { |
|
691 | 691 | // Used for /user/login/ and /user/prompt/ |
692 | 692 | // $errors is a hash of potential errors from a previous log in attempt. |
693 | 693 | ?> |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | public function glossary_atoz(&$GLOSSARY) { |
792 | 792 | // Print out a nice list of lettered links to glossary pages |
793 | 793 | |
794 | - $letters = array (); |
|
794 | + $letters = array(); |
|
795 | 795 | |
796 | 796 | foreach ($GLOSSARY->alphabet as $letter => $eps) { |
797 | 797 | // if we're writing out the current letter (list or item) |
@@ -802,11 +802,11 @@ discard block |
||
802 | 802 | $URL->insert(array('az' => $letter)); |
803 | 803 | $letter_link = $URL->generate('url'); |
804 | 804 | |
805 | - $letters[] = "<li class=\"on\"><a href=\"" . $letter_link . "\">" . $letter . "</a></li>"; |
|
805 | + $letters[] = "<li class=\"on\"><a href=\"".$letter_link."\">".$letter."</a></li>"; |
|
806 | 806 | } |
807 | 807 | // otherwise in list view show no link |
808 | 808 | else { |
809 | - $letters[] = "<li class=\"on\">" . $letter . "</li>"; |
|
809 | + $letters[] = "<li class=\"on\">".$letter."</li>"; |
|
810 | 810 | } |
811 | 811 | } |
812 | 812 | elseif (!empty($GLOSSARY->alphabet[$letter])) { |
@@ -814,24 +814,24 @@ discard block |
||
814 | 814 | $URL->insert(array('az' => $letter)); |
815 | 815 | $letter_link = $URL->generate('url'); |
816 | 816 | |
817 | - $letters[] = "<li><a href=\"" . $letter_link . "\">" . $letter . "</a></li>"; |
|
817 | + $letters[] = "<li><a href=\"".$letter_link."\">".$letter."</a></li>"; |
|
818 | 818 | } |
819 | 819 | else { |
820 | - $letters[] = '<li>' . $letter . '</li>'; |
|
820 | + $letters[] = '<li>'.$letter.'</li>'; |
|
821 | 821 | } |
822 | 822 | } |
823 | 823 | ?> |
824 | 824 | <div class="letters"> |
825 | 825 | <ul> |
826 | 826 | <?php |
827 | - for ($n=0; $n<13; $n++) { |
|
827 | + for ($n = 0; $n < 13; $n++) { |
|
828 | 828 | print $letters[$n]; |
829 | 829 | } |
830 | 830 | ?> |
831 | 831 | </ul> |
832 | 832 | <ul> |
833 | 833 | <?php |
834 | - for ($n=13; $n<26; $n++) { |
|
834 | + for ($n = 13; $n < 26; $n++) { |
|
835 | 835 | print $letters[$n]; |
836 | 836 | } |
837 | 837 | ?> |
@@ -851,7 +851,7 @@ discard block |
||
851 | 851 | // add some extra controls for the administrators |
852 | 852 | if ($this_page == "admin_glossary") { |
853 | 853 | print "<a id=\"gl".$term['glossary_id']."\"></a>"; |
854 | - print "<h3>" . $term['title'] . "</h3>"; |
|
854 | + print "<h3>".$term['title']."</h3>"; |
|
855 | 855 | $URL = new \MySociety\TheyWorkForYou\Url('admin_glossary'); |
856 | 856 | $URL->insert(array("delete_confirm" => $term['glossary_id'])); |
857 | 857 | $delete_url = $URL->generate(); |
@@ -866,13 +866,13 @@ discard block |
||
866 | 866 | $URL->insert(array('u' => $term['user_id'])); |
867 | 867 | $user_link = $URL->generate('url'); |
868 | 868 | |
869 | - $user_details = "\t\t\t\t<p><small>contributed by user <a href=\"" . $user_link . "\">" . $term['firstname'] . " " . $term['lastname'] . "</a></small>" . $admin_links . "</p>\n"; |
|
869 | + $user_details = "\t\t\t\t<p><small>contributed by user <a href=\"".$user_link."\">".$term['firstname']." ".$term['lastname']."</a></small>".$admin_links."</p>\n"; |
|
870 | 870 | } |
871 | 871 | else { |
872 | 872 | $user_details = ""; |
873 | 873 | } |
874 | 874 | |
875 | - print "\t\t\t\t<p class=\"glossary-body\">" . $term['body'] . "</p>\n" . $user_details; |
|
875 | + print "\t\t\t\t<p class=\"glossary-body\">".$term['body']."</p>\n".$user_details; |
|
876 | 876 | |
877 | 877 | if ($this_page == "glossary_item") { |
878 | 878 | // Add a direct search link for current glossary item |
@@ -880,7 +880,7 @@ discard block |
||
880 | 880 | // remember to quote the term for phrase matching in search |
881 | 881 | $URL->insert(array('s' => '"'.$term['title'].'"')); |
882 | 882 | $search_url = $URL->generate(); |
883 | - printf ("\t\t\t\t<p>Search hansard for \"<a href=\"%s\" title=\"View search results for this glossary item\">%s</a>\"</p>", $search_url, $term['title']); |
|
883 | + printf("\t\t\t\t<p>Search hansard for \"<a href=\"%s\" title=\"View search results for this glossary item\">%s</a>\"</p>", $search_url, $term['title']); |
|
884 | 884 | } |
885 | 885 | } |
886 | 886 | |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | $URL = new \MySociety\TheyWorkForYou\Url('glossary'); |
913 | 913 | $URL->remove(array("g")); |
914 | 914 | $glossary_link = $URL->generate('url'); |
915 | - print "<small><a href=\"" . $glossary_link . "\">Browse the glossary</a></small>"; |
|
915 | + print "<small><a href=\"".$glossary_link."\">Browse the glossary</a></small>"; |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | public function glossary_links() { |
@@ -955,13 +955,13 @@ discard block |
||
955 | 955 | |
956 | 956 | // Generate all the page links. |
957 | 957 | $URL = new \MySociety\TheyWorkForYou\Url($this_page); |
958 | - $URL->insert( array('wtt' => get_http_var('wtt')) ); |
|
958 | + $URL->insert(array('wtt' => get_http_var('wtt'))); |
|
959 | 959 | if (isset($pagedata['s'])) { |
960 | 960 | # XXX: Should be taken out in *one* place, not here + search_form etc. |
961 | 961 | $value = $pagedata['s']; |
962 | 962 | if (preg_match_all('#speaker:(\d+)#', $value, $m) == 1) { |
963 | 963 | $person_id = $m[1][0]; |
964 | - $value = str_replace('speaker:' . $person_id, '', $value); |
|
964 | + $value = str_replace('speaker:'.$person_id, '', $value); |
|
965 | 965 | $URL->insert(array('pid' => $person_id)); |
966 | 966 | } |
967 | 967 | $URL->insert(array('s' => $value)); |
@@ -980,7 +980,7 @@ discard block |
||
980 | 980 | } |
981 | 981 | |
982 | 982 | if ($n != $page) { |
983 | - $pagelinks[] = '<a href="' . $URL->generate() . '">' . $n . '</a>'; |
|
983 | + $pagelinks[] = '<a href="'.$URL->generate().'">'.$n.'</a>'; |
|
984 | 984 | } else { |
985 | 985 | $pagelinks[] = "<strong>$n</strong>"; |
986 | 986 | } |
@@ -1001,7 +1001,7 @@ discard block |
||
1001 | 1001 | <?php |
1002 | 1002 | } |
1003 | 1003 | |
1004 | - echo "\t\t\t\t" . implode(' ', $pagelinks); |
|
1004 | + echo "\t\t\t\t".implode(' ', $pagelinks); |
|
1005 | 1005 | |
1006 | 1006 | if ($page != $numpages) { |
1007 | 1007 | $nextpage = $page + 1; |
@@ -1027,7 +1027,7 @@ discard block |
||
1027 | 1027 | if ($data['user_id'] > 0) { |
1028 | 1028 | $USERURL = new \MySociety\TheyWorkForYou\Url('userview'); |
1029 | 1029 | $USERURL->insert(array('id'=>$data['user_id'])); |
1030 | - $username = '<a href="' . $USERURL->generate() . '">' . _htmlentities($data['user_name']) . '</a>'; |
|
1030 | + $username = '<a href="'.$USERURL->generate().'">'._htmlentities($data['user_name']).'</a>'; |
|
1031 | 1031 | } else { |
1032 | 1032 | $username = _htmlentities($data['user_name']); |
1033 | 1033 | } |
@@ -1086,15 +1086,15 @@ discard block |
||
1086 | 1086 | 'rid' => $report['report_id'], |
1087 | 1087 | 'cid' => $report['comment_id'], |
1088 | 1088 | )); |
1089 | - $editlink = '<a href="' . $EDITURL->generate() . '">View</a>'; |
|
1089 | + $editlink = '<a href="'.$EDITURL->generate().'">View</a>'; |
|
1090 | 1090 | } else { |
1091 | 1091 | $editlink = 'Locked'; |
1092 | 1092 | } |
1093 | 1093 | |
1094 | 1094 | $body = trim_characters($report['body'], 0, 40); |
1095 | 1095 | |
1096 | - $tabledata['rows'][] = array ( |
|
1097 | - _htmlentities($report['firstname'] . ' ' . $report['lastname']), |
|
1096 | + $tabledata['rows'][] = array( |
|
1097 | + _htmlentities($report['firstname'].' '.$report['lastname']), |
|
1098 | 1098 | _htmlentities($body), |
1099 | 1099 | $report['reported'], |
1100 | 1100 | $editlink |
@@ -1124,13 +1124,13 @@ discard block |
||
1124 | 1124 | // $page is the name of the page the dates should link to. |
1125 | 1125 | |
1126 | 1126 | // Create array containing abbreviations of days of week. |
1127 | - $daysOfWeek = array('Mon','Tue','Wed','Thu','Fri','Sat','Sun'); |
|
1127 | + $daysOfWeek = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'); |
|
1128 | 1128 | |
1129 | 1129 | // What is the first day of the month in question? |
1130 | - $firstDayOfMonth = mktime(0,0,0,$month,1,$year); |
|
1130 | + $firstDayOfMonth = mktime(0, 0, 0, $month, 1, $year); |
|
1131 | 1131 | |
1132 | 1132 | // How many days does this month contain? |
1133 | - $numberDays = date('t',$firstDayOfMonth); |
|
1133 | + $numberDays = date('t', $firstDayOfMonth); |
|
1134 | 1134 | |
1135 | 1135 | // Retrieve some information about the first day of the |
1136 | 1136 | // month in question. |
@@ -1211,13 +1211,13 @@ discard block |
||
1211 | 1211 | |
1212 | 1212 | // Is the $currentDay a member of $dateArray? If so, |
1213 | 1213 | // the day should be linked. |
1214 | - if (in_array($currentDay,$dateArray)) { |
|
1214 | + if (in_array($currentDay, $dateArray)) { |
|
1215 | 1215 | |
1216 | 1216 | $date = sprintf("%04d-%02d-%02d", $year, $month, $currentDay); |
1217 | 1217 | |
1218 | 1218 | $DAYURL->insert(array('d'=>$date)); |
1219 | 1219 | |
1220 | - $calendar .= "<a href=\"" . $DAYURL->generate() . "\">$currentDay</a></td>"; |
|
1220 | + $calendar .= "<a href=\"".$DAYURL->generate()."\">$currentDay</a></td>"; |
|
1221 | 1221 | |
1222 | 1222 | // $currentDay is not a member of $dateArray. |
1223 | 1223 | |
@@ -1312,8 +1312,8 @@ discard block |
||
1312 | 1312 | // Returns HTML suitable for putting in the sidebar on Admin pages. |
1313 | 1313 | global $this_page, $DATA; |
1314 | 1314 | |
1315 | - $pages = array ('admin_home', |
|
1316 | - 'admin_comments','admin_trackbacks', 'admin_searchlogs', 'admin_popularsearches', 'admin_failedsearches', |
|
1315 | + $pages = array('admin_home', |
|
1316 | + 'admin_comments', 'admin_trackbacks', 'admin_searchlogs', 'admin_popularsearches', 'admin_failedsearches', |
|
1317 | 1317 | 'alert_stats', 'admin_statistics', 'admin_reportstats', |
1318 | 1318 | 'admin_commentreports', 'admin_glossary', 'admin_glossary_pending', 'admin_badusers', |
1319 | 1319 | 'admin_photos', 'admin_mpurls', 'admin_policies', 'admin_banner', 'admin_featured', 'admin_topics' |
@@ -1326,9 +1326,9 @@ discard block |
||
1326 | 1326 | |
1327 | 1327 | if ($page != $this_page) { |
1328 | 1328 | $URL = new \MySociety\TheyWorkForYou\Url($page); |
1329 | - $title = '<a href="' . $URL->generate() . '">' . $title . '</a>'; |
|
1329 | + $title = '<a href="'.$URL->generate().'">'.$title.'</a>'; |
|
1330 | 1330 | } else { |
1331 | - $title = '<strong>' . $title . '</strong>'; |
|
1331 | + $title = '<strong>'.$title.'</strong>'; |
|
1332 | 1332 | } |
1333 | 1333 | |
1334 | 1334 | $links[] = $title; |
@@ -1336,7 +1336,7 @@ discard block |
||
1336 | 1336 | |
1337 | 1337 | $html = "<ul>\n"; |
1338 | 1338 | |
1339 | - $html .= "<li>" . implode("</li>\n<li>", $links) . "</li>\n"; |
|
1339 | + $html .= "<li>".implode("</li>\n<li>", $links)."</li>\n"; |
|
1340 | 1340 | |
1341 | 1341 | $html .= "</ul>\n"; |
1342 | 1342 |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | public $body = ''; |
32 | 32 | public $posted = ''; |
33 | 33 | public $visible = false; |
34 | - public $modflagged = NULL; // Is a datetime when set. |
|
35 | - public $firstname = ''; // Of the person who posted it. |
|
34 | + public $modflagged = NULL; // Is a datetime when set. |
|
35 | + public $firstname = ''; // Of the person who posted it. |
|
36 | 36 | public $lastname = ''; |
37 | 37 | public $url = ''; |
38 | 38 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | public $exists = false; |
42 | 42 | |
43 | 43 | |
44 | - public function __construct($comment_id='') { |
|
44 | + public function __construct($comment_id = '') { |
|
45 | 45 | |
46 | 46 | $this->db = new ParlDB; |
47 | 47 | |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | if ($q->rows() > 0) { |
70 | 70 | |
71 | 71 | $this->comment_id = $comment_id; |
72 | - $this->user_id = $q->field(0, 'user_id'); |
|
72 | + $this->user_id = $q->field(0, 'user_id'); |
|
73 | 73 | $this->epobject_id = $q->field(0, 'epobject_id'); |
74 | - $this->body = $q->field(0, 'body'); |
|
75 | - $this->posted = $q->field(0, 'posted'); |
|
76 | - $this->visible = $q->field(0, 'visible'); |
|
77 | - $this->modflagged = $q->field(0, 'modflagged'); |
|
74 | + $this->body = $q->field(0, 'body'); |
|
75 | + $this->posted = $q->field(0, 'posted'); |
|
76 | + $this->visible = $q->field(0, 'visible'); |
|
77 | + $this->modflagged = $q->field(0, 'modflagged'); |
|
78 | 78 | |
79 | 79 | // Sets the URL and username for this comment. Duh. |
80 | 80 | $this->_set_url(); |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | public function comments_enabled() { return $this->comments_enabled; } |
105 | 105 | |
106 | 106 | |
107 | - public function display($format='html', $template='comments') { |
|
107 | + public function display($format = 'html', $template = 'comments') { |
|
108 | 108 | |
109 | - $data['comments'][0] = array ( |
|
109 | + $data['comments'][0] = array( |
|
110 | 110 | 'comment_id' => $this->comment_id, |
111 | 111 | 'user_id' => $this->user_id, |
112 | 112 | 'epobject_id' => $this->epobject_id, |
@@ -142,19 +142,19 @@ discard block |
||
142 | 142 | $flag = 'NULL'; |
143 | 143 | |
144 | 144 | } else { |
145 | - $PAGE->error_message ("Why are you trying to switch this comment's modflag to '" . _htmlentities($switch) . "'!"); |
|
145 | + $PAGE->error_message("Why are you trying to switch this comment's modflag to '"._htmlentities($switch)."'!"); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $q = $this->db->query("UPDATE comments |
149 | 149 | SET modflagged = $flag |
150 | - WHERE comment_id = '" . $this->comment_id . "' |
|
150 | + WHERE comment_id = '".$this->comment_id."' |
|
151 | 151 | "); |
152 | 152 | |
153 | 153 | if ($q->success()) { |
154 | 154 | $this->modflagged = $date; |
155 | 155 | return true; |
156 | 156 | } else { |
157 | - $message = array ( |
|
157 | + $message = array( |
|
158 | 158 | 'title' => 'Sorry', |
159 | 159 | 'text' => "We couldn't update the annotation's modflag." |
160 | 160 | ); |
@@ -171,12 +171,12 @@ discard block |
||
171 | 171 | global $THEUSER, $PAGE; |
172 | 172 | |
173 | 173 | if ($THEUSER->is_able_to('deletecomment')) { |
174 | - $q = $this->db->query("UPDATE comments SET visible = '0' WHERE comment_id = '" . $this->comment_id . "'"); |
|
174 | + $q = $this->db->query("UPDATE comments SET visible = '0' WHERE comment_id = '".$this->comment_id."'"); |
|
175 | 175 | |
176 | 176 | if ($q->success()) { |
177 | 177 | return true; |
178 | 178 | } else { |
179 | - $message = array ( |
|
179 | + $message = array( |
|
180 | 180 | 'title' => 'Sorry', |
181 | 181 | 'text' => "We were unable to delete the annotation." |
182 | 182 | ); |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | } |
186 | 186 | |
187 | 187 | } else { |
188 | - $message = array ( |
|
188 | + $message = array( |
|
189 | 189 | 'title' => 'Sorry', |
190 | 190 | 'text' => "You are not authorised to delete annotations." |
191 | 191 | ); |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | |
221 | 221 | $URL = new \MySociety\TheyWorkForYou\Url($page); |
222 | 222 | $URL->insert(array('id'=>$gid)); |
223 | - $this->url = $URL->generate() . '#c' . $this->comment_id; |
|
223 | + $this->url = $URL->generate().'#c'.$this->comment_id; |
|
224 | 224 | } |
225 | 225 | } |
226 | 226 | } |
@@ -56,22 +56,22 @@ discard block |
||
56 | 56 | |
57 | 57 | class USER { |
58 | 58 | |
59 | - public $user_id = "0"; // So we have an ID for non-logged in users reporting comments etc. |
|
60 | - public $firstname = "Guest"; // So we have something to print for non-logged in users. |
|
59 | + public $user_id = "0"; // So we have an ID for non-logged in users reporting comments etc. |
|
60 | + public $firstname = "Guest"; // So we have something to print for non-logged in users. |
|
61 | 61 | public $lastname = ""; |
62 | - public $password = ""; // This will be a hashed version of a plaintext pw. |
|
62 | + public $password = ""; // This will be a hashed version of a plaintext pw. |
|
63 | 63 | public $email = ""; |
64 | - public $emailpublic = ""; // boolean - can other users see this user's email? |
|
64 | + public $emailpublic = ""; // boolean - can other users see this user's email? |
|
65 | 65 | public $postcode = ""; |
66 | 66 | public $url = ""; |
67 | - public $lastvisit = ""; // Last time the logged-in user loaded a page (GMT). |
|
67 | + public $lastvisit = ""; // Last time the logged-in user loaded a page (GMT). |
|
68 | 68 | public $registrationtime = ""; // When they registered (GMT). |
69 | - public $registrationip = ""; // Where they registered from. |
|
70 | - public $optin = ""; // boolean - Do they want emails from us? |
|
71 | - public $deleted = ""; // User can't log in or have their info displayed. |
|
72 | - public $confirmed = ''; // boolean - Has the user confirmed via email? |
|
73 | - public $facebook_id = ''; // Facebook ID for users who login with FB |
|
74 | - public $facebook_token = ''; // Facebook token for users who login with FB |
|
69 | + public $registrationip = ""; // Where they registered from. |
|
70 | + public $optin = ""; // boolean - Do they want emails from us? |
|
71 | + public $deleted = ""; // User can't log in or have their info displayed. |
|
72 | + public $confirmed = ''; // boolean - Has the user confirmed via email? |
|
73 | + public $facebook_id = ''; // Facebook ID for users who login with FB |
|
74 | + public $facebook_token = ''; // Facebook token for users who login with FB |
|
75 | 75 | // Don't use the status to check access privileges - use the is_able_to() function. |
76 | 76 | public $status = "Viewer"; |
77 | 77 | |
@@ -118,23 +118,23 @@ discard block |
||
118 | 118 | // We've got a user, so set them up. |
119 | 119 | |
120 | 120 | $this->user_id = $user_id; |
121 | - $this->firstname = $q->field(0,"firstname"); |
|
122 | - $this->lastname = $q->field(0,"lastname"); |
|
123 | - $this->password = $q->field(0,"password"); |
|
124 | - $this->email = $q->field(0,"email"); |
|
125 | - $this->emailpublic = $q->field(0,"emailpublic") == 1 ? true : false; |
|
126 | - $this->postcode = $q->field(0,"postcode"); |
|
127 | - $this->facebook_id = $q->field(0,"facebook_id"); |
|
128 | - $this->facebook_token = $q->field(0,"facebook_token"); |
|
129 | - $this->url = $q->field(0,"url"); |
|
130 | - $this->lastvisit = $q->field(0,"lastvisit"); |
|
121 | + $this->firstname = $q->field(0, "firstname"); |
|
122 | + $this->lastname = $q->field(0, "lastname"); |
|
123 | + $this->password = $q->field(0, "password"); |
|
124 | + $this->email = $q->field(0, "email"); |
|
125 | + $this->emailpublic = $q->field(0, "emailpublic") == 1 ? true : false; |
|
126 | + $this->postcode = $q->field(0, "postcode"); |
|
127 | + $this->facebook_id = $q->field(0, "facebook_id"); |
|
128 | + $this->facebook_token = $q->field(0, "facebook_token"); |
|
129 | + $this->url = $q->field(0, "url"); |
|
130 | + $this->lastvisit = $q->field(0, "lastvisit"); |
|
131 | 131 | $this->registrationtoken = $q->field(0, 'registrationtoken'); |
132 | - $this->registrationtime = $q->field(0,"registrationtime"); |
|
133 | - $this->registrationip = $q->field(0,"registrationip"); |
|
134 | - $this->optin = $q->field(0,"optin") == 1 ? true : false; |
|
135 | - $this->status = $q->field(0,"status"); |
|
136 | - $this->deleted = $q->field(0,"deleted") == 1 ? true : false; |
|
137 | - $this->confirmed = $q->field(0,"confirmed") == 1 ? true : false; |
|
132 | + $this->registrationtime = $q->field(0, "registrationtime"); |
|
133 | + $this->registrationip = $q->field(0, "registrationip"); |
|
134 | + $this->optin = $q->field(0, "optin") == 1 ? true : false; |
|
135 | + $this->status = $q->field(0, "status"); |
|
136 | + $this->deleted = $q->field(0, "deleted") == 1 ? true : false; |
|
137 | + $this->confirmed = $q->field(0, "confirmed") == 1 ? true : false; |
|
138 | 138 | |
139 | 139 | return true; |
140 | 140 | |
@@ -143,16 +143,16 @@ discard block |
||
143 | 143 | // we're going to show an error too, just in case. |
144 | 144 | // *Should* never happen... |
145 | 145 | return false; |
146 | - twfy_debug("USER", "There is more than one user with an id of '" . _htmlentities($user_id) . "'"); |
|
146 | + twfy_debug("USER", "There is more than one user with an id of '"._htmlentities($user_id)."'"); |
|
147 | 147 | |
148 | 148 | } else { |
149 | 149 | return false; |
150 | - twfy_debug("USER", "There is no user with an id of '" . _htmlentities($user_id) . "'"); |
|
150 | + twfy_debug("USER", "There is no user with an id of '"._htmlentities($user_id)."'"); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | } |
154 | 154 | |
155 | - public function add($details, $confirmation_required=true) { |
|
155 | + public function add($details, $confirmation_required = true) { |
|
156 | 156 | // Adds a new user's info into the db. |
157 | 157 | // Then optionally (and usually) calls another function to |
158 | 158 | // send them a confirmation email. |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | // This will be sent to them via email, so we can confirm they exist. |
240 | 240 | // The token will be the first 16 characters of a hash. |
241 | 241 | |
242 | - $token = substr( password_hash($details["email"] . microtime(), PASSWORD_BCRYPT), 29, 16 ); |
|
242 | + $token = substr(password_hash($details["email"].microtime(), PASSWORD_BCRYPT), 29, 16); |
|
243 | 243 | |
244 | 244 | // Full stops don't work well at the end of URLs in emails, |
245 | 245 | // so replace them. We won't be doing anything clever with the hash |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | $r = $this->db->query("UPDATE users |
252 | 252 | SET registrationtoken = :registrationtoken |
253 | 253 | WHERE user_id = :user_id |
254 | - ", array ( |
|
254 | + ", array( |
|
255 | 255 | ':registrationtoken' => $this->registrationtoken, |
256 | 256 | ':user_id' => $this->user_id |
257 | 257 | )); |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | } |
299 | 299 | |
300 | 300 | public function add_facebook_id($facebook_id) { |
301 | - $q = $this->db->query ("UPDATE users SET facebook_id = :facebook_id WHERE email = :email", |
|
301 | + $q = $this->db->query("UPDATE users SET facebook_id = :facebook_id WHERE email = :email", |
|
302 | 302 | array( |
303 | 303 | ':facebook_id' => $facebook_id, |
304 | 304 | ':email' => $this->email |
@@ -319,24 +319,24 @@ discard block |
||
319 | 319 | !isset($details['email']) || |
320 | 320 | $details['email'] == '' || |
321 | 321 | !isset($details['token']) || |
322 | - $details['token'] == '' ) { |
|
322 | + $details['token'] == '') { |
|
323 | 323 | return false; |
324 | 324 | } |
325 | 325 | |
326 | 326 | // We prefix the registration token with the user's id and '-'. |
327 | 327 | // Not for any particularly good reason, but we do. |
328 | 328 | |
329 | - $urltoken = $this->user_id . '-' . $details['token']; |
|
329 | + $urltoken = $this->user_id.'-'.$details['token']; |
|
330 | 330 | |
331 | - $confirmurl = 'https://' . DOMAIN . '/E/' . $urltoken; |
|
331 | + $confirmurl = 'https://'.DOMAIN.'/E/'.$urltoken; |
|
332 | 332 | |
333 | 333 | // Arrays we need to send a templated email. |
334 | - $data = array ( |
|
334 | + $data = array( |
|
335 | 335 | 'to' => $details['email'], |
336 | 336 | 'template' => 'email_confirmation' |
337 | 337 | ); |
338 | 338 | |
339 | - $merge = array ( |
|
339 | + $merge = array( |
|
340 | 340 | 'FIRSTNAME' => $details['firstname'], |
341 | 341 | 'LASTNAME' => $details['lastname'], |
342 | 342 | 'CONFIRMURL' => $confirmurl |
@@ -368,17 +368,17 @@ discard block |
||
368 | 368 | // We prefix the registration token with the user's id and '-'. |
369 | 369 | // Not for any particularly good reason, but we do. |
370 | 370 | |
371 | - $urltoken = $this->user_id . '-' . $this->registrationtoken; |
|
371 | + $urltoken = $this->user_id.'-'.$this->registrationtoken; |
|
372 | 372 | |
373 | - $confirmurl = 'https://' . DOMAIN . '/U/' . $urltoken; |
|
373 | + $confirmurl = 'https://'.DOMAIN.'/U/'.$urltoken; |
|
374 | 374 | |
375 | 375 | // Arrays we need to send a templated email. |
376 | - $data = array ( |
|
376 | + $data = array( |
|
377 | 377 | 'to' => $details['email'], |
378 | 378 | 'template' => 'join_confirmation' |
379 | 379 | ); |
380 | 380 | |
381 | - $merge = array ( |
|
381 | + $merge = array( |
|
382 | 382 | 'FIRSTNAME' => $details['firstname'], |
383 | 383 | 'LASTNAME' => $details['lastname'], |
384 | 384 | 'CONFIRMURL' => $confirmurl |
@@ -440,23 +440,23 @@ discard block |
||
440 | 440 | $this->email = $email; |
441 | 441 | for (;;) { |
442 | 442 | |
443 | - $pwd=null; |
|
444 | - $o=null; |
|
443 | + $pwd = null; |
|
444 | + $o = null; |
|
445 | 445 | |
446 | 446 | // Generates the password .... |
447 | - for ($x=0; $x < 6;) { |
|
448 | - $y = rand(1,1000); |
|
449 | - if($y>350 && $y<601) $d=chr(rand(48,57)); |
|
450 | - if($y<351) $d=chr(rand(65,90)); |
|
451 | - if($y>600) $d=chr(rand(97,122)); |
|
452 | - if ($d!=$o && !preg_match('#[O01lI]#', $d)) { |
|
453 | - $o=$d; $pwd.=$d; $x++; |
|
447 | + for ($x = 0; $x < 6;) { |
|
448 | + $y = rand(1, 1000); |
|
449 | + if ($y > 350 && $y < 601) $d = chr(rand(48, 57)); |
|
450 | + if ($y < 351) $d = chr(rand(65, 90)); |
|
451 | + if ($y > 600) $d = chr(rand(97, 122)); |
|
452 | + if ($d != $o && !preg_match('#[O01lI]#', $d)) { |
|
453 | + $o = $d; $pwd .= $d; $x++; |
|
454 | 454 | } |
455 | 455 | } |
456 | 456 | |
457 | 457 | // If the PW fits your purpose (e.g. this regexpression) return it, else make a new one |
458 | 458 | // (You can change this regular-expression how you want ....) |
459 | - if (preg_match("/^[a-zA-Z]{1}([a-zA-Z]+[0-9][a-zA-Z]+)+/",$pwd)) { |
|
459 | + if (preg_match("/^[a-zA-Z]{1}([a-zA-Z]+[0-9][a-zA-Z]+)+/", $pwd)) { |
|
460 | 460 | break; |
461 | 461 | } |
462 | 462 | |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | |
475 | 475 | $passwordforDB = password_hash($pwd, PASSWORD_BCRYPT); |
476 | 476 | |
477 | - $q = $this->db->query ("UPDATE users SET password = :password WHERE email = :email", |
|
477 | + $q = $this->db->query("UPDATE users SET password = :password WHERE email = :email", |
|
478 | 478 | array( |
479 | 479 | ':password' => $passwordforDB, |
480 | 480 | ':email' => $email |
@@ -502,16 +502,16 @@ discard block |
||
502 | 502 | return false; |
503 | 503 | } |
504 | 504 | |
505 | - $data = array ( |
|
505 | + $data = array( |
|
506 | 506 | 'to' => $this->email(), |
507 | 507 | 'template' => 'new_password' |
508 | 508 | ); |
509 | 509 | |
510 | 510 | $URL = new \MySociety\TheyWorkForYou\Url("userlogin"); |
511 | 511 | |
512 | - $merge = array ( |
|
512 | + $merge = array( |
|
513 | 513 | 'EMAIL' => $this->email(), |
514 | - 'LOGINURL' => "https://" . DOMAIN . $URL->generate(), |
|
514 | + 'LOGINURL' => "https://".DOMAIN.$URL->generate(), |
|
515 | 515 | 'PASSWORD' => $this->password() |
516 | 516 | ); |
517 | 517 | |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | public function facebook_id_exists($id, $return_id = false) { |
569 | 569 | // Returns true if there's a user with this facebook id. |
570 | 570 | |
571 | - if ($id!= "") { |
|
571 | + if ($id != "") { |
|
572 | 572 | $q = $this->db->query("SELECT user_id FROM users WHERE facebook_id = :id", array(':id' => $id)); |
573 | 573 | if ($q->rows() > 0) { |
574 | 574 | if ($return_id) { |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | /* Everyone */ return true; |
648 | 648 | |
649 | 649 | default: |
650 | - $PAGE->error_message ("You need to set permissions for '$action'!"); |
|
650 | + $PAGE->error_message("You need to set permissions for '$action'!"); |
|
651 | 651 | |
652 | 652 | return false; |
653 | 653 | |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | // Maybe there's a way of fetching these from the DB, |
666 | 666 | // so we don't duplicate them here...? |
667 | 667 | |
668 | - $statuses = array ("Viewer", "User", "Moderator", "Administrator", "Superuser"); |
|
668 | + $statuses = array("Viewer", "User", "Moderator", "Administrator", "Superuser"); |
|
669 | 669 | |
670 | 670 | return $statuses; |
671 | 671 | |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | . $deletedsql |
804 | 804 | . $confirmedsql |
805 | 805 | . $emailsql |
806 | - . $statussql . " |
|
806 | + . $statussql." |
|
807 | 807 | optin = :optin |
808 | 808 | WHERE user_id = :user_id |
809 | 809 | ", array_merge($params, array( |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | return $details; |
824 | 824 | |
825 | 825 | } else { |
826 | - $PAGE->error_message ("Sorry, we were unable to update user id '" . _htmlentities($details["user_id"]) . "'"); |
|
826 | + $PAGE->error_message("Sorry, we were unable to update user id '"._htmlentities($details["user_id"])."'"); |
|
827 | 827 | |
828 | 828 | return false; |
829 | 829 | } |
@@ -896,13 +896,13 @@ discard block |
||
896 | 896 | |
897 | 897 | if ($this->facebook_user) { |
898 | 898 | if (md5($this->facebook_token()) == $matches[2] && $this->deleted() == false) { |
899 | - twfy_debug ("THEUSER", "init SUCCESS: setting as logged in"); |
|
899 | + twfy_debug("THEUSER", "init SUCCESS: setting as logged in"); |
|
900 | 900 | $this->loggedin = true; |
901 | - } elseif (md5 ($this->facebook_token()) != $matches[2]) { |
|
902 | - twfy_debug ("THEUSER", "init FAILED: Facebook token doesn't match cookie"); |
|
901 | + } elseif (md5($this->facebook_token()) != $matches[2]) { |
|
902 | + twfy_debug("THEUSER", "init FAILED: Facebook token doesn't match cookie"); |
|
903 | 903 | $this->loggedin = false; |
904 | 904 | } else { |
905 | - twfy_debug ("THEUSER", "init FAILED: User is deleted"); |
|
905 | + twfy_debug("THEUSER", "init FAILED: User is deleted"); |
|
906 | 906 | $this->loggedin = false; |
907 | 907 | } |
908 | 908 | } else { |
@@ -915,30 +915,30 @@ discard block |
||
915 | 915 | // to need. Their preferences and saved things or something. |
916 | 916 | |
917 | 917 | |
918 | - twfy_debug ("THEUSER init SUCCEEDED", "setting as logged in"); |
|
918 | + twfy_debug("THEUSER init SUCCEEDED", "setting as logged in"); |
|
919 | 919 | $this->loggedin = true; |
920 | 920 | |
921 | - } elseif (md5 ($this->password()) != $matches[2]) { |
|
922 | - twfy_debug ("THEUSER init FAILED", "Password doesn't match cookie"); |
|
921 | + } elseif (md5($this->password()) != $matches[2]) { |
|
922 | + twfy_debug("THEUSER init FAILED", "Password doesn't match cookie"); |
|
923 | 923 | $this->loggedin = false; |
924 | 924 | } else { |
925 | - twfy_debug ("THEUSER init FAILED", "User is deleted"); |
|
925 | + twfy_debug("THEUSER init FAILED", "User is deleted"); |
|
926 | 926 | $this->loggedin = false; |
927 | 927 | } |
928 | 928 | } |
929 | 929 | |
930 | 930 | } else { |
931 | - twfy_debug ("THEUSER init FAILED", "didn't get 1 row from db"); |
|
931 | + twfy_debug("THEUSER init FAILED", "didn't get 1 row from db"); |
|
932 | 932 | $this->loggedin = false; |
933 | 933 | } |
934 | 934 | |
935 | 935 | } else { |
936 | - twfy_debug ("THEUSER init FAILED", "cookie's user_id is not numeric"); |
|
936 | + twfy_debug("THEUSER init FAILED", "cookie's user_id is not numeric"); |
|
937 | 937 | $this->loggedin = false; |
938 | 938 | } |
939 | 939 | |
940 | 940 | } else { |
941 | - twfy_debug ("THEUSER init FAILED", "cookie is not of the correct form"); |
|
941 | + twfy_debug("THEUSER init FAILED", "cookie is not of the correct form"); |
|
942 | 942 | $this->loggedin = false; |
943 | 943 | } |
944 | 944 | |
@@ -965,7 +965,7 @@ discard block |
||
965 | 965 | $date_now = gmdate("Y-m-d H:i:s"); |
966 | 966 | $q = $this->db->query("UPDATE users |
967 | 967 | SET lastvisit = '$date_now' |
968 | - WHERE user_id = '" . $this->user_id() . "'"); |
|
968 | + WHERE user_id = '".$this->user_id()."'"); |
|
969 | 969 | |
970 | 970 | $this->lastvisit = $date_now; |
971 | 971 | } |
@@ -1004,83 +1004,83 @@ discard block |
||
1004 | 1004 | // This error string is shared between both email and password errors to |
1005 | 1005 | // prevent leaking of account existence. |
1006 | 1006 | |
1007 | - $error_string = 'There is no user registered with an email of ' . _htmlentities($email) . ', or the given password is incorrect. If you are subscribed to email alerts, you are not necessarily registered on the website. If you register, you will be able to manage your email alerts, as well as leave annotations.'; |
|
1007 | + $error_string = 'There is no user registered with an email of '._htmlentities($email).', or the given password is incorrect. If you are subscribed to email alerts, you are not necessarily registered on the website. If you register, you will be able to manage your email alerts, as well as leave annotations.'; |
|
1008 | 1008 | |
1009 | 1009 | $q = $this->db->query("SELECT user_id, password, deleted, confirmed FROM users WHERE email = :email", array(':email' => $email)); |
1010 | 1010 | |
1011 | 1011 | if ($q->rows() == 1) { |
1012 | 1012 | // OK. |
1013 | - $dbpassword = $q->field(0,"password"); |
|
1013 | + $dbpassword = $q->field(0, "password"); |
|
1014 | 1014 | if (password_verify($userenteredpassword, $dbpassword)) { |
1015 | - $this->user_id = $q->field(0,"user_id"); |
|
1015 | + $this->user_id = $q->field(0, "user_id"); |
|
1016 | 1016 | $this->password = $dbpassword; |
1017 | 1017 | // We'll need these when we're going to log in. |
1018 | - $this->deleted = $q->field(0,"deleted") == 1 ? true : false; |
|
1019 | - $this->confirmed = $q->field(0,"confirmed") == 1 ? true : false; |
|
1018 | + $this->deleted = $q->field(0, "deleted") == 1 ? true : false; |
|
1019 | + $this->confirmed = $q->field(0, "confirmed") == 1 ? true : false; |
|
1020 | 1020 | |
1021 | 1021 | return true; |
1022 | 1022 | |
1023 | 1023 | } else { |
1024 | 1024 | // Failed. |
1025 | - return array ("invalidemail" => $error_string); |
|
1025 | + return array("invalidemail" => $error_string); |
|
1026 | 1026 | |
1027 | 1027 | } |
1028 | 1028 | |
1029 | 1029 | } else { |
1030 | 1030 | // Failed. |
1031 | - return array ("invalidemail" => $error_string); |
|
1031 | + return array("invalidemail" => $error_string); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | public function has_postcode() { |
1037 | 1037 | $has_postcode = false; |
1038 | - if ( $this->isloggedin() && $this->postcode() != '' || $this->postcode_is_set() ) { |
|
1038 | + if ($this->isloggedin() && $this->postcode() != '' || $this->postcode_is_set()) { |
|
1039 | 1039 | $has_postcode = true; |
1040 | 1040 | } |
1041 | 1041 | return $has_postcode; |
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | |
1045 | - public function facebook_login($returl="", $expire, $accessToken) { |
|
1045 | + public function facebook_login($returl = "", $expire, $accessToken) { |
|
1046 | 1046 | global $PAGE; |
1047 | 1047 | |
1048 | - twfy_debug("THEUSER", "Faceook login, user_id " . $this->user_id); |
|
1049 | - twfy_debug("THEUSER", "Faceook login, facebook_id " . $this->facebook_id); |
|
1050 | - twfy_debug("THEUSER", "Faceook login, email" . $this->email); |
|
1048 | + twfy_debug("THEUSER", "Faceook login, user_id ".$this->user_id); |
|
1049 | + twfy_debug("THEUSER", "Faceook login, facebook_id ".$this->facebook_id); |
|
1050 | + twfy_debug("THEUSER", "Faceook login, email".$this->email); |
|
1051 | 1051 | if ($this->facebook_id() == "") { |
1052 | - $PAGE->error_message ("We don't have a facebook id for this user.", true); |
|
1052 | + $PAGE->error_message("We don't have a facebook id for this user.", true); |
|
1053 | 1053 | |
1054 | 1054 | return; |
1055 | 1055 | } |
1056 | 1056 | |
1057 | - twfy_debug("THEUSER", "Faceook login, facebook_token: " . $accessToken); |
|
1057 | + twfy_debug("THEUSER", "Faceook login, facebook_token: ".$accessToken); |
|
1058 | 1058 | |
1059 | - $q = $this->db->query ("UPDATE users SET facebook_token = :token WHERE email = :email", |
|
1059 | + $q = $this->db->query("UPDATE users SET facebook_token = :token WHERE email = :email", |
|
1060 | 1060 | array( |
1061 | 1061 | ':token' => $accessToken, |
1062 | 1062 | ':email' => $this->email |
1063 | 1063 | )); |
1064 | 1064 | |
1065 | 1065 | if (!$q->success()) { |
1066 | - $PAGE->error_message ("There was a problem logging you in", true); |
|
1066 | + $PAGE->error_message("There was a problem logging you in", true); |
|
1067 | 1067 | twfy_debug("THEUSER", "Faceook login, failed to set accessToken"); |
1068 | 1068 | |
1069 | 1069 | return false; |
1070 | 1070 | } |
1071 | 1071 | |
1072 | 1072 | // facebook login users probably don't have a password |
1073 | - $cookie = $this->user_id() . "." . md5 ($accessToken); |
|
1074 | - twfy_debug("THEUSER", "Faceook login, cookie: " . $cookie); |
|
1073 | + $cookie = $this->user_id().".".md5($accessToken); |
|
1074 | + twfy_debug("THEUSER", "Faceook login, cookie: ".$cookie); |
|
1075 | 1075 | |
1076 | - twfy_debug("USER", "logging in user from facebook " . $this->user_id); |
|
1076 | + twfy_debug("USER", "logging in user from facebook ".$this->user_id); |
|
1077 | 1077 | |
1078 | 1078 | $this->loggedin = True; |
1079 | 1079 | $this->_login($returl, $expire, $cookie, 'facebook_id'); |
1080 | 1080 | return true; |
1081 | 1081 | } |
1082 | 1082 | |
1083 | - public function login($returl="", $expire) { |
|
1083 | + public function login($returl = "", $expire) { |
|
1084 | 1084 | |
1085 | 1085 | // This is used to log the user in. Duh. |
1086 | 1086 | // You should already have checked the user's email and password using |
@@ -1102,21 +1102,21 @@ discard block |
||
1102 | 1102 | |
1103 | 1103 | // Various checks about the user - if they fail, we exit. |
1104 | 1104 | if ($this->user_id() == "" || $this->password == "") { |
1105 | - $PAGE->error_message ("We don't have the user_id or password to make the cookie.", true); |
|
1105 | + $PAGE->error_message("We don't have the user_id or password to make the cookie.", true); |
|
1106 | 1106 | |
1107 | 1107 | return; |
1108 | 1108 | } elseif ($this->deleted) { |
1109 | - $PAGE->error_message ("This user has been deleted.", true); |
|
1109 | + $PAGE->error_message("This user has been deleted.", true); |
|
1110 | 1110 | |
1111 | 1111 | return; |
1112 | 1112 | } elseif (!$this->confirmed) { |
1113 | - $PAGE->error_message ("You have not yet confirmed your account by clicking the link in the confirmation email we sent to you. If you don't have the email, you can <a href='/user/login/?resend=" . $this->user_id() . "'>have it resent</a>. If it still doesn't arrive, get in touch.", true); |
|
1113 | + $PAGE->error_message("You have not yet confirmed your account by clicking the link in the confirmation email we sent to you. If you don't have the email, you can <a href='/user/login/?resend=".$this->user_id()."'>have it resent</a>. If it still doesn't arrive, get in touch.", true); |
|
1114 | 1114 | |
1115 | 1115 | return; |
1116 | 1116 | } |
1117 | 1117 | |
1118 | 1118 | // Reminder: $this->password is actually a hashed version of the plaintext pw. |
1119 | - $cookie = $this->user_id() . "." . md5 ($this->password()); |
|
1119 | + $cookie = $this->user_id().".".md5($this->password()); |
|
1120 | 1120 | |
1121 | 1121 | $this->_login($returl, $expire, $cookie); |
1122 | 1122 | } |
@@ -1127,14 +1127,14 @@ discard block |
||
1127 | 1127 | // user. We don't want it hanging around as it causes confusion. |
1128 | 1128 | $this->unset_postcode_cookie(); |
1129 | 1129 | |
1130 | - twfy_debug("THEUSER", "expire is " . $expire); |
|
1130 | + twfy_debug("THEUSER", "expire is ".$expire); |
|
1131 | 1131 | |
1132 | 1132 | $cookie_expires = 0; |
1133 | 1133 | if ($expire == 'never') { |
1134 | 1134 | twfy_debug("THEUSER", "cookie never expires"); |
1135 | - $cookie_expires = time()+86400*365*20; |
|
1135 | + $cookie_expires = time() + 86400 * 365 * 20; |
|
1136 | 1136 | } elseif (is_int($expire) && $expire > time()) { |
1137 | - twfy_debug("THEUSER", "cookie expires at " . $expire); |
|
1137 | + twfy_debug("THEUSER", "cookie expires at ".$expire); |
|
1138 | 1138 | $cookie_expires = $expire; |
1139 | 1139 | } else { |
1140 | 1140 | twfy_debug("THEUSER", "cookie expires with session"); |
@@ -1170,7 +1170,7 @@ discard block |
||
1170 | 1170 | } |
1171 | 1171 | } |
1172 | 1172 | |
1173 | - public function confirm_email($token, $redirect=true) { |
|
1173 | + public function confirm_email($token, $redirect = true) { |
|
1174 | 1174 | $arg = ''; |
1175 | 1175 | if (strstr($token, '::')) $arg = '::'; |
1176 | 1176 | if (strstr($token, '-')) $arg = '-'; |
@@ -1183,24 +1183,24 @@ discard block |
||
1183 | 1183 | FROM tokens |
1184 | 1184 | WHERE token = :token |
1185 | 1185 | AND type = 'E' |
1186 | - ", array (':token' => $registrationtoken)); |
|
1186 | + ", array(':token' => $registrationtoken)); |
|
1187 | 1187 | |
1188 | 1188 | if ($q->rows() == 1) { |
1189 | 1189 | $expires = $q->field(0, 'expires'); |
1190 | 1190 | $expire_time = strtotime($expires); |
1191 | - if ( $expire_time < time() ) { |
|
1191 | + if ($expire_time < time()) { |
|
1192 | 1192 | global $PAGE; |
1193 | 1193 | if ($PAGE && $redirect) { |
1194 | - $PAGE->error_message ("Sorry, that token seems to have expired"); |
|
1194 | + $PAGE->error_message("Sorry, that token seems to have expired"); |
|
1195 | 1195 | } |
1196 | 1196 | |
1197 | 1197 | return false; |
1198 | 1198 | } |
1199 | 1199 | |
1200 | - list( $user_id, $email ) = explode('::', $q->field(0, 'data')); |
|
1200 | + list($user_id, $email) = explode('::', $q->field(0, 'data')); |
|
1201 | 1201 | |
1202 | 1202 | // if we are logged in as someone else don't change the email |
1203 | - if ( $this->user_id() != 0 && $this->user_id() != $user_id ) { |
|
1203 | + if ($this->user_id() != 0 && $this->user_id() != $user_id) { |
|
1204 | 1204 | return false; |
1205 | 1205 | } |
1206 | 1206 | |
@@ -1292,7 +1292,7 @@ discard block |
||
1292 | 1292 | # This should probably be in the ALERT class |
1293 | 1293 | $this->db->query('update alerts set confirmed=1 where email = :email and criteria = :criteria', array( |
1294 | 1294 | ':email' => $this->email, |
1295 | - ':criteria' => 'speaker:' . $pid |
|
1295 | + ':criteria' => 'speaker:'.$pid |
|
1296 | 1296 | )); |
1297 | 1297 | } catch (MySociety\TheyWorkForYou\MemberException $e) { |
1298 | 1298 | } |
@@ -1328,7 +1328,7 @@ discard block |
||
1328 | 1328 | // |
1329 | 1329 | // Note that this doesn't login or redirect the user. |
1330 | 1330 | |
1331 | - twfy_debug("THEUSER", "Confirming user without token: " . $this->user_id()); |
|
1331 | + twfy_debug("THEUSER", "Confirming user without token: ".$this->user_id()); |
|
1332 | 1332 | $q = $this->db->query("SELECT email, password, postcode |
1333 | 1333 | FROM users |
1334 | 1334 | WHERE user_id = :user_id |
@@ -1338,9 +1338,9 @@ discard block |
||
1338 | 1338 | |
1339 | 1339 | if ($q->rows() == 1) { |
1340 | 1340 | |
1341 | - twfy_debug("THEUSER", "User with ID found to confirm: " . $this->user_id()); |
|
1341 | + twfy_debug("THEUSER", "User with ID found to confirm: ".$this->user_id()); |
|
1342 | 1342 | // We'll need these to be set before logging the user in. |
1343 | - $this->email = $q->field(0, 'email'); |
|
1343 | + $this->email = $q->field(0, 'email'); |
|
1344 | 1344 | |
1345 | 1345 | // Set that they're confirmed in the DB. |
1346 | 1346 | $r = $this->db->query("UPDATE users |
@@ -1355,18 +1355,18 @@ discard block |
||
1355 | 1355 | # This should probably be in the ALERT class |
1356 | 1356 | $this->db->query('update alerts set confirmed=1 where email = :email and criteria = :criteria', array( |
1357 | 1357 | ':email' => $this->email, |
1358 | - ':criteria' => 'speaker:' . $pid |
|
1358 | + ':criteria' => 'speaker:'.$pid |
|
1359 | 1359 | )); |
1360 | 1360 | } catch (MySociety\TheyWorkForYou\MemberException $e) { |
1361 | 1361 | } |
1362 | 1362 | } |
1363 | 1363 | |
1364 | 1364 | if ($r->success()) { |
1365 | - twfy_debug("THEUSER", "User with ID confirmed: " . $this->user_id()); |
|
1365 | + twfy_debug("THEUSER", "User with ID confirmed: ".$this->user_id()); |
|
1366 | 1366 | $this->confirmed = true; |
1367 | 1367 | return true; |
1368 | 1368 | } else { |
1369 | - twfy_debug("THEUSER", "User with ID not confirmed: " . $this->user_id()); |
|
1369 | + twfy_debug("THEUSER", "User with ID not confirmed: ".$this->user_id()); |
|
1370 | 1370 | // Couldn't set them as confirmed in the DB. |
1371 | 1371 | return false; |
1372 | 1372 | } |
@@ -1374,7 +1374,7 @@ discard block |
||
1374 | 1374 | } else { |
1375 | 1375 | // Couldn't find this user in the DB. Maybe the token was |
1376 | 1376 | // wrong or incomplete? |
1377 | - twfy_debug("THEUSER", "User with ID not found to confirm: " . $this->user_id()); |
|
1377 | + twfy_debug("THEUSER", "User with ID not found to confirm: ".$this->user_id()); |
|
1378 | 1378 | return false; |
1379 | 1379 | } |
1380 | 1380 | } |
@@ -1387,14 +1387,14 @@ discard block |
||
1387 | 1387 | |
1388 | 1388 | $this->postcode = $pc; |
1389 | 1389 | if (!headers_sent()) // if in debug mode |
1390 | - setcookie (POSTCODE_COOKIE, $pc, time()+7*86400, "/", COOKIEDOMAIN); |
|
1390 | + setcookie(POSTCODE_COOKIE, $pc, time() + 7 * 86400, "/", COOKIEDOMAIN); |
|
1391 | 1391 | |
1392 | - twfy_debug('USER', "Set the cookie named '" . POSTCODE_COOKIE . " to '$pc' for " . COOKIEDOMAIN . " domain"); |
|
1392 | + twfy_debug('USER', "Set the cookie named '".POSTCODE_COOKIE." to '$pc' for ".COOKIEDOMAIN." domain"); |
|
1393 | 1393 | } |
1394 | 1394 | |
1395 | 1395 | public function unset_postcode_cookie() { |
1396 | 1396 | if (!headers_sent()) // if in debug mode |
1397 | - setcookie (POSTCODE_COOKIE, '', time() - 3600, '/', COOKIEDOMAIN); |
|
1397 | + setcookie(POSTCODE_COOKIE, '', time() - 3600, '/', COOKIEDOMAIN); |
|
1398 | 1398 | } |
1399 | 1399 | |
1400 | 1400 | // mostly here for updating from facebook where we do not need |
@@ -1407,8 +1407,8 @@ discard block |
||
1407 | 1407 | |
1408 | 1408 | // this is checked elsewhere but just in case we check here and |
1409 | 1409 | // bail out to be on the safe side |
1410 | - if ( isset($details['email'] ) ) { |
|
1411 | - if ( $details['email'] != $this->email() && $this->email_exists( $details['email'] ) ) { |
|
1410 | + if (isset($details['email'])) { |
|
1411 | + if ($details['email'] != $this->email() && $this->email_exists($details['email'])) { |
|
1412 | 1412 | return false; |
1413 | 1413 | } |
1414 | 1414 | } |
@@ -1457,8 +1457,8 @@ discard block |
||
1457 | 1457 | // this is checked elsewhere but just in case we check here and |
1458 | 1458 | // bail out to be on the safe side |
1459 | 1459 | $email = ''; |
1460 | - if ( isset($details['email'] ) ) { |
|
1461 | - if ( $details['email'] != $this->email() && $this->email_exists( $details['email'] ) ) { |
|
1460 | + if (isset($details['email'])) { |
|
1461 | + if ($details['email'] != $this->email() && $this->email_exists($details['email'])) { |
|
1462 | 1462 | return false; |
1463 | 1463 | } |
1464 | 1464 | $email = $details['email']; |
@@ -1486,8 +1486,8 @@ discard block |
||
1486 | 1486 | } |
1487 | 1487 | |
1488 | 1488 | if ($email && $email != $this->email) { |
1489 | - $token = substr( password_hash($email . microtime(), PASSWORD_BCRYPT), 29, 16 ); |
|
1490 | - $data = $this->user_id() . '::' . $email; |
|
1489 | + $token = substr(password_hash($email.microtime(), PASSWORD_BCRYPT), 29, 16); |
|
1490 | + $data = $this->user_id().'::'.$email; |
|
1491 | 1491 | $r = $this->db->query("INSERT INTO tokens |
1492 | 1492 | ( expires, token, type, data ) |
1493 | 1493 | VALUES |
@@ -1503,7 +1503,7 @@ discard block |
||
1503 | 1503 | )); |
1504 | 1504 | |
1505 | 1505 | // send confirmation email here |
1506 | - if ( $r->success() ) { |
|
1506 | + if ($r->success()) { |
|
1507 | 1507 | $newdetails['email'] = $email; |
1508 | 1508 | $newdetails['token'] = $token; |
1509 | 1509 | if ($confirm_email) { |