示例#1
0
function generate_rows($q)
{
    global $db;
    $rows = array();
    $USERURL = new URL('userview');
    for ($row = 0; $row < $q->rows(); $row++) {
        $email = $q->field($row, 'email');
        $criteria = $q->field($row, 'criteria');
        $SEARCHENGINE = new SEARCHENGINE($criteria);
        $r = $db->query("SELECT user_id,firstname,lastname FROM users WHERE email = '" . mysql_escape_string($email) . "'");
        if ($r->rows() > 0) {
            $user_id = $r->field(0, 'user_id');
            $USERURL->insert(array('u' => $user_id));
            $name = '<a href="' . $USERURL->generate() . '">' . $r->field(0, 'firstname') . ' ' . $r->field(0, 'lastname') . '</a>';
        } else {
            $name = $email;
        }
        $created = $q->field($row, 'created');
        if ($created == '0000-00-00 00:00:00') {
            $created = '&nbsp;';
        }
        $rows[] = array($name, $SEARCHENGINE->query_description_long(), $created);
    }
    return $rows;
}
 /**
  * Test that glossarising a single word works as expected.
  *
  * @group xapian
  */
 public function testSearchLink()
 {
     $SEARCHENGINE = new SEARCHENGINE('test');
     $this->assertEquals('<a href="/mp/?m=40584" title="Our page on Mr Test - \'the Member for Birmingham (Mr Test)\'">Mr <span class="hi">Test</span></a>', $SEARCHENGINE->highlight('<a href="/mp/?m=40584" title="Our page on Mr Test - \'the Member for Birmingham (Mr Test)\'">Mr Test</a>'));
 }
