@@ -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', |
@@ -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 | |
@@ -919,10 +940,16 @@ discard block |
||
| 919 | 940 | switch ($house) { |
| 920 | 941 | case HOUSE_TYPE_LORDS: |
| 921 | 942 | $s = ''; |
| 922 | - if (!$family_name) $s = 'the '; |
|
| 943 | + if (!$family_name) { |
|
| 944 | + $s = 'the '; |
|
| 945 | + } |
|
| 923 | 946 | $s .= $title; |
| 924 | - if ($family_name) $s .= ' ' . $family_name; |
|
| 925 | - if ($lordofname) $s .= ' of ' . $lordofname; |
|
| 947 | + if ($family_name) { |
|
| 948 | + $s .= ' ' . $family_name; |
|
| 949 | + } |
|
| 950 | + if ($lordofname) { |
|
| 951 | + $s .= ' of ' . $lordofname; |
|
| 952 | + } |
|
| 926 | 953 | return $s; |
| 927 | 954 | |
| 928 | 955 | case HOUSE_TYPE_ROYAL: |
@@ -940,14 +967,18 @@ discard block |
||
| 940 | 967 | } |
| 941 | 968 | |
| 942 | 969 | function by_peer_name($a, $b) { |
| 943 | - if (!$a['family_name'] && !$b['family_name']) |
|
| 944 | - return strcmp($a['lordofname'], $b['lordofname']); |
|
| 945 | - if (!$a['family_name']) |
|
| 946 | - return strcmp($a['lordofname'], $b['family_name']); |
|
| 947 | - if (!$b['family_name']) |
|
| 948 | - return strcmp($a['family_name'], $b['lordofname']); |
|
| 949 | - if (strcmp($a['family_name'], $b['family_name'])) |
|
| 950 | - return strcmp($a['family_name'], $b['family_name']); |
|
| 970 | + if (!$a['family_name'] && !$b['family_name']) { |
|
| 971 | + return strcmp($a['lordofname'], $b['lordofname']); |
|
| 972 | + } |
|
| 973 | + if (!$a['family_name']) { |
|
| 974 | + return strcmp($a['lordofname'], $b['family_name']); |
|
| 975 | + } |
|
| 976 | + if (!$b['family_name']) { |
|
| 977 | + return strcmp($a['family_name'], $b['lordofname']); |
|
| 978 | + } |
|
| 979 | + if (strcmp($a['family_name'], $b['family_name'])) { |
|
| 980 | + return strcmp($a['family_name'], $b['family_name']); |
|
| 981 | + } |
|
| 951 | 982 | return strcmp($a['lordofname'], $b['lordofname']); |
| 952 | 983 | } |
| 953 | 984 | |
@@ -974,12 +1005,17 @@ discard block |
||
| 974 | 1005 | 'Lords in Waiting (HM Household)' => 'Government Whip', |
| 975 | 1006 | 'Baronesses in Waiting, HM Household' => 'Government Whip', |
| 976 | 1007 | ); |
| 977 | - if ($pos) { # Government post, or Chairman of Select Committee |
|
| 1008 | + if ($pos) { |
|
| 1009 | +# Government post, or Chairman of Select Committee |
|
| 978 | 1010 | $pretty = $pos; |
| 979 | - if ($dept && $dept != 'No Department') $pretty .= ", $dept"; |
|
| 980 | - if (array_key_exists($pretty, $lookup)) |
|
| 981 | - $pretty = $lookup[$pretty]; |
|
| 982 | - } else { # Member of Select Committee |
|
| 1011 | + if ($dept && $dept != 'No Department') { |
|
| 1012 | + $pretty .= ", $dept"; |
|
| 1013 | + } |
|
| 1014 | + if (array_key_exists($pretty, $lookup)) { |
|
| 1015 | + $pretty = $lookup[$pretty]; |
|
| 1016 | + } |
|
| 1017 | + } else { |
|
| 1018 | +# Member of Select Committee |
|
| 983 | 1019 | $pretty = "Member, $dept"; |
| 984 | 1020 | } |
| 985 | 1021 | return $pretty; |
@@ -997,13 +1033,16 @@ discard block |
||
| 997 | 1033 | } |
| 998 | 1034 | |
| 999 | 1035 | // single date? |
| 1000 | - if (isset($data['date'])) $one_date = true; |
|
| 1036 | + if (isset($data['date'])) { |
|
| 1037 | + $one_date = true; |
|
| 1038 | + } |
|
| 1001 | 1039 | |
| 1002 | 1040 | // remove empty entries, so they don't produce errors |
| 1003 | 1041 | foreach (array_keys($hansardmajors) as $major) { |
| 1004 | 1042 | if (array_key_exists($major, $data)) { |
| 1005 | - if (count($data[$major]) == 0) |
|
| 1006 | - unset($data[$major]); |
|
| 1043 | + if (count($data[$major]) == 0) { |
|
| 1044 | + unset($data[$major]); |
|
| 1045 | + } |
|
| 1007 | 1046 | } |
| 1008 | 1047 | } |
| 1009 | 1048 | |
@@ -1012,22 +1051,29 @@ discard block |
||
| 1012 | 1051 | if (!$one_date) { |
| 1013 | 1052 | $todaystime = gmmktime(0, 0, 0, date('m'), date('d'), date('Y')); |
| 1014 | 1053 | foreach ($data as $major => $array) { |
| 1015 | - if (!in_array('timestamp', $array)) $daytext[$major] = "The most recent "; |
|
| 1016 | - elseif ($todaystime - $array['timestamp'] == 86400) $daytext[$major] = "Yesterday’s"; |
|
| 1017 | - elseif ($todaystime - $array['timestamp'] <= (6 * 86400)) $daytext[$major] = gmdate('l', $array['timestamp']) . "’s"; |
|
| 1018 | - else $daytext[$major] = "The most recent "; |
|
| 1054 | + if (!in_array('timestamp', $array)) { |
|
| 1055 | + $daytext[$major] = "The most recent "; |
|
| 1056 | + } elseif ($todaystime - $array['timestamp'] == 86400) { |
|
| 1057 | + $daytext[$major] = "Yesterday’s"; |
|
| 1058 | + } elseif ($todaystime - $array['timestamp'] <= (6 * 86400)) { |
|
| 1059 | + $daytext[$major] = gmdate('l', $array['timestamp']) . "’s"; |
|
| 1060 | + } else { |
|
| 1061 | + $daytext[$major] = "The most recent "; |
|
| 1062 | + } |
|
| 1019 | 1063 | } |
| 1020 | 1064 | } |
| 1021 | 1065 | |
| 1022 | 1066 | //build html |
| 1023 | 1067 | foreach ($printed_majors as $p_major) { |
| 1024 | - if (!array_key_exists($p_major, $data)) |
|
| 1025 | - continue; |
|
| 1068 | + if (!array_key_exists($p_major, $data)) { |
|
| 1069 | + continue; |
|
| 1070 | + } |
|
| 1026 | 1071 | |
| 1027 | - if ($one_date) |
|
| 1028 | - $date = $data['date']; |
|
| 1029 | - else |
|
| 1030 | - $date = $data[$p_major]['hdate']; |
|
| 1072 | + if ($one_date) { |
|
| 1073 | + $date = $data['date']; |
|
| 1074 | + } else { |
|
| 1075 | + $date = $data[$p_major]['hdate']; |
|
| 1076 | + } |
|
| 1031 | 1077 | $q = $db->query('SELECT section_id, body, gid |
| 1032 | 1078 | FROM hansard, epobject |
| 1033 | 1079 | WHERE hansard.epobject_id = epobject.epobject_id ' |
@@ -1079,14 +1125,16 @@ discard block |
||
| 1079 | 1125 | } |
| 1080 | 1126 | |
| 1081 | 1127 | $return .= '<a href="'; |
| 1082 | - if (isset($data[$major]['listurl'])) |
|
| 1083 | - $return .= $data[$major]['listurl']; |
|
| 1084 | - else { |
|
| 1128 | + if (isset($data[$major]['listurl'])) { |
|
| 1129 | + $return .= $data[$major]['listurl']; |
|
| 1130 | + } else { |
|
| 1085 | 1131 | $LISTURL->reset(); |
| 1086 | 1132 | $return .= $LISTURL->generate(); |
| 1087 | 1133 | } |
| 1088 | 1134 | $return .= '">' . $hansardmajors[$major]['title'] . '</a>'; |
| 1089 | - if (isset($daytext[$major])) $return; |
|
| 1135 | + if (isset($daytext[$major])) { |
|
| 1136 | + $return; |
|
| 1137 | + } |
|
| 1090 | 1138 | $return .= '</h4>'; |
| 1091 | 1139 | |
| 1092 | 1140 | return $return; |
@@ -1094,20 +1142,21 @@ discard block |
||
| 1094 | 1142 | |
| 1095 | 1143 | function score_to_strongly($dmpscore) { |
| 1096 | 1144 | $dmpdesc = "unknown about"; |
| 1097 | - if ($dmpscore > 0.95 && $dmpscore <= 1.0) |
|
| 1098 | - $dmpdesc = "consistently voted against"; |
|
| 1099 | - elseif ($dmpscore > 0.85) |
|
| 1100 | - $dmpdesc = "almost always voted against"; |
|
| 1101 | - elseif ($dmpscore > 0.6) |
|
| 1102 | - $dmpdesc = "generally voted against"; |
|
| 1103 | - elseif ($dmpscore > 0.4) |
|
| 1104 | - $dmpdesc = "voted a mixture of for and against"; |
|
| 1105 | - elseif ($dmpscore > 0.15) |
|
| 1106 | - $dmpdesc = "generally voted for"; |
|
| 1107 | - elseif ($dmpscore > 0.05) |
|
| 1108 | - $dmpdesc = "almost always voted for"; |
|
| 1109 | - elseif ($dmpscore >= 0.0) |
|
| 1110 | - $dmpdesc = "consistently voted for"; |
|
| 1145 | + if ($dmpscore > 0.95 && $dmpscore <= 1.0) { |
|
| 1146 | + $dmpdesc = "consistently voted against"; |
|
| 1147 | + } elseif ($dmpscore > 0.85) { |
|
| 1148 | + $dmpdesc = "almost always voted against"; |
|
| 1149 | + } elseif ($dmpscore > 0.6) { |
|
| 1150 | + $dmpdesc = "generally voted against"; |
|
| 1151 | + } elseif ($dmpscore > 0.4) { |
|
| 1152 | + $dmpdesc = "voted a mixture of for and against"; |
|
| 1153 | + } elseif ($dmpscore > 0.15) { |
|
| 1154 | + $dmpdesc = "generally voted for"; |
|
| 1155 | + } elseif ($dmpscore > 0.05) { |
|
| 1156 | + $dmpdesc = "almost always voted for"; |
|
| 1157 | + } elseif ($dmpscore >= 0.0) { |
|
| 1158 | + $dmpdesc = "consistently voted for"; |
|
| 1159 | + } |
|
| 1111 | 1160 | return $dmpdesc; |
| 1112 | 1161 | } |
| 1113 | 1162 | |
@@ -364,7 +364,7 @@ |
||
| 364 | 364 | $this->extra_info = array(); |
| 365 | 365 | |
| 366 | 366 | $q = $this->db->query('SELECT * FROM moffice WHERE person=:person_id ORDER BY from_date DESC, moffice_id', |
| 367 | - array(':person_id' => $this->person_id)); |
|
| 367 | + array(':person_id' => $this->person_id)); |
|
| 368 | 368 | $this->extra_info['office'] = $q->fetchAll(); |
| 369 | 369 | |
| 370 | 370 | // Info specific to member id (e.g. attendance during that period of office) |