1<?php 2 3use phpweb\I18n\Languages; 4use phpweb\UserPreferences; 5 6$_SERVER['BASE_PAGE'] = 'my.php'; 7include_once __DIR__ . '/include/prepend.inc'; 8 9// Try to make this page non-cached 10header_nocache(); 11 12// Languages array copy and options to list 13$langs = Languages::ACTIVE_ONLINE_LANGUAGES; 14$options = []; 15 16// We have post data, and it is an available language 17if (isset($_POST['my_lang'], $langs[$_POST['my_lang']])) { 18 19 // Set the language preference 20 $userPreferences->languageCode = $_POST['my_lang']; 21 22 // Add this as first option, selected 23 $options[] = '<option value="' . $_POST['my_lang'] . '" selected>' . 24 $langs[$_POST['my_lang']] . "</option>\n"; 25 26 // Remove, so it is not listed two times 27 unset($langs[$_POST['my_lang']]); 28} 29 30// We have received a cookie and it is an available language 31elseif (isset($langs[$userPreferences->languageCode])) { 32 33 // Add this as first option, selected 34 $options[] = '<option value="' . $userPreferences->languageCode . '" selected>' . 35 $langs[$userPreferences->languageCode] . "</option>\n"; 36 37 // Remove, so it is not listed two times 38 unset($langs[$userPreferences->languageCode]); 39} 40 41// We have no cookie and no form submitted 42else { 43 // Add this as first option, selected 44 $options[] = "<option value=\"not_set\" selected=\"selected\">Not Set</option>\n"; 45} 46 47// Add all other languages 48foreach ($langs as $code => $name) { 49 $options[] = '<option value="' . $code . '">' . $name . "</option>\n"; 50} 51 52// Assemble form from collected data 53$langpref = "<select id=\"form-my_lang\" name=\"my_lang\">\n" . 54 implode("", $options) . "</select>\n"; 55 56// Save URL shortcut fallback setting 57if (isset($_POST['urlsearch'])) { 58 $userPreferences->setUrlSearchType($_POST['urlsearch']); 59} 60 61if (isset($_POST["showug"])) { 62 $userPreferences->setIsUserGroupTipsEnabled($_POST["showug"] === "enable"); 63} 64 65// Prepare mirror array 66$mirror_sites = $MIRRORS; 67$mirror_sites["NONE"] = [7 => MIRROR_OK]; 68 69$userPreferences->save(); 70 71site_header("My PHP.net", ["current" => "community"]); 72?> 73 74<form action="/my.php" method="post"> 75<h1>My PHP.net</h1> 76 77<p> 78 This page allows you to customize the PHP.net site. 79</p> 80 81<?php if (!is_official_mirror()) { ?> 82<p class="warn"> 83 This is not an official PHP.net mirror site, and therefore the settings 84 you set and see here will <strong>not</strong> be effective on any 85 official PHP.net mirror site. The settings you specify here are only 86 going to be active for this URL, and only if you have cookies enabled. 87</p> 88<?php } else { ?> 89<p> 90 These settings are cookie-based and will work on all official PHP.net 91 mirror sites. 92</p> 93<?php } ?> 94 95<h2>Preferred language</h2> 96 97<p> 98 If you use a shortcut or search for a function, the language used 99 is determined by checking for the following settings. The list is 100 in priority order, the first is the most important. Normally you don't 101 need to set your preferred language, as your browser's language preferences 102 are detected automatically using the Accept-Language header. 103</p> 104 105<div class="indent"> 106<table border="0" cellpadding="3" cellspacing="2" class="standard"> 107<?php 108 109// Data for the language settings table 110$langinfo = [ 111 112 "<label for=\"form-my_lang\">Your preferred language</label>" => 113 $langpref, 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>URL search fallback</h2> 150 151<p> 152 When you try to access a PHP.net page via a URL shortcut, and 153 the site is unable to find that particular page, it falls back 154 to a documentation search, or a function list lookup, depending on 155 your choice. The default is a function list lookup, as most of 156 the URL shortcut users try to access function documentation pages. 157</p> 158 159<div class="indent"> 160 Your setting: <input id="form-urlsearch-quickref" type="radio" name="urlsearch" value="quickref" 161<?php 162$type = $userPreferences->searchType; 163if ($type === UserPreferences::URL_NONE || $type === UserPreferences::URL_FUNC) { 164 echo ' checked="checked"'; 165} 166echo '> <label for="form-urlsearch-quickref">Function list search</label> <input id="form-urlsearch-manual" type="radio" name="urlsearch" value="manual"'; 167if ($type === UserPreferences::URL_MANUAL) { 168 echo ' checked="checked"'; 169} 170?> 171> <label for="form-urlsearch-manual">PHP Documentation search</label> 172</div> 173 174<br> 175<h2>User Group tips</h2> 176 177<p> 178We are experimenting with listing nearby user groups. This feature is highly experimental 179and will very likely change a lot and be broken at times. 180</p> 181<label for="showugenable">Enable UG tips</label> <input type="radio" name="showug" id="showugenable" value="enable" <?php echo $userPreferences->isUserGroupTipsEnabled ? "checked=checked" : "" ?>><br> 182<label for="showugdisable">Disable UG tips</label> <input type="radio" name="showug" id="showugdisable" value="disable" <?php echo $userPreferences->isUserGroupTipsEnabled ? "" : "checked=checked" ?>> 183 184<p class="center"> 185 <input type="submit" value="Set All Preferences"> 186</p> 187</form> 188 189<?php site_footer(); ?> 190