protected function parse($filename) { $version = phpversion(); // Capture hidden PHP errors from the parsing. $php_errormsg = null; $track_errors = ini_get('track_errors'); ini_set('track_errors', true); if ($version >= '5.3.1') { $contents = file_get_contents($filename); $contents = str_replace('_QQ_', '"\\""', $contents); $strings = @parse_ini_string($contents); } else { $strings = @parse_ini_file($filename); if ($version == '5.3.0' && is_array($strings)) { foreach ($strings as $key => $string) { $strings[$key] = str_replace('_QQ_', '"', $string); } } } // Restore error tracking to what it was before. ini_set('track_errors', $track_errors); if (!is_array($strings)) { $strings = array(); } if ($this->debug) { // Initialise variables for manually parsing the file for common errors. $blacklist = array('YES', 'NO', 'NULL', 'FALSE', 'ON', 'OFF', 'NONE', 'TRUE'); $regex = '/^(|(\\[[^\\]]*\\])|([A-Z][A-Z0-9_\\-]*\\s*=(\\s*(("[^"]*")|(_QQ_)))+))\\s*(;.*)?$/'; $this->debug = false; $errors = array(); $lineNumber = 0; // Open the file as a stream. $stream = new MStream(); $stream->open($filename); while (!$stream->eof()) { $line = $stream->gets(); // Avoid BOM error as BOM is OK when using parse_ini if ($lineNumber == 0) { $line = str_replace("", '', $line); } $lineNumber++; // Check that the key is not in the blacklist and that the line format passes the regex. $key = strtoupper(trim(substr($line, 0, strpos($line, '=')))); if (!preg_match($regex, $line) || in_array($key, $blacklist)) { $errors[] = $lineNumber; } } $stream->close(); // Check if we encountered any errors. if (count($errors)) { if (basename($filename) != $this->lang . '.ini') { $this->errorfiles[$filename] = $filename . MText::sprintf('MERROR_PARSING_LANGUAGE_FILE', implode(', ', $errors)); } else { $this->errorfiles[$filename] = $filename . ' : error(s) in line(s) ' . implode(', ', $errors); } } elseif ($php_errormsg) { // We didn't find any errors but there's probably a parse notice. $this->errorfiles['PHP' . $filename] = 'PHP parser errors :' . $php_errormsg; } $this->debug = true; } return $strings; }