Revert "Change Page page for http headers"

This reverts commit 16220a9291.
This commit is contained in:
Visman 2020-08-23 22:43:01 +07:00
parent 16220a9291
commit 1efacf8a25
15 changed files with 24 additions and 356 deletions

View file

@ -362,13 +362,6 @@ class Routing
'SendEmail'
);
}
// feed
$r->add(
$r::GET,
'/feed/{type:atom|rss}[/forum/{fid:[1-9]\d*}][/topic/{tid:[1-9]\d*}]',
'Feed:view',
'Feed'
);
}
// админ и модератор

View file

@ -15,12 +15,6 @@ abstract class Page extends Model
*/
protected $pageHeaders = [];
/**
* Http заголовки
* @var array
*/
protected $httpHeaders = [];
/**
* Конструктор
*
@ -44,7 +38,7 @@ abstract class Page extends Model
$this->fIndex = 'index'; # string Указатель на активный пункт навигации
$this->httpStatus = 200; # int HTTP статус ответа для данной страницы
# $this->httpHeaders = []; # array HTTP заголовки отличные от статуса
$this->httpHeaders = []; # array HTTP заголовки отличные от статуса
# $this->nameTpl = null; # null|string Имя шаблона
# $this->titles = []; # array Массив титула страницы | setTitles()
$this->fIswev = []; # array Массив info, success, warning, error, validation информации
@ -67,15 +61,6 @@ abstract class Page extends Model
'type' => 'text/css',
'href' => $this->c->PUBLIC_URL . '/style/' . $this->user->style . '/style.css',
]);
$now = \gmdate('D, d M Y H:i:s') . ' GMT';
$this->header('Cache-Control', 'no-cache, no-store, must-revalidate')
// ->header('Cache-Control', 'private, no-cache')
->header('Content-type', 'text/html; charset=utf-8')
->header('Date', $now)
->header('Last-Modified', $now)
->header('Expires', $now);
}
/**
@ -359,7 +344,9 @@ abstract class Page extends Model
} else {
$key .= ':';
}
$this->httpHeaders[] = ["{$key} {$value}", $replace];
$attr = $this->getAttr('httpHeaders', []);
$attr[] = ["{$key} {$value}", $replace];
$this->setAttr('httpHeaders', $attr);
return $this;
}
@ -372,9 +359,17 @@ abstract class Page extends Model
*/
protected function gethttpHeaders(): array
{
$this->httpStatus();
$now = \gmdate('D, d M Y H:i:s') . ' GMT';
return $this->httpHeaders;
$this->httpStatus()
->header('Cache-Control', 'no-cache, no-store, must-revalidate')
// ->header('Cache-Control', 'private, no-cache')
->header('Content-type', 'text/html; charset=utf-8')
->header('Date', $now)
->header('Last-Modified', $now)
->header('Expires', $now);
return $this->getAttr('httpHeaders', []);
}
/**

View file

@ -565,26 +565,4 @@ class Update extends Admin
return null;
}
/**
* rev.8 to rev.9
*/
protected function stageNumber8(array $args): ?int
{
$coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
$coreConfig->add(
'multiple=>Feed',
'\\ForkBB\\Models\\Pages\\Feed::class',
'Email'
);
$coreConfig->add(
'multiple=>PostManagerFeed',
'\\ForkBB\\Models\\Post\\Feed::class',
'PostManagerMove'
);
$coreConfig->save();
return null;
}
}

View file

