@@ -38,8 +38,9 @@ discard block |
||
38 | 38 | public $error; |
39 | 39 | |
40 | 40 | public function __construct($query, $lang='') { |
41 | - if (!defined('XAPIANDB') || !XAPIANDB) |
|
42 | - return null; |
|
41 | + if (!defined('XAPIANDB') || !XAPIANDB) { |
|
42 | + return null; |
|
43 | + } |
|
43 | 44 | |
44 | 45 | global $xapiandb, $PAGE; |
45 | 46 | if (!$xapiandb) { |
@@ -54,8 +55,12 @@ discard block |
||
54 | 55 | } |
55 | 56 | } |
56 | 57 | $this->query = $query; |
57 | - if (!isset($this->stemmer)) $this->stemmer = new XapianStem('english'); |
|
58 | - if (!isset($this->enquire)) $this->enquire = new XapianEnquire($xapiandb); |
|
58 | + if (!isset($this->stemmer)) { |
|
59 | + $this->stemmer = new XapianStem('english'); |
|
60 | + } |
|
61 | + if (!isset($this->enquire)) { |
|
62 | + $this->enquire = new XapianEnquire($xapiandb); |
|
63 | + } |
|
59 | 64 | if (!isset($this->queryparser)) { |
60 | 65 | $this->queryparser = new XapianQueryParser(); |
61 | 66 | $this->datevaluerange = new XapianDateValueRangeProcessor(1); |
@@ -111,7 +116,9 @@ discard block |
||
111 | 116 | foreach ($all_words as $word) { |
112 | 117 | if ($word == '"') { |
113 | 118 | $in_quote = !$in_quote; |
114 | - if ($in_quote) array_push($this->phrases, array()); |
|
119 | + if ($in_quote) { |
|
120 | + array_push($this->phrases, array()); |
|
121 | + } |
|
115 | 122 | if (!$in_quote && !count($this->phrases[count($this->phrases) - 1])) { |
116 | 123 | array_pop($this->phrases); |
117 | 124 | } |
@@ -124,24 +131,41 @@ discard block |
||
124 | 131 | if (strpos($word, ':') !== false) { |
125 | 132 | $items = explode(":", strtolower($word)); |
126 | 133 | $type = $items[0]; |
127 | - if (substr($type, 0, 1)=='-') $type = substr($type, 1); |
|
134 | + if (substr($type, 0, 1)=='-') { |
|
135 | + $type = substr($type, 1); |
|
136 | + } |
|
128 | 137 | $value = strtolower(join(":", array_slice($items,1))); |
129 | 138 | if ($type == 'section') { |
130 | 139 | $newv = $value; |
131 | - if ($value == 'debates' || $value == 'debate') $newv = 1; |
|
132 | - elseif ($value == 'whall' || $value == 'westminster' || $value == 'westminhall') $newv = 2; |
|
133 | - elseif ($value == 'wrans' || $value == 'wran') $newv = 3; |
|
134 | - elseif ($value == 'wms' || $value == 'statements' || $value == 'statement') $newv = 4; |
|
135 | - elseif ($value == 'lordsdebates' || $value == 'lords') $newv = 101; |
|
136 | - elseif ($value == 'ni' || $value == 'nidebates') $newv = 5; |
|
137 | - elseif ($value == 'pbc' || $value == 'standing') $newv = 6; |
|
138 | - elseif ($value == 'sp') $newv = 7; |
|
139 | - elseif ($value == 'spwrans' || $value == 'spwran') $newv = 8; |
|
140 | - elseif ($value == 'lmqs') $newv = 9; |
|
141 | - elseif ($value == 'uk') $newv = array(1,2,3,4,6,101); |
|
142 | - elseif ($value == 'scotland') $newv = array(7,8); |
|
143 | - elseif ($value == 'wales') $newv = ($lang == 'cy' || LANGUAGE == 'cy') ? 11 : 10; |
|
144 | - elseif ($value == 'future') $newv = 'F'; |
|
140 | + if ($value == 'debates' || $value == 'debate') { |
|
141 | + $newv = 1; |
|
142 | + } elseif ($value == 'whall' || $value == 'westminster' || $value == 'westminhall') { |
|
143 | + $newv = 2; |
|
144 | + } elseif ($value == 'wrans' || $value == 'wran') { |
|
145 | + $newv = 3; |
|
146 | + } elseif ($value == 'wms' || $value == 'statements' || $value == 'statement') { |
|
147 | + $newv = 4; |
|
148 | + } elseif ($value == 'lordsdebates' || $value == 'lords') { |
|
149 | + $newv = 101; |
|
150 | + } elseif ($value == 'ni' || $value == 'nidebates') { |
|
151 | + $newv = 5; |
|
152 | + } elseif ($value == 'pbc' || $value == 'standing') { |
|
153 | + $newv = 6; |
|
154 | + } elseif ($value == 'sp') { |
|
155 | + $newv = 7; |
|
156 | + } elseif ($value == 'spwrans' || $value == 'spwran') { |
|
157 | + $newv = 8; |
|
158 | + } elseif ($value == 'lmqs') { |
|
159 | + $newv = 9; |
|
160 | + } elseif ($value == 'uk') { |
|
161 | + $newv = array(1,2,3,4,6,101); |
|
162 | + } elseif ($value == 'scotland') { |
|
163 | + $newv = array(7,8); |
|
164 | + } elseif ($value == 'wales') { |
|
165 | + $newv = ($lang == 'cy' || LANGUAGE == 'cy') ? 11 : 10; |
|
166 | + } elseif ($value == 'future') { |
|
167 | + $newv = 'F'; |
|
168 | + } |
|
145 | 169 | if (is_array($newv)) { |
146 | 170 | $newv = 'major:' . join(' major:', $newv); |
147 | 171 | } else { |
@@ -150,8 +174,12 @@ discard block |
||
150 | 174 | $this->query = str_ireplace("$type:$value", $newv, $this->query); |
151 | 175 | } elseif ($type == 'groupby') { |
152 | 176 | $newv = $value; |
153 | - if ($value == 'debates' || $value == 'debate') $newv = 'debate'; |
|
154 | - if ($value == 'speech' || $value == 'speeches') $newv = 'speech'; |
|
177 | + if ($value == 'debates' || $value == 'debate') { |
|
178 | + $newv = 'debate'; |
|
179 | + } |
|
180 | + if ($value == 'speech' || $value == 'speeches') { |
|
181 | + $newv = 'speech'; |
|
182 | + } |
|
155 | 183 | $this->query = str_ireplace("$type:$value", '', $this->query); |
156 | 184 | array_push($this->prefixed, array($type, $newv)); |
157 | 185 | } elseif ($type == 'from') { |
@@ -288,7 +316,9 @@ discard block |
||
288 | 316 | $end = $this->queryparser->unstem_end($mm); |
289 | 317 | while (!$iter->equals($end)) { |
290 | 318 | $tt = $iter->get_term(); |
291 | - if (!in_array($tt, $used)) break; |
|
319 | + if (!in_array($tt, $used)) { |
|
320 | + break; |
|
321 | + } |
|
292 | 322 | $iter->next(); |
293 | 323 | } |
294 | 324 | $used[] = $tt; |
@@ -375,8 +405,9 @@ discard block |
||
375 | 405 | |
376 | 406 | // Perform partial query to get a count of number of matches |
377 | 407 | public function run_count($first_result, $results_per_page, $sort_order='relevance') { |
378 | - if (!defined('XAPIANDB') || !XAPIANDB) |
|
379 | - return null; |
|
408 | + if (!defined('XAPIANDB') || !XAPIANDB) { |
|
409 | + return null; |
|
410 | + } |
|
380 | 411 | |
381 | 412 | $start = getmicrotime(); |
382 | 413 | |
@@ -406,16 +437,18 @@ discard block |
||
406 | 437 | $collapsed = true; |
407 | 438 | if ($items[1] == 'speech') |
408 | 439 | ; // no collapse key |
409 | - elseif ($items[1] == 'debate') |
|
410 | - $this->enquire->set_collapse_key(3); |
|
411 | - else |
|
412 | - $PAGE->error_message("Unknown group by '$items[1]' ignored"); |
|
440 | + elseif ($items[1] == 'debate') { |
|
441 | + $this->enquire->set_collapse_key(3); |
|
442 | + } else { |
|
443 | + $PAGE->error_message("Unknown group by '$items[1]' ignored"); |
|
444 | + } |
|
413 | 445 | } |
414 | 446 | } |
415 | 447 | |
416 | 448 | // default to grouping by subdebate, i.e. by page |
417 | - if (!$collapsed) |
|
418 | - $this->enquire->set_collapse_key(3); |
|
449 | + if (!$collapsed) { |
|
450 | + $this->enquire->set_collapse_key(3); |
|
451 | + } |
|
419 | 452 | |
420 | 453 | /* |
421 | 454 | XXX Helping to debug possible Xapian bug |
@@ -495,8 +528,9 @@ discard block |
||
495 | 528 | |
496 | 529 | // Puts HTML highlighting round all the matching words in the text |
497 | 530 | public function highlight($body) { |
498 | - if (!defined('XAPIANDB') || !XAPIANDB) |
|
499 | - return $body; |
|
531 | + if (!defined('XAPIANDB') || !XAPIANDB) { |
|
532 | + return $body; |
|
533 | + } |
|
500 | 534 | |
501 | 535 | $stemmed_words = array_map(array($this, 'stem'), $this->words); |
502 | 536 | if (is_array($body)) { |
@@ -514,8 +548,9 @@ discard block |
||
514 | 548 | private $specialchars_upper = array('<', '>', '"', '&'); |
515 | 549 | |
516 | 550 | public function highlight_internal($body, $stemmed_words) { |
517 | - if (!defined('XAPIANDB') || !XAPIANDB) |
|
518 | - return $body; |
|
551 | + if (!defined('XAPIANDB') || !XAPIANDB) { |
|
552 | + return $body; |
|
553 | + } |
|
519 | 554 | |
520 | 555 | # Does html_entity_decode without the htmlspecialchars |
521 | 556 | $body = str_replace($this->specialchars, $this->specialchars_upper, $body); |
@@ -536,7 +571,9 @@ discard block |
||
536 | 571 | $hl = false; |
537 | 572 | $matchword = $this->stem($extractword); |
538 | 573 | foreach ($stemmed_words as $word) { |
539 | - if ($word == '') continue; |
|
574 | + if ($word == '') { |
|
575 | + continue; |
|
576 | + } |
|
540 | 577 | if ($matchword == $word) { |
541 | 578 | $hl = true; |
542 | 579 | break; |
@@ -588,8 +625,7 @@ discard block |
||
588 | 625 | // look for phrases |
589 | 626 | foreach ($this->phrases as $phrase) { |
590 | 627 | $phrasematch = join($phrase, '[^'.$this->wordchars.']+'); |
591 | - if (preg_match('/([^'.$this->wordchars.']' . $phrasematch . '[^A-Za-z0-9])/', $lcbody, $matches)) |
|
592 | - { |
|
628 | + if (preg_match('/([^'.$this->wordchars.']' . $phrasematch . '[^A-Za-z0-9])/', $lcbody, $matches)) { |
|
593 | 629 | $wordpos = strpos( $lcbody, $matches[0] ); |
594 | 630 | if ($wordpos) { |
595 | 631 | if ( ($wordpos < $pos) || ($pos==-1) ) { |
@@ -598,17 +634,25 @@ discard block |
||
598 | 634 | } |
599 | 635 | } |
600 | 636 | } |
601 | - if ($pos != -1) return $pos; |
|
637 | + if ($pos != -1) { |
|
638 | + return $pos; |
|
639 | + } |
|
602 | 640 | |
603 | 641 | $splitextract = preg_split('/([0-9,.]+|['.$this->wordcharsnodigit.']+)/', $lcbody, -1, PREG_SPLIT_DELIM_CAPTURE); |
604 | 642 | $stemmed_words = array_map(array($this, 'stem'), $this->words); |
605 | 643 | foreach ($splitextract as $extractword) { |
606 | 644 | $extractword = preg_replace('/&$/', '', $extractword); |
607 | - if (!$extractword) continue; |
|
645 | + if (!$extractword) { |
|
646 | + continue; |
|
647 | + } |
|
608 | 648 | $wordpos = strpos($lcbody, $extractword); |
609 | - if (!$wordpos) continue; |
|
649 | + if (!$wordpos) { |
|
650 | + continue; |
|
651 | + } |
|
610 | 652 | foreach ($stemmed_words as $word) { |
611 | - if ($word == '') continue; |
|
653 | + if ($word == '') { |
|
654 | + continue; |
|
655 | + } |
|
612 | 656 | $matchword = $this->stem($extractword); |
613 | 657 | if ($matchword == $word && ($wordpos < $pos || $pos==-1)) { |
614 | 658 | $pos = $wordpos; |
@@ -616,10 +660,14 @@ discard block |
||
616 | 660 | } |
617 | 661 | } |
618 | 662 | // only look for earlier words if phrases weren't found |
619 | - if ($pos != -1) return $pos; |
|
663 | + if ($pos != -1) { |
|
664 | + return $pos; |
|
665 | + } |
|
620 | 666 | |
621 | 667 | foreach ($this->words as $word) { |
622 | - if (ctype_digit($word)) $word = '(?:'.$word.'|'.number_format($word).')'; |
|
668 | + if (ctype_digit($word)) { |
|
669 | + $word = '(?:'.$word.'|'.number_format($word).')'; |
|
670 | + } |
|
623 | 671 | if (preg_match('/([^'.$this->wordchars.']' . $word . '[^'.$this->wordchars. '])/', $lcbody, $matches)) { |
624 | 672 | $wordpos = strpos( $lcbody, $matches[0] ); |
625 | 673 | if ($wordpos) { |
@@ -630,10 +678,14 @@ discard block |
||
630 | 678 | } |
631 | 679 | } |
632 | 680 | // only look for something containing the word (ie. something stemmed, but doesn't work all the time) if no whole word was found |
633 | - if ($pos != -1) return $pos; |
|
681 | + if ($pos != -1) { |
|
682 | + return $pos; |
|
683 | + } |
|
634 | 684 | |
635 | 685 | foreach ($this->words as $word) { |
636 | - if (ctype_digit($word)) $word = '(?:'.$word.'|'.number_format($word).')'; |
|
686 | + if (ctype_digit($word)) { |
|
687 | + $word = '(?:'.$word.'|'.number_format($word).')'; |
|
688 | + } |
|
637 | 689 | if (preg_match('/(' . $word . ')/', $lcbody, $matches)) { |
638 | 690 | $wordpos = strpos( $lcbody, $matches[0] ); |
639 | 691 | if ($wordpos) { |
@@ -644,8 +696,9 @@ discard block |
||
644 | 696 | } |
645 | 697 | } |
646 | 698 | |
647 | - if ($pos == -1) |
|
648 | - $pos = 0; |
|
699 | + if ($pos == -1) { |
|
700 | + $pos = 0; |
|
701 | + } |
|
649 | 702 | |
650 | 703 | return $pos; |
651 | 704 | } |
@@ -19,9 +19,11 @@ |
||
19 | 19 | } |
20 | 20 | ?> |
21 | 21 | <h2><?= sprintf(gettext('%s in constituencies matching <em class="current-search-term">%s</em>'), $desc, _htmlentities($searchstring)) ?></h2> |
22 | - <?php } elseif ($mp_types['former']) { // count($cons) <= 1 ?> |
|
22 | + <?php } elseif ($mp_types['former']) { |
|
23 | +// count($cons) <= 1 ?> |
|
23 | 24 | <h2><?= sprintf(gettext('Former MP for <em class="current-search-term">%s</em>'), _htmlentities($searchstring)) ?></h2> |
24 | - <?php } else { // count($cons) <= 1 ?> |
|
25 | + <?php } else { |
|
26 | +// count($cons) <= 1 ?> |
|
25 | 27 | <h2><?= sprintf(gettext('MP for <em class="current-search-term">%s</em>'), _htmlentities($searchstring)) ?></h2> |
26 | 28 | <?php } ?> |
27 | 29 | <?php foreach ( $cons as $member ) { ?> |
@@ -217,11 +217,14 @@ |
||
217 | 217 | <?= $recent_appearances['additional_links'] ?> |
218 | 218 | <?php endif; ?> |
219 | 219 | |
220 | - <?php else: ?> |
|
220 | + <?php else { |
|
221 | + : ?> |
|
221 | 222 | |
222 | 223 | <p><?=gettext('No recent appearances to display.') ?></p> |
223 | 224 | |
224 | - <?php endif; ?> |
|
225 | + <?php endif; |
|
226 | +} |
|
227 | +?> |
|
225 | 228 | |
226 | 229 | </div> |
227 | 230 | <?php endif; ?> |
@@ -52,7 +52,9 @@ discard block |
||
52 | 52 | $ret = self::postcodeFetchFromMapit($postcode); |
53 | 53 | } |
54 | 54 | |
55 | - if (is_string($ret)) return $ret; |
|
55 | + if (is_string($ret)) { |
|
56 | + return $ret; |
|
57 | + } |
|
56 | 58 | |
57 | 59 | $last_postcode = $postcode; |
58 | 60 | $last_postcode_value = $ret; |
@@ -126,8 +128,9 @@ discard block |
||
126 | 128 | } |
127 | 129 | $areas = array(); |
128 | 130 | foreach ($r['areas'] as $row) { |
129 | - if (in_array($row['type'], array('WMC', 'SPC', 'SPE', 'NIE', 'WAC', 'WAE'))) |
|
130 | - $areas[$row['type']] = $row['name']; |
|
131 | + if (in_array($row['type'], array('WMC', 'SPC', 'SPE', 'NIE', 'WAC', 'WAE'))) { |
|
132 | + $areas[$row['type']] = $row['name']; |
|
133 | + } |
|
131 | 134 | } |
132 | 135 | |
133 | 136 | if (!isset($areas['WMC'])) { |