Compare commits

...

1 Commits

Author SHA1 Message Date
Flatlogic Bot
b113664b26 A-1 2025-10-21 11:59:17 +00:00
5 changed files with 344 additions and 143 deletions

27
api/search.php Normal file
View File

@ -0,0 +1,27 @@
<?php
header('Content-Type: application/json');
$query = isset($_GET['q']) ? trim($_GET['q']) : '';
if (empty($query)) {
echo json_encode(['error' => 'Query parameter is missing.']);
exit;
}
$url = 'https://api.duckduckgo.com/?q=' . urlencode($query) . '&format=json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'ArtickleSearch/1.0');
$output = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code !== 200) {
http_response_code(500);
echo json_encode(['error' => 'Failed to fetch data from the external API.']);
exit;
}
echo $output;

117
api/summarize.php Normal file
View File

@ -0,0 +1,117 @@
<?php
session_start();
header('Content-Type: application/json');
require_once __DIR__ . '/../db/config.php';
// --- Rate Limiting ---
try {
$db = db();
$ip_address = $_SERVER['REMOTE_ADDR'];
// Create table if it doesn't exist (simple migration)
$db->exec("CREATE TABLE IF NOT EXISTS rate_limits (
id INT AUTO_INCREMENT PRIMARY KEY,
ip_address VARCHAR(45) NOT NULL,
request_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)");
// Clean up old records
$db->prepare("DELETE FROM rate_limits WHERE request_timestamp < NOW() - INTERVAL 1 DAY")->execute();
// Check minute limit (5 requests)
$stmt_minute = $db->prepare("SELECT COUNT(*) FROM rate_limits WHERE ip_address = ? AND request_timestamp > NOW() - INTERVAL 1 MINUTE");
$stmt_minute->execute([$ip_address]);
if ($stmt_minute->fetchColumn() >= 5) {
http_response_code(429); // Too Many Requests
echo json_encode(['error' => 'Too many requests. Please wait a minute before trying again.']);
exit;
}
// Check daily limit (100 requests)
$stmt_day = $db->prepare("SELECT COUNT(*) FROM rate_limits WHERE ip_address = ?");
$stmt_day->execute([$ip_address]);
if ($stmt_day->fetchColumn() >= 100) {
http_response_code(429);
echo json_encode(['error' => 'You have reached your daily limit of 100 summaries.']);
exit;
}
} catch (PDOException $e) {
http_response_code(500);
// Do not expose detailed error to client
echo json_encode(['error' => 'Could not connect to the database for rate limiting.']);
exit;
}
// --- Summarization Logic ---
$url = isset($_POST['url']) ? trim($_POST['url']) : '';
if (empty($url) || !filter_var($url, FILTER_VALIDATE_URL)) {
http_response_code(400);
echo json_encode(['error' => 'Invalid or missing URL.']);
exit;
}
$url_hash = md5($url);
// Check session for cached summary (valid for 30 minutes)
if (isset($_SESSION['summaries'][$url_hash]) && (time() - $_SESSION['summaries'][$url_hash]['timestamp'] < 1800)) {
echo json_encode(['summary' => $_SESSION['summaries'][$url_hash]['summary']]);
exit;
}
// If not cached, proceed to fetch and summarize
// Log the request for rate limiting
$db->prepare("INSERT INTO rate_limits (ip_address) VALUES (?)")->execute([$ip_address]);
// 1. Scrape the article content using cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'ArtickleSummarizer/1.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)');
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$html = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code < 200 || $http_code >= 300 || empty($html)) {
http_response_code(500);
echo json_encode(['error' => 'Failed to fetch article content. The site may be down or blocking requests.']);
exit;
}
// 2. Extract main content (simple heuristic)
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTML($html);
libxml_clear_errors();
$paragraphs = $doc->getElementsByTagName('p');
$text_content = "";
foreach ($paragraphs as $p) {
$text_content .= $p->nodeValue . "\n\n";
}
if (trim($text_content) === "") {
http_response_code(500);
echo json_encode(['error' => 'Could not extract readable content from the article.']);
exit;
}
// 3. Summarize (Placeholder for in-house model)
// This is a placeholder function. In a real scenario, this would call an internal summarization model.
// For now, it returns the first 5 paragraphs.
$sentences = explode("\n\n", $text_content);
$summary = implode("\n\n", array_slice($sentences, 0, 5));
// 4. Cache the summary in the session
$_SESSION['summaries'][$url_hash] = [
'summary' => $summary,
'timestamp' => time()
];
echo json_encode(['summary' => $summary]);

22
assets/css/custom.css Normal file
View File

@ -0,0 +1,22 @@
body {
font-family: 'Inter', sans-serif;
}
.input-group-lg .form-control, .input-group-lg .btn {
height: calc(2.5rem + 10px);
padding: 0.5rem 1rem;
font-size: 1.25rem;
}
.result-card {
transition: transform 0.2s ease-in-out;
}
.result-card:hover {
transform: translateY(-5px);
}
#search-button i {
width: 24px;
height: 24px;
}

