forked from featherbb/featherbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.php
More file actions
237 lines (210 loc) · 11.1 KB
/
Copy pathparser.php
File metadata and controls
237 lines (210 loc) · 11.1 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?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\admin;
class parser
{
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->header = new \controller\header();
$this->footer = new \controller\footer();
$this->model = new \model\admin\parser();
}
public function __autoload($class_name)
{
require FEATHER_ROOT . $class_name . '.php';
}
public function display()
{
global $lang_common, $lang_admin_parser, $lang_admin_common;
require FEATHER_ROOT.'include/common_admin.php';
if ($this->user->g_id != FEATHER_ADMIN) {
message($lang_common['No permission'], '403');
}
define('FEATHER_ADMIN_CONSOLE', 1);
// Load the admin_options.php language file
require FEATHER_ROOT.'lang/'.$admin_language.'/parser.php';
// This is where the parser data lives and breathes.
$cache_file = FEATHER_ROOT.'cache/cache_parser_data.php';
// If RESET button pushed, or no cache file, re-compile master bbcode source file.
if ($this->request->post('reset') || !file_exists($cache_file)) {
require_once(FEATHER_ROOT.'include/bbcd_source.php');
require_once(FEATHER_ROOT.'include/bbcd_compile.php');
redirect(get_link('admin/parser/'), $lang_admin_parser['reset_success']);
}
// Load the current BBCode $pd array from include/parser_data.inc.php.
require_once($cache_file); // Fetch $pd compiled global regex data.
$bbcd = $pd['bbcd']; // Local scratch copy of $bbcd.
$smilies = $pd['smilies']; // Local scratch copy of $smilies.
$config = $pd['config']; // Local scratch copy of $config.
$count = count($bbcd);
if ($this->request->post('form_sent')) {
// Upload new smiley image to img/smilies
if ($this->request->post('upload') && isset($_FILES['new_smiley']) && isset($_FILES['new_smiley']['error'])) {
$f = $_FILES['new_smiley'];
switch ($f['error']) {
case 0: // 0: Successful upload.
$name = str_replace(' ', '_', $f['name']); // Convert spaces to underscoree.
$name = preg_replace('/[^\w\-.]/S', '', $name); // Weed out all unsavory filename chars.
if (preg_match('/^[\w\-.]++$/', $name)) { // If we have a valid filename?
if (preg_match('%^image/%', $f['type'])) { // If we have an image file type?
if ($f['size'] > 0 && $f['size'] <= $this->config['o_avatars_size']) {
if (move_uploaded_file($f['tmp_name'], FEATHER_ROOT .'img/smilies/'. $name)) {
redirect(get_link('admin/parser/'), $lang_admin_parser['upload success']);
} else { // Error #1: 'Smiley upload failed. Unable to move to smiley folder.'.
message($lang_admin_parser['upload_err_1']);
}
} else { // Error #2: 'Smiley upload failed. File is too big.'
message($lang_admin_parser['upload_err_2']);
}
} else { // Error #3: 'Smiley upload failed. File type is not an image.'.
message($lang_admin_parser['upload_err_3']);
}
} else { // Error #4: 'Smiley upload failed. Bad filename.'
message($lang_admin_parser['upload_err_4']);
}
break;
case 1: // case 1 similar to case 2 so fall through...
case 2: message($lang_admin_parser['upload_err_2']); // File exceeds MAX_FILE_SIZE.
case 3: message($lang_admin_parser['upload_err_5']); // File only partially uploaded.
// case 4: break; // No error. Normal response when this form element left empty
case 4: message($lang_admin_parser['upload_err_6']); // No filename.
case 6: message($lang_admin_parser['upload_err_7']); // No temp folder.
case 7: message($lang_admin_parser['upload_err_8']); // Cannot write to disk.
default: message($lang_admin_parser['upload_err_9']); // Generic/unknown error
}
}
// Set new $config values:
if ($this->request->post('config')) {
$pcfg = $this->request->post('config');
if (isset($pcfg['textile'])) {
if ($pcfg['textile'] == '1') {
$config['textile'] = true;
} else {
$config['textile'] = false;
}
}
if (isset($pcfg['quote_links'])) {
if ($pcfg['quote_links'] == '1') {
$config['quote_links'] = true;
} else {
$config['quote_links'] = false;
}
}
if (isset($pcfg['quote_imgs'])) {
if ($pcfg['quote_imgs'] == '1') {
$config['quote_imgs'] = true;
} else {
$config['quote_imgs'] = false;
}
}
if (isset($pcfg['valid_imgs'])) {
if ($pcfg['valid_imgs'] == '1') {
$config['valid_imgs'] = true;
} else {
$config['valid_imgs'] = false;
}
}
if (isset($pcfg['click_imgs'])) {
if ($pcfg['click_imgs'] == '1') {
$config['click_imgs'] = true;
} else {
$config['click_imgs'] = false;
}
}
if (isset($pcfg['max_size']) && preg_match('/^\d++$/', $pcfg['max_size'])) {
$config['max_size'] = (int)$pcfg['max_size'];
}
if (isset($pcfg['max_width']) && preg_match('/^\d++$/', $pcfg['max_width'])) {
$config['max_width'] = (int)$pcfg['max_width']; // Limit default to maximum.
if ($config['def_width'] > $config['max_width']) {
$config['def_width'] = $config['max_width'];
}
}
if (isset($pcfg['max_height']) && preg_match('/^\d++$/', $pcfg['max_height'])) {
$config['max_height'] = (int)$pcfg['max_height']; // Limit default to maximum.
if ($config['def_height'] > $config['max_height']) {
$config['def_height'] = $config['max_height'];
}
}
if (isset($pcfg['def_width']) && preg_match('/^\d++$/', $pcfg['def_width'])) {
$config['def_width'] = (int)$pcfg['def_width']; // Limit default to maximum.
if ($config['def_width'] > $config['max_width']) {
$config['def_width'] = $config['max_width'];
}
}
if (isset($pcfg['def_height']) && preg_match('/^\d++$/', $pcfg['def_height'])) {
$config['def_height'] = (int)$pcfg['def_height']; // Limit default to maximum.
if ($config['def_height'] > $config['max_height']) {
$config['def_height'] = $config['max_height'];
}
}
if (isset($pcfg['smiley_size']) && preg_match('/^\s*+(\d++)\s*+%?+\s*+$/', $pcfg['smiley_size'], $m)) {
$config['smiley_size'] = (int)$m[1]; // Limit default to maximum.
}
}
// Set new $bbcd values:
foreach ($bbcd as $tagname => $tagdata) {
if ($tagname == '_ROOT_') {
continue; // Skip last pseudo-tag
}
$tag =& $bbcd[$tagname];
if ($this->request->post($tagname.'_in_post') && $this->request->post($tagname.'_in_post') == '1') {
$tag['in_post'] = true;
} else {
$tag['in_post'] = false;
}
if ($this->request->post($tagname.'_in_sig') && $this->request->post($tagname.'_in_sig') == '1') {
$tag['in_sig'] = true;
} else {
$tag['in_sig'] = false;
}
if ($this->request->post($tagname.'_depth_max') && preg_match('/^\d++$/', $this->request->post($tagname.'_depth_max'))) {
$tag['depth_max'] = (int)$this->request->post($tagname.'_depth_max');
}
}
// Set new $smilies values:
if ($this->request->post('smiley_text') && is_array($this->request->post('smiley_text')) &&
$this->request->post('smiley_file') && is_array($this->request->post('smiley_file')) &&
count($this->request->post('smiley_text')) === count($this->request->post('smiley_file'))) {
$stext = $this->request->post('smiley_text');
$sfile = $this->request->post('smiley_file');
$len = count($stext);
$good = '';
$smilies = array();
for ($i = 0; $i < $len; ++$i) { // Loop through all posted smileys.
if ($stext[$i] && $sfile !== 'select new file') {
$smilies[$stext[$i]] = array('file' => $sfile[$i]);
}
}
}
require_once('include/bbcd_compile.php'); // Compile $bbcd and save into $pd['bbcd']
redirect(get_link('admin/parser/'), $lang_admin_parser['save_success']);
}
$page_title = array(feather_escape($this->config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Parser']);
define('FEATHER_ACTIVE_PAGE', 'admin');
$this->header->setTitle($page_title)->display();
generate_admin_menu('parser');
$this->feather->render('admin/parser.php', array(
'lang_admin_parser' => $lang_admin_parser,
'lang_admin_common' => $lang_admin_common,
'smiley_files' => $this->model->get_smiley_files(),
'bbcd' => $bbcd,
'config' => $config,
'feather_config' => $this->config,
'smilies' => $smilies,
'i' => -1,
)
);
$this->footer->display();
}
}