PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/kernel/setup/ezsetupcommon.php

https://github.com/granitegreg/ezpublish
PHP | 234 lines | 174 code | 14 blank | 46 comment | 17 complexity | a020d632f346a0e46d94b3118a6e55bd MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. //
  3. // eZSetup
  4. //
  5. // Created on: <08-Nov-2002 11:00:54 kd>
  6. //
  7. // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  8. // SOFTWARE NAME: eZ Publish
  9. // SOFTWARE RELEASE: 4.1.x
  10. // COPYRIGHT NOTICE: Copyright (C) 1999-2011 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. // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  29. //
  30. // This file holds shared functions for the ezsetup files
  31. /*!
  32. \return an array with tests that need to be run
  33. and succeed for the setup to continue.
  34. */
  35. function eZSetupCriticalTests()
  36. {
  37. $ini = eZINI::instance();
  38. return $ini->variableArray( 'SetupSettings', 'CriticalTests' );
  39. }
  40. /*!
  41. \return an array with tests that when run will give information on finetuning.
  42. */
  43. function eZSetupOptionalTests()
  44. {
  45. $ini = eZINI::instance();
  46. return $ini->variableArray( 'SetupSettings', 'OptionalTests' );
  47. }
  48. function eZSetupDatabaseMap()
  49. {
  50. return array( 'mysqli' => array( 'type' => 'mysqli',
  51. 'driver' => 'ezmysqli',
  52. 'name' => 'MySQL Improved',
  53. 'required_version' => '4.1.1',
  54. 'has_demo_data' => true,
  55. 'supports_unicode' => true ),
  56. 'mysql' => array( 'type' => 'mysql',
  57. 'driver' => 'ezmysql',
  58. 'name' => 'MySQL (Deprecated)',
  59. 'required_version' => '4.1.1',
  60. 'has_demo_data' => true,
  61. 'supports_unicode' => false ),
  62. 'pgsql' => array( 'type' => 'pgsql',
  63. 'driver' => 'ezpostgresql',
  64. 'name' => 'PostgreSQL',
  65. 'required_version' => '8.0',
  66. 'has_demo_data' => false,
  67. 'supports_unicode' => true ),
  68. );
  69. }
  70. function eZSetupFetchPersistenceList()
  71. {
  72. $persistenceList = array();
  73. $http = eZHTTPTool::instance();
  74. $postVariables = $http->attribute( 'post' );
  75. foreach ( $postVariables as $name => $value )
  76. {
  77. if ( preg_match( '/^P_([a-zA-Z0-9_]+)-([a-zA-Z0-9_]+)$/', $name, $matches ) )
  78. {
  79. $persistenceGroup = $matches[1];
  80. $persistenceName = $matches[2];
  81. $persistenceList[$persistenceGroup][$persistenceName] = $value;
  82. }
  83. }
  84. return $persistenceList;
  85. }
  86. function eZSetupSetPersistencePostVariable( $var, $value )
  87. {
  88. $http = eZHTTPTool::instance();
  89. if ( is_array( $value ) )
  90. {
  91. foreach ( $value as $valueKey => $valueItem )
  92. {
  93. $http->setPostVariable( 'P_' . $var . '-' . $valueKey, $valueItem );
  94. }
  95. }
  96. else
  97. {
  98. $http->setPostVariable( 'P_' . $var . '-0', $value );
  99. }
  100. }
  101. function eZSetupMergePersistenceList( &$persistenceList, $persistenceDataList )
  102. {
  103. foreach ( $persistenceDataList as $persistenceData )
  104. {
  105. $persistenceName = $persistenceData[0];
  106. $persistenceValues = $persistenceData[1];
  107. if ( !isset( $persistenceList[$persistenceName] ) )
  108. {
  109. $values =& $persistenceList[$persistenceName];
  110. foreach ( $persistenceValues as $persistenceValueName => $persistenceValueData )
  111. {
  112. $values[$persistenceValueName] = $persistenceValueData['value'];
  113. }
  114. }
  115. else
  116. {
  117. $oldValues =& $persistenceList[$persistenceName];
  118. foreach ( $persistenceValues as $persistenceValueName => $persistenceValueData )
  119. {
  120. if ( !isset( $oldValues[$persistenceValueName] ) )
  121. {
  122. $oldValues[$persistenceValueName] = $persistenceValueData['value'];
  123. }
  124. else if ( is_array( $persistenceValueData['value'] ) and
  125. isset( $persistenceValueData['merge'] ) and
  126. $persistenceValueData['merge'] )
  127. {
  128. $merged = array_merge( $oldValues[$persistenceValueName], $persistenceValueData['value'] );
  129. if ( isset( $persistenceValueData['unique'] ) and
  130. $persistenceValueData['unique'] )
  131. $merged = array_unique( $merged );
  132. $oldValues[$persistenceValueName] = $merged;
  133. }
  134. else
  135. {
  136. $oldValues[$persistenceValueName] = $persistenceValueData['value'];
  137. }
  138. }
  139. }
  140. }
  141. }
  142. function eZSetupLanguageList( &$languageList, &$defaultLanguage, &$defaultExtraLanguages )
  143. {
  144. $locales = eZLocale::localeList( true );
  145. $languageList = array();
  146. $httpMap = array();
  147. $httpMapShort = array();
  148. // This alias array must be filled in with known names.
  149. // The key is the value from the locale INI file (HTTP group)
  150. // and the value is the HTTP alias.
  151. $httpAliases = array( 'no-bokmaal' => 'nb',
  152. 'no-nynorsk' => 'nn',
  153. 'ru-ru' => 'ru' );
  154. foreach ( array_keys( $locales ) as $localeKey )
  155. {
  156. $locale =& $locales[$localeKey];
  157. if ( !$locale->attribute( 'country_variation' ) )
  158. {
  159. $languageList[] = $locale;
  160. $httpLocale = strtolower( $locale->httpLocaleCode() );
  161. $httpMap[$httpLocale] = $locale;
  162. list( $httpLocaleShort ) = explode( '-', $httpLocale );
  163. $httpMapShort[$httpLocale] = $locale;
  164. if ( isset( $httpAliases[$httpLocale] ) )
  165. {
  166. $httpMapShort[$httpAliases[$httpLocale]] = $locale;
  167. }
  168. }
  169. }
  170. // bubble sort language based on language name. bubble bad, but only about 8-9 elements
  171. for ( $i =0; $i < count( $languageList ); $i++ )
  172. for ( $n = 0; $n < count( $languageList ) - 1; $n++ )
  173. {
  174. if ( strcmp( $languageList[$n]->attribute( 'language_name' ), $languageList[$n+1]->attribute( 'language_name' ) ) > 0 )
  175. {
  176. $tmpElement = $languageList[$n];
  177. $languageList[$n] = $languageList[$n+1];
  178. $languageList[$n+1] = $tmpElement;
  179. }
  180. }
  181. $defaultLanguage = false;
  182. $defaultExtraLanguages = array();
  183. if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) )
  184. {
  185. $acceptLanguages = explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
  186. foreach ( $acceptLanguages as $acceptLanguage )
  187. {
  188. list( $acceptLanguageCode ) = explode( ';', $acceptLanguage );
  189. $acceptLanguageCode = strtolower( $acceptLanguageCode );
  190. $languageCode = false;
  191. if ( isset( $httpMap[$acceptLanguageCode] ) )
  192. {
  193. $languageCode = $httpMap[$acceptLanguageCode]->localeCode();
  194. }
  195. elseif ( isset( $httpMapShort[$acceptLanguageCode] ) )
  196. {
  197. $languageCode = $httpMapShort[$acceptLanguageCode]->localeCode();
  198. }
  199. if ( $languageCode )
  200. {
  201. if ( $defaultLanguage === false )
  202. {
  203. $defaultLanguage = $languageCode;
  204. }
  205. /*
  206. else
  207. {
  208. $defaultExtraLanguages[] = $languageCode;
  209. }
  210. */
  211. }
  212. }
  213. }
  214. if ( $defaultLanguage === false )
  215. {
  216. $defaultLanguage = 'eng-GB';
  217. }
  218. $defaultExtraLanguages = array_unique( array_diff( $defaultExtraLanguages, array( $defaultLanguage ) ) );
  219. }
  220. ?>