cvs: phpweb /include languages.inc site.inc

From: Date: Sat, 21 Dec 2002 12:26:15 +0000
Subject: cvs: phpweb /include languages.inc site.inc
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-14376@lists.php.net to get a copy of this message
goba Sat Dec 21 07:26:15 2002 EDT Added files: /phpweb/include languages.inc Modified files: /phpweb/include site.inc Log: Update site.inc to support new $MIRRORS array element: - Add mirror_status() function to get status of one mirror from the array - Add optional site parameters to mirror functions to get info of one particular mirror. Makes the direct access of the $MIRRORS array in some places removable. - Make constant definitions conditional, in case the new mirror list is used, which defines and uses the constants itself - Move languages list into separate include file (much like mirrors and countries are in separate files) - Use _SERVER array to get site name - Update default mirror array element to new structure

Index: phpweb/include/site.inc diff -u phpweb/include/site.inc:1.229 phpweb/include/site.inc:1.230 --- phpweb/include/site.inc:1.229 Sun Dec 15 16:31:37 2002 +++ phpweb/include/site.inc Sat Dec 21 07:26:15 2002 @@ -1,157 +1,115 @@ <?php -require_once 'mirrors.inc'; -require_once 'countries.inc'; -function is_primary_site() { +// Define $MIRRORS array, and some constants +include_once 'mirrors.inc'; + +// Define $COUNTRIES array +include_once 'countries.inc'; + +// Define $LANGUAGES array +include_once 'languages.inc'; + +// Returns true if the current (or specified) +// site is the primary mirror site +function is_primary_site($site = FALSE) { global $MYSITE; - return $MYSITE == "http://www.php.net/"; + if (!$site) { $site = $MYSITE; } + return $site == "http://www.php.net/"; } -function is_backup_primary() { +// Returns true if the current (or specified) +// site is the backup site of the primary site +function is_backup_primary($site = FALSE) { global $MYSITE; - return $MYSITE == "http://download.php.net/"; + if (!$site) { $site = $MYSITE; } + return $site == "http://download.php.net/"; } -function default_language() { - global $MIRRORS,$MYSITE; - return $MIRRORS[$MYSITE][6]; +// Returns the current (or specified) +// mirror site's default language +function default_language($site = FALSE) { + global $MIRRORS, $MYSITE; + if (!$site) { $site = $MYSITE; } + return $MIRRORS[$site][6]; } -function have_search() { - global $MIRRORS,$MYSITE; - return $MIRRORS[$MYSITE][5]; +// Returns true if the current (or specified) mirror +// site is registered to have local search support +function have_search($site = FALSE) { + global $MIRRORS, $MYSITE; + if (!$site) { $site = $MYSITE; } + return $MIRRORS[$site][5]; } -function have_stats() { - global $MIRRORS,$MYSITE; - return $MIRRORS[$MYSITE][2]; +// Returns true if the current (or specified) mirror +// site is registered to have local stats support +function have_stats($site = FALSE) { + global $MIRRORS, $MYSITE; + if (!$site) { $site = $MYSITE; } + return $MIRRORS[$site][2]; } -function mirror_provider() { - global $MIRRORS,$MYSITE; - return $MIRRORS[$MYSITE][1]; +// Returns the current (or specified) +// mirror site's provider's name +function mirror_provider($site = FALSE) { + global $MIRRORS, $MYSITE; + if (!$site) { $site = $MYSITE; } + return $MIRRORS[$site][1]; } -function mirror_provider_url() { +// Returns the current (or specified) +// mirror site's provider's URL +function mirror_provider_url($site = FALSE) { global $MIRRORS,$MYSITE; - return $MIRRORS[$MYSITE][3]; + if (!$site) { $site = $MYSITE; } + return $MIRRORS[$site][3]; } -define("MIRROR_DOWNLOAD", 0); -define("MIRROR_STANDARD", 1); -define("MIRROR_SPECIAL", 2); +// Define mirror type and status constants +// if they are not already defined (BC) +if (!defined("MIRROR_STANDARD")) { -function mirror_type() { - global $MIRRORS,$MYSITE; - return $MIRRORS[$MYSITE][4]; -} + define('MIRROR_STANDARD', 1); + define('MIRROR_SPECIAL', 2); + + define('MIRROR_OK', 0); + define('MIRROR_NOTACTIVE', 1); + define('MIRROR_OUTDATED', 2); + define('MIRROR_DOESNOTWORK', 3); -function show_mirror_options ($current) { - global $MIRRORS, $COUNTRIES, $REQUEST_URI; - foreach ($MIRRORS as $url => $mirror) { - if ($mirror[4] == 1) { /* only list full mirrors here */ - // If this is the current one, or the REQUEST_URI starts with the URL - // (the server provides a different name as it's name then what is - // used to access it} => selected it by default - if ($url == $current || preg_match("!^$url!", $REQUEST_URI)) { - echo '<option value="' . $url . '" selected>' . $COUNTRIES[$mirror[0]] . - ' (' . $mirror[1] . ") *</option>\n"; - } else { - echo '<option value="' . $url . '">' . $COUNTRIES[$mirror[0]] . - ' (' . $mirror[1] . ")</option>\n"; - } - } - } } -// Find the closest mirror sites (based on mirror country info -// and user TLD), and return with the addresses -function find_closest_mirrors () -{ - global $REMOTE_HOST, $REMOTE_ADDR, $HTTP_X_FORWARDED_FOR, $MIRRORS; - - // We do not know the country - $country = ''; - - // Figure out IP address and hostname - $ipaddr = $HTTP_X_FORWARDED_FOR ? $HTTP_X_FORWARDED_FOR : $REMOTE_ADDR; - $hostname = $REMOTE_HOST; - - // If we have no hostname, or if it's an IP - // address, then try to get that hostname - if (!$hostname || $hostname == $ipaddr) { - $hostname = @gethostbyaddr($ipaddr); - if ($hostname == $ipaddr) { $hostname = ""; } - } - - // If we have that hostname finnaly, get the TLD - if ($hostname) { - if (ereg('([a-zA-Z]+)$', $hostname, $reg)) { - $country = $reg[0]; - } - } +// Returns the current (or specified) +// mirror site's type (use the constants!) +function mirror_type($site = FALSE) { + global $MIRRORS, $MYSITE; + if (!$site) { $site = $MYSITE; } + return $MIRRORS[$site][4]; +} - // These two entires need to be checked - $check_mirrors = array( - "http://" . $country . ".php.net/", - "http://" . $country . "2.php.net/" - ); - - // We do not know about any mirrors here - $found_mirrors = array(); - - // Check for those mirrors - foreach ($check_mirrors as $mirror) { - if (isset($MIRRORS[$mirror])) { - $found_mirrors[] = $mirror; - } - } - - return $found_mirrors; +// Returns the current (or specified) +// mirror site's status (use the constants!) +function mirror_status($site = FALSE) { + global $MIRRORS, $MYSITE; + if (!$site) { $site = $MYSITE; } + return $MIRRORS[$site][7]; } -# http://www.unicode.org/unicode/onlinedat/languages.html -$LANGUAGES = array( - 'en' => 'English', - 'pt_BR' => 'Brazilian Portuguese', - 'bg' => 'Bulgarian', - 'ca' => 'Catalan', - 'zh' => 'Chinese', - 'zh_cn' => 'Chinese', - 'cs' => 'Czech', - 'da' => 'Danish', - 'nl' => 'Dutch', - 'fi' => 'Finnish', - 'fr' => 'French', - 'de' => 'German', - 'el' => 'Greek', - 'hu' => 'Hungarian', - 'in' => 'Indonesian', - 'it' => 'Italian', - 'ja' => 'Japanese', - 'ko' => 'Korean', - 'kr' => 'Korean', # this should be 'ko'. its wrong in phpdoc. - 'lv' => 'Latvian', - 'no' => 'Norwegian', - 'pl' => 'Polish', - 'pt' => 'Portuguese', - 'ro' => 'Romanian', - 'ru' => 'Russian', - 'sk' => 'Slovak', - 'sl' => 'Slovenian', - 'es' => 'Spanish', - 'sv' => 'Swedish', - 'th' => 'Thai', - 'tr' => 'Turkish', - 'uk' => 'Ukranian', -); +// Guess the current site from what Apache tells us +$MYSITE = 'http://' . $_SERVER["SERVER_NAME"] . '/'; -$MYSITE = 'http://' . getenv("SERVER_NAME") . '/'; -if (!isset($MIRRORS[$MYSITE])) { - $MYSITE='http://' . ereg_replace("^www\\.","",$HTTP_HOST) . '/'; -} +// If this site does not exist if (!isset($MIRRORS[$MYSITE])) { - $MIRRORS[$MYSITE] = array("xx", $MYSITE, 0, $MYSITE, 2, 0, "en"); + + // Try the hostname [without www] + $MYSITE = 'http://' . ereg_replace("^www\\.", "", $_SERVER["HTTP_HOST"]) . '/'; + + // If the mirror is not registered with this name, provide defaults + // (no country code, no search, no stats, English default language ...) + if (!isset($MIRRORS[$MYSITE])) { + $MIRRORS[$MYSITE] = array("xx", $MYSITE, FALSE, $MYSITE, MIRROR_SPECIAL, FALSE, "en", MIRROR_OK); + } + } ?> Index: phpweb/include/languages.inc +++ phpweb/include/languages.inc <?php // http://www.unicode.org/unicode/onlinedat/languages.html $LANGUAGES = array( 'en' => 'English', 'pt_BR' => 'Brazilian Portuguese', 'bg' => 'Bulgarian', 'ca' => 'Catalan', 'zh' => 'Chinese', 'zh_cn' => 'Chinese', 'cs' => 'Czech', 'da' => 'Danish', 'nl' => 'Dutch', 'fi' => 'Finnish', 'fr' => 'French', 'de' => 'German', 'el' => 'Greek', 'hu' => 'Hungarian', 'in' => 'Indonesian', 'it' => 'Italian', 'ja' => 'Japanese', 'ko' => 'Korean', 'kr' => 'Korean', // This should be 'ko'. It is wrong in phpdoc! 'lv' => 'Latvian', 'no' => 'Norwegian', 'pl' => 'Polish', 'pt' => 'Portuguese', 'ro' => 'Romanian', 'ru' => 'Russian', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'es' => 'Spanish', 'sv' => 'Swedish', 'th' => 'Thai', 'tr' => 'Turkish', 'uk' => 'Ukranian', ); ?>
« previous php.mirrors (#14376) next »