Commit bb74a497 authored by Aria Givi's avatar Aria Givi
Browse files

Code stellenweise optimiert, Hilfsfunktionen hinzugefügt zum richtigen Parsen der Daten

parent b581a2fa
...@@ -164,6 +164,16 @@ class LanguageController extends Controller ...@@ -164,6 +164,16 @@ class LanguageController extends Controller
$languageObjects = []; $languageObjects = [];
$to = []; $to = [];
#Dekodieren ausgeschlossener Dateien anhand des URL-Parameters
$ex = ['files' => [], 'new' => 0];
if ($exclude !== "") {
try {
$ex = unserialize(base64_decode($exclude));
} catch (\ErrorException $e) {
$ex = ['files' => [], 'new' => 0];
}
}
#Instanziiere LanguageObject #Instanziiere LanguageObject
foreach ($languageFolders as $folder) { foreach ($languageFolders as $folder) {
if (is_dir($languageFilePath . $folder) && $folder !== "." && $folder !== "..") { if (is_dir($languageFilePath . $folder) && $folder !== "." && $folder !== "..") {
...@@ -171,11 +181,16 @@ class LanguageController extends Controller ...@@ -171,11 +181,16 @@ class LanguageController extends Controller
} }
} }
#Speichere Daten in LanguageObject #Speichere Daten in LanguageObject, überspringe ausgeschlossene Dateien
foreach ($languageObjects as $folder => $languageObject) { foreach ($languageObjects as $folder => $languageObject) {
$to[] = $folder; $to[] = $folder;
$di = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($languageObject->filePath)); $di = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($languageObject->filePath));
foreach($di as $filename => $file) { foreach($di as $filename => $file) {
foreach($ex['files'] as $file) {
if($file === basename($filename)) {
continue 2;
}
}
if(!$this->endsWith($filename, ".")) { if(!$this->endsWith($filename, ".")) {
$tmp = include $filename; $tmp = include $filename;
foreach ($tmp as $key => $value) { foreach ($tmp as $key => $value) {
...@@ -185,26 +200,11 @@ class LanguageController extends Controller ...@@ -185,26 +200,11 @@ class LanguageController extends Controller
} }
} }
#Dekodieren ausgeschlossener Dateien anhand des URL-Parameters
$ex = ['files' => [], 'new' => 0];
if ($exclude !== "") {
try {
$ex = unserialize(base64_decode($exclude));
} catch (\ErrorException $e) {
$ex = ['files' => [], 'new' => 0];
}
}
$fn = ""; $fn = "";
#Wähle die erste Datei aus, welche nicht ausgeschlossen worden ist #Wähle die erste Datei aus
foreach($languageObjects as $folder => $languageObject) { foreach($languageObjects as $folder => $languageObject) {
foreach($languageObject->stringMap as $languageFileName => $languageFile) { foreach($languageObject->stringMap as $languageFileName => $languageFile) {
foreach($ex['files'] as $file) {
if($file === $languageFileName) {
continue 2;
}
}
$fn = $languageFileName; $fn = $languageFileName;
break 2; break 2;
} }
......
...@@ -118,7 +118,7 @@ class MailController extends Controller ...@@ -118,7 +118,7 @@ class MailController extends Controller
} }
#Ueberprueft ob ein bereits vorhandener Eintrag bearbeitet worden ist #Ueberprueft ob ein bereits vorhandener Eintrag bearbeitet worden ist
public function isEdited($k, $v, $filename) private function isEdited($k, $v, $filename)
{ {
$temp = include resource_path()."/".$filename; $temp = include resource_path()."/".$filename;
foreach ($temp as $key => $value) { foreach ($temp as $key => $value) {
...@@ -129,6 +129,27 @@ class MailController extends Controller ...@@ -129,6 +129,27 @@ class MailController extends Controller
return false; return false;
} }
private function extractLanguage($key)
{
preg_match("/^(?:_new_)?([^_]*)/", $key, $matches);
foreach($matches as $dir) {
if(strlen($dir) == 2)
return $dir;
}
}
private function processKey($key)
{
$key = trim($key);
preg_match("/^(?:_new_)?(?:[^_]*)_(\w*#?\w*)/", $key, $matches);
foreach($matches as $processedKey) {
if(strpos($processedKey, "_") === FALSE) {
return $processedKey;
}
}
return $key;
}
public function sendLanguageFile(Request $request, $from, $to, $exclude = "", $email ="") public function sendLanguageFile(Request $request, $from, $to, $exclude = "", $email ="")
{ {
$filename = $request->input('filename'); $filename = $request->input('filename');
...@@ -152,8 +173,7 @@ class MailController extends Controller ...@@ -152,8 +173,7 @@ class MailController extends Controller
$key = substr($key, strpos($key, "_new_") + 5); $key = substr($key, strpos($key, "_new_") + 5);
$editedKeys = $editedKeys."\n".$key; $editedKeys = $editedKeys."\n".$key;
} } else if ($this->isEdited($key, $value, $filename)) {
else if ($this->isEdited($key, $value, $filename)) {
$new++; $new++;
$editedKeys = $editedKeys."\n".$key; $editedKeys = $editedKeys."\n".$key;
} }
...@@ -205,8 +225,7 @@ class MailController extends Controller ...@@ -205,8 +225,7 @@ class MailController extends Controller
if($emailAddress !== "") { if($emailAddress !== "") {
Mail::to("aria@suma-ev.de") Mail::to("aria@suma-ev.de")
->send(new Sprachdatei($message, $output, basename($filename), $emailAddress)); ->send(new Sprachdatei($message, $output, basename($filename), $emailAddress));
} } else {
else {
Mail::to("aria@suma-ev.de") Mail::to("aria@suma-ev.de")
->send(new Sprachdatei($message, $output, basename($filename))); ->send(new Sprachdatei($message, $output, basename($filename)));
} }
...@@ -217,47 +236,36 @@ class MailController extends Controller ...@@ -217,47 +236,36 @@ class MailController extends Controller
} }
public function downloadModifiedLanguagefiles(Request $request, $exclude = "") { public function downloadModifiedLanguagefiles(Request $request, $exclude = "") {
$filename = $request->input('filename'); $filename = $request->input('filename');
# Wir erstellen nun zunächst den Inhalt der Datei:
$data = []; $data = [];
$new = 0; $new = 0;
$emailAddress = ""; $editedFiles = [];
$editedKeys = "";
foreach ($request->all() as $key => $value) { foreach ($request->all() as $key => $value) {
if ($key === "filename" || $value === "") { if ($key === "filename" || $value === "") {
continue; continue;
} }
$key = base64_decode($key); $key = base64_decode($key);
#Pfad zur Datei anhand des Schlüsselnamens rekonstruieren (Schlüssel enthält Sprachkürzel) #Pfad zur Datei anhand des Schlüsselnamens rekonstruieren (Schlüssel enthält Sprachkürzel)
$filename = "languages/".substr($key, strpos($key, "/_\w\w_/"), strripos($key, "_"))."/".$filename; $langdir = $this->extractLanguage($key);
$fn = "lang/".$langdir."/".$filename;
if (strpos($key, "_new_") === 0 && $value !== "") { if (strpos($key, "_new_") === 0 && $value !== "") {
$new++; $new++;
$key = preg_filter("/_\w*_/", "", $key); $editedFiles[$langdir] = $filename;
$editedKeys = $editedKeys."\n".$key; } else if ($this->isEdited($key, $value, $fn)) {
}
else if ($this->isEdited($key, $value, $filename)) {
$new++; $new++;
$editedKeys = $editedKeys."\n".$key; $editedFiles[$langdir] = $filename;
} }
$key = trim($key); #Key verarbeiten, sodass er nur den eigentlichen Keynamen enthält
if (!strpos($key, "#")) { $key = $this->processKey($key);
$data[$key] = $value; $data[$langdir][$key] = $value;
} else { }
$ref = &$data;
do {
$ref = &$ref[substr($key, 0, strpos($key, "#"))];
$key = substr($key, strpos($key, "#") + 1);
} while (strpos($key, "#"));
$ref = &$ref[$key];
$ref = $value;
}
}
$output = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); $output = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$output = preg_replace("/\{/si", "[", $output); $output = preg_replace("/\{/si", "[", $output);
$output = preg_replace("/\}/si", "]", $output); $output = preg_replace("/\}/si", "]", $output);
...@@ -265,10 +273,6 @@ class MailController extends Controller ...@@ -265,10 +273,6 @@ class MailController extends Controller
$output = "<?php\n\nreturn $output;\n"; $output = "<?php\n\nreturn $output;\n";
$message = "Moin moin,\n\nein Benutzer hat eine Sprachdatei aktualisiert.\nBearbeitet wurden die Einträge: $editedKeys\n\nSollten die Texte so in Ordnung sein, ersetzt, oder erstellt die Datei aus dem Anhang in folgendem Pfad:\n$filename\n\nFolgend zusätzlich der Inhalt der Datei:\n\n$output";
# Wir haben nun eine Mail an uns geschickt, welche die entsprechende Datei beinhaltet.
# Nun müssen wir den Nutzer eigentlich nur noch zurück leiten und die Letzte bearbeitete Datei ausschließen:
$ex = []; $ex = [];
if ($exclude !== "") { if ($exclude !== "") {
try { try {
......
...@@ -29,15 +29,15 @@ ...@@ -29,15 +29,15 @@
<tbody> <tbody>
@foreach($texts as $key => $language) @foreach($texts as $key => $language)
<tr> <!--Key --> <tr> <!--Key -->
<td class="name language-name">{{preg_replace("/(\s*).*#(.*)$/si", "$1$2", $key)}}</td> <td class="name language-name">{{$key}}</td>
@foreach($language as $lang => $languageValue) @foreach($language as $lang => $languageValue)
@if($languageValue !== "") @if($languageValue !== "")
<td> <td>
<textarea class="language-text-area" rows="1" readonly cols="20" form="submit" name="{{base64_encode($lang."_".$key)}}">{{ $languageValue }} </textarea> <textarea class="language-text-area" rows="1" cols="20" form="submit" name="{{base64_encode($lang."_".$key)}}">{{ $languageValue }} </textarea>
</td> </td>
@else @else
<td> <td>
<textarea class="language-text-area" rows="1" cols="20" form="submit" name="{{base64_encode("_new_".$lang."_".$key)}}">{{ $languageValue }} </textarea> <textarea class="language-text-area" rows="1" cols="20" form="submit" name="{{base64_encode("_new_".$lang."_".$key)}}"></textarea>
</td> </td>
@endif @endif
@endforeach @endforeach
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment