Skip to content

Commit 4a94547

Browse files
committed
WIP: New parser. Todo: store smilies in DB to cache them
1 parent 92559fb commit 4a94547

File tree

5 files changed

+115
-531
lines changed

5 files changed

+115
-531
lines changed

featherbb/Controller/Admin/Parser.php

Lines changed: 17 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,21 @@ public function display($req, $res, $args)
2929
{
3030
Container::get('hooks')->fire('controller.admin.parser.display');
3131

32-
// This is where the parser data lives and breathes.
33-
$cacheFile = ForumEnv::get('FEATHER_ROOT').'cache/cache_parser_data.php';
34-
35-
// If RESET button pushed, or no cache file, re-compile master bbcode source file.
36-
if (Input::post('reset') || !file_exists($cacheFile)) {
37-
require_once(ForumEnv::get('FEATHER_ROOT').'featherbb/Core/parser/bbcd_source.php');
38-
require_once(ForumEnv::get('FEATHER_ROOT').'featherbb/Core/parser/bbcd_compile.php');
39-
return Router::redirect(Router::pathFor('adminParser'), __('reset_success'));
40-
}
41-
42-
// Load the current BBCode $pd array from featherbb/Core/parser/parser_data.inc.php.
43-
require_once($cacheFile); // Fetch $pd compiled global regex data.
44-
$bbcd = $pd['bbcd']; // Local scratch copy of $bbcd.
45-
$smilies = $pd['smilies']; // Local scratch copy of $smilies.
46-
$config = $pd['config']; // Local scratch copy of $config.
47-
$count = count($bbcd);
32+
$smilies = Container::get('cache')->retrieve('smilies');
4833

4934
if (Input::post('form_sent')) {
50-
5135
// Upload new smiley image to style/img/smilies
52-
if (Input::post('upload') && isset($_fILES['new_smiley']) && isset($_fILES['new_smiley']['error'])) {
53-
$f = $_fILES['new_smiley'];
36+
if (Input::post('upload') && isset($_FILES['new_smiley']) && isset($_FILES['new_smiley']['error'])) {
37+
$f = $_FILES['new_smiley'];
5438
switch ($f['error']) {
5539
case 0: // 0: Successful upload.
56-
$name = str_replace(' ', '_', $f['name']); // Convert spaces to underscoree.
40+
$name = str_replace(' ', '_', $f['name']); // Convert spaces to underscore.
5741
$name = preg_replace('/[^\w\-.]/S', '', $name); // Weed out all unsavory filename chars.
5842
if (preg_match('/^[\w\-.]++$/', $name)) { // If we have a valid filename?
5943
if (preg_match('%^image/%', $f['type'])) { // If we have an image file type?
6044
if ($f['size'] > 0 && $f['size'] <= ForumSettings::get('o_avatars_size')) {
6145
if (move_uploaded_file($f['tmp_name'], ForumEnv::get('FEATHER_ROOT') .'style/img/smilies/'. $name)) {
62-
return Router::redirect(Router::pathFor('adminParser'), __('upload success'));
46+
return Router::redirect(Router::pathFor('adminParser'), _e('upload success'));
6347
} else { // Error #1: 'Smiley upload failed. Unable to move to smiley folder.'.
6448
throw new Error(__('upload_err_1'), 500);
6549
}
@@ -84,131 +68,37 @@ public function display($req, $res, $args)
8468
}
8569
}
8670

87-
// Set new $config values:
88-
if (Input::post('config')) {
89-
$pcfg = Input::post('config');
90-
91-
if (isset($pcfg['textile'])) {
92-
if ($pcfg['textile'] == '1') {
93-
$config['textile'] = true;
94-
} else {
95-
$config['textile'] = false;
96-
}
97-
}
98-
if (isset($pcfg['quote_links'])) {
99-
if ($pcfg['quote_links'] == '1') {
100-
$config['quote_links'] = true;
101-
} else {
102-
$config['quote_links'] = false;
103-
}
104-
}
105-
if (isset($pcfg['quote_imgs'])) {
106-
if ($pcfg['quote_imgs'] == '1') {
107-
$config['quote_imgs'] = true;
108-
} else {
109-
$config['quote_imgs'] = false;
110-
}
111-
}
112-
if (isset($pcfg['valid_imgs'])) {
113-
if ($pcfg['valid_imgs'] == '1') {
114-
$config['valid_imgs'] = true;
115-
} else {
116-
$config['valid_imgs'] = false;
117-
}
118-
}
119-
if (isset($pcfg['click_imgs'])) {
120-
if ($pcfg['click_imgs'] == '1') {
121-
$config['click_imgs'] = true;
122-
} else {
123-
$config['click_imgs'] = false;
124-
}
125-
}
126-
if (isset($pcfg['max_size']) && preg_match('/^\d++$/', $pcfg['max_size'])) {
127-
$config['max_size'] = (int)$pcfg['max_size'];
128-
}
129-
if (isset($pcfg['max_width']) && preg_match('/^\d++$/', $pcfg['max_width'])) {
130-
$config['max_width'] = (int)$pcfg['max_width']; // Limit default to maximum.
131-
if ($config['def_width'] > $config['max_width']) {
132-
$config['def_width'] = $config['max_width'];
133-
}
134-
}
135-
if (isset($pcfg['max_height']) && preg_match('/^\d++$/', $pcfg['max_height'])) {
136-
$config['max_height'] = (int)$pcfg['max_height']; // Limit default to maximum.
137-
if ($config['def_height'] > $config['max_height']) {
138-
$config['def_height'] = $config['max_height'];
139-
}
140-
}
141-
if (isset($pcfg['def_width']) && preg_match('/^\d++$/', $pcfg['def_width'])) {
142-
$config['def_width'] = (int)$pcfg['def_width']; // Limit default to maximum.
143-
if ($config['def_width'] > $config['max_width']) {
144-
$config['def_width'] = $config['max_width'];
145-
}
146-
}
147-
if (isset($pcfg['def_height']) && preg_match('/^\d++$/', $pcfg['def_height'])) {
148-
$config['def_height'] = (int)$pcfg['def_height']; // Limit default to maximum.
149-
if ($config['def_height'] > $config['max_height']) {
150-
$config['def_height'] = $config['max_height'];
151-
}
152-
}
153-
if (isset($pcfg['smiley_size']) && preg_match('/^\s*+(\d++)\s*+%?+\s*+$/', $pcfg['smiley_size'], $m)) {
154-
$config['smiley_size'] = (int)$m[1]; // Limit default to maximum.
155-
}
156-
}
157-
158-
// Set new $bbcd values:
159-
foreach ($bbcd as $tagname => $tagdata) {
160-
if ($tagname == '_ROOT_') {
161-
continue; // Skip last pseudo-tag
162-
}
163-
$tag =& $bbcd[$tagname];
164-
if (Input::post($tagname.'_in_post') && Input::post($tagname.'_in_post') == '1') {
165-
$tag['in_post'] = true;
166-
} else {
167-
$tag['in_post'] = false;
168-
}
169-
if (Input::post($tagname.'_in_sig') && Input::post($tagname.'_in_sig') == '1') {
170-
$tag['in_sig'] = true;
171-
} else {
172-
$tag['in_sig'] = false;
173-
}
174-
if (Input::post($tagname.'_depth_max') && preg_match('/^\d++$/', Input::post($tagname.'_depth_max'))) {
175-
$tag['depth_max'] = (int)Input::post($tagname.'_depth_max');
176-
}
177-
}
178-
17971
// Set new $smilies values:
18072
if (Input::post('smiley_text') && is_array(Input::post('smiley_text')) &&
18173
Input::post('smiley_file') && is_array(Input::post('smiley_file')) &&
18274
count(Input::post('smiley_text')) === count(Input::post('smiley_file'))) {
18375
$stext = Input::post('smiley_text');
18476
$sfile = Input::post('smiley_file');
185-
$len = count($stext);
186-
$good = '';
187-
$smilies = [];
77+
$len = count(Input::post('smiley_text'));
78+
$smilies = array();
18879
for ($i = 0; $i < $len; ++$i) { // Loop through all posted smileys.
189-
if ($stext[$i] && $sfile !== 'select new file') {
190-
$smilies[$stext[$i]] = ['file' => $sfile[$i]];
80+
if (isset($stext[$i]) && $stext[$i] != '' && $sfile !== 'select new file') {
81+
echo $i.'<br>';
82+
$smilies[$stext[$i]] = $sfile[$i];
19183
}
19284
}
85+
86+
Container::get('cache')->store('smilies', $smilies);
19387
}
19488

195-
require_once('featherbb/Core/parser/bbcd_compile.php'); // Compile $bbcd and save into $pd['bbcd']
196-
return Router::redirect(Router::pathFor('adminParser'), __('save_success'));
89+
return Router::redirect(Router::pathFor('adminParser'), _e('save_success'));
19790
}
19891

19992
AdminUtils::generateAdminMenu('parser');
20093

201-
return View::setPageInfo([
202-
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Parser')],
94+
return View::setPageInfo(array(
95+
'title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Parser')),
20396
'active_page' => 'admin',
20497
'admin_console' => true,
205-
'tag_summary' => $this->model->tagSummary(),
20698
'smiley_files' => $this->model->getSmileyFiles(),
207-
'bbcd' => $bbcd,
208-
'config' => $config,
20999
'smilies' => $smilies,
210-
'i' => -1,
211-
]
100+
'urlBase' => URL::base().'/style/img/smilies/',
101+
)
212102
)->addTemplate('admin/parser.php')->display();
213103
}
214104
}

featherbb/Controller/Install.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ public function loadDefaultConfig(array $data)
312312
'o_show_user_info' => 1,
313313
'o_show_post_count' => 1,
314314
'o_signatures' => 1,
315-
// 'o_smilies' => 1,
316-
// 'o_smilies_sig' => 1,
315+
'o_smilies' => 1,
316+
'o_smilies_sig' => 1,
317317
'o_make_links' => 1,
318318
// 'o_default_lang' => $data['default_lang'],
319319
// 'o_default_style' => $data['default_style'],

0 commit comments

Comments
 (0)