Compare commits
No commits in common. "ai-dev" and "master" have entirely different histories.
18
.htaccess
18
.htaccess
@ -1,4 +1,18 @@
|
||||
DirectoryIndex index.php index.html
|
||||
Options -Indexes
|
||||
Options -MultiViews
|
||||
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
|
||||
# 0) Serve existing files/directories as-is
|
||||
RewriteCond %{REQUEST_FILENAME} -f [OR]
|
||||
RewriteCond %{REQUEST_FILENAME} -d
|
||||
RewriteRule ^ - [L]
|
||||
|
||||
# 1) Internal map: /page or /page/ -> /page.php (if such PHP file exists)
|
||||
RewriteCond %{REQUEST_FILENAME}.php -f
|
||||
RewriteRule ^(.+?)/?$ $1.php [L]
|
||||
|
||||
# 2) Optional: strip trailing slash for non-directories (keeps .php links working)
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^([^/]+)$ /index.php?code=$1 [L,QSA]
|
||||
RewriteRule ^(.+)/$ $1 [R=301,L]
|
||||
|
||||
@ -1,41 +1,17 @@
|
||||
<?php
|
||||
// Generated by setup_mariadb_project.sh — edit as needed.
|
||||
define('DB_HOST', '127.0.0.1');
|
||||
define('DB_NAME', 'app_30908');
|
||||
define('DB_USER', 'app_30908');
|
||||
define('DB_PASS', '98b730aa-be6c-479d-a47d-e5e7abc49229');
|
||||
|
||||
function db() {
|
||||
static $pdoconn = null;
|
||||
if ($pdoconn === null) {
|
||||
$host = '127.0.0.1';
|
||||
$db = 'shortkenny';
|
||||
$user = 'user';
|
||||
$pass = 'password';
|
||||
$charset = 'utf8mb4';
|
||||
|
||||
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
|
||||
$options = [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
];
|
||||
try {
|
||||
// Create database if it doesn't exist
|
||||
$dbh = new PDO("mysql:host=$host", $user, $pass);
|
||||
$dbh->exec("CREATE DATABASE IF NOT EXISTS `$db`;")
|
||||
or die(print_r($dbh->errorInfo(), true));
|
||||
|
||||
$pdoconn = new PDO($dsn, $user, $pass, $options);
|
||||
|
||||
// Create table
|
||||
$pdoconn->exec("
|
||||
CREATE TABLE IF NOT EXISTS links (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
original_url VARCHAR(2048) NOT NULL,
|
||||
short_code VARCHAR(10) NOT NULL UNIQUE,
|
||||
click_count INT DEFAULT 0,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
");
|
||||
|
||||
} catch ("PDOException" $e) {
|
||||
throw new "::PDOException($e->getMessage(), (int)$e->getCode());
|
||||
}
|
||||
}
|
||||
return $pdoconn;
|
||||
}
|
||||
static $pdo;
|
||||
if (!$pdo) {
|
||||
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
}
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
321
index.php
321
index.php
@ -1,187 +1,150 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
$pdo = db();
|
||||
$shortened_url = null;
|
||||
$error_message = null;
|
||||
|
||||
// Handle redirection
|
||||
if (isset($_GET['code']) && !empty($_GET['code'])) {
|
||||
$stmt = $pdo->prepare("SELECT original_url FROM links WHERE short_code = ?");
|
||||
$stmt->execute([$_GET['code']]);
|
||||
$link = $stmt->fetch();
|
||||
|
||||
if ($link) {
|
||||
$updateStmt = $pdo->prepare("UPDATE links SET click_count = click_count + 1 WHERE short_code = ?");
|
||||
$updateStmt->execute([$_GET['code']]);
|
||||
header("Location: " . $link['original_url']);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle form submission
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['url'])) {
|
||||
$original_url = trim($_POST['url']);
|
||||
|
||||
if (filter_var($original_url, FILTER_VALIDATE_URL)) {
|
||||
$short_code = substr(md5(uniqid(rand(), true)), 0, 7);
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO links (original_url, short_code) VALUES (?, ?)");
|
||||
$stmt->execute([$original_url, $short_code]);
|
||||
|
||||
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http";
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
$shortened_url = "$protocol://$host/$short_code";
|
||||
|
||||
if (!isset($_SESSION['recent_links'])) {
|
||||
$_SESSION['recent_links'] = [];
|
||||
}
|
||||
array_unshift($_SESSION['recent_links'], ['short' => $shortened_url, 'original' => $original_url, 'clicks' => 0]);
|
||||
$_SESSION['recent_links'] = array_slice($_SESSION['recent_links'], 0, 10);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$error_message = "Could not create short link. Please try again.";
|
||||
}
|
||||
} else {
|
||||
$error_message = "Please enter a valid URL.";
|
||||
}
|
||||
}
|
||||
|
||||
$recent_links = $_SESSION['recent_links'] ?? [];
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>ShortKenny - Minimal URL Shortener</title>
|
||||
<meta name="description" content="ShortKenny: Effortlessly shorten URLs for easy sharing and tracking in your web applications.">
|
||||
<meta name="keywords" content="url shortener, link shortener, custom url, short url, link management, analytics, tracking, web application, minimal">
|
||||
<meta property="og:title" content="ShortKenny">
|
||||
<meta property="og:description" content="ShortKenny: Effortlessly shorten URLs for easy sharing and tracking in your web applications.">
|
||||
<meta property="og:image" content="https://project-screens.s3.amazonaws.com/screenshots/34646/app-hero-20251004-102617.png">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:image" content="https://project-screens.s3.amazonaws.com/screenshots/34646/app-hero-20251004-102617.png">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
|
||||
<style>
|
||||
body { background-color: #f8f9fa; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; }
|
||||
.hero { background: linear-gradient(135deg, #f8f9fa, #e9ecef); padding: 4rem 0; text-align: center; }
|
||||
.hero h1 { font-family: 'Georgia', serif; font-weight: bold; }
|
||||
.form-container { max-width: 600px; margin: 2rem auto; background: #fff; padding: 2rem; border-radius: 0.5rem; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
|
||||
.result-container { display: none; }
|
||||
.copy-btn { cursor: pointer; }
|
||||
.table { margin-top: 2rem; }
|
||||
</style>
|
||||
<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>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header class="hero">
|
||||
<div class="container">
|
||||
<h1>ShortKenny</h1>
|
||||
<p class="lead">A simple, fast, and reliable URL shortener.</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="container">
|
||||
<div class="form-container">
|
||||
<form action="/" method="POST" id="shorten-form">
|
||||
<div class="mb-3">
|
||||
<label for="url" class="form-label">URL to Shorten</label>
|
||||
<input type="url" class="form-control form-control-lg" id="url" name="url" placeholder="https://example.com/my-long-url" required pattern="https?://.+">
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary btn-lg">Shorten URL</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php if ($error_message): ?>
|
||||
<div class="alert alert-danger mt-3"><?php echo htmlspecialchars($error_message); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($shortened_url): ?>
|
||||
<div class="mt-4 p-3 bg-light rounded border" id="result-container">
|
||||
<h5>Your short URL:</h5>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" value="<?php echo htmlspecialchars($shortened_url); ?>" readonly id="short-url-input">
|
||||
<button class="btn btn-outline-secondary copy-btn" type="button" id="copy-button" title="Copy to clipboard">
|
||||
<i class="bi bi-clipboard"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div id="copy-toast" class="toast align-items-center text-white bg-success border-0 position-fixed bottom-0 end-0 p-3" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
Copied to clipboard!
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($recent_links)): ?>
|
||||
<div class="mt-5">
|
||||
<h3 class="text-center mb-4">Recently Created Links (This Session)</h3>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Short URL</th>
|
||||
<th>Original URL</th>
|
||||
<th>Clicks</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($recent_links as $link): ?>
|
||||
<tr>
|
||||
<td><a href="<?php echo htmlspecialchars($link['short']); ?>" target="_blank"><?php echo htmlspecialchars($link['short']); ?></a></td>
|
||||
<td class="text-truncate" style="max-width: 300px;"><a href="<?php echo htmlspecialchars($link['original']); ?>" target="_blank" title="<?php echo htmlspecialchars($link['original']); ?>"><?php echo htmlspecialchars($link['original']); ?></a></td>
|
||||
<td><?php echo htmlspecialchars($link['clicks']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
</main>
|
||||
|
||||
<footer class="text-center py-4 mt-5">
|
||||
<p>© <?php echo date("Y"); ?> ShortKenny. All rights reserved.</p>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const copyButton = document.getElementById('copy-button');
|
||||
const shortUrlInput = document.getElementById('short-url-input');
|
||||
const copyToastEl = document.getElementById('copy-toast');
|
||||
const copyToast = new bootstrap.Toast(copyToastEl);
|
||||
|
||||
if (copyButton) {
|
||||
copyButton.addEventListener('click', function () {
|
||||
shortUrlInput.select();
|
||||
document.execCommand('copy');
|
||||
copyToast.show();
|
||||
});
|
||||
}
|
||||
|
||||
const form = document.getElementById('shorten-form');
|
||||
const urlInput = document.getElementById('url');
|
||||
form.addEventListener('submit', function(e) {
|
||||
if (!urlInput.checkValidity()) {
|
||||
e.preventDefault();
|
||||
urlInput.classList.add('is-invalid');
|
||||
} else {
|
||||
urlInput.classList.remove('is-invalid');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user