includes/lang.php
changeset 516 9a52679143db
parent 514 ecbfb747743e
child 519 94214ec0871c
equal deleted inserted replaced
515:be77f34d03af 516:9a52679143db
   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     }
   355     {
   358     {
   356       $db->_die('lang.php - invalid or non-well-formed language file');
   359       $db->_die('lang.php - invalid or non-well-formed language file');
   357     }
   360     }
   358     
   361     
   359     if ( $debug )
   362     if ( $debug )
   360       echo "  Starting string import\n";
   363       echo "  Starting string import$br\n";
   361     
   364     
   362     return $this->import_array($langdata, $debug);
   365     return $this->import_array($langdata, $debug);
   363   }
   366   }
   364   
   367   
   365   /**
   368   /**
   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);
   485     }
   491     }
   486     
   492     
   487     if ( $debug )
   493     if ( $debug )
   488     {
   494     {
   489       $time = round(microtime_float() - $start, 5);
   495       $time = round(microtime_float() - $start, 5);
   490       echo "({$time}s)\n";
   496       echo "({$time}s)$br\n";
   491     }
   497     }
   492     
   498     
   493     if ( !empty($insert_list) )
   499     if ( !empty($insert_list) )
   494     {
   500     {
   495       if ( $debug )
   501       if ( $debug )
   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.