Changeset 5371 for trunk/admin/include/languages.class.php
- Timestamp:
- Mar 26, 2010, 1:55:12 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/languages.class.php
r5357 r5371 37 37 38 38 /** 39 * Set tabsheet for languages pages. 40 * @param string selected page. 41 */ 42 function set_tabsheet($selected) 43 { 44 include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); 45 46 $link = get_root_url().'admin.php?page='; 47 48 $tabsheet = new tabsheet(); 49 $tabsheet->add('languages_installed', l10n('Installed Languages'), $link.'languages_installed'); 50 $tabsheet->add('languages_new', l10n('Add New Language'), $link.'languages_new'); 51 $tabsheet->select($selected); 52 $tabsheet->assign(); 53 } 54 55 /** 39 56 * Perform requested actions 40 57 * @param string - action … … 171 188 $this->db_languages[ $row['id'] ] = $row['name']; 172 189 } 190 } 191 192 /** 193 * Retrieve PEM server datas to $server_languages 194 */ 195 function get_server_languages() 196 { 197 global $user; 198 199 $pem_category_id = 8; 200 201 // Retrieve PEM versions 202 $version = PHPWG_VERSION; 203 $versions_to_check = array(); 204 $url = PEM_URL . '/api/get_version_list.php?category_id='.$pem_category_id.'&format=php'; 205 if (fetchRemote($url, $result) and $pem_versions = @unserialize($result)) 206 { 207 if (!preg_match('/^\d+\.\d+\.\d+/', $version)) 208 { 209 $version = $pem_versions[0]['name']; 210 } 211 $branch = substr($version, 0, strrpos($version, '.')); 212 foreach ($pem_versions as $pem_version) 213 { 214 if (strpos($pem_version['name'], $branch) === 0) 215 { 216 $versions_to_check[] = $pem_version['id']; 217 } 218 } 219 } 220 if (empty($versions_to_check)) 221 { 222 return false; 223 } 224 225 // Retrieve PEM languages infos 226 $url = PEM_URL . '/api/get_revision_list.php?category_id='.$pem_category_id.'&format=php&last_revision_only=true'; 227 $url .= '&version=' . implode(',', $versions_to_check); 228 $url .= '&lang='.$user['language']; 229 230 if (fetchRemote($url, $result)) 231 { 232 $pem_languages = @unserialize($result); 233 if (!is_array($pem_languages)) 234 { 235 return false; 236 } 237 foreach ($pem_languages as $language) 238 { 239 if (preg_match('/^.*? \[[A-Z]{2}\]$/', $language['extension_name']) 240 and !in_array($language['extension_name'], $this->fs_languages)) 241 { 242 $this->server_languages[] = $language; 243 } 244 } 245 return true; 246 } 247 return false; 248 } 249 250 /** 251 * Extract language files from archive 252 * 253 * @param string - install or upgrade 254 * @param string - remote revision identifier (numeric) 255 * @param string - language id or extension id 256 */ 257 function extract_language_files($action, $revision, $dest='') 258 { 259 if ($archive = tempnam( PHPWG_ROOT_PATH.'language', 'zip')) 260 { 261 $url = PEM_URL . '/download.php?rid=' . $revision; 262 $url .= '&origin=piwigo_' . $action; 263 264 if ($handle = @fopen($archive, 'wb') and fetchRemote($url, $handle)) 265 { 266 fclose($handle); 267 include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php'); 268 $zip = new PclZip($archive); 269 if ($list = $zip->listContent()) 270 { 271 foreach ($list as $file) 272 { 273 // we search iso.txt in archive 274 if (basename($file['filename']) == 'iso.txt' 275 and (!isset($main_filepath) 276 or strlen($file['filename']) < strlen($main_filepath))) 277 { 278 $main_filepath = $file['filename']; 279 } 280 } 281 if (isset($main_filepath)) 282 { 283 $root = basename(dirname($main_filepath)); // iso.txt path in archive 284 if (preg_match('/^[a-z]{2}_[A-Z]{2}$/', $root)) 285 { 286 if ($action == 'install') 287 { 288 $dest = $root; 289 } 290 $extract_path = PHPWG_ROOT_PATH.'language/'.$dest; 291 if ( 292 $result = $zip->extract( 293 PCLZIP_OPT_PATH, $extract_path, 294 PCLZIP_OPT_REMOVE_PATH, $root, 295 PCLZIP_OPT_REPLACE_NEWER 296 ) 297 ) 298 { 299 foreach ($result as $file) 300 { 301 if ($file['stored_filename'] == $main_filepath) 302 { 303 $status = $file['status']; 304 break; 305 } 306 } 307 if ($status == 'ok') 308 { 309 $this->fs_languages = $this->get_fs_languages(); 310 $this->perform_action('activate', $dest); 311 } 312 if (file_exists($extract_path.'/obsolete.list') 313 and $old_files = file($extract_path.'/obsolete.list', FILE_IGNORE_NEW_LINES) 314 and !empty($old_files)) 315 { 316 array_push($old_files, 'obsolete.list'); 317 foreach($old_files as $old_file) 318 { 319 $path = $extract_path.'/'.$old_file; 320 if (is_file($path)) 321 { 322 @unlink($path); 323 } 324 elseif (is_dir($path)) 325 { 326 if (!$this->deltree($path)) 327 { 328 $this->send_to_trash($path); 329 } 330 } 331 } 332 } 333 } 334 else $status = 'extract_error'; 335 } 336 else $status = 'archive_error'; 337 } 338 else $status = 'archive_error'; 339 } 340 else $status = 'archive_error'; 341 } 342 else $status = 'dl_archive_error'; 343 } 344 else $status = 'temp_path_error'; 345 346 @unlink($archive); 347 return $status; 173 348 } 174 349
Note: See TracChangeset
for help on using the changeset viewer.