Refactor project

This commit is contained in:
TheAlluringCO
2025-07-10 00:21:08 +02:00
parent 6af2403497
commit bb06ed902b
11 changed files with 81 additions and 86 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.env

1
ENV_TEMPLATE Normal file
View File

@@ -0,0 +1 @@
APIKEY=123

View File

@@ -1,7 +1,11 @@
<?php
// config.php
return [
'openai_api_key' => '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',
];
function getApi(){
$api_key = getenv('APIKEY');
if($api_key){
return array('openai_api_key' => $api_key);
}else{
return false;
}
}
?>

View File

@@ -1,26 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AI Email Generator</title>
<link rel="stylesheet" href="style.css">
</head>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/header.php');?>
<body>
<div class="container">
<h1>AI Email Generator</h1>
<p>Effortlessly craft polished, professional emails in seconds.</p>
<a href="index.php"><button>Start Generating Emails</button></a>
<a href="/"><button>Start Generating Emails</button></a>
<button id="darkModeBtn">Toggle Dark Mode</button>
</div>
<script>
const darkBtn = document.getElementById('darkModeBtn');
if (darkBtn) {
darkBtn.onclick = function () {
document.body.classList.toggle('dark-mode');
};
}
</script>
</body>
</html>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/footer.php');

9
inc/js/theme.js Normal file
View File

@@ -0,0 +1,9 @@
document.addEventListener('DOMContentLoaded', () =>{
const toggleBtn = document.getElementById('darkModeBtn');
if(toggleBtn){
toggleBtn.addEventListener('click', (e) =>{
e.preventDefault();
document.body.classList.toggle('dark-mode');
})
}
})

3
inc/php/footer.php Normal file
View File

@@ -0,0 +1,3 @@
<script src="/inc/js/theme.js"></script>
</body>
</html>

7
inc/php/header.php Normal file
View File

@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AI Email Generator - Result</title>
<link rel="stylesheet" href="style.css">
</head>

31
inc/php/resources.php Normal file
View File

@@ -0,0 +1,31 @@
<?php
function getLanguages(){
return array(
'English',
'Swedish',
'Spanish',
'French',
'German',
'Italian',
'Portuguese',
'Dutch',
'Norwegian',
'Danish',
'Finnish',
'Polish',
'Czech',
'Hungarian',
'Greek',
'Turkish',
'Russian',
'Chinese',
'Japanese',
'Korean',
'Arabic',
'Hebrew',
'Hindi',
'Thai',
'Vietnamese',
);
}

View File

@@ -1,10 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AI Email Generator</title>
<link rel="stylesheet" href="style.css">
</head>
<?php
include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/header.php');
include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/resources.php');
$languages = getLanguages();
?>
<body>
<div class="container">
<h1>AI Email Generator</h1>
@@ -21,45 +19,13 @@
<label for="language">Select Language:</label>
<select name="language" id="language" required>
<option value="English">English</option>
<option value="Swedish">Swedish</option>
<option value="Spanish">Spanish</option>
<option value="French">French</option>
<option value="German">German</option>
<option value="Italian">Italian</option>
<option value="Portuguese">Portuguese</option>
<option value="Dutch">Dutch</option>
<option value="Norwegian">Norwegian</option>
<option value="Danish">Danish</option>
<option value="Finnish">Finnish</option>
<option value="Polish">Polish</option>
<option value="Czech">Czech</option>
<option value="Hungarian">Hungarian</option>
<option value="Greek">Greek</option>
<option value="Turkish">Turkish</option>
<option value="Russian">Russian</option>
<option value="Chinese">Chinese</option>
<option value="Japanese">Japanese</option>
<option value="Korean">Korean</option>
<option value="Arabic">Arabic</option>
<option value="Hebrew">Hebrew</option>
<option value="Hindi">Hindi</option>
<option value="Thai">Thai</option>
<option value="Vietnamese">Vietnamese</option>
<?php foreach($languages as $language) :?>
<option value="<?=$language;?>"><?=$language;?></option>
<?php endforeach;?>
</select>
<button type="submit">Generate Email</button>
<button id="darkModeBtn" type="button">Toggle Dark Mode</button>
</form>
</div>
<script>
const darkBtn = document.getElementById('darkModeBtn');
if (darkBtn) {
darkBtn.onclick = function () {
document.body.classList.toggle('dark-mode');
};
}
</script>
</body>
</html>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/footer.php');

View File

@@ -1,21 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AI Email Generator - Result</title>
<link rel="stylesheet" href="style.css">
</head>
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/config.php');
include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/header.php');
?>
<body>
<div class="container">
<?php
// Load API key from config
$config = include 'config.php';
$apikey = $config['openai_api_key'];
$apikey = getApi();
// Sanitize and validate user inputs
$emailInput = trim($_POST['email_input'] ?? '');
$tone = $_POST['tone'] ?? '';
$language = $_POST['language'] ?? 'English'; // Language selector
$tone = htmlspecialchars($_POST['tone']) ?? '';
$language = htmlspecialchars($_POST['language']) ?? 'English'; // Language selector
$allowedTones = [
'formal' => 'Write this email in a formal tone',
@@ -106,12 +103,5 @@
return false;
};
}
if (darkBtn) {
darkBtn.onclick = function () {
document.body.classList.toggle('dark-mode');
};
}
</script>
</body>
</html>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/footer.php');