[ Index ]
 

Code source de WebCalendar 1.0.5

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables | Statistiques

title

Body

[fermer]

/includes/ -> config.php (source)

   1  <?php
   2  /**
   3   * This file loads configuration settings from the data file settings.php and
   4   * sets up some needed variables.
   5   *
   6   * The settings.php file is created during installation using the web-based db
   7   * setup page (install/index.php).
   8   *
   9   * <b>Note:</b>
  10   * DO NOT EDIT THIS FILE!
  11   *
  12   * (Versions 0.9.44 and older required users to edit this file to configure
  13   * WebCalendar.  Version 0.9.45 and later requires editing the settings.php
  14   * file instead.)
  15   *
  16   * @version $Id: config.php,v 1.53.2.18 2007/03/04 16:12:05 cknudsen Exp $
  17   * @package WebCalendar
  18   */
  19  if ( empty ( $PHP_SELF ) && ! empty ( $_SERVER ) &&
  20    ! empty ( $_SERVER['PHP_SELF'] ) ) {
  21    $PHP_SELF = $_SERVER['PHP_SELF'];
  22  }
  23  if ( ! empty ( $PHP_SELF ) && preg_match ( "/\/includes\//", $PHP_SELF ) ) {
  24      die ( "You can't access this file directly!" );
  25  }
  26  
  27  // Unset some variables in case the server has register_globals
  28  // enabled.  This will prevent users from settings these values
  29  // in a URL:
  30  // http://localhost/calendar/month.php?includedir=http://xxx/bad-guy
  31  unset ( $includedir );
  32  unset ( $db_type );
  33  unset ( $db_database );
  34  unset ( $db_login );
  35  unset ( $db_password );
  36  unset ( $db_persistent );
  37  unset ( $single_user_login );
  38  unset ( $readonly );
  39  unset ( $mode );
  40  unset ( $use_http_auth );
  41  unset ( $single_user );
  42  unset ( $user_inc );
  43  unset ( $includedir );
  44  unset ( $basedir );
  45  
  46  
  47  $PROGRAM_VERSION = "v1.0.5";
  48  $PROGRAM_DATE = "04 Mar 2007";
  49  $PROGRAM_NAME = "WebCalendar $PROGRAM_VERSION ($PROGRAM_DATE)";
  50  $PROGRAM_URL = "http://webcalendar.sourceforge.net/";
  51  
  52  $TROUBLE_URL = "docs/WebCalendar-SysAdmin.html#trouble";
  53  
  54  /**
  55   * Prints a fatal error message to the user along with a link to the
  56   * Troubleshooting section of the WebCalendar System Administrator's Guide.
  57   *
  58   * Execution is aborted.
  59   *
  60   * @param string $error The error message to display
  61   *
  62   * @internal We don't normally put functions in this file.  But, since this
  63   *           file is included before some of the others, this function either
  64   *           goes here or we repeat this code in multiple files.
  65   */
  66  function die_miserable_death ( $error )
  67  {
  68  global $TROUBLE_URL;
  69    echo "<html><head><title>WebCalendar: Fatal Error</title></head>\n" .
  70      "<body><h2>WebCalendar Error</h2>\n" .
  71      "<p>$error</p>\n<hr />" .
  72      "<p><a href=\"$TROUBLE_URL\" target=\"_blank\">" .
  73      "Troubleshooting Help</a></p></body></html>\n";
  74    exit;
  75  }
  76  
  77  
  78  
  79  // Open settings file to read
  80  $settings = array ();
  81  $settings_file = dirname(__FILE__) . "/settings.php";
  82  //called from send_reminders.php
  83  if ( ! empty ( $includedir ) ) 
  84    $fd = @fopen ( "$includedir/settings.php", "rb", true );
  85  else
  86    $fd = @fopen ( "settings.php", "rb", true );
  87  if ( ! $fd )
  88    $fd = @fopen ( "includes/settings.php", "rb", true );
  89  if ( ! $fd  && file_exists ( $settings_file ) )
  90    $fd = @fopen ( $settings_file, "rb", true );
  91  if ( empty ( $fd ) ) {
  92    // There is no settings.php file.
  93    // Redirect user to install page if it exists.
  94    if ( file_exists ( "install/index.php" ) ) {
  95      Header ( "Location: install/index.php" );
  96      exit;
  97    } else {
  98      die_miserable_death ( "Could not find settings.php file.<br />\n" .
  99        "Please copy settings.php.orig to settings.php and modify for your " .
 100        "site.\n" );
 101    }
 102  }
 103  
 104  // We don't use fgets() since it seems to have problems with Mac-formatted
 105  // text files.  Instead, we read in the entire file, then split the lines
 106  // manually.
 107  $data = '';
 108  while ( ! feof ( $fd ) ) {
 109    $data .= fgets ( $fd, 4096 );
 110  }
 111  fclose ( $fd );
 112  
 113  // Replace any combination of carriage return (\r) and new line (\n)
 114  // with a single new line.
 115  $data = preg_replace ( "/[\r\n]+/", "\n", $data );
 116  
 117  // Split the data into lines.
 118  $configLines = explode ( "\n", $data );
 119  
 120  for ( $n = 0; $n < count ( $configLines ); $n++ ) {
 121    $buffer = $configLines[$n];
 122    $buffer = trim ( $buffer, "\r\n " );
 123    if ( preg_match ( "/^#/", $buffer ) )
 124      continue;
 125    if ( preg_match ( "/^<\?/", $buffer ) ) // start php code
 126      continue;
 127    if ( preg_match ( "/^\?>/", $buffer ) ) // end php code
 128      continue;
 129    if ( preg_match ( "/(\S+):\s*(\S+)/", $buffer, $matches ) ) {
 130      $settings[$matches[1]] = $matches[2];
 131      //echo "settings $matches[1] => $matches[2] <br>";
 132    }
 133  }
 134  $configLines = $data = '';
 135  
 136  // Extract db settings into global vars
 137  $db_type = $settings['db_type'];
 138  $db_host = $settings['db_host'];
 139  $db_login = $settings['db_login'];
 140  $db_password = $settings['db_password'];
 141  $db_database = $settings['db_database'];
 142  $db_persistent = preg_match ( "/(1|yes|true|on)/i",
 143    $settings['db_persistent'] ) ? '1' : '0';
 144  
 145  foreach ( array ( "db_type", "db_host", "db_login", "db_password" ) as $s ) {
 146    if ( empty ( $settings[$s] ) ) {
 147      die_miserable_death ( "Could not find <tt>$s</tt> defined in " .
 148        "your <tt>settings.php</tt> file.\n" );
 149    }
 150  }
 151  
 152  $readonly = preg_match ( "/(1|yes|true|on)/i",
 153    $settings['readonly'] ) ? 'Y' : 'N';
 154  
 155  $single_user = "N";
 156  $single_user = preg_match ( "/(1|yes|true|on)/i",
 157    $settings['single_user'] ) ? 'Y' : 'N';
 158  if ( $single_user == 'Y' )
 159    $single_user_login = $settings['single_user_login'];
 160  
 161  if ( $single_user == 'Y' && empty ( $single_user_login ) ) {
 162    die_miserable_death ( "You must define <tt>single_user_login</tt> in " .
 163      "the settings.php file.\n" );
 164  }
 165  
 166  
 167  $use_http_auth = preg_match ( "/(1|yes|true|on)/i",
 168    $settings['use_http_auth'] ) ? true : false;
 169  
 170  // Type of user authentication
 171  $user_inc = $settings['user_inc'];
 172  
 173  // We can add extra 'nonuser' calendars such as a corporate calendar,
 174  // holiday calendar, departmental calendar, etc.  We need a unique prefix
 175  // for these calendars as not to get mixed up with real logins.  This prefix
 176  // should be a Maximum of 5 characters and should NOT change once set!
 177  $NONUSER_PREFIX = '_NUC_';
 178  
 179  // Language options  The first is the name presented to users while
 180  // the second is the filename (without the ".txt") that must exist
 181  // in the translations subdirectory.
 182  $languages = array (
 183    "Browser-defined" =>"none",
 184    "English" =>"English-US",
 185    "Basque" => "Basque",
 186    "Bulgarian" => "Bulgarian",
 187    "Catalan" => "Catalan",
 188    "Chinese (Traditonal/Big5)" => "Chinese-Big5",
 189    "Chinese (Simplified/GB2312)" => "Chinese-GB2312",
 190    "Czech" => "Czech",
 191    "Danish" => "Danish",
 192    "Dutch" =>"Dutch",
 193    "Estonian" => "Estonian",
 194    "Finnish" =>"Finnish",
 195    "French" =>"French",
 196    "French(UTF-8)" =>"French-UTF8",
 197    "Galician" => "Galician",
 198    "German" =>"German",
 199    "Greek" =>"Greek",
 200    "Holo (Taiwanese)" => "Holo-Big5",
 201    "Hungarian" =>"Hungarian",
 202    "Icelandic" => "Icelandic",
 203    "Italian" => "Italian",
 204    "Japanese(SHIFT JIS)" => "Japanese",
 205    "Japanese(EUC-JP)" => "Japanese-eucjp",
 206    "Japanese(UTF-8)" => "Japanese-utf8",
 207    "Korean" =>"Korean",
 208    "Norwegian" => "Norwegian",
 209    "Polish" => "Polish",
 210    "Portuguese" =>"Portuguese",
 211    "Portuguese/Brazil" => "Portuguese_BR",
 212    "Romanian" => "Romanian",
 213    "Russian" => "Russian",
 214    "Spanish" =>"Spanish",
 215    "Swedish" =>"Swedish",
 216    "Turkish" =>"Turkish",
 217    "Welsh" =>"Welsh"
 218    // add new languages here!  (don't forget to add a comma at the end of
 219    // last line above.)
 220  );
 221  
 222  // If the user sets "Browser-defined" as their language setting, then
 223  // use the $HTTP_ACCEPT_LANGUAGE settings to determine the language.
 224  // The array below translates browser language abbreviations into
 225  // our available language files.
 226  // NOTE: These should all be lowercase on the left side even though
 227  // the proper listing is like "en-US"!
 228  // Not sure what the abbreviation is?  Check out the following URL:
 229  // http://www.geocities.com/click2speak/languages.html
 230  $browser_languages = array (
 231    "eu" => "Basque",
 232    "bg" => "Bulgarian",
 233    "ca" => "Catalan",
 234    "zh" => "Chinese-GB2312",    // Simplified Chinese
 235    "zh-cn" => "Chinese-GB2312",
 236    "zh-tw" => "Chinese-Big5",   // Traditional Chinese
 237    "cs" => "Czech",
 238    "en" => "English-US",
 239    "en-us" => "English-US",
 240    "en-gb" => "English-US",
 241    "da" => "Danish",
 242    "nl" =>"Dutch",
 243    "ee" => "Estonian",
 244    "fi" =>"Finnish",
 245    "fr" =>"French",
 246    "fr-ch" =>"French", // French/Swiss
 247    "fr-ca" =>"French", // French/Canada
 248    "gl" => "Galician",
 249    "de" =>"German",
 250    "de-at" =>"German", // German/Austria
 251    "de-ch" =>"German", // German/Switzerland
 252    "de-de" =>"German", // German/German
 253    "el" =>"Greek", // German/German
 254    "hu" => "Hungarian",
 255    "zh-min-nan-tw" => "Holo-Big5",
 256    "is" => "Icelandic",
 257    "it" => "Italian",
 258    "it-ch" => "Italian", // Italian/Switzerland
 259    "ja" => "Japanese",
 260    "ko" =>"Korean",
 261    "no" => "Norwegian",
 262    "pl" => "Polish",
 263    "pt" =>"Portuguese",
 264    "pt-br" => "Portuguese_BR", // Portuguese/Brazil
 265    "ro" =>"Romanian",
 266    "ru" =>"Russian",
 267    "es" =>"Spanish",
 268    "sv" =>"Swedish",
 269    "tr" =>"Turkish",
 270    "cy" => "Welsh"
 271  );
 272  
 273  // The following comments will be picked up by update_translation.pl so
 274  // translators will be aware that they also need to translate language names.
 275  //
 276  // translate("English")
 277  // translate("Basque")
 278  // translate("Bulgarian")
 279  // translate("Catalan")
 280  // translate("Chinese (Traditonal/Big5)")
 281  // translate("Chinese (Simplified/GB2312)")
 282  // translate("Czech")
 283  // translate("Danish")
 284  // translate("Dutch")
 285  // translate("Estonian")
 286  // translate("Finnish")
 287  // translate("French")
 288  // translate("Galician")
 289  // translate("German")
 290  // translate("Greek")
 291  // translate("Holo (Taiwanese)")
 292  // translate("Hungarian")
 293  // translate("Icelandic")
 294  // translate("Italian")
 295  // translate("Japanese")
 296  // translate("Korean")
 297  // translate("Norwegian")
 298  // translate("Polish")
 299  // translate("Portuguese")
 300  // translate("Portuguese/Brazil")
 301  // translate("Romanian")
 302  // translate("Russian")
 303  // translate("Spanish")
 304  // translate("Swedish")
 305  // translate("Turkish")
 306  // translate("Welsh")
 307  
 308  if ( $single_user != "Y" )
 309    $single_user_login = "";
 310  
 311  // Make sure magic quotes is enabled, since this app requires it.
 312  if ( get_magic_quotes_gpc () == 0 ) {
 313    ob_start ();
 314    phpinfo ();
 315    $val = ob_get_contents ();
 316    ob_end_clean ();
 317    $loc = '';
 318    if ( preg_match ( "/>([^<>]*php.ini)</", $val, $matches ) ) {
 319      $loc = "Please edit the following file and restart your server:" .
 320        "<br /><br />\n" .
 321        "<blockquote>\n<tt>" . $matches[1] . "</tt>\n</blockquote>\n";
 322    }
 323    die_miserable_death ( "You must reconfigure your <tt>php.ini</tt> file to " .
 324      "have <span style=\"font-weight:bold;\">magic_quotes_gpc</span> set " .
 325      " to <span style=\"font-weight:bold;\">ON</span>.<br /><br />\n" .
 326      $loc );
 327  }
 328  
 329  ?>


Généré le : Fri Nov 30 19:09:19 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics