includes/lang.php
changeset 348 87e08a6e4fec
parent 345 4ccdfeee9a11
child 355 d15e4411ef65
--- a/includes/lang.php	Thu Jan 03 18:39:19 2008 -0500
+++ b/includes/lang.php	Wed Jan 16 13:55:49 2008 -0500
@@ -185,7 +185,16 @@
     global $db, $session, $paths, $template, $plugins; // Common objects
     
     if ( !file_exists($file) )
-      $db->_die('lang.php - requested JSON file doesn\'t exist');
+    {
+      if ( defined('IN_ENANO_INSTALL') )
+      {
+        die('lang.php - requested JSON file (' . htmlspecialchars($file) . ') doesn\'t exist');
+      }
+      else
+      {
+        $db->_die('lang.php - requested JSON file doesn\'t exist');
+      }
+    }
     
     $contents = trim(@file_get_contents($file));
     if ( empty($contents) )
@@ -206,7 +215,29 @@
     }
     else
     {
-      $langdata = enano_json_decode($contents);
+      // Correct syntax to be nice to the json parser
+    
+      // eliminate comments
+      $contents = preg_replace(array(
+              // eliminate single line comments in '// ...' form
+              '#^\s*//(.+)$#m',
+              // eliminate multi-line comments in '/* ... */' form, at start of string
+              '#^\s*/\*(.+)\*/#Us',
+              // eliminate multi-line comments in '/* ... */' form, at end of string
+              '#/\*(.+)\*/\s*$#Us'
+            ), '', $contents);
+      
+      $contents = preg_replace('/([,\{\[])([\s]*?)([a-z0-9_]+)([\s]*?):/', '\\1\\2"\\3" :', $contents);
+      
+      try
+      {
+        $langdata = enano_json_decode($contents);
+      }
+      catch(Zend_Json_Exception $e)
+      {
+        $db->_die('lang.php - Exception caught by JSON parser</p><pre>' . htmlspecialchars(print_r($e, true)) . '</pre><p>');
+        exit;
+      }
     
       if ( !is_array($langdata) )
         $db->_die('lang.php - invalid language file');