@ -1,156 +0,0 @@
<?php
namespace ForkBB\Models\Pages;
use ForkBB\Models\Page;
use ForkBB\Models\Forum\Model as Forum;
use ForkBB\Models\Topic\Model as Topic;
use ForkBB\Models\User\Model as User;
use function \ForkBB\__;
class Feed extends Page
{
protected function exit(string $message): Page
{
return $this;
}
/**
* Подготовка данных для шаблона
*
* @param array $args
* @param string $method
*
* @return Page
*/
public function view(array $args, string $method): Page
{
$this->c->DEBUG = 0;
if ('0' == $this->c->config->o_feed_type) {
return $this->exit('Bad request');
}
$fid = (int) ($args['fid'] ?? 0);
$tid = (int) ($args['tid'] ?? 0);
if ($fid > 0 && $tid > 0) {
return $this->exit('Bad request');
}
if ($tid) {
$topic = $this->c->topics->load($tid);
if (! $topic instanceof Topic) {
return $this->exit('Bad request');
}
$feed = [
'id' => $this->c->Router->link('Feed', $args),
'title' => $this->c->config->o_board_title . __('Title separator') . $topic->subject,
'link' => $topic->link,
'description' => __('The most recent posts in %s topic', $topic->subject),
'updated' => $topic->last_post,
'items' => [],
];
$items = $this->c->posts->feed($topic);
if (! empty($items)) {
$uids = [];
foreach ($items as $cur) {
$uids[$cur['uid']] = $cur['uid'];
}
unset($uids[1]);
$this->c->users->loadByIds($uids);
foreach ($items as $cur) {
$user = $this->c->users->get($cur['uid']);
$email = $user instanceof User && 0 === $user->email_setting ? $user->email : null;
$item = [
'id' => $this->c->Router->link('ViewPost', ['id' => $cur['pid']]),
'title' => $topic->subject,
'updated' => $cur['edited'] > $cur['posted'] ? $cur['edited'] : $cur['posted'],
'link' => $this->c->Router->link('ViewPost', ['id' => $cur['pid']]),
'author' => $cur['username'],
'email' => $email ?? 'dummy@example.com',
'isEmail' => null !== $email,
'content' => $this->c->Parser->parseMessage($cur['content'], (bool) $cur['hide_smilies']),
'published' => $cur['posted'],
];
$feed['items'][] = $item;
}
}
} else {
$forum = $this->c->forums->loadTree($fid);
if (! $forum instanceof Forum) {
return $this->exit('Bad request');
}
$feed = [
'id' => $this->c->Router->link('Feed', $args),
'title' => $this->c->config->o_board_title,
'link' => $forum->link,
'updated' => $forum->tree->last_post,
'items' => [],
];
if (0 === $fid) {
$feed['description'] = __('The most recent posts at %s board', $this->c->config->o_board_title);
} else {
$feed['description'] = __('The most recent posts in %s forum', $forum->forum_name);
$feed['title'] .= __('Title separator') . $forum->forum_name;
}
$items = $this->c->posts->feed($forum);
if (! empty($items)) {
$uids = [];
foreach ($items as $cur) {
$uids[$cur['uid']] = $cur['uid'];
}
unset($uids[1]);
$this->c->users->loadByIds($uids);
foreach ($items as $cur) {
$user = $this->c->users->get($cur['uid']);
$email = $user instanceof User && 0 === $user->email_setting ? $user->email : null;
$fName = $this->c->forums->get($cur['fid'])->forum_name;
$item = [
'id' => $this->c->Router->link('ViewPost', ['id' => $cur['pid']]),
'title' => $fName . __('Title separator') . $cur['topic_name'],
'updated' => $cur['edited'] > $cur['posted'] ? $cur['edited'] : $cur['posted'],
'link' => $this->c->Router->link('ViewPost', ['id' => $cur['pid']]),
'author' => $cur['username'],
'email' => $email ?? 'dummy@example.com',
'isEmail' => null !== $email,
'content' => $this->c->Parser->parseMessage($cur['content'], (bool) $cur['hide_smilies']),
'published' => $cur['posted'],
];
$feed['items'][] = $item;
}
}
}
$this->nameTpl = "feed_{$args['type']}";
$this->onlinePos = 'feed';
$this->onlineDetail = false;
$this->onlineFilter = false;
$this->feed = $feed;
$this->header('Content-type', "application/{$args['type']}+xml; charset=utf-8");
return $this;
}
/**
* Экранирует в соответствии с XML 1.
*/
public function e(string $text): string
{
return \htmlspecialchars($text, \ENT_XML1 , 'UTF-8');
}
}

View file

