Esempio n. 1
0
 /**
  * Test testing for Scottish postcode
  */
 public function testPostcodeIsScottish()
 {
     $this->assertEquals(true, postcode_is_scottish('EH1 0AA'));
     $this->assertEquals(false, postcode_is_scottish('SW1A 1AA'));
 }
Esempio n. 2
0
 /**
  * Output Page
  *
  * Assembles a completed page from template and sends it to output.
  *
  * @param string $template The name of the template file to load.
  * @param array  $data     An associative array of data to be made available to the template.
  */
 public static function output($template, $data = array())
 {
     // Include includes.
     // TODO: Wrap these in a class somewhere autoloadable.
     include_once INCLUDESPATH . 'postcode.inc';
     ////////////////////////////////////////////////////////////
     // Find the user's country. Used by header, so a safe bit to do regardless.
     if (preg_match('#^[A-Z]{2}$#i', get_http_var('country'))) {
         $data['country'] = strtoupper(get_http_var('country'));
     } else {
         $data['country'] = Gaze::get_country_by_ip($_SERVER["REMOTE_ADDR"]);
     }
     ////////////////////////////////////////////////////////////
     // Get the page data
     global $DATA, $this_page, $THEUSER;
     $header = new Renderer\Header();
     $data = array_merge($header->data, $data);
     ////////////////////////////////////////////////////////////
     // User Navigation Links
     $data['user_nav_links'] = array();
     // We may want to send the user back to this current page after they've
     // joined, logged out or logged in. So we put the URL in $returl.
     $URL = new \URL($this_page);
     $returl = $URL->generate('none');
     //user logged in
     if ($THEUSER->isloggedin()) {
         // The 'Edit details' link.
         $menudata = $DATA->page_metadata('userviewself', 'menu');
         $edittext = $menudata['text'];
         $edittitle = $menudata['title'];
         $EDITURL = new \URL('userviewself');
         if ($this_page == 'userviewself' || $this_page == 'useredit' || $header->top_highlight == 'userviewself') {
             $editclass = 'on';
         } else {
             $editclass = '';
         }
         // The 'Log out' link.
         $menudata = $DATA->page_metadata('userlogout', 'menu');
         $logouttext = $menudata['text'];
         $logouttitle = $menudata['title'];
         $LOGOUTURL = new \URL('userlogout');
         if ($this_page != 'userlogout') {
             $LOGOUTURL->insert(array("ret" => $returl));
             $logoutclass = '';
         } else {
             $logoutclass = 'on';
         }
         $username = $THEUSER->firstname() . ' ' . $THEUSER->lastname();
         $data['user_nav_links'][] = array('href' => $LOGOUTURL->generate(), 'title' => $logouttitle, 'classes' => $logoutclass, 'text' => $logouttext);
         $data['user_nav_links'][] = array('href' => $EDITURL->generate(), 'title' => $edittitle, 'classes' => $editclass, 'text' => $edittext);
         $data['user_nav_links'][] = array('href' => $EDITURL->generate(), 'title' => $edittitle, 'classes' => $editclass, 'text' => _htmlentities($username));
     } else {
         // User not logged in
         // The 'Join' link.
         $menudata = $DATA->page_metadata('userjoin', 'menu');
         $jointext = $menudata['text'];
         $jointitle = $menudata['title'];
         $JOINURL = new \URL('userjoin');
         if ($this_page != 'userjoin') {
             if ($this_page != 'userlogout' && $this_page != 'userlogin') {
                 // We don't do this on the logout page, because then the user
                 // will return straight to the logout page and be logged out
                 // immediately!
                 $JOINURL->insert(array("ret" => $returl));
             }
             $joinclass = '';
         } else {
             $joinclass = 'on';
         }
         // The 'Log in' link.
         $menudata = $DATA->page_metadata('userlogin', 'menu');
         $logintext = $menudata['text'];
         $logintitle = $menudata['title'];
         $LOGINURL = new \URL('userlogin');
         if ($this_page != 'userlogin') {
             if ($this_page != "userlogout" && $this_page != "userpassword" && $this_page != 'userjoin') {
                 // We don't do this on the logout page, because then the user
                 // will return straight to the logout page and be logged out
                 // immediately!
                 // And it's also silly if we're sent back to Change Password.
                 // And the join page.
                 $LOGINURL->insert(array("ret" => $returl));
             }
             $loginclass = '';
         } else {
             $loginclass = 'on';
         }
         $data['user_nav_links'][] = array('href' => $LOGINURL->generate(), 'title' => $logintitle, 'classes' => $loginclass, 'text' => $logintext);
         $data['user_nav_links'][] = array('href' => $JOINURL->generate(), 'title' => $jointitle, 'classes' => $joinclass, 'text' => $jointext);
     }
     // If the user's postcode is set, then we add a link to Your MP etc.
     if ($THEUSER->postcode_is_set()) {
         $items = array('yourmp');
         if (postcode_is_scottish($THEUSER->postcode())) {
             $items[] = 'yourmsp';
         } elseif (postcode_is_ni($THEUSER->postcode())) {
             $items[] = 'yourmla';
         }
         foreach ($items as $item) {
             $menudata = $DATA->page_metadata($item, 'menu');
             $logintext = $menudata['text'];
             $URL = new \URL($item);
             $data['user_nav_links'][] = array('href' => $URL->generate(), 'title' => '', 'classes' => '', 'text' => $logintext);
         }
     }
     ////////////////////////////////////////////////////////////
     // Search URL
     $SEARCH = new \URL('search');
     $SEARCH->reset();
     $data['search_url'] = $SEARCH->generate();
     ////////////////////////////////////////////////////////////
     // Search URL
     // Footer Links
     $footer = new Renderer\Footer();
     $data['footer_links'] = $footer->data;
     # banner text
     $b = new Model\Banner();
     $data['banner_text'] = $b->get_text();
     # mini survey
     // we never want to display this on the front page or any
     // other survey page we might have
     if (!in_array($this_page, array('survey', 'overview'))) {
         $mini = new MiniSurvey();
         $data['mini_survey'] = $mini->get_values();
     }
     ////////////////////////////////////////////////////////////
     // Unpack the data we've been passed so it's available for use in the templates.
     extract($data);
     ////////////////////////////////////////////////////////////
     // Require the templates and output
     header('Content-Type: text/html; charset=iso-8859-1');
     require_once INCLUDESPATH . 'easyparliament/templates/html/header.php';
     require_once INCLUDESPATH . 'easyparliament/templates/html/' . $template . '.php';
     require_once INCLUDESPATH . 'easyparliament/templates/html/footer.php';
 }
