includes/lang.php
changeset 334 c72b545f1304
parent 243 a7d0f2711df1
child 335 67bd3121a12e
equal deleted inserted replaced
333:32429702305e 334:c72b545f1304
   214     {
   214     {
   215       $this->load_cache_file("./cache/lang_json_{$checksum}.php");
   215       $this->load_cache_file("./cache/lang_json_{$checksum}.php");
   216     }
   216     }
   217     else
   217     else
   218     {
   218     {
   219       $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
   219       $langdata = enano_json_decode($contents);
   220       $langdata = $json->decode($contents);
       
   221     
   220     
   222       if ( !is_array($langdata) )
   221       if ( !is_array($langdata) )
   223         $db->_die('lang.php - invalid language file');
   222         $db->_die('lang.php - invalid language file');
   224       
   223       
   225       if ( !isset($langdata['categories']) || !isset($langdata['strings']) )
   224       if ( !isset($langdata['categories']) || !isset($langdata['strings']) )
   297     
   296     
   298     // Trim off all text before and after the starting and ending braces
   297     // Trim off all text before and after the starting and ending braces
   299     $contents = preg_replace('/^([^{]+)\{/', '{', $contents);
   298     $contents = preg_replace('/^([^{]+)\{/', '{', $contents);
   300     $contents = preg_replace('/\}([^}]+)$/', '}', $contents);
   299     $contents = preg_replace('/\}([^}]+)$/', '}', $contents);
   301     
   300     
   302     $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
   301     // Correct syntax to be nice to the json parser
   303     $langdata = $json->decode($contents);
   302     
       
   303     // eliminate comments
       
   304     $contents = preg_replace(array(
       
   305             // eliminate single line comments in '// ...' form
       
   306             '#^\s*//(.+)$#m',
       
   307             // eliminate multi-line comments in '/* ... */' form, at start of string
       
   308             '#^\s*/\*(.+)\*/#Us',
       
   309             // eliminate multi-line comments in '/* ... */' form, at end of string
       
   310             '#/\*(.+)\*/\s*$#Us'
       
   311           ), '', $contents);
       
   312     
       
   313     $contents = preg_replace('/([,\{\[])([\s]*?)([a-z0-9_]+)([\s]*?):/', '\\1\\2"\\3" :', $contents);
       
   314     
       
   315     try
       
   316     {
       
   317       $langdata = enano_json_decode($contents);
       
   318     }
       
   319     catch(Zend_Json_Exception $e)
       
   320     {
       
   321       $db->_die('lang.php - Exception caught by JSON parser');
       
   322       exit;
       
   323     }
   304     
   324     
   305     if ( !is_array($langdata) )
   325     if ( !is_array($langdata) )
   306       $db->_die('lang.php - invalid language file');
   326     {
       
   327       $db->_die('lang.php - invalid or non-well-formed language file');
       
   328     }
   307     
   329     
   308     if ( !isset($langdata['categories']) || !isset($langdata['strings']) )
   330     if ( !isset($langdata['categories']) || !isset($langdata['strings']) )
   309       $db->_die('lang.php - language file does not contain the proper items');
   331       $db->_die('lang.php - language file does not contain the proper items');
   310     
   332     
   311     $insert_list = array();
   333     $insert_list = array();