CMXX - Myaccount

This commit is contained in:
“VeLiTi”
2025-02-23 15:25:46 +01:00
parent 0b2ee8c3ce
commit 5dd2973a26
12 changed files with 440 additions and 223 deletions

View File

@@ -1,66 +1,90 @@
<?php
defined('admin') or exit;
// Capture post data
if (isset($_POST['language_US'], $_POST['language_NL'])) {
// Save templates
file_put_contents(dirname(__FILE__,-1).'/custom/translations/translations_US.php', $_POST['language_US']);
file_put_contents(dirname(__FILE__,-1).'/custom/translations/translations_NL.php', $_POST['language_NL']);
header('Location: index.php?page=language&success_msg=1');
exit;
}
// Read language_US template PHP file
$contents = file_get_contents(dirname(__FILE__,-1).'/custom/translations/translations_US.php');
// Read language template PHP file
$contents2 = file_get_contents(dirname(__FILE__,-1).'/custom/translations/translations_NL.php');
// Handle success messages
if (isset($_GET['success_msg'])) {
if ($_GET['success_msg'] == 1) {
$success_msg = 'Settings updated successfully!';
}
}
?>
//------------------------------------------
// Languages supported
//------------------------------------------
$supportedLanguages = ['US', 'NL', 'DE', 'ES','FR', 'IT'];
if(isset($_POST['generatefile'])){
<?=template_admin_header('Language', 'language')?>
$language_key = (isset($_POST['language'])) ? $_POST['language'] : '';
<form action="" method="post">
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
<h2 class="responsive-width-100">Translations</h2>
<input type="submit" name="submit" value="Save" class="btn">
</div>
<?php if (isset($success_msg)): ?>
<div class="msg success">
<i class="fas fa-check-circle"></i>
<p><?=$success_msg?></p>
<i class="fas fa-times"></i>
</div>
<?php endif; ?>
<div class="tabs">
<a href="#" class="active">US</a>
<a href="#" class="">NL</a>
</div>
<div class="content-block">
<div class="form responsive-width-100">
function generateFile($language_key,$token){
//GET TRANSLATION RECORDS
$api_url = '/v2/translations/generatefile='.$language_key;
$responses = ioAPIv2($api_url,'',$token);
if (!empty($responses)){
//define translation variable
$translation = '<?php'.PHP_EOL;
<div class="tab-content active">
<label for="language_US">Language_US:</label>
<textarea name="language_US" id="language_US" style="min-height: 100vh;"><?=$contents?></textarea>
</div>
<div class="tab-content">
<label for="language_NL">Language_NL:</label>
<textarea name="language_NL" id="language_NL" style="min-height: 100vh;"><?=$contents2?></textarea>
</div>
//decode the API response
$responses = json_decode($responses,true);
//loop through translation records and create variables
foreach ($responses as $response){
$text = str_replace(
['\\', "'", "\r", "\n", "\0", "\t"],
['\\\\', "\\'", '\\r', '\\n', '\\0', '\\t'],
$response['translation']
);
//create variable_name = translation per item
$translation .= '$'.$response['variable'].' = \''.$text.'\';'.PHP_EOL;
}
//ADD closure tag for PHP
$translation .= '?>';
//Target dir
$target_dir = '../custom/translations/';
//Filename
$input_file = $target_dir.'translations_'.strtoupper($language_key).'.php';
//store translation to the file
file_put_contents($input_file, $translation);
}
}
if ($language_key != ''){
generateFile($language_key,$clientsecret);
} else {
foreach ($supportedLanguages as $language){
generateFile($language,$clientsecret);
}
}
}
template_admin_header('Language', 'language');
$view .='
<form action="" method="post">
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
<h2 class="responsive-width-100">Maintenance</h2>
</div>';
$view .= '<div class="tabs">
<a href="#" class="active">'.($general_actions ?? 'Actions' ).'</a>
</div>
';
$view .= '<div class="content-block tab-content active">
<div class="form responsive-width-100">
<label for="">Language</label>
<select id="language" name="language">';
$view .='<option value=""></option>';
foreach ($supportedLanguages as $language){
$view .='<option value="'.$language.'">'.$language.'</option>';
}
$view .=' </select>
<input type="submit" name="generatefile" style="width: 15%;" value="Generate language" class="btn">
</div>
</div>';
</form>
<script>
document.querySelectorAll("input[type='checkbox']").forEach(checkbox => {
checkbox.onclick = () => checkbox.value = checkbox.checked ? 'true' : 'false';
});
</script>
$view .= '</form>';
<?=template_admin_footer()?>
//Output
echo $view;
template_admin_footer();