319 |
319 |
320 if ( $this->lang_id == 0 ) |
320 if ( $this->lang_id == 0 ) |
321 $db->_die('lang.php - BUG: trying to perform import when $lang->lang_id == 0'); |
321 $db->_die('lang.php - BUG: trying to perform import when $lang->lang_id == 0'); |
322 |
322 |
323 if ( $debug ) |
323 if ( $debug ) |
324 echo "Importing file: $file\n Checking file...\n"; |
324 $br = ( isset($_SERVER['REQUEST_URI']) ) ? '<br />' : ''; |
|
325 |
|
326 if ( $debug ) |
|
327 echo "Importing file: $file$br\n Checking file...$br\n"; |
325 |
328 |
326 $contents = trim(@file_get_contents($file)); |
329 $contents = trim(@file_get_contents($file)); |
327 |
330 |
328 if ( empty($contents) ) |
331 if ( empty($contents) ) |
329 $db->_die('lang.php - can\'t load the contents of the language file'); |
332 $db->_die('lang.php - can\'t load the contents of the language file'); |
330 |
333 |
331 if ( $debug ) |
334 if ( $debug ) |
332 echo " Cleaning up JSON\n"; |
335 echo " Cleaning up JSON$br\n"; |
333 |
336 |
334 // Trim off all text before and after the starting and ending braces |
337 // Trim off all text before and after the starting and ending braces |
335 $contents = preg_replace('/^([^{]+)\{/', '{', $contents); |
338 $contents = preg_replace('/^([^{]+)\{/', '{', $contents); |
336 $contents = preg_replace('/\}([^}]+)$/', '}', $contents); |
339 $contents = preg_replace('/\}([^}]+)$/', '}', $contents); |
337 |
340 |
338 // Correct syntax to be nice to the json parser |
341 // Correct syntax to be nice to the json parser |
339 $contents = enano_clean_json($contents); |
342 $contents = enano_clean_json($contents); |
340 |
343 |
341 if ( $debug ) |
344 if ( $debug ) |
342 echo " Decoding JSON stream\n"; |
345 echo " Decoding JSON stream$br\n"; |
343 |
346 |
344 try |
347 try |
345 { |
348 { |
346 $langdata = enano_json_decode($contents); |
349 $langdata = enano_json_decode($contents); |
347 } |
350 } |
439 global $db, $session, $paths, $template, $plugins; // Common objects |
442 global $db, $session, $paths, $template, $plugins; // Common objects |
440 |
443 |
441 if ( !isset($langdata['categories']) || !isset($langdata['strings']) ) |
444 if ( !isset($langdata['categories']) || !isset($langdata['strings']) ) |
442 $db->_die('lang.php - language file does not contain the proper items'); |
445 $db->_die('lang.php - language file does not contain the proper items'); |
443 |
446 |
|
447 if ( $debug ) |
|
448 $br = ( isset($_SERVER['REQUEST_URI']) ) ? '<br />' : ''; |
|
449 |
444 $insert_list = array(); |
450 $insert_list = array(); |
445 $delete_list = array(); |
451 $delete_list = array(); |
446 |
452 |
447 foreach ( $langdata['categories'] as $category ) |
453 foreach ( $langdata['categories'] as $category ) |
448 { |
454 { |
449 if ( isset($langdata['strings'][$category]) ) |
455 if ( isset($langdata['strings'][$category]) ) |
450 { |
456 { |
451 if ( $debug ) |
457 if ( $debug ) |
452 { |
458 { |
453 $desc = ( isset($langdata['strings']['meta'][$category]) ) ? $langdata['strings']['meta'][$category] : $this->get("meta_$category"); |
459 $desc = ( isset($langdata['strings']['meta'][$category]) ) ? $langdata['strings']['meta'][$category] : $this->get("meta_$category"); |
454 echo " Indexing category: $category ({$desc})\n"; |
460 echo " Indexing category: $category ({$desc})$br\n"; |
455 } |
461 } |
456 foreach ( $langdata['strings'][$category] as $string_name => $string_value ) |
462 foreach ( $langdata['strings'][$category] as $string_name => $string_value ) |
457 { |
463 { |
458 $string_name = $db->escape($string_name); |
464 $string_name = $db->escape($string_name); |
459 $string_value = $db->escape($string_value); |
465 $string_value = $db->escape($string_value); |
509 $db->_die('lang.php - couldn\'t insert strings in import()'); |
515 $db->_die('lang.php - couldn\'t insert strings in import()'); |
510 |
516 |
511 if ( $debug ) |
517 if ( $debug ) |
512 { |
518 { |
513 $time = round(microtime_float() - $start, 5); |
519 $time = round(microtime_float() - $start, 5); |
514 echo "({$time}s)\n"; |
520 echo "({$time}s)$br\n"; |
515 } |
521 } |
516 } |
522 } |
517 |
523 |
518 // YAY! done! |
524 // YAY! done! |
519 // This will regenerate the cache file if possible. |
525 // This will regenerate the cache file if possible. |
520 if ( $debug ) |
526 if ( $debug ) |
521 echo " Regenerating cache file\n"; |
527 echo " Regenerating cache file$br\n"; |
522 $this->regen_caches(); |
528 $this->regen_caches(); |
523 } |
529 } |
524 |
530 |
525 /** |
531 /** |
526 * Refetches the strings and writes out the cache file. |
532 * Refetches the strings and writes out the cache file. |