191 lines
6.8 KiB
PHP
191 lines
6.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
@ini_set('display_errors', '1');
|
|
@error_reporting(E_ALL);
|
|
@date_default_timezone_set('UTC');
|
|
|
|
$happy_things = [
|
|
"Why do programmers prefer dark mode? Because light attracts bugs.",
|
|
"A programmer puts two glasses on his bedside table. One with water if he gets thirsty, and one empty in case he doesn't.",
|
|
"['hip', 'hip']",
|
|
"To understand what recursion is, you must first understand recursion.",
|
|
"I'm not lazy, I'm just on energy-saving mode.",
|
|
"Why did the programmer quit his job? Because he didn't get arrays.",
|
|
"A programmer's wife tells him: 'Go to the store and buy a loaf of bread. If they have eggs, buy a dozen.' The programmer returns with 12 loaves of bread.",
|
|
"There are 10 types of people in the world: those who understand binary, and those who don't.",
|
|
"Documentation is like sex: when it's good, it's very, very good; and when it's bad, it's better than nothing.",
|
|
"The best thing about a boolean is even if you are wrong, you are only off by a bit.",
|
|
"A programmer had a problem. He decided to use Java. Now he has a ProblemFactory.",
|
|
"Don't worry if it doesn't work right. If everything did, you'd be out of a job.",
|
|
"Programming is like writing a book... if you miss a single comma on page 1, the whole story makes no sense.",
|
|
"The six stages of debugging: 1. That can't happen. 2. It shouldn't happen. 3. It did happen. 4. Why did it happen? 5. Oh, I see. 6. How did that ever work?",
|
|
"Talk is cheap. Show me the code.",
|
|
"It's not a bug, it's an undocumented feature.",
|
|
"Weeks of programming can save you hours of planning.",
|
|
"One man's crappy software is another man's full-time job."
|
|
];
|
|
|
|
$happy_thing = $happy_things[array_rand($happy_things)];
|
|
|
|
// Fetch a background image from Pexels
|
|
$bg_image_url = 'assets/pasted-20250924-152027-2c3eed44.jpg'; // Fallback image
|
|
$pexels_api_key = getenv('PEXELS_KEY') ?: 'Vc99rnmOhHhJAbgGQoKLZtsaIVfkeownoQNbTj78VemUjKh08ZYRbf18';
|
|
$query = 'developer desk';
|
|
$pexels_url = 'https://api.pexels.com/v1/search?query=' . urlencode($query) . '&orientation=landscape&per_page=1';
|
|
|
|
$ch = curl_init();
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_URL => $pexels_url,
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_HTTPHEADER => ['Authorization: ' . $pexels_api_key],
|
|
CURLOPT_TIMEOUT => 15,
|
|
]);
|
|
$response = curl_exec($ch);
|
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
if ($http_code >= 200 && $http_code < 300 && $response) {
|
|
$data = json_decode($response, true);
|
|
if (!empty($data['photos'])) {
|
|
$photo = $data['photos'][0];
|
|
$src = $photo['src']['large2x'] ?? $photo['src']['large'] ?? $photo['src']['original'];
|
|
$bg_image_url = $src;
|
|
}
|
|
}
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>How to Make a Developer Happy</title>
|
|
<meta name="description" content="A simple page to bring a smile to a developer's face.">
|
|
<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&family=Source+Code+Pro&display=swap" rel="stylesheet">
|
|
<style>
|
|
:root {
|
|
--text-color: #ffffff;
|
|
--card-bg-color: rgba(0, 0, 0, 0.4);
|
|
--card-border-color: rgba(255, 255, 255, 0.2);
|
|
--button-bg-color: #007bff;
|
|
--button-hover-bg-color: #0056b3;
|
|
}
|
|
body {
|
|
margin: 0;
|
|
font-family: 'Inter', sans-serif;
|
|
color: var(--text-color);
|
|
background: url('<?= htmlspecialchars($bg_image_url) ?>') no-repeat center center fixed;
|
|
background-size: cover;
|
|
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-color: rgba(0, 0, 0, 0.5);
|
|
z-index: 1;
|
|
}
|
|
main {
|
|
padding: 2rem;
|
|
position: relative;
|
|
z-index: 2;
|
|
}
|
|
.card {
|
|
background: var(--card-bg-color);
|
|
border: 1px solid var(--card-border-color);
|
|
border-radius: 16px;
|
|
padding: 2rem 3rem;
|
|
backdrop-filter: blur(10px);
|
|
-webkit-backdrop-filter: blur(10px);
|
|
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
|
|
max-width: 600px;
|
|
}
|
|
h1 {
|
|
font-size: 2.5rem;
|
|
font-weight: 700;
|
|
margin: 0 0 1.5rem;
|
|
letter-spacing: -1px;
|
|
}
|
|
.happy-content {
|
|
font-family: 'Source Code Pro', monospace;
|
|
font-size: 1.2rem;
|
|
margin: 2rem 0;
|
|
min-height: 80px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
.btn {
|
|
background-color: var(--button-bg-color);
|
|
color: var(--text-color);
|
|
border: none;
|
|
padding: 1rem 2rem;
|
|
font-size: 1.2rem;
|
|
font-weight: 700;
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
transition: background-color 0.3s ease;
|
|
text-decoration: none;
|
|
}
|
|
.btn:hover {
|
|
background-color: var(--button-hover-bg-color);
|
|
}
|
|
footer {
|
|
position: absolute;
|
|
bottom: 1rem;
|
|
font-size: 0.8rem;
|
|
opacity: 0.7;
|
|
z-index: 2;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<div class="card">
|
|
<h1>How to Make a Developer Happy</h1>
|
|
<div id="question-container">
|
|
<p class="happy-content">Ready for some developer happiness?</p>
|
|
<button id="show-happiness-btn" class="btn">Yes!</button>
|
|
</div>
|
|
<div id="happiness-container" style="display: none;">
|
|
<div id="happy-content" class="happy-content">
|
|
<p><?= htmlspecialchars($happy_thing) ?></p>
|
|
</div>
|
|
<button id="make-happy-btn" class="btn">Make me happy</button>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
<footer>
|
|
Powered by Gemini
|
|
</footer>
|
|
<script>
|
|
const happyThings = <?= json_encode($happy_things) ?>;
|
|
const happyContent = document.getElementById('happy-content');
|
|
const makeHappyBtn = document.getElementById('make-happy-btn');
|
|
const showHappinessBtn = document.getElementById('show-happiness-btn');
|
|
const questionContainer = document.getElementById('question-container');
|
|
const happinessContainer = document.getElementById('happiness-container');
|
|
|
|
showHappinessBtn.addEventListener('click', () => {
|
|
questionContainer.style.display = 'none';
|
|
happinessContainer.style.display = 'block';
|
|
});
|
|
|
|
makeHappyBtn.addEventListener('click', () => {
|
|
const randomIndex = Math.floor(Math.random() * happyThings.length);
|
|
const newHappyThing = happyThings[randomIndex];
|
|
happyContent.innerHTML = `<p>${newHappyThing}</p>`;
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|