Completed
Pull Request — master (#965)
by Nick
24:32
created
www/docs/regmem/index.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -205,6 +205,10 @@
 block discarded – undo
205 205
     return 0;
206 206
 }
207 207
 
208
+/**
209
+ * @param string $file
210
+ * @param string $type
211
+ */
208 212
 function parse_file($file, $date, $type, &$out) {
209 213
     global $cats, $names;
210 214
     preg_match_all('#<regmem personid="uk.org.publicwhip/person/(.*?)" (?:memberid="(.*?)" )?membername="(.*?)" date="(.*?)">(.*?)</regmem>#s', $file, $mm, PREG_SET_ORDER);
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
 rsort($files);
14 14
 
15 15
 if (!DEVSITE) {
16
-   header('Cache-Control: max-age=3600');
16
+    header('Cache-Control: max-age=3600');
17 17
 }
18 18
 
19 19
 $PAGE->page_start();
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 include_once '../../includes/easyparliament/init.php';
4 4
 
5
-$dir = RAWDATA . 'scrapedxml/regmem';
5
+$dir = RAWDATA.'scrapedxml/regmem';
6 6
 $dh = opendir($dir);
7 7
 $files = array();
8 8
 while ($file = readdir($dh)) {
@@ -103,26 +103,26 @@  discard block
 block discarded – undo
103 103
             break;
104 104
         }
105 105
         $date_pre = preg_replace("#$dir/regmem(.*?)\.xml#", '$1', $_);
106
-        $date_post = preg_replace("#$dir/regmem(.*?)\.xml#", '$1', $files[$i+1]);
106
+        $date_post = preg_replace("#$dir/regmem(.*?)\.xml#", '$1', $files[$i + 1]);
107 107
         $pretty = format_date($date_pre, LONGDATEFORMAT);
108 108
         $oout = '';
109 109
         foreach ($data[$_] as $cat_type => $cat_data) {
110
-            $old = array_key_exists($cat_type, $data[$files[$i+1]]) ? $data[$files[$i+1]][$cat_type] : '';
110
+            $old = array_key_exists($cat_type, $data[$files[$i + 1]]) ? $data[$files[$i + 1]][$cat_type] : '';
111 111
             $new = $data[$_][$cat_type];
112 112
             if ($diff = clean_diff($old, $new)) {
113
-                $oout .= cat_heading($cat_type, $date_pre, $date_post) . $diff;
113
+                $oout .= cat_heading($cat_type, $date_pre, $date_post).$diff;
114 114
             }
115 115
         }
116
-        foreach ($data[$files[$i+1]] as $cat_type => $cat_data) {
116
+        foreach ($data[$files[$i + 1]] as $cat_type => $cat_data) {
117 117
             if (array_key_exists($cat_type, $data[$_])) {
118 118
                 continue;
119 119
             }
120
-            if ($diff = clean_diff($data[$files[$i+1]][$cat_type], '')) {
121
-                $oout .= cat_heading($cat_type, $date_pre, $date_post) . $diff;
120
+            if ($diff = clean_diff($data[$files[$i + 1]][$cat_type], '')) {
121
+                $oout .= cat_heading($cat_type, $date_pre, $date_post).$diff;
122 122
             }
123 123
         }
124 124
         if ($oout) {
125
-            $out .= span_row("<h2>$pretty - <a href=\"./?d=$date_pre#$p\">View full entry</a></h2>", true) . $oout;
125
+            $out .= span_row("<h2>$pretty - <a href=\"./?d=$date_pre#$p\">View full entry</a></h2>", true).$oout;
126 126
         }
127 127
     }
128 128
     $_ = $earliest;
@@ -148,14 +148,14 @@  discard block
 block discarded – undo
148 148
     $new = 0;
149 149
     if ($f) {
150 150
         $f = "$dir/regmem$f.xml";
151
-        for ($i=0; $i<count($files); ++$i) {
151
+        for ($i = 0; $i < count($files); ++$i) {
152 152
             if ($files[$i] == $f) {
153 153
                 $new = $i;
154 154
                 break;
155 155
             }
156 156
         }
157 157
     }
158
-    $old = $new+1;
158
+    $old = $new + 1;
159 159
     $old = $files[$old];
160 160
     $old_iso = preg_replace("#$dir/regmem(.*?)\.xml#", '$1', $old);
161 161
     $old_pretty = format_date($old_iso, LONGDATEFORMAT);
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
             $out .= clean_diff($old, $new);
188 188
         }
189 189
         if ($out) {
190
-            print span_row('<h2>'.$names[$person_id].' - <a href="?p='.$person_id.'">Register history</a> | <a href="/mp/?pid='.$person_id.'">MP&rsquo;s page</a></h2>', true) . $out;
190
+            print span_row('<h2>'.$names[$person_id].' - <a href="?p='.$person_id.'">Register history</a> | <a href="/mp/?pid='.$person_id.'">MP&rsquo;s page</a></h2>', true).$out;
191 191
         }
192 192
     }
193 193
     print '</table>';
@@ -237,27 +237,27 @@  discard block
 block discarded – undo
237 237
     }
238 238
     $c = 0; $year = 0;
239 239
     $view = ''; $compare = '';
