function doPost($strSource, $strDest) { if (!in_array($strDest, getLangFiles())) { if (copy($strSource, $strDest)) { iniTable(); echo "<h1>File created successfully</h1>"; echo "you can now edit your file: <a href=edit.php?lang={$strDest}>{$strDest}</a><br>"; echo "or you can also <a href=index.php>go back to the main page</a>"; endTable(); } else { showError("There was an error creating the file, please try again in a few minutes."); } } else { showError("That file already exists."); } }
<?php include_once 'langList.php'; include_once 'common.php'; echoStyle(); if (isset($_POST['strLine'], $_POST['intLine'], $_POST['fileName'])) { doPost($_POST['strLine'], $_POST['intLine'], $_POST['fileName']); } elseif (isset($_GET['lang'])) { $filename = strtolower($_GET['lang']); if ($filename != "") { if (in_array($filename, getLangFiles())) { showEdit($filename); } else { badData("LANGUAGE FILE (" . $filename . ") NOT FOUND"); } } else { badData("NO LANGUAGE FILE ENTERED"); } } else { badData("NO LANGUAGE FILE ENTERED"); } function doPost($strLine, $intLine, $fileName) { $strLine = str_replace("\\", "", $strLine); if (substr($strLine, 0, 1) != '"' or substr($strLine, -2) != '";') { showError('All lines must start with " and end with "; ', $strLine); } else { $flines = file($fileName); //Update the line $flines[$intLine] = substr($flines[$intLine], 0, 40) . $strLine . "\n"; //reWrite the file
//print("search for $stringToSearch..."); for ($i = 0; $i < $stop; $i++) { if (substr_count($old[$i], $stringToSearch) == 1) { // print("found!<br>"); return $old[$i]; } } //print("not found!<br>"); return false; // if ereg string // return whole line // else false } // opens original files and save in array $english = getFileInArray(ORIGINAL_FILE_PATH); $all = getLangFiles(); //$all = array('../../langs/cz-utf-8.php'); //, '../../langs/si-utf-8.php'); foreach ($all as $file) { print $file . "<br><br>"; $fileDestination = PATH_DESTINATION . substr($file, strrpos($file, '/') + 1); print "<br>" . $fileDestination; $new = $english; $old = getFileInArray($file); // algo // go througt $new file $currentLine = 0; foreach ($new as $newLine) { $stringToSearch = ''; if (ereg("] =", $newLine)) { $stringToSearch = substr($newLine, 0, strpos($newLine, '=')); // print($stringToSearch . "<br>");
function doPost($strKey, $strValue) { if (substr($strKey, 0, 2) == '//') { $strNewLine = "\n " . $strKey . $strValue . "\n"; } else { $strNewLine = " " . str_pad($strKey, 29) . " = " . $strValue . "\n"; } foreach (getLangFiles() as $key => $fileName) { //Search for the end of the dictionary $flines = file($fileName); for ($i = count($flines); $i > 1; $i--) { $flines[$i + 1] = $flines[$i]; if (trim($flines[$i]) == "}") { break; } } if (trim($flines[$i]) == "}") { //Update the line $flines[$i] = $strNewLine; //reWrite the file $fh = fopen($fileName, 'w'); while (1) { if (flock($fh, LOCK_EX)) { fwrite($fh, implode("", $flines)); flock($fh, LOCK_UN); break; } } } } return "Data added successfully: <br><br>" . htmlspecialchars($strNewLine); }