Completed
Pull Request — master (#1322)
by Nick
11:36 queued 06:31
created
scripts/wikipedia-cron.php 3 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -16,39 +16,39 @@  discard block
 block discarded – undo
16 16
 contributions('212.35.252.2'); # LibDem
17 17
 
18 18
 function contributions($ip) {
19
-	global $dir;
19
+    global $dir;
20 20
 
21
-	$file = fetch("/w/index.php?title=Special:Contributions&limit=100&target=$ip");
22
-	if (!$file) return;
23
-	$fp = fopen($dir . $ip, 'w');
24
-	fwrite($fp, $file['body']);
25
-	fclose($fp);
26
-	preg_match_all('#<li>(.*?) \(<a[^>]*>hist</a>\) \(<a href="(.*?title=(.*?)&.*?oldid=(.*?))"[^>]*>diff</a>\)  <a[^>]*>(.*?)</a> .*?</li>#', $file['body'], $m, PREG_SET_ORDER);
27
-	foreach ($m as $row) {
28
-		# print "$row[3] / $row[4]";
29
-		$filename = html_entity_decode("$row[3].$row[4]");
30
-		$path = $dir;
31
-		if (strstr($filename, '/')) {
32
-			$bits = explode('/', $filename);
33
-			array_pop($bits);
34
-			foreach ($bits as $bit) {
35
-				@mkdir($path . $bit);
36
-				$path .= "$bit/";
37
-			}
38
-		}
39
-		$cache = $dir . $filename;
40
-		if (!is_file($cache)) {
41
-			# print " - fetching";
42
-			$file = fetch(html_entity_decode($row[2]));
43
-			if (!$file) continue;
44
-			$fp = fopen($cache, 'w');
45
-			if ($fp) {
46
-				fwrite($fp, $file['body']);
47
-				fclose($fp);
48
-			}
49
-		}
50
-		# print "\n";
51
-	}
21
+    $file = fetch("/w/index.php?title=Special:Contributions&limit=100&target=$ip");
22
+    if (!$file) return;
23
+    $fp = fopen($dir . $ip, 'w');
24
+    fwrite($fp, $file['body']);
25
+    fclose($fp);
26
+    preg_match_all('#<li>(.*?) \(<a[^>]*>hist</a>\) \(<a href="(.*?title=(.*?)&.*?oldid=(.*?))"[^>]*>diff</a>\)  <a[^>]*>(.*?)</a> .*?</li>#', $file['body'], $m, PREG_SET_ORDER);
27
+    foreach ($m as $row) {
28
+        # print "$row[3] / $row[4]";
29
+        $filename = html_entity_decode("$row[3].$row[4]");
30
+        $path = $dir;
31
+        if (strstr($filename, '/')) {
32
+            $bits = explode('/', $filename);
33
+            array_pop($bits);
34
+            foreach ($bits as $bit) {
35
+                @mkdir($path . $bit);
36
+                $path .= "$bit/";
37
+            }
38
+        }
39
+        $cache = $dir . $filename;
40
+        if (!is_file($cache)) {
41
+            # print " - fetching";
42
+            $file = fetch(html_entity_decode($row[2]));
43
+            if (!$file) continue;
44
+            $fp = fopen($cache, 'w');
45
+            if ($fp) {
46
+                fwrite($fp, $file['body']);
47
+                fclose($fp);
48
+            }
49
+        }
50
+        # print "\n";
51
+    }
52 52
 }
53 53
 
54 54
 function fetch($url) {
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
     $host = 'en.wikipedia.org';
57 57
     $fp = @fsockopen($host, 80, $errno, $errstr, 10);
58 58
     if (!$fp) {
59
-	    #print "$errstr ($errno)\n";
59
+        #print "$errstr ($errno)\n";
60 60
             return '';
61 61
         }
62 62
     $out = "GET $url HTTP/1.1\r\n";
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,7 +19,9 @@  discard block
 block discarded – undo
19 19
 	global $dir;
20 20
 
21 21
 	$file = fetch("/w/index.php?title=Special:Contributions&limit=100&target=$ip");
22
-	if (!$file) return;
22
+	if (!$file) {
23
+	    return;
24
+	}
23 25
 	$fp = fopen($dir . $ip, 'w');
24 26
 	fwrite($fp, $file['body']);
25 27
 	fclose($fp);
@@ -40,7 +42,9 @@  discard block
 block discarded – undo
40 42
 		if (!is_file($cache)) {
41 43
 			# print " - fetching";
42 44
 			$file = fetch(html_entity_decode($row[2]));
43
-			if (!$file) continue;
45
+			if (!$file) {
46
+			    continue;
47
+			}
44 48
 			$fp = fopen($cache, 'w');
45 49
 			if ($fp) {
46 50
 				fwrite($fp, $file['body']);
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@
 block discarded – undo
59 59
 	    #print "$errstr ($errno)\n";
60 60
             return '';
61 61
         }
62
-    $out = "GET $url HTTP/1.1\r\n";
62
+    $out = "get $url HTTP/1.1\r\n";
63 63
     $out .= "Host: $host\r\n";
64 64
     $out .= "User-Agent: $ua\r\n";
65 65
     $out .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9;text/plain;q=0.8,image/png,*/*;q=0.5\r\n";
Please login to merge, or discard this patch.
scripts/alertmpchanged.php 4 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -22,26 +22,26 @@  discard block
 block discarded – undo
22 22
 $toemail = '';
23 23
 $template = 'alert_new_mp';
24 24
 for ($k=1; $k<$argc; $k++) {
25
-	if ($argv[$k] == '--nomail')
26
-		$nomail = true;
27
-	if (preg_match('#^--only=(.*)$#', $argv[$k], $m))
28
-		$onlyemail = $m[1];
29
-	if (preg_match('#^--from=(.*)$#', $argv[$k], $m))
30
-		$fromemail = $m[1];
31
-	if (preg_match('#^--to=(.*)$#', $argv[$k], $m))
32
-		$toemail = $m[1];
25
+    if ($argv[$k] == '--nomail')
26
+        $nomail = true;
27
+    if (preg_match('#^--only=(.*)$#', $argv[$k], $m))
28
+        $onlyemail = $m[1];
29
+    if (preg_match('#^--from=(.*)$#', $argv[$k], $m))
30
+        $fromemail = $m[1];
31
+    if (preg_match('#^--to=(.*)$#', $argv[$k], $m))
32
+        $toemail = $m[1];
33 33
 }
34 34
 
35 35
 if (DEVSITE)
36
-  $nomail = true;
36
+    $nomail = true;
37 37
 
38 38
 # Change this to the end date
39 39
 $END_DATE = '2017-05-03';
40 40
 
41 41
 if ($nomail) mlog("NOT SENDING EMAIL\n");
42 42
 if (($fromemail && $onlyemail) || ($toemail && $onlyemail)) {
43
-	mlog("Can't have both from/to and only!\n");
44
-	exit;
43
+    mlog("Can't have both from/to and only!\n");
44
+    exit;
45 45
 }
46 46
 
47 47
 $active = 0;
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 $members = array();
67 67
 $start_time = time();
68 68
 foreach ($alertdata as $alertitem) {
69
-	$active++;
70
-	$email = $alertitem['email'];
69
+    $active++;
70
+    $email = $alertitem['email'];
71 71
     if ($onlyemail && $email != $onlyemail) continue;
72 72
     if ($fromemail && strtolower($email) == $fromemail) $fromflag = true;
73 73
     if ($fromemail && !$fromflag) continue;
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
 
144 144
 $sss = "Active alerts: $active\nEmail lookups: $registered registered, $unregistered unregistered\nQuery lookups: $queries\nSent emails: $sentemails\n";
145 145
 if ($globalsuccess) {
146
-      $sss .= 'Everything went swimmingly, in ';
146
+        $sss .= 'Everything went swimmingly, in ';
147 147
 } else {
148
-      $sss .= 'Something went wrong! Total time: ';
148
+        $sss .= 'Something went wrong! Total time: ';
149 149
 }
150 150
 $sss .= (getmicrotime()-$global_start)."\n\n";
151 151
 mlog($sss);
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@
 block discarded – undo
155 155
     global $globalsuccess, $sentemails, $nomail, $start_time;
156 156
 
157 157
     $sentemails++;
158
-    mlog("SEND $sentemails : Sending email to $current[email] ... ");
158
+    mlog("send $sentemails : Sending email to $current[email] ... ");
159 159
     $d = array('to' => $current['email'], 'template' => $template);
160 160
     $m = array(
161 161
         'DATA' => join("\n", $data),
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 $fromflag = false;
22 22
 $toemail = '';
23 23
 $template = 'alert_new_mp';
24
-for ($k=1; $k<$argc; $k++) {
24
+for ($k = 1; $k < $argc; $k++) {
25 25
 	if ($argv[$k] == '--nomail')
26 26
 		$nomail = true;
27 27
 	if (preg_match('#^--only=(.*)$#', $argv[$k], $m))
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
     // skip if they didn't lose their westminster seat in the most recent election
92 92
     if ($member->left_house(1)['date'] != $END_DATE) continue;
93 93
 
94
-    if ( !isset($cons[$member->constituency]) ) {
94
+    if (!isset($cons[$member->constituency])) {
95 95
         $cons_member = new MEMBER(array('constituency' => $member->constituency, 'house' => 1));
96
-        if ( !$cons_member ) {
96
+        if (!$cons_member) {
97 97
             continue;
98 98
         }
99 99
         $cons[$member->constituency] = $cons_member;
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
     }
103 103
 
104 104
     // these should never happen but let's just be sure
105
-    if ( $cons_member->person_id == $member->person_id ) continue;
105
+    if ($cons_member->person_id == $member->person_id) continue;
106 106
     if (!$cons_member->current_member_anywhere()) continue;
107 107
 
108 108
     if ($email != $current['email']) {
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
             $user_id = 0;
123 123
             $unregistered++;
124 124
         }
125
-        mlog("\nEMAIL: $email, uid $user_id; memory usage : ".memory_get_usage()."\n");
125
+        mlog("\nEMAIL: $email, uid $user_id; memory usage : " . memory_get_usage() . "\n");
126 126
     }
127 127
 
128 128
     $lh = $member->left_house();
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 } else {
148 148
       $sss .= 'Something went wrong! Total time: ';
149 149
 }
150
-$sss .= (getmicrotime()-$global_start)."\n\n";
150
+$sss .= (getmicrotime() - $global_start) . "\n\n";
151 151
 mlog($sss);
152 152
 mlog(date('r') . "\n");
153 153
 
@@ -160,18 +160,18 @@  discard block
 block discarded – undo
160 160
     $m = array(
161 161
         'DATA' => join("\n", $data),
162 162
         'CHANGE' => join("\n", $change),
163
-        'ALERT_IS' => count($data)==1 ? 'alert is' : 'alerts are',
164
-        'MPS' => count($data)==1 ? 'This MP' : 'These MPs',
165
-        'MPS2' => count($data)==1 ? 'MP' : 'MPs',
166
-        'ALERTS' => count($data)==1 ? 'an alert' : 'some alerts',
167
-        'ALERTS2' => count($data)==1 ? 'alert' : 'alerts',
168
-        'LINKS' => count($data)==1 ? 'link' : 'links',
163
+        'ALERT_IS' => count($data) == 1 ? 'alert is' : 'alerts are',
164
+        'MPS' => count($data) == 1 ? 'This MP' : 'These MPs',
165
+        'MPS2' => count($data) == 1 ? 'MP' : 'MPs',
166
+        'ALERTS' => count($data) == 1 ? 'an alert' : 'some alerts',
167
+        'ALERTS2' => count($data) == 1 ? 'alert' : 'alerts',
168
+        'LINKS' => count($data) == 1 ? 'link' : 'links',
169 169
     );
170 170
     if (!$nomail) {
171 171
         $success = send_template_email($d, $m, true);
172 172
         mlog("sent ... ");
173 173
         # sleep if time between sending mails is less than a certain number of seconds on average
174
-        if (((time() - $start_time) / $sentemails) < 0.5 ) { # number of seconds per mail not to be quicker than
174
+        if (((time() - $start_time) / $sentemails) < 0.5) { # number of seconds per mail not to be quicker than
175 175
             mlog("pausing ... ");
176 176
             sleep(1);
177 177
         }
Please login to merge, or discard this patch.
Braces   +56 added lines, -26 removed lines patch added patch discarded remove patch
@@ -22,23 +22,30 @@  discard block
 block discarded – undo
22 22
 $toemail = '';
23 23
 $template = 'alert_new_mp';
24 24
 for ($k=1; $k<$argc; $k++) {
25
-	if ($argv[$k] == '--nomail')
26
-		$nomail = true;
27
-	if (preg_match('#^--only=(.*)$#', $argv[$k], $m))
28
-		$onlyemail = $m[1];
29
-	if (preg_match('#^--from=(.*)$#', $argv[$k], $m))
30
-		$fromemail = $m[1];
31
-	if (preg_match('#^--to=(.*)$#', $argv[$k], $m))
32
-		$toemail = $m[1];
33
-}
34
-
35
-if (DEVSITE)
25
+	if ($argv[$k] == '--nomail') {
26
+			$nomail = true;
27
+	}
28
+	if (preg_match('#^--only=(.*)$#', $argv[$k], $m)) {
29
+			$onlyemail = $m[1];
30
+	}
31
+	if (preg_match('#^--from=(.*)$#', $argv[$k], $m)) {
32
+			$fromemail = $m[1];
33
+	}
34
+	if (preg_match('#^--to=(.*)$#', $argv[$k], $m)) {
35
+			$toemail = $m[1];
36
+	}
37
+	}
38
+
39
+if (DEVSITE) {
36 40
   $nomail = true;
41
+}
37 42
 
38 43
 # Change this to the end date
39 44
 $END_DATE = '2017-05-03';
40 45
 
41
-if ($nomail) mlog("NOT SENDING EMAIL\n");
46
+if ($nomail) {
47
+    mlog("NOT SENDING EMAIL\n");
48
+}
42 49
 if (($fromemail && $onlyemail) || ($toemail && $onlyemail)) {
43 50
 	mlog("Can't have both from/to and only!\n");
44 51
 	exit;
@@ -68,14 +75,24 @@  discard block
 block discarded – undo
68 75
 foreach ($alertdata as $alertitem) {
69 76
 	$active++;
70 77
 	$email = $alertitem['email'];
71
-    if ($onlyemail && $email != $onlyemail) continue;
72
-    if ($fromemail && strtolower($email) == $fromemail) $fromflag = true;
73
-    if ($fromemail && !$fromflag) continue;
74
-    if ($toemail && strtolower($email) >= $toemail) continue;
78
+    if ($onlyemail && $email != $onlyemail) {
79
+        continue;
80
+    }
81
+    if ($fromemail && strtolower($email) == $fromemail) {
82
+        $fromflag = true;
83
+    }
84
+    if ($fromemail && !$fromflag) {
85
+        continue;
86
+    }
87
+    if ($toemail && strtolower($email) >= $toemail) {
88
+        continue;
89
+    }
75 90
     $criteria_raw = $alertitem['criteria'];
76 91
 
77 92
     // we only care about alerts for people speaking
78
-    if (!strstr($criteria_raw, 'speaker:')) continue;
93
+    if (!strstr($criteria_raw, 'speaker:')) {
94
+        continue;
95
+    }
79 96
 
80 97
     preg_match('#speaker:(\d+)#', $criteria_raw, $m);
81 98
     $person_id = $m[1];
@@ -86,10 +103,14 @@  discard block
 block discarded – undo
86 103
     $member = $members[$person_id];
87 104
 
88 105
     // if they're still elected then don't send the email
89
-    if ($member->current_member_anywhere()) continue;
106
+    if ($member->current_member_anywhere()) {
107
+        continue;
108
+    }
90 109
 
91 110
     // skip if they didn't lose their westminster seat in the most recent election
92
-    if ($member->left_house(1)['date'] != $END_DATE) continue;
111
+    if ($member->left_house(1)['date'] != $END_DATE) {
112
+        continue;
113
+    }
93 114
 
94 115
     if ( !isset($cons[$member->constituency]) ) {
95 116
         $cons_member = new MEMBER(array('constituency' => $member->constituency, 'house' => 1));
@@ -97,13 +118,18 @@  discard block
 block discarded – undo
97 118
             continue;
98 119
         }
99 120
         $cons[$member->constituency] = $cons_member;
100
-    } else {
121
+    }
122
+    else {
101 123
         $cons_member = $cons[$member->constituency];
102 124
     }
103 125
 
104 126
     // these should never happen but let's just be sure
105
-    if ( $cons_member->person_id == $member->person_id ) continue;
106
-    if (!$cons_member->current_member_anywhere()) continue;
127
+    if ( $cons_member->person_id == $member->person_id ) {
128
+        continue;
129
+    }
130
+    if (!$cons_member->current_member_anywhere()) {
131
+        continue;
132
+    }
107 133
 
108 134
     if ($email != $current['email']) {
109 135
         if ($email_text && $change_text) {
@@ -118,7 +144,8 @@  discard block
 block discarded – undo
118 144
         if ($q->rows() > 0) {
119 145
             $user_id = $q->field(0, 'user_id');
120 146
             $registered++;
121
-        } else {
147
+        }
148
+        else {
122 149
             $user_id = 0;
123 150
             $unregistered++;
124 151
         }
@@ -144,7 +171,8 @@  discard block
 block discarded – undo
144 171
 $sss = "Active alerts: $active\nEmail lookups: $registered registered, $unregistered unregistered\nQuery lookups: $queries\nSent emails: $sentemails\n";
145 172
 if ($globalsuccess) {
146 173
       $sss .= 'Everything went swimmingly, in ';
147
-} else {
174
+}
175
+else {
148 176
       $sss .= 'Something went wrong! Total time: ';
149 177
 }
150 178
 $sss .= (getmicrotime()-$global_start)."\n\n";
@@ -171,11 +199,13 @@  discard block
 block discarded – undo
171 199
         $success = send_template_email($d, $m, true);
172 200
         mlog("sent ... ");
173 201
         # sleep if time between sending mails is less than a certain number of seconds on average
174
-        if (((time() - $start_time) / $sentemails) < 0.5 ) { # number of seconds per mail not to be quicker than
202
+        if (((time() - $start_time) / $sentemails) < 0.5 ) {
203
+# number of seconds per mail not to be quicker than
175 204
             mlog("pausing ... ");
176 205
             sleep(1);
177 206
         }
178
-    } else {
207
+    }
208
+    else {
179 209
         mlog(join('', $data));
180 210
         $success = 1;
181 211
     }
Please login to merge, or discard this patch.
scripts/video-mark-missing.php 2 patches
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@  discard block
 block discarded – undo
16 16
 
17 17
 $date = substr($from, 0, 10);
18 18
 $from = 'uk.org.publicwhip/debate/' . $from;
19
-if ($to) $to = 'uk.org.publicwhip/debate/' . $to;
19
+if ($to) {
20
+    $to = 'uk.org.publicwhip/debate/' . $to;
21
+}
20 22
 
21 23
 $q = $db->query('select hpos from hansard where gid="' . $from . '"');
22 24
 $hpos_from = $q->field(0, 'hpos');
@@ -34,8 +36,9 @@  discard block
 block discarded – undo
34 36
 
35 37
 $query = "update hansard set video_status = video_status | 8
36 38
     where major=1 and hdate='$date' and hpos>=$hpos_from";
37
-if ($to)
39
+if ($to) {
38 40
     $query .= " and hpos<=$hpos_to";
41
+}
39 42
 
40 43
 print "Executing $query...\n";
41 44
 $q = $db->query($query);
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,6 +37,6 @@
 block discarded – undo
37 37
 if ($to)
38 38
     $query .= " and hpos<=$hpos_to";
39 39
 
40
-print "Executing $query...\n";
40
+print "executing $query...\n";
41 41
 $q = $db->query($query);
42 42
 print '  ' . $q->affected_rows() . " rows have been marked as missing\n";
Please login to merge, or discard this patch.
scripts/wranstats.php 3 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 $db = new ParlDB;
7 7
 
8 8
 $q = $db->query(
9
-	'select person_id,
9
+    'select person_id,
10 10
 		count(hansard.epobject_id) as wrans,
11 11
 		sum(yes_votes) + IFNULL((select sum(vote) from uservotes, hansard as hansard2
12 12
 				  where uservotes.epobject_id=hansard2.epobject_id
@@ -20,23 +20,23 @@  discard block
 block discarded – undo
20 20
 	group by person_id');
21 21
 
22 22
 for ($i=0; $i<$q->rows(); $i++) {
23
-	$p_id = $q->field($i, 'person_id');
24
-	$name = $q->field($i, 'first_name') . ' ' . $q->field($i, 'last_name');
25
-	$con = $q->field($i, 'constituency');
26
-	$wrans = $q->field($i, 'wrans');
27
-	$yes = $q->field($i, 'yes');
28
-	$no = $q->field($i, 'no');
29
-	if ($p_id) {
30
-	$qq = $db->query('(select hansard.epobject_id from hansard, uservotes
23
+    $p_id = $q->field($i, 'person_id');
24
+    $name = $q->field($i, 'first_name') . ' ' . $q->field($i, 'last_name');
25
+    $con = $q->field($i, 'constituency');
26
+    $wrans = $q->field($i, 'wrans');
27
+    $yes = $q->field($i, 'yes');
28
+    $no = $q->field($i, 'no');
29
+    if ($p_id) {
30
+    $qq = $db->query('(select hansard.epobject_id from hansard, uservotes
31 31
 			where hansard.epobject_id=uservotes.epobject_id
32 32
             and hansard.person_id = '.$p_id.' and major=3 and minor=2 and left_house>curdate())
33 33
 		union
34 34
 			(select hansard.epobject_id from hansard,member,anonvotes
35 35
 			 where hansard.epobject_id=anonvotes.epobject_id
36 36
              and hansard.person_id = '.$p_id.' and major=3 and minor=2 and left_house>curdate())');
37
-	$wrans_with_votes = $qq->rows();
38
-	} else {
39
-		$wrans_with_votes = '';
40
-	}
41
-	print "$name\t$con\t$wrans\t$wrans_with_votes\t$yes\t$no\n";
37
+    $wrans_with_votes = $qq->rows();
38
+    } else {
39
+        $wrans_with_votes = '';
40
+    }
41
+    print "$name\t$con\t$wrans\t$wrans_with_votes\t$yes\t$no\n";
42 42
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 		where major = 3 and minor = 2 and left_house > curdate()
20 20
 	group by person_id');
21 21
 
22
-for ($i=0; $i<$q->rows(); $i++) {
22
+for ($i = 0; $i < $q->rows(); $i++) {
23 23
 	$p_id = $q->field($i, 'person_id');
24 24
 	$name = $q->field($i, 'first_name') . ' ' . $q->field($i, 'last_name');
25 25
 	$con = $q->field($i, 'constituency');
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
 	if ($p_id) {
30 30
 	$qq = $db->query('(select hansard.epobject_id from hansard, uservotes
31 31
 			where hansard.epobject_id=uservotes.epobject_id
32
-            and hansard.person_id = '.$p_id.' and major=3 and minor=2 and left_house>curdate())
32
+            and hansard.person_id = '.$p_id . ' and major=3 and minor=2 and left_house>curdate())
33 33
 		union
34 34
 			(select hansard.epobject_id from hansard,member,anonvotes
35 35
 			 where hansard.epobject_id=anonvotes.epobject_id
36
-             and hansard.person_id = '.$p_id.' and major=3 and minor=2 and left_house>curdate())');
36
+             and hansard.person_id = '.$p_id . ' and major=3 and minor=2 and left_house>curdate())');
37 37
 	$wrans_with_votes = $qq->rows();
38 38
 	} else {
39 39
 		$wrans_with_votes = '';
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,8 @@
 block discarded – undo
35 35
 			 where hansard.epobject_id=anonvotes.epobject_id
36 36
              and hansard.person_id = '.$p_id.' and major=3 and minor=2 and left_house>curdate())');
37 37
 	$wrans_with_votes = $qq->rows();
38
-	} else {
38
+	}
39
+	else {
39 40
 		$wrans_with_votes = '';
40 41
 	}
41 42
 	print "$name\t$con\t$wrans\t$wrans_with_votes\t$yes\t$no\n";
Please login to merge, or discard this patch.
scripts/video-check.php 3 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -10,18 +10,18 @@
 block discarded – undo
10 10
 	order by hdate, hpos');
11 11
 $last = array('hdate'=>'');
12 12
 for ($i=0; $i<$q->rows(); $i++) {
13
-	$row = array(
14
-		'atime' => $q->field($i, 'atime'),
15
-		'hdate' => $q->field($i, 'hdate'),
16
-		'gid' => $q->field($i, 'gid'),
17
-		'hpos' => $q->field($i, 'hpos')
18
-	);
19
-	if ($row['hdate'] != $last['hdate'])
20
-		$last = array();
21
-	if ($last && $row['atime'] < $last['atime']-5) {
22
-		print "PROBLEM; current row is $row[gid] $row[hdate] $row[atime]\n";
23
-		print "  Last was $last[gid] $last[hdate] $last[atime]\n";
24
-	}
25
-	$last = $row;
13
+    $row = array(
14
+        'atime' => $q->field($i, 'atime'),
15
+        'hdate' => $q->field($i, 'hdate'),
16
+        'gid' => $q->field($i, 'gid'),
17
+        'hpos' => $q->field($i, 'hpos')
18
+    );
19
+    if ($row['hdate'] != $last['hdate'])
20
+        $last = array();
21
+    if ($last && $row['atime'] < $last['atime']-5) {
22
+        print "PROBLEM; current row is $row[gid] $row[hdate] $row[atime]\n";
23
+        print "  Last was $last[gid] $last[hdate] $last[atime]\n";
24
+    }
25
+    $last = $row;
26 26
 }
27 27
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 		and (user_id is null or user_id != -1) and deleted=0
10 10
 	order by hdate, hpos');
11 11
 $last = array('hdate'=>'');
12
-for ($i=0; $i<$q->rows(); $i++) {
12
+for ($i = 0; $i < $q->rows(); $i++) {
13 13
 	$row = array(
14 14
 		'atime' => $q->field($i, 'atime'),
15 15
 		'hdate' => $q->field($i, 'hdate'),
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 	);
19 19
 	if ($row['hdate'] != $last['hdate'])
20 20
 		$last = array();
21
-	if ($last && $row['atime'] < $last['atime']-5) {
21
+	if ($last && $row['atime'] < $last['atime'] - 5) {
22 22
 		print "PROBLEM; current row is $row[gid] $row[hdate] $row[atime]\n";
23 23
 		print "  Last was $last[gid] $last[hdate] $last[atime]\n";
24 24
 	}
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,8 +16,9 @@
 block discarded – undo
16 16
 		'gid' => $q->field($i, 'gid'),
17 17
 		'hpos' => $q->field($i, 'hpos')
18 18
 	);
19
-	if ($row['hdate'] != $last['hdate'])
20
-		$last = array();
19
+	if ($row['hdate'] != $last['hdate']) {
20
+			$last = array();
21
+	}
21 22
 	if ($last && $row['atime'] < $last['atime']-5) {
22 23
 		print "PROBLEM; current row is $row[gid] $row[hdate] $row[atime]\n";
23 24
 		print "  Last was $last[gid] $last[hdate] $last[atime]\n";
Please login to merge, or discard this patch.
scripts/daily-api-usage.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,9 @@
 block discarded – undo
52 52
 <br><small style='color:#666'>$reason</small>
53 53
 ";
54 54
 }
55
-if (!$out) exit;
55
+if (!$out) {
56
+    exit;
57
+}
56 58
 
57 59
 $headers =
58 60
     "From: TheyWorkForYou <" . CONTACTEMAIL . ">\r\n" .
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 ');
23 23
 
24 24
 $keys = array();
25
-for ($i=0; $i<$q->rows(); $i++) {
25
+for ($i = 0; $i < $q->rows(); $i++) {
26 26
     $keys[] = $q->field($i, 'api_key');
27 27
 }
28 28
 $keys = join("','", $keys);
@@ -34,18 +34,18 @@  discard block
 block discarded – undo
34 34
     GROUP BY api_key
35 35
 ");
36 36
 $summary = array();
37
-for ($i=0; $i<$q2->rows(); $i++) {
37
+for ($i = 0; $i < $q2->rows(); $i++) {
38 38
     $row = $q2->row($i);
39 39
     $summary[$row['api_key']] = array($row['first_use'], $row['count']);
40 40
 }
41 41
 
42 42
 $out = '';
43
-for ($i=0; $i<$q->rows(); $i++) {
43
+for ($i = 0; $i < $q->rows(); $i++) {
44 44
     $row = $q->row($i);
45 45
     $reason = preg_replace("/\r?\n/", ' ', $row['reason']);
46
-    $comm = $row['commercial']==1 ? ', commercial' : '';
47
-    $ipa = $row['ip_addresses']!=1 ? 'es' : '';
48
-    $hp = $row['count']!=1 ? 's' : '';
46
+    $comm = $row['commercial'] == 1 ? ', commercial' : '';
47
+    $ipa = $row['ip_addresses'] != 1 ? 'es' : '';
48
+    $hp = $row['count'] != 1 ? 's' : '';
49 49
     list($first, $total) = $summary[$row['api_key']];
50 50
     $out .= "<p><b>$row[count] hit$hp, from $row[ip_addresses] IP address$ipa.</b> $row[firstname] $row[lastname] &lt;$row[email]&gt;
51 51
 <br>$row[api_key], created $row[created], first use $first$comm, total calls $total
@@ -61,5 +61,5 @@  discard block
 block discarded – undo
61 61
     "Content-Transfer-Encoding: 8bit\r\n";
62 62
 $subject = 'Daily TheyWorkForYou API usage';
63 63
 $to = join(chr(64), array('commercial', 'mysociety.org'));
64
-mail ($to, $subject, $out, $headers);
64
+mail($to, $subject, $out, $headers);
65 65
 
Please login to merge, or discard this patch.
scripts/wrans-votes-by-dept.php 3 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 
11 11
 # Done directly as storing everything in an array as $db->query() does runs out of memory, unsurprisingly
12 12
 $q = mysql_query(
13
-	'select section.body, gid, yes_votes, no_votes
13
+    'select section.body, gid, yes_votes, no_votes
14 14
 	from hansard
15 15
 		inner join epobject as section on hansard.section_id = section.epobject_id
16 16
 		left join anonvotes on hansard.epobject_id = anonvotes.epobject_id
@@ -24,34 +24,34 @@  discard block
 block discarded – undo
24 24
 
25 25
 $votes = array();
26 26
 while ($row = mysql_fetch_assoc($q)) {
27
-	$dept = $row['body'];
28
-	if (!isset($votes[$dept])) $votes[$dept] = array(
29
-		'verymoreyes'=>0, 'moreyes'=>0, 'verymoreno'=>0, 'moreno'=>0, 'same'=>0, 'none'=>0
30
-	);
31
-	$yes = $row['yes_votes'];
32
-	$no = $row['no_votes'];
33
-	$gid = $row['gid'];
34
-	if (is_null($yes)) {
35
-		$votes[$dept]['none']++;
36
-	} else {
37
-		if ($no > $yes+10) {
38
-			$votes[$dept]['verymoreno']++;
39
-		} elseif ($no > $yes) {
40
-			$votes[$dept]['moreno']++;
41
-		} elseif ($no + 10 < $yes) {
42
-			$votes[$dept]['verymoreyes']++;
43
-		} elseif ($no < $yes) {
44
-			$votes[$dept]['moreyes']++;
45
-		} else {
46
-			$votes[$dept]['same']++;
47
-		}
48
-	}
27
+    $dept = $row['body'];
28
+    if (!isset($votes[$dept])) $votes[$dept] = array(
29
+        'verymoreyes'=>0, 'moreyes'=>0, 'verymoreno'=>0, 'moreno'=>0, 'same'=>0, 'none'=>0
30
+    );
31
+    $yes = $row['yes_votes'];
32
+    $no = $row['no_votes'];
33
+    $gid = $row['gid'];
34
+    if (is_null($yes)) {
35
+        $votes[$dept]['none']++;
36
+    } else {
37
+        if ($no > $yes+10) {
38
+            $votes[$dept]['verymoreno']++;
39
+        } elseif ($no > $yes) {
40
+            $votes[$dept]['moreno']++;
41
+        } elseif ($no + 10 < $yes) {
42
+            $votes[$dept]['verymoreyes']++;
43
+        } elseif ($no < $yes) {
44
+            $votes[$dept]['moreyes']++;
45
+        } else {
46
+            $votes[$dept]['same']++;
47
+        }
48
+    }
49 49
 }
50 50
 
51 51
 print "Department,11+ more yes votes than no,1-10 more yes votes than no,11+ more no votes than yes,1-10 more no votes than yes,Same votes yes/no,No votes\n";
52 52
 foreach ($votes as $dept => $v) {
53
-	#if (!$v['moreyes'] && !$v['moreno'] && !$v['same']) continue;
54
-	if (strstr($dept, ','))
55
-		$dept = "\"$dept\"";
56
-	print "$dept,$v[verymoreyes],$v[moreyes],$v[verymoreno],$v[moreno],$v[same],$v[none]\n";
53
+    #if (!$v['moreyes'] && !$v['moreno'] && !$v['same']) continue;
54
+    if (strstr($dept, ','))
55
+        $dept = "\"$dept\"";
56
+    print "$dept,$v[verymoreyes],$v[moreyes],$v[verymoreno],$v[moreno],$v[same],$v[none]\n";
57 57
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
 	if (is_null($yes)) {
35 35
 		$votes[$dept]['none']++;
36 36
 	} else {
37
-		if ($no > $yes+10) {
37
+		if ($no > $yes + 10) {
38 38
 			$votes[$dept]['verymoreno']++;
39 39
 		} elseif ($no > $yes) {
40 40
 			$votes[$dept]['moreno']++;
Please login to merge, or discard this patch.
Braces   +16 added lines, -8 removed lines patch added patch discarded remove patch
@@ -25,24 +25,31 @@  discard block
 block discarded – undo
25 25
 $votes = array();
26 26
 while ($row = mysql_fetch_assoc($q)) {
27 27
 	$dept = $row['body'];
28
-	if (!isset($votes[$dept])) $votes[$dept] = array(
28
+	if (!isset($votes[$dept])) {
29
+	    $votes[$dept] = array(
29 30
 		'verymoreyes'=>0, 'moreyes'=>0, 'verymoreno'=>0, 'moreno'=>0, 'same'=>0, 'none'=>0
30 31
 	);
32
+	}
31 33
 	$yes = $row['yes_votes'];
32 34
 	$no = $row['no_votes'];
33 35
 	$gid = $row['gid'];
34 36
 	if (is_null($yes)) {
35 37
 		$votes[$dept]['none']++;
36
-	} else {
38
+	}
39
+	else {
37 40
 		if ($no > $yes+10) {
38 41
 			$votes[$dept]['verymoreno']++;
39
-		} elseif ($no > $yes) {
42
+		}
43
+		elseif ($no > $yes) {
40 44
 			$votes[$dept]['moreno']++;
41
-		} elseif ($no + 10 < $yes) {
45
+		}
46
+		elseif ($no + 10 < $yes) {
42 47
 			$votes[$dept]['verymoreyes']++;
43
-		} elseif ($no < $yes) {
48
+		}
49
+		elseif ($no < $yes) {
44 50
 			$votes[$dept]['moreyes']++;
45
-		} else {
51
+		}
52
+		else {
46 53
 			$votes[$dept]['same']++;
47 54
 		}
48 55
 	}
@@ -51,7 +58,8 @@  discard block
 block discarded – undo
51 58
 print "Department,11+ more yes votes than no,1-10 more yes votes than no,11+ more no votes than yes,1-10 more no votes than yes,Same votes yes/no,No votes\n";
52 59
 foreach ($votes as $dept => $v) {
53 60
 	#if (!$v['moreyes'] && !$v['moreno'] && !$v['same']) continue;
54
-	if (strstr($dept, ','))
55
-		$dept = "\"$dept\"";
61
+	if (strstr($dept, ',')) {
62
+			$dept = "\"$dept\"";
63
+	}
56 64
 	print "$dept,$v[verymoreyes],$v[moreyes],$v[verymoreno],$v[moreno],$v[same],$v[none]\n";
57 65
 }
Please login to merge, or discard this patch.
scripts/alertmailer.php 4 patches
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  */
7 7
 
8 8
 function mlog($message) {
9
-	print $message;
9
+    print $message;
10 10
 }
11 11
 
12 12
 include_once '../www/includes/easyparliament/init.php';
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
 # Last sent is timestamp of last alerts gone out.
25 25
 # Last batch is the search index batch number last alert went out to.
26 26
 if (is_file('alerts-lastsent'))
27
-	$lastsent = file('alerts-lastsent');
27
+    $lastsent = file('alerts-lastsent');
28 28
 else
29
-	$lastsent = array('', 0);
29
+    $lastsent = array('', 0);
30 30
 
31 31
 $lastupdated = trim($lastsent[0]);
32 32
 if (!$lastupdated) $lastupdated = strtotime('00:00 today');
@@ -38,13 +38,13 @@  discard block
 block discarded – undo
38 38
 # have been made since last time we ran
39 39
 $batch_query_fragment = "";
40 40
 for ($i=$lastbatch + 1; $i <= $max_batch_id; $i++) {
41
-	$batch_query_fragment .= "batch:$i ";
41
+    $batch_query_fragment .= "batch:$i ";
42 42
 }
43 43
 $batch_query_fragment = trim($batch_query_fragment);
44 44
 mlog("batch_query_fragment: " . $batch_query_fragment . "\n");
45 45
 
46 46
 if (!$batch_query_fragment) {
47
-	mlog("No new batches since last run - nothing to run over!");
47
+    mlog("No new batches since last run - nothing to run over!");
48 48
     exit;
49 49
 }
50 50
 
@@ -56,28 +56,28 @@  discard block
 block discarded – undo
56 56
 $toemail = '';
57 57
 $template = 'alert_mailout';
58 58
 for ($k=1; $k<$argc; $k++) {
59
-	if ($argv[$k] == '--nomail')
60
-		$nomail = true;
61
-	if (preg_match('#^--only=(.*)$#', $argv[$k], $m))
62
-		$onlyemail = $m[1];
63
-	if (preg_match('#^--from=(.*)$#', $argv[$k], $m))
64
-		$fromemail = $m[1];
65
-	if (preg_match('#^--to=(.*)$#', $argv[$k], $m))
66
-		$toemail = $m[1];
67
-	if (preg_match('#^--template=(.*)$#', $argv[$k], $m)) {
68
-		$template = $m[1];
69
-		# Tee hee
70
-		$template = "../../../../../../../../../../home/twfy-live/email-alert-templates/alert_mailout_$template";
71
-	}
59
+    if ($argv[$k] == '--nomail')
60
+        $nomail = true;
61
+    if (preg_match('#^--only=(.*)$#', $argv[$k], $m))
62
+        $onlyemail = $m[1];
63
+    if (preg_match('#^--from=(.*)$#', $argv[$k], $m))
64
+        $fromemail = $m[1];
65
+    if (preg_match('#^--to=(.*)$#', $argv[$k], $m))
66
+        $toemail = $m[1];
67
+    if (preg_match('#^--template=(.*)$#', $argv[$k], $m)) {
68
+        $template = $m[1];
69
+        # Tee hee
70
+        $template = "../../../../../../../../../../home/twfy-live/email-alert-templates/alert_mailout_$template";
71
+    }
72 72
 }
73 73
 
74 74
 if (DEVSITE)
75
-	$nomail = true;
75
+    $nomail = true;
76 76
 
77 77
 if ($nomail) mlog("NOT SENDING EMAIL\n");
78 78
 if (($fromemail && $onlyemail) || ($toemail && $onlyemail)) {
79
-	mlog("Can't have both from/to and only!\n");
80
-	exit;
79
+    mlog("Can't have both from/to and only!\n");
80
+    exit;
81 81
 }
82 82
 
83 83
 $active = 0;
@@ -140,142 +140,142 @@  discard block
 block discarded – undo
140 140
 $outof = count($alertdata);
141 141
 $start_time = time();
142 142
 foreach ($alertdata as $alertitem) {
143
-	$active++;
144
-	$email = $alertitem['email'];
145
-	if ($onlyemail && $email != $onlyemail) continue;
146
-	if ($fromemail && strtolower($email) == $fromemail) $fromflag = true;
147
-	if ($fromemail && !$fromflag) continue;
148
-	if ($toemail && strtolower($email) >= $toemail) continue;
149
-	$criteria_raw = $alertitem['criteria'];
150
-	if (preg_match('#\bOR\b#', $criteria_raw)) {
151
-		$criteria_raw = "($criteria_raw)";
152
-	}
153
-	$criteria_batch = $criteria_raw . " " . $batch_query_fragment;
154
-
155
-	if ($email != $current['email']) {
156
-		if ($email_text)
157
-			write_and_send_email($current, $email_text, $template);
158
-		$current['email'] = $email;
159
-		$current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken'];
160
-		$email_text = '';
161
-		$q = $db->query('SELECT user_id FROM users WHERE email = :email', array(
143
+    $active++;
144
+    $email = $alertitem['email'];
145
+    if ($onlyemail && $email != $onlyemail) continue;
146
+    if ($fromemail && strtolower($email) == $fromemail) $fromflag = true;
147
+    if ($fromemail && !$fromflag) continue;
148
+    if ($toemail && strtolower($email) >= $toemail) continue;
149
+    $criteria_raw = $alertitem['criteria'];
150
+    if (preg_match('#\bOR\b#', $criteria_raw)) {
151
+        $criteria_raw = "($criteria_raw)";
152
+    }
153
+    $criteria_batch = $criteria_raw . " " . $batch_query_fragment;
154
+
155
+    if ($email != $current['email']) {
156
+        if ($email_text)
157
+            write_and_send_email($current, $email_text, $template);
158
+        $current['email'] = $email;
159
+        $current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken'];
160
+        $email_text = '';
161
+        $q = $db->query('SELECT user_id FROM users WHERE email = :email', array(
162 162
             ':email' => $email
163 163
             ));
164
-		if ($q->rows() > 0) {
165
-			$user_id = $q->field(0, 'user_id');
166
-			$registered++;
167
-		} else {
168
-			$user_id = 0;
169
-			$unregistered++;
170
-		}
171
-		mlog("\nEMAIL: $email, uid $user_id; memory usage : ".memory_get_usage()."\n");
172
-	}
173
-
174
-	$data = null;
175
-	if (!isset($results[$criteria_batch])) {
176
-		mlog("  ALERT $active/$outof QUERY $queries : Xapian query '$criteria_batch'");
177
-		$start = getmicrotime();
178
-		$SEARCHENGINE = new SEARCHENGINE($criteria_batch);
179
-		#mlog("query_remade: " . $SEARCHENGINE->query_remade() . "\n");
180
-		$args = array(
181
-			's' => $criteria_raw, # Note: use raw here for URLs, whereas search engine has batch
182
-			'threshold' => $lastupdated, # Return everything added since last time this script was run
183
-			'o' => 'c',
184
-			'num' => 1000, // this is limited to 1000 in hansardlist.php anyway
185
-			'pop' => 1,
186
-			'e' => 1 # Don't escape ampersands
187
-		);
188
-		$data = $DEBATELIST->_get_data_by_search($args);
189
-		# add to cache (but only for speaker queries, which are commonly repeated)
190
-		# Don't cache, it's very quick, and we'd prefer low memory usage
191
-		#if (preg_match('#^speaker:\d+$#', $criteria_raw, $m)) {
192
-		#	mlog(", caching");
193
-		#	$results[$criteria_batch] = $data;
194
-		#}
195
-		#		unset($SEARCHENGINE);
196
-		$total_results = $data['info']['total_results'];
197
-		$queries++;
198
-		mlog(", hits ".$total_results.", time ".(getmicrotime()-$start)."\n");
199
-	} else {
200
-		mlog("  ACTION $active/$outof CACHE HIT : Using cached result for '$criteria_batch'\n");
201
-		$data = $results[$criteria_batch];
202
-	}
203
-
204
-	if (isset($data['rows']) && count($data['rows']) > 0) {
205
-		usort($data['rows'], 'sort_by_stuff'); # Sort results into order, by major, then date, then hpos
206
-		$o = array(); $major = 0; $count = array(); $total = 0;
207
-		$any_content = false;
208
-		foreach ($data['rows'] as $row) {
209
-			if ($major !== $row['major']) {
210
-				$count[$major] = $total; $total = 0;
211
-				$major = $row['major'];
212
-				$o[$major] = '';
213
-				$k = 3;
214
-			}
215
-			#mlog($row['major'] . " " . $row['gid'] ."\n");
216
-
217
-			# Due to database server failure and restoring from day
218
-			# old backup, 17th January 2012 is being newly
219
-			# inserted, but has already been alerted upon. So
220
-			# manually now stop anything from before 18th January
221
-			# 2012 from sending an email alert again.
222
-			if ($row['hdate'] < '2012-01-18') continue;
223
-
224
-			$q = $db->query('SELECT gid_from FROM gidredirect WHERE gid_to = :gid_to', array(
164
+        if ($q->rows() > 0) {
165
+            $user_id = $q->field(0, 'user_id');
166
+            $registered++;
167
+        } else {
168
+            $user_id = 0;
169
+            $unregistered++;
170
+        }
171
+        mlog("\nEMAIL: $email, uid $user_id; memory usage : ".memory_get_usage()."\n");
172
+    }
173
+
174
+    $data = null;
175
+    if (!isset($results[$criteria_batch])) {
176
+        mlog("  ALERT $active/$outof QUERY $queries : Xapian query '$criteria_batch'");
177
+        $start = getmicrotime();
178
+        $SEARCHENGINE = new SEARCHENGINE($criteria_batch);
179
+        #mlog("query_remade: " . $SEARCHENGINE->query_remade() . "\n");
180
+        $args = array(
181
+            's' => $criteria_raw, # Note: use raw here for URLs, whereas search engine has batch
182
+            'threshold' => $lastupdated, # Return everything added since last time this script was run
183
+            'o' => 'c',
184
+            'num' => 1000, // this is limited to 1000 in hansardlist.php anyway
185
+            'pop' => 1,
186
+            'e' => 1 # Don't escape ampersands
187
+        );
188
+        $data = $DEBATELIST->_get_data_by_search($args);
189
+        # add to cache (but only for speaker queries, which are commonly repeated)
190
+        # Don't cache, it's very quick, and we'd prefer low memory usage
191
+        #if (preg_match('#^speaker:\d+$#', $criteria_raw, $m)) {
192
+        #	mlog(", caching");
193
+        #	$results[$criteria_batch] = $data;
194
+        #}
195
+        #		unset($SEARCHENGINE);
196
+        $total_results = $data['info']['total_results'];
197
+        $queries++;
198
+        mlog(", hits ".$total_results.", time ".(getmicrotime()-$start)."\n");
199
+    } else {
200
+        mlog("  ACTION $active/$outof CACHE HIT : Using cached result for '$criteria_batch'\n");
201
+        $data = $results[$criteria_batch];
202
+    }
203
+
204
+    if (isset($data['rows']) && count($data['rows']) > 0) {
205
+        usort($data['rows'], 'sort_by_stuff'); # Sort results into order, by major, then date, then hpos
206
+        $o = array(); $major = 0; $count = array(); $total = 0;
207
+        $any_content = false;
208
+        foreach ($data['rows'] as $row) {
209
+            if ($major !== $row['major']) {
210
+                $count[$major] = $total; $total = 0;
211
+                $major = $row['major'];
212
+                $o[$major] = '';
213
+                $k = 3;
214
+            }
215
+            #mlog($row['major'] . " " . $row['gid'] ."\n");
216
+
217
+            # Due to database server failure and restoring from day
218
+            # old backup, 17th January 2012 is being newly
219
+            # inserted, but has already been alerted upon. So
220
+            # manually now stop anything from before 18th January
221
+            # 2012 from sending an email alert again.
222
+            if ($row['hdate'] < '2012-01-18') continue;
223
+
224
+            $q = $db->query('SELECT gid_from FROM gidredirect WHERE gid_to = :gid_to', array(
225 225
                 ':gid_to' => 'uk.org.publicwhip/' . $sects_gid[$major] . '/' . $row['gid']
226 226
                 ));
227
-			if ($q->rows() > 0) continue;
228
-			--$k;
229
-			if ($k>=0) {
230
-				$any_content = true;
231
-				$parentbody = text_html_to_email($row['parent']['body']);
232
-				$body = text_html_to_email($row['extract']);
233
-				if (isset($row['speaker']) && count($row['speaker'])) $body = $row['speaker']['name'] . ': ' . $body;
234
-
235
-				$body = wordwrap($body, 72);
236
-				$o[$major] .= $parentbody . ' (' . format_date($row['hdate'], SHORTDATEFORMAT) . ")\nhttps://www.theyworkforyou.com" . $row['listurl'] . "\n";
237
-				$o[$major] .= $body . "\n\n";
238
-			}
239
-			$total++;
240
-		}
241
-		$count[$major] = $total;
242
-
243
-		if ($any_content) {
244
-			# Add data to email_text
245
-			$desc = trim(html_entity_decode($data['searchdescription']));
246
-			$desc = trim(preg_replace('#\(?B\d+( OR B\d+)*\)?\s*#', '', $desc));
247
-			foreach ($o as $major => $body) {
248
-				if ($body) {
249
-					$heading = $desc . ' : ' . $count[$major] . ' ' . $sects[$major] . ($count[$major]!=1?'s':'');
250
-					$email_text .= "$heading\n".str_repeat('=',strlen($heading))."\n\n";
251
-					if ($count[$major] > 3) {
252
-						$email_text .= "There are more results than we have shown here. See more:\nhttps://www.theyworkforyou.com/search/?s=".urlencode($criteria_raw)."+section:".$sects_search[$major]."&o=d\n\n";
253
-					}
254
-					$email_text .= $body;
255
-				}
256
-			}
257
-		}
258
-	}
227
+            if ($q->rows() > 0) continue;
228
+            --$k;
229
+            if ($k>=0) {
230
+                $any_content = true;
231
+                $parentbody = text_html_to_email($row['parent']['body']);
232
+                $body = text_html_to_email($row['extract']);
233
+                if (isset($row['speaker']) && count($row['speaker'])) $body = $row['speaker']['name'] . ': ' . $body;
234
+
235
+                $body = wordwrap($body, 72);
236
+                $o[$major] .= $parentbody . ' (' . format_date($row['hdate'], SHORTDATEFORMAT) . ")\nhttps://www.theyworkforyou.com" . $row['listurl'] . "\n";
237
+                $o[$major] .= $body . "\n\n";
238
+            }
239
+            $total++;
240
+        }
241
+        $count[$major] = $total;
242
+
243
+        if ($any_content) {
244
+            # Add data to email_text
245
+            $desc = trim(html_entity_decode($data['searchdescription']));
246
+            $desc = trim(preg_replace('#\(?B\d+( OR B\d+)*\)?\s*#', '', $desc));
247
+            foreach ($o as $major => $body) {
248
+                if ($body) {
249
+                    $heading = $desc . ' : ' . $count[$major] . ' ' . $sects[$major] . ($count[$major]!=1?'s':'');
250
+                    $email_text .= "$heading\n".str_repeat('=',strlen($heading))."\n\n";
251
+                    if ($count[$major] > 3) {
252
+                        $email_text .= "There are more results than we have shown here. See more:\nhttps://www.theyworkforyou.com/search/?s=".urlencode($criteria_raw)."+section:".$sects_search[$major]."&o=d\n\n";
253
+                    }
254
+                    $email_text .= $body;
255
+                }
256
+            }
257
+        }
258
+    }
259 259
 }
260 260
 if ($email_text)
261
-	write_and_send_email($current, $email_text, $template);
261
+    write_and_send_email($current, $email_text, $template);
262 262
 
263 263
 mlog("\n");
264 264
 
265 265
 $sss = "Active alerts: $active\nEmail lookups: $registered registered, $unregistered unregistered\nQuery lookups: $queries\nSent emails: $sentemails\n";
266 266
 if ($globalsuccess) {
267
-	$sss .= 'Everything went swimmingly, in ';
267
+    $sss .= 'Everything went swimmingly, in ';
268 268
 } else {
269
-	$sss .= 'Something went wrong! Total time: ';
269
+    $sss .= 'Something went wrong! Total time: ';
270 270
 }
271 271
 $sss .= (getmicrotime()-$global_start)."\n\n";
272 272
 mlog($sss);
273 273
 if (!$nomail && !$onlyemail) {
274
-	$fp = fopen('alerts-lastsent', 'w');
275
-	fwrite($fp, time() . "\n");
276
-	fwrite($fp, $max_batch_id);
277
-	fclose($fp);
278
-	mail(ALERT_STATS_EMAILS, 'Email alert statistics', $sss, 'From: Email Alerts <[email protected]>');
274
+    $fp = fopen('alerts-lastsent', 'w');
275
+    fwrite($fp, time() . "\n");
276
+    fwrite($fp, $max_batch_id);
277
+    fclose($fp);
278
+    mail(ALERT_STATS_EMAILS, 'Email alert statistics', $sss, 'From: Email Alerts <[email protected]>');
279 279
 }
280 280
 mlog(date('r') . "\n");
281 281
 
@@ -303,30 +303,30 @@  discard block
 block discarded – undo
303 303
 }
304 304
 
305 305
 function write_and_send_email($current, $data, $template) {
306
-	global $globalsuccess, $sentemails, $nomail, $start_time;
307
-
308
-	$data .= '====================';
309
-	$sentemails++;
310
-	mlog("SEND $sentemails : Sending email to $current[email] ... ");
311
-	$d = array('to' => $current['email'], 'template' => $template);
312
-	$m = array(
313
-		'DATA' => $data,
314
-		'MANAGE' => 'https://www.theyworkforyou.com/D/' . $current['token'],
315
-	);
316
-	if (!$nomail) {
317
-		$success = send_template_email($d, $m, true, true); # true = "Precedence: bulk", want bounces
318
-		mlog("sent ... ");
319
-		# sleep if time between sending mails is less than a certain number of seconds on average
320
-		if (((time() - $start_time) / $sentemails) < 0.5 ) { # number of seconds per mail not to be quicker than
321
-			mlog("pausing ... ");
322
-			sleep(1);
323
-		}
324
-	} else {
325
-		mlog($data);
326
-		$success = 1;
327
-	}
328
-	mlog("done\n");
329
-	if (!$success) $globalsuccess = 0;
306
+    global $globalsuccess, $sentemails, $nomail, $start_time;
307
+
308
+    $data .= '====================';
309
+    $sentemails++;
310
+    mlog("SEND $sentemails : Sending email to $current[email] ... ");
311
+    $d = array('to' => $current['email'], 'template' => $template);
312
+    $m = array(
313
+        'DATA' => $data,
314
+        'MANAGE' => 'https://www.theyworkforyou.com/D/' . $current['token'],
315
+    );
316
+    if (!$nomail) {
317
+        $success = send_template_email($d, $m, true, true); # true = "Precedence: bulk", want bounces
318
+        mlog("sent ... ");
319
+        # sleep if time between sending mails is less than a certain number of seconds on average
320
+        if (((time() - $start_time) / $sentemails) < 0.5 ) { # number of seconds per mail not to be quicker than
321
+            mlog("pausing ... ");
322
+            sleep(1);
323
+        }
324
+    } else {
325
+        mlog($data);
326
+        $success = 1;
327
+    }
328
+    mlog("done\n");
329
+    if (!$success) $globalsuccess = 0;
330 330
 }
331 331
 
332 332
 function text_html_to_email($s) {
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -307,7 +307,7 @@
 block discarded – undo
307 307
 
308 308
 	$data .= '====================';
309 309
 	$sentemails++;
310
-	mlog("SEND $sentemails : Sending email to $current[email] ... ");
310
+	mlog("send $sentemails : Sending email to $current[email] ... ");
311 311
 	$d = array('to' => $current['email'], 'template' => $template);
312 312
 	$m = array(
313 313
 		'DATA' => $data,
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 # Construct query fragment to select search index batches which
38 38
 # have been made since last time we ran
39 39
 $batch_query_fragment = "";
40
-for ($i=$lastbatch + 1; $i <= $max_batch_id; $i++) {
40
+for ($i = $lastbatch + 1; $i <= $max_batch_id; $i++) {
41 41
 	$batch_query_fragment .= "batch:$i ";
42 42
 }
43 43
 $batch_query_fragment = trim($batch_query_fragment);
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 $fromflag = false;
56 56
 $toemail = '';
57 57
 $template = 'alert_mailout';
58
-for ($k=1; $k<$argc; $k++) {
58
+for ($k = 1; $k < $argc; $k++) {
59 59
 	if ($argv[$k] == '--nomail')
60 60
 		$nomail = true;
61 61
 	if (preg_match('#^--only=(.*)$#', $argv[$k], $m))
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 			$user_id = 0;
169 169
 			$unregistered++;
170 170
 		}
171
-		mlog("\nEMAIL: $email, uid $user_id; memory usage : ".memory_get_usage()."\n");
171
+		mlog("\nEMAIL: $email, uid $user_id; memory usage : " . memory_get_usage() . "\n");
172 172
 	}
173 173
 
174 174
 	$data = null;
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 		#		unset($SEARCHENGINE);
196 196
 		$total_results = $data['info']['total_results'];
197 197
 		$queries++;
198
-		mlog(", hits ".$total_results.", time ".(getmicrotime()-$start)."\n");
198
+		mlog(", hits " . $total_results . ", time " . (getmicrotime() - $start) . "\n");
199 199
 	} else {
200 200
 		mlog("  ACTION $active/$outof CACHE HIT : Using cached result for '$criteria_batch'\n");
201 201
 		$data = $results[$criteria_batch];
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
                 ));
227 227
 			if ($q->rows() > 0) continue;
228 228
 			--$k;
229
-			if ($k>=0) {
229
+			if ($k >= 0) {
230 230
 				$any_content = true;
231 231
 				$parentbody = text_html_to_email($row['parent']['body']);
232 232
 				$body = text_html_to_email($row['extract']);
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
 			$desc = trim(preg_replace('#\(?B\d+( OR B\d+)*\)?\s*#', '', $desc));
247 247
 			foreach ($o as $major => $body) {
248 248
 				if ($body) {
249
-					$heading = $desc . ' : ' . $count[$major] . ' ' . $sects[$major] . ($count[$major]!=1?'s':'');
250
-					$email_text .= "$heading\n".str_repeat('=',strlen($heading))."\n\n";
249
+					$heading = $desc . ' : ' . $count[$major] . ' ' . $sects[$major] . ($count[$major] != 1 ? 's' : '');
250
+					$email_text .= "$heading\n" . str_repeat('=', strlen($heading)) . "\n\n";
251 251
 					if ($count[$major] > 3) {
252
-						$email_text .= "There are more results than we have shown here. See more:\nhttps://www.theyworkforyou.com/search/?s=".urlencode($criteria_raw)."+section:".$sects_search[$major]."&o=d\n\n";
252
+						$email_text .= "There are more results than we have shown here. See more:\nhttps://www.theyworkforyou.com/search/?s=" . urlencode($criteria_raw) . "+section:" . $sects_search[$major] . "&o=d\n\n";
253 253
 					}
254 254
 					$email_text .= $body;
255 255
 				}
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 } else {
269 269
 	$sss .= 'Something went wrong! Total time: ';
270 270
 }
271
-$sss .= (getmicrotime()-$global_start)."\n\n";
271
+$sss .= (getmicrotime() - $global_start) . "\n\n";
272 272
 mlog($sss);
273 273
 if (!$nomail && !$onlyemail) {
274 274
 	$fp = fopen('alerts-lastsent', 'w');
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 		$success = send_template_email($d, $m, true, true); # true = "Precedence: bulk", want bounces
318 318
 		mlog("sent ... ");
319 319
 		# sleep if time between sending mails is less than a certain number of seconds on average
320
-		if (((time() - $start_time) / $sentemails) < 0.5 ) { # number of seconds per mail not to be quicker than
320
+		if (((time() - $start_time) / $sentemails) < 0.5) { # number of seconds per mail not to be quicker than
321 321
 			mlog("pausing ... ");
322 322
 			sleep(1);
323 323
 		}
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
     $s = preg_replace('#</?span[^>]*>#', '*', $s);
335 335
     $s = str_replace(
336 336
         array('&#163;', '&#8211;', '&#8212;', '&#8217;', '<br>'),
337
-        array("\xa3",   '-',       '-',       "'",       "\n"  ),
337
+        array("\xa3", '-', '-', "'", "\n"),
338 338
         $s
339 339
     );
340 340
     return $s;
Please login to merge, or discard this patch.
Braces   +96 added lines, -41 removed lines patch added patch discarded remove patch
@@ -23,15 +23,21 @@  discard block
 block discarded – undo
23 23
 
24 24
 # Last sent is timestamp of last alerts gone out.
25 25
 # Last batch is the search index batch number last alert went out to.
26
-if (is_file('alerts-lastsent'))
26
+if (is_file('alerts-lastsent')) {
27 27
 	$lastsent = file('alerts-lastsent');
28
-else
28
+}
29
+else {
29 30
 	$lastsent = array('', 0);
31
+}
30 32
 
31 33
 $lastupdated = trim($lastsent[0]);
32
-if (!$lastupdated) $lastupdated = strtotime('00:00 today');
34
+if (!$lastupdated) {
35
+    $lastupdated = strtotime('00:00 today');
36
+}
33 37
 $lastbatch = trim($lastsent[1]);
34
-if (!$lastbatch) $lastbatch = 0;
38
+if (!$lastbatch) {
39
+    $lastbatch = 0;
40
+}
35 41
 mlog("lastupdated: $lastupdated lastbatch: $lastbatch\n");
36 42
 
37 43
 # Construct query fragment to select search index batches which
@@ -56,14 +62,18 @@  discard block
 block discarded – undo
56 62
 $toemail = '';
57 63
 $template = 'alert_mailout';
58 64
 for ($k=1; $k<$argc; $k++) {
59
-	if ($argv[$k] == '--nomail')
60
-		$nomail = true;
61
-	if (preg_match('#^--only=(.*)$#', $argv[$k], $m))
62
-		$onlyemail = $m[1];
63
-	if (preg_match('#^--from=(.*)$#', $argv[$k], $m))
64
-		$fromemail = $m[1];
65
-	if (preg_match('#^--to=(.*)$#', $argv[$k], $m))
66
-		$toemail = $m[1];
65
+	if ($argv[$k] == '--nomail') {
66
+			$nomail = true;
67
+	}
68
+	if (preg_match('#^--only=(.*)$#', $argv[$k], $m)) {
69
+			$onlyemail = $m[1];
70
+	}
71
+	if (preg_match('#^--from=(.*)$#', $argv[$k], $m)) {
72
+			$fromemail = $m[1];
73
+	}
74
+	if (preg_match('#^--to=(.*)$#', $argv[$k], $m)) {
75
+			$toemail = $m[1];
76
+	}
67 77
 	if (preg_match('#^--template=(.*)$#', $argv[$k], $m)) {
68 78
 		$template = $m[1];
69 79
 		# Tee hee
@@ -71,10 +81,13 @@  discard block
 block discarded – undo
71 81
 	}
72 82
 }
73 83
 
74
-if (DEVSITE)
84
+if (DEVSITE) {
75 85
 	$nomail = true;
86
+}
76 87
 
77
-if ($nomail) mlog("NOT SENDING EMAIL\n");
88
+if ($nomail) {
89
+    mlog("NOT SENDING EMAIL\n");
90
+}
78 91
 if (($fromemail && $onlyemail) || ($toemail && $onlyemail)) {
79 92
 	mlog("Can't have both from/to and only!\n");
80 93
 	exit;
@@ -142,10 +155,18 @@  discard block
 block discarded – undo
142 155
 foreach ($alertdata as $alertitem) {
143 156
 	$active++;
144 157
 	$email = $alertitem['email'];
145
-	if ($onlyemail && $email != $onlyemail) continue;
146
-	if ($fromemail && strtolower($email) == $fromemail) $fromflag = true;
147
-	if ($fromemail && !$fromflag) continue;
148
-	if ($toemail && strtolower($email) >= $toemail) continue;
158
+	if ($onlyemail && $email != $onlyemail) {
159
+	    continue;
160
+	}
161
+	if ($fromemail && strtolower($email) == $fromemail) {
162
+	    $fromflag = true;
163
+	}
164
+	if ($fromemail && !$fromflag) {
165
+	    continue;
166
+	}
167
+	if ($toemail && strtolower($email) >= $toemail) {
168
+	    continue;
169
+	}
149 170
 	$criteria_raw = $alertitem['criteria'];
150 171
 	if (preg_match('#\bOR\b#', $criteria_raw)) {
151 172
 		$criteria_raw = "($criteria_raw)";
@@ -153,8 +174,9 @@  discard block
 block discarded – undo
153 174
 	$criteria_batch = $criteria_raw . " " . $batch_query_fragment;
154 175
 
155 176
 	if ($email != $current['email']) {
156
-		if ($email_text)
157
-			write_and_send_email($current, $email_text, $template);
177
+		if ($email_text) {
178
+					write_and_send_email($current, $email_text, $template);
179
+		}
158 180
 		$current['email'] = $email;
159 181
 		$current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken'];
160 182
 		$email_text = '';
@@ -164,7 +186,8 @@  discard block
 block discarded – undo
164 186
 		if ($q->rows() > 0) {
165 187
 			$user_id = $q->field(0, 'user_id');
166 188
 			$registered++;
167
-		} else {
189
+		}
190
+		else {
168 191
 			$user_id = 0;
169 192
 			$unregistered++;
170 193
 		}
@@ -196,7 +219,8 @@  discard block
 block discarded – undo
196 219
 		$total_results = $data['info']['total_results'];
197 220
 		$queries++;
198 221
 		mlog(", hits ".$total_results.", time ".(getmicrotime()-$start)."\n");
199
-	} else {
222
+	}
223
+	else {
200 224
 		mlog("  ACTION $active/$outof CACHE HIT : Using cached result for '$criteria_batch'\n");
201 225
 		$data = $results[$criteria_batch];
202 226
 	}
@@ -219,18 +243,24 @@  discard block
 block discarded – undo
219 243
 			# inserted, but has already been alerted upon. So
220 244
 			# manually now stop anything from before 18th January
221 245
 			# 2012 from sending an email alert again.
222
-			if ($row['hdate'] < '2012-01-18') continue;
246
+			if ($row['hdate'] < '2012-01-18') {
247
+			    continue;
248
+			}
223 249
 
224 250
 			$q = $db->query('SELECT gid_from FROM gidredirect WHERE gid_to = :gid_to', array(
225 251
                 ':gid_to' => 'uk.org.publicwhip/' . $sects_gid[$major] . '/' . $row['gid']
226 252
                 ));
227
-			if ($q->rows() > 0) continue;
253
+			if ($q->rows() > 0) {
254
+			    continue;
255
+			}
228 256
 			--$k;
229 257
 			if ($k>=0) {
230 258
 				$any_content = true;
231 259
 				$parentbody = text_html_to_email($row['parent']['body']);
232 260
 				$body = text_html_to_email($row['extract']);
233
-				if (isset($row['speaker']) && count($row['speaker'])) $body = $row['speaker']['name'] . ': ' . $body;
261
+				if (isset($row['speaker']) && count($row['speaker'])) {
262
+				    $body = $row['speaker']['name'] . ': ' . $body;
263
+				}
234 264
 
235 265
 				$body = wordwrap($body, 72);
236 266
 				$o[$major] .= $parentbody . ' (' . format_date($row['hdate'], SHORTDATEFORMAT) . ")\nhttps://www.theyworkforyou.com" . $row['listurl'] . "\n";
@@ -257,15 +287,17 @@  discard block
 block discarded – undo
257 287
 		}
258 288
 	}
259 289
 }
260
-if ($email_text)
290
+if ($email_text) {
261 291
 	write_and_send_email($current, $email_text, $template);
292
+}
262 293
 
263 294
 mlog("\n");
264 295
 
265 296
 $sss = "Active alerts: $active\nEmail lookups: $registered registered, $unregistered unregistered\nQuery lookups: $queries\nSent emails: $sentemails\n";
266 297
 if ($globalsuccess) {
267 298
 	$sss .= 'Everything went swimmingly, in ';
268
-} else {
299
+}
300
+else {
269 301
 	$sss .= 'Something went wrong! Total time: ';
270 302
 }
271 303
 $sss .= (getmicrotime()-$global_start)."\n\n";
@@ -281,24 +313,43 @@  discard block
 block discarded – undo
281 313
 
282 314
 function sort_by_stuff($a, $b) {
283 315
     # Always have future business first.
284
-    if ($a['major'] == 'F' && $b['major'] != 'F') return -1;
285
-    if ($b['major'] == 'F' && $a['major'] != 'F') return 1;
316
+    if ($a['major'] == 'F' && $b['major'] != 'F') {
317
+        return -1;
318
+    }
319
+    if ($b['major'] == 'F' && $a['major'] != 'F') {
320
+        return 1;
321
+    }
286 322
 
287 323
     # Otherwise sort firstly by major number (so Commons before NI before SP before Lords)
288
-    if ($a['major'] > $b['major']) return 1;
289
-    if ($a['major'] < $b['major']) return -1;
324
+    if ($a['major'] > $b['major']) {
325
+        return 1;
326
+    }
327
+    if ($a['major'] < $b['major']) {
328
+        return -1;
329
+    }
290 330
 
291 331
     # Then by date (most recent first for everything except future, which is the opposite)
292 332
     if ($a['major'] == 'F') {
293
-        if ($a['hdate'] > $b['hdate']) return 1;
294
-        if ($a['hdate'] < $b['hdate']) return -1;
295
-    } else {
296
-        if ($a['hdate'] < $b['hdate']) return 1;
297
-        if ($a['hdate'] > $b['hdate']) return -1;
333
+        if ($a['hdate'] > $b['hdate']) {
334
+            return 1;
335
+        }
336
+        if ($a['hdate'] < $b['hdate']) {
337
+            return -1;
338
+        }
339
+    }
340
+    else {
341
+        if ($a['hdate'] < $b['hdate']) {
342
+            return 1;
343
+        }
344
+        if ($a['hdate'] > $b['hdate']) {
345
+            return -1;
346
+        }
298 347
     }
299 348
 
300 349
     # Lastly by speech position within a debate.
301
-    if ($a['hpos'] == $b['hpos']) return 0;
350
+    if ($a['hpos'] == $b['hpos']) {
351
+        return 0;
352
+    }
302 353
     return ($a['hpos'] > $b['hpos']) ? 1 : -1;
303 354
 }
304 355
 
@@ -317,17 +368,21 @@  discard block
 block discarded – undo
317 368
 		$success = send_template_email($d, $m, true, true); # true = "Precedence: bulk", want bounces
318 369
 		mlog("sent ... ");
319 370
 		# sleep if time between sending mails is less than a certain number of seconds on average
320
-		if (((time() - $start_time) / $sentemails) < 0.5 ) { # number of seconds per mail not to be quicker than
371
+		if (((time() - $start_time) / $sentemails) < 0.5 ) {
372
+# number of seconds per mail not to be quicker than
321 373
 			mlog("pausing ... ");
322 374
 			sleep(1);
323 375
 		}
324
-	} else {
376
+	}
377
+	else {
325 378
 		mlog($data);
326 379
 		$success = 1;
327 380
 	}
328 381
 	mlog("done\n");
329
-	if (!$success) $globalsuccess = 0;
330
-}
382
+	if (!$success) {
383
+	    $globalsuccess = 0;
384
+	}
385
+	}
331 386
 
332 387
 function text_html_to_email($s) {
333 388
     $s = preg_replace('#</?(i|small)>#', '', $s);
Please login to merge, or discard this patch.
scripts/create_initial_topics.php 3 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -133,14 +133,14 @@
 block discarded – undo
133 133
 );
134 134
 
135 135
 foreach ($all_topics as $name => $topic) {
136
-  $existing = $topics->getTopic($name);
137
-  if ($existing) {
138
-      print "$name already exists\n";
139
-  } else {
140
-      $topic['slug'] = $name;
141
-      $topic['description'] = $topic['blurb'];
142
-      $topic = new MySociety\TheyWorkForYou\Topic($topic);
143
-      $topic->save();
144
-      print "created $name\n";
145
-  }
136
+    $existing = $topics->getTopic($name);
137
+    if ($existing) {
138
+        print "$name already exists\n";
139
+    } else {
140
+        $topic['slug'] = $name;
141
+        $topic['description'] = $topic['blurb'];
142
+        $topic = new MySociety\TheyWorkForYou\Topic($topic);
143
+        $topic->save();
144
+        print "created $name\n";
145
+    }
146 146
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 
3 3
 <?php
4 4
 
5
-include_once dirname(__FILE__) .'/../www/includes/easyparliament/init.php';
5
+include_once dirname(__FILE__) . '/../www/includes/easyparliament/init.php';
6 6
 
7 7
 $topics = new MySociety\TheyWorkForYou\Topics();
8 8
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -136,7 +136,8 @@
 block discarded – undo
136 136
   $existing = $topics->getTopic($name);
137 137
   if ($existing) {
138 138
       print "$name already exists\n";
139
-  } else {
139
+  }
140
+  else {
140 141
       $topic['slug'] = $name;
141 142
       $topic['description'] = $topic['blurb'];
142 143
       $topic = new MySociety\TheyWorkForYou\Topic($topic);
Please login to merge, or discard this patch.