Exemple #1
0
    <?php 
include_once '../../includes/easyparliament/init.php';
include_once INCLUDESPATH . "easyparliament/glossary.php";
include_once INCLUDESPATH . "easyparliament/glossarylist.php";
$this_page = "glossary_addlink";
$args = array('action' => $this_page);
// First things first...
if (get_http_var('g') != '' && get_http_var('previewterm') == '') {
    // We're searching for something.
    $args['s'] = filter_user_input(get_http_var('g'), 'strict');
    $GLOSSARY = new GLOSSARY($args);
} else {
    $args['sort'] = "regexp_replace";
    $GLOSSARY = new GLOSSARY($args);
    $args['s'] = filter_user_input(get_http_var('g'), 'strict');
}
$PAGE->page_start();
$PAGE->stripe_start();
$data = array('title' => get_http_var('g'), 'body' => get_http_var('definition'));
// For previewing and adding a Glossary term.
// We should have post args of 'body' and 'term'.
if (get_http_var("submitterm") != '') {
    // We're submitting a comment.
    $success = $GLOSSARY->create($data);
    if ($success) {
        // $success will be the editqueue_id().
        print "<h4>All good so far...</h4><p>Your definition for <strong>&quot;" . $data['title'] . "&quot;</strong> now awaits moderator approval or somesuch thing...</p>";
        $PAGE->glossary_links();
    } else {
        $PAGE->error_message("Sorry, there was an error and we were unable to add your Glossary item.");
    }
Exemple #2
0
    function load_extra_info()
    {
        $q = $this->db->query('SELECT * FROM moffice WHERE person=' . mysql_real_escape_string($this->person_id) . ' ORDER BY from_date DESC');
        for ($row = 0; $row < $q->rows(); $row++) {
            $this->extra_info['office'][] = $q->row($row);
        }
        // Info specific to member id (e.g. attendance during that period of office)
        #$q = $this->db->query("SELECT data_key, data_value,
        #			(SELECT count(member_id) FROM memberinfo AS m2
        #				WHERE m2.data_key=memberinfo.data_key AND m2.data_value=memberinfo.data_value) AS joint
        #               FROM 	memberinfo
        #               WHERE	member_id = '" . mysql_real_escape_string($this->member_id) . "'
        #               ");
        $q = $this->db->query("SELECT data_key, data_value\n                        FROM \tmemberinfo\n                        WHERE\tmember_id = '" . mysql_real_escape_string($this->member_id) . "'\n                        ");
        for ($row = 0; $row < $q->rows(); $row++) {
            $this->extra_info[$q->field($row, 'data_key')] = $q->field($row, 'data_value');
            #		if ($q->field($row, 'joint') > 1)
            #			$this->extra_info[$q->field($row, 'data_key').'_joint'] = true;
        }
        // Info specific to person id (e.g. their permanent page on the Guardian website)
        #$q = $this->db->query("SELECT data_key, data_value, (SELECT person_id FROM personinfo AS p2
        #		WHERE p2.person_id <> personinfo.person_id AND p2.data_key=personinfo.data_key AND p2.data_value=personinfo.data_value LIMIT 1) AS count
        #               FROM 	personinfo
        #               WHERE	person_id = '" . mysql_real_escape_string($this->person_id) . "'
        #               ");
        $q = $this->db->query("SELECT data_key, data_value\n                        FROM \tpersoninfo\n                        WHERE\tperson_id = '" . mysql_real_escape_string($this->person_id) . "'\n                        ");
        for ($row = 0; $row < $q->rows(); $row++) {
            $this->extra_info[$q->field($row, 'data_key')] = $q->field($row, 'data_value');
            #	    if ($q->field($row, 'count') > 1)
            #	    	$this->extra_info[$q->field($row, 'data_key').'_joint'] = true;
        }
        // Info specific to constituency (e.g. election results page on Guardian website)
        $q = $this->db->query("SELECT\tdata_key,\n                                data_value\n                        FROM \tconsinfo\n                        WHERE\tconstituency = '" . mysql_real_escape_string($this->constituency) . "'\n                        ");
        for ($row = 0; $row < $q->rows(); $row++) {
            $this->extra_info[$q->field($row, 'data_key')] = $q->field($row, 'data_value');
        }
        if (array_key_exists('guardian_mp_summary', $this->extra_info)) {
            $guardian_url = $this->extra_info['guardian_mp_summary'];
            $this->extra_info['guardian_register_member_interests'] = str_replace("/person/", "/person/parliamentrmi/", $guardian_url);
            $this->extra_info['guardian_parliament_history'] = str_replace("/person/", "/person/parliament/", $guardian_url);
            $this->extra_info['guardian_biography'] = $guardian_url;
            #                    str_replace("/person/", "/person/biography/", $guardian_url);
            $this->extra_info['guardian_candidacies'] = str_replace("/person/", "/person/candidacies/", $guardian_url);
            $this->extra_info['guardian_howtheyvoted'] = str_replace("/person/", "/person/howtheyvoted/", $guardian_url);
            $this->extra_info['guardian_contactdetails'] = str_replace("/person/", "/person/contactdetails/", $guardian_url);
        }
        if (array_key_exists('public_whip_rebellions', $this->extra_info)) {
            $rebellions = $this->extra_info['public_whip_rebellions'];
            $rebel_desc = "<unknown>";
            if ($rebellions == 0) {
                $rebel_desc = "never";
            } elseif ($rebellions <= 1) {
                $rebel_desc = "hardly ever";
            } elseif ($rebellions <= 3) {
                $rebel_desc = "occasionally";
            } elseif ($rebellions <= 5) {
                $rebel_desc = "sometimes";
            } elseif ($rebellions > 5) {
                $rebel_desc = "quite often";
            }
            $this->extra_info['public_whip_rebel_description'] = $rebel_desc;
        }
        if (isset($this->extra_info['public_whip_attendrank'])) {
            $prefix = $this->house(2) ? 'L' : '';
            $this->extra_info[$prefix . 'public_whip_division_attendance_rank'] = $this->extra_info['public_whip_attendrank'];
            $this->extra_info[$prefix . 'public_whip_division_attendance_rank_outof'] = $this->extra_info['public_whip_attendrank_outof'];
            $this->extra_info[$prefix . 'public_whip_division_attendance_quintile'] = floor($this->extra_info['public_whip_attendrank'] / ($this->extra_info['public_whip_attendrank_outof'] + 1) * 5);
        }
        if ($this->house(2) && isset($this->extra_info['public_whip_division_attendance'])) {
            $this->extra_info['Lpublic_whip_division_attendance'] = $this->extra_info['public_whip_division_attendance'];
            unset($this->extra_info['public_whip_division_attendance']);
        }
        if (array_key_exists('register_member_interests_html', $this->extra_info) && $this->extra_info['register_member_interests_html'] != '') {
            $args = array("sort" => "regexp_replace");
            $GLOSSARY = new GLOSSARY($args);
            $this->extra_info['register_member_interests_html'] = $GLOSSARY->glossarise($this->extra_info['register_member_interests_html']);
        }
        $q = $this->db->query('select count(*) as c from alerts where criteria like "%speaker:' . $this->person_id . '%" and confirmed and not deleted');
        $this->extra_info['number_of_alerts'] = $q->field(0, 'c');
        if (isset($this->extra_info['reading_ease'])) {
            $this->extra_info['reading_ease'] = round($this->extra_info['reading_ease'], 2);
            $this->extra_info['reading_year'] = round($this->extra_info['reading_year'], 0);
            $this->extra_info['reading_age'] = $this->extra_info['reading_year'] + 4;
            $this->extra_info['reading_age'] .= '&ndash;' . ($this->extra_info['reading_year'] + 5);
        }
        # Public Bill Committees
        $q = $this->db->query('select bill_id,session,title,sum(attending) as a,sum(chairman) as c
		from pbc_members, bills
		where bill_id = bills.id and member_id = ' . $this->member_id() . ' group by bill_id');
        $this->extra_info['pbc'] = array();
        for ($i = 0; $i < $q->rows(); $i++) {
            $bill_id = $q->field($i, 'bill_id');
            $c = $this->db->query('select count(*) as c from hansard where major=6 and minor=' . $bill_id . ' and htype=10');
            $c = $c->field(0, 'c');
            $title = $q->field($i, 'title');
            $attending = $q->field($i, 'a');
            $chairman = $q->field($i, 'c');
            $this->extra_info['pbc'][$bill_id] = array('title' => $title, 'session' => $q->field($i, 'session'), 'attending' => $attending, 'chairman' => $chairman > 0, 'outof' => $c);
        }
    }
 protected function display_section_or_speech($args = array())
 {
     global $DATA, $this_page, $THEUSER;
     # += as we *don't* want to override any already supplied argument
     $args += array('gid' => get_http_var('id'), 's' => get_http_var('s'), 'member_id' => get_http_var('m'));
     if (preg_match('/speaker:(\\d+)/', get_http_var('s'), $mmm)) {
         $args['person_id'] = $mmm[1];
     }
     try {
         $data = $this->list->display('gid', $args, 'none');
     } catch (\RedirectException $e) {
         $URL = new \URL($this->major_data['page_all']);
         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'));
         } else {
             $URL->insert(array('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']));
         }
         redirect($URL->generate('none'));
     }
     $data['individual_item'] = $this->list->commentspage == $this_page;
     if ($data['individual_item']) {
         $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('epobject_id' => $this->list->epobject_id(), 'gid' => get_http_var('id'), 'return_page' => $this_page);
     }
     if (!isset($data['info'])) {
         header("HTTP/1.0 404 Not Found");
         exit;
         # XXX
     }
     # Okay, let's set up highlighting and glossarisation
     $SEARCHENGINE = null;
     if (isset($data['info']['searchstring']) && $data['info']['searchstring'] != '') {
         $SEARCHENGINE = new \SEARCHENGINE($data['info']['searchstring']);
     }
     // Before we print the body text we need to insert glossary links
     // and highlight search string words.
     $speeches = 0;
     $bodies = array();
     foreach ($data['rows'] as $row) {
         $htype = $row['htype'];
         if ($htype == 12 || $htype == 13) {
             $speeches++;
         }
         $body = $row['body'];
         $body = preg_replace('#<phrase class="honfriend" id="uk.org.publicwhip/member/(\\d+)" name="([^"]*?)">(.*?\\s*\\((.*?)\\))</phrase>#', '<a href="/mp/?m=$1" title="Our page on $2 - \'$3\'">$4</a>', $body);
         $body = preg_replace_callback('#<phrase class="offrep" id="(.*?)/(\\d+)-(\\d+)-(\\d+)\\.(.*?)">(.*?)</phrase>#', function ($matches) {
             return '<a href="/search/?pop=1&s=date:' . $matches[2] . $matches[3] . $matches[4] . '+column:' . $matches[5] . '+section:' . $matches[1] . '">' . str_replace("Official Report", "Hansard", $matches[6]) . '</a>';
         }, $body);
         #$body = preg_replace('#<phrase class="offrep" id="((.*?)/(\d+)-(\d+)-(\d+)\.(.*?))">(.*?)</phrase>#e', "\"<a href='/search/?pop=1&amp;s=date:$3$4$5+column:$6+section:$2&amp;match=$1'>\" . str_replace('Official Report', 'Hansard', '$7') . '</a>'", $body);
         $bodies[] = $body;
     }
     // Do all this unless the glossary is turned off in the URL
     if (get_http_var('ug') != 1) {
         // And glossary phrases
         twfy_debug_timestamp('Before glossarise');
         $args['sort'] = "regexp_replace";
         $GLOSSARY = new \GLOSSARY($args);
         $bodies = $GLOSSARY->glossarise($bodies, 1);
         twfy_debug_timestamp('After glossarise');
     }
     if ($SEARCHENGINE) {
         // We have some search terms to highlight.
         twfy_debug_timestamp('Before highlight');
         $bodies = $SEARCHENGINE->highlight($bodies);
         twfy_debug_timestamp('After highlight');
     }
     $first_speech = null;
     $data['section_title'] = '';
     $subsection_title = '';
     for ($i = 0; $i < count($data['rows']); $i++) {
         $row = $data['rows'][$i];
         $htype = $row['htype'];
         // HPOS should be defined below if it's needed; otherwise default to 0
         $heading_hpos = 0;
         if ($htype == 10) {
             $data['section_title'] = $row['body'];
             $heading_hpos = $row['hpos'];
         } elseif ($htype == 11) {
             $subsection_title = $row['body'];
             $heading_hpos = $row['hpos'];
         } elseif ($htype == 12) {
             # Splitting out highlighting results back into individual bits
             $data['rows'][$i]['body'] = $bodies[$i];
         }
         if ($htype == 12 || $htype == 13) {
             if (!$first_speech) {
                 $first_speech = $data['rows'][$i];
             }
             # 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']);
             }
             # Annotation link
             if ($this->is_debate_section_page()) {
                 // Build the 'Add an annotation' link.
                 if (!$THEUSER->isloggedin()) {
                     $URL = new \URL('userprompt');
                     $URL->insert(array('ret' => $row['commentsurl']));
                     $data['rows'][$i]['annotation_url'] = $URL->generate();
                 } else {
                     $data['rows'][$i]['annotation_url'] = $row['commentsurl'];
                 }
                 $data['rows'][$i]['commentteaser'] = $this->generate_commentteaser($row);
             }
             if (isset($row['mentions'])) {
                 $data['rows'][$i]['mentions'] = $this->get_question_mentions_html($row['mentions']);
             }
             if ($this->major == 1) {
                 $data['rows'][$i]['video'] = $this->get_video_html($row, $heading_hpos, $speeches);
             }
         }
     }
     if ($subsection_title) {
         $data['heading'] = $subsection_title;
     } else {
         $data['heading'] = $data['section_title'];
     }
     if ($subsection_title) {
         $data['intro'] = "{$data['section_title']}";
     } else {
         $data['intro'] = "";
     }
     $country = 'UK';
     if ($this->major == 1) {
         $data['location'] = '&ndash; in the House of Commons';
     } elseif ($this->major == 2) {
         $data['location'] = '&ndash; in Westminster Hall';
     } elseif ($this->major == 3) {
         $data['location'] = 'written question &ndash; answered';
     } elseif ($this->major == 4) {
         $data['location'] = 'written statement &ndash; made';
     } elseif ($this->major == 5) {
         $country = 'NORTHERN IRELAND';
         $data['location'] = '&ndash; in the Northern Ireland Assembly';
     } elseif ($this->major == 6) {
         $data['location'] = '&ndash; in a Public Bill Committee';
     } elseif ($this->major == 7) {
         $country = 'SCOTLAND';
         $data['location'] = '&ndash; in the Scottish Parliament';
     } elseif ($this->major == 8) {
         $country = 'SCOTLAND';
         $data['location'] = '&ndash; Scottish Parliament written question &ndash; answered';
     } elseif ($this->major == 101) {
         $data['location'] = '&ndash; in the House of Lords';
     }
     $data['current_assembly'] = "westminster--debate";
     switch ($country) {
         case "UK":
             $data['current_assembly'] = "westminster--debate";
             break;
         case "SCOTLAND":
             $data['current_assembly'] = "scotland";
             break;
         case "NORTHERN IRELAND":
             $data['current_assembly'] = "ni";
             break;
     }
     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) {
             $data['email_alert_text'] = $data['section_title'];
         } else {
             $data['email_alert_text'] = $data['info']['text_heading'];
         }
     } else {
         // The user has requested only part of a debate, so find a suitable title
         if ($subsection_title) {
             $data['intro'] = "Part of {$data['section_title']}";
         } else {
             $data['intro'] = "Part of the debate";
         }
         foreach ($data['rows'] as $row) {
             if ($row['htype'] == 10 || $row['htype'] == 11) {
                 $data['email_alert_text'] = $row['body'];
                 $data['full_debate_url'] = $row['listurl'];
                 break;
             }
         }
     }
     // strip a couple of common characters that result in encode junk in the
     // search string
     $data['email_alert_text'] = preg_replace('/(?:[:()\\[\\]]|&#\\d+;)/', '', $data['email_alert_text']);
     $data['debate_time_human'] = format_time($first_speech['htime'], 'g:i a');
     $data['debate_day_human'] = format_date($first_speech['hdate'], 'jS F Y');
     $URL = new \URL($this->list->listpage);
     $URL->insert(array('d' => $first_speech['hdate']));
     $URL->remove(array('id'));
     $data['debate_day_link'] = $URL->generate();
     $data['nextprev'] = $DATA->page_metadata($this_page, 'nextprev');
     return $data;
 }
