-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPost.php
More file actions
139 lines (109 loc) · 5.06 KB
/
Post.php
File metadata and controls
139 lines (109 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* Copyright (C) 2015-2019 FeatherBB
* based on code by (C) 2008-2015 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace FeatherBB\Model\Api;
use FeatherBB\Core\Database as DB;
use FeatherBB\Core\Error;
use FeatherBB\Core\Interfaces\Hooks;
use FeatherBB\Core\Interfaces\User;
use FeatherBB\Core\Interfaces\User;
use FeatherBB\Core\Utils;
class Post extends Api
{
public function display($id)
{
$post = new \FeatherBB\Model\Post();
try {
$data = $post->getInfoEdit($id);
} catch (Error $e) {
return $this->errorMessage;
}
$data = $data->asArray();
$data['moderators'] = unserialize($data['moderators']);
return $data;
}
public function getDeletePermissions($curPost, $args)
{
$modsArray = ($curPost['moderators'] != '') ? unserialize($curPost['moderators']) : [];
$isAdmmod = (User::isAdmin($this->user) || (User::isAdminMod($this->user) && array_key_exists($this->user->username, $modsArray))) ? true : false;
$isTopicPost = ($args['id'] == $curPost['first_post_id']) ? true : false;
// Do we have permission to edit this post?
if ((!User::can('post.delete', $this->user) ||
(!User::can('post.delete', $this->user) && $isTopicPost) ||
$curPost['poster_id'] != $this->user->id ||
$curPost['closed'] == '1') &&
!$isAdmmod) {
return json_encode($this->errorMessage, JSON_PRETTY_PRINT);
}
if ($isAdmmod && !User::isAdmin($this->user) && in_array($curPost['poster_id'], Utils::getAdminIds())) {
return json_encode($this->errorMessage, JSON_PRETTY_PRINT);
}
return $isTopicPost;
}
public function getEditPermissions($curPost)
{
// Sort out who the moderators are and if we are currently a moderator (or an admin)
$modsArray = ($curPost['moderators'] != '') ? unserialize($curPost['moderators']) : [];
$isAdmmod = (User::isAdmin($this->user) || (User::isAdminMod($this->user) && array_key_exists($this->user->username, $modsArray))) ? true : false;
// Do we have permission to edit this post?
if ((!User::can('post.edit', $this->user) || $curPost['poster_id'] != $this->user->id || $curPost['closed'] == '1') && !$isAdmmod) {
return json_encode($this->errorMessage, JSON_PRETTY_PRINT);
}
if ($isAdmmod && !User::isAdmin($this->user) && in_array($curPost['poster_id'], Utils::getAdminIds())) {
return json_encode($this->errorMessage, JSON_PRETTY_PRINT);
}
return $isAdmmod;
}
public function getInfoEdit($id)
{
$curPost['select'] = ['fid' => 'f.id', 'f.forum_name', 'f.moderators', 'f.redirect_url', 'fp.post_topics', 'tid' => 't.id', 't.subject', 't.posted', 't.first_post_id', 't.sticky', 't.closed', 'p.poster', 'p.poster_id', 'p.message', 'p.hide_smilies'];
$curPost['where'] = [
['fp.read_forum' => 'IS NULL'],
['fp.read_forum' => '1']
];
$curPost = DB::table('posts')
->tableAlias('p')
->selectMany($curPost['select'])
->innerJoin('topics', ['t.id', '=', 'p.topic_id'], 't')
->innerJoin('forums', ['f.id', '=', 't.forum_id'], 'f')
->leftOuterJoin('forum_perms', 'fp.forum_id=f.id AND fp.group_id='.$this->user->g_id, 'fp')
->whereAnyIs($curPost['where'])
->where('p.id', $id);
$curPost = $curPost->findOne();
if (!$curPost) {
return json_encode($this->errorMessage, JSON_PRETTY_PRINT);
}
return $curPost;
}
public function getInfoDelete($id)
{
$id = Hooks::fire('model.post.get_info_delete_start', $id);
$query['select'] = ['fid' => 'f.id', 'f.forum_name', 'f.moderators', 'f.redirect_url', 'fp.post_replies', 'fp.post_topics', 'tid' => 't.id', 't.subject', 't.first_post_id', 't.closed', 'p.poster', 'p.posted', 'p.poster_id', 'p.message', 'p.hide_smilies'];
$query['where'] = [
['fp.read_forum' => 'IS NULL'],
['fp.read_forum' => '1']
];
$query = DB::table('posts')
->tableAlias('p')
->selectMany($query['select'])
->innerJoin('topics', ['t.id', '=', 'p.topic_id'], 't')
->innerJoin('forums', ['f.id', '=', 't.forum_id'], 'f')
->leftOuterJoin('forum_perms', 'fp.forum_id=f.id AND fp.group_id='.$this->user->g_id, 'fp')
->whereAnyIs($query['where'])
->where('p.id', $id);
$query = Hooks::fireDB('model.post.get_info_delete_query', $query);
$query = $query->findOne();
if (!$query) {
return json_encode($this->errorMessage, JSON_PRETTY_PRINT);
}
return $query;
}
public function update($args, $canEditSubject, $post, $curPost, $isAdmmod)
{
\FeatherBB\Model\Post::editPost($args['id'], $canEditSubject, $post, $curPost, $isAdmmod, $this->user->username);
}
}