equal
deleted
inserted
replaced
183 function load_file($file) |
183 function load_file($file) |
184 { |
184 { |
185 global $db, $session, $paths, $template, $plugins; // Common objects |
185 global $db, $session, $paths, $template, $plugins; // Common objects |
186 |
186 |
187 if ( !file_exists($file) ) |
187 if ( !file_exists($file) ) |
188 $db->_die('lang.php - requested JSON file doesn\'t exist'); |
188 { |
|
189 if ( defined('IN_ENANO_INSTALL') ) |
|
190 { |
|
191 die('lang.php - requested JSON file (' . htmlspecialchars($file) . ') doesn\'t exist'); |
|
192 } |
|
193 else |
|
194 { |
|
195 $db->_die('lang.php - requested JSON file doesn\'t exist'); |
|
196 } |
|
197 } |
189 |
198 |
190 $contents = trim(@file_get_contents($file)); |
199 $contents = trim(@file_get_contents($file)); |
191 if ( empty($contents) ) |
200 if ( empty($contents) ) |
192 $db->_die('lang.php - empty language file...'); |
201 $db->_die('lang.php - empty language file...'); |
193 |
202 |
204 { |
213 { |
205 $this->load_cache_file("./cache/lang_json_{$checksum}.php"); |
214 $this->load_cache_file("./cache/lang_json_{$checksum}.php"); |
206 } |
215 } |
207 else |
216 else |
208 { |
217 { |
209 $langdata = enano_json_decode($contents); |
218 // Correct syntax to be nice to the json parser |
|
219 |
|
220 // eliminate comments |
|
221 $contents = preg_replace(array( |
|
222 // eliminate single line comments in '// ...' form |
|
223 '#^\s*//(.+)$#m', |
|
224 // eliminate multi-line comments in '/* ... */' form, at start of string |
|
225 '#^\s*/\*(.+)\*/#Us', |
|
226 // eliminate multi-line comments in '/* ... */' form, at end of string |
|
227 '#/\*(.+)\*/\s*$#Us' |
|
228 ), '', $contents); |
|
229 |
|
230 $contents = preg_replace('/([,\{\[])([\s]*?)([a-z0-9_]+)([\s]*?):/', '\\1\\2"\\3" :', $contents); |
|
231 |
|
232 try |
|
233 { |
|
234 $langdata = enano_json_decode($contents); |
|
235 } |
|
236 catch(Zend_Json_Exception $e) |
|
237 { |
|
238 $db->_die('lang.php - Exception caught by JSON parser</p><pre>' . htmlspecialchars(print_r($e, true)) . '</pre><p>'); |
|
239 exit; |
|
240 } |
210 |
241 |
211 if ( !is_array($langdata) ) |
242 if ( !is_array($langdata) ) |
212 $db->_die('lang.php - invalid language file'); |
243 $db->_die('lang.php - invalid language file'); |
213 |
244 |
214 if ( !isset($langdata['categories']) || !isset($langdata['strings']) ) |
245 if ( !isset($langdata['categories']) || !isset($langdata['strings']) ) |