Загрузить файлы в «/»

This commit is contained in:
2026-04-30 08:09:46 +00:00
commit 08fe53fa5c
5 changed files with 1331 additions and 0 deletions
+183
View File
@@ -0,0 +1,183 @@
<?php
/**
* Flickr OAuth Authorization Handler
*
* Usage:
* 1. Visit flickr_auth.php to start authorization
* 2. Authorize on Flickr
* 3. Callback returns here with tokens saved
*/
session_start();
require_once __DIR__ . '/classes/FlickrOAuth.php';
// Load config
$configFile = __DIR__ . '/config.php';
if (!file_exists($configFile)) {
die('Configuration not found');
}
$config = require $configFile;
if (empty($config['flickr']['api_key']) || empty($config['flickr']['api_secret'])) {
die('Flickr API credentials not configured');
}
$oauth = new FlickrOAuth(
$config['flickr']['api_key'],
$config['flickr']['api_secret']
);
$action = $_GET['action'] ?? '';
$baseUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http')
. '://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']);
// Handle OAuth callback from Flickr
if (isset($_GET['oauth_token']) && isset($_GET['oauth_verifier'])) {
try {
$result = $oauth->handleCallback($_GET['oauth_token'], $_GET['oauth_verifier']);
$message = "Авторизация успешна! Пользователь: " . htmlspecialchars($result['username'] ?? $result['user_nsid']);
$success = true;
} catch (Exception $e) {
$message = "Ошибка авторизации: " . htmlspecialchars($e->getMessage());
$success = false;
}
// Show result
?>
<!DOCTYPE html>
<html>
<head>
<title>Flickr OAuth</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, sans-serif; padding: 40px; background: #f5f5f7; }
.card { background: white; padding: 30px; border-radius: 16px; max-width: 500px; margin: 0 auto; box-shadow: 0 4px 20px rgba(0,0,0,0.1); }
h1 { margin-top: 0; }
.success { color: #34C759; }
.error { color: #FF3B30; }
.btn { display: inline-block; padding: 12px 24px; background: #007AFF; color: white; text-decoration: none; border-radius: 8px; margin-top: 20px; }
.btn:hover { background: #0056CC; }
</style>
</head>
<body>
<div class="card">
<h1 class="<?= $success ? 'success' : 'error' ?>"><?= $success ? '✓' : '✗' ?> <?= $message ?></h1>
<?php if ($success): ?>
<p>Теперь приложение может загружать фотографии в оригинальном качестве.</p>
<?php endif; ?>
<a href="index.php" class="btn">Вернуться в приложение</a>
</div>
</body>
</html>
<?php
exit;
}
// Handle logout
if ($action === 'logout') {
$oauth->clearTokens();
header('Location: flickr_auth.php');
exit;
}
// Check current status or start auth
$isAuthorized = $oauth->isAuthorized();
if ($action === 'authorize' && !$isAuthorized) {
try {
$callbackUrl = $baseUrl . '/flickr_auth.php';
$authUrl = $oauth->getAuthorizationUrl($callbackUrl);
header('Location: ' . $authUrl);
exit;
} catch (Exception $e) {
$error = $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Flickr OAuth Authorization</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
padding: 40px;
background: #f5f5f7;
min-height: 100vh;
margin: 0;
}
.card {
background: white;
padding: 30px;
border-radius: 16px;
max-width: 500px;
margin: 0 auto;
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}
h1 { margin-top: 0; font-size: 1.5rem; }
.status {
padding: 16px;
border-radius: 8px;
margin: 20px 0;
}
.status.authorized { background: #d4edda; color: #155724; }
.status.not-authorized { background: #fff3cd; color: #856404; }
.btn {
display: inline-block;
padding: 12px 24px;
background: #007AFF;
color: white;
text-decoration: none;
border-radius: 8px;
border: none;
cursor: pointer;
font-size: 1rem;
}
.btn:hover { background: #0056CC; }
.btn-danger { background: #FF3B30; }
.btn-danger:hover { background: #CC2F27; }
.btn-secondary { background: #8E8E93; }
.error { color: #FF3B30; margin: 20px 0; }
ul { padding-left: 20px; }
li { margin: 8px 0; }
</style>
</head>
<body>
<div class="card">
<h1>🔐 Flickr OAuth Authorization</h1>
<?php if (isset($error)): ?>
<div class="error">Ошибка: <?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<?php if ($isAuthorized): ?>
<div class="status authorized">
✓ <strong>Авторизован</strong> — доступ к оригиналам фото включён
</div>
<p>Приложение авторизовано и может загружать фотографии в оригинальном качестве.</p>
<p>
<a href="index.php" class="btn">Открыть приложение</a>
<a href="?action=logout" class="btn btn-danger" style="margin-left: 10px;">Выйти</a>
</p>
<?php else: ?>
<div class="status not-authorized">
⚠ <strong>Не авторизован</strong> — доступны только уменьшенные версии
</div>
<p>Для загрузки фотографий в оригинальном качестве необходимо авторизовать приложение:</p>
<ul>
<li>Вы будете перенаправлены на Flickr</li>
<li>Flickr запросит разрешение на <strong>чтение</strong> ваших фото</li>
<li>После подтверждения вернётесь обратно</li>
</ul>
<p>
<a href="?action=authorize" class="btn">Авторизовать через Flickr</a>
<a href="index.php" class="btn btn-secondary" style="margin-left: 10px;">Назад</a>
</p>
<?php endif; ?>
</div>
</body>
</html>