cvs: phpweb / my.php /error index.php /include langchooser.inc prepend.inc site.inc
| From: | Gabor Hojtsy | Date: | Sat, 24 May 2003 19:50:37 +0000 |
| Subject: | cvs: phpweb / my.php /error index.php /include langchooser.inc prepend.inc site.inc | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-18034@lists.php.net to get a copy of this message | ||
goba Sat May 24 15:50:37 2003 EDT
Modified files:
/phpweb my.php
/phpweb/include langchooser.inc prepend.inc site.inc
/phpweb/error index.php
Log:
Comment the BC code for pre 4.1.0 mirrors as we have
them disabled now, so autoglobal vars should work on
all mirrors without special preparation
Use $_SERVER['DOCUMENT_ROOT'] for includes
instead of a user defined constant, as the docroot
value is always available [even before prepend.inc]
This ensures consistency and causes no stat() calls
Add myphpnet_...() functions to load, get/set and save
the user preferences, and use them everywhere. This
enables us to easily add new preferences to the same
cookie. Every preference will last for a year this way,
and the cookie will only be set again, if someone
modifies his data on my.php
If this works nicely, then we can easily add a preferred
mirror site setting (and more)
[These changes seem to work on my local mirror]
Index: phpweb/my.php
diff -u phpweb/my.php:1.15 phpweb/my.php:1.16
--- phpweb/my.php:1.15 Sat May 17 08:52:21 2003
+++ phpweb/my.php Sat May 24 15:50:36 2003
@@ -1,5 +1,5 @@
<?php
-/* $Id: my.php,v 1.15 2003/05/17 12:52:21 goba Exp $ */
+/* $Id: my.php,v 1.16 2003/05/24 19:50:36 goba Exp $ */
include_once "prepend.inc";
@@ -12,8 +12,9 @@
// We have post data, and it is an available language
if (isset($_POST['my_lang']) && isset($langs[$_POST['my_lang']])) {
- // Set the language in a cookie for a year
- mirror_setcookie("MYPHPNET", $_POST['my_lang'], 60*60*24*365);
+ // Set the language preference
+ myphpnet_language($_POST['my_lang']);
+ myphpnet_save();
// Add this as first option, selected
$options[] = '<option value="' . $_POST['my_lang'] . '"
selected>' .
@@ -24,14 +25,14 @@
}
// We have recevied a cookie and it is an available language
-elseif (isset($_COOKIE['MYPHPNET']) &&
isset($langs[$_COOKIE['MYPHPNET']])) {
+elseif (isset($langs[myphpnet_language()])) {
// Add this as first option, selected
- $options[] = '<option value="' . $_COOKIE['MYPHPNET'] .
'" selected>' .
- $langs[$_COOKIE['MYPHPNET']] . "</option>\n";
+ $options[] = '<option value="' . myphpnet_language() . '"
selected>' .
+ $langs[myphpnet_language()] . "</option>\n";
// Remove, so it is not listed two times
- unset($langs[$_COOKIE['MYPHPNET']]);
+ unset($langs[myphpnet_language()]);
}
// We have no cookie and no form submitted
Index: phpweb/include/langchooser.inc
diff -u phpweb/include/langchooser.inc:1.26 phpweb/include/langchooser.inc:1.27
--- phpweb/include/langchooser.inc:1.26 Sat May 17 08:46:44 2003
+++ phpweb/include/langchooser.inc Sat May 24 15:50:37 2003
@@ -1,6 +1,6 @@
<?php // -*- C++ -*-
-// $Id: langchooser.inc,v 1.26 2003/05/17 12:46:44 goba Exp $
+// $Id: langchooser.inc,v 1.27 2003/05/24 19:50:37 goba Exp $
/*
@@ -88,8 +88,8 @@
}
// Honor the users own language setting (if available)
- if (isset($_COOKIE['MYPHPNET'])) {
- language_add($_COOKIE['MYPHPNET'], $languages);
+ if (myphpnet_language()) {
+ language_add(myphpnet_language(), $languages);
}
// Put the last selected language in the priority order (if available)
Index: phpweb/include/prepend.inc
diff -u phpweb/include/prepend.inc:1.25 phpweb/include/prepend.inc:1.26
--- phpweb/include/prepend.inc:1.25 Fri May 23 09:35:56 2003
+++ phpweb/include/prepend.inc Sat May 24 15:50:37 2003
@@ -1,6 +1,6 @@
<?php // -*- C++ -*-
-// $Id: prepend.inc,v 1.25 2003/05/23 13:35:56 iliaa Exp $
+// $Id: prepend.inc,v 1.26 2003/05/24 19:50:37 goba Exp $
// Start measuring time spent on page
$page_creation_start = getmicrotime();
@@ -20,11 +20,13 @@
unset($LANG);
unset($COUNTRY);
unset($ONLOAD);
+unset($MYPHPNET);
// Backward compatible array creation. After this point, the
// PHP 4.1.0+ arrays can be used to access variables coming
// from outside PHP. But it should be noted that these variables
// are not necessarily superglobals, so they need to be global-ed!
+/*
if (!isset($_SERVER)) {
$_GET = &$HTTP_GET_VARS;
$_POST = &$HTTP_POST_VARS;
@@ -33,30 +35,30 @@
$_COOKIE = &$HTTP_COOKIE_VARS;
$_REQUEST = array_merge($_GET, $_POST, $_COOKIE);
}
+*/
+
+// Load the My PHP.net settings before any includes
+myphpnet_load();
// Put the magic quotes setting to $MQ
$MQ = (boolean) get_magic_quotes_gpc();
-/* for performance reasons use this define when including files */
-$path = !strncmp(__FILE__, '/', 1) ? __FILE__ : realpath(__FILE__);
-define('__PHPWEB_INC_PATH__', dirname($path) . '/');
-
// Site details (mirror site information)
-include_once __PHPWEB_INC_PATH__ . 'site.inc';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/include/site.inc';
// Choose language used for translated parts
-include_once __PHPWEB_INC_PATH__ . 'langchooser.inc';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/include/langchooser.inc';
// Get country of the user and set it in a cookie
-include_once __PHPWEB_INC_PATH__ . 'ip-to-country.inc';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/include/ip-to-country.inc';
// Common layout functions
-include_once __PHPWEB_INC_PATH__ . 'layout.inc';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/include/layout.inc';
-// This file is generated on rsync.php.net and propogated
+// This file is generated on rsync.php.net and propagated
// from there. It just defines $LAST_UPDATED, which is the
// mirror's last updated time.
-include_once __PHPWEB_INC_PATH__ . 'last_updated.inc';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/include/last_updated.inc';
// Function used to import request vars to global scope.
// Walks through $array, and imports all values associated
@@ -106,4 +108,43 @@
{
list($usec, $sec) = explode(" ", microtime());
return ((float) $usec + (float) $sec);
+}
+
+// Load in the user preferences
+function myphpnet_load()
+{
+ global $MYPHPNET;
+
+ // Empty the preferences array
+ $MYPHPNET = array();
+
+ // If we have a cookie, set the values in the array
+ if (isset($_COOKIE['MYPHPNET'])) {
+ $MYPHPNET[0] = $_COOKIE['MYPHPNET'];
+ }
+}
+
+// Get or set preferred language code
+function myphpnet_language($langcode = FALSE)
+{
+ global $MYPHPNET;
+
+ // Set language code
+ if ($langcode) {
+ $MYPHPNET[0] = $langcode;
+ }
+ // Return code or FALSE
+ elseif (isset($MYPHPNET[0])) {
+ return $MYPHPNET[0];
+ }
+ else { return FALSE; }
+}
+
+// Save user settings in cookie
+function myphpnet_save()
+{
+ global $MYPHPNET;
+
+ // Set all the preferred values for a year
+ mirror_setcookie("MYPHPNET", join(",", $MYPHPNET), 60*60*24*365);
}
Index: phpweb/include/site.inc
diff -u phpweb/include/site.inc:1.248 phpweb/include/site.inc:1.249
--- phpweb/include/site.inc:1.248 Fri May 23 09:35:56 2003
+++ phpweb/include/site.inc Sat May 24 15:50:37 2003
@@ -1,15 +1,15 @@
<?php // -*- C++ -*-
-// $Id: site.inc,v 1.248 2003/05/23 13:35:56 iliaa Exp $
+// $Id: site.inc,v 1.249 2003/05/24 19:50:37 goba Exp $
// Define $MIRRORS array, and some constants
-include_once __PHPWEB_INC_PATH__ . 'mirrors.inc';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/include/mirrors.inc';
// Define $COUNTRIES array
-include_once __PHPWEB_INC_PATH__ . 'countries.inc';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/include/countries.inc';
// Define $LANGUAGES array
-include_once __PHPWEB_INC_PATH__ . 'languages.inc';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/include/languages.inc';
// Returns true if the current (or specified)
// site is the primary mirror site
Index: phpweb/error/index.php
diff -u phpweb/error/index.php:1.117 phpweb/error/index.php:1.118
--- phpweb/error/index.php:1.117 Sat May 24 07:30:34 2003
+++ phpweb/error/index.php Sat May 24 15:50:37 2003
@@ -1,11 +1,11 @@
<?php
-// $Id: index.php,v 1.117 2003/05/24 11:30:34 goba Exp $
+// $Id: index.php,v 1.118 2003/05/24 19:50:37 goba Exp $
/*
This script handles all 401, 403 and 404 error redirects,
- and some directory requests (like /images). Uses the $LANG
+ and some directory requests (like /images). Uses the
preferred language setting and the REQUEST_URI to guess what
page should be displayed. In case there is no page that can
be displayed, the user is redirected to a search page.
@@ -13,8 +13,8 @@
*/
// Ensure that our environment is set up
-include_once 'prepend.inc';
-include_once __PHPWEB_INC_PATH__ . 'loadavg.inc';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/include/prepend.inc';
+include_once $_SERVER['DOCUMENT_ROOT'] . '/include/loadavg.inc';
// Get URI for this request (without the leading slash)
// See langchooser.inc for more info on STRIPPED_URI