240
-    for ($i=0; $i<count($files); ++$i) {
240
+    for ($i = 0; $i < count($files); ++$i) {
241 241
         preg_match('/(\d\d\d\d)-(\d\d-\d\d)/', $files[$i], $m);
242 242
         $y = $m[1]; $md = $m[2];
243 243
         if ($c++) {
244 244
             $view .= ' | ';
245
-            if ($i<count($files)-1) {
245
+            if ($i < count($files) - 1) {
246 246
                 $compare .= ' | ';
247 247
             }
248 248
         }
249 249
         if ($year != $y) {
250 250
             $year = $y;
251 251
             $view .= "<em>$year</em> ";
252
-            if ($i<count($files)-1) {
252
+            if ($i < count($files) - 1) {
253 253
                 $compare .= "<em>$year</em> ";
254 254
             }
255 255
         }
256 256
         $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
257 257
         preg_match('/(\d\d)-(\d\d)/', $md, $m);
258
-        $date = ($m[2]+0) . ' '. $months[$m[1]-1];
258
+        $date = ($m[2] + 0).' '.$months[$m[1] - 1];
259 259
         $view .= '<a href="./?d='.$y.'-'.$md.'">'.$date.'</a>';
260
-        if ($i<count($files)-1) {
260
+        if ($i < count($files) - 1) {
261 261
             $compare .= '<a href="?f='.$y.'-'.$md.'">'.$date.'</a>';
262 262
         }
263 263
     }
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
     $data = array();
293 293
     parse_file($d, $d_iso, 'only', $data);
294 294
     $this_page = 'regmem_date';
295
-    $DATA->set_page_metadata($this_page, 'heading', "The Register of Members' Interests, $d_pretty");;
295
+    $DATA->set_page_metadata($this_page, 'heading', "The Register of Members' Interests, $d_pretty"); ;
296 296
     $PAGE->stripe_start();
297 297
     print $link;
298 298
 ?>
@@ -310,9 +310,9 @@  discard block
 block discarded – undo
310 310
         }
311 311
         if ($out) {
312 312
             print '<div class="block">';
313
-            print '<h2><a name="' . $person_id . '"></a>' . $names[$person_id] . ' - ';
314
-            print '<a href="?p=' . $person_id . '">Register history</a> | ';
315
-            print '<a href="/mp/?pid=' . $person_id . '">MP&rsquo;s page</a>';
313
+            print '<h2><a name="'.$person_id.'"></a>'.$names[$person_id].' - ';
314
+            print '<a href="?p='.$person_id.'">Register history</a> | ';
315
+            print '<a href="/mp/?pid='.$person_id.'">MP&rsquo;s page</a>';
316 316
             print '</h2> <div class="blockbody">';
317 317
             print "\n$out";
318 318
             print '</div></div>';
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 
344 344
 function _clean($s) {
345 345
     $s = preg_replace("/&(pound|#163);/", "\xa3", $s);
346
-    $s = preg_replace("#</?(span|i|em)( [^>]*)?" . ">#i", '', $s);
346
+    $s = preg_replace("#</?(span|i|em)( [^>]*)?".">#i", '', $s);
347 347
     $s = utf8_encode($s);
348 348
     $s = preg_split("/\s*\n\s*/", $s);
349 349
     return $s;
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
     }
360 360
     $r = join("\n", $r); $r = $r ? '<td class="r"><ul>'.$r.'</ul></td>' : '<td>&nbsp;</td>';
361 361
     $a = join("\n", $a); $a = $a ? '<td class="a"><ul>'.$a.'</ul></td>' : '<td>&nbsp;</td>';
362
-    $diff = '<tr>' . $r . $a . '</tr>';
362
+    $diff = '<tr>'.$r.$a.'</tr>';
363 363
     $diff = preg_replace('#<item.*?>(.*?)</item>#', '<li>$1</li>', $diff);
364 364
     return $diff;
365 365
 }
Please login to merge, or discard this patch.
www/docs/video/index.php 3 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -342,6 +342,9 @@  discard block
 block discarded – undo
342 342
     echo '</ul></div>';
343 343
 }
344 344
 
345
+/**
346
+ * @param integer $limit
347
+ */
345 348
 function display_league($limit, $q = '') {
346 349
     global $THEUSER;
347 350
     $db = new ParlDB;
@@ -468,6 +471,9 @@  discard block
 block discarded – undo
468 471
     echo '</ol>';
469 472
 }
470 473
 
474
+/**
475
+ * @param integer $count
476
+ */
471 477
 function disp_speech($row, $count) {
472 478
     echo '<li';
473 479
     if ($row['htype']==13) echo ' class="unspoken"';
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 $parent_body = $q->field(0, 'parent_body');
55 55
 $parent_epid = $q->field(0, 'subsection_id');
56 56
 
57
-if (!($video_status&1) || ($video_status&8)) {
57
+if (!($video_status & 1) || ($video_status & 8)) {
58 58
     $PAGE->error_message('That GID does not appear to have any video. Please visit the <a href="/video/">video front page</a>.', true, 404);
59 59
     exit;
60 60
 }
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 $gids_previous = array();
88 88
 $gids_following = array();
89 89
 $gid_actual = array();
90
-for ($i=0; $i<$q->rows(); $i++) {
90
+for ($i = 0; $i < $q->rows(); $i++) {
91 91
     $row = $q->row($i);
92 92
     if ($row['adate']) $row['hdate'] = $row['adate'];
93 93
     if ($row['atime']) $row['htime'] = $row['atime'];
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 <?php
180 180
     $hidden_int = (isset($_COOKIE['hideVideoInt']) && $_COOKIE['hideVideoInt']);
181 181
     echo '<table id="video_table" border="0" cellspacing="0" cellpadding="5"><tr valign="top"><td width="50%">';
182
-    if ($gid_actual['video_status']&4) {
182
+    if ($gid_actual['video_status'] & 4) {
183 183
         $q = $db->query("select timediff(current_timestamp,max(whenstamped)) as ws from video_timestamps where gid='$q_gid' and (user_id is null or user_id != -1) and deleted=0");
184 184
         $max = $q->field(0, 'ws');
185 185
         echo '<p class="informational">Thanks, but this speech has <strong>already been stamped</strong>';
@@ -240,13 +240,13 @@  discard block
 block discarded – undo
240 240
     $q = $db->query('select video_status&4 as checked,count(*) as c from hansard
241 241
     where major=1 and video_status>0 and video_status<8 and video_status!=2 and htype in (12,13) group by video_status&4');
242 242
     $totaliser = array(0=>0, 4=>0);
243
-    for ($i=0; $i<$q->rows(); $i++) {
243
+    for ($i = 0; $i < $q->rows(); $i++) {
244 244
         $status = $q->field($i, 'checked');
245 245
         $count = $q->field($i, 'c');
246 246
         $totaliser[$status] = $count;
247 247
     }
248
-    $percentage = round($totaliser[4] / ($totaliser[0]+$totaliser[4]) * 10000) / 100;
249
-    $out = "$totaliser[4] timestamped out of " . ($totaliser[0] + $totaliser[4]) . " ($percentage%)"
248
+    $percentage = round($totaliser[4] / ($totaliser[0] + $totaliser[4]) * 10000) / 100;
249
+    $out = "$totaliser[4] timestamped out of ".($totaliser[0] + $totaliser[4])." ($percentage%)"
250 250
 ?>
251 251
 
252 252
 <p style="margin-top:1em"><big>TheyWorkForYou has video of the House of Commons from the BBC, and
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
         and hdate=(select max(hdate) from hansard where major=1)
302 302
     group by video_status&4');
303 303
     $totaliser = array(0=>0, 4=>0);
304
-    for ($i=0; $i<$q->rows(); $i++) {
304
+    for ($i = 0; $i < $q->rows(); $i++) {
305 305
         $status = $q->field($i, 'checked');
306 306
         $count = $q->field($i, 'c');
307 307
         $totaliser[$status] = $count;
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
     where (user_id != -1 or user_id is null) and video_timestamps.deleted=0
329 329
         and video_timestamps.gid = hansard.gid and hansard.subsection_id = epobject.epobject_id
330 330
     order by whenstamped desc limit 20');
331
-    for ($i=0; $i<$q->rows(); $i++) {
331
+    for ($i = 0; $i < $q->rows(); $i++) {
332 332
         $gid = $q->field($i, 'gid');
333 333
         $body = $q->field($i, 'body');
334 334
         if ($q->field($i, 'major') == 101) {
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
         } else {
337 337
             $url = '/debate/?id=';
338 338
         }
339
-        echo '<li><a href="', $url, fix_gid_from_db($gid) . '">' . $body . '</a>';
339
+        echo '<li><a href="', $url, fix_gid_from_db($gid).'">'.$body.'</a>';
340 340
     }
341 341
 
342 342
     echo '</ul></div>';
@@ -348,18 +348,18 @@  discard block
 block discarded – undo
348 348
     $q = $db->query('select firstname,lastname,video_timestamps.user_id,count(*) as c
349 349
         from video_timestamps left join users on video_timestamps.user_id=users.user_id
350 350
         where video_timestamps.deleted=0 and (video_timestamps.user_id is null or video_timestamps.user_id!=-1) '
351
-        . $q . ' group by user_id order by c desc' . ($THEUSER->user_id() ? '' : " limit $limit") );
351
+        . $q.' group by user_id order by c desc'.($THEUSER->user_id() ? '' : " limit $limit"));
352 352
     $out = ''; $rank = 0;
353
-    for ($i=0; $i<$q->rows(); $i++) {
354
-        $name = $q->field($i, 'firstname') . ' ' . $q->field($i, 'lastname');
353
+    for ($i = 0; $i < $q->rows(); $i++) {
354
+        $name = $q->field($i, 'firstname').' '.$q->field($i, 'lastname');
355 355
         $user_id = $q->field($i, 'user_id');
356 356
         #if ($user_id == -1) continue; # $name = 'CaptionerBot';
357 357
         if ($user_id == 0) $name = 'Anonymous';
358 358
         $count = $q->field($i, 'c');
359 359
         if ($THEUSER->user_id() == $user_id) {
360
-            $rank = $i+1;
360
+            $rank = $i + 1;
361 361
         }
362
-        if ($i>=$limit) continue;
362
+        if ($i >= $limit) continue;
363 363
         $out .= '<li>';
364 364
         if ($THEUSER->user_id() == $user_id)
365 365
             $out .= '<strong>';
@@ -376,9 +376,9 @@  discard block
 block discarded – undo
376 376
 function video_quote($gid_actual, $parent_gid, $parent_body) {
377 377
     #echo '<h4>Press &ldquo;Play&rdquo;, then click &ldquo;Now!&rdquo; when you hear:</h4>';
378 378
     echo '<div id="video_quote">';
379
-    echo '<span class="video_name">' . $gid_actual['given_name'] . ' ' . $gid_actual['family_name'] . '</span> ';
379
+    echo '<span class="video_name">'.$gid_actual['given_name'].' '.$gid_actual['family_name'].'</span> ';
380 380
     echo $gid_actual['body_first'];
381
-    echo '<p align="right">&mdash; from debate entitled &ldquo;<a title="View entire debate" href="' . $parent_gid . '">' . $parent_body . '</a>&rdquo;</p>';
381
+    echo '<p align="right">&mdash; from debate entitled &ldquo;<a title="View entire debate" href="'.$parent_gid.'">'.$parent_body.'</a>&rdquo;</p>';
382 382
     echo '</div>';
383 383
 }
384 384
 
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 <?php	} ?>
413 413
 <li>If the video suddenly <strong>jumps</strong> a couple of hours, or otherwise appears broken, <a href="mailto:<?=str_replace('@', '&#64;', CONTACTEMAIL) ?>?subject=Video%20<?=$file?>%20for%20ID%20<?=$gid_safe?>%20broken">let us know</a>.
414 414
 <li>If the speech you're looking for is <strong>beyond the end</strong> of the video,
415
-<a href="/video/?gid=<?=$gid_safe?>&amp;file=<?=$file+1?>&amp;start=1<?=$pid_url?>">move on to the next video chunk</a>.
415
+<a href="/video/?gid=<?=$gid_safe?>&amp;file=<?=$file + 1?>&amp;start=1<?=$pid_url?>">move on to the next video chunk</a>.
416 416
 <li>If you're right at the start of a day, it's quite possible the start of the video
417 417
 will be the end of the previous programme on BBC Parliament, skip ahead some minutes
418 418
 to check :)
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
 <a href="/user/login/?ret=/video/">Log in</a> |
444 444
 <?php	} ?>
445 445
 <a href="mailto:<?=str_replace('@', '&#64;', CONTACTEMAIL) ?>?subject=Video%20<?=$file?>%20for%20ID%20<?=$gid_safe?>%20broken">Broken video</a> |
446
-<a href="/video/?gid=<?=$gid_safe?>&amp;file=<?=$file+1?>&amp;start=1<?=$pid_url?>" title="Loads the next video chunk">Speech past end of video</a>
446
+<a href="/video/?gid=<?=$gid_safe?>&amp;file=<?=$file + 1?>&amp;start=1<?=$pid_url?>" title="Loads the next video chunk">Speech past end of video</a>
447 447
 </p>
448 448
 
449 449
 <p align="right"><small><!-- <b>Credits:</b> Video from <a href='http://www.bbc.co.uk/parliament/'>BBC Parliament</a> and mySociety. -->
@@ -470,14 +470,14 @@  discard block
 block discarded – undo
470 470
 
471 471
 function disp_speech($row, $count) {
472 472
     echo '<li';
473
-    if ($row['htype']==13) echo ' class="unspoken"';
474
-    elseif ($row['htype']<12) echo ' class="heading"';
475
-    if (!($count%2)) echo ' style="background-color: #F5FDEA;"';
473
+    if ($row['htype'] == 13) echo ' class="unspoken"';
474
+    elseif ($row['htype'] < 12) echo ' class="heading"';
475
+    if (!($count % 2)) echo ' style="background-color: #F5FDEA;"';
476 476
     else echo ' style="background-color: #E8FDCB;"';
477 477
     echo '>';
478 478
     if ($count) echo "<em>$count earlier:</em> ";
479
-    if ($row['htype']==12)
480
-        echo '<span class="video_name">' . $row['given_name'] . ' ' . $row['family_name'] . '</span> ';
479
+    if ($row['htype'] == 12)
480
+        echo '<span class="video_name">'.$row['given_name'].' '.$row['family_name'].'</span> ';
481 481
     echo $row['body'];
482 482
     echo '</li>';
483 483
 }
Please login to merge, or discard this patch.
Braces   +80 added lines, -33 removed lines patch added patch discarded remove patch
@@ -47,8 +47,12 @@  discard block
 block discarded – undo
47 47
 $htime = $q->field(0, 'htime');
48 48
 $atime = $q->field(0, 'atime');
49 49
 $adate = $q->field(0, 'adate');
50
-if ($atime) $htime = $atime;
51
-if ($adate) $hdate = $adate;
50
+if ($atime) {
51
+    $htime = $atime;
52
+}
53
+if ($adate) {
54
+    $hdate = $adate;
55
+}
52 56
 $parent_gid = str_replace('uk.org.publicwhip/debate/', '/debates/?id=', $q->field(0, 'parent_gid'));
53 57
 $parent_gid = str_replace('uk.org.publicwhip/lords/', '/lords/?gid=', $parent_gid);
54 58
 $parent_body = $q->field(0, 'parent_body');
@@ -89,8 +93,12 @@  discard block
 block discarded – undo
89 93
 $gid_actual = array();
90 94
 for ($i=0; $i<$q->rows(); $i++) {
91 95
     $row = $q->row($i);
92
-    if ($row['adate']) $row['hdate'] = $row['adate'];
93
-    if ($row['atime']) $row['htime'] = $row['atime'];
96
+    if ($row['adate']) {
97
+        $row['hdate'] = $row['adate'];
98
+    }
99
+    if ($row['atime']) {
100
+        $row['htime'] = $row['atime'];
101
+    }
94 102
     if ($row['hpos'] < $hpos) {
95 103
         $gids_previous[] = $row;
96 104
     } elseif ($row['hpos'] > $hpos) {
@@ -134,14 +142,20 @@  discard block
 block discarded – undo
134 142
 }
135 143
 $video = \MySociety\TheyWorkForYou\Utility\Video::fromTimestamp($videodb, $hdate, $htime);
136 144
 
137
-if (!$start)
145
+if (!$start) {
138 146
     $start = $video['offset'] - $offset;
139
-if ($start < 0) $start = 0;
147
+}
148
+if ($start < 0) {
149
+    $start = 0;
150
+}
140 151
 
141
-if (get_http_var('barcamp'))
152
+if (get_http_var('barcamp')) {
142 153
     $video['id'] -= 4000;
154
+}
143 155
 
144
-if (!$file) $file = $video['id'];
156
+if (!$file) {
157
+    $file = $video['id'];
158
+}
145 159
 
146 160
 # Start displaying
147 161
 
@@ -280,14 +294,26 @@  discard block
 block discarded – undo
280 294
     global $THEUSER;
281 295
     if ($THEUSER->user_id() && ($rank_today || $rank_week || $rank_overall)) {
282 296
         echo '<p align="center"><big>You are ';
283
-        if ($rank_today) echo make_ranking($rank_today), ' today, ';
284
-        if ($rank_week) echo make_ranking($rank_week), ' last 4 weeks, ';
285
-        if ($rank_overall) echo make_ranking($rank_overall), ' overall';
297
+        if ($rank_today) {
298
+            echo make_ranking($rank_today), ' today, ';
299
+        }
300
+        if ($rank_week) {
301
+            echo make_ranking($rank_week), ' last 4 weeks, ';
302
+        }
303
+        if ($rank_overall) {
304
+            echo make_ranking($rank_overall), ' overall';
305
+        }
286 306
         echo '</big></p>';
287 307
     }
288
-    if ($out_today) echo "<h3>Top timestampers (today)</h3> <ol>$out_today</ol>";
289
-    if ($out_week) echo "<h3>Top timestampers (last 4 weeks)</h3> <ol>$out_week</ol>";
290
-    if ($out_overall) echo "<h3>Top timestampers (overall)</h3> <ol>$out_overall</ol>";
308
+    if ($out_today) {
309
+        echo "<h3>Top timestampers (today)</h3> <ol>$out_today</ol>";
310
+    }
311
+    if ($out_week) {
312
+        echo "<h3>Top timestampers (last 4 weeks)</h3> <ol>$out_week</ol>";
313
+    }
314
+    if ($out_overall) {
315
+        echo "<h3>Top timestampers (overall)</h3> <ol>$out_overall</ol>";
316
+    }
291 317
     echo '</div>';
292 318
 ?>
293 319
 <div style="float: right; width: 50%">
@@ -354,18 +380,24 @@  discard block
 block discarded – undo
354 380
         $name = $q->field($i, 'firstname') . ' ' . $q->field($i, 'lastname');
355 381
         $user_id = $q->field($i, 'user_id');
356 382
         #if ($user_id == -1) continue; # $name = 'CaptionerBot';
357
-        if ($user_id == 0) $name = 'Anonymous';
383
+        if ($user_id == 0) {
384
+            $name = 'Anonymous';
385
+        }
358 386
         $count = $q->field($i, 'c');
359 387
         if ($THEUSER->user_id() == $user_id) {
360 388
             $rank = $i+1;
361 389
         }
362
-        if ($i>=$limit) continue;
390
+        if ($i>=$limit) {
391
+            continue;
392
+        }
363 393
         $out .= '<li>';
364
-        if ($THEUSER->user_id() == $user_id)
365
-            $out .= '<strong>';
394
+        if ($THEUSER->user_id() == $user_id) {
395
+                    $out .= '<strong>';
396
+        }
366 397
         $out .= "$name : $count";
367
-        if ($THEUSER->user_id() == $user_id)
368
-            $out .= '</strong>';
398
+        if ($THEUSER->user_id() == $user_id) {
399
+                    $out .= '</strong>';
400
+        }
369 401
         #if ($user_id == -1) {
370 402
         #	echo ' <small>(initial run program that tries to guess timestamp from captions, wildly variable)</small>';
371 403
         #}
@@ -384,8 +416,10 @@  discard block
 block discarded – undo
384 416
 
385 417
 function basic_instructions($pid) {
386 418
     $pid_url = '';
387
-    if ($pid) $pid_url = "&amp;pid=$pid";
388
-?>
419
+    if ($pid) {
420
+        $pid_url = "&amp;pid=$pid";
421
+    }
422
+    ?>
389 423
 <ol style="font-size: 150%;">
390 424
 <li>Have a quick scan of the speech under the video, then press &ldquo;Play&rdquo;.
391 425
 <li>When you hear the start of that speech, press &ldquo;Now!&rdquo;.
@@ -403,8 +437,10 @@  discard block
 block discarded – undo
403 437
 function basic_hints($gid_safe, $file, $pid) {
404 438
     global $THEUSER;
405 439
     $pid_url = '';
406
-    if ($pid) $pid_url = "&amp;pid=$pid";
407
-?>
440
+    if ($pid) {
441
+        $pid_url = "&amp;pid=$pid";
442
+    }
443
+    ?>
408 444
 
409 445
 <ul>
410 446
 <?php	if (!$THEUSER->loggedin()) { ?>
@@ -434,8 +470,10 @@  discard block
 block discarded – undo
434 470
 function advanced_hints($gid_safe, $file, $pid) {
435 471
     global $THEUSER;
436 472
     $pid_url = '';
437
-    if ($pid) $pid_url = "&amp;pid=$pid";
438
-?>
473
+    if ($pid) {
474
+        $pid_url = "&amp;pid=$pid";
475
+    }
476
+    ?>
439 477
 
440 478
 <p align="center">Actions:
441 479
 <a href="/video/next.php?action=random">Skip</a> |
@@ -470,14 +508,23 @@  discard block
 block discarded – undo
470 508
 
471 509
 function disp_speech($row, $count) {
472 510
     echo '<li';
473
-    if ($row['htype']==13) echo ' class="unspoken"';
474
-    elseif ($row['htype']<12) echo ' class="heading"';
475
-    if (!($count%2)) echo ' style="background-color: #F5FDEA;"';
476
-    else echo ' style="background-color: #E8FDCB;"';
511
+    if ($row['htype']==13) {
512
+        echo ' class="unspoken"';
513
+    } elseif ($row['htype']<12) {
514
+        echo ' class="heading"';
515
+    }
516
+    if (!($count%2)) {
517
+        echo ' style="background-color: #F5FDEA;"';
518
+    } else {
519
+        echo ' style="background-color: #E8FDCB;"';
520
+    }
477 521
     echo '>';
478
-    if ($count) echo "<em>$count earlier:</em> ";
479
-    if ($row['htype']==12)
480
-        echo '<span class="video_name">' . $row['given_name'] . ' ' . $row['family_name'] . '</span> ';
522
+    if ($count) {
523
+        echo "<em>$count earlier:</em> ";
524
+    }
525
+    if ($row['htype']==12) {
526
+            echo '<span class="video_name">' . $row['given_name'] . ' ' . $row['family_name'] . '</span> ';
527
+    }
481 528
     echo $row['body'];
482 529
     echo '</li>';
483 530
 }
Please login to merge, or discard this patch.
www/includes/data.php 2 patches
Doc Comments   +8 added lines patch added patch discarded remove patch
@@ -95,6 +95,10 @@  discard block
 block discarded – undo
95 95
     // Getting page and section metadata
96 96
     // $page/$section is a page name.
97 97
     // $key is the element of metadata you want to retrieve.
98
+
99
+    /**
100
+     * @param string $key
101
+     */
98 102
     public function page_metadata($page, $key) {
99 103
         return $this->_get_metadata(array("page"=>$page, "key"=>$key), "page");
100 104
     }
@@ -145,6 +149,10 @@  discard block
 block discarded – undo
145 149
 ///////////////////////////////////////
146 150
 
147 151
     // Only accessed through page_metadata() or section_metadata()
152
+
153
+    /**
154
+     * @param string $type
155
+     */
148 156
     public function _get_metadata($args="", $type) {
149 157
         // $type is either 'page' or 'section'
150 158
         global $this_page, $this_section;
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 
76 76
     public function __construct() {
77 77
 
78
-        include_once METADATAPATH;	// defined in config.php
78
+        include_once METADATAPATH; // defined in config.php
79 79
 
80 80
     }
81 81
 
@@ -108,11 +108,11 @@  discard block
 block discarded – undo
108 108
     // Setting page and section.
109 109
     // $page/$section, $key and $value should make sense...
110 110
     public function set_page_metadata($page, $key, $value) {
111
-        $this->_set_metadata(array("page"=>$page,"key"=>$key,"value"=>$value));
111
+        $this->_set_metadata(array("page"=>$page, "key"=>$key, "value"=>$value));
112 112
     }
113 113
 
114 114
     public function set_section_metadata($section, $key, $value) {
115
-        $this->_set_metadata(array("section"=>$section,"key"=>$key,"value"=>$value));
115
+        $this->_set_metadata(array("section"=>$section, "key"=>$key, "value"=>$value));
116 116
     }
117 117
 
118 118
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
     // Test for the presence of something.
132 132
     // eg $exists = $DATA->test_for_metadata("page", "about", "title")
133 133
     public function test_for_metadata($type, $item, $key) {
134
-        $dataarray =& $this->$type;
134
+        $dataarray = & $this->$type;
135 135
 
136 136
         if (isset($dataarray[$item][$key])) {
137 137
             return true;
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 ///////////////////////////////////////
146 146
 
147 147
     // Only accessed through page_metadata() or section_metadata()
148
-    public function _get_metadata($args="", $type) {
148
+    public function _get_metadata($args = "", $type) {
149 149
         // $type is either 'page' or 'section'
150 150
         global $this_page, $this_section;
151 151
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
         }
160 160
 
161 161
         twfy_debug("DATA", "$type: $item, $key");
162
-        $dataarray =& $this->$type;
162
+        $dataarray = & $this->$type;
163 163
 
164 164
         if ($this->test_for_metadata($type, $item, $key)) {
165 165
             $return = $dataarray[$item][$key];
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
             $debugtext = "No metadata found for key '$key'";
175 175
         }
176 176
 
177
-        twfy_debug("DATA", "$debugtext, returning '" . (is_scalar($return) ? $return : gettype($return)) . "'.");
177
+        twfy_debug("DATA", "$debugtext, returning '".(is_scalar($return) ? $return : gettype($return))."'.");
178 178
 
179 179
         return $return;
180 180
     }
@@ -192,9 +192,9 @@  discard block
 block discarded – undo
192 192
         $key = $args["key"];
193 193
         $value = $args["value"];
194 194
 
195
-        twfy_debug("DATA", "Setting: ".$type."[".$item."][".$key."] = '" . print_r($value, 1) . "'");
195
+        twfy_debug("DATA", "Setting: ".$type."[".$item."][".$key."] = '".print_r($value, 1)."'");
196 196
 
197
-        $dataarray =& $this->$type;
197
+        $dataarray = & $this->$type;
198 198
         $dataarray[$item][$key] = $value;
199 199
     }
200 200
 
Please login to merge, or discard this patch.
www/includes/easyparliament/alert.php 4 patches
Doc Comments   +11 added lines patch added patch discarded remove patch
@@ -51,6 +51,10 @@  discard block
 block discarded – undo
51 51
 
52 52
 // FUNCTION: fetch_between
53 53
 
54
+    /**
55
+     * @param integer $confirmed
56
+     * @param integer $deleted
57
+     */
54 58
     public function fetch_between($confirmed, $deleted, $start_date, $end_date) {
55 59
       // Return summary data on all the alerts that were created between $start_date
56 60
       // and $end_date (inclusive) and whose confirmed and deleted values match the booleans
@@ -79,6 +83,10 @@  discard block
 block discarded – undo
79 83
 
80 84
 // FUNCTION: fetch
81 85
 
86
+    /**
87
+     * @param integer $confirmed
88
+     * @param integer $deleted
89
+     */
82 90
     public function fetch($confirmed, $deleted) {
83 91
         // Pass it an alert id and it will fetch data about alerts from the db
84 92
         // and put it all in the appropriate variables.
@@ -320,6 +328,9 @@  discard block
 block discarded – undo
320 328
         }
321 329
     }
322 330
 
331
+    /**
332
+     * @param string $email
333
+     */
323 334
     public function email_exists($email) {
324 335
         // Returns true if there's a user with this email address.
325 336
 
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,9 +52,9 @@  discard block
 block discarded – undo
52 52
 // FUNCTION: fetch_between
53 53
 
54 54
     public function fetch_between($confirmed, $deleted, $start_date, $end_date) {
55
-      // Return summary data on all the alerts that were created between $start_date
56
-      // and $end_date (inclusive) and whose confirmed and deleted values match the booleans
57
-      // passed in $confirmed and $deleted
55
+        // Return summary data on all the alerts that were created between $start_date
56
+        // and $end_date (inclusive) and whose confirmed and deleted values match the booleans
57
+        // passed in $confirmed and $deleted
58 58
         $q = $this->db->query("SELECT   criteria, count(*) as cnt
59 59
             FROM     alerts
60 60
             WHERE    confirmed = :confirmed
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
             ));
70 70
         $data = array();
71 71
     for ($row=0; $row<$q->rows(); $row++) {
72
-      $contents = array('criteria' => $q->field($row, 'criteria'), 'count' => $q->field($row, 'cnt'));
73
-          $data[] = $contents;
72
+        $contents = array('criteria' => $q->field($row, 'criteria'), 'count' => $q->field($row, 'cnt'));
73
+            $data[] = $contents;
74 74
     }
75 75
     $data = array ('alerts' => $data);
76 76
 
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 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
 
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
             ':end_date' => $end_date
69 69
             ));
70 70
         $data = array();
71
-    for ($row=0; $row<$q->rows(); $row++) {
71
+    for ($row = 0; $row < $q->rows(); $row++) {
72 72
       $contents = array('criteria' => $q->field($row, 'criteria'), 'count' => $q->field($row, 'cnt'));
73 73
           $data[] = $contents;
74 74
     }
75
-    $data = array ('alerts' => $data);
75
+    $data = array('alerts' => $data);
76 76
 
77 77
     return $data;
78 78
     }
@@ -94,13 +94,13 @@  discard block
 block discarded – undo
94 94
                         deleted,
95 95
                         confirmed
96 96
                         FROM alerts
97
-                        WHERE confirmed =" . $confirmed .
98
-                        " AND deleted=" . $deleted .
97
+                        WHERE confirmed =" . $confirmed.
98
+                        " AND deleted=".$deleted.
99 99
                         ' ORDER BY email');
100 100
 
101 101
         $data = array();
102 102
 
103
-            for ($row=0; $row<$q->rows(); $row++) {
103
+            for ($row = 0; $row < $q->rows(); $row++) {
104 104
                 $contents = array(
105 105
                 'alert_id' 	=> $q->field($row, 'alert_id'),
106 106
                 'email' 	=> $q->field($row, 'email'),
@@ -112,13 +112,13 @@  discard block
 block discarded – undo
112 112
                 $data[] = $contents;
113 113
             }
114 114
             $info = "Alert";
115
-            $data = array ('info' => $info, 'data' => $data);
115
+            $data = array('info' => $info, 'data' => $data);
116 116
 
117 117
 
118 118
             return $data;
119 119
     }
120 120
 
121
-    public function add($details, $confirmation_email=false, $instantly_confirm=true) {
121
+    public function add($details, $confirmation_email = false, $instantly_confirm = true) {
122 122
 
123 123
         // Adds a new alert's info into the database.
124 124
         // Then calls another function to send them a confirmation email.
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
             // This gives a code for their email address which is then joined
183 183
             // to the timestamp so as to provide a unique ID for each alert.
184 184
 
185
-            $token = substr( password_hash($details["email"] . microtime(), PASSWORD_BCRYPT), 29, 16 );
185
+            $token = substr(password_hash($details["email"].microtime(), PASSWORD_BCRYPT), 29, 16);
186 186
 
187 187
             // Full stops don't work well at the end of URLs in emails,
188 188
             // so replace them. We won't be doing anything clever with the hash
@@ -253,21 +253,21 @@  discard block
 block discarded – undo
253 253
         // We prefix the registration token with the alert's id and '-'.
254 254
         // Not for any particularly good reason, but we do.
255 255
 
256
-        $urltoken = $this->alert_id . '-' . $this->registrationtoken;
256
+        $urltoken = $this->alert_id.'-'.$this->registrationtoken;
257 257
 
258
-        if ( isset($details['confirm_base']) && $details['confirm_base'] !== '' ) {
259
-            $confirmurl = $details['confirm_base'] . $urltoken;
258
+        if (isset($details['confirm_base']) && $details['confirm_base'] !== '') {
259
+            $confirmurl = $details['confirm_base'].$urltoken;
260 260
         } else {
261
-            $confirmurl = 'https://' . DOMAIN . '/A/' . $urltoken;
261
+            $confirmurl = 'https://'.DOMAIN.'/A/'.$urltoken;
262 262
         }
263 263
 
264 264
         // Arrays we need to send a templated email.
265
-        $data = array (
265
+        $data = array(
266 266
             'to' 		=> $details['email'],
267 267
             'template' 	=> 'alert_confirmation'
268 268
         );
269 269
 
270
-        $merge = array (
270
+        $merge = array(
271 271
             'FIRSTNAME' 	=> 'THEY WORK FOR YOU',
272 272
             'LASTNAME' 		=> ' ALERT CONFIRMATION',
273 273
             'CONFIRMURL'	=> $confirmurl,
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
     }
284 284
 
285 285
     public function send_already_signedup_email($details) {
286
-        $data = array (
286
+        $data = array(
287 287
             'to' 		=> $details['email'],
288 288
             'template' 	=> 'alert_already_signedup'
289 289
         );
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
         $criteria = \MySociety\TheyWorkForYou\Utility\Alert::detailsToCriteria($details);
292 292
         $this->criteria = $criteria;
293 293
 
294
-        $merge = array (
294
+        $merge = array(
295 295
             'FIRSTNAME' 	=> 'THEY WORK FOR YOU',
296 296
             'LASTNAME' 		=> ' ALERT ALREADY SIGNED UP',
297 297
             'CRITERIA'	=> $this->criteria_pretty()
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
             AND email = :email
312 312
             AND criteria = :criteria", array(
313 313
                 ':email' => $email,
314
-                ':criteria' => 'speaker:' . $pid
314
+                ':criteria' => 'speaker:'.$pid
315 315
             ));
316 316
         if ($q->rows() > 0) {
317 317
             return true;
@@ -442,17 +442,17 @@  discard block
 block discarded – undo
442 442
     public function email() { return $this->email; }
443 443
     public function criteria() { return $this->criteria; }
444 444
     public function criteria_pretty($html = false) {
445
-        $criteria = explode(' ',$this->criteria);
445
+        $criteria = explode(' ', $this->criteria);
446 446
         $spokenby = array_values(\MySociety\TheyWorkForYou\Utility\Search::speakerNamesForIDs($this->criteria));
447 447
         $words = array();
448 448
         foreach ($criteria as $c) {
449
-            if (!preg_match('#^speaker:(\d+)#',$c,$m)) {
449
+            if (!preg_match('#^speaker:(\d+)#', $c, $m)) {
450 450
                 $words[] = $c;
451 451
             }
452 452
         }
453 453
         $criteria = '';
454
-        if (count($words)) $criteria .= ($html?'<li>':'* ') . 'Mentions of [' . implode(' ', $words) . ']' . ($html?'</li>':'') . "\n";
455
-        if ($spokenby) $criteria .= ($html?'<li>':'* ') . "Things by " . implode(' or ', $spokenby) . ($html?'</li>':'') . "\n";
454
+        if (count($words)) $criteria .= ($html ? '<li>' : '* ').'Mentions of ['.implode(' ', $words).']'.($html ? '</li>' : '')."\n";
455
+        if ($spokenby) $criteria .= ($html ? '<li>' : '* ')."Things by ".implode(' or ', $spokenby).($html ? '</li>' : '')."\n";
456 456
         return $criteria;
457 457
     }
458 458
 
Please login to merge, or discard this patch.
Braces   +27 added lines, -12 removed lines patch added patch discarded remove patch
@@ -340,17 +340,20 @@  discard block
 block discarded – undo
340 340
     }
341 341
 
342 342
     public function check_token($token) {
343
-        if (!is_null($this->token_checked))
344
-            return $this->token_checked;
343
+        if (!is_null($this->token_checked)) {
344
+                    return $this->token_checked;
345
+        }
345 346
 
346 347
         $arg = strstr($token, '::') ? '::' : '-';
347 348
         $token_parts = explode($arg, $token);
348
-        if (count($token_parts) != 2)
349
-            return false;
349
+        if (count($token_parts) != 2) {
350
+                    return false;
351
+        }
350 352
 
351 353
         list($alert_id, $registrationtoken) = $token_parts;
352
-        if (!is_numeric($alert_id) || !$registrationtoken)
353
-            return false;
354
+        if (!is_numeric($alert_id) || !$registrationtoken) {
355
+                    return false;
356
+        }
354 357
 
355 358
         $q = $this->db->query("SELECT alert_id, email, criteria
356 359
                         FROM alerts
@@ -398,7 +401,9 @@  discard block
 block discarded – undo
398 401
     // If all goes well the alert will be confirmed.
399 402
     // The alert will be active when scripts run each day to send the actual emails.
400 403
     public function confirm($token) {
401
-        if (!($alert = $this->check_token($token))) return false;
404
+        if (!($alert = $this->check_token($token))) {
405
+            return false;
406
+        }
402 407
         $this->criteria = $alert['criteria'];
403 408
         $this->email = $alert['email'];
404 409
         $r = $this->db->query("UPDATE alerts SET confirmed = 1, deleted = 0 WHERE alert_id = :alert_id", array(
@@ -412,7 +417,9 @@  discard block
 block discarded – undo
412 417
     // and the deletion page has passed the token from the URL to here.
413 418
     // If all goes well the alert will be flagged as deleted.
414 419
     public function delete($token) {
415
-        if (!($alert = $this->check_token($token))) return false;
420
+        if (!($alert = $this->check_token($token))) {
421
+            return false;
422
+        }
416 423
         $r = $this->db->query("UPDATE alerts SET deleted = 1 WHERE alert_id = :alert_id", array(
417 424
             ':alert_id' => $alert['id']
418 425
             ));
@@ -421,7 +428,9 @@  discard block
 block discarded – undo
421 428
     }
422 429
 
423 430
     public function suspend($token) {
424
-        if (!($alert = $this->check_token($token))) return false;
431
+        if (!($alert = $this->check_token($token))) {
432
+            return false;
433
+        }
425 434
         $r = $this->db->query("UPDATE alerts SET deleted = 2 WHERE alert_id = :alert_id", array(
426 435
             ':alert_id' => $alert['id']
427 436
             ));
@@ -430,7 +439,9 @@  discard block
 block discarded – undo
430 439
     }
431 440
 
432 441
     public function resume($token) {
433
-        if (!($alert = $this->check_token($token))) return false;
442
+        if (!($alert = $this->check_token($token))) {
443
+            return false;
444
+        }
434 445
         $r = $this->db->query("UPDATE alerts SET deleted = 0 WHERE alert_id = :alert_id", array(
435 446
             ':alert_id' => $alert['id']
436 447
             ));
@@ -451,8 +462,12 @@  discard block
 block discarded – undo
451 462
             }
452 463
         }
453 464
         $criteria = '';
454
-        if (count($words)) $criteria .= ($html?'<li>':'* ') . 'Mentions of [' . implode(' ', $words) . ']' . ($html?'</li>':'') . "\n";
455
-        if ($spokenby) $criteria .= ($html?'<li>':'* ') . "Things by " . implode(' or ', $spokenby) . ($html?'</li>':'') . "\n";
465
+        if (count($words)) {
466
+            $criteria .= ($html?'<li>':'* ') . 'Mentions of [' . implode(' ', $words) . ']' . ($html?'</li>':'') . "\n";
467
+        }
468
+        if ($spokenby) {
469
+            $criteria .= ($html?'<li>':'* ') . "Things by " . implode(' or ', $spokenby) . ($html?'</li>':'') . "\n";
470
+        }
456 471
         return $criteria;
457 472
     }
458 473
 
Please login to merge, or discard this patch.
www/includes/easyparliament/commentlist.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -44,6 +44,9 @@
 block discarded – undo
44 44
     }
45 45
 
46 46
 
47
+    /**
48
+     * @param string $view
49
+     */
47 50
     public function display ($view, $args=array(), $format='html') {
48 51
         // $view is what we're viewing by:
49 52
         //	'ep' is all the comments attached to an epobject.
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
         return $data;
319 319
     }
320 320
 
321
-  public function _get_data_by_dates($args) {
321
+    public function _get_data_by_dates($args) {
322 322
     // $args should contain start_date and end_date
323 323
 
324 324
         twfy_debug (get_class($this), "getting data by recent");
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
         $commentsdata = $this->_get_comment_data($input);
339 339
         $data['comments'] = $commentsdata;
340 340
         return $data;
341
-  }
341
+    }
342 342
 
343 343
     public function _get_data_by_search($args) {
344 344
         // $args should contain 'num', indicating how many to get.
Please login to merge, or discard this patch.
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -542,11 +542,11 @@
 block discarded – undo
542 542
         }
543 543
         if ($limit != '') {
544 544
             # Can't use parameter as >1 argument
545
-            $limit = "LIMIT $limit";
545
+            $limit = "limit $limit";
546 546
         }
547 547
 
548 548
         // Finally, do the query!
549
-        $q = $this->db->query ("SELECT $fields
549
+        $q = $this->db->query ("select $fields
550 550
                         FROM 	comments
551 551
                         $join
552 552
                         WHERE $where
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     }
43 43
 
44 44
 
45
-    public function display ($view, $args=array(), $format='html') {
45
+    public function display($view, $args = array(), $format = 'html') {
46 46
         // $view is what we're viewing by:
47 47
         //	'ep' is all the comments attached to an epobject.
48 48
         //	'user' is all the comments written by a user.
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 
67 67
         } else {
68 68
             // Don't have a valid $view;
69
-            $PAGE->error_message ("You haven't specified a view type.");
69
+            $PAGE->error_message("You haven't specified a view type.");
70 70
             return false;
71 71
         }
72 72
 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
         return true;
86 86
     }
87 87
 
88
-    public function render($data, $format='html', $template='comments') {
88
+    public function render($data, $format = 'html', $template = 'comments') {
89 89
         include (INCLUDESPATH."easyparliament/templates/$format/$template.php");
90 90
     }
91 91
 
@@ -93,21 +93,21 @@  discard block
 block discarded – undo
93 93
         // Get all the data attached to an epobject.
94 94
         global $PAGE;
95 95
 
96
-        twfy_debug (get_class($this), "getting data by epobject");
96
+        twfy_debug(get_class($this), "getting data by epobject");
97 97
 
98 98
         // What we return.
99 99
         $data = array();
100 100
         if (!is_numeric($args['epobject_id'])) {
101
-            $PAGE->error_message ("Sorry, we don't have a valid epobject id");
101
+            $PAGE->error_message("Sorry, we don't have a valid epobject id");
102 102
             return $data;
103 103
         }
104 104
 
105 105
         // For getting the data.
106
-        $input = array (
107
-            'amount' => array (
106
+        $input = array(
107
+            'amount' => array(
108 108
                 'user' => true
109 109
             ),
110
-            'where' => array (
110
+            'where' => array(
111 111
                 'comments.epobject_id=' => $args['epobject_id'],
112 112
                 #'visible=' => '1'
113 113
             ),
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
         // comments by things in $args?
136 136
         global $PAGE;
137 137
 
138
-        twfy_debug (get_class($this), "getting data by user");
138
+        twfy_debug(get_class($this), "getting data by user");
139 139
 
140 140
         // What we return.
141 141
         $data = array();
142 142
 
143 143
         if (!is_numeric($args['user_id'])) {
144
-            $PAGE->error_message ("Sorry, we don't have a valid user id");
144
+            $PAGE->error_message("Sorry, we don't have a valid user id");
145 145
             return $data;
146 146
         }
147 147
 
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
             $num = 10;
152 152
         }
153 153
 
154
-        if (isset($args['page']) && is_numeric($args['page']) && $args['page']>1) {
154
+        if (isset($args['page']) && is_numeric($args['page']) && $args['page'] > 1) {
155 155
             $page = $args['page'];
156 156
         } else {
157 157
             $page = 1;
158 158
         }
159 159
 
160
-        $limit = $num*($page-1) . ',' . $num;
160
+        $limit = $num * ($page - 1).','.$num;
161 161
 
162 162
         // We're getting the most recent comments posted to epobjects.
163 163
         // We're grouping them by epobject so we can just link to each hansard thing once.
@@ -193,10 +193,10 @@  discard block
 block discarded – undo
193 193
 
194 194
         if ($q->rows() > 0) {
195 195
 
196
-            for ($n=0; $n<$q->rows(); $n++) {
196
+            for ($n = 0; $n < $q->rows(); $n++) {
197 197
 
198 198
                 // All the basic stuff...
199
-                $comments[$n] = array (
199
+                $comments[$n] = array(
200 200
                     'comment_id'		=> $q->field($n, 'comment_id'),
201 201
                     'posted'			=> $q->field($n, 'posted'),
202 202
                     'total_comments'	=> $q->field($n, 'total_comments'),
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
                 );
209 209
 
210 210
                 // Add the URL...
211
-                $urldata = array (
211
+                $urldata = array(
212 212
                     'major' 		=> $q->field($n, 'major'),
213 213
                     'gid'			=> $q->field($n, 'gid'),
214 214
                     'comment_id'	=> $q->field($n, 'comment_id'),
@@ -234,14 +234,14 @@  discard block
 block discarded – undo
234 234
 
235 235
                 $commentbodies = array();
236 236
 
237
-                for ($n=0; $n<$r->rows(); $n++) {
238
-                    $commentbodies[ $r->field($n, 'comment_id') ] = $r->field($n, 'body');
237
+                for ($n = 0; $n < $r->rows(); $n++) {
238
+                    $commentbodies[$r->field($n, 'comment_id')] = $r->field($n, 'body');
239 239
                 }
240 240
 
241 241
                 // This does rely on both this and the previous query returning
242 242
                 // stuff in the same order...
243 243
                 foreach ($comments as $n => $commentdata) {
244
-                    $comments[$n]['body'] = $commentbodies[ $comments[$n]['comment_id'] ];
244
+                    $comments[$n]['body'] = $commentbodies[$comments[$n]['comment_id']];
245 245
                 }
246 246
             }
247 247
         }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
         $data['comments'] = $comments;
250 250
         $data['results_per_page'] = $num;
251 251
         $data['page'] = $page;
252
-        $q = $this->db->query('SELECT COUNT(DISTINCT(epobject_id)) AS count FROM comments WHERE visible=1 AND user_id=' . $args['user_id']);
252
+        $q = $this->db->query('SELECT COUNT(DISTINCT(epobject_id)) AS count FROM comments WHERE visible=1 AND user_id='.$args['user_id']);
253 253
         $data['total_results'] = $q->field(0, 'count');
254 254
         return $data;
255 255
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
         // $args should contain 'num', indicating how many to get.
262 262
         // and perhaps pid too, for a particular person
263 263
 
264
-        twfy_debug (get_class($this), "getting data by recent");
264
+        twfy_debug(get_class($this), "getting data by recent");
265 265
 
266 266
         // What we return.
267 267
         $data = array();
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
             $page = 1;
279 279
         }
280 280
 
281
-        $limit = $num*($page-1) . ',' . $num;
281
+        $limit = $num * ($page - 1).','.$num;
282 282
 
283 283
         $where = array(
284 284
             'visible=' => '1'
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
         if (isset($args['pid']) && is_numeric($args['pid'])) {
287 287
             $where['person_id='] = $args['pid'];
288 288
         }
289
-        $input = array (
290
-            'amount' => array (
289
+        $input = array(
290
+            'amount' => array(
291 291
                 'user' => true
292 292
             ),
293 293
             'where'  => $where,
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
             $data['pid'] = $args['pid'];
306 306
             $q = 'SELECT title, given_name, family_name, lordofname, house FROM member m, person_names p WHERE m.person_id=p.person_id AND p.type="name" AND left_house="9999-12-31" AND m.person_id = :pid';
307 307
             $q = $this->db->query($q, array(':pid' => $args['pid']));
308
-            $data['full_name'] = member_full_name($q->field(0, 'house'), $q->field(0, 'title'), $q->field(0, 'given_name'), $q->field(0, 'family_name'), $q->field(0,'lordofname'));
308
+            $data['full_name'] = member_full_name($q->field(0, 'house'), $q->field(0, 'title'), $q->field(0, 'given_name'), $q->field(0, 'family_name'), $q->field(0, 'lordofname'));
309 309
             $q = 'SELECT COUNT(*) AS count FROM comments,hansard WHERE visible=1 AND comments.epobject_id = hansard.epobject_id and hansard.person_id = :pid';
310 310
             $params[':pid'] = $args['pid'];
311 311
         } else {
@@ -319,15 +319,15 @@  discard block
 block discarded – undo
319 319
   public function _get_data_by_dates($args) {
320 320
     // $args should contain start_date and end_date
321 321
 
322
-        twfy_debug (get_class($this), "getting data by recent");
322
+        twfy_debug(get_class($this), "getting data by recent");
323 323
         $data = array();
324 324
         $where = array(
325 325
             'visible=' => '1',
326 326
             'date(posted)>=' => $args['start_date'],
327 327
             'date(posted)<=' => $args['end_date']
328 328
         );
329
-        $input = array (
330
-            'amount' => array (
329
+        $input = array(
330
+            'amount' => array(
331 331
                 'user' => true
332 332
             ),
333 333
             'where'  => $where,
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
     public function _get_data_by_search($args) {
342 342
         // $args should contain 'num', indicating how many to get.
343 343
 
344
-        twfy_debug (get_class($this), "getting data by search");
344
+        twfy_debug(get_class($this), "getting data by search");
345 345
 
346 346
         // What we return.
347 347
         $data = array();
@@ -358,13 +358,13 @@  discard block
 block discarded – undo
358 358
             $page = 1;
359 359
         }
360 360
 
361
-        $limit = $num*($page-1) . ',' . $num;
361
+        $limit = $num * ($page - 1).','.$num;
362 362
 
363
-        $input = array (
364
-            'amount' => array (
363
+        $input = array(
364
+            'amount' => array(
365 365
                 'user'=> true
366 366
             ),
367
-            'where'  => array (
367
+            'where'  => array(
368 368
                 'comments.body LIKE' => "%$args[s]%"
369 369
             ),
370 370
             'order' => 'posted DESC',
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
         // It returns the URL for the comment.
392 392
 
393 393
         $major 		= $urldata['major'];
394
-        $gid 		= $urldata['gid'];
394
+        $gid = $urldata['gid'];
395 395
         $comment_id = $urldata['comment_id'];
396 396
         $user_id = isset($urldata['user_id']) ? $urldata['user_id'] : false;
397 397
 
@@ -405,11 +405,11 @@  discard block
 block discarded – undo
405 405
         $URL = new URL($page);
406 406
 
407 407
         $gid = fix_gid_from_db($gid); // In includes/utility.php
408
-        $URL->insert(array('id' => $gid ));
408
+        $URL->insert(array('id' => $gid));
409 409
         if ($user_id) {
410 410
             $URL->insert(array('u' => $user_id));
411 411
         }
412
-        $url = $URL->generate() . '#c' . $comment_id;
412
+        $url = $URL->generate().'#c'.$comment_id;
413 413
 
414 414
         return $url;
415 415
     }
@@ -483,9 +483,9 @@  discard block
 block discarded – undo
483 483
         $limit = isset($input['limit']) ? $input['limit'] : '';
484 484
 
485 485
         // The fields to fetch from db. 'table' => array ('field1', 'field2').
486
-        $fieldsarr = array (
487
-            'comments' => array ('comment_id', 'user_id', 'epobject_id', 'body', 'posted', 'modflagged', 'visible'),
488
-            'hansard' => array ('major', 'gid')
486
+        $fieldsarr = array(
487
+            'comments' => array('comment_id', 'user_id', 'epobject_id', 'body', 'posted', 'modflagged', 'visible'),
488
+            'hansard' => array('major', 'gid')
489 489
         );
490 490
 
491 491
         // Yes, we need the gid of a comment's associated hansard object
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
 
497 497
         // Add on the stuff for getting a user's details.
498 498
         if (isset($amount['user']) && $amount['user'] == true) {
499
-            $fieldsarr['users'] = array ('firstname', 'lastname', 'user_id');
499
+            $fieldsarr['users'] = array('firstname', 'lastname', 'user_id');
500 500
             // Like doing "FROM comments, users" but it's easier to add
501 501
             // an "INNER JOIN..." automatically to the query.
502 502
             $join .= ' INNER JOIN users ON comments.user_id = users.user_id ';
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
             $fieldsarr['epobject'] = array('body');
508 508
         }
509 509
 
510
-        $fieldsarr2 = array ();
510
+        $fieldsarr2 = array();
511 511
         // Construct the $fields clause.
512 512
         foreach ($fieldsarr as $table => $tablesfields) {
513 513
             foreach ($tablesfields as $n => $field) {
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
         $fields = implode(', ', $fieldsarr2);
525 525
 
526 526
 
527
-        $wherearr2 = array ();
527
+        $wherearr2 = array();
528 528
         $params = array();
529 529
         $i = 0;
530 530
         // Construct the $where clause.
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
             $params[":where$i"] = $val;
534 534
             $i++;
535 535
         }
536
-        $where = implode (" AND ", $wherearr2);
536
+        $where = implode(" AND ", $wherearr2);
537 537
 
538 538
         if ($order != '') {
539 539
             $order = "ORDER BY $order";
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
         }
545 545
 
546 546
         // Finally, do the query!
547
-        $q = $this->db->query ("SELECT $fields
547
+        $q = $this->db->query("SELECT $fields
548 548
                         FROM 	comments
549 549
                         $join
550 550
                         WHERE $where
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
                         ", $params);
554 554
 
555 555
         // Format the data into an array for returning.
556
-        $data = array ();
556
+        $data = array();
557 557
 
558 558
         if ($q->rows() > 0) {
559 559
 
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
             // We'll generate permalinks for each comment.
564 564
             // Assuming every comment is from the same major...
565 565
 
566
-            for ($n=0; $n<$q->rows(); $n++) {
566
+            for ($n = 0; $n < $q->rows(); $n++) {
567 567
 
568 568
                 // Put each row returned into its own array in $data.
569 569
                 foreach ($fieldsarr as $table => $tablesfields) {
Please login to merge, or discard this patch.
www/includes/easyparliament/hansardlist.php 4 patches
Doc Comments   +13 added lines patch added patch discarded remove patch
@@ -114,6 +114,9 @@  discard block
 block discarded – undo
114 114
 
115 115
 
116 116
 
117
+    /**
118
+     * @param string $view
119
+     */
117 120
     public function display ($view, $args=array(), $format='html') {
118 121
 
119 122
         // $view is what we're viewing by:
@@ -726,6 +729,10 @@  discard block
 block discarded – undo
726 729
 
727 730
     }
728 731
 
732
+    /**
733
+     * @param string $from
734
+     * @param string $to
735
+     */
729 736
     private function check_gid_change($gid, $from, $to) {
730 737
         $input = array (
731 738
             'amount' => array (
@@ -1610,6 +1617,9 @@  discard block
 block discarded – undo
1610 1617
 
1611 1618
     }
1612 1619
 
1620
+    /**
1621
+     * @param string $spid
1622
+     */
1613 1623
     public function _get_mentions($spid) {
1614 1624
         $result = array();
1615 1625
         $q = $this->db->query("select gid, type, date, url, mentioned_gid
@@ -2622,6 +2632,9 @@  discard block
 block discarded – undo
2622 2632
     public $commentspage = 'spwrans';
2623 2633
     public $gidprefix = 'uk.org.publicwhip/spwa/';
2624 2634
 
2635
+    /**
2636
+     * @return string
2637
+     */
2625 2638
     public function get_gid_from_spid($spid) {
2626 2639
         // Fix the common errors of S.0 instead of S.O and leading
2627 2640
         // zeros in the numbers:
Please login to merge, or discard this patch.
Spacing   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -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,
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
         if ($view == 'search' && (!defined('FRONT_END_SEARCH') || !FRONT_END_SEARCH))
142 142
             return false;
143 143
 
144
-        $validviews = array ('calendar', 'date', 'gid', 'person', 'search', 'search_min', 'search_video', 'recent', 'recent_mostvotes', 'biggest_debates', 'recent_wrans', 'recent_wms', 'column', 'mp', 'bill', 'session', 'recent_debates', 'recent_pbc_debates', 'featured_gid');
144
+        $validviews = array('calendar', 'date', 'gid', 'person', 'search', 'search_min', 'search_video', 'recent', 'recent_mostvotes', 'biggest_debates', 'recent_wrans', 'recent_wms', 'column', 'mp', 'bill', 'session', 'recent_debates', 'recent_pbc_debates', 'featured_gid');
145 145
         if (in_array($view, $validviews)) {
146 146
 
147 147
             // What function do we call for this view?
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 
152 152
         } else {
153 153
             // Don't have a valid $view.
154
-            $PAGE->error_message ("You haven't specified a view type.");
154
+            $PAGE->error_message("You haven't specified a view type.");
155 155
             return false;
156 156
         }
157 157
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 
173 173
 
174 174
 
175
-    public function render($view, $data, $format='html') {
175
+    public function render($view, $data, $format = 'html') {
176 176
         // Once we have the data that's to be rendered,
177 177
         // include the template.
178 178
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
             return $data;
182 182
         }
183 183
 
184
-        include (INCLUDESPATH."easyparliament/templates/$format/hansard_$view" . ".php");
184
+        include (INCLUDESPATH."easyparliament/templates/$format/hansard_$view".".php");
185 185
         return true;
186 186
 
187 187
     }
@@ -226,13 +226,13 @@  discard block
 block discarded – undo
226 226
             $hdate = $q->field(0, 'hdate');
227 227
             if ($hdate) {
228 228
                 $URL = new URL($this->listpage);
229
-                $URL->insert( array('d'=>$hdate) );
229
+                $URL->insert(array('d'=>$hdate));
230 230
 
231 231
                 // Work out a timestamp which is handy for comparing to now.
232 232
                 list($year, $month, $date) = explode('-', $hdate);
233
-                $timestamp = gmmktime (0, 0, 0, $month, $date, $year);
233
+                $timestamp = gmmktime(0, 0, 0, $month, $date, $year);
234 234
 
235
-                $data = array (
235
+                $data = array(
236 236
                     'hdate'		=> $hdate,
237 237
                     'timestamp'	=> $timestamp,
238 238
                     'listurl'	=> $URL->generate()
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
         // Pass it an array of data about an item and it will return an
267 267
         // array of data about the item's section heading.
268 268
 
269
-        twfy_debug (get_class($this), "getting an item's section");
269
+        twfy_debug(get_class($this), "getting an item's section");
270 270
 
271 271
         if ($itemdata['htype'] != '10') {
272 272
 
@@ -275,11 +275,11 @@  discard block
 block discarded – undo
275 275
             // so get the section info above this item.
276 276
 
277 277
             // For getting hansard data.
278
-            $input = array (
279
-                'amount' => array (
278
+            $input = array(
279
+                'amount' => array(
280 280
                     'body' => true
281 281
                 ),
282
-                'where' => array (
282
+                'where' => array(
283 283
                     'hansard.epobject_id=' => $itemdata['section_id']
284 284
                 )
285 285
             );
@@ -306,21 +306,21 @@  discard block
 block discarded – undo
306 306
         // Pass it an array of data about an item and it will return an
307 307
         // array of data about the item's subsection heading.
308 308
 
309
-        twfy_debug (get_class($this), "getting an item's subsection");
309
+        twfy_debug(get_class($this), "getting an item's subsection");
310 310
 
311 311
         // What we return.
312
-        $subsectiondata = array ();
312
+        $subsectiondata = array();
313 313
 
314 314
         if ($itemdata['htype'] == '12' || $itemdata['htype'] == '13') {
315 315
             // This item is a speech or procedural, so get the
316 316
             // subsection info above this item.
317 317
 
318 318
             // For getting hansard data.
319
-            $input = array (
320
-                'amount' => array (
319
+            $input = array(
320
+                'amount' => array(
321 321
                     'body' => true
322 322
                 ),
323
-                'where' => array (
323
+                'where' => array(
324 324
                     'hansard.epobject_id=' => $itemdata['subsection_id']
325 325
                 )
326 326
             );
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
         // Pass it an array of item info, of a section/subsection, and this will return
348 348
         // data for the next/prev items.
349 349
 
350
-        twfy_debug (get_class($this), "getting next/prev items");
350
+        twfy_debug(get_class($this), "getting next/prev items");
351 351
 
352 352
         // What we return.
353 353
         $nextprevdata = array();
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
         } else {
366 366
             // Anything else in debates - get the next element that isn't
367 367
             // a subsection or section, and is within THIS subsection.
368
-            $where = "subsection_id = '" . $itemdata['subsection_id'] . "' AND (htype != 10 AND htype != 11)";
368
+            $where = "subsection_id = '".$itemdata['subsection_id']."' AND (htype != 10 AND htype != 11)";
369 369
         }
370 370
 
371 371
         // Find if there are next/previous debate items of our
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
         // Find the epobject_id of the previous item (if any):
379 379
         $q = $this->db->query("SELECT epobject_id
380 380
                         FROM 	hansard
381
-                        WHERE 	hdate = '" . $itemdata['hdate'] . "'
382
-                        AND 	hpos < '" . $itemdata['hpos'] . "'
383
-                        AND 	major = '" . $itemdata['major'] . "'
381
+                        WHERE 	hdate = '" . $itemdata['hdate']."'
382
+                        AND 	hpos < '" . $itemdata['hpos']."'
383
+                        AND 	major = '" . $itemdata['major']."'
384 384
                         AND 	$where
385 385
                         ORDER BY hpos DESC
386 386
                         LIMIT 1");
@@ -392,9 +392,9 @@  discard block
 block discarded – undo
392 392
         // Find the epobject_id of the next item (if any):
393 393
         $q = $this->db->query("SELECT epobject_id
394 394
                         FROM 	hansard
395
-                        WHERE 	hdate = '" . $itemdata['hdate'] . "'
396
-                        AND 	hpos > '" . $itemdata['hpos'] . "'
397
-                        AND 	major = '" . $itemdata['major'] . "'
395
+                        WHERE 	hdate = '" . $itemdata['hdate']."'
396
+                        AND 	hpos > '" . $itemdata['hpos']."'
397
+                        AND 	major = '" . $itemdata['major']."'
398 398
                         AND 	$where
399 399
                         ORDER BY hpos ASC
400 400
                         LIMIT 1");
@@ -413,8 +413,8 @@  discard block
 block discarded – undo
413 413
             $wherearr['hansard.epobject_id='] = $prev_item_id;
414 414
 
415 415
             // For getting hansard data.
416
-            $input = array (
417
-                'amount' => array (
416
+            $input = array(
417
+                'amount' => array(
418 418
                     'body' => true,
419 419
                     'speaker' => true
420 420
                 ),
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
                 if ($itemdata['htype'] == '10' || $itemdata['htype'] == '11') {
430 430
                     // Linking to the prev (sub)section.
431 431
                     $thing = $hansardmajors[$this->major]['singular'];
432
-                    $nextprevdata['prev'] = array (
432
+                    $nextprevdata['prev'] = array(
433 433
                         'body'		=> "Previous $thing",
434 434
                         'url'		=> $prevdata[0]['listurl'],
435 435
                         'title'		=> $prevdata[0]['body']
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
                     } else {
443 443
                         $title = '';
444 444
                     }
445
-                    $nextprevdata['prev'] = array (
445
+                    $nextprevdata['prev'] = array(
446 446
                         'body'		=> 'Previous speaker',
447 447
                         'url'		=> $prevdata[0]['commentsurl'],
448 448
                         'title'		=> $title
@@ -458,8 +458,8 @@  discard block
 block discarded – undo
458 458
             $wherearr['hansard.epobject_id='] = $next_item_id;
459 459
 
460 460
             // For getting hansard data.
461
-            $input = array (
462
-                'amount' => array (
461
+            $input = array(
462
+                'amount' => array(
463 463
                     'body' => true,
464 464
                     'speaker' => true
465 465
                 ),
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
                 if ($itemdata['htype'] == '10' || $itemdata['htype'] == '11') {
474 474
                     // Linking to the next (sub)section.
475 475
                     $thing = $hansardmajors[$this->major]['singular'];
476
-                    $nextprevdata['next'] = array (
476
+                    $nextprevdata['next'] = array(
477 477
                         'body'		=> "Next $thing",
478 478
                         'url'		=> $nextdata[0]['listurl'],
479 479
                         'title'		=> $nextdata[0]['body']
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
                     } else {
487 487
                         $title = '';
488 488
                     }
489
-                    $nextprevdata['next'] = array (
489
+                    $nextprevdata['next'] = array(
490 490
                         'body'		=> 'Next speaker',
491 491
                         'url'		=> $nextdata[0]['commentsurl'],
492 492
                         'title'		=> $title
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
             $nextprevdata['up'] = array(
502 502
                 'body'	=> _htmlspecialchars($this->bill_title),
503 503
                 'title'	=> '',
504
-                'url'	=> $URL->generate() . $this->url,
504
+                'url'	=> $URL->generate().$this->url,
505 505
             );
506 506
         } elseif ($itemdata['htype'] == '10' || $itemdata['htype'] == '11') {
507 507
             $URL = new URL($this->listpage);
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
             $URL->remove(array('id'));
511 511
             $things = $hansardmajors[$itemdata['major']]['title'];
512 512
             $nextprevdata['up'] = array(
513
-                'body'	=> "All $things on " . format_date($itemdata['hdate'], SHORTDATEFORMAT),
513
+                'body'	=> "All $things on ".format_date($itemdata['hdate'], SHORTDATEFORMAT),
514 514
                 'title'	=> '',
515 515
                 'url' 	=> $URL->generate()
516 516
             );
@@ -530,14 +530,14 @@  discard block
 block discarded – undo
530 530
         // containing the next/prev dates that contain items from
531 531
         // $this->major of hansard object.
532 532
 
533
-        twfy_debug (get_class($this), "getting next/prev dates");
533
+        twfy_debug(get_class($this), "getting next/prev dates");
534 534
 
535 535
         // What we return.
536
-        $nextprevdata = array ();
536
+        $nextprevdata = array();
537 537
 
538 538
         $URL = new URL($this->listpage);
539 539
 
540
-        $looper = array ("next", "prev");
540
+        $looper = array("next", "prev");
541 541
 
542 542
         foreach ($looper as $n => $nextorprev) {
543 543
 
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
             // when displaying the first day of debates.
562 562
             if ($q->rows() > 0 && $q->field(0, 'hdate') != NULL) {
563 563
 
564
-                $URL->insert( array( 'd'=>$q->field(0, 'hdate') ) );
564
+                $URL->insert(array('d'=>$q->field(0, 'hdate')));
565 565
 
566 566
                 if ($nextorprev == 'next') {
567 567
                     $body = 'Next day';
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
 
572 572
                 $title = format_date($q->field(0, 'hdate'), SHORTDATEFORMAT);
573 573
 
574
-                $nextprevdata[$nextorprev] = array (
574
+                $nextprevdata[$nextorprev] = array(
575 575
                     'hdate'		=> $q->field(0, 'hdate'),
576 576
                     'url'	 	=> $URL->generate(),
577 577
                     'body'		=> $body,
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
         $thing = $hansardmajors[$this->major]['plural'];
586 586
         $URL->insert(array('y'=>$year));
587 587
 
588
-        $nextprevdata['up'] = array (
588
+        $nextprevdata['up'] = array(
589 589
             'body' 	=> "All of $year's $thing",
590 590
             'title'	=> '',
591 591
             'url' 	=> $URL->generate()
@@ -606,19 +606,19 @@  discard block
 block discarded – undo
606 606
         if (isset($args['date'])) {
607 607
             $date = $args['date'];
608 608
         } else {
609
-            $PAGE->error_message ("Sorry, we don't have a date.");
609
+            $PAGE->error_message("Sorry, we don't have a date.");
610 610
             return false;
611 611
         }
612 612
 
613 613
         if (!preg_match("/^(\d\d\d\d)-(\d{1,2})-(\d{1,2})$/", $date, $matches)) {
614
-            $PAGE->error_message ("Sorry, '" . _htmlentities($date) . "' isn't of the right format (YYYY-MM-DD).");
614
+            $PAGE->error_message("Sorry, '"._htmlentities($date)."' isn't of the right format (YYYY-MM-DD).");
615 615
             return false;
616 616
         }
617 617
 
618 618
         list(, $year, $month, $day) = $matches;
619 619
 
620 620
         if (!checkdate($month, $day, $year)) {
621
-            $PAGE->error_message ("Sorry, '" . _htmlentities($date) . "' isn't a valid date.");
621
+            $PAGE->error_message("Sorry, '"._htmlentities($date)."' isn't a valid date.");
622 622
             return false;
623 623
         }
624 624
 
@@ -636,29 +636,29 @@  discard block
 block discarded – undo
636 636
         global $PAGE;
637 637
 
638 638
         if (!isset($args['gid']) && $args['gid'] == '') {
639
-            $PAGE->error_message ("Sorry, we don't have an item gid.");
639
+            $PAGE->error_message("Sorry, we don't have an item gid.");
640 640
             return false;
641 641
         }
642 642
 
643 643
 
644 644
         // Get all the data just for this epobject_id.
645
-        $input = array (
646
-            'amount' => array (
645
+        $input = array(
646
+            'amount' => array(
647 647
                 'body' => true,
648 648
                 'speaker' => true,
649 649
                 'comment' => true,
650 650
                 'votes' => true
651 651
             ),
652
-            'where' => array (
652
+            'where' => array(
653 653
                 // Need to add the 'uk.org.publicwhip/debate/' or whatever on before
654 654
                 // looking in the DB.
655
-                'gid=' => $this->gidprefix . $args['gid']
655
+                'gid=' => $this->gidprefix.$args['gid']
656 656
             )
657 657
         );
658 658
 
659
-        twfy_debug (get_class($this), "looking for redirected gid");
660
-        $gid = $this->gidprefix . $args['gid'];
661
-        $q = $this->db->query ("SELECT gid_to FROM gidredirect WHERE gid_from = :gid", array(':gid' => $gid));
659
+        twfy_debug(get_class($this), "looking for redirected gid");
660
+        $gid = $this->gidprefix.$args['gid'];
661
+        $q = $this->db->query("SELECT gid_to FROM gidredirect WHERE gid_from = :gid", array(':gid' => $gid));
662 662
         if ($q->rows() == 0) {
663 663
             $itemdata = $this->_get_hansard_data($input);
664 664
         } else {
@@ -666,10 +666,10 @@  discard block
 block discarded – undo
666 666
                 $gid = $q->field(0, 'gid_to');
667 667
                 $q = $this->db->query("SELECT gid_to FROM gidredirect WHERE gid_from = :gid", array(':gid' => $gid));
668 668
             } while ($q->rows() > 0);
669
-            twfy_debug (get_class($this), "found redirected gid $gid" );
669
+            twfy_debug(get_class($this), "found redirected gid $gid");
670 670
             $input['where'] = array('gid=' => $gid);
671 671
             $itemdata = $this->_get_hansard_data($input);
672
-            if (count($itemdata) > 0 ) {
672
+            if (count($itemdata) > 0) {
673 673
                 throw new RedirectException(fix_gid_from_db($gid));
674 674
             }
675 675
         }
@@ -683,9 +683,9 @@  discard block
 block discarded – undo
683 683
             $this->check_gid_change($args['gid'], 'a', '');
684 684
 
685 685
             if (substr($args['gid'], -1) == 'L') {
686
-                $letts = array('a','b','c','d','e');
687
-                for ($i=0; $i<4; $i++) {
688
-                    $this->check_gid_change($args['gid'], $letts[$i], $letts[$i+1]);
686
+                $letts = array('a', 'b', 'c', 'd', 'e');
687
+                for ($i = 0; $i < 4; $i++) {
688
+                    $this->check_gid_change($args['gid'], $letts[$i], $letts[$i + 1]);
689 689
                 }
690 690
             }
691 691
 
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
             #	$u = $q->field(0, 'source_url');
719 719
             #	$u = '<br><a href="'. $u . '">' . $u . '</a>';
720 720
             #}
721
-            $PAGE->error_message ("Sorry, there is no Hansard object with a gid of '" . _htmlentities($args['gid']) . "'.");
721
+            $PAGE->error_message("Sorry, there is no Hansard object with a gid of '"._htmlentities($args['gid'])."'.");
722 722
             return false;
723 723
         }
724 724
 
@@ -727,8 +727,8 @@  discard block
 block discarded – undo
727 727
     }
728 728
 
729 729
     private function check_gid_change($gid, $from, $to) {
730
-        $input = array (
731
-            'amount' => array (
730
+        $input = array(
731
+            'amount' => array(
732 732
                 'body' => true,
733 733
                 'speaker' => true,
734 734
                 'comment' => true,
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
         );
738 738
         if (strstr($gid, $from)) {
739 739
             $check_gid = str_replace($from, $to, $gid);
740
-            $input['where'] = array('gid=' => $this->gidprefix . $check_gid);
740
+            $input['where'] = array('gid=' => $this->gidprefix.$check_gid);
741 741
             $itemdata = $this->_get_hansard_data($input);
742 742
             if (count($itemdata) > 0) {
743 743
                 throw new RedirectException($check_gid);
@@ -752,10 +752,10 @@  discard block
 block discarded – undo
752 752
 
753 753
         global $DATA, $this_page;
754 754
 
755
-        twfy_debug (get_class($this), "getting data by date");
755
+        twfy_debug(get_class($this), "getting data by date");
756 756
 
757 757
         // Where we'll put all the data we want to render.
758
-        $data = array ();
758
+        $data = array();
759 759
 
760 760
         $date = $this->_validate_date($args);
761 761
 
@@ -769,13 +769,13 @@  discard block
 block discarded – undo
769 769
 
770 770
             // Get all the sections for this date.
771 771
             // Then for each of those we'll get the subsections and rows.
772
-            $input = array (
773
-                'amount' => array (
772
+            $input = array(
773
+                'amount' => array(
774 774
                     'body' => true,
775 775
                     'comment' => true,
776 776
                     'excerpt' => true
777 777
                 ),
778
-                'where' => array (
778
+                'where' => array(
779 779
                     'hdate=' => "$date",
780 780
                     'htype=' => '10',
781 781
                     'major=' => $this->major
@@ -791,20 +791,20 @@  discard block
 block discarded – undo
791 791
                 $data['rows'] = array();
792 792
 
793 793
                 $num_sections = count($sections);
794
-                for ($n=0; $n<$num_sections; $n++) {
794
+                for ($n = 0; $n < $num_sections; $n++) {
795 795
                     // For each section on this date, get the subsections within it.
796 796
 
797 797
                     // Get all the section data.
798 798
                     $sectionrow = $this->_get_section($sections[$n]);
799 799
 
800 800
                     // Get the subsections within the section.
801
-                    $input = array (
802
-                        'amount' => array (
801
+                    $input = array(
802
+                        'amount' => array(
803 803
                             'body' => true,
804 804
                             'comment' => true,
805 805
                             'excerpt' => true
806 806
                         ),
807
-                        'where' => array (
807
+                        'where' => array(
808 808
                             'section_id='	=> $sections[$n]['epobject_id'],
809 809
                             'htype='		=> '11',
810 810
                             'major='		=> $this->major
@@ -815,10 +815,10 @@  discard block
 block discarded – undo
815 815
                     $rows = $this->_get_hansard_data($input);
816 816
 
817 817
                     // Put the section at the top of the rows array.
818
-                    array_unshift ($rows, $sectionrow);
818
+                    array_unshift($rows, $sectionrow);
819 819
 
820 820
                     // Add the section heading and the subsections to the full list.
821
-                    $data['rows'] = array_merge ($data['rows'], $rows);
821
+                    $data['rows'] = array_merge($data['rows'], $rows);
822 822
                 }
823 823
             }
824 824
 
@@ -854,9 +854,9 @@  discard block
 block discarded – undo
854 854
             $major = '';
855 855
         }
856 856
 
857
-        $data = array ();
857
+        $data = array();
858 858
 
859
-        $q = $this->db->query ("SELECT DISTINCT(hdate)
859
+        $q = $this->db->query("SELECT DISTINCT(hdate)
860 860
                         FROM 	hansard
861 861
                         $major
862 862
                         ORDER BY hdate DESC
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
 
868 868
             $URL = new URL($this->listpage);
869 869
 
870
-            for ($n=0; $n<$q->rows(); $n++) {
870
+            for ($n = 0; $n < $q->rows(); $n++) {
871 871
                 $rowdata = array();
872 872
 
873 873
                 $rowdata['body'] = format_date($q->field($n, 'hdate'), SHORTDATEFORMAT);
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
         $data = array();
897 897
 
898 898
         if (!isset($args['person_id'])) {
899
-            $PAGE->error_message ("Sorry, we need a valid person ID.");
899
+            $PAGE->error_message("Sorry, we need a valid person ID.");
900 900
             return $data;
901 901
         }
902 902
 
@@ -936,8 +936,8 @@  discard block
 block discarded – undo
936 936
 
937 937
         $speeches = array();
938 938
         if ($q->rows() > 0) {
939
-            for ($n=0; $n<$q->rows(); $n++) {
940
-                $speech = array (
939
+            for ($n = 0; $n < $q->rows(); $n++) {
940
+                $speech = array(
941 941
                     'subsection_id'	=> $q->field($n, 'subsection_id'),
942 942
                     'section_id'	=> $q->field($n, 'section_id'),
943 943
                     'htype'		=> $q->field($n, 'htype'),
@@ -952,9 +952,9 @@  discard block
 block discarded – undo
952 952
                     'gid'		=> fix_gid_from_db($q->field($n, 'gid')),
953 953
                 );
954 954
                 // Cache parent id to speed up _get_listurl
955
-                $this->epobjectid_to_gid[$q->field($n, 'subsection_id') ] = fix_gid_from_db( $q->field($n, 'gid_subsection') );
955
+                $this->epobjectid_to_gid[$q->field($n, 'subsection_id')] = fix_gid_from_db($q->field($n, 'gid_subsection'));
956 956
 
957
-                $url_args = array ('p'=>$q->field($n, 'person_id'));
957
+                $url_args = array('p'=>$q->field($n, 'person_id'));
958 958
                 $speech['listurl'] = $this->_get_listurl($speech, $url_args);
959 959
                 $speeches[] = $speech;
960 960
             }
@@ -963,13 +963,13 @@  discard block
 block discarded – undo
963 963
         if (count($speeches) > 0) {
964 964
             // Get the subsection texts.
965 965
             $num_speeches = count($speeches);
966
-            for ($n=0; $n<$num_speeches; $n++) {
966
+            for ($n = 0; $n < $num_speeches; $n++) {
967 967
                 $thing = $hansardmajors[$speeches[$n]['major']]['title'];
968 968
                 // Add the parent's body on...
969
-                $speeches[$n]['parent']['body'] = $speeches[$n]['body_section'] . ' | ' . $thing;
969
+                $speeches[$n]['parent']['body'] = $speeches[$n]['body_section'].' | '.$thing;
970 970
                 if ($speeches[$n]['subsection_id'] != $speeches[$n]['section_id']) {
971
-                    $speeches[$n]['parent']['body'] = $speeches[$n]['body_subsection'] .
972
-                        ' | ' . $speeches[$n]['parent']['body'];
971
+                    $speeches[$n]['parent']['body'] = $speeches[$n]['body_subsection'].
972
+                        ' | '.$speeches[$n]['parent']['body'];
973 973
                 }
974 974
             }
975 975
             $data['rows'] = $speeches;
@@ -1001,7 +1001,7 @@  discard block
 block discarded – undo
1001 1001
             // eg, by doing filter_user_input($s, 'strict');
1002 1002
             $searchstring = $args['s'];
1003 1003
         } else {
1004
-            if ( isset($args['exceptions']) ) {
1004
+            if (isset($args['exceptions'])) {
1005 1005
                 throw new \Exception('No search string provided.');
1006 1006
             } else {
1007 1007
                 $PAGE->error_message("No search string");
@@ -1010,14 +1010,14 @@  discard block
 block discarded – undo
1010 1010
         }
1011 1011
 
1012 1012
         // What we'll return.
1013
-        $data = array ();
1013
+        $data = array();
1014 1014
 
1015 1015
         $data['info']['s'] = $args['s'];
1016 1016
 
1017 1017
         // Allows us to specify how many results we want
1018 1018
         // Mainly for glossary term adding
1019 1019
         if (isset($args['num']) && $args['num']) {
1020
-            $results_per_page = $args['num']+0;
1020
+            $results_per_page = $args['num'] + 0;
1021 1021
         }
1022 1022
         else {
1023 1023
             $results_per_page = 20;
@@ -1045,16 +1045,16 @@  discard block
 block discarded – undo
1045 1045
         global $SEARCHENGINE;
1046 1046
 
1047 1047
         // For Xapian's equivalent of an SQL LIMIT clause.
1048
-        $first_result = ($page-1) * $results_per_page;
1048
+        $first_result = ($page - 1) * $results_per_page;
1049 1049
         $data['info']['first_result'] = $first_result + 1; // Take account of LIMIT's 0 base.
1050 1050
 
1051 1051
         // Get the gids from Xapian
1052 1052
         $sort_order = 'date';
1053 1053
         if (isset($args['o'])) {
1054
-            if ($args['o']=='d') $sort_order = 'newest';
1055
-            if ($args['o']=='o') $sort_order = 'oldest';
1056
-            elseif ($args['o']=='c') $sort_order = 'created';
1057
-            elseif ($args['o']=='r') $sort_order = 'relevance';
1054
+            if ($args['o'] == 'd') $sort_order = 'newest';
1055
+            if ($args['o'] == 'o') $sort_order = 'oldest';
1056
+            elseif ($args['o'] == 'c') $sort_order = 'created';
1057
+            elseif ($args['o'] == 'r') $sort_order = 'relevance';
1058 1058
         }
1059 1059
 
1060 1060
         $data['searchdescription'] = $SEARCHENGINE->query_description_long();
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
 
1065 1065
         // Log this query so we can improve them - if it wasn't a "popular
1066 1066
         // query" link
1067
-        if (! isset($args['pop']) or $args['pop'] != 1) {
1067
+        if (!isset($args['pop']) or $args['pop'] != 1) {
1068 1068
             global $SEARCHLOG;
1069 1069
             $SEARCHLOG->add(
1070 1070
             array('query' => $searchstring,
@@ -1079,7 +1079,7 @@  discard block
 block discarded – undo
1079 1079
 
1080 1080
         $SEARCHENGINE->run_search($first_result, $results_per_page, $sort_order);
1081 1081
         $gids = $SEARCHENGINE->get_gids();
1082
-        if ($sort_order=='created') {
1082
+        if ($sort_order == 'created') {
1083 1083
             $createds = $SEARCHENGINE->get_createds();
1084 1084
         }
1085 1085
         $relevances = $SEARCHENGINE->get_relevances();
@@ -1095,13 +1095,13 @@  discard block
 block discarded – undo
1095 1095
 
1096 1096
         // Cycle through each result, munge the data, get more, and put it all in $data.
1097 1097
         $num_gids = count($gids);
1098
-        for ($n=0; $n<$num_gids; $n++) {
1098
+        for ($n = 0; $n < $num_gids; $n++) {
1099 1099
             $gid = $gids[$n];
1100 1100
             $relevancy = $relevances[$n];
1101 1101
             $collapsed = $SEARCHENGINE->collapsed[$n];
1102
-            if ($sort_order=='created') {
1102
+            if ($sort_order == 'created') {
1103 1103
                 #$created = substr($createds[$n], 0, strpos($createds[$n], ':'));
1104
-                if ($createds[$n]<$args['threshold']) {
1104
+                if ($createds[$n] < $args['threshold']) {
1105 1105
                     $data['info']['total_results'] = $n;
1106 1106
                     break;
1107 1107
                 }
@@ -1127,9 +1127,9 @@  discard block
 block discarded – undo
1127 1127
                         continue;
1128 1128
 
1129 1129
                 list($cal_item, $cal_meta) = \MySociety\TheyWorkForYou\Utility\Calendar::meta($itemdata);
1130
-                $body = $this->prepare_search_result_for_display($cal_item) . '.';
1130
+                $body = $this->prepare_search_result_for_display($cal_item).'.';
1131 1131
                 if (!empty($cal_meta)) {
1132
-                    $body .= ' <span class="future_meta">' . join('; ', $cal_meta) . '</span>';
1132
+                    $body .= ' <span class="future_meta">'.join('; ', $cal_meta).'</span>';
1133 1133
                 }
1134 1134
                 if ($itemdata['witnesses']) {
1135 1135
                     $body .= '<br><small>Witnesses: '
@@ -1144,9 +1144,9 @@  discard block
 block discarded – undo
1144 1144
                 }
1145 1145
                 $itemdata['gid']            = $id;
1146 1146
                 $itemdata['relevance']      = $relevancy;
1147
-                $itemdata['parent']['body'] = $title . ' &#8211; ' . $itemdata['chamber'];
1147
+                $itemdata['parent']['body'] = $title.' &#8211; '.$itemdata['chamber'];
1148 1148
                 $itemdata['extract']        = $body;
1149
-                $itemdata['listurl']        = '/calendar/?d=' . $itemdata['event_date'] . '#cal' . $itemdata['id'];
1149
+                $itemdata['listurl']        = '/calendar/?d='.$itemdata['event_date'].'#cal'.$itemdata['id'];
1150 1150
                 $itemdata['major']          = 'F';
1151 1151
 
1152 1152
             } else {
@@ -1163,7 +1163,7 @@  discard block
 block discarded – undo
1163 1163
                 , array(':gid' => $gid));
1164 1164
 
1165 1165
                 if ($q->rows() > 1) {
1166
-                    if ( $isset($args['exceptions']) ) {
1166
+                    if ($isset($args['exceptions'])) {
1167 1167
                         throw new \Exception("Got more than one row getting data for $gid.");
1168 1168
                     } else {
1169 1169
                         $PAGE->error_message("Got more than one row getting data for $gid");
@@ -1177,14 +1177,14 @@  discard block
 block discarded – undo
1177 1177
 
1178 1178
                 $itemdata = $q->row(0);
1179 1179
                 $itemdata['collapsed']  = $collapsed;
1180
-                $itemdata['gid']        = fix_gid_from_db( $q->field(0, 'gid') );
1180
+                $itemdata['gid']        = fix_gid_from_db($q->field(0, 'gid'));
1181 1181
                 $itemdata['relevance']  = $relevancy;
1182 1182
                 $itemdata['extract']    = $this->prepare_search_result_for_display($q->field(0, 'body'));
1183 1183
 
1184 1184
                 //////////////////////////
1185 1185
                 // 2. Create the URL to link to this bit of text.
1186 1186
 
1187
-                $id_data = array (
1187
+                $id_data = array(
1188 1188
                     'major'            => $itemdata['major'],
1189 1189
                     'minor'            => $itemdata['minor'],
1190 1190
                     'htype'         => $itemdata['htype'],
@@ -1195,7 +1195,7 @@  discard block
 block discarded – undo
1195 1195
 
1196 1196
                 // We append the query onto the end of the URL as variable 's'
1197 1197
                 // so we can highlight them on the debate/wrans list page.
1198
-                $url_args = array ('s' => $searchstring);
1198
+                $url_args = array('s' => $searchstring);
1199 1199
 
1200 1200
                 $itemdata['listurl'] = $this->_get_listurl($id_data, $url_args, $encode);
1201 1201
 
@@ -1215,15 +1215,15 @@  discard block
 block discarded – undo
1215 1215
 #                        $itemdata['parent']['listurl'] = $section['listurl'];
1216 1216
                         if ($itemdata['section_id'] != $itemdata['subsection_id']) {
1217 1217
                             $subsection = $this->_get_subsection($itemdata);
1218
-                            $itemdata['parent']['body'] .= ': ' . $subsection['body'];
1218
+                            $itemdata['parent']['body'] .= ': '.$subsection['body'];
1219 1219
 #                            $itemdata['parent']['listurl'] = $subsection['listurl'];
1220 1220
                         }
1221 1221
                         if ($itemdata['major'] == 5) {
1222
-                            $itemdata['parent']['body'] = 'Northern Ireland Assembly: ' . $itemdata['parent']['body'];
1222
+                            $itemdata['parent']['body'] = 'Northern Ireland Assembly: '.$itemdata['parent']['body'];
1223 1223
                         } elseif ($itemdata['major'] == 6) {
1224
-                            $itemdata['parent']['body'] = 'Public Bill Committee: ' . $itemdata['parent']['body'];
1224
+                            $itemdata['parent']['body'] = 'Public Bill Committee: '.$itemdata['parent']['body'];
1225 1225
                         } elseif ($itemdata['major'] == 7) {
1226
-                            $itemdata['parent']['body'] = 'Scottish Parliament: ' . $itemdata['parent']['body'];
1226
+                            $itemdata['parent']['body'] = 'Scottish Parliament: '.$itemdata['parent']['body'];
1227 1227
                         }
1228 1228
 
1229 1229
                     } else {
@@ -1236,19 +1236,19 @@  discard block
 block discarded – undo
1236 1236
                     // Wrans or WMS
1237 1237
                     $section = $this->_get_section($itemdata);
1238 1238
                     $subsection = $this->_get_subsection($itemdata);
1239
-                    $body = $hansardmajors[$itemdata['major']]['title'] . ' &#8212; ';
1239
+                    $body = $hansardmajors[$itemdata['major']]['title'].' &#8212; ';
1240 1240
                     if (isset($section['body'])) $body .= $section['body'];
1241
-                    if (isset($subsection['body'])) $body .= ': ' . $subsection['body'];
1241
+                    if (isset($subsection['body'])) $body .= ': '.$subsection['body'];
1242 1242
                     if (isset($subsection['listurl'])) $listurl = $subsection['listurl'];
1243 1243
                     else $listurl = '';
1244
-                    $itemdata['parent'] = array (
1244
+                    $itemdata['parent'] = array(
1245 1245
                         'body' => $body,
1246 1246
                         'listurl' => $listurl
1247 1247
                     );
1248 1248
                     if ($itemdata['htype'] == 11) {
1249 1249
                         # Search result was a subsection heading; fetch the first entry
1250 1250
                         # from the wrans/wms to show under the heading
1251
-                        $input = array (
1251
+                        $input = array(
1252 1252
                             'amount' => array(
1253 1253
                                 'body' => true,
1254 1254
                                 'speaker' => true
@@ -1303,7 +1303,7 @@  discard block
 block discarded – undo
1303 1303
         }
1304 1304
 
1305 1305
         // Trim it to length and position, adding ellipses.
1306
-        $extract = trim_characters ($extract, $startpos, $length_of_extract);
1306
+        $extract = trim_characters($extract, $startpos, $length_of_extract);
1307 1307
 
1308 1308
         // Highlight search words
1309 1309
         $extract = $SEARCHENGINE->highlight($extract);
@@ -1363,7 +1363,7 @@  discard block
 block discarded – undo
1363 1363
 
1364 1364
             // A check to prevent anyone requestion 500000 months.
1365 1365
             if ($args['months'] > 12) {
1366
-                $PAGE->error_message("Sorry, you can't view " . $args['months'] . " months.");
1366
+                $PAGE->error_message("Sorry, you can't view ".$args['months']." months.");
1367 1367
                 return $data;
1368 1368
             }
1369 1369
 
@@ -1458,8 +1458,8 @@  discard block
 block discarded – undo
1458 1458
             }
1459 1459
 
1460 1460
             $params = array(
1461
-                ':firstdate' => $firstyear . '-' . $firstmonth . '-01',
1462
-                ':finaldate' => $finalyear . '-' . $finalmonth . '-31');
1461
+                ':firstdate' => $firstyear.'-'.$firstmonth.'-01',
1462
+                ':finaldate' => $finalyear.'-'.$finalmonth.'-31');
1463 1463
 
1464 1464
             // Check there are some dates for this year/month.
1465 1465
             $q = $this->db->query("SELECT epobject_id
@@ -1484,13 +1484,13 @@  discard block
 block discarded – undo
1484 1484
         $params = array();
1485 1485
 
1486 1486
         if ($finalyear > $firstyear || $finalmonth >= $firstmonth) {
1487
-            $params[':finaldate'] = $finalyear . '-' . $finalmonth . '-31';
1487
+            $params[':finaldate'] = $finalyear.'-'.$finalmonth.'-31';
1488 1488
             $where = 'AND hdate <= :finaldate';
1489 1489
         }
1490 1490
 
1491 1491
         $params[':major'] = $this->major;
1492
-        $params[':firstdate'] = $firstyear . '-' . $firstmonth . '-01';
1493
-        $q =  $this->db->query("SELECT 	DISTINCT(hdate) AS hdate
1492
+        $params[':firstdate'] = $firstyear.'-'.$firstmonth.'-01';
1493
+        $q = $this->db->query("SELECT 	DISTINCT(hdate) AS hdate
1494 1494
                         FROM		hansard
1495 1495
                         WHERE		major = :major
1496 1496
                         AND			hdate >= :firstdate
@@ -1503,7 +1503,7 @@  discard block
 block discarded – undo
1503 1503
             // We put the data in this array. See top of function for the structure.
1504 1504
             $years = array();
1505 1505
 
1506
-            for ($row=0; $row<$q->rows(); $row++) {
1506
+            for ($row = 0; $row < $q->rows(); $row++) {
1507 1507
 
1508 1508
                 list($year, $month, $day) = explode('-', $q->field($row, 'hdate'));
1509 1509
 
@@ -1557,9 +1557,9 @@  discard block
 block discarded – undo
1557 1557
             if ($action == 'recentyear') {
1558 1558
                 // Assuming there will be a previous year!
1559 1559
 
1560
-                $YEARURL->insert(array('y'=> $firstyear-1));
1560
+                $YEARURL->insert(array('y'=> $firstyear - 1));
1561 1561
 
1562
-                $nextprev['prev'] = array (
1562
+                $nextprev['prev'] = array(
1563 1563
                     'body' => 'Previous year',
1564 1564
                     'title' => $firstyear - 1,
1565 1565
                     'url' => $YEARURL->generate()
@@ -1567,8 +1567,8 @@  discard block
 block discarded – undo
1567 1567
 
1568 1568
             } else { // action is 'year'.
1569 1569
 
1570
-                $nextprev['prev'] = array ('body' => 'Previous year');
1571
-                $nextprev['next'] = array ('body' => 'Next year');
1570
+                $nextprev['prev'] = array('body' => 'Previous year');
1571
+                $nextprev['next'] = array('body' => 'Next year');
1572 1572
 
1573 1573
                 $q = $this->db->query("SELECT DATE_FORMAT(hdate, '%Y') AS year
1574 1574
                             FROM hansard WHERE major = :major
@@ -1616,7 +1616,7 @@  discard block
 block discarded – undo
1616 1616
             from mentions where gid like 'uk.org.publicwhip/spq/$spid'
1617 1617
             order by date, type");
1618 1618
         $nrows = $q->rows();
1619
-        for ($i=0; $i < $nrows; $i++) {
1619
+        for ($i = 0; $i < $nrows; $i++) {
1620 1620
             $result[$i] = $q->row($i);
1621 1621
         }
1622 1622
         return $result;
@@ -1663,14 +1663,14 @@  discard block
 block discarded – undo
1663 1663
         // $input['limit'] as a string for the $limit clause, eg '21,20'.
1664 1664
 
1665 1665
         $amount 		= isset($input['amount']) ? $input['amount'] : array();
1666
-        $wherearr 		= isset($input['where']) ? $input['where'] : array();
1666
+        $wherearr = isset($input['where']) ? $input['where'] : array();
1667 1667
         $order 			= isset($input['order']) ? $input['order'] : '';
1668 1668
         $limit 			= isset($input['limit']) ? $input['limit'] : '';
1669 1669
 
1670 1670
 
1671 1671
         // The fields to fetch from db. 'table' => array ('field1', 'field2').
1672
-        $fieldsarr = array (
1673
-            'hansard' => array ('epobject_id', 'htype', 'gid', 'hpos', 'section_id', 'subsection_id', 'hdate', 'htime', 'source_url', 'major', 'minor', 'video_status', 'colnum')
1672
+        $fieldsarr = array(
1673
+            'hansard' => array('epobject_id', 'htype', 'gid', 'hpos', 'section_id', 'subsection_id', 'hdate', 'htime', 'source_url', 'major', 'minor', 'video_status', 'colnum')
1674 1674
         );
1675 1675
 
1676 1676
         $params = array();
@@ -1682,14 +1682,14 @@  discard block
 block discarded – undo
1682 1682
         if ((isset($amount['body']) && $amount['body'] == true) ||
1683 1683
             (isset($amount['comment']) && $amount['comment'] == true)
1684 1684
             ) {
1685
-            $fieldsarr['epobject'] = array ('body');
1685
+            $fieldsarr['epobject'] = array('body');
1686 1686
             $join = 'LEFT OUTER JOIN epobject ON hansard.epobject_id = epobject.epobject_id';
1687 1687
         } else {
1688 1688
             $join = '';
1689 1689
         }
1690 1690
 
1691 1691
 
1692
-        $fieldsarr2 = array ();
1692
+        $fieldsarr2 = array();
1693 1693
         // Construct the $fields clause.
1694 1694
         foreach ($fieldsarr as $table => $tablesfields) {
1695 1695
             foreach ($tablesfields as $n => $field) {
@@ -1698,7 +1698,7 @@  discard block
 block discarded – undo
1698 1698
         }
1699 1699
         $fields = implode(', ', $fieldsarr2);
1700 1700
 
1701
-        $wherearr2 = array ();
1701
+        $wherearr2 = array();
1702 1702
         // Construct the $where clause.
1703 1703
         $i = 0;
1704 1704
         foreach ($wherearr as $key => $val) {
@@ -1706,7 +1706,7 @@  discard block
 block discarded – undo
1706 1706
             $wherearr2[] = "$key :where$i";
1707 1707
             $i++;
1708 1708
         }
1709
-        $where = implode (" AND ", $wherearr2);
1709
+        $where = implode(" AND ", $wherearr2);
1710 1710
 
1711 1711
 
1712 1712
         if ($order != '') {
@@ -1724,7 +1724,7 @@  discard block
 block discarded – undo
1724 1724
         }
1725 1725
 
1726 1726
         // Finally, do the query!
1727
-        $q = $this->db->query ("SELECT $fields
1727
+        $q = $this->db->query("SELECT $fields
1728 1728
                         FROM 	hansard
1729 1729
                         $join
1730 1730
                         WHERE $where
@@ -1733,11 +1733,11 @@  discard block
 block discarded – undo
1733 1733
                         ", $params);
1734 1734
 
1735 1735
         // Format the data into an array for returning.
1736
-        $data = array ();
1736
+        $data = array();
1737 1737
 
1738 1738
         if ($q->rows() > 0) {
1739 1739
 
1740
-            for ($n=0; $n<$q->rows(); $n++) {
1740
+            for ($n = 0; $n < $q->rows(); $n++) {
1741 1741
 
1742 1742
                 // Where we'll store the data for this item before adding
1743 1743
                 // it to $data.
@@ -1753,23 +1753,23 @@  discard block
 block discarded – undo
1753 1753
                 if (isset($item['gid'])) {
1754 1754
                     // Remove the "uk.org.publicwhip/blah/" from the gid:
1755 1755
                     // (In includes/utility.php)
1756
-                    $item['gid'] = fix_gid_from_db( $item['gid'] );
1756
+                    $item['gid'] = fix_gid_from_db($item['gid']);
1757 1757
                 }
1758 1758
 
1759 1759
                 // Add mentions if (a) it's a question in the written
1760 1760
                 // answer section or (b) it's in the official reports
1761 1761
                 // and the body text ends in a bracketed SPID.
1762
-                if (($this->major && $hansardmajors[$this->major]['page']=='spwrans') && ($item['htype'] == '12' && $item['minor'] == '1')) {
1762
+                if (($this->major && $hansardmajors[$this->major]['page'] == 'spwrans') && ($item['htype'] == '12' && $item['minor'] == '1')) {
1763 1763
                     // Get out the SPID:
1764
-                    if ( preg_match('#\d{4}-\d\d-\d\d\.(.*?)\.q#', $item['gid'], $m) ) {
1764
+                    if (preg_match('#\d{4}-\d\d-\d\d\.(.*?)\.q#', $item['gid'], $m)) {
1765 1765
                         $item['mentions'] = $this->_get_mentions($m[1]);
1766 1766
                     }
1767 1767
                 }
1768 1768
 
1769 1769
                 // The second case (b):
1770
-                if (($this->major && $hansardmajors[$this->major]['page']=='spdebates') && isset($item['body'])) {
1771
-                    $stripped_body = preg_replace('/<[^>]+>/ms','',$item['body']);
1772
-                    if ( preg_match('/\((S\d+\w+-\d+)\)/ms',$stripped_body,$m) ) {
1770
+                if (($this->major && $hansardmajors[$this->major]['page'] == 'spdebates') && isset($item['body'])) {
1771
+                    $stripped_body = preg_replace('/<[^>]+>/ms', '', $item['body']);
1772
+                    if (preg_match('/\((S\d+\w+-\d+)\)/ms', $stripped_body, $m)) {
1773 1773
                         $item['mentions'] = $this->_get_mentions($m[1]);
1774 1774
                     }
1775 1775
                 }
@@ -1782,17 +1782,17 @@  discard block
 block discarded – undo
1782 1782
                 // Get the number of items within a section or subsection.
1783 1783
                 // It could be that we can do this in the main query?
1784 1784
                 // Not sure.
1785
-                if ( ($this->major && $hansardmajors[$this->major]['type']=='debate') && ($item['htype'] == '10' || $item['htype'] == '11') ) {
1785
+                if (($this->major && $hansardmajors[$this->major]['type'] == 'debate') && ($item['htype'] == '10' || $item['htype'] == '11')) {
1786 1786
 
1787 1787
                     if ($item['htype'] == '10') {
1788 1788
                         // Section - get a count of items within this section that
1789 1789
                         // don't have a subsection heading.
1790
-                        $where = "section_id = '" . $item['epobject_id'] . "'
1791
-                            AND subsection_id = '" . $item['epobject_id'] . "'";
1790
+                        $where = "section_id = '".$item['epobject_id']."'
1791
+                            AND subsection_id = '" . $item['epobject_id']."'";
1792 1792
 
1793 1793
                     } else {
1794 1794
                         // Subsection - get a count of items within this subsection.
1795
-                        $where = "subsection_id = '" . $item['epobject_id'] . "'";
1795
+                        $where = "subsection_id = '".$item['epobject_id']."'";
1796 1796
                     }
1797 1797
 
1798 1798
                     $r = $this->db->query("SELECT COUNT(*) AS count
@@ -1843,7 +1843,7 @@  discard block
 block discarded – undo
1843 1843
                 // 'commentsurl' is the URL of the item on its own page, with comments.
1844 1844
 
1845 1845
                 // All the things we need to work out a listurl!
1846
-                $item_data = array (
1846
+                $item_data = array(
1847 1847
                     'major'			=> $this->major,
1848 1848
                     'minor' 		=> $item['minor'],
1849 1849
                     'htype' 		=> $item['htype'],
@@ -1863,8 +1863,8 @@  discard block
 block discarded – undo
1863 1863
                         # Another hack...
1864 1864
                         $COMMENTSURL->remove(array('id'));
1865 1865
                         $id = preg_replace('#^.*?_.*?_#', '', $item['gid']);
1866
-                        $fragment = $this->url . $id;
1867
-                        $item['commentsurl'] = $COMMENTSURL->generate() . $fragment;
1866
+                        $fragment = $this->url.$id;
1867
+                        $item['commentsurl'] = $COMMENTSURL->generate().$fragment;
1868 1868
                     } else {
1869 1869
                         $COMMENTSURL->insert(array('id' => $item['gid']));
1870 1870
                         $item['commentsurl'] = $COMMENTSURL->generate();
@@ -1876,11 +1876,11 @@  discard block
 block discarded – undo
1876 1876
                     $item['htype'] == '12') {
1877 1877
                     // Debate speech or written answers (not questions).
1878 1878
 
1879
-                    $item['votes'] = $this->_get_votes( $item['epobject_id'] );
1879
+                    $item['votes'] = $this->_get_votes($item['epobject_id']);
1880 1880
                 }
1881 1881
 
1882 1882
                 // Get the speaker for this item, if applicable.
1883
-                if ( (isset($amount['speaker']) && $amount['speaker'] == true) &&
1883
+                if ((isset($amount['speaker']) && $amount['speaker'] == true) &&
1884 1884
                     $item['person_id'] != '') {
1885 1885
 
1886 1886
                     $item['speaker'] = $this->_get_speaker($item['person_id'], $item['hdate'], $item['htime'], $item['major']);
@@ -1891,7 +1891,7 @@  discard block
 block discarded – undo
1891 1891
                 if (isset($amount['comment']) && $amount['comment'] == true) {
1892 1892
 
1893 1893
                     // All the things we need to get the comment data.
1894
-                    $item_data = array (
1894
+                    $item_data = array(
1895 1895
                         'htype' => $item['htype'],
1896 1896
                         'epobject_id' => $item['epobject_id']
1897 1897
                     );
@@ -1965,7 +1965,7 @@  discard block
 block discarded – undo
1965 1965
     }
1966 1966
 
1967 1967
 
1968
-    public function _get_listurl ($id_data, $url_args=array(), $encode='html') {
1968
+    public function _get_listurl($id_data, $url_args = array(), $encode = 'html') {
1969 1969
         global $hansardmajors;
1970 1970
         // Generates an item's listurl - this is the 'contextual' url
1971 1971
         // for an item, in the full list view with an anchor (if appropriate).
@@ -1991,10 +1991,10 @@  discard block
 block discarded – undo
1991 1991
             if ($this->major == 6) {
1992 1992
                 $id = preg_replace('#^.*?_.*?_#', '', $id_data['gid']);
1993 1993
                 global $DATA;
1994
-                $DATA->set_page_metadata('pbc_clause', 'url', 'pbc/' . $this->url . $id);
1994
+                $DATA->set_page_metadata('pbc_clause', 'url', 'pbc/'.$this->url.$id);
1995 1995
                 $LISTURL->remove(array('id'));
1996 1996
             } else {
1997
-                $LISTURL->insert( array( 'id' => $id_data['gid'] ) );
1997
+                $LISTURL->insert(array('id' => $id_data['gid']));
1998 1998
             }
1999 1999
         } else {
2000 2000
             // A debate speech or question/answer, etc.
@@ -2007,10 +2007,10 @@  discard block
 block discarded – undo
2007 2007
             // Find the gid of this item's (sub)section.
2008 2008
             $parent_gid = '';
2009 2009
 
2010
-            if (isset($this->epobjectid_to_gid[ $parent_epobject_id ])) {
2010
+            if (isset($this->epobjectid_to_gid[$parent_epobject_id])) {
2011 2011
                 // We've previously cached the gid for this epobject_id, so use that.
2012 2012
 
2013
-                $parent_gid = $this->epobjectid_to_gid[ $parent_epobject_id ];
2013
+                $parent_gid = $this->epobjectid_to_gid[$parent_epobject_id];
2014 2014
 
2015 2015
             } else {
2016 2016
                 // We haven't cached the gid, so fetch from db.
@@ -2023,10 +2023,10 @@  discard block
 block discarded – undo
2023 2023
                 if ($r->rows() > 0) {
2024 2024
                     // Remove the "uk.org.publicwhip/blah/" from the gid:
2025 2025
                     // (In includes/utility.php)
2026
-                    $parent_gid = fix_gid_from_db( $r->field(0, 'gid') );
2026
+                    $parent_gid = fix_gid_from_db($r->field(0, 'gid'));
2027 2027
 
2028 2028
                     // Cache it for if we need it again:
2029
-                    $this->epobjectid_to_gid[ $parent_epobject_id ] = $parent_gid;
2029
+                    $this->epobjectid_to_gid[$parent_epobject_id] = $parent_gid;
2030 2030
                 }
2031 2031
             }
2032 2032
 
@@ -2041,24 +2041,24 @@  discard block
 block discarded – undo
2041 2041
                         $session = $qq->field(0, 'session');
2042 2042
                         $this->bill_lookup[$minor] = array($title, $session);
2043 2043
                     }
2044
-                    $url = "$session/" . urlencode(str_replace(' ','_',$title));
2044
+                    $url = "$session/".urlencode(str_replace(' ', '_', $title));
2045 2045
                     $parent_gid = preg_replace('#^.*?_.*?_#', '', $parent_gid);
2046 2046
                     global $DATA;
2047 2047
                     $DATA->set_page_metadata('pbc_clause', 'url', "pbc/$url/$parent_gid");
2048 2048
                     $LISTURL->remove(array('id'));
2049 2049
                 } else {
2050
-                    $LISTURL->insert( array( 'id' => $parent_gid ) );
2050
+                    $LISTURL->insert(array('id' => $parent_gid));
2051 2051
                 }
2052 2052
                 // Use a truncated form of this item's gid for the anchor.
2053
-                $fragment = '#g' . gid_to_anchor($id_data['gid']);
2053
+                $fragment = '#g'.gid_to_anchor($id_data['gid']);
2054 2054
             }
2055 2055
         }
2056 2056
 
2057 2057
         if (count($url_args) > 0) {
2058
-            $LISTURL->insert( $url_args);
2058
+            $LISTURL->insert($url_args);
2059 2059
         }
2060 2060
 
2061
-        return $LISTURL->generate($encode) . $fragment;
2061
+        return $LISTURL->generate($encode).$fragment;
2062 2062
     }
2063 2063
 
2064 2064
     private $major_to_house = array(
@@ -2118,10 +2118,10 @@  discard block
 block discarded – undo
2118 2118
         $member = $this->_get_speaker_alone($q->data, $person_id, $hdate, $htime, $major);
2119 2119
 
2120 2120
         $URL = $this->_get_speaker_url($member['house']);
2121
-        $URL->insert( array ('p' => $person_id) );
2121
+        $URL->insert(array('p' => $person_id));
2122 2122
 
2123 2123
         $name = member_full_name($member['house'], $member['title'], $member['given_name'], $member['family_name'], $member['lordofname']);
2124
-        $speaker = array (
2124
+        $speaker = array(
2125 2125
             'member_id' => $member['member_id'],
2126 2126
             "name" => $name,
2127 2127
             'house' => $member['house'],
@@ -2160,7 +2160,7 @@  discard block
 block discarded – undo
2160 2160
             }
2161 2161
         }
2162 2162
         if (count($members) != 1) {
2163
-            throw new \Exception('Wanted one result, but got ' . count($members) . " for $person_id, $hdate, $major.");
2163
+            throw new \Exception('Wanted one result, but got '.count($members)." for $person_id, $hdate, $major.");
2164 2164
         }
2165 2165
 
2166 2166
         return $members[0];
@@ -2168,13 +2168,13 @@  discard block
 block discarded – undo
2168 2168
 
2169 2169
     private function _get_speaker_url($house) {
2170 2170
         $URL = new URL('mp'); # Default, house=1
2171
-        if ($house==2) {
2171
+        if ($house == 2) {
2172 2172
             $URL = new URL('peer');
2173
-        } elseif ($house==3) {
2173
+        } elseif ($house == 3) {
2174 2174
             $URL = new URL('mla');
2175
-        } elseif ($house==4) {
2175
+        } elseif ($house == 4) {
2176 2176
             $URL = new URL('msp');
2177
-        } elseif ($house==0) {
2177
+        } elseif ($house == 0) {
2178 2178
             $URL = new URL('royal');
2179 2179
         }
2180 2180
         return $URL;
@@ -2190,7 +2190,7 @@  discard block
 block discarded – undo
2190 2190
         if (!$rows) {
2191 2191
             return $offices;
2192 2192
         }
2193
-        for ($row=0; $row<$rows; $row++) {
2193
+        for ($row = 0; $row < $rows; $row++) {
2194 2194
             $dept = $q->field($row, 'dept');
2195 2195
             $pos = $q->field($row, 'position');
2196 2196
             $source = $q->field($row, 'source');
@@ -2249,12 +2249,12 @@  discard block
 block discarded – undo
2249 2249
                     array(':epobject_id' => $item_data['epobject_id']));
2250 2250
 
2251 2251
                 // Add this comment to the data structure.
2252
-                $comment = array (
2252
+                $comment = array(
2253 2253
                     'comment_id' => $q->field(0, 'comment_id'),
2254 2254
                     'user_id'	=> $q->field(0, 'user_id'),
2255 2255
                     'body'		=> $q->field(0, 'body'),
2256 2256
                     'posted'	=> $q->field(0, 'posted'),
2257
-                    'username'	=> $q->field(0, 'firstname') .' '. $q->field(0, 'lastname')
2257
+                    'username'	=> $q->field(0, 'firstname').' '.$q->field(0, 'lastname')
2258 2258
                 );
2259 2259
             }
2260 2260
 
@@ -2264,7 +2264,7 @@  discard block
 block discarded – undo
2264 2264
         // or subsection itself, only the items within them. So
2265 2265
         // we don't get the most recent comment. Because there isn't one.
2266 2266
 
2267
-        $return = array (
2267
+        $return = array(
2268 2268
             'totalcomments' => $totalcomments,
2269 2269
             'comment' => $comment
2270 2270
         );
@@ -2278,7 +2278,7 @@  discard block
 block discarded – undo
2278 2278
         // What it says on the tin.
2279 2279
         // $item_data must have 'htype' and 'epobject_id' elements. TODO: Check for major==4
2280 2280
 
2281
-        if (($hansardmajors[$this->major]['type']=='debate') &&
2281
+        if (($hansardmajors[$this->major]['type'] == 'debate') &&
2282 2282
             ($item_data['htype'] == '10' || $item_data['htype'] == '11')
2283 2283
             ) {
2284 2284
             // We'll be getting a count of the comments on all items
@@ -2362,7 +2362,7 @@  discard block
 block discarded – undo
2362 2362
         // Then depending on what htype it is, we get the data for other items too.
2363 2363
         global $DATA, $this_page, $hansardmajors;
2364 2364
 
2365
-        twfy_debug (get_class($this), "getting data by gid");
2365
+        twfy_debug(get_class($this), "getting data by gid");
2366 2366
 
2367 2367
         // Get the information about the item this URL refers to.
2368 2368
         $itemdata = $this->_get_item($args);
@@ -2371,25 +2371,25 @@  discard block
 block discarded – undo
2371 2371
         }
2372 2372
 
2373 2373
         // If part of a Written Answer (just question or just answer), select the whole thing
2374
-        if (isset($itemdata['major']) && $hansardmajors[$itemdata['major']]['type']=='other' and ($itemdata['htype'] == '12' or $itemdata['htype'] == '13')) {
2374
+        if (isset($itemdata['major']) && $hansardmajors[$itemdata['major']]['type'] == 'other' and ($itemdata['htype'] == '12' or $itemdata['htype'] == '13')) {
2375 2375
             // find the gid of the subheading which holds this part
2376
-            $input = array (
2376
+            $input = array(
2377 2377
                 'amount' => array('gid' => true),
2378
-                'where' => array (
2378
+                'where' => array(
2379 2379
                     'epobject_id=' => $itemdata['subsection_id'],
2380 2380
                 ),
2381 2381
             );
2382 2382
             $parent = $this->_get_hansard_data($input);
2383 2383
             // display that item, i.e. the whole of the Written Answer
2384
-            twfy_debug (get_class($this), "instead of " . $args['gid'] . " selecting subheading gid " . $parent[0]['gid'] . " to get whole wrans");
2384
+            twfy_debug(get_class($this), "instead of ".$args['gid']." selecting subheading gid ".$parent[0]['gid']." to get whole wrans");
2385 2385
             $args['gid'] = $parent[0]['gid'];
2386 2386
             $this->_get_item($args);
2387 2387
             throw new RedirectException($args['gid']);
2388 2388
         }
2389 2389
 
2390 2390
         # If a WMS main heading, go to next gid
2391
-        if (isset($itemdata['major']) && $itemdata['major']==4 && $itemdata['htype'] == '10') {
2392
-            $input = array (
2391
+        if (isset($itemdata['major']) && $itemdata['major'] == 4 && $itemdata['htype'] == '10') {
2392
+            $input = array(
2393 2393
                 'amount' => array('gid' => true),
2394 2394
                 'where' => array(
2395 2395
                     'section_id=' => $itemdata['epobject_id'],
@@ -2399,7 +2399,7 @@  discard block
 block discarded – undo
2399 2399
             );
2400 2400
             $next = $this->_get_hansard_data($input);
2401 2401
             if (!empty($next)) {
2402
-                twfy_debug (get_class($this), 'instead of ' . $args['gid'] . ' moving to ' . $next[0]['gid']);
2402
+                twfy_debug(get_class($this), 'instead of '.$args['gid'].' moving to '.$next[0]['gid']);
2403 2403
                 $args['gid'] = $next[0]['gid'];
2404 2404
                 $this->_get_item($args);
2405 2405
                 throw new RedirectException($args['gid']);
@@ -2451,16 +2451,16 @@  discard block
 block discarded – undo
2451 2451
         // Get the nextprev links for this item, to link to next/prev pages.
2452 2452
         // Duh.
2453 2453
         if ($itemdata['htype'] == '10') {
2454
-            $nextprev = $this->_get_nextprev_items( $sectionrow );
2454
+            $nextprev = $this->_get_nextprev_items($sectionrow);
2455 2455
             $data['info']['text_heading'] = $itemdata['body'];
2456 2456
 
2457 2457
         } elseif ($itemdata['htype'] == '11') {
2458
-            $nextprev = $this->_get_nextprev_items( $subsectionrow );
2458
+            $nextprev = $this->_get_nextprev_items($subsectionrow);
2459 2459
             $data['info']['text_heading'] = $itemdata['body'];
2460 2460
 
2461 2461
         } else {
2462 2462
             // Ordinary lowly item.
2463
-            $nextprev = $this->_get_nextprev_items( $itemdata );
2463
+            $nextprev = $this->_get_nextprev_items($itemdata);
2464 2464
 
2465 2465
             if (isset($subsectionrow['gid'])) {
2466 2466
                 $nextprev['up']['url'] 		= $subsectionrow['listurl'];
@@ -2469,7 +2469,7 @@  discard block
 block discarded – undo
2469 2469
                 $nextprev['up']['url'] 		= $sectionrow['listurl'];
2470 2470
                 $nextprev['up']['title'] 	= $sectionrow['body'];
2471 2471
             }
2472
-            $nextprev['up']['body']		= 'See the whole debate';
2472
+            $nextprev['up']['body'] = 'See the whole debate';
2473 2473
         }
2474 2474
 
2475 2475
         // We can then access this from $PAGE and the templates.
@@ -2478,7 +2478,7 @@  discard block
 block discarded – undo
2478 2478
         // Now get all the non-heading rows.
2479 2479
 
2480 2480
         // What data do we want for each item?
2481
-        $amount = array (
2481
+        $amount = array(
2482 2482
             'body' => true,
2483 2483
             'speaker' => true,
2484 2484
             'comment' => true,
@@ -2491,9 +2491,9 @@  discard block
 block discarded – undo
2491 2491
 
2492 2492
             # $sectionrow['trackback'] = $this->_get_trackback_data($sectionrow);
2493 2493
 
2494
-            $input = array (
2494
+            $input = array(
2495 2495
                 'amount' => $amount,
2496
-                'where' => array (
2496
+                'where' => array(
2497 2497
                     'section_id=' => $itemdata['epobject_id'],
2498 2498
                     'subsection_id=' => $itemdata['epobject_id']
2499 2499
                 ),
@@ -2501,15 +2501,15 @@  discard block
 block discarded – undo
2501 2501
             );
2502 2502
 
2503 2503
             $data['rows'] = $this->_get_hansard_data($input);
2504
-            if (!count($data['rows']) || (count($data['rows'])==1 && strstr($data['rows'][0]['body'], 'was asked'))) {
2504
+            if (!count($data['rows']) || (count($data['rows']) == 1 && strstr($data['rows'][0]['body'], 'was asked'))) {
2505 2505
 
2506
-                $input = array (
2507
-                    'amount' => array (
2506
+                $input = array(
2507
+                    'amount' => array(
2508 2508
                         'body' => true,
2509 2509
                         'comment' => true,
2510 2510
                         'excerpt' => true
2511 2511
                     ),
2512
-                    'where' => array (
2512
+                    'where' => array(
2513 2513
                         'section_id='	=> $sectionrow['epobject_id'],
2514 2514
                         'htype='		=> '11',
2515 2515
                         'major='		=> $this->major
@@ -2527,9 +2527,9 @@  discard block
 block discarded – undo
2527 2527
 
2528 2528
             # $subsectionrow['trackback'] = $this->_get_trackback_data($subsectionrow);
2529 2529
 
2530
-            $input = array (
2530
+            $input = array(
2531 2531
                 'amount' => $amount,
2532
-                'where' => array (
2532
+                'where' => array(
2533 2533
                     'subsection_id=' => $itemdata['epobject_id']
2534 2534
                 ),
2535 2535
                 'order' => 'hpos ASC'
@@ -2552,10 +2552,10 @@  discard block
 block discarded – undo
2552 2552
             $subsectionrow['gid'] != $sectionrow['gid']) {
2553 2553
             // If we're looking at a section, there may not be a subsection.
2554 2554
             // And if the subsectionrow and sectionrow aren't the same.
2555
-            array_unshift ($data['rows'], $subsectionrow);
2555
+            array_unshift($data['rows'], $subsectionrow);
2556 2556
         }
2557 2557
 
2558
-        array_unshift ($data['rows'], $sectionrow);
2558
+        array_unshift($data['rows'], $sectionrow);
2559 2559
 
2560 2560
         return $data;
2561 2561
 
@@ -2564,10 +2564,10 @@  discard block
 block discarded – undo
2564 2564
     public function _get_data_by_column($args) {
2565 2565
         global $this_page;
2566 2566
 
2567
-        twfy_debug (get_class($this), "getting data by column");
2567
+        twfy_debug(get_class($this), "getting data by column");
2568 2568
 
2569
-        $input = array( 'amount' => array('body'=>true, 'comment'=>true, 'speaker'=>true),
2570
-        'where' => array( 'hdate='=>$args['date'], 'major=' => $this->major, 'gid LIKE ' =>'%.'.$args['column'].'.%' ),
2569
+        $input = array('amount' => array('body'=>true, 'comment'=>true, 'speaker'=>true),
2570
+        'where' => array('hdate='=>$args['date'], 'major=' => $this->major, 'gid LIKE ' =>'%.'.$args['column'].'.%'),
2571 2571
         'order' => 'hpos'
2572 2572
         );
2573 2573
         $data = $this->_get_hansard_data($input);
@@ -2626,11 +2626,11 @@  discard block
 block discarded – undo
2626 2626
     public function get_gid_from_spid($spid) {
2627 2627
         // Fix the common errors of S.0 instead of S.O and leading
2628 2628
         // zeros in the numbers:
2629
-        $fixed_spid = preg_replace('/(S[0-9]+)0-([0-9]+)/','${1}O-${2}',$spid);
2630
-        $fixed_spid = preg_replace('/(S[0-9]+\w+)-0*([0-9]+)/','${1}-${2}',$fixed_spid);
2629
+        $fixed_spid = preg_replace('/(S[0-9]+)0-([0-9]+)/', '${1}O-${2}', $spid);
2630
+        $fixed_spid = preg_replace('/(S[0-9]+\w+)-0*([0-9]+)/', '${1}-${2}', $fixed_spid);
2631 2631
         $q = $this->db->query(
2632 2632
             "select mentioned_gid from mentions where gid = :gid_from_spid and (type = 4 or type = 6)",
2633
-            array(':gid_from_spid' => 'uk.org.publicwhip/spq/' . $fixed_spid)
2633
+            array(':gid_from_spid' => 'uk.org.publicwhip/spq/'.$fixed_spid)
2634 2634
         );
2635 2635
         $gid = $q->field(0, 'mentioned_gid');
2636 2636
         if ($gid) return $gid;
@@ -2639,7 +2639,7 @@  discard block
 block discarded – undo
2639 2639
     public function old_get_gid_from_spid($spid) {
2640 2640
         $q = $this->db->query(
2641 2641
             "select gid from hansard where gid like :gid_like",
2642
-            array(':gid_like' => 'uk.org.publicwhip/spwa/%.' . $spid . '.h')
2642
+            array(':gid_like' => 'uk.org.publicwhip/spwa/%.'.$spid.'.h')
2643 2643
         );
2644 2644
         $gid = $q->field(0, 'gid');
2645 2645
         if ($gid) return str_replace('uk.org.publicwhip/spwa/', '', $gid);
@@ -2702,14 +2702,14 @@  discard block
 block discarded – undo
2702 2702
                         ", array(':major' => $this->major));
2703 2703
 
2704 2704
         // What we return.
2705
-        $data = array ();
2705
+        $data = array();
2706 2706
         $speeches = array();
2707 2707
 
2708 2708
         if ($q->rows() > 0) {
2709 2709
 
2710
-            for ($n=0; $n<$q->rows(); $n++) {
2710
+            for ($n = 0; $n < $q->rows(); $n++) {
2711 2711
 
2712
-                $speech = array (
2712
+                $speech = array(
2713 2713
                     'subsection_id'	=> $q->field($n, 'subsection_id'),
2714 2714
                     'section_id'	=> $q->field($n, 'section_id'),
2715 2715
                     'htype'			=> $q->field($n, 'htype'),
@@ -2722,11 +2722,11 @@  discard block
 block discarded – undo
2722 2722
 
2723 2723
                 // Remove the "uk.org.publicwhip/blah/" from the gid:
2724 2724
                 // (In includes/utility.php)
2725
-                $speech['gid'] = fix_gid_from_db( $q->field($n, 'gid') );
2725
+                $speech['gid'] = fix_gid_from_db($q->field($n, 'gid'));
2726 2726
 
2727 2727
                 $speech['listurl'] = $this->_get_listurl($speech);
2728 2728
 
2729
-                $speech['speaker'] = $this->_get_speaker($q->field($n, 'person_id'), $q->field($n, 'hdate'), $q->field($n, 'htime'), $this->major );
2729
+                $speech['speaker'] = $this->_get_speaker($q->field($n, 'person_id'), $q->field($n, 'hdate'), $q->field($n, 'htime'), $this->major);
2730 2730
 
2731 2731
                 $speeches[] = $speech;
2732 2732
             }
@@ -2736,10 +2736,10 @@  discard block
 block discarded – undo
2736 2736
             // Get the subsection texts.
2737 2737
 
2738 2738
             $num_speeches = count($speeches);
2739
-            for ($n=0; $n<$num_speeches; $n++) {
2739
+            for ($n = 0; $n < $num_speeches; $n++) {
2740 2740
                 //if ($this->major == 1) {
2741 2741
                     // Debate.
2742
-                    $parent = $this->_get_subsection ($speeches[$n]);
2742
+                    $parent = $this->_get_subsection($speeches[$n]);
2743 2743
 
2744 2744
                 //} elseif ($this->major == 3) {
2745 2745
                     // Wrans.
@@ -2758,7 +2758,7 @@  discard block
 block discarded – undo
2758 2758
             $data['rows'] = $speeches;
2759 2759
 
2760 2760
         } else {
2761
-            $data['rows'] = array ();
2761
+            $data['rows'] = array();
2762 2762
         }
2763 2763
 
2764 2764
         $data['info']['days'] = $days;
@@ -2775,13 +2775,13 @@  discard block
 block discarded – undo
2775 2775
     }
2776 2776
 
2777 2777
 
2778
-    public function biggest_debates($args=array()) {
2778
+    public function biggest_debates($args = array()) {
2779 2779
         // So we can just get the data back for special formatting
2780 2780
         // on the front page, without doing the whole display() thing.
2781 2781
         return $this->_get_data_by_biggest_debates($args);
2782 2782
     }
2783 2783
 
2784
-    public function _get_data_by_featured_gid($args=array()) {
2784
+    public function _get_data_by_featured_gid($args = array()) {
2785 2785
         $params = array();
2786 2786
         $data = array();
2787 2787
 
@@ -2807,21 +2807,21 @@  discard block
 block discarded – undo
2807 2807
 
2808 2808
         $q = $this->db->query($query, $params);
2809 2809
 
2810
-        if ( $q->rows ) {
2810
+        if ($q->rows) {
2811 2811
 
2812 2812
             // This array just used for getting further data about this debate.
2813
-            $item_data = array (
2813
+            $item_data = array(
2814 2814
                 'major'         => $this->major,
2815 2815
                 'minor'         => $q->field(0, 'minor'),
2816
-                'gid'           => fix_gid_from_db( $q->field(0, 'gid') ),
2816
+                'gid'           => fix_gid_from_db($q->field(0, 'gid')),
2817 2817
                 'htype'         => $q->field(0, 'htype'),
2818 2818
                 'section_id'    => $q->field(0, 'section_id'),
2819 2819
                 'subsection_id' => $q->field(0, 'subsection_id'),
2820 2820
                 'epobject_id'   => $q->field(0, 'epobject_id')
2821 2821
             );
2822 2822
 
2823
-            $list_url      = $this->_get_listurl( $item_data );
2824
-            $totalcomments = $this->_get_comment_count_for_epobject( $item_data );
2823
+            $list_url      = $this->_get_listurl($item_data);
2824
+            $totalcomments = $this->_get_comment_count_for_epobject($item_data);
2825 2825
 
2826 2826
             $body          = $q->field(0, 'body');
2827 2827
             $hdate         = $q->field(0, 'hdate');
@@ -2841,21 +2841,21 @@  discard block
 block discarded – undo
2841 2841
                                     ':subsection_id' => $item_data['subsection_id'],
2842 2842
                                 )
2843 2843
                             );
2844
-                $section_body  = $r->field(0, 'sec_body');
2844
+                $section_body = $r->field(0, 'sec_body');
2845 2845
                 $subsection_body = $r->field(0, 'sub_body');
2846
-                if ( $section_body && $subsection_body ) {
2846
+                if ($section_body && $subsection_body) {
2847 2847
                     $parentbody = "$section_body : $subsection_body";
2848 2848
                 } else {
2849 2849
                     $parentbody = "$section_body$subsection_body";
2850 2850
                 }
2851
-            } else if ( $item_data['htype'] == 10 ) {
2851
+            } else if ($item_data['htype'] == 10) {
2852 2852
                 $parentbody = $body;
2853 2853
             }
2854 2854
 
2855 2855
             // Get the question for this item.
2856
-            if ( $item_data['htype'] == 12 ) {
2856
+            if ($item_data['htype'] == 12) {
2857 2857
                 $childbody = $body;
2858
-                $speaker = $this->_get_speaker($q->field(0, 'person_id'), $q->field(0, 'hdate'), $q->field(0, 'htime'), $this->major );
2858
+                $speaker = $this->_get_speaker($q->field(0, 'person_id'), $q->field(0, 'hdate'), $q->field(0, 'htime'), $this->major);
2859 2859
             } else {
2860 2860
                 $r = $this->db->query("SELECT e.body, e.title,
2861 2861
                                         h.person_id, h.hdate, h.htime
@@ -2865,10 +2865,10 @@  discard block
 block discarded – undo
2865 2865
                                 ORDER BY hpos
2866 2866
                                 LIMIT 1
2867 2867
                                 ",
2868
-                                array( ':object_id' => $item_data['epobject_id'] )
2868
+                                array(':object_id' => $item_data['epobject_id'])
2869 2869
                 );
2870 2870
                 $childbody = $r->field(0, 'body');
2871
-                $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major );
2871
+                $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major);
2872 2872
             }
2873 2873
 
2874 2874
             $contentcount = 0;
@@ -2884,7 +2884,7 @@  discard block
 block discarded – undo
2884 2884
             }
2885 2885
 
2886 2886
             global $hansardmajors;
2887
-            $more_url = new \URL( $hansardmajors[$this->major]['page_all'] );
2887
+            $more_url = new \URL($hansardmajors[$this->major]['page_all']);
2888 2888
             $details = array(
2889 2889
                 'body'          => $body,
2890 2890
                 'contentcount'  => $contentcount,
@@ -2903,7 +2903,7 @@  discard block
 block discarded – undo
2903 2903
                 'more_url' => $more_url->generate()
2904 2904
             );
2905 2905
 
2906
-            $data = array (
2906
+            $data = array(
2907 2907
                 'gid' => $args['gid'],
2908 2908
                 'major' => $this->major,
2909 2909
                 'info' => array(),
@@ -2914,7 +2914,7 @@  discard block
 block discarded – undo
2914 2914
         return $data;
2915 2915
 
2916 2916
     }
2917
-    public function _get_data_by_recent_debates($args=array()) {
2917
+    public function _get_data_by_recent_debates($args = array()) {
2918 2918
         // Returns an array of some random recent debates from a set number of
2919 2919
         // recent days (that's recent days starting from the most recent day
2920 2920
         // that had any debates on).
@@ -2972,20 +2972,20 @@  discard block
 block discarded – undo
2972 2972
 
2973 2973
         $q = $this->db->query($query, $params);
2974 2974
 
2975
-        for ($row=0; $row<$q->rows; $row++) {
2975
+        for ($row = 0; $row < $q->rows; $row++) {
2976 2976
 
2977 2977
             // This array just used for getting further data about this debate.
2978
-            $item_data = array (
2978
+            $item_data = array(
2979 2979
                 'major'         => $this->major,
2980
-                'gid'           => fix_gid_from_db( $q->field($row, 'gid') ),
2980
+                'gid'           => fix_gid_from_db($q->field($row, 'gid')),
2981 2981
                 'htype'         => $q->field($row, 'htype'),
2982 2982
                 'section_id'    => $q->field($row, 'section_id'),
2983 2983
                 'subsection_id' => $q->field($row, 'subsection_id'),
2984 2984
                 'epobject_id'   => $q->field($row, 'epobject_id')
2985 2985
             );
2986 2986
 
2987
-            $list_url      = $this->_get_listurl( $item_data );
2988
-            $totalcomments = $this->_get_comment_count_for_epobject( $item_data );
2987
+            $list_url      = $this->_get_listurl($item_data);
2988
+            $totalcomments = $this->_get_comment_count_for_epobject($item_data);
2989 2989
 
2990 2990
             $contentcount  = $q->field($row, 'count');
2991 2991
             $body          = $q->field($row, 'body');
@@ -3008,12 +3008,12 @@  discard block
 block discarded – undo
3008 3008
                                     h.person_id, h.hdate, h.htime
3009 3009
                             FROM    hansard h, epobject e
3010 3010
                             WHERE   h.epobject_id = e.epobject_id
3011
-                            AND     h.subsection_id = '" . $item_data['epobject_id'] . "'
3011
+                            AND     h.subsection_id = '" . $item_data['epobject_id']."'
3012 3012
                             ORDER BY hpos
3013 3013
                             LIMIT 1
3014 3014
                             ");
3015 3015
             $childbody = $r->field(0, 'body');
3016
-            $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major );
3016
+            $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major);
3017 3017
 
3018 3018
             $data[] = array(
3019 3019
                 'contentcount'  => $contentcount,
@@ -3033,7 +3033,7 @@  discard block
 block discarded – undo
3033 3033
 
3034 3034
         }
3035 3035
 
3036
-        $data = array (
3036
+        $data = array(
3037 3037
             'info' => array(),
3038 3038
             'data' => $data
3039 3039
         );
@@ -3042,7 +3042,7 @@  discard block
 block discarded – undo
3042 3042
 
3043 3043
     }
3044 3044
 
3045
-    public function _get_data_by_biggest_debates($args=array()) {
3045
+    public function _get_data_by_biggest_debates($args = array()) {
3046 3046
         // Returns an array of the debates with most speeches in from
3047 3047
         // a set number of recent days (that's recent days starting from the
3048 3048
         // most recent day that had any debates on).
@@ -3094,28 +3094,28 @@  discard block
 block discarded – undo
3094 3094
                         LIMIT :limit", $params);
3095 3095
 
3096 3096
 
3097
-        for ($row=0; $row<$q->rows; $row++) {
3097
+        for ($row = 0; $row < $q->rows; $row++) {
3098 3098
 
3099 3099
             // This array just used for getting further data about this debate.
3100
-            $item_data = array (
3100
+            $item_data = array(
3101 3101
                 'major'			=> $this->major,
3102
-                'gid'			=> fix_gid_from_db( $q->field($row, 'gid') ),
3102
+                'gid'			=> fix_gid_from_db($q->field($row, 'gid')),
3103 3103
                 'htype'			=> $q->field($row, 'htype'),
3104 3104
                 'section_id'	=> $q->field($row, 'section_id'),
3105 3105
                 'subsection_id'	=> $q->field($row, 'subsection_id'),
3106 3106
                 'epobject_id'	=> $q->field($row, 'epobject_id')
3107 3107
             );
3108 3108
 
3109
-            $list_url 		= $this->_get_listurl( $item_data );
3110
-            $totalcomments	= $this->_get_comment_count_for_epobject( $item_data );
3109
+            $list_url = $this->_get_listurl($item_data);
3110
+            $totalcomments = $this->_get_comment_count_for_epobject($item_data);
3111 3111
 
3112
-            $contentcount	= $q->field($row, 'count');
3112
+            $contentcount = $q->field($row, 'count');
3113 3113
             $body 			= $q->field($row, 'body');
3114 3114
             $hdate			= $q->field($row, 'hdate');
3115 3115
 
3116 3116
 
3117 3117
             // This array will be added to $data, which is what gets returned.
3118
-            $debate = array (
3118
+            $debate = array(
3119 3119
                 'contentcount'	=> $contentcount,
3120 3120
                 'body'			=> $body,
3121 3121
                 'hdate'			=> $hdate,
@@ -3138,12 +3138,12 @@  discard block
 block discarded – undo
3138 3138
                                     h.person_id, h.hdate, h.htime
3139 3139
                             FROM    hansard h, epobject e
3140 3140
                             WHERE   h.epobject_id = e.epobject_id
3141
-                            AND     h.subsection_id = '" . $item_data['epobject_id'] . "'
3141
+                            AND     h.subsection_id = '" . $item_data['epobject_id']."'
3142 3142
                             ORDER BY hpos
3143 3143
                             LIMIT 1
3144 3144
                             ");
3145 3145
             $childbody = $r->field(0, 'body');
3146
-            $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major );
3146
+            $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major);
3147 3147
 
3148 3148
             $debate['child'] = array(
3149 3149
                 'body' => $childbody,
@@ -3153,7 +3153,7 @@  discard block
 block discarded – undo
3153 3153
             $data[] = $debate;
3154 3154
         }
3155 3155
 
3156
-        $data = array (
3156
+        $data = array(
3157 3157
             'info' => array(),
3158 3158
             'data' => $data
3159 3159
         );
@@ -3176,7 +3176,7 @@  discard block
 block discarded – undo
3176 3176
         return $q->field(0, 'count');
3177 3177
     }
3178 3178
 
3179
-    public function _get_data_by_recent_wrans ($args=array()) {
3179
+    public function _get_data_by_recent_wrans($args = array()) {
3180 3180
         global $hansardmajors;
3181 3181
 
3182 3182
         // $args['days'] is the number of days back to look for biggest debates.
@@ -3238,19 +3238,19 @@  discard block
 block discarded – undo
3238 3238
 
3239 3239
         $q = $this->db->query($query, $params);
3240 3240
 
3241
-        for ($row=0; $row<$q->rows; $row++) {
3241
+        for ($row = 0; $row < $q->rows; $row++) {
3242 3242
             // This array just used for getting further data about this debate.
3243
-            $item_data = array (
3243
+            $item_data = array(
3244 3244
                 'major'			=> $this->major,
3245
-                'gid'			=> fix_gid_from_db( $q->field($row, 'gid') ),
3245
+                'gid'			=> fix_gid_from_db($q->field($row, 'gid')),
3246 3246
                 'htype'			=> $q->field($row, 'htype'),
3247 3247
                 'section_id'	=> $q->field($row, 'section_id'),
3248 3248
                 'subsection_id'	=> $q->field($row, 'subsection_id'),
3249 3249
                 'epobject_id'	=> $q->field($row, 'epobject_id')
3250 3250
             );
3251 3251
 
3252
-            $list_url 		= $this->_get_listurl( $item_data );
3253
-            $totalcomments	= $this->_get_comment_count_for_epobject( $item_data );
3252
+            $list_url = $this->_get_listurl($item_data);
3253
+            $totalcomments = $this->_get_comment_count_for_epobject($item_data);
3254 3254
 
3255 3255
             $body 			= $q->field($row, 'body');
3256 3256
             $hdate			= $q->field($row, 'hdate');
@@ -3261,7 +3261,7 @@  discard block
 block discarded – undo
3261 3261
                 $r = $this->db->query("SELECT e.body
3262 3262
                             FROM	hansard h, epobject e
3263 3263
                             WHERE	h.epobject_id = e.epobject_id
3264
-                            AND		h.epobject_id = '" . $q->field($row, 'section_id') . "'
3264
+                            AND		h.epobject_id = '" . $q->field($row, 'section_id')."'
3265 3265
                             ");
3266 3266
                 $parentbody = $r->field(0, 'body');
3267 3267
             }
@@ -3271,30 +3271,30 @@  discard block
 block discarded – undo
3271 3271
                                     h.person_id, h.hdate, h.htime
3272 3272
                             FROM	hansard h, epobject e
3273 3273
                             WHERE	h.epobject_id = e.epobject_id
3274
-                            AND 	h.subsection_id = '" . $q->field($row, 'epobject_id') . "'
3274
+                            AND 	h.subsection_id = '" . $q->field($row, 'epobject_id')."'
3275 3275
                             ORDER BY hpos
3276 3276
                             LIMIT 1
3277 3277
                             ");
3278 3278
             $childbody = $r->field(0, 'body');
3279
-            $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major );
3279
+            $speaker = $this->_get_speaker($r->field(0, 'person_id'), $r->field(0, 'hdate'), $r->field(0, 'htime'), $this->major);
3280 3280
 
3281
-            $data[] = array (
3281
+            $data[] = array(
3282 3282
                 'body'			=> $body,
3283 3283
                 'hdate'			=> $hdate,
3284 3284
                 'list_url'		=> $list_url,
3285 3285
                 'totalcomments'	=> $totalcomments,
3286
-                'child'			=> array (
3286
+                'child'			=> array(
3287 3287
                     'body'		=> $childbody,
3288 3288
                     'speaker'	=> $speaker
3289 3289
                 ),
3290
-                'parent'		=> array (
3290
+                'parent'		=> array(
3291 3291
                     'body'		=> $parentbody
3292 3292
                 )
3293 3293
             );
3294 3294
 
3295 3295
         }
3296 3296
 
3297
-        $data = array (
3297
+        $data = array(
3298 3298
             'info' => array(),
3299 3299
             'data' => $data
3300 3300
         );
@@ -3311,11 +3311,11 @@  discard block
 block discarded – undo
3311 3311
     public $commentspage = 'pbc_speech';
3312 3312
     public $gidprefix = 'uk.org.publicwhip/standing/';
3313 3313
 
3314
-    public function __construct($session='', $title='') {
3314
+    public function __construct($session = '', $title = '') {
3315 3315
         parent::__construct();
3316 3316
         $this->bill_title = $title;
3317 3317
         $title = str_replace(' ', '_', $title);
3318
-        $this->url = urlencode($session) . '/' . urlencode($title) . '/';
3318
+        $this->url = urlencode($session).'/'.urlencode($title).'/';
3319 3319
     }
3320 3320
 
3321 3321
     public function _get_committee($bill_id) {
@@ -3332,7 +3332,7 @@  discard block
 block discarded – undo
3332 3332
                 where bill_id = :bill_id group by person_id',
3333 3333
             array(':bill_id' => $bill_id));
3334 3334
         $comm = array('sittings' => $sittings, 'chairmen' => array(), 'members' => array());
3335
-        for ($i=0; $i<$q->rows(); $i++) {
3335
+        for ($i = 0; $i < $q->rows(); $i++) {
3336 3336
             $person_id = $q->field($i, 'person_id');
3337 3337
             $mp = new MEMBER(array('person_id'=>$person_id));
3338 3338
             $attending = $q->field($i, 'attending');
@@ -3353,13 +3353,13 @@  discard block
 block discarded – undo
3353 3353
     public function _get_data_by_bill($args) {
3354 3354
         global $DATA, $this_page;
3355 3355
         $data = array();
3356
-        $input = array (
3357
-            'amount' => array (
3356
+        $input = array(
3357
+            'amount' => array(
3358 3358
                 'body' => true,
3359 3359
                 'comment' => true,
3360 3360
                 'excerpt' => true
3361 3361
             ),
3362
-            'where' => array (
3362
+            'where' => array(
3363 3363
                 'htype=' => '10',
3364 3364
                 'major=' => $this->major,
3365 3365
                 'minor=' => $args['id'],
@@ -3370,18 +3370,18 @@  discard block
 block discarded – undo
3370 3370
         if (count($sections) > 0) {
3371 3371
             $data['rows'] = array();
3372 3372
             $num_sections = count($sections);
3373
-            for ($n=0; $n<$num_sections; $n++) {
3373
+            for ($n = 0; $n < $num_sections; $n++) {
3374 3374
                 $sectionrow = $sections[$n];
3375 3375
                 list($sitting, $part) = $this->_get_sitting($sectionrow['gid']);
3376 3376
                 $sectionrow['sitting'] = $sitting;
3377 3377
                 $sectionrow['part'] = $part;
3378
-                $input = array (
3379
-                    'amount' => array (
3378
+                $input = array(
3379
+                    'amount' => array(
3380 3380
                         'body' => true,
3381 3381
                         'comment' => true,
3382 3382
                         'excerpt' => true
3383 3383
                     ),
3384
-                    'where' => array (
3384
+                    'where' => array(
3385 3385
                         'section_id='	=> $sectionrow['epobject_id'],
3386 3386
                         'htype='	=> '11',
3387 3387
                         'major='	=> $this->major
@@ -3389,8 +3389,8 @@  discard block
 block discarded – undo
3389 3389
                     'order' => 'hpos'
3390 3390
                 );
3391 3391
                 $rows = $this->_get_hansard_data($input);
3392
-                array_unshift ($rows, $sectionrow);
3393
-                $data['rows'] = array_merge ($data['rows'], $rows);
3392
+                array_unshift($rows, $sectionrow);
3393
+                $data['rows'] = array_merge($data['rows'], $rows);
3394 3394
             }
3395 3395
         }
3396 3396
         $data['info']['bill'] = $args['title'];
@@ -3408,18 +3408,18 @@  discard block
 block discarded – undo
3408 3408
             array(':session' => $session)
3409 3409
         );
3410 3410
         $bills = array();
3411
-        for ($i=0; $i<$q->rows(); $i++) {
3411
+        for ($i = 0; $i < $q->rows(); $i++) {
3412 3412
             $bills[$q->field($i, 'id')] = $q->field($i, 'title');
3413 3413
         }
3414 3414
         if (!count($bills)) {
3415 3415
             return array();
3416 3416
         }
3417 3417
         $q = $this->db->query('select minor,count(*) as c from hansard where major=6 and htype=12
3418
-            and minor in (' . join(',', array_keys($bills)) . ')
3418
+            and minor in (' . join(',', array_keys($bills)).')
3419 3419
             group by minor');
3420 3420
         $counts = array();
3421 3421
         # $comments = array();
3422
-        for ($i=0; $i<$q->rows(); $i++) {
3422
+        for ($i = 0; $i < $q->rows(); $i++) {
3423 3423
             $minor = $q->field($i, 'minor');
3424 3424
             $counts[$minor] = $q->field($i, 'c');
3425 3425
             # $comments[$minor] = 0;
@@ -3438,7 +3438,7 @@  discard block
 block discarded – undo
3438 3438
         foreach ($bills as $id => $title) {
3439 3439
             $data[] = array(
3440 3440
                 'title' => $title,
3441
-                'url' => "/pbc/" . urlencode($session) . '/' . urlencode(str_replace(' ', '_', $title)) . '/',
3441
+                'url' => "/pbc/".urlencode($session).'/'.urlencode(str_replace(' ', '_', $title)).'/',
3442 3442
                 'contentcount' => isset($counts[$id]) ? $counts[$id] : '???',
3443 3443
                 # 'totalcomments' => isset($comments[$id]) ? $comments[$id] : '???',
3444 3444
             );
@@ -3446,8 +3446,8 @@  discard block
 block discarded – undo
3446 3446
 
3447 3447
         $YEARURL = new URL('pbc_session');
3448 3448
         $nextprev = array();
3449
-        $nextprev['prev'] = array ('body' => 'Previous session', 'title'=>'');
3450
-        $nextprev['next'] = array ('body' => 'Next session', 'title'=>'');
3449
+        $nextprev['prev'] = array('body' => 'Previous session', 'title'=>'');
3450
+        $nextprev['next'] = array('body' => 'Next session', 'title'=>'');
3451 3451
         $q = $this->db->query(
3452 3452
             "SELECT session FROM bills WHERE session < :session ORDER BY session DESC LIMIT 1",
3453 3453
             array(':session' => $session)
@@ -3459,10 +3459,10 @@  discard block
 block discarded – undo
3459 3459
         );
3460 3460
         $nextyear = $q->field(0, 'session');
3461 3461
         if ($prevyear) {
3462
-            $nextprev['prev']['url'] = $YEARURL->generate() . $prevyear . '/';
3462
+            $nextprev['prev']['url'] = $YEARURL->generate().$prevyear.'/';
3463 3463
         }
3464 3464
         if ($nextyear) {
3465
-            $nextprev['next']['url'] = $YEARURL->generate() . $nextyear . '/';
3465
+            $nextprev['next']['url'] = $YEARURL->generate().$nextyear.'/';
3466 3466
         }
3467 3467
         $DATA->set_page_metadata($this_page, 'nextprev', $nextprev);
3468 3468
 
@@ -3475,7 +3475,7 @@  discard block
 block discarded – undo
3475 3475
             where htype=10 and major=6
3476 3476
             order by hdate desc limit ' . $args['num']);
3477 3477
         $data = array();
3478
-        for ($i=0; $i<$q->rows(); $i++) {
3478
+        for ($i = 0; $i < $q->rows(); $i++) {
3479 3479
             $minor = $q->field($i, 'minor');
3480 3480
             $gid = $q->field($i, 'gid');
3481 3481
             $hdate = format_date($q->field($i, 'hdate'), LONGDATEFORMAT);
@@ -3483,12 +3483,12 @@  discard block
 block discarded – undo
3483 3483
             $title = $qq->field(0, 'title');
3484 3484
             $session = $qq->field(0, 'session');
3485 3485
             list($sitting, $part) = $this->_get_sitting($gid);
3486
-            $sitting_txt = make_ranking($sitting) . ' sitting';
3487
-            if ($part>0) $sitting .= ", part $part";
3486
+            $sitting_txt = make_ranking($sitting).' sitting';
3487
+            if ($part > 0) $sitting .= ", part $part";
3488 3488
             $data[$hdate][] = array(
3489 3489
                 'bill'=> $title,
3490 3490
                 'sitting' => $sitting_txt,
3491
-                'url' => "/pbc/$session/" . urlencode(str_replace(' ','_',$title)) . '/#sitting' . $sitting,
3491
+                'url' => "/pbc/$session/".urlencode(str_replace(' ', '_', $title)).'/#sitting'.$sitting,
3492 3492
             );
3493 3493
         }
3494 3494
         return $data;
@@ -3497,7 +3497,7 @@  discard block
 block discarded – undo
3497 3497
     # Given a GID, parse out the sitting number and optional part from it
3498 3498
     public function _get_sitting($gid) {
3499 3499
         if (preg_match('#_(\d\d)-(\d)_#', $gid, $m))
3500
-            return array($m[1]+0, $m[2]);
3500
+            return array($m[1] + 0, $m[2]);
3501 3501
         return array(0, 0);
3502 3502
     }
3503 3503
 }
Please login to merge, or discard this patch.
Braces   +68 added lines, -36 removed lines patch added patch discarded remove patch
@@ -138,8 +138,9 @@  discard block
 block discarded – undo
138 138
 
139 139
         global $PAGE;
140 140
 
141
-        if ($view == 'search' && (!defined('FRONT_END_SEARCH') || !FRONT_END_SEARCH))
142
-            return false;
141
+        if ($view == 'search' && (!defined('FRONT_END_SEARCH') || !FRONT_END_SEARCH)) {
142
+                    return false;
143
+        }
143 144
 
144 145
         $validviews = array ('calendar', 'date', 'gid', 'person', 'search', 'search_min', 'search_video', 'recent', 'recent_mostvotes', 'biggest_debates', 'recent_wrans', 'recent_wms', 'column', 'mp', 'bill', 'session', 'recent_debates', 'recent_pbc_debates', 'featured_gid');
145 146
         if (in_array($view, $validviews)) {
@@ -326,10 +327,11 @@  discard block
 block discarded – undo
326 327
             );
327 328
 
328 329
             $subsectiondata = $this->_get_hansard_data($input);
329
-            if (count($subsectiondata) == 0)
330
-                $subsectiondata = null;
331
-            else
332
-                $subsectiondata = $subsectiondata[0];
330
+            if (count($subsectiondata) == 0) {
331
+                            $subsectiondata = null;
332
+            } else {
333
+                            $subsectiondata = $subsectiondata[0];
334
+            }
333 335
 
334 336
         } elseif ($itemdata['htype'] == '11') {
335 337
             // It's a subsection, so use the item itself.
@@ -1018,12 +1020,12 @@  discard block
 block discarded – undo
1018 1020
         // Mainly for glossary term adding
1019 1021
         if (isset($args['num']) && $args['num']) {
1020 1022
             $results_per_page = $args['num']+0;
1021
-        }
1022
-        else {
1023
+        } else {
1023 1024
             $results_per_page = 20;
1024 1025
         }
1025
-        if ($results_per_page > 1000)
1026
-            $results_per_page = 1000;
1026
+        if ($results_per_page > 1000) {
1027
+                    $results_per_page = 1000;
1028
+        }
1027 1029
 
1028 1030
         $data['info']['results_per_page'] = $results_per_page;
1029 1031
 
@@ -1051,10 +1053,16 @@  discard block
 block discarded – undo
1051 1053
         // Get the gids from Xapian
1052 1054
         $sort_order = 'date';
1053 1055
         if (isset($args['o'])) {
1054
-            if ($args['o']=='d') $sort_order = 'newest';
1055
-            if ($args['o']=='o') $sort_order = 'oldest';
1056
-            elseif ($args['o']=='c') $sort_order = 'created';
1057
-            elseif ($args['o']=='r') $sort_order = 'relevance';
1056
+            if ($args['o']=='d') {
1057
+                $sort_order = 'newest';
1058
+            }
1059
+            if ($args['o']=='o') {
1060
+                $sort_order = 'oldest';
1061
+            } elseif ($args['o']=='c') {
1062
+                $sort_order = 'created';
1063
+            } elseif ($args['o']=='r') {
1064
+                $sort_order = 'relevance';
1065
+            }
1058 1066
         }
1059 1067
 
1060 1068
         $data['searchdescription'] = $SEARCHENGINE->query_description_long();
@@ -1114,7 +1122,9 @@  discard block
 block discarded – undo
1114 1122
                     FROM future
1115 1123
                     LEFT JOIN future_people ON id=calendar_id AND witness=0
1116 1124
                     WHERE id = $id AND deleted=0");
1117
-                if ($q->rows() == 0) continue;
1125
+                if ($q->rows() == 0) {
1126
+                    continue;
1127
+                }
1118 1128
 
1119 1129
                 $itemdata = $q->row(0);
1120 1130
 
@@ -1123,8 +1133,9 @@  discard block
 block discarded – undo
1123 1133
                     in_array($itemdata['chamber'], array(
1124 1134
                         'Commons: Main Chamber', 'Lords: Main Chamber',
1125 1135
                         'Commons: Westminster Hall',
1126
-                    )))
1127
-                        continue;
1136
+                    ))) {
1137
+                                        continue;
1138
+                }
1128 1139
 
1129 1140
                 list($cal_item, $cal_meta) = \MySociety\TheyWorkForYou\Utility\Calendar::meta($itemdata);
1130 1141
                 $body = $this->prepare_search_result_for_display($cal_item) . '.';
@@ -1237,10 +1248,17 @@  discard block
 block discarded – undo
1237 1248
                     $section = $this->_get_section($itemdata);
1238 1249
                     $subsection = $this->_get_subsection($itemdata);
1239 1250
                     $body = $hansardmajors[$itemdata['major']]['title'] . ' &#8212; ';
1240
-                    if (isset($section['body'])) $body .= $section['body'];
1241
-                    if (isset($subsection['body'])) $body .= ': ' . $subsection['body'];
1242
-                    if (isset($subsection['listurl'])) $listurl = $subsection['listurl'];
1243
-                    else $listurl = '';
1251
+                    if (isset($section['body'])) {
1252
+                        $body .= $section['body'];
1253
+                    }
1254
+                    if (isset($subsection['body'])) {
1255
+                        $body .= ': ' . $subsection['body'];
1256
+                    }
1257
+                    if (isset($subsection['listurl'])) {
1258
+                        $listurl = $subsection['listurl'];
1259
+                    } else {
1260
+                        $listurl = '';
1261
+                    }
1244 1262
                     $itemdata['parent'] = array (
1245 1263
                         'body' => $body,
1246 1264
                         'listurl' => $listurl
@@ -1980,10 +1998,11 @@  discard block
 block discarded – undo
1980 1998
         // );
1981 1999
 
1982 2000
         // $url_args is an array of other key/value pairs to be appended in the GET string.
1983
-        if ($id_data['major'])
1984
-            $LISTURL = new URL($hansardmajors[$id_data['major']]['page_all']);
1985
-        else
1986
-            $LISTURL = new URL('wrans');
2001
+        if ($id_data['major']) {
2002
+                    $LISTURL = new URL($hansardmajors[$id_data['major']]['page_all']);
2003
+        } else {
2004
+                    $LISTURL = new URL('wrans');
2005
+        }
1987 2006
 
1988 2007
         $fragment = '';
1989 2008
 
@@ -2633,7 +2652,9 @@  discard block
 block discarded – undo
2633 2652
             array(':gid_from_spid' => 'uk.org.publicwhip/spq/' . $fixed_spid)
2634 2653
         );
2635 2654
         $gid = $q->field(0, 'mentioned_gid');
2636
-        if ($gid) return $gid;
2655
+        if ($gid) {
2656
+            return $gid;
2657
+        }
2637 2658
         return null;
2638 2659
     }
2639 2660
     public function old_get_gid_from_spid($spid) {
@@ -2642,7 +2663,9 @@  discard block
 block discarded – undo
2642 2663
             array(':gid_like' => 'uk.org.publicwhip/spwa/%.' . $spid . '.h')
2643 2664
         );
2644 2665
         $gid = $q->field(0, 'gid');
2645
-        if ($gid) return str_replace('uk.org.publicwhip/spwa/', '', $gid);
2666
+        if ($gid) {
2667
+            return str_replace('uk.org.publicwhip/spwa/', '', $gid);
2668
+        }
2646 2669
         return null;
2647 2670
     }
2648 2671
 }
@@ -2928,7 +2951,9 @@  discard block
 block discarded – undo
2928 2951
 
2929 2952
         // Get the most recent day on which we have a debate.
2930 2953
         $recentday = $this->most_recent_day();
2931
-        if (!count($recentday)) return $data;
2954
+        if (!count($recentday)) {
2955
+            return $data;
2956
+        }
2932 2957
 
2933 2958
         if (!isset($args['days']) || !is_numeric($args['days'])) {
2934 2959
             $args['days'] = 1;
@@ -3055,8 +3080,9 @@  discard block
 block discarded – undo
3055 3080
 
3056 3081
         // Get the most recent day on which we have a debate.
3057 3082
         $recentday = $this->most_recent_day();
3058
-        if (!count($recentday))
3059
-            return array();
3083
+        if (!count($recentday)) {
3084
+                    return array();
3085
+        }
3060 3086
 
3061 3087
         if (!isset($args['days']) || !is_numeric($args['days'])) {
3062 3088
             $args['days'] = 1;
@@ -3189,8 +3215,9 @@  discard block
 block discarded – undo
3189 3215
 
3190 3216
         // Get the most recent day on which we have wrans.
3191 3217
         $recentday = $this->most_recent_day();
3192
-        if (!count($recentday))
3193
-            return $data;
3218
+        if (!count($recentday)) {
3219
+                    return $data;
3220
+        }
3194 3221
 
3195 3222
         if (!isset($args['days']) || !is_numeric($args['days'])) {
3196 3223
             $args['days'] = 1;
@@ -3470,7 +3497,9 @@  discard block
 block discarded – undo
3470 3497
     }
3471 3498
 
3472 3499
     public function _get_data_by_recent_pbc_debates($args) {
3473
-        if (!isset($args['num'])) $args['num'] = 20;
3500
+        if (!isset($args['num'])) {
3501
+            $args['num'] = 20;
3502
+        }
3474 3503
         $q = $this->db->query('select gid, minor, hdate from hansard
3475 3504
             where htype=10 and major=6
3476 3505
             order by hdate desc limit ' . $args['num']);
@@ -3484,7 +3513,9 @@  discard block
 block discarded – undo
3484 3513
             $session = $qq->field(0, 'session');
3485 3514
             list($sitting, $part) = $this->_get_sitting($gid);
3486 3515
             $sitting_txt = make_ranking($sitting) . ' sitting';
3487
-            if ($part>0) $sitting .= ", part $part";
3516
+            if ($part>0) {
3517
+                $sitting .= ", part $part";
3518
+            }
3488 3519
             $data[$hdate][] = array(
3489 3520
                 'bill'=> $title,
3490 3521
                 'sitting' => $sitting_txt,
@@ -3496,8 +3527,9 @@  discard block
 block discarded – undo
3496 3527
 
3497 3528
     # Given a GID, parse out the sitting number and optional part from it
3498 3529
     public function _get_sitting($gid) {
3499
-        if (preg_match('#_(\d\d)-(\d)_#', $gid, $m))
3500
-            return array($m[1]+0, $m[2]);
3530
+        if (preg_match('#_(\d\d)-(\d)_#', $gid, $m)) {
3531
+                    return array($m[1]+0, $m[2]);
3532
+        }
3501 3533
         return array(0, 0);
3502 3534
     }
3503 3535
 }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
                     // Linking to the prev (sub)section.
431 431
                     $thing = $hansardmajors[$this->major]['singular'];
432 432
                     $nextprevdata['prev'] = array (
433
-                        'body'		=> "Previous $thing",
433
+                        'body'		=> "previous $thing",
434 434
                         'url'		=> $prevdata[0]['listurl'],
435 435
                         'title'		=> $prevdata[0]['body']
436 436
                     );
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
                     // Linking to the next (sub)section.
475 475
                     $thing = $hansardmajors[$this->major]['singular'];
476 476
                     $nextprevdata['next'] = array (
477
-                        'body'		=> "Next $thing",
477
+                        'body'		=> "next $thing",
478 478
                         'url'		=> $nextdata[0]['listurl'],
479 479
                         'title'		=> $nextdata[0]['body']
480 480
                     );
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
             $URL->remove(array('id'));
511 511
             $things = $hansardmajors[$itemdata['major']]['title'];
512 512
             $nextprevdata['up'] = array(
513
-                'body'	=> "All $things on " . format_date($itemdata['hdate'], SHORTDATEFORMAT),
513
+                'body'	=> "all $things on " . format_date($itemdata['hdate'], SHORTDATEFORMAT),
514 514
                 'title'	=> '',
515 515
                 'url' 	=> $URL->generate()
516 516
             );
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 
560 560
             // The '!= NULL' bit is needed otherwise I was getting errors
561 561
             // when displaying the first day of debates.
562
-            if ($q->rows() > 0 && $q->field(0, 'hdate') != NULL) {
562
+            if ($q->rows() > 0 && $q->field(0, 'hdate') != null) {
563 563
 
564 564
                 $URL->insert( array( 'd'=>$q->field(0, 'hdate') ) );
565 565
 
@@ -1403,7 +1403,7 @@  discard block
 block discarded – undo
1403 1403
                             WHERE	major = :major",
1404 1404
                 array(':major' => $this->major));
1405 1405
 
1406
-            if ($q->field(0, 'hdate') != NULL) {
1406
+            if ($q->field(0, 'hdate') != null) {
1407 1407
                 $recentdate = $q->field(0, 'hdate');
1408 1408
             } else {
1409 1409
                 $PAGE->error_message("Couldn't find the most recent date");
@@ -1724,7 +1724,7 @@  discard block
 block discarded – undo
1724 1724
         }
1725 1725
 
1726 1726
         // Finally, do the query!
1727
-        $q = $this->db->query ("SELECT $fields
1727
+        $q = $this->db->query ("select $fields
1728 1728
                         FROM 	hansard
1729 1729
                         $join
1730 1730
                         WHERE $where
Please login to merge, or discard this patch.
www/includes/easyparliament/searchengine.php 5 patches
Doc Comments   +13 added lines patch added patch discarded remove patch
@@ -307,6 +307,9 @@  discard block
 block discarded – undo
307 307
         $this->valid = true;
308 308
     }
309 309
 
310
+    /**
311
+     * @param boolean $long
312
+     */
310 313
     public function query_description_internal($long) {
311 314
         if (!defined('XAPIANDB') || !XAPIANDB) {
312 315
             return '';
@@ -341,6 +344,11 @@  discard block
 block discarded – undo
341 344
     }
342 345
 
343 346
     // Perform partial query to get a count of number of matches
347
+
348
+    /**
349
+     * @param integer $first_result
350
+     * @param integer $results_per_page
351
+     */
344 352
     public function run_count($first_result, $results_per_page, $sort_order='relevance') {
345 353
         if (!defined('XAPIANDB') || !XAPIANDB)
346 354
             return null;
@@ -420,6 +428,11 @@  discard block
 block discarded – undo
420 428
     }
421 429
 
422 430
     // Perform the full search...
431
+
432
+    /**
433
+     * @param integer $first_result
434
+     * @param integer $results_per_page
435
+     */
423 436
     public function run_search($first_result, $results_per_page, $sort_order='relevance') {
424 437
         $start = getmicrotime();
425 438
 
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
     }
334 334
 
335 335
     public function get_spelling_correction() {
336
-         if (!defined('XAPIANDB') || !XAPIANDB)
336
+            if (!defined('XAPIANDB') || !XAPIANDB)
337 337
             return null;
338 338
 
339 339
         $qd = $this->queryparser->get_corrected_query_string();
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
             {
560 560
                 $wordpos = strpos( $lcbody, $matches[0] );
561 561
                 if ($wordpos) {
562
-                   if ( ($wordpos < $pos) || ($pos==-1) ) {
562
+                    if ( ($wordpos < $pos) || ($pos==-1) ) {
563 563
                         $pos = $wordpos;
564 564
                     }
565 565
                 }
Please login to merge, or discard this patch.
Braces   +99 added lines, -46 removed lines patch added patch discarded remove patch
@@ -40,8 +40,9 @@  discard block
 block discarded – undo
40 40
     public $error;
41 41
 
42 42
     public function __construct($query) {
43
-        if (!defined('XAPIANDB') || !XAPIANDB)
44
-            return null;
43
+        if (!defined('XAPIANDB') || !XAPIANDB) {
44
+                    return null;
45
+        }
45 46
 
46 47
         global $xapiandb, $PAGE, $hansardmajors, $parties;
47 48
         if (!$xapiandb) {
@@ -56,8 +57,12 @@  discard block
 block discarded – undo
56 57
             }
57 58
         }
58 59
         $this->query = $query;
59
-        if (!isset($this->stemmer)) $this->stemmer = new XapianStem('english');
60
-        if (!isset($this->enquire)) $this->enquire = new XapianEnquire($xapiandb);
60
+        if (!isset($this->stemmer)) {
61
+            $this->stemmer = new XapianStem('english');
62
+        }
63
+        if (!isset($this->enquire)) {
64
+            $this->enquire = new XapianEnquire($xapiandb);
65
+        }
61 66
         if (!isset($this->queryparser)) {
62 67
             $this->queryparser = new XapianQueryParser();
63 68
             $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,22 +131,37 @@  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 == 'uk') $newv = array(1,2,3,4,6,101);
141
-                    elseif ($value == 'scotland') $newv = array(7,8);
142
-                    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 == 'uk') {
159
+                        $newv = array(1,2,3,4,6,101);
160
+                    } elseif ($value == 'scotland') {
161
+                        $newv = array(7,8);
162
+                    } elseif ($value == 'future') {
163
+                        $newv = 'F';
164
+                    }
143 165
                     if (is_array($newv)) {
144 166
                         $newv = 'major:' . join(' major:', $newv);
145 167
                     } else {
@@ -148,8 +170,12 @@  discard block
 block discarded – undo
148 170
                     $this->query = str_ireplace("$type:$value", $newv, $this->query);
149 171
                 } elseif ($type == 'groupby') {
150 172
                     $newv = $value;
151
-                    if ($value == 'debates' || $value == 'debate') $newv = 'debate';
152
-                    if ($value == 'speech' || $value == 'speeches') $newv = 'speech';
173
+                    if ($value == 'debates' || $value == 'debate') {
174
+                        $newv = 'debate';
175
+                    }
176
+                    if ($value == 'speech' || $value == 'speeches') {
177
+                        $newv = 'speech';
178
+                    }
153 179
                     $this->query = str_ireplace("$type:$value", '', $this->query);
154 180
                     array_push($this->prefixed, array($type, $newv));
155 181
                 } elseif ($type == 'from') {
@@ -254,7 +280,9 @@  discard block
 block discarded – undo
254 280
             $end = $this->queryparser->unstem_end($mm);
255 281
             while (!$iter->equals($end)) {
256 282
                 $tt = $iter->get_term();
257
-                if (!in_array($tt, $used)) break;
283
+                if (!in_array($tt, $used)) {
284
+                    break;
285
+                }
258 286
                 $iter->next();
259 287
             }
260 288
             $used[] = $tt;
@@ -333,8 +361,9 @@  discard block
 block discarded – undo
333 361
     }
334 362
 
335 363
     public function get_spelling_correction() {
336
-         if (!defined('XAPIANDB') || !XAPIANDB)
337
-            return null;
364
+         if (!defined('XAPIANDB') || !XAPIANDB) {
365
+                     return null;
366
+         }
338 367
 
339 368
         $qd = $this->queryparser->get_corrected_query_string();
340 369
         return $qd;
@@ -342,8 +371,9 @@  discard block
 block discarded – undo
342 371
 
343 372
     // Perform partial query to get a count of number of matches
344 373
     public function run_count($first_result, $results_per_page, $sort_order='relevance') {
345
-        if (!defined('XAPIANDB') || !XAPIANDB)
346
-            return null;
374
+        if (!defined('XAPIANDB') || !XAPIANDB) {
375
+                    return null;
376
+        }
347 377
 
348 378
         $start = getmicrotime();
349 379
 
@@ -373,16 +403,18 @@  discard block
 block discarded – undo
373 403
                 $collapsed = true;
374 404
                 if ($items[1] == 'speech')
375 405
                     ; // no collapse key
376
-                elseif ($items[1] == 'debate')
377
-                    $this->enquire->set_collapse_key(3);
378
-                else
379
-                    $PAGE->error_message("Unknown group by '$items[1]' ignored");
406
+                elseif ($items[1] == 'debate') {
407
+                                    $this->enquire->set_collapse_key(3);
408
+                } else {
409
+                                    $PAGE->error_message("Unknown group by '$items[1]' ignored");
410
+                }
380 411
             }
381 412
         }
382 413
 
383 414
         // default to grouping by subdebate, i.e. by page
384
-        if (!$collapsed)
385
-            $this->enquire->set_collapse_key(3);
415
+        if (!$collapsed) {
416
+                    $this->enquire->set_collapse_key(3);
417
+        }
386 418
 
387 419
         /*
388 420
         XXX Helping to debug possible Xapian bug
@@ -462,8 +494,9 @@  discard block
 block discarded – undo
462 494
 
463 495
     // Puts HTML highlighting round all the matching words in the text
464 496
     public function highlight($body) {
465
-        if (!defined('XAPIANDB') || !XAPIANDB)
466
-            return $body;
497
+        if (!defined('XAPIANDB') || !XAPIANDB) {
498
+                    return $body;
499
+        }
467 500
 
468 501
         $stemmed_words = array_map(array($this, 'stem'), $this->words);
469 502
         if (is_array($body)) {
@@ -481,8 +514,9 @@  discard block
 block discarded – undo
481 514
     private $specialchars_upper = array('&LT;', '&GT;', '&QUOT;', '&AMP;');
482 515
 
483 516
     public function highlight_internal($body, $stemmed_words) {
484
-        if (!defined('XAPIANDB') || !XAPIANDB)
485
-            return $body;
517
+        if (!defined('XAPIANDB') || !XAPIANDB) {
518
+                    return $body;
519
+        }
486 520
 
487 521
         # Does html_entity_decode without the htmlspecialchars
488 522
         $body = str_replace($this->specialchars, $this->specialchars_upper, $body);
@@ -503,7 +537,9 @@  discard block
 block discarded – undo
503 537
             $hl = false;
504 538
             $matchword = $this->stem($extractword);
505 539
             foreach ($stemmed_words as $word) {
506
-                if ($word == '') continue;
540
+                if ($word == '') {
541
+                    continue;
542
+                }
507 543
                 if ($matchword == $word) {
508 544
                     $hl = true;
509 545
                     break;
@@ -565,17 +601,25 @@  discard block
 block discarded – undo
565 601
                 }
566 602
             }
567 603
         }
568
-        if ($pos != -1) return $pos;
604
+        if ($pos != -1) {
605
+            return $pos;
606
+        }
569 607
 
570 608
         $splitextract = preg_split('/([0-9,.]+|['.$this->wordcharsnodigit.']+)/', $lcbody, -1, PREG_SPLIT_DELIM_CAPTURE);
571 609
         $stemmed_words = array_map(array($this, 'stem'), $this->words);
572 610
         foreach ($splitextract as $extractword) {
573 611
             $extractword = preg_replace('/&$/', '', $extractword);
574
-            if (!$extractword) continue;
612
+            if (!$extractword) {
613
+                continue;
614
+            }
575 615
             $wordpos = strpos($lcbody, $extractword);
576
-            if (!$wordpos) continue;
616
+            if (!$wordpos) {
617
+                continue;
618
+            }
577 619
             foreach ($stemmed_words as $word) {
578
-                if ($word == '') continue;
620
+                if ($word == '') {
621
+                    continue;
622
+                }
579 623
                 $matchword = $this->stem($extractword);
580 624
                 if ($matchword == $word && ($wordpos < $pos || $pos==-1)) {
581 625
                     $pos = $wordpos;
@@ -583,10 +627,14 @@  discard block
 block discarded – undo
583 627
             }
584 628
         }
585 629
         // only look for earlier words if phrases weren't found
586
-        if ($pos != -1) return $pos;
630
+        if ($pos != -1) {
631
+            return $pos;
632
+        }
587 633
 
588 634
         foreach ($this->words as $word) {
589
-            if (ctype_digit($word)) $word = '(?:'.$word.'|'.number_format($word).')';
635
+            if (ctype_digit($word)) {
636
+                $word = '(?:'.$word.'|'.number_format($word).')';
637
+            }
590 638
             if (preg_match('/([^'.$this->wordchars.']' . $word . '[^'.$this->wordchars. '])/', $lcbody, $matches)) {
591 639
                 $wordpos = strpos( $lcbody, $matches[0] );
592 640
                 if ($wordpos) {
@@ -597,10 +645,14 @@  discard block
 block discarded – undo
597 645
             }
598 646
         }
599 647
         // only look for something containing the word (ie. something stemmed, but doesn't work all the time) if no whole word was found
600
-        if ($pos != -1) return $pos;
648
+        if ($pos != -1) {
649
+            return $pos;
650
+        }
601 651
 
602 652
         foreach ($this->words as $word) {
603
-            if (ctype_digit($word)) $word = '(?:'.$word.'|'.number_format($word).')';
653
+            if (ctype_digit($word)) {
654
+                $word = '(?:'.$word.'|'.number_format($word).')';
655
+            }
604 656
             if (preg_match('/(' . $word . ')/', $lcbody, $matches)) {
605 657
                 $wordpos = strpos( $lcbody, $matches[0] );
606 658
                 if ($wordpos) {
@@ -611,8 +663,9 @@  discard block
 block discarded – undo
611 663
             }
612 664
         }
613 665
 
614
-        if ($pos == -1)
615
-            $pos = 0;
666
+        if ($pos == -1) {
667
+                    $pos = 0;
668
+        }
616 669
 
617 670
         return $pos;
618 671
     }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
             if (strstr(XAPIANDB, ":")) {
47 47
                 //ini_set('display_errors', 'On');
48 48
                 list ($xapian_host, $xapian_port) = explode(":", XAPIANDB);
49
-                twfy_debug("SEARCH", "Using Xapian remote backend: " . $xapian_host . " port " . $xapian_port);
49
+                twfy_debug("SEARCH", "Using Xapian remote backend: ".$xapian_host." port ".$xapian_port);
50 50
                 $xapiandb_remote = remote_open($xapian_host, intval($xapian_port));
51 51
                 $xapiandb = new XapianDatabase($xapiandb_remote);
52 52
             } else {
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
         $this->prefixed = array();
93 93
 
94 94
         // Split words up into individual words, and quoted phrases
95
-        preg_match_all('/(' .
96
-            '"|' . # match either a quote, or...
97
-            '(?:(?<![' .$this->wordchars. '])-)?' . # optionally a - (exclude)
95
+        preg_match_all('/('.
96
+            '"|'.# match either a quote, or...
97
+            '(?:(?<!['.$this->wordchars.'])-)?'.# optionally a - (exclude)
98 98
             # if at start of word (i.e. not preceded by a word character, in
99 99
             # which case it is probably a hyphenated-word)
100
-            '['.$this->wordchars.']+' . # followed by a string of word-characters
100
+            '['.$this->wordchars.']+'.# followed by a string of word-characters
101 101
             ')/', $this->query, $all_words);
102 102
         if ($all_words) {
103 103
             $all_words = $all_words[0];
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
             if (strpos($word, ':') !== false) {
123 123
                 $items = explode(":", strtolower($word));
124 124
                 $type = $items[0];
125
-                if (substr($type, 0, 1)=='-') $type = substr($type, 1);
126
-                $value = strtolower(join(":", array_slice($items,1)));
125
+                if (substr($type, 0, 1) == '-') $type = substr($type, 1);
126
+                $value = strtolower(join(":", array_slice($items, 1)));
127 127
                 if ($type == 'section') {
128 128
                     $newv = $value;
129 129
                     if ($value == 'debates' || $value == 'debate') $newv = 1;
@@ -135,11 +135,11 @@  discard block
 block discarded – undo
135 135
                     elseif ($value == 'pbc' || $value == 'standing') $newv = 6;
136 136
                     elseif ($value == 'sp') $newv = 7;
137 137
                     elseif ($value == 'spwrans' || $value == 'spwran') $newv = 8;
138
-                    elseif ($value == 'uk') $newv = array(1,2,3,4,6,101);
139
-                    elseif ($value == 'scotland') $newv = array(7,8);
138
+                    elseif ($value == 'uk') $newv = array(1, 2, 3, 4, 6, 101);
139
+                    elseif ($value == 'scotland') $newv = array(7, 8);
140 140
                     elseif ($value == 'future') $newv = 'F';
141 141
                     if (is_array($newv)) {
142
-                        $newv = 'major:' . join(' major:', $newv);
142
+                        $newv = 'major:'.join(' major:', $newv);
143 143
                     } else {
144 144
                         $newv = "major:$newv";
145 145
                     }
@@ -179,15 +179,15 @@  discard block
 block discarded – undo
179 179
         # Merged people
180 180
         $db = new ParlDB;
181 181
         $merged = $db->query('SELECT * FROM gidredirect WHERE gid_from LIKE :gid_from', array(':gid_from' => "uk.org.publicwhip/person/%"));
182
-        for ($n=0; $n<$merged->rows(); $n++) {
182
+        for ($n = 0; $n < $merged->rows(); $n++) {
183 183
             $from_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_from'));
184 184
             $to_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_to'));
185 185
             $this->query = preg_replace("#speaker:($from_id|$to_id)#i", "(speaker:$from_id OR speaker:$to_id)", $this->query);
186 186
         }
187 187
 
188
-        twfy_debug("SEARCH", "prefixed: " . var_export($this->prefixed, true));
188
+        twfy_debug("SEARCH", "prefixed: ".var_export($this->prefixed, true));
189 189
 
190
-        twfy_debug("SEARCH", "query -- ". $this->query);
190
+        twfy_debug("SEARCH", "query -- ".$this->query);
191 191
         $flags = XapianQueryParser::FLAG_BOOLEAN | XapianQueryParser::FLAG_LOVEHATE |
192 192
             XapianQueryParser::FLAG_WILDCARD | XapianQueryParser::FLAG_SPELLING_CORRECTION;
193 193
         $flags = $flags | XapianQueryParser::FLAG_PHRASE;
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         # Now parse the parsed query back into a query string, yummy
206 206
 
207 207
         $qd = $query->get_description();
208
-        twfy_debug("SEARCH", "queryparser original description -- " . $qd);
208
+        twfy_debug("SEARCH", "queryparser original description -- ".$qd);
209 209
         $qd = substr($qd, 14, -1); # Strip Xapian::Query()
210 210
         $qd = preg_replace('#:\(.*?\)#', '', $qd); # Don't need pos or weight
211 211
         # Date range
@@ -256,11 +256,11 @@  discard block
 block discarded – undo
256 256
                 $iter->next();
257 257
             }
258 258
             $used[] = $tt;
259
-            $qd = preg_replace('#' . preg_quote($mm, '#') . '#', $tt, $qd, 1);
259
+            $qd = preg_replace('#'.preg_quote($mm, '#').'#', $tt, $qd, 1);
260 260
         }
261 261
 
262 262
         # Speakers
263
-        for ($n=0; $n<$merged->rows(); $n++) {
263
+        for ($n = 0; $n < $merged->rows(); $n++) {
264 264
             $from_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_from'));
265 265
             $to_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_to'));
266 266
             $qd = str_replace("(S$from_id OR S$to_id)", "S$to_id", $qd);
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
         $qd = preg_replace('#AND_NOT ([a-z0-9"]+)#', '-$1', $qd);
279 279
         preg_match_all('#AND_NOT \((.*?)\)#', $qd, $m);
280 280
         foreach ($m[1] as $mm) {
281
-            $mmn = '-' . join(' -', explode(' OR ', $mm));
281
+            $mmn = '-'.join(' -', explode(' OR ', $mm));
282 282
             $qd = str_replace("AND_NOT ($mm)", $mmn, $qd);
283 283
         }
284 284
 
@@ -297,9 +297,9 @@  discard block
 block discarded – undo
297 297
         $this->query_desc = trim($qd);
298 298
 
299 299
         #print 'DEBUG: ' . $query->get_description();
300
-        twfy_debug("SEARCH", "words: " . var_export($this->words, true));
301
-        twfy_debug("SEARCH", "phrases: " . var_export($this->phrases, true));
302
-        twfy_debug("SEARCH", "queryparser description -- " . $this->query_desc);
300
+        twfy_debug("SEARCH", "words: ".var_export($this->words, true));
301
+        twfy_debug("SEARCH", "phrases: ".var_export($this->phrases, true));
302
+        twfy_debug("SEARCH", "queryparser description -- ".$this->query_desc);
303 303
 
304 304
         $this->valid = true;
305 305
     }
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
     }
340 340
 
341 341
     // Perform partial query to get a count of number of matches
342
-    public function run_count($first_result, $results_per_page, $sort_order='relevance') {
342
+    public function run_count($first_result, $results_per_page, $sort_order = 'relevance') {
343 343
         if (!defined('XAPIANDB') || !XAPIANDB)
344 344
             return null;
345 345
 
@@ -412,13 +412,13 @@  discard block
 block discarded – undo
412 412
         #}
413 413
 
414 414
         $duration = getmicrotime() - $start;
415
-        twfy_debug ("SEARCH", "Search count took $duration seconds.");
415
+        twfy_debug("SEARCH", "Search count took $duration seconds.");
416 416
 
417 417
         return $count;
418 418
     }
419 419
 
420 420
     // Perform the full search...
421
-    public function run_search($first_result, $results_per_page, $sort_order='relevance') {
421
+    public function run_search($first_result, $results_per_page, $sort_order = 'relevance') {
422 422
         $start = getmicrotime();
423 423
 
424 424
         #$matches = $this->enquire->get_mset($first_result, $results_per_page);
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
             $iter->next();
446 446
         }
447 447
         $duration = getmicrotime() - $start;
448
-        twfy_debug ("SEARCH", "Run search took $duration seconds.");
448
+        twfy_debug("SEARCH", "Run search took $duration seconds.");
449 449
     }
450 450
     // ... use these to get the results
451 451
     public function get_gids() {
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
             if ($hl) {
511 511
                 $hlextract .= "<span class=\"hi\">$extractword</span>$endswithamp";
512 512
             } else {
513
-                $hlextract .= $extractword . $endswithamp;
513
+                $hlextract .= $extractword.$endswithamp;
514 514
             }
515 515
         }
516 516
         $body = preg_replace("#</span>\s+<span class=\"hi\">#", " ", $hlextract);
@@ -547,17 +547,17 @@  discard block
 block discarded – undo
547 547
 
548 548
     // Find the position of the first of the search words/phrases in $body.
549 549
     public function position_of_first_word($body) {
550
-        $lcbody = ' ' . html_entity_decode(strtolower($body)) . ' '; // spaces to make regexp mapping easier
550
+        $lcbody = ' '.html_entity_decode(strtolower($body)).' '; // spaces to make regexp mapping easier
551 551
         $pos = -1;
552 552
 
553 553
         // look for phrases
554 554
         foreach ($this->phrases as $phrase) {
555 555
             $phrasematch = join($phrase, '[^'.$this->wordchars.']+');
556
-            if (preg_match('/([^'.$this->wordchars.']' . $phrasematch . '[^A-Za-z0-9])/', $lcbody, $matches))
556
+            if (preg_match('/([^'.$this->wordchars.']'.$phrasematch.'[^A-Za-z0-9])/', $lcbody, $matches))
557 557
             {
558
-                $wordpos = strpos( $lcbody, $matches[0] );
558
+                $wordpos = strpos($lcbody, $matches[0]);
559 559
                 if ($wordpos) {
560
-                   if ( ($wordpos < $pos) || ($pos==-1) ) {
560
+                   if (($wordpos < $pos) || ($pos == -1)) {
561 561
                         $pos = $wordpos;
562 562
                     }
563 563
                 }
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
             foreach ($stemmed_words as $word) {
576 576
                 if ($word == '') continue;
577 577
                 $matchword = $this->stem($extractword);
578
-                if ($matchword == $word && ($wordpos < $pos || $pos==-1)) {
578
+                if ($matchword == $word && ($wordpos < $pos || $pos == -1)) {
579 579
                     $pos = $wordpos;
580 580
                 }
581 581
             }
@@ -585,10 +585,10 @@  discard block
 block discarded – undo
585 585
 
586 586
         foreach ($this->words as $word) {
587 587
             if (ctype_digit($word)) $word = '(?:'.$word.'|'.number_format($word).')';
588
-            if (preg_match('/([^'.$this->wordchars.']' . $word . '[^'.$this->wordchars. '])/', $lcbody, $matches)) {
589
-                $wordpos = strpos( $lcbody, $matches[0] );
588
+            if (preg_match('/([^'.$this->wordchars.']'.$word.'[^'.$this->wordchars.'])/', $lcbody, $matches)) {
589
+                $wordpos = strpos($lcbody, $matches[0]);
590 590
                 if ($wordpos) {
591
-                    if ( ($wordpos < $pos) || ($pos==-1) ) {
591
+                    if (($wordpos < $pos) || ($pos == -1)) {
592 592
                         $pos = $wordpos;
593 593
                     }
594 594
                 }
@@ -599,10 +599,10 @@  discard block
 block discarded – undo
599 599
 
600 600
         foreach ($this->words as $word) {
601 601
             if (ctype_digit($word)) $word = '(?:'.$word.'|'.number_format($word).')';
602
-            if (preg_match('/(' . $word . ')/', $lcbody, $matches)) {
603
-                $wordpos = strpos( $lcbody, $matches[0] );
602
+            if (preg_match('/('.$word.')/', $lcbody, $matches)) {
603
+                $wordpos = strpos($lcbody, $matches[0]);
604 604
                 if ($wordpos) {
605
-                    if ( ($wordpos < $pos) || ($pos==-1) ) {
605
+                    if (($wordpos < $pos) || ($pos == -1)) {
606 606
                         $pos = $wordpos;
607 607
                     }
608 608
                 }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
 */
27 27
 
28
-if (defined('XAPIANDB') AND XAPIANDB != '') {
28
+if (defined('XAPIANDB') and XAPIANDB != '') {
29 29
     if (file_exists('/usr/share/php/xapian.php')) {
30 30
         include_once '/usr/share/php/xapian.php';
31 31
     } else {
@@ -263,15 +263,15 @@  discard block
 block discarded – undo
263 263
         for ($n=0; $n<$merged->rows(); $n++) {
264 264
             $from_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_from'));
265 265
             $to_id = str_replace('uk.org.publicwhip/person/', '', $merged->field($n, 'gid_to'));
266
-            $qd = str_replace("(S$from_id OR S$to_id)", "S$to_id", $qd);
267
-            $qd = str_replace("S$from_id OR S$to_id", "S$to_id", $qd);
266
+            $qd = str_replace("(S$from_id OR S$to_id)", "s$to_id", $qd);
267
+            $qd = str_replace("s$from_id OR S$to_id", "s$to_id", $qd);
268 268
         }
269 269
 
270 270
         preg_match_all('#S(\d+)#', $qd, $m);
271 271
         foreach ($m[1] as $mm) {
272 272
             $member = new MEMBER(array('person_id' => $mm));
273 273
             $name = $member->full_name();
274
-            $qd = str_replace("S$mm", "speaker:$name", $qd);
274
+            $qd = str_replace("s$mm", "speaker:$name", $qd);
275 275
         }
276 276
 
277 277
         # Simplify display of excluded words
Please login to merge, or discard this patch.
www/includes/easyparliament/searchlog.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -99,6 +99,9 @@
 block discarded – undo
99 99
         return $popular_searches;
100 100
     }
101 101
 
102
+    /**
103
+     * @param integer $row
104
+     */
102 105
     public function _db_row_to_array($q, $row) {
103 106
         $query = $q->field($row, 'query_string');
104 107
         $this->SEARCHURL->insert(array('s'=>$query, 'pop'=>1));
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -69,14 +69,14 @@  discard block
 block discarded – undo
69 69
     // Select popular queries
70 70
     public function popular_recent($count, $max_chars = null) {
71 71
 
72
-        $q =  $this->db->query("SELECT *, count(*) AS c FROM search_query_log
72
+        $q = $this->db->query("SELECT *, count(*) AS c FROM search_query_log
73 73
                 WHERE count_hits != 0 AND query_string != 'twat'
74 74
            AND query_string != 'suffragettes' AND page_number=1
75 75
                 AND query_time > date_sub(NOW(), INTERVAL 1 DAY)
76 76
                 GROUP BY query_string ORDER BY c desc LIMIT $count;");
77 77
 
78 78
         $popular_searches = array();
79
-        for ($row=0; $row<$q->rows(); $row++) {
79
+        for ($row = 0; $row < $q->rows(); $row++) {
80 80
             array_push($popular_searches, $this->_db_row_to_array($q, $row));
81 81
         }
82 82
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
         $rowarray['query'] = $query;
123 123
         $rowarray['visible_name'] = $visible_name;
124 124
         $rowarray['url'] = $url;
125
-        $rowarray['display'] = '<a href="' . $url . '">' . ($htmlescape ? _htmlentities($visible_name) : $visible_name). '</a>';
125
+        $rowarray['display'] = '<a href="'.$url.'">'.($htmlescape ? _htmlentities($visible_name) : $visible_name).'</a>';
126 126
 
127 127
         return $rowarray;
128 128
     }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         $q = $this->db->query("SELECT query_string, page_number, count_hits, ip_address, query_time
133 133
                 FROM search_query_log ORDER BY query_time desc LIMIT $count");
134 134
         $searches_array = array();
135
-        for ($row=0; $row<$q->rows(); $row++) {
135
+        for ($row = 0; $row < $q->rows(); $row++) {
136 136
             array_push($searches_array, $this->_db_row_to_array($q, $row));
137 137
         }
138 138
 
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
 
142 142
     public function admin_popular_searches($count) {
143 143
 
144
-        $q =  $this->db->query("SELECT *, count(*) AS c FROM search_query_log
144
+        $q = $this->db->query("SELECT *, count(*) AS c FROM search_query_log
145 145
                 WHERE count_hits != 0 AND query_string NOT LIKE '%speaker:%'
146 146
                 AND query_time > date_sub(NOW(), INTERVAL 30 DAY)
147 147
                 GROUP BY query_string ORDER BY c desc LIMIT $count;");
148 148
 
149 149
         $popular_searches = array();
150
-        for ($row=0; $row<$q->rows(); $row++) {
150
+        for ($row = 0; $row < $q->rows(); $row++) {
151 151
             array_push($popular_searches, $this->_db_row_to_array($q, $row));
152 152
         }
153 153
 
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
                 FROM search_query_log GROUP BY query_string HAVING count_hits = 0
164 164
                 ORDER BY count_ips DESC, max_time DESC");
165 165
         $searches_array = array();
166
-        for ($row=0; $row<$q->rows(); $row++) {
166
+        for ($row = 0; $row < $q->rows(); $row++) {
167 167
             array_push($searches_array, $this->_db_row_to_array($q, $row));
168 168
         }
169 169
 
Please login to merge, or discard this patch.
www/includes/lib_filter.php 3 patches
Doc Comments   +8 added lines patch added patch discarded remove patch
@@ -294,6 +294,9 @@  discard block
 block discarded – undo
294 294
 
295 295
         #####################################################################################
296 296
 
297
+        /**
298
+         * @param string $data
299
+         */
297 300
         function process_param_protocol($data) {
298 301
 
299 302
             $data = $this->validate_entities($data, 1);
@@ -407,6 +410,11 @@  discard block
 block discarded – undo
407 410
         # ampersand) is allowed, else corrects it.
408 411
         #
409 412
 
413
+        /**
414
+         * @param integer $in_attribute
415
+         *
416
+         * @return string
417
+         */
410 418
         function validate_entities($data, $in_attribute) {
411 419
 
412 420
             #
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
         function escape_comments($data) {
154 154
 
155 155
             $data = preg_replace_callback("/<!--(.*?)-->/s", function($matches) {
156
-                    return '<!--' . HtmlSpecialChars($this->StripSingle($matches[1])) . '-->';
156
+                    return '<!--'.HtmlSpecialChars($this->StripSingle($matches[1])).'-->';
157 157
                 }, $data);
158 158
 
159 159
             return $data;
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
                 }, $data);
208 208
 
209 209
             foreach (array_keys($this->tag_counts) as $tag) {
210
-                for ($i=0; $i<$this->tag_counts[$tag]; $i++) {
210
+                for ($i = 0; $i < $this->tag_counts[$tag]; $i++) {
211 211
                     $data .= "</$tag>";
212 212
                 }
213 213
             }
@@ -242,9 +242,9 @@  discard block
 block discarded – undo
242 242
                 $ending = $matches[3];
243 243
                 if (in_array($name, array_keys($this->allowed))) {
244 244
                     $params = "";
245
-                    preg_match_all("/([a-z0-9]+)=([\"'])(.*?)\\2/si", $body, $matches_2, PREG_SET_ORDER);		# <foo a="b" />
246
-                    preg_match_all("/([a-z0-9]+)(=)([^\"\s']+)/si", $body, $matches_1, PREG_SET_ORDER);		# <foo a=b />
247
-                    preg_match_all("/([a-z0-9]+)=([\"'])([^\"']*?)\s*$/si", $body, $matches_3, PREG_SET_ORDER);	# <foo a="b />
245
+                    preg_match_all("/([a-z0-9]+)=([\"'])(.*?)\\2/si", $body, $matches_2, PREG_SET_ORDER); # <foo a="b" />
246
+                    preg_match_all("/([a-z0-9]+)(=)([^\"\s']+)/si", $body, $matches_1, PREG_SET_ORDER); # <foo a=b />
247
+                    preg_match_all("/([a-z0-9]+)=([\"'])([^\"']*?)\s*$/si", $body, $matches_3, PREG_SET_ORDER); # <foo a="b />
248 248
                     $matches = array_merge($matches_1, $matches_2, $matches_3);
249 249
 
250 250
                     foreach ($matches as $match) {
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 
301 301
             if (preg_match("/^([^:]+)\:/si", $data, $matches)) {
302 302
                 if (!in_array($matches[1], $this->allowed_protocols)) {
303
-                    $data = '#'.substr($data, strlen($matches[1])+1);
303
+                    $data = '#'.substr($data, strlen($matches[1]) + 1);
304 304
                 }
305 305
             }
306 306
 
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
             # if there are less than 5, just allow it as-is
351 351
             #
352 352
 
353
-            if (strlen($data_notags)<5) {
353
+            if (strlen($data_notags) < 5) {
354 354
                 return $data;
355 355
             }
356 356
 
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
         # inside strings. within general text, we decode hex/dec entities.
561 561
         #
562 562
 
563
-        function decode_entities($data, $in_attribute=1) {
563
+        function decode_entities($data, $in_attribute = 1) {
564 564
 
565 565
             $data = preg_replace_callback('!(&)#(\d+);?!', array($this, 'decode_dec_entity'), $data);
566 566
             $data = preg_replace_callback('!(&)#x([0-9a-f]+);?!i', array($this, 'decode_hex_entity'), $data);
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -322,7 +322,9 @@
 block discarded – undo
322 322
                 while (1) {
323 323
                     $len = strlen($data);
324 324
                     $data = preg_replace("/<({$tags})(\s[^>]*)?(><\\/\\1>|\\/>)/", '', $data);
325
-                    if ($len == strlen($data)) break;
325
+                    if ($len == strlen($data)) {
326
+                        break;
327
+                    }
326 328
                 }
327 329
             }
328 330
 
Please login to merge, or discard this patch.