|
@@ -23,10 +23,11 @@ class Forum extends Page
|
|
*/
|
|
*/
|
|
public function view(array $args)
|
|
public function view(array $args)
|
|
{
|
|
{
|
|
- $this->c->Lang->load('index');
|
|
|
|
|
|
+ $this->c->Lang->load('forum');
|
|
$this->c->Lang->load('subforums');
|
|
$this->c->Lang->load('subforums');
|
|
|
|
|
|
list($fTree, $fDesc, $fAsc) = $this->c->forums;
|
|
list($fTree, $fDesc, $fAsc) = $this->c->forums;
|
|
|
|
+
|
|
// раздел отсутствует в доступных
|
|
// раздел отсутствует в доступных
|
|
if (empty($fDesc[$args['id']])) {
|
|
if (empty($fDesc[$args['id']])) {
|
|
return $this->c->Message->message('Bad request');
|
|
return $this->c->Message->message('Bad request');
|
|
@@ -47,14 +48,14 @@ class Forum extends Page
|
|
':gid' => $user->groupId,
|
|
':gid' => $user->groupId,
|
|
];
|
|
];
|
|
if ($user->isGuest) {
|
|
if ($user->isGuest) {
|
|
- $sql = 'SELECT f.forum_name, f.moderators, f.num_topics, f.sort_by, 0 AS is_subscribed FROM ::forums AS f WHERE f.id=?i:fid';
|
|
|
|
|
|
+ $sql = 'SELECT f.moderators, f.num_topics, f.sort_by, 0 AS is_subscribed FROM ::forums AS f WHERE f.id=?i:fid';
|
|
} else {
|
|
} else {
|
|
- $sql = 'SELECT f.forum_name, f.moderators, f.num_topics, f.sort_by, s.user_id AS is_subscribed, mof.mf_upper, mof.mf_lower FROM ::forums AS f LEFT JOIN ::forum_subscriptions AS s ON (f.id=s.forum_id AND s.user_id=?i:uid) LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:uid AND f.id=mof.fid) WHERE f.id=?i:fid';
|
|
|
|
|
|
+ $sql = 'SELECT f.moderators, f.num_topics, f.sort_by, s.user_id AS is_subscribed, mof.mf_mark_all_read FROM ::forums AS f LEFT JOIN ::forum_subscriptions AS s ON (f.id=s.forum_id AND s.user_id=?i:uid) LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:uid AND f.id=mof.fid) WHERE f.id=?i:fid';
|
|
}
|
|
}
|
|
$curForum = $this->c->DB->query($sql, $vars)->fetch();
|
|
$curForum = $this->c->DB->query($sql, $vars)->fetch();
|
|
|
|
|
|
// нет данных по данному разделу
|
|
// нет данных по данному разделу
|
|
- if (! isset($curForum['forum_name'])) {
|
|
|
|
|
|
+ if (empty($curForum)) {
|
|
return $this->c->Message->message('Bad request'); //???? может в лог ошибок?
|
|
return $this->c->Message->message('Bad request'); //???? может в лог ошибок?
|
|
}
|
|
}
|
|
|
|
|
|
@@ -64,15 +65,18 @@ class Forum extends Page
|
|
if ($page !== 1) {
|
|
if ($page !== 1) {
|
|
return $this->c->Message->message('Bad request');
|
|
return $this->c->Message->message('Bad request');
|
|
}
|
|
}
|
|
|
|
+
|
|
$pages = 1;
|
|
$pages = 1;
|
|
$offset = 0;
|
|
$offset = 0;
|
|
$topics = null;
|
|
$topics = null;
|
|
} else {
|
|
} else {
|
|
$pages = ceil($curForum['num_topics'] / $user->dispTopics);
|
|
$pages = ceil($curForum['num_topics'] / $user->dispTopics);
|
|
|
|
+
|
|
// попытка открыть страницу которой нет
|
|
// попытка открыть страницу которой нет
|
|
if ($page < 1 || $page > $pages) {
|
|
if ($page < 1 || $page > $pages) {
|
|
return $this->c->Message->message('Bad request');
|
|
return $this->c->Message->message('Bad request');
|
|
}
|
|
}
|
|
|
|
+
|
|
$offset = $user->dispTopics * ($page - 1);
|
|
$offset = $user->dispTopics * ($page - 1);
|
|
|
|
|
|
switch ($curForum['sort_by']) {
|
|
switch ($curForum['sort_by']) {
|
|
@@ -98,7 +102,6 @@ class Forum extends Page
|
|
->fetchAll(\PDO::FETCH_COLUMN);
|
|
->fetchAll(\PDO::FETCH_COLUMN);
|
|
}
|
|
}
|
|
|
|
|
|
- $dotTopics = [];
|
|
|
|
if (! empty($topics)) {
|
|
if (! empty($topics)) {
|
|
$vars = [
|
|
$vars = [
|
|
':uid' => $user->id,
|
|
':uid' => $user->id,
|
|
@@ -106,27 +109,68 @@ class Forum extends Page
|
|
];
|
|
];
|
|
|
|
|
|
if (! $user->isGuest && $this->config['o_show_dot'] == '1') {
|
|
if (! $user->isGuest && $this->config['o_show_dot'] == '1') {
|
|
- $dotTopics = $this->c->DB
|
|
|
|
- ->query('SELECT topic_id FROM ::posts WHERE topic_id IN (?ai:topics) AND poster_id=?i:uid GROUP BY topic_id', $vars)
|
|
|
|
|
|
+ $dots = $this->c->DB
|
|
|
|
+ ->query('SELECT topic_id FROM ::posts WHERE poster_id=?i:uid AND topic_id IN (?ai:topics) GROUP BY topic_id', $vars)
|
|
->fetchAll(\PDO::FETCH_COLUMN);
|
|
->fetchAll(\PDO::FETCH_COLUMN);
|
|
|
|
+ $dots = array_flip($dots);
|
|
|
|
+ } else {
|
|
|
|
+ $dots = [];
|
|
}
|
|
}
|
|
|
|
|
|
if ($user->isGuest) {
|
|
if ($user->isGuest) {
|
|
$sql = "SELECT id, poster, subject, posted, last_post, last_post_id, last_poster, num_views, num_replies, closed, sticky, moved_to, poll_type FROM ::topics WHERE id IN(?ai:topics) ORDER BY sticky DESC, {$sortBy}, id DESC";
|
|
$sql = "SELECT id, poster, subject, posted, last_post, last_post_id, last_poster, num_views, num_replies, closed, sticky, moved_to, poll_type FROM ::topics WHERE id IN(?ai:topics) ORDER BY sticky DESC, {$sortBy}, id DESC";
|
|
} else {
|
|
} else {
|
|
- $sql = "SELECT t.id, t.poster, t.subject, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to, t.poll_type, mot.mt_upper, mot.mt_lower FROM ::topics AS t LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:uid AND t.id=mot.tid) WHERE t.id IN (?ai:topics) ORDER BY t.sticky DESC, t.{$sortBy}, t.id DESC";
|
|
|
|
|
|
+ $sql = "SELECT t.id, t.poster, t.subject, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to, t.poll_type, mot.mt_last_visit, mot.mt_last_read FROM ::topics AS t LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:uid AND t.id=mot.tid) WHERE t.id IN (?ai:topics) ORDER BY t.sticky DESC, t.{$sortBy}, t.id DESC";
|
|
}
|
|
}
|
|
$topics = $this->c->DB->query($sql, $vars)->fetchAll();
|
|
$topics = $this->c->DB->query($sql, $vars)->fetchAll();
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
+ if (! $user->isGuest) {
|
|
|
|
+ $lower = max((int) $user->uMarkAllRead, (int) $curForum['mf_mark_all_read']);
|
|
|
|
+ $upper = max($lower, (int) $user->lastVisit);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ foreach ($topics as &$cur) {
|
|
|
|
+ if ($this->config['o_censoring'] == '1') {
|
|
|
|
+ $cur['subject'] = preg_replace($this->c->censoring[0], $this->c->censoring[1], $cur['subject']);
|
|
|
|
+ }
|
|
|
|
+ if (empty($cur['moved_to'])) {
|
|
|
|
+ $cur['link'] = $this->c->Router->link('Topic', ['id' => $cur['id'], 'name' => $cur['subject']]);
|
|
|
|
+ $cur['link_last'] = $this->c->Router->link('viewPost', ['id' => $cur['last_post_id']]);
|
|
|
|
+ if ($user->isGuest) {
|
|
|
|
+ $cur['link_new'] = null;
|
|
|
|
+ $cur['link_unread'] = null;
|
|
|
|
+ $cur['dot'] = false;
|
|
|
|
+ } else {
|
|
|
|
+ if ($cur['last_post'] > max($upper, $cur['mt_last_visit'])) {
|
|
|
|
+ $cur['link_new'] = $this->c->Router->link('TopicGoToNew', ['id' => $cur['id']]);
|
|
|
|
+ } else {
|
|
|
|
+ $cur['link_new'] = null;
|
|
|
|
+ }
|
|
|
|
+ if ($cur['last_post'] > max($lower, $cur['mt_last_read'])) {
|
|
|
|
+ $cur['link_unread'] = $this->c->Router->link('TopicGoToUnread', ['id' => $cur['id']]);
|
|
|
|
+ } else {
|
|
|
|
+ $cur['link_unread'] = null;
|
|
|
|
+ }
|
|
|
|
+ $cur['dot'] = isset($dots[$cur['id']]);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ $cur['link'] = $this->c->Router->link('Topic', ['id' => $cur['moved_to'], 'name' => $cur['subject']]);
|
|
|
|
+ $cur['link_last'] = null;
|
|
|
|
+ $cur['link_new'] = null;
|
|
|
|
+ $cur['link_unread'] = null;
|
|
|
|
+ $cur['dot'] = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ unset($cur);
|
|
|
|
+ }
|
|
|
|
|
|
$moders = empty($curForum['moderators']) ? [] : array_flip(unserialize($curForum['moderators']));
|
|
$moders = empty($curForum['moderators']) ? [] : array_flip(unserialize($curForum['moderators']));
|
|
|
|
+ $newOn = $perm['post_topics'] == 1
|
|
|
|
+ || (null === $perm['post_topics'] && $user->gPostTopics == 1)
|
|
|
|
+ || $user->isAdmin
|
|
|
|
+ || ($user->isAdmMod && isset($moders[$user->id]));
|
|
|
|
|
|
- $this->onlinePos = 'forum' . $args['id'];
|
|
|
|
-
|
|
|
|
- // хлебные крошки и титул
|
|
|
|
|
|
+ $this->onlinePos = 'forum-' . $args['id'];
|
|
$this->titles = [];
|
|
$this->titles = [];
|
|
$crumbs = [];
|
|
$crumbs = [];
|
|
$id = $args['id'];
|
|
$id = $args['id'];
|
|
@@ -154,10 +198,14 @@ class Forum extends Page
|
|
$this->data = [
|
|
$this->data = [
|
|
'forums' => $this->getForumsData($args['id']),
|
|
'forums' => $this->getForumsData($args['id']),
|
|
'topics' => $topics,
|
|
'topics' => $topics,
|
|
- 'dots' => array_flip($dotTopics),
|
|
|
|
'crumbs' => array_reverse($crumbs),
|
|
'crumbs' => array_reverse($crumbs),
|
|
|
|
+ 'forumName' => $fDesc[$args['id']]['forum_name'],
|
|
|
|
+ 'newTopic' => $newOn ? $this->c->Router->link('NewTopic', ['id' => $args['id']]) : null,
|
|
|
|
+ 'pages' => $this->c->Func->paginate($pages, $page, 'Forum', ['id' => $args['id'], 'name' => $fDesc[$args['id']]['forum_name']]),
|
|
];
|
|
];
|
|
-
|
|
|
|
|
|
+#echo "<pre>\n";
|
|
|
|
+#var_dump($this->data);
|
|
|
|
+#echo "</pre>\n";
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -185,7 +233,7 @@ class Forum extends Page
|
|
if ($user->isGuest) {
|
|
if ($user->isGuest) {
|
|
$stmt = $this->c->DB->query('SELECT id, forum_desc, moderators, num_topics, num_posts, last_post, last_post_id, last_poster, last_topic FROM ::forums WHERE id IN (?ai:forums)', $vars);
|
|
$stmt = $this->c->DB->query('SELECT id, forum_desc, moderators, num_topics, num_posts, last_post, last_post_id, last_poster, last_topic FROM ::forums WHERE id IN (?ai:forums)', $vars);
|
|
} else {
|
|
} else {
|
|
- $stmt = $this->c->DB->query('SELECT f.id, f.forum_desc, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster, f.last_topic, mof.mf_upper FROM ::forums AS f LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:id AND f.id=mof.fid) WHERE f.id IN (?ai:forums)', $vars);
|
|
|
|
|
|
+ $stmt = $this->c->DB->query('SELECT f.id, f.forum_desc, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster, f.last_topic, mof.mf_last_visit FROM ::forums AS f LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:id AND f.id=mof.fid) WHERE f.id IN (?ai:forums)', $vars);
|
|
}
|
|
}
|
|
$forums = [];
|
|
$forums = [];
|
|
while ($cur = $stmt->fetch()) {
|
|
while ($cur = $stmt->fetch()) {
|
|
@@ -198,7 +246,7 @@ class Forum extends Page
|
|
// предварительная проверка разделов
|
|
// предварительная проверка разделов
|
|
$max = max((int) $user->lastVisit, (int) $user->uMarkAllRead);
|
|
$max = max((int) $user->lastVisit, (int) $user->uMarkAllRead);
|
|
foreach ($forums as $id => $cur) {
|
|
foreach ($forums as $id => $cur) {
|
|
- $t = max($max, (int) $cur['mf_upper']);
|
|
|
|
|
|
+ $t = max($max, (int) $cur['mf_last_visit']);
|
|
if ($cur['last_post'] > $t) {
|
|
if ($cur['last_post'] > $t) {
|
|
$new[$id] = $t;
|
|
$new[$id] = $t;
|
|
}
|
|
}
|
|
@@ -210,7 +258,7 @@ class Forum extends Page
|
|
':forums' => $new,
|
|
':forums' => $new,
|
|
':max' => $max,
|
|
':max' => $max,
|
|
];
|
|
];
|
|
- $stmt = $this->c->DB->query('SELECT t.forum_id, t.id, t.last_post FROM ::topics AS t LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:id AND mot.tid=t.id) WHERE t.forum_id IN(?ai:forums) AND t.last_post>?i:max AND t.moved_to IS NULL AND (mot.mt_upper IS NULL OR t.last_post>mot.mt_upper)', $vars);
|
|
|
|
|
|
+ $stmt = $this->c->DB->query('SELECT t.forum_id, t.id, t.last_post FROM ::topics AS t LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:id AND mot.tid=t.id) WHERE t.forum_id IN(?ai:forums) AND t.last_post>?i:max AND t.moved_to IS NULL AND (mot.mt_last_visit IS NULL OR t.last_post>mot.mt_last_visit)', $vars);
|
|
$tmp = [];
|
|
$tmp = [];
|
|
while ($cur = $stmt->fetch()) {
|
|
while ($cur = $stmt->fetch()) {
|
|
if ($cur['last_post']>$new[$cur['forum_id']]) {
|
|
if ($cur['last_post']>$new[$cur['forum_id']]) {
|
|
@@ -294,7 +342,7 @@ class Forum extends Page
|
|
'topics' => $this->number($numT),
|
|
'topics' => $this->number($numT),
|
|
'posts' => $this->number($numP),
|
|
'posts' => $this->number($numP),
|
|
'last_post' => $this->time($time),
|
|
'last_post' => $this->time($time),
|
|
- 'last_post_id' => $postId > 0 ? $r->link('viewPost', ['id' => $postId]) : null,
|
|
|
|
|
|
+ 'last_post_id' => $postId > 0 ? $r->link('ViewPost', ['id' => $postId]) : null,
|
|
'last_poster' => $poster,
|
|
'last_poster' => $poster,
|
|
'last_topic' => $topic,
|
|
'last_topic' => $topic,
|
|
'new' => $fnew,
|
|
'new' => $fnew,
|