Passed
Pull Request — master (#1700)
by Struan
04:10
created
tests/AlertsPageTest.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
      */
12 12
     public function getDataSet()
13 13
     {
14
-        return $this->createMySQLXMLDataSet(dirname(__FILE__).'/_fixtures/alertspage.xml');
14
+        return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/alertspage.xml');
15 15
     }
16 16
 
17 17
     private function fetch_page($vars)
@@ -21,37 +21,37 @@  discard block
 block discarded – undo
21 21
 
22 22
     public function testFetchPage()
23 23
     {
24
-        $page = $this->fetch_page( array() );
24
+        $page = $this->fetch_page(array());
25 25
         $this->assertContains('TheyWorkForYou Email Alerts', $page);
26 26
     }
27 27
 
28 28
     public function testKeywordOnly() {
29
-        $page = $this->fetch_page( array( 'alertsearch' => 'elephant') );
29
+        $page = $this->fetch_page(array('alertsearch' => 'elephant'));
30 30
         $this->assertContains('Receive alerts when [elephant] is mentioned', $page);
31 31
     }
32 32
 
33 33
     public function testPostCodeOnly() {
34
-        $page = $this->fetch_page( array( 'alertsearch' => 'SE17 3HE') );
34
+        $page = $this->fetch_page(array('alertsearch' => 'SE17 3HE'));
35 35
         $this->assertContains('when Mrs Test Current-MP', $page);
36 36
     }
37 37
 
38 38
     public function testPostCodeWithKeyWord()
39 39
     {
40
-        $page = $this->fetch_page( array( 'alertsearch' => 'SE17 3HE elephant') );
40
+        $page = $this->fetch_page(array('alertsearch' => 'SE17 3HE elephant'));
41 41
         $this->assertContains('You have used a postcode and something else', $page);
42 42
         $this->assertContains('Mentions of [elephant] by your MP, Mrs Test Current-MP', $page);
43 43
         $this->assertNotContains('by your MSP', $page);
44 44
     }
45 45
 
46 46
     public function testScottishPostcodeWithKeyword() {
47
-        $page = $this->fetch_page( array( 'alertsearch' => 'PH6 2DB elephant') );
47
+        $page = $this->fetch_page(array('alertsearch' => 'PH6 2DB elephant'));
48 48
         $this->assertContains('You have used a postcode and something else', $page);
49 49
         $this->assertContains('Mentions of [elephant] by your MP, Mr Test2 Current-MP', $page);
50 50
         $this->assertContains('Mentions of [elephant] by your MSP, Mrs Test Current-MSP', $page);
51 51
     }
52 52
 
53 53
     public function testPostcodeAndKeywordWithNoSittingMP() {
54
-        $page = $this->fetch_page( array( 'alertsearch' => 'OX1 4LF elephant') );
54
+        $page = $this->fetch_page(array('alertsearch' => 'OX1 4LF elephant'));
55 55
         $this->assertContains('You have used a postcode and something else', $page);
56 56
         $this->assertNotContains('Did you mean to get alerts for when your MP', $page);
57 57
     }
Please login to merge, or discard this patch.
tests/SectionTest.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -20,13 +20,13 @@  discard block
 block discarded – undo
20 20
 
21 21
     public function testDebatesFront() {
22 22
         foreach ($this->types as $type) {
23
-            $this->fetch_page( array( 'type' => $type ) );
23
+            $this->fetch_page(array('type' => $type));
24 24
         }
25 25
     }
26 26
 
27 27
     public function testDebatesYear() {
28 28
         foreach ($this->types as $type) {
29
-            $page = $this->fetch_page( array( 'type' => $type, 'y' => '2014' ) );
29
+            $page = $this->fetch_page(array('type' => $type, 'y' => '2014'));
30 30
             $this->assertContains('<div class="calendar">', $page);
31 31
             $this->assertContains('January', $page);
32 32
             $this->assertRegExp('/<td colspan="2">&nbsp;<\/td><td[^>]*><a href="\/' . $type . '\/\?d=2014-01-01">1<\/a><\/td><td[^>]*><span>2<\/span><\/td>/', $page);
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
     public function testDebatesDay() {
37 37
         foreach ($this->types as $type) {
38
-            $page = $this->fetch_page( array( 'type' => $type, 'd' => '2014-01-01' ) );
38
+            $page = $this->fetch_page(array('type' => $type, 'd' => '2014-01-01'));
39 39
             $this->assertContains('Wednesday,  1 January 2014', $page);
40 40
             $this->assertContains('HeadingA', $page);
41 41
             if ($type == 'wrans') {
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
                 continue;
61 61
             }
62 62
 
63
-            $page = $this->fetch_page( array( 'type' => $type, 'id' => '2014-01-01b.1.1' ) );
63
+            $page = $this->fetch_page(array('type' => $type, 'id' => '2014-01-01b.1.1'));
64 64
             if ($type == 'wrans') {
65 65
                 $this->assertRegexp("#All .*?written answers on  1 Jan 2014#i", $page);
66 66
                 $this->assertContains("QuestionA", $page);
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 
73 73
     public function testDebatesSubheading() {
74 74
         foreach ($this->types as $type) {
75
-            $page = $this->fetch_page( array( 'type' => $type, 'id' => '2014-01-01b.1.2' ) );
75
+            $page = $this->fetch_page(array('type' => $type, 'id' => '2014-01-01b.1.2'));
76 76
             $this->assertContains("HeadingA", $page);
77 77
             if ($type == 'spwrans') {
78 78
                 $this->assertContains("QuestionA", $page);
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 
102 102
     public function testDebatesSpeech() {
103 103
         foreach ($this->types as $type) {
104
-            $page = $this->fetch_page( array( 'type' => $type, 'id' => '2014-01-01b.1.3' ) );
104
+            $page = $this->fetch_page(array('type' => $type, 'id' => '2014-01-01b.1.3'));
105 105
             if ($type == 'wrans' || $type == 'spwrans' || $type == 'wms') {
106 106
                 $this->assertRegexp("#Location: .*?/$type/\?id=2014-01-01b\.1\.2#", $page);
107 107
             } else {
@@ -125,13 +125,13 @@  discard block
 block discarded – undo
125 125
      * @group xapian
126 126
      */
127 127
     public function testGlossaryAndSearchHighlights() {
128
-            $page = $this->fetch_page( array( 'type' => 'lords', 's' => 'constituency', 'id' => '2014-02-02b.1.3' ) );
128
+            $page = $this->fetch_page(array('type' => 'lords', 's' => 'constituency', 'id' => '2014-02-02b.1.3'));
129 129
             $this->assertContains("constituency", $page);
130 130
             $this->assertContains("<span class=\"hi\"><a href=\"/glossary/?gl=1\" title=\"In a general election, each Constituency chooses an MP to represent them....\" class=\"glossary\">constituency</a></span>", $page);
131 131
     }
132 132
 
133 133
     public function testGidRedirect() {
134
-        $page = $this->fetch_page( array( 'type' => 'wrans', 'id' => '2014-01-01a.187335.h' ) );
134
+        $page = $this->fetch_page(array('type' => 'wrans', 'id' => '2014-01-01a.187335.h'));
135 135
         $this->assertRegexp("#Location: .*?/wrans/\?id=2014-01-01b\.1\.2#", $page);
136 136
     }
137 137
 }
Please login to merge, or discard this patch.
scripts/alertmailer.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -245,7 +245,7 @@
 block discarded – undo
245 245
     $data = $DEBATELIST->_get_data_by_search($args);
246 246
     $total_results = $data['info']['total_results'];
247 247
     $queries++;
248
-    mlog(", hits " . $total_results . ", time " . (getmicrotime()-$start) . "\n");
248
+    mlog(", hits " . $total_results . ", time " . (getmicrotime() - $start) . "\n");
249 249
 
250 250
     # Divisions
251 251
     if (preg_match('#^speaker:(\d+)$#', $criteria_raw, $m)) {
Please login to merge, or discard this patch.
www/docs/postcode/index.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 
15 15
 $pc = preg_replace('#[^a-z0-9]#i', '', $pc);
16 16
 if (!validate_postcode($pc)) {
17
-    twfy_debug ('MP', "Can't display an MP because the submitted postcode wasn't of a valid form.");
17
+    twfy_debug('MP', "Can't display an MP because the submitted postcode wasn't of a valid form.");
18 18
     postcode_error("Sorry, " . _htmlentities($pc) . " isn't a valid postcode");
19 19
 }
20 20
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
     exit;
61 61
 }
62 62
 
63
-function fetch_mp($pc, $constituencies, $house=null) {
63
+function fetch_mp($pc, $constituencies, $house = null) {
64 64
     global $THEUSER;
65 65
     $args = array('constituency' => $constituencies['WMC']);
66 66
     if ($house) {
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     }
69 69
     try {
70 70
         $MEMBER = new MEMBER($args);
71
-    } catch (MySociety\TheyWorkForYou\MemberException $e){
71
+    } catch (MySociety\TheyWorkForYou\MemberException $e) {
72 72
         postcode_error($e->getMessage());
73 73
     }
74 74
     if ($MEMBER->person_id()) {
Please login to merge, or discard this patch.
www/docs/mp/index.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
     }
140 140
     if ($pid) {
141 141
         $URL = new \MySociety\TheyWorkForYou\Url('search');
142
-        $URL->insert( array('pid'=>$pid, 'pop'=>1) );
142
+        $URL->insert(array('pid'=>$pid, 'pop'=>1));
143 143
         header('Location: ' . $URL->generate('none'));
144 144
         exit;
145 145
     }
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
     } elseif ($THEUSER->postcode_is_set()) {
190 190
         get_mp_by_user_postcode($THEUSER->postcode());
191 191
     } else {
192
-        twfy_debug ('MP', "We don't have any way of telling what MP to display");
192
+        twfy_debug('MP', "We don't have any way of telling what MP to display");
193 193
         throw new MySociety\TheyWorkForYou\MemberException('Sorry, but we can&rsquo;t tell which representative to display.');
194 194
     }
195 195
     if (!isset($MEMBER) || !$MEMBER->valid) {
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
     if (!$MEMBER->current_member(HOUSE_TYPE_SCOTLAND)) {
262 262
         $title .= ', former';
263 263
     }
264
-    $title .= ' MSP, '.$MEMBER->constituency();
264
+    $title .= ' MSP, ' . $MEMBER->constituency();
265 265
 }
266 266
 
267 267
 // Enhance title if this is a member of Welsh Parliament
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
     if (!$MEMBER->current_member(HOUSE_TYPE_WALES)) {
276 276
         $title .= ', former';
277 277
     }
278
-    $title .= ' MS, '.$MEMBER->constituency();
278
+    $title .= ' MS, ' . $MEMBER->constituency();
279 279
 }
280 280
 
281 281
 $known_for = '';
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 $data['eu_stance'] = $MEMBER->getEUStance();
346 346
 
347 347
 # People who are or were MPs and Lords potentially have voting records, except Sinn Fein MPs
348
-$data['has_voting_record'] = ( ($MEMBER->house(HOUSE_TYPE_COMMONS) && $MEMBER->party() != 'Sinn Féin') || $MEMBER->house(HOUSE_TYPE_LORDS) );
348
+$data['has_voting_record'] = (($MEMBER->house(HOUSE_TYPE_COMMONS) && $MEMBER->party() != 'Sinn Féin') || $MEMBER->house(HOUSE_TYPE_LORDS));
349 349
 # Everyone who is currently somewhere has email alert signup, apart from current Sinn Fein MPs who are not MLAs
350 350
 $data['has_email_alerts'] = ($MEMBER->current_member_anywhere() && !($MEMBER->current_member(HOUSE_TYPE_COMMONS) && $MEMBER->party() == 'Sinn Féin' && !$MEMBER->current_member(HOUSE_TYPE_NI)));
351 351
 $data['has_expenses'] = $data['leave_date'] > '2004-01-01';
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
         $divisions = new MySociety\TheyWorkForYou\Divisions($MEMBER);
386 386
         $policySummaries = $divisions->getMemberDivisionDetails();
387 387
 
388
-        $policyOptions = array( 'summaries' => $policySummaries);
388
+        $policyOptions = array('summaries' => $policySummaries);
389 389
 
390 390
         // Generate voting segments
391 391
         $set_descriptions = $policiesList->getSetDescriptions();
392
-        if ( $policy_set && array_key_exists($policy_set, $set_descriptions) ) {
392
+        if ($policy_set && array_key_exists($policy_set, $set_descriptions)) {
393 393
             $sets = array($policy_set);
394 394
             $data['og_image'] = $MEMBER->url(true) . "/policy_set_png?policy_set=" . $policy_set;
395 395
             $data['page_title'] = $set_descriptions[$policy_set] . ' ' . $title . ' - TheyWorkForYou';
@@ -431,15 +431,15 @@  discard block
 block discarded – undo
431 431
 
432 432
     case 'divisions':
433 433
         $policyID = get_http_var('policy');
434
-        if ( $policyID ) {
435
-            $policiesList = new MySociety\TheyWorkForYou\Policies( $policyID );
434
+        if ($policyID) {
435
+            $policiesList = new MySociety\TheyWorkForYou\Policies($policyID);
436 436
         } else {
437 437
             $policiesList = new MySociety\TheyWorkForYou\Policies;
438 438
         }
439
-        $positions = new MySociety\TheyWorkForYou\PolicyPositions( $policiesList, $MEMBER );
439
+        $positions = new MySociety\TheyWorkForYou\PolicyPositions($policiesList, $MEMBER);
440 440
         $divisions = new MySociety\TheyWorkForYou\Divisions($MEMBER, $positions, $policiesList);
441 441
 
442
-        if ( $policyID ) {
442
+        if ($policyID) {
443 443
             $data['policydivisions'] = $divisions->getMemberDivisionsForPolicy($policyID);
444 444
         } else {
445 445
             $data['policydivisions'] = $divisions->getAllMemberDivisionsByPolicy();
@@ -515,16 +515,16 @@  discard block
 block discarded – undo
515 515
     global $THEUSER;
516 516
     $pc = preg_replace('#[^a-z0-9]#i', '', $pc);
517 517
     if (!validate_postcode($pc)) {
518
-        twfy_debug ('MP', "Can't display an MP because the submitted postcode wasn't of a valid form.");
519
-        throw new MySociety\TheyWorkForYou\MemberException('Sorry, '._htmlentities($pc) .' isn&rsquo;t a valid postcode');
518
+        twfy_debug('MP', "Can't display an MP because the submitted postcode wasn't of a valid form.");
519
+        throw new MySociety\TheyWorkForYou\MemberException('Sorry, ' . _htmlentities($pc) . ' isn&rsquo;t a valid postcode');
520 520
     }
521
-    twfy_debug ('MP', "MP lookup by postcode");
521
+    twfy_debug('MP', "MP lookup by postcode");
522 522
     $constituency = strtolower(MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituency($pc));
523 523
     if ($constituency == "connection_timed_out") {
524 524
         throw new MySociety\TheyWorkForYou\MemberException('Sorry, we couldn&rsquo;t check your postcode right now, as our postcode lookup server is under quite a lot of load.');
525 525
     } elseif ($constituency == "") {
526
-        twfy_debug ('MP', "Can't display an MP, as submitted postcode didn't match a constituency");
527
-        throw new MySociety\TheyWorkForYou\MemberException('Sorry, '._htmlentities($pc) .' isn&rsquo;t a known postcode');
526
+        twfy_debug('MP', "Can't display an MP, as submitted postcode didn't match a constituency");
527
+        throw new MySociety\TheyWorkForYou\MemberException('Sorry, ' . _htmlentities($pc) . ' isn&rsquo;t a known postcode');
528 528
     } else {
529 529
         // Redirect to the canonical MP page, with a person id.
530 530
         $MEMBER = new MySociety\TheyWorkForYou\Member(array('constituency' => $constituency, 'house' => HOUSE_TYPE_COMMONS));
@@ -536,11 +536,11 @@  discard block
 block discarded – undo
536 536
     }
537 537
 }
538 538
 
539
-function get_person_by_name($name, $const='') {
539
+function get_person_by_name($name, $const = '') {
540 540
     $MEMBER = new MySociety\TheyWorkForYou\Member(array('name' => $name, 'constituency' => $const));
541 541
     // Edge case, only attempt further detection if this isn't the Queen.
542 542
     if (($name !== 'elizabeth the second' && $name !== 'prince charles') || $const) {
543
-        twfy_debug ('MP', 'Redirecting for MP found by name/constituency');
543
+        twfy_debug('MP', 'Redirecting for MP found by name/constituency');
544 544
         member_redirect($MEMBER);
545 545
     }
546 546
     return $MEMBER;
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
  * Redirect to the canonical page for a member.
578 578
  */
579 579
 
580
-function member_redirect (&$MEMBER, $code = 301, $pagetype = NULL) {
580
+function member_redirect(&$MEMBER, $code = 301, $pagetype = NULL) {
581 581
     // We come here after creating a MEMBER object by various methods.
582 582
     // Now we redirect to the canonical MP page, with a person_id.
583 583
     if ($MEMBER->person_id()) {
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
         } else {
597 597
             $pagetype = '';
598 598
         }
599
-        header('Location: ' . $url . $pagetype, true, $code );
599
+        header('Location: ' . $url . $pagetype, true, $code);
600 600
         exit;
601 601
     }
602 602
 }
@@ -624,7 +624,7 @@  discard block
 block discarded – undo
624 624
 
625 625
 function person_error_page($message) {
626 626
     global $this_page;
627
-    switch($this_page) {
627
+    switch ($this_page) {
628 628
         case 'mla':
629 629
             $rep = 'MLA';
630 630
             $SEARCHURL = '/postcode/';
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
  * Generate the summary of this person's held positions.
663 663
  */
664 664
 
665
-function person_summary_description ($MEMBER) {
665
+function person_summary_description($MEMBER) {
666 666
     $entered_house = $MEMBER->entered_house();
667 667
     $current_member = $MEMBER->current_member();
668 668
     $left_house = $MEMBER->left_house();
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
     }
679 679
     $desc = '';
680 680
     foreach ($MEMBER->houses() as $house) {
681
-        if ($house==HOUSE_TYPE_COMMONS && isset($entered_house[HOUSE_TYPE_LORDS])) {
681
+        if ($house == HOUSE_TYPE_COMMONS && isset($entered_house[HOUSE_TYPE_LORDS])) {
682 682
             # Same info is printed further down
683 683
             continue;
684 684
         }
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
  * @return string A HTML summary of this person's rebellion rate.
752 752
  */
753 753
 
754
-function person_rebellion_rate ($member) {
754
+function person_rebellion_rate($member) {
755 755
 
756 756
     // Rebellion string may be empty.
757 757
     $rebellion_string = '';
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
         $SEARCHENGINE = new \SEARCHENGINE($searchstring);
801 801
 
802 802
         $hansard = new MySociety\TheyWorkForYou\Hansard();
803
-        $args = array (
803
+        $args = array(
804 804
             's' => $searchstring,
805 805
             'p' => 1,
806 806
             'num' => 3,
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
     twfy_debug_timestamp();
816 816
 
817 817
     $MOREURL = new \MySociety\TheyWorkForYou\Url('search');
818
-    $MOREURL->insert( array('pid'=>$person_id, 'pop'=>1) );
818
+    $MOREURL->insert(array('pid'=>$person_id, 'pop'=>1));
819 819
 
820 820
     $out['more_href'] = $MOREURL->generate() . '#n4';
821 821
     $out['more_text'] = sprintf(gettext('More of %s’s recent appearances'), ucfirst($member->full_name()));
@@ -989,7 +989,7 @@  discard block
 block discarded – undo
989 989
         return;
990 990
     }
991 991
 
992
-    $reg = array( 'date' => '', 'data' => '<p>Nil</p>' );
992
+    $reg = array('date' => '', 'data' => '<p>Nil</p>');
993 993
     if (isset($extra_info['register_member_interests_date'])) {
994 994
         $reg['date'] = format_date($extra_info['register_member_interests_date'], SHORTDATEFORMAT);
995 995
     }
@@ -1079,8 +1079,8 @@  discard block
 block discarded – undo
1079 1079
         }
1080 1080
     }
1081 1081
 
1082
-    foreach($mreg as $reg) {
1083
-        $data['members'][] = array (
1082
+    foreach ($mreg as $reg) {
1083
+        $data['members'][] = array(
1084 1084
             'url' => '/' . $rep_type . '/?p=' . $reg['person_id'],
1085 1085
             'name' => $reg['given_name'] . ' ' . $reg['family_name']
1086 1086
         );
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
     # comparison which is Commons only
1150 1150
     $data['party_member_count'] = $party->getCurrentMemberCount(HOUSE_TYPE_COMMONS);
1151 1151
 
1152
-    $positions = new MySociety\TheyWorkForYou\PolicyPositions( $policiesList, $MEMBER, [
1152
+    $positions = new MySociety\TheyWorkForYou\PolicyPositions($policiesList, $MEMBER, [
1153 1153
         'summaries' => $policySummaries,
1154 1154
     ]);
1155 1155
     $policy_diffs = $MEMBER->getPartyPolicyDiffs($partyCohort, $policiesList, $positions, $only_diffs);
Please login to merge, or discard this patch.
www/includes/easyparliament/page.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
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,7 +32,7 @@  discard block
 block discarded – undo
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'] = '';
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
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 57
                 $text = "<a href=\"" . $LOGINURL->generate() . '">' . gettext('You’d better sign in!') . '</a>';
58 58
             } else {
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
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
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
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.
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
     }
135 135
 
136 136
 
137
-    public function stripe_end ($contents = array(), $extra = '') {
137
+    public function stripe_end($contents = array(), $extra = '') {
138 138
         // $contents is an array containing 0 or more hashes.
139 139
         // Each hash has two values, 'type' and 'content'.
140 140
         // 'Type' could be one of these:
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
     public function include_sidebar_template($sidebarname) {
238 238
         global $this_page, $DATA;
239 239
 
240
-            $sidebarpath = INCLUDESPATH.'easyparliament/sidebars/'.$sidebarname.'.php';
240
+            $sidebarpath = INCLUDESPATH . 'easyparliament/sidebars/' . $sidebarname . '.php';
241 241
 
242 242
             if (file_exists($sidebarpath)) {
243 243
                 include $sidebarpath;
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
     }
246 246
 
247 247
 
248
-    public function block_start($data=array()) {
248
+    public function block_start($data = array()) {
249 249
         // Starts a 'block' div, used mostly on the home page,
250 250
         // on the MP page, and in the sidebars.
251 251
         // $data is a hash like this:
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
         if (is_string($message)) {
393 393
             // Sometimes we're just sending a single line to this function
394 394
             // rather like the bigger array...
395
-            $message = array (
395
+            $message = array(
396 396
                 'text' => $message
397 397
             );
398 398
         }
@@ -400,13 +400,13 @@  discard block
 block discarded – undo
400 400
         // if the page has started then we're most likely in an old school page
401 401
         // so we should just print out the error, otherwise stick it in the error
402 402
         // global which will then be displayed by the header template
403
-        if ( $this->page_started() ) {
403
+        if ($this->page_started()) {
404 404
             $this->message($message, 'error');
405 405
         } else {
406
-            if ( !isset($page_errors) ) {
406
+            if (!isset($page_errors)) {
407 407
                 $page_errors = array();
408 408
             }
409
-            $page_errors[]  = $message;
409
+            $page_errors[] = $message;
410 410
         }
411 411
 
412 412
         if ($fatal) {
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
     }
424 424
 
425 425
 
426
-    public function message($message, $class='') {
426
+    public function message($message, $class = '') {
427 427
         // Generates a very simple but common page content.
428 428
         // Used for when a user logs out, or votes, or any simple thing
429 429
         // where there's a little message and probably a link elsewhere.
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
             if ($page_title != '') {
514 514
                 $page_title .= ': ';
515 515
             }
516
-            $page_title .= format_date ($info['date'], SHORTDATEFORMAT);
516
+            $page_title .= format_date($info['date'], SHORTDATEFORMAT);
517 517
         }
518 518
 
519 519
         if ($page_title != '') {
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
 
569 569
         if (isset($nextprev['up'])) {
570 570
 
571
-            $uplink = '<span class="up"><a href="' .  $nextprev['up']['url'] . '" title="' . $nextprev['up']['title'] . '">' . $nextprev['up']['body'] . '</a>';
571
+            $uplink = '<span class="up"><a href="' . $nextprev['up']['url'] . '" title="' . $nextprev['up']['title'] . '">' . $nextprev['up']['body'] . '</a>';
572 572
             if (get_http_var('s')) {
573 573
                 $URL = new \MySociety\TheyWorkForYou\Url($this_page);
574 574
                 $uplink .= '<br><a href="' . $URL->generate() . '">' . gettext('Remove highlighting') . '</a>';
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
             $next = $nextprev['next'];
584 584
 
585 585
             if (isset($next['url'])) {
586
-                $nextlink = '<a href="' .  $next['url'] . '" title="' . $next['title'] . '" class="linkbutton">' . $next['body'] . ' &raquo;</a>';
586
+                $nextlink = '<a href="' . $next['url'] . '" title="' . $next['title'] . '" class="linkbutton">' . $next['body'] . ' &raquo;</a>';
587 587
             } else {
588 588
                 $nextlink = $next['body'] . ' &raquo;';
589 589
             }
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
     }
601 601
 
602 602
 
603
-    public function search_form($value='') {
603
+    public function search_form($value = '') {
604 604
         global $SEARCHENGINE;
605 605
         // Search box on the search page.
606 606
         // If $value is set then it will be displayed in the form.
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
             }
631 631
 
632 632
         echo '<div class="mainsearchbox">';
633
-        if ($wtt<2) {
633
+        if ($wtt < 2) {
634 634
                 echo '<form action="', $URL->generate(), '" method="get">';
635 635
                 if (get_http_var('o')) {
636 636
                     echo '<input type="hidden" name="o" value="', _htmlentities(get_http_var('o')), '">';
@@ -663,16 +663,16 @@  discard block
 block discarded – undo
663 663
                     $ordering = 'd';
664 664
                 }
665 665
 
666
-                if ($ordering=='r') {
666
+                if ($ordering == 'r') {
667 667
                 print '<strong>' . gettext('Sorted by relevance') . '</strong>';
668 668
                 } else {
669 669
                 printf(gettext("<a href='%s'>Sort by relevance</a>"), $orderUrl->generate('html', array('o'=>'r')));
670 670
                 }
671 671
 
672 672
                 print "&nbsp;|&nbsp;";
673
-                if ($ordering=='d') {
673
+                if ($ordering == 'd') {
674 674
                 print '<strong>' . gettext('Sorted by date:') . ' ' . gettext('newest') . '</strong> / <a href="' . $orderUrl->generate('html', array('o'=>'o')) . '">' . gettext('oldest') . '</a>';
675
-                } elseif ($ordering=='o') {
675
+                } elseif ($ordering == 'o') {
676 676
                 print '<strong>' . gettext('Sorted by date:') . '</strong> <a href="' . $orderUrl->generate('html', array('o'=>'d')) . '">' . gettext('newest') . '</a> / <strong>' . gettext('oldest') . '</strong>';
677 677
                 } else {
678 678
                 print gettext("Sort by date:") . ' ';
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
                 }
686 686
 
687 687
             print "&nbsp;|&nbsp;";
688
-            if ($ordering=='p') {
688
+            if ($ordering == 'p') {
689 689
                 print '<strong>' . gettext('Use by person') . '</strong>';
690 690
             } else {
691 691
                 printf('<a href="%s">', $orderUrl->generate('html', array('o'=>'p')));
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
         echo '</form> </div>';
707 707
     }
708 708
 
709
-    public function login_form ($errors = array()) {
709
+    public function login_form($errors = array()) {
710 710
         // Used for /user/login/ and /user/prompt/
711 711
         // $errors is a hash of potential errors from a previous log in attempt.
712 712
         ?>
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
     public function glossary_atoz(&$GLOSSARY) {
810 810
     // Print out a nice list of lettered links to glossary pages
811 811
 
812
-        $letters = array ();
812
+        $letters = array();
813 813
 
814 814
         foreach ($GLOSSARY->alphabet as $letter => $eps) {
815 815
             // if we're writing out the current letter (list or item)
@@ -840,14 +840,14 @@  discard block
 block discarded – undo
840 840
                     <div class="letters">
841 841
                         <ul>
842 842
     <?php
843
-        for ($n=0; $n<13; $n++) {
843
+        for ($n = 0; $n < 13; $n++) {
844 844
             print $letters[$n];
845 845
         }
846 846
         ?>
847 847
                         </ul>
848 848
                         <ul>
849 849
     <?php
850
-        for ($n=13; $n<26; $n++) {
850
+        for ($n = 13; $n < 26; $n++) {
851 851
             print $letters[$n];
852 852
         }
853 853
         ?>
@@ -866,12 +866,12 @@  discard block
 block discarded – undo
866 866
 
867 867
         // add some extra controls for the administrators
868 868
         if ($this_page == "admin_glossary") {
869
-            print "<a id=\"gl".$term['glossary_id']."\"></a>";
869
+            print "<a id=\"gl" . $term['glossary_id'] . "\"></a>";
870 870
             print "<h3>" . $term['title'] . "</h3>";
871 871
             $URL = new \MySociety\TheyWorkForYou\Url('admin_glossary');
872 872
             $URL->insert(array("delete_confirm" => $term['glossary_id']));
873 873
             $delete_url = $URL->generate();
874
-            $admin_links = "<br><small><a href=\"".$delete_url."\">delete</a></small>";
874
+            $admin_links = "<br><small><a href=\"" . $delete_url . "\">delete</a></small>";
875 875
         } else {
876 876
             $admin_links = "";
877 877
         }
@@ -892,9 +892,9 @@  discard block
 block discarded – undo
892 892
             // Add a direct search link for current glossary item
893 893
             $URL = new \MySociety\TheyWorkForYou\Url('search');
894 894
             // remember to quote the term for phrase matching in search
895
-            $URL->insert(array('s' => '"'.$term['title'].'"'));
895
+            $URL->insert(array('s' => '"' . $term['title'] . '"'));
896 896
             $search_url = $URL->generate();
897
-            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']);
897
+            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']);
898 898
         }
899 899
     }
900 900
 
@@ -969,7 +969,7 @@  discard block
 block discarded – undo
969 969
 
970 970
             // Generate all the page links.
971 971
             $URL = new \MySociety\TheyWorkForYou\Url($this_page);
972
-            $URL->insert( array('wtt' => get_http_var('wtt')) );
972
+            $URL->insert(array('wtt' => get_http_var('wtt')));
973 973
             if (isset($pagedata['s'])) {
974 974
                 # XXX: Should be taken out in *one* place, not here + search_form etc.
975 975
                 $value = $pagedata['s'];
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
 
1108 1108
                 $body = trim_characters($report['body'], 0, 40);
1109 1109
 
1110
-                $tabledata['rows'][] = array (
1110
+                $tabledata['rows'][] = array(
1111 1111
                     _htmlentities($report['firstname'] . ' ' . $report['lastname']),
1112 1112
                     _htmlentities($body),
1113 1113
                     $report['reported'],
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
         // Returns HTML suitable for putting in the sidebar on Admin pages.
1190 1190
         global $this_page, $DATA;
1191 1191
 
1192
-        $pages = array ('admin_home',
1192
+        $pages = array('admin_home',
1193 1193
                 'admin_comments', 'admin_searchlogs', 'admin_popularsearches', 'admin_failedsearches',
1194 1194
                 'alert_stats', 'admin_statistics', 'admin_reportstats',
1195 1195
                 'admin_commentreports', 'admin_glossary', 'admin_glossary_pending', 'admin_badusers',
Please login to merge, or discard this patch.
www/includes/easyparliament/hansardlist.php 2 patches
Upper-Lower-Casing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 
562 562
             // The '!= NULL' bit is needed otherwise I was getting errors
563 563
             // when displaying the first day of debates.
564
-            if ($q && $q['hdate'] != NULL) {
564
+            if ($q && $q['hdate'] != null) {
565 565
 
566 566
                 $URL->insert( array( 'd' => $q['hdate'] ) );
567 567
 
@@ -1410,7 +1410,7 @@  discard block
 block discarded – undo
1410 1410
                             WHERE	major = :major",
1411 1411
                 array(':major' => $this->major))->first();
1412 1412
 
1413
-            if ($q && $q['hdate'] != NULL) {
1413
+            if ($q && $q['hdate'] != null) {
1414 1414
                 $recentdate = $q['hdate'];
1415 1415
             } else {
1416 1416
                 $PAGE->error_message("Couldn't find the most recent date");
@@ -1725,7 +1725,7 @@  discard block
 block discarded – undo
1725 1725
         }
1726 1726
 
1727 1727
         // Finally, do the query!
1728
-        $q = $this->db->query ("SELECT $fields
1728
+        $q = $this->db->query ("select $fields
1729 1729
                         FROM 	hansard
1730 1730
                         $join
1731 1731
                         WHERE $where
Please login to merge, or discard this patch.
Spacing   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-include_once INCLUDESPATH."easyparliament/searchengine.php";
4
-include_once INCLUDESPATH."easyparliament/searchlog.php";
3
+include_once INCLUDESPATH . "easyparliament/searchengine.php";
4
+include_once INCLUDESPATH . "easyparliament/searchlog.php";
5 5
 
6 6
 /*
7 7
 
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 class HANSARDLIST {
54 54
     // This will be used to cache information about speakers on this page
55 55
     // so we don't have to keep fetching the same data from the DB.
56
-    public $speakers = array ();
56
+    public $speakers = array();
57 57
     /*
58 58
     $this->speakers[ $person_id ] = array (
59 59
         "name" => $name,
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 
67 67
     // This will be used to cache mappings from epobject_id to gid,
68 68
     // so we don't have to continually fetch the same data in get_hansard_data().
69
-    public $epobjectid_to_gid = array ();
69
+    public $epobjectid_to_gid = array();
70 70
     /*
71 71
     $this->epobjectid_to_gid[ $epobject_id ] => $gid;
72 72
     */
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 
115 115
 
116 116
 
117
-    public function display ($view, $args=array(), $format='html') {
117
+    public function display($view, $args = array(), $format = 'html') {
118 118
 
119 119
         // $view is what we're viewing by:
120 120
         // 	'gid' is the gid of a hansard object,
@@ -142,17 +142,17 @@  discard block
 block discarded – undo
142 142
             return false;
143 143
         }
144 144
 
145
-        $validviews = array ('calendar', 'date', 'gid', 'person', 'search', 'recent', 'recent_mostvotes', 'biggest_debates', 'recent_wrans', 'recent_wms', 'column', 'mp', 'bill', 'session', 'recent_debates', 'recent_pbc_debates', 'featured_gid');
145
+        $validviews = array('calendar', 'date', 'gid', 'person', 'search', 'recent', 'recent_mostvotes', 'biggest_debates', 'recent_wrans', 'recent_wms', 'column', 'mp', 'bill', 'session', 'recent_debates', 'recent_pbc_debates', 'featured_gid');
146 146
         if (in_array($view, $validviews)) {
147 147
 
148 148
             // What function do we call for this view?
149
-            $function = '_get_data_by_'.$view;
149
+            $function = '_get_data_by_' . $view;
150 150
             // Get all the data that's to be rendered.
151 151
             $data = $this->$function($args);
152 152
 
153 153
         } else {
154 154
             // Don't have a valid $view.
155
-            $PAGE->error_message ("You haven't specified a view type.");
155
+            $PAGE->error_message("You haven't specified a view type.");
156 156
             return false;
157 157
         }
158 158
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 
174 174
 
175 175
 
176
-    public function render($view, $data, $format='html') {
176
+    public function render($view, $data, $format = 'html') {
177 177
         // Once we have the data that's to be rendered,
178 178
         // include the template.
179 179
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
             return $data;
183 183
         }
184 184
 
185
-        include (INCLUDESPATH."easyparliament/templates/$format/hansard_$view" . ".php");
185
+        include (INCLUDESPATH . "easyparliament/templates/$format/hansard_$view" . ".php");
186 186
         return true;
187 187
 
188 188
     }
@@ -227,13 +227,13 @@  discard block
 block discarded – undo
227 227
             $hdate = $q['hdate'];
228 228
             if ($hdate) {
229 229
                 $URL = new \MySociety\TheyWorkForYou\Url($this->listpage);
230
-                $URL->insert( array('d'=>$hdate) );
230
+                $URL->insert(array('d'=>$hdate));
231 231
 
232 232
                 // Work out a timestamp which is handy for comparing to now.
233 233
                 list($year, $month, $date) = explode('-', $hdate);
234
-                $timestamp = gmmktime (0, 0, 0, $month, $date, $year);
234
+                $timestamp = gmmktime(0, 0, 0, $month, $date, $year);
235 235
 
236
-                $data = array (
236
+                $data = array(
237 237
                     'hdate'		=> $hdate,
238 238
                     'timestamp'	=> $timestamp,
239 239
                     'listurl'	=> $URL->generate()
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
         // Pass it an array of data about an item and it will return an
268 268
         // array of data about the item's section heading.
269 269
 
270
-        twfy_debug (get_class($this), "getting an item's section");
270
+        twfy_debug(get_class($this), "getting an item's section");
271 271
 
272 272
         if ($itemdata['htype'] != '10') {
273 273
 
@@ -276,11 +276,11 @@  discard block
 block discarded – undo
276 276
             // so get the section info above this item.
277 277
 
278 278
             // For getting hansard data.
279
-            $input = array (
280
-                'amount' => array (
279
+            $input = array(
280
+                'amount' => array(
281 281
                     'body' => true
282 282
                 ),
283
-                'where' => array (
283
+                'where' => array(
284 284
                     'hansard.epobject_id=' => $itemdata['section_id']
285 285
                 )
286 286
             );
@@ -307,21 +307,21 @@  discard block
 block discarded – undo
307 307
         // Pass it an array of data about an item and it will return an
308 308
         // array of data about the item's subsection heading.
309 309
 
310
-        twfy_debug (get_class($this), "getting an item's subsection");
310
+        twfy_debug(get_class($this), "getting an item's subsection");
311 311
 
312 312
         // What we return.
313
-        $subsectiondata = array ();
313
+        $subsectiondata = array();
314 314
 
315 315
         if ($itemdata['htype'] == '12' || $itemdata['htype'] == '13' || $itemdata['htype'] == '14') {
316 316
             // This item is a speech or procedural, so get the
317 317
             // subsection info above this item.
318 318
 
319 319
             // For getting hansard data.
320
-            $input = array (
321
-                'amount' => array (
320
+            $input = array(
321
+                'amount' => array(
322 322
                     'body' => true
323 323
                 ),
324
-                'where' => array (
324
+                'where' => array(
325 325
                     'hansard.epobject_id=' => $itemdata['subsection_id']
326 326
                 )
327 327
             );
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
         // Pass it an array of item info, of a section/subsection, and this will return
350 350
         // data for the next/prev items.
351 351
 
352
-        twfy_debug (get_class($this), "getting next/prev items");
352
+        twfy_debug(get_class($this), "getting next/prev items");
353 353
 
354 354
         // What we return.
355 355
         $nextprevdata = array();
@@ -415,8 +415,8 @@  discard block
 block discarded – undo
415 415
             $wherearr['hansard.epobject_id='] = $prev_item_id;
416 416
 
417 417
             // For getting hansard data.
418
-            $input = array (
419
-                'amount' => array (
418
+            $input = array(
419
+                'amount' => array(
420 420
                     'body' => true,
421 421
                     'speaker' => true
422 422
                 ),
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
                 if ($itemdata['htype'] == '10' || $itemdata['htype'] == '11') {
432 432
                     // Linking to the prev (sub)section.
433 433
                     $thing = $hansardmajors[$this->major]['singular'];
434
-                    $nextprevdata['prev'] = array (
434
+                    $nextprevdata['prev'] = array(
435 435
                         'body'		=> sprintf(gettext("Previous %s"), $thing),
436 436
                         'url'		=> $prevdata[0]['listurl'],
437 437
                         'title'		=> $prevdata[0]['body']
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
                     } else {
445 445
                         $title = '';
446 446
                     }
447
-                    $nextprevdata['prev'] = array (
447
+                    $nextprevdata['prev'] = array(
448 448
                         'body'		=> gettext('Previous speaker'),
449 449
                         'url'		=> $prevdata[0]['commentsurl'],
450 450
                         'title'		=> $title
@@ -460,8 +460,8 @@  discard block
 block discarded – undo
460 460
             $wherearr['hansard.epobject_id='] = $next_item_id;
461 461
 
462 462
             // For getting hansard data.
463
-            $input = array (
464
-                'amount' => array (
463
+            $input = array(
464
+                'amount' => array(
465 465
                     'body' => true,
466 466
                     'speaker' => true
467 467
                 ),
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
                 if ($itemdata['htype'] == '10' || $itemdata['htype'] == '11') {
476 476
                     // Linking to the next (sub)section.
477 477
                     $thing = $hansardmajors[$this->major]['singular'];
478
-                    $nextprevdata['next'] = array (
478
+                    $nextprevdata['next'] = array(
479 479
                         'body'		=> sprintf(gettext("Next %s"), $thing),
480 480
                         'url'		=> $nextdata[0]['listurl'],
481 481
                         'title'		=> $nextdata[0]['body']
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
                     } else {
489 489
                         $title = '';
490 490
                     }
491
-                    $nextprevdata['next'] = array (
491
+                    $nextprevdata['next'] = array(
492 492
                         'body'		=> gettext('Next speaker'),
493 493
                         'url'		=> $nextdata[0]['commentsurl'],
494 494
                         'title'		=> $title
@@ -532,14 +532,14 @@  discard block
 block discarded – undo
532 532
         // containing the next/prev dates that contain items from
533 533
         // $this->major of hansard object.
534 534
 
535
-        twfy_debug (get_class($this), "getting next/prev dates");
535
+        twfy_debug(get_class($this), "getting next/prev dates");
536 536
 
537 537
         // What we return.
538
-        $nextprevdata = array ();
538
+        $nextprevdata = array();
539 539
 
540 540
         $URL = new \MySociety\TheyWorkForYou\Url($this->listpage);
541 541
 
542
-        $looper = array ("next", "prev");
542
+        $looper = array("next", "prev");
543 543
 
544 544
         foreach ($looper as $n => $nextorprev) {
545 545
 
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
             // when displaying the first day of debates.
564 564
             if ($q && $q['hdate'] != NULL) {
565 565
 
566
-                $URL->insert( array( 'd' => $q['hdate'] ) );
566
+                $URL->insert(array('d' => $q['hdate']));
567 567
 
568 568
                 if ($nextorprev == 'next') {
569 569
                     $body = gettext('Next day');
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
 
574 574
                 $title = format_date($q['hdate'], SHORTDATEFORMAT);
575 575
 
576
-                $nextprevdata[$nextorprev] = array (
576
+                $nextprevdata[$nextorprev] = array(
577 577
                     'hdate' => $q['hdate'],
578 578
                     'url' => $URL->generate(),
579 579
                     'body' => $body,
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
         $thing = $hansardmajors[$this->major]['plural'];
588 588
         $URL->insert(array('y'=>$year));
589 589
 
590
-        $nextprevdata['up'] = array (
590
+        $nextprevdata['up'] = array(
591 591
             'body' 	=> sprintf(gettext("All of %s’s %s"), $year, $thing),
592 592
             'title'	=> '',
593 593
             'url' 	=> $URL->generate()
@@ -608,19 +608,19 @@  discard block
 block discarded – undo
608 608
         if (isset($args['date'])) {
609 609
             $date = $args['date'];
610 610
         } else {
611
-            $PAGE->error_message ("Sorry, we don't have a date.");
611
+            $PAGE->error_message("Sorry, we don't have a date.");
612 612
             return false;
613 613
         }
614 614
 
615 615
         if (!preg_match("/^(\d\d\d\d)-(\d{1,2})-(\d{1,2})$/", $date, $matches)) {
616
-            $PAGE->error_message ("Sorry, '" . _htmlentities($date) . "' isn't of the right format (YYYY-MM-DD).");
616
+            $PAGE->error_message("Sorry, '" . _htmlentities($date) . "' isn't of the right format (YYYY-MM-DD).");
617 617
             return false;
618 618
         }
619 619
 
620 620
         list(, $year, $month, $day) = $matches;
621 621
 
622 622
         if (!checkdate($month, $day, $year)) {
623
-            $PAGE->error_message ("Sorry, '" . _htmlentities($date) . "' isn't a valid date.");
623
+            $PAGE->error_message("Sorry, '" . _htmlentities($date) . "' isn't a valid date.");
624 624
             return false;
625 625
         }
626 626
 
@@ -638,29 +638,29 @@  discard block
 block discarded – undo
638 638
         global $PAGE;
639 639
 
640 640
         if (!isset($args['gid']) && $args['gid'] == '') {
641
-            $PAGE->error_message ("Sorry, we don't have an item gid.");
641
+            $PAGE->error_message("Sorry, we don't have an item gid.");
642 642
             return false;
643 643
         }
644 644
 
645 645
 
646 646
         // Get all the data just for this epobject_id.
647
-        $input = array (
648
-            'amount' => array (
647
+        $input = array(
648
+            'amount' => array(
649 649
                 'body' => true,
650 650
                 'speaker' => true,
651 651
                 'comment' => true,
652 652
                 'votes' => true
653 653
             ),
654
-            'where' => array (
654
+            'where' => array(
655 655
                 // Need to add the 'uk.org.publicwhip/debate/' or whatever on before
656 656
                 // looking in the DB.
657 657
                 'gid=' => $this->gidprefix . $args['gid']
658 658
             )
659 659
         );
660 660
 
661
-        twfy_debug (get_class($this), "looking for redirected gid");
661
+        twfy_debug(get_class($this), "looking for redirected gid");
662 662
         $gid = $this->gidprefix . $args['gid'];
663
-        $q = $this->db->query ("SELECT gid_to FROM gidredirect WHERE gid_from = :gid", array(':gid' => $gid))->first();
663
+        $q = $this->db->query("SELECT gid_to FROM gidredirect WHERE gid_from = :gid", array(':gid' => $gid))->first();
664 664
         if (!$q) {
665 665
             $itemdata = $this->_get_hansard_data($input);
666 666
         } else {
@@ -668,10 +668,10 @@  discard block
 block discarded – undo
668 668
                 $gid = $q['gid_to'];
669 669
                 $q = $this->db->query("SELECT gid_to FROM gidredirect WHERE gid_from = :gid", array(':gid' => $gid))->first();
670 670
             } while ($q);
671
-            twfy_debug (get_class($this), "found redirected gid $gid" );
671
+            twfy_debug(get_class($this), "found redirected gid $gid");
672 672
             $input['where'] = array('gid=' => $gid);
673 673
             $itemdata = $this->_get_hansard_data($input);
674
-            if (count($itemdata) > 0 ) {
674
+            if (count($itemdata) > 0) {
675 675
                 throw new RedirectException(fix_gid_from_db($gid));
676 676
             }
677 677
         }
@@ -685,9 +685,9 @@  discard block
 block discarded – undo
685 685
             $this->check_gid_change($args['gid'], 'a', '');
686 686
 
687 687
             if (substr($args['gid'], -1) == 'L') {
688
-                $letts = array('a','b','c','d','e');
689
-                for ($i=0; $i<4; $i++) {
690
-                    $this->check_gid_change($args['gid'], $letts[$i], $letts[$i+1]);
688
+                $letts = array('a', 'b', 'c', 'd', 'e');
689
+                for ($i = 0; $i < 4; $i++) {
690
+                    $this->check_gid_change($args['gid'], $letts[$i], $letts[$i + 1]);
691 691
                 }
692 692
             }
693 693
 
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
             #	$u = $q['source_url'];
721 721
             #	$u = '<br><a href="'. $u . '">' . $u . '</a>';
722 722
             #}
723
-            $PAGE->error_message ("Sorry, there is no Hansard object with a gid of '" . _htmlentities($args['gid']) . "'.");
723
+            $PAGE->error_message("Sorry, there is no Hansard object with a gid of '" . _htmlentities($args['gid']) . "'.");
724 724
             return false;
725 725
         }
726 726
 
@@ -729,8 +729,8 @@  discard block
 block discarded – undo
729 729
     }
730 730
 
731 731
     private function check_gid_change($gid, $from, $to) {
732
-        $input = array (
733
-            'amount' => array (
732
+        $input = array(
733
+            'amount' => array(
734 734
                 'body' => true,
735 735
                 'speaker' => true,
736 736
                 'comment' => true,
@@ -754,10 +754,10 @@  discard block
 block discarded – undo
754 754
 
755 755
         global $DATA, $this_page;
756 756
 
757
-        twfy_debug (get_class($this), "getting data by date");
757
+        twfy_debug(get_class($this), "getting data by date");
758 758
 
759 759
         // Where we'll put all the data we want to render.
760
-        $data = array ();
760
+        $data = array();
761 761
 
762 762
         $date = $this->_validate_date($args);
763 763
 
@@ -771,13 +771,13 @@  discard block
 block discarded – undo
771 771
 
772 772
             // Get all the sections for this date.
773 773
             // Then for each of those we'll get the subsections and rows.
774
-            $input = array (
775
-                'amount' => array (
774
+            $input = array(
775
+                'amount' => array(
776 776
                     'body' => true,
777 777
                     'comment' => true,
778 778
                     'excerpt' => true
779 779
                 ),
780
-                'where' => array (
780
+                'where' => array(
781 781
                     'hdate=' => "$date",
782 782
                     'htype=' => '10',
783 783
                     'major=' => $this->major
@@ -793,20 +793,20 @@  discard block
 block discarded – undo
793 793
                 $data['rows'] = array();
794 794
 
795 795
                 $num_sections = count($sections);
796
-                for ($n=0; $n<$num_sections; $n++) {
796
+                for ($n = 0; $n < $num_sections; $n++) {
797 797
                     // For each section on this date, get the subsections within it.
798 798
 
799 799
                     // Get all the section data.
800 800
                     $sectionrow = $this->_get_section($sections[$n]);
801 801
 
802 802
                     // Get the subsections within the section.
803
-                    $input = array (
804
-                        'amount' => array (
803
+                    $input = array(
804
+                        'amount' => array(
805 805
                             'body' => true,
806 806
                             'comment' => true,
807 807
                             'excerpt' => true
808 808
                         ),
809
-                        'where' => array (
809
+                        'where' => array(
810 810
                             'section_id='	=> $sections[$n]['epobject_id'],
811 811
                             'htype='		=> '11',
812 812
                             'major='		=> $this->major
@@ -817,10 +817,10 @@  discard block
 block discarded – undo
817 817
                     $rows = $this->_get_hansard_data($input);
818 818
 
819 819
                     // Put the section at the top of the rows array.
820
-                    array_unshift ($rows, $sectionrow);
820
+                    array_unshift($rows, $sectionrow);
821 821
 
822 822
                     // Add the section heading and the subsections to the full list.
823
-                    $data['rows'] = array_merge ($data['rows'], $rows);
823
+                    $data['rows'] = array_merge($data['rows'], $rows);
824 824
                 }
825 825
             }
826 826
 
@@ -856,9 +856,9 @@  discard block
 block discarded – undo
856 856
             $major = '';
857 857
         }
858 858
 
859
-        $data = array ();
859
+        $data = array();
860 860
 
861
-        $q = $this->db->query ("SELECT DISTINCT(hdate)
861
+        $q = $this->db->query("SELECT DISTINCT(hdate)
862 862
                         FROM 	hansard
863 863
                         $major
864 864
                         ORDER BY hdate DESC
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
         $data = array();
892 892
 
893 893
         if (!isset($args['person_id'])) {
894
-            $PAGE->error_message ("Sorry, we need a valid person ID.");
894
+            $PAGE->error_message("Sorry, we need a valid person ID.");
895 895
             return $data;
896 896
         }
897 897
 
@@ -931,7 +931,7 @@  discard block
 block discarded – undo
931 931
 
932 932
         $speeches = array();
933 933
         foreach ($q as $row) {
934
-            $speech = array (
934
+            $speech = array(
935 935
                 'subsection_id' => $row['subsection_id'],
936 936
                 'section_id' => $row['section_id'],
937 937
                 'htype' => $row['htype'],
@@ -948,7 +948,7 @@  discard block
 block discarded – undo
948 948
             // Cache parent id to speed up _get_listurl
949 949
             $this->epobjectid_to_gid[$row['subsection_id']] = fix_gid_from_db($row['gid_subsection']);
950 950
 
951
-            $url_args = array ('p' => $row['person_id']);
951
+            $url_args = array('p' => $row['person_id']);
952 952
             $speech['listurl'] = $this->_get_listurl($speech, $url_args);
953 953
             $speeches[] = $speech;
954 954
         }
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
         if (count($speeches) > 0) {
957 957
             // Get the subsection texts.
958 958
             $num_speeches = count($speeches);
959
-            for ($n=0; $n<$num_speeches; $n++) {
959
+            for ($n = 0; $n < $num_speeches; $n++) {
960 960
                 $thing = $hansardmajors[$speeches[$n]['major']]['title'];
961 961
                 // Add the parent's body on...
962 962
                 $speeches[$n]['parent']['body'] = $speeches[$n]['body_section'] . ' | ' . $thing;
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
             // eg, by doing filter_user_input($s, 'strict');
988 988
             $searchstring = $args['s'];
989 989
         } else {
990
-            if ( isset($args['exceptions']) ) {
990
+            if (isset($args['exceptions'])) {
991 991
                 throw new \Exception('No search string provided.');
992 992
             } else {
993 993
                 $PAGE->error_message("No search string");
@@ -996,14 +996,14 @@  discard block
 block discarded – undo
996 996
         }
997 997
 
998 998
         // What we'll return.
999
-        $data = array ();
999
+        $data = array();
1000 1000
 
1001 1001
         $data['info']['s'] = $args['s'];
1002 1002
 
1003 1003
         // Allows us to specify how many results we want
1004 1004
         // Mainly for glossary term adding
1005 1005
         if (isset($args['num']) && is_numeric($args['num'])) {
1006
-            $results_per_page = (int)$args['num'];
1006
+            $results_per_page = (int) $args['num'];
1007 1007
         } else {
1008 1008
             $results_per_page = 20;
1009 1009
         }
@@ -1031,20 +1031,20 @@  discard block
 block discarded – undo
1031 1031
         global $SEARCHENGINE;
1032 1032
 
1033 1033
         // For Xapian's equivalent of an SQL LIMIT clause.
1034
-        $first_result = ($page-1) * $results_per_page;
1034
+        $first_result = ($page - 1) * $results_per_page;
1035 1035
         $data['info']['first_result'] = $first_result + 1; // Take account of LIMIT's 0 base.
1036 1036
 
1037 1037
         // Get the gids from Xapian
1038 1038
         $sort_order = 'date';
1039 1039
         if (isset($args['o'])) {
1040
-            if ($args['o']=='d') {
1040
+            if ($args['o'] == 'd') {
1041 1041
                 $sort_order = 'newest';
1042 1042
             }
1043
-            if ($args['o']=='o') {
1043
+            if ($args['o'] == 'o') {
1044 1044
                 $sort_order = 'oldest';
1045
-            } elseif ($args['o']=='c') {
1045
+            } elseif ($args['o'] == 'c') {
1046 1046
                 $sort_order = 'created';
1047
-            } elseif ($args['o']=='r') {
1047
+            } elseif ($args['o'] == 'r') {
1048 1048
                 $sort_order = 'relevance';
1049 1049
             }
1050 1050
         }
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
 
1057 1057
         // Log this query so we can improve them - if it wasn't a "popular
1058 1058
         // query" link
1059
-        if (! isset($args['pop']) or $args['pop'] != 1) {
1059
+        if (!isset($args['pop']) or $args['pop'] != 1) {
1060 1060
             global $SEARCHLOG;
1061 1061
             $SEARCHLOG->add(
1062 1062
             array('query' => $searchstring,
@@ -1071,7 +1071,7 @@  discard block
 block discarded – undo
1071 1071
 
1072 1072
         $SEARCHENGINE->run_search($first_result, $results_per_page, $sort_order);
1073 1073
         $gids = $SEARCHENGINE->get_gids();
1074
-        if ($sort_order=='created') {
1074
+        if ($sort_order == 'created') {
1075 1075
             $createds = $SEARCHENGINE->get_createds();
1076 1076
         }
1077 1077
         $relevances = $SEARCHENGINE->get_relevances();
@@ -1087,13 +1087,13 @@  discard block
 block discarded – undo
1087 1087
 
1088 1088
         // Cycle through each result, munge the data, get more, and put it all in $data.
1089 1089
         $num_gids = count($gids);
1090
-        for ($n=0; $n<$num_gids; $n++) {
1090
+        for ($n = 0; $n < $num_gids; $n++) {
1091 1091
             $gid = $gids[$n];
1092 1092
             $relevancy = $relevances[$n];
1093 1093
             $collapsed = $SEARCHENGINE->collapsed[$n];
1094
-            if ($sort_order=='created') {
1094
+            if ($sort_order == 'created') {
1095 1095
                 #$created = substr($createds[$n], 0, strpos($createds[$n], ':'));
1096
-                if ($createds[$n]<$args['threshold']) {
1096
+                if ($createds[$n] < $args['threshold']) {
1097 1097
                     $data['info']['total_results'] = $n;
1098 1098
                     break;
1099 1099
                 }
@@ -1162,7 +1162,7 @@  discard block
 block discarded – undo
1162 1162
                 , array(':gid' => $gid));
1163 1163
 
1164 1164
                 if ($q->rows() > 1) {
1165
-                    if ( $isset($args['exceptions']) ) {
1165
+                    if ($isset($args['exceptions'])) {
1166 1166
                         throw new \Exception("Got more than one row getting data for $gid.");
1167 1167
                     } else {
1168 1168
                         $PAGE->error_message("Got more than one row getting data for $gid");
@@ -1183,7 +1183,7 @@  discard block
 block discarded – undo
1183 1183
                 //////////////////////////
1184 1184
                 // 2. Create the URL to link to this bit of text.
1185 1185
 
1186
-                $id_data = array (
1186
+                $id_data = array(
1187 1187
                     'major'            => $itemdata['major'],
1188 1188
                     'minor'            => $itemdata['minor'],
1189 1189
                     'htype'         => $itemdata['htype'],
@@ -1194,7 +1194,7 @@  discard block
 block discarded – undo
1194 1194
 
1195 1195
                 // We append the query onto the end of the URL as variable 's'
1196 1196
                 // so we can highlight them on the debate/wrans list page.
1197
-                $url_args = array ('s' => $searchstring);
1197
+                $url_args = array('s' => $searchstring);
1198 1198
 
1199 1199
                 $itemdata['listurl'] = $this->_get_listurl($id_data, $url_args, $encode);
1200 1200
 
@@ -1247,14 +1247,14 @@  discard block
 block discarded – undo
1247 1247
                     } else {
1248 1248
                         $listurl = '';
1249 1249
                     }
1250
-                    $itemdata['parent'] = array (
1250
+                    $itemdata['parent'] = array(
1251 1251
                         'body' => $body,
1252 1252
                         'listurl' => $listurl
1253 1253
                     );
1254 1254
                     if ($itemdata['htype'] == 11) {
1255 1255
                         # Search result was a subsection heading; fetch the first entry
1256 1256
                         # from the wrans/wms to show under the heading
1257
-                        $input = array (
1257
+                        $input = array(
1258 1258
                             'amount' => array(
1259 1259
                                 'body' => true,
1260 1260
                                 'speaker' => true
@@ -1313,7 +1313,7 @@  discard block
 block discarded – undo
1313 1313
         $extract = trim_characters(html_entity_decode($extract), $startpos, $length_of_extract);
1314 1314
 
1315 1315
         // Highlight search words
1316
-        $extract = mb_encode_numericentity( htmlentities($extract, ENT_QUOTES, 'UTF-8'), [0x80, 0x10FFFF, 0, ~0], 'UTF-8');
1316
+        $extract = mb_encode_numericentity(htmlentities($extract, ENT_QUOTES, 'UTF-8'), [0x80, 0x10FFFF, 0, ~0], 'UTF-8');
1317 1317
         $extract = $SEARCHENGINE->highlight($extract);
1318 1318
 
1319 1319
         return $extract;
@@ -1498,7 +1498,7 @@  discard block
 block discarded – undo
1498 1498
 
1499 1499
         $params[':major'] = $this->major;
1500 1500
         $params[':firstdate'] = $firstyear . '-' . $firstmonth . '-01';
1501
-        $q =  $this->db->query("SELECT 	DISTINCT(hdate) AS hdate
1501
+        $q = $this->db->query("SELECT 	DISTINCT(hdate) AS hdate
1502 1502
                         FROM		hansard
1503 1503
                         WHERE		major = :major
1504 1504
                         AND			hdate >= :firstdate
@@ -1564,9 +1564,9 @@  discard block
 block discarded – undo
1564 1564
             if ($action == 'recentyear') {
1565 1565
                 // Assuming there will be a previous year!
1566 1566
 
1567
-                $YEARURL->insert(array('y'=> $firstyear-1));
1567
+                $YEARURL->insert(array('y'=> $firstyear - 1));
1568 1568
 
1569
-                $nextprev['prev'] = array (
1569
+                $nextprev['prev'] = array(
1570 1570
                     'body' => 'Previous year',
1571 1571
                     'title' => $firstyear - 1,
1572 1572
                     'url' => $YEARURL->generate()
@@ -1575,8 +1575,8 @@  discard block
 block discarded – undo
1575 1575
             } else {
1576 1576
                 // action is 'year'.
1577 1577
 
1578
-                $nextprev['prev'] = array ('body' => 'Previous year');
1579
-                $nextprev['next'] = array ('body' => 'Next year');
1578
+                $nextprev['prev'] = array('body' => 'Previous year');
1579
+                $nextprev['next'] = array('body' => 'Next year');
1580 1580
 
1581 1581
                 $q = $this->db->query("SELECT DATE_FORMAT(hdate, '%Y') AS year
1582 1582
                             FROM hansard WHERE major = :major
@@ -1665,14 +1665,14 @@  discard block
 block discarded – undo
1665 1665
         // $input['limit'] as a string for the $limit clause, eg '21,20'.
1666 1666
 
1667 1667
         $amount 		= isset($input['amount']) ? $input['amount'] : array();
1668
-        $wherearr 		= isset($input['where']) ? $input['where'] : array();
1668
+        $wherearr = isset($input['where']) ? $input['where'] : array();
1669 1669
         $order 			= isset($input['order']) ? $input['order'] : '';
1670 1670
         $limit 			= isset($input['limit']) ? $input['limit'] : '';
1671 1671
 
1672 1672
 
1673 1673
         // The fields to fetch from db. 'table' => array ('field1', 'field2').
1674
-        $fieldsarr = array (
1675
-            'hansard' => array ('epobject_id', 'htype', 'gid', 'hpos', 'section_id', 'subsection_id', 'hdate', 'htime', 'source_url', 'major', 'minor', 'colnum')
1674
+        $fieldsarr = array(
1675
+            'hansard' => array('epobject_id', 'htype', 'gid', 'hpos', 'section_id', 'subsection_id', 'hdate', 'htime', 'source_url', 'major', 'minor', 'colnum')
1676 1676
         );
1677 1677
 
1678 1678
         $params = array();
@@ -1684,23 +1684,23 @@  discard block
 block discarded – undo
1684 1684
         if ((isset($amount['body']) && $amount['body'] == true) ||
1685 1685
             (isset($amount['comment']) && $amount['comment'] == true)
1686 1686
             ) {
1687
-            $fieldsarr['epobject'] = array ('body');
1687
+            $fieldsarr['epobject'] = array('body');
1688 1688
             $join = 'LEFT OUTER JOIN epobject ON hansard.epobject_id = epobject.epobject_id';
1689 1689
         } else {
1690 1690
             $join = '';
1691 1691
         }
1692 1692
 
1693 1693
 
1694
-        $fieldsarr2 = array ();
1694
+        $fieldsarr2 = array();
1695 1695
         // Construct the $fields clause.
1696 1696
         foreach ($fieldsarr as $table => $tablesfields) {
1697 1697
             foreach ($tablesfields as $n => $field) {
1698
-                $fieldsarr2[] = $table.'.'.$field;
1698
+                $fieldsarr2[] = $table . '.' . $field;
1699 1699
             }
1700 1700
         }
1701 1701
         $fields = implode(', ', $fieldsarr2);
1702 1702
 
1703
-        $wherearr2 = array ();
1703
+        $wherearr2 = array();
1704 1704
         // Construct the $where clause.
1705 1705
         $i = 0;
1706 1706
         foreach ($wherearr as $key => $val) {
@@ -1708,7 +1708,7 @@  discard block
 block discarded – undo
1708 1708
             $wherearr2[] = "$key :where$i";
1709 1709
             $i++;
1710 1710
         }
1711
-        $where = implode (" AND ", $wherearr2);
1711
+        $where = implode(" AND ", $wherearr2);
1712 1712
 
1713 1713
 
1714 1714
         if ($order != '') {
@@ -1726,7 +1726,7 @@  discard block
 block discarded – undo
1726 1726
         }
1727 1727
 
1728 1728
         // Finally, do the query!
1729
-        $q = $this->db->query ("SELECT $fields
1729
+        $q = $this->db->query("SELECT $fields
1730 1730
                         FROM 	hansard
1731 1731
                         $join
1732 1732
                         WHERE $where
@@ -1751,23 +1751,23 @@  discard block
 block discarded – undo
1751 1751
             if (isset($item['gid'])) {
1752 1752
                 // Remove the "uk.org.publicwhip/blah/" from the gid:
1753 1753
                 // (In includes/utility.php)
1754
-                $item['gid'] = fix_gid_from_db( $item['gid'] );
1754
+                $item['gid'] = fix_gid_from_db($item['gid']);
1755 1755
             }
1756 1756
 
1757 1757
             // Add mentions if (a) it's a question in the written
1758 1758
             // answer section or (b) it's in the official reports
1759 1759
             // and the body text ends in a bracketed SPID.
1760
-            if (($this->major && $hansardmajors[$this->major]['page']=='spwrans') && ($item['htype'] == '12' && $item['minor'] == '1')) {
1760
+            if (($this->major && $hansardmajors[$this->major]['page'] == 'spwrans') && ($item['htype'] == '12' && $item['minor'] == '1')) {
1761 1761
                 // Get out the SPID:
1762
-                if ( preg_match('#\d{4}-\d\d-\d\d\.(.*?)\.q#', $item['gid'], $m) ) {
1762
+                if (preg_match('#\d{4}-\d\d-\d\d\.(.*?)\.q#', $item['gid'], $m)) {
1763 1763
                     $item['mentions'] = $this->_get_mentions($m[1]);
1764 1764
                 }
1765 1765
             }
1766 1766
 
1767 1767
             // The second case (b):
1768
-            if (($this->major && $hansardmajors[$this->major]['page']=='spdebates') && isset($item['body'])) {
1769
-                $stripped_body = preg_replace('/<[^>]+>/ms','',$item['body']);
1770
-                if ( preg_match('/\((S\d+\w+-\d+)\)/ms',$stripped_body,$m) ) {
1768
+            if (($this->major && $hansardmajors[$this->major]['page'] == 'spdebates') && isset($item['body'])) {
1769
+                $stripped_body = preg_replace('/<[^>]+>/ms', '', $item['body']);
1770
+                if (preg_match('/\((S\d+\w+-\d+)\)/ms', $stripped_body, $m)) {
1771 1771
                     $item['mentions'] = $this->_get_mentions($m[1]);
1772 1772
                 }
1773 1773
             }
@@ -1780,7 +1780,7 @@  discard block
 block discarded – undo
1780 1780
             // Get the number of items within a section or subsection.
1781 1781
             // It could be that we can do this in the main query?
1782 1782
             // Not sure.
1783
-            if ( ($this->major && $hansardmajors[$this->major]['type']=='debate') && ($item['htype'] == '10' || $item['htype'] == '11') ) {
1783
+            if (($this->major && $hansardmajors[$this->major]['type'] == 'debate') && ($item['htype'] == '10' || $item['htype'] == '11')) {
1784 1784
 
1785 1785
                 if ($item['htype'] == '10') {
1786 1786
                     // Section - get a count of items within this section that
@@ -1858,7 +1858,7 @@  discard block
 block discarded – undo
1858 1858
             // 'commentsurl' is the URL of the item on its own page, with comments.
1859 1859
 
1860 1860
             // All the things we need to work out a listurl!
1861
-            $item_data = array (
1861
+            $item_data = array(
1862 1862
                 'major'			=> $this->major,
1863 1863
                 'minor' 		=> $item['minor'],
1864 1864
                 'htype' 		=> $item['htype'],
@@ -1891,11 +1891,11 @@  discard block
 block discarded – undo
1891 1891
                 $item['htype'] == '12') {
1892 1892
                 // Debate speech or written answers (not questions).
1893 1893
 
1894
-                $item['votes'] = $this->_get_votes( $item['epobject_id'] );
1894
+                $item['votes'] = $this->_get_votes($item['epobject_id']);
1895 1895
             }
1896 1896
 
1897 1897
             // Get the speaker for this item, if applicable.
1898
-            if ( (isset($amount['speaker']) && $amount['speaker'] == true) &&
1898
+            if ((isset($amount['speaker']) && $amount['speaker'] == true) &&
1899 1899
                 $item['person_id'] != '') {
1900 1900
 
1901 1901
                 $item['speaker'] = $this->_get_speaker($item['person_id'], $item['hdate'], $item['htime'], $item['major']);
@@ -1906,7 +1906,7 @@  discard block
 block discarded – undo
1906 1906
             if (isset($amount['comment']) && $amount['comment'] == true) {
1907 1907
 
1908 1908
                 // All the things we need to get the comment data.
1909
-                $item_data = array (
1909
+                $item_data = array(
1910 1910
                     'htype' => $item['htype'],
1911 1911
                     'epobject_id' => $item['epobject_id']
1912 1912
                 );
@@ -1979,7 +1979,7 @@  discard block
 block discarded – undo
1979 1979
     }
1980 1980
 
1981 1981
 
1982
-    public function _get_listurl ($id_data, $url_args=array(), $encode='html') {
1982
+    public function _get_listurl($id_data, $url_args = array(), $encode = 'html') {
1983 1983
         global $hansardmajors;
1984 1984
         // Generates an item's listurl - this is the 'contextual' url
1985 1985
         // for an item, in the full list view with an anchor (if appropriate).
@@ -2009,7 +2009,7 @@  discard block
 block discarded – undo
2009 2009
                 $DATA->set_page_metadata('pbc_clause', 'url', 'pbc/' . $this->url . $id);
2010 2010
                 $LISTURL->remove(array('id'));
2011 2011
             } else {
2012
-                $LISTURL->insert( array( 'id' => $id_data['gid'] ) );
2012
+                $LISTURL->insert(array('id' => $id_data['gid']));
2013 2013
             }
2014 2014
         } else {
2015 2015
             // A debate speech or question/answer, etc.
@@ -2022,10 +2022,10 @@  discard block
 block discarded – undo
2022 2022
             // Find the gid of this item's (sub)section.
2023 2023
             $parent_gid = '';
2024 2024
 
2025
-            if (isset($this->epobjectid_to_gid[ $parent_epobject_id ])) {
2025
+            if (isset($this->epobjectid_to_gid[$parent_epobject_id])) {
2026 2026
                 // We've previously cached the gid for this epobject_id, so use that.
2027 2027
 
2028
-                $parent_gid = $this->epobjectid_to_gid[ $parent_epobject_id ];
2028
+                $parent_gid = $this->epobjectid_to_gid[$parent_epobject_id];
2029 2029
 
2030 2030
             } else {
2031 2031
                 // We haven't cached the gid, so fetch from db.
@@ -2041,7 +2041,7 @@  discard block
 block discarded – undo
2041 2041
                     $parent_gid = fix_gid_from_db($r['gid']);
2042 2042
 
2043 2043
                     // Cache it for if we need it again:
2044
-                    $this->epobjectid_to_gid[ $parent_epobject_id ] = $parent_gid;
2044
+                    $this->epobjectid_to_gid[$parent_epobject_id] = $parent_gid;
2045 2045
                 }
2046 2046
             }
2047 2047
 
@@ -2056,13 +2056,13 @@  discard block
 block discarded – undo
2056 2056
                         $session = $qq['session'];
2057 2057
                         $this->bill_lookup[$minor] = array($title, $session);
2058 2058
                     }
2059
-                    $url = "$session/" . urlencode(str_replace(' ','_',$title));
2059
+                    $url = "$session/" . urlencode(str_replace(' ', '_', $title));
2060 2060
                     $parent_gid = preg_replace('#^.*?_.*?_#', '', $parent_gid);
2061 2061
                     global $DATA;
2062 2062
                     $DATA->set_page_metadata('pbc_clause', 'url', "pbc/$url/$parent_gid");
2063 2063
                     $LISTURL->remove(array('id'));
2064 2064
                 } else {
2065
-                    $LISTURL->insert( array( 'id' => $parent_gid ) );
2065
+                    $LISTURL->insert(array('id' => $parent_gid));
2066 2066
                 }
2067 2067
                 // Use a truncated form of this item's gid for the anchor.
2068 2068
                 $fragment = '#g' . gid_to_anchor($id_data['gid']);
@@ -2070,7 +2070,7 @@  discard block
 block discarded – undo
2070 2070
         }
2071 2071
 
2072 2072
         if (count($url_args) > 0) {
2073
-            $LISTURL->insert( $url_args);
2073
+            $LISTURL->insert($url_args);
2074 2074
         }
2075 2075
 
2076 2076
         return $LISTURL->generate($encode) . $fragment;
@@ -2133,10 +2133,10 @@  discard block
 block discarded – undo
2133 2133
         $member = $this->_get_speaker_alone($q, $person_id, $hdate, $htime, $major);
2134 2134
 
2135 2135
         $URL = $this->_get_speaker_url($member['house']);
2136
-        $URL->insert( array ('p' => $person_id) );
2136
+        $URL->insert(array('p' => $person_id));
2137 2137
 
2138 2138
         $name = member_full_name($member['house'], $member['title'], $member['given_name'], $member['family_name'], $member['lordofname']);
2139
-        $speaker = array (
2139
+        $speaker = array(
2140 2140
             'member_id' => $member['member_id'],
2141 2141
             "name" => $name,
2142 2142
             'house' => $member['house'],
@@ -2264,12 +2264,12 @@  discard block
 block discarded – undo
2264 2264
                     array(':epobject_id' => $item_data['epobject_id']))->first();
2265 2265
 
2266 2266
                 // Add this comment to the data structure.
2267
-                $comment = array (
2267
+                $comment = array(
2268 2268
                     'comment_id' => $q['comment_id'],
2269 2269
                     'user_id'	=> $q['user_id'],
2270 2270
                     'body'		=> $q['body'],
2271 2271
                     'posted'	=> $q['posted'],
2272
-                    'username'	=> $q['firstname'] .' '. $q['lastname']
2272
+                    'username'	=> $q['firstname'] . ' ' . $q['lastname']
2273 2273
                 );
2274 2274
             }
2275 2275
 
@@ -2279,7 +2279,7 @@  discard block
 block discarded – undo
2279 2279
         // or subsection itself, only the items within them. So
2280 2280
         // we don't get the most recent comment. Because there isn't one.
2281 2281
 
2282
-        $return = array (
2282
+        $return = array(
2283 2283
             'totalcomments' => $totalcomments,
2284 2284
             'comment' => $comment
2285 2285
         );
@@ -2293,7 +2293,7 @@  discard block
 block discarded – undo
2293 2293
         // What it says on the tin.
2294 2294
         // $item_data must have 'htype' and 'epobject_id' elements. TODO: Check for major==4
2295 2295
 
2296
-        if (($hansardmajors[$this->major]['type']=='debate') &&
2296
+        if (($hansardmajors[$this->major]['type'] == 'debate') &&
2297 2297
             ($item_data['htype'] == '10' || $item_data['htype'] == '11')
2298 2298
             ) {
2299 2299
             // We'll be getting a count of the comments on all items
@@ -2329,7 +2329,7 @@  discard block
 block discarded – undo
2329 2329
         // Then depending on what htype it is, we get the data for other items too.
2330 2330
         global $DATA, $this_page, $hansardmajors;
2331 2331
 
2332
-        twfy_debug (get_class($this), "getting data by gid");
2332
+        twfy_debug(get_class($this), "getting data by gid");
2333 2333
 
2334 2334
         // Get the information about the item this URL refers to.
2335 2335
         $itemdata = $this->_get_item($args);
@@ -2338,25 +2338,25 @@  discard block
 block discarded – undo
2338 2338
         }
2339 2339
 
2340 2340
         // If part of a Written Answer (just question or just answer), select the whole thing
2341
-        if (isset($itemdata['major']) && $hansardmajors[$itemdata['major']]['type']=='other' and ($itemdata['htype'] == '12' or $itemdata['htype'] == '13' or $itemdata['htype'] == '14')) {
2341
+        if (isset($itemdata['major']) && $hansardmajors[$itemdata['major']]['type'] == 'other' and ($itemdata['htype'] == '12' or $itemdata['htype'] == '13' or $itemdata['htype'] == '14')) {
2342 2342
             // find the gid of the subheading which holds this part
2343
-            $input = array (
2343
+            $input = array(
2344 2344
                 'amount' => array('gid' => true),
2345
-                'where' => array (
2345
+                'where' => array(
2346 2346
                     'epobject_id=' => $itemdata['subsection_id'],
2347 2347
                 ),
2348 2348
             );
2349 2349
             $parent = $this->_get_hansard_data($input);
2350 2350
             // display that item, i.e. the whole of the Written Answer
2351
-            twfy_debug (get_class($this), "instead of " . $args['gid'] . " selecting subheading gid " . $parent[0]['gid'] . " to get whole wrans");
2351
+            twfy_debug(get_class($this), "instead of " . $args['gid'] . " selecting subheading gid " . $parent[0]['gid'] . " to get whole wrans");
2352 2352
             $args['gid'] = $parent[0]['gid'];
2353 2353
             $this->_get_item($args);
2354 2354
             throw new RedirectException($args['gid']);
2355 2355
         }
2356 2356
 
2357 2357
         # If a WMS main heading, go to next gid
2358
-        if (isset($itemdata['major']) && $itemdata['major']==4 && $itemdata['htype'] == '10') {
2359
-            $input = array (
2358
+        if (isset($itemdata['major']) && $itemdata['major'] == 4 && $itemdata['htype'] == '10') {
2359
+            $input = array(
2360 2360
                 'amount' => array('gid' => true),
2361 2361
                 'where' => array(
2362 2362
                     'section_id=' => $itemdata['epobject_id'],
@@ -2366,7 +2366,7 @@  discard block
 block discarded – undo
2366 2366
             );
2367 2367
             $next = $this->_get_hansard_data($input);
2368 2368
             if (!empty($next)) {
2369
-                twfy_debug (get_class($this), 'instead of ' . $args['gid'] . ' moving to ' . $next[0]['gid']);
2369
+                twfy_debug(get_class($this), 'instead of ' . $args['gid'] . ' moving to ' . $next[0]['gid']);
2370 2370
                 $args['gid'] = $next[0]['gid'];
2371 2371
                 $this->_get_item($args);
2372 2372
                 throw new RedirectException($args['gid']);
@@ -2418,16 +2418,16 @@  discard block
 block discarded – undo
2418 2418
         // Get the nextprev links for this item, to link to next/prev pages.
2419 2419
         // Duh.
2420 2420
         if ($itemdata['htype'] == '10') {
2421
-            $nextprev = $this->_get_nextprev_items( $sectionrow );
2421
+            $nextprev = $this->_get_nextprev_items($sectionrow);
2422 2422
             $data['info']['text_heading'] = $itemdata['body'];
2423 2423
 
2424 2424
         } elseif ($itemdata['htype'] == '11') {
2425
-            $nextprev = $this->_get_nextprev_items( $subsectionrow );
2425
+            $nextprev = $this->_get_nextprev_items($subsectionrow);
2426 2426
             $data['info']['text_heading'] = $itemdata['body'];
2427 2427
 
2428 2428
         } else {
2429 2429
             // Ordinary lowly item.
2430
-            $nextprev = $this->_get_nextprev_items( $itemdata );
2430
+            $nextprev = $this->_get_nextprev_items($itemdata);
2431 2431
 
2432 2432
             if (isset($subsectionrow['gid'])) {
2433 2433
                 $nextprev['up']['url'] 		= $subsectionrow['listurl'];
@@ -2436,7 +2436,7 @@  discard block
 block discarded – undo
2436 2436
                 $nextprev['up']['url'] 		= $sectionrow['listurl'];
2437 2437
                 $nextprev['up']['title'] 	= $sectionrow['body'];
2438 2438
             }
2439
-            $nextprev['up']['body']		= gettext('See the whole debate');
2439
+            $nextprev['up']['body'] = gettext('See the whole debate');
2440 2440
         }
2441 2441
 
2442 2442
         // We can then access this from $PAGE and the templates.
@@ -2445,7 +2445,7 @@  discard block
 block discarded – undo
2445 2445
         // Now get all the non-heading rows.
2446 2446
 
2447 2447
         // What data do we want for each item?
2448
-        $amount = array (
2448
+        $amount = array(
2449 2449
             'body' => true,
2450 2450
             'speaker' => true,
2451 2451
             'comment' => true,
@@ -2456,9 +2456,9 @@  discard block
 block discarded – undo
2456 2456
             // This item is a section, so we're displaying all the items within
2457 2457
             // it that aren't within a subsection.
2458 2458
 
2459
-            $input = array (
2459
+            $input = array(
2460 2460
                 'amount' => $amount,
2461
-                'where' => array (
2461
+                'where' => array(
2462 2462
                     'section_id=' => $itemdata['epobject_id'],
2463 2463
                     'subsection_id=' => $itemdata['epobject_id']
2464 2464
                 ),
@@ -2466,15 +2466,15 @@  discard block
 block discarded – undo
2466 2466
             );
2467 2467
 
2468 2468
             $data['rows'] = $this->_get_hansard_data($input);
2469
-            if (!count($data['rows']) || (count($data['rows'])==1 && strstr($data['rows'][0]['body'], 'was asked'))) {
2469
+            if (!count($data['rows']) || (count($data['rows']) == 1 && strstr($data['rows'][0]['body'], 'was asked'))) {
2470 2470
 
2471
-                $input = array (
2472
-                    'amount' => array (
2471
+                $input = array(
2472
+                    'amount' => array(
2473 2473
                         'body' => true,
2474 2474
                         'comment' => true,
2475 2475
                         'excerpt' => true
2476 2476
                     ),
2477
-                    'where' => array (
2477
+                    'where' => array(
2478 2478
                         'section_id='	=> $sectionrow['epobject_id'],
2479 2479
                         'htype='		=> '11',
2480 2480
                         'major='		=> $this->major
@@ -2490,9 +2490,9 @@  discard block
 block discarded – undo
2490 2490
         } elseif ($itemdata['htype'] == '11') {
2491 2491
             // This item is a subsection, so we're displaying everything within it.
2492 2492
 
2493
-            $input = array (
2493
+            $input = array(
2494 2494
                 'amount' => $amount,
2495
-                'where' => array (
2495
+                'where' => array(
2496 2496
                     'subsection_id=' => $itemdata['epobject_id']
2497 2497
                 ),
2498 2498
                 'order' => 'hpos ASC'
@@ -2513,10 +2513,10 @@  discard block
 block discarded – undo
2513 2513
             $subsectionrow['gid'] != $sectionrow['gid']) {
2514 2514
             // If we're looking at a section, there may not be a subsection.
2515 2515
             // And if the subsectionrow and sectionrow aren't the same.
2516
-            array_unshift ($data['rows'], $subsectionrow);
2516
+            array_unshift($data['rows'], $subsectionrow);
2517 2517
         }
2518 2518
 
2519
-        array_unshift ($data['rows'], $sectionrow);
2519
+        array_unshift($data['rows'], $sectionrow);
2520 2520
 
2521 2521
         return $data;
2522 2522
 
@@ -2525,10 +2525,10 @@  discard block
 block discarded – undo
2525 2525
     public function _get_data_by_column($args) {
2526 2526
         global $this_page;
2527 2527
 
2528
-        twfy_debug (get_class($this), "getting data by column");
2528
+        twfy_debug(get_class($this), "getting data by column");
2529 2529
 
2530
-        $input = array( 'amount' => array('body'=>true, 'comment'=>true, 'speaker'=>true),
2531
-        'where' => array( 'hdate='=>$args['date'], 'major=' => $this->major, 'gid LIKE ' =>'%.'.$args['column'].'.%' ),
2530
+        $input = array('amount' => array('body'=>true, 'comment'=>true, 'speaker'=>true),
2531
+        'where' => array('hdate='=>$args['date'], 'major=' => $this->major, 'gid LIKE ' =>'%.' . $args['column'] . '.%'),
2532 2532
         'order' => 'hpos'
2533 2533
         );
2534 2534
         $data = $this->_get_hansard_data($input);
@@ -2608,8 +2608,8 @@  discard block
 block discarded – undo
2608 2608
     public function get_gid_from_spid($spid) {
2609 2609
         // Fix the common errors of S.0 instead of S.O and leading
2610 2610
         // zeros in the numbers:
2611
-        $fixed_spid = preg_replace('/(S[0-9]+)0-([0-9]+)/','${1}O-${2}',$spid);
2612
-        $fixed_spid = preg_replace('/(S[0-9]+\w+)-0*([0-9]+)/','${1}-${2}',$fixed_spid);
2611
+        $fixed_spid = preg_replace('/(S[0-9]+)0-([0-9]+)/', '${1}O-${2}', $spid);
2612
+        $fixed_spid = preg_replace('/(S[0-9]+\w+)-0*([0-9]+)/', '${1}-${2}', $fixed_spid);
2613 2613
         $q = $this->db->query(
2614 2614
             "select mentioned_gid from mentions where gid = :gid_from_spid and (type = 4 or type = 6)",
2615 2615
             array(':gid_from_spid' => 'uk.org.publicwhip/spq/' . $fixed_spid)
@@ -2688,10 +2688,10 @@  discard block
 block discarded – undo
2688 2688
                         ", array(':major' => $this->major));
2689 2689
 
2690 2690
         // What we return.
2691
-        $data = array ();
2691
+        $data = array();
2692 2692
         $speeches = array();
2693 2693
         foreach ($q as $row) {
2694
-            $speech = array (
2694
+            $speech = array(
2695 2695
                 'subsection_id' => $row['subsection_id'],
2696 2696
                 'section_id' => $row['section_id'],
2697 2697
                 'htype' => $row['htype'],
@@ -2704,9 +2704,9 @@  discard block
 block discarded – undo
2704 2704
 
2705 2705
             // Remove the "uk.org.publicwhip/blah/" from the gid:
2706 2706
             // (In includes/utility.php)
2707
-            $speech['gid'] = fix_gid_from_db( $row['gid'] );
2707
+            $speech['gid'] = fix_gid_from_db($row['gid']);
2708 2708
             $speech['listurl'] = $this->_get_listurl($speech);
2709
-            $speech['speaker'] = $this->_get_speaker($row['person_id'], $row['hdate'], $row['htime'], $this->major );
2709
+            $speech['speaker'] = $this->_get_speaker($row['person_id'], $row['hdate'], $row['htime'], $this->major);
2710 2710
             $speeches[] = $speech;
2711 2711
         }
2712 2712
 
@@ -2714,10 +2714,10 @@  discard block
 block discarded – undo
2714 2714
             // Get the subsection texts.
2715 2715
 
2716 2716
             $num_speeches = count($speeches);
2717
-            for ($n=0; $n<$num_speeches; $n++) {
2717
+            for ($n = 0; $n < $num_speeches; $n++) {
2718 2718
                 //if ($this->major == 1) {
2719 2719
                     // Debate.
2720
-                    $parent = $this->_get_subsection ($speeches[$n]);
2720
+                    $parent = $this->_get_subsection($speeches[$n]);
2721 2721
 
2722 2722
                 //} elseif ($this->major == 3) {
2723 2723
                     // Wrans.
@@ -2736,7 +2736,7 @@  discard block
 block discarded – undo
2736 2736
             $data['rows'] = $speeches;
2737 2737
 
2738 2738
         } else {
2739
-            $data['rows'] = array ();
2739
+            $data['rows'] = array();
2740 2740
         }
2741 2741
 
2742 2742
         $data['info']['days'] = $days;
@@ -2753,13 +2753,13 @@  discard block
 block discarded – undo
2753 2753
     }
2754 2754
 
2755 2755
 
2756
-    public function biggest_debates($args=array()) {
2756
+    public function biggest_debates($args = array()) {
2757 2757
         // So we can just get the data back for special formatting
2758 2758
         // on the front page, without doing the whole display() thing.
2759 2759
         return $this->_get_data_by_biggest_debates($args);
2760 2760
     }
2761 2761
 
2762
-    public function _get_data_by_featured_gid($args=array()) {
2762
+    public function _get_data_by_featured_gid($args = array()) {
2763 2763
         $params = array();
2764 2764
         $data = array();
2765 2765
 
@@ -2788,18 +2788,18 @@  discard block
 block discarded – undo
2788 2788
         if ($q) {
2789 2789
 
2790 2790
             // This array just used for getting further data about this debate.
2791
-            $item_data = array (
2791
+            $item_data = array(
2792 2792
                 'major'         => $this->major,
2793 2793
                 'minor'         => $q['minor'],
2794
-                'gid'           => fix_gid_from_db( $q['gid'] ),
2794
+                'gid'           => fix_gid_from_db($q['gid']),
2795 2795
                 'htype'         => $q['htype'],
2796 2796
                 'section_id'    => $q['section_id'],
2797 2797
                 'subsection_id' => $q['subsection_id'],
2798 2798
                 'epobject_id'   => $q['epobject_id']
2799 2799
             );
2800 2800
 
2801
-            $list_url      = $this->_get_listurl( $item_data );
2802
-            $totalcomments = $this->_get_comment_count_for_epobject( $item_data );
2801
+            $list_url      = $this->_get_listurl($item_data);
2802
+            $totalcomments = $this->_get_comment_count_for_epobject($item_data);
2803 2803
 
2804 2804
             $body          = $q['body'];
2805 2805
             $hdate         = $q['hdate'];
@@ -2819,21 +2819,21 @@  discard block
 block discarded – undo
2819 2819
                                     ':subsection_id' => $item_data['subsection_id'],
2820 2820
                                 )
2821 2821
                             )->first();
2822
-                $section_body  = $r['sec_body'];
2822
+                $section_body = $r['sec_body'];
2823 2823
                 $subsection_body = $r['sub_body'];
2824
-                if ( $section_body && $subsection_body ) {
2824
+                if ($section_body && $subsection_body) {
2825 2825
                     $parentbody = "$section_body : $subsection_body";
2826 2826
                 } else {
2827 2827
                     $parentbody = "$section_body$subsection_body";
2828 2828
                 }
2829
-            } else if ( $item_data['htype'] == 10 ) {
2829
+            } else if ($item_data['htype'] == 10) {
2830 2830
                 $parentbody = $body;
2831 2831
             }
2832 2832
 
2833 2833
             // Get the question for this item.
2834
-            if ( $item_data['htype'] == 12 ) {
2834
+            if ($item_data['htype'] == 12) {
2835 2835
                 $childbody = $body;
2836
-                $speaker = $this->_get_speaker($q['person_id'], $q['hdate'], $q['htime'], $this->major );
2836
+                $speaker = $this->_get_speaker($q['person_id'], $q['hdate'], $q['htime'], $this->major);
2837 2837
             } else {
2838 2838
                 $r = $this->db->query("SELECT e.body, e.title,
2839 2839
                                         h.person_id, h.hdate, h.htime
@@ -2843,10 +2843,10 @@  discard block
 block discarded – undo
2843 2843
                                 ORDER BY hpos
2844 2844
                                 LIMIT 1
2845 2845
                                 ",
2846
-                                array( ':object_id' => $item_data['epobject_id'] )
2846
+                                array(':object_id' => $item_data['epobject_id'])
2847 2847
                 )->first();
2848 2848
                 $childbody = $r['body'];
2849
-                $speaker = $this->_get_speaker($r['person_id'], $r['hdate'], $r['htime'], $this->major );
2849
+                $speaker = $this->_get_speaker($r['person_id'], $r['hdate'], $r['htime'], $this->major);
2850 2850
             }
2851 2851
 
2852 2852
             $contentcount = 0;
@@ -2862,7 +2862,7 @@  discard block
 block discarded – undo
2862 2862
             }
2863 2863
 
2864 2864
             global $hansardmajors;
2865
-            $more_url = new \MySociety\TheyWorkForYou\Url( $hansardmajors[$this->major]['page_all'] );
2865
+            $more_url = new \MySociety\TheyWorkForYou\Url($hansardmajors[$this->major]['page_all']);
2866 2866
             $details = array(
2867 2867
                 'body'          => $body,
2868 2868
                 'contentcount'  => $contentcount,
@@ -2881,7 +2881,7 @@  discard block
 block discarded – undo
2881 2881
                 'more_url' => $more_url->generate()
2882 2882
             );
2883 2883
 
2884
-            $data = array (
2884
+            $data = array(
2885 2885
                 'gid' => $args['gid'],
2886 2886
                 'major' => $this->major,
2887 2887
                 'info' => array(),
@@ -2892,7 +2892,7 @@  discard block
 block discarded – undo
2892 2892
         return $data;
2893 2893
 
2894 2894
     }
2895
-    public function _get_data_by_recent_debates($args=array()) {
2895
+    public function _get_data_by_recent_debates($args = array()) {
2896 2896
         // Returns an array of some random recent debates from a set number of
2897 2897
         // recent days (that's recent days starting from the most recent day
2898 2898
         // that had any debates on).
@@ -2954,17 +2954,17 @@  discard block
 block discarded – undo
2954 2954
         foreach ($q as $row) {
2955 2955
 
2956 2956
             // This array just used for getting further data about this debate.
2957
-            $item_data = array (
2957
+            $item_data = array(
2958 2958
                 'major' => $this->major,
2959
-                'gid' => fix_gid_from_db( $row['gid'] ),
2959
+                'gid' => fix_gid_from_db($row['gid']),
2960 2960
                 'htype' => $row['htype'],
2961 2961
                 'section_id' => $row['section_id'],
2962 2962
                 'subsection_id' => $row['subsection_id'],
2963 2963
                 'epobject_id' => $row['epobject_id']
2964 2964
             );
2965 2965
 
2966
-            $list_url      = $this->_get_listurl( $item_data );
2967
-            $totalcomments = $this->_get_comment_count_for_epobject( $item_data );
2966
+            $list_url      = $this->_get_listurl($item_data);
2967
+            $totalcomments = $this->_get_comment_count_for_epobject($item_data);
2968 2968
 
2969 2969
             $contentcount  = $row['count'];
2970 2970
             $body          = $row['body'];
@@ -2992,7 +2992,7 @@  discard block
 block discarded – undo
2992 2992
                             LIMIT 1
2993 2993
                             ")->first();
2994 2994
             $childbody = $r['body'];
2995
-            $speaker = $this->_get_speaker($r['person_id'], $r['hdate'], $r['htime'], $this->major );
2995
+            $speaker = $this->_get_speaker($r['person_id'], $r['hdate'], $r['htime'], $this->major);
2996 2996
 
2997 2997
             $data[] = array(
2998 2998
                 'contentcount'  => $contentcount,
@@ -3012,7 +3012,7 @@  discard block
 block discarded – undo
3012 3012
 
3013 3013
         }
3014 3014
 
3015
-        $data = array (
3015
+        $data = array(
3016 3016
             'info' => array(),
3017 3017
             'data' => $data
3018 3018
         );
@@ -3021,7 +3021,7 @@  discard block
 block discarded – undo
3021 3021
 
3022 3022
     }
3023 3023
 
3024
-    public function _get_data_by_biggest_debates($args=array()) {
3024
+    public function _get_data_by_biggest_debates($args = array()) {
3025 3025
         // Returns an array of the debates with most speeches in from
3026 3026
         // a set number of recent days (that's recent days starting from the
3027 3027
         // most recent day that had any debates on).
@@ -3076,17 +3076,17 @@  discard block
 block discarded – undo
3076 3076
         foreach ($q as $row) {
3077 3077
 
3078 3078
             // This array just used for getting further data about this debate.
3079
-            $item_data = array (
3079
+            $item_data = array(
3080 3080
                 'major' => $this->major,
3081
-                'gid' => fix_gid_from_db( $row['gid'] ),
3081
+                'gid' => fix_gid_from_db($row['gid']),
3082 3082
                 'htype' => $row['htype'],
3083 3083
                 'section_id' => $row['section_id'],
3084 3084
                 'subsection_id' => $row['subsection_id'],
3085 3085
                 'epobject_id' => $row['epobject_id']
3086 3086
             );
3087 3087
 
3088
-            $list_url 		= $this->_get_listurl( $item_data );
3089
-            $totalcomments	= $this->_get_comment_count_for_epobject( $item_data );
3088
+            $list_url = $this->_get_listurl($item_data);
3089
+            $totalcomments = $this->_get_comment_count_for_epobject($item_data);
3090 3090
 
3091 3091
             $contentcount = $row['count'];
3092 3092
             $body = $row['body'];
@@ -3094,7 +3094,7 @@  discard block
 block discarded – undo
3094 3094
 
3095 3095
 
3096 3096
             // This array will be added to $data, which is what gets returned.
3097
-            $debate = array (
3097
+            $debate = array(
3098 3098
                 'contentcount'	=> $contentcount,
3099 3099
                 'body'			=> $body,
3100 3100
                 'hdate'			=> $hdate,
@@ -3122,7 +3122,7 @@  discard block
 block discarded – undo
3122 3122
                             LIMIT 1
3123 3123
                             ")->first();
3124 3124
             $childbody = $r['body'];
3125
-            $speaker = $this->_get_speaker($r['person_id'], $r['hdate'], $r['htime'], $this->major );
3125
+            $speaker = $this->_get_speaker($r['person_id'], $r['hdate'], $r['htime'], $this->major);
3126 3126
 
3127 3127
             $debate['child'] = array(
3128 3128
                 'body' => $childbody,
@@ -3132,7 +3132,7 @@  discard block
 block discarded – undo
3132 3132
             $data[] = $debate;
3133 3133
         }
3134 3134
 
3135
-        $data = array (
3135
+        $data = array(
3136 3136
             'info' => array(),
3137 3137
             'data' => $data
3138 3138
         );
@@ -3155,7 +3155,7 @@  discard block
 block discarded – undo
3155 3155
         return $q->first()['count'];
3156 3156
     }
3157 3157
 
3158
-    public function _get_data_by_recent_wrans ($args=array()) {
3158
+    public function _get_data_by_recent_wrans($args = array()) {
3159 3159
         global $hansardmajors;
3160 3160
 
3161 3161
         // $args['days'] is the number of days back to look for biggest debates.
@@ -3220,17 +3220,17 @@  discard block
 block discarded – undo
3220 3220
 
3221 3221
         foreach ($q as $row) {
3222 3222
             // This array just used for getting further data about this debate.
3223
-            $item_data = array (
3223
+            $item_data = array(
3224 3224
                 'major' => $this->major,
3225
-                'gid' => fix_gid_from_db( $row['gid'] ),
3225
+                'gid' => fix_gid_from_db($row['gid']),
3226 3226
                 'htype' => $row['htype'],
3227 3227
                 'section_id' => $row['section_id'],
3228 3228
                 'subsection_id' => $row['subsection_id'],
3229 3229
                 'epobject_id' => $row['epobject_id']
3230 3230
             );
3231 3231
 
3232
-            $list_url 		= $this->_get_listurl( $item_data );
3233
-            $totalcomments	= $this->_get_comment_count_for_epobject( $item_data );
3232
+            $list_url = $this->_get_listurl($item_data);
3233
+            $totalcomments = $this->_get_comment_count_for_epobject($item_data);
3234 3234
 
3235 3235
             $body = $row['body'];
3236 3236
             $hdate = $row['hdate'];
@@ -3256,25 +3256,25 @@  discard block
 block discarded – undo
3256 3256
                             LIMIT 1
3257 3257
                             ")->first();
3258 3258
             $childbody = $r['body'];
3259
-            $speaker = $this->_get_speaker($r['person_id'], $r['hdate'], $r['htime'], $this->major );
3259
+            $speaker = $this->_get_speaker($r['person_id'], $r['hdate'], $r['htime'], $this->major);
3260 3260
 
3261
-            $data[] = array (
3261
+            $data[] = array(
3262 3262
                 'body'			=> $body,
3263 3263
                 'hdate'			=> $hdate,
3264 3264
                 'list_url'		=> $list_url,
3265 3265
                 'totalcomments'	=> $totalcomments,
3266
-                'child'			=> array (
3266
+                'child'			=> array(
3267 3267
                     'body'		=> $childbody,
3268 3268
                     'speaker'	=> $speaker
3269 3269
                 ),
3270
-                'parent'		=> array (
3270
+                'parent'		=> array(
3271 3271
                     'body'		=> $parentbody
3272 3272
                 )
3273 3273
             );
3274 3274
 
3275 3275
         }
3276 3276
 
3277
-        $data = array (
3277
+        $data = array(
3278 3278
             'info' => array(),
3279 3279
             'data' => $data
3280 3280
         );
@@ -3291,7 +3291,7 @@  discard block
 block discarded – undo
3291 3291
     public $commentspage = 'pbc_speech';
3292 3292
     public $gidprefix = 'uk.org.publicwhip/standing/';
3293 3293
 
3294
-    public function __construct($session='', $title='') {
3294
+    public function __construct($session = '', $title = '') {
3295 3295
         parent::__construct();
3296 3296
         $this->bill_title = $title;
3297 3297
         $title = str_replace(' ', '_', $title);
@@ -3299,7 +3299,7 @@  discard block
 block discarded – undo
3299 3299
     }
3300 3300
 
3301 3301
     public function _get_committee($bill_id) {
3302
-        include_once INCLUDESPATH."easyparliament/member.php";
3302
+        include_once INCLUDESPATH . "easyparliament/member.php";
3303 3303
         $q = $this->db->query(
3304 3304
             'select count(*) as c from hansard
3305 3305
                 where major=6 and minor=:bill_id and htype=10',
@@ -3333,13 +3333,13 @@  discard block
 block discarded – undo
3333 3333
     public function _get_data_by_bill($args) {
3334 3334
         global $DATA, $this_page;
3335 3335
         $data = array();
3336
-        $input = array (
3337
-            'amount' => array (
3336
+        $input = array(
3337
+            'amount' => array(
3338 3338
                 'body' => true,
3339 3339
                 'comment' => true,
3340 3340
                 'excerpt' => true
3341 3341
             ),
3342
-            'where' => array (
3342
+            'where' => array(
3343 3343
                 'htype=' => '10',
3344 3344
                 'major=' => $this->major,
3345 3345
                 'minor=' => $args['id'],
@@ -3350,18 +3350,18 @@  discard block
 block discarded – undo
3350 3350
         if (count($sections) > 0) {
3351 3351
             $data['rows'] = array();
3352 3352
             $num_sections = count($sections);
3353
-            for ($n=0; $n<$num_sections; $n++) {
3353
+            for ($n = 0; $n < $num_sections; $n++) {
3354 3354
                 $sectionrow = $sections[$n];
3355 3355
                 list($sitting, $part) = $this->_get_sitting($sectionrow['gid']);
3356 3356
                 $sectionrow['sitting'] = $sitting;
3357 3357
                 $sectionrow['part'] = $part;
3358
-                $input = array (
3359
-                    'amount' => array (
3358
+                $input = array(
3359
+                    'amount' => array(
3360 3360
                         'body' => true,
3361 3361
                         'comment' => true,
3362 3362
                         'excerpt' => true
3363 3363
                     ),
3364
-                    'where' => array (
3364
+                    'where' => array(
3365 3365
                         'section_id='	=> $sectionrow['epobject_id'],
3366 3366
                         'htype='	=> '11',
3367 3367
                         'major='	=> $this->major
@@ -3369,8 +3369,8 @@  discard block
 block discarded – undo
3369 3369
                     'order' => 'hpos'
3370 3370
                 );
3371 3371
                 $rows = $this->_get_hansard_data($input);
3372
-                array_unshift ($rows, $sectionrow);
3373
-                $data['rows'] = array_merge ($data['rows'], $rows);
3372
+                array_unshift($rows, $sectionrow);
3373
+                $data['rows'] = array_merge($data['rows'], $rows);
3374 3374
             }
3375 3375
         }
3376 3376
         $data['info']['bill'] = $args['title'];
@@ -3426,8 +3426,8 @@  discard block
 block discarded – undo
3426 3426
 
3427 3427
         $YEARURL = new \MySociety\TheyWorkForYou\Url('pbc_session');
3428 3428
         $nextprev = array();
3429
-        $nextprev['prev'] = array ('body' => 'Previous session', 'title'=>'');
3430
-        $nextprev['next'] = array ('body' => 'Next session', 'title'=>'');
3429
+        $nextprev['prev'] = array('body' => 'Previous session', 'title'=>'');
3430
+        $nextprev['next'] = array('body' => 'Next session', 'title'=>'');
3431 3431
         $q = $this->db->query(
3432 3432
             "SELECT session FROM bills WHERE session < :session ORDER BY session DESC LIMIT 1",
3433 3433
             array(':session' => $session)
@@ -3464,13 +3464,13 @@  discard block
 block discarded – undo
3464 3464
             $session = $qq['session'];
3465 3465
             list($sitting, $part) = $this->_get_sitting($gid);
3466 3466
             $sitting_txt = make_ranking($sitting) . ' sitting';
3467
-            if ($part>0) {
3467
+            if ($part > 0) {
3468 3468
                 $sitting .= ", part $part";
3469 3469
             }
3470 3470
             $data[$hdate][] = array(
3471 3471
                 'bill'=> $title,
3472 3472
                 'sitting' => $sitting_txt,
3473
-                'url' => "/pbc/$session/" . urlencode(str_replace(' ','_',$title)) . '/#sitting' . $sitting,
3473
+                'url' => "/pbc/$session/" . urlencode(str_replace(' ', '_', $title)) . '/#sitting' . $sitting,
3474 3474
             );
3475 3475
         }
3476 3476
         return $data;
@@ -3479,7 +3479,7 @@  discard block
 block discarded – undo
3479 3479
     # Given a GID, parse out the sitting number and optional part from it
3480 3480
     public function _get_sitting($gid) {
3481 3481
         if (preg_match('#_(\d\d)-(\d)_#', $gid, $m)) {
3482
-            return array($m[1]+0, $m[2]);
3482
+            return array($m[1] + 0, $m[2]);
3483 3483
         }
3484 3484
         return array(0, 0);
3485 3485
     }
Please login to merge, or discard this patch.
www/includes/easyparliament/alert.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     public $token_checked = null;
42 42
     private $alert_id = "";
43 43
     public $email = "";
44
-    public $criteria = "";		// Sets the terms that are used to produce the search results.
44
+    public $criteria = ""; // Sets the terms that are used to produce the search results.
45 45
 
46 46
     private $db;
47 47
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
             $contents = array('criteria' => $row['criteria'], 'count' => $row['cnt']);
73 73
             $data[] = $contents;
74 74
         }
75
-        $data = array ('alerts' => $data);
75
+        $data = array('alerts' => $data);
76 76
         return $data;
77 77
     }
78 78
 
@@ -100,12 +100,12 @@  discard block
 block discarded – undo
100 100
 
101 101
         $data = $q->fetchAll();
102 102
         $info = "Alert";
103
-        $data = array ('info' => $info, 'data' => $data);
103
+        $data = array('info' => $info, 'data' => $data);
104 104
 
105 105
         return $data;
106 106
     }
107 107
 
108
-    public function add($details, $confirmation_email=false, $instantly_confirm=true) {
108
+    public function add($details, $confirmation_email = false, $instantly_confirm = true) {
109 109
 
110 110
         // Adds a new alert's info into the database.
111 111
         // Then calls another function to send them a confirmation email.
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
             // This gives a code for their email address which is then joined
171 171
             // to the timestamp so as to provide a unique ID for each alert.
172 172
 
173
-            $token = substr( password_hash($details["email"] . microtime(), PASSWORD_BCRYPT), 29, 16 );
173
+            $token = substr(password_hash($details["email"] . microtime(), PASSWORD_BCRYPT), 29, 16);
174 174
 
175 175
             // Full stops don't work well at the end of URLs in emails, so
176 176
             // replace them. And double slash would be treated as single and
@@ -244,19 +244,19 @@  discard block
 block discarded – undo
244 244
 
245 245
         $urltoken = $this->alert_id . '-' . $this->registrationtoken;
246 246
 
247
-        if ( isset($details['confirm_base']) && $details['confirm_base'] !== '' ) {
247
+        if (isset($details['confirm_base']) && $details['confirm_base'] !== '') {
248 248
             $confirmurl = $details['confirm_base'] . $urltoken;
249 249
         } else {
250 250
             $confirmurl = 'https://' . DOMAIN . '/A/' . $urltoken;
251 251
         }
252 252
 
253 253
         // Arrays we need to send a templated email.
254
-        $data = array (
254
+        $data = array(
255 255
             'to' 		=> $details['email'],
256 256
             'template' 	=> 'alert_confirmation'
257 257
         );
258 258
 
259
-        $merge = array (
259
+        $merge = array(
260 260
             'CONFIRMURL'	=> $confirmurl,
261 261
             'CRITERIA'	=> $this->criteria_pretty()
262 262
         );
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
     }
271 271
 
272 272
     public function send_already_signedup_email($details) {
273
-        $data = array (
273
+        $data = array(
274 274
             'to' 		=> $details['email'],
275 275
             'template' 	=> 'alert_already_signedup'
276 276
         );
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
         $criteria = \MySociety\TheyWorkForYou\Utility\Alert::detailsToCriteria($details);
279 279
         $this->criteria = $criteria;
280 280
 
281
-        $merge = array (
281
+        $merge = array(
282 282
             'CRITERIA'	=> $this->criteria_pretty()
283 283
         );
284 284
 
@@ -449,20 +449,20 @@  discard block
 block discarded – undo
449 449
     public function email() { return $this->email; }
450 450
     public function criteria() { return $this->criteria; }
451 451
     public function criteria_pretty($html = false) {
452
-        $criteria = explode(' ',$this->criteria);
452
+        $criteria = explode(' ', $this->criteria);
453 453
         $spokenby = array_values(\MySociety\TheyWorkForYou\Utility\Search::speakerNamesForIDs($this->criteria));
454 454
         $words = array();
455 455
         foreach ($criteria as $c) {
456
-            if (!preg_match('#^speaker:(\d+)#',$c,$m)) {
456
+            if (!preg_match('#^speaker:(\d+)#', $c, $m)) {
457 457
                 $words[] = $c;
458 458
             }
459 459
         }
460 460
         $criteria = '';
461 461
         if (count($words)) {
462
-            $criteria .= ($html?'<li>':'* ') . sprintf(gettext('Mentions of [%s]'), implode(' ', $words)) . ($html?'</li>':'') . "\n";
462
+            $criteria .= ($html ? '<li>' : '* ') . sprintf(gettext('Mentions of [%s]'), implode(' ', $words)) . ($html ? '</li>' : '') . "\n";
463 463
         }
464 464
         if ($spokenby) {
465
-            $criteria .= ($html?'<li>':'* ') . sprintf(gettext("Things by %s"), implode(' or ', $spokenby)) . ($html?'</li>':'') . "\n";
465
+            $criteria .= ($html ? '<li>' : '* ') . sprintf(gettext("Things by %s"), implode(' or ', $spokenby)) . ($html ? '</li>' : '') . "\n";
466 466
         }
467 467
         return $criteria;
468 468
     }
Please login to merge, or discard this patch.
www/includes/easyparliament/searchengine.php 2 patches
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     public $valid = false;
38 38
     public $error;
39 39
 
40
-    public function __construct($query, $lang='') {
40
+    public function __construct($query, $lang = '') {
41 41
         if (!defined('XAPIANDB') || !XAPIANDB)
42 42
             return null;
43 43
 
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
         // Split words up into individual words, and quoted phrases
97 97
         preg_match_all('/(' .
98 98
             '"|' . # match either a quote, or...
99
-            '(?:(?<![' .$this->wordchars. '])-)?' . # optionally a - (exclude)
99
+            '(?:(?<![' . $this->wordchars . '])-)?' . # optionally a - (exclude)
100 100
             # if at start of word (i.e. not preceded by a word character, in
101 101
             # which case it is probably a hyphenated-word)
102
-            '['.$this->wordchars.']+' . # followed by a string of word-characters
102
+            '[' . $this->wordchars . ']+' . # followed by a string of word-characters
103 103
             ')/', $this->query, $all_words);
104 104
         if ($all_words) {
105 105
             $all_words = $all_words[0];
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
             if (strpos($word, ':') !== false) {
125 125
                 $items = explode(":", strtolower($word));
126 126
                 $type = $items[0];
127
-                if (substr($type, 0, 1)=='-') $type = substr($type, 1);
128
-                $value = strtolower(join(":", array_slice($items,1)));
127
+                if (substr($type, 0, 1) == '-') $type = substr($type, 1);
128
+                $value = strtolower(join(":", array_slice($items, 1)));
129 129
                 if ($type == 'section') {
130 130
                     $newv = $value;
131 131
                     if ($value == 'debates' || $value == 'debate') $newv = 1;
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
                     elseif ($value == 'sp') $newv = 7;
139 139
                     elseif ($value == 'spwrans' || $value == 'spwran') $newv = 8;
140 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);
141
+                    elseif ($value == 'uk') $newv = array(1, 2, 3, 4, 6, 101);
142
+                    elseif ($value == 'scotland') $newv = array(7, 8);
143 143
                     elseif ($value == 'wales') $newv = ($lang == 'cy' || LANGUAGE == 'cy') ? 11 : 10;
144 144
                     elseif ($value == 'future') $newv = 'F';
145 145
                     if (is_array($newv)) {
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
             $this->query .= " $from..$to";
175 175
         } elseif ($from) {
176 176
             $this->query = str_ireplace("from:$from", '', $this->query);
177
-            $this->query .= " $from..".date('Ymd');
177
+            $this->query .= " $from.." . date('Ymd');
178 178
         } elseif ($to) {
179 179
             $this->query = str_ireplace("to:$to", '', $this->query);
180 180
             $this->query .= " 19990101..$to";
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
         twfy_debug("SEARCH", "prefixed: " . var_export($this->prefixed, true));
193 193
 
194
-        twfy_debug("SEARCH", "query -- ". $this->query);
194
+        twfy_debug("SEARCH", "query -- " . $this->query);
195 195
         $flags = XapianQueryParser::FLAG_BOOLEAN | XapianQueryParser::FLAG_LOVEHATE |
196 196
             XapianQueryParser::FLAG_WILDCARD | XapianQueryParser::FLAG_SPELLING_CORRECTION;
197 197
         $flags = $flags | XapianQueryParser::FLAG_PHRASE;
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
         foreach ($m[1] as $phrase) {
245 245
             $phrase_new = preg_replace('# PHRASE \d+#', '', $phrase);
246 246
             #$this->phrases[] = preg_split('#\s+#', $phrase_new);
247
-            $qd = str_replace("($phrase)", '"'.$phrase_new.'"', $qd);
247
+            $qd = str_replace("($phrase)", '"' . $phrase_new . '"', $qd);
248 248
         }
249 249
         preg_match_all('#\(([^(]*? NEAR [^(]*?)\)#', $qd, $m);
250 250
         foreach ($m[1] as $mm) {
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
     }
375 375
 
376 376
     // Perform partial query to get a count of number of matches
377
-    public function run_count($first_result, $results_per_page, $sort_order='relevance') {
377
+    public function run_count($first_result, $results_per_page, $sort_order = 'relevance') {
378 378
         if (!defined('XAPIANDB') || !XAPIANDB)
379 379
             return null;
380 380
 
@@ -447,13 +447,13 @@  discard block
 block discarded – undo
447 447
         #}
448 448
 
449 449
         $duration = getmicrotime() - $start;
450
-        twfy_debug ("SEARCH", "Search count took $duration seconds.");
450
+        twfy_debug("SEARCH", "Search count took $duration seconds.");
451 451
 
452 452
         return $count;
453 453
     }
454 454
 
455 455
     // Perform the full search...
456
-    public function run_search($first_result, $results_per_page, $sort_order='relevance') {
456
+    public function run_search($first_result, $results_per_page, $sort_order = 'relevance') {
457 457
         $start = getmicrotime();
458 458
 
459 459
         #$matches = $this->enquire->get_mset($first_result, $results_per_page);
@@ -474,13 +474,13 @@  discard block
 block discarded – undo
474 474
                 array_push($this->created, join('', unpack('N', $doc->get_value(2)))); # XXX Needs fixing
475 475
             }
476 476
             twfy_debug("SEARCH", "gid: $gid relevancy: $relevancy% weight: $weight");
477
-            array_push($this->gids, "uk.org.publicwhip/".$gid);
477
+            array_push($this->gids, "uk.org.publicwhip/" . $gid);
478 478
             array_push($this->collapsed, $collapsed);
479 479
             array_push($this->relevances, $relevancy);
480 480
             $iter->next();
481 481
         }
482 482
         $duration = getmicrotime() - $start;
483
-        twfy_debug ("SEARCH", "Run search took $duration seconds.");
483
+        twfy_debug("SEARCH", "Run search took $duration seconds.");
484 484
     }
485 485
     // ... use these to get the results
486 486
     public function get_gids() {
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
         $body = str_replace($this->specialchars, $this->specialchars_upper, $body);
522 522
         $body = mb_convert_encoding($body, "UTF-8", "HTML-ENTITIES");
523 523
         $body = str_replace($this->specialchars_upper, $this->specialchars, $body);
524
-        $splitextract = preg_split('/(<[^>]*>|[0-9,.]+|['.$this->wordcharsnodigit.']+)/', $body, -1, PREG_SPLIT_DELIM_CAPTURE);
524
+        $splitextract = preg_split('/(<[^>]*>|[0-9,.]+|[' . $this->wordcharsnodigit . ']+)/', $body, -1, PREG_SPLIT_DELIM_CAPTURE);
525 525
         $hlextract = "";
526 526
         foreach ($splitextract as $extractword) {
527 527
             if (preg_match('/^<[^>]*>$/', $extractword)) {
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
         */
570 570
 
571 571
         foreach ($this->phrases as $phrase) {
572
-            $phrasematch = join($phrase, '[^'.$this->wordchars.']+');
572
+            $phrasematch = join($phrase, '[^' . $this->wordchars . ']+');
573 573
             array_push($findwords, "/\b($phrasematch)\b(?!(?>[^<>]*>))/i");
574 574
             $replacewords[] = "<span class=\"hi\">\\1</span>";
575 575
         }
@@ -587,12 +587,12 @@  discard block
 block discarded – undo
587 587
 
588 588
         // look for phrases
589 589
         foreach ($this->phrases as $phrase) {
590
-            $phrasematch = join($phrase, '[^'.$this->wordchars.']+');
591
-            if (preg_match('/([^'.$this->wordchars.']' . $phrasematch . '[^A-Za-z0-9])/', $lcbody, $matches))
590
+            $phrasematch = join($phrase, '[^' . $this->wordchars . ']+');
591
+            if (preg_match('/([^' . $this->wordchars . ']' . $phrasematch . '[^A-Za-z0-9])/', $lcbody, $matches))
592 592
             {
593
-                $wordpos = strpos( $lcbody, $matches[0] );
593
+                $wordpos = strpos($lcbody, $matches[0]);
594 594
                 if ($wordpos) {
595
-                    if ( ($wordpos < $pos) || ($pos==-1) ) {
595
+                    if (($wordpos < $pos) || ($pos == -1)) {
596 596
                         $pos = $wordpos;
597 597
                     }
598 598
                 }
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
         }
601 601
         if ($pos != -1) return $pos;
602 602
 
603
-        $splitextract = preg_split('/([0-9,.]+|['.$this->wordcharsnodigit.']+)/', $lcbody, -1, PREG_SPLIT_DELIM_CAPTURE);
603
+        $splitextract = preg_split('/([0-9,.]+|[' . $this->wordcharsnodigit . ']+)/', $lcbody, -1, PREG_SPLIT_DELIM_CAPTURE);
604 604
         $stemmed_words = array_map(array($this, 'stem'), $this->words);
605 605
         foreach ($splitextract as $extractword) {
606 606
             $extractword = preg_replace('/&$/', '', $extractword);
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
             foreach ($stemmed_words as $word) {
611 611
                 if ($word == '') continue;
612 612
                 $matchword = $this->stem($extractword);
613
-                if ($matchword == $word && ($wordpos < $pos || $pos==-1)) {
613
+                if ($matchword == $word && ($wordpos < $pos || $pos == -1)) {
614 614
                     $pos = $wordpos;
615 615
                 }
616 616
             }
@@ -619,11 +619,11 @@  discard block
 block discarded – undo
619 619
         if ($pos != -1) return $pos;
620 620
 
621 621
         foreach ($this->words as $word) {
622
-            if (ctype_digit($word)) $word = '(?:'.$word.'|'.number_format($word).')';
623
-            if (preg_match('/([^'.$this->wordchars.']' . $word . '[^'.$this->wordchars. '])/', $lcbody, $matches)) {
624
-                $wordpos = strpos( $lcbody, $matches[0] );
622
+            if (ctype_digit($word)) $word = '(?:' . $word . '|' . number_format($word) . ')';
623
+            if (preg_match('/([^' . $this->wordchars . ']' . $word . '[^' . $this->wordchars . '])/', $lcbody, $matches)) {
624
+                $wordpos = strpos($lcbody, $matches[0]);
625 625
                 if ($wordpos) {
626
-                    if ( ($wordpos < $pos) || ($pos==-1) ) {
626
+                    if (($wordpos < $pos) || ($pos == -1)) {
627 627
                         $pos = $wordpos;
628 628
                     }
629 629
                 }
@@ -633,11 +633,11 @@  discard block
 block discarded – undo
633 633
         if ($pos != -1) return $pos;
634 634
 
635 635
         foreach ($this->words as $word) {
636
-            if (ctype_digit($word)) $word = '(?:'.$word.'|'.number_format($word).')';
636
+            if (ctype_digit($word)) $word = '(?:' . $word . '|' . number_format($word) . ')';
637 637
             if (preg_match('/(' . $word . ')/', $lcbody, $matches)) {
638
-                $wordpos = strpos( $lcbody, $matches[0] );
638
+                $wordpos = strpos($lcbody, $matches[0]);
639 639
                 if ($wordpos) {
640
-                    if ( ($wordpos < $pos) || ($pos==-1) ) {
640
+                    if (($wordpos < $pos) || ($pos == -1)) {
641 641
                         $pos = $wordpos;
642 642
                     }
643 643
                 }
Please login to merge, or discard this patch.
Braces   +101 added lines, -48 removed lines patch added patch discarded remove patch
@@ -38,8 +38,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
514 548
     private $specialchars_upper = array('&LT;', '&GT;', '&QUOT;', '&AMP;');
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.