function search_by_usage($search, $house = 0)
{
    $data = array();
    $SEARCHENGINE = new SEARCHENGINE($search);
    $data['pagetitle'] = $SEARCHENGINE->query_description_short();
    $SEARCHENGINE = new SEARCHENGINE($search . ' groupby:speech');
    $count = $SEARCHENGINE->run_count(0, 5000, 'date');
    if ($count <= 0) {
        $data['error'] = 'No results';
        return $data;
    }
    $SEARCHENGINE->run_search(0, 5000, 'date');
    $gids = $SEARCHENGINE->get_gids();
    if (count($gids) <= 0) {
        $data['error'] = 'No results';
        return $data;
    }
    if (count($gids) == 5000) {
        $data['limit_reached'] = true;
    }
    # Fetch all the speakers of the results, count them up and get min/max date usage
    $speaker_count = array();
    $gids = join('","', $gids);
    $db = new ParlDB();
    $q = $db->query('SELECT gid,person_id,hdate FROM hansard WHERE gid IN ("' . $gids . '")');
    for ($n = 0; $n < $q->rows(); $n++) {
        $gid = $q->field($n, 'gid');
        $person_id = $q->field($n, 'person_id');
        $hdate = $q->field($n, 'hdate');
        if (!isset($speaker_count[$person_id])) {
            $speaker_count[$person_id] = 0;
            $maxdate[$person_id] = '1001-01-01';
            $mindate[$person_id] = '9999-12-31';
        }
        $speaker_count[$person_id]++;
        if ($hdate < $mindate[$person_id]) {
            $mindate[$person_id] = $hdate;
        }
        if ($hdate > $maxdate[$person_id]) {
            $maxdate[$person_id] = $hdate;
        }
    }
    # Fetch details of all the speakers
    $speakers = array();
    $pids = array();
    if (count($speaker_count)) {
        $person_ids = join(',', array_keys($speaker_count));
        $q = $db->query('SELECT member_id, member.person_id, title, given_name, family_name, lordofname,
                                constituency, house, party,
                                moffice_id, dept, position, from_date, to_date, left_house
                            FROM member LEFT JOIN moffice ON member.person_id = moffice.person
                                JOIN person_names pn ON member.person_id = pn.person_id AND pn.type="name" AND pn.start_date <= left_house AND left_house <= pn.end_date
                            WHERE member.person_id IN (' . $person_ids . ')
                            ' . ($house ? " AND house={$house}" : '') . '
                            ORDER BY left_house DESC');
        for ($n = 0; $n < $q->rows(); $n++) {
            $mid = $q->field($n, 'member_id');
            if (!isset($pids[$mid])) {
                $title = $q->field($n, 'title');
                $first = $q->field($n, 'given_name');
                $last = $q->field($n, 'family_name');
                $lordofname = $q->field($n, 'lordofname');
                $house = $q->field($n, 'house');
                $party = $q->field($n, 'party');
                $full_name = ucfirst(member_full_name($house, $title, $first, $last, $lordofname));
                $pid = $q->field($n, 'person_id');
                $pids[$mid] = $pid;
                $speakers[$pid]['house'] = $house;
                $speakers[$pid]['left'] = $q->field($n, 'left_house');
            }
            $dept = $q->field($n, 'dept');
            $posn = $q->field($n, 'position');
            $moffice_id = $q->field($n, 'moffice_id');
            if ($dept && $q->field($n, 'to_date') == '9999-12-31') {
                $speakers[$pid]['office'][$moffice_id] = prettify_office($posn, $dept);
            }
            if (!isset($speakers[$pid]['name'])) {
                $speakers[$pid]['name'] = $full_name . ($house == 1 ? ' MP' : '');
                $speakers[$pid]['party'] = $party;
            }
        }
    }
    if (isset($speaker_count[0])) {
        $speakers[0] = array('party' => '', 'name' => 'Headings, procedural text, etc.', 'house' => 0, 'count' => 0);
    }
    $party_count = array();
    $ok = 0;
    foreach ($speakers as $pid => &$speaker) {
        $speaker['count'] = $speaker_count[$pid];
        $speaker['pmaxdate'] = $maxdate[$pid];
        $speaker['pmindate'] = $mindate[$pid];
        $ok = 1;
        if (!isset($party_count[$speaker['party']])) {
            $party_count[$speaker['party']] = 0;
        }
        $party_count[$speaker['party']] += $count;
    }
    function sort_by_count($a, $b)
    {
        if ($a['count'] > $b['count']) {
            return -1;
        }
        if ($a['count'] < $b['count']) {
            return 1;
        }
        return 0;
    }
    uasort($speakers, 'sort_by_count');
    arsort($party_count);
    if (!$ok) {
        $data['error'] = 'No results';
        return $data;
    }
    $data['party_count'] = $party_count;
    $data['speakers'] = $speakers;
    return $data;
}
示例#4
0
文件: mobile.php 项目: leowmjw/twfy
                 $hdates[$hdate]++;
             }
             arsort($hdates);
             print '<table><tr><th>No.</th><th>Date</th></tr>';
             foreach ($hdates as $hdate => $count) {
                 print '<tr><td>';
                 print $count . '</td><td>';
                 print '<a href="' . WEBPATH . 'hansard/?d=' . $hdate . '">';
                 print $hdate;
                 print '</a>';
                 print '</td></tr>';
             }
             print '</table>';
     */
 } else {
     $SEARCHENGINE = new SEARCHENGINE($searchstring);
     $pagetitle = "Search: " . $SEARCHENGINE->query_description_short();
     $pagenum = get_http_var('p');
     if (is_numeric($pagenum) && $pagenum > 1) {
         $pagetitle .= " page {$pagenum}";
     }
     $DATA->set_page_metadata($this_page, 'title', $pagetitle);
     $DATA->set_page_metadata($this_page, 'rss', 'search/rss/?s=' . urlencode($searchstring));
     $PAGE->page_start_mobile();
     $PAGE->stripe_start();
     $PAGE->search_form();
     $o = get_http_var('o');
     $args = array('s' => $searchstring, 'p' => $pagenum, 'num' => get_http_var('num'), 'pop' => get_http_var('pop'), 'o' => $o == 'd' || $o == 'r' ? $o : 'd');
     $LIST = new HANSARDLIST();
     if ($args['s']) {
         $db = $LIST->db;
示例#5
0
 /**
  * Test that search highlighting with phrases skips words contained in link title attributes.
  *
  * @group xapian
  */
 public function testSearchPhraseHighlightingInTags()
 {
     $SEARCHENGINE = new SEARCHENGINE('"Shabana"');
     $expected_text = '<p pid="b.893.4/1">On a point of order, Mr <a href="/glossary/?gl=21" title="The Speaker is an MP who has been elected to act as Chairman during debates..." class="glossary">Speaker</a>. In yesterday&#8217;s Finance Bill debate, <a href="/mp/?m=40084" title="Our page on Shabana Mahmood - \'the hon. Member for Birmingham, Ladywood (Shabana Mahmood)\'"><span class="hi">Shabana</span> Mahmood</a> said that the tax gap was 32 billion when the previous Government left office and that it has now gone up to 35 billion. Official Her Majesty&#8217;s Revenue and Customs figures show the tax gap was actually 42 billion when Labour left office, so there has been a fall of 7 billion under this Government';
     $text = '<p pid="b.893.4/1">On a point of order, Mr <a href="/glossary/?gl=21" title="The Speaker is an MP who has been elected to act as Chairman during debates..." class="glossary">Speaker</a>. In yesterday&#8217;s Finance Bill debate, <a href="/mp/?m=40084" title="Our page on Shabana Mahmood - \'the hon. Member for Birmingham, Ladywood (Shabana Mahmood)\'">Shabana Mahmood</a> said that the tax gap was 32 billion when the previous Government left office and that it has now gone up to 35 billion. Official Her Majesty&#8217;s Revenue and Customs figures show the tax gap was actually 42 billion when Labour left office, so there has been a fall of 7 billion under this Government';
     $this->assertEquals($expected_text, $SEARCHENGINE->highlight($text));
 }
示例#6
0
 private function get_sidebar_links()
 {
     global $DATA, $SEARCHENGINE, $this_page;
     $links = array();
     $links['rss'] = $DATA->page_metadata($this_page, 'rss');
     if ($SEARCHENGINE) {
         $links['email'] = '/alert/?' . ($this->searchstring ? 'alertsearch=' . urlencode($this->searchstring) : '');
         $links['email_desc'] = $SEARCHENGINE->query_description_long();
     }
     $filter_ss = $this->searchstring;
     $section = get_http_var('section');
     if (preg_match('#\\s*section:([a-z]*)#', $filter_ss, $m)) {
         $section = $m[1];
         $filter_ss = preg_replace("#\\s*section:{$section}#", '', $filter_ss);
     }
     if ($section && $filter_ss) {
         $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_desc'] = $search_engine->query_description_long();
     }
     return $links;
 }
示例#7
0
		'content' => $sidebar
	)
));
*/
if ($data['info']['date'] == date('Y-m-d')) { ?>
<div style="padding: 4px; margin: 1em; color: #000000; background-color: #ffeeee; border: solid 2px #ff0000;">
Warning: Showing data from the current day is <strong>experimental</strong> and may not work correctly.
</div>
<?
}

