Пример #1
0
 /**
  * Run Tool
  *
  * Does the actual stuff we want the tool to do after submission
  */
 function run_tool(&$error)
 {
     if (!check_form_key('organize_lang')) {
         $error[] = 'FORM_INVALID';
         return;
     }
     $file = request_var('file', '');
     if (!$file || !file_exists(TITANIA_ROOT . 'language/' . $file) && !file_exists(TITANIA_ROOT . 'language/' . $file . '.' . PHP_EXT)) {
         $error[] = 'NO_FILE';
         return;
     }
     organize_lang($file);
     trigger_back('ORGANIZE_LANG_SUCCESS');
 }
Пример #2
0
/**
* 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);
}