[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/setup/steps/ -> ezstep_language_options.php (source)

   1  <?php
   2  //
   3  // Definition of eZStepLanguageOptions class
   4  //
   5  // Created on: <11-Aug-2003 17:27:57 kk>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file ezstep_language_options.php
  30  */
  31  include_once ( 'kernel/setup/steps/ezstep_installer.php' );
  32  include_once ( 'kernel/setup/ezsetupcommon.php' );
  33  include_once ( "kernel/common/i18n.php" );
  34  
  35  /*!
  36    \class eZStepLanguageOptions ezstep_language_options.php
  37    \brief The class eZStepLanguageOptions does
  38  
  39  */
  40  
  41  class eZStepLanguageOptions extends eZStepInstaller
  42  {
  43      /*!
  44       Constructor
  45       \reimp
  46      */
  47      function eZStepLanguageOptions(&$tpl, &$http, &$ini, &$persistenceList )
  48      {
  49          $this->eZStepInstaller( $tpl, $http, $ini, $persistenceList,
  50                                  'language_options', 'Language options' );
  51      }
  52  
  53      /*!
  54       \reimp
  55       */
  56      function processPostData()
  57      {
  58          $primaryLanguage = $this->Http->postVariable( 'eZSetupDefaultLanguage' );
  59          $languages       = $this->Http->hasPostVariable( 'eZSetupLanguages' ) ? $this->Http->postVariable( 'eZSetupLanguages' ): array();
  60          $enableUnicode   = $this->Http->hasPostVariable( 'eZEnableUnicode' );
  61  
  62          if ( !in_array( $primaryLanguage, $languages ) )
  63              $languages[] = $primaryLanguage;
  64  
  65          $regionalInfo = array();
  66          $regionalInfo['language_type'] = 1 ;
  67          $regionalInfo['primary_language'] = $primaryLanguage;
  68          $regionalInfo['languages'] = $languages;
  69          $regionalInfo['enable_unicode'] = $enableUnicode;
  70          if ( $enableUnicode )
  71          {
  72              $regionalInfo['site_charset'] = 'utf-8';
  73          }
  74          $this->PersistenceList['regional_info'] = $regionalInfo;
  75  
  76          if ( !isset( $this->PersistenceList['database_info']['use_unicode'] ) ||
  77               $this->PersistenceList['database_info']['use_unicode'] == false )
  78          {
  79              // If we have already figured out charset and it is utf-8
  80              // we don't have to check the new languages
  81              if ( isset( $this->PersistenceList['regional_info']['site_charset'] ) and
  82                   $this->PersistenceList['regional_info']['site_charset'] == 'utf-8' )
  83              {
  84                  $charset = 'utf-8';
  85              }
  86              else
  87              {
  88                  include_once ( 'lib/ezlocale/classes/ezlocale.php' );
  89                  $primaryLanguage     = null;
  90                  $allLanguages        = array();
  91                  $allLanguageCodes    = array();
  92                  $variationsLanguages = array();
  93                  $primaryLanguageCode = $this->PersistenceList['regional_info']['primary_language'];
  94                  $extraLanguageCodes  = isset( $this->PersistenceList['regional_info']['languages'] ) ? $this->PersistenceList['regional_info']['languages'] : array();
  95                  $extraLanguageCodes  = array_diff( $extraLanguageCodes, array( $primaryLanguageCode ) );
  96  
  97                  /*
  98                  if ( isset( $this->PersistenceList['regional_info']['variations'] ) )
  99                  {
 100                      $variations = $this->PersistenceList['regional_info']['variations'];
 101                      foreach ( $variations as $variation )
 102                      {
 103                          $locale = eZLocale::create( $variation );
 104                          if ( $locale->localeCode() == $primaryLanguageCode )
 105                          {
 106                              $primaryLanguage = $locale;
 107                          }
 108                          else
 109                          {
 110                              $variationsLanguages[] = $locale;
 111                          }
 112                      }
 113                  }
 114                  */
 115  
 116                  if ( $primaryLanguage === null )
 117                      $primaryLanguage = eZLocale::create( $primaryLanguageCode );
 118  
 119                  $allLanguages[] =& $primaryLanguage;
 120  
 121                  foreach ( $extraLanguageCodes as $extraLanguageCode )
 122                  {
 123                      $allLanguages[] =& eZLocale::create( $extraLanguageCode );
 124                      $allLanguageCodes[] = $extraLanguageCode;
 125                  }
 126  
 127                  $charset = $this->findAppropriateCharset( $primaryLanguage, $allLanguages, false );
 128  
 129                  if ( !$charset )
 130                  {
 131                      $this->Error = 1;
 132                      return false;
 133                  }
 134              }
 135              // Store the charset for later handling
 136              $this->PersistenceList['regional_info']['site_charset'] = $charset;
 137          }
 138  
 139          return true;
 140      }
 141  
 142      /*!
 143        \reimp
 144       */
 145      function init()
 146      {
 147          if ( $this->hasKickstartData() )
 148          {
 149              $data = $this->kickstartData();
 150  
 151              $regionalInfo = array();
 152              $regionalInfo['primary_language'] = $data['Primary'];
 153              if ( !in_array( $data['Primary'], $data['Languages'] ) )
 154                  $data['Languages'][] = $data['Primary'];
 155              $regionalInfo['languages'] = $data['Languages'];
 156              if ( isset( $data['EnableUnicode'] ) )
 157              {
 158                  $regionalInfo['enable_unicode'] = $data['EnableUnicode'] == 'true';
 159              }
 160              $this->PersistenceList['regional_info'] = $regionalInfo;
 161              $this->storePersistenceData();
 162  
 163              return $this->kickstartContinueNextStep();
 164          }
 165  
 166          return false;
 167      }
 168  
 169      /*!
 170       \reimp
 171       */
 172      function display()
 173      {
 174          $locales = eZLocale::localeList( true );
 175          $languages = array();
 176          $httpMap   = array();
 177          $httpMapShort = array();
 178          // This alias array must be filled in with known names.
 179          // The key is the value from the locale INI file (HTTP group)
 180          // and the value is the HTTP alias.
 181          $httpAliases = array( 'no-bokmaal' => 'nb',
 182                                'no-nynorsk' => 'nn' );
 183          foreach ( array_keys( $locales ) as $localeKey )
 184          {
 185              $locale =& $locales[$localeKey];
 186              if ( !$locale->attribute( 'country_variation' ) )
 187              {
 188                  $languages[] = $locale;
 189                  $httpLocale = strtolower( $locale->httpLocaleCode() );
 190                  $httpMap[$httpLocale] = $locale;
 191                  list( $httpLocaleShort ) = explode( '-', $httpLocale );
 192                  $httpMapShort[$httpLocale] = $locale;
 193                  if ( isset( $httpAliases[$httpLocale] ) )
 194                  {
 195                      $httpMapShort[$httpAliases[$httpLocale]] = $locale;
 196                  }
 197              }
 198          }
 199  
 200          // bubble sort language based on language name. bubble bad, but only about 8-9 elements
 201          for ( $i =0; $i < count( $languages ); $i++ )
 202              for ( $n = 0; $n < count( $languages ) - 1; $n++ )
 203              {
 204                  if ( strcmp( $languages[$n]['language_name'], $languages[$n+1]['language_name'] ) > 0 )
 205                  {
 206                      $tmpElement = $languages[$n];
 207                      $languages[$n] = $languages[$n+1];
 208                      $languages[$n+1] = $tmpElement;
 209                  }
 210              }
 211  
 212          $this->Tpl->setVariable( 'language_list', $languages );
 213          $showUnicodeError = false;
 214          if ( isset( $this->Error ) )
 215          {
 216              $showUnicodeError = !$this->PersistenceList['database_info']['use_unicode'];
 217              unset( $this->PersistenceList['database_info']['use_unicode'] );
 218          }
 219          $this->Tpl->setVariable( 'show_unicode_error', $showUnicodeError );
 220  
 221          $defaultLanguage = false;
 222          $defaultExtraLanguages = array();
 223          if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) )
 224          {
 225              $acceptLanguages = explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
 226              foreach ( $acceptLanguages as $acceptLanguage )
 227              {
 228                  list( $acceptLanguageCode ) = explode( ';', $acceptLanguage );
 229                  $languageCode = false;
 230                  if ( isset( $httpMap[$acceptLanguageCode] ) )
 231                  {
 232                      $languageCode = $httpMap[$acceptLanguageCode]->localeCode();
 233                  }
 234                  elseif ( isset( $httpMapShort[$acceptLanguageCode] ) )
 235                  {
 236                      $languageCode = $httpMapShort[$acceptLanguageCode]->localeCode();
 237                  }
 238                  if ( $languageCode )
 239                  {
 240                      if ( $defaultLanguage === false )
 241                      {
 242                          $defaultLanguage = $languageCode;
 243                      }
 244  /*                    else
 245                      {
 246                          $defaultExtraLanguages[] = $languageCode;
 247                      }*/
 248                  }
 249              }
 250          }
 251          if ( $defaultLanguage === false )
 252          {
 253              $defaultLanguage = 'eng-GB';
 254          }
 255          $defaultExtraLanguages = array_unique( array_diff( $defaultExtraLanguages, array( $defaultLanguage ) ) );
 256  
 257          $regionalInfo = array( 'primary_language' => $defaultLanguage,
 258                                 'languages' => $defaultExtraLanguages );
 259          if ( isset( $this->PersistenceList['regional_info'] ) )
 260              $regionalInfo = $this->PersistenceList['regional_info'];
 261          if ( !isset( $regionalInfo['enable_unicode'] ) )
 262              $regionalInfo['enable_unicode'] = true;
 263  
 264          $this->Tpl->setVariable( 'regional_info', $regionalInfo );
 265  
 266          // The default is to not use unicode if it has not been detected by
 267          // database driver to be OK.
 268          $databaseInfo = array( 'use_unicode' => false );
 269          if ( isset( $this->PersistenceList['database_info'] ) )
 270          {
 271              $databaseInfo = $this->PersistenceList['database_info'];
 272          }
 273  
 274          $this->Tpl->setVariable( 'database_info', $databaseInfo );
 275  
 276          $result = array();
 277          // Display template
 278  
 279          $result['content'] = $this->Tpl->fetch( "design:setup/init/language_options.tpl" );
 280          $result['path'] = array( array( 'text' => ezi18n( 'design/standard/setup/init',
 281                                                            'Language options' ),
 282                                          'url' => false ) );
 283          return $result;
 284      }
 285  
 286  
 287      var $Error;
 288  }
 289  
 290  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7