@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | include_once '../../../includes/easyparliament/init.php'; |
4 | -include_once INCLUDESPATH . "easyparliament/member.php"; |
|
4 | +include_once INCLUDESPATH."easyparliament/member.php"; |
|
5 | 5 | $DATA->set_page_metadata($this_page, 'heading', 'MPs photo status on TheyWorkForYou'); |
6 | 6 | $PAGE->page_start(); |
7 | 7 | $PAGE->stripe_start(); |
@@ -9,17 +9,17 @@ discard block |
||
9 | 9 | $query = 'SELECT person_id, constituency, party |
10 | 10 | FROM member |
11 | 11 | WHERE house=1 AND left_house = (SELECT MAX(left_house) FROM member) '; |
12 | -$q = $db->query($query . "ORDER BY person_id"); |
|
12 | +$q = $db->query($query."ORDER BY person_id"); |
|
13 | 13 | $out = array('both'=>'', 'small'=>'', 'none'=>array()); |
14 | -for ($i=0; $i<$q->rows(); $i++) { |
|
14 | +for ($i = 0; $i < $q->rows(); $i++) { |
|
15 | 15 | $p_id = $q->field($i, 'person_id'); |
16 | 16 | list($dummy, $sz) = MySociety\TheyWorkForYou\Utility\Member::findMemberImage($p_id); |
17 | 17 | if ($sz == 'L') { |
18 | - $out['both'] .= $q->field($i, 'person_id') . ', '; |
|
18 | + $out['both'] .= $q->field($i, 'person_id').', '; |
|
19 | 19 | } elseif ($sz == 'S') { |
20 | - $out['small'] .= $q->field($i, 'person_id') . ', '; |
|
20 | + $out['small'] .= $q->field($i, 'person_id').', '; |
|
21 | 21 | } else { |
22 | - array_push($out['none'], '<li>' . $q->field($i, 'person_id') . ' (' . $q->field($i, 'party') . ')' . ', ' . $q->field($i, 'constituency')); |
|
22 | + array_push($out['none'], '<li>'.$q->field($i, 'person_id').' ('.$q->field($i, 'party').')'.', '.$q->field($i, 'constituency')); |
|
23 | 23 | } |
24 | 24 | } |
25 | 25 | print '<h3>Missing completely ('.count($out['none']).')</h3> <ul>'; |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | |
23 | 23 | include '../www/includes/easyparliament/init.php'; |
24 | -include_once INCLUDESPATH . 'easyparliament/member.php'; |
|
24 | +include_once INCLUDESPATH.'easyparliament/member.php'; |
|
25 | 25 | |
26 | 26 | $ARGV = $_SERVER['argv']; |
27 | 27 | $db = new ParlDB(); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | exit(1); |
34 | 34 | } |
35 | 35 | |
36 | -if ( !file_exists($csvfile) ) { |
|
36 | +if (!file_exists($csvfile)) { |
|
37 | 37 | print "$csvfile cannot be found\n"; |
38 | 38 | exit(1); |
39 | 39 | } |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | $count = 0; |
49 | -while ( ( $policy = fgetcsv($file) ) !== FALSE ) { |
|
50 | - if ( intval($policy[0]) ) { |
|
49 | +while (($policy = fgetcsv($file)) !== FALSE) { |
|
50 | + if (intval($policy[0])) { |
|
51 | 51 | $policy_id = $policy[0]; |
52 | 52 | $img_id = $policy[1] ? $policy[1] : $policy_id; |
53 | 53 | $title = $policy[2]; |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | ':policy_id' => $policy_id, |
65 | 65 | ':title' => $title, |
66 | 66 | ':description' => $description, |
67 | - ':image' => "/images/policies/" . $img_id . ".jpg", |
|
67 | + ':image' => "/images/policies/".$img_id.".jpg", |
|
68 | 68 | ':image_source' => $source, |
69 | 69 | ':image_attribution' => $attribution, |
70 | 70 | ':license_url' => $licence_url) |
71 | 71 | ); |
72 | - if ( $q->success() ) { |
|
72 | + if ($q->success()) { |
|
73 | 73 | $count += $q->affected_rows(); |
74 | 74 | } else { |
75 | 75 | print "failed to update data for $policy_id\n"; |
@@ -46,7 +46,7 @@ |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | $count = 0; |
49 | -while ( ( $policy = fgetcsv($file) ) !== FALSE ) { |
|
49 | +while ( ( $policy = fgetcsv($file) ) !== false ) { |
|
50 | 50 | if ( intval($policy[0]) ) { |
51 | 51 | $policy_id = $policy[0]; |
52 | 52 | $img_id = $policy[1] ? $policy[1] : $policy_id; |
@@ -16,39 +16,39 @@ discard block |
||
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 |
||
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"; |
@@ -5,9 +5,9 @@ discard block |
||
5 | 5 | # from Parliament, political party IP addresses etc. |
6 | 6 | # (the stuff for Wikipedia title links is elsewhere) |
7 | 7 | |
8 | -require_once dirname(__FILE__) . '/../conf/general'; |
|
8 | +require_once dirname(__FILE__).'/../conf/general'; |
|
9 | 9 | |
10 | -$dir = BASEDIR . '/wikipedia/cache/'; |
|
10 | +$dir = BASEDIR.'/wikipedia/cache/'; |
|
11 | 11 | |
12 | 12 | contributions('194.60.38.10'); # Parliament |
13 | 13 | contributions('194.203.158.97'); # Conservative |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | |
21 | 21 | $file = fetch("/w/index.php?title=Special:Contributions&limit=100&target=$ip"); |
22 | 22 | if (!$file) return; |
23 | - $fp = fopen($dir . $ip, 'w'); |
|
23 | + $fp = fopen($dir.$ip, 'w'); |
|
24 | 24 | fwrite($fp, $file['body']); |
25 | 25 | fclose($fp); |
26 | 26 | preg_match_all('#<li>(.*?) \(<a[^>]*>hist</a>\) \(<a href="(.*?title=(.*?)&.*?oldid=(.*?))"[^>]*>diff</a>\) <a[^>]*>(.*?)</a> .*?</li>#', $file['body'], $m, PREG_SET_ORDER); |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | $bits = explode('/', $filename); |
33 | 33 | array_pop($bits); |
34 | 34 | foreach ($bits as $bit) { |
35 | - @mkdir($path . $bit); |
|
35 | + @mkdir($path.$bit); |
|
36 | 36 | $path .= "$bit/"; |
37 | 37 | } |
38 | 38 | } |
39 | - $cache = $dir . $filename; |
|
39 | + $cache = $dir.$filename; |
|
40 | 40 | if (!is_file($cache)) { |
41 | 41 | # print " - fetching"; |
42 | 42 | $file = fetch(html_entity_decode($row[2])); |
@@ -19,7 +19,9 @@ discard block |
||
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 |
||
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']); |
@@ -59,7 +59,7 @@ |
||
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"; |
@@ -22,26 +22,26 @@ discard block |
||
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 |
||
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 |
||
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); |
@@ -8,9 +8,9 @@ discard block |
||
8 | 8 | print $message; |
9 | 9 | } |
10 | 10 | |
11 | -include_once dirname(__FILE__) . '/../www/includes/easyparliament/init.php'; |
|
11 | +include_once dirname(__FILE__).'/../www/includes/easyparliament/init.php'; |
|
12 | 12 | ini_set('memory_limit', -1); |
13 | -include_once INCLUDESPATH . 'easyparliament/member.php'; |
|
13 | +include_once INCLUDESPATH.'easyparliament/member.php'; |
|
14 | 14 | |
15 | 15 | $global_start = getmicrotime(); |
16 | 16 | $db = new ParlDB; |
@@ -21,7 +21,7 @@ discard block |
||
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 |
||
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 |
||
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']) { |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | write_and_send_email($current, $email_text, $change_text, $template); |
111 | 111 | } |
112 | 112 | $current['email'] = $email; |
113 | - $current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken']; |
|
113 | + $current['token'] = $alertitem['alert_id'].'-'.$alertitem['registrationtoken']; |
|
114 | 114 | $email_text = array(); |
115 | 115 | $change_text = array(); |
116 | 116 | $q = $db->query('SELECT user_id FROM users WHERE email = :email', array( |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | |
128 | 128 | $lh = $member->left_house(); |
129 | 129 | $lh = array_shift($lh); |
130 | - $text = '* ' . $member->full_name(); |
|
130 | + $text = '* '.$member->full_name(); |
|
131 | 131 | if (!in_array($text, $email_text)) { |
132 | 132 | $email_text[] = $text; |
133 | 133 | |
134 | - $change = '* ' . $member->full_name() . ': https://' . DOMAIN . '/C/' . $alertitem['registrationtoken']; |
|
134 | + $change = '* '.$member->full_name().': https://'.DOMAIN.'/C/'.$alertitem['registrationtoken']; |
|
135 | 135 | $change_text[] = $change; |
136 | 136 | } |
137 | 137 | } |
@@ -147,9 +147,9 @@ discard block |
||
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 | -mlog(date('r') . "\n"); |
|
152 | +mlog(date('r')."\n"); |
|
153 | 153 | |
154 | 154 | function write_and_send_email($current, $data, $change, $template) { |
155 | 155 | global $globalsuccess, $sentemails, $nomail, $start_time; |
@@ -160,18 +160,18 @@ discard block |
||
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 | } |
@@ -22,23 +22,30 @@ discard block |
||
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 |
||
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 |
||
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)); |
@@ -102,8 +123,12 @@ discard block |
||
102 | 123 | } |
103 | 124 | |
104 | 125 | // 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; |
|
126 | + if ( $cons_member->person_id == $member->person_id ) { |
|
127 | + continue; |
|
128 | + } |
|
129 | + if (!$cons_member->current_member_anywhere()) { |
|
130 | + continue; |
|
131 | + } |
|
107 | 132 | |
108 | 133 | if ($email != $current['email']) { |
109 | 134 | if ($email_text && $change_text) { |
@@ -155,7 +155,7 @@ |
||
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), |
@@ -15,17 +15,17 @@ discard block |
||
15 | 15 | } |
16 | 16 | |
17 | 17 | $date = substr($from, 0, 10); |
18 | -$from = 'uk.org.publicwhip/debate/' . $from; |
|
19 | -if ($to) $to = 'uk.org.publicwhip/debate/' . $to; |
|
18 | +$from = 'uk.org.publicwhip/debate/'.$from; |
|
19 | +if ($to) $to = 'uk.org.publicwhip/debate/'.$to; |
|
20 | 20 | |
21 | -$q = $db->query('select hpos from hansard where gid="' . $from . '"'); |
|
21 | +$q = $db->query('select hpos from hansard where gid="'.$from.'"'); |
|
22 | 22 | $hpos_from = $q->field(0, 'hpos'); |
23 | 23 | if (!$hpos_from) { |
24 | 24 | print "No hpos for from gid!\n"; exit; |
25 | 25 | } |
26 | 26 | |
27 | 27 | if ($to) { |
28 | - $q = $db->query('select hpos from hansard where gid="' . $to . '"'); |
|
28 | + $q = $db->query('select hpos from hansard where gid="'.$to.'"'); |
|
29 | 29 | $hpos_to = $q->field(0, 'hpos'); |
30 | 30 | if (!$hpos_to) { |
31 | 31 | print "No hpos for to gid!\n"; exit; |
@@ -39,4 +39,4 @@ discard block |
||
39 | 39 | |
40 | 40 | print "Executing $query...\n"; |
41 | 41 | $q = $db->query($query); |
42 | -print ' ' . $q->affected_rows() . " rows have been marked as missing\n"; |
|
42 | +print ' '.$q->affected_rows()." rows have been marked as missing\n"; |
@@ -16,7 +16,9 @@ discard block |
||
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 |
||
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); |
@@ -37,6 +37,6 @@ |
||
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"; |
@@ -6,7 +6,7 @@ discard block |
||
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 |
||
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 | } |
@@ -19,9 +19,9 @@ |
||
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 | - $name = $q->field($i, 'first_name') . ' ' . $q->field($i, 'last_name'); |
|
24 | + $name = $q->field($i, 'first_name').' '.$q->field($i, 'last_name'); |
|
25 | 25 | $con = $q->field($i, 'constituency'); |
26 | 26 | $wrans = $q->field($i, 'wrans'); |
27 | 27 | $yes = $q->field($i, 'yes'); |
@@ -10,18 +10,18 @@ |
||
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 |
@@ -9,7 +9,7 @@ discard block |
||
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 |
||
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 | } |
@@ -16,8 +16,9 @@ |
||
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"; |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * Description: Summary of the day's API usage |
6 | 6 | */ |
7 | 7 | |
8 | -include_once dirname(__FILE__) . '/../www/includes/easyparliament/init.php'; |
|
8 | +include_once dirname(__FILE__).'/../www/includes/easyparliament/init.php'; |
|
9 | 9 | |
10 | 10 | $db = new ParlDB; |
11 | 11 | $q = $db->query('SELECT |
@@ -22,7 +22,7 @@ discard block |
||
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 |
||
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] <$row[email]> |
51 | 51 | <br>$row[api_key], created $row[created], first use $first$comm, total calls $total |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | if (!$out) exit; |
56 | 56 | |
57 | 57 | $headers = |
58 | - "From: TheyWorkForYou <" . CONTACTEMAIL . ">\r\n" . |
|
59 | - "Content-Type: text/html; charset=utf-8\r\n" . |
|
60 | - "MIME-Version: 1.0\r\n" . |
|
58 | + "From: TheyWorkForYou <".CONTACTEMAIL.">\r\n". |
|
59 | + "Content-Type: text/html; charset=utf-8\r\n". |
|
60 | + "MIME-Version: 1.0\r\n". |
|
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 |
@@ -52,7 +52,9 @@ |
||
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" . |
@@ -1,22 +1,22 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -include_once dirname(__FILE__) . '/../www/includes/easyparliament/init.php'; |
|
3 | +include_once dirname(__FILE__).'/../www/includes/easyparliament/init.php'; |
|
4 | 4 | |
5 | 5 | $parties = MySociety\TheyWorkForYou\Party::getParties(); |
6 | 6 | $policies = new MySociety\TheyWorkForYou\Policies; |
7 | 7 | |
8 | 8 | $party_count = 0; |
9 | -foreach ( $parties as $party ) { |
|
9 | +foreach ($parties as $party) { |
|
10 | 10 | $party = new MySociety\TheyWorkForYou\Party($party); |
11 | 11 | |
12 | 12 | $positions = $party->calculateAllPolicyPositions($policies); |
13 | 13 | |
14 | - if ( count( $positions ) ) { |
|
14 | + if (count($positions)) { |
|
15 | 15 | $party_count++; |
16 | 16 | } |
17 | 17 | |
18 | - foreach ( $positions as $position ) { |
|
19 | - $party->cache_position( $position ); |
|
18 | + foreach ($positions as $position) { |
|
19 | + $party->cache_position($position); |
|
20 | 20 | } |
21 | 21 | } |
22 | 22 |