@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | // $Id: dbtypes.php,v 1.8 2009-04-28 13:13:04 matthew Exp $ |
4 | 4 | |
5 | 5 | // The type field in the epobject database table |
6 | -define ('EPTYPE_HANSARD', 1); |
|
7 | -define ('EPTYPE_GLOSSARY', 2); |
|
6 | +define('EPTYPE_HANSARD', 1); |
|
7 | +define('EPTYPE_GLOSSARY', 2); |
|
8 | 8 | |
9 | 9 | // The major field in the hansard database table |
10 | 10 | $hansardmajors = array( |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | ); |
122 | 122 | $hansardmajors[104] = $hansardmajors[4]; |
123 | 123 | |
124 | -$parties = array ( |
|
124 | +$parties = array( |
|
125 | 125 | 'Bp' => 'Bishop', |
126 | 126 | 'Con' => 'Conservative', |
127 | 127 | 'CWM' => 'Deputy Speaker', |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | */ |
164 | 164 | |
165 | 165 | // Constants for various house types |
166 | -define ('HOUSE_TYPE_ROYAL', 0); |
|
167 | -define ('HOUSE_TYPE_COMMONS', 1); |
|
168 | -define ('HOUSE_TYPE_LORDS', 2); |
|
169 | -define ('HOUSE_TYPE_NI', 3); |
|
170 | -define ('HOUSE_TYPE_SCOTLAND', 4); |
|
171 | -define ('HOUSE_TYPE_WALES', 5); |
|
172 | -define ('HOUSE_TYPE_LONDON_ASSEMBLY', 6); |
|
166 | +define('HOUSE_TYPE_ROYAL', 0); |
|
167 | +define('HOUSE_TYPE_COMMONS', 1); |
|
168 | +define('HOUSE_TYPE_LORDS', 2); |
|
169 | +define('HOUSE_TYPE_NI', 3); |
|
170 | +define('HOUSE_TYPE_SCOTLAND', 4); |
|
171 | +define('HOUSE_TYPE_WALES', 5); |
|
172 | +define('HOUSE_TYPE_LONDON_ASSEMBLY', 6); |
@@ -49,7 +49,9 @@ discard block |
||
49 | 49 | |
50 | 50 | // If we can show this header, then, er, show it. |
51 | 51 | if ( in_array($header, $allowed_headers) || $debug_level >= 4) { |
52 | - if (is_array($text)) $text = call_user_func($text); |
|
52 | + if (is_array($text)) { |
|
53 | + $text = call_user_func($text); |
|
54 | + } |
|
53 | 55 | print "<p><span style=\"color:#039;\"><strong>$header</strong></span> $text</p>\n"; |
54 | 56 | } |
55 | 57 | } |
@@ -65,7 +67,9 @@ discard block |
||
65 | 67 | global $PAGE; |
66 | 68 | |
67 | 69 | # Ignore errors we've asked to ignore |
68 | - if (error_reporting()==0) return; |
|
70 | + if (error_reporting()==0) { |
|
71 | + return; |
|
72 | + } |
|
69 | 73 | |
70 | 74 | // define an assoc array of error string |
71 | 75 | // in reality the only entries we should |
@@ -209,19 +213,29 @@ discard block |
||
209 | 213 | array_shift($traceArr); |
210 | 214 | $tabs = sizeof($traceArr)-1; |
211 | 215 | foreach ($traceArr as $arr) { |
212 | - for ($i=0; $i < $tabs; $i++) $s .= ' '; |
|
216 | + for ($i=0; $i < $tabs; $i++) { |
|
217 | + $s .= ' '; |
|
218 | + } |
|
213 | 219 | $tabs -= 1; |
214 | - if (isset($arr['class'])) $s .= $arr['class'].'.'; |
|
220 | + if (isset($arr['class'])) { |
|
221 | + $s .= $arr['class'].'.'; |
|
222 | + } |
|
215 | 223 | $args = array(); |
216 | - if (isset($arr['args'])) foreach ($arr['args'] as $v) { |
|
224 | + if (isset($arr['args'])) { |
|
225 | + foreach ($arr['args'] as $v) { |
|
217 | 226 | if (is_null($v)) $args[] = 'null'; |
218 | - elseif (is_array($v)) $args[] = 'Array['.sizeof($v).']'; |
|
219 | - elseif (is_object($v)) $args[] = 'Object:'.get_class($v); |
|
220 | - elseif (is_bool($v)) $args[] = $v ? 'true' : 'false'; |
|
221 | - else { |
|
227 | + } elseif (is_array($v)) { |
|
228 | + $args[] = 'Array['.sizeof($v).']'; |
|
229 | + } elseif (is_object($v)) { |
|
230 | + $args[] = 'Object:'.get_class($v); |
|
231 | + } elseif (is_bool($v)) { |
|
232 | + $args[] = $v ? 'true' : 'false'; |
|
233 | + } else { |
|
222 | 234 | $v = (string) @$v; |
223 | 235 | $str = _htmlspecialchars(substr($v,0,$MAXSTRLEN)); |
224 | - if (strlen($v) > $MAXSTRLEN) $str .= '...'; |
|
236 | + if (strlen($v) > $MAXSTRLEN) { |
|
237 | + $str .= '...'; |
|
238 | + } |
|
225 | 239 | $args[] = $str; |
226 | 240 | } |
227 | 241 | } |
@@ -232,7 +246,9 @@ discard block |
||
232 | 246 | // $arr['line'],$arr['file'],$arr['file']); |
233 | 247 | $s .= "\n"; |
234 | 248 | } |
235 | - if ($print) print $s; |
|
249 | + if ($print) { |
|
250 | + print $s; |
|
251 | + } |
|
236 | 252 | } |
237 | 253 | |
238 | 254 | return $s; |
@@ -326,7 +342,8 @@ discard block |
||
326 | 342 | |
327 | 343 | if (preg_match("/^(\d\d\d\d)-(\d\d?)-(\d\d?)$/", $date, $matches)) { |
328 | 344 | list($string, $year, $month, $day) = $matches; |
329 | - if ($year < 1902) { # gmdate fns only go back to Dec. 1901 |
|
345 | + if ($year < 1902) { |
|
346 | +# gmdate fns only go back to Dec. 1901 |
|
330 | 347 | if ($format == SHORTDATEFORMAT) { |
331 | 348 | return ($day+0) . ' ' . $format_date_months_short[$month+0] . " $year"; |
332 | 349 | } else { |
@@ -755,7 +772,9 @@ discard block |
||
755 | 772 | // easily to all the emails we send out from the site. |
756 | 773 | // eg, we might want to add a .sig to everything here... |
757 | 774 | |
758 | - if (!$from) $from = CONTACTEMAIL; |
|
775 | + if (!$from) { |
|
776 | + $from = CONTACTEMAIL; |
|
777 | + } |
|
759 | 778 | |
760 | 779 | $headers = |
761 | 780 | "From: TheyWorkForYou <$from>\r\n" . |
@@ -847,17 +866,21 @@ discard block |
||
847 | 866 | $rank = $rank + 0; |
848 | 867 | |
849 | 868 | # 11th, 12th, 13th use "th" not "st", "nd", "rd" |
850 | - if (floor(($rank % 100) / 10) == 1) |
|
851 | - return $rank . "th"; |
|
869 | + if (floor(($rank % 100) / 10) == 1) { |
|
870 | + return $rank . "th"; |
|
871 | + } |
|
852 | 872 | # 1st |
853 | - if ($rank % 10 == 1) |
|
854 | - return $rank . "st"; |
|
873 | + if ($rank % 10 == 1) { |
|
874 | + return $rank . "st"; |
|
875 | + } |
|
855 | 876 | # 2nd |
856 | - if ($rank % 10 == 2) |
|
857 | - return $rank . "nd"; |
|
877 | + if ($rank % 10 == 2) { |
|
878 | + return $rank . "nd"; |
|
879 | + } |
|
858 | 880 | # 3rd |
859 | - if ($rank % 10 == 3) |
|
860 | - return $rank . "rd"; |
|
881 | + if ($rank % 10 == 3) { |
|
882 | + return $rank . "rd"; |
|
883 | + } |
|
861 | 884 | # Everything else use th |
862 | 885 | |
863 | 886 | return $rank . "th"; |
@@ -865,8 +888,9 @@ discard block |
||
865 | 888 | |
866 | 889 | function make_plural($word, $number) |
867 | 890 | { |
868 | - if ($number == 1) |
|
869 | - return $word; |
|
891 | + if ($number == 1) { |
|
892 | + return $word; |
|
893 | + } |
|
870 | 894 | return $word . "s"; |
871 | 895 | } |
872 | 896 | |
@@ -884,8 +908,7 @@ discard block |
||
884 | 908 | function make_member_url($name, $const = '', $house = HOUSE_TYPE_COMMONS, $pid = NULL) { |
885 | 909 | |
886 | 910 | // Case for Elizabeth II |
887 | - if ($house == HOUSE_TYPE_ROYAL) |
|
888 | - { |
|
911 | + if ($house == HOUSE_TYPE_ROYAL) { |
|
889 | 912 | return 'elizabeth_the_second'; |
890 | 913 | } |
891 | 914 | |
@@ -897,8 +920,7 @@ discard block |
||
897 | 920 | $out = ''; |
898 | 921 | |
899 | 922 | // Insert the Person ID if known. |
900 | - if ($pid !== NULL) |
|
901 | - { |
|
923 | + if ($pid !== NULL) { |
|
902 | 924 | $out .= $pid . '/'; |
903 | 925 | } |
904 | 926 | |
@@ -906,8 +928,7 @@ discard block |
||
906 | 928 | $out .= urlencode(str_replace($s2, $r, str_replace($s, $r, $name))); |
907 | 929 | |
908 | 930 | // If there is a constituency, inject that too |
909 | - if ($const && $house == HOUSE_TYPE_COMMONS) |
|
910 | - { |
|
931 | + if ($const && $house == HOUSE_TYPE_COMMONS) { |
|
911 | 932 | $out .= '/' . urlencode(str_replace($s2, $r, str_replace($s, $r, strtolower($const)))); |
912 | 933 | } |
913 | 934 | |
@@ -920,10 +941,16 @@ discard block |
||
920 | 941 | |
921 | 942 | case HOUSE_TYPE_LORDS: |
922 | 943 | $s = ''; |
923 | - if (!$family_name) $s = 'the '; |
|
944 | + if (!$family_name) { |
|
945 | + $s = 'the '; |
|
946 | + } |
|
924 | 947 | $s .= $title; |
925 | - if ($family_name) $s .= ' ' . $family_name; |
|
926 | - if ($lordofname) $s .= ' of ' . $lordofname; |
|
948 | + if ($family_name) { |
|
949 | + $s .= ' ' . $family_name; |
|
950 | + } |
|
951 | + if ($lordofname) { |
|
952 | + $s .= ' of ' . $lordofname; |
|
953 | + } |
|
927 | 954 | return $s; |
928 | 955 | |
929 | 956 | case HOUSE_TYPE_ROYAL: |
@@ -942,14 +969,18 @@ discard block |
||
942 | 969 | } |
943 | 970 | |
944 | 971 | function by_peer_name($a, $b) { |
945 | - if (!$a['family_name'] && !$b['family_name']) |
|
946 | - return strcmp($a['lordofname'], $b['lordofname']); |
|
947 | - if (!$a['family_name']) |
|
948 | - return strcmp($a['lordofname'], $b['family_name']); |
|
949 | - if (!$b['family_name']) |
|
950 | - return strcmp($a['family_name'], $b['lordofname']); |
|
951 | - if (strcmp($a['family_name'], $b['family_name'])) |
|
952 | - return strcmp($a['family_name'], $b['family_name']); |
|
972 | + if (!$a['family_name'] && !$b['family_name']) { |
|
973 | + return strcmp($a['lordofname'], $b['lordofname']); |
|
974 | + } |
|
975 | + if (!$a['family_name']) { |
|
976 | + return strcmp($a['lordofname'], $b['family_name']); |
|
977 | + } |
|
978 | + if (!$b['family_name']) { |
|
979 | + return strcmp($a['family_name'], $b['lordofname']); |
|
980 | + } |
|
981 | + if (strcmp($a['family_name'], $b['family_name'])) { |
|
982 | + return strcmp($a['family_name'], $b['family_name']); |
|
983 | + } |
|
953 | 984 | return strcmp($a['lordofname'], $b['lordofname']); |
954 | 985 | } |
955 | 986 | |
@@ -976,12 +1007,17 @@ discard block |
||
976 | 1007 | 'Lords in Waiting (HM Household)' => 'Government Whip', |
977 | 1008 | 'Baronesses in Waiting, HM Household' => 'Government Whip', |
978 | 1009 | ); |
979 | - if ($pos) { # Government post, or Chairman of Select Committee |
|
1010 | + if ($pos) { |
|
1011 | +# Government post, or Chairman of Select Committee |
|
980 | 1012 | $pretty = $pos; |
981 | - if ($dept && $dept != 'No Department') $pretty .= ", $dept"; |
|
982 | - if (array_key_exists($pretty, $lookup)) |
|
983 | - $pretty = $lookup[$pretty]; |
|
984 | - } else { # Member of Select Committee |
|
1013 | + if ($dept && $dept != 'No Department') { |
|
1014 | + $pretty .= ", $dept"; |
|
1015 | + } |
|
1016 | + if (array_key_exists($pretty, $lookup)) { |
|
1017 | + $pretty = $lookup[$pretty]; |
|
1018 | + } |
|
1019 | + } else { |
|
1020 | +# Member of Select Committee |
|
985 | 1021 | $pretty = "Member, $dept"; |
986 | 1022 | } |
987 | 1023 | return $pretty; |
@@ -999,13 +1035,16 @@ discard block |
||
999 | 1035 | } |
1000 | 1036 | |
1001 | 1037 | // single date? |
1002 | - if (isset($data['date'])) $one_date = true; |
|
1038 | + if (isset($data['date'])) { |
|
1039 | + $one_date = true; |
|
1040 | + } |
|
1003 | 1041 | |
1004 | 1042 | // remove empty entries, so they don't produce errors |
1005 | 1043 | foreach (array_keys($hansardmajors) as $major) { |
1006 | 1044 | if (array_key_exists($major, $data)) { |
1007 | - if (count($data[$major]) == 0) |
|
1008 | - unset($data[$major]); |
|
1045 | + if (count($data[$major]) == 0) { |
|
1046 | + unset($data[$major]); |
|
1047 | + } |
|
1009 | 1048 | } |
1010 | 1049 | } |
1011 | 1050 | |
@@ -1014,22 +1053,29 @@ discard block |
||
1014 | 1053 | if (!$one_date) { |
1015 | 1054 | $todaystime = gmmktime(0, 0, 0, date('m'), date('d'), date('Y')); |
1016 | 1055 | foreach ($data as $major => $array) { |
1017 | - if (!in_array('timestamp', $array)) $daytext[$major] = "The most recent "; |
|
1018 | - elseif ($todaystime - $array['timestamp'] == 86400) $daytext[$major] = "Yesterday’s"; |
|
1019 | - elseif ($todaystime - $array['timestamp'] <= (6 * 86400)) $daytext[$major] = gmdate('l', $array['timestamp']) . "’s"; |
|
1020 | - else $daytext[$major] = "The most recent "; |
|
1056 | + if (!in_array('timestamp', $array)) { |
|
1057 | + $daytext[$major] = "The most recent "; |
|
1058 | + } elseif ($todaystime - $array['timestamp'] == 86400) { |
|
1059 | + $daytext[$major] = "Yesterday’s"; |
|
1060 | + } elseif ($todaystime - $array['timestamp'] <= (6 * 86400)) { |
|
1061 | + $daytext[$major] = gmdate('l', $array['timestamp']) . "’s"; |
|
1062 | + } else { |
|
1063 | + $daytext[$major] = "The most recent "; |
|
1064 | + } |
|
1021 | 1065 | } |
1022 | 1066 | } |
1023 | 1067 | |
1024 | 1068 | //build html |
1025 | 1069 | foreach ($printed_majors as $p_major) { |
1026 | - if (!array_key_exists($p_major, $data)) |
|
1027 | - continue; |
|
1070 | + if (!array_key_exists($p_major, $data)) { |
|
1071 | + continue; |
|
1072 | + } |
|
1028 | 1073 | |
1029 | - if ($one_date) |
|
1030 | - $date = $data['date']; |
|
1031 | - else |
|
1032 | - $date = $data[$p_major]['hdate']; |
|
1074 | + if ($one_date) { |
|
1075 | + $date = $data['date']; |
|
1076 | + } else { |
|
1077 | + $date = $data[$p_major]['hdate']; |
|
1078 | + } |
|
1033 | 1079 | $q = $db->query('SELECT section_id, body, gid |
1034 | 1080 | FROM hansard, epobject |
1035 | 1081 | WHERE hansard.epobject_id = epobject.epobject_id ' |
@@ -1081,14 +1127,16 @@ discard block |
||
1081 | 1127 | } |
1082 | 1128 | |
1083 | 1129 | $return .= '<a href="'; |
1084 | - if (isset($data[$major]['listurl'])) |
|
1085 | - $return .= $data[$major]['listurl']; |
|
1086 | - else { |
|
1130 | + if (isset($data[$major]['listurl'])) { |
|
1131 | + $return .= $data[$major]['listurl']; |
|
1132 | + } else { |
|
1087 | 1133 | $LISTURL->reset(); |
1088 | 1134 | $return .= $LISTURL->generate(); |
1089 | 1135 | } |
1090 | 1136 | $return .= '">' . $hansardmajors[$major]['title'] . '</a>'; |
1091 | - if (isset($daytext[$major])) $return; |
|
1137 | + if (isset($daytext[$major])) { |
|
1138 | + $return; |
|
1139 | + } |
|
1092 | 1140 | $return .= '</h4>'; |
1093 | 1141 | |
1094 | 1142 | return $return; |
@@ -1096,20 +1144,21 @@ discard block |
||
1096 | 1144 | |
1097 | 1145 | function score_to_strongly($dmpscore) { |
1098 | 1146 | $dmpdesc = "unknown about"; |
1099 | - if ($dmpscore > 0.95 && $dmpscore <= 1.0) |
|
1100 | - $dmpdesc = "consistently voted against"; |
|
1101 | - elseif ($dmpscore > 0.85) |
|
1102 | - $dmpdesc = "almost always voted against"; |
|
1103 | - elseif ($dmpscore > 0.6) |
|
1104 | - $dmpdesc = "generally voted against"; |
|
1105 | - elseif ($dmpscore > 0.4) |
|
1106 | - $dmpdesc = "voted a mixture of for and against"; |
|
1107 | - elseif ($dmpscore > 0.15) |
|
1108 | - $dmpdesc = "generally voted for"; |
|
1109 | - elseif ($dmpscore > 0.05) |
|
1110 | - $dmpdesc = "almost always voted for"; |
|
1111 | - elseif ($dmpscore >= 0.0) |
|
1112 | - $dmpdesc = "consistently voted for"; |
|
1147 | + if ($dmpscore > 0.95 && $dmpscore <= 1.0) { |
|
1148 | + $dmpdesc = "consistently voted against"; |
|
1149 | + } elseif ($dmpscore > 0.85) { |
|
1150 | + $dmpdesc = "almost always voted against"; |
|
1151 | + } elseif ($dmpscore > 0.6) { |
|
1152 | + $dmpdesc = "generally voted against"; |
|
1153 | + } elseif ($dmpscore > 0.4) { |
|
1154 | + $dmpdesc = "voted a mixture of for and against"; |
|
1155 | + } elseif ($dmpscore > 0.15) { |
|
1156 | + $dmpdesc = "generally voted for"; |
|
1157 | + } elseif ($dmpscore > 0.05) { |
|
1158 | + $dmpdesc = "almost always voted for"; |
|
1159 | + } elseif ($dmpscore >= 0.0) { |
|
1160 | + $dmpdesc = "consistently voted for"; |
|
1161 | + } |
|
1113 | 1162 | return $dmpdesc; |
1114 | 1163 | } |
1115 | 1164 |