From 7d5383b694bd692dd4fb2f9478473df5256fecac Mon Sep 17 00:00:00 2001 From: Alex Parsons Date: Tue, 1 Oct 2024 10:52:48 +0000 Subject: [PATCH] Apply formatting change --- classes/AlertView.php | 9 +- classes/AlertView/Simple.php | 79 +- classes/AlertView/Standard.php | 60 +- classes/Common.php | 1 - classes/Data.php | 16 +- classes/Db/Connection.php | 1 - classes/Db/Query.php | 11 +- classes/Dissolution.php | 12 +- classes/Divisions.php | 281 +-- classes/EditQueue.php | 71 +- classes/FacebookLogin.php | 14 +- classes/Gid.php | 7 +- classes/GlossaryEditQueue.php | 9 +- classes/Hansard.php | 1 - classes/Homepage.php | 77 +- classes/Member.php | 119 +- classes/MemberException.php | 4 +- classes/Memcache.php | 15 +- classes/Model/AnnouncementManagement.php | 31 +- classes/Model/Featured.php | 41 +- classes/Office.php | 5 +- classes/Party.php | 13 +- classes/PartyCohort.php | 22 +- classes/People.php | 67 +- classes/People/LondonAssemblyMembers.php | 4 +- classes/People/MLAs.php | 1 - classes/People/MPs.php | 9 +- classes/People/MSPs.php | 1 - classes/People/MSs.php | 2 - classes/People/Peers.php | 9 +- classes/Policies.php | 82 +- classes/PolicyPositions.php | 54 +- classes/Redis.php | 2 +- classes/Renderer.php | 21 +- classes/Renderer/Footer.php | 36 +- classes/Renderer/Header.php | 72 +- classes/Renderer/Markdown.php | 28 +- classes/Renderer/User.php | 67 +- classes/SPHomepage.php | 25 +- classes/Search.php | 62 +- classes/Search/ByUsage.php | 2 +- classes/Search/Normal.php | 142 +- classes/Search/ParseArgs.php | 2 +- classes/Search/SearchBox.php | 22 +- classes/SectionView/DebatesView.php | 40 +- classes/SectionView/LondonView.php | 10 +- classes/SectionView/LordsView.php | 2 +- classes/SectionView/NiView.php | 46 +- classes/SectionView/PbcView.php | 36 +- classes/SectionView/SectionView.php | 193 ++- classes/SectionView/SeneddView.php | 44 +- classes/SectionView/SpView.php | 10 +- classes/SectionView/SpwransView.php | 58 +- classes/SectionView/WhallView.php | 2 +- classes/SectionView/WmsView.php | 4 +- classes/SectionView/WransView.php | 44 +- classes/Stripe.php | 2 +- classes/Subscription.php | 21 +- classes/TestStripe.php | 2 +- classes/Topic.php | 134 +- classes/Topics.php | 11 +- classes/Url.php | 9 +- classes/User.php | 68 +- classes/Utility/Alert.php | 38 +- classes/Utility/Calendar.php | 20 +- classes/Utility/Constituencies.php | 12 +- classes/Utility/Gaze.php | 7 +- classes/Utility/Hansard.php | 11 +- classes/Utility/House.php | 107 +- classes/Utility/LibFilter.php | 80 +- classes/Utility/Member.php | 9 +- classes/Utility/Postcode.php | 51 +- classes/Utility/Search.php | 68 +- classes/Utility/Shuffle.php | 5 +- classes/Utility/Wikipedia.php | 131 +- scripts/alertgonemps.php | 162 +- scripts/alertmailer.php | 77 +- scripts/alertmpchanged.php | 96 +- scripts/create_initial_topics.php | 102 +- scripts/mprss.php | 92 +- scripts/populate-policy-images.php | 18 +- scripts/wrans-votes-by-dept.php | 17 +- scripts/wranstats.php | 9 +- tests/AcceptApiTest.php | 111 +- tests/AcceptBasicTest.php | 38 +- tests/AlertsPageTest.php | 30 +- tests/AlertsTest.php | 112 +- tests/Bootstrap.php | 6 +- tests/CommentTest.php | 29 +- tests/DivisionsTest.php | 37 +- tests/FetchPageTestCase.php | 13 +- tests/GlossaryTest.php | 54 +- tests/HansardTest.php | 54 +- tests/HousesTest.php | 25 +- tests/LibFilterTest.php | 24 +- tests/MemberTest.php | 179 +- tests/PageTest.php | 56 +- tests/PartyTest.php | 152 +- tests/PeopleTest.php | 49 +- tests/PostcodeTest.php | 24 +- tests/SearchTest.php | 60 +- tests/SectionTest.php | 32 +- tests/TWFY_Database_TestCase.php | 22 +- tests/TopicsTest.php | 31 +- tests/UserPageTest.php | 45 +- tests/UserTest.php | 52 +- tests/UtilityTest.php | 9 +- tests/VotesTest.php | 12 +- www/docs/404.php | 10 +- www/docs/about/index.php | 2 +- www/docs/admin/alert_stats.php | 85 +- www/docs/admin/badusers.php | 62 +- www/docs/admin/banner.php | 24 +- www/docs/admin/comments.php | 16 +- www/docs/admin/edittopic.php | 74 +- www/docs/admin/failedsearches.php | 30 +- www/docs/admin/featured.php | 40 +- www/docs/admin/glossary.php | 37 +- www/docs/admin/glossary_pending.php | 48 +- www/docs/admin/index.php | 42 +- www/docs/admin/photos.php | 86 +- www/docs/admin/policies.php | 35 +- www/docs/admin/popularsearches.php | 32 +- www/docs/admin/profile-message.php | 46 +- www/docs/admin/report.php | 62 +- www/docs/admin/reporting_stats.php | 14 +- www/docs/admin/reports.php | 14 +- www/docs/admin/searchlogs.php | 32 +- www/docs/admin/statistics.php | 22 +- www/docs/admin/topics.php | 12 +- www/docs/admin/users.php | 70 +- www/docs/admin/websites.php | 40 +- www/docs/admin/wikipedia.php | 4 +- www/docs/alert/authed.php | 19 +- www/docs/alert/by-postcode/index.php | 1 - www/docs/alert/update-mp/index.php | 3 +- www/docs/api/api_convertURL.php | 48 +- www/docs/api/api_functions.php | 246 +-- www/docs/api/api_getAlerts.php | 6 +- www/docs/api/api_getBoundary.php | 2 +- www/docs/api/api_getComments.php | 42 +- www/docs/api/api_getCommittee.php | 40 +- www/docs/api/api_getConstituencies.php | 48 +- www/docs/api/api_getConstituency.php | 8 +- www/docs/api/api_getDebates.php | 6 +- www/docs/api/api_getGeometry.php | 80 +- www/docs/api/api_getHansard.php | 44 +- www/docs/api/api_getLord.php | 5 +- www/docs/api/api_getLords.php | 2 +- www/docs/api/api_getMLA.php | 2 +- www/docs/api/api_getMLAs.php | 2 +- www/docs/api/api_getMP.php | 2 +- www/docs/api/api_getMPInfo.php | 2 +- www/docs/api/api_getMPs.php | 2 +- www/docs/api/api_getMPsInfo.php | 14 +- www/docs/api/api_getMS.php | 3 +- www/docs/api/api_getMSP.php | 2 +- www/docs/api/api_getMSPs.php | 2 +- www/docs/api/api_getMSs.php | 2 +- www/docs/api/api_getMembers.php | 41 +- www/docs/api/api_getPerson.php | 55 +- www/docs/api/api_getQuota.php | 4 +- www/docs/api/api_getWMS.php | 10 +- www/docs/api/api_getWrans.php | 10 +- www/docs/api/cancel-plan.php | 2 +- www/docs/api/hook.php | 6 +- www/docs/api/index.php | 62 +- www/docs/api/invoices.php | 2 +- www/docs/api/key.php | 14 +- www/docs/api/terms.php | 2 +- www/docs/api/update-plan.php | 4 +- .../bills/2005-06/identity-cards/index.php | 20 +- .../index.php | 162 +- www/docs/boundaries/index.php | 54 +- www/docs/calendar/index.php | 54 +- www/docs/comments/recent/index.php | 8 +- www/docs/contact/index.php | 2 +- www/docs/departments/index.php | 12 +- www/docs/departments/questions.php | 14 +- www/docs/departments/statements.php | 14 +- www/docs/divisions/division.php | 16 +- www/docs/divisions/index.php | 2 +- www/docs/email/index.php | 24 +- www/docs/foiorder2009/index.php | 2 +- www/docs/foiorder2009/share.php | 4 +- www/docs/freeourbills/doshare.php | 2 +- www/docs/freeourbills/index.php | 6 +- www/docs/freeourbills/share.php | 4 +- www/docs/freeourbills/sharethis.php | 24 +- www/docs/glossary/index.php | 54 +- www/docs/hansardbugs/index.php | 8 +- www/docs/help/index.php | 2 +- www/docs/help/linktous/index.php | 2 +- www/docs/houserules/index.php | 2 +- www/docs/images/mps/photo-status.php | 8 +- www/docs/index-election.php | 78 +- www/docs/index.php | 2 +- www/docs/mp/index.php | 245 +-- www/docs/mps/index.php | 2 +- www/docs/mps/multiple.php | 8 +- www/docs/news/editme.php | 842 +++++---- www/docs/news/home_page_include.php | 2 +- www/docs/news/index.php | 22 +- www/docs/news/rdf.php | 32 +- www/docs/news/sidebar_archives.php | 6 +- www/docs/parliament/index.php | 7 +- www/docs/parliaments/index.php | 2 +- www/docs/postcode/index.php | 44 +- www/docs/privacy/index.php | 2 +- www/docs/random/index.php | 2 +- www/docs/regmem/index.php | 98 +- www/docs/report/index.php | 20 +- www/docs/rss/index.php | 10 +- www/docs/scotland/index.php | 2 +- www/docs/search-hansard/index.php | 7 +- www/docs/search/rss/index.php | 9 +- www/docs/section.php | 7 +- www/docs/support-us/failed.php | 4 +- www/docs/support-us/index.php | 4 +- www/docs/support-us/thanks.php | 4 +- www/docs/topic/image.php | 2 +- www/docs/topic/topic.php | 20 +- www/docs/user/confirm/index.php | 70 +- www/docs/user/index.php | 18 +- www/docs/user/login/fb.php | 10 +- www/docs/user/login/index.php | 28 +- www/docs/user/logout/index.php | 2 +- www/docs/user/password/index.php | 25 +- www/docs/user/prompt/index.php | 2 +- www/docs/vote/index.php | 44 +- www/docs/voting-information/index.php | 4 +- .../written-answers-and-statements/index.php | 3 +- www/includes/dbtypes.php | 253 +-- www/includes/easyparliament/alert.php | 179 +- www/includes/easyparliament/comment.php | 107 +- www/includes/easyparliament/commentlist.php | 234 +-- www/includes/easyparliament/commentreport.php | 139 +- .../easyparliament/commentreportlist.php | 21 +- www/includes/easyparliament/glossary.php | 113 +- www/includes/easyparliament/glossarylist.php | 5 +- www/includes/easyparliament/hansardlist.php | 1154 ++++++------ www/includes/easyparliament/helper-donate.php | 25 +- www/includes/easyparliament/init.php | 48 +- www/includes/easyparliament/member.php | 241 +-- www/includes/easyparliament/metadata.php | 1539 +++++++++-------- www/includes/easyparliament/page.php | 302 ++-- www/includes/easyparliament/recess.php | 739 ++++---- www/includes/easyparliament/searchengine.php | 246 ++- www/includes/easyparliament/searchlog.php | 25 +- .../easyparliament/sidebars/bills_intro.php | 2 +- .../sidebars/comments_recent.php | 5 +- .../easyparliament/sidebars/donate.php | 2 +- .../easyparliament/sidebars/front.php | 2 +- .../easyparliament/sidebars/glossary_add.php | 2 +- .../easyparliament/sidebars/hocdebates.php | 2 +- .../sidebars/hocdebates_short.php | 13 +- .../easyparliament/sidebars/holdebates.php | 2 +- .../sidebars/holdebates_short.php | 13 +- .../easyparliament/sidebars/mla_search.php | 8 +- .../sidebars/mp_email_friend.php | 2 +- .../easyparliament/sidebars/mp_search.php | 8 +- .../sidebars/mp_speech_search.php | 2 +- www/includes/easyparliament/sidebars/mps.php | 8 +- .../easyparliament/sidebars/msp_search.php | 8 +- .../easyparliament/sidebars/nidebates.php | 2 +- .../sidebars/nidebates_short.php | 13 +- www/includes/easyparliament/sidebars/pbc.php | 2 +- .../easyparliament/sidebars/pbc_short.php | 13 +- .../easyparliament/sidebars/peer_search.php | 8 +- .../easyparliament/sidebars/sitenews.php | 4 +- .../sidebars/sitenews_recent.php | 2 +- .../easyparliament/sidebars/spdebates.php | 2 +- .../sidebars/spdebates_short.php | 13 +- .../easyparliament/sidebars/userjoin.php | 2 +- .../easyparliament/sidebars/userlogin.php | 2 +- .../easyparliament/sidebars/whalldebates.php | 2 +- .../sidebars/whalldebates_short.php | 13 +- .../sidebars/whatisthissite.php | 2 +- www/includes/easyparliament/sidebars/wms.php | 2 +- .../easyparliament/sidebars/wms_short.php | 13 +- .../easyparliament/sidebars/wrans.php | 2 +- .../easyparliament/sidebars/wrans_short.php | 13 +- .../staticpages/search_help.php | 4 +- .../easyparliament/templates/api/comments.php | 16 +- .../templates/api/comments_recent.php | 2 +- .../templates/api/comments_user.php | 2 +- .../templates/api/hansard_calendar.php | 3 +- .../templates/api/hansard_date.php | 11 +- .../templates/api/hansard_gid.php | 18 +- .../templates/html/alert/_list.php | 6 +- .../templates/html/alert/index.php | 60 +- .../_sidebar_right_announcements.php | 6 +- .../templates/html/api/check.php | 4 +- .../templates/html/api/update.php | 44 +- .../templates/html/calendar/index.php | 10 +- .../templates/html/comments.php | 20 +- .../templates/html/comments_recent.php | 10 +- .../templates/html/comments_user.php | 2 +- .../html/divisions/_name_vote_list.php | 32 +- .../html/divisions/_vote_description.php | 2 +- .../html/divisions/_vote_summary.php | 4 +- .../templates/html/divisions/_votes.php | 26 +- .../templates/html/divisions/_your_mp.php | 12 +- .../templates/html/divisions/index.php | 6 +- .../templates/html/divisions/vote.php | 10 +- .../templates/html/donate/_stripe_donate.php | 56 +- .../easyparliament/templates/html/footer.php | 28 +- .../templates/html/glossary.php | 18 +- .../html/hansard_glossary_search.php | 8 +- .../templates/html/hansard_person.php | 2 +- .../html/hansard_recent_mostvotes.php | 38 +- .../easyparliament/templates/html/header.php | 14 +- .../templates/html/homepage/devolved-list.php | 54 +- .../html/homepage/featured-content.php | 10 +- .../html/homepage/recent-debates.php | 8 +- .../templates/html/homepage/recent-votes.php | 2 +- .../easyparliament/templates/html/index.php | 33 +- .../templates/html/london/index.php | 12 +- .../templates/html/mp/_chamber_info_panel.php | 2 +- .../html/mp/_division_description.php | 74 +- .../templates/html/mp/_donation.php | 4 +- .../templates/html/mp/_featured_content.php | 4 +- .../templates/html/mp/_vote_description.php | 6 +- .../templates/html/mp/divisions.php | 72 +- .../templates/html/mp/header.php | 76 +- .../templates/html/mp/profile.php | 2 +- .../templates/html/mp/recent.php | 34 +- .../templates/html/mp/votes.php | 148 +- .../templates/html/mp/votes_svg.php | 60 +- .../templates/html/ni/index.php | 8 +- .../templates/html/people/index.php | 64 +- .../templates/html/postcode/index.php | 52 +- .../templates/html/scotland/index.php | 8 +- .../templates/html/search/by-person.php | 66 +- .../templates/html/search/form_main.php | 4 +- .../templates/html/search/person.php | 4 +- .../templates/html/search/results.php | 62 +- .../templates/html/search/sidebar.php | 4 +- .../html/section/_business_list_item.php | 8 +- .../html/section/_business_section.php | 10 +- .../templates/html/section/_calendar.php | 230 +-- .../html/section/_calendar_section.php | 2 +- .../templates/html/section/_search.php | 4 +- .../html/section/_section_content.php | 229 +-- .../templates/html/section/_section_toc.php | 8 +- .../templates/html/section/column.php | 11 +- .../templates/html/section/day.php | 31 +- .../templates/html/section/index.php | 25 +- .../templates/html/section/ni_index.php | 7 +- .../templates/html/section/pbc_bill.php | 32 +- .../templates/html/section/pbc_index.php | 5 +- .../templates/html/section/pbc_session.php | 6 +- .../templates/html/section/recent.php | 3 +- .../templates/html/section/section.php | 19 +- .../templates/html/section/senedd_index.php | 7 +- .../templates/html/section/wrans_index.php | 13 +- .../templates/html/section/year.php | 5 +- .../templates/html/senedd/index.php | 8 +- .../templates/html/static/linktous.php | 38 +- .../templates/html/topic/topic.php | 2 +- .../templates/html/user/form.php | 16 +- .../templates/html/user/index.php | 2 +- .../templates/html/user/join.php | 18 +- .../templates/html/user/view_user.php | 2 +- .../templates/rss/hansard_search.php | 34 +- www/includes/easyparliament/user.php | 426 +++-- www/includes/test/utility_test.php | 17 +- www/includes/utility.php | 453 ++--- 368 files changed, 8737 insertions(+), 8526 deletions(-) diff --git a/classes/AlertView.php b/classes/AlertView.php index 91b2c56277..0ececa8671 100644 --- a/classes/AlertView.php +++ b/classes/AlertView.php @@ -3,9 +3,8 @@ namespace MySociety\TheyWorkForYou; class AlertView { - - const ALERT_EXISTS = -2; - const CREATE_FAILED = -1; + public const ALERT_EXISTS = -2; + public const CREATE_FAILED = -1; protected $user; protected $db; @@ -13,8 +12,8 @@ class AlertView { public function __construct($THEUSER = null) { $this->user = $THEUSER; - $this->db = new \ParlDB; - $this->alert = new \ALERT; + $this->db = new \ParlDB(); + $this->alert = new \ALERT(); } protected function confirmAlert($token) { diff --git a/classes/AlertView/Simple.php b/classes/AlertView/Simple.php index d61e4ec811..90a0ff2e76 100644 --- a/classes/AlertView/Simple.php +++ b/classes/AlertView/Simple.php @@ -3,11 +3,10 @@ namespace MySociety\TheyWorkForYou\AlertView; class Simple extends \MySociety\TheyWorkForYou\AlertView { - public function display() { - $data = array(); + $data = []; $data['recent_election'] = false; - if ( $this->user->loggedin() ) { + if ($this->user->loggedin()) { $data['user_signed_in'] = true; } @@ -17,21 +16,21 @@ public function display() { $data['postcode'] = trim(get_http_var('postcode')); $result = $this->createAlertForPostCode($data['email'], $data['postcode']); - $data = array_merge( $data, $result ); + $data = array_merge($data, $result); } elseif (get_http_var('update')) { $result = $this->getNewMP(get_http_var('update')); - $data = array_merge( $data, $result ); + $data = array_merge($data, $result); } elseif (get_http_var('update-alert')) { - $success = $this->replaceAlert( get_http_var('confirmation') ); + $success = $this->replaceAlert(get_http_var('confirmation')); $data['confirmation_received'] = $success; } elseif (get_http_var('confirmed')) { - $success = $this->confirmAlert( get_http_var('confirmed') ); + $success = $this->confirmAlert(get_http_var('confirmed')); $data['confirmation_received'] = $success; } else { $data['email'] = $this->user->email() ? $this->user->email() : ''; $data['postcode'] = $this->user->postcode_is_set() ? $this->user->postcode() : ''; - if ( $this->isEmailSignedUpForPostCode( $data['email'], $data['postcode'] ) ) { + if ($this->isEmailSignedUpForPostCode($data['email'], $data['postcode'])) { $data['already_signed_up'] = true; $mp = $this->getPersonFromPostcode($data['postcode']); $data['mp_name'] = $mp->full_name(); @@ -42,10 +41,10 @@ public function display() { } private function getPersonFromPostcode($postcode) { - $args = array( + $args = [ 'postcode' => $postcode, - 'house' => 1 - ); + 'house' => 1, + ]; $member = new \MySociety\TheyWorkForYou\Member($args); return $member; @@ -66,30 +65,30 @@ private function validateDetails($email, $postcode) { } private function createAlertForPostCode($email, $postcode) { - if ( !$this->validateDetails($email, $postcode) ) { - return array('invalid-postcode-or-email' => true); + if (!$this->validateDetails($email, $postcode)) { + return ['invalid-postcode-or-email' => true]; } try { $person = $this->getPersonFromPostcode($postcode); - } catch ( \MySociety\TheyWorkForYou\MemberException $e ) { - return array('bad-constituency' => true); + } catch (\MySociety\TheyWorkForYou\MemberException $e) { + return ['bad-constituency' => true]; } - $details = array( + $details = [ 'email' => $email, 'pid' => $person->person_id, 'pc' => $postcode, 'confirm_base' => 'https://' . DOMAIN . '/alert/by-postcode?confirmed=', - ); + ]; - $data = array(); + $data = []; $not_logged_in = $this->user->loggedin ? false : true; $result = $this->alert->add($details, $not_logged_in); switch ($result) { case self::ALERT_EXISTS: - if ( $not_logged_in ) { + if ($not_logged_in) { // no logged in user so send them an email to let them // know someone tried to create an alert $this->alert->send_already_signedup_email($details); @@ -102,7 +101,7 @@ private function createAlertForPostCode($email, $postcode) { $data['error'] = true; break; default: // alert created - if ( $not_logged_in ) { + if ($not_logged_in) { $data['confirmation_sent'] = true; } else { $data['signedup_no_confirm'] = true; @@ -116,8 +115,8 @@ private function replaceAlert($confirmation) { $existing = $this->alert->fetch_by_token($confirmation); preg_match('/speaker:(\d+)/', $existing['criteria'], $matches); $old_mp_id = $matches[1]; - $old_mp = new \MySociety\TheyWorkForYou\Member(array( 'person_id' => $old_mp_id ) ); - $new_mp = new \MySociety\TheyWorkForYou\Member(array( 'constituency' => $old_mp->constituency, 'house' => 1 )); + $old_mp = new \MySociety\TheyWorkForYou\Member([ 'person_id' => $old_mp_id ]); + $new_mp = new \MySociety\TheyWorkForYou\Member([ 'constituency' => $old_mp->constituency, 'house' => 1 ]); $q = $this->db->query( "SELECT alert_id, criteria, registrationtoken FROM alerts @@ -125,10 +124,10 @@ private function replaceAlert($confirmation) { AND criteria LIKE :criteria AND confirmed = 1 AND deleted = 0", - array( + [ ':email' => $existing['email'], - ':criteria' => '%speaker:' . $old_mp_id . '%' - ) + ':criteria' => '%speaker:' . $old_mp_id . '%', + ] ); foreach ($q as $row) { @@ -136,12 +135,12 @@ private function replaceAlert($confirmation) { $this->alert->token_checked = null; $other_criteria = trim(preg_replace('/speaker:\d+/', '', $row['criteria'])); - $details = array( + $details = [ 'email' => $existing['email'], 'pid' => $new_mp->person_id, 'pc' => '', - ); - if ( $other_criteria ) { + ]; + if ($other_criteria) { $details['keyword'] = $other_criteria; } @@ -149,20 +148,20 @@ private function replaceAlert($confirmation) { $this->alert->add($details, false); } - return array( + return [ 'signedup_no_confirm' => true, 'new_mp' => $new_mp->full_name(), - ); + ]; } private function isEmailSignedUpForPostCode($email, $postcode) { $is_signed_up = false; - if ( $email && $postcode ) { + if ($email && $postcode) { try { $person = $this->getPersonFromPostcode($postcode); $is_signed_up = $this->alert->fetch_by_mp($email, $person->person_id); - } catch ( \MySociety\TheyWorkForYou\MemberException $e ) { + } catch (\MySociety\TheyWorkForYou\MemberException $e) { $is_signed_up = false; } } @@ -171,27 +170,27 @@ private function isEmailSignedUpForPostCode($email, $postcode) { private function getNewMP($confirmation) { if (!$confirmation) { - return array(); + return []; } $existing = $this->alert->fetch_by_token($confirmation); preg_match('/speaker:(\d+)/', $existing['criteria'], $matches); $criteria = $matches[1]; - $old_mp = new \MySociety\TheyWorkForYou\Member(array( 'person_id' => $criteria ) ); - $new_mp = new \MySociety\TheyWorkForYou\Member(array( 'constituency' => $old_mp->constituency, 'house' => 1 )); + $old_mp = new \MySociety\TheyWorkForYou\Member([ 'person_id' => $criteria ]); + $new_mp = new \MySociety\TheyWorkForYou\Member([ 'constituency' => $old_mp->constituency, 'house' => 1 ]); - if ( $this->alert->fetch_by_mp( $existing['email'], $new_mp->person_id) ) { - $data = array( + if ($this->alert->fetch_by_mp($existing['email'], $new_mp->person_id)) { + $data = [ 'already_signed_up' => true, 'old_mp' => $old_mp->full_name(), 'mp_name' => $new_mp->full_name(), - ); + ]; } else { - $data = array( + $data = [ 'old_mp' => $old_mp->full_name(), 'new_mp' => $new_mp->full_name(), - ); + ]; } $data['update'] = true; diff --git a/classes/AlertView/Standard.php b/classes/AlertView/Standard.php index 29a7f2e1de..0f07f09dcb 100644 --- a/classes/AlertView/Standard.php +++ b/classes/AlertView/Standard.php @@ -13,7 +13,7 @@ class Standard extends \MySociety\TheyWorkForYou\AlertView { public function __construct($THEUSER = null) { parent::__construct($THEUSER); - $this->data = array(); + $this->data = []; } public function display() { @@ -111,7 +111,7 @@ private function getBasicData() { private function checkInput() { global $SEARCHENGINE; - $errors = array(); + $errors = []; // Check each of the things the user has input. // If there is a problem with any of them, set an entry in the $errors array. @@ -159,15 +159,15 @@ private function searchForConstituenciesAndMembers() { // Do the search if ($this->data['alertsearch']) { $this->data['members'] = \MySociety\TheyWorkForYou\Utility\Search::searchMemberDbLookupWithNames($this->data['alertsearch'], true); - list ($this->data['constituencies'], $this->data['valid_postcode']) = \MySociety\TheyWorkForYou\Utility\Search::searchConstituenciesByQuery($this->data['alertsearch']); + [$this->data['constituencies'], $this->data['valid_postcode']] = \MySociety\TheyWorkForYou\Utility\Search::searchConstituenciesByQuery($this->data['alertsearch']); } else { - $this->data['members'] = array(); + $this->data['members'] = []; } # If the above search returned one result for constituency # search by postcode, use it immediately if (isset($this->data['constituencies']) && count($this->data['constituencies']) == 1 && $this->data['valid_postcode']) { - $MEMBER = new \MEMBER(array('constituency' => $this->data['constituencies'][0], 'house' => 1)); + $MEMBER = new \MEMBER(['constituency' => $this->data['constituencies'][0], 'house' => 1]); $this->data['pid'] = $MEMBER->person_id(); $this->data['pc'] = $this->data['alertsearch']; unset($this->data['constituencies']); @@ -175,12 +175,12 @@ private function searchForConstituenciesAndMembers() { } if (isset($this->data['constituencies'])) { - $cons = array(); + $cons = []; foreach ($this->data['constituencies'] as $constituency) { try { - $MEMBER = new \MEMBER(array('constituency'=>$constituency, 'house' => 1)); + $MEMBER = new \MEMBER(['constituency' => $constituency, 'house' => 1]); $cons[$constituency] = $MEMBER; - } catch ( \MySociety\TheyWorkForYou\MemberException $e ) { + } catch (\MySociety\TheyWorkForYou\MemberException $e) { // do nothing } } @@ -200,17 +200,17 @@ private function addAlert() { // If this goes well, the alert will be added to the database and a confirmation email // will be sent to them. - $success = $this->alert->add( $this->data, $confirm ); + $success = $this->alert->add($this->data, $confirm); - if ($success>0 && !$confirm) { + if ($success > 0 && !$confirm) { $result = 'alert-added'; - } elseif ($success>0) { + } elseif ($success > 0) { $result = 'alert-confirmation'; } elseif ($success == -2) { // we need to make sure we know that the person attempting to sign up // for the alert has that email address to stop people trying to work // out what alerts they are signed up to - if ( $this->data['email_verified'] || ( $this->user->loggedin && $this->user->email() == $this->data['email'] ) ) { + if ($this->data['email_verified'] || ($this->user->loggedin && $this->user->email() == $this->data['email'])) { $result = 'alert-exists'; } else { // don't throw an error message as that implies that they have already signed @@ -235,7 +235,7 @@ private function addAlert() { private function formatSearchTerms() { - if ( $this->data['alertsearch'] ) { + if ($this->data['alertsearch']) { $this->data['alertsearch_pretty'] = \MySociety\TheyWorkForYou\Utility\Alert::prettifyCriteria($this->data['alertsearch']); $this->data['search_text'] = $this->data['alertsearch']; } else { @@ -244,15 +244,15 @@ private function formatSearchTerms() { } private function checkForCommonMistakes() { - $mistakes = array(); + $mistakes = []; if (strstr($this->data['alertsearch'], ',') > -1) { $mistakes['multiple'] = 1; } if ( - preg_match('#([A-Z]{1,2}\d+[A-Z]? ?\d[A-Z]{2})#i', $this->data['alertsearch'], $m) && - strlen($this->data['alertsearch']) > strlen($m[1]) && - validate_postcode($m[1]) + preg_match('#([A-Z]{1,2}\d+[A-Z]? ?\d[A-Z]{2})#i', $this->data['alertsearch'], $m) && + strlen($this->data['alertsearch']) > strlen($m[1]) && + validate_postcode($m[1]) ) { $this->data['postcode'] = $m[1]; $mistakes['postcode_and'] = 1; @@ -262,11 +262,11 @@ private function checkForCommonMistakes() { } private function formatSearchMemberData() { - if ( isset($this->data['postcode']) ) { + if (isset($this->data['postcode'])) { try { $postcode = $this->data['postcode']; - $MEMBER = new \MEMBER( array('postcode' => $postcode) ); + $MEMBER = new \MEMBER(['postcode' => $postcode]); // move the postcode to the front just to be tidy $tidy_alertsearch = $postcode . " " . trim(str_replace("$postcode", "", $this->data['alertsearch'])); $alertsearch_display = str_replace("$postcode ", "", $tidy_alertsearch); @@ -275,39 +275,39 @@ private function formatSearchMemberData() { $this->data['member_displaysearch'] = $alertsearch_display; $this->data['member'] = $MEMBER; - if ( isset($this->data['mistakes']['postcode_and']) ) { + if (isset($this->data['mistakes']['postcode_and'])) { $constituencies = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($postcode); - if ( isset($constituencies['SPC']) ) { - $MEMBER = new \MEMBER(array('constituency' => $constituencies['SPC'], 'house' => HOUSE_TYPE_SCOTLAND)); + if (isset($constituencies['SPC'])) { + $MEMBER = new \MEMBER(['constituency' => $constituencies['SPC'], 'house' => HOUSE_TYPE_SCOTLAND]); $this->data['scottish_alertsearch'] = str_replace("$postcode", "speaker:" . $MEMBER->person_id, $tidy_alertsearch); $this->data['scottish_member'] = $MEMBER; - } elseif ( isset($constituencies['WAC']) ) { - $MEMBER = new \MEMBER(array('constituency' => $constituencies['WAC'], 'house' => HOUSE_TYPE_WALES)); + } elseif (isset($constituencies['WAC'])) { + $MEMBER = new \MEMBER(['constituency' => $constituencies['WAC'], 'house' => HOUSE_TYPE_WALES]); $this->data['welsh_alertsearch'] = str_replace("$postcode", "speaker:" . $MEMBER->person_id, $tidy_alertsearch); $this->data['welsh_member'] = $MEMBER; } } - } catch ( \MySociety\TheyWorkForYou\MemberException $e ) { + } catch (\MySociety\TheyWorkForYou\MemberException $e) { $this->data['member_error'] = 1; } } - if ( $this->data['pid'] ) { - $MEMBER = new \MEMBER( array('person_id' => $this->data['pid']) ); + if ($this->data['pid']) { + $MEMBER = new \MEMBER(['person_id' => $this->data['pid']]); $this->data['pid_member'] = $MEMBER; } - if ( $this->data['keyword'] ) { + if ($this->data['keyword']) { $this->data['display_keyword'] = \MySociety\TheyWorkForYou\Utility\Alert::prettifyCriteria($this->data['keyword']); } } private function setUserData() { $this->data['current_mp'] = false; - $this->data['alerts'] = array(); + $this->data['alerts'] = []; if ($this->data['email_verified']) { if ($this->user->postcode()) { - $current_mp = new \MEMBER(array('postcode' => $this->user->postcode())); + $current_mp = new \MEMBER(['postcode' => $this->user->postcode()]); if (!$this->alert->fetch_by_mp($this->data['email'], $current_mp->person_id())) { $this->data['current_mp'] = $current_mp; } diff --git a/classes/Common.php b/classes/Common.php index 8086a3c554..812d15e594 100644 --- a/classes/Common.php +++ b/classes/Common.php @@ -3,7 +3,6 @@ namespace MySociety\TheyWorkForYou; class Common { - public function getPopularSearches() { global $SEARCHLOG; $popular_searches = $SEARCHLOG->popular_recent(10, 2000); diff --git a/classes/Data.php b/classes/Data.php index ccc57becce..4ddb904433 100644 --- a/classes/Data.php +++ b/classes/Data.php @@ -82,10 +82,10 @@ public function set_section() { public function page_metadata($page, $key) { return $this->getMetadata( - array( + [ 'page' => $page, - 'key' => $key - ), + 'key' => $key, + ], 'page' ); } @@ -99,10 +99,10 @@ public function page_metadata($page, $key) { public function section_metadata($section, $key) { return $this->getMetadata( - array( + [ 'section' => $section, - 'key' => $key - ), + 'key' => $key, + ], 'section' ); } @@ -116,7 +116,7 @@ public function section_metadata($section, $key) { */ public function set_page_metadata($page, $key, $value) { - $this->setMetadata(array("page"=>$page, "key"=>$key, "value"=>$value)); + $this->setMetadata(["page" => $page, "key" => $key, "value" => $value]); } /** @@ -128,7 +128,7 @@ public function set_page_metadata($page, $key, $value) { */ public function set_section_metadata($section, $key, $value) { - $this->setMetadata(array("section"=>$section, "key"=>$key, "value"=>$value)); + $this->setMetadata(["section" => $section, "key" => $key, "value" => $value]); } /** diff --git a/classes/Db/Connection.php b/classes/Db/Connection.php index c7064eaa5c..aec310c7c0 100644 --- a/classes/Db/Connection.php +++ b/classes/Db/Connection.php @@ -43,7 +43,6 @@ */ class Connection { - /** * Initialise Connection * diff --git a/classes/Db/Query.php b/classes/Db/Query.php index 365e91769e..633e61185e 100644 --- a/classes/Db/Query.php +++ b/classes/Db/Query.php @@ -37,10 +37,9 @@ */ class Query implements \IteratorAggregate, \ArrayAccess { - private $success = true; private $rows = null; - private $data = array(); + private $data = []; private $insert_id = null; private $affected_rows = null; @@ -118,7 +117,7 @@ public function query($sql = "", $params = null) { } $this->affected_rows = $pdoStatement->rowCount(); - twfy_debug("SQLRESULT", array($this, 'displayResult')); + twfy_debug("SQLRESULT", [$this, 'displayResult']); // mysql_free_result($q); } } @@ -146,7 +145,7 @@ public function offsetGet($offset) { } public function offsetSet($offset, $value) { - throw new \Exception; + throw new \Exception(); } public function offsetExists($offset) { @@ -154,7 +153,7 @@ public function offsetExists($offset) { } public function offsetUnset($offset) { - throw new \Exception; + throw new \Exception(); } public function fetchAll() { @@ -185,7 +184,7 @@ public function row($row_index) { if ($this->success && $this->rows > 0) { return $this->data[$row_index]; } - return array(); + return []; } public function exists() { diff --git a/classes/Dissolution.php b/classes/Dissolution.php index 23410cb37a..aed4b8ae1c 100644 --- a/classes/Dissolution.php +++ b/classes/Dissolution.php @@ -4,10 +4,10 @@ class Dissolution { public static function dates() { - $out = array(); + $out = []; $dates = array_filter(explode(',', DISSOLUTION_DATE)); foreach ($dates as $houseanddate) { - list ($house, $date) = explode(':', $houseanddate); + [$house, $date] = explode(':', $houseanddate); $out[$house] = $date; } return $out; @@ -18,16 +18,16 @@ public static function db() { return null; } - $params = array(); - $query = array(); + $params = []; + $query = []; foreach ($dates as $house => $date) { $params[":dissdate$house"] = $date; $query[] = "left_house = :dissdate$house"; } - return array( + return [ 'query' => '(' . join(' OR ', $query) . ')', 'params' => $params, - ); + ]; } } diff --git a/classes/Divisions.php b/classes/Divisions.php index 73d7ebc0af..586366c555 100644 --- a/classes/Divisions.php +++ b/classes/Divisions.php @@ -8,7 +8,6 @@ namespace MySociety\TheyWorkForYou; class Divisions { - /** * Member */ @@ -29,16 +28,15 @@ class Divisions { * @param Member $member The member to get positions for. */ - public function __construct(Member $member = null, PolicyPositions $positions = null) - { + public function __construct(Member $member = null, PolicyPositions $positions = null) { $this->member = $member; $this->positions = $positions; - $this->policies = new Policies; - $this->db = new \ParlDB; + $this->policies = new Policies(); + $this->db = new \ParlDB(); } public static function getMostRecentDivisionDate() { - $db = new \ParlDB; + $db = new \ParlDB(); $q = $db->query( "SELECT policy_id, max(division_date) as recent FROM policydivisions @@ -46,7 +44,7 @@ public static function getMostRecentDivisionDate() { GROUP BY policy_id" ); - $policy_maxes = array(); + $policy_maxes = []; foreach ($q as $row) { $policy_maxes[$row['policy_id']] = $row['recent']; } @@ -63,14 +61,14 @@ public function getRecentDivisions($number = 20, $houses = null) { $select = ''; $order = 'ORDER BY division_date DESC, division_number DESC'; $limit = 'LIMIT :count'; - $params = array( - ':count' => $number - ); + $params = [ + ':count' => $number, + ]; $where = []; if ($houses) { - if ( is_string($houses) ) { - $houses = array( $houses ); + if (is_string($houses)) { + $houses = [ $houses ]; } $where[] = 'house IN ("' . implode('", "', $houses) . '")'; } @@ -83,7 +81,7 @@ public function getRecentDivisions($number = 20, $houses = null) { } $where = 'WHERE ' . join(' AND ', $where); - if ( $this->member ) { + if ($this->member) { $select = "SELECT divisions.*, vote FROM divisions LEFT JOIN persondivisionvotes ON divisions.division_id=persondivisionvotes.division_id AND person_id=:person_id"; $params[':person_id'] = $this->member->person_id; @@ -96,7 +94,7 @@ public function getRecentDivisions($number = 20, $houses = null) { $params ); - $divisions = array(); + $divisions = []; foreach ($q as $division) { $data = $this->getParliamentDivisionDetails($division); @@ -122,7 +120,7 @@ public function getRecentDivisions($number = 20, $houses = null) { $divisions[] = $data; } - return array('divisions' => $divisions); + return ['divisions' => $divisions]; } /** @@ -157,10 +155,10 @@ public function getRecentDebatesWithDivisions($number = 20, $majors = null) { GROUP BY h.subsection_id ORDER BY h.hdate DESC, h.hpos DESC LIMIT :count", - array(':count' => $number) + [':count' => $number] ); - $debates = array(); + $debates = []; foreach ($q as $debate) { $debate_gid = fix_gid_from_db($debate['debate_gid']); $anchor = ''; @@ -168,7 +166,7 @@ public function getRecentDebatesWithDivisions($number = 20, $majors = null) { $anchor = '#g' . gid_to_anchor(fix_gid_from_db($debate['gid'])); } $url = new Url($hansardmajors[$debate['major']]['page']); - $url->insert(array('gid' => $debate_gid)); + $url->insert(['gid' => $debate_gid]); $debates[] = [ 'url' => $url->generate() . $anchor, 'title' => "$debate[section_body] : $debate[subsection_body]", @@ -180,9 +178,9 @@ public function getRecentDebatesWithDivisions($number = 20, $majors = null) { } public function getRecentDivisionsForPolicies($policies, $number = 20) { - $args = array(':number' => $number); + $args = [':number' => $number]; - $quoted = array(); + $quoted = []; foreach ($policies as $policy) { $quoted[] = $this->db->quote($policy); } @@ -198,9 +196,9 @@ public function getRecentDivisionsForPolicies($policies, $number = 20) { $args ); - $divisions = array(); + $divisions = []; foreach ($q as $row) { - $divisions[] = $this->getParliamentDivisionDetails($row); + $divisions[] = $this->getParliamentDivisionDetails($row); } return $divisions; @@ -222,8 +220,8 @@ public function getRecentDivisionsForPolicies($policies, $number = 20) { public function getMemberDivisionsForPolicy($policyID = null) { $where_extra = ''; - $args = array(':person_id' => $this->member->person_id); - if ( $policyID ) { + $args = [':person_id' => $this->member->person_id]; + if ($policyID) { $where_extra = 'AND policy_id = :policy_id'; $args[':policy_id'] = $policyID; } @@ -240,9 +238,9 @@ public function getMemberDivisionsForPolicy($policyID = null) { } public function getMemberDivisionDetails($strong_only = false) { - $args = array(':person_id' => $this->member->person_id); + $args = [':person_id' => $this->member->person_id]; - $policy_divisions = array(); + $policy_divisions = []; if ($strong_only) { $where_extra = "AND (policy_vote = 'no3' OR policy_vote = 'aye3')"; } else { @@ -259,54 +257,54 @@ public function getMemberDivisionDetails($strong_only = false) { ); foreach ($q as $row) { - $policy_id = $row['policy_id']; + $policy_id = $row['policy_id']; + + if (!array_key_exists($policy_id, $policy_divisions)) { + $summary = [ + 'max' => $row['latest'], + 'min' => $row['earliest'], + 'total' => $row['total'], + 'for' => 0, 'against' => 0, 'absent' => 0, 'both' => 0, 'tell' => 0, + ]; + + $policy_divisions[$policy_id] = $summary; + } - if (!array_key_exists($policy_id, $policy_divisions)) { - $summary = array( - 'max' => $row['latest'], - 'min' => $row['earliest'], - 'total' => $row['total'], - 'for' => 0, 'against' => 0, 'absent' => 0, 'both' => 0, 'tell' => 0 - ); + $summary = $policy_divisions[$policy_id]; + + $summary['total'] += $row['total']; + if ($summary['max'] < $row['latest']) { + $summary['max'] = $row['latest']; + } + if ($summary['min'] > $row['latest']) { + $summary['min'] = $row['latest']; + } + + $vote = $row['vote']; + $policy_vote = str_replace('3', '', $row['policy_vote']); + if ($vote == 'absent') { + $summary['absent'] += $row['total']; + } elseif ($vote == 'both') { + $summary['both'] += $row['total']; + } elseif (strpos($vote, 'tell') !== false) { + $summary['tell'] += $row['total']; + } elseif ($policy_vote == $vote) { + $summary['for'] += $row['total']; + } elseif ($policy_vote != $vote) { + $summary['against'] += $row['total']; + } $policy_divisions[$policy_id] = $summary; - } - - $summary = $policy_divisions[$policy_id]; - - $summary['total'] += $row['total']; - if ($summary['max'] < $row['latest']) { - $summary['max'] = $row['latest']; - } - if ($summary['min'] > $row['latest']) { - $summary['min'] = $row['latest']; - } - - $vote = $row['vote']; - $policy_vote = str_replace('3', '', $row['policy_vote']); - if ( $vote == 'absent' ) { - $summary['absent'] += $row['total']; - } else if ( $vote == 'both' ) { - $summary['both'] += $row['total']; - } else if ( strpos($vote, 'tell') !== false ) { - $summary['tell'] += $row['total']; - } else if ( $policy_vote == $vote ) { - $summary['for'] += $row['total']; - } else if ( $policy_vote != $vote ) { - $summary['against'] += $row['total']; - } - - $policy_divisions[$policy_id] = $summary; } // for each key in $policy_divisions, we want to add agreement information - + $policies_list = new \MySociety\TheyWorkForYou\Policies(); foreach ($policy_divisions as $policy_id => &$summary) { - $agreement_details = $this->member->member_agreements($policy_id, HOUSE_TYPE_COMMONS, $policies_list ); + $agreement_details = $this->member->member_agreements($policy_id, HOUSE_TYPE_COMMONS, $policies_list); $summary["agreements_for"] = 0; $summary["agreements_against"] = 0; - foreach ($agreement_details as $agreement){ + foreach ($agreement_details as $agreement) { if ($strong_only == true & $agreement["strength"] != "strong") { continue; } @@ -321,9 +319,9 @@ public function getMemberDivisionDetails($strong_only = false) { } public function getDivisionByGid($gid) { - $args = array( - ':gid' => $gid - ); + $args = [ + ':gid' => $gid, + ]; $q = $this->db->query("SELECT * FROM divisions WHERE gid = :gid", $args)->first(); if (!$q) { @@ -334,9 +332,9 @@ public function getDivisionByGid($gid) { } public function getDivisionResults($division_id) { - $args = array( - ':division_id' => $division_id - ); + $args = [ + ':division_id' => $division_id, + ]; $q = $this->db->query("SELECT * FROM divisions WHERE division_id = :division_id", $args)->first(); if (!$q) { @@ -367,19 +365,19 @@ private function _division_data($row) { $args ); - $votes = array( - 'yes_votes' => array(), - 'no_votes' => array(), - 'absent_votes' => array(), - 'both_votes' => array() - ); + $votes = [ + 'yes_votes' => [], + 'no_votes' => [], + 'absent_votes' => [], + 'both_votes' => [], + ]; - $party_breakdown = array( - 'yes_votes' => array(), - 'no_votes' => array(), - 'absent_votes' => array(), - 'both_votes' => array() - ); + $party_breakdown = [ + 'yes_votes' => [], + 'no_votes' => [], + 'absent_votes' => [], + 'both_votes' => [], + ]; # Sort Lords specially $data = $q->fetchAll(); @@ -388,14 +386,19 @@ private function _division_data($row) { } foreach ($data as $vote) { - $detail = array( - 'person_id' => $vote['person_id'], - 'name' => ucfirst(member_full_name($args['house'], $vote['title'], $vote['given_name'], - $vote['family_name'], $vote['lordofname'])), - 'party' => $vote['party'], - 'proxy' => false, - 'teller' => false - ); + $detail = [ + 'person_id' => $vote['person_id'], + 'name' => ucfirst(member_full_name( + $args['house'], + $vote['title'], + $vote['given_name'], + $vote['family_name'], + $vote['lordofname'] + )), + 'party' => $vote['party'], + 'proxy' => false, + 'teller' => false, + ]; if (strpos($vote['vote'], 'tell') !== false) { $detail['teller'] = true; @@ -410,34 +413,38 @@ private function _division_data($row) { [ ':person_id' => $vote['proxy'], ':division_date' => $row['division_date'] ] )->first(); $detail['proxy'] = ucfirst(member_full_name( - HOUSE_TYPE_COMMONS, $q['title'], $q['given_name'], - $q['family_name'], $q['lordofname'])); + HOUSE_TYPE_COMMONS, + $q['title'], + $q['given_name'], + $q['family_name'], + $q['lordofname'] + )); } if ($vote['vote'] == 'aye' or $vote['vote'] == 'tellaye') { - $votes['yes_votes'][] = $detail; - @$party_breakdown['yes_votes'][$detail['party']]++; - } else if ($vote['vote'] == 'no' or $vote['vote'] == 'tellno') { - $votes['no_votes'][] = $detail; - @$party_breakdown['no_votes'][$detail['party']]++; - } else if ($vote['vote'] == 'absent') { - $votes['absent_votes'][] = $detail; - @$party_breakdown['absent_votes'][$detail['party']]++; - } else if ($vote['vote'] == 'both') { - $votes['both_votes'][] = $detail; - @$party_breakdown['both_votes'][$detail['party']]++; + $votes['yes_votes'][] = $detail; + @$party_breakdown['yes_votes'][$detail['party']]++; + } elseif ($vote['vote'] == 'no' or $vote['vote'] == 'tellno') { + $votes['no_votes'][] = $detail; + @$party_breakdown['no_votes'][$detail['party']]++; + } elseif ($vote['vote'] == 'absent') { + $votes['absent_votes'][] = $detail; + @$party_breakdown['absent_votes'][$detail['party']]++; + } elseif ($vote['vote'] == 'both') { + $votes['both_votes'][] = $detail; + @$party_breakdown['both_votes'][$detail['party']]++; } } foreach ($votes as $vote => $count) { // array('yes_votes', 'no_votes', 'absent_votes', 'both_votes') as $vote) { - $votes[$vote . '_by_party'] = $votes[$vote]; - usort($votes[$vote . '_by_party'], function ($a, $b) { - return $a['party']>$b['party']; + $votes[$vote . '_by_party'] = $votes[$vote]; + usort($votes[$vote . '_by_party'], function ($a, $b) { + return $a['party'] > $b['party']; }); } foreach ($party_breakdown as $vote => $parties) { - $summary = array(); + $summary = []; foreach ($parties as $party => $count) { array_push($summary, "$party: $count"); } @@ -456,10 +463,10 @@ private function _division_data($row) { } public function getDivisionResultsForMember($division_id, $person_id) { - $args = array( + $args = [ ':division_id' => $division_id, - ':person_id' => $person_id - ); + ':person_id' => $person_id, + ]; $q = $this->db->query( "SELECT division_id, division_title, yes_text, no_text, division_date, division_number, gid, vote FROM divisions JOIN persondivisionvotes USING(division_id) @@ -481,23 +488,23 @@ public function generateSummary($votes) { $max = $votes['max']; $min = $votes['min']; - $actions = array( + $actions = [ $votes['for'] . ' ' . make_plural('vote', $votes['for']) . ' for', - $votes['against'] . ' ' . make_plural('vote', $votes['against']) . ' against' - ); + $votes['against'] . ' ' . make_plural('vote', $votes['against']) . ' against', + ]; - if ( $votes['agreements_for']) { + if ($votes['agreements_for']) { $actions[] = $votes['agreements_for'] . ' ' . make_plural('agreement', $votes['agreements_for']) . ' for'; } - if ( $votes['agreements_against']) { + if ($votes['agreements_against']) { $actions[] = $votes['agreements_against'] . ' ' . make_plural('agreement', $votes['agreements_against']) . ' against'; } - if ( $votes['both'] ) { + if ($votes['both']) { $actions[] = $votes['both'] . ' ' . make_plural('abstention', $votes['both']); } - if ( $votes['absent'] ) { + if ($votes['absent']) { $actions[] = $votes['absent'] . ' ' . make_plural('absence', $votes['absent']); } if ($max == $min) { @@ -535,7 +542,7 @@ public function getAllMemberDivisionsByPolicy() { * Returns an array of divisions */ public function getRecentMemberDivisions($number = 20) { - $args = array(':person_id' => $this->member->person_id, ':number' => $number); + $args = [':person_id' => $this->member->person_id, ':number' => $number]; $q = $this->db->query( "SELECT * FROM persondivisionvotes @@ -545,7 +552,7 @@ public function getRecentMemberDivisions($number = 20) { $args ); - $divisions = array(); + $divisions = []; foreach ($q as $row) { $divisions[] = $this->getDivisionDetails($row); } @@ -555,7 +562,7 @@ public function getRecentMemberDivisions($number = 20) { private function constructYesNoVoteDescription($direction, $title, $short_text) { $text = ' ' ; - if ( $short_text ) { + if ($short_text) { $text .= sprintf(gettext('voted %s'), $short_text); } else { $text .= sprintf(gettext('voted %s on %s'), $direction, $title); @@ -572,7 +579,7 @@ private function constructVoteDescription($vote, $yes_text, $no_text, $division_ * votes so we need to generate some text using the title of the division */ - switch ( strtolower($vote) ) { + switch (strtolower($vote)) { case 'yes': case 'aye': $description = $this->constructYesNoVoteDescription('yes', $division_title, $yes_text); @@ -602,7 +609,7 @@ private function getBasicDivisionDetails($row, $vote) { $yes_text = $row['yes_text']; $no_text = $row['no_text']; - $division = array( + $division = [ 'division_id' => $row['division_id'], 'date' => $row['division_date'], 'gid' => fix_gid_from_db($row['gid']), @@ -610,7 +617,7 @@ private function getBasicDivisionDetails($row, $vote) { 'text' => $this->constructVoteDescription($vote, $yes_text, $no_text, $row['division_title']), 'has_description' => $yes_text && $no_text, 'vote' => $vote, - ); + ]; if ($row['gid']) { $division['debate_url'] = $this->divisionUrlFromGid($row['gid']); @@ -628,22 +635,22 @@ private function getBasicDivisionDetails($row, $vote) { "SELECT policy_id, direction FROM policydivisions WHERE division_id = :division_id", - array(':division_id' => $row['division_id']) + [':division_id' => $row['division_id']] ); - $division['related_policies'] = array(); + $division['related_policies'] = []; $policy_lookup = $this->policies->getPolicies(); foreach ($q as $policy) { - $division['related_policies'][] = array( + $division['related_policies'][] = [ 'policy_id' => $policy['policy_id'], 'policy_title' => preg_replace('#]*>#', '', $policy_lookup[$policy['policy_id']]), 'direction' => $policy['direction'], - ); + ]; } if (array_key_exists('direction', $row)) { $division['direction'] = $row['direction']; - if ( strpos( $row['direction'], 'strong') !== false ) { + if (strpos($row['direction'], 'strong') !== false) { $division['strong'] = true; } else { $division['strong'] = false; @@ -670,7 +677,7 @@ private function getParliamentDivisionDetails($row) { } private function divisionsByPolicy($q) { - $policies = array(); + $policies = []; # iterate through each division, and adds it to an array of policies # if there is only one policy being queried, it will be an array of 1 @@ -678,19 +685,19 @@ private function divisionsByPolicy($q) { $policy_id = $row['policy_id']; # if this policy hasn't come up yet, create the key for it - if ( !array_key_exists($policy_id, $policies) ) { - $policies[$policy_id] = array( + if (!array_key_exists($policy_id, $policies)) { + $policies[$policy_id] = [ 'policy_id' => $policy_id, - 'divisions' => array() - ); + 'divisions' => [], + ]; $policies[$policy_id]['desc'] = $this->policies->getPolicies()[$policy_id]; $policies[$policy_id]['header'] = $this->policies->getPolicyDetails($policy_id); - if ( $this->positions ) { + if ($this->positions) { $policies[$policy_id]['position'] = $this->positions->positionsById[$policy_id]; } } - + $division = $this->getDivisionDetails($row); $policies[$policy_id]['divisions'][] = $division; @@ -704,13 +711,13 @@ private function divisionUrlFromGid($gid) { $gid = get_canonical_gid($gid); - $q = $this->db->query("SELECT gid, major FROM hansard WHERE epobject_id = ( SELECT subsection_id FROM hansard WHERE gid = :gid )", array( ':gid' => $gid ))->first(); + $q = $this->db->query("SELECT gid, major FROM hansard WHERE epobject_id = ( SELECT subsection_id FROM hansard WHERE gid = :gid )", [ ':gid' => $gid ])->first(); if (!$q) { return ''; } $parent_gid = fix_gid_from_db($q['gid']); $url = new Url($hansardmajors[$q['major']]['page']); - $url->insert(array('gid' => $parent_gid)); + $url->insert(['gid' => $parent_gid]); return $url->generate() . '#g' . gid_to_anchor(fix_gid_from_db($gid)); } } diff --git a/classes/EditQueue.php b/classes/EditQueue.php index bcd3ef0700..b93b567469 100644 --- a/classes/EditQueue.php +++ b/classes/EditQueue.php @@ -54,11 +54,10 @@ // [TODO] what happens when two things with the same name are in the editqueue? class EditQueue { - public $pending_count = ''; public function __construct() { - $this->db = new \ParlDB; + $this->db = new \ParlDB(); } public function add($data) { @@ -108,8 +107,8 @@ public function add($data) { } public function approve($data) { - // Approve items for inclusion - // Create new epobject and update the editqueue + // Approve items for inclusion + // Create new epobject and update the editqueue global $THEUSER; @@ -155,20 +154,22 @@ public function approve($data) { case EPTYPE_GLOSSARY: $previous_insert_id = $q->insert_id(); - $q = $this->db->query('INSERT INTO glossary + $q = $this->db->query( + 'INSERT INTO glossary (epobject_id, type, visible) VALUES (:id, :type, :enabled);', - array( - ':id' => $q->insert_id(), - ':type' => EPTYPE_GLOSSARY, - ':enabled' => 1, - )); + [ + ':id' => $q->insert_id(), + ':type' => EPTYPE_GLOSSARY, + ':enabled' => 1, + ] + ); // Again, no point carrying on if this fails, // so remove the previous entry if (!$q->success()) { print "glossary trouble!"; - $this->db->query('DELETE FROM epobject WHERE epobject_id=:id ;', array(':id' => $previous_insert_id)); + $this->db->query('DELETE FROM epobject WHERE epobject_id=:id ;', [':id' => $previous_insert_id]); return false; } break; @@ -178,20 +179,22 @@ public function approve($data) { // Then finally update the editqueue with // the new epobject id and approval details. - $q = $this->db->query('UPDATE editqueue + $q = $this->db->query( + 'UPDATE editqueue SET epobject_id_l=:current, editor_id=:editor, approved=:approved, decided=:timestamp WHERE edit_id=:approval_id ;', - array( - ':current' => $this->current_epobject_id, - ':editor' => addslashes($THEUSER->user_id()), - ':approved' => '1', - ':timestamp' => $timestamp, - ':approval_id' => $approval_id - )); + [ + ':current' => $this->current_epobject_id, + ':editor' => addslashes($THEUSER->user_id()), + ':approved' => '1', + ':timestamp' => $timestamp, + ':approval_id' => $approval_id, + ] + ); if (!$q->success()) { break; } else { @@ -199,7 +202,7 @@ public function approve($data) { // Scrub that one from the list of pending items - unset ($this->pending[$approval_id]); + unset($this->pending[$approval_id]); } } @@ -209,7 +212,7 @@ public function approve($data) { } public function decline($data) { - // Decline a list of term submissions from users + // Decline a list of term submissions from users global $THEUSER; @@ -237,7 +240,7 @@ public function decline($data) { break; } else { // Scrub that one from the list of pending items - unset ($this->pending[$decline_id]); + unset($this->pending[$decline_id]); } } @@ -248,9 +251,9 @@ public function decline($data) { } public function get_pending() { - // Fetch all pending editqueue items. - // Sets $this->pending and returns a body count. - // Return organised by type? - maybe not for the moment + // Fetch all pending editqueue items. + // Sets $this->pending and returns a body count. + // Return organised by type? - maybe not for the moment $q = $this->db->query("SELECT eq.edit_id, eq.user_id, u.firstname, u.lastname, eq.glossary_id, eq.title, eq.body, eq.submitted FROM editqueue AS eq, users AS u WHERE eq.user_id = u.user_id AND eq.approved IS NULL ORDER BY eq.submitted DESC;"); if ($q->success() && $q->rows()) { @@ -267,27 +270,27 @@ public function get_pending() { } public function display() { - // Print all our pending items out in a nice list or something - // Add links later for "approve, decline, refer" - // Just get the fucker working for now + // Print all our pending items out in a nice list or something + // Add links later for "approve, decline, refer" + // Just get the fucker working for now - $URL = new Url('admin_glossary_pending'); - $URL->reset(); - $form_link = $URL->generate('url'); + $URL = new Url('admin_glossary_pending'); + $URL->reset(); + $form_link = $URL->generate('url'); ?>
pending as $editqueue_id => $pender) { $URL = new Url('admin_glossary_pending'); - $URL->insert(array('approve' => $editqueue_id)); + $URL->insert(['approve' => $editqueue_id]); $approve_link = $URL->generate('url'); $URL = new Url('admin_glossary_pending'); - $URL->insert(array('modify' => $editqueue_id)); + $URL->insert(['modify' => $editqueue_id]); $modify_link = $URL->generate('url'); $URL = new Url('admin_glossary_pending'); - $URL->insert(array('decline' => $editqueue_id)); + $URL->insert(['decline' => $editqueue_id]); $decline_link = $URL->generate('url'); ?>
diff --git a/classes/FacebookLogin.php b/classes/FacebookLogin.php index 339359dbc3..216a55b085 100644 --- a/classes/FacebookLogin.php +++ b/classes/FacebookLogin.php @@ -39,7 +39,7 @@ public function getLoginURL() { public function handleFacebookRedirect() { $helper = $this->getFacebookObject()->getRedirectLoginHelper(); - $data = array('login_url' => $this->getLoginURL()); + $data = ['login_url' => $this->getLoginURL()]; try { $accessToken = $helper->getAccessToken(); @@ -54,7 +54,7 @@ public function handleFacebookRedirect() { $token = $this->checkAccessToken($accessToken); if ($token) { - return array('token' => $token); + return ['token' => $token]; } else { $data['error'] = 'Problem getting Facebook token'; return $data; @@ -127,7 +127,7 @@ public function createUser($accessToken, $user) { $first_name = array_shift($name_parts); $last_name = implode(' ', $name_parts); global $THEUSER; - $details = array( + $details = [ 'firstname' => $first_name, 'lastname' => $last_name, 'email' => $user['email'], @@ -137,8 +137,8 @@ public function createUser($accessToken, $user) { 'password' => '', 'optin' => false, 'mp_alert' => false, - 'facebook_id' => $user['id'] - ); + 'facebook_id' => $user['id'], + ]; $added = $THEUSER->add($details, false); if ($added) { twfy_debug("THEUSER", "Added new user from facebook details " . $THEUSER->user_id()); @@ -155,7 +155,7 @@ public function updateUser($user) { $first_name = array_shift($name_parts); $last_name = implode(' ', $name_parts); - $details = array( + $details = [ 'firstname' => $first_name, 'lastname' => $last_name, 'email' => $user['email'], @@ -163,7 +163,7 @@ public function updateUser($user) { 'url' => $THEUSER->url(), 'optin' => $THEUSER->optin(), 'password' => '', - ); + ]; $THEUSER->update_self_no_confirm($details); } diff --git a/classes/Gid.php b/classes/Gid.php index f17f464b17..6878b0aab9 100644 --- a/classes/Gid.php +++ b/classes/Gid.php @@ -3,19 +3,18 @@ namespace MySociety\TheyWorkForYou; class Gid { - public $gid; private $db; public function __construct($gid) { $this->gid = $gid; - $this->db = new \ParlDB; + $this->db = new \ParlDB(); } public function checkForRedirect() { $q = $this->db->query( "SELECT gid_to FROM gidredirect WHERE gid_from = :gid", - array(':gid' => $this->gid) + [':gid' => $this->gid] )->first(); if (!$q) { @@ -25,7 +24,7 @@ public function checkForRedirect() { $gid = $q['gid_to']; $q = $this->db->query( "SELECT gid_to FROM gidredirect WHERE gid_from = :gid", - array(':gid' => $gid) + [':gid' => $gid] )->first(); } while ($q); return $gid; diff --git a/classes/GlossaryEditQueue.php b/classes/GlossaryEditQueue.php index 2c904761c9..6d84493a26 100644 --- a/classes/GlossaryEditQueue.php +++ b/classes/GlossaryEditQueue.php @@ -13,10 +13,9 @@ // Glossary overrides class GlossaryEditQueue extends EditQueue { - public function approve($data) { - // Approve items for inclusion - // Create new epobject and update the editqueue + // Approve items for inclusion + // Create new epobject and update the editqueue global $THEUSER; @@ -61,7 +60,7 @@ public function approve($data) { // the new epobject id and approval details. $q = $this->db->query("UPDATE editqueue SET - glossary_id='" . $this->current_epobject_id. "', + glossary_id='" . $this->current_epobject_id . "', editor_id='" . addslashes($THEUSER->user_id()) . "', approved='1', decided='" . $timestamp . "' @@ -70,7 +69,7 @@ public function approve($data) { break; } else { // Scrub that one from the list of pending items - unset ($this->pending[$approval_id]); + unset($this->pending[$approval_id]); } } diff --git a/classes/Hansard.php b/classes/Hansard.php index 13cf1802ca..1686740722 100644 --- a/classes/Hansard.php +++ b/classes/Hansard.php @@ -7,7 +7,6 @@ */ class Hansard extends \HANSARDLIST { - /** * Search * diff --git a/classes/Homepage.php b/classes/Homepage.php index 13aeda313b..b442bfd813 100644 --- a/classes/Homepage.php +++ b/classes/Homepage.php @@ -3,35 +3,34 @@ namespace MySociety\TheyWorkForYou; class Homepage { - private $db; protected $mp_house = 1; protected $cons_type = 'WMC'; protected $mp_url = 'yourmp'; protected $page = 'overview'; - protected $houses = array(1, 101); + protected $houses = [1, 101]; - protected $recent_types = array( - 'DEBATELIST' => array('recent_debates', 'debatesfront', 'Commons debates'), - 'LORDSDEBATELIST' => array('recent_debates', 'lordsdebatesfront', 'Lords debates'), - 'WHALLLIST' => array('recent_debates', 'whallfront', 'Westminster Hall debates'), - 'WMSLIST' => array('recent_wms', 'wmsfront', 'Written ministerial statements'), - 'WRANSLIST' => array('recent_wrans', 'wransfront', 'Written answers'), - 'StandingCommittee' => array('recent_pbc_debates', 'pbcfront', 'Public Bill committees') - ); + protected $recent_types = [ + 'DEBATELIST' => ['recent_debates', 'debatesfront', 'Commons debates'], + 'LORDSDEBATELIST' => ['recent_debates', 'lordsdebatesfront', 'Lords debates'], + 'WHALLLIST' => ['recent_debates', 'whallfront', 'Westminster Hall debates'], + 'WMSLIST' => ['recent_wms', 'wmsfront', 'Written ministerial statements'], + 'WRANSLIST' => ['recent_wrans', 'wransfront', 'Written answers'], + 'StandingCommittee' => ['recent_pbc_debates', 'pbcfront', 'Public Bill committees'], + ]; public function __construct() { - $this->db = new \ParlDB; + $this->db = new \ParlDB(); } public function display() { global $this_page; $this_page = $this->page; - $data = array(); + $data = []; - $common = new Common; + $common = new Common(); $dissolution = Dissolution::dates(); $data['debates'] = $this->getDebatesData(); @@ -52,7 +51,7 @@ public function display() { return $data; } - protected function getSearchBox(array $data): Search\SearchBox{ + protected function getSearchBox(array $data): Search\SearchBox { $search_box = new Search\SearchBox(); $search_box->homepage_panel_class = "panel--homepage--overall"; $search_box->homepage_subhead = ""; @@ -74,27 +73,27 @@ protected function getRegionalList() { } protected function getEditorialContent() { - $debatelist = new \DEBATELIST; - $featured = new Model\Featured; + $debatelist = new \DEBATELIST(); + $featured = new Model\Featured(); $gid = $featured->get_gid(); $gidCheck = new Gid($gid); $gid = $gidCheck->checkForRedirect(); - if ( $gid ) { + if ($gid) { $title = $featured->get_title(); $context = $featured->get_context(); $related = $featured->get_related(); $item = $this->getFeaturedDebate($gid, $title, $context, $related); } else { - $item = $debatelist->display('recent_debates', array('days' => 7, 'num' => 1), 'none'); - if ( isset($item['data']) && count($item['data']) ) { + $item = $debatelist->display('recent_debates', ['days' => 7, 'num' => 1], 'none'); + if (isset($item['data']) && count($item['data'])) { $item = $item['data'][0]; $more_url = new Url('debates'); $item['more_url'] = $more_url->generate(); $item['desc'] = 'Commons Debates'; - $item['related'] = array(); + $item['related'] = []; $item['featured'] = false; } else { - $item = array(); + $item = []; } } @@ -103,23 +102,23 @@ protected function getEditorialContent() { public function getFeaturedDebate($gid, $title, $context, $related) { if (strpos($gid, 'lords') !== false) { - $debatelist = new \LORDSDEBATELIST; + $debatelist = new \LORDSDEBATELIST(); } elseif (strpos($gid, 'westminhall') !== false) { - $debatelist = new \WHALLLIST; + $debatelist = new \WHALLLIST(); } else { - $debatelist = new \DEBATELIST; + $debatelist = new \DEBATELIST(); } - $item = $debatelist->display('featured_gid', array('gid' => $gid), 'none'); + $item = $debatelist->display('featured_gid', ['gid' => $gid], 'none'); $item = $item['data']; $item['headline'] = $title; $item['context'] = $context; $item['featured'] = true; - $related_debates = array(); - foreach ( $related as $related_gid ) { - if ( $related_gid ) { - $related_item = $debatelist->display('featured_gid', array('gid' => $related_gid), 'none'); + $related_debates = []; + foreach ($related as $related_gid) { + if ($related_gid) { + $related_item = $debatelist->display('featured_gid', ['gid' => $related_gid], 'none'); $related_debates[] = $related_item['data']; } } @@ -138,31 +137,31 @@ private function getRecentDivisions() { } protected function getURLs() { - $urls = array(); + $urls = []; return $urls; } protected function getDebatesData() { - $debates = array(); // holds the most recent data there is data for, indexed by type + $debates = []; // holds the most recent data there is data for, indexed by type - $recent_content = array(); + $recent_content = []; - foreach ( $this->recent_types as $class => $recent ) { + foreach ($this->recent_types as $class => $recent) { $class = "\\$class"; $instance = new $class(); $more_url = new Url($recent[1]); - if ( $recent[0] == 'recent_pbc_debates' ) { - $content = array( 'data' => $instance->display($recent[0], array('num' => 5), 'none') ); + if ($recent[0] == 'recent_pbc_debates') { + $content = [ 'data' => $instance->display($recent[0], ['num' => 5], 'none') ]; } else { - $content = $instance->display($recent[0], array('days' => 7, 'num' => 1), 'none'); - if ( isset($content['data']) && count($content['data']) ) { + $content = $instance->display($recent[0], ['days' => 7, 'num' => 1], 'none'); + if (isset($content['data']) && count($content['data'])) { $content = $content['data'][0]; } else { - $content = array(); + $content = []; } } - if ( $content ) { + if ($content) { $content['more_url'] = $more_url->generate(); $content['desc'] = $recent[2]; $recent_content[] = $content; diff --git a/classes/Member.php b/classes/Member.php index a2f6b86834..943afef938 100644 --- a/classes/Member.php +++ b/classes/Member.php @@ -12,7 +12,6 @@ */ class Member extends \MEMBER { - /** * Is Dead * @@ -30,14 +29,14 @@ public function isDead() { // This member has left a house, and might be dead. See if they are. // Types of house to test for death. - $house_types = array( + $house_types = [ HOUSE_TYPE_COMMONS, HOUSE_TYPE_LORDS, HOUSE_TYPE_SCOTLAND, HOUSE_TYPE_NI, HOUSE_TYPE_WALES, HOUSE_TYPE_LONDON_ASSEMBLY, - ); + ]; foreach ($house_types as $house_type) { @@ -63,15 +62,15 @@ public function isDead() { public function cohortPartyComparisonDirection() { // Is this MP and their cohort compared against the // first or last party they have? - // By default, mirroring the partycohort query, - // this is the first party. + // By default, mirroring the partycohort query, + // this is the first party. // However, this is ignored for the Speaker, and additional // individual overrides can be added below. // This makes most sense when a party switch was a long time ago. - // As long as this person is in a cohort of 1 and has a unique set + // As long as this person is in a cohort of 1 and has a unique set // of memberships (which is likely for edge cases) it doesn't matter // that their original party is what is used when in the party cohort - // construction query. + // construction query. $person_id = $this->person_id(); @@ -82,7 +81,7 @@ public function cohortPartyComparisonDirection() { // MPs who have switched parties but should be compared against their // current party can go here. - $use_last_party = array(10172, 14031, 25873, 10218); + $use_last_party = [10172, 14031, 25873, 10218]; if (in_array($person_id, $use_last_party)) { $direction = "last"; @@ -91,23 +90,23 @@ public function cohortPartyComparisonDirection() { return $direction; } - public function currentPartyComparison(){ + public function currentPartyComparison() { # Simplify the current party when being compared to the original # Stops co-op and labour being seen as different $party = $this->party; - if ( $party == 'Labour/Co-operative' ) { + if ($party == 'Labour/Co-operative') { $party = 'Labour'; } return $party; } - public function cohortParty($house = HOUSE_TYPE_COMMONS){ + public function cohortParty($house = HOUSE_TYPE_COMMONS) { // The party being compared against for party comparison purposes // Unless specified by the condition in cohortPartyComparisonDirection // This is the first, not last, party a person has. $person_id = $this->person_id(); - $db = new \ParlDB; + $db = new \ParlDB(); $cohort_direction = $this->cohortPartyComparisonDirection(); @@ -122,11 +121,11 @@ public function cohortParty($house = HOUSE_TYPE_COMMONS){ and person_id = :person_id and party != '' order by entered_house - " . $direction, array(":house" => $house, - ":person_id" => $person_id))->first(); + " . $direction, [":house" => $house, + ":person_id" => $person_id])->first(); if ($row) { $party = $row["party"]; - if ( $party == 'Labour/Co-operative' ) { + if ($party == 'Labour/Co-operative') { $party = 'Labour'; } elseif ($party == 'Sinn Féin') { $party = 'Sinn Fein'; @@ -156,7 +155,7 @@ public function isNew($house = HOUSE_TYPE_COMMONS) { $now = new \DateTime(); $diff = $date_entered->diff($now); - if ( $diff->y == 0 && $diff->m <= 6 ) { + if ($diff->y == 0 && $diff->m <= 6) { return true; } } @@ -177,7 +176,7 @@ public function getEntryDate($house = HOUSE_TYPE_COMMONS) { $entered_house = $this->entered_house($house); - if ( $entered_house ) { + if ($entered_house) { $date_entered = $entered_house['date']; } @@ -197,7 +196,7 @@ public function getLeftDate($house = HOUSE_TYPE_COMMONS) { $left_house = $this->left_house($house); - if ( $left_house ) { + if ($left_house) { $date_left = $left_house['date']; } @@ -225,9 +224,9 @@ public function image() { $is_lord = $this->house(HOUSE_TYPE_LORDS); if ($is_lord) { - list($image,$size) = Utility\Member::findMemberImage($this->person_id(), false, 'lord'); + [$image, $size] = Utility\Member::findMemberImage($this->person_id(), false, 'lord'); } else { - list($image,$size) = Utility\Member::findMemberImage($this->person_id(), false, true); + [$image, $size] = Utility\Member::findMemberImage($this->person_id(), false, true); } // We can determine if the image exists or not by testing if size is set @@ -237,11 +236,11 @@ public function image() { $exists = false; } - return array( + return [ 'url' => $image, 'size' => $size, - 'exists' => $exists - ); + 'exists' => $exists, + ]; } @@ -251,9 +250,9 @@ public function getMostRecentMembership() { usort( $departures, function ($a, $b) { - if ( $a['date'] == $b['date'] ) { + if ($a['date'] == $b['date']) { return 0; - } else if ( $a['date'] < $b['date'] ) { + } elseif ($a['date'] < $b['date']) { return -1; } else { return 1; @@ -284,14 +283,14 @@ function ($a, $b) { public function offices($include_only = null, $ignore_committees = false) { - $out = array(); + $out = []; if (array_key_exists('office', $this->extra_info())) { $office = $this->extra_info(); $office = $office['office']; foreach ($office as $row) { - if ( $officeObject = $this->getOfficeObject($include_only, $ignore_committees, $row) ) { + if ($officeObject = $this->getOfficeObject($include_only, $ignore_committees, $row)) { $out[] = $officeObject; } } @@ -309,7 +308,7 @@ private function getOfficeObject($include_only, $ignore_committees, $row) { return null; } - $officeObject = new Office; + $officeObject = new Office(); $officeObject->title = prettify_office($row['position'], $row['dept']); $officeObject->from_date = $row['from_date']; $officeObject->to_date = $row['to_date']; @@ -345,7 +344,7 @@ public function getOtherPartiesString() { if (!empty($this->other_parties) && $this->party != 'Speaker' && $this->party != 'Deputy Speaker') { $output = 'Party was '; - $other_parties = array(); + $other_parties = []; foreach ($this->other_parties as $r) { $other_parties[] = $r['from'] . ' until ' . format_date($r['date'], SHORTDATEFORMAT); } @@ -385,7 +384,7 @@ public function getOtherConstituenciesString() { * @return array An array of strings of when this member entered or left houses. */ public function getEnterLeaveStrings() { - $output = array(); + $output = []; $output[] = $this->entered_house_line(HOUSE_TYPE_LORDS, gettext('House of Lords')); @@ -430,7 +429,7 @@ public function getEnterLeaveStrings() { private function entered_house_line($house, $house_name) { if (isset($this->entered_house[$house]['date'])) { $string = ""; - if (strlen($this->entered_house[$house]['date_pretty'])==4) { + if (strlen($this->entered_house[$house]['date_pretty']) == 4) { $string .= sprintf(gettext("Entered the %s in %s"), $house_name, $this->entered_house[$house]['date_pretty']); } else { $string .= sprintf(gettext("Entered the %s on %s"), $house_name, $this->entered_house[$house]['date_pretty']); @@ -446,7 +445,7 @@ private function entered_house_line($house, $house_name) { private function left_house_line($house, $house_name) { if ($this->house($house) && !$this->current_member($house)) { $string = ""; - if (strlen($this->left_house[$house]['date_pretty'])==4) { + if (strlen($this->left_house[$house]['date_pretty']) == 4) { $string .= sprintf(gettext("Left the %s in %s"), $house_name, $this->left_house[$house]['date_pretty']); } else { $string .= sprintf(gettext("Left the %s on %s"), $house_name, $this->left_house[$house]['date_pretty']); @@ -460,15 +459,15 @@ private function left_house_line($house, $house_name) { } public function getPartyPolicyDiffs($partyCohort, $policiesList, $positions) { - $policy_diffs = array(); + $policy_diffs = []; $party_positions = $partyCohort->getAllPolicyPositions($policiesList); - if ( !$party_positions ) { + if (!$party_positions) { return $policy_diffs; } - foreach ( $positions->positionsById as $policy_id => $details ) { - if ( $details['has_strong'] && $details['score'] != -1 && isset($party_positions[$policy_id])) { + foreach ($positions->positionsById as $policy_id => $details) { + if ($details['has_strong'] && $details['score'] != -1 && isset($party_positions[$policy_id])) { $mp_score = $details['score']; $party_position = $party_positions[$policy_id]; $party_score = $party_position['score']; @@ -493,25 +492,25 @@ public function getPartyPolicyDiffs($partyCohort, $policiesList, $positions) { } } - uasort($policy_diffs, function($a, $b) { + uasort($policy_diffs, function ($a, $b) { return $b['score_difference'] - $a['score_difference']; }); return $policy_diffs; } - private function calculatePolicyDiffScore( $mp_score, $party_score ) { + private function calculatePolicyDiffScore($mp_score, $party_score) { $score_diff = abs($mp_score - $party_score); // if they are on opposite sides of mixture of for and against if ( - ( $mp_score < 0.4 && $party_score > 0.6 ) || - ( $mp_score > 0.6 && $party_score < 0.4 ) + ($mp_score < 0.4 && $party_score > 0.6) || + ($mp_score > 0.6 && $party_score < 0.4) ) { $score_diff += 2; - // if on is mixture of for and against and one is for/against - } else if ( - ( $mp_score > 0.4 && $mp_score < 0.6 && ( $party_score > 0.6 || $party_score < 0.4 ) ) || - ( $party_score > 0.4 && $party_score < 0.6 && ( $mp_score > 0.6 || $mp_score < 0.4 ) ) + // if on is mixture of for and against and one is for/against + } elseif ( + ($mp_score > 0.4 && $mp_score < 0.6 && ($party_score > 0.6 || $party_score < 0.4)) || + ($party_score > 0.4 && $party_score < 0.6 && ($mp_score > 0.6 || $mp_score < 0.4)) ) { $score_diff += 1; } @@ -520,11 +519,11 @@ private function calculatePolicyDiffScore( $mp_score, $party_score ) { } public static function getRegionalList($postcode, $house, $type) { - $db = new \ParlDB; + $db = new \ParlDB(); - $mreg = array(); + $mreg = []; $constituencies = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($postcode); - if ( isset($constituencies[$type]) ) { + if (isset($constituencies[$type])) { $cons_name = $constituencies[$type]; $query_base = "SELECT member.person_id, title, lordofname, given_name, family_name, constituency, house FROM member, person_names @@ -535,29 +534,31 @@ public static function getRegionalList($postcode, $house, $type) { AND house = :house AND left_house >= start_date AND left_house <= end_date"; - $q = $db->query("$query_base AND left_reason = 'still_in_office'", - array( + $q = $db->query( + "$query_base AND left_reason = 'still_in_office'", + [ ':house' => $house, - ':cons_name' => $cons_name - ) + ':cons_name' => $cons_name, + ] ); - if ( !$q->rows() && ($dissolution = Dissolution::db()) ) { - $q = $db->query("$query_base AND $dissolution[query]", - array( + if (!$q->rows() && ($dissolution = Dissolution::db())) { + $q = $db->query( + "$query_base AND $dissolution[query]", + [ ':house' => $house, ':cons_name' => $cons_name, - ) + $dissolution['params'] + ] + $dissolution['params'] ); } foreach ($q as $row) { $name = member_full_name($house, $row['title'], $row['given_name'], $row['family_name'], $row['lordofname']); - $mreg[] = array( + $mreg[] = [ 'person_id' => $row['person_id'], 'name' => $name, 'house' => $row['house'], - 'constituency' => gettext($row['constituency']) - ); + 'constituency' => gettext($row['constituency']), + ]; } } @@ -565,7 +566,7 @@ public static function getRegionalList($postcode, $house, $type) { } public static function getRepNameForHouse($house) { - switch ( $house ) { + switch ($house) { case HOUSE_TYPE_COMMONS: $name = 'MP'; break; diff --git a/classes/MemberException.php b/classes/MemberException.php index 6da5d3f844..be6eb78e3f 100644 --- a/classes/MemberException.php +++ b/classes/MemberException.php @@ -8,6 +8,4 @@ * For when something has gone wrong identifying a member. */ -class MemberException extends \Exception { - -} +class MemberException extends \Exception {} diff --git a/classes/Memcache.php b/classes/Memcache.php index e78f9b47ba..5d29ce80cc 100644 --- a/classes/Memcache.php +++ b/classes/Memcache.php @@ -9,16 +9,15 @@ namespace MySociety\TheyWorkForYou; class Memcache { - - static $memcache; + public static $memcache; public function __construct() { if (!self::$memcache) { if (class_exists('\Memcached')) { - self::$memcache = new \Memcached; + self::$memcache = new \Memcached(); self::$memcache->addServer(OPTION_TWFY_MEMCACHED_HOST, OPTION_TWFY_MEMCACHED_PORT); } elseif (class_exists('\Memcache')) { - self::$memcache = new \Memcache; + self::$memcache = new \Memcache(); self::$memcache->connect(OPTION_TWFY_MEMCACHED_HOST, OPTION_TWFY_MEMCACHED_PORT); } } @@ -29,9 +28,9 @@ public function set($key, $value, $timeout = 3600) { return; } if (class_exists('\Memcached')) { - self::$memcache->set(OPTION_TWFY_DB_NAME.':'.$key, $value, $timeout); + self::$memcache->set(OPTION_TWFY_DB_NAME . ':' . $key, $value, $timeout); } else { - self::$memcache->set(OPTION_TWFY_DB_NAME.':'.$key, $value, MEMCACHE_COMPRESSED, $timeout); + self::$memcache->set(OPTION_TWFY_DB_NAME . ':' . $key, $value, MEMCACHE_COMPRESSED, $timeout); } } @@ -39,9 +38,9 @@ public function get($key) { // see http://php.net/manual/en/memcache.get.php#112056 for explanation of this $was_found = false; if (class_exists('\Memcached')) { - $value = self::$memcache->get(OPTION_TWFY_DB_NAME.':'.$key, null, $was_found); + $value = self::$memcache->get(OPTION_TWFY_DB_NAME . ':' . $key, null, $was_found); } elseif (class_exists('\Memcache')) { - $value = self::$memcache->get(OPTION_TWFY_DB_NAME.':'.$key, $was_found); + $value = self::$memcache->get(OPTION_TWFY_DB_NAME . ':' . $key, $was_found); } if ($was_found === false) { return false; // mmmmm diff --git a/classes/Model/AnnouncementManagement.php b/classes/Model/AnnouncementManagement.php index 8f4bd31ed3..6c77066b7f 100644 --- a/classes/Model/AnnouncementManagement.php +++ b/classes/Model/AnnouncementManagement.php @@ -7,8 +7,7 @@ namespace MySociety\TheyWorkForYou\Model; -function is_valid_item($item) -{ +function is_valid_item($item) { // used in an array sort to filter out invalid items // set default language @@ -45,8 +44,7 @@ function is_valid_item($item) $end_time > date("Y-m-d\TH:i:s"); } -function select_based_on_weight($items) -{ +function select_based_on_weight($items) { # banners have a weight attribute, which is the probability of being selected # the higher the weight, the higher the probability $total_weight = 0; @@ -65,8 +63,7 @@ function select_based_on_weight($items) } } -class AnnouncementManagement -{ +class AnnouncementManagement { // Multi-purpose announcement storage system // Builds on previous banner system, but extends to // other locations for announcements @@ -80,14 +77,12 @@ class AnnouncementManagement */ private $mem; - public function __construct() - { + public function __construct() { $this->db = new \ParlDB(); $this->mem = new \MySociety\TheyWorkForYou\Memcache(); } - public function get_text($editorial_option) - { + public function get_text($editorial_option) { $text = $this->mem->get($editorial_option); if ($text === false) { @@ -110,8 +105,7 @@ public function get_text($editorial_option) return $text; } - public function set_text($text, $editorial_option) - { + public function set_text($text, $editorial_option) { $q = $this->db->query( "REPLACE INTO editorial set item = :editorial_option, value = :announcement_text", [ @@ -130,8 +124,7 @@ public function set_text($text, $editorial_option) return false; } - public function set_json($text, $editorial_option) - { + public function set_json($text, $editorial_option) { // check text is valid json $json_obj = json_decode($text); @@ -142,8 +135,7 @@ public function set_json($text, $editorial_option) return $this->set_text($text, $editorial_option); } - private function get_json($editorial_option) - { + private function get_json($editorial_option) { // for debugging, can use json files instead of db $use_json_file = false; @@ -163,8 +155,7 @@ private function get_json($editorial_option) return $json_obj; } - public function get_random_valid_banner() - { + public function get_random_valid_banner() { // get banners stored in json $banners = $this->get_json("banner"); @@ -185,8 +176,7 @@ public function get_random_valid_banner() return select_based_on_weight($banners); } - public function get_random_valid_item($location) - { + public function get_random_valid_item($location) { // get announcements stored in json $items = $this->get_json("announcements"); @@ -212,4 +202,3 @@ public function get_random_valid_item($location) return select_based_on_weight($items); } } -?> diff --git a/classes/Model/Featured.php b/classes/Model/Featured.php index 3d975282dc..a70e108975 100644 --- a/classes/Model/Featured.php +++ b/classes/Model/Featured.php @@ -8,14 +8,13 @@ namespace MySociety\TheyWorkForYou\Model; class Featured { - /** * DB handle */ private $db; public function __construct() { - $this->db = new \ParlDB; + $this->db = new \ParlDB(); } public function get_title() { @@ -57,14 +56,14 @@ private function _get($key) { $q = $this->db->query( "SELECT value FROM editorial WHERE item = :key", - array( - ':key' => $key - ) + [ + ':key' => $key, + ] )->first(); if ($q) { $text = $q['value']; - if ( trim($text) == '' ) { + if (trim($text) == '') { $text = null; } } @@ -73,32 +72,34 @@ private function _get($key) { } private function _set($key, $value) { - if ( trim($value) == '' ) { + if (trim($value) == '') { $value = null; } $check_q = $this->db->query( "SELECT value FROM editorial WHERE item = :key", - array( - ':key' => $key - ) + [ + ':key' => $key, + ] ); - if ( $check_q->rows() ) { - $set_q = $this->db->query("UPDATE editorial set value = :value WHERE item = :key", - array( + if ($check_q->rows()) { + $set_q = $this->db->query( + "UPDATE editorial set value = :value WHERE item = :key", + [ ':key' => $key, - ':value' => $value - ) + ':value' => $value, + ] ); } else { - $set_q = $this->db->query("INSERT INTO editorial (item, value ) VALUES (:key, :value)", - array( + $set_q = $this->db->query( + "INSERT INTO editorial (item, value ) VALUES (:key, :value)", + [ ':key' => $key, - ':value' => $value - ) + ':value' => $value, + ] ); } - if ( $set_q->success() ) { + if ($set_q->success()) { return true; } return false; diff --git a/classes/Office.php b/classes/Office.php index e2e879d1d5..f4f1f335c1 100644 --- a/classes/Office.php +++ b/classes/Office.php @@ -12,7 +12,6 @@ */ class Office { - public $title; public $from_date; public $to_date; @@ -27,7 +26,7 @@ class Office { */ public function __toString() { - if (isset ($this->title)) { + if (isset($this->title)) { return (string) $this->title; } else { return 'Unnamed Office'; @@ -70,7 +69,7 @@ public function pretty_dates() { if ($this->source == 'chgpages/privsec' && $this->from_date == '2005-11-10') { $output .= 'before '; } - $output .= format_date($this->from_date,SHORTDATEFORMAT) . ' '; + $output .= format_date($this->from_date, SHORTDATEFORMAT) . ' '; } $output .= 'to '; diff --git a/classes/Party.php b/classes/Party.php index 7cf55bc7bb..dcc264a6ff 100644 --- a/classes/Party.php +++ b/classes/Party.php @@ -12,7 +12,6 @@ */ class Party { - public $name; private $db; @@ -20,11 +19,11 @@ class Party { public function __construct($name) { // treat Labour and Labour/Co-operative the same as that's how // people view them and it'll confuse the results otherwise - if ( $name == 'Labour/Co-operative' ) { + if ($name == 'Labour/Co-operative') { $name = 'Labour'; } $this->name = $name; - $this->db = new \ParlDB; + $this->db = new \ParlDB(); } public function getCurrentMemberCount($house) { @@ -42,11 +41,11 @@ public function getCurrentMemberCount($house) { AND house = :house AND entered_house <= :date AND left_house >= :date", - array( + [ ':party' => $this->name, ':house' => $house, ':date' => $date, - ) + ] )->first(); if ($member_count) { $num_members = $member_count['num_members']; @@ -57,13 +56,13 @@ public function getCurrentMemberCount($house) { } public static function getParties() { - $db = new \ParlDB; + $db = new \ParlDB(); $party_list = $db->query( "SELECT DISTINCT party FROM member WHERE party <> ''" ); - $parties = array(); + $parties = []; foreach ($party_list as $row) { $party = $row['party']; if ( diff --git a/classes/PartyCohort.php b/classes/PartyCohort.php index d599c928a7..98d6b1f4b8 100644 --- a/classes/PartyCohort.php +++ b/classes/PartyCohort.php @@ -12,25 +12,22 @@ * Party */ -class PartyCohort -{ +class PartyCohort { private $db; private $party; private $hash; - public function __construct($person_id, $party) - { + public function __construct($person_id, $party) { // treat Labour and Labour/Co-operative the same as that's how // people view them and it'll confuse the results otherwise $this->party = $party; $this->hash = "$person_id-$party"; - $this->db = new \ParlDB; + $this->db = new \ParlDB(); } - public function getAllPolicyPositions($policies) - { - $positions = array(); + public function getAllPolicyPositions($policies) { + $positions = []; $party = $this->party; if ($party == 'Independent') { @@ -51,8 +48,7 @@ public function getAllPolicyPositions($policies) return $positions; } - public function policy_position($policy_id) - { + public function policy_position($policy_id) { $position = $this->db->query( "SELECT score, divisions, date_min, date_max FROM partypolicy @@ -60,10 +56,10 @@ public function policy_position($policy_id) party = :party AND house = 1 AND policy_id = :policy_id", - array( + [ ':party' => $this->hash, - ':policy_id' => $policy_id - ) + ':policy_id' => $policy_id, + ] )->first(); if ($position) { diff --git a/classes/People.php b/classes/People.php index 5ed382ff23..943612a548 100644 --- a/classes/People.php +++ b/classes/People.php @@ -12,7 +12,6 @@ */ class People { - public $type; public $rep_name; public $rep_plural; @@ -32,18 +31,18 @@ protected function getRegionalReps($user) { return $user->getRegionalReps($this->reg_cons_type, $this->house); } - public function getData($args = array()) { + public function getData($args = []) { $data = $this->_get_data_by_group($args); $user = new User(); - if ( $reps = $this->getRegionalReps($user) ) { + if ($reps = $this->getRegionalReps($user)) { $data['reps'] = $reps; } $data['mp_data'] = $user->getRep($this->cons_type, $this->house); $data['data'] = $this->addImagesToData($data['data']); $data['urls'] = $this->addUrlsToData(); - $data['order'] = isset($args['order']) ? $args['order'] : 'l'; + $data['order'] = $args['order'] ?? 'l'; $data['rep_plural'] = $this->rep_plural; $data['rep_name'] = $this->rep_name; $data['type'] = $this->type; @@ -55,7 +54,7 @@ public function getData($args = array()) { } public function getArgs() { - $args = array(); + $args = []; if (get_http_var('f') == 'csv') { $args['f'] = 'csv'; @@ -71,15 +70,15 @@ public function getArgs() { $args['all'] = true; } - if ( $this->type == 'peers' ) { + if ($this->type == 'peers') { $args['order'] = 'name'; } $order = get_http_var('o'); - $orders = array( + $orders = [ 'n' => 'name', 'f' => 'given_name', 'l' => 'family_name', 'c' => 'constituency', 'p' => 'party', - ); + ]; if (array_key_exists($order, $orders)) { $args['order'] = $orders[$order]; } @@ -100,17 +99,17 @@ public function setMetaData($args) { } protected function getCSVHeaders() { - return array(gettext('Person ID'), gettext('Name'), gettext('Party'), gettext('Constituency'), gettext('URI')); + return [gettext('Person ID'), gettext('Name'), gettext('Party'), gettext('Constituency'), gettext('URI')]; } protected function getCSVRow($details) { - return array( + return [ $details['person_id'], $details['name'], $details['party'], $details['constituency'], - 'https://www.theyworkforyou.com/mp/' . $details['url'] - ); + 'https://www.theyworkforyou.com/mp/' . $details['url'], + ]; } public function sendAsCSV($data) { @@ -130,9 +129,9 @@ public function sendAsCSV($data) { } private function addImagesToData($data) { - $new_data = array(); - foreach ( $data as $pid => $details ) { - list($image, ) = Utility\Member::findMemberImage($pid, true, $this->subs_missing_image); + $new_data = []; + foreach ($data as $pid => $details) { + [$image, ] = Utility\Member::findMemberImage($pid, true, $this->subs_missing_image); $details['image'] = $image; $new_data[$pid] = $details; } @@ -143,28 +142,28 @@ private function addImagesToData($data) { private function addUrlsToData() { global $this_page; - $urls = array(); + $urls = []; $URL = new Url($this_page); $urls['plain'] = $URL->generate(); - $URL->insert(array( 'o' => 'n')); + $URL->insert([ 'o' => 'n']); $urls['by_name'] = $URL->generate(); - $URL->insert(array( 'o' => 'l')); + $URL->insert([ 'o' => 'l']); $urls['by_last'] = $URL->generate(); - $URL->insert(array( 'o' => 'f')); + $URL->insert([ 'o' => 'f']); $urls['by_first'] = $URL->generate(); - $URL->insert(array( 'o' => 'p')); + $URL->insert([ 'o' => 'p']); $urls['by_party'] = $URL->generate(); - $URL->insert(array( 'f' => 'csv')); - $URL->remove(array( 'o')); - if ( $date = get_http_var('date') ) { - $URL->insert(array('date' => $date)); + $URL->insert([ 'f' => 'csv']); + $URL->remove([ 'o']); + if ($date = get_http_var('date')) { + $URL->insert(['date' => $date]); } $urls['by_csv'] = $URL->generate(); @@ -176,7 +175,7 @@ private function _get_data_by_group($args) { $order = 'family_name'; $sqlorder = 'family_name, given_name'; - $params = array(); + $params = []; $query = 'SELECT distinct member.person_id, title, given_name, family_name, lordofname, constituency, party, left_reason '; $query .= 'FROM member JOIN person_names p ON p.person_id = member.person_id AND p.type = "name" '; if (isset($args['date'])) { @@ -206,7 +205,7 @@ private function _get_data_by_group($args) { $q = $this->db->query($query . "ORDER BY $sqlorder", $params); - $data = array(); + $data = []; foreach ($q as $row) { $p_id = $row['person_id']; if (!isset($data[$p_id])) { @@ -214,7 +213,7 @@ private function _get_data_by_group($args) { $constituency = $row['constituency'] ? gettext($row['constituency']) : ''; $party = $row['party'] ? gettext($row['party']) : ''; $url = make_member_url($name, $constituency, $this->house, $p_id); - $narray = array ( + $narray = [ 'person_id' => $p_id, 'given_name' => $row['given_name'], 'family_name' => $row['family_name'], @@ -224,7 +223,7 @@ private function _get_data_by_group($args) { 'constituency' => $constituency, 'party' => $party, 'left_reason' => $row['left_reason'], - ); + ]; $data[$p_id] = $narray; } } @@ -232,12 +231,12 @@ private function _get_data_by_group($args) { uasort($data, 'by_peer_name'); } - $data = array ( - 'info' => array ( - 'order' => $order - ), - 'data' => $data - ); + $data = [ + 'info' => [ + 'order' => $order, + ], + 'data' => $data, + ]; return $data; diff --git a/classes/People/LondonAssemblyMembers.php b/classes/People/LondonAssemblyMembers.php index 473d503a51..8386f121af 100644 --- a/classes/People/LondonAssemblyMembers.php +++ b/classes/People/LondonAssemblyMembers.php @@ -7,9 +7,7 @@ namespace MySociety\TheyWorkForYou\People; -class LondonAssemblyMembers extends \MySociety\TheyWorkForYou\People -{ - +class LondonAssemblyMembers extends \MySociety\TheyWorkForYou\People { public $type = 'london-assembly-members'; public $rep_name = 'London Assembly Member'; public $rep_plural = 'London Assembly Members'; diff --git a/classes/People/MLAs.php b/classes/People/MLAs.php index f9557c5d5c..56003610bc 100644 --- a/classes/People/MLAs.php +++ b/classes/People/MLAs.php @@ -8,7 +8,6 @@ namespace MySociety\TheyWorkForYou\People; class MLAs extends \MySociety\TheyWorkForYou\People { - public $type = 'mlas'; public $rep_name = 'MLA'; public $rep_plural = 'MLAs'; diff --git a/classes/People/MPs.php b/classes/People/MPs.php index fa9f6106fc..47d95d67b5 100644 --- a/classes/People/MPs.php +++ b/classes/People/MPs.php @@ -8,7 +8,6 @@ namespace MySociety\TheyWorkForYou\People; class MPs extends \MySociety\TheyWorkForYou\People { - public $type = 'mps'; public $rep_name = 'MP'; public $rep_plural = 'MPs'; @@ -20,17 +19,17 @@ protected function getRegionalReps($user) { } protected function getCSVHeaders() { - return array('Person ID', 'First name', 'Last name', 'Party', 'Constituency', 'URI'); + return ['Person ID', 'First name', 'Last name', 'Party', 'Constituency', 'URI']; } protected function getCSVRow($details) { - return array( + return [ $details['person_id'], $details['given_name'], $details['family_name'], $details['party'], $details['constituency'], - 'https://www.theyworkforyou.com/mp/' . $details['url'] - ); + 'https://www.theyworkforyou.com/mp/' . $details['url'], + ]; } } diff --git a/classes/People/MSPs.php b/classes/People/MSPs.php index 814d041f8c..567e9b982b 100644 --- a/classes/People/MSPs.php +++ b/classes/People/MSPs.php @@ -8,7 +8,6 @@ namespace MySociety\TheyWorkForYou\People; class MSPs extends \MySociety\TheyWorkForYou\People { - public $type = 'msps'; public $rep_name = 'MSP'; public $rep_plural = 'MSPs'; diff --git a/classes/People/MSs.php b/classes/People/MSs.php index 392913dc82..9c0076f468 100644 --- a/classes/People/MSs.php +++ b/classes/People/MSs.php @@ -8,7 +8,6 @@ namespace MySociety\TheyWorkForYou\People; class MSs extends \MySociety\TheyWorkForYou\People { - public $type = 'mss'; public $house = HOUSE_TYPE_WALES; public $cons_type = 'WAC'; @@ -25,4 +24,3 @@ public function __construct() { parent::__construct(); } } - diff --git a/classes/People/Peers.php b/classes/People/Peers.php index a9fb9d7842..453e401579 100644 --- a/classes/People/Peers.php +++ b/classes/People/Peers.php @@ -8,7 +8,6 @@ namespace MySociety\TheyWorkForYou\People; class Peers extends \MySociety\TheyWorkForYou\People { - public $type = 'peers'; public $rep_name = 'Member of the House of Lords'; public $rep_plural = 'Members of the House of Lords'; @@ -20,15 +19,15 @@ protected function getRegionalReps($user) { } protected function getCSVHeaders() { - return array('Person ID', 'Name', 'Party', 'URI'); + return ['Person ID', 'Name', 'Party', 'URI']; } protected function getCSVRow($details) { - return array( + return [ $details['person_id'], $details['name'], $details['party'], - 'https://www.theyworkforyou.com/peer/' . $details['url'] - ); + 'https://www.theyworkforyou.com/peer/' . $details['url'], + ]; } } diff --git a/classes/Policies.php b/classes/Policies.php index bca4fb1df4..966b02f202 100644 --- a/classes/Policies.php +++ b/classes/Policies.php @@ -14,12 +14,11 @@ */ class Policies { - - private $commons_only = array( + private $commons_only = [ 811, 826, 1053, - ); + ]; # policies where votes affected by covid voting restrictions protected $covid_affected = [1136, 6860]; @@ -34,22 +33,22 @@ class Policies { private array $policies; /** - * @var array $sets - key-value pair of a set slug to an array of policy IDs + * @var array $sets - key-value pair of a set slug to an array of policy IDs * in that set. * e.g. "foreignpolicy": ["975", "984"[] */ private array $sets; /** - * @var array $set_descs - key-value pairs of a set slug to a description + * @var array $set_descs - key-value pairs of a set slug to a description * of that set. * e.g. "foreignpolicy": "Foreign Policy" */ private array $set_descs; /** - * @var array $all_policy_agreements - key-value pair of a policy ID to - * an array of + * @var array $all_policy_agreements - key-value pair of a policy ID to + * an array of * agreements links. * e.g. "1030": [{ * "division_name": "Approval of SI setting 2050 Net Zero target date", @@ -64,7 +63,7 @@ class Policies { public array $all_policy_agreements; public function __construct($policy_id = null) { - $this->db = new \ParlDB; + $this->db = new \ParlDB(); if (defined('TESTING') && TESTING == true) { $policy_data = json_decode(file_get_contents(dirname(__FILE__) . '/../tests/policies.json'), true); @@ -77,11 +76,11 @@ public function __construct($policy_id = null) { $this->all_policy_agreements = $policy_data['agreements'] ?? []; - if ( $policy_id ) { + if ($policy_id) { $this->policy_id = $policy_id; - $this->policies = array( - $policy_id => $this->policies[$policy_id] - ); + $this->policies = [ + $policy_id => $this->policies[$policy_id], + ]; } } @@ -109,13 +108,13 @@ public function getSetDescriptions() { * @return array Array of policies in the form `[ {id} , {text} ]` */ public function getPoliciesData() { - $out = array(); + $out = []; foreach ($this->policies as $policy_id => $policy_text) { - $out[] = array( + $out[] = [ 'id' => $policy_id, 'text' => $policy_text, - 'commons_only'=> in_array($policy_id, $this->commons_only), - ); + 'commons_only' => in_array($policy_id, $this->commons_only), + ]; } return $out; } @@ -149,22 +148,19 @@ public function shuffle() { public function limitToSet($set) { // Sanity check the set exists - if (isset($this->sets[$set])) - { - $out = array(); + if (isset($this->sets[$set])) { + $out = []; // Reassemble the new policies list based on the set. - foreach ($this->sets[$set] as $set_policy) - { - if (isset($this->policies[$set_policy])) - { + foreach ($this->sets[$set] as $set_policy) { + if (isset($this->policies[$set_policy])) { $out[$set_policy] = $this->policies[$set_policy]; } else { // if we've limited the policies to a single one then we only // want to complain here if we're looking for that policy and // it does not exist. Otherwise, if the single policy isn't in // the set we want to return an empty set - if ( !isset($this->policy_id) || $set_policy == $this->policy_id ) { - throw new \Exception ('Policy ' . $set_policy . ' in set "' . $set . '" does not exist.'); + if (!isset($this->policy_id) || $set_policy == $this->policy_id) { + throw new \Exception('Policy ' . $set_policy . ' in set "' . $set . '" does not exist.'); } } } @@ -175,33 +171,33 @@ public function limitToSet($set) { return $new_policies->shuffle(); } else { - throw new \Exception ('Policy set "' . $set . '" does not exist.'); + throw new \Exception('Policy set "' . $set . '" does not exist.'); } } public function limitToArray($policies) { - $out = array(); - // Reassemble the new policies list based on the set. - foreach ($policies as $policy) { - if (isset($this->policies[$policy])) { - $out[$policy] = $this->policies[$policy]; - } - } - - $new_policies = new self(); - $new_policies->policies = $out; - - return $new_policies; + $out = []; + // Reassemble the new policies list based on the set. + foreach ($policies as $policy) { + if (isset($this->policies[$policy])) { + $out[$policy] = $this->policies[$policy]; + } + } + + $new_policies = new self(); + $new_policies->policies = $out; + + return $new_policies; } public function getPolicyDetails($policyID) { $q = $this->db->query( "SELECT policy_id, title, description, image, image_attrib, image_license, image_license_url, image_source FROM policies WHERE policy_id = :policy_id", - array(':policy_id' => $policyID) + [':policy_id' => $policyID] )->first(); - $props = array( + $props = [ 'policy_id' => $q['policy_id'], 'title' => $q['title'], // remove full stops from the end of descriptions. Some of them have them and @@ -211,12 +207,12 @@ public function getPolicyDetails($policyID) { 'image_license' => '', 'image_attribution' => '', 'image_source' => '', - 'image_license_url' => '' - ); + 'image_license_url' => '', + ]; $image = $q['image']; - if ( $image && file_exists(BASEDIR . '/' . $image)) { + if ($image && file_exists(BASEDIR . '/' . $image)) { $props['image'] = $image; $props['image_license'] = $q['image_license']; $props['image_attribution'] = $q['image_attrib']; diff --git a/classes/PolicyPositions.php b/classes/PolicyPositions.php index 8286f498e9..a034b1036b 100644 --- a/classes/PolicyPositions.php +++ b/classes/PolicyPositions.php @@ -15,7 +15,6 @@ */ class PolicyPositions { - /** * Member */ @@ -40,9 +39,9 @@ class PolicyPositions { * Array of positions held by the member. */ - public $positions = array(); + public $positions = []; - public $positionsById = array(); + public $positionsById = []; /** * 'Since' String @@ -62,14 +61,13 @@ class PolicyPositions { * @param int $limit The number of policies to limit the list to. */ - public function __construct(Policies $policies, Member $member, $options = array()) - { + public function __construct(Policies $policies, Member $member, $options = []) { $this->policies = $policies; $this->member = $member; - $this->summaries = isset($options['summaries']) ? $options['summaries'] : array(); + $this->summaries = $options['summaries'] ?? []; $this->divisions = new \MySociety\TheyWorkForYou\Divisions($member); - $limit = isset($options['limit']) ? $options['limit'] : null; + $limit = $options['limit'] ?? null; // Do the actual getting of positions $this->getMemberPolicyPositions($limit); @@ -83,7 +81,7 @@ public function __construct(Policies $policies, Member $member, $options = array * @param int $limit The number of results to limit the output to. */ - private function getMemberPolicyPositions ($limit = null) { + private function getMemberPolicyPositions($limit = null) { // Make sure member info has actually been set. if (count($this->member->extra_info) === 0) { @@ -104,7 +102,7 @@ private function getMemberPolicyPositions ($limit = null) { // Set the current policy count to 0 $i = 0; - $this->positions = array(); + $this->positions = []; // Loop around all the policies. foreach ($policies as $policy) { @@ -124,35 +122,35 @@ private function getMemberPolicyPositions ($limit = null) { continue; } - $votes_summary = array_key_exists($policy['id'], $this->summaries) ? $this->summaries[$policy['id']] : array(); + $votes_summary = array_key_exists($policy['id'], $this->summaries) ? $this->summaries[$policy['id']] : []; $dream_info = $this->displayDreamComparison($policy['id'], $policy['text'], $votes_summary); // don't return votes where they haven't voted on a strong division // if we're limiting the number of votes - if ( $limit && !empty($dream_info) && !$dream_info['has_strong'] ) { + if ($limit && !empty($dream_info) && !$dream_info['has_strong']) { continue; } // Make sure the dream actually exists if (!empty($dream_info)) { $summary = $votes_summary ? $this->divisions->generateSummary($votes_summary) : ''; - $this->positions[] = array( + $this->positions[] = [ 'policy_id' => $policy['id'], 'policy' => $policy['text'], 'desc' => $dream_info['full_sentence'], 'has_strong' => $dream_info['has_strong'], 'position' => $dream_info['position'], - 'summary' => $summary - ); - $this->positionsById[$policy['id']] = array( + 'summary' => $summary, + ]; + $this->positionsById[$policy['id']] = [ 'policy_id' => $policy['id'], 'policy' => $policy['text'], 'desc' => $dream_info['full_sentence'], 'position' => $dream_info['position'], 'has_strong' => $dream_info['has_strong'], 'score' => $dream_info['score'], - 'summary' => $summary - ); + 'summary' => $summary, + ]; $i++; } } @@ -183,7 +181,7 @@ private function getMemberPolicyPositions ($limit = null) { */ private function displayDreamComparison($dreamid, $policy_description, $votes_summary) { - $out = array(); + $out = []; $extra_info = $this->member->extra_info(); @@ -208,14 +206,13 @@ private function displayDreamComparison($dreamid, $policy_description, $votes_su $has_strong = 1; } $full_sentence = $consistency . ' ' . $policy_description; - $out = array( 'full_sentence' => $full_sentence, 'score' => $dmpscore, 'position' => $consistency, 'has_strong' => $has_strong ); + $out = [ 'full_sentence' => $full_sentence, 'score' => $dmpscore, 'position' => $consistency, 'has_strong' => $has_strong ]; } return $out; } - private function generateSinceString() - { + private function generateSinceString() { $member_houses = $this->member->houses(); $entered_house = $this->member->entered_house(); @@ -239,7 +236,7 @@ private function generateSinceString() # If not current MP/Lord, but current MLA/MSP, need to say voting record is when MP if (!$current_member[HOUSE_TYPE_COMMONS] and !$current_member[HOUSE_TYPE_LORDS] and - ( $current_member[HOUSE_TYPE_SCOTLAND] or $current_member[HOUSE_TYPE_NI] ) + ($current_member[HOUSE_TYPE_SCOTLAND] or $current_member[HOUSE_TYPE_NI]) ) { $since .= ' whilst an MP'; } @@ -248,23 +245,22 @@ private function generateSinceString() } } - private function generateMoreLinksString() - { + private function generateMoreLinksString() { $extra_info = $this->member->extra_info; // Links to full record at Guardian and Public Whip - $record = array(); + $record = []; if (isset($extra_info['guardian_howtheyvoted'])) { $record[] = 'well-known issues (from the Guardian)'; } if ( - ( isset($extra_info['public_whip_division_attendance']) and - $extra_info['public_whip_division_attendance'] != 'n/a' ) + (isset($extra_info['public_whip_division_attendance']) and + $extra_info['public_whip_division_attendance'] != 'n/a') or - ( isset($extra_info['Lpublic_whip_division_attendance']) and - $extra_info['Lpublic_whip_division_attendance'] != 'n/a' ) + (isset($extra_info['Lpublic_whip_division_attendance']) and + $extra_info['Lpublic_whip_division_attendance'] != 'n/a') ) { $record[] = 'data, $data); - if ( isset($page_errors) ) { + if (isset($page_errors)) { $data['page_errors'] = $page_errors; } @@ -62,7 +59,7 @@ public static function output($template, $data = array(), $template_only = false $data['footer_links'] = $footer->data; # banner text - $announcement_manager = new Model\AnnouncementManagement; + $announcement_manager = new Model\AnnouncementManagement(); $data['random_banner'] = $announcement_manager->get_random_valid_banner(); $data = self::addCommonURLs($data); @@ -86,15 +83,15 @@ public static function output($template, $data = array(), $template_only = false } private static function addCommonURLs($data) { - $urls = array(); - if ( isset($data['urls']) ) { + $urls = []; + if (isset($data['urls'])) { $urls = $data['urls']; } - $common_urls = array('search', 'alert'); + $common_urls = ['search', 'alert']; - foreach ( $common_urls as $path ) { - if (!isset($urls[$path]) ) { + foreach ($common_urls as $path) { + if (!isset($urls[$path])) { $url = new Url($path); $urls[$path] = $url->generate(); } diff --git a/classes/Renderer/Footer.php b/classes/Renderer/Footer.php index 319ece628c..2418b762f9 100644 --- a/classes/Renderer/Footer.php +++ b/classes/Renderer/Footer.php @@ -9,15 +9,13 @@ * for use in header and footer. */ -class Footer -{ - +class Footer { public $data; - private $about_links = array ('help', 'about', 'linktous', 'news', 'privacy'); - private $assemblies_links = array('hansard', 'sp_home', 'wales_home', 'ni_home', 'london_home'); - private $international_links = array('australia', 'ireland', 'mzalendo'); - private $tech_links = array('code', 'api', 'data', 'devmailinglist', 'contact'); + private $about_links = ['help', 'about', 'linktous', 'news', 'privacy']; + private $assemblies_links = ['hansard', 'sp_home', 'wales_home', 'ni_home', 'london_home']; + private $international_links = ['australia', 'ireland', 'mzalendo']; + private $tech_links = ['code', 'api', 'data', 'devmailinglist', 'contact']; /* @@ -26,12 +24,12 @@ class Footer * Populates $data with array of array of links in the footer */ public function __construct() { - $this->data = array(); + $this->data = []; - $this->data['about'] = $this->get_menu_links( $this->about_links ); - $this->data['assemblies'] = $this->get_menu_links( $this->assemblies_links ); - $this->data['international'] = $this->get_menu_links( $this->international_links ); - $this->data['tech'] = $this->get_menu_links( $this->tech_links ); + $this->data['about'] = $this->get_menu_links($this->about_links); + $this->data['assemblies'] = $this->get_menu_links($this->assemblies_links); + $this->data['international'] = $this->get_menu_links($this->international_links); + $this->data['tech'] = $this->get_menu_links($this->tech_links); } /** @@ -43,7 +41,7 @@ public function __construct() { private function get_menu_links($pages) { global $DATA, $this_page; - $links = array(); + $links = []; foreach ($pages as $page) { @@ -65,19 +63,19 @@ private function get_menu_links($pages) { //make the link if ($page == $this_page) { - $links[] = array( + $links[] = [ 'href' => '#', 'title' => '', 'classes' => '', - 'text' => $title - ); + 'text' => $title, + ]; } else { - $links[] = array( + $links[] = [ 'href' => $url, 'title' => $tooltip, 'classes' => '', - 'text' => $title - ); + 'text' => $title, + ]; } } diff --git a/classes/Renderer/Header.php b/classes/Renderer/Header.php index 0e1d83c458..809d4a12eb 100644 --- a/classes/Renderer/Header.php +++ b/classes/Renderer/Header.php @@ -8,9 +8,7 @@ * Prepares variables for inclusion in a template header. */ -class Header -{ - +class Header { public $nav_highlights; public $data; @@ -18,7 +16,7 @@ class Header private $keywords_title; public function __construct() { - $this->data = array(); + $this->data = []; $this->get_page_url(); $this->get_page_title(); @@ -125,16 +123,16 @@ private function get_page_keywords() { private function get_header_links() { global $this_page; - $this->data['header_links'] = array(); + $this->data['header_links'] = []; if ($this_page != 'overview') { $URL = new \MySociety\TheyWorkForYou\Url('overview'); - $this->data['header_links'][] = array( + $this->data['header_links'][] = [ 'rel' => 'start', 'title' => 'Home', - 'href' => $URL->generate() - ); + 'href' => $URL->generate(), + ]; } } @@ -144,7 +142,7 @@ private function generate_next_prev_link($nextprev, $linktype) { if (isset($nextprev[$linktype]) && isset($nextprev[$linktype]['url'])) { if (isset($nextprev[$linktype]['body'])) { - $linktitle = _htmlentities( trim_characters($nextprev[$linktype]['body'], 0, 40) ); + $linktitle = _htmlentities(trim_characters($nextprev[$linktype]['body'], 0, 40)); if (isset($nextprev[$linktype]['speaker']) && count($nextprev[$linktype]['speaker']) > 0) { $linktitle = $nextprev[$linktype]['speaker']['name'] . ': ' . $linktitle; @@ -154,11 +152,11 @@ private function generate_next_prev_link($nextprev, $linktype) { $linktitle = format_date($nextprev[$linktype]['hdate'], SHORTDATEFORMAT); } - $link = array( + $link = [ 'rel' => $linktype, 'title' => $linktitle, - 'href' => $nextprev[$linktype]['url'] - ); + 'href' => $nextprev[$linktype]['url'], + ]; } return $link; @@ -171,10 +169,10 @@ private function get_next_prev_links() { if ($nextprev) { // Four different kinds of back/forth links we might build. - $links = array ("first", "prev", "up", "next", "last"); + $links = ["first", "prev", "up", "next", "last"]; foreach ($links as $type) { - if ( $link = $this->generate_next_prev_link( $nextprev, $type ) ) { + if ($link = $this->generate_next_prev_link($nextprev, $type)) { $this->data['header_links'][] = $link; } @@ -209,7 +207,7 @@ private function get_menu_highlights() { } else { - $parents = array($parent); + $parents = [$parent]; $p = $parent; while ($p) { $p = $DATA->page_metadata($p, 'parent'); @@ -280,7 +278,7 @@ private function get_menu_highlights() { // in the top bar if ($this_page == "alert") { if ($pid = get_http_var('pid')) { - $person = new \MySociety\TheyWorkForYou\Member(array('person_id' => $pid)); + $person = new \MySociety\TheyWorkForYou\Member(['person_id' => $pid]); $membership = $person->getMostRecentMembership(); $parliament = $membership['house']; if ($parliament == 'ni') { @@ -295,12 +293,12 @@ private function get_menu_highlights() { } } - $this->nav_highlights = array( + $this->nav_highlights = [ 'top' => $top_highlight, 'bottom' => $bottom_highlight, 'top_selected' => $selected_top_link, 'section' => $section, - ); + ]; } private function get_top_and_bottom_links() { @@ -309,17 +307,17 @@ private function get_top_and_bottom_links() { // Page names mapping to those in metadata.php. // Links in the top menu, and the sublinks we see if // we're within that section. - $nav_items = array ( - array('home'), - array('hansard', 'mps', 'peers', 'alldebatesfront', 'wranswmsfront', 'pbc_front', 'divisions_recent_commons', 'divisions_recent_lords', 'calendar_summary'), - array('sp_home', 'spoverview', 'msps', 'spdebatesfront', 'divisions_recent_sp'), #'spwransfront' - array('ni_home', 'nioverview', 'mlas'), - array('wales_home', 'seneddoverview', 'mss', 'wales_debates', 'divisions_recent_wales'), - array('london_home', 'lmqsfront', 'london-assembly-members'), - ); - - $this->data['assembly_nav_links'] = array(); - $this->data['section_nav_links'] = array(); + $nav_items = [ + ['home'], + ['hansard', 'mps', 'peers', 'alldebatesfront', 'wranswmsfront', 'pbc_front', 'divisions_recent_commons', 'divisions_recent_lords', 'calendar_summary'], + ['sp_home', 'spoverview', 'msps', 'spdebatesfront', 'divisions_recent_sp'], #'spwransfront' + ['ni_home', 'nioverview', 'mlas'], + ['wales_home', 'seneddoverview', 'mss', 'wales_debates', 'divisions_recent_wales'], + ['london_home', 'lmqsfront', 'london-assembly-members'], + ]; + + $this->data['assembly_nav_links'] = []; + $this->data['section_nav_links'] = []; //get the top and bottom links foreach ($nav_items as $bottompages) { @@ -345,17 +343,17 @@ private function get_top_and_bottom_links() { // we need to escape back to the english site $URL = new \MySociety\TheyWorkForYou\Url($toppage); $url = $URL->generate(); - if (LANGUAGE == 'cy' && strpos($url, '/senedd/') === false ) { + if (LANGUAGE == 'cy' && strpos($url, '/senedd/') === false) { $url = "//" . DOMAIN . $url; } - $top_link = array( + $top_link = [ 'href' => $url, 'title' => $title, 'classes' => $class, - 'text' => $text - ); - if ($toppage != "london_home"){ + 'text' => $text, + ]; + if ($toppage != "london_home") { array_push($this->data['assembly_nav_links'], $top_link); } @@ -369,12 +367,12 @@ private function get_top_and_bottom_links() { // Where we're linking to. $URL = new \MySociety\TheyWorkForYou\Url($bottompage); $class = $bottompage == $this->nav_highlights['bottom'] ? 'on' : ''; - $this->data['section_nav_links'][] = array( + $this->data['section_nav_links'][] = [ 'href' => $URL->generate(), 'title' => $title, 'classes' => $class, - 'text' => $text - ); + 'text' => $text, + ]; } } } diff --git a/classes/Renderer/Markdown.php b/classes/Renderer/Markdown.php index 00ed6f33b5..4749659909 100644 --- a/classes/Renderer/Markdown.php +++ b/classes/Renderer/Markdown.php @@ -9,35 +9,33 @@ */ -function render_php($template_file) -{ +function render_php($template_file) { $path = INCLUDESPATH . 'easyparliament/templates/html/' . $template_file . '.php'; ob_start(); include($path); return ob_get_clean(); } -class Markdown -{ - public function markdown_document($this_page, $show_menu = true){ +class Markdown { + public function markdown_document($this_page, $show_menu = true) { // This function takes a markdown file and converts it to HTML - + $markdown_file = '../../../markdown/' . $this_page . '.md'; $Parsedown = new \Parsedown(); - + $text = file_get_contents($markdown_file); $html = $Parsedown->text($text); - + # title is the first h1 preg_match('/

([^<]+)<\/h1>/i', $html, $matches); - + $title = $matches[1]; - - $html = preg_replace_callback('/([^<]+)<\/h[1-3]>/i', function($matches) { + + $html = preg_replace_callback('/([^<]+)<\/h[1-3]>/i', function ($matches) { $level = $matches[1]; $htitle = $matches[2]; $slug = slugify($htitle); - if ($level == 1){ + if ($level == 1) { $title_class = "js-toc-title"; } else { $title_class = "js-toc-item"; @@ -53,12 +51,12 @@ public function markdown_document($this_page, $show_menu = true){ $html = str_replace('{{ donate_box }}', render_php('donate/_stripe_donate'), $html); } - \MySociety\TheyWorkForYou\Renderer::output('static/markdown_template', array( + \MySociety\TheyWorkForYou\Renderer::output('static/markdown_template', [ 'html' => $html, 'this_page' => $this_page, 'page_title' => $title, 'show_menu' => $show_menu, - )); - + ]); + } } diff --git a/classes/Renderer/User.php b/classes/Renderer/User.php index 9493a4d3a9..c9f5a46821 100644 --- a/classes/Renderer/User.php +++ b/classes/Renderer/User.php @@ -6,8 +6,7 @@ * User data for headers */ -class User -{ +class User { public $data; private $user; @@ -21,12 +20,12 @@ public function __construct() { $this->user = $THEUSER; $this->pagedata = $DATA; $this->page = $this_page; - $this->data = array(); + $this->data = []; $this->setupNavLinks(); } private function setupNavLinks() { - $this->data['user_nav_links'] = array(); + $this->data['user_nav_links'] = []; // We may want to send the user back to this current page after they've // joined, logged out or logged in. So we put the URL in $returl. @@ -41,7 +40,7 @@ private function setupNavLinks() { } } - private function AddLangSwitcher(){ + private function AddLangSwitcher() { if (preg_match('#^(senedd|wales|ms(?!p))#', $this->page)) { $href = $_SERVER['REQUEST_URI']; if (LANGUAGE == 'cy') { @@ -55,12 +54,12 @@ private function AddLangSwitcher(){ $href = "//cy." . DOMAIN . $href; } } - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $href, 'classes' => '', 'title' => '', 'text' => $text, - ); + ]; } } @@ -69,7 +68,7 @@ private function addLoggedInLinks() { $menudata = $this->pagedata->page_metadata('userviewself', 'menu'); $edittitle = $menudata['title']; $EDITURL = new \MySociety\TheyWorkForYou\Url('userviewself'); - if ($this->page == 'userviewself' || $this->page == 'useredit' ) { + if ($this->page == 'userviewself' || $this->page == 'useredit') { $editclass = 'on'; } else { $editclass = ''; @@ -78,11 +77,11 @@ private function addLoggedInLinks() { // The 'Log out' link. $menudata = $this->pagedata->page_metadata('userlogout', 'menu'); $logouttext = $menudata['text']; - $logouttitle= $menudata['title']; + $logouttitle = $menudata['title']; $LOGOUTURL = new \MySociety\TheyWorkForYou\Url('userlogout'); if ($this->page != 'userlogout') { - $LOGOUTURL->insert(array("ret"=>$this->returl)); + $LOGOUTURL->insert(["ret" => $this->returl]); $logoutclass = ''; } else { $logoutclass = 'on'; @@ -92,19 +91,19 @@ private function addLoggedInLinks() { $this->addRepLinks(); - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $EDITURL->generate(), 'title' => $edittitle, 'classes' => $editclass, - 'text' => _htmlentities($username) - ); + 'text' => _htmlentities($username), + ]; - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $LOGOUTURL->generate(), 'title' => $logouttitle, 'classes' => $logoutclass, - 'text' => $logouttext - ); + 'text' => $logouttext, + ]; $this->addContactLink(); $this->addDonateLink(); @@ -123,7 +122,7 @@ private function addLoggedOutLinks() { // We don't do this on the logout page, because then the user // will return straight to the logout page and be logged out // immediately! - $JOINURL->insert(array("ret"=>$this->returl)); + $JOINURL->insert(["ret" => $this->returl]); } $joinclass = ''; } else { @@ -145,26 +144,26 @@ private function addLoggedOutLinks() { // immediately! // And it's also silly if we're sent back to Change Password. // And the join page. - $LOGINURL->insert(array("ret"=>$this->returl)); + $LOGINURL->insert(["ret" => $this->returl]); } $loginclass = ''; } else { $loginclass = 'on'; } - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $LOGINURL->generate(), 'title' => $logintitle, 'classes' => $loginclass, - 'text' => $logintext - ); + 'text' => $logintext, + ]; - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $JOINURL->generate(), 'title' => $jointitle, 'classes' => $joinclass, - 'text' => $jointext - ); + 'text' => $jointext, + ]; $this->addRepLinks(); $this->addContactLink(); @@ -177,7 +176,7 @@ private function addRepLinks() { if ($this->user->postcode_is_set()) { $areas = \MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituencies($this->user->postcode()); - $items = array('yourmp'); + $items = ['yourmp']; if (isset($areas['SPC'])) { $items[] = 'yourmsp'; } elseif (isset($areas['NIE'])) { @@ -190,12 +189,12 @@ private function addRepLinks() { $menudata = $this->pagedata->page_metadata($item, 'menu'); $logintext = $menudata['text']; $URL = new \MySociety\TheyWorkForYou\Url($item); - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $URL->generate(), 'title' => '', 'classes' => '', - 'text' => $logintext - ); + 'text' => $logintext, + ]; } } @@ -206,12 +205,12 @@ private function addContactLink() { $text = $menudata['text']; $title = $menudata['title']; $url = new \MySociety\TheyWorkForYou\Url('contact'); - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $url->generate(), 'title' => $title, 'classes' => '', - 'text' => $text - ); + 'text' => $text, + ]; } private function addDonateLink() { @@ -222,12 +221,12 @@ private function addDonateLink() { $text = $menudata['text']; $title = $menudata['title']; $url = new \MySociety\TheyWorkForYou\Url('donate'); - $this->data['user_nav_links'][] = array( + $this->data['user_nav_links'][] = [ 'href' => $url->generate(), 'title' => $title, 'classes' => 'donate-button', - 'text' => $text - ); + 'text' => $text, + ]; } } diff --git a/classes/SPHomepage.php b/classes/SPHomepage.php index fe5abefd79..e11bada617 100644 --- a/classes/SPHomepage.php +++ b/classes/SPHomepage.php @@ -3,19 +3,18 @@ namespace MySociety\TheyWorkForYou; class SPHomepage extends Homepage { - protected $mp_house = 4; protected $cons_type = 'SPC'; protected $mp_url = 'yourmsp'; protected $page = 'spoverview'; - protected $houses = array(7); + protected $houses = [7]; - protected $recent_types = array( - 'SPLIST' => array('recent_debates', 'spdebatesfront', 'Scottish parliament debates'), - 'SPWRANSLIST' => array('recent_wrans', 'spwransfront', 'Written answers'), - ); + protected $recent_types = [ + 'SPLIST' => ['recent_debates', 'spdebatesfront', 'Scottish parliament debates'], + 'SPWRANSLIST' => ['recent_wrans', 'spwransfront', 'Written answers'], + ]; - protected function getSearchBox(array $data): Search\SearchBox{ + protected function getSearchBox(array $data): Search\SearchBox { $search_box = new Search\SearchBox(); $search_box->homepage_panel_class = "panel--homepage--scotland"; $search_box->homepage_subhead = "Scottish Parliament"; @@ -24,7 +23,7 @@ protected function getSearchBox(array $data): Search\SearchBox{ $search_box->quick_links = []; if (count($data["mp_data"])) { $regional_con = $data["regional"][0]["constituency"]; - $search_box->add_quick_link('Find out more about your MSPs for ' . $data["mp_data"]["constituency"] . ' (' . $regional_con . ')', '/postcode/?pc=' . $data["mp_data"]['postcode'], 'torso' ); + $search_box->add_quick_link('Find out more about your MSPs for ' . $data["mp_data"]["constituency"] . ' (' . $regional_con . ')', '/postcode/?pc=' . $data["mp_data"]['postcode'], 'torso'); } $search_box->add_quick_link('Create and manage email alerts', '/alert/', 'megaphone'); $search_box->add_quick_link(gettext('Subscribe to our newsletter'), '/about/#about-mysociety', 'mail'); @@ -34,21 +33,21 @@ protected function getSearchBox(array $data): Search\SearchBox{ } protected function getEditorialContent() { - $debatelist = new \SPLIST; - $item = $debatelist->display('recent_debates', array('days' => 7, 'num' => 1), 'none'); + $debatelist = new \SPLIST(); + $item = $debatelist->display('recent_debates', ['days' => 7, 'num' => 1], 'none'); $item = $item['data'][0]; $more_url = new Url('spdebatesfront'); $item['more_url'] = $more_url->generate(); $item['desc'] = 'Scottish Parliament debate'; - $item['related'] = array(); + $item['related'] = []; $item['featured'] = false; return $item; } protected function getURLs() { - $urls = array(); + $urls = []; $regional = new Url('msp'); $urls['regional'] = $regional->generate(); @@ -64,7 +63,7 @@ protected function getCalendarData() { protected function getRegionalList() { global $THEUSER; - $mreg = array(); + $mreg = []; if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) { return Member::getRegionalList($THEUSER->postcode, 4, 'SPE'); diff --git a/classes/Search.php b/classes/Search.php index fec5043f25..439939b987 100644 --- a/classes/Search.php +++ b/classes/Search.php @@ -1,10 +1,10 @@ searchstring = $argparser->construct_search_string(); $this->searchkeyword = $argparser->searchkeyword; - if ( !$this->searchstring ) { + if (!$this->searchstring) { $data = $this->get_form_params($data); $data['searchstring'] = ''; $data['template'] = 'search/results'; @@ -28,14 +28,14 @@ public function display() { $this->searchstring = filter_user_input($this->searchstring, 'strict'); $warnings = $this->validate_search_string(); - if ( $warnings ) { + if ($warnings) { $data['warnings'] = $warnings; $data['template'] = 'search/results'; $data['searchstring'] = $this->searchstring; $data = $this->get_form_params($data); return $data; } else { - if (get_http_var('o')=='p') { + if (get_http_var('o') == 'p') { $search = new Search\ByUsage(); $data = $search->search($this->searchstring); $data['template'] = 'search/by-person'; @@ -48,11 +48,11 @@ public function display() { $data['person_id'] = $argparser->person_id; if ($argparser->person_id) { - $MEMBER = new \MEMBER(array('person_id'=>$argparser->person_id)); + $MEMBER = new \MEMBER(['person_id' => $argparser->person_id]); $data['person_name'] = $MEMBER->full_name(); } - if ( isset($data['info']['spelling_correction']) ) { + if (isset($data['info']['spelling_correction'])) { $data['info']['spelling_correction_display'] = $this->prettifySearchString($data['info']['spelling_correction']); } @@ -131,16 +131,16 @@ private function prettify_search_section($section) { private function get_urls() { global $this_page; - $urls = array(); + $urls = []; $url = new Url($this_page); - $url->insert(array('o' => 'r')); + $url->insert(['o' => 'r']); $urls['relevance'] = $url->generate(); - $url->insert(array('o' => 'o')); + $url->insert(['o' => 'o']); $urls['oldest'] = $url->generate(); - $url->insert(array('o' => 'd')); + $url->insert(['o' => 'd']); $urls['newest'] = $url->generate(); - $url->insert(array('o' => 'p')); + $url->insert(['o' => 'p']); $urls['by-person'] = $url->generate(); return $urls; @@ -150,15 +150,15 @@ private function get_form_params($data) { $data['search_keyword'] = $this->searchkeyword; $is_adv = false; - foreach ( array('to', 'from', 'person', 'section', 'column', 'phrase', 'exclude' ) as $var ) { + foreach (['to', 'from', 'person', 'section', 'column', 'phrase', 'exclude' ] as $var) { $key = "search_$var"; - $data[$key] = get_http_var( $var ); - if ( $data[$key] ) { + $data[$key] = get_http_var($var); + if ($data[$key]) { $is_adv = true; } } - if ( isset($data['search_section']) ) { + if (isset($data['search_section'])) { $data['search_section_pretty'] = $this->prettify_search_section($data['search_section']); } @@ -168,16 +168,16 @@ private function get_form_params($data) { private function set_wtt_options($data) { $data['wtt'] = ''; - if ( $wtt = get_http_var('wtt') ) { + if ($wtt = get_http_var('wtt')) { $data['wtt'] = $wtt; - if ( $wtt == 2 && $pid = get_http_var('pid') ) { + if ($wtt == 2 && $pid = get_http_var('pid')) { $data['pid'] = null; try { - $lord = new Member(array('person_id' => $pid, 'house' => 2)); - } catch ( MemberException $e ) { + $lord = new Member(['person_id' => $pid, 'house' => 2]); + } catch (MemberException $e) { return $data; } - if ( $lord->valid ) { + if ($lord->valid) { $data['pid'] = $pid; $data['wtt_lord_name'] = $lord->full_name(); } @@ -197,20 +197,20 @@ protected function get_search_url($params = true) { if (preg_match_all('#speaker:(\d+)#', $value, $m) == 1) { $person_id = $m[1][0]; $value = str_replace('speaker:' . $person_id, '', $value); - $url->insert(array('pid' => $person_id)); - } - $url->insert(array('q' => $value)); + $url->insert(['pid' => $person_id]); + } + $url->insert(['q' => $value]); } - if ( $params ) { - if ( get_http_var('house') ) { - $url->insert(array('house' => get_http_var('house'))); + if ($params) { + if (get_http_var('house')) { + $url->insert(['house' => get_http_var('house')]); } - if ( get_http_var('wtt') ) { - $url->insert(array('wtt' => get_http_var('wtt'))); + if (get_http_var('wtt')) { + $url->insert(['wtt' => get_http_var('wtt')]); } } else { - $url->remove(array('o', 'house')); + $url->remove(['o', 'house']); } return $url; @@ -220,7 +220,7 @@ private function set_page_title($data) { global $DATA, $this_page; $pagetitle = ''; - if ( isset($data['search_type']) && $data['search_type'] == 'person' ) { + if (isset($data['search_type']) && $data['search_type'] == 'person') { if (isset($data['wtt']) && $data['wtt'] > 0) { $pagetitle = 'League table of Lords who say ' . $data['pagetitle']; } else { diff --git a/classes/Search/ByUsage.php b/classes/Search/ByUsage.php index 71d12f84a3..529e14e8fe 100644 --- a/classes/Search/ByUsage.php +++ b/classes/Search/ByUsage.php @@ -1,10 +1,10 @@ $this->searchstring, 'p' => $pagenum, 'num' => get_http_var('num'), 'pop' => get_http_var('pop'), - 'o' => ($o=='d' || $o=='r' || $o=='o') ? $o : 'd', - ); + 'o' => ($o == 'd' || $o == 'r' || $o == 'o') ? $o : 'd', + ]; return $args; } @@ -28,14 +28,14 @@ private function get_first_page_data($args) { $cons = null; $glossary = null; - $mp_types = array(); + $mp_types = []; if ($args['p'] == 1 && $args['s'] && !preg_match('#[a-z]+:[a-z0-9]+#', $args['s'])) { $members = $this->find_members(); - list($cons, $mp_types) = $this->find_constituency($args); + [$cons, $mp_types] = $this->find_constituency($args); $glossary = $this->find_glossary_items($args); } - return array($members, $cons, $mp_types, $glossary); + return [$members, $cons, $mp_types, $glossary]; } public function search($searchstring) { @@ -55,25 +55,25 @@ public function search($searchstring) { } $sort_order = 'newest'; - if ( $args['o'] == 'o' ) { + if ($args['o'] == 'o') { $sort_order = 'oldest'; - } else if ( $args['o'] == 'r' ) { + } elseif ($args['o'] == 'r') { $sort_order = 'relevance'; } - list($members, $cons, $mp_types, $glossary) = $this->get_first_page_data($args); + [$members, $cons, $mp_types, $glossary] = $this->get_first_page_data($args); if (!defined('FRONT_END_SEARCH') || !FRONT_END_SEARCH) { - return array( - 'error' =>'Apologies, search has been turned off currently for performance reasons.' - ); + return [ + 'error' => 'Apologies, search has been turned off currently for performance reasons.', + ]; } if (!$SEARCHENGINE->valid) { - return array('error' => $SEARCHENGINE->error); + return ['error' => $SEARCHENGINE->error]; } else { $LIST = new \HANSARDLIST(); - $data = $LIST->display('search', $args , 'none'); + $data = $LIST->display('search', $args, 'none'); $data['search_type'] = 'normal'; $data['sort_order'] = $sort_order; $data['members'] = $members; @@ -93,63 +93,65 @@ private function find_constituency($args) { return false; } - list ($constituencies, ) = \MySociety\TheyWorkForYou\Utility\Search::searchConstituenciesByQuery($searchterm); + [$constituencies, ] = \MySociety\TheyWorkForYou\Utility\Search::searchConstituenciesByQuery($searchterm); $constituency = ""; - if (count($constituencies)==1) { + if (count($constituencies) == 1) { $constituency = $constituencies[0]; } - $cons = array(); - $mp_types = array( + $cons = []; + $mp_types = [ 'mp' => 0, - 'former' => 0 - ); + 'former' => 0, + ]; if ($constituency != '') { try { - // Got a match, display.... + // Got a match, display.... - $MEMBER = new \MySociety\TheyWorkForYou\Member(array('constituency'=>$constituency, 'house' => 1)); + $MEMBER = new \MySociety\TheyWorkForYou\Member(['constituency' => $constituency, 'house' => 1]); $cons[] = $MEMBER; - if ( $MEMBER->current_member(1) ) { + if ($MEMBER->current_member(1)) { $mp_types['mp']++; } else { $mp_types['former']++; } - } catch ( \MySociety\TheyWorkForYou\MemberException $e ) { - $cons = array(); + } catch (\MySociety\TheyWorkForYou\MemberException $e) { + $cons = []; } } elseif (count($constituencies)) { foreach ($constituencies as $constituency) { try { - $MEMBER = new \MySociety\TheyWorkForYou\Member(array('constituency'=>$constituency, 'house' => 1)); + $MEMBER = new \MySociety\TheyWorkForYou\Member(['constituency' => $constituency, 'house' => 1]); $cons[] = $MEMBER; - if ( $MEMBER->current_member(1) ) { + if ($MEMBER->current_member(1)) { $mp_types['mp']++; } else { $mp_types['former']++; } - } catch ( \MySociety\TheyWorkForYou\MemberException $e ) { + } catch (\MySociety\TheyWorkForYou\MemberException $e) { continue; } } } - return array($cons, $mp_types); + return [$cons, $mp_types]; } private function find_members() { $searchstring = trim(preg_replace('#-?[a-z]+:[a-z0-9]+#', '', $this->searchstring)); if (!$searchstring) { - return array(); + return []; } $members = \MySociety\TheyWorkForYou\Utility\Search::searchMemberDbLookup($searchstring); - $db = new \ParlDB; - $q = $db->query("SELECT person FROM moffice WHERE position LIKE :pos ORDER BY from_date DESC, moffice_id", - array('pos' => "%$searchstring%")); + $db = new \ParlDB(); + $q = $db->query( + "SELECT person FROM moffice WHERE position LIKE :pos ORDER BY from_date DESC, moffice_id", + ['pos' => "%$searchstring%"] + ); foreach ($q as $row) { $members[] = $row['person']; } @@ -158,7 +160,7 @@ private function find_members() { $members = array_unique($members); foreach ($members as $i => $pid) { - $member = new \MySociety\TheyWorkForYou\Member(array('person_id' => $pid)); + $member = new \MySociety\TheyWorkForYou\Member(['person_id' => $pid]); $members[$i] = $member; } return $members; @@ -166,40 +168,40 @@ private function find_members() { private function find_glossary_items($args) { $GLOSSARY = new \GLOSSARY($args); - $items = array(); + $items = []; if (isset($GLOSSARY->num_search_matches) && $GLOSSARY->num_search_matches >= 1) { $URL = new \MySociety\TheyWorkForYou\Url('glossary'); - $URL->insert(array('gl' => "")); + $URL->insert(['gl' => ""]); foreach ($GLOSSARY->search_matches as $glossary_id => $term) { - $URL->update(array("gl" => $glossary_id)); - $items[] = array( + $URL->update(["gl" => $glossary_id]); + $items[] = [ 'url' => $URL->generate(), 'term' => $term['title'], - 'body' => $term['body'] - ); + 'body' => $term['body'], + ]; } } return $items; } private function generate_pagination_links($data, $url, $first, $last) { - $links = array(); + $links = []; for ($n = $first; $n <= $last; $n++) { if ($n > 1) { - $url->insert(array('p'=>$n)); + $url->insert(['p' => $n]); } else { // No page number for the first page. - $url->remove(array('p')); + $url->remove(['p']); } - $link = array( + $link = [ 'url' => $url->generate(), 'page' => $n, - 'current' => ( $n == $data['page'] ) - ); + 'current' => ($n == $data['page']), + ]; $links[] = $link; } @@ -211,7 +213,7 @@ private function generate_pagination($data) { $total_results = $data['total_results']; $results_per_page = $data['results_per_page']; $page = $data['page']; - $pagelinks = array(); + $pagelinks = []; $URL = $this->get_search_url($data); @@ -239,30 +241,30 @@ private function generate_pagination($data) { $numlinks = $this->generate_pagination_links($data, $URL, $firstpage, $lastpage); $pagelinks['nums'] = $numlinks; - $pagelinks['first_result'] = $page == 1 ? 1 : ( ( $page - 1 ) * $results_per_page ) + 1; - $pagelinks['last_result'] = $page == $numpages ? $total_results : $pagelinks['first_result'] + ( $results_per_page - 1 ); + $pagelinks['first_result'] = $page == 1 ? 1 : (($page - 1) * $results_per_page) + 1; + $pagelinks['last_result'] = $page == $numpages ? $total_results : $pagelinks['first_result'] + ($results_per_page - 1); - if ( $page != 1 ) { + if ($page != 1) { $prev_page = $page - 1; - $URL->insert(array( 'p' => $prev_page ) ); - $pagelinks['prev'] = array( - 'url' => $URL->generate() - ); - $URL->insert(array( 'p' => 1 ) ); - $pagelinks['firstpage'] = array( - 'url' => $URL->generate() - ); + $URL->insert([ 'p' => $prev_page ]); + $pagelinks['prev'] = [ + 'url' => $URL->generate(), + ]; + $URL->insert([ 'p' => 1 ]); + $pagelinks['firstpage'] = [ + 'url' => $URL->generate(), + ]; } if ($page != $numpages) { $next_page = $page + 1; - $URL->insert(array( 'p' => $next_page ) ); - $pagelinks['next'] = array( - 'url' => $URL->generate() - ); - $URL->insert(array( 'p' => $numpages ) ); - $pagelinks['lastpage'] = array( - 'url' => $URL->generate() - ); + $URL->insert([ 'p' => $next_page ]); + $pagelinks['next'] = [ + 'url' => $URL->generate(), + ]; + $URL->insert([ 'p' => $numpages ]); + $pagelinks['lastpage'] = [ + 'url' => $URL->generate(), + ]; } } @@ -272,11 +274,11 @@ private function generate_pagination($data) { private function get_sidebar_links() { global $DATA, $SEARCHENGINE, $this_page; - $links = array(); + $links = []; $links['rss'] = $DATA->page_metadata($this_page, 'rss'); if ($SEARCHENGINE) { - $links['email'] = '/alert/?' . ($this->searchstring ? 'alertsearch='.urlencode($this->searchstring) : ''); + $links['email'] = '/alert/?' . ($this->searchstring ? 'alertsearch=' . urlencode($this->searchstring) : ''); $links['email_desc'] = $SEARCHENGINE->query_description_long(); } @@ -290,7 +292,7 @@ private function get_sidebar_links() { $search_engine = new \SEARCHENGINE($filter_ss); $links['email_section'] = $links['email']; $links['email_desc_section'] = $links['email_desc']; - $links['email'] = '/alert/?' . ($filter_ss ? 'alertsearch='.urlencode($filter_ss) : ''); + $links['email'] = '/alert/?' . ($filter_ss ? 'alertsearch=' . urlencode($filter_ss) : ''); $links['email_desc'] = $search_engine->query_description_long(); } diff --git a/classes/Search/ParseArgs.php b/classes/Search/ParseArgs.php index c9a3e134db..5a6c950755 100644 --- a/classes/Search/ParseArgs.php +++ b/classes/Search/ParseArgs.php @@ -1,10 +1,10 @@ homepage_panel_class = $homepage_panel_class; $this->homepage_subhead = $homepage_subhead; $this->homepage_desc = $homepage_desc; @@ -24,11 +23,8 @@ public function __construct(string $homepage_panel_class = '', $this->quick_links = $quick_links; } - public function add_quick_link(string $title, string $url, string $icon): void - { + public function add_quick_link(string $title, string $url, string $icon): void { $this->quick_links[] = ['title' => $title, 'url' => $url, 'icon' => $icon]; } } - -?> \ No newline at end of file diff --git a/classes/SectionView/DebatesView.php b/classes/SectionView/DebatesView.php index 726233b9ab..5cc51bd867 100644 --- a/classes/SectionView/DebatesView.php +++ b/classes/SectionView/DebatesView.php @@ -13,39 +13,39 @@ protected function display_front() { $this_page = "alldebatesfront"; - $DEBATELIST = new \DEBATELIST; - $debates = array(); - $debates['data'] = $DEBATELIST->display('biggest_debates', array('days'=>7, 'num'=>10), 'none'); - $args = array( 'months' => 1 ); + $DEBATELIST = new \DEBATELIST(); + $debates = []; + $debates['data'] = $DEBATELIST->display('biggest_debates', ['days' => 7, 'num' => 10], 'none'); + $args = [ 'months' => 1 ]; $debates['calendar'] = $DEBATELIST->display('calendar', $args, 'none'); $debates['rssurl'] = $DATA->page_metadata($this_page, 'rss'); $this_page = "whallfront"; - $whall = array(); + $whall = []; - $WHALLLIST = new \WHALLLIST; - $whall['data'] = $WHALLLIST->display('biggest_debates', array('days'=>7, 'num'=>10), 'none'); - $args = array( 'months' => 1 ); + $WHALLLIST = new \WHALLLIST(); + $whall['data'] = $WHALLLIST->display('biggest_debates', ['days' => 7, 'num' => 10], 'none'); + $args = [ 'months' => 1 ]; $whall['calendar'] = $WHALLLIST->display('calendar', $args, 'none'); $whall['rssurl'] = $DATA->page_metadata($this_page, 'rss'); $this_page = "lordsdebatesfront"; - $lords = array(); + $lords = []; - $LORDSDEBATELIST = new \LORDSDEBATELIST; - $lords['data'] = $LORDSDEBATELIST->display('biggest_debates', array('days'=>7, 'num'=>10), 'none'); - $args = array( 'months' => 1 ); + $LORDSDEBATELIST = new \LORDSDEBATELIST(); + $lords['data'] = $LORDSDEBATELIST->display('biggest_debates', ['days' => 7, 'num' => 10], 'none'); + $args = [ 'months' => 1 ]; $lords['calendar'] = $LORDSDEBATELIST->display('calendar', $args, 'none'); $lords['rssurl'] = $DATA->page_metadata($this_page, 'rss'); - $data = array( + $data = [ 'debates' => $debates, 'lords' => $lords, - 'whall' => $whall - ); + 'whall' => $whall, + ]; $data['template'] = 'section/index'; $this_page = "alldebatesfront"; @@ -54,10 +54,10 @@ protected function display_front() { } protected function getSearchSections() { - return array( - array( 'section' => 'debates', 'title' => 'House of Commons' ), - array( 'section' => 'lords', 'title' => 'House of Lords' ), - array( 'section' => 'whall', 'title' => 'Westminster Hall' ) - ); + return [ + [ 'section' => 'debates', 'title' => 'House of Commons' ], + [ 'section' => 'lords', 'title' => 'House of Lords' ], + [ 'section' => 'whall', 'title' => 'Westminster Hall' ], + ]; } } diff --git a/classes/SectionView/LondonView.php b/classes/SectionView/LondonView.php index 566c6f7174..f3aa4bca3a 100644 --- a/classes/SectionView/LondonView.php +++ b/classes/SectionView/LondonView.php @@ -7,11 +7,11 @@ class LondonView extends SectionView { protected $class = 'LMQLIST'; protected function front_content() { - return $this->list->display('recent_wrans', array('days'=>30, 'num'=>20), 'none'); + return $this->list->display('recent_wrans', ['days' => 30, 'num' => 20], 'none'); } protected function getViewUrls() { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('lmqs'); $urls['lmqsday'] = $day; $urls['day'] = $day; @@ -19,8 +19,8 @@ protected function getViewUrls() { } protected function getSearchSections() { - return array( - array( 'section' => 'lmqs', 'title' => 'Mayoral Questions' ) - ); + return [ + [ 'section' => 'lmqs', 'title' => 'Mayoral Questions' ], + ]; } } diff --git a/classes/SectionView/LordsView.php b/classes/SectionView/LordsView.php index 42d2a8c57c..f18e1927e7 100644 --- a/classes/SectionView/LordsView.php +++ b/classes/SectionView/LordsView.php @@ -7,6 +7,6 @@ class LordsView extends SectionView { protected $class = 'LORDSDEBATELIST'; protected function front_content() { - return $this->list->display('biggest_debates', array('days'=>7, 'num'=>20), 'none'); + return $this->list->display('biggest_debates', ['days' => 7, 'num' => 20], 'none'); } } diff --git a/classes/SectionView/NiView.php b/classes/SectionView/NiView.php index 965fd1b29d..3530f3f4a1 100644 --- a/classes/SectionView/NiView.php +++ b/classes/SectionView/NiView.php @@ -16,11 +16,11 @@ protected function display_front() { } protected function front_content() { - return $this->list->display('biggest_debates', array('days'=>30, 'num'=>20), 'none'); + return $this->list->display('biggest_debates', ['days' => 30, 'num' => 20], 'none'); } protected function getURLs($data) { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('nidebates'); $urls['niday'] = $day; @@ -31,43 +31,43 @@ protected function getURLs($data) { } protected function getSearchSections() { - return array( - array( 'section' => 'ni' ) - ); + return [ + [ 'section' => 'ni' ], + ]; } protected function display_front_ni() { global $this_page; $this_page = "nioverview"; - $data = array(); + $data = []; $data['popular_searches'] = null; $data['urls'] = $this->getURLs($data); - $DEBATELIST = new \NILIST; + $DEBATELIST = new \NILIST(); - $debates = $DEBATELIST->display('recent_debates', array('days' => 30, 'num' => 6), 'none'); + $debates = $DEBATELIST->display('recent_debates', ['days' => 30, 'num' => 6], 'none'); $MOREURL = new \MySociety\TheyWorkForYou\Url('nidebatesfront'); - $MOREURL->insert( array( 'more' => 1 ) ); + $MOREURL->insert([ 'more' => 1 ]); // this makes sure that we don't repeat this debate in the list below $random_debate = null; - if ( isset($debates['data']) && count($debates['data']) ) { + if (isset($debates['data']) && count($debates['data'])) { $random_debate = $debates['data'][0]; } - $recent = array(); - if ( isset($debates['data']) && count($debates['data']) ) { + $recent = []; + if (isset($debates['data']) && count($debates['data'])) { // at the start of a session there may be less than 6 // debates $max = 6; - if ( count($debates['data']) < 6 ) { + if (count($debates['data']) < 6) { $max = count($debates['data']); } - for ( $i = 1; $i < $max; $i++ ) { + for ($i = 1; $i < $max; $i++) { $debate = $debates['data'][$i]; $debate['desc'] = "Northern Ireland Assembly debates"; $debate['more_url'] = $MOREURL->generate(); @@ -75,17 +75,17 @@ protected function display_front_ni() { } } - $featured = array(); - if ( $random_debate ) { + $featured = []; + if ($random_debate) { $featured = $random_debate; $featured['more_url'] = $MOREURL->generate(); $featured['desc'] = 'Northern Ireland Assembly debate'; - $featured['related'] = array(); + $featured['related'] = []; $featured['featured'] = false; } $data['featured'] = $featured; - $data['debates'] = array( 'recent' => $recent); + $data['debates'] = [ 'recent' => $recent]; $data['regional'] = $this->getMLAList(); $data['search_box'] = $this->getSearchBox($data); @@ -93,8 +93,8 @@ protected function display_front_ni() { return $data; } - - protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\SearchBox{ + + protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\SearchBox { global $THEUSER; @@ -114,9 +114,9 @@ protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\S $constituency = $data["regional"][0]["constituency"]; $search_box->add_quick_link('Find out more about your MLAs for ' . $constituency, '/postcode/?pc=' . $postcode, 'torso'); } - $search_box->add_quick_link('Create and manage email alerts', '/alert/','megaphone'); + $search_box->add_quick_link('Create and manage email alerts', '/alert/', 'megaphone'); $search_box->add_quick_link(gettext('Subscribe to our newsletter'), '/about/#about-mysociety', 'mail'); - $search_box->add_quick_link('Donate to support our work', '/support-us/','heart'); + $search_box->add_quick_link('Donate to support our work', '/support-us/', 'heart'); $search_box->add_quick_link('Learn more about TheyWorkForYou', '/about/', 'magnifying-glass'); return $search_box; } @@ -124,7 +124,7 @@ protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\S protected function getMLAList() { global $THEUSER; - $mreg = array(); + $mreg = []; if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) { return \MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, 3, 'NIE'); } diff --git a/classes/SectionView/PbcView.php b/classes/SectionView/PbcView.php index 7b1ca79a76..e6d29076e7 100644 --- a/classes/SectionView/PbcView.php +++ b/classes/SectionView/PbcView.php @@ -33,10 +33,10 @@ protected function public_bill_committees() { $bill_id = null; if ($this->session && $this->bill) { $q = $this->list->db->query('select id,standingprefix from bills where title = :bill - and session = :session', array( + and session = :session', [ ':bill' => $this->bill, - ':session' => $this->session - ))->first(); + ':session' => $this->session, + ])->first(); if ($q) { $bill_id = $q['id']; $standingprefix = $q['standingprefix']; @@ -44,18 +44,18 @@ protected function public_bill_committees() { } if ($bill_id && $id) { - return $this->display_section_or_speech(array( + return $this->display_section_or_speech([ 'gid' => $standingprefix . $id, - )); + ]); } elseif ($bill_id) { # Display the page for a particular bill $this_page = 'pbc_bill'; - $args = array ( + $args = [ 'id' => $bill_id, 'title' => $this->bill, 'session' => $this->session, - ); - $data = array(); + ]; + $data = []; $data['content'] = $this->list->display('bill', $args, 'none'); $data['session'] = $this->session; $data['template'] = 'section/pbc_bill'; @@ -69,10 +69,10 @@ protected function public_bill_committees() { # Display the bills for a particular session $this_page = 'pbc_session'; $DATA->set_page_metadata($this_page, 'title', "Session $this->session"); - $args = array ( + $args = [ 'session' => $this->session, - ); - $data = array(); + ]; + $data = []; $data['rows'] = $this->list->display('session', $args, 'none'); $data['template'] = 'section/pbc_session'; $data['session'] = $this->session; @@ -83,30 +83,30 @@ protected function public_bill_committees() { } protected function getViewUrls() { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('pbc_front'); $urls['pbcday'] = $day; return $urls; } protected function getSearchSections() { - return array( - array( 'section' => 'pbc' ) - ); + return [ + [ 'section' => 'pbc' ], + ]; } protected function front_content() { - return $this->list->display( 'recent_pbc_debates', array( 'num' => 50 ), 'none' ); + return $this->list->display('recent_pbc_debates', [ 'num' => 50 ], 'none'); } protected function display_front() { global $DATA, $this_page; $this_page = 'pbc_front'; - $data = array(); + $data = []; $data['template'] = $this->index_template; - $content = array(); + $content = []; $content['data'] = $this->front_content(); $content['rssurl'] = $DATA->page_metadata($this_page, 'rss'); diff --git a/classes/SectionView/SectionView.php b/classes/SectionView/SectionView.php index 4d16afbe78..4c8bf97491 100644 --- a/classes/SectionView/SectionView.php +++ b/classes/SectionView/SectionView.php @@ -1,4 +1,5 @@ list = new $this->class(); } - list($country, $location, $assembly) = $this->getCountryDetails(); + [$country, $location, $assembly] = $this->getCountryDetails(); $this->location = $location; $this->assembly = $assembly; } @@ -38,7 +39,7 @@ public function display() { $data = $this->addCommonData($data); } elseif ($date = get_http_var('d')) { $data = $this->display_day($date); - if ( !isset($data['template']) ) { + if (!isset($data['template'])) { $data['template'] = 'section/day'; } $data = $this->addCommonData($data); @@ -46,7 +47,7 @@ public function display() { $data = $this->display_section_or_speech(); } else { $data = $this->display_front(); - if ( !isset($data['template']) ) { + if (!isset($data['template'])) { $data['template'] = 'section/recent'; } $data['search_sections'] = $this->getSearchSections(); @@ -62,16 +63,16 @@ public function display() { protected function addCommonData($data) { global $DATA, $this_page; - $common = new \MySociety\TheyWorkForYou\Common; + $common = new \MySociety\TheyWorkForYou\Common(); $data['urls'] = $this->getURLs($data); $data['popular_searches'] = []; #$common->getPopularSearches(); $data['recess_major'] = $this->getRecessMajor(); $nextprev = $DATA->page_metadata($this_page, 'nextprev'); - if ( isset($nextprev['next']['url']) ) { + if (isset($nextprev['next']['url'])) { $data['next'] = $nextprev['next']; } - if ( isset($nextprev['prev']['url']) ) { + if (isset($nextprev['prev']['url'])) { $data['prev'] = $nextprev['prev']; } @@ -80,7 +81,7 @@ protected function addCommonData($data) { if (!isset($data['title']) && $parent_page != '') { $data['title'] = $DATA->page_metadata($parent_page, 'title'); } - if ( $parent_page ) { + if ($parent_page) { $data['parent_title'] = $DATA->page_metadata($parent_page, 'title'); } @@ -92,11 +93,11 @@ protected function addCommonData($data) { protected function getURLs($data) { global $DATA, $this_page; - $urls = array(); + $urls = []; $urls = array_merge($urls, $this->getViewUrls()); - if ( isset($data['info']['page']) ) { + if (isset($data['info']['page'])) { $day = new \MySociety\TheyWorkForYou\Url($data['info']['page']); $urls['day'] = $day; } @@ -105,7 +106,7 @@ protected function getURLs($data) { } protected function getViewUrls() { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('debates'); $urls['debatesday'] = $day; $urls['day'] = $day; @@ -117,7 +118,7 @@ protected function getViewUrls() { } protected function getSearchSections() { - return array(); + return []; } protected function getRecessMajor() { @@ -140,7 +141,7 @@ protected function display_year($year) { $DATA->set_page_metadata($this_page, 'title', $year); } - $args = array ( 'year' => $year ); + $args = [ 'year' => $year ]; $data = $this->list->display('calendar', $args, 'none'); return $data; } @@ -148,18 +149,18 @@ protected function display_year($year) { protected function display_column($date, $column) { global $this_page; $this_page = $this->page_base; - $args = array( 'date' => $date, 'column' => $column ); + $args = [ 'date' => $date, 'column' => $column ]; $content = $this->list->display('column', $args, 'none'); - $data = array(); + $data = []; $data['column'] = $column; $URL = new \MySociety\TheyWorkForYou\Url($this->list->listpage); - $URL->insert(array('d' => $date)); + $URL->insert(['d' => $date]); $data['debate_day_link'] = $URL->generate(); $data['debate_day_human'] = format_date($date, LONGDATEFORMAT); $data['rows'] = $content; - $data['info'] = array('major' => $this->major, 'date' => $date); + $data['info'] = ['major' => $this->major, 'date' => $date]; $data['template'] = 'section/column'; return $data; @@ -168,26 +169,26 @@ protected function display_column($date, $column) { protected function display_day($date) { global $this_page; $this_page = $this->page_base . 'day'; - $args = array ( 'date' => get_http_var('d') ); + $args = [ 'date' => get_http_var('d') ]; $data = $this->list->display('date', $args, 'none'); - list($year, $month, $day) = explode('-', $date); - $args = array( 'year' => $year, 'month' => $month, 'day' => $day); + [$year, $month, $day] = explode('-', $date); + $args = [ 'year' => $year, 'month' => $month, 'day' => $day]; $calendar = $this->list->display('calendar', $args, 'none'); - if ( isset($calendar['years']) ) { + if (isset($calendar['years'])) { $data['calendar'] = $calendar['years']; } return $data; } - protected function display_section_or_speech($args = array()) { + protected function display_section_or_speech($args = []) { global $DATA, $this_page, $THEUSER; # += as we *don't* want to override any already supplied argument - $args += array ( + $args += [ 'gid' => get_http_var('id'), 's' => get_http_var('s'), // Search terms to be highlighted. 'member_id' => get_http_var('m'), // Member's speeches to be highlighted. - ); + ]; if (preg_match('/speaker:(\d+)/', get_http_var('s'), $mmm)) { $args['person_id'] = $mmm[1]; @@ -200,14 +201,14 @@ protected function display_section_or_speech($args = array()) { if ($this->major == 6) { # Magically (as in I can't remember quite why), pbc_clause will # contain the new URL without any change... - $URL->remove( array('id') ); + $URL->remove(['id']); } else { - $URL->insert( array('id'=>$e->getMessage()) ); + $URL->insert(['id' => $e->getMessage()]); } # put the search term back in so highlighting works. # NB: as we don't see the # part of the URL we lose this :( - if ( $args['s'] !== '' ) { - $URL->insert( array('s'=>$args['s']) ); + if ($args['s'] !== '') { + $URL->insert(['s' => $args['s']]); } redirect($URL->generate('none'), 301); } @@ -215,16 +216,16 @@ protected function display_section_or_speech($args = array()) { $data['individual_item'] = ($this->list->commentspage == $this_page); if ($data['individual_item']) { - $COMMENTLIST = new \COMMENTLIST; + $COMMENTLIST = new \COMMENTLIST(); $args['user_id'] = get_http_var('u'); $args['epobject_id'] = $this->list->epobject_id(); $data['comments']['object'] = $COMMENTLIST; $data['comments']['args'] = $args; - $data['comments']['commentdata'] = array( + $data['comments']['commentdata'] = [ 'epobject_id' => $this->list->epobject_id(), 'gid' => get_http_var('id'), # wrans is LIST->gid? - 'return_page' => $this_page - ); + 'return_page' => $this_page, + ]; } if (!isset($data['info'])) { @@ -235,9 +236,9 @@ protected function display_section_or_speech($args = array()) { # Okay, let's set up highlighting and glossarisation - list($bodies, $speeches) = $this->highlightSpeeches($data); + [$bodies, $speeches] = $this->highlightSpeeches($data); - list($data, $first_speech, $subsection_title) = $this->annotateSpeeches($data, $bodies, $speeches); + [$data, $first_speech, $subsection_title] = $this->annotateSpeeches($data, $bodies, $speeches); $data = $this->setTitleAndAlertText($data, $subsection_title); @@ -247,8 +248,8 @@ protected function display_section_or_speech($args = array()) { $data['debate_day_human'] = format_date($data['info']['date'], LONGDATEFORMAT); $URL = new \MySociety\TheyWorkForYou\Url($this->list->listpage); - $URL->insert(array('d' => $data['info']['date'])); - $URL->remove(array('id')); + $URL->insert(['d' => $data['info']['date']]); + $URL->remove(['id']); $data['debate_day_link'] = $URL->generate(); $data['nextprev'] = $DATA->page_metadata($this_page, 'nextprev'); @@ -286,7 +287,7 @@ private function setTitleAndAlertText($data, $subsection_title) { if (array_key_exists('text_heading', $data['info'])) { // avoid having Clause 1 etc as the alert text search string on PBC pages as it's // almost certainly not what the person wants - if ( $this->major == 6 ) { + if ($this->major == 6) { $data['email_alert_text'] = $data['section_title']; } else { $data['email_alert_text'] = $data['info']['text_heading']; @@ -323,7 +324,7 @@ private function highlightSpeeches($data) { // and highlight search string words. $speeches = 0; - $bodies = array(); + $bodies = []; foreach ($data['rows'] as $row) { $htype = $row['htype']; if ($htype == 12 || $htype == 13 || $htype == 14) { @@ -332,8 +333,8 @@ private function highlightSpeeches($data) { $body = $row['body']; $body = preg_replace('#(.*?\s*\((.*?)\))#', '$4', $body); $body = preg_replace('#(.*?\s*\((.*?)\))#', '$4', $body); - $body = preg_replace_callback('#(.*?)#', function($matches) { - return '' . str_replace("Official Report", "Hansard", $matches[6]) . ''; + $body = preg_replace_callback('#(.*?)#', function ($matches) { + return '' . str_replace("Official Report", "Hansard", $matches[6]) . ''; }, $body); #$body = preg_replace('#(.*?)#e', "\"\" . str_replace('Official Report', 'Hansard', '$7') . ''", $body); $bodies[] = $body; @@ -357,7 +358,7 @@ private function highlightSpeeches($data) { twfy_debug_timestamp('After glossarise'); } - return array($bodies, $speeches); + return [$bodies, $speeches]; } private function annotateSpeeches($data, $bodies, $speeches) { @@ -366,7 +367,7 @@ private function annotateSpeeches($data, $bodies, $speeches) { $data['section_title'] = ''; $subsection_title = ''; $rows = count($data['rows']); - for ($i=0; $i<$rows; $i++) { + for ($i = 0; $i < $rows; $i++) { $row = $data['rows'][$i]; $htype = $row['htype']; // HPOS should be defined below if it's needed; otherwise default to 0 @@ -389,7 +390,7 @@ private function annotateSpeeches($data, $bodies, $speeches) { # Voting links $data['rows'][$i]['voting_data'] = ''; if (isset($row['votes'])) { - $data['rows'][$i]['voting_data'] = $this->generate_votes( $row['votes'], $row['epobject_id'], $row['gid'] ); + $data['rows'][$i]['voting_data'] = $this->generate_votes($row['votes'], $row['epobject_id'], $row['gid']); } # Annotation link @@ -421,79 +422,79 @@ private function annotateSpeeches($data, $bodies, $speeches) { } } - return array($data, $first_speech, $subsection_title); + return [$data, $first_speech, $subsection_title]; } private function getCountryDetails() { - $details = array( - 1 => array ( + $details = [ + 1 => [ 'country' => 'UK', 'assembly' => 'uk-commons', - 'location' => '– in the House of Commons' - ), - 2 => array ( + 'location' => '– in the House of Commons', + ], + 2 => [ 'country' => 'UK', 'assembly' => 'uk-commons', - 'location' => '– in Westminster Hall' - ), - 3 => array ( + 'location' => '– in Westminster Hall', + ], + 3 => [ 'country' => 'UK', 'assembly' => 'uk-commons', - 'location' => 'written question – answered' - ), - 4 => array ( + 'location' => 'written question – answered', + ], + 4 => [ 'country' => 'UK', 'assembly' => 'uk-commons', - 'location' => 'written statement – made' - ), - 5 => array ( + 'location' => 'written statement – made', + ], + 5 => [ 'country' => 'NORTHERN IRELAND', 'assembly' => 'ni', - 'location' => '– in the Northern Ireland Assembly' - ), - 6 => array ( + 'location' => '– in the Northern Ireland Assembly', + ], + 6 => [ 'country' => 'UK', 'assembly' => 'uk-commons', - 'location' => '– in a Public Bill Committee' - ), - 7 => array ( + 'location' => '– in a Public Bill Committee', + ], + 7 => [ 'country' => 'SCOTLAND', 'assembly' => 'scotland', - 'location' => '– in the Scottish Parliament' - ), - 8 => array ( + 'location' => '– in the Scottish Parliament', + ], + 8 => [ 'country' => 'SCOTLAND', 'assembly' => 'scotland', - 'location' => '– Scottish Parliament written question – answered' - ), - 9 => array ( + 'location' => '– Scottish Parliament written question – answered', + ], + 9 => [ 'country' => 'LONDON', 'assembly' => 'london-assembly', - 'location' => 'Questions to the Mayor of London – answered' - ), - 10 => array ( + 'location' => 'Questions to the Mayor of London – answered', + ], + 10 => [ 'country' => 'WALES', 'assembly' => 'senedd', - 'location' => '– in the Senedd' - ), - 11 => array ( + 'location' => '– in the Senedd', + ], + 11 => [ 'country' => 'WALES', 'assembly' => 'senedd', - 'location' => '– Senedd Cymru' - ), - 101 => array ( + 'location' => '– Senedd Cymru', + ], + 101 => [ 'country' => 'UK', 'assembly' => 'uk-lords', - 'location' => '– in the House of Lords' - ) - ); + 'location' => '– in the House of Lords', + ], + ]; $detail = $details[$this->major]; - return array($detail['country'], $detail['location'], $detail['assembly']); + return [$detail['country'], $detail['location'], $detail['assembly']]; } private function majorToConsType() { - $major_to_cons_type = array( + $major_to_cons_type = [ 1 => 'WMC', 2 => 'WMC', 3 => 'WMC', @@ -505,7 +506,7 @@ private function majorToConsType() { 10 => 'WAC', 11 => 'WAC', 101 => '', - ); + ]; return $major_to_cons_type[$this->major]; } @@ -513,18 +514,18 @@ private function majorToConsType() { protected function display_front() { global $DATA, $this_page; $this_page = $this->page_base . 'front'; - $data = array(); - if ( $this->index_template ) { + $data = []; + if ($this->index_template) { $data['template'] = $this->index_template; } - $class = new $this->class; - $content = array(); + $class = new $this->class(); + $content = []; $content['data'] = $this->front_content(); - $content['calendar'] = $class->display('calendar', array('months' => 1), 'none'); + $content['calendar'] = $class->display('calendar', ['months' => 1], 'none'); - if ( $rssurl = $DATA->page_metadata($this_page, 'rss') ) { + if ($rssurl = $DATA->page_metadata($this_page, 'rss')) { $content['rssurl'] = $rssurl; } @@ -539,7 +540,7 @@ public function is_debate_section_page() { } //$totalcomments, $comment, $commenturl - function generate_commentteaser ($row) { + public function generate_commentteaser($row) { // Returns HTML for the one fragment of comment and link for the sidebar. // $totalcomments is the number of comments this item has on it. // $comment is an array like: @@ -588,13 +589,13 @@ function generate_commentteaser ($row) { } } - return array( + return [ 'body' => prepare_comment_for_display($commentbody), 'username' => _htmlentities($comment['username']), 'linktext' => $linktext, 'commentsurl' => $row['commentsurl'], 'comment_id' => $comment['comment_id'], - ); + ]; } protected function get_question_mentions_html($row_data) { @@ -602,7 +603,7 @@ protected function get_question_mentions_html($row_data) { } private function pageToSection() { - $sections = array( + $sections = [ 1 => 'debates', 2 => 'whall', 3 => 'wrans', @@ -614,8 +615,8 @@ private function pageToSection() { 9 => 'lmqs', 10 => 'senedd', 11 => 'senedd', - 101 => 'lords' - ); + 101 => 'lords', + ]; return $sections[$this->major]; } diff --git a/classes/SectionView/SeneddView.php b/classes/SectionView/SeneddView.php index fad488dc95..4ea0b7d452 100644 --- a/classes/SectionView/SeneddView.php +++ b/classes/SectionView/SeneddView.php @@ -25,11 +25,11 @@ protected function display_front() { } protected function front_content() { - return $this->list->display('biggest_debates', array('days'=>30, 'num'=>20), 'none'); + return $this->list->display('biggest_debates', ['days' => 30, 'num' => 20], 'none'); } protected function getURLs($data) { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('senedddebates'); $urls['seneddday'] = $day; @@ -39,16 +39,16 @@ protected function getURLs($data) { } protected function getSearchSections() { - return array( - array( 'section' => 'wales' ) - ); + return [ + [ 'section' => 'wales' ], + ]; } protected function display_front_senedd() { global $this_page; $this_page = "seneddoverview"; - $data = array(); + $data = []; $data['popular_searches'] = null; @@ -59,25 +59,25 @@ protected function display_front_senedd() { $DEBATELIST = new $this->class(); - $debates = $DEBATELIST->display('recent_debates', array('days' => 30, 'num' => 6), 'none'); + $debates = $DEBATELIST->display('recent_debates', ['days' => 30, 'num' => 6], 'none'); $MOREURL = new \MySociety\TheyWorkForYou\Url('senedddebatesfront'); - $MOREURL->insert( array( 'more' => 1 ) ); + $MOREURL->insert([ 'more' => 1 ]); // this makes sure that we don't repeat this debate in the list below $random_debate = null; - if ( isset($debates['data']) && count($debates['data']) ) { + if (isset($debates['data']) && count($debates['data'])) { $random_debate = $debates['data'][0]; } - $recent = array(); - if ( isset($debates['data']) && count($debates['data']) ) { + $recent = []; + if (isset($debates['data']) && count($debates['data'])) { // at the start of a session there may be less than 6 // debates $max = 6; - if ( count($debates['data']) < 6 ) { + if (count($debates['data']) < 6) { $max = count($debates['data']); } - for ( $i = 1; $i < $max; $i++ ) { + for ($i = 1; $i < $max; $i++) { $debate = $debates['data'][$i]; $debate['desc'] = "Senedd"; $debate['more_url'] = $MOREURL->generate(); @@ -85,17 +85,17 @@ protected function display_front_senedd() { } } - $featured = array(); - if ( $random_debate ) { + $featured = []; + if ($random_debate) { $featured = $random_debate; $featured['more_url'] = $MOREURL->generate(); $featured['desc'] = 'Senedd'; - $featured['related'] = array(); + $featured['related'] = []; $featured['featured'] = false; } $data['featured'] = $featured; - $data['debates'] = array( 'recent' => $recent); + $data['debates'] = [ 'recent' => $recent]; $data['regional'] = $this->getMSList(); $data['search_box'] = $this->getSearchBox($data); @@ -104,7 +104,7 @@ protected function display_front_senedd() { return $data; } - protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\SearchBox{ + protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\SearchBox { $search_box = new \MySociety\TheyWorkForYou\Search\SearchBox(); $search_box->homepage_panel_class = "panel--homepage--senedd"; $search_box->homepage_subhead = gettext("Senedd / Welsh Parliament"); @@ -113,14 +113,14 @@ protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\S $search_box->quick_links = []; if (count($data["regional"])) { // get all unique constituencies - $constituencies = array(); + $constituencies = []; foreach ($data["regional"] as $member) { $constituencies[$member["constituency"]] = 1; } $constituencies = array_keys($constituencies); - $search_box->add_quick_link(sprintf(gettext('Find out more about your MSs for %s and %s'), $constituencies[0], $constituencies[1]), '/postcode/?pc=' . $data["mp_data"]['postcode'],'torso'); + $search_box->add_quick_link(sprintf(gettext('Find out more about your MSs for %s and %s'), $constituencies[0], $constituencies[1]), '/postcode/?pc=' . $data["mp_data"]['postcode'], 'torso'); } - $search_box->add_quick_link(gettext('Create and manage email alerts'), '/alert/','megaphone'); + $search_box->add_quick_link(gettext('Create and manage email alerts'), '/alert/', 'megaphone'); $search_box->add_quick_link(gettext('Subscribe to our newsletter'), '/about/#about-mysociety', 'mail'); $search_box->add_quick_link(gettext('Donate to support our work'), '/support-us/', 'heart'); $search_box->add_quick_link(gettext('Learn more about TheyWorkForYou'), '/about/', 'magnifying-glass'); @@ -130,7 +130,7 @@ protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\S protected function getMSList() { global $THEUSER; - $mreg = array(); + $mreg = []; if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) { return array_merge( \MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, 5, 'WAC'), diff --git a/classes/SectionView/SpView.php b/classes/SectionView/SpView.php index b4b61d8a4b..e1d11dff64 100644 --- a/classes/SectionView/SpView.php +++ b/classes/SectionView/SpView.php @@ -7,7 +7,7 @@ class SpView extends SectionView { protected $class = 'SPLIST'; protected function front_content() { - return $this->list->display('biggest_debates', array('days'=>7, 'num'=>20), 'none'); + return $this->list->display('biggest_debates', ['days' => 7, 'num' => 20], 'none'); } protected function get_question_mentions_html($row_data) { @@ -15,7 +15,7 @@ protected function get_question_mentions_html($row_data) { } protected function getViewUrls() { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('spdebates'); $urls['spdebatesday'] = $day; $urls['day'] = $day; @@ -23,8 +23,8 @@ protected function getViewUrls() { } protected function getSearchSections() { - return array( - array( 'section' => 'sp' ) - ); + return [ + [ 'section' => 'sp' ], + ]; } } diff --git a/classes/SectionView/SpwransView.php b/classes/SectionView/SpwransView.php index f125271ea0..fa56234ce2 100644 --- a/classes/SectionView/SpwransView.php +++ b/classes/SectionView/SpwransView.php @@ -19,13 +19,13 @@ public function display() { protected function display_front() { global $this_page, $DATA; $this_page = 'spwransfront'; - $data = array(); + $data = []; - $args = array( 'months' => 1 ); - $WRANSLIST = new \SPWRANSLIST; + $args = [ 'months' => 1 ]; + $WRANSLIST = new \SPWRANSLIST(); - $wrans = array(); - $wrans['data'] = $WRANSLIST->display('recent_wrans', array('days'=>7, 'num'=>5), 'none'); + $wrans = []; + $wrans['data'] = $WRANSLIST->display('recent_wrans', ['days' => 7, 'num' => 5], 'none'); $wrans['calendar'] = $WRANSLIST->display('calendar', $args, 'none'); $data['content'] = $wrans; @@ -34,7 +34,7 @@ protected function display_front() { } protected function getViewUrls() { - $urls = array(); + $urls = []; $day = new \MySociety\TheyWorkForYou\Url('spwrans'); $urls['day'] = $day; $urls['spwransday'] = $day; @@ -42,60 +42,60 @@ protected function getViewUrls() { } protected function getSearchSections() { - return array( - array( 'section' => 'spwrans' ) - ); + return [ + [ 'section' => 'spwrans' ], + ]; } private function spwrans_redirect($spid) { global $PAGE; # We have a Scottish Parliament ID, need to find the date - $SPWRANSLIST = new \SPWRANSLIST; + $SPWRANSLIST = new \SPWRANSLIST(); $gid = $SPWRANSLIST->get_gid_from_spid($spid); if ($gid) { - if (preg_match('/uk\.org\.publicwhip\/spwa\/(\d{4}-\d\d-\d\d\.(.*))/',$gid,$m)) { + if (preg_match('/uk\.org\.publicwhip\/spwa\/(\d{4}-\d\d-\d\d\.(.*))/', $gid, $m)) { $URL = new \MySociety\TheyWorkForYou\Url('spwrans'); $URL->reset(); - $URL->insert( array('id' => $m[1]) ); + $URL->insert(['id' => $m[1]]); $fragment_identifier = '#g' . $m[2]; header('Location: ' . $URL->generate('none') . $fragment_identifier, true, 303); exit; - } elseif (preg_match('/uk\.org\.publicwhip\/spor\/(\d{4}-\d\d-\d\d\.(.*))/',$gid,$m)) { + } elseif (preg_match('/uk\.org\.publicwhip\/spor\/(\d{4}-\d\d-\d\d\.(.*))/', $gid, $m)) { $URL = new \MySociety\TheyWorkForYou\Url('spdebates'); $URL->reset(); - $URL->insert( array('id' => $m[1]) ); + $URL->insert(['id' => $m[1]]); $fragment_identifier = '#g' . $m[2]; header('Location: ' . $URL->generate('none') . $fragment_identifier, true, 303); exit; } else { - $PAGE->error_message ("Strange GID ($gid) for that Scottish Parliament ID."); + $PAGE->error_message("Strange GID ($gid) for that Scottish Parliament ID."); } } - $PAGE->error_message ("Couldn't match that Scottish Parliament ID to a GID."); + $PAGE->error_message("Couldn't match that Scottish Parliament ID to a GID."); } protected function get_question_mentions_html($row_data) { - if( count($row_data) == 0 ) { + if(count($row_data) == 0) { return ''; } $result = ''; $last_date = null; $first_difference_output = true; // Keep the references until after the history that's in a timeline: - $references = array(); + $references = []; foreach ($row_data as $row) { - if( ! $row["date"] ) { + if(! $row["date"]) { // If this mention isn't associated with a date, the difference won't be interesting. $last_date = null; } $description = ''; if ($last_date && ($last_date != $row["date"])) { // Calculate how long the gap was in days: - $daysdiff = (integer)((strtotime($row["date"]) - strtotime($last_date)) / 86400); + $daysdiff = (int) ((strtotime($row["date"]) - strtotime($last_date)) / 86400); $daysstring = ($daysdiff == 1) ? "day" : "days"; $further = ""; - if( $first_difference_output ) { + if($first_difference_output) { $first_difference_output = false; } else { $further = " a further"; @@ -106,7 +106,7 @@ protected function get_question_mentions_html($row_data) { $inner = "BUG: Unknown mention type $row[type]"; $date = format_date($row['date'], SHORTDATEFORMAT); $url = $row['url']; - if ( strpos($url, 'business/businessBulletin') !== false ) { + if (strpos($url, 'business/businessBulletin') !== false) { $url = str_replace('www.scottish', 'archive.scottish', $url); } switch ($row["type"]) { @@ -120,9 +120,9 @@ protected function get_question_mentions_html($row_data) { $inner = "Mentioned in tabled written questions on $date"; break; case 4: - if( preg_match('/^uk.org.publicwhip\/spq\/(.*)$/',$row['gid'],$m) ) { + if(preg_match('/^uk.org.publicwhip\/spq\/(.*)$/', $row['gid'], $m)) { $URL = new \MySociety\TheyWorkForYou\Url("spwrans"); - $URL->insert( array('spid' => $m[1]) ); + $URL->insert(['spid' => $m[1]]); $relative_url = $URL->generate("none"); $inner = "Given a written answer on $date"; } @@ -131,25 +131,25 @@ protected function get_question_mentions_html($row_data) { $inner = "Given a holding answer on $date"; break; case 6: - if( preg_match('/^uk.org.publicwhip\/spor\/(.*)$/',$row['mentioned_gid'],$m) ) { + if(preg_match('/^uk.org.publicwhip\/spor\/(.*)$/', $row['mentioned_gid'], $m)) { $URL = new \MySociety\TheyWorkForYou\Url("spdebates"); - $URL->insert( array('id' => $m[1]) ); + $URL->insert(['id' => $m[1]]); $relative_url = $URL->generate("none"); $inner = "Asked in parliament on $date"; } break; case 7: - if( preg_match('/^uk.org.publicwhip\/spq\/(.*)$/',$row['mentioned_gid'],$m) ) { + if(preg_match('/^uk.org.publicwhip\/spq\/(.*)$/', $row['mentioned_gid'], $m)) { $referencing_spid = $m[1]; $URL = new \MySociety\TheyWorkForYou\Url("spwrans"); - $URL->insert( array('spid' => $referencing_spid) ); + $URL->insert(['spid' => $referencing_spid]); $relative_url = $URL->generate("none"); $inner = "Referenced in question $referencing_spid"; $reference = true; } break; } - if( $reference ) { + if($reference) { $references[] = "\n
  • $inner."; } else { $result .= "\n
  • - - 1 ) { - if ( $mp_types['mp'] > 0 && $mp_types['former'] > 0 ) { + + 1) { + if ($mp_types['mp'] > 0 && $mp_types['former'] > 0) { $desc = gettext('MPs and former MPs'); - } elseif ( $mp_types['mp'] > 0 ) { + } elseif ($mp_types['mp'] > 0) { $desc = gettext('MPs'); - } elseif ( $mp_types['former'] > 0 ) { + } elseif ($mp_types['former'] > 0) { $desc = gettext('Former MPs'); } - ?> + ?>

    %s'), $desc, _htmlentities($searchstring)) ?>

    - +

    %s'), _htmlentities($searchstring)) ?>

    - +

    %s'), _htmlentities($searchstring)) ?>

    - + - +

    %s'), _htmlentities($searchstring)) ?>

    - +
    @@ -45,43 +45,43 @@

    Glossary items matching

    - +
    - +

    I want to write to

    - + There was an error – – searching for .

    %s', _htmlentities($searchdescription)); - if ( $pagination_links ) { ?> + $term = sprintf('%s', _htmlentities($searchdescription)); + if ($pagination_links) { ?> - + - +

    - -

    ' . _htmlentities( $info['spelling_correction_display'] ) . '') ?>

    + +

    ' . _htmlentities($info['spelling_correction_display']) . '') ?>

    - +
      - +
    • : /
    • - +
    • relevance'), $urls['relevance']) ?>
    • : /
    • @@ -92,7 +92,7 @@
    - +

    ()

    @@ -101,22 +101,22 @@
    - +
    - + << < - + > - + > >>
    - +
    diff --git a/www/includes/easyparliament/templates/html/search/sidebar.php b/www/includes/easyparliament/templates/html/search/sidebar.php index eaeb712146..560c3dea3d 100644 --- a/www/includes/easyparliament/templates/html/search/sidebar.php +++ b/www/includes/easyparliament/templates/html/search/sidebar.php @@ -1,9 +1,9 @@
    - +

    diff --git a/www/includes/easyparliament/templates/html/section/_business_list_item.php b/www/includes/easyparliament/templates/html/section/_business_list_item.php index c48b891e12..e59c2dcca7 100644 --- a/www/includes/easyparliament/templates/html/section/_business_list_item.php +++ b/www/includes/easyparliament/templates/html/section/_business_list_item.php @@ -1,6 +1,6 @@

    - +
    @@ -12,11 +12,11 @@
    - +

    - 0 ) { ?> + 0) { ?> - +

    diff --git a/www/includes/easyparliament/templates/html/section/_business_section.php b/www/includes/easyparliament/templates/html/section/_business_section.php index 451b74146d..4f922f25a5 100644 --- a/www/includes/easyparliament/templates/html/section/_business_section.php +++ b/www/includes/easyparliament/templates/html/section/_business_section.php @@ -1,7 +1,7 @@

    - + Dadleuon diweddar Y Senedd @@ -10,7 +10,7 @@

    @@ -21,10 +21,10 @@
    + include '_calendar_section.php'; + ?>
    - +

    diff --git a/www/includes/easyparliament/templates/html/section/_calendar.php b/www/includes/easyparliament/templates/html/section/_calendar.php index 6786880602..44f006e544 100644 --- a/www/includes/easyparliament/templates/html/section/_calendar.php +++ b/www/includes/easyparliament/templates/html/section/_calendar.php @@ -1,45 +1,45 @@

    2 && $datebits[0] == $year && $datebits[1] == $month) { - $toDay = $datebits[2]; - } else { - $toDay = ''; - } - } else { - // If this calendar is for this current, real world, month - // we get the value of today, so we can highlight it. - $nowDateComponents = getdate(); - - if ($nowDateComponents['year'] == $year && $nowDateComponents['mon'] == $month) { - $toDay = $nowDateComponents['mday']; - } else { - $toDay = ''; - } - } - - $dayOfWeek = strftime('%w', $firstDayOfMonth) - 1; - - // Adjusted to cope with the week starting on Monday. - if ($dayOfWeek < 0) { - $dayOfWeek = 6; - } - ?> + // What is the first day of the month in question? + $firstDayOfMonth = mktime(0, 0, 0, $month, 1, $year); + + // How many days does this month contain? + $numberDays = date('t', $firstDayOfMonth); + + // What is the name of the month in question? + $monthName = strftime('%B', $firstDayOfMonth); + + if (isset($info['onday'])) { + // 'onday' is like 'yyyy-mm-dd'. + $datebits = explode('-', $info['onday']); + if (count($datebits) > 2 && $datebits[0] == $year && $datebits[1] == $month) { + $toDay = $datebits[2]; + } else { + $toDay = ''; + } + } else { + // If this calendar is for this current, real world, month + // we get the value of today, so we can highlight it. + $nowDateComponents = getdate(); + + if ($nowDateComponents['year'] == $year && $nowDateComponents['mon'] == $month) { + $toDay = $nowDateComponents['mday']; + } else { + $toDay = ''; + } + } + + $dayOfWeek = strftime('%w', $firstDayOfMonth) - 1; + + // Adjusted to cope with the week starting on Monday. + if ($dayOfWeek < 0) { + $dayOfWeek = 6; + } + ?> + if (!isset($years)) { ?>
    - +   @@ -47,7 +47,7 @@ - +   @@ -75,93 +75,93 @@ 0) { - print " "; - } + if ($dayOfWeek > 0) { + print " "; + } - $currentDay = 1; + $currentDay = 1; - while ($currentDay <= $numberDays) { + while ($currentDay <= $numberDays) { - // Seventh column (Sunday) reached. Start a new row. + // Seventh column (Sunday) reached. Start a new row. - if ($dayOfWeek == 7) { + if ($dayOfWeek == 7) { - $dayOfWeek = 0; - ?> + $dayOfWeek = 0; + ?> '; - } elseif ($recess[0]) { - print ''; - } else { - print ''; - } - - // Is the $currentDay a member of $dates? If so, - // the day should be linked. - if (in_array($currentDay,$dates)) { - - $date = sprintf("%04d-%02d-%02d", $year, $month, $currentDay); - - if ($currentDay == $toDay) { - print '' . $currentDay . ''; - } else { - $day_section = $section; - if ($section == 'sp') { - $day_section = 'spdebates'; - } - $urls[$day_section . 'day']->insert(array('d'=>$date)); - print "generate() . "\">$currentDay"; - } - - // $currentDay is not a member of $dates. - - } else { - - print '' . $currentDay . ''; - } - // Increment counters - - $currentDay++; - $dayOfWeek++; - } - - // Complete the row of the last week in month, if necessary - - if ($dayOfWeek != 7) { - - $remainingDays = 7 - $dayOfWeek; - print " "; - } -?> + } + + $recess = recess_prettify($currentDay, $month, $year, $recess_major); + + // Is this day actually Today in the real world? + // If so, higlight it. + // Also highlight days where there are no + // sittings - e.g. WH is only Tuesday-Thursday + if ($currentDay == $toDay) { + print ''; + } elseif ($recess[0]) { + print ''; + } else { + print ''; + } + + // Is the $currentDay a member of $dates? If so, + // the day should be linked. + if (in_array($currentDay, $dates)) { + + $date = sprintf("%04d-%02d-%02d", $year, $month, $currentDay); + + if ($currentDay == $toDay) { + print '' . $currentDay . ''; + } else { + $day_section = $section; + if ($section == 'sp') { + $day_section = 'spdebates'; + } + $urls[$day_section . 'day']->insert(['d' => $date]); + print "generate() . "\">$currentDay"; + } + + // $currentDay is not a member of $dates. + + } else { + + print '' . $currentDay . ''; + } + // Increment counters + + $currentDay++; + $dayOfWeek++; + } + + // Complete the row of the last week in month, if necessary + + if ($dayOfWeek != 7) { + + $remainingDays = 7 - $dayOfWeek; + print " "; + } + ?> - + diff --git a/www/includes/easyparliament/templates/html/section/_calendar_section.php b/www/includes/easyparliament/templates/html/section/_calendar_section.php index 142a6fe7ce..9a6fae6192 100644 --- a/www/includes/easyparliament/templates/html/section/_calendar_section.php +++ b/www/includes/easyparliament/templates/html/section/_calendar_section.php @@ -1,6 +1,6 @@ $months) { foreach ($months as $month => $dates) { - include '_calendar.php'; + include '_calendar.php'; } } ?> diff --git a/www/includes/easyparliament/templates/html/section/_search.php b/www/includes/easyparliament/templates/html/section/_search.php index 5d595e2030..8f5dee7260 100644 --- a/www/includes/easyparliament/templates/html/section/_search.php +++ b/www/includes/easyparliament/templates/html/section/_search.php @@ -13,14 +13,14 @@ - 1) { ?> + 1) { ?>
    + } elseif (isset($section)) { ?> diff --git a/www/includes/easyparliament/templates/html/section/_section_content.php b/www/includes/easyparliament/templates/html/section/_section_content.php index 771133ac10..b993407fd6 100644 --- a/www/includes/easyparliament/templates/html/section/_section_content.php +++ b/www/includes/easyparliament/templates/html/section/_section_content.php @@ -13,17 +13,20 @@ if ($speech['htype'] == 12) { if ($hansardmajors[$data['info']['major']]['location'] == 'Scotland') { $body = preg_replace('# (S\d[O0WF]-\d+)[, ]#', ' $1 ', $body); - $body = preg_replace_callback('#\[(.*?)\]#', function($matches) { - if ($matches[1] == 'spor') { - $href_segment = 'sp/?g'; - } elseif ($matches[1] == 'spwa') { + $body = preg_replace_callback( + '#\[(.*?)\]#', + function ($matches) { + if ($matches[1] == 'spor') { + $href_segment = 'sp/?g'; + } elseif ($matches[1] == 'spwa') { $href_segment = 'spwrans/?'; } else { $href_segment = 'debates/?'; } return '[' . $matches[3] . ']'; }, - $body); + $body + ); $body = str_replace('href="../../../', 'href="http://www.scottish.parliament.uk/', $body); } @@ -55,35 +58,35 @@ # Assume a paragraph starting with a lowercase character should be run on $body = preg_replace('#(?\s*]*>(?=[a-z])(?![ivx]+\.)#', ' ', $body); - $body = str_replace(array('
    ', '

    ', '

    ', '

    ', '

    + $speaker_name = ucfirst($speaker['name']); + + [$image_url, $size] = MySociety\TheyWorkForYou\Utility\Member::findMemberImage( + $speaker['person_id'], + true, + $data['info']['major'] == 101 ? 'lord' : 'general' + ); + + if (count($speaker['office'])) { + $desc = []; + foreach ($speaker['office'] as $off) { + $desc[] = $off['pretty']; + } + $speaker_position = join(', ', $desc); + } else { + $speaker_position = _htmlentities($speaker['party']); + if ($speaker['house'] == 1 && + $speaker['party'] != 'Speaker' && + $speaker['party'] != 'Deputy Speaker' && + $speaker['constituency'] + ) { + $speaker_position .= ', ' . $speaker['constituency']; + } + } + + ?> Photo of <?= $speaker_name ?> @@ -162,8 +165,8 @@

    + if ($data['info']['major'] == 8 && preg_match('#\d{4}-\d\d-\d\d\.(.*?)\.q#', $speech['gid'], $m)) { + ?>

    @@ -184,20 +187,20 @@
    - +
    $speech['mp_vote']['vote'] ); - if ( isset($speech['before_mp']) ) { - $before_mp = $speech['before_mp']; - } - if ( isset($speech['after_mp']) ) { - $after_mp = $speech['after_mp']; - } - include dirname(__FILE__) . '/../divisions/_your_mp.php'; + $mp_vote = [ 'vote' => $speech['mp_vote']['vote'] ]; + if (isset($speech['before_mp'])) { + $before_mp = $speech['before_mp']; + } + if (isset($speech['after_mp'])) { + $after_mp = $speech['after_mp']; + } + include dirname(__FILE__) . '/../divisions/_your_mp.php'; } ?>
    @@ -213,7 +216,7 @@
    -
    @@ -267,41 +270,41 @@ $in_context = gettext('See this item in context'); $link_to = gettext('Link to this item'); } - ?> + ?> + if (!$section || !$individual_item) { ?> + } + if ($speech['socialteaser'] && $speech['socialurl']) { + $twitter_href = sprintf( + 'https://twitter.com/share?url=%s&text=%s&related=%s', + urlencode($speech['socialurl']), + urlencode($speech['socialteaser']), + urlencode('theyworkforyou,mysociety') + ); + $facebook_href = sprintf( + 'https://www.facebook.com/dialog/share?app_id=%s&display=popup&href=%s"e=%s', + urlencode(FACEBOOK_APP_ID), + urlencode($speech['socialurl']), + urlencode($speech['socialteaser']) + ); ?> + } + if ($source) { ?> + } + if (isset($speech['mentions'])) { + echo $speech['mentions']; + } ?> @@ -327,55 +330,55 @@ } // end foreach - if (isset($data['subrows'])) { - print '
      '; - foreach ($data['subrows'] as $row) { - print '
    • '; - if (isset($row['contentcount']) && $row['contentcount'] > 0) { - $has_content = true; - } elseif ($row['htype'] == '11' && $hansardmajors[$row['major']]['type'] == 'other') { - $has_content = true; - } else { - $has_content = false; +if (isset($data['subrows'])) { + print '
        '; + foreach ($data['subrows'] as $row) { + print '
      • '; + if (isset($row['contentcount']) && $row['contentcount'] > 0) { + $has_content = true; + } elseif ($row['htype'] == '11' && $hansardmajors[$row['major']]['type'] == 'other') { + $has_content = true; + } else { + $has_content = false; + } + if ($has_content) { + print '' . $row['body'] . ' '; + // For the "x speeches, x comments" text. + $moreinfo = []; + if ($hansardmajors[$row['major']]['type'] != 'other') { + // All wrans have 2 speeches, so no need for this. + // All WMS have 1 speech + $moreinfo[] = sprintf(ngettext('%s speech', '%s speeches', $row['contentcount']), $row['contentcount']); } - if ($has_content) { - print '' . $row['body'] . ' '; - // For the "x speeches, x comments" text. - $moreinfo = array(); - if ($hansardmajors[$row['major']]['type'] != 'other') { - // All wrans have 2 speeches, so no need for this. - // All WMS have 1 speech - $moreinfo[] = sprintf(ngettext('%s speech', '%s speeches', $row['contentcount']), $row['contentcount']); - } - if ($row['totalcomments'] > 0) { - $moreinfo[] = sprintf(ngettext('%s annotation', '%s annotations', $row['totalcomments']), $row['totalcomments']); - } - if (count($moreinfo) > 0) { - print "(" . implode (', ', $moreinfo) . ") "; - } - } else { - // Nothing in this item, so no link. - print $row['body']; + if ($row['totalcomments'] > 0) { + $moreinfo[] = sprintf(ngettext('%s annotation', '%s annotations', $row['totalcomments']), $row['totalcomments']); } - if (isset($row['excerpt'])) { - print "

        " . trim_characters($row['excerpt'], 0, 200) . "

        "; + if (count($moreinfo) > 0) { + print "(" . implode(', ', $moreinfo) . ") "; } + } else { + // Nothing in this item, so no link. + print $row['body']; + } + if (isset($row['excerpt'])) { + print "

        " . trim_characters($row['excerpt'], 0, 200) . "

        "; } - print '
      '; } + print '
    '; +} - if ($section && $individual_item) { ?> +if ($section && $individual_item) { ?>
    display('ep', $comments['args']); - # XXX COMMENT SIDEBAR SHOULD GO HERE IF LOGGED IN - ?> + # XXX + global $PAGE; + $comments['object']->display('ep', $comments['args']); + # XXX COMMENT SIDEBAR SHOULD GO HERE IF LOGGED IN + ?>
    + ?>
    @@ -30,11 +30,11 @@
      + ?>

    • - + diff --git a/www/includes/easyparliament/templates/html/section/column.php b/www/includes/easyparliament/templates/html/section/column.php index b1d09d83b0..c656df350c 100644 --- a/www/includes/easyparliament/templates/html/section/column.php +++ b/www/includes/easyparliament/templates/html/section/column.php @@ -1,7 +1,7 @@ @@ -19,11 +19,11 @@
    - +
    - + We only have information about columns for debates in the House of Commons and the House of Lords. We can't find anything in column on . @@ -32,7 +32,8 @@
    diff --git a/www/includes/easyparliament/templates/html/section/day.php b/www/includes/easyparliament/templates/html/section/day.php index ef3ec8373c..4828135d5a 100644 --- a/www/includes/easyparliament/templates/html/section/day.php +++ b/www/includes/easyparliament/templates/html/section/day.php @@ -6,32 +6,32 @@

    - +

    - +
      - + foreach ($rows as $row) { ?> +
    - +
  • + if ($prevlevel == '') { ?>
  • - +
    • - +

      @@ -42,26 +42,26 @@

      - 0 ) { ?> + 0) { ?> + if (isset($row['excerpt'])) { ?>

      - +

      -
    • - +
  • @@ -83,6 +83,7 @@
    - +
    diff --git a/www/includes/easyparliament/templates/html/section/index.php b/www/includes/easyparliament/templates/html/section/index.php index 30e270365a..93049641a8 100644 --- a/www/includes/easyparliament/templates/html/section/index.php +++ b/www/includes/easyparliament/templates/html/section/index.php @@ -1,18 +1,21 @@
    - - + + + $content = $whall; + $title = "Westminster Hall debates"; + $urls['day'] = $urls['whallday']; + include '_business_section.php'; ?> + $section = 'lords'; + $content = $lords; + $title = "House of Lords debates"; + $urls['day'] = $urls['lordsday']; + include '_business_section.php'; ?>
    diff --git a/www/includes/easyparliament/templates/html/section/ni_index.php b/www/includes/easyparliament/templates/html/section/ni_index.php index 21c40d6789..778be9873f 100644 --- a/www/includes/easyparliament/templates/html/section/ni_index.php +++ b/www/includes/easyparliament/templates/html/section/ni_index.php @@ -2,10 +2,11 @@ - + diff --git a/www/includes/easyparliament/templates/html/section/pbc_bill.php b/www/includes/easyparliament/templates/html/section/pbc_bill.php index eb20e028e3..a54b25f952 100644 --- a/www/includes/easyparliament/templates/html/section/pbc_bill.php +++ b/www/includes/easyparliament/templates/html/section/pbc_bill.php @@ -24,12 +24,12 @@
      '; - $first = 1; - } ?> + foreach ($content['rows'] as $row) { + if ($row['htype'] == 10) { + if (!$first) { + print ''; + $first = 1; + } ?>
    • href="" class="business-list__title">

      @@ -37,16 +37,16 @@

      - + sitting · - - 0 ) { ?> + + 0) { ?> ·

      - +

        @@ -61,7 +61,7 @@

        - +

        @@ -69,13 +69,13 @@
      + } ?>
    - + ?>

    All bills in this session @@ -85,13 +85,13 @@

    Chairpersons

      - +
    • ()

    Members

      - +
    • ()
    diff --git a/www/includes/easyparliament/templates/html/section/pbc_index.php b/www/includes/easyparliament/templates/html/section/pbc_index.php index 63b635a0d0..9fbe30695d 100644 --- a/www/includes/easyparliament/templates/html/section/pbc_index.php +++ b/www/includes/easyparliament/templates/html/section/pbc_index.php @@ -37,7 +37,7 @@

    + } ?>
    @@ -47,6 +47,7 @@
    - + diff --git a/www/includes/easyparliament/templates/html/section/pbc_session.php b/www/includes/easyparliament/templates/html/section/pbc_session.php index b5611d0519..68d024ff1b 100644 --- a/www/includes/easyparliament/templates/html/section/pbc_session.php +++ b/www/includes/easyparliament/templates/html/section/pbc_session.php @@ -24,7 +24,7 @@
      + foreach ($rows as $row) { ?>
    • @@ -42,7 +42,7 @@
      - +   @@ -50,7 +50,7 @@ session - +   diff --git a/www/includes/easyparliament/templates/html/section/recent.php b/www/includes/easyparliament/templates/html/section/recent.php index c569c20656..a8255dd558 100644 --- a/www/includes/easyparliament/templates/html/section/recent.php +++ b/www/includes/easyparliament/templates/html/section/recent.php @@ -1,4 +1,5 @@
      - +
      diff --git a/www/includes/easyparliament/templates/html/section/section.php b/www/includes/easyparliament/templates/html/section/section.php index 6a783129dc..108fc6db7b 100644 --- a/www/includes/easyparliament/templates/html/section/section.php +++ b/www/includes/easyparliament/templates/html/section/section.php @@ -1,7 +1,7 @@ @@ -15,24 +15,25 @@ %s'), $debate_day_link, $debate_day_human); - ?>. +print ' '; +printf(gettext('on %s'), $debate_day_link, $debate_day_human); +?>.

      - +
      diff --git a/www/includes/easyparliament/templates/html/section/senedd_index.php b/www/includes/easyparliament/templates/html/section/senedd_index.php index 68753edd90..e7c0dba3d7 100644 --- a/www/includes/easyparliament/templates/html/section/senedd_index.php +++ b/www/includes/easyparliament/templates/html/section/senedd_index.php @@ -2,10 +2,11 @@ - + diff --git a/www/includes/easyparliament/templates/html/section/wrans_index.php b/www/includes/easyparliament/templates/html/section/wrans_index.php index 5312cff5c3..ce5dc4aeab 100644 --- a/www/includes/easyparliament/templates/html/section/wrans_index.php +++ b/www/includes/easyparliament/templates/html/section/wrans_index.php @@ -1,7 +1,14 @@
      - - - + + +
      diff --git a/www/includes/easyparliament/templates/html/section/year.php b/www/includes/easyparliament/templates/html/section/year.php index d4c3d5427a..34d6a44589 100644 --- a/www/includes/easyparliament/templates/html/section/year.php +++ b/www/includes/easyparliament/templates/html/section/year.php @@ -28,12 +28,13 @@ } ?> + } else { ?> - + diff --git a/www/includes/easyparliament/templates/html/senedd/index.php b/www/includes/easyparliament/templates/html/senedd/index.php index 455a7d47b2..72f3d5d282 100644 --- a/www/includes/easyparliament/templates/html/senedd/index.php +++ b/www/includes/easyparliament/templates/html/senedd/index.php @@ -6,8 +6,8 @@
      @@ -23,10 +23,10 @@

      +?>

    diff --git a/www/includes/easyparliament/templates/html/static/linktous.php b/www/includes/easyparliament/templates/html/static/linktous.php index d42d4033d4..4f8b94dd76 100644 --- a/www/includes/easyparliament/templates/html/static/linktous.php +++ b/www/includes/easyparliament/templates/html/static/linktous.php @@ -8,25 +8,25 @@

    Alternatively, if you would like to place a TheyWorkForYou search box on your site, like this one…

    -
    -
    TheyWorkForYou.com
    -
    - - - -
    -
    - - - -
    -
    -
    - -END; -print $link_to_us_form; -?> + +
    +
    TheyWorkForYou.com
    +
    + + + +
    +
    + + + +
    +
    +
    + + END; + print $link_to_us_form; + ?>

    Cut and paste the code below into your webpage: