Commit: f8d7a46022c01e0ac4c3143bc573b90ada6cde42 Author: Sara Golemon <poll...@php.net> Fri, 27 Nov 2020 14:33:41 +0000 Parents: 99eb7625278d4a88d449553b20ed282a401cd356 Branches: master
Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=f8d7a46022c01e0ac4c3143bc573b90ada6cde42 Log: Refactor php8 announcement helpers into common include file Changed paths: M include/layout.inc A releases/8.0/common.php M releases/8.0/de.php M releases/8.0/en.php M releases/8.0/fr.php M releases/8.0/pt_BR.php M releases/8.0/ru.php M releases/8.0/zh.php
diff --git a/include/layout.inc b/include/layout.inc index 2968e9b6d..e8e741c3b 100644 --- a/include/layout.inc +++ b/include/layout.inc @@ -706,41 +706,4 @@ function doc_toc_title($lang, $index, $file, $elm = "dt") { echo "<$elm><a href='/manual/$lang/$link'>$title</a></$elm>\n"; } - -function release_language_chooser($currentlang) { - $LANGUAGES = array( - 'en' => 'English', - 'pt_BR' => 'Brazilian Portuguese', - 'de' => 'German', - 'fr' => 'French', - 'ru' => 'Russian', - 'zh' => 'Chinese Simplified', - ); - - // Print out the form with all the options - $format_options = function () use ($currentlang, $LANGUAGES) { - $out = ''; - $tab = str_repeat(' ', 6); - foreach ($LANGUAGES as $lang => $text) { - $selected = ''; - if ($lang == $currentlang) { - $selected = ' selected="selected"'; - } - $out .= "$tab<option value='$lang'$selected>$text</option>\n"; - } - return trim($out); - }; - $r = <<<CHANGE_LANG - <form action="" method="get" id="changelang" name="changelang"> - <fieldset> - <label for="changelang-langs">Change language:</label> - <select onchange="document.changelang.submit()" name="lang" id="changelang-langs"> - {$format_options()} - </select> - </fieldset> - </form> -CHANGE_LANG; - return trim($r); -} - /* vim: set et ts=4 sw=4 ft=php: : */ diff --git a/releases/8.0/common.php b/releases/8.0/common.php new file mode 100644 index 000000000..914a7b270 --- /dev/null +++ b/releases/8.0/common.php @@ -0,0 +1,87 @@ +<?php declare(strict_types=1); + +namespace releases\php80; +include_once __DIR__ . '/../../include/prepend.inc'; + +function language_redirect(string $currentLang): void { + global $LANG; + + // At the time of writing, $LANG is safely ^\w{2}(-\w{2})?$ + // However, since it may be user-sourced, + // be extra careful about how we use it. + $baseLANG = basename($LANG); + $urlLANG = urlencode($LANG); + + if ($LANG === $currentLang) { + // We're on the right page for our language. Stay here. + return; + } + + if (file_exists(__DIR__ . "/$baseLANG.php")) { + \mirror_redirect("/releases/8.0/$urlLANG.php?lang=$urlLANG"); + exit; + } + + // We don't have a translation as requested, + // so soldier on with this one. + return; +} + +function common_header(string $description): void { + global $MYSITE; + + $meta_image_path = \htmlspecialchars( + \filter_var($MYSITE . 'images/php8/php_8_released.png', \FILTER_VALIDATE_URL)); + $meta_description = \htmlspecialchars($description); + + \site_header("PHP 8.0.0 Release Announcement", [ + 'current' => 'php8', + 'css' => ['php8.css'], + 'meta_tags' => <<<META +<meta name="twitter:card" content="summary_large_image" /> +<meta name="twitter:site" content="@official_php" /> +<meta name="twitter:title" content="PHP 8.0 Released" /> +<meta name="twitter:description" content="{$meta_description}" /> +<meta name="twitter:creator" content="@official_php" /> +<meta name="twitter:image:src" content="{$meta_image_path}" /> + +<meta itemprop="name" content="PHP 8.0 Released" /> +<meta itemprop="description" content="{$meta_description}" /> +<meta itemprop="image" content="{$meta_image_path}" /> + +<meta property="og:image" content="{$meta_image_path}" /> +<meta property="og:description" content="{$meta_description}" /> +META + ]); +} + +function language_chooser(string $currentLang): void { + $LANGUAGES = [ + 'en' => 'English', + 'pt_BR' => 'Brazilian Portuguese', + 'de' => 'German', + 'fr' => 'French', + 'ru' => 'Russian', + 'zh' => 'Chinese Simplified', + ]; + + // Print out the form with all the options + echo ' + <form action="" method="get" id="changelang" name="changelang"> + <fieldset> + <label for="changelang-langs">Change language:</label> + <select onchange="document.changelang.submit()" name="lang" id="changelang-langs"> +'; + + $tab = ' '; + foreach ($LANGUAGES as $lang => $text) { + $selected = ($lang === $currentLang) ? ' selected="selected"' : ''; + echo $tab, "<option value='$lang'$selected>$text</option>\n"; + } + + echo ' </select> + </fieldset> + </form> +'; +} + diff --git a/releases/8.0/de.php b/releases/8.0/de.php index bb6d319ba..8769cc14f 100644 --- a/releases/8.0/de.php +++ b/releases/8.0/de.php @@ -1,41 +1,20 @@ <?php $_SERVER['BASE_PAGE'] = 'releases/8.0/de.php'; -include_once __DIR__ . '/../../include/prepend.inc'; +include_once __DIR__ . '/common.php'; -if ($LANG === 'en') { - mirror_redirect('/releases/8.0/en.php?lang=en'); -} - -if (($LANG !== 'de') && file_exists(__DIR__ . '/' . basename($LANG) . '.php')) { - mirror_redirect('/releases/8.0/' . urlencode($LANG) . '.php?lang=' . urlencode($LANG)); -} - -$meta_image_path = $MYSITE . 'images/php8/php_8_released.png'; -$meta_description = 'PHP 8.0 ist ein Major-Update der Sprache PHP. Es beinhaltet viele neue Funktionen und Optimierungen wie beispielsweise Named Arguments, Union Types, Attribute, Constructor Property Promotion, Match Ausdrücke, Nullsafe Operator, JIT und Verbesserungen des Typen-Systems, der Fehlerbehandlung und der Konsistenz.'; -site_header("PHP 8.0.0 Release Announcement", array( - "current" => "php8", - 'css' => array('php8.css'), - 'meta_tags' => <<<META -<meta name="twitter:card" content="summary_large_image" /> -<meta name="twitter:site" content="@official_php" /> -<meta name="twitter:title" content="PHP 8.0 Released" /> -<meta name="twitter:description" content="{$meta_description}" /> -<meta name="twitter:creator" content="@official_php" /> -<meta name="twitter:image:src" content="{$meta_image_path}" /> - -<meta itemprop="name" content="PHP 8.0 Released" /> -<meta itemprop="description" content="{$meta_description}" /> -<meta itemprop="image" content="{$meta_image_path}" /> +releases\php80\language_redirect('de'); +releases\php80\common_header( + 'PHP 8.0 ist ein Major-Update der Sprache PHP. ' . + 'Es beinhaltet viele neue Funktionen und Optimierungen wie beispielsweise ' . + 'Named Arguments, Union Types, Attribute, Constructor Property Promotion, ' . + 'Match Ausdrücke, Nullsafe Operator, JIT und Verbesserungen des Typen-Systems, ' . + 'der Fehlerbehandlung und der Konsistenz.'); -<meta property="og:image" content="{$meta_image_path}" /> -<meta property="og:description" content="{$meta_description}" /> -META -)); ?> <section class="php8-section php8-section_dark php8-section_header center"> <div class="page-tools"> <div class="change-language"> - <?php echo release_language_chooser($LANG); ?> + <?php releases\php80\language_chooser('de'); ?> </div> </div> <div class="php8-section__content"> diff --git a/releases/8.0/en.php b/releases/8.0/en.php index 6c3cfdd40..a09fc57f7 100644 --- a/releases/8.0/en.php +++ b/releases/8.0/en.php @@ -1,37 +1,21 @@ <?php $_SERVER['BASE_PAGE'] = 'releases/8.0/en.php'; -include_once __DIR__ . '/../../include/prepend.inc'; +include_once __DIR__ . '/common.php'; -if (($LANG !== 'en') && file_exists(__DIR__ . '/' . basename($LANG) . '.php')) { - mirror_redirect('/releases/8.0/' . urlencode($LANG) . '.php?lang=' . urlencode($LANG)); -} - -$meta_image_path = $MYSITE . 'images/php8/php_8_released.png'; -$meta_description = 'PHP 8.0 is a major update of the PHP language. It contains many new features and optimizations including named arguments, union types, attributes, constructor property promotion, match expression, nullsafe operator, JIT, and improvements in the type system, error handling, and consistency.'; -site_header("PHP 8.0.0 Release Announcement", array( - "current" => "php8", - 'css' => array('php8.css'), - 'meta_tags' => <<<META -<meta name="twitter:card" content="summary_large_image" /> -<meta name="twitter:site" content="@official_php" /> -<meta name="twitter:title" content="PHP 8.0 Released" /> -<meta name="twitter:description" content="{$meta_description}" /> -<meta name="twitter:creator" content="@official_php" /> -<meta name="twitter:image:src" content="{$meta_image_path}" /> +releases\php80\language_redirect('en'); -<meta itemprop="name" content="PHP 8.0 Released" /> -<meta itemprop="description" content="{$meta_description}" /> -<meta itemprop="image" content="{$meta_image_path}" /> +releases\php80\common_header( + 'PHP 8.0 is a major update of the PHP language. ' . + 'It contains many new features and optimizations including ' . + 'named arguments, union types, attributes, constructor property promotion, ' . + 'match expression, nullsafe operator, JIT, and ' . + 'improvements in the type system, error handling, and consistency.'); -<meta property="og:image" content="{$meta_image_path}" /> -<meta property="og:description" content="{$meta_description}" /> -META -)); ?> <section class="php8-section php8-section_dark php8-section_header center"> <div class="page-tools"> <div class="change-language"> - <?php echo release_language_chooser($LANG); ?> + <?php releases\php80\language_chooser('en'); ?> </div> </div> <div class="php8-section__content"> diff --git a/releases/8.0/fr.php b/releases/8.0/fr.php index 6008de68c..4b031451c 100644 --- a/releases/8.0/fr.php +++ b/releases/8.0/fr.php @@ -1,37 +1,22 @@ <?php $_SERVER['BASE_PAGE'] = 'releases/8.0/en.php'; -include_once __DIR__ . '/../../include/prepend.inc'; +include_once __DIR__ . '/common.php'; -if (($LANG !== 'fr') && file_exists(__DIR__ . '/' . basename($LANG) . '.php')) { - mirror_redirect('/releases/8.0/' . urlencode($LANG) . '.php?lang=' . urlencode($LANG)); -} - -$meta_image_path = $MYSITE . 'images/php8/php_8_released.png'; -$meta_description = "PHP 8.0 est une mise à jour majeure du langage PHP. Elle contient beaucoup de nouvelle fonctionnalités et d'optimisations, incluant les arguments nommés, les types d'union, attributs, promotion de propriétés de constructeur, l'expression match, l'opérateur nullsafe, JIT (Compilation à la Volée), et des améliorations dans le système de typage, la gestion d'erreur, et de cohérence."; -site_header("Annonce de la Sortie de PHP 8.0.0", array( - "current" => "php8", - 'css' => array('php8.css'), - 'meta_tags' => <<<META -<meta name="twitter:card" content="summary_large_image" /> -<meta name="twitter:site" content="@official_php" /> -<meta name="twitter:title" content="PHP 8.0 Released" /> -<meta name="twitter:description" content="{$meta_description}" /> -<meta name="twitter:creator" content="@official_php" /> -<meta name="twitter:image:src" content="{$meta_image_path}" /> - -<meta itemprop="name" content="PHP 8.0 Released" /> -<meta itemprop="description" content="{$meta_description}" /> -<meta itemprop="image" content="{$meta_image_path}" /> +releases\php80\language_redirect('fr'); +releases\php80\common_header( + "PHP 8.0 est une mise à jour majeure du langage PHP. " . + "Elle contient beaucoup de nouvelle fonctionnalités et d'optimisations, " . + "incluant les arguments nommés, les types d'union, attributs, " . + "promotion de propriétés de constructeur, l'expression match, " . + "l'opérateur nullsafe, JIT (Compilation à la Volée), " . + "et des améliorations dans le système de typage, " . + "la gestion d'erreur, et de cohérence."); -<meta property="og:image" content="{$meta_image_path}" /> -<meta property="og:description" content="{$meta_description}" /> -META -)); ?> <section class="php8-section php8-section_dark php8-section_header center"> <div class="page-tools"> <div class="change-language"> - <?php echo release_language_chooser($LANG); ?> + <?php releases\php80\language_chooser('fr'); ?> </div> </div> <div class="php8-section__content"> diff --git a/releases/8.0/pt_BR.php b/releases/8.0/pt_BR.php index 398abdf2f..fccd5d345 100644 --- a/releases/8.0/pt_BR.php +++ b/releases/8.0/pt_BR.php @@ -1,41 +1,21 @@ <?php $_SERVER['BASE_PAGE'] = 'releases/8.0/pt_BR.php'; -include_once __DIR__ . '/../../include/prepend.inc'; +include_once __DIR__ . '/common.php'; -if ($LANG === 'en') { - mirror_redirect('/releases/8.0/en.php?lang=en'); -} - -if (($LANG !== 'pt_BR') && file_exists(__DIR__ . '/' . basename($LANG) . '.php')) { - mirror_redirect('/releases/8.0/' . urlencode($LANG) . '.php?lang=' . urlencode($LANG)); -} - -$meta_image_path = $MYSITE . 'images/php8/php_8_released.png'; -$meta_description = 'PHP 8.0 é uma atualização importante da linguagem PHP. Ela contém muitos novos recursos e otimizações, incluindo argumentos nomeados, união de tipos, atributos, promoção de propriedade do construtor, expressão match, operador nullsafe, JIT e melhorias no sistema de tipos, tratamento de erros e consistência.'; -site_header("PHP 8.0.0 Release Announcement", array( - "current" => "php8", - 'css' => array('php8.css'), - 'meta_tags' => <<<META -<meta name="twitter:card" content="summary_large_image" /> -<meta name="twitter:site" content="@official_php" /> -<meta name="twitter:title" content="PHP 8.0 Released" /> -<meta name="twitter:description" content="{$meta_description}" /> -<meta name="twitter:creator" content="@official_php" /> -<meta name="twitter:image:src" content="{$meta_image_path}" /> - -<meta itemprop="name" content="PHP 8.0 Released" /> -<meta itemprop="description" content="{$meta_description}" /> -<meta itemprop="image" content="{$meta_image_path}" /> +releases\php80\language_redirect('pt_BR'); +releases\php80\common_header( + 'PHP 8.0 é uma atualização importante da linguagem PHP. ' . + 'Ela contém muitos novos recursos e otimizações, ' . + 'incluindo argumentos nomeados, união de tipos, atributos, ' . + 'promoção de propriedade do construtor, expressão match, ' . + 'operador nullsafe, JIT e melhorias no sistema de tipos, ' . + 'tratamento de erros e consistência.'); -<meta property="og:image" content="{$meta_image_path}" /> -<meta property="og:description" content="{$meta_description}" /> -META -)); ?> <section class="php8-section php8-section_dark php8-section_header center"> <div class="page-tools"> <div class="change-language"> - <?php echo release_language_chooser($LANG); ?> + <?php releases\php80\language_chooser('pt_BR'); ?> </div> </div> <div class="php8-section__content"> diff --git a/releases/8.0/ru.php b/releases/8.0/ru.php index 3befb18e2..52c20052d 100644 --- a/releases/8.0/ru.php +++ b/releases/8.0/ru.php @@ -1,41 +1,21 @@ <?php $_SERVER['BASE_PAGE'] = 'releases/8.0/ru.php'; -include_once __DIR__ . '/../../include/prepend.inc'; +include_once __DIR__ . '/common.php'; -if ($LANG === 'en') { - mirror_redirect('/releases/8.0/en.php?lang=en'); -} - -if (($LANG !== 'ru') && file_exists(__DIR__ . '/' . basename($LANG) . '.php')) { - mirror_redirect('/releases/8.0/' . urlencode($LANG) . '.php?lang=' . urlencode($LANG)); -} - -$meta_image_path = $MYSITE . 'images/php8/php_8_released.png'; -$meta_description = 'PHP 8.0 — большое обновление языка PHP. Оно содержит множество новых возможностей и оптимизаций, включая именованные аргументы, union type, атрибуты, упрощённое определение свойств в конструкторе, выражение match, оператор nullsafe, JIT и улучшения в системе типов, обработке ошибок и консистентности.'; -site_header("PHP 8.0.0 Release Announcement", array( - "current" => "php8", - 'css' => array('php8.css'), - 'meta_tags' => <<<META -<meta name="twitter:card" content="summary_large_image" /> -<meta name="twitter:site" content="@official_php" /> -<meta name="twitter:title" content="PHP 8.0 релиз" /> -<meta name="twitter:description" content="{$meta_description}" /> -<meta name="twitter:creator" content="@official_php" /> -<meta name="twitter:image:src" content="{$meta_image_path}" /> - -<meta itemprop="name" content="PHP 8.0 релиз" /> -<meta itemprop="description" content="{$meta_description}" /> -<meta itemprop="image" content="{$meta_image_path}" /> +releases\php80\language_redirect('ru'); +releases\php80\common_header( + 'PHP 8.0 — большое обновление языка PHP. ' . + 'Оно содержит множество новых возможностей и оптимизаций, ' . + 'включая именованные аргументы, union type, атрибуты, ' . + 'упрощённое определение свойств в конструкторе, выражение match, ' . + 'оператор nullsafe, JIT и улучшения в системе типов, ' . + 'обработке ошибок и консистентности.'); -<meta property="og:image" content="{$meta_image_path}" /> -<meta property="og:description" content="{$meta_description}" /> -META -)); ?> <section class="php8-section php8-section_dark php8-section_header center"> <div class="page-tools"> <div class="change-language"> - <?php echo release_language_chooser($LANG); ?> + <?php releases\php80\language_chooser('ru'); ?> </div> </div> <div class="php8-section__content"> diff --git a/releases/8.0/zh.php b/releases/8.0/zh.php index 8467201a7..ea368db7c 100644 --- a/releases/8.0/zh.php +++ b/releases/8.0/zh.php @@ -1,35 +1,18 @@ <?php -$_SERVER['BASE_PAGE'] = 'releases/8.0/en.php'; -include_once __DIR__ . '/../../include/prepend.inc'; +$_SERVER['BASE_PAGE'] = 'releases/8.0/zh.php'; +include_once __DIR__ . '/common.php'; -if (($LANG !== 'zh') && file_exists(__DIR__ . '/' . basename($LANG) . '.php')) { - mirror_redirect('/releases/8.0/' . urlencode($LANG) . '.php?lang=' . urlencode($LANG)); -} +releases\php80\language_redirect('zh'); +releases\php80\common_header( + 'PHP 8.0 是 PHP 语言的一个主版本更新。它包含了很多新功能与优化项,' . + '包括命名参数、联合类型、注解、构造器属性提升、match 表达式、' . + 'Nullsafe 运算符、JIT,并改进了类型系统、错误处理、语法一致性。'); -$meta_image_path = $MYSITE . 'images/php8/php_8_released.png'; -$meta_description = 'PHP 8.0 是 PHP 语言的一个主版本更新。它包含了很多新功能与优化项,包括命名参数、联合类型、注解、构造器属性提升、match 表达式、Nullsafe 运算符、JIT,并改进了类型系统、错误处理、语法一致性。'; -site_header("PHP 8.0.0 发布公告", array( - "current" => "php8", - 'css' => array('php8.css'), - 'meta_tags' => <<<META -<meta name="twitter:card" content="summary_large_image" /> -<meta name="twitter:site" content="@official_php" /> -<meta name="twitter:title" content="PHP 8.0 已发布" /> -<meta name="twitter:description" content="{$meta_description}" /> -<meta name="twitter:creator" content="@official_php" /> -<meta name="twitter:image:src" content="{$meta_image_path}" /> -<meta itemprop="name" content="PHP 8.0 Released" /> -<meta itemprop="description" content="{$meta_description}" /> -<meta itemprop="image" content="{$meta_image_path}" /> -<meta property="og:image" content="{$meta_image_path}" /> -<meta property="og:description" content="{$meta_description}" /> -META -)); ?> <section class="php8-section php8-section_dark php8-section_header center"> <div class="page-tools"> <div class="change-language"> - <?php echo release_language_chooser($LANG); ?> + <?php releases\php80\language_chooser('zh'); ?> </div> </div> <div class="php8-section__content"> @@ -506,4 +489,4 @@ array_chunk([], -1); // ValueError: array_chunk(): Argument #2 ($length) must be -<?php site_footer(); \ No newline at end of file +<?php site_footer();
-- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php