Foro: reemplazar el foro anterior por el port del foro estilo FusionCMS
Se sustituye por completo el foro anterior de Next (que estaba vacío: 0 temas, 0 posts) por una adaptación del foro PHP de FusionCMS que tenía el usuario, con su estructura, sus imágenes y su estética, llevadas a Next. BASE DE DATOS (acore_web), esquema idéntico al original (sql/forum_fusion.sql): forum_categories(id, order, name) forum_forums(id, category, order, name, description, icon, colortitle, type) forum_topics(id, forum, name, sticky, locked, deleted, created) forum_posts(id, topic, poster, text, time, deleted) Se hizo DROP de las tablas antiguas (forums, forum_categories, forum_topics, forum_posts) y CREATE de estas, con el seed original (News/Reports/General, foros con icono, clases con color, subforos por idioma con bandera). Única diferencia con el dump: forum_topics.created, que faltaba y usan las vistas, y el recorte del salto de línea final en los nombres de clase. Los temas no guardan autor ni última actividad: se derivan del primer/último post, como en el original. `poster` es el AccountID de acore_auth; el nombre se resuelve al render (username sin el sufijo #N de Battle.net). El texto se guarda como HTML saneado con nh3 (no BBCode) para encajar con el editor. EDITOR: TinyMCE community self-hosted (licenseKey gpl), servido desde /tinymce (scripts/copy-tinymce.mjs en postinstall; public/tinymce en .gitignore por ser artefacto). El HTML se sanea SIEMPRE en el servidor. PÁGINAS (app/[locale]/forum): índice con los 3 tipos de foro (fila normal, tarjeta de clase tipo 1, tarjeta de idioma tipo 2), subforo, tema, crear y editar. La lógica de forum.js (crear/responder/editar/moderar) se portó a fetch + los avisos del sitio, sin jQuery/SweetAlert, y la moderación pasa por POST (no GET). CSS: forum.css adaptado al tema (app/forum.css), rutas de imagen a /forum, dorado alineado al acento del sitio (#d79602), y se aportan .nice_button/.main-wide/ .pagination que no estaban en theme.css. ADMIN: lib/admin-forum.ts, sus rutas y AdminForumManager reescritos al esquema nuevo (categoría, icono, color, tipo, orden; sin _en/visibility). Se eliminan /forum/search y /forum/user (no existen en el foro nuevo) y los componentes que quedaban huérfanos (ForumSearchBox, PostActions, TopicModBar, NewTopicForm). i18n ES/EN completado (next-intl). Verificado en producción: el índice renderiza en es/en con categorías, clases, banderas e iconos; los assets y TinyMCE sirven 200; crear tema y responder guardan las filas con el esquema correcto y las páginas las muestran (autor resuelto, HTML saneado). Datos de prueba borrados: el foro arranca vacío. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,18 +1,26 @@
|
||||
import { notFound } from 'next/navigation'
|
||||
import { getTranslations, setRequestLocale } from 'next-intl/server'
|
||||
import { Link } from '@/i18n/navigation'
|
||||
import { getTopic, getPosts, countPosts, listForumsForMove } from '@/lib/forum'
|
||||
import {
|
||||
getTopic,
|
||||
getTopicPath,
|
||||
getPosts,
|
||||
countPosts,
|
||||
resolvePosters,
|
||||
getUserPostCount,
|
||||
} from '@/lib/forum'
|
||||
import { formatForumDate } from '@/lib/forum-format'
|
||||
import { getSession } from '@/lib/session'
|
||||
import { forumIsModerator, canEditPost } from '@/lib/forum-perm'
|
||||
import { PageShell } from '@/components/PageShell'
|
||||
import { ReplyForm } from '@/components/ReplyForm'
|
||||
import { PostActions } from '@/components/PostActions'
|
||||
import { TopicModBar } from '@/components/TopicModBar'
|
||||
import { ForumBreadcrumb } from '@/components/ForumBreadcrumb'
|
||||
import { Pagination } from '@/components/Pagination'
|
||||
import { ReplyForm } from '@/components/ReplyForm'
|
||||
import { EditPostForm } from '@/components/EditPostForm'
|
||||
import { ForumModActions } from '@/components/ForumModActions'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const PER_PAGE = 15
|
||||
const PER_PAGE = 5
|
||||
|
||||
export default async function TopicPage({
|
||||
params,
|
||||
@@ -30,77 +38,136 @@ export default async function TopicPage({
|
||||
const isMod = await forumIsModerator(session)
|
||||
const topic = await getTopic(id, isMod)
|
||||
if (!topic) notFound()
|
||||
|
||||
const total = await countPosts(id, isMod)
|
||||
const totalPages = Math.max(1, Math.ceil(total / PER_PAGE))
|
||||
const page = Math.min(Math.max(1, Number((await searchParams).page) || 1), totalPages)
|
||||
const posts = await getPosts(id, (page - 1) * PER_PAGE, PER_PAGE, isMod)
|
||||
const moveForums = isMod ? (await listForumsForMove()).filter((f) => f.id !== topic!.forum_id) : []
|
||||
const canReply = Boolean(session.username) && (!topic!.locked || isMod)
|
||||
|
||||
const title = (
|
||||
<>
|
||||
{topic!.sticky && <span className="second-yellow">[{t('pinned')}] </span>}
|
||||
{topic!.locked && <span className="red-info2">[{t('locked')}] </span>}
|
||||
{topic!.deleted && <span className="red-info2">[{t('deletedMark')}] </span>}
|
||||
{topic!.name}
|
||||
</>
|
||||
const posters = await resolvePosters(posts.map((p) => p.poster))
|
||||
// Nº de posts por autor visible (para el panel lateral), en paralelo.
|
||||
const uniquePosters = [...new Set(posts.map((p) => p.poster))]
|
||||
const counts = new Map<number, number>(
|
||||
await Promise.all(uniquePosters.map(async (pid) => [pid, await getUserPostCount(pid)] as const)),
|
||||
)
|
||||
|
||||
const path = await getTopicPath(id)
|
||||
const canReply = Boolean(session.username) && (!topic.locked || isMod)
|
||||
|
||||
return (
|
||||
<PageShell title={title}>
|
||||
<div className="box-content">
|
||||
<div className="body-box-content">
|
||||
<p>
|
||||
<Link href="/forum">← {t('backToForum')}</Link>
|
||||
</p>
|
||||
<br />
|
||||
<PageShell
|
||||
title={
|
||||
<>
|
||||
{topic.sticky && `[${t('sticky')}] `}
|
||||
{topic.locked && `[${t('locked')}] `}
|
||||
{topic.deleted && `[${t('deleted')}] `}
|
||||
{topic.name}
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="main-wide">
|
||||
{path && (
|
||||
<ForumBreadcrumb
|
||||
items={[
|
||||
{ label: t('title'), href: '/forum' },
|
||||
{ label: path.forum, href: `/forum/${path.forum_id}` },
|
||||
{ label: path.topic },
|
||||
]}
|
||||
/>
|
||||
)}
|
||||
|
||||
{isMod && (
|
||||
<TopicModBar
|
||||
topicId={id}
|
||||
locked={topic!.locked}
|
||||
sticky={topic!.sticky}
|
||||
deleted={topic!.deleted}
|
||||
moveForums={moveForums}
|
||||
/>
|
||||
)}
|
||||
|
||||
{posts.map((post) => (
|
||||
<div key={post.id} className="inline-div" style={{ display: 'block', opacity: post.deleted ? 0.5 : 1 }}>
|
||||
<div className="lefted">
|
||||
<span className="yellow-info">
|
||||
<Link href={`/forum/user/${encodeURIComponent(post.poster)}`}>{post.poster}</Link>
|
||||
{post.deleted && <span className="red-info2 small-font"> [{t('deletedMark')}]</span>}
|
||||
</span>
|
||||
{post.time && (
|
||||
<span className="date third-brown small-font">
|
||||
{new Date(post.time).toLocaleString(locale)}
|
||||
{post.edited && <span className="grey-info2"> · {t('editedMark')}</span>}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<hr />
|
||||
<div className="post-content" dangerouslySetInnerHTML={{ __html: post.text }} />
|
||||
{canEditPost(session, isMod, post.poster_id) && (
|
||||
<PostActions postId={post.id} initialText={post.text} deleted={post.deleted} />
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
|
||||
<Pagination page={page} totalPages={totalPages} hrefFor={(p) => `/forum/topic/${id}?page=${p}`} />
|
||||
|
||||
{canReply ? (
|
||||
page === totalPages ? (
|
||||
<ReplyForm topicId={id} />
|
||||
) : (
|
||||
<p className="separate">
|
||||
<Link href={`/forum/topic/${id}?page=${totalPages}`}>{t('replyOnLastPage')}</Link>
|
||||
</p>
|
||||
)
|
||||
) : (
|
||||
!session.username && <p className="second-brown centered separate">{t('loginToPost')}</p>
|
||||
)}
|
||||
<div className="topic_header">
|
||||
<div className="topic_title">
|
||||
<h1>{topic.name}</h1>
|
||||
<h3>{formatForumDate(topic.created, locale)}</h3>
|
||||
</div>
|
||||
<h4>
|
||||
<b>{total}</b> {t('posts')}
|
||||
</h4>
|
||||
</div>
|
||||
|
||||
<div className="actions_c">
|
||||
<span />
|
||||
<Pagination page={page} totalPages={totalPages} hrefFor={(p) => `/forum/topic/${id}?page=${p}`} />
|
||||
</div>
|
||||
|
||||
{posts.map((post) => {
|
||||
const author = posters.get(post.poster)
|
||||
const isStaff = author?.isStaff ?? false
|
||||
return (
|
||||
<div key={post.id} className={`topic_post${isStaff ? ' isStaff' : ''}${post.deleted ? ' post_deleted' : ''}`}>
|
||||
<div className="left_side">
|
||||
<div className="username_container">
|
||||
<span className="username">{author?.name ?? `#${post.poster}`}</span>
|
||||
</div>
|
||||
<div className={`user_avatar${isStaff ? ' isStaff' : ''}`}>
|
||||
<span />
|
||||
</div>
|
||||
<div className="user_info">
|
||||
<h3 className="post_field">
|
||||
<dt>
|
||||
<i className="fa-solid fa-user-shield fa-fw" />
|
||||
</dt>
|
||||
<dd className={isStaff ? 'badge_staff' : undefined}>{isStaff ? t('staff') : t('member')}</dd>
|
||||
</h3>
|
||||
<h3 className="post_field">
|
||||
<dt>
|
||||
<i className="fa-solid fa-calendar fa-fw" />
|
||||
</dt>
|
||||
<dd>{formatForumDate(author?.joindate ?? null, locale) || '—'}</dd>
|
||||
</h3>
|
||||
<h3 className="post_field">
|
||||
<dt>
|
||||
<i className="fa-solid fa-comments fa-fw" />
|
||||
</dt>
|
||||
<dd>
|
||||
{t('posts')}: {counts.get(post.poster) ?? 0}
|
||||
</dd>
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div className="right_side">
|
||||
<div className="post_container" dangerouslySetInnerHTML={{ __html: post.text }} />
|
||||
<ul className="post_controls">
|
||||
<li className="post_date">{formatForumDate(post.time, locale)}</li>
|
||||
{canEditPost(session, isMod, post.poster) && (
|
||||
<li>
|
||||
<EditPostForm postId={post.id} initialText={post.text} />
|
||||
</li>
|
||||
)}
|
||||
{isMod && (
|
||||
<li>
|
||||
<ForumModActions kind="post" id={post.id} deleted={post.deleted} />
|
||||
</li>
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
||||
<div className="actions_c">
|
||||
<span />
|
||||
<Pagination page={page} totalPages={totalPages} hrefFor={(p) => `/forum/topic/${id}?page=${p}`} />
|
||||
</div>
|
||||
|
||||
{isMod && (
|
||||
<div className="forum-form-actions" style={{ marginBottom: 20 }}>
|
||||
<ForumModActions kind="topic" id={id} deleted={topic.deleted} locked={topic.locked} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{canReply ? (
|
||||
page === totalPages ? (
|
||||
<ReplyForm topicId={id} />
|
||||
) : (
|
||||
<p className="forum-empty">
|
||||
<a href={`/forum/topic/${id}?page=${totalPages}`}>{t('replyOnLastPage')}</a>
|
||||
</p>
|
||||
)
|
||||
) : (
|
||||
!session.username && <p className="forum-empty">{t('loginToPost')}</p>
|
||||
)}
|
||||
</div>
|
||||
</PageShell>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user