forked from featherbb/featherbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.php
More file actions
124 lines (105 loc) · 5.13 KB
/
Copy pathedit.php
File metadata and controls
124 lines (105 loc) · 5.13 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
<?php
/**
* Copyright (C) 2015 FeatherBB
* based on code by (C) 2008-2012 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace controller;
class edit
{
public function __construct()
{
$this->feather = \Slim\Slim::getInstance();
$this->start = $this->feather->start;
$this->config = $this->feather->config;
$this->user = $this->feather->user;
$this->request = $this->feather->request;
$this->model = new \model\edit();
load_textdomain('featherbb', FEATHER_ROOT.'lang/'.$this->user->language.'/register.mo');
load_textdomain('featherbb', FEATHER_ROOT.'lang/'.$this->user->language.'/prof_reg.mo');
load_textdomain('featherbb', FEATHER_ROOT.'lang/'.$this->user->language.'/post.mo');
load_textdomain('featherbb', FEATHER_ROOT.'lang/'.$this->user->language.'/bbeditor.mo');
}
public function __autoload($class_name)
{
require FEATHER_ROOT . $class_name . '.php';
}
public function editpost($id)
{
if ($this->user->g_read_board == '0') {
throw new \FeatherBB\Error(__('No view'), 403);
}
// Fetch some informations about the post, the topic and the forum
$cur_post = $this->model->get_info_edit($id);
// Sort out who the moderators are and if we are currently a moderator (or an admin)
$mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
$is_admmod = ($this->user->g_id == FEATHER_ADMIN || ($this->user->g_moderator == '1' && array_key_exists($this->user->username, $mods_array))) ? true : false;
$can_edit_subject = $id == $cur_post['first_post_id'];
if ($this->config['o_censoring'] == '1') {
$cur_post['subject'] = censor_words($cur_post['subject']);
$cur_post['message'] = censor_words($cur_post['message']);
}
// Do we have permission to edit this post?
if (($this->user->g_edit_posts == '0' || $cur_post['poster_id'] != $this->user->id || $cur_post['closed'] == '1') && !$is_admmod) {
throw new \FeatherBB\Error(__('No permission'), 403);
}
if ($is_admmod && $this->user->g_id != FEATHER_ADMIN && in_array($cur_post['poster_id'], get_admin_ids())) {
throw new \FeatherBB\Error(__('No permission'), 403);
}
// Start with a clean slate
$errors = array();
if ($this->feather->request()->isPost()) {
// Let's see if everything went right
$errors = $this->model->check_errors_before_edit($can_edit_subject, $errors);
// Setup some variables before post
$post = $this->model->setup_variables($cur_post, $is_admmod, $can_edit_subject, $errors);
// Did everything go according to plan?
if (empty($errors) && !$this->request->post('preview')) {
// Edit the post
$this->model->edit_post($id, $can_edit_subject, $post, $cur_post, $is_admmod);
redirect($this->feather->url->get('post/'.$id.'/#p'.$id), __('Post redirect'));
}
} else {
$post = '';
}
if ($this->request->post('preview')) {
require_once FEATHER_ROOT.'include/parser.php';
$preview_message = parse_message($post['message'], $post['hide_smilies']);
} else {
$preview_message = '';
}
$lang_bbeditor = array(
'btnBold' => __('btnBold'),
'btnItalic' => __('btnItalic'),
'btnUnderline' => __('btnUnderline'),
'btnColor' => __('btnColor'),
'btnLeft' => __('btnLeft'),
'btnRight' => __('btnRight'),
'btnJustify' => __('btnJustify'),
'btnCenter' => __('btnCenter'),
'btnLink' => __('btnLink'),
'btnPicture' => __('btnPicture'),
'btnList' => __('btnList'),
'btnQuote' => __('btnQuote'),
'btnCode' => __('btnCode'),
'promptImage' => __('promptImage'),
'promptUrl' => __('promptUrl'),
'promptQuote' => __('promptQuote')
);
$this->feather->view2->setPageInfo(array(
'title' => array($this->feather->utils->escape($this->config['o_board_title']), __('Edit post')),
'required_fields' => array('req_subject' => __('Subject'), 'req_message' => __('Message')),
'focus_element' => array('edit', 'req_message'),
'cur_post' => $cur_post,
'errors' => $errors,
'preview_message' => $preview_message,
'id' => $id,
'checkboxes' => $this->model->get_checkboxes($can_edit_subject, $is_admmod, $cur_post, 1),
'can_edit_subject' => $can_edit_subject,
'lang_bbeditor' => $lang_bbeditor,
'post' => $post,
)
)->addTemplate('edit.php')->display();
}
}