|
@@ -100,110 +100,76 @@ class Edit extends Page
|
|
|
*/
|
|
|
protected function endEdit(Post $post, Validator $v)
|
|
|
{
|
|
|
- $now = time();
|
|
|
- $user = $this->c->user;
|
|
|
- $username = $user->isGuest ? $v->username : $user->username;
|
|
|
- $merge = false;
|
|
|
- $executive = $user->isAdmin || $user->isModerator($model);
|
|
|
-
|
|
|
- // подготовка к объединению/сохранению сообщения
|
|
|
- if (null === $v->subject) {
|
|
|
- $createTopic = false;
|
|
|
- $forum = $model->parent;
|
|
|
- $topic = $model;
|
|
|
-
|
|
|
- if (! $user->isGuest && $topic->last_poster === $username) {
|
|
|
- if ($executive) {
|
|
|
- if ($v->merge_post) {
|
|
|
- $merge = true;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if ($this->c->config->o_merge_timeout > 0 // ???? стоит завязать на время редактирование сообщений?
|
|
|
- && $now - $topic->last_post < $this->c->config->o_merge_timeout
|
|
|
- ) {
|
|
|
- $merge = true;
|
|
|
- }
|
|
|
- }
|
|
|
+ $now = time();
|
|
|
+ $user = $this->c->user;
|
|
|
+ $executive = $user->isAdmin || $user->isModerator($post);
|
|
|
+ $topic = $post->parent;
|
|
|
+ $editSubject = $post->id === $topic->first_post_id;
|
|
|
+ $calcPost = false;
|
|
|
+ $calcTopic = false;
|
|
|
+ $calcForum = false;
|
|
|
+
|
|
|
+ // текст сообщения
|
|
|
+ if ($post->message !== $v->message) {
|
|
|
+ $post->message = $v->message;
|
|
|
+ $post->edited = $now;
|
|
|
+ $post->edited_by = $user->username;
|
|
|
+ $calcPost = true;
|
|
|
+ if ($post->id === $topic->last_post_id) {
|
|
|
+ $calcTopic = true;
|
|
|
+ $calcForum = true;
|
|
|
}
|
|
|
- // создание темы
|
|
|
- } else {
|
|
|
- $createTopic = true;
|
|
|
- $forum = $model;
|
|
|
- $topic = $this->c->ModelTopic;
|
|
|
-
|
|
|
- $topic->subject = $v->subject;
|
|
|
- $topic->poster = $username;
|
|
|
- $topic->last_poster = $username;
|
|
|
- $topic->posted = $now;
|
|
|
- $topic->last_post = $now;
|
|
|
- $topic->sticky = $v->stick_topic ? 1 : 0;
|
|
|
- $topic->stick_fp = $v->stick_fp ? 1 : 0;
|
|
|
-# $topic->poll_type = ;
|
|
|
-# $topic->poll_time = ;
|
|
|
-# $topic->poll_term = ;
|
|
|
-# $topic->poll_kol = ;
|
|
|
-
|
|
|
- $topic->insert();
|
|
|
}
|
|
|
-
|
|
|
- // попытка объеденить новое сообщение с крайним в теме
|
|
|
- if ($merge) {
|
|
|
- $lastPost = $this->c->ModelPost->load($topic->last_post_id);
|
|
|
- $newLength = mb_strlen($lastPost->message . $v->message, 'UTF-8');
|
|
|
-
|
|
|
- if ($newLength < $this->c->MAX_POST_SIZE - 100) {
|
|
|
- $lastPost->message = $lastPost->message . "\n[after=" . ($now - $topic->last_post) . "]\n" . $v->message; //????
|
|
|
- $lastPost->edited = $now;
|
|
|
- $lastPost->edited_by = $username;
|
|
|
-
|
|
|
- $lastPost->update();
|
|
|
- } else {
|
|
|
- $merge = false;
|
|
|
- }
|
|
|
+ // показ смайлов
|
|
|
+ if ($this->c->config->o_smilies == '1' && (bool) $post->hide_smilies !== (bool) $v->hide_smilies ) {
|
|
|
+ $post->hide_smilies = $v->hide_smilies ? 1 : 0;
|
|
|
}
|
|
|
-
|
|
|
- // создание нового сообщения
|
|
|
- if (! $merge) {
|
|
|
- $post = $this->c->ModelPost;
|
|
|
-
|
|
|
- $post->poster = $username;
|
|
|
- $post->poster_id = $this->c->user->id;
|
|
|
- $post->poster_ip = $this->c->user->ip;
|
|
|
- $post->poster_email = $v->email;
|
|
|
- $post->message = $v->message; //?????
|
|
|
- $post->hide_smilies = $v->hide_smilies ? 1 : 0;
|
|
|
-# $post->edit_post =
|
|
|
- $post->posted = $now;
|
|
|
-# $post->edited =
|
|
|
-# $post->edited_by =
|
|
|
- $post->user_agent = $this->c->user->userAgent;
|
|
|
- $post->topic_id = $topic->id;
|
|
|
-
|
|
|
- $post->insert();
|
|
|
+ // редактирование без ограничений
|
|
|
+ if ($executive && (bool) $post->edit_post !== (bool) $v->edit_post) {
|
|
|
+ $post->edit_post = $v->edit_post ? 1 : 0;
|
|
|
}
|
|
|
|
|
|
- if ($createTopic) {
|
|
|
- $topic->forum_id = $forum->id;
|
|
|
- $topic->first_post_id = $post->id;
|
|
|
+ if ($editSubject) {
|
|
|
+ // заголовок темы
|
|
|
+ if ($topic->subject !== $v->subject) {
|
|
|
+ $topic->subject = $v->subject;
|
|
|
+ $post->edited = $now;
|
|
|
+ $post->edited_by = $user->username;
|
|
|
+ $calcForum = true;
|
|
|
+ }
|
|
|
+ // выделение темы
|
|
|
+ if ($executive && (bool) $topic->sticky !== (bool) $v->stick_topic) {
|
|
|
+ $topic->sticky = $v->stick_topic ? 1 : 0;
|
|
|
+ }
|
|
|
+ // закрепление первого сообшения
|
|
|
+ if ($executive && (bool) $topic->stick_fp !== (bool) $v->stick_fp) {
|
|
|
+ $topic->stick_fp = $v->stick_fp ? 1 : 0;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // обновление данных в теме и разделе
|
|
|
- $topic->calcStat()->update();
|
|
|
- $forum->calcStat()->update();
|
|
|
+ // обновление сообщения
|
|
|
+ $post->update();
|
|
|
|
|
|
- // обновление данных текущего пользователя
|
|
|
- if (! $merge && ! $user->isGuest && $forum->no_sum_mess != '1') {
|
|
|
- $user->num_posts = $user->num_posts + 1;
|
|
|
+ // обновление темы
|
|
|
+ if ($calcTopic) {
|
|
|
+ $topic->calcStat();
|
|
|
+ }
|
|
|
+ $topic->update();
|
|
|
|
|
|
- if ($user->g_promote_next_group != '0' && $user->num_posts >= $user->g_promote_min_posts) {
|
|
|
- $user->group_id = $user->g_promote_next_group;
|
|
|
- }
|
|
|
+ // обновление раздела
|
|
|
+ if ($calcForum) {
|
|
|
+ $topic->parent->calcStat();
|
|
|
+ }
|
|
|
+ $topic->parent->update();
|
|
|
+
|
|
|
+ // антифлуд
|
|
|
+ if ($calcPost || $calcForum) {
|
|
|
+ $user->last_post = $now; //????
|
|
|
+ $user->update();
|
|
|
}
|
|
|
- $user->last_post = $now;
|
|
|
- $user->update();
|
|
|
|
|
|
return $this->c->Redirect
|
|
|
- ->page('ViewPost', ['id' => $merge ? $lastPost->id : $post->id])
|
|
|
- ->message(\ForkBB\__('Post redirect'));
|
|
|
+ ->page('ViewPost', ['id' => $post->id])
|
|
|
+ ->message(\ForkBB\__('Edit redirect'));
|
|
|
}
|
|
|
}
|