|
1 <?php |
|
2 |
|
3 /* |
|
4 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
5 * Version 1.0.3 (Dyrad) |
|
6 * Copyright (C) 2006-2007 Dan Fuhry |
|
7 * |
|
8 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
9 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
10 * |
|
11 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
13 */ |
|
14 |
|
15 function page_Admin_LangManager() |
|
16 { |
|
17 global $db, $session, $paths, $template, $plugins; // Common objects |
|
18 global $lang; |
|
19 if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN ) |
|
20 { |
|
21 $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true); |
|
22 echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>'; |
|
23 echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>'; |
|
24 return; |
|
25 } |
|
26 if ( isset($_POST['action']) ) |
|
27 { |
|
28 $action =& $_POST['action']; |
|
29 if ( strpos($action, ';') ) |
|
30 { |
|
31 $parms = substr($action, strpos($action, ';') + 1); |
|
32 $action = substr($action, 0, strpos($action, ';')); |
|
33 preg_match_all('/([a-z0-9_]+)=(.+?)(;|$)/', $parms, $matches); |
|
34 $parms = array(); |
|
35 foreach ( $matches[0] as $i => $_ ) |
|
36 { |
|
37 $parms[$matches[1][$i]] = $matches[2][$i]; |
|
38 } |
|
39 } |
|
40 switch ( $action ) |
|
41 { |
|
42 case 'edit_language': |
|
43 break; |
|
44 case 'install_language': |
|
45 $lang_list = list_available_languages(); |
|
46 // Verify that we have this language's metadata |
|
47 if ( isset($lang_list[@$parms['iso639']]) ) |
|
48 { |
|
49 // From here it's all downhill :-) |
|
50 $lang_code =& $parms['iso639']; |
|
51 $lang_data =& $lang_list[$lang_code]; |
|
52 |
|
53 $result = install_language($lang_code, $lang_data['name_eng'], $lang_data['name']); |
|
54 if ( $result ) |
|
55 { |
|
56 // Language installed. Import the language files. |
|
57 $lang_local = new Language($lang_code); |
|
58 foreach ( array('core', 'admin', 'tools', 'user') as $file ) |
|
59 { |
|
60 $lang_local->import(ENANO_ROOT . "/language/{$lang_data['dir']}/$file.json"); |
|
61 } |
|
62 unset($lang_local); |
|
63 |
|
64 echo '<div class="info-box">' . $lang->get('acplm_msg_lang_install_success', array('lang_name' => htmlspecialchars($lang_data['name_eng']))) . '</div>'; |
|
65 } |
|
66 } |
|
67 break; |
|
68 } |
|
69 } |
|
70 |
|
71 // $lang_list is fetched by the posthandler sometimes |
|
72 if ( !isset($lang_list) ) |
|
73 { |
|
74 // Build a list of languages in the languages/ directory, then |
|
75 // eliminate the ones that are already installed. |
|
76 $lang_list = list_available_languages(); |
|
77 } |
|
78 |
|
79 // Select current languages |
|
80 $q = $db->sql_query('SELECT lang_code FROM ' . table_prefix . "language;"); |
|
81 if ( !$q ) |
|
82 $db->_die(); |
|
83 |
|
84 while ( $row = $db->fetchrow() ) |
|
85 { |
|
86 $lang_code =& $row['lang_code']; |
|
87 if ( isset($lang_list[$lang_code]) ) |
|
88 { |
|
89 unset($lang_list[$lang_code]); |
|
90 unset($lang_list[$lang_code]); // PHP <5.1.4 Zend bug |
|
91 } |
|
92 } |
|
93 |
|
94 if ( count($lang_list) > 0 ) |
|
95 { |
|
96 echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post">'; |
|
97 echo '<h3>' . $lang->get('acplm_heading_install') . '</h3>'; |
|
98 echo '<div class="tblholder"> |
|
99 <table border="0" cellspacing="1" cellpadding="4"> |
|
100 <tr> |
|
101 <th>' . $lang->get('acplm_col_lang_code') . '</th> |
|
102 <th>' . $lang->get('acplm_col_lang_name') . '</th> |
|
103 <th>' . $lang->get('acplm_col_lang_name_eng') . '</th> |
|
104 <th></th> |
|
105 </tr>'; |
|
106 |
|
107 $cls = 'row2'; |
|
108 foreach ( $lang_list as $lang_code => $lang_data ) |
|
109 { |
|
110 $cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; |
|
111 |
|
112 echo '<tr>'; |
|
113 |
|
114 $lang_code = htmlspecialchars($lang_code); |
|
115 $lang_data['name'] = htmlspecialchars($lang_data['name']); |
|
116 $lang_data['name_eng'] = htmlspecialchars($lang_data['name_eng']); |
|
117 |
|
118 echo "<td class=\"$cls\" style=\"text-align: center;\">$lang_code</td>"; |
|
119 echo "<td class=\"$cls\" style=\"text-align: center;\">{$lang_data['name']}</td>"; |
|
120 echo "<td class=\"$cls\" style=\"text-align: center;\">{$lang_data['name_eng']}</td>"; |
|
121 echo "<td class=\"$cls\" style=\"text-align: center;\"><button name=\"action\" value=\"install_language;iso639=$lang_code\">" . $lang->get('acplm_btn_install_language') . "</button></td>"; |
|
122 |
|
123 echo '</tr>'; |
|
124 } |
|
125 echo ' </tr> |
|
126 </table> |
|
127 </div>'; |
|
128 echo '</form>'; |
|
129 } |
|
130 } |
|
131 |