@ -62,15 +62,6 @@ class Forum extends Page
$this->formMod = $this->formMod($forum);
}
if ($this->c->config->o_feed_type > 0) {
$feedType = '2' == $this->c->config->o_feed_type ? 'atom' : 'rss';
$this->pageHeader('feed', 'link', [
'rel' => 'alternate',
'type' => "application/{$feedType}+xml",
'href' => $this->c->Router->link('Feed', ['type' => $feedType, 'fid' => $forum->id]),
]);
}
return $this;
}

View file

@ -66,15 +66,6 @@ class Index extends Page
);
}
if ($this->c->config->o_feed_type > 0) {
$feedType = '2' == $this->c->config->o_feed_type ? 'atom' : 'rss';
$this->pageHeader('feed', 'link', [
'rel' => 'alternate',
'type' => "application/{$feedType}+xml",
'href' => $this->c->Router->link('Feed', ['type' => $feedType]),
]);
}
return $this;
}
}

View file

@ -184,15 +184,6 @@ class Topic extends Page
}
$topic->updateVisits();
if ($this->c->config->o_feed_type > 0) {
$feedType = '2' == $this->c->config->o_feed_type ? 'atom' : 'rss';
$this->pageHeader('feed', 'link', [
'rel' => 'alternate',
'type' => "application/{$feedType}+xml",
'href' => $this->c->Router->link('Feed', ['type' => $feedType, 'tid' => $topic->id]),
]);
}
return $this;
}

View file

@ -1,61 +0,0 @@
<?php
namespace ForkBB\Models\Post;
use ForkBB\Models\Action;
use ForkBB\Models\DataModel;
use ForkBB\Models\Topic\Model as Topic;
use ForkBB\Models\Forum\Model as Forum;
use InvalidArgumentException;
use RuntimeException;
class Feed extends Action
{
/**
* Загружает данные для feed
*
* @throws InvalidArgumentException
*/
public function Feed(DataModel $model): array
{
if ($model instanceof Topic) {
if (0 !== $model->moved_to) {
return [];
}
$vars = [
':id' => $model->id,
];
$query = 'SELECT p.id as pid, p.poster as username, p.poster_id as uid, p.message as content,
p.hide_smilies, p.posted, p.edited
FROM ::posts AS p
WHERE p.topic_id=?i:id
ORDER BY p.id DESC
LIMIT 50';
} else if ($model instanceof Forum) {
$ids = \array_keys($model->descendants);
if (empty($ids)) {
return [];
}
$vars = [
':forums' => $ids,
];
$query = 'SELECT p.id as pid, p.poster as username, p.poster_id as uid, p.message as content,
p.hide_smilies, p.posted, p.edited, t.id as tid, t.subject as topic_name, t.forum_id as fid
FROM ::posts AS p
INNER JOIN ::topics AS t ON t.id=p.topic_id
WHERE t.forum_id IN(?ai:forums)
ORDER BY p.id DESC
LIMIT 50';
} else {
throw new InvalidArgumentException('Expected Topic or Forum');
}
return $this->c->DB->query($query, $vars)->fetchAll();
}
}

View file

@ -42,7 +42,7 @@ if (
}
$c->PUBLIC_URL = $c->BASE_URL . $forkPublicPrefix;
$c->FORK_REVISION = 9;
$c->FORK_REVISION = 8;
$c->START = $forkStart;
$c->DIR_APP = __DIR__;
$c->DIR_PUBLIC = $forkPublic;

View file

