Exemple #1
0
 /**
  * @param string|array $field
  * @param mixed $value
  * @param callable|null $callback
  *
  * @return mixed
  */
 public function validate($field, $value, callable $callback = null)
 {
     $key = $field;
     if (is_array($field)) {
         $key = key($field);
         $field = current($field);
     }
     if ($callback !== null) {
         $value = $callback($value);
     }
     while (!empty($this->stack)) {
         $item = array_shift($this->stack);
         if (false === ($validator = $this->collection->get($item['name']))) {
             throw new \RuntimeException('Unknown validator `' . $item['name'] . '`');
         }
         $arguments = $validator->getFormattedArgs($item['arguments']);
         if ($validator->validate($value, $arguments)) {
             continue;
         }
         if (!isset($arguments['field'])) {
             $arguments['field'] = $field;
         }
         if (!isset($arguments['value'])) {
             $arguments['value'] = is_array($value) ? var_export($value, true) : $value;
         }
         $this->stack = array();
         $error = isset($item['error']) ? $item['error'] : $validator->getError();
         $this->errors[$key] = $this->placeholder->replace($error, $arguments);
         break;
     }
     return $value;
 }
Exemple #2
0
 /**
  * Extracts the URL from a CSS URL value.
  *
  * @param string $url
  * @return string
  */
 public static function extractUrl($url)
 {
     if (is_string($url)) {
         // Extract the URL from a given CSS URL value|string
         //
         // Examples:
         // - "http://www.example.com"
         // - 'http://www.example.com'
         // - url("http://www.example.com")
         // - url( 'http://www.example.com' )
         // - url(http://www.example.com)
         // - url( http://www.example.com )
         // - url("http://www.example.com?escape=\"escape\"")
         //
         // "Parentheses, whitespace characters, single quotes (') and double quotes (") appearing in a URL must be
         // escaped with a backslash so that the resulting value is a valid URL token"
         $url = Placeholder::replaceStringPlaceholders($url);
         $url = preg_replace('/^url\\(|\\)$/', '', $url);
         $url = str_replace(["\\(", "\\)", "\\ ", "\\'", "\\\""], ["(", ")", " ", "'", "\""], $url);
         $url = preg_replace('/^(["\'])(.*)\\g{1}$/', '\\2', $url);
         $url = urldecode($url);
         return $url;
     } else {
         throw new \InvalidArgumentException("Invalid type '" . gettype($url) . "' for argument 'url' given.");
     }
 }
 public function getValue($placeholder)
 {
     $value = parent::getValue($placeholder);
     if (is_null($value)) {
         return NULL;
     }
     return $placeholder . '=' . rawurlencode($value);
 }
Exemple #4
0
 public static function handle($template)
 {
     $placeholders = array();
     preg_match_all(RE_PLACEHOLDER, $template, $placeholders);
     if (count($placeholders[0]) == 1 && $placeholders[0][0] == $template) {
         return Placeholder::handle($template);
     }
     $search = array();
     $replace = array();
     foreach ($placeholders[0] as $placeholder) {
         $search[] = $placeholder;
         $replace[] = Placeholder::handle($placeholder);
     }
     return str_replace($search, $replace, $template);
 }
 function CreateControls()
 {
     require_once 'xhtml/xhtml-element.class.php';
     require_once 'xhtml/forms/form-part.class.php';
     require_once 'xhtml/forms/textbox.class.php';
     $this->AddCssClass('legacy-form');
     $o_comp = $this->GetDataObject();
     /* @var $o_type IdValue */
     /* @var $o_comp Competition */
     /* @var $o_season Season */
     # add name
     $o_name_box = new TextBox('name', $o_comp->GetName(), $this->IsValidSubmit());
     $o_name_box->AddAttribute('maxlength', 100);
     $o_name = new FormPart('Competition name', $o_name_box);
     $this->AddControl($o_name);
     # Add seasons once competition saved
     if ($o_comp->GetId()) {
         $a_seasons = $o_comp->GetSeasons();
         $o_season_part = new FormPart('Seasons');
         $o_season_control = new Placeholder();
         # List exisiting seasons
         if (is_array($a_seasons) and count($a_seasons)) {
             $o_seasons = new XhtmlElement('ul');
             foreach ($a_seasons as $o_season) {
                 $o_season_link = new XhtmlAnchor(Html::Encode($o_season->GetName()), $o_season->GetEditSeasonUrl());
                 $o_seasons->AddControl(new XhtmlElement('li', $o_season_link));
             }
             $o_season_control->AddControl($o_seasons);
         }
         $o_new_season = new XhtmlAnchor('Add season', '/play/competitions/seasonedit.php?competition=' . $o_comp->GetId());
         $o_season_control->AddControl($o_new_season);
         $o_season_part->SetControl($o_season_control);
         $this->AddControl($o_season_part);
     }
     # Still going?
     $this->AddControl(new CheckBox('active', 'This competition is still played', 1, $o_comp->GetIsActive(), $this->IsValidSubmit()));
     # add player type
     $o_type_list = new XhtmlSelect('playerType', null, $this->IsValidSubmit());
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::MIXED), PlayerType::MIXED));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::LADIES), PlayerType::LADIES));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::JUNIOR_MIXED), PlayerType::JUNIOR_MIXED));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::GIRLS), PlayerType::GIRLS));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::MEN), PlayerType::MEN));
     $o_type_list->AddControl(new XhtmlOption(PlayerType::Text(PlayerType::BOYS), PlayerType::BOYS));
     if (!is_null($o_comp->GetPlayerType()) and $this->IsValidSubmit()) {
         $o_type_list->SelectOption($o_comp->GetPlayerType());
     }
     $o_type_part = new FormPart('Player type', $o_type_list);
     $this->AddControl($o_type_part);
     # add players per team
     $players_box = new TextBox('players', $o_comp->GetMaximumPlayersPerTeam(), $this->IsValidSubmit());
     $players_box->SetMaxLength(2);
     $players = new FormPart('Max players in league/cup team', $players_box);
     $this->AddControl($players);
     # add overs
     $overs_box = new TextBox('overs', $o_comp->GetOvers(), $this->IsValidSubmit());
     $overs_box->SetMaxLength(2);
     $overs = new FormPart('Overs per innings', $overs_box);
     $this->AddControl($overs);
     # category
     $cat_select = new CategorySelectControl($this->categories, $this->IsValidSubmit());
     $cat_select->SetXhtmlId($this->GetNamingPrefix() . 'category');
     if (!is_null($o_comp->GetCategory()) and $this->IsValidSubmit()) {
         $cat_select->SelectOption($o_comp->GetCategory()->GetId());
     }
     $this->AddControl(new FormPart('Category', $cat_select));
     # add intro
     $o_intro_box = new TextBox('intro', $o_comp->GetIntro(), $this->IsValidSubmit());
     $o_intro_box->SetMode(TextBoxMode::MultiLine());
     $o_intro = new FormPart('Introduction', $o_intro_box);
     $this->AddControl($o_intro);
     # add contact info
     $o_contact_box = new TextBox('contact', $o_comp->GetContact(), $this->IsValidSubmit());
     $o_contact_box->SetMode(TextBoxMode::MultiLine());
     $o_contact = new FormPart('Contact details', $o_contact_box);
     $this->AddControl($o_contact);
     # Add notification email
     $o_notify_box = new TextBox('notification', $o_comp->GetNotificationEmail(), $this->IsValidSubmit());
     $o_notify_box->SetMaxLength(200);
     $o_notify = new FormPart('Notification email', $o_notify_box);
     $this->AddControl($o_notify);
     # add website
     $o_website_box = new TextBox('website', $o_comp->GetWebsiteUrl(), $this->IsValidSubmit());
     $o_website_box->SetMaxLength(250);
     $o_website = new FormPart('Website', $o_website_box);
     $this->AddControl($o_website);
     # Remember short URL
     $o_short_url = new TextBox($this->GetNamingPrefix() . 'ShortUrl', $o_comp->GetShortUrl(), $this->IsValidSubmit());
     $this->AddControl(new FormPart('Short URL', $o_short_url));
 }
 function PostalAddressEditControl()
 {
     # set up element
     parent::Placeholder();
     $this->s_data_object_class = 'PostalAddress';
 }
Exemple #7
0
}
// 从query中提取参数
$args = array_keys($opts);
foreach ($args as $arg) {
    if (isset($_GET[$arg])) {
        $opts[$arg] = $_GET[$arg];
    }
}
// 解码text参数
$opts['text'] = urldecode($opts['text']);
// 把size展开成width和height
$size = $opts['size'];
if (is_numeric($size)) {
    $opts['width'] = $opts['height'] = $size;
} elseif (preg_match('/(\\d+)\\s*[^\\d]+\\s*(\\d+)/i', $size, $match)) {
    list(, $opts['width'], $opts['height']) = $match;
}
// 更新size和fontSize
if (isset($opts['fontSize'])) {
    $opts['size'] = $opts['fontSize'];
    unset($opts['fontSize']);
} else {
    unset($opts['size']);
}
// 默认展示帮助页面
if (!$opts['width']) {
    die(file_get_contents('help.html'));
}
// 输出图片
$placeholder = new Placeholder($opts);
$placeholder->showImage();
Exemple #8
0
 /**
  * Parsing second pass, finding placeholders in strings
  */
 protected function findPlaceholders()
 {
     $data = array();
     foreach ($this->data as $part) {
         if (is_string($part)) {
             while (preg_match('#^(.+){{([^}]+)}}(.+)$#Usi', $part, $match)) {
                 $data[] = $match[1];
                 $placeholder = new Placeholder($match[2]);
                 $data[] = $placeholder;
                 $this->placeholders[$placeholder->getName()] = $placeholder;
                 $part = $match[3];
             }
             $data[] = $part;
         } else {
             $data[] = $part;
         }
     }
     $this->data = $data;
 }
 /**
  * @return void
  * @param XhtmlElement[] $a_controls
  * @desc Sets the array of child elements for this element
  */
 public function SetControls($a_controls)
 {
     parent::SetControls($a_controls);
     $this->InvalidateXhtml();
 }
Exemple #10
0
 /**
  * @param string $text The text with placeholders
  * @param array $arguments The arguments supplying values for the placeholders
  * @param string $result The result of Phrase rendering
  *
  * @dataProvider renderPlaceholderDataProvider
  */
 public function testRenderPlaceholder($text, array $arguments, $result)
 {
     $this->assertEquals($result, $this->_renderer->render([$text], $arguments));
 }
 /**
  * Creates, and re-populates on postback, text displaying one property of a related data item
  *
  * @param string $s_validated_value
  * @param string $s_name
  * @param int $i_row_count
  * @param int $i_total_rows
  * @param string[] $a_display_values
  * @return Placeholder
  */
 protected function CreateDisplayText($s_validated_value, $s_name, $i_row_count, $i_total_rows, $a_display_values = null)
 {
     $textbox = $this->CreateTextBox($s_validated_value, $s_name, $i_row_count, $i_total_rows);
     $textbox->SetMode(TextBoxMode::Hidden());
     $container = new Placeholder($textbox);
     if (is_array($a_display_values) and array_key_exists($textbox->GetText(), $a_display_values)) {
         # This path used on initial load request, and when controlling editor's save button is clicked when a row is being added
         # Textbox value is the key to an array of values
         $container->AddControl($a_display_values[$textbox->GetText()]->__toString());
         $textbox->SetText($textbox->GetText() . RelatedIdEditor::VALUE_DIVIDER . $a_display_values[$textbox->GetText()]->__toString());
     } else {
         # Copy textbox value, remove prepended id, and use as display text
         $s_value = $textbox->GetText();
         $i_pos = strpos($s_value, RelatedIdEditor::VALUE_DIVIDER);
         if ($i_pos) {
             $s_value = substr($s_value, $i_pos + strlen(RelatedIdEditor::VALUE_DIVIDER));
         }
         $container->AddControl(ucfirst($s_value));
     }
     return $container;
 }
 function TeamListControl($a_teams = null)
 {
     parent::Placeholder();
     $this->teams = is_array($a_teams) ? $a_teams : array();
 }
 /**
  * Creates, and re-populates on postback, non-editable text with an associated id
  *
  * @param string $s_validated_value
  * @param string $s_name
  * @param int $i_row_count
  * @param int $i_total_rows
  * @param bool $b_required
  * @return TextBox
  */
 protected function CreateNonEditableText($i_validated_id, $s_validated_value, $s_name, $i_row_count, $i_total_rows)
 {
     # Establish current status
     $b_is_add_row = is_null($i_row_count);
     $b_repopulate_add_row = (!$this->IsValid() or $this->DeleteClicked() or $this->IsUnrelatedInternalPostback());
     # Create text boxes
     $textbox_id = new TextBox($this->GetNamingPrefix() . $s_name . $i_row_count);
     $textbox_id->SetMode(TextBoxMode::Hidden());
     $textbox_value = new TextBox($this->GetNamingPrefix() . $s_name . 'Value' . $i_row_count);
     $textbox_value->SetMode(TextBoxMode::Hidden());
     # Repopulate the previous value
     # If this is the row used to add a new related item...
     if ($b_is_add_row) {
         # ...if we repopulate, it'll be with the exact value posted,
         # as validation has either failed or not occurred
         if ($b_repopulate_add_row and isset($_POST[$textbox_id->GetXhtmlId()])) {
             $textbox_id->SetText($_POST[$textbox_id->GetXhtmlId()]);
         }
         if ($b_repopulate_add_row and isset($_POST[$textbox_value->GetXhtmlId()])) {
             $textbox_value->SetText($_POST[$textbox_value->GetXhtmlId()]);
         }
     } else {
         if ($this->IsValid()) {
             if ($this->AddClicked() and $i_row_count == $this->i_row_added) {
                 # If a new row was posted, is valid, and is now displayed here, need to get the posted value from the add row
                 $s_textbox_id_in_add_row = substr($textbox_id->GetXhtmlId(), 0, strlen($textbox_id->GetXhtmlId()) - strlen($i_row_count));
                 if (isset($_POST[$s_textbox_id_in_add_row])) {
                     $textbox_id->SetText($_POST[$s_textbox_id_in_add_row]);
                 }
                 $s_textbox_value_in_add_row = substr($textbox_value->GetXhtmlId(), 0, strlen($textbox_value->GetXhtmlId()) - strlen($i_row_count));
                 if (isset($_POST[$s_textbox_value_in_add_row])) {
                     $textbox_value->SetText($_POST[$s_textbox_value_in_add_row]);
                 } else {
                     # If the add row doesn't populate the item name as well as the item id, it can be passed in as the validated value
                     $textbox_value->SetText($s_validated_value);
                 }
             } else {
                 # Even though the editor as a whole is valid, this row wasn't validated
                 # so just restore the previous value
                 if (isset($_POST[$textbox_id->GetXhtmlId()])) {
                     $textbox_id->SetText($_POST[$textbox_id->GetXhtmlId()]);
                 } else {
                     # Won't be in $_POST when page is first loaded
                     $textbox_id->SetText($i_validated_id);
                 }
                 # Even though the editor as a whole is valid, this row wasn't validated
                 # so just restore the previous value
                 if (isset($_POST[$textbox_value->GetXhtmlId()])) {
                     $textbox_value->SetText($_POST[$textbox_value->GetXhtmlId()]);
                 } else {
                     # Won't be in $_POST when page is first loaded
                     $textbox_value->SetText($s_validated_value);
                 }
             }
         } else {
             # Repopulate with the exact value posted, as validation has failed
             $textbox_id->SetText($_POST[$textbox_id->GetXhtmlId()]);
             $textbox_value->SetText($_POST[$textbox_value->GetXhtmlId()]);
         }
     }
     # Return textboxes so that other things can be done to them - eg add a CSS class or maxlength
     $placeholder = new Placeholder();
     $placeholder->AddControl($textbox_id);
     $placeholder->AddControl($textbox_value);
     $placeholder->AddControl($textbox_value->GetText());
     return $placeholder;
 }
 /**
  * Create a table row to add or edit a match
  *
  * @param object $data_object
  * @param int $i_row_count
  * @param int $i_total_rows
  */
 protected function AddItemToTable($data_object = null, $i_row_count = null, $i_total_rows = null)
 {
     /* @var $data_object Match */
     $b_has_data_object = !is_null($data_object);
     // Which match?
     if (is_null($i_row_count)) {
         $order = $this->CreateTextBox(null, 'MatchOrder', null, $i_total_rows);
         $order->AddAttribute("type", "number");
         $order->SetCssClass("numeric");
         $this->max_sort_order++;
         $order->SetText($this->max_sort_order);
         $home_control = $this->AddTeamList('HomeTeamId', $b_has_data_object ? $data_object->GetHomeTeamId() : '', $i_total_rows);
         $away_control = $this->AddTeamList('AwayTeamId', $b_has_data_object ? $data_object->GetAwayTeamId() : '', $i_total_rows);
         $match_control = new Placeholder();
         $match_control->AddControl($home_control);
         $match_control->AddControl(" v ");
         $match_control->AddControl($away_control);
         $this->AddRowToTable(array($order, $match_control));
     } else {
         # Display the match title. When the add button is used, we need to get the team names for the new match because they weren't posted.
         if ($b_has_data_object) {
             $this->EnsureTeamName($data_object->GetHomeTeam());
             $this->EnsureTeamName($data_object->GetAwayTeam());
         }
         $match_order = $b_has_data_object ? $data_object->GetOrderInTournament() : null;
         if (is_null($match_order)) {
             $match_order = $this->max_sort_order + 1;
         }
         if ($match_order > $this->max_sort_order) {
             $this->max_sort_order = $match_order;
         }
         $order = $this->CreateTextBox($match_order, 'MatchOrder', $i_row_count, $i_total_rows);
         $order->AddAttribute("type", "number");
         $order->SetCssClass("numeric");
         $match_control = $this->CreateNonEditableText($b_has_data_object ? $data_object->GetId() : null, $b_has_data_object ? $data_object->GetTitle() : '', 'MatchId', $i_row_count, $i_total_rows);
         # If the add button is used, remember the team ids until the final save is requested
         $home_team_id = $this->CreateTextBox($data_object->GetHomeTeamId(), 'HomeTeamId', $i_row_count, $i_total_rows);
         $home_team_id->SetMode(TextBoxMode::Hidden());
         $away_team_id = $this->CreateTextBox($data_object->GetAwayTeamId(), 'AwayTeamId', $i_row_count, $i_total_rows);
         $away_team_id->SetMode(TextBoxMode::Hidden());
         $container = new Placeholder();
         $container->SetControls(array($match_control, $home_team_id, $away_team_id));
         $this->AddRowToTable(array($order, $container));
     }
 }
 /**
  * Creates a StatisticsHighlightTable
  * @param Batting[] $best_batting
  * @param Batting[] $most_runs
  * @param Bowling[] $best_bowling
  * @param Bowling[] $most_wickets
  * @param array[Player,int] $most_catches
  * @param string $description
  * @return void
  */
 public function __construct($best_batting, $most_runs, $best_bowling, $most_wickets, $most_catches, $description)
 {
     parent::Placeholder();
     $best_batting_count = count($best_batting);
     $best_bowling_count = count($best_bowling);
     $most_runs_count = count($most_runs);
     $most_wickets_count = count($most_wickets);
     $most_catches_count = count($most_catches);
     $has_player_stats = ($best_batting_count or $best_bowling_count or $most_runs_count or $most_wickets_count or $most_catches_count);
     if (!$has_player_stats) {
         return;
     }
     # Show top players
     $this->AddControl('<table class="playerSummary large"><thead><tr><th colspan="2" class="scope">' . $description . '</th></tr><tr><th>Player</th><th class="total">Total</th></tr></thead><tbody>');
     $i = 1;
     $best = "";
     $list_open = false;
     $row_open = false;
     foreach ($best_batting as $performance) {
         $count = $performance["runs_scored"];
         $not_out = ($performance["how_out"] == Batting::NOT_OUT or $performance["how_out"] == Batting::RETIRED or $performance["how_out"] == Batting::RETIRED_HURT);
         if ($not_out) {
             $count .= "*";
         }
         if ($best and $best != $count) {
             $best_batting_count--;
         } else {
             if ($i == 1) {
                 $this->AddControl('<tr><td>');
                 $row_open = true;
             }
             if ($i == 1 and $best_batting_count > 1) {
                 $this->AddControl("<ul>");
                 $list_open = true;
             }
             if ($best_batting_count > 1) {
                 $this->AddControl("<li>");
             }
             $this->AddControl('<span typeof="schema:Person" about="http://www.stoolball.org.uk/id/player' . $performance["player_url"] . '"><a property="schema:name" rel="schema:url" href="' . $performance["player_url"] . '">' . $performance["player_name"] . "</a></span>");
             if ($best_batting_count > 1) {
                 $this->AddControl("</li>");
             }
             $best = $count;
         }
         if ($i >= $best_batting_count and $row_open) {
             if ($list_open) {
                 $this->AddControl("</ul>");
             }
             $this->AddControl("</td><td class=\"stat\">best batting<span class=\"stat\">{$best}</span></td></tr>\n");
             $row_open = false;
         }
         $i++;
     }
     $i = 1;
     foreach ($most_runs as $performance) {
         $count = $performance["statistic"];
         $runs = $count == 1 ? "run" : "runs";
         if ($i == 1) {
             $this->AddControl('<tr><td>');
         }
         if ($i == 1 and $most_runs_count > 1) {
             $this->AddControl("<ul>");
         }
         if ($most_runs_count > 1) {
             $this->AddControl("<li>");
         }
         $this->AddControl('<span typeof="schema:Person" about="http://www.stoolball.org.uk/id/player' . $performance["player_url"] . '"><a property="schema:name" rel="schema:url" href="' . $performance["player_url"] . '">' . $performance["player_name"] . "</a></span>");
         if ($most_runs_count > 1) {
             $this->AddControl("</li>");
         }
         if ($i == $most_runs_count and $most_runs_count > 1) {
             $this->AddControl("</ul>");
         }
         if ($i == $most_runs_count) {
             $this->AddControl("</td><td class=\"stat\"><span class=\"stat\">{$count}</span> {$runs}</td></tr>\n");
         }
         $i++;
     }
     $i = 1;
     $best = "";
     $list_open = false;
     foreach ($best_bowling as $performance) {
         $count = $performance["wickets"] . "/" . $performance["runs_conceded"];
         if ($best and $best != $count) {
             $best_bowling_count--;
         } else {
             if ($i == 1) {
                 $this->AddControl('<tr><td>');
                 $row_open = true;
             }
             if ($i == 1 and $best_bowling_count > 1) {
                 $this->AddControl("<ul>");
                 $list_open = true;
             }
             if ($best_bowling_count > 1) {
                 $this->AddControl("<li>");
             }
             $this->AddControl('<span typeof="schema:Person" about="http://www.stoolball.org.uk/id/player' . $performance["player_url"] . '"><a property="schema:name" rel="schema:url" href="' . $performance["player_url"] . '">' . $performance["player_name"] . "</a></span>");
             if ($best_bowling_count > 1) {
                 $this->AddControl("</li>");
             }
             $best = $count;
         }
         if ($i >= $best_bowling_count and $row_open) {
             if ($list_open) {
                 $this->AddControl("</ul>");
             }
             $this->AddControl("</td><td class=\"stat\">best bowling<span class=\"stat\">{$best}</span></td></tr>\n");
             $row_open = false;
         }
         $i++;
     }
     $i = 1;
     foreach ($most_wickets as $performance) {
         $count = $performance["statistic"];
         $wicket = $count == 1 ? "wicket" : "wickets";
         if ($i == 1) {
             $this->AddControl('<tr><td>');
         }
         if ($i == 1 and $most_wickets_count > 1) {
             $this->AddControl("<ul>");
         }
         if ($most_wickets_count > 1) {
             $this->AddControl("<li>");
         }
         $this->AddControl('<span typeof="schema:Person" about="http://www.stoolball.org.uk/id/player' . $performance["player_url"] . '"><a property="schema:name" rel="schema:url" href="' . $performance["player_url"] . '">' . $performance["player_name"] . "</a></span>");
         if ($most_wickets_count > 1) {
             $this->AddControl("</li>");
         }
         if ($i == $most_wickets_count and $most_wickets_count > 1) {
             $this->AddControl("</ul>");
         }
         if ($i == $most_wickets_count) {
             $this->AddControl("</td><td class=\"stat\"><span class=\"stat\">{$count}</span> {$wicket}</td></tr>\n");
         }
         $i++;
     }
     $i = 1;
     foreach ($most_catches as $performance) {
         $count = $performance["statistic"];
         $catch = $count == 1 ? "catch" : "catches";
         if ($i == 1) {
             $this->AddControl('<tr><td>');
         }
         if ($i == 1 and $most_catches_count > 1) {
             $this->AddControl("<ul>");
         }
         if ($most_catches_count > 1) {
             $this->AddControl("<li>");
         }
         $this->AddControl('<span typeof="schema:Person" about="http://www.stoolball.org.uk/id/player' . $performance["player_url"] . '"><a property="schema:name" rel="schema:url" href="' . $performance["player_url"] . '">' . $performance["player_name"] . "</a></span>");
         if ($most_catches_count > 1) {
             $this->AddControl("</li>");
         }
         if ($i == $most_catches_count and $most_catches_count > 1) {
             $this->AddControl("</ul>");
         }
         if ($i == $most_catches_count) {
             $this->AddControl("</td><td class=\"stat\"><span class=\"stat\">{$count}</span> {$catch}</td></tr>\n");
         }
         $i++;
     }
     $this->AddControl("</tbody></table>");
 }
Exemple #16
0
 /**
  * Splits a condition list with nested conditions (CSS4) into multiple conditions (CSS3 compatible).
  *
  * @param string $conditionList
  * @param string $charset
  * @return array
  */
 public static function splitNestedConditions($conditionList, $charset = "UTF-8")
 {
     // Check arguments
     if (!is_string($conditionList)) {
         throw new \InvalidArgumentException("Invalid type '" . gettype($conditionList) . "' for argument 'conditionList' given.");
     }
     if (!is_string($charset)) {
         throw new \InvalidArgumentException("Invalid type '" . gettype($charset) . "' for argument 'charset' given.");
     } elseif (!in_array($charset, mb_list_encodings())) {
         throw new \InvalidArgumentException("Invalid value '" . $charset . "' for argument 'charset' given. Charset not supported.");
     }
     // Remove at-rule and unnecessary white-spaces
     $conditionList = trim($conditionList, " \r\n\t\f");
     // Strings and comments should already be replaced, but let's check it again...
     $conditionList = Placeholder::replaceStringsAndComments($conditionList);
     $inFunction = false;
     $groupsOpened = 0;
     $enclosedChar = null;
     $conditions = [];
     $currentConditions = [""];
     $currentConditionKeys = [0];
     $subConditionList = "";
     if (preg_match('/[^\\x00-\\x7f]/', $conditionList)) {
         $isAscii = false;
         $strLen = mb_strlen($conditionList, $charset);
         $getOr = function ($i) use($conditionList) {
             return strtolower(substr($conditionList, $i, 4));
         };
     } else {
         $isAscii = true;
         $strLen = strlen($conditionList);
         $getOr = function ($i) use($charset, $conditionList) {
             return mb_strtolower(mb_substr($conditionList, $i, 4, $charset), $charset);
         };
     }
     for ($i = 0, $j = $strLen; $i < $j; $i++) {
         if ($isAscii === true) {
             $char = $conditionList[$i];
         } else {
             $char = mb_substr($conditionList, $i, 1, $charset);
         }
         if ($char === "(") {
             if ($groupsOpened > 0) {
                 $subConditionList .= $char;
             } else {
                 if ($i > 0) {
                     $prevChar = mb_substr($conditionList, $i - 1, 1, $charset);
                     if ($prevChar !== "(" && $prevChar !== " ") {
                         $inFunction = true;
                     }
                 }
             }
             if ($inFunction === false) {
                 $groupsOpened++;
             } else {
                 foreach ($currentConditionKeys as $index) {
                     $currentConditions[$index] .= $char;
                 }
             }
         } elseif ($char === ")") {
             if ($inFunction === false) {
                 $groupsOpened--;
                 if ($groupsOpened > 0) {
                     $subConditionList .= $char;
                 } else {
                     if ($subConditionList != "") {
                         $subConditions = self::splitNestedConditions($subConditionList, $charset);
                         $newConditions = [];
                         foreach ($subConditions as $subCondition) {
                             foreach ($currentConditions as $currentCondition) {
                                 $newConditions[] = trim($currentCondition, " \r\n\t\f") . " " . $subCondition;
                             }
                         }
                         $currentConditions = $newConditions;
                         $currentConditionKeys = array_keys($currentConditions);
                     }
                     $subConditionList = "";
                 }
             } else {
                 if ($groupsOpened > 0) {
                     $subConditionList .= $char;
                 }
                 foreach ($currentConditionKeys as $index) {
                     $currentConditions[$index] .= $char;
                 }
                 $inFunction = false;
             }
         } elseif ($char === " " && $getOr($i) === " or ") {
             if ($groupsOpened > 0) {
                 $subConditionList .= " or ";
             } else {
                 foreach ($currentConditions as $currentCondition) {
                     $conditions[] = trim($currentCondition, " \r\n\t\f");
                 }
                 $currentConditions = [""];
                 $currentConditionKeys = [0];
             }
             $i += 4 - 1;
         } else {
             if ($groupsOpened > 0) {
                 $subConditionList .= $char;
             } else {
                 foreach ($currentConditionKeys as $index) {
                     $currentConditions[$index] .= $char;
                 }
             }
         }
     }
     foreach ($currentConditions as $currentCondition) {
         $conditions[] = trim($currentCondition, " \r\n\t\f");
     }
     return $conditions;
 }
Exemple #17
0
/** @return Placeholder */
function …()
{
    return Placeholder::create();
}
<?php
// Include placeholder generator class
require('placeholder.class.php');

// Get variables from $_GET
$width           = isset($_GET['w']) ? trim($_GET['w']) : null;
$height          = isset($_GET['h']) ? trim($_GET['h']) : null;
$backgroundColor = isset($_GET['bgColor']) ? strtolower(trim($_GET['bgColor'])) : null;
$textColor       = isset($_GET['textColor']) ? strtolower(trim($_GET['textColor'])) : null;
$cache			 = isset($_GET['c']) && $_GET['c'] == 1 ? true : false;

try {
    $placeholder = new Placeholder();
    $placeholder->setWidth($width);
    $placeholder->setHeight($height);
	$placeholder->setCache($cache);
    if ($backgroundColor) $placeholder->setBackgroundColor($backgroundColor);
    if ($textColor) $placeholder->setTextColor($textColor);
    $placeholder->render();
} catch (Exception $e){
    die($e->getMessage());
}
 protected function OnPreRender()
 {
     # Build up child option controls for the select list
     $options = array();
     # Add blank option if requested
     if ($this->b_blank) {
         $options[] = new XhtmlOption();
     }
     # Loop through options, converting group names to option groups
     $current_group_name = '';
     $current_group = null;
     foreach ($this->GetControls() as $option) {
         /* @var $option XhtmlOption */
         # Same group as last option
         if ($option->GetGroupName() === $current_group_name) {
             if ($current_group_name) {
                 # Add option to the group
                 $current_group->AddControl($option);
             } else {
                 # It's not in a group
                 $options[] = $option;
             }
         } else {
             # Different group than last option
             if (!is_null($current_group)) {
                 $options[] = $current_group;
             }
             # If it's another group, create the group
             if ($option->GetGroupName()) {
                 $current_group_name = $option->GetGroupName();
                 $current_group = new XhtmlElement('optgroup', $option);
                 $current_group->AddAttribute('label', $current_group_name);
             } else {
                 # If we're now out of a group, clear the current groups
                 $current_group_name = '';
                 $current_group = null;
                 $options[] = $option;
             }
         }
     }
     # Add the final group, if there is one
     if (!is_null($current_group)) {
         $options[] = $current_group;
     }
     # Move child controls into select list
     $this->o_select->SetControls($options);
     $no_controls = array();
     $this->SetControls($no_controls);
     # Add select list to this control
     if ($this->GetLabel()) {
         if ($this->b_hide_label) {
             $o_label = new XhtmlElement('label');
             $o_label->SetCssClass('aural');
             $o_label->AddAttribute('for', $this->o_select->GetXhtmlId());
             $o_label->AddControl($this->GetLabel() . ' ');
             $this->AddControl($o_label);
             $this->AddControl($this->o_select);
         } else {
             $o_label = new XhtmlElement('label');
             $o_label->AddAttribute('for', $this->o_select->GetXhtmlId());
             $o_label->AddControl($this->GetLabel() . ' ');
             $o_label->AddControl($this->o_select);
             $this->AddControl($o_label);
         }
     } else {
         $this->AddControl($this->o_select);
     }
     parent::OnPreRender();
 }