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,17 +1,19 @@
|
||||
import { notFound } from 'next/navigation'
|
||||
import { getTranslations, setRequestLocale } from 'next-intl/server'
|
||||
import { Link } from '@/i18n/navigation'
|
||||
import { getForum, getTopics, countTopics } from '@/lib/forum'
|
||||
import { getForum, getForumPath, countTopics, getTopics, resolvePosters } from '@/lib/forum'
|
||||
import { formatForumDate } from '@/lib/forum-format'
|
||||
import { getSession } from '@/lib/session'
|
||||
import { forumIsModerator } from '@/lib/forum-perm'
|
||||
import { PageShell } from '@/components/PageShell'
|
||||
import { NewTopicForm } from '@/components/NewTopicForm'
|
||||
import { ForumBreadcrumb } from '@/components/ForumBreadcrumb'
|
||||
import { Pagination } from '@/components/Pagination'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const PER_PAGE = 20
|
||||
const PER_PAGE = 10
|
||||
|
||||
export default async function ForumPage({
|
||||
export default async function SubforumPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: {
|
||||
@@ -23,58 +25,93 @@ export default async function ForumPage({
|
||||
const t = await getTranslations('Forum')
|
||||
|
||||
const id = Number(forumId)
|
||||
const forum = await getForum(id, locale)
|
||||
const forum = await getForum(id)
|
||||
if (!forum) notFound()
|
||||
|
||||
const session = await getSession()
|
||||
const isMod = await forumIsModerator(session)
|
||||
const canCreate = Boolean(session.username)
|
||||
|
||||
const total = await countTopics(id)
|
||||
const totalPages = Math.max(1, Math.ceil(total / PER_PAGE))
|
||||
const page = Math.min(Math.max(1, Number((await searchParams).page) || 1), totalPages)
|
||||
const topics = await getTopics(id, (page - 1) * PER_PAGE, PER_PAGE)
|
||||
const session = await getSession()
|
||||
const canPost = Boolean(session.username)
|
||||
const topics = await getTopics(id, (page - 1) * PER_PAGE, PER_PAGE, isMod)
|
||||
|
||||
const posters = await resolvePosters(
|
||||
topics.flatMap((tp) => [tp.poster, tp.last_poster].filter(Boolean) as number[]),
|
||||
)
|
||||
const name = (pid: number | null) => (pid != null ? posters.get(pid)?.name ?? `#${pid}` : '')
|
||||
|
||||
const path = await getForumPath(id)
|
||||
const hrefFor = (p: number) => `/forum/${id}?page=${p}`
|
||||
|
||||
return (
|
||||
<PageShell title={forum!.name}>
|
||||
<div className="box-content">
|
||||
<div className="body-box-content">
|
||||
<p>
|
||||
<Link href="/forum">← {t('backToForum')}</Link>
|
||||
</p>
|
||||
{forum!.description && <p className="second-brown">{forum!.description}</p>}
|
||||
<br />
|
||||
<PageShell title={forum.name}>
|
||||
<div className="main-wide">
|
||||
{path && <ForumBreadcrumb items={[{ label: t('title'), href: '/forum' }, { label: path.forum }]} />}
|
||||
<div className="forum-padding">
|
||||
<div className="forum_header">
|
||||
<div className="forum_title">
|
||||
<h1>{forum.name}</h1>
|
||||
{forum.description && <h3>{forum.description}</h3>}
|
||||
</div>
|
||||
<h4>
|
||||
<b>{total}</b> {t('topics')}
|
||||
</h4>
|
||||
</div>
|
||||
|
||||
<div className="actions_c">
|
||||
{canCreate ? (
|
||||
<Link href={`/forum/create/${id}`} className="nice_button">
|
||||
{t('createTopic')}
|
||||
</Link>
|
||||
) : (
|
||||
<span />
|
||||
)}
|
||||
<Pagination page={page} totalPages={totalPages} hrefFor={hrefFor} />
|
||||
</div>
|
||||
|
||||
{topics.length === 0 ? (
|
||||
<p className="second-brown centered">{t('noTopics')}</p>
|
||||
<h2 className="forum-empty">{t('noTopics')}</h2>
|
||||
) : (
|
||||
<table className="max-center-table">
|
||||
<tbody>
|
||||
{topics.map((topic) => (
|
||||
<tr key={topic.id} className="team-center-table-tr">
|
||||
<td className="lefted separate">
|
||||
<Link href={`/forum/topic/${topic.id}`} className="yellow-info">
|
||||
{topic.sticky && <span className="second-yellow small-font">[{t('sticky')}] </span>}
|
||||
{topic.locked && <span className="red-info2 small-font">[{t('locked')}] </span>}
|
||||
{topic.name}
|
||||
</Link>
|
||||
<p className="third-brown small-font">
|
||||
{t('by')} {topic.poster}
|
||||
</p>
|
||||
</td>
|
||||
<td className="real-info-box no-wrap-td second-brown small-font">
|
||||
{topic.views} {t('views')}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
topics.map((tp) => (
|
||||
<ul className="topic_row" key={tp.id}>
|
||||
<li className="icon">
|
||||
<img
|
||||
src={`/forum/forum_icons/topic_${tp.locked ? 'read_locked' : tp.deleted ? 'read_mine' : 'unread'}.png`}
|
||||
height={39}
|
||||
width={55}
|
||||
alt=""
|
||||
/>
|
||||
</li>
|
||||
<li className="topic_title_by_date">
|
||||
<h1>
|
||||
<Link href={`/forum/topic/${tp.id}`}>
|
||||
{tp.deleted && `[${t('deleted')}] `}
|
||||
{tp.sticky && `[${t('sticky')}] `}
|
||||
{tp.locked && `[${t('locked')}] `}
|
||||
{tp.name}
|
||||
</Link>
|
||||
</h1>
|
||||
<p>
|
||||
{t('createdBy')} <span className="username">{name(tp.poster)}</span>,{' '}
|
||||
{formatForumDate(tp.created, locale)}
|
||||
</p>
|
||||
</li>
|
||||
<li className="lastpost">
|
||||
<h4>
|
||||
{t('by')} {name(tp.last_poster)}
|
||||
</h4>
|
||||
<h5>{formatForumDate(tp.time_updated, locale)}</h5>
|
||||
</li>
|
||||
</ul>
|
||||
))
|
||||
)}
|
||||
|
||||
<Pagination page={page} totalPages={totalPages} hrefFor={(p) => `/forum/${id}?page=${p}`} />
|
||||
|
||||
{canPost ? (
|
||||
<NewTopicForm forumId={id} />
|
||||
) : (
|
||||
<p className="second-brown centered separate">{t('loginToPost')}</p>
|
||||
)}
|
||||
<div className="actions_c" style={{ marginTop: 20 }}>
|
||||
<span />
|
||||
<Pagination page={page} totalPages={totalPages} hrefFor={hrefFor} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</PageShell>
|
||||
|
||||
Reference in New Issue
Block a user