Exemple #4
0
<?php

// Some sketchy crap for displaying pending glossary additions
include_once "../../includes/easyparliament/init.php";
include_once INCLUDESPATH . "easyparliament/editqueue.php";
include_once INCLUDESPATH . "easyparliament/glossary.php";
$this_page = "admin_glossary";
$EDITQUEUE = new GLOSSEDITQUEUE();
$args = array('sort' => "regexp_replace");
$GLOSSARY = new GLOSSARY($args);
// If we're coming back here from a recent action we will have
// an http POST var of 'approve' or 'decline'.
// 'approve' can be an array or a single value depending on whether or not it was a form submission.
// 'decline' will always be a single value.
if (get_http_var('approve')) {
    $approve = get_http_var('approve');
    if (!is_array($approve)) {
        $approve = array($approve);
    }
    // Add all approved items
    $data = array('approvals' => $approve, 'epobject_type' => 2);
    $EDITQUEUE->approve($data);
} elseif (get_http_var('decline')) {
    $decline = array(get_http_var('decline'));
    // Dump all declined items
    $data = array('declines' => $decline, 'epobject_type' => 2);
    $EDITQUEUE->decline($data);
} elseif (get_http_var('delete_confirm')) {
    $delete_id = get_http_var('delete_confirm');
    // Delete the existing glossary entry
    $GLOSSARY->delete($delete_id);
Exemple #5
0
    function load_extra_info($display = false)
    {
        global $memcache;
        if (!$memcache) {
            $memcache = new Memcache();
            $memcache->connect('localhost', 11211);
        }
        $this->extra_info = $memcache->get(OPTION_TWFY_DB_NAME . ':extra_info:' . $this->person_id);
        if ($this->extra_info) {
            return;
        }
        $this->extra_info = array();
        $q = $this->db->query('SELECT * FROM moffice WHERE person=' . mysql_real_escape_string($this->person_id) . ' ORDER BY from_date DESC');
        for ($row = 0; $row < $q->rows(); $row++) {
            $this->extra_info['office'][] = $q->row($row);
        }
        // Info specific to member id (e.g. attendance during that period of office)
        #$q = $this->db->query("SELECT data_key, data_value,
        #			(SELECT count(member_id) FROM memberinfo AS m2
        #				WHERE m2.data_key=memberinfo.data_key AND m2.data_value=memberinfo.data_value) AS joint
        #               FROM 	memberinfo
        #               WHERE	member_id = '" . mysql_real_escape_string($this->member_id) . "'
        #               ");
        $q = $this->db->query("SELECT data_key, data_value\n                        FROM \tmemberinfo\n                        WHERE\tmember_id = '" . mysql_real_escape_string($this->member_id) . "'\n                        ");
        for ($row = 0; $row < $q->rows(); $row++) {
            $this->extra_info[$q->field($row, 'data_key')] = $q->field($row, 'data_value');
            #		if ($q->field($row, 'joint') > 1)
            #			$this->extra_info[$q->field($row, 'data_key').'_joint'] = true;
        }
        // Info specific to person id (e.g. their permanent page on the Guardian website)
        #$q = $this->db->query("SELECT data_key, data_value, (SELECT person_id FROM personinfo AS p2
        #		WHERE p2.person_id <> personinfo.person_id AND p2.data_key=personinfo.data_key AND p2.data_value=personinfo.data_value LIMIT 1) AS count
        #               FROM 	personinfo
        #               WHERE	person_id = '" . mysql_real_escape_string($this->person_id) . "'
        #               ");
        $q = $this->db->query("SELECT data_key, data_value\n                        FROM \tpersoninfo\n                        WHERE\tperson_id = '" . mysql_real_escape_string($this->person_id) . "'\n                        ");
        for ($row = 0; $row < $q->rows(); $row++) {
            $this->extra_info[$q->field($row, 'data_key')] = $q->field($row, 'data_value');
            #	    if ($q->field($row, 'count') > 1)
            #	    	$this->extra_info[$q->field($row, 'data_key').'_joint'] = true;
        }
        // Info specific to constituency (e.g. election results page on Guardian website)
        if ($this->house(1)) {
            $q = $this->db->query("SELECT data_key, data_value FROM consinfo\n\t\t\tWHERE constituency = '" . mysql_real_escape_string($this->constituency) . "'");
            for ($row = 0; $row < $q->rows(); $row++) {
                $this->extra_info[$q->field($row, 'data_key')] = $q->field($row, 'data_value');
            }
            if (array_key_exists('guardian_mp_summary', $this->extra_info)) {
                $guardian_url = $this->extra_info['guardian_mp_summary'];
                $this->extra_info['guardian_biography'] = $guardian_url;
            }
            if (array_key_exists('guardian_aristotle_id', $this->extra_info)) {
                $politics_base_url = 'http://politics.guardian.co.uk/person/';
                $aristotle_id = $this->extra_info['guardian_aristotle_id'];
                $this->extra_info['guardian_howtheyvoted'] = $politics_base_url . "howtheyvoted/0,,-{$aristotle_id},00.html";
            }
        }
        if (array_key_exists('public_whip_rebellions', $this->extra_info)) {
            $rebellions = $this->extra_info['public_whip_rebellions'];
            $rebel_desc = "<unknown>";
            if ($rebellions == 0) {
                $rebel_desc = "never";
            } else {
                if ($rebellions == 1) {
                    $rebel_desc = "hardly ever";
                } else {
                    if ($rebellions == 2 or $rebellions == 3) {
                        $rebel_desc = "occasionally";
                    } else {
                        if ($rebellions == 4 or $rebellions == 5) {
                            $rebel_desc = "sometimes";
                        } else {
                            if ($rebellions > 5) {
                                $rebel_desc = "quite often";
                            }
                        }
                    }
                }
            }
            $this->extra_info['public_whip_rebel_description'] = $rebel_desc;
        }
        if (isset($this->extra_info['public_whip_attendrank'])) {
            $prefix = $this->house(2) ? 'L' : '';
            $this->extra_info[$prefix . 'public_whip_division_attendance_rank'] = $this->extra_info['public_whip_attendrank'];
            $this->extra_info[$prefix . 'public_whip_division_attendance_rank_outof'] = $this->extra_info['public_whip_attendrank_outof'];
            $this->extra_info[$prefix . 'public_whip_division_attendance_quintile'] = floor($this->extra_info['public_whip_attendrank'] / ($this->extra_info['public_whip_attendrank_outof'] + 1) * 5);
        }
        if ($this->house(2) && isset($this->extra_info['public_whip_division_attendance'])) {
            $this->extra_info['Lpublic_whip_division_attendance'] = $this->extra_info['public_whip_division_attendance'];
            unset($this->extra_info['public_whip_division_attendance']);
        }
        if ($display && array_key_exists('register_member_interests_html', $this->extra_info) && $this->extra_info['register_member_interests_html'] != '') {
            $args = array("sort" => "regexp_replace");
            $GLOSSARY = new GLOSSARY($args);
            $this->extra_info['register_member_interests_html'] = $GLOSSARY->glossarise($this->extra_info['register_member_interests_html']);
        }
        $q = $this->db->query('select count(*) as c from alerts where criteria like "%speaker:' . $this->person_id . '%" and confirmed and not deleted');
        $this->extra_info['number_of_alerts'] = $q->field(0, 'c');
        if (isset($this->extra_info['reading_ease'])) {
            $this->extra_info['reading_ease'] = round($this->extra_info['reading_ease'], 2);
            $this->extra_info['reading_year'] = round($this->extra_info['reading_year'], 0);
            $this->extra_info['reading_age'] = $this->extra_info['reading_year'] + 4;
            $this->extra_info['reading_age'] .= '&ndash;' . ($this->extra_info['reading_year'] + 5);
        }
        # Public Bill Committees
        $q = $this->db->query('select bill_id,session,title,sum(attending) as a,sum(chairman) as c
		from pbc_members, bills
		where bill_id = bills.id and member_id in (select member_id from member where person_id = ' . $this->person_id() . ') group by bill_id order by session desc');
        $this->extra_info['pbc'] = array();
        for ($i = 0; $i < $q->rows(); $i++) {
            $bill_id = $q->field($i, 'bill_id');
            #$c = $this->db->query('select count(*) as c from hansard where major=6 and minor='.$bill_id.' and htype=10');
            #$c = $c->field(0, 'c');
            $c = 'n/a';
            $title = $q->field($i, 'title');
            $attending = $q->field($i, 'a');
            $chairman = $q->field($i, 'c');
            $this->extra_info['pbc'][$bill_id] = array('title' => $title, 'session' => $q->field($i, 'session'), 'attending' => $attending, 'chairman' => $chairman > 0, 'outof' => $c);
        }
        $memcache->set(OPTION_TWFY_DB_NAME . ':extra_info:' . $this->person_id, $this->extra_info, MEMCACHE_COMPRESSED, 3600);
    }
Exemple #6
0
 private function highlightSpeeches($data)
 {
     $SEARCHENGINE = null;
     if (isset($data['info']['searchstring']) && $data['info']['searchstring'] != '') {
         $SEARCHENGINE = new \SEARCHENGINE($data['info']['searchstring']);
     }
     // Before we print the body text we need to insert glossary links
     // and highlight search string words.
     $speeches = 0;
     $bodies = array();
     foreach ($data['rows'] as $row) {
         $htype = $row['htype'];
         if ($htype == 12 || $htype == 13) {
             $speeches++;
         }
         $body = $row['body'];
         $body = preg_replace('#<phrase class="honfriend" id="uk.org.publicwhip/member/(\\d+)" name="([^"]*?)">(.*?\\s*\\((.*?)\\))</phrase>#', '<a href="/mp/?m=$1" title="Our page on $2 - \'$3\'">$4</a>', $body);
         $body = preg_replace('#<phrase class="honfriend" name="([^"]*?)" person_id="uk.org.publicwhip/person/(\\d+)">(.*?\\s*\\((.*?)\\))</phrase>#', '<a href="/mp/?p=$2" title="Our page on $1 - \'$3\'">$4</a>', $body);
         $body = preg_replace_callback('#<phrase class="offrep" id="(.*?)/(\\d+)-(\\d+)-(\\d+)\\.(.*?)">(.*?)</phrase>#', function ($matches) {
             return '<a href="/search/?pop=1&s=date:' . $matches[2] . $matches[3] . $matches[4] . '+column:' . $matches[5] . '+section:' . $matches[1] . '">' . str_replace("Official Report", "Hansard", $matches[6]) . '</a>';
         }, $body);
         #$body = preg_replace('#<phrase class="offrep" id="((.*?)/(\d+)-(\d+)-(\d+)\.(.*?))">(.*?)</phrase>#e', "\"<a href='/search/?pop=1&amp;s=date:$3$4$5+column:$6+section:$2&amp;match=$1'>\" . str_replace('Official Report', 'Hansard', '$7') . '</a>'", $body);
         $bodies[] = $body;
     }
     if ($SEARCHENGINE) {
         // We have some search terms to highlight.
         twfy_debug_timestamp('Before highlight');
         $bodies = $SEARCHENGINE->highlight($bodies);
         twfy_debug_timestamp('After highlight');
     }
     // Do all this unless the glossary is turned off in the URL
     if (get_http_var('ug') != 1) {
         // And glossary phrases
         twfy_debug_timestamp('Before glossarise');
         $args['sort'] = "regexp_replace";
         $GLOSSARY = new \GLOSSARY($args);
         $bodies = $GLOSSARY->glossarise($bodies, 1);
         twfy_debug_timestamp('After glossarise');
     }
     return array($bodies, $speeches);
 }
Exemple #7
0
<?php

include_once "../../includes/easyparliament/init.php";
include_once INCLUDESPATH . "easyparliament/glossary.php";
include_once INCLUDESPATH . "easyparliament/glossarylist.php";
//$this_page = "glossary_addterm";
$this_page = "help_us_out";
$args = array('action' => $this_page);
// First things first...
if (get_http_var('g') != '' && get_http_var('previewterm') == '') {
    // We're searching for something.
    $args['s'] = filter_user_input(get_http_var('g'), 'strict');
    $GLOSSARY = new GLOSSARY($args);
} else {
    $args['sort'] = "regexp_replace";
    $GLOSSARY = new GLOSSARY($args);
    $args['s'] = filter_user_input(get_http_var('g'), 'strict');
}
// Check that people aren't trying to define silly words
if (in_array(strtolower($GLOSSARY->query), $GLOSSARY->stopwords)) {
    $GLOSSARY->query = "";
    $args['blankform'] = 1;
    $URL = new URL('help_us_out');
    $backlink = $URL->generate();
    $error_message = "Sorry, that phrase appears too many times to be a useful as a link within the parliamentary record.";
}
// do a quick searchengine count
if ($GLOSSARY->query != "") {
    $SEARCHENGINE = new SEARCHENGINE('"' . $args['s'] . '"');
    $args['count'] = $SEARCHENGINE->run_count();
    if (!$args['count']) {
Exemple #8
0
 public function load_extra_info($display = false)
 {
     $memcache = new MySociety\TheyWorkForYou\Memcache();
     $memcache_key = 'extra_info:' . $this->person_id . ($display ? '' : ':plain');
     $this->extra_info = $memcache->get($memcache_key);
     if (!DEVSITE && $this->extra_info) {
         return;
     }
     $this->extra_info = array();
     $q = $this->db->query('SELECT * FROM moffice WHERE person=:person_id ORDER BY from_date DESC', array(':person_id' => $this->person_id));
     for ($row = 0; $row < $q->rows(); $row++) {
         $this->extra_info['office'][] = $q->row($row);
     }
     // Info specific to member id (e.g. attendance during that period of office)
     $q = $this->db->query("SELECT data_key, data_value\n                        FROM \tmemberinfo\n                        WHERE\tmember_id = :member_id", array(':member_id' => $this->member_id));
     for ($row = 0; $row < $q->rows(); $row++) {
         $this->extra_info[$q->field($row, 'data_key')] = $q->field($row, 'data_value');
         #		if ($q->field($row, 'joint') > 1)
         #			$this->extra_info[$q->field($row, 'data_key').'_joint'] = true;
     }
     // Info specific to person id (e.g. their permanent page on the Guardian website)
     $q = $this->db->query("SELECT data_key, data_value\n                        FROM \tpersoninfo\n                        WHERE\tperson_id = :person_id", array(':person_id' => $this->person_id));
     for ($row = 0; $row < $q->rows(); $row++) {
         $this->extra_info[$q->field($row, 'data_key')] = $q->field($row, 'data_value');
         #	    if ($q->field($row, 'count') > 1)
         #	    	$this->extra_info[$q->field($row, 'data_key').'_joint'] = true;
     }
     // Info specific to constituency (e.g. election results page on Guardian website)
     if ($this->house(HOUSE_TYPE_COMMONS)) {
         $q = $this->db->query("SELECT data_key, data_value FROM consinfo\n            WHERE constituency = :constituency", array(':constituency' => $this->constituency));
         for ($row = 0; $row < $q->rows(); $row++) {
             $this->extra_info[$q->field($row, 'data_key')] = $q->field($row, 'data_value');
         }
     }
     if (array_key_exists('public_whip_rebellions', $this->extra_info)) {
         $rebellions = $this->extra_info['public_whip_rebellions'];
         $rebel_desc = "<unknown>";
         if ($rebellions == 0) {
             $rebel_desc = "never";
         } elseif ($rebellions <= 1) {
             $rebel_desc = "hardly ever";
         } elseif ($rebellions <= 3) {
             $rebel_desc = "occasionally";
         } elseif ($rebellions <= 5) {
             $rebel_desc = "sometimes";
         } elseif ($rebellions > 5) {
             $rebel_desc = "quite often";
         }
         $this->extra_info['public_whip_rebel_description'] = $rebel_desc;
     }
     if (isset($this->extra_info['public_whip_attendrank'])) {
         $prefix = $this->house(HOUSE_TYPE_LORDS) ? 'L' : '';
         $this->extra_info[$prefix . 'public_whip_division_attendance_rank'] = $this->extra_info['public_whip_attendrank'];
         $this->extra_info[$prefix . 'public_whip_division_attendance_rank_outof'] = $this->extra_info['public_whip_attendrank_outof'];
         $this->extra_info[$prefix . 'public_whip_division_attendance_quintile'] = floor($this->extra_info['public_whip_attendrank'] / ($this->extra_info['public_whip_attendrank_outof'] + 1) * 5);
     }
     if ($this->house(HOUSE_TYPE_LORDS) && isset($this->extra_info['public_whip_division_attendance'])) {
         $this->extra_info['Lpublic_whip_division_attendance'] = $this->extra_info['public_whip_division_attendance'];
         unset($this->extra_info['public_whip_division_attendance']);
     }
     if ($display && array_key_exists('register_member_interests_html', $this->extra_info) && $this->extra_info['register_member_interests_html'] != '') {
         $args = array("sort" => "regexp_replace");
         $GLOSSARY = new GLOSSARY($args);
         $this->extra_info['register_member_interests_html'] = $GLOSSARY->glossarise($this->extra_info['register_member_interests_html']);
     }
     $q = $this->db->query('select count(*) as c from alerts where criteria like "%speaker:' . $this->person_id . '%" and confirmed and not deleted');
     $this->extra_info['number_of_alerts'] = $q->field(0, 'c');
     if (isset($this->extra_info['reading_ease'])) {
         $this->extra_info['reading_ease'] = round($this->extra_info['reading_ease'], 2);
         $this->extra_info['reading_year'] = round($this->extra_info['reading_year'], 0);
         $this->extra_info['reading_age'] = $this->extra_info['reading_year'] + 4;
         $this->extra_info['reading_age'] .= '&ndash;' . ($this->extra_info['reading_year'] + 5);
     }
     # Public Bill Committees
     $q = $this->db->query('select bill_id,session,title,sum(attending) as a,sum(chairman) as c
         from pbc_members, bills
         where bill_id = bills.id and person_id = ' . $this->person_id() . ' group by bill_id order by session desc');
     $this->extra_info['pbc'] = array();
     for ($i = 0; $i < $q->rows(); $i++) {
         $bill_id = $q->field($i, 'bill_id');
         $c = $this->db->query('select count(*) as c from hansard where major=6 and minor=' . $bill_id . ' and htype=10');
         $c = $c->field(0, 'c');
         $title = $q->field($i, 'title');
         $attending = $q->field($i, 'a');
         $chairman = $q->field($i, 'c');
         $this->extra_info['pbc'][$bill_id] = array('title' => $title, 'session' => $q->field($i, 'session'), 'attending' => $attending, 'chairman' => $chairman > 0, 'outof' => $c);
     }
     $memcache->set($memcache_key, $this->extra_info);
 }
 /**
  * Test that glossarising a Wikipedia title bounded by other characters with spaces works as expected.
  */
 public function testWikipediaLinkInSpacedString()
 {
     $args['sort'] = "regexp_replace";
     $glossary = new GLOSSARY($args);
     $this->assertEquals('foo <a href="http://en.wikipedia.org/wiki/MP">MP</a> bar', $glossary->glossarise('foo MP bar'));
 }