修复bug,增加分享功能
修复bug,markdown解析,编辑出空白
This commit is contained in:
+788
-10
@@ -170,17 +170,12 @@ function downloadAndSaveImage($url) {
|
||||
|
||||
// 自动格式化链接
|
||||
function autoFormatLinks($content) {
|
||||
// 匹配非Markdown格式的URL
|
||||
$pattern = '/(?<!\]\()https?:\/\/[^\s\)]+(?!\))/i';
|
||||
// 匹配非Markdown格式的URL,但排除已经是Markdown链接的部分
|
||||
$pattern = '/(?<![\[\(])https?:\/\/[^\s\)]+(?![\)\]])/i';
|
||||
|
||||
$content = preg_replace_callback($pattern, function($matches) {
|
||||
$url = $matches[0];
|
||||
|
||||
// 如果已经是Markdown链接格式,则跳过
|
||||
if (preg_match('/\[' . preg_quote($url, '/') . '\]\(' . preg_quote($url, '/') . '\)/', $content)) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
// 如果是图片URL,则跳过(已在processExternalImages中处理)
|
||||
if (isExternalImage($url)) {
|
||||
return $url;
|
||||
@@ -234,11 +229,28 @@ function initDatabase() {
|
||||
)
|
||||
');
|
||||
|
||||
// 创建分享表
|
||||
$db->exec('
|
||||
CREATE TABLE IF NOT EXISTS shares (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
note_id INTEGER NOT NULL,
|
||||
share_token TEXT UNIQUE NOT NULL,
|
||||
password TEXT,
|
||||
view_limit INTEGER DEFAULT 0,
|
||||
view_count INTEGER DEFAULT 0,
|
||||
expires_at DATETIME,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (note_id) REFERENCES notes (id) ON DELETE CASCADE
|
||||
)
|
||||
');
|
||||
|
||||
// 创建索引
|
||||
$db->exec('CREATE INDEX IF NOT EXISTS idx_notes_title ON notes(title)');
|
||||
$db->exec('CREATE INDEX IF NOT EXISTS idx_notes_tags ON notes(tags)');
|
||||
$db->exec('CREATE INDEX IF NOT EXISTS idx_notes_created ON notes(created_at)');
|
||||
$db->exec('CREATE INDEX IF NOT EXISTS idx_attachments_note_id ON attachments(note_id)');
|
||||
$db->exec('CREATE INDEX IF NOT EXISTS idx_shares_token ON shares(share_token)');
|
||||
$db->exec('CREATE INDEX IF NOT EXISTS idx_shares_note_id ON shares(note_id)');
|
||||
|
||||
return $db;
|
||||
} catch (Exception $e) {
|
||||
@@ -569,6 +581,75 @@ function isLoggedIn() {
|
||||
return isset($_SESSION['user_id']);
|
||||
}
|
||||
|
||||
// 创建分享
|
||||
function createShare($noteId, $password = null, $viewLimit = 0, $expiresAt = null) {
|
||||
$db = getDB();
|
||||
|
||||
// 生成唯一的分享令牌
|
||||
$shareToken = bin2hex(random_bytes(16));
|
||||
|
||||
$stmt = $db->prepare('INSERT INTO shares (note_id, share_token, password, view_limit, expires_at) VALUES (?, ?, ?, ?, ?)');
|
||||
$stmt->bindValue(1, $noteId, SQLITE3_INTEGER);
|
||||
$stmt->bindValue(2, $shareToken, SQLITE3_TEXT);
|
||||
$stmt->bindValue(3, $password ? password_hash($password, PASSWORD_DEFAULT) : null, SQLITE3_TEXT);
|
||||
$stmt->bindValue(4, $viewLimit, SQLITE3_INTEGER);
|
||||
$stmt->bindValue(5, $expiresAt, SQLITE3_TEXT);
|
||||
$stmt->execute();
|
||||
|
||||
return $shareToken;
|
||||
}
|
||||
|
||||
// 获取分享信息
|
||||
function getShareByToken($token) {
|
||||
$db = getDB();
|
||||
$stmt = $db->prepare('SELECT * FROM shares WHERE share_token = ?');
|
||||
$stmt->bindValue(1, $token, SQLITE3_TEXT);
|
||||
$result = $stmt->execute();
|
||||
$share = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($share) {
|
||||
// 检查是否过期
|
||||
if ($share['expires_at'] && strtotime($share['expires_at']) < time()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 检查查看次数限制
|
||||
if ($share['view_limit'] > 0 && $share['view_count'] >= $share['view_limit']) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 增加查看次数
|
||||
$updateStmt = $db->prepare('UPDATE shares SET view_count = view_count + 1 WHERE id = ?');
|
||||
$updateStmt->bindValue(1, $share['id'], SQLITE3_INTEGER);
|
||||
$updateStmt->execute();
|
||||
}
|
||||
|
||||
return $share;
|
||||
}
|
||||
|
||||
// 获取笔记的分享列表
|
||||
function getNoteShares($noteId) {
|
||||
$db = getDB();
|
||||
$stmt = $db->prepare('SELECT * FROM shares WHERE note_id = ? ORDER BY created_at DESC');
|
||||
$stmt->bindValue(1, $noteId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$shares = [];
|
||||
|
||||
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$shares[] = $row;
|
||||
}
|
||||
|
||||
return $shares;
|
||||
}
|
||||
|
||||
// 删除分享
|
||||
function deleteShare($id) {
|
||||
$db = getDB();
|
||||
$stmt = $db->prepare('DELETE FROM shares WHERE id = ?');
|
||||
$stmt->bindValue(1, $id, SQLITE3_INTEGER);
|
||||
return $stmt->execute();
|
||||
}
|
||||
|
||||
// 处理登录
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
||||
if ($_POST['action'] === 'init') {
|
||||
@@ -652,6 +733,34 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
||||
} else {
|
||||
$error = '标题和内容不能为空';
|
||||
}
|
||||
} elseif ($_POST['action'] === 'create_share') {
|
||||
if (!isLoggedIn()) {
|
||||
header('Location: ?');
|
||||
exit;
|
||||
}
|
||||
|
||||
$noteId = intval($_POST['note_id'] ?? 0);
|
||||
$password = trim($_POST['share_password'] ?? '');
|
||||
$viewLimit = intval($_POST['view_limit'] ?? 0);
|
||||
$expiresIn = intval($_POST['expires_in'] ?? 0);
|
||||
|
||||
// 计算过期时间
|
||||
$expiresAt = null;
|
||||
if ($expiresIn > 0) {
|
||||
$expiresAt = date('Y-m-d H:i:s', time() + $expiresIn * 3600); // 小时转换为秒
|
||||
}
|
||||
|
||||
$shareToken = createShare($noteId, $password ?: null, $viewLimit, $expiresAt);
|
||||
|
||||
if ($shareToken) {
|
||||
$shareUrl = getBaseUrl() . '/' . getCurrentFile() . '?share=' . $shareToken;
|
||||
$_SESSION['share_success'] = '分享链接已创建: <a href="' . $shareUrl . '" target="_blank">' . $shareUrl . '</a>';
|
||||
} else {
|
||||
$error = '创建分享失败';
|
||||
}
|
||||
|
||||
header('Location: ?view=' . $noteId);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -671,6 +780,14 @@ if (isset($_GET['delete_attachment']) && isLoggedIn()) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// 处理删除分享
|
||||
if (isset($_GET['delete_share']) && isLoggedIn()) {
|
||||
$id = intval($_GET['delete_share']);
|
||||
deleteShare($id);
|
||||
header('Location: ' . $_SERVER['HTTP_REFERER']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 处理登出
|
||||
if (isset($_GET['logout'])) {
|
||||
session_destroy();
|
||||
@@ -686,6 +803,392 @@ if (isset($_GET['logout'])) {
|
||||
// 获取导航URL
|
||||
$homeUrl = getHomeUrl();
|
||||
|
||||
// 处理分享访问
|
||||
if (isset($_GET['share'])) {
|
||||
$shareToken = $_GET['share'];
|
||||
$share = getShareByToken($shareToken);
|
||||
|
||||
if (!$share) {
|
||||
$shareError = '分享链接无效或已过期';
|
||||
} else {
|
||||
$note = getNote($share['note_id']);
|
||||
if (!$note) {
|
||||
$shareError = '笔记不存在';
|
||||
} else {
|
||||
// 检查是否需要密码
|
||||
if ($share['password'] && !isset($_SESSION['share_authenticated'][$shareToken])) {
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'verify_share_password') {
|
||||
$password = $_POST['share_password'] ?? '';
|
||||
if (password_verify($password, $share['password'])) {
|
||||
$_SESSION['share_authenticated'][$shareToken] = true;
|
||||
} else {
|
||||
$shareError = '密码错误';
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($_SESSION['share_authenticated'][$shareToken])) {
|
||||
// 显示密码输入页面
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>密码验证 - <?php echo APP_NAME; ?></title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.login-container {
|
||||
background: white;
|
||||
padding: 40px;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
font-size: 28px;
|
||||
color: #333;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.login-header p {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #555;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.form-input {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
.form-input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.login-btn:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.error {
|
||||
background: #fee;
|
||||
color: #c33;
|
||||
padding: 10px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-container">
|
||||
<div class="login-header">
|
||||
<h1><?php echo APP_NAME; ?></h1>
|
||||
<p>此分享需要密码验证</p>
|
||||
</div>
|
||||
|
||||
<?php if (isset($shareError)): ?>
|
||||
<div class="error"><?php echo $shareError; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post">
|
||||
<input type="hidden" name="action" value="verify_share_password">
|
||||
<div class="form-group">
|
||||
<label class="form-label">请输入分享密码</label>
|
||||
<input type="password" name="share_password" class="form-input" required>
|
||||
</div>
|
||||
<button type="submit" class="login-btn">验证</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// 显示分享的笔记
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?php echo htmlspecialchars($note['title']); ?> - <?php echo APP_NAME; ?></title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
:root {
|
||||
--bg-primary: #ffffff;
|
||||
--bg-secondary: #f8f9fa;
|
||||
--bg-tertiary: #e9ecef;
|
||||
--text-primary: #2c3e50;
|
||||
--text-secondary: #6c757d;
|
||||
--text-muted: #adb5bd;
|
||||
--border-color: #dee2e6;
|
||||
--accent-color: #3498db;
|
||||
--success-color: #27ae60;
|
||||
--danger-color: #e74c3c;
|
||||
--hover-bg: #f1f3f5;
|
||||
--shadow-sm: 0 2px 4px rgba(0,0,0,0.08);
|
||||
--shadow-md: 0 4px 12px rgba(0,0,0,0.1);
|
||||
--transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
[data-theme="dark"] {
|
||||
--bg-primary: #1a1a1a;
|
||||
--bg-secondary: #2d2d2d;
|
||||
--bg-tertiary: #404040;
|
||||
--text-primary: #e9ecef;
|
||||
--text-secondary: #adb5bd;
|
||||
--text-muted: #6c757d;
|
||||
--border-color: #495057;
|
||||
--accent-color: #5dade2;
|
||||
--hover-bg: #343434;
|
||||
--shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
|
||||
--shadow-md: 0 4px 12px rgba(0,0,0,0.4);
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
line-height: 1.6;
|
||||
transition: var(--transition);
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
/* Header */
|
||||
header {
|
||||
background: var(--bg-secondary);
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.header-content {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.logo-link {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.logo-link:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.share-info {
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* Note View */
|
||||
.note-view {
|
||||
background: var(--bg-secondary);
|
||||
border-radius: 8px;
|
||||
padding: 30px;
|
||||
margin-top: 30px;
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.note-view-header {
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.note-view-title {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.note-view-meta {
|
||||
color: var(--text-muted);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.note-view-content {
|
||||
line-height: 1.8;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.note-view-tags {
|
||||
margin-top: 30px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.sidebar-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 15px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.tag-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.tag {
|
||||
padding: 4px 10px;
|
||||
background: var(--bg-tertiary);
|
||||
color: var(--text-secondary);
|
||||
border-radius: 12px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* Footer */
|
||||
footer {
|
||||
margin-top: 40px;
|
||||
padding: 20px 0;
|
||||
text-align: center;
|
||||
color: var(--text-muted);
|
||||
font-size: 14px;
|
||||
border-top: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 768px) {
|
||||
.note-view-title {
|
||||
font-size: 24px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="container">
|
||||
<div class="header-content">
|
||||
<div class="logo">
|
||||
<a href="<?php echo getBaseUrl(); ?>" class="logo-link">
|
||||
<?php echo APP_NAME; ?>
|
||||
</a>
|
||||
</div>
|
||||
<div class="share-info">
|
||||
分享笔记
|
||||
<?php if ($share['view_limit'] > 0): ?>
|
||||
· 剩余查看次数: <?php echo $share['view_limit'] - $share['view_count']; ?>
|
||||
<?php endif; ?>
|
||||
<?php if ($share['expires_at']): ?>
|
||||
· 过期时间: <?php echo date('Y-m-d H:i', strtotime($share['expires_at'])); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="container">
|
||||
<div class="note-view">
|
||||
<div class="note-view-header">
|
||||
<div class="note-view-title"><?php echo htmlspecialchars($note['title']); ?></div>
|
||||
<div class="note-view-meta">
|
||||
创建于 <?php echo date('Y-m-d H:i', strtotime($note['created_at'])); ?>
|
||||
<?php if ($note['updated_at'] !== $note['created_at']): ?>
|
||||
· 更新于 <?php echo date('Y-m-d H:i', strtotime($note['updated_at'])); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="note-view-content">
|
||||
<?php echo markdownToHtml($note['content']); ?>
|
||||
</div>
|
||||
|
||||
<?php if ($note['tags']): ?>
|
||||
<div class="note-view-tags">
|
||||
<div class="sidebar-title">标签</div>
|
||||
<div class="tag-list">
|
||||
<?php foreach (explode(',', $note['tags']) as $tag): ?>
|
||||
<span class="tag"><?php echo htmlspecialchars(trim($tag)); ?></span>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="container">
|
||||
<p>由 <?php echo APP_NAME; ?> 强力驱动</p>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果未初始化,显示初始化页面
|
||||
if (!isInitialized()) {
|
||||
?>
|
||||
@@ -1463,7 +1966,7 @@ if (isset($_GET['edit'])) {
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.form-input, .form-textarea {
|
||||
.form-input, .form-textarea, .form-select {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
border: 1px solid var(--border-color);
|
||||
@@ -1475,7 +1978,7 @@ if (isset($_GET['edit'])) {
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.form-input:focus, .form-textarea:focus {
|
||||
.form-input:focus, .form-textarea:focus, .form-select:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent-color);
|
||||
}
|
||||
@@ -1703,6 +2206,137 @@ if (isset($_GET['edit'])) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Share Section */
|
||||
.share-section {
|
||||
margin-top: 20px;
|
||||
padding: 15px;
|
||||
background: var(--bg-tertiary);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.share-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 10px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.share-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.share-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
background: var(--bg-primary);
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.share-item:hover {
|
||||
background: var(--hover-bg);
|
||||
}
|
||||
|
||||
.share-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.share-link {
|
||||
color: var(--accent-color);
|
||||
text-decoration: none;
|
||||
font-family: monospace;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.share-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.share-meta {
|
||||
color: var(--text-muted);
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.share-actions {
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.share-btn {
|
||||
padding: 4px 8px;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--text-muted);
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.share-btn:hover {
|
||||
color: var(--accent-color);
|
||||
}
|
||||
|
||||
.share-btn.delete:hover {
|
||||
color: var(--danger-color);
|
||||
}
|
||||
|
||||
.share-form {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.share-form-group {
|
||||
flex: 1;
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
.share-form-label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.share-form-input {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
font-size: 12px;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.share-form-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent-color);
|
||||
}
|
||||
|
||||
.share-form-btn {
|
||||
padding: 8px 16px;
|
||||
background: var(--accent-color);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.share-form-btn:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
/* Modal */
|
||||
.modal {
|
||||
display: none;
|
||||
@@ -1767,6 +2401,21 @@ if (isset($_GET['edit'])) {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* Success Message */
|
||||
.success-message {
|
||||
background: var(--success-color);
|
||||
color: white;
|
||||
padding: 10px 15px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.success-message a {
|
||||
color: white;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* Animations */
|
||||
@keyframes slideUp {
|
||||
from {
|
||||
@@ -1818,6 +2467,14 @@ if (isset($_GET['edit'])) {
|
||||
padding: 4px 6px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.share-form {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.share-form-group {
|
||||
min-width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
@@ -1879,6 +2536,7 @@ if (isset($_GET['edit'])) {
|
||||
</div>
|
||||
<div class="note-view-actions">
|
||||
<button class="btn" onclick="editNote(<?php echo $viewNote['id']; ?>)">编辑</button>
|
||||
<button class="btn" onclick="shareNote(<?php echo $viewNote['id']; ?>)">分享</button>
|
||||
<button class="btn" onclick="deleteNote(<?php echo $viewNote['id']; ?>)" style="color: var(--danger-color);">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1911,6 +2569,41 @@ if (isset($_GET['edit'])) {
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Shares -->
|
||||
<?php $shares = getNoteShares($viewNote['id']); ?>
|
||||
<?php if (!empty($shares)): ?>
|
||||
<div class="share-section">
|
||||
<div class="share-title">分享链接</div>
|
||||
<div class="share-list">
|
||||
<?php foreach ($shares as $share): ?>
|
||||
<div class="share-item">
|
||||
<div class="share-info">
|
||||
<a href="<?php echo getBaseUrl() . '/' . getCurrentFile() . '?share=' . $share['share_token']; ?>" class="share-link" target="_blank">
|
||||
<?php echo getBaseUrl() . '/' . getCurrentFile() . '?share=' . $share['share_token']; ?>
|
||||
</a>
|
||||
<div class="share-meta">
|
||||
创建于 <?php echo date('Y-m-d H:i', strtotime($share['created_at'])); ?>
|
||||
<?php if ($share['view_limit'] > 0): ?>
|
||||
· 剩余查看: <?php echo $share['view_limit'] - $share['view_count']; ?>
|
||||
<?php endif; ?>
|
||||
<?php if ($share['expires_at']): ?>
|
||||
· 过期: <?php echo date('Y-m-d H:i', strtotime($share['expires_at'])); ?>
|
||||
<?php endif; ?>
|
||||
<?php if ($share['password']): ?>
|
||||
· 有密码保护
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="share-actions">
|
||||
<button class="share-btn" onclick="copyShareLink('<?php echo getBaseUrl() . '/' . getCurrentFile() . '?share=' . $share['share_token']; ?>')">复制</button>
|
||||
<button class="share-btn delete" onclick="deleteShare(<?php echo $share['id']; ?>)">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($viewNote['tags']): ?>
|
||||
<div class="note-view-tags">
|
||||
<div class="sidebar-title">标签</div>
|
||||
@@ -2053,6 +2746,12 @@ if (isset($_GET['edit'])) {
|
||||
<div class="notes-count">共 <?php echo $totalNotes; ?> 篇</div>
|
||||
</div>
|
||||
|
||||
<?php if (isset($_SESSION['share_success'])): ?>
|
||||
<div class="success-message">
|
||||
<?php echo $_SESSION['share_success']; unset($_SESSION['share_success']); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (empty($notes)): ?>
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon">📝</div>
|
||||
@@ -2076,10 +2775,11 @@ if (isset($_GET['edit'])) {
|
||||
<div class="note-actions" onclick="event.stopPropagation()">
|
||||
<button class="note-btn" onclick="viewNote(<?php echo $note['id']; ?>)">👁️</button>
|
||||
<button class="note-btn" onclick="editNote(<?php echo $note['id']; ?>)">✏️</button>
|
||||
<button class="note-btn" onclick="shareNote(<?php echo $note['id']; ?>)">🔗</button>
|
||||
<button class="note-btn delete" onclick="deleteNote(<?php echo $note['id']; ?>)">🗑️</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="note-content"><?php echo htmlspecialchars(mb_substr(strip_tags($note['content']), 0, 200)); ?>...</div>
|
||||
<div class="note-content"><?php echo htmlspecialchars(substr(strip_tags($note['content']), 0, 200)); ?>...</div>
|
||||
<?php if ($note['tags']): ?>
|
||||
<div class="note-tags">
|
||||
<?php foreach (explode(',', $note['tags']) as $noteTag): ?>
|
||||
@@ -2142,6 +2842,43 @@ if (isset($_GET['edit'])) {
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- Share Modal -->
|
||||
<div class="modal" id="shareModal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<span class="close-modal" onclick="closeShareModal()">×</span>
|
||||
<div class="modal-title">分享笔记</div>
|
||||
</div>
|
||||
<?php if (isset($error)): ?>
|
||||
<div style="color: var(--danger-color); margin-bottom: 15px;"><?php echo $error; ?></div>
|
||||
<?php endif; ?>
|
||||
<form method="post" id="shareForm">
|
||||
<input type="hidden" name="action" value="create_share">
|
||||
<input type="hidden" name="note_id" id="shareNoteId">
|
||||
<div class="form-group">
|
||||
<label class="form-label">分享密码(可选)</label>
|
||||
<input type="password" name="share_password" class="form-input" placeholder="留空则无需密码">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">查看次数限制(0为无限制)</label>
|
||||
<input type="number" name="view_limit" class="form-input" min="0" value="0">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">有效期(小时,0为永久)</label>
|
||||
<select name="expires_in" class="form-select">
|
||||
<option value="0">永久</option>
|
||||
<option value="1">1小时</option>
|
||||
<option value="6">6小时</option>
|
||||
<option value="24">1天</option>
|
||||
<option value="168">1周</option>
|
||||
<option value="720">1月</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary" style="width: 100%;">创建分享链接</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Password Modal -->
|
||||
<div class="modal" id="passwordModal">
|
||||
<div class="modal-content">
|
||||
@@ -2456,6 +3193,12 @@ if (isset($_GET['edit'])) {
|
||||
window.location.href = '?edit=' + id;
|
||||
}
|
||||
|
||||
// Share Note
|
||||
function shareNote(id) {
|
||||
document.getElementById('shareNoteId').value = id;
|
||||
document.getElementById('shareModal').classList.add('active');
|
||||
}
|
||||
|
||||
// Delete Note
|
||||
function deleteNote(id) {
|
||||
if (confirm('确定要删除这篇笔记吗?')) {
|
||||
@@ -2470,6 +3213,35 @@ if (isset($_GET['edit'])) {
|
||||
}
|
||||
}
|
||||
|
||||
// Delete Share
|
||||
function deleteShare(id) {
|
||||
if (confirm('确定要删除这个分享链接吗?')) {
|
||||
window.location.href = '?delete_share=' + id;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy Share Link
|
||||
function copyShareLink(url) {
|
||||
navigator.clipboard.writeText(url).then(() => {
|
||||
alert('分享链接已复制到剪贴板');
|
||||
}).catch(err => {
|
||||
console.error('复制失败:', err);
|
||||
// 降级方案
|
||||
const textArea = document.createElement('textarea');
|
||||
textArea.value = url;
|
||||
document.body.appendChild(textArea);
|
||||
textArea.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(textArea);
|
||||
alert('分享链接已复制到剪贴板');
|
||||
});
|
||||
}
|
||||
|
||||
// Share Modal
|
||||
function closeShareModal() {
|
||||
document.getElementById('shareModal').classList.remove('active');
|
||||
}
|
||||
|
||||
// Password Modal
|
||||
function openPasswordModal() {
|
||||
document.getElementById('passwordModal').classList.add('active');
|
||||
@@ -2480,6 +3252,12 @@ if (isset($_GET['edit'])) {
|
||||
}
|
||||
|
||||
// Close modal when clicking outside
|
||||
document.getElementById('shareModal').addEventListener('click', (e) => {
|
||||
if (e.target === e.currentTarget) {
|
||||
closeShareModal();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('passwordModal').addEventListener('click', (e) => {
|
||||
if (e.target === e.currentTarget) {
|
||||
closePasswordModal();
|
||||
|
||||
Reference in New Issue
Block a user