@ -163,7 +163,6 @@ return [
'Moderate' => \ForkBB\Models\Pages\Moderate::class,
'Report' => \ForkBB\Models\Pages\Report::class,
'Email' => \ForkBB\Models\Pages\Email::class,
'Feed' => \ForkBB\Models\Pages\Feed::class,
'ProfileView' => \ForkBB\Models\Pages\Profile\View::class,
'ProfileEdit' => \ForkBB\Models\Pages\Profile\Edit::class,
'ProfileConfig' => \ForkBB\Models\Pages\Profile\Config::class,
@ -267,7 +266,6 @@ return [
'PostManagerUserInfoFromIP' => \ForkBB\Models\Post\UserInfoFromIP::class,
'PostManagerUserStat' => \ForkBB\Models\Post\UserStat::class,
'PostManagerMove' => \ForkBB\Models\Post\Move::class,
'PostManagerFeed' => \ForkBB\Models\Post\Feed::class,
'ReportModel' => \ForkBB\Models\Report\Model::class,
'ReportManagerSave' => \ForkBB\Models\Report\Save::class,

View file

@ -425,14 +425,11 @@ msgstr "Query"
msgid "Total query time"
msgstr "Total query time: %s"
msgid "The most recent posts at %s board"
msgstr "The most recent posts at \"%s\" board."
msgid "RSS description"
msgstr "The most recent topics at %s."
msgid "The most recent posts in %s forum"
msgstr "The most recent posts in \"%s\" forum."
msgid "The most recent posts in %s topic"
msgstr "The most recent posts in \"%s\" topic."
msgid "RSS description topic"
msgstr "The most recent posts in %s."
msgid "RSS reply"
msgstr "Re: "

View file

@ -427,14 +427,11 @@ msgstr "Запрос"
msgid "Total query time"
msgstr "Итого: %s"
msgid "The most recent posts at %s board"
msgstr "Самые свежие сообщения на форуме \"%s\"."
msgid "RSS description"
msgstr "Самые свежие темы на %s."
msgid "The most recent posts in %s forum"
msgstr "Самые свежие сообщения в разделе \"%s\"."
msgid "The most recent posts in %s topic"
msgstr "Самые свежие сообщения в теме \"%s\"."
msgid "RSS description topic"
msgstr "Самые свежие сообщения в %s."
msgid "RSS reply"
msgstr "Re: "

View file

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">{!! $p->e($p->feed['title']) !!}</title>
<link rel="self" type="application/atom+xml" href="{!! $p->feed['id'] !!}" />
<link rel="alternate" type="text/html" href="{!! $p->feed['link'] !!}" />
<updated>{!! $p->e(\gmdate('c', $p->feed['updated'])) !!}</updated>
<generator>ForkBB</generator>
<id>{!! $p->e($p->feed['id']) !!}</id>
@foreach($p->feed['items'] as $item)
<entry>
<title>{!! $p->e($item['title']) !!}</title>
<link rel="alternate" type="text/html" href="{!! $item['link'] !!}" />
<id>{!! $p->e($item['id']) !!}</id>
<updated>{!! $p->e(\gmdate('c', $item['updated'])) !!}</updated>
<published>{!! $p->e(\gmdate('c', $item['published'])) !!}</published>
<author>
<name>{!! $p->e($item['author']) !!}</name>
@if ($item['isEmail'])
<email>{!! $p->e($item['email']) !!}</email>
@endif
</author>
<content type="html">{!! $p->e($item['content']) !!}</content>
</entry>
@endforeach
</feed>

View file

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="{!! $p->feed['id'] !!}" rel="self" type="application/rss+xml" />
<title>{!! $p->e($p->feed['title']) !!}</title>
<link>{!! $p->e($p->feed['link']) !!}</link>
<description>{!! $p->e($p->feed['description']) !!}</description>
<pubDate>{!! $p->e(\gmdate('r', $p->feed['updated'])) !!}</pubDate>
<generator>ForkBB</generator>
@foreach($p->feed['items'] as $item)
<item>
<title>{!! $p->e($item['title']) !!}</title>
<link>{!! $p->e($item['link']) !!}</link>
<description>{!! $p->e($item['content']) !!}</description>
<author>{!! $p->e($item['email']) !!} ({!! $p->e($item['author']) !!})</author>
<guid>{!! $p->e($item['id']) !!}</guid>
<pubDate>{!! $p->e(\gmdate('r', $item['published'])) !!}</pubDate>
</item>
@endforeach
</channel>
</rss>

View file

@ -1,4 +1,4 @@
# ForkBB rev 9 Pre-Alpha Readme
# ForkBB rev 8 Pre-Alpha Readme
## About