Changeset 1370 for trunk/bb-admin/class-install.php
- Timestamp:
- 03/24/2008 10:53:25 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/bb-admin/class-install.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bb-admin/class-install.php
r1353 r1370 20 20 **/ 21 21 var $load_includes = false; 22 23 /** 24 * An array of available languages to use in the installer 25 * 26 * @var array 27 **/ 28 var $languages = array('en_US' => 'en_US'); 29 30 /** 31 * The currently selected language for the installer 32 * 33 * @var string 34 **/ 35 var $language = 'en_US'; 22 36 23 37 /** … … 129 143 'intro' => array( 130 144 __('We\'re now going to go through a few steps to get you up and running.'), 145 $this->get_language_selector(), 131 146 sprintf(__('Ready? Then <a href="%s">let\'s get started!</a>'), 'install.php?step=1') 132 147 ) … … 185 200 function check_prerequisites() 186 201 { 187 if ( phpversion() < '4.2') {188 $this->strings[-1]['messages']['error'][] = sprintf(__('Your server is running PHP version %s but bbPress requires at least 4. 2'), phpversion());202 if (version_compare(PHP_VERSION, '4.3', '<')) { 203 $this->strings[-1]['messages']['error'][] = sprintf(__('Your server is running PHP version %s but bbPress requires at least 4.3'), PHP_VERSION); 189 204 $this->step = -1; 190 205 } … … 201 216 } 202 217 218 if (defined('DB_NAME') || defined('WP_BB') && WP_BB) { 219 $this->strings[-1]['messages']['error'][] = __('Please complete your installation before attempting to include WordPress within bbPress'); 220 $this->step = -1; 221 } 222 203 223 if ($this->step === -1) { 204 224 return false; … … 248 268 } 249 269 270 // Define the language file directory 271 if ( !defined('BB_LANG_DIR') ) 272 define('BB_LANG_DIR', BB_PATH . BB_INC . 'languages/'); // absolute path with trailing slash 273 250 274 return true; 275 } 276 277 /** 278 * Gets an array of available languages form the language directory 279 * 280 * @return array 281 **/ 282 function get_languages() 283 { 284 foreach (bb_glob(BB_LANG_DIR . '*.mo') as $language) { 285 $language = str_replace('.mo', '', basename($language)); 286 $this->languages[$language] = $language; 287 } 288 return $this->languages; 289 } 290 291 /** 292 * Returns a language selector for switching installation languages 293 * 294 * @return string|false Either the html for the selector or false if there are no languages 295 **/ 296 function get_language_selector() 297 { 298 // Don't provide a selection if there is only english 299 if (count($this->languages) < 2) { 300 return false; 301 } 302 303 $r = '<script type="text/javascript" charset="utf-8">' . "\n"; 304 $r .= ' function changeLanguage(selectObj) {' . "\n"; 305 $r .= ' var selectedLanguage = selectObj.options[selectObj.selectedIndex].value;' . "\n"; 306 $r .= ' location.href = "install.php?language=" + selectedLanguage;' . "\n"; 307 $r .= ' }' . "\n"; 308 $r .= '</script>' . "\n"; 309 $r .= '<form id="lang" action="install.php?step=' . $this->step . '">' . "\n"; 310 $r .= ' <label>' . "\n"; 311 $r .= ' ' . __('Please select the language you wish to use during installation -') . "\n"; 312 $r .= ' <select onchange="changeLanguage(this);" name="language">' . "\n"; 313 foreach ($this->languages as $language) { 314 $selected = ''; 315 if ($language == $this->language) { 316 $selected = ' selected="selected"'; 317 } 318 $r .= ' <option value="' . $language . '"' . $selected . '>' . $language . '</option>' . "\n"; 319 } 320 $r .= ' </select>' . "\n"; 321 $r .= ' </label>' . "\n"; 322 $r .= '</form>' . "\n"; 323 324 return $r; 325 } 326 327 /** 328 * Sets the current installation language 329 * 330 * @return string The currently set language 331 **/ 332 function set_language() 333 { 334 if (isset($_COOKIE['bb_install_language']) && count($this->languages) > 1) { 335 if (in_array($_COOKIE['bb_install_language'], $this->languages)) { 336 $this->language = $_COOKIE['bb_install_language']; 337 } 338 } 339 340 if ($_GET['language'] && count($this->languages) > 1) { 341 if (in_array($_GET['language'], $this->languages)) { 342 $this->language = $_GET['language']; 343 setcookie('bb_install_language', $this->language); 344 } 345 } 346 347 if (!$this->language || $this->language == 'en_US') { 348 $this->language = 'en_US'; 349 setcookie('bb_install_language', ' ', time() - 31536000); 350 } 351 352 return $this->language; 251 353 } 252 354 … … 448 550 'note' => __('That database user\'s password.') 449 551 ), 552 'bb_lang' => array( 553 'value' => '', 554 'label' => __('Language'), 555 'note' => sprintf(__('The language which bbPress will be presented in once installed. Your current language choice (%s) will remain for the rest of the install process.'), $this->language) 556 ), 450 557 'toggle_1' => array( 451 558 'value' => 0, … … 832 939 833 940 $data =& $this->data[1]['form']; 941 942 if ($data['bb_lang']['value'] == 'en_US') { 943 $data['bb_lang']['value'] = ''; 944 } 834 945 835 946 $data['bb_table_prefix']['value'] = preg_replace('/[^0-9a-zA-Z_]/', '', $data['bb_table_prefix']['value']); … … 909 1020 $config_lines[] = str_replace("'bb_'", "'" . $data['bb_table_prefix']['value'] . "'", $line); 910 1021 break; 1022 case "define('BB_LANG', ": 1023 $config_lines[] = str_replace("''", "'" . $data['bb_lang']['value'] . "'", $line); 1024 break; 911 1025 default: 912 1026 $config_lines[] = $line; … … 1303 1417 // Check the referer 1304 1418 bb_check_admin_referer('bbpress-installer'); 1305 $installation_log[] = __('Referrer is OK, beginning installation ...');1419 $installation_log[] = __('Referrer is OK, beginning installation…'); 1306 1420 1307 1421 global $bbdb; … … 1603 1717 if ($forum_id = bb_new_forum(array('forum_name' => $data3['forum_name']['value']))) { 1604 1718 $installation_log[] = '>>> ' . __('Forum name:') . ' ' . $data3['forum_name']['value']; 1719 1720 if ($this->language != BB_LANG) { 1721 global $locale, $l10n; 1722 $locale = BB_LANG; 1723 unset($l10n['default']); 1724 load_default_textdomain(); 1725 } 1726 1727 $topic_title = __('Your first topic'); 1605 1728 $topic_id = bb_insert_topic( 1606 1729 array( 1607 'topic_title' => __('Your first topic'),1730 'topic_title' => $topic_title, 1608 1731 'forum_id' => $forum_id, 1609 1732 'tags' => 'bbPress' 1610 1733 ) 1611 1734 ); 1612 $ installation_log[] = '>>>>>> ' . __('Topic:') . ' ' . __('Your first topic');1735 $post_text = __('First Post! w00t.'); 1613 1736 bb_insert_post( 1614 1737 array( 1615 1738 'topic_id' => $topic_id, 1616 'post_text' => __('First Post! w00t.')1739 'post_text' => $post_text 1617 1740 ) 1618 1741 ); 1619 $installation_log[] = '>>>>>>>>> ' . __('Post:') . ' ' . __('First Post! w00t.'); 1742 1743 if ($this->language != BB_LANG) { 1744 $locale = $this->language; 1745 unset($l10n['default']); 1746 load_default_textdomain(); 1747 } 1748 1749 $installation_log[] = '>>>>>> ' . __('Topic:') . ' ' . $topic_title; 1750 $installation_log[] = '>>>>>>>>> ' . __('Post:') . ' ' . $post_text; 1620 1751 } else { 1621 1752 $installation_log[] = '>>> ' . __('Forum could not be created!'); … … 1661 1792 } 1662 1793 1663 function input_text($key )1794 function input_text($key, $direction = false) 1664 1795 { 1665 1796 $data = $this->data[$this->step]['form'][$key]; … … 1693 1824 } 1694 1825 1695 $r .= '<input type="' . $type . '" id="' . $key . '" name="' . $key . '" class="text" value="' . $data['value'] . '"' . $maxlength . ' />' . "\n"; 1826 if ($direction) { 1827 $direction = ' dir="' . $direction . '"'; 1828 } 1829 1830 $r .= '<input' . $direction . ' type="' . $type . '" id="' . $key . '" name="' . $key . '" class="text" value="' . $data['value'] . '"' . $maxlength . ' />' . "\n"; 1696 1831 $r .= '</label>' . "\n"; 1697 1832 … … 1710 1845 } 1711 1846 1712 function textarea($key )1847 function textarea($key, $direction = false) 1713 1848 { 1714 1849 $data = $this->data[$this->step]['form'][$key]; … … 1720 1855 } 1721 1856 1722 $r .= '<textarea id="' . $key . '" rows="5" cols="30">' . $data['value'] . '</textarea>' . "\n"; 1857 if ($direction) { 1858 $direction = ' dir="' . $direction . '"'; 1859 } 1860 1861 $r .= '<textarea' . $direction . ' id="' . $key . '" rows="5" cols="30">' . $data['value'] . '</textarea>' . "\n"; 1723 1862 $r .= '</label>' . "\n"; 1724 1863 … … 1769 1908 1770 1909 echo $r; 1910 } 1911 1912 function select_language() 1913 { 1914 if (count($this->languages) > 1) { 1915 $this->data[1]['form']['bb_lang']['value'] = $this->language; 1916 $this->data[1]['form']['bb_lang']['options'] = $this->languages; 1917 $this->select('bb_lang'); 1918 } else { 1919 $this->data[1]['form']['bb_lang']['value'] = 'en_US'; 1920 $this->input_hidden('bb_lang'); 1921 } 1771 1922 } 1772 1923
Note: See TracChangeset
for help on using the changeset viewer.