function get_listurl($q) { global $hansardmajors; $id_data = array( 'gid' => fix_gid_from_db($q->field(0, 'gid')), 'major' => $q->field(0, 'major'), 'htype' => $q->field(0, 'htype'), 'subsection_id' => $q->field(0, 'subsection_id'), ); $db = new ParlDB; $LISTURL = new URL($hansardmajors[$id_data['major']]['page_all']); $fragment = ''; if ($id_data['htype'] == '11' || $id_data['htype'] == '10') { $LISTURL->insert( array( 'id' => $id_data['gid'] ) ); } else { $parent_epobject_id = $id_data['subsection_id']; $parent_gid = ''; $r = $db->query("SELECT gid FROM hansard WHERE epobject_id = '" . mysql_real_escape_string($parent_epobject_id) . "' "); if ($r->rows() > 0) { $parent_gid = fix_gid_from_db( $r->field(0, 'gid') ); } if ($parent_gid != '') { $LISTURL->insert( array( 'id' => $parent_gid ) ); $fragment = '#g' . gid_to_anchor($id_data['gid']); } } return $LISTURL->generate('none') . $fragment; }
function gid_to_url($gid) { if (!$gid) { return ''; } global $hansardmajors; global $db; $q = $db->query("SELECT major FROM hansard WHERE gid = :gid", array(':gid' => $gid)); $url_gid = fix_gid_from_db($gid); $url = new \URL($hansardmajors[$q->field(0, 'major')]['page']); $url->insert(array('id' => $url_gid)); $url = 'http://' . DOMAIN . $url->generate(); return $url; }
if (!$dept) { } else { $dept = strtolower(str_replace('_',' ',$dept)); $q = $db->query('select epobject.epobject_id from hansard,epobject where hansard.epobject_id=epobject.epobject_id and major=4 and section_id=0 and hdate>(select max(hdate) from hansard where major=4) - interval 7 day and lower(body) = "' . mysql_real_escape_string($dept).'"'); $ids = array(); for ($i=0; $i<$q->rows(); $i++) { $ids[] = $q->field($i, 'epobject_id'); } print '<h2>' . ucwords($dept) . '</h2>'; print '<h3>Written Ministerial Statements from the past week</h3>'; $q = $db->query('select gid,body from hansard,epobject where hansard.epobject_id=epobject.epobject_id and major=4 and subsection_id=0 and section_id in (' . join(',', $ids) . ') order by body'); print '<ul>'; for ($i=0; $i<$q->rows(); $i++) { print '<li><a href="/wms/?id=' . fix_gid_from_db($q->field($i, 'gid')). '">' . $q->field($i, 'body'). '</a>'; print '</li>'; } print '</ul>'; } $PAGE->stripe_end(); $PAGE->page_end();
function _set_url() { global $hansardmajors; // Creates and sets the URL for the comment. if ($this->url == '') { $q = $this->db->query("SELECT major,\n\t\t\t\t\t\t\t\t\tgid\n\t\t\t\t\t\t\tFROM\thansard\n\t\t\t\t\t\t\tWHERE\tepobject_id = '" . addslashes($this->epobject_id) . "'\n\t\t\t\t\t\t\t"); if ($q->rows() > 0) { // If you change stuff here, you might have to change it in // $COMMENTLIST->_get_comment_data() too... $gid = fix_gid_from_db($q->field(0, 'gid')); // In includes/utility.php $major = $q->field(0, 'major'); $page = $hansardmajors[$major]['page']; $gidvar = $hansardmajors[$major]['gidvar']; $URL = new URL($page); $URL->insert(array($gidvar => $gid)); $this->url = $URL->generate() . '#c' . $this->comment_id; } } }
function _get_data_by_recent_wrans($args = array()) { global $hansardmajors; // $args['days'] is the number of days back to look for biggest debates. // (1 by default) // $args['num'] is the number of links to return (1 by default). $data = array(); // Get the most recent day on which we have wrans. $recentday = $this->most_recent_day(); if (!count($recentday)) { return array(); } if (!isset($args['days']) || !is_numeric($args['days'])) { $args['days'] = 1; } if (!isset($args['num']) || !is_numeric($args['num'])) { $args['num'] = 1; } if ($args['num'] == 1) { $datewhere = "h.hdate = '" . mysql_escape_string($recentday['hdate']) . "'"; } else { $firstdate = gmdate('Y-m-d', $recentday['timestamp'] - 86400 * $args['days']); $datewhere = "h.hdate >= '" . mysql_escape_string($firstdate) . "'\n\t\t\t\t\t\tAND\t\th.hdate <= '" . mysql_escape_string($recentday['hdate']) . "'"; } // Get a random selection of subsections in wrans. if ($hansardmajors[$this->major]['location'] == 'Scotland') { $htype = 'htype = 10 and section_id = 0'; } else { $htype = 'htype = 11 and section_id != 0'; } $q = $this->db->query("SELECT e.body,\n\t\t\t\t\t\t\t\th.hdate,\n\t\t\t\t\t\t\t\th.htype,\n\t\t\t\t\t\t\t\th.gid,\n\t\t\t\t\t\t\t\th.subsection_id,\n\t\t\t\t\t\t\t\th.section_id,\n\t\t\t\t\t\t\t\th.epobject_id\n\t\t\t\t\t\tFROM\thansard h, epobject e\n\t\t\t\t\t\tWHERE\th.major = '" . $this->major . "'\n\t\t\t\t\t\tAND\t\t{$htype}\n\t\t\t\t\t\tAND\t\tsubsection_id = 0\n\t\t\t\t\t\tAND\t\t{$datewhere}\n\t\t\t\t\t\tAND\t\th.epobject_id = e.epobject_id\n\t\t\t\t\t\tORDER BY RAND()\n\t\t\t\t\t\tLIMIT \t" . mysql_escape_string($args['num']) . "\n\t\t\t\t\t\t"); for ($row = 0; $row < $q->rows; $row++) { // This array just used for getting further data about this debate. $item_data = array('major' => $this->major, 'gid' => fix_gid_from_db($q->field($row, 'gid')), 'htype' => $q->field($row, 'htype'), 'section_id' => $q->field($row, 'section_id'), 'subsection_id' => $q->field($row, 'subsection_id'), 'epobject_id' => $q->field($row, 'epobject_id')); $list_url = $this->_get_listurl($item_data); $totalcomments = $this->_get_comment_count_for_epobject($item_data); $body = $q->field($row, 'body'); $hdate = $q->field($row, 'hdate'); // Get the parent section for this item. $parentbody = ''; if ($q->field($row, 'section_id')) { $r = $this->db->query("SELECT e.body\n\t\t\t\t\t\t\tFROM\thansard h, epobject e\n\t\t\t\t\t\t\tWHERE\th.epobject_id = e.epobject_id\n\t\t\t\t\t\t\tAND\t\th.epobject_id = '" . $q->field($row, 'section_id') . "'\n\t\t\t\t\t\t\t"); $parentbody = $r->field(0, 'body'); } // Get the question for this item. $r = $this->db->query("SELECT e.body,\n\t\t\t\t\t\t\t\t\th.speaker_id, h.hdate\n\t\t\t\t\t\t\tFROM\thansard h, epobject e\n\t\t\t\t\t\t\tWHERE\th.epobject_id = e.epobject_id\n\t\t\t\t\t\t\tAND \th.subsection_id = '" . $q->field($row, 'epobject_id') . "'\n\t\t\t\t\t\t\tORDER BY hpos\n\t\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t\t\t"); $childbody = $r->field(0, 'body'); $speaker = $this->_get_speaker($r->field(0, 'speaker_id'), $r->field(0, 'hdate')); $data[] = array('body' => $body, 'hdate' => $hdate, 'list_url' => $list_url, 'totalcomments' => $totalcomments, 'child' => array('body' => $childbody, 'speaker' => $speaker), 'parent' => array('body' => $parentbody)); } $data = array('info' => array(), 'data' => $data); return $data; }
<?php include_once '../../includes/easyparliament/init.php'; include_once INCLUDESPATH . "easyparliament/glossary.php"; $this_page = "debate"; $this_page = "debates"; $dates = file('alldates'); shuffle($dates); $date = trim($dates[0]); $db = new ParlDB(); $q = $db->query("select gid from hansard where htype in (10,11) and major=1 and hdate='{$date}' order by rand() limit 1"); $gid = $q->field(0, 'gid'); $args = array('gid' => fix_gid_from_db($gid), 'sort' => 'regexp_replace'); $GLOSSARY = new GLOSSARY($args); $LIST = new DEBATELIST(); $result = $LIST->display('gid', $args); $PAGE->page_end();
function _comment_url($urldata) { global $hansardmajors; // Pass it the major and gid of the comment's epobject and the comment_id. // And optionally the user's id, for highlighting the comments on the destination page. // It returns the URL for the comment. $major = $urldata['major']; $gid = $urldata['gid']; $comment_id = $urldata['comment_id']; $user_id = isset($urldata['user_id']) ? $urldata['user_id'] : false; // If you change stuff here, you might have to change it in // $COMMENT->_set_url() too... // We'll generate permalinks for each comment. // Assuming every comment is from the same major... $page = $hansardmajors[$major]['page']; $gidvar = $hansardmajors[$major]['gidvar']; $URL = new URL($page); $gid = fix_gid_from_db($gid); // In includes/utility.php $URL->insert(array($gidvar => $gid)); if ($user_id) { $URL->insert(array('u' => $user_id)); } $url = $URL->generate() . '#c' . $comment_id; return $url; }
include_once "../../includes/easyparliament/init.php"; $dept = get_http_var('dept'); $PAGE->page_start(); $PAGE->stripe_start(); $db = new ParlDB(); if (!$dept) { } else { $dept = strtolower(str_replace('_', ' ', $dept)); $q = $db->query('select epobject.epobject_id from hansard,epobject where hansard.epobject_id=epobject.epobject_id and major=3 and section_id=0 and hdate>(select max(hdate) from hansard where major=3) - interval 7 day and lower(body) = "' . mysql_escape_string($dept) . '"'); $ids = array(); for ($i = 0; $i < $q->rows(); $i++) { $ids[] = $q->field($i, 'epobject_id'); } print '<h2>' . ucwords($dept) . '</h2>'; print '<h3>Written Questions from the past week</h3>'; $q = $db->query('select gid,body from hansard,epobject where hansard.epobject_id=epobject.epobject_id and major=3 and subsection_id=0 and section_id in (' . join(',', $ids) . ') order by body'); print '<ul>'; for ($i = 0; $i < $q->rows(); $i++) { print '<li><a href="' . WEBPATH . '/wrans/?id=' . fix_gid_from_db($q->field($i, 'gid')) . '">' . $q->field($i, 'body') . '</a>'; print '</li>'; } print '</ul>'; } $PAGE->stripe_end(); $PAGE->page_end();
function generate_member_links($member, $links) { // Receives its data from $MEMBER->display_links; // This returns HTML, rather than outputting it. // Why? Because we need this to be in the sidebar, and // we can't call the MEMBER object from the sidebar includes // to get the links. So we call this function from the mp // page and pass the HTML through to stripe_end(). Better than nothing. // Bah, can't use $this->block_start() for this, as we're returning HTML... $html = '<div class="block"> <h4>More useful links for this person</h4> <div class="blockbody"> <ul' . (get_http_var('c4') ? ' style="list-style-type:none;"' : '') . '>'; if (isset($links['maiden_speech'])) { $maiden_speech = fix_gid_from_db($links['maiden_speech']); $html .= '<li><a href="' . WEBPATH . 'debate/?id=' . $maiden_speech . '">Maiden speech</a></li>'; } // BIOGRAPHY. if (isset($links['mp_email'])) { $html .= ' <li><a href="mailto:' . $links['mp_email'] . '">Email ' . $member->full_name() . '</a></li>'; } elseif (isset($links['mp_contact_form'])) { $html .= ' <li><a href="' . $links['mp_contact_form'] . '">Contact form</a> <small>(On the Australian Parliament website)</small></li>'; } if (isset($links['mp_twitter_url'])) { $html .= ' <li><a href="' . $links['mp_twitter_url'] . '">' . $member->full_name() . ' on Twitter</a></li>'; } if (isset($links['mp_facebook_url'])) { $html .= ' <li><a href="' . $links['mp_facebook_url'] . '">' . $member->full_name() . ' on Facebook</a></li>'; } if (isset($links['mp_website'])) { $html .= '<li><a href="' . $links['mp_website'] . '">' . $member->full_name() . '\'s personal website</a></li>'; } if (isset($links['sp_url'])) { $html .= '<li><a href="' . $links['sp_url'] . '">' . $member->full_name() . '\'s page on the Scottish Parliament website</a></li>'; } if (isset($links['aph_url'])) { $html .= '<li><a href="' . $links['aph_url'] . '">Parliament House web page for ' . $member->full_name() . '</a></li>'; } if (isset($links['guardian_biography'])) { $html .= ' <li><a href="' . $links['guardian_biography'] . '">Biography</a> <small>(From The Guardian)</small></li>'; } if (isset($links['wikipedia_url'])) { $html .= ' <li><a href="' . $links['wikipedia_url'] . '">Biography</a> <small>(From Wikipedia)</small></li>'; } if (isset($links['mp_biography_qanda']) && $links['mp_biography_qanda'] != "") { $html .= ' <li><a href="' . $links['mp_biography_qanda'] . '">Biography</a> <small>(From ABC\'s Q & A)</small></li>'; } if (isset($links['diocese_url'])) { $html .= ' <li><a href="' . $links['diocese_url'] . '">Diocese website</a></li>'; } if (isset($links['journa_list_link'])) { $html .= ' <li><a href="' . $links['journa_list_link'] . '">Newspaper articles written by this MP</a> <small>(From Journa-list)</small></li>'; } if (isset($links['guardian_parliament_history'])) { $html .= ' <li><a href="' . $links['guardian_parliament_history'] . '">Parliamentary career</a> <small>(From The Guardian)</small></li>'; } if (isset($links['guardian_election_results'])) { $html .= ' <li><a href="' . $links['guardian_election_results'] . '">Election results for ' . $member->constituency() . '</a> <small>(From The Guardian)</small></li>'; } if (isset($links['abc_election_results_2013'])) { $html .= ' <li><a href="' . $links['abc_election_results_2013'] . '">2013 Election results for ' . $member->constituency() . '</a> <small>(From ABC)</small></li>'; } if (isset($links['abc_election_results_2010'])) { $html .= ' <li><a href="' . $links['abc_election_results_2010'] . '">2010 Election results for ' . $member->constituency() . '</a> <small>(From ABC)</small></li>'; } if (isset($links['abc_election_results_2007'])) { $html .= ' <li><a href="' . $links['abc_election_results_2007'] . '">2007 Election results for ' . $member->constituency() . '</a> <small>(From ABC)</small></li>'; } if (isset($links['guardian_candidacies'])) { $html .= ' <li><a href="' . $links['guardian_candidacies'] . '">Previous candidacies</a> <small>(From The Guardian)</small></li>'; } if (isset($links['guardian_contactdetails'])) { $html .= ' <li><a href="' . $links['guardian_contactdetails'] . '">Contact details</a> <small>(From The Guardian)</small></li>'; } if (isset($links['bbc_profile_url'])) { $html .= ' <li><a href="' . $links['bbc_profile_url'] . '">General information</a> <small>(From BBC News)</small></li>'; } $bbc_name = urlencode($member->first_name()) . "%20" . urlencode($member->last_name()); if ($member->member_id() == -1) { $bbc_name = 'Queen Elizabeth'; } #$html .= ' <li><a href="http://catalogue.bbc.co.uk/catalogue/infax/search/' . $bbc_name . '">TV/radio appearances</a> <small>(From BBC Programme Catalogue)</small></li>'; $html .= "\t</ul>\n\t\t\t\t\t</div>\n\t\t\t\t</div> <!-- end block -->\n"; return $html; }
function generate_member_links($member) { // Receives its data from $MEMBER->display_links; // This returns HTML, rather than outputting it. // Why? Because we need this to be in the sidebar, and // we can't call the MEMBER object from the sidebar includes // to get the links. So we call this function from the mp // page and pass the HTML through to stripe_end(). Better than nothing. $links = $member->extra_info(); // Bah, can't use $this->block_start() for this, as we're returning HTML... $html = '<div class="block"> <h4>More useful links for this person</h4> <div class="blockbody"> <ul' . (get_http_var('c4') ? ' style="list-style-type:none;"' : '') . '>'; if (isset($links['maiden_speech'])) { $maiden_speech = fix_gid_from_db($links['maiden_speech']); $html .= '<li><a href="' . WEBPATH . 'debate/?id=' . $maiden_speech . '">Maiden speech</a></li>'; } // BIOGRAPHY. global $THEUSER; if (isset($links['mp_website'])) { $html .= '<li><a href="' . $links['mp_website'] . '">' . $member->full_name() . '\'s personal website</a>'; if ($THEUSER->is_able_to('viewadminsection')) { $html .= ' [<a href="/admin/websites.php?editperson=' . $member->person_id() . '">Edit</a>]'; } $html .= '</li>'; } elseif ($THEUSER->is_able_to('viewadminsection')) { $html .= '<li>[<a href="/admin/websites.php?editperson=' . $member->person_id() . '">Add personal website</a>]</li>'; } if (isset($links['twitter_username'])) { $html .= '<li><a href="http://twitter.com/' . $links['twitter_username'] . '">' . $member->full_name() . '’s Twitter feed</a></li>'; } if (isset($links['sp_url'])) { $html .= '<li><a href="' . $links['sp_url'] . '">' . $member->full_name() . '\'s page on the Scottish Parliament website</a></li>'; } if (isset($links['guardian_biography'])) { $html .= ' <li><a href="' . $links['guardian_biography'] . '">Guardian profile</a></li>'; } if (isset($links['wikipedia_url'])) { $html .= ' <li><a href="' . $links['wikipedia_url'] . '">Wikipedia page</a></li>'; } if (isset($links['bbc_profile_url'])) { $html .= ' <li><a href="' . $links['bbc_profile_url'] . '">BBC News profile</a></li>'; } if (isset($links['diocese_url'])) { $html .= ' <li><a href="' . $links['diocese_url'] . '">Diocese website</a></li>'; } $html .= '<li><a href="http://www.edms.org.uk/mps/' . $member->person_id() . '/">Early Day Motions signed by this MP</a> <small>(From edms.org.uk)</small></li>'; if (isset($links['journa_list_link'])) { $html .= ' <li><a href="' . $links['journa_list_link'] . '">Newspaper articles written by this MP</a> <small>(From Journalisted)</small></li>'; } if (isset($links['guardian_election_results'])) { $html .= ' <li><a href="' . $links['guardian_election_results'] . '">Election results for ' . $member->constituency() . '</a> <small>(From The Guardian)</small></li>'; } /* # BBC Catalogue is offline $bbc_name = urlencode($member->first_name()) . "%20" . urlencode($member->last_name()); if ($member->member_id() == -1) $bbc_name = 'Queen Elizabeth'; $html .= ' <li><a href="http://catalogue.bbc.co.uk/catalogue/infax/search/' . $bbc_name . '">TV/radio appearances</a> <small>(From BBC Programme Catalogue)</small></li>'; */ $html .= " </ul>\n\t\t\t\t</div>\n\t\t\t</div> <!-- end block -->\n"; return $html; }
function major_summary($data, $echo = true) { global $hansardmajors; $html = ''; $db = new ParlDB(); $one_date = false; //if no printed majors passed, default to all if (!isset($printed_majors)) { $printed_majors = array(1, 2, 3, 5, 101, 7); # 8 } // single date? if (isset($data['date'])) { $one_date = true; } // remove empty entries, so they don't produce errors foreach (array_keys($hansardmajors) as $major) { if (array_key_exists($major, $data)) { if (count($data[$major]) == 0) { unset($data[$major]); } } } //work out the date text to be displaid $daytext = array(); if (!$one_date) { $todaystime = gmmktime(0, 0, 0, date('m'), date('d'), date('Y')); foreach ($data as $major => $array) { if (!in_array('timestamp', $array)) { $daytext[$major] = "The most recent "; } elseif ($todaystime - $array['timestamp'] == 86400) { $daytext[$major] = "Yesterday’s"; } elseif ($todaystime - $array['timestamp'] <= 6 * 86400) { $daytext[$major] = gmdate('l', $array['timestamp']) . "’s"; } else { $daytext[$major] = "The most recent "; } } } //build html foreach ($printed_majors as $p_major) { if (!array_key_exists($p_major, $data)) { continue; } if ($one_date) { $date = $data['date']; } else { $date = $data[$p_major]['hdate']; } $q = $db->query('SELECT body, gid FROM hansard, epobject WHERE hansard.epobject_id = epobject.epobject_id AND section_id = 0 AND hdate = "' . $date . '" AND major = ' . $p_major . ' ORDER BY hpos'); $out = ''; $LISTURL = new URL($hansardmajors[$p_major]['page_all']); for ($i = 0; $i < $q->rows(); $i++) { $gid = fix_gid_from_db($q->field($i, 'gid')); $body = $q->field($i, 'body'); //if (strstr($body, 'Chair]')) continue; $LISTURL->insert(array('id' => $gid)); $out .= '<li><a href="' . $LISTURL->generate() . '">'; $out .= $body . '</a>'; } if ($out) { $html .= _major_summary_title($p_major, $data, $LISTURL, $daytext); $html .= '<ul class="hansard-day">'; $html .= $out; $html .= '</ul>'; } } if (array_key_exists(4, $data)) { if ($one_date) { $date = $data['date']; } else { $date = $data[4]['hdate']; } $q = $db->query('SELECT section_id, body, gid FROM hansard,epobject WHERE hansard.epobject_id = epobject.epobject_id AND major=4 AND hdate="' . $date . '" AND subsection_id=0 ORDER BY major, hpos'); if ($q->rows()) { $LISTURL = new URL($hansardmajors[4]['page_all']); $html .= _major_summary_title(4, $data, $LISTURL, $daytext); $html .= "<ul>"; $current_sid = 0; for ($i = 0; $i < $q->rows(); $i++) { $gid = fix_gid_from_db($q->field($i, 'gid')); $body = $q->field($i, 'body'); $section_id = $q->field($i, 'section_id'); if (!$section_id) { if ($current_sid++) { $html .= '</ul>'; } $html .= '<li>' . $body . '<ul>'; } else { $LISTURL->insert(array('id' => $gid)); $html .= '<li><a href="' . $LISTURL->generate() . '">'; $html .= $body . '</a>'; } } $html .= '</ul>'; } } $html .= '</ul>'; if ($echo) { print $html; } else { return $html; } }
function major_summary($data, $limit = "") { global $hansardmajors; $db = new ParlDB(); $one_date = false; if (isset($data['date'])) { $one_date = true; } $limitsql = ""; if ($limit) { $limitsql = " limit {$limit}"; } $daytext = array(); if (!$one_date) { $todaystime = gmmktime(0, 0, 0, date('m'), date('d'), date('Y')); foreach ($data as $major => $array) { if ($todaystime - $array['timestamp'] == 86400) { $daytext[$major] = "Yesterday's"; } elseif ($todaystime - $array['timestamp'] <= 6 * 86400) { $daytext[$major] = gmdate('l', $array['timestamp']) . "'s"; } else { $daytext[$major] = "The most recent "; } } } $printed_majors = array(1, 2, 3, 5, 101); print '<ul id="hansard-day">'; while (count($printed_majors)) { if (!array_key_exists($printed_majors[0], $data)) { unset($printed_majors[0]); sort($printed_majors); continue; } if ($one_date) { $date = $data['date']; } else { $date = $data[$printed_majors[0]]['hdate']; } $q = $db->query('SELECT major, body, gid FROM hansard,epobject WHERE hansard.epobject_id = epobject.epobject_id AND section_id=0 AND hdate="' . $date . '" AND major IN (' . join(',', $printed_majors) . ') ORDER BY major desc, hpos' . $limitsql); $current_major = 0; for ($i = 0; $i < $q->rows(); $i++) { $gid = fix_gid_from_db($q->field($i, 'gid')); $major = $q->field($i, 'major'); $body = $q->field($i, 'body'); //if (strstr($body, 'Chair]')) continue; if ($major != $current_major) { if ($current_major) { print '</ul>'; } $LISTURL = new URL($hansardmajors[$major]['page_all']); _major_summary_title($major, $data, $LISTURL, $daytext); $current_major = $major; # XXX: Surely a better way of doing this? Oh well unset($printed_majors[array_search($major, $printed_majors)]); sort($printed_majors); } $LISTURL->insert(array('id' => $gid)); print '<li><a href="' . $LISTURL->generate() . '">'; print $body . '</a>'; } print '</ul>'; if ($one_date) { $printed_majors = array(); } } if (array_key_exists(4, $data)) { if ($one_date) { $date = $data['date']; } else { $date = $data[4]['hdate']; } $q = $db->query('SELECT section_id, body, gid FROM hansard,epobject WHERE hansard.epobject_id = epobject.epobject_id AND major=4 AND hdate="' . $date . '" AND subsection_id=0 ORDER BY major, hpos' . $limitsql); if ($q->rows()) { $LISTURL = new URL($hansardmajors[4]['page_all']); _major_summary_title(4, $data, $LISTURL, $daytext); $current_sid = 0; for ($i = 0; $i < $q->rows(); $i++) { $gid = fix_gid_from_db($q->field($i, 'gid')); $body = $q->field($i, 'body'); $section_id = $q->field($i, 'section_id'); if (!$section_id) { if ($current_sid++) { print '</ul>'; } print '<li>' . $body . '<ul>'; } else { $LISTURL->insert(array('id' => $gid)); print '<li><a href="' . $LISTURL->generate() . '">'; print $body . '</a>'; } } print '</ul></ul>'; } } print '</ul>'; }
/** * Search * * Performs a search of Hansard. * * @param string $searchstring The string to initialise SEARCHENGINE with. * @param array $args An array of arguments to restrict search results. * * @return array An array of search results. */ public function search($searchstring, $args) { if (!defined('FRONT_END_SEARCH') || !FRONT_END_SEARCH) { throw new \Exception('FRONT_END_SEARCH is not defined or is false.'); } // $args is an associative array with 's'=>'my search term' and // (optionally) 'p'=>1 (the page number of results to show) annd // (optionall) 'pop'=>1 (if "popular" search link, so don't log) global $PAGE, $hansardmajors; if (isset($args['s'])) { // $args['s'] should have been tidied up by the time we get here. // eg, by doing filter_user_input($s, 'strict'); $searchstring = $args['s']; } else { throw new \Exception('No search string provided.'); } // What we'll return. $data = array(); $data['info']['s'] = $args['s']; // Allows us to specify how many results we want // Mainly for glossary term adding if (isset($args['num']) && $args['num']) { $results_per_page = $args['num'] + 0; } else { $results_per_page = 20; } if ($results_per_page > 1000) { $results_per_page = 1000; } $data['info']['results_per_page'] = $results_per_page; // What page are we on? if (isset($args['p']) && is_numeric($args['p'])) { $page = $args['p']; } else { $page = 1; } $data['info']['page'] = $page; if (isset($args['e'])) { $encode = 'url'; } else { $encode = 'html'; } // Gloablise the search engine global $SEARCHENGINE; // For Xapian's equivalent of an SQL LIMIT clause. $first_result = ($page - 1) * $results_per_page; $data['info']['first_result'] = $first_result + 1; // Take account of LIMIT's 0 base. // Get the gids from Xapian $sort_order = 'date'; if (isset($args['o'])) { if ($args['o'] == 'd') { $sort_order = 'newest'; } if ($args['o'] == 'o') { $sort_order = 'oldest'; } elseif ($args['o'] == 'c') { $sort_order = 'created'; } elseif ($args['o'] == 'r') { $sort_order = 'relevance'; } } $data['searchdescription'] = $SEARCHENGINE->query_description_long(); $count = $SEARCHENGINE->run_count($first_result, $results_per_page, $sort_order); $data['info']['total_results'] = $count; $data['info']['spelling_correction'] = $SEARCHENGINE->get_spelling_correction(); // Log this query so we can improve them - if it wasn't a "popular // query" link if (!isset($args['pop']) or $args['pop'] != 1) { global $SEARCHLOG; $SEARCHLOG->add(array('query' => $searchstring, 'page' => $page, 'hits' => $count)); } // No results. if ($count <= 0) { $data['rows'] = array(); return $data; } $SEARCHENGINE->run_search($first_result, $results_per_page, $sort_order); $gids = $SEARCHENGINE->get_gids(); if ($sort_order == 'created') { $createds = $SEARCHENGINE->get_createds(); } $relevances = $SEARCHENGINE->get_relevances(); if (count($gids) <= 0) { // No results. $data['rows'] = array(); return $data; } #if ($sort_order=='created') { print_r($gids); } // We'll put all the data in here before giving it to a template. $rows = array(); // We'll cache the ids=>names of speakers here. $speakers = array(); // We'll cache (sub)section_ids here: $hansard_to_gid = array(); // Cycle through each result, munge the data, get more, and put it all in $data. $gids_count = count($gids); for ($n = 0; $n < $gids_count; $n++) { $gid = $gids[$n]; $relevancy = $relevances[$n]; $collapsed = $SEARCHENGINE->collapsed[$n]; if ($sort_order == 'created') { #$created = substr($createds[$n], 0, strpos($createds[$n], ':')); if ($createds[$n] < $args['threshold']) { $data['info']['total_results'] = $n; break; } } if (strstr($gid, 'calendar')) { $id = fix_gid_from_db($gid); $q = $this->db->query("SELECT *, event_date as hdate, pos as hpos\n FROM future\n LEFT JOIN future_people ON id=calendar_id AND witness=0\n WHERE id = {$id} AND deleted=0"); if ($q->rows() == 0) { continue; } $itemdata = $q->row(0); # Ignore past events in places that we cover (we'll have the data from Hansard) if ($itemdata['event_date'] < date('Y-m-d') && in_array($itemdata['chamber'], array('Commons: Main Chamber', 'Lords: Main Chamber', 'Commons: Westminster Hall'))) { continue; } list($cal_item, $cal_meta) = calendar_meta($itemdata); $body = $this->prepare_search_result_for_display($cal_item) . '.'; if ($cal_meta) { $body .= ' <span class="future_meta">' . join('; ', $cal_meta) . '</span>'; } if ($itemdata['witnesses']) { $body .= '<br><small>Witnesses: ' . $this->prepare_search_result_for_display($itemdata['witnesses']) . '</small>'; } if ($itemdata['event_date'] >= date('Y-m-d')) { $title = 'Upcoming Business'; } else { $title = 'Previous Business'; } $itemdata['gid'] = $id; $itemdata['relevance'] = $relevances[$n]; $itemdata['parent']['body'] = $title . ' – ' . $itemdata['chamber']; $itemdata['extract'] = $body; $itemdata['listurl'] = '/calendar/?d=' . $itemdata['event_date'] . '#cal' . $itemdata['id']; $itemdata['major'] = 'F'; } else { // Get the data for the gid from the database $q = $this->db->query("SELECT hansard.gid, hansard.hdate,\n hansard.htime, hansard.section_id, hansard.subsection_id,\n hansard.htype, hansard.major, hansard.minor,\n hansard.person_id, hansard.hpos, hansard.video_status,\n epobject.epobject_id, epobject.body\n FROM hansard, epobject\n WHERE hansard.gid = '{$gid}'\n AND hansard.epobject_id = epobject.epobject_id"); if ($q->rows() > 1) { throw new \Exception('Got more than one row getting data for $gid.'); } if ($q->rows() == 0) { # This error message is totally spurious, so don't show it # $PAGE->error_message("Unexpected missing gid $gid while searching"); continue; } $itemdata = $q->row(0); $itemdata['collapsed'] = $collapsed; $itemdata['gid'] = fix_gid_from_db($q->field(0, 'gid')); $itemdata['relevance'] = $relevances[$n]; $itemdata['extract'] = $this->prepare_search_result_for_display($q->field(0, 'body')); ////////////////////////// // 2. Create the URL to link to this bit of text. $id_data = array('major' => $itemdata['major'], 'minor' => $itemdata['minor'], 'htype' => $itemdata['htype'], 'gid' => $itemdata['gid'], 'section_id' => $itemdata['section_id'], 'subsection_id' => $itemdata['subsection_id']); // We append the query onto the end of the URL as variable 's' // so we can highlight them on the debate/wrans list page. $url_args = array('s' => $searchstring); $itemdata['listurl'] = $this->_get_listurl($id_data, $url_args, $encode); ////////////////////////// // 3. Get the speaker for this item, if applicable. if ($itemdata['person_id'] != 0) { $itemdata['speaker'] = $this->_get_speaker($itemdata['person_id'], $itemdata['hdate'], $itemdata['htime'], $itemdata['major']); } ////////////////////////// // 4. Get data about the parent (sub)section. if ($itemdata['major'] && $hansardmajors[$itemdata['major']]['type'] == 'debate') { // Debate if ($itemdata['htype'] != 10) { $section = $this->_get_section($itemdata); $itemdata['parent']['body'] = $section['body']; # $itemdata['parent']['listurl'] = $section['listurl']; if ($itemdata['section_id'] != $itemdata['subsection_id']) { $subsection = $this->_get_subsection($itemdata); $itemdata['parent']['body'] .= ': ' . $subsection['body']; # $itemdata['parent']['listurl'] = $subsection['listurl']; } if ($itemdata['major'] == 5) { $itemdata['parent']['body'] = 'Northern Ireland Assembly: ' . $itemdata['parent']['body']; } elseif ($itemdata['major'] == 6) { $itemdata['parent']['body'] = 'Public Bill Committee: ' . $itemdata['parent']['body']; } elseif ($itemdata['major'] == 7) { $itemdata['parent']['body'] = 'Scottish Parliament: ' . $itemdata['parent']['body']; } } else { // It's a section, so it will be its own title. $itemdata['parent']['body'] = $itemdata['body']; $itemdata['body'] = ''; } } else { // Wrans or WMS $section = $this->_get_section($itemdata); $subsection = $this->_get_subsection($itemdata); $body = $hansardmajors[$itemdata['major']]['title'] . ' — '; if (isset($section['body'])) { $body .= $section['body']; } if (isset($subsection['body'])) { $body .= ': ' . $subsection['body']; } if (isset($subsection['listurl'])) { $listurl = $subsection['listurl']; } else { $listurl = ''; } $itemdata['parent'] = array('body' => $body, 'listurl' => $listurl); if ($itemdata['htype'] == 11) { # Search result was a subsection heading; fetch the first entry # from the wrans/wms to show under the heading $input = array('amount' => array('body' => true, 'speaker' => true), 'where' => array('hansard.subsection_id=' => $itemdata['epobject_id']), 'order' => 'hpos ASC', 'limit' => 1); $ddata = $this->_get_hansard_data($input); if (count($ddata)) { $itemdata['body'] = $ddata[0]['body']; $itemdata['extract'] = $this->prepare_search_result_for_display($ddata[0]['body']); $itemdata['person_id'] = $ddata[0]['person_id']; if ($itemdata['person_id']) { $itemdata['speaker'] = $this->_get_speaker($itemdata['person_id'], $itemdata['hdate'], $itemdata['htime'], $itemdata['major']); } } } elseif ($itemdata['htype'] == 10) { $itemdata['body'] = ''; $itemdata['extract'] = ''; } } } // End of handling non-calendar search result $rows[] = $itemdata; } $data['rows'] = $rows; return $data; }
function video_front_page() { $db = new ParlDB; $statuses = array( 0 => 'Unstamped', 4 => 'Timestamped by users', ); $q = $db->query('select video_status&4 as checked,count(*) as c from hansard where major=1 and video_status>0 and video_status<8 and video_status!=2 and htype in (12,13) group by video_status&4'); $totaliser = array(0=>0, 4=>0); for ($i=0; $i<$q->rows(); $i++) { $status = $q->field($i, 'checked'); $count = $q->field($i, 'c'); $totaliser[$status] = $count; } $percentage = round($totaliser[4] / ($totaliser[0]+$totaliser[4]) * 10000) / 100; $out = "$totaliser[4] timestamped out of " . ($totaliser[0] + $totaliser[4]) . " ($percentage%)" ?> <p style="margin-top:1em"><big>TheyWorkForYou has video of the House of Commons from the BBC, and the text of Hansard from Parliament. Now we need <strong>your</strong> help to match up the two.</big></p> <p>We've written a little Flash app where you can (hopefully) match up the written speech being displayed to what's playing on the video. We'll then store your results and use them to put the video, timestamped to the right location, on the relevant page of TheyWorkForYou.</p> <p>If you're a registered user and logged in, your timestampings will appear in our chart below – there may be prizes for best timestampers… :) Registration is not needed to timestamp videos, but you can <a href="/user/?pg=join&ret=/video/">register here</a> if you want.</p> <p id="video_attract"><? if ($totaliser[0]) { echo '<a href="next.php?action=random">Give me a random speech that needs timestamping</a>'; } else { echo 'Wow, everything that can currently be timestamped appears to have been, thanks!'; } ?></p> <div id="top" style="float: left; width: 45%;"> <? list($out_today, $rank_today) = display_league(20, 'and date(whenstamped)=current_date'); list($out_week, $rank_week) = display_league(40, 'and date(whenstamped)>current_date-interval 28 day'); list($out_overall, $rank_overall) = display_league(100); $out_overall = ''; global $THEUSER; if ($THEUSER->user_id() && ($rank_today || $rank_week || $rank_overall)) { echo '<p align="center"><big>You are '; if ($rank_today) echo make_ranking($rank_today), ' today, '; if ($rank_week) echo make_ranking($rank_week), ' last 4 weeks, '; if ($rank_overall) echo make_ranking($rank_overall), ' overall'; echo '</big></p>'; } if ($out_today) echo "<h3>Top timestampers (today)</h3> <ol>$out_today</ol>"; if ($out_week) echo "<h3>Top timestampers (last 4 weeks)</h3> <ol>$out_week</ol>"; if ($out_overall) echo "<h3>Top timestampers (overall)</h3> <ol>$out_overall</ol>"; echo '</div>'; ?> <div style="float: right; width: 50%"> <img align="right" width=200 height=100 src="http://chart.apis.google.com/chart?chs=200x100&cht=gom&chd=t:<?php echo $percentage; ?> " alt="<?php echo $percentage; ?> % of speeches have been timestamped"> <h3>Totaliser</h3> <ul><?php echo $out; ?> </ul> <? $q = $db->query('select video_status&4 as checked,count(*) as c from hansard where major=1 and video_status>0 and video_status<8 and video_status!=2 and htype in (12,13) and hdate=(select max(hdate) from hansard where major=1) group by video_status&4'); $totaliser = array(0=>0, 4=>0); for ($i=0; $i<$q->rows(); $i++) { $status = $q->field($i, 'checked'); $count = $q->field($i, 'c'); $totaliser[$status] = $count; } $total_possible = $totaliser[0] + $totaliser[4]; if ($total_possible == 0) { $percentage = 0; $out = 'Nothing possible to timestamp on most recent day'; } else { $percentage = round($totaliser[4] / $total_possible * 10000) / 100; $out = "$totaliser[4] timestamped out of $total_possible ($percentage%)"; } ?> <h3 style="padding-top:0.5em;clear:right">Totaliser for most recent day</h3> <img align="right" width=200 height=100 src="http://chart.apis.google.com/chart?chs=200x100&cht=gom&chd=t:<?php echo $percentage; ?> " alt="<?php echo $percentage; ?> % of speeches have been timestamped"> <ul><?php echo $out; ?> </ul> <h3 style="clear:both;margin-top:1em">Latest stamped</h3> <ul> <? $q = $db->query('select hansard.gid, body, major from video_timestamps, hansard, epobject where (user_id != -1 or user_id is null) and video_timestamps.deleted=0 and video_timestamps.gid = hansard.gid and hansard.subsection_id = epobject.epobject_id order by whenstamped desc limit 20'); for ($i=0; $i<$q->rows(); $i++) { $gid = $q->field($i, 'gid'); $body = $q->field($i, 'body'); if ($q->field($i, 'major') == 101) { $url = '/lords/?gid='; } else { $url = '/debate/?id='; } echo '<li><a href="', $url, fix_gid_from_db($gid) . '">' . $body . '</a>'; } echo '</ul></div>'; }
function person_useful_links($member) { $links = $member->extra_info(); $out = array(); if (isset($links['maiden_speech'])) { $maiden_speech = fix_gid_from_db($links['maiden_speech']); $out[] = array('href' => WEBPATH . 'debate/?id=' . $maiden_speech, 'text' => 'Maiden speech'); } // BIOGRAPHY. global $THEUSER; if (isset($links['mp_website'])) { $out[] = array('href' => $links['mp_website'], 'text' => 'Personal website'); } if (isset($links['twitter_username'])) { $out[] = array('href' => 'http://twitter.com/' . $links['twitter_username'], 'text' => 'Twitter feed'); } if (isset($links['sp_url'])) { $out[] = array('href' => $links['sp_url'], 'text' => 'Page on the Scottish Parliament website'); } if (isset($links['wikipedia_url'])) { $out[] = array('href' => $links['wikipedia_url'], 'text' => 'Wikipedia page'); } if (isset($links['bbc_profile_url'])) { $out[] = array('href' => $links['bbc_profile_url'], 'text' => 'BBC News profile'); } if (isset($links['diocese_url'])) { $out[] = array('href' => $links['diocese_url'], 'text' => 'Diocese website'); } if ($member->house(HOUSE_TYPE_COMMONS)) { $out[] = array('href' => 'http://www.edms.org.uk/mps/' . $member->person_id(), 'text' => 'Early Day Motions signed by this MP'); } if (isset($links['journa_list_link'])) { $out[] = array('href' => $links['journa_list_link'], 'text' => 'Newspaper articles written by this MP'); } return $out; }
private function divisionUrlFromGid($gid) { global $hansardmajors; $q = $this->db->query("SELECT gid, major FROM hansard WHERE epobject_id = ( SELECT subsection_id FROM hansard WHERE gid = :gid )", array(':gid' => $gid)); $parent_gid = $q->field(0, 'gid'); if (!$parent_gid) { return ''; } $parent_gid = fix_gid_from_db($parent_gid); $url = new \URL($hansardmajors[$q->field(0, 'major')]['page']); $url->insert(array('gid' => $parent_gid)); return $url->generate(); }