function OnPreRender()
 {
     /* @var $o_season Season */
     /* @var $o_team Team */
     $this->SetCaption($this->o_competition->GetName());
     $o_headings = new XhtmlRow(array('Name of team', 'Ground address', 'Contact details'));
     $o_headings->SetIsHeader(true);
     $this->AddRow($o_headings);
     foreach ($this->o_competition->GetLatestSeason()->GetTeams() as $o_team) {
         if ($o_team instanceof Team) {
             $o_row = new XhtmlRow();
             $o_row->AddCell(new XhtmlAnchor(Html::Encode($o_team->GetName()), $o_team->GetEditTeamUrl()));
             $o_row->AddCell(new PostalAddressControl($o_team->GetGround()->GetAddress()));
             $private = $o_team->GetPrivateContact();
             $public = $o_team->GetContact();
             $private_header = '<h2 style="margin:0; font-size:1.1em; color: #900;">Private</h2>';
             if ($private and $public) {
                 $contact = $public . $private_header . $private;
             } else {
                 $contact = $private ? $private_header . $private : $public;
             }
             $o_row->AddCell(nl2br(XhtmlMarkup::ApplySimpleTags(XhtmlMarkup::ApplyLinks($contact, true))));
             $this->AddRow($o_row);
         }
     }
     parent::OnPreRender();
 }
 /**
  * Gets text to use as the description of this competition in search results
  */
 public function GetSearchDescription()
 {
     $description = "A stoolball competition";
     $season = $this->competition->GetLatestSeason();
     $teams = $season->GetTeams();
     $teams_count = count($teams);
     if ($teams_count) {
         $description .= " played by ";
         if ($teams_count > 10) {
             $description .= "teams including ";
             $teams_count = 10;
         }
         for ($i = 0; $i < $teams_count; $i++) {
             $description .= $teams[$i]->GetName();
             if ($i < $teams_count - 2) {
                 $description .= ", ";
             }
             if ($i == $teams_count - 2) {
                 $description .= " and ";
             }
         }
     } else {
         if ($this->competition->GetIntro()) {
             $description = trim($this->competition->GetIntro());
             $description = XhtmlMarkup::ApplyLinks($description, true);
             $description = XhtmlMarkup::ApplyLists($description, true);
             $description = XhtmlMarkup::ApplySimpleTags($description, true);
             $break = strpos($description, "\n");
             if ($break !== false and $break > 0) {
                 $description = substr($description, 0, $break - 1);
             }
         }
     }
     $description .= ".";
     return $description;
 }
 function OnPageLoad()
 {
     echo '<div class="ground vcard" typeof="schema:Place" about="' . $this->ground->GetLinkedDataUri() . '">';
     $o_fn = new XhtmlElement('h1', htmlentities($this->ground->GetNameAndTown(), ENT_QUOTES, "UTF-8", false));
     $o_fn->SetCssClass('fn');
     $o_fn->AddAttribute("property", "schema:name");
     echo $o_fn;
     require_once 'xhtml/navigation/tabs.class.php';
     $tabs = array('Summary' => '', 'Statistics' => $this->ground->GetStatsNavigateUrl());
     echo new Tabs($tabs);
     ?>
     <div class="box tab-box">
         <div class="dataFilter"></div>
         <div class="box-content">
     <?php 
     $address = new XhtmlElement("div");
     $address->AddAttribute("rel", "schema:address");
     $address->AddAttribute("resource", $this->ground->GetLinkedDataUri() . "#PostalAddress");
     $postal = new PostalAddressControl($this->ground->GetAddress());
     $postal->AddAttribute("about", $this->ground->GetLinkedDataUri() . "#PostalAddress");
     $address->AddControl($postal);
     echo $address;
     # Show teams based at this ground
     if ($this->ground->Teams()->GetCount()) {
         require_once "stoolball/team-list-control.class.php";
         echo "<h2>Teams based at this ground</h2>" . new TeamListControl($this->ground->Teams()->GetItems());
     }
     if (!is_null($this->ground->GetAddress()->GetLatitude()) and !is_null($this->ground->GetAddress()->GetLongitude())) {
         $o_geo = new XhtmlElement('div');
         $o_geo->SetXhtmlId('geoGround');
         $o_geo->AddAttribute("rel", "schema:geo");
         $o_geo->AddAttribute("resource", $this->ground->GetLinkedDataUri() . "#geo");
         $o_latlong = new XhtmlElement('p');
         $o_latlong->SetCssClass('geo');
         # geo microformat
         $o_latlong->AddAttribute("about", $this->ground->GetLinkedDataUri() . "#geo");
         $o_latlong->AddAttribute("typeof", "schema:GeoCoordinates");
         $o_latlong->AddControl('Latitude ');
         $o_lat = new XhtmlElement('span', (string) $this->ground->GetAddress()->GetLatitude());
         $o_lat->SetCssClass('latitude');
         # geo microformat
         $o_lat->AddAttribute("property", "schema:latitude");
         $o_latlong->AddControl($o_lat);
         $o_latlong->AddControl('; longitude ');
         $o_long = new XhtmlElement('span', (string) $this->ground->GetAddress()->GetLongitude());
         $o_long->SetCssClass('longitude');
         # geo microformat
         $o_long->AddAttribute("property", "schema:longitude");
         $o_latlong->AddControl($o_long);
         $o_geo->AddControl($o_latlong);
         $s_place = '';
         $s_class = '';
         switch ($this->ground->GetAddress()->GetGeoPrecision()) {
             case GeoPrecision::Exact():
                 $s_place = $this->ground->GetNameAndTown();
                 $s_class = 'exact';
                 break;
             case GeoPrecision::Postcode():
                 $s_place = $this->ground->GetAddress()->GetPostcode();
                 $s_class = 'postcode';
                 break;
             case GeoPrecision::StreetDescriptor():
                 $s_place = $this->ground->GetAddress()->GetStreetDescriptor() . ', ' . $this->ground->GetAddress()->GetTown();
                 $s_class = 'street';
                 break;
             case GeoPrecision::Town():
                 $s_place = $this->ground->GetAddress()->GetTown();
                 $s_class = 'town';
                 break;
         }
         $o_map_link = new XhtmlAnchor('Map of <span class="' . $s_class . '">' . htmlentities($s_place, ENT_QUOTES, "UTF-8", false) . '</span> on Google Maps', 'http://maps.google.co.uk/?z=16&amp;q=' . urlencode($this->ground->GetNameAndTown()) . '@' . $this->ground->GetAddress()->GetLatitude() . ',' . $this->ground->GetAddress()->GetLongitude() . '&amp;ll=' . $this->ground->GetAddress()->GetLatitude() . ',' . $this->ground->GetAddress()->GetLongitude());
         $o_map = new XhtmlElement('div', $o_map_link);
         $o_geo->AddControl($o_map);
         echo $o_geo;
     }
     if ($this->ground->GetDirections()) {
         echo new XhtmlElement('h2', 'Directions');
         $s_directions = htmlentities($this->ground->GetDirections(), ENT_QUOTES, "UTF-8", false);
         $s_directions = XhtmlMarkup::ApplyCharacterEntities($s_directions);
         $s_directions = XhtmlMarkup::ApplyParagraphs($s_directions);
         $s_directions = XhtmlMarkup::ApplySimpleTags($s_directions);
         echo $s_directions;
     }
     if ($this->ground->GetParking()) {
         echo new XhtmlElement('h2', 'Parking');
         $s_parking = htmlentities($this->ground->GetParking(), ENT_QUOTES, "UTF-8", false);
         $s_parking = XhtmlMarkup::ApplyCharacterEntities($s_parking);
         $s_parking = XhtmlMarkup::ApplyParagraphs($s_parking);
         $s_parking = XhtmlMarkup::ApplySimpleTags($s_parking);
         $s_parking = XhtmlMarkup::ApplyLinks($s_parking);
         echo $s_parking;
     }
     if ($this->ground->GetFacilities()) {
         echo new XhtmlElement('h2', 'Facilities');
         $s_facilities = htmlentities($this->ground->GetFacilities(), ENT_QUOTES, "UTF-8", false);
         $s_facilities = XhtmlMarkup::ApplyCharacterEntities($s_facilities);
         $s_facilities = XhtmlMarkup::ApplyParagraphs($s_facilities);
         $s_facilities = XhtmlMarkup::ApplySimpleTags($s_facilities);
         $s_facilities = XhtmlMarkup::ApplyLinks($s_facilities);
         echo $s_facilities;
     }
     $o_meta = new XhtmlElement('p');
     $o_meta->SetCssClass('metadata');
     $o_meta->AddControl('Status: ');
     $o_uid = new XhtmlElement('span', $this->ground->GetLinkedDataUri());
     $o_uid->SetCssClass('uid');
     $o_meta->AddControl($o_uid);
     $o_meta->AddControl(' last updated at ');
     $o_rev = new XhtmlElement('abbr', Date::BritishDateAndTime($this->ground->GetDateUpdated()));
     $o_rev->SetTitle(Date::Microformat($this->ground->GetDateUpdated()));
     $o_rev->SetCssClass('rev');
     $o_meta->AddControl($o_rev);
     $o_meta->AddControl(', sort as ');
     $o_url = new XhtmlAnchor(htmlentities($this->ground->GetAddress()->GenerateSortName(), ENT_QUOTES, "UTF-8", false), $this->ground->GetNavigateUrl());
     $o_url->SetCssClass('url sort-string');
     $o_meta->AddControl($o_url);
     echo $o_meta;
     echo "</div>";
     ?>
     </div>
     </div>
     <?php 
     $this->AddSeparator();
     $o_user = new UserEditPanel($this->GetSettings(), 'this ground');
     $o_user->AddCssClass("with-tabs");
     if (AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_GROUNDS)) {
         $o_user->AddLink("edit this ground", $this->ground->GetEditGroundUrl());
         $o_user->AddLink("delete this ground", $this->ground->GetDeleteGroundUrl());
     }
     echo $o_user;
     # Show top players
     if ($this->has_player_stats) {
         require_once 'stoolball/statistics-highlight-table.class.php';
         echo new StatisticsHighlightTable($this->best_batting, $this->most_runs, $this->best_bowling, $this->most_wickets, $this->most_catches, "All seasons");
     }
 }
   function OnPageLoad()
   {
       require_once 'xhtml/navigation/tabs.class.php';
       require_once 'stoolball/season-list-control.class.php';
       /* @var $season Season */
       $season = $this->competition->GetWorkingSeason();
       echo new XhtmlElement('h1', Html::Encode($this->GetPageTitle()));
       $tabs = array('Summary' => $season->GetNavigateUrl());
       $tabs['Table'] = '';
       if (count($season->GetTeams())) {
           $tabs['Map'] = $season->GetMapUrl();
       }
       $tabs['Statistics'] = $season->GetStatisticsUrl();
       echo new Tabs($tabs);
       ?>
       <div class="box tab-box">
           <div class="dataFilter"></div>
           <div class="box-content">
 
       <?php 
       # Add matches
       $a_matches = $season->GetMatches();
       # Add teams
       $a_teams = $season->GetTeams();
       $no_content = true;
       if (count($a_teams) > 0) {
           # Check whether there's at least one league match to show a league table for
           $has_league_match = 0;
           foreach ($a_matches as $match) {
               /* @var $match Match */
               if ($match->GetMatchType() == MatchType::LEAGUE) {
                   $has_league_match = true;
                   break;
               }
           }
           if ($season->GetShowTable() and $has_league_match) {
               require_once 'stoolball/season-table.class.php';
               echo new SeasonTable($this->GetSettings(), $season);
               $no_content = false;
           }
       }
       # Add results
       if ($season->GetResults()) {
           $s_results = htmlentities($season->GetResults(), ENT_QUOTES, "UTF-8", false);
           $s_results = XhtmlMarkup::ApplyCharacterEntities($s_results);
           $s_results = XhtmlMarkup::ApplyParagraphs($s_results);
           $s_results = XhtmlMarkup::ApplyLinks($s_results);
           $s_results = XhtmlMarkup::ApplyLists($s_results);
           $s_results = XhtmlMarkup::ApplySimpleTags($s_results);
           $s_results = XhtmlMarkup::ApplyTables($s_results);
           echo $s_results;
           $no_content = false;
       }
       if ($no_content) {
           ?>
           <img class="screenshot" src="/images/features/league-table.png" alt="Example league table" width="308" />
           <p>There's no league table for this season yet.</p>
           <p>You can have your league table updated automatically by adding your matches
               and results to this website. Find out about <a href="/play/manage/website/league-tables/">league tables &#8211; how they work</a>.</p>
           <?php 
       }
       # Check for other seasons. Check is >2 becuase current season is there twice - added above
       if (count($this->competition->GetSeasons()) > 2) {
           require_once "stoolball/season-list-control.class.php";
           echo new XhtmlElement('h2', 'Other seasons in the ' . htmlentities($this->competition->GetName(), ENT_QUOTES, "UTF-8", false), "screen");
           $season_list = new SeasonListControl($this->competition->GetSeasons());
           $season_list->SetExcludedSeasons(array($this->season));
           $season_list->AddCssClass("screen");
           $season_list->SetUrlMethod('GetTableUrl');
           echo $season_list;
       }
       ?>
       </div>
       </div>
       <?php 
       $this->ShowSocial();
   }
    function OnPageLoad()
    {
        require_once 'xhtml/navigation/tabs.class.php';
        require_once 'stoolball/match-list-control.class.php';
        require_once 'stoolball/season-list-control.class.php';
        /* @var $season Season */
        $season = $this->competition->GetWorkingSeason();
        echo new XhtmlElement('h1', Html::Encode($this->season->GetCompetitionName()));
        $tabs = array('Summary' => '');
        if ($season->MatchTypes()->Contains(MatchType::LEAGUE)) {
            $tabs['Table'] = $season->GetTableUrl();
        }
        if (count($season->GetTeams())) {
            $tabs['Map'] = $season->GetMapUrl();
        }
        $tabs['Statistics'] = $season->GetStatisticsUrl();
        echo new Tabs($tabs);
        ?>

        <div class="box tab-box">
            <div class="dataFilter"></div>
            <div class="box-content">
  
        <?php 
        # Add intro
        if ($this->competition->GetIntro()) {
            $intro = htmlentities($this->competition->GetIntro(), ENT_QUOTES, "UTF-8", false);
            $intro = XhtmlMarkup::ApplyParagraphs($intro);
            $intro = XhtmlMarkup::ApplyLists($intro);
            $intro = XhtmlMarkup::ApplySimpleXhtmlTags($intro, false);
            $intro = XhtmlMarkup::ApplyLinks($intro);
            echo $intro;
        }
        # Add season intro
        if ($season->GetIntro()) {
            $intro = htmlentities($season->GetIntro(), ENT_QUOTES, "UTF-8", false);
            $intro = XhtmlMarkup::ApplyCharacterEntities($intro);
            $intro = XhtmlMarkup::ApplyParagraphs($intro);
            $intro = XhtmlMarkup::ApplyLinks($intro);
            $intro = XhtmlMarkup::ApplyLists($intro);
            $intro = XhtmlMarkup::ApplySimpleTags($intro);
            $intro = XhtmlMarkup::ApplyTables($intro);
            echo $intro;
        }
        # Add not active, if relevant
        if (!$this->competition->GetIsActive()) {
            echo new XhtmlElement('p', new XhtmlElement('strong', 'This competition isn\'t played any more.'));
        }
        # Add matches
        $a_matches = $season->GetMatches();
        $i_matches = count($a_matches);
        if ($i_matches > 0) {
            echo new XhtmlElement('h2', 'Matches in ' . htmlentities($season->GetName(), ENT_QUOTES, "UTF-8", false) . ' season');
            $o_matches = new MatchListControl($a_matches);
            if ($season->MatchTypes()->Contains(MatchType::LEAGUE)) {
                $o_matches->SetMatchTypesToLabel(array(MatchType::FRIENDLY, MatchType::CUP, MatchType::PRACTICE));
            } else {
                if ($season->MatchTypes()->Contains(MatchType::CUP)) {
                    $o_matches->SetMatchTypesToLabel(array(MatchType::FRIENDLY, MatchType::PRACTICE));
                } else {
                    $o_matches->SetMatchTypesToLabel(array(MatchType::PRACTICE));
                }
            }
            echo $o_matches;
        }
        # Add teams
        $a_teams = $season->GetTeams();
        if (count($a_teams) > 0) {
            require_once 'stoolball/team-list-control.class.php';
            echo new XhtmlElement('h2', 'Teams playing in ' . htmlentities($season->GetName(), ENT_QUOTES, "UTF-8", false) . ' season');
            echo new TeamListControl($a_teams);
        }
        # Add results
        if ($season->GetResults()) {
            $s_results = htmlentities($season->GetResults(), ENT_QUOTES, "UTF-8", false);
            $s_results = XhtmlMarkup::ApplyCharacterEntities($s_results);
            $s_results = XhtmlMarkup::ApplyParagraphs($s_results);
            $s_results = XhtmlMarkup::ApplyLinks($s_results);
            $s_results = XhtmlMarkup::ApplyLists($s_results);
            $s_results = XhtmlMarkup::ApplySimpleTags($s_results);
            $s_results = XhtmlMarkup::ApplyTables($s_results);
            echo $s_results;
        }
        # Add contact details
        $s_contact = $this->competition->GetContact();
        $s_website = $this->competition->GetWebsiteUrl();
        if ($s_contact or $s_website) {
            echo new XhtmlElement('h2', 'Contact details');
        }
        if ($s_contact) {
            $s_contact = htmlentities($s_contact, ENT_QUOTES, "UTF-8", false);
            $s_contact = XhtmlMarkup::ApplyCharacterEntities($s_contact);
            require_once 'email/email-address-protector.class.php';
            $protector = new EmailAddressProtector($this->GetSettings());
            $s_contact = $protector->ApplyEmailProtection($s_contact, AuthenticationManager::GetUser()->IsSignedIn());
            $s_contact = XhtmlMarkup::ApplyParagraphs($s_contact);
            $s_contact = XhtmlMarkup::ApplyLists($s_contact);
            $s_contact = XhtmlMarkup::ApplySimpleXhtmlTags($s_contact, false);
            $s_contact = XhtmlMarkup::ApplyLinks($s_contact);
            echo $s_contact;
        }
        if ($s_website) {
            echo new XhtmlAnchor("Visit the " . htmlentities($this->competition->GetName(), ENT_QUOTES, "UTF-8", false) . ' website', $s_website);
        }
        # Check for other seasons. Check is >2 becuase current season is there twice - added above
        if (count($this->competition->GetSeasons()) > 2) {
            require_once "stoolball/season-list-control.class.php";
            echo new XhtmlElement('h2', 'Other seasons in the ' . htmlentities($this->competition->GetName(), ENT_QUOTES, "UTF-8", false), "screen");
            $season_list = new SeasonListControl($this->competition->GetSeasons());
            $season_list->SetExcludedSeasons(array($this->season));
            $season_list->AddCssClass("screen");
            echo $season_list;
        }
        ?>
        </div>
        </div>
        <?php 
        $this->ShowSocial();
        $this->AddSeparator();
        # Panel for updates
        $you_can = new UserEditPanel($this->GetSettings(), 'this season');
        $you_can->AddCssClass("with-tabs");
        if (AuthenticationManager::GetUser()->Permissions()->HasPermission(PermissionType::MANAGE_COMPETITIONS)) {
            $you_can->AddLink('edit this competition', $this->competition->GetEditCompetitionUrl());
            $you_can->AddLink('delete this competition', $this->competition->GetDeleteCompetitionUrl());
            $you_can->AddLink('edit this season', $this->season->GetEditSeasonUrl());
            # Only offer delete option if there's more than one season. Don't want to delete last season because
            # that leaves an empty competition which won't display. Instead, must delete whole competition with its one remaining season.
            if (count($this->competition->GetSeasons()) > 1) {
                $you_can->AddLink('delete this season', $this->season->GetDeleteSeasonUrl());
            }
        }
        foreach ($this->season->MatchTypes() as $i_type) {
            if ($i_type != MatchType::PRACTICE and $i_type != MatchType::TOURNAMENT_MATCH) {
                $you_can->AddLink('add a ' . MatchType::Text($i_type), $this->season->GetNewMatchNavigateUrl($i_type));
            }
        }
        if (count($this->season->GetMatches())) {
            # Make sure there's at least one match which is not a tournament or a practice
            foreach ($this->season->GetMatches() as $o_match) {
                /* @var $o_match Match */
                if ($o_match->GetMatchType() == MatchType::PRACTICE or $o_match->GetMatchType() == MatchType::TOURNAMENT or $o_match->GetMatchType() == MatchType::TOURNAMENT_MATCH) {
                    continue;
                } else {
                    $you_can->AddLink('update results', $this->season->GetResultsNavigateUrl());
                    break;
                }
            }
            $you_can->AddLink('add matches to your calendar', $this->season->GetCalendarNavigateUrl());
        }
        echo $you_can;
        if ($this->has_player_stats) {
            require_once 'stoolball/statistics-highlight-table.class.php';
            echo new StatisticsHighlightTable($this->best_batting, $this->most_runs, $this->best_bowling, $this->most_wickets, $this->most_catches, $this->season->GetName() . " season");
        }
    }
 function GetExcerpt()
 {
     # get an excerpt of the message -- strip formatting tags
     $s_text = "";
     if ($this->GetFilteredBody()) {
         $s_text = XhtmlMarkup::ApplyCharacterEntities($this->GetFilteredBody());
         $s_text = XhtmlMarkup::ApplyLinks($s_text, true);
         $s_text = XhtmlMarkup::ApplyLists($s_text, true);
         $s_text = XhtmlMarkup::ApplySimpleTags($s_text, true);
         $s_text = XhtmlMarkup::ApplySimpleXhtmlTags($s_text, true);
         $s_text = XhtmlMarkup::CloseUnmatchedTags($s_text, true);
         $s_text = str_replace("\n", '', $s_text);
         # collapse new lines
         if (strlen($s_text) > 200) {
             $s_text = substr($s_text, 0, 200);
             $pos = strrpos($s_text, " ");
             if ($pos > 0) {
                 $s_text = substr($s_text, 0, $pos);
             }
             # cut off any half-words
             $s_text .= '...';
             # plain text - don't use real ellipsis
         }
         $s_text = strip_tags(html_entity_decode($s_text, ENT_QUOTES));
         # plain text
     }
     return $s_text;
 }
 function OnPreRender()
 {
     /* @var $match Match */
     /* @var $o_home Team */
     /* @var $o_away Team */
     $match = $this->match;
     $player_type = PlayerType::Text($match->GetPlayerType());
     # Show time and place
     $date = new XhtmlElement('p', 'When: ' . $match->GetStartTimeFormatted());
     $date->AddAttribute("property", "schema:startDate");
     $date->AddAttribute("datatype", "xsd:date");
     $date->AddAttribute("content", Date::Microformat($match->GetStartTime()));
     $this->AddControl($date);
     # If we know the time and place, show when the sun sets
     # TODO: assumes UK
     if ($match->GetGround() instanceof Ground and $match->GetGround()->GetAddress()->GetLatitude() and $match->GetGround()->GetAddress()->GetLongitude()) {
         $date->AddControl(' <span class="sunset">sunset ' . Date::Time(date_sunset($match->GetStartTime(), SUNFUNCS_RET_TIMESTAMP, $match->GetGround()->GetAddress()->GetLatitude(), $match->GetGround()->GetAddress()->GetLongitude())) . '</span>');
     }
     $ground = $match->GetGround();
     if (is_object($ground)) {
         $ground_link = new XhtmlElement('a', $ground->GetNameAndTown());
         $ground_link->AddAttribute('href', $ground->GetNavigateUrl());
         $ground_link->SetCssClass('location');
         # hCalendar
         $ground_link->AddAttribute("typeof", "schema:Place");
         $ground_link->AddAttribute("about", $ground->GetLinkedDataUri());
         $ground_link->AddAttribute("rel", "schema:url");
         $ground_link->AddAttribute("property", "schema:name");
         $ground_control = new XhtmlElement('p', 'Where: ');
         $ground_control->AddAttribute("rel", "schema:location");
         $ground_control->AddControl($ground_link);
         $this->AddControl($ground_control);
     }
     # Format
     if ($match->GetIsOversKnown()) {
         $this->AddControl(new XhtmlElement("p", "Matches are " . $match->GetOvers() . " overs."));
     }
     # Add teams
     $a_teams = $match->GetAwayTeams();
     if (!is_array($a_teams)) {
         $a_teams = array();
     }
     if (!is_null($match->GetHomeTeam())) {
         array_unshift($a_teams, $match->GetHomeTeam());
     }
     # shouldn't be home teams any more, but doesn't hurt!
     $how_many_teams = count($a_teams);
     $qualification = $match->GetQualificationType();
     if ($qualification === MatchQualification::OPEN_TOURNAMENT) {
         $qualification = "Any " . strtolower($player_type) . " team may enter this tournament. ";
     } else {
         if ($qualification === MatchQualification::CLOSED_TOURNAMENT) {
             $qualification = "Only invited or qualifying teams may enter this tournament. ";
         } else {
             $qualification = "";
         }
     }
     $show_spaces_left = ($match->GetMaximumTeamsInTournament() and gmdate('U') < $match->GetStartTime() and $match->GetQualificationType() !== MatchQualification::CLOSED_TOURNAMENT);
     if ($match->GetIsMaximumPlayersPerTeamKnown() or $show_spaces_left or $how_many_teams or $qualification) {
         $this->AddControl(new XhtmlElement('h2', 'Teams'));
     }
     $who_can_play = "";
     if ($match->GetIsMaximumPlayersPerTeamKnown()) {
         $who_can_play = Html::Encode($match->GetMaximumPlayersPerTeam() . " players per team. ");
     }
     $who_can_play .= Html::Encode($qualification);
     if ($show_spaces_left) {
         $who_can_play .= '<strong class="spaces-left">' . $match->GetSpacesLeftInTournament() . " spaces left.</strong>";
     }
     if ($who_can_play) {
         $this->AddControl("<p>" . trim($who_can_play) . "</p>");
     }
     if ($how_many_teams) {
         $teams = new TeamListControl($a_teams);
         $this->AddControl('<div rel="schema:performers">' . $teams . '</div>');
     }
     # Add matches
     $a_matches = $match->GetMatchesInTournament();
     if (is_array($a_matches) && count($a_matches)) {
         $o_hmatches = new XhtmlElement('h2', 'Matches');
         $matches = new MatchListControl($a_matches);
         $matches->AddAttribute("rel", "schema:subEvents");
         $this->AddControl($o_hmatches);
         $this->AddControl($matches);
     }
     # Add notes
     if ($match->GetNotes() or $match->Seasons()->GetCount() > 0) {
         $this->AddControl(new XhtmlElement('h2', 'Notes'));
     }
     if ($match->GetNotes()) {
         $s_notes = XhtmlMarkup::ApplyCharacterEntities($match->GetNotes());
         require_once 'email/email-address-protector.class.php';
         $protector = new EmailAddressProtector($this->settings);
         $s_notes = $protector->ApplyEmailProtection($s_notes, AuthenticationManager::GetUser()->IsSignedIn());
         $s_notes = XhtmlMarkup::ApplyHeadings($s_notes);
         $s_notes = XhtmlMarkup::ApplyParagraphs($s_notes);
         $s_notes = XhtmlMarkup::ApplyLists($s_notes);
         $s_notes = XhtmlMarkup::ApplySimpleTags($s_notes);
         $s_notes = XhtmlMarkup::ApplyLinks($s_notes);
         if (strpos($s_notes, '<p>') > -1) {
             $this->AddControl($s_notes);
         } else {
             $this->AddControl(new XhtmlElement('p', $s_notes));
         }
     }
     # Show details of the seasons
     if ($match->Seasons()->GetCount() == 1) {
         $season = $match->Seasons()->GetFirst();
         $season_name = new XhtmlAnchor($season->GetCompetitionName(), $season->GetNavigateUrl());
         $b_the = !(stristr($season->GetCompetitionName(), 'the ') === 0);
         $this->AddControl(new XhtmlElement('p', 'This tournament is listed in ' . ($b_the ? 'the ' : '') . $season_name->__toString() . '.'));
     } elseif ($match->Seasons()->GetCount() > 1) {
         $this->AddControl(new XhtmlElement('p', 'This tournament is listed in the following seasons: '));
         $season_list = new XhtmlElement('ul');
         $this->AddControl($season_list);
         $seasons = $match->Seasons()->GetItems();
         $total_seasons = count($seasons);
         for ($i = 0; $i < $total_seasons; $i++) {
             $season = $seasons[$i];
             /* @var $season Season */
             $season_name = new XhtmlAnchor($season->GetCompetitionName(), $season->GetNavigateUrl());
             $li = new XhtmlElement('li', $season_name);
             if ($i < $total_seasons - 2) {
                 $li->AddControl(new XhtmlElement('span', ', ', 'metadata'));
             } else {
                 if ($i < $total_seasons - 1) {
                     $li->AddControl(new XhtmlElement('span', ' and ', 'metadata'));
                 }
             }
             $season_list->AddControl($li);
         }
     }
 }
 protected function OnPreRender()
 {
     /* @var $o_home Team */
     /* @var $o_away Team */
     /* @var $o_tourney Match */
     # Date and tournament
     $o_date_para = new XhtmlElement('p');
     $o_date = new XhtmlElement('abbr', htmlentities($this->o_match->GetStartTimeFormatted(), ENT_QUOTES, "UTF-8", false));
     $o_date->SetTitle(Date::Microformat($this->o_match->GetStartTime()));
     # hCalendar
     $o_date->SetCssClass('dtstart');
     # hCalendar
     $o_date->AddAttribute("property", "schema:startDate");
     $o_date->AddAttribute("datatype", "xsd:date");
     $o_date->AddAttribute("content", Date::Microformat($this->o_match->GetStartTime()));
     $o_date_para->AddControl('When: ');
     $o_date_para->AddControl($o_date);
     # hCalendar end date
     if ($this->o_match->GetIsStartTimeKnown()) {
         $i_end_time = $this->o_match->GetStartTime() + 60 * 90;
         $o_hcal_end = new XhtmlElement('abbr', ' until around ' . htmlentities(Date::Time($i_end_time), ENT_QUOTES, "UTF-8", false));
         $o_hcal_end->SetTitle(Date::Microformat($i_end_time));
         $o_hcal_end->SetCssClass('metadata dtend');
         $o_date_para->AddControl($o_hcal_end);
     }
     # If we know the time and place, show when the sun sets
     # TODO: Assumes UK
     if ($this->o_match->GetGround() instanceof Ground and $this->o_match->GetGround()->GetAddress()->GetLatitude() and $this->o_match->GetGround()->GetAddress()->GetLongitude()) {
         $o_date_para->AddControl(' <span class="sunset">sunset ' . htmlentities(Date::Time(date_sunset($this->o_match->GetStartTime(), SUNFUNCS_RET_TIMESTAMP, $this->o_match->GetGround()->GetAddress()->GetLatitude(), $this->o_match->GetGround()->GetAddress()->GetLongitude())), ENT_QUOTES, "UTF-8", false) . '</span>');
     }
     # Display match type/season/tournament
     if ($this->o_match->GetMatchType() == MatchType::TOURNAMENT_MATCH) {
         $o_date_para->SetCssClass('description');
         # hCal
         $o_tourney = $this->o_match->GetTournament();
         if (is_object($o_tourney)) {
             $tournament_link = new XhtmlAnchor(htmlentities($o_tourney->GetTitle(), ENT_QUOTES, "UTF-8", false), $o_tourney->GetNavigateUrl());
             $tournament_link->AddAttribute("typeof", "schema:SportsEvent");
             $tournament_link->AddAttribute("about", $o_tourney->GetLinkedDataUri());
             $tournament_link->AddAttribute("rel", "schema:url");
             $tournament_link->AddAttribute("property", "schema:name");
             $tournament_container = new XhtmlElement("span", $tournament_link);
             $tournament_container->AddAttribute("rel", "schema:superEvent");
             # Check for 'the' to get the grammar right
             $s_title = strtolower($o_tourney->GetTitle());
             if (strlen($s_title) >= 4 and substr($s_title, 0, 4) == 'the ') {
                 $o_date_para->AddControl(', in ');
             } else {
                 $o_date_para->AddControl(', in the ');
             }
             $o_date_para->AddControl($tournament_container);
             $o_date_para->AddControl('.');
         } else {
             $o_date_para->AddControl(', in a tournament.');
         }
     } else {
         # hCalendar desc, built up at the same time as the date and league/tournament
         $hcal_desc = new XhtmlElement('div', null, 'description');
         $this->AddControl($hcal_desc);
         $s_detail_xhtml = ucfirst(MatchType::Text($this->o_match->GetMatchType()));
         $season_list_xhtml = null;
         if ($this->o_match->Seasons()->GetCount() == 1) {
             $season = $this->o_match->Seasons()->GetFirst();
             $season_name = new XhtmlAnchor(htmlentities($season->GetCompetitionName(), ENT_QUOTES, "UTF-8", false), $season->GetNavigateUrl());
             $b_the = !(stristr($season->GetCompetitionName(), 'the ') === 0);
             $s_detail_xhtml .= ' in ' . ($b_the ? 'the ' : '') . $season_name->__toString() . '.';
         } elseif ($this->o_match->Seasons()->GetCount() > 1) {
             $s_detail_xhtml .= ' in the following seasons: ';
             $season_list_xhtml = new XhtmlElement('ul');
             $seasons = $this->o_match->Seasons()->GetItems();
             $total_seasons = count($seasons);
             for ($i = 0; $i < $total_seasons; $i++) {
                 $season = $seasons[$i];
                 /* @var $season Season */
                 $season_name = new XhtmlAnchor(htmlentities($season->GetCompetitionName(), ENT_QUOTES, "UTF-8", false), $season->GetNavigateUrl());
                 $li = new XhtmlElement('li', $season_name);
                 if ($i < $total_seasons - 2) {
                     $li->AddControl(new XhtmlElement('span', ', ', 'metadata'));
                 } else {
                     if ($i < $total_seasons - 1) {
                         $li->AddControl(new XhtmlElement('span', ' and ', 'metadata'));
                     }
                 }
                 $season_list_xhtml->AddControl($li);
             }
         } else {
             $s_detail_xhtml .= '.';
         }
         $hcal_desc->AddControl(new XhtmlElement('p', $s_detail_xhtml));
         if (!is_null($season_list_xhtml)) {
             $hcal_desc->AddControl($season_list_xhtml);
         }
     }
     # Who
     $o_home = $this->o_match->GetHomeTeam();
     $o_away = $this->o_match->GetAwayTeam();
     $has_home = $o_home instanceof Team;
     $has_away = $o_away instanceof Team;
     if ($has_home or $has_away) {
         $who = new XhtmlElement("p", "Who: ");
         if ($has_home) {
             $who->AddControl($this->CreateTeamLink($o_home));
         }
         if ($has_home and $has_away) {
             $who->AddControl(" and ");
         }
         if ($has_away) {
             $who->AddControl($this->CreateTeamLink($o_away));
         }
         $this->AddControl($who);
     }
     # When
     $this->AddControl($o_date_para);
     # Ground
     $o_ground = $this->o_match->GetGround();
     if (is_object($o_ground)) {
         $o_ground_link = new XhtmlElement('a', htmlentities($o_ground->GetNameAndTown(), ENT_QUOTES, "UTF-8", false));
         $o_ground_link->AddAttribute('href', $o_ground->GetNavigateUrl());
         $o_ground_link->SetCssClass('location');
         # hCalendar
         $o_ground_link->AddAttribute("typeof", "schema:Place");
         $o_ground_link->AddAttribute("about", $o_ground->GetLinkedDataUri());
         $o_ground_link->AddAttribute("rel", "schema:url");
         $o_ground_link->AddAttribute("property", "schema:name");
         $o_ground_control = new XhtmlElement('p', 'Where: ');
         $o_ground_control->AddAttribute("rel", "schema:location");
         $o_ground_control->AddControl($o_ground_link);
         $this->AddControl($o_ground_control);
     }
     # Add result
     $o_result = $this->o_match->Result();
     $b_result_known = !$o_result->GetResultType() == MatchResult::UNKNOWN;
     $toss_known = !is_null($this->o_match->Result()->GetTossWonBy());
     $b_batting_order_known = !is_null($this->o_match->Result()->GetHomeBattedFirst());
     $has_scorecard_data = ($o_result->HomeBatting()->GetCount() or $o_result->HomeBowling()->GetCount() or $o_result->AwayBatting()->GetCount() or $o_result->AwayBowling()->GetCount() or $o_result->GetHomeRuns() or $o_result->GetHomeWickets() or $o_result->GetAwayRuns() or $o_result->GetAwayWickets());
     $has_player_of_match = $this->o_match->Result()->GetPlayerOfTheMatch() instanceof Player and $this->o_match->Result()->GetPlayerOfTheMatch()->GetName();
     $has_player_of_match_home = $this->o_match->Result()->GetPlayerOfTheMatchHome() instanceof Player and $this->o_match->Result()->GetPlayerOfTheMatchHome()->GetName();
     $has_player_of_match_away = $this->o_match->Result()->GetPlayerOfTheMatchAway() instanceof Player and $this->o_match->Result()->GetPlayerOfTheMatchAway()->GetName();
     if ($b_result_known or $b_batting_order_known or $has_scorecard_data) {
         # Put result in header, so long as we have something to put after it. Otherwise put the result after it.
         $result_header = "Result";
         if ($b_result_known and ($b_batting_order_known or $has_scorecard_data)) {
             $result_header .= ": " . $this->o_match->GetResultDescription();
         }
         $result_header = new XhtmlElement('h2', htmlentities($result_header, ENT_QUOTES, "UTF-8", false));
         if ($has_scorecard_data) {
             $result_header->AddCssClass("hasScorecard");
         }
         $this->AddControl($result_header);
     }
     if ($toss_known) {
         $toss_team = $this->o_match->Result()->GetTossWonBy() === TeamRole::Home() ? $this->o_match->GetHomeTeam() : $this->o_match->GetAwayTeam();
         if ($toss_team instanceof Team) {
             $toss_text = $toss_team->GetName() . " won the toss";
             if ($b_batting_order_known) {
                 $chose_to = ($this->o_match->Result()->GetTossWonBy() === TeamRole::Home()) == $this->o_match->Result()->GetHomeBattedFirst() ? "bat" : "bowl";
                 $toss_text .= " and chose to " . $chose_to;
             }
             $this->AddControl("<p>" . Html::Encode($toss_text) . '.</p>');
         }
     }
     # If at least one player recorded, create a container for the schema.org metadata
     if ($has_scorecard_data or $has_player_of_match or $has_player_of_match_home or $has_player_of_match_away) {
         $this->AddControl('<div rel="schema:performers">');
     }
     if ($has_scorecard_data) {
         $this->CreateScorecard($this->o_match);
     } else {
         # Got to be just result and batting order now. Only include result if batting order's not there, otherwise result will already be in header.
         if ($b_result_known and !$b_batting_order_known) {
             $this->AddControl(new XhtmlElement('p', htmlentities($this->o_match->GetResultDescription(), ENT_QUOTES, "UTF-8", false) . '.'));
         }
         if ($b_batting_order_known) {
             $this->AddControl(new XhtmlElement('p', htmlentities(($this->o_match->Result()->GetHomeBattedFirst() ? $o_home->GetName() : $o_away->GetName()) . ' batted first.'), ENT_QUOTES, "UTF-8", false));
         }
     }
     # Player of the match
     if ($has_player_of_match) {
         $player = $this->o_match->Result()->GetPlayerOfTheMatch();
         $team = $player->Team()->GetId() == $o_home->GetId() ? $o_home->GetName() : $o_away->GetName();
         $player_of_match = new XhtmlElement('p', 'Player of the match: <a property="schema:name" rel="schema:url" href="' . htmlentities($player->GetPlayerUrl(), ENT_QUOTES, "UTF-8", false) . '">' . htmlentities($player->GetName(), ENT_QUOTES, "UTF-8", false) . "</a> ({$team})");
         $player_of_match->AddAttribute("typeof", "schema:Person");
         $player_of_match->AddAttribute("about", $player->GetLinkedDataUri());
         $this->AddControl($player_of_match);
     }
     if ($has_player_of_match_home) {
         $player = $this->o_match->Result()->GetPlayerOfTheMatchHome();
         $player_of_match = new XhtmlElement('p', $o_home->GetName() . ' player of the match: <a property="schema:name" rel="schema:url" href="' . htmlentities($player->GetPlayerUrl(), ENT_QUOTES, "UTF-8", false) . '">' . htmlentities($player->GetName(), ENT_QUOTES, "UTF-8", false) . "</a>");
         $player_of_match->AddAttribute("typeof", "schema:Person");
         $player_of_match->AddAttribute("about", $player->GetLinkedDataUri());
         $this->AddControl($player_of_match);
     }
     if ($has_player_of_match_away) {
         $player = $this->o_match->Result()->GetPlayerOfTheMatchAway();
         $player_of_match = new XhtmlElement('p', $o_away->GetName() . ' player of the match: <a property="schema:name" rel="schema:url" href="' . htmlentities($player->GetPlayerUrl(), ENT_QUOTES, "UTF-8", false) . '">' . htmlentities($player->GetName(), ENT_QUOTES, "UTF-8", false) . "</a>");
         $player_of_match->AddAttribute("typeof", "schema:Person");
         $player_of_match->AddAttribute("about", $player->GetLinkedDataUri());
         $this->AddControl($player_of_match);
     }
     # End container for the schema.org metadata
     if ($has_scorecard_data or $has_player_of_match or $has_player_of_match_home or $has_player_of_match_away) {
         $this->AddControl('</div>');
     }
     # Add notes
     if ($this->o_match->GetNotes()) {
         $this->AddControl(new XhtmlElement('h2', 'Notes'));
         $s_notes = htmlentities($this->o_match->GetNotes(), ENT_QUOTES, "UTF-8", false);
         $s_notes = XhtmlMarkup::ApplyCharacterEntities($s_notes);
         require_once 'email/email-address-protector.class.php';
         $protector = new EmailAddressProtector($this->o_settings);
         $s_notes = $protector->ApplyEmailProtection($s_notes, AuthenticationManager::GetUser()->IsSignedIn());
         $s_notes = XhtmlMarkup::ApplyHeadings($s_notes);
         $s_notes = XhtmlMarkup::ApplyParagraphs($s_notes);
         $s_notes = XhtmlMarkup::ApplyLists($s_notes);
         $s_notes = XhtmlMarkup::ApplySimpleTags($s_notes);
         $s_notes = XhtmlMarkup::ApplyLinks($s_notes);
         if (strpos($s_notes, '<p>') > -1) {
             $this->AddControl($s_notes);
         } else {
             $this->AddControl(new XhtmlElement('p', $s_notes));
         }
     }
     # hCalendar metadata
     $o_hcal_para = new XhtmlElement('p');
     $o_hcal_para->SetCssClass('metadata');
     $this->AddControl($o_hcal_para);
     # hCalendar timestamp
     $o_hcal_para->AddControl('Status: At ');
     $o_hcal_stamp = new XhtmlElement('abbr', htmlentities(Date::Time(gmdate('U')), ENT_QUOTES, "UTF-8", false));
     $o_hcal_stamp->SetTitle(Date::Microformat());
     $o_hcal_stamp->SetCssClass('dtstamp');
     $o_hcal_para->AddControl($o_hcal_stamp);
     # hCalendar GUID
     $o_hcal_para->AddControl(' match ');
     $o_hcal_guid = new XhtmlElement('span', htmlentities($this->o_match->GetLinkedDataUri(), ENT_QUOTES, "UTF-8", false));
     $o_hcal_guid->SetCssClass('uid');
     $o_hcal_para->AddControl($o_hcal_guid);
     # work out hCalendar status
     $s_status = 'CONFIRMED';
     switch ($this->o_match->Result()->GetResultType()) {
         case MatchResult::CANCELLED:
         case MatchResult::POSTPONED:
         case MatchResult::AWAY_WIN_BY_FORFEIT:
         case MatchResult::HOME_WIN_BY_FORFEIT:
             $s_status = 'CANCELLED';
     }
     # hCalendar URL and status
     $o_hcal_para->AddControl(' is ');
     $o_hcal_url = new XhtmlAnchor($s_status, 'http://' . $_SERVER['HTTP_HOST'] . $this->o_match->GetNavigateUrl());
     $o_hcal_url->SetCssClass('url status');
     $o_hcal_para->AddControl($o_hcal_url);
 }
 function ApplyInterestsMarkup($text, $b_strip_tags = 0)
 {
     if ($text) {
         $text = HTML::Encode($text);
         $text = XhtmlMarkup::ApplyCharacterEntities($text);
         require_once 'email/email-address-protector.class.php';
         $protector = new EmailAddressProtector($this->GetSettings());
         $text = $protector->ApplyEmailProtection($text, AuthenticationManager::GetUser()->IsSignedIn());
         $text = XhtmlMarkup::ApplyParagraphs($text, $b_strip_tags);
         $text = XhtmlMarkup::ApplyLists($text, $b_strip_tags);
         $text = XhtmlMarkup::ApplyLinks($text, $b_strip_tags);
         $text = XhtmlMarkup::ApplySimpleTags($text, $b_strip_tags);
         $text = XhtmlMarkup::ApplySimpleXhtmlTags($text, $b_strip_tags);
         $text = XhtmlMarkup::CloseUnmatchedTags($text);
     }
     return $text;
 }