/kernel/setup/ezsetupcommon.php

https://github.com/edorfaus/ezpublish · PHP · 206 lines · 168 code · 14 blank · 24 comment · 17 complexity · b3c24d6e5b5f30910e7b39e2a0b85c8f MD5 · raw file

  1. <?php
  2. /**
  3. * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
  4. * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
  5. * @version //autogentag//
  6. * @package kernel
  7. */
  8. // This file holds shared functions for the ezsetup files
  9. /*!
  10. \return an array with tests that need to be run
  11. and succeed for the setup to continue.
  12. */
  13. function eZSetupCriticalTests()
  14. {
  15. $ini = eZINI::instance();
  16. return $ini->variableArray( 'SetupSettings', 'CriticalTests' );
  17. }
  18. /*!
  19. \return an array with tests that when run will give information on finetuning.
  20. */
  21. function eZSetupOptionalTests()
  22. {
  23. $ini = eZINI::instance();
  24. return $ini->variableArray( 'SetupSettings', 'OptionalTests' );
  25. }
  26. function eZSetupDatabaseMap()
  27. {
  28. return array( 'mysqli' => array( 'type' => 'mysqli',
  29. 'driver' => 'ezmysqli',
  30. 'name' => 'MySQL Improved',
  31. 'required_version' => '4.1.1',
  32. 'has_demo_data' => true,
  33. 'supports_unicode' => true ),
  34. 'pgsql' => array( 'type' => 'pgsql',
  35. 'driver' => 'ezpostgresql',
  36. 'name' => 'PostgreSQL',
  37. 'required_version' => '8.0',
  38. 'has_demo_data' => false,
  39. 'supports_unicode' => true ),
  40. );
  41. }
  42. function eZSetupFetchPersistenceList()
  43. {
  44. $persistenceList = array();
  45. $http = eZHTTPTool::instance();
  46. $postVariables = $http->attribute( 'post' );
  47. foreach ( $postVariables as $name => $value )
  48. {
  49. if ( preg_match( '/^P_([a-zA-Z0-9_]+)-([a-zA-Z0-9_]+)$/', $name, $matches ) )
  50. {
  51. $persistenceGroup = $matches[1];
  52. $persistenceName = $matches[2];
  53. $persistenceList[$persistenceGroup][$persistenceName] = $value;
  54. }
  55. }
  56. return $persistenceList;
  57. }
  58. function eZSetupSetPersistencePostVariable( $var, $value )
  59. {
  60. $http = eZHTTPTool::instance();
  61. if ( is_array( $value ) )
  62. {
  63. foreach ( $value as $valueKey => $valueItem )
  64. {
  65. $http->setPostVariable( 'P_' . $var . '-' . $valueKey, $valueItem );
  66. }
  67. }
  68. else
  69. {
  70. $http->setPostVariable( 'P_' . $var . '-0', $value );
  71. }
  72. }
  73. function eZSetupMergePersistenceList( &$persistenceList, $persistenceDataList )
  74. {
  75. foreach ( $persistenceDataList as $persistenceData )
  76. {
  77. $persistenceName = $persistenceData[0];
  78. $persistenceValues = $persistenceData[1];
  79. if ( !isset( $persistenceList[$persistenceName] ) )
  80. {
  81. $values =& $persistenceList[$persistenceName];
  82. foreach ( $persistenceValues as $persistenceValueName => $persistenceValueData )
  83. {
  84. $values[$persistenceValueName] = $persistenceValueData['value'];
  85. }
  86. }
  87. else
  88. {
  89. $oldValues =& $persistenceList[$persistenceName];
  90. foreach ( $persistenceValues as $persistenceValueName => $persistenceValueData )
  91. {
  92. if ( !isset( $oldValues[$persistenceValueName] ) )
  93. {
  94. $oldValues[$persistenceValueName] = $persistenceValueData['value'];
  95. }
  96. else if ( is_array( $persistenceValueData['value'] ) and
  97. isset( $persistenceValueData['merge'] ) and
  98. $persistenceValueData['merge'] )
  99. {
  100. $merged = array_merge( $oldValues[$persistenceValueName], $persistenceValueData['value'] );
  101. if ( isset( $persistenceValueData['unique'] ) and
  102. $persistenceValueData['unique'] )
  103. $merged = array_unique( $merged );
  104. $oldValues[$persistenceValueName] = $merged;
  105. }
  106. else
  107. {
  108. $oldValues[$persistenceValueName] = $persistenceValueData['value'];
  109. }
  110. }
  111. }
  112. }
  113. }
  114. function eZSetupLanguageList( &$languageList, &$defaultLanguage, &$defaultExtraLanguages )
  115. {
  116. $locales = eZLocale::localeList( true );
  117. $languageList = array();
  118. $httpMap = array();
  119. $httpMapShort = array();
  120. // This alias array must be filled in with known names.
  121. // The key is the value from the locale INI file (HTTP group)
  122. // and the value is the HTTP alias.
  123. $httpAliases = array( 'no-bokmaal' => 'nb',
  124. 'no-nynorsk' => 'nn',
  125. 'ru-ru' => 'ru' );
  126. foreach ( array_keys( $locales ) as $localeKey )
  127. {
  128. $locale =& $locales[$localeKey];
  129. if ( !$locale->attribute( 'country_variation' ) )
  130. {
  131. $languageList[] = $locale;
  132. $httpLocale = strtolower( $locale->httpLocaleCode() );
  133. $httpMap[$httpLocale] = $locale;
  134. list( $httpLocaleShort ) = explode( '-', $httpLocale );
  135. $httpMapShort[$httpLocale] = $locale;
  136. if ( isset( $httpAliases[$httpLocale] ) )
  137. {
  138. $httpMapShort[$httpAliases[$httpLocale]] = $locale;
  139. }
  140. }
  141. }
  142. // bubble sort language based on language name. bubble bad, but only about 8-9 elements
  143. for ( $i =0; $i < count( $languageList ); $i++ )
  144. for ( $n = 0; $n < count( $languageList ) - 1; $n++ )
  145. {
  146. if ( strcmp( $languageList[$n]->attribute( 'language_name' ), $languageList[$n+1]->attribute( 'language_name' ) ) > 0 )
  147. {
  148. $tmpElement = $languageList[$n];
  149. $languageList[$n] = $languageList[$n+1];
  150. $languageList[$n+1] = $tmpElement;
  151. }
  152. }
  153. $defaultLanguage = false;
  154. $defaultExtraLanguages = array();
  155. if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) )
  156. {
  157. $acceptLanguages = explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
  158. foreach ( $acceptLanguages as $acceptLanguage )
  159. {
  160. list( $acceptLanguageCode ) = explode( ';', $acceptLanguage );
  161. $acceptLanguageCode = strtolower( $acceptLanguageCode );
  162. $languageCode = false;
  163. if ( isset( $httpMap[$acceptLanguageCode] ) )
  164. {
  165. $languageCode = $httpMap[$acceptLanguageCode]->localeCode();
  166. }
  167. elseif ( isset( $httpMapShort[$acceptLanguageCode] ) )
  168. {
  169. $languageCode = $httpMapShort[$acceptLanguageCode]->localeCode();
  170. }
  171. if ( $languageCode )
  172. {
  173. if ( $defaultLanguage === false )
  174. {
  175. $defaultLanguage = $languageCode;
  176. }
  177. /*
  178. else
  179. {
  180. $defaultExtraLanguages[] = $languageCode;
  181. }
  182. */
  183. }
  184. }
  185. }
  186. if ( $defaultLanguage === false )
  187. {
  188. $defaultLanguage = 'eng-GB';
  189. }
  190. $defaultExtraLanguages = array_unique( array_diff( $defaultExtraLanguages, array( $defaultLanguage ) ) );
  191. }
  192. ?>