if (isset ($data['rows'])) {
	// For highlighting
	$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.
	
	$bodies = array();
	foreach ($data['rows'] as $row) {
		$bodies[] = $row['body'];
	}
	if (isset($data['info']['glossarise']) && $data['info']['glossarise']) {
		// And glossary phrases
		twfy_debug_timestamp('Before glossarise');
		$bodies = $GLOSSARY->glossarise($bodies, $data['info']['glossarise']);
		twfy_debug_timestamp('After glossarise');
	}
示例#8
0
        arsort($hdates);
        print '<table><tr><th>No.</th><th>Date</th></tr>';
        foreach ($hdates as $hdate => $count) {
            print '<tr><td>';
            print $count . '</td><td>';
            print '<a href="' . WEBPATH . 'hansard/?d=' . $hdate . '">';
            print $hdate;
            print '</a>';
            print '</td></tr>';
        }
        print '</table>';
*/
    } else {


        $SEARCHENGINE = new SEARCHENGINE($searchstring); 
    	$pagetitle = 'Search for ' . $SEARCHENGINE->query_description_short();
    	$pagenum = get_http_var('p');
    	if (is_numeric($pagenum) && $pagenum > 1) {
    		$pagetitle .= ", page $pagenum";
    	}
	
    	$DATA->set_page_metadata($this_page, 'title', $pagetitle);
	    $DATA->set_page_metadata($this_page, 'rss', 'search/rss/?s=' . urlencode($searchstring));
    	$PAGE->page_start();
    	$PAGE->stripe_start();
    	$PAGE->search_form($searchstring);
	
        $o = get_http_var('o');
    	$args = array (
    		's' => $searchstring,
 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;
 }
示例#10
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);
 }
示例#11
0
文件: index.php 项目: NathanaelB/twfy
} 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']) {
        $GLOSSARY->query = "";
        $args['blankform'] = 1;
        $error_message = "Unfortunately <strong>" . $args['s'] . "</strong>, doesn't seem to appear in hansard at all...</p>";
    }
}
$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);
$email_text = '';
$email_text_anywhere = '';
# XXX global $searchstring is horrible
global $SEARCHENGINE, $searchstring;
if ($SEARCHENGINE) {
    $email_link = '/alert/?' . ($searchstring ? 'alertsearch=' . urlencode($searchstring) : '');
    $email_text = $SEARCHENGINE->query_description_long();
}
$filter_ss = $searchstring;
$section = get_http_var('section');
if (preg_match('#\\s*section:([a-z]*)#', $filter_ss, $m)) {
    $section = $m[1];
    $filter_ss = preg_replace("#\\s*section:{$section}#", '', $filter_ss);
}
if ($section) {
    $search_engine = new SEARCHENGINE($filter_ss);
    $email_link_anywhere = '/alert/?' . ($filter_ss ? 'alertsearch=' . urlencode($filter_ss) : '');
    $email_text_anywhere = $search_engine->query_description_long();
}
if ($email_text || $rss) {
    $this->block_start(array('title' => "Being alerted to new search results"));
    echo '<ul id="search_links">';
    if ($email_text) {
        if ($email_text_anywhere) {
            echo '<li id="search_links_email"><a href="', $email_link_anywhere, '">Subscribe to an email alert</a> for ', $email_text_anywhere;
            echo ' <br><small>(or just <a href="', $email_link, '">subscribe</a> for ', $email_text, ')</small></li>';
        } else {
            echo '<li id="search_links_email"><a href="', $email_link, '">Subscribe to an email alert</a> for ', $email_text, '</li>';
        }
    }
    if ($rss) {
示例#13
0
} 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(0, 10000);
    if (!$args['count']) {
        $GLOSSARY->query = "";
        $args['blankform'] = 1;
        $error_message = "Unfortunately <strong>" . $args['s'] . "</strong>, doesn't seem to appear in hansard at all...</p>";
    }
}
$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);
示例#14
0
function search_normal($searchstring)
{
    global $PAGE, $DATA, $this_page, $SEARCHENGINE;
    $SEARCHENGINE = new SEARCHENGINE($searchstring);
    $qd = $SEARCHENGINE->valid ? $SEARCHENGINE->query_description_short() : $searchstring;
    $pagetitle = 'Search for ' . $qd;
    $pagenum = get_http_var('p');
    if (!is_numeric($pagenum)) {
        $pagenum = 1;
    }
    if ($pagenum > 1) {
        $pagetitle .= ", page {$pagenum}";
    }
    $DATA->set_page_metadata($this_page, 'title', $pagetitle);
    $DATA->set_page_metadata($this_page, 'rss', 'search/rss/?s=' . urlencode($searchstring));
    if ($pagenum == 1) {
        # Allow indexing of first page of search results
        $DATA->set_page_metadata($this_page, 'robots', '');
    }
    $PAGE->page_start();
    $PAGE->stripe_start();
    $PAGE->search_form($searchstring);
    $o = get_http_var('o');
    $args = array('s' => $searchstring, 'p' => $pagenum, 'num' => get_http_var('num'), 'pop' => get_http_var('pop'), 'o' => $o == 'd' || $o == 'r' || $o == 'o' ? $o : 'd');
    if ($pagenum == 1 && $args['s'] && !preg_match('#[a-z]+:[a-z0-9]+#', $args['s'])) {
        find_members($args['s']);
        find_constituency($args);
        find_glossary_items($args);
    }
    if (!defined('FRONT_END_SEARCH') || !FRONT_END_SEARCH) {
        print '<p>Apologies, search has been turned off currently for performance reasons.</p>';
    }
    if (!$SEARCHENGINE->valid) {
        $PAGE->error_message($SEARCHENGINE->error);
    } else {
        $LIST = new HANSARDLIST();
        $LIST->display('search', $args);
    }
}