99
assets/js/main.js Normal file
View File

@ -0,0 +1,99 @@
document.addEventListener('DOMContentLoaded', function () {
const searchForm = document.getElementById('search-form');
const searchInput = document.getElementById('search-input');
const resultsContainer = document.getElementById('results-container');
const loadingIndicator = document.getElementById('loading-indicator');
const summaryModalEl = document.getElementById('summary-modal');
const summaryModal = new bootstrap.Modal(summaryModalEl);
const summaryModalBody = document.getElementById('summary-modal-body');
const originalArticleLink = document.getElementById('original-article-link');
searchForm.addEventListener('submit', function (e) {
e.preventDefault();
const query = searchInput.value.trim();
if (query) {
fetchResults(query);
}
});
function fetchResults(query) {
resultsContainer.innerHTML = '';
loadingIndicator.style.display = 'block';
fetch(`/api/search.php?q=${encodeURIComponent(query)}`)
.then(response => response.json())
.then(data => {
displayResults(data.RelatedTopics);
})
.catch(error => {
console.error('Error fetching search results:', error);
resultsContainer.innerHTML = '<div class="alert alert-danger">Failed to fetch results. Please try again.</div>';
})
.finally(() => {
loadingIndicator.style.display = 'none';
});
}
function displayResults(results) {
if (!results || results.length === 0) {
resultsContainer.innerHTML = '<div class="alert alert-info">No results found.</div>';
return;
}
results.forEach(item => {
if(item.Text) {
const card = `
<div class="card mb-3 result-card">
<div class="card-body">
<h5 class="card-title">${item.Text}</h5>
<p class="card-text">${item.Result}</p>
<button class="btn btn-primary btn-sm summarize-btn" data-url="${item.FirstURL}">Summarize</button>
</div>
</div>
`;
resultsContainer.innerHTML += card;
}
});
}
resultsContainer.addEventListener('click', function(e) {
if (e.target.classList.contains('summarize-btn')) {
const url = e.target.dataset.url;
getSummary(url);
}
});
function getSummary(url) {
summaryModalBody.innerHTML = `
<div class="d-flex justify-content-center">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
`;
summaryModal.show();
originalArticleLink.href = url;
const formData = new FormData();
formData.append('url', url);
fetch('/api/summarize.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.error) {
summaryModalBody.innerHTML = `<div class="alert alert-danger">${data.error}</div>`;
} else {
summaryModalBody.innerHTML = data.summary.replace(/\n/g, '<br>');
}
})
.catch(error => {
console.error('Error fetching summary:', error);
summaryModalBody.innerHTML = '<div class="alert alert-danger">Failed to fetch summary.</div>';
});
}
});

220
index.php
View File

@ -1,150 +1,86 @@
<?php
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" />
<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.0">
<title>Artickle</title>
<meta name="description" content="Search for articles and get summarized, easy-to-understand results.">
<meta name="keywords" content="article summarizer, search engine, simplified articles, content summary, AI search, Built with Flatlogic Generator">
<meta property="og:title" content="Artickle">
<meta property="og:description" content="Search for articles and get summarized, easy-to-understand results.">
<meta property="og:image" content="">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.css">
<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>
<header class="py-3 mb-4 border-bottom">
<div class="container d-flex flex-wrap justify-content-center">
<a href="/" class="d-flex align-items-center mb-3 mb-lg-0 me-lg-auto text-dark text-decoration-none">
<span class="fs-4">Artickle</span>
</a>
</div>
</header>
<main class="container">
<div class="row">
<div class="col-md-8 offset-md-2">
<h1 class="text-center mb-4">Search for Articles</h1>
<form id="search-form" class="mb-5">
<div class="input-group input-group-lg">
<input type="search" id="search-input" class="form-control" placeholder="Enter your search query..." aria-label="Search query" required>
<button class="btn btn-primary" type="submit" id="search-button">
<i data-feather="search"></i>
</button>
</div>
</form>
<div id="results-container">
<!-- Search results will be injected here -->
</div>
<div id="loading-indicator" class="text-center" style="display: none;">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</div>
</div>
</main>
<!-- Summary Modal -->
<div class="modal fade" id="summary-modal" tabindex="-1" aria-labelledby="summaryModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="summaryModalLabel">Article Summary</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="summary-modal-body">
<!-- Summary content will be injected here -->
</div>
<div class="modal-footer">
<a href="#" id="original-article-link" class="btn btn-outline-secondary" target="_blank">Read Original</a>
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</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>
<footer class="py-3 my-4">
<ul class="nav justify-content-center border-bottom pb-3 mb-3">
<li class="nav-item"><a href="/" class="nav-link px-2 text-muted">Home</a></li>
</ul>
<p class="text-center text-muted">&copy; 2025 Artickle</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
<script>
feather.replace()
</script>
</body>
</html>