Refactor project
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.env
|
||||||
1
ENV_TEMPLATE
Normal file
1
ENV_TEMPLATE
Normal file
@@ -0,0 +1 @@
|
|||||||
|
APIKEY=123
|
||||||
12
config.php
12
config.php
@@ -1,7 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
// config.php
|
// config.php
|
||||||
return [
|
function getApi(){
|
||||||
'openai_api_key' => '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',
|
$api_key = getenv('APIKEY');
|
||||||
|
if($api_key){
|
||||||
];
|
return array('openai_api_key' => $api_key);
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
23
home.php
23
home.php
@@ -1,26 +1,9 @@
|
|||||||
|
<?php include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/header.php');?>
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>AI Email Generator</title>
|
|
||||||
<link rel="stylesheet" href="style.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>AI Email Generator</h1>
|
<h1>AI Email Generator</h1>
|
||||||
<p>Effortlessly craft polished, professional emails in seconds.</p>
|
<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>
|
<button id="darkModeBtn">Toggle Dark Mode</button>
|
||||||
</div>
|
</div>
|
||||||
|
<?php include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/footer.php');
|
||||||
<script>
|
|
||||||
const darkBtn = document.getElementById('darkModeBtn');
|
|
||||||
if (darkBtn) {
|
|
||||||
darkBtn.onclick = function () {
|
|
||||||
document.body.classList.toggle('dark-mode');
|
|
||||||
};
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|||||||
9
inc/js/theme.js
Normal file
9
inc/js/theme.js
Normal 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
3
inc/php/footer.php
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<script src="/inc/js/theme.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
7
inc/php/header.php
Normal file
7
inc/php/header.php
Normal 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
31
inc/php/resources.php
Normal 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',
|
||||||
|
);
|
||||||
|
}
|
||||||
52
index.php
52
index.php
@@ -1,10 +1,8 @@
|
|||||||
<!DOCTYPE html>
|
<?php
|
||||||
<html lang="en">
|
include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/header.php');
|
||||||
<head>
|
include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/resources.php');
|
||||||
<meta charset="UTF-8">
|
$languages = getLanguages();
|
||||||
<title>AI Email Generator</title>
|
?>
|
||||||
<link rel="stylesheet" href="style.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>AI Email Generator</h1>
|
<h1>AI Email Generator</h1>
|
||||||
@@ -21,45 +19,13 @@
|
|||||||
|
|
||||||
<label for="language">Select Language:</label>
|
<label for="language">Select Language:</label>
|
||||||
<select name="language" id="language" required>
|
<select name="language" id="language" required>
|
||||||
<option value="English">English</option>
|
<?php foreach($languages as $language) :?>
|
||||||
<option value="Swedish">Swedish</option>
|
<option value="<?=$language;?>"><?=$language;?></option>
|
||||||
<option value="Spanish">Spanish</option>
|
<?php endforeach;?>
|
||||||
<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>
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<button type="submit">Generate Email</button>
|
<button type="submit">Generate Email</button>
|
||||||
<button id="darkModeBtn" type="button">Toggle Dark Mode</button>
|
<button id="darkModeBtn" type="button">Toggle Dark Mode</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<?php include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/footer.php');
|
||||||
<script>
|
|
||||||
const darkBtn = document.getElementById('darkModeBtn');
|
|
||||||
if (darkBtn) {
|
|
||||||
darkBtn.onclick = function () {
|
|
||||||
document.body.classList.toggle('dark-mode');
|
|
||||||
};
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|||||||
28
process.php
28
process.php
@@ -1,21 +1,18 @@
|
|||||||
<!DOCTYPE html>
|
<?php
|
||||||
<html lang="en">
|
require_once($_SERVER['DOCUMENT_ROOT'] . '/config.php');
|
||||||
<head>
|
include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/header.php');
|
||||||
<meta charset="UTF-8">
|
?>
|
||||||
<title>AI Email Generator - Result</title>
|
|
||||||
<link rel="stylesheet" href="style.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<?php
|
<?php
|
||||||
// Load API key from config
|
// Load API key from config
|
||||||
$config = include 'config.php';
|
$apikey = getApi();
|
||||||
$apikey = $config['openai_api_key'];
|
|
||||||
|
|
||||||
// Sanitize and validate user inputs
|
// Sanitize and validate user inputs
|
||||||
$emailInput = trim($_POST['email_input'] ?? '');
|
$emailInput = trim($_POST['email_input'] ?? '');
|
||||||
$tone = $_POST['tone'] ?? '';
|
$tone = htmlspecialchars($_POST['tone']) ?? '';
|
||||||
$language = $_POST['language'] ?? 'English'; // Language selector
|
$language = htmlspecialchars($_POST['language']) ?? 'English'; // Language selector
|
||||||
|
|
||||||
$allowedTones = [
|
$allowedTones = [
|
||||||
'formal' => 'Write this email in a formal tone',
|
'formal' => 'Write this email in a formal tone',
|
||||||
@@ -106,12 +103,5 @@
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (darkBtn) {
|
|
||||||
darkBtn.onclick = function () {
|
|
||||||
document.body.classList.toggle('dark-mode');
|
|
||||||
};
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
<?php include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/footer.php');
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user