/** * Organize the language file by the lang keys, then re-output the data to the file */ function organize_lang($file, $skip_errors = false) { if (substr($file, -1) == '/') { $file = substr($file, 0, -1); } // If the user submitted a directory, do every language file in that directory if (is_dir(TITANIA_ROOT . 'language/' . $file)) { if ($handle = opendir(TITANIA_ROOT . 'language/' . $file)) { while (false !== ($file1 = readdir($handle))) { if ($file1 == '.' || $file1 == '..' || $file1 == '.svn') { continue; } if (strpos($file1, '.' . PHP_EXT)) { organize_lang($file . '/' . substr($file1, 0, strpos($file1, '.' . PHP_EXT)), true); } else { if (is_dir(TITANIA_ROOT . 'language/' . $file . '/' . $file1)) { organize_lang($file . '/' . $file1); } } } closedir($handle); } // if we went to a subdirectory, return if ($file != request_var('file', '') && $file . '/' != request_var('file', '')) { return; } // Finished entire directory return; } // include the file @(include TITANIA_ROOT . 'language/' . $file . '.' . PHP_EXT); // make sure it is a valid language file if (!isset($lang) || !is_array($lang)) { if ($skip_errors) { return; } trigger_back('Bad Language File. language/' . $file); } // setup the $output var $output = ''; // lets get the header of the file... $handle = @fopen(TITANIA_ROOT . 'language/' . $file . '.' . PHP_EXT, "r"); if ($handle) { $stopped = false; while (!feof($handle)) { $line = fgets($handle, 4096); // if the line is $lang = array_merge($lang, array( break out of the while loop if ($line == '$lang = array_merge($lang, array(' . "\n") { $stopped = true; break; } $output .= $line; } fclose($handle); if (!$stopped) { if ($skip_errors) { echo 'Bad line endings in ' . TITANIA_ROOT . 'language/' . $file . '.' . PHP_EXT . '<br />'; return; } trigger_back('Please make sure you are using UNIX line endings.'); } } // sort the languages by keys ksort($lang); // get the maximum length of the name string so we can format the page nicely when we output it $max_length = 1; find_max_length($lang, $max_length); // now add $lang = array_merge($lang, array( to the output $output .= '$lang = array_merge($lang, array('; lang_lines($lang, $max_length, $output); // add the end $output .= ')); '; // write the contents to the specified file file_put_contents(TITANIA_ROOT . 'language/' . $file . '.' . PHP_EXT, $output); }
/** * Organize the language file by the lang keys, then re-output the data to the file * * The Filename is inputted by sending it via a HTTP Get variable */ function organize_lang($file = false, $skip_errors = false) { global $phpbb_root_path, $phpEx; $file = $file === false ? request_var('file', 'en/mods/') : $file; if (substr($file, -1) == '/') { $file = substr($file, 0, -1); } // make sure they have a file name if ($file == '') { if ($skip_errors) { return; } trigger_error('No File Specified.'); } // make sure they are not trying to get out of the language directory, otherwise this would be a security risk. ;) if (strpos($file, '.')) { trigger_error('You are not allowed out of the language/ directory.'); } // If the user submitted a directory, do every language file in that directory if (is_dir($phpbb_root_path . 'language/' . $file)) { if ($handle = opendir($phpbb_root_path . 'language/' . $file)) { while (false !== ($file1 = readdir($handle))) { if ($file1 == '.' || $file1 == '..' || $file1 == '.svn') { continue; } if (strpos($file1, ".{$phpEx}")) { organize_lang($file . '/' . substr($file1, 0, strpos($file1, ".{$phpEx}")), true); } else { if (is_dir($phpbb_root_path . 'language/' . $file . '/' . $file1)) { organize_lang($file . '/' . $file1); } } } closedir($handle); } // if we went to a subdirectory, return if ($file != request_var('file', '') && $file . '/' != request_var('file', '')) { return; } trigger_error('Done organizing all of the language files in language/' . $file . '.'); } // include the file @(include $phpbb_root_path . 'language/' . $file . '.' . $phpEx); // make sure it is a valid language file if (!isset($lang) || !is_array($lang)) { if ($skip_errors) { return; } trigger_error('Bad Language File. language/' . $file); } // setup the $output var $output = ''; // lets get the header of the file... $handle = @fopen($phpbb_root_path . 'language/' . $file . '.' . $phpEx, "r"); if ($handle) { $stopped = false; while (!feof($handle)) { $line = fgets($handle, 4096); // if the line is $lang = array_merge($lang, array( break out of the while loop if ($line == '$lang = array_merge($lang, array(' . "\n") { $stopped = true; break; } $output .= $line; } fclose($handle); if (!$stopped) { if ($skip_errors) { echo 'Bad line endings in ' . $phpbb_root_path . 'language/' . $file . '.' . $phpEx . '<br />'; return; } trigger_error('Please make sure you are using UNIX line endings.'); } } // sort the languages by keys ksort($lang); // get the maximum length of the name string so we can format the page nicely when we output it $max_length = 1; find_max_length($lang, $max_length); // now add $lang = array_merge($lang, array( to the output $output .= '$lang = array_merge($lang, array('; lang_lines($lang, $max_length, $output); // add the end $output .= ')); ?>'; // write the contents to the specified file file_put_contents($phpbb_root_path . 'language/' . $file . '.' . $phpEx, $output); }