xref: /web-php/my.php (revision c093fb53)
1<?php
2$_SERVER['BASE_PAGE'] = 'my.php';
3include_once __DIR__ . '/include/prepend.inc';
4
5// Try to make this page non-cached
6header_nocache();
7
8// Languages array copy and options to list
9$langs = $ACTIVE_ONLINE_LANGUAGES;
10$options = [];
11
12// We have post data, and it is an available language
13if (isset($_POST['my_lang'], $langs[$_POST['my_lang']])) {
14
15    // Set the language preference
16    $MYPHPNET[0] = $_POST['my_lang'];
17
18    // Add this as first option, selected
19    $options[] = '<option value="' . $_POST['my_lang'] . '" selected>' .
20                 $langs[$_POST['my_lang']] . "</option>\n";
21
22    // Remove, so it is not listed two times
23    unset($langs[$_POST['my_lang']]);
24}
25
26// We have received a cookie and it is an available language
27elseif (isset($langs[myphpnet_language()])) {
28
29    // Add this as first option, selected
30    $options[] = '<option value="' . myphpnet_language() . '" selected>' .
31                 $langs[myphpnet_language()] . "</option>\n";
32
33    // Remove, so it is not listed two times
34    unset($langs[myphpnet_language()]);
35}
36
37// We have no cookie and no form submitted
38else {
39    // Add this as first option, selected
40    $options[] = "<option value=\"not_set\" selected=\"selected\">Not Set</option>\n";
41}
42
43// Add all other languages
44foreach ($langs as $code => $name) {
45    $options[] = '<option value="' . $code . '">' . $name . "</option>\n";
46}
47
48// Assemble form from collected data
49$langpref = "<select id=\"form-my_lang\" name=\"my_lang\">\n" .
50            implode("", $options) . "</select>\n";
51
52// Save URL shortcut fallback setting
53if (isset($_POST['urlsearch'])) {
54    myphpnet_urlsearch($_POST['urlsearch']);
55}
56
57if (isset($_POST["showug"])) {
58    myphpnet_showug($_POST["showug"] === "enable");
59}
60
61// Prepare mirror array
62$mirror_sites = $MIRRORS;
63$mirror_sites["NONE"] = [7 => MIRROR_OK];
64
65myphpnet_save();
66
67site_header("My PHP.net", ["current" => "community"]);
68?>
69
70<form action="/my.php" method="post">
71<h1>My PHP.net</h1>
72
73<p>
74 This page allows you to customize the PHP.net site.
75</p>
76
77<?php if (!is_official_mirror()) { ?>
78<p class="warn">
79 This is not an official PHP.net mirror site, and therefore the settings
80 you set and see here will <strong>not</strong> be effective on any
81 official PHP.net mirror site. The settings you specify here are only
82 going to be active for this URL, and only if you have cookies enabled.
83</p>
84<?php } else { ?>
85<p>
86 These settings are cookie-based and will work on all official PHP.net
87 mirror sites.
88</p>
89<?php } ?>
90
91<h2>Preferred language</h2>
92
93<p>
94 If you use a shortcut or search for a function, the language used
95 is determined by checking for the following settings. The list is
96 in priority order, the first is the most important. Normally you don't
97 need to set your preferred language, as your last seen language is
98 always remembered, and is a good estimate of your preferred language
99 most of the time.
100</p>
101
102<div class="indent">
103<table border="0" cellpadding="3" cellspacing="2" class="standard">
104<?php
105
106// Data for the language settings table
107$langinfo = [
108
109    "<label for=\"form-my_lang\">Your preferred language</label>" =>
110    $langpref,
111
112    "Last seen language" =>
113    (isset($_COOKIE['LAST_LANG']) ? htmlentities($_COOKIE['LAST_LANG'], ENT_QUOTES | ENT_IGNORE, 'UTF-8') : "None"),
114
115    "Your Accept-Language browser setting" =>
116    (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? htmlentities($_SERVER['HTTP_ACCEPT_LANGUAGE'], ENT_QUOTES | ENT_IGNORE, 'UTF-8') : "None"),
117
118    "The mirror's default language" =>
119    default_language(),
120
121    "Default" => "en",
122];
123
124// Write a row for all settings
125foreach ($langinfo as $lin => $lid) {
126    echo " <tr>\n  <td class=\"sub\">" . $lin . "</td>\n";
127    echo "  <td>" . $lid . "</td>\n </tr>\n";
128}
129
130?>
131</table>
132</div>
133
134<p>
135 These settings are only overridden in case you have passed a language
136 setting URL parameter or POST data to a page or you are viewing a manual
137 page in a particular language. In these cases, the explicit specification
138 overrides the language selected from the above list.
139</p>
140
141<p>
142 The language setting is honored when you use a
143 <a href="/urlhowto.php">URL shortcut</a>, when you start
144 a function list search on a non-manual page, when you visit
145 the <a href="/download-docs.php">manual download</a> or
146 <a href="/docs.php">language selection</a> pages, etc.
147</p>
148
149<h2>Your country</h2>
150
151<p>
152 The PHP.net site tries to detect your country
153 using the <a href="http://www.directi.com/?site=ip-to-country">Directi
154 Ip-to-Country Database</a>. This information is used to mark
155 the events in your country specially.
156</p>
157
158<div class="indent">
159<?php
160if (i2c_valid_country()) {
161    echo "We detected that you are from <b>" . $COUNTRIES[$COUNTRY] . "</b>";
162} else {
163    echo "We were unable to detect your country";
164}
165?>
166</div>
167
168<h2>URL search fallback</h2>
169
170<p>
171 When you try to access a PHP.net page via a URL shortcut, and
172 the site is unable to find that particular page, it falls back
173 to a documentation search, or a function list lookup, depending on
174 your choice. The default is a function list lookup, as most of
175 the URL shortcut users try to access function documentation pages.
176</p>
177
178<div class="indent">
179 Your setting: <input id="form-urlsearch-quickref" type="radio" name="urlsearch" value="quickref"
180<?php
181$type = myphpnet_urlsearch();
182if ($type === MYPHPNET_URL_NONE || $type === MYPHPNET_URL_FUNC) {
183    echo ' checked="checked"';
184}
185echo '> <label for="form-urlsearch-quickref">Function list search</label> <input id="form-urlsearch-manual" type="radio" name="urlsearch" value="manual"';
186if ($type === MYPHPNET_URL_MANUAL) {
187    echo ' checked="checked"';
188}
189?>
190> <label for="form-urlsearch-manual">PHP Documentation search</label>
191</div>
192
193<br>
194<h2>User Group tips</h2>
195
196<p>
197We are experimenting with listing nearby user groups. This feature is highly experimental
198and will very likely change a lot and be broken at times.
199</p>
200<label for="showugenable">Enable UG tips</label> <input type="radio" name="showug" id="showugenable" value="enable" <?php echo myphpnet_showug() ? "checked=checked" : "" ?>><br>
201<label for="showugdisable">Disable UG tips</label> <input type="radio" name="showug" id="showugdisable" value="disable" <?php echo myphpnet_showug() ? "" : "checked=checked" ?>>
202
203<p class="center">
204 <input type="submit" value="Set All Preferences">
205</p>
206</form>
207
208<?php site_footer(); ?>
209