Esempio n. 3
0
            if ($MEMBER->person_id()) {
                // This will cookie the postcode.
                $THEUSER->set_postcode_cookie($pc);
            }
            member_redirect($MEMBER);
        }
    } else {
        $errors['pc'] = "Sorry, " . htmlentities($pc) . " isn't a valid postcode";
        twfy_debug('MP', "Can't display an MP because the submitted postcode wasn't of a valid form.");
    }
    /////////////////////////////////////////////////////////
    // DOES THE USER HAVE A POSTCODE ALREADY SET?
    // (Either in their logged-in details or in a cookie from a previous search.)
} elseif ($this_page == 'msp' && $THEUSER->postcode_is_set() && $name == '' && $cconstituency == '') {
    $this_page = 'yourmsp';
    if (postcode_is_scottish($THEUSER->postcode())) {
        regional_list($THEUSER->postcode(), 'SPC', 'msp');
        exit;
    } else {
        $PAGE->error_message('Your set postcode is not in Scotland.');
    }
} elseif ($this_page == 'mla' && $THEUSER->postcode_is_set() && $name == '' && $cconstituency == '') {
    $this_page = 'yourmla';
    if (postcode_is_ni($THEUSER->postcode())) {
        regional_list($THEUSER->postcode(), 'NIE', 'mla');
        exit;
    } else {
        $PAGE->error_message('Your set postcode is not in Northern Ireland.');
    }
} elseif ($THEUSER->postcode_is_set() && $name == '' && $cconstituency == '') {
    $MEMBER = new MEMBER(array('postcode' => $THEUSER->postcode()));
Esempio n. 4
0
 /**
  * Output Page
  *
  * Assembles a completed page from template and sends it to output.
  *
  * @param string $template The name of the template file to load.
  * @param array  $data     An associative array of data to be made available to the template.
  */
 public static function output($template, $data = array())
 {
     // Include includes.
     // TODO: Wrap these in a class somewhere autoloadable.
     include_once INCLUDESPATH . 'postcode.inc';
     ////////////////////////////////////////////////////////////
     // Find the user's country. Used by header, so a safe bit to do regardless.
     if (preg_match('#^[A-Z]{2}$#i', get_http_var('country'))) {
         $data['country'] = strtoupper(get_http_var('country'));
     } else {
         $data['country'] = Gaze::get_country_by_ip($_SERVER["REMOTE_ADDR"]);
     }
     ////////////////////////////////////////////////////////////
     // Get the page data
     global $DATA, $this_page, $THEUSER;
     ////////////////////////////////////////////////////////////
     // Assemble the page title
     $data['page_title'] = '';
     $sitetitle = $DATA->page_metadata($this_page, "sitetitle");
     $keywords_title = '';
     if ($this_page == 'overview') {
         $data['page_title'] = $sitetitle . ': ' . $DATA->page_metadata($this_page, "title");
     } else {
         if ($page_title = $DATA->page_metadata($this_page, "title")) {
             $data['page_title'] = $page_title;
         }
         // We'll put this in the meta keywords tag.
         $keywords_title = $data['page_title'];
         $parent_page = $DATA->page_metadata($this_page, 'parent');
         if ($parent_title = $DATA->page_metadata($parent_page, 'title')) {
             if ($data['page_title']) {
                 $data['page_title'] .= ': ';
             }
             $data['page_title'] .= $parent_title;
         }
         if ($data['page_title'] == '') {
             $data['page_title'] = $sitetitle;
         } else {
             $data['page_title'] .= ' - ' . $sitetitle;
         }
     }
     ////////////////////////////////////////////////////////////
     // Meta keywords
     if (!($data['meta_keywords'] = $DATA->page_metadata($this_page, "meta_keywords"))) {
         $data['meta_keywords'] = $keywords_title;
         if ($data['meta_keywords']) {
             $data['meta_keywords'] .= ', ';
         }
         $data['meta_keywords'] .= 'Hansard, Official Report, Parliament, government, House of Commons, House of Lords, MP, Peer, Member of Parliament, MPs, Peers, Lords, Commons, Scottish Parliament, Northern Ireland Assembly, MSP, MLA, MSPs, MLAs';
     }
     $data['meta_description'] = '';
     if ($DATA->page_metadata($this_page, "meta_description")) {
         $data['meta_description'] = $DATA->page_metadata($this_page, "meta_description");
     }
     ////////////////////////////////////////////////////////////
     // Header <link>s
     $data['header_links'] = array();
     if ($this_page != 'overview') {
         $URL = new \URL('overview');
         $data['header_links'][] = array('rel' => 'start', 'title' => 'Home', 'href' => $URL->generate());
     }
     ////////////////////////////////////////////////////////////
     // Create the next/prev/up links for navigation.
     // Their data is put in the metadata in hansardlist.php
     $nextprev = $DATA->page_metadata($this_page, "nextprev");
     if ($nextprev) {
         // Four different kinds of back/forth links we might build.
         $links = array("first", "prev", "up", "next", "last");
         foreach ($links as $type) {
             if (isset($nextprev[$type]) && isset($nextprev[$type]['url'])) {
                 if (isset($nextprev[$type]['body'])) {
                     $linktitle = _htmlentities(trim_characters($nextprev[$type]['body'], 0, 40));
                     if (isset($nextprev[$type]['speaker']) && count($nextprev[$type]['speaker']) > 0) {
                         $linktitle = $nextprev[$type]['speaker']['name'] . ': ' . $linktitle;
                     }
                 } elseif (isset($nextprev[$type]['hdate'])) {
                     $linktitle = format_date($nextprev[$type]['hdate'], SHORTDATEFORMAT);
                 }
                 $data['header_links'][] = array('rel' => $type, 'title' => $linktitle, 'href' => $nextprev[$type]['url']);
             }
         }
     }
     ////////////////////////////////////////////////////////////
     // Page RSS URL
     if ($DATA->page_metadata($this_page, 'rss')) {
         // If this page has an RSS feed set.
         $data['page_rss_url'] = 'http://' . DOMAIN . WEBPATH . $DATA->page_metadata($this_page, 'rss');
     }
     ////////////////////////////////////////////////////////////
     // Site Navigation Links
     $data['assembly_nav_links'] = array();
     $data['section_nav_links'] = array();
     // Page names mapping to those in metadata.php.
     // Links in the top menu, and the sublinks we see if
     // we're within that section.
     $nav_items = array(array('home'), array('hansard', 'mps', 'peers', 'alldebatesfront', 'wranswmsfront', 'pbc_front', 'calendar_summary'), array('sp_home', 'spoverview', 'msps', 'spdebatesfront', 'spwransfront'), array('ni_home', 'nioverview', 'mlas'), array('wales_home'));
     // We work out which of the items in the top and bottom menus
     // are highlighted - $top_highlight and $bottom_highlight respectively.
     $parent = $DATA->page_metadata($this_page, 'parent');
     if (!$parent) {
         $top_highlight = $this_page;
         $bottom_highlight = '';
         $selected_top_link = $DATA->page_metadata('hansard', 'menu');
         $url = new \URL('hansard');
         $selected_top_link['link'] = $url->generate();
     } else {
         $parents = array($parent);
         $p = $parent;
         while ($p) {
             $p = $DATA->page_metadata($p, 'parent');
             if ($p) {
                 $parents[] = $p;
             }
         }
         $top_highlight = array_pop($parents);
         if (!$parents) {
             // No grandparent - this page's parent is in the top menu.
             // We're on one of the pages linked to by the bottom menu.
             // So highlight it and its parent.
             $bottom_highlight = $this_page;
         } else {
             // This page is not in either menu. So highlight its parent
             // (in the bottom menu) and its grandparent (in the top).
             $bottom_highlight = array_pop($parents);
         }
         $selected_top_link = $DATA->page_metadata($top_highlight, 'menu');
         if (!$selected_top_link) {
             # Just in case something's gone wrong
             $selected_top_link = $DATA->page_metadata('hansard', 'menu');
         }
         $url = new \URL($top_highlight);
         $selected_top_link['link'] = $url->generate();
     }
     if ($top_highlight == 'hansard') {
         $section = 'uk';
         $selected_top_link['text'] = 'UK';
     } elseif ($top_highlight == 'ni_home') {
         $section = 'ni';
         $selected_top_link['text'] = 'NORTHERN IRELAND';
     } elseif ($top_highlight == 'sp_home') {
         $section = 'scotland';
         $selected_top_link['text'] = 'SCOTLAND';
     } else {
         $section = '';
     }
     $nav_highlights = array('top' => $top_highlight, 'bottom' => $bottom_highlight, 'top_selected' => $selected_top_link, 'section' => $section);
     //get the top and bottom links
     foreach ($nav_items as $bottompages) {
         $toppage = array_shift($bottompages);
         // Generate the links for the top menu.
         // What gets displayed for this page.
         $menudata = $DATA->page_metadata($toppage, 'menu');
         $text = $menudata['text'];
         $title = $menudata['title'];
         if (!$title) {
             continue;
         }
         //get link and description for the menu ans add it to the array
         $class = $toppage == $nav_highlights['top'] ? 'on' : '';
         $URL = new \URL($toppage);
         $top_link = array('href' => $URL->generate(), 'title' => $title, 'classes' => $class, 'text' => $text);
         array_push($data['assembly_nav_links'], $top_link);
         if ($toppage == $nav_highlights['top']) {
             // This top menu link is highlighted, so generate its bottom menu.
             foreach ($bottompages as $bottompage) {
                 $menudata = $DATA->page_metadata($bottompage, 'menu');
                 $text = $menudata['text'];
                 $title = $menudata['title'];
                 // Where we're linking to.
                 $URL = new \URL($bottompage);
                 $class = $bottompage == $nav_highlights['bottom'] ? 'on' : '';
                 $data['section_nav_links'][] = array('href' => $URL->generate(), 'title' => $title, 'classes' => $class, 'text' => $text);
             }
         }
     }
     $data['assembly_nav_current'] = $nav_highlights['top_selected']['text'];
     ////////////////////////////////////////////////////////////
     // User Navigation Links
     $data['user_nav_links'] = array();
     // We may want to send the user back to this current page after they've
     // joined, logged out or logged in. So we put the URL in $returl.
     $URL = new \URL($this_page);
     $returl = $URL->generate('none');
     //user logged in
     if ($THEUSER->isloggedin()) {
         // The 'Edit details' link.
         $menudata = $DATA->page_metadata('userviewself', 'menu');
         $edittext = $menudata['text'];
         $edittitle = $menudata['title'];
         $EDITURL = new \URL('userviewself');
         if ($this_page == 'userviewself' || $this_page == 'useredit' || $top_highlight == 'userviewself') {
             $editclass = 'on';
         } else {
             $editclass = '';
         }
         // The 'Log out' link.
         $menudata = $DATA->page_metadata('userlogout', 'menu');
         $logouttext = $menudata['text'];
         $logouttitle = $menudata['title'];
         $LOGOUTURL = new \URL('userlogout');
         if ($this_page != 'userlogout') {
             $LOGOUTURL->insert(array("ret" => $returl));
             $logoutclass = '';
         } else {
             $logoutclass = 'on';
         }
         $username = $THEUSER->firstname() . ' ' . $THEUSER->lastname();
         $data['user_nav_links'][] = array('href' => $LOGOUTURL->generate(), 'title' => $logouttitle, 'classes' => $logoutclass, 'text' => $logouttext);
         $data['user_nav_links'][] = array('href' => $EDITURL->generate(), 'title' => $edittitle, 'classes' => $editclass, 'text' => $edittext);
         $data['user_nav_links'][] = array('href' => $EDITURL->generate(), 'title' => $edittitle, 'classes' => $editclass, 'text' => _htmlentities($username));
     } else {
         // User not logged in
         // The 'Join' link.
         $menudata = $DATA->page_metadata('userjoin', 'menu');
         $jointext = $menudata['text'];
         $jointitle = $menudata['title'];
         $JOINURL = new \URL('userjoin');
         if ($this_page != 'userjoin') {
             if ($this_page != 'userlogout' && $this_page != 'userlogin') {
                 // We don't do this on the logout page, because then the user
                 // will return straight to the logout page and be logged out
                 // immediately!
                 $JOINURL->insert(array("ret" => $returl));
             }
             $joinclass = '';
         } else {
             $joinclass = 'on';
         }
         // The 'Log in' link.
         $menudata = $DATA->page_metadata('userlogin', 'menu');
         $logintext = $menudata['text'];
         $logintitle = $menudata['title'];
         $LOGINURL = new \URL('userlogin');
         if ($this_page != 'userlogin') {
             if ($this_page != "userlogout" && $this_page != "userpassword" && $this_page != 'userjoin') {
                 // We don't do this on the logout page, because then the user
                 // will return straight to the logout page and be logged out
                 // immediately!
                 // And it's also silly if we're sent back to Change Password.
                 // And the join page.
                 $LOGINURL->insert(array("ret" => $returl));
             }
             $loginclass = '';
         } else {
             $loginclass = 'on';
         }
         $data['user_nav_links'][] = array('href' => $LOGINURL->generate(), 'title' => $logintitle, 'classes' => $loginclass, 'text' => $logintext);
         $data['user_nav_links'][] = array('href' => $JOINURL->generate(), 'title' => $jointitle, 'classes' => $joinclass, 'text' => $jointext);
     }
     // If the user's postcode is set, then we add a link to Your MP etc.
     if ($THEUSER->postcode_is_set()) {
         $items = array('yourmp');
         if (postcode_is_scottish($THEUSER->postcode())) {
             $items[] = 'yourmsp';
         } elseif (postcode_is_ni($THEUSER->postcode())) {
             $items[] = 'yourmla';
         }
         foreach ($items as $item) {
             $menudata = $DATA->page_metadata($item, 'menu');
             $logintext = $menudata['text'];
             $URL = new \URL($item);
             $data['user_nav_links'][] = array('href' => $URL->generate(), 'title' => '', 'classes' => '', 'text' => $logintext);
         }
     }
     ////////////////////////////////////////////////////////////
     // Search URL
     $SEARCH = new \URL('search');
     $SEARCH->reset();
     $data['search_url'] = $SEARCH->generate();
     ////////////////////////////////////////////////////////////
     // Search URL
     // Footer Links
     $data['footer_links']['about'] = self::get_menu_links(array('help', 'about', 'linktous', 'houserules', 'blog', 'news', 'contact', 'privacy'));
     $data['footer_links']['assemblies'] = self::get_menu_links(array('hansard', 'sp_home', 'ni_home', 'wales_home', 'boundaries'));
     $data['footer_links']['international'] = self::get_menu_links(array('newzealand', 'australia', 'ireland', 'mzalendo'));
     $data['footer_links']['tech'] = self::get_menu_links(array('code', 'api', 'data', 'pombola', 'devmailinglist', 'irc'));
     # banner text
     $b = new Model\Banner();
     $data['banner_text'] = $b->get_text();
     # Robots header
     if (DEVSITE) {
         $data['robots'] = 'noindex,nofollow';
     } elseif ($robots = $DATA->page_metadata($this_page, 'robots')) {
         $data['robots'] = $robots;
     }
     ////////////////////////////////////////////////////////////
     // Unpack the data we've been passed so it's available for use in the templates.
     extract($data);
     ////////////////////////////////////////////////////////////
     // Require the templates and output
     header('Content-Type: text/html; charset=iso-8859-1');
     require_once INCLUDESPATH . 'easyparliament/templates/html/header.php';
     require_once INCLUDESPATH . 'easyparliament/templates/html/' . $template . '.php';
     require_once INCLUDESPATH . 'easyparliament/templates/html/footer.php';
 }
Esempio n. 5
0
function get_regional_by_user_postcode($pc, $page)
{
    global $this_page;
    $this_page = "your{$page}";
    if ($page == 'msp' && postcode_is_scottish($pc)) {
        regional_list($pc, 'SPC', $page);
    } elseif ($page == 'mla' && postcode_is_ni($pc)) {
        regional_list($pc, 'NIE', $page);
    } else {
        throw new MySociety\TheyWorkForYou\MemberException('Your set postcode is not in the right region.');
    }
}
Esempio n. 6
0
    public function user_bar($top_highlight = '')
    {
        // Called from menu(), but separated out here for clarity.
        // Does just the bit of the menu related to login/join/etc.
        global $this_page, $DATA, $THEUSER;
        // We may want to send the user back to this current page after they've
        // joined, logged out or logged in. So we put the URL in $returl.
        $URL = new URL($this_page);
        $returl = $URL->generate('none');
        //user logged in
        if ($THEUSER->isloggedin()) {
            // The 'Edit details' link.
            $menudata = $DATA->page_metadata('userviewself', 'menu');
            $edittext = $menudata['text'];
            $edittitle = $menudata['title'];
            $EDITURL = new URL('userviewself');
            if ($this_page == 'userviewself' || $this_page == 'useredit' || $top_highlight == 'userviewself') {
                $editclass = ' class="on"';
            } else {
                $editclass = '';
            }
            // The 'Log out' link.
            $menudata = $DATA->page_metadata('userlogout', 'menu');
            $logouttext = $menudata['text'];
            $logouttitle = $menudata['title'];
            $LOGOUTURL = new URL('userlogout');
            if ($this_page != 'userlogout') {
                $LOGOUTURL->insert(array("ret" => $returl));
                $logoutclass = '';
            } else {
                $logoutclass = ' class="on"';
            }
            $username = $THEUSER->firstname() . ' ' . $THEUSER->lastname();
            ?>

            <ul id="user">
            <li><a href="<?php 
            echo $LOGOUTURL->generate();
            ?>
" title="<?php 
            echo $logouttitle;
            ?>
"<?php 
            echo $logoutclass;
            ?>
><?php 
            echo $logouttext;
            ?>
</a></li>
            <li><a href="<?php 
            echo $EDITURL->generate();
            ?>
" title="<?php 
            echo $edittitle;
            ?>
"<?php 
            echo $editclass;
            ?>
><?php 
            echo $edittext;
            ?>
</a></li>
            <li><a href="<?php 
            echo $EDITURL->generate();
            ?>
" title="<?php 
            echo $edittitle;
            ?>
"<?php 
            echo $editclass;
            ?>
><?php 
            echo _htmlentities($username);
            ?>
</a></li>
<?php 
        } else {
            // User not logged in
            // The 'Join' link.
            $menudata = $DATA->page_metadata('userjoin', 'menu');
            $jointext = $menudata['text'];
            $jointitle = $menudata['title'];
            $JOINURL = new URL('userjoin');
            if ($this_page != 'userjoin') {
                if ($this_page != 'userlogout' && $this_page != 'userlogin') {
                    // We don't do this on the logout page, because then the user
                    // will return straight to the logout page and be logged out
                    // immediately!
                    $JOINURL->insert(array("ret" => $returl));
                }
                $joinclass = '';
            } else {
                $joinclass = ' class="on"';
            }
            // The 'Log in' link.
            $menudata = $DATA->page_metadata('userlogin', 'menu');
            $logintext = $menudata['text'];
            $logintitle = $menudata['title'];
            $LOGINURL = new URL('userlogin');
            if ($this_page != 'userlogin') {
                if ($this_page != "userlogout" && $this_page != "userpassword" && $this_page != 'userjoin') {
                    // We don't do this on the logout page, because then the user
                    // will return straight to the logout page and be logged out
                    // immediately!
                    // And it's also silly if we're sent back to Change Password.
                    // And the join page.
                    $LOGINURL->insert(array("ret" => $returl));
                }
                $loginclass = '';
            } else {
                $loginclass = ' class="on"';
            }
            ?>
            <ul id="user">
            <li><a href="<?php 
            echo $LOGINURL->generate();
            ?>
" title="<?php 
            echo $logintitle;
            ?>
"<?php 
            echo $loginclass;
            ?>
><?php 
            echo $logintext;
            ?>
</a></li>
            <li><a href="<?php 
            echo $JOINURL->generate();
            ?>
" title="<?php 
            echo $jointitle;
            ?>
"<?php 
            echo $joinclass;
            ?>
><?php 
            echo $jointext;
            ?>
</a></li>
<?php 
        }
        // If the user's postcode is set, then we add a link to Your MP etc.
        $divider = true;
        if ($THEUSER->postcode_is_set()) {
            $items = array('yourmp');
            if (postcode_is_scottish($THEUSER->postcode())) {
                $items[] = 'yourmsp';
            } elseif (postcode_is_ni($THEUSER->postcode())) {
                $items[] = 'yourmla';
            }
            foreach ($items as $item) {
                $menudata = $DATA->page_metadata($item, 'menu');
                $logintext = $menudata['text'];
                $logintitle = $menudata['title'];
                $URL = new URL($item);
                if ($divider) {
                    echo '<li class="divider"><a href="' . $URL->generate() . '">' . $logintext . '</a></li>';
                } else {
                    echo '<li><a href="' . $URL->generate() . '">' . $logintext . '</a></li>';
                }
                $divider = false;
            }
        }
        echo '</ul>';
    }
Esempio n. 7
0
function display_search_form($alert, $details = array(), $errors = array())
{
    global $this_page, $PAGE;
    $ACTIONURL = new URL($this_page);
    $ACTIONURL->reset();
    $form_start = '<form action="' . $ACTIONURL->generate() . '" method="post">
<input type="hidden" name="t" value="' . _htmlspecialchars(get_http_var('t')) . '">
<input type="hidden" name="email" value="' . _htmlspecialchars(get_http_var('email')) . '">';
    if (isset($details['members']) && $details['members']->rows() > 0) {
        echo '<ul class="hilites">';
        $q = $details['members'];
        for ($n = 0; $n < $q->rows(); $n++) {
            echo '<li>';
            echo $form_start . '<input type="hidden" name="pid" value="' . $q->field($n, 'person_id') . '">';
            echo 'Things by ';
            $name = member_full_name($q->field($n, 'house'), $q->field($n, 'title'), $q->field($n, 'given_name'), $q->field($n, 'family_name'), $q->field($n, 'lordofname'));
            if ($q->field($n, 'constituency')) {
                echo $name . ' (' . $q->field($n, 'constituency') . ') ';
            } else {
                echo $name;
            }
            echo ' <input type="submit" value="Subscribe"></form>';
            echo "</li>\n";
        }
        echo '</ul>';
    }
    if (isset($details['constituencies'])) {
        echo '<ul class="hilites">';
        foreach ($details['constituencies'] as $constituency) {
            $MEMBER = new MEMBER(array('constituency' => $constituency, 'house' => 1));
            echo "<li>";
            echo $form_start . '<input type="hidden" name="pid" value="' . $MEMBER->person_id() . '">';
            if ($details['valid_postcode']) {
                echo '<input type="hidden" name="pc" value="' . _htmlspecialchars($details['alertsearch']) . '">';
            }
            echo $MEMBER->full_name();
            echo ' (' . _htmlspecialchars($constituency) . ')';
            echo ' <input type="submit" value="Subscribe"></form>';
            echo "</li>";
        }
        echo '</ul>';
    }
    if ($details['alertsearch']) {
        echo '<ul class="hilites"><li>';
        echo $form_start . '<input type="hidden" name="keyword" value="' . _htmlspecialchars($details['alertsearch']) . '">';
        echo 'Mentions of [';
        $alertsearch = $details['alertsearch'];
        if (preg_match('#speaker:(\\d+)#', $alertsearch, $m)) {
            $MEMBER = new MEMBER(array('person_id' => $m[1]));
            $alertsearch = str_replace("speaker:{$m['1']}", "speaker:" . $MEMBER->full_name(), $alertsearch);
        }
        echo _htmlspecialchars($alertsearch) . '] ';
        echo ' <input type="submit" value="Subscribe"></form>';
        # Use original alertsearch variable here, because name replacement might introduce a comma
        if (strstr($details['alertsearch'], ',') > -1) {
            echo '<em class="error">You have used a comma in your search term &ndash; are you sure this is what you want?
You cannot sign up to multiple search terms using a comma &ndash; either use OR, or fill in this form multiple times.</em>';
        }
        if (preg_match('#([A-Z]{1,2}\\d+[A-Z]? ?\\d[A-Z]{2})#i', $alertsearch, $m) && strlen($alertsearch) > strlen($m[1]) && validate_postcode($m[1])) {
            $scottish_text = '';
            $mp_display_text = '';
            if (postcode_is_scottish($m[1])) {
                $mp_display_text = 'your MP, ';
                $scottish_text = ' or MSP';
            }
            echo '<em class="error">You have used a postcode and something else in your search term &ndash; are you sure this is what you want?
                  You will only get an alert if all of these are mentioned in the same debate. Did you mean to get alerts for when your MP' . $scottish_text . ' mentions something instead? If so click subscribe below.</em></li>';
            try {
                $MEMBER = new MEMBER(array('postcode' => $m[1]));
                // move the postcode to the front just to be tidy
                $tidy_alertsearch = $m[1] . " " . trim(str_replace("{$m['1']}", "", $alertsearch));
                $alertsearch_display = str_replace("{$m['1']} ", "", $tidy_alertsearch);
                $alertsearch = str_replace("{$m['1']}", "speaker:" . $MEMBER->person_id, $tidy_alertsearch);
                echo "<li>";
                echo $form_start . '<input type="hidden" name="keyword" value="' . _htmlspecialchars($alertsearch) . '">';
                echo 'Mentions of [';
                echo _htmlspecialchars($alertsearch_display) . '] by ' . $mp_display_text . $MEMBER->full_name();
                echo ' <input type="submit" value="Subscribe"></form>';
                if ($scottish_text) {
                    $constituencies = postcode_to_constituencies($m[1]);
                    if (isset($constituencies['SPC'])) {
                        $MEMBER = new MEMBER(array('constituency' => $constituencies['SPC'], 'house' => 4));
                        // move the postcode to the front just to be tidy
                        $alertsearch = str_replace("{$m['1']}", "speaker:" . $MEMBER->person_id, $tidy_alertsearch);
                        echo "</li><li>";
                        echo $form_start . '<input type="hidden" name="keyword" value="' . _htmlspecialchars($alertsearch) . '">';
                        echo 'Mentions of [';
                        echo _htmlspecialchars($alertsearch_display) . '] by your MSP, ' . $MEMBER->full_name();
                        echo ' <input type="submit" value="Subscribe"></form>';
                    }
                }
            } catch (MySociety\TheyWorkForYou\MemberException $e) {
                echo '<p>We had a problem looking up your representative.</p>';
            }
        }
        echo "</li></ul>";
    }
    if ($details['pid']) {
        $MEMBER = new MEMBER(array('person_id' => $details['pid']));
        echo '<ul class="hilites"><li>';
        echo "Signing up for things by " . $MEMBER->full_name();
        echo ' (' . _htmlspecialchars($MEMBER->constituency()) . ')';
        echo "</li></ul>";
    }
    if ($details['keyword']) {
        echo '<ul class="hilites"><li>';
        echo 'Signing up for results from a search for [';
        $alertsearch = $details['keyword'];
        if (preg_match('#speaker:(\\d+)#', $alertsearch, $m)) {
            $MEMBER = new MEMBER(array('person_id' => $m[1]));
            $alertsearch = str_replace("speaker:{$m['1']}", "speaker:" . $MEMBER->full_name(), $alertsearch);
        }
        echo _htmlspecialchars($alertsearch) . ']';
        echo "</li></ul>";
    }
    if (!$details['pid'] && !$details['keyword']) {
        ?>

<p><label for="alertsearch">To sign up to an email alert, enter either your
<strong>postcode</strong>, the <strong>name</strong> of who you're interested
in, or the <strong>search term</strong> you wish to receive alerts
for.</label> To be alerted on an exact <strong>phrase</strong>, be sure to put it in quotes.
Also use quotes around a word to avoid stemming (where &lsquo;horse&rsquo; would
also match &lsquo;horses&rsquo;).

<?php 
    }
    echo '<form action="' . $ACTIONURL->generate() . '" method="post">
<input type="hidden" name="t" value="' . _htmlspecialchars(get_http_var('t')) . '">
<input type="hidden" name="submitted" value="1">';
    if (!$details['pid'] && !$details['keyword'] || isset($errors['alertsearch'])) {
        if (isset($errors["alertsearch"])) {
            $PAGE->error_message($errors["alertsearch"]);
        }
        $text = $details['alertsearch'];
        if (!$text) {
            $text = $details['keyword'];
        }
        ?>

<div class="row">
<input type="text" name="alertsearch" id="alertsearch" value="<?php 
        if ($text) {
            echo _htmlentities($text);
        }
        ?>
" maxlength="255" size="30" style="font-size:150%">
</div>

<?php 
    }
    if ($details['pid']) {
        echo '<input type="hidden" name="pid" value="' . _htmlspecialchars($details['pid']) . '">';
    }
    if ($details['keyword']) {
        echo '<input type="hidden" name="keyword" value="' . _htmlspecialchars($details['keyword']) . '">';
    }
    if (!$details['email_verified']) {
        if (isset($errors["email"]) && $details['submitted']) {
            $PAGE->error_message($errors["email"]);
        }
        ?>
        <div class="row">
            <label for="email">Your email address:</label>
            <input type="text" name="email" id="email" value="<?php 
        if (isset($details["email"])) {
            echo _htmlentities($details["email"]);
        }
        ?>
" maxlength="255" size="30" class="form">
        </div>
<?php 
    }
    ?>

    <div class="row">
        <input type="submit" class="submit" value="<?php 
    echo $details['pid'] || $details['keyword'] ? 'Subscribe' : 'Search';
    ?>
">
    </div>

    <div class="row">
<?php 
    if (!$details['email_verified']) {
        ?>
        <p>If you <a href="/user/?pg=join">join</a> or <a href="/user/login/?ret=%2Falert%2F">sign in</a>, you won't need to confirm your email
        address for every alert you set.<br><br>
<?php 
    }
    if (!$details['pid'] && !$details['keyword']) {
        ?>
        <p>Please note that you should only enter <strong>one term per alert</strong> &ndash; if
        you wish to receive alerts on more than one thing, or for more than
        one person, simply fill in this form as many times as you need, or use boolean OR.<br><br></p>
        <p>For example, if you wish to receive alerts whenever the words
        <i>horse</i> or <i>pony</i> are mentioned in Parliament, please fill in
        this form once with the word <i>horse</i> and then again with the word
        <i>pony</i> (or you can put <i>horse OR pony</i> with the OR in capitals
        as explained on the right). Do not put <i>horse, pony</i> as that will only
        sign you up for alerts where <strong>both</strong> horse and pony are mentioned.</p>
<?php 
    }
    ?>
    </div>
<?php 
    if (get_http_var('sign')) {
        echo '<input type="hidden" name="sign" value="' . _htmlspecialchars(get_http_var('sign')) . '">';
    }
    if (get_http_var('site')) {
        echo '<input type="hidden" name="site" value="' . _htmlspecialchars(get_http_var('site')) . '">';
    }
    echo '</form>';
}