xref: /web-php/releases/8.4/common.php (revision 43b9c293)
1<?php
2
3declare(strict_types=1);
4
5namespace releases\php84;
6
7include_once __DIR__ . '/../../include/prepend.inc';
8
9const LANGUAGES = [
10    'en' => 'English',
11    'fr' => 'Français',
12    'ru' => 'Russian',
13    'pt_BR' => 'Português do Brasil',
14    'nl' => 'Nederlands',
15    'es' => 'Spanish',
16    'uk' => 'Українська',
17    'zh' => '简体中文',
18    'ja' => '日本語',
19];
20
21function common_header(string $description): void {
22    global $MYSITE;
23
24    $meta_image_path = \htmlspecialchars(
25        \filter_var($MYSITE . 'images/php8/php_8_4_released.png', \FILTER_VALIDATE_URL));
26    $meta_description = \htmlspecialchars($description);
27
28    \site_header("PHP 8.4.0 Release Announcement", [
29        'current' => 'php8',
30        'css' => ['php8.css'],
31        'meta_tags' => <<<META
32<meta name="twitter:card" content="summary_large_image" />
33<meta name="twitter:site" content="@official_php" />
34<meta name="twitter:title" content="PHP 8.4 Released" />
35<meta name="twitter:description" content="{$meta_description}" />
36<meta name="twitter:creator" content="@official_php" />
37<meta name="twitter:image:src" content="{$meta_image_path}" />
38
39<meta itemprop="name" content="PHP 8.4 Released" />
40<meta itemprop="description" content="{$meta_description}" />
41<meta itemprop="image" content="{$meta_image_path}" />
42
43<meta property="og:image" content="{$meta_image_path}" />
44<meta property="og:description" content="{$meta_description}" />
45META
46    ]);
47}
48
49function language_chooser(string $currentLang): void {
50    // Print out the form with all the options
51    echo '
52      <form action="" method="get" id="changelang" name="changelang">
53        <fieldset>
54          <label for="changelang-langs">Change language:</label>
55          <select onchange="location = this.value + \'.php\'" name="lang" id="changelang-langs">
56';
57
58    $tab = '            ';
59    foreach (LANGUAGES as $lang => $text) {
60        $selected = ($lang === $currentLang) ? ' selected="selected"' : '';
61        echo $tab, "<option value='$lang'$selected>$text</option>\n";
62    }
63
64    echo '          </select>
65        </fieldset>
66      </form>
67';
68}
69
70function message($code, $language = 'en')
71{
72    $original = require __DIR__ . '/languages/en.php';
73    if (($language !== 'en') && file_exists(__DIR__ . '/languages/' . $language . '.php')) {
74        $translation = require __DIR__ . '/languages/' . $language . '.php';
75    }
76
77    return $translation[$code] ?? $original[$code] ?? $code;
78}
79