Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ccee67363 | ||
|
|
725333cdea | ||
|
|
004e3d3a7d |
172
add_food.php
Normal file
172
add_food.php
Normal file
@ -0,0 +1,172 @@
|
||||
|
||||
|
||||
<?php
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
$success_message = "";
|
||||
$error_message = "";
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
if (!empty($_POST['food_name']) && !empty($_POST['calories']) && is_numeric($_POST['calories'])) {
|
||||
try {
|
||||
$food_name = $_POST['food_name'];
|
||||
$calories = (int)$_POST['calories'];
|
||||
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("INSERT INTO food_log (food_name, calories) VALUES (?, ?)");
|
||||
$stmt->execute([$food_name, $calories]);
|
||||
|
||||
$success_message = "Successfully added $food_name with $calories calories!";
|
||||
} catch (PDOException $e) {
|
||||
$error_message = "Error: Could not record the food. " . $e->getMessage();
|
||||
}
|
||||
} else {
|
||||
$error_message = "Please fill out all fields correctly.";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Add Food - Calorie Tracker</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
<?php if ($success_message): ?>
|
||||
<meta http-equiv="refresh" content="2;url=index.php">
|
||||
<?php endif; ?>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="mobile-container">
|
||||
<header class="app-header">
|
||||
<h1>Add Food</h1>
|
||||
</header>
|
||||
|
||||
<main class="main-content">
|
||||
<?php if ($success_message): ?>
|
||||
<div class="alert success">
|
||||
<?php echo $success_message; ?>
|
||||
<p>Redirecting you home...</p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<?php if ($error_message): ?>
|
||||
<div class="alert error">
|
||||
<?php echo $error_message; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="food-search-container">
|
||||
<div class="form-group">
|
||||
<label for="food_search">Search for a food</label>
|
||||
<input type="text" id="food_search" placeholder="e.g., Apple">
|
||||
</div>
|
||||
<button type="button" id="search_btn" class="btn">Search</button>
|
||||
<div id="search_results"></div>
|
||||
</div>
|
||||
|
||||
<form action="add_food.php" method="POST" class="add-sale-form">
|
||||
<div class="form-group">
|
||||
<label for="food_name">Food Name</label>
|
||||
<input type="text" id="food_name" name="food_name" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="calories">Calories</label>
|
||||
<input type="number" id="calories" name="calories" min="0" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary">Log Food</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</main>
|
||||
|
||||
<nav class="bottom-nav">
|
||||
<a href="index.php" class="nav-item">
|
||||
<i class="bi bi-house-door-fill"></i>
|
||||
<span>Home</span>
|
||||
</a>
|
||||
<a href="add_food.php" class="nav-item active">
|
||||
<i class="bi bi-plus-circle-fill"></i>
|
||||
<span>Add Food</span>
|
||||
</a>
|
||||
<a href="dashboard.php" class="nav-item">
|
||||
<i class="bi bi-bar-chart-line-fill"></i>
|
||||
<span>Dashboard</span>
|
||||
</a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function debounce(func, wait) {
|
||||
let timeout;
|
||||
return function(...args) {
|
||||
const context = this;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => func.apply(context, args), wait);
|
||||
};
|
||||
}
|
||||
|
||||
const searchInput = document.getElementById('food_search');
|
||||
const searchBtn = document.getElementById('search_btn');
|
||||
const resultsContainer = document.getElementById('search_results');
|
||||
|
||||
// Hide the original search button, as search will be triggered by typing
|
||||
searchBtn.style.display = 'none';
|
||||
|
||||
const searchHandler = debounce(function() {
|
||||
const searchTerm = searchInput.value;
|
||||
if (searchTerm.trim() === '') {
|
||||
resultsContainer.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
resultsContainer.innerHTML = '<p style="padding: 15px;">Searching...</p>';
|
||||
|
||||
fetch(`https://world.openfoodfacts.org/cgi/search.pl?search_terms=${encodeURIComponent(searchTerm)}&action=process&json=1&page_size=10`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
resultsContainer.innerHTML = '';
|
||||
if (data.products && data.products.length > 0) {
|
||||
const list = document.createElement('ul');
|
||||
list.className = 'search-results-list'; // Add a class for styling
|
||||
data.products.forEach(product => {
|
||||
const productName = product.product_name_en || product.product_name || 'Unknown Food';
|
||||
const calories = product.nutriments['energy-kcal_100g'] || product.nutriments['energy-kcal'] || 0;
|
||||
|
||||
if (!productName.trim()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const listItem = document.createElement('li');
|
||||
listItem.innerHTML = `${productName} <span>(${calories} kcal/100g)</span>`;
|
||||
listItem.addEventListener('click', function() {
|
||||
document.getElementById('food_name').value = productName;
|
||||
document.getElementById('calories').value = calories;
|
||||
resultsContainer.innerHTML = '';
|
||||
searchInput.value = '';
|
||||
});
|
||||
list.appendChild(listItem);
|
||||
});
|
||||
resultsContainer.appendChild(list);
|
||||
} else {
|
||||
resultsContainer.innerHTML = '<p style="padding: 15px;">No results found.</p>';
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching data:', error);
|
||||
resultsContainer.innerHTML = '<p style="padding: 15px;">An error occurred while searching.</p>';
|
||||
});
|
||||
}, 300); // 300ms debounce delay
|
||||
|
||||
searchInput.addEventListener('input', searchHandler);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
19
api/pexels.php
Normal file
19
api/pexels.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require_once __DIR__.'/../includes/pexels.php';
|
||||
$q = isset($_GET['query']) ? $_GET['query'] : 'nature';
|
||||
$orientation = isset($_GET['orientation']) ? $_GET['orientation'] : 'portrait';
|
||||
$url = 'https://api.pexels.com/v1/search?query=' . urlencode($q) . '&orientation=' . urlencode($orientation) . '&per_page=1&page=1';
|
||||
$data = pexels_get($url);
|
||||
if (!$data || empty($data['photos'])) { echo json_encode(['error'=>'Failed to fetch image']); exit; }
|
||||
$photo = $data['photos'][0];
|
||||
$src = $photo['src']['large2x'] ?? ($photo['src']['large'] ?? $photo['src']['original']);
|
||||
$target = __DIR__ . '/../assets/images/pexels/' . $photo['id'] . '.jpg';
|
||||
download_to($src, $target);
|
||||
// Return minimal info and local relative path
|
||||
echo json_encode([
|
||||
'id' => $photo['id'],
|
||||
'local' => 'assets/images/pexels/' . $photo['id'] . '.jpg',
|
||||
'photographer' => $photo['photographer'] ?? null,
|
||||
'photographer_url' => $photo['photographer_url'] ?? null,
|
||||
]);
|
||||
261
assets/css/custom.css
Normal file
261
assets/css/custom.css
Normal file
@ -0,0 +1,261 @@
|
||||
body {
|
||||
background-color: #1a1a2e;
|
||||
font-family: 'Poppins', sans-serif;
|
||||
color: #e0e0e0;
|
||||
}
|
||||
|
||||
.mobile-container {
|
||||
max-width: 480px;
|
||||
margin: auto;
|
||||
background-color: transparent;
|
||||
min-height: 100vh;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.background-gradient {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 50vh;
|
||||
background: linear-gradient(to bottom, #1f4287, #1a1a2e);
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.app-header {
|
||||
background: transparent;
|
||||
color: white;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1030;
|
||||
}
|
||||
|
||||
.product-card {
|
||||
border-radius: 1rem;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
height: 200px;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
color: white;
|
||||
box-shadow: 0 10px 20px rgba(0,0,0,0.2), 0 6px 6px rgba(0,0,0,0.2);
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.product-card:hover {
|
||||
transform: translateY(-5px);
|
||||
}
|
||||
|
||||
.card-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 100%);
|
||||
}
|
||||
|
||||
.card-content {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
padding: 1rem;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-weight: 600;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.card-text {
|
||||
font-size: 0.9rem;
|
||||
margin-bottom: 0.5rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.nutrient-badge {
|
||||
font-size: 0.75rem;
|
||||
padding: 0.3em 0.6em;
|
||||
background-color: rgba(255, 255, 255, 0.15);
|
||||
backdrop-filter: blur(5px);
|
||||
border-radius: 50px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
/* Add Sale Page & Form */
|
||||
.add-sale-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
padding: 20px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 15px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
backdrop-filter: blur(10px);
|
||||
-webkit-backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
margin-bottom: 8px;
|
||||
font-weight: 600;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||
background-color: rgba(0, 0, 0, 0.2);
|
||||
color: #fff;
|
||||
font-family: 'Poppins', sans-serif;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.form-group select {
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='white' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
|
||||
background-repeat: no-repeat;
|
||||
background-position: right 15px center;
|
||||
padding-right: 40px;
|
||||
}
|
||||
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
outline: none;
|
||||
border-color: #8E44AD;
|
||||
box-shadow: 0 0 0 3px rgba(142, 68, 173, 0.5);
|
||||
}
|
||||
|
||||
.btn.btn-primary {
|
||||
padding: 15px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
background: linear-gradient(45deg, #8E44AD, #C0392B);
|
||||
color: white;
|
||||
font-weight: 600;
|
||||
font-size: 1.1rem;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.btn.btn-primary:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.back-button {
|
||||
position: absolute;
|
||||
left: 15px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
font-size: 1.8rem;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.alert.success {
|
||||
padding: 15px;
|
||||
background-color: rgba(46, 204, 113, 0.8);
|
||||
color: white;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Bottom Navigation */
|
||||
.bottom-nav {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
max-width: 480px;
|
||||
margin: auto;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
background-color: rgba(26, 26, 46, 0.8);
|
||||
backdrop-filter: blur(10px);
|
||||
-webkit-backdrop-filter: blur(10px);
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
||||
padding: 10px 0;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
color: #e0e0e0;
|
||||
text-decoration: none;
|
||||
font-size: 0.75rem;
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
.nav-item i {
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.nav-item.active,
|
||||
.nav-item:hover {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
main.p-3 {
|
||||
padding-bottom: 100px !important; /* Space for bottom nav */
|
||||
}
|
||||
|
||||
.food-search-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#search_results {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: #1f1f3d;
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-top: none;
|
||||
border-radius: 0 0 15px 15px;
|
||||
z-index: 1000;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.search-results-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.search-results-list li {
|
||||
padding: 15px;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.search-results-list li:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.search-results-list li:hover {
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.search-results-list li span {
|
||||
color: #aaa;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
BIN
assets/pasted-20251121-114725-33d5afd9.jpg
Normal file
BIN
assets/pasted-20251121-114725-33d5afd9.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 51 KiB |
BIN
assets/pasted-20251121-115632-d3e25129.png
Normal file
BIN
assets/pasted-20251121-115632-d3e25129.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 245 KiB |
BIN
assets/pasted-20251121-121911-9a3aea89.png
Normal file
BIN
assets/pasted-20251121-121911-9a3aea89.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 168 KiB |
BIN
assets/vm-shot-2025-11-21T11-47-05-928Z.jpg
Normal file
BIN
assets/vm-shot-2025-11-21T11-47-05-928Z.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 51 KiB |
133
dashboard.php
Normal file
133
dashboard.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
$food_log_data = [];
|
||||
$error_message = '';
|
||||
$total_foods = 0;
|
||||
$total_calories = 0;
|
||||
$calories_by_food = [];
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->query("SELECT food_name, calories, sale_date FROM food_log ORDER BY sale_date DESC");
|
||||
$food_log_data = $stmt->fetchAll();
|
||||
|
||||
if ($food_log_data) {
|
||||
$total_foods = count($food_log_data);
|
||||
$total_calories = array_sum(array_column($food_log_data, 'calories'));
|
||||
|
||||
foreach ($food_log_data as $food) {
|
||||
if (!isset($calories_by_food[$food['food_name']])) {
|
||||
$calories_by_food[$food['food_name']] = 0;
|
||||
}
|
||||
$calories_by_food[$food['food_name']] += $food['calories'];
|
||||
}
|
||||
arsort($calories_by_food);
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$error_message = "Error fetching food log data: " . $e->getMessage();
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Dashboard - Calorie Tracker</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="mobile-container">
|
||||
<header class="app-header">
|
||||
<a href="index.php" class="back-button">←</a>
|
||||
<h1>Dashboard</h1>
|
||||
</header>
|
||||
|
||||
<main class="main-content">
|
||||
<?php if ($error_message): ?>
|
||||
<div class="alert error">
|
||||
<?php echo htmlspecialchars($error_message); ?>
|
||||
</div>
|
||||
<?php elseif (empty($food_log_data)) : ?>
|
||||
<div class="alert">
|
||||
No food logged yet. Add a food item to see your stats here.
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="stats-summary">
|
||||
<div class="summary-card">
|
||||
<span class="value"><?php echo $total_foods; ?></span>
|
||||
<span class="label">Total Foods</span>
|
||||
</div>
|
||||
<div class="summary-card">
|
||||
<span class="value"><?php echo $total_calories; ?></span>
|
||||
<span class="label">Total Calories</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2 class="h5 mt-4 mb-3 text-white">Calories by Food</h2>
|
||||
<div class="table-responsive">
|
||||
<table class="table sales-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Food</th>
|
||||
<th>Total Calories</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($calories_by_food as $food_name => $calories): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($food_name); ?></td>
|
||||
<td><?php echo htmlspecialchars((string)$calories); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<h2 class="h5 mt-4 mb-3 text-white">Recent Entries</h2>
|
||||
<div class="table-responsive">
|
||||
<table class="table sales-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Food</th>
|
||||
<th>Calories</th>
|
||||
<th>Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($food_log_data as $food): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($food['food_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars((string)$food['calories']); ?></td>
|
||||
<td><?php echo htmlspecialchars(date("M d, Y H:i", strtotime($food['sale_date']))); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<!-- Bottom Navigation -->
|
||||
<nav class="bottom-nav">
|
||||
<a href="index.php" class="nav-item">
|
||||
<i class="bi bi-house-door-fill"></i>
|
||||
<span>Home</span>
|
||||
</a>
|
||||
<a href="add_food.php" class="nav-item">
|
||||
<i class="bi bi-plus-circle-fill"></i>
|
||||
<span>Add Food</span>
|
||||
</a>
|
||||
<a href="dashboard.php" class="nav-item active">
|
||||
<i class="bi bi-bar-chart-line-fill"></i>
|
||||
<span>Dashboard</span>
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
25
includes/pexels.php
Normal file
25
includes/pexels.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
function pexels_key() {
|
||||
$k = getenv('PEXELS_KEY');
|
||||
return $k && strlen($k) > 0 ? $k : 'Vc99rnmOhHhJAbgGQoKLZtsaIVfkeownoQNbTj78VemUjKh08ZYRbf18';
|
||||
}
|
||||
function pexels_get($url) {
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HTTPHEADER => [ 'Authorization: '. pexels_key() ],
|
||||
CURLOPT_TIMEOUT => 15,
|
||||
]);
|
||||
$resp = curl_exec($ch);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
if ($code >= 200 && $code < 300 && $resp) return json_decode($resp, true);
|
||||
return null;
|
||||
}
|
||||
function download_to($srcUrl, $destPath) {
|
||||
$data = file_get_contents($srcUrl);
|
||||
if ($data === false) return false;
|
||||
if (!is_dir(dirname($destPath))) mkdir(dirname($destPath), 0775, true);
|
||||
return file_put_contents($destPath, $data) !== false;
|
||||
}
|
||||
233
index.php
233
index.php
@ -1,150 +1,103 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
// Mock data for products. In a real app, this would come from a database.
|
||||
$products = [
|
||||
['id' => 1, 'name' => 'Avocado', 'calories' => 160, 'protein' => 2, 'carbs' => 9, 'fat' => 15],
|
||||
['id' => 2, 'name' => 'Chicken Breast', 'calories' => 165, 'protein' => 31, 'carbs' => 0, 'fat' => 3.6],
|
||||
['id' => 3, 'name' => 'Salmon Fillet', 'calories' => 208, 'protein' => 20, 'carbs' => 0, 'fat' => 13],
|
||||
['id' => 4, 'name' => 'Brown Rice', 'calories' => 111, 'protein' => 2.6, 'carbs' => 23, 'fat' => 0.9],
|
||||
['id' => 5, 'name' => 'Broccoli', 'calories' => 55, 'protein' => 3.7, 'carbs' => 11, 'fat' => 0.6],
|
||||
['id' => 6, 'name' => 'Apple', 'calories' => 52, 'protein' => 0.3, 'carbs' => 14, 'fat' => 0.2],
|
||||
['id' => 7, 'name' => 'Banana', 'calories' => 89, 'protein' => 1.1, 'carbs' => 23, 'fat' => 0.3],
|
||||
['id' => 8, 'name' => 'Almonds', 'calories' => 579, 'protein' => 21, 'carbs' => 22, 'fat' => 49],
|
||||
];
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$projectName = $_SERVER['PROJECT_NAME'] ?? 'Calorie Tracker';
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title><?= htmlspecialchars($projectName) ?></title>
|
||||
|
||||
<?php
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Track your daily calorie and nutrient intake.';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<meta name="description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<meta property="og:title" content="<?= htmlspecialchars($projectName) ?>" />
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<meta property="twitter:card" content="summary" />
|
||||
<meta property="twitter:title" content="<?= htmlspecialchars($projectName) ?>" />
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
|
||||
<div class="mobile-container">
|
||||
<div class="background-gradient"></div>
|
||||
<header class="app-header p-3 text-center">
|
||||
<h1 class="h4 mb-0"><?= htmlspecialchars($projectName) ?></h1>
|
||||
</header>
|
||||
|
||||
<main class="p-3">
|
||||
<h2 class="h5 mb-3 text-white">Food Library</h2>
|
||||
<div class="list-group">
|
||||
<?php foreach ($products as $product): ?>
|
||||
<?php
|
||||
$imageUrl = 'https://picsum.photos/seed/' . $product['id'] . '/400/200';
|
||||
// Note: The Pexels API integration can be used here for higher quality images.
|
||||
// Example: $imageUrl = 'api/pexels.php?query=' . urlencode($product['name']);
|
||||
?>
|
||||
<div class="product-card mb-4" style="background-image: url('<?= $imageUrl ?>');">
|
||||
<div class="card-overlay"></div>
|
||||
<div class="card-content">
|
||||
<h5 class="card-title"><?= htmlspecialchars($product['name']) ?></h5>
|
||||
<p class="card-text"><?= (int)$product['calories'] ?> kcal</p>
|
||||
<div class="d-flex gap-2 mt-2">
|
||||
<span class="badge nutrient-badge">
|
||||
Protein: <?= (float)$product['protein'] ?>g
|
||||
</span>
|
||||
<span class="badge nutrient-badge">
|
||||
Carbs: <?= (float)$product['carbs'] ?>g
|
||||
</span>
|
||||
<span class="badge nutrient-badge">
|
||||
Fat: <?= (float)$product['fat'] ?>g
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<nav class="bottom-nav">
|
||||
<a href="index.php" class="nav-item active">
|
||||
<i class="bi bi-house-door-fill"></i>
|
||||
<span>Home</span>
|
||||
</a>
|
||||
<a href="add_food.php" class="nav-item">
|
||||
<i class="bi bi-plus-circle-fill"></i>
|
||||
<span>Add Food</span>
|
||||
</a>
|
||||
<a href="dashboard.php" class="nav-item">
|
||||
<i class="bi bi-bar-chart-line-fill"></i>
|
||||
<span>Dashboard</span>
|
||||
</a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user