diff --git a/inc/8chan-mod-pages.php b/inc/8chan-mod-pages.php index 5f0e68dc..1474cf20 100644 --- a/inc/8chan-mod-pages.php +++ b/inc/8chan-mod-pages.php @@ -132,13 +132,15 @@ $config['mod']['custom_pages']['/flags/(\%b)'] = function($b) { global $config, $mod, $board; require_once 'inc/image.php'; - if (!hasPermission($config['mod']['edit_flags'], $b)) error($config['error']['noaccess']); if (!openBoard($b)) error("Could not open board!"); + if (file_exists("$b/flags.ser")) + $config['user_flags'] = unserialize(file_get_contents("$b/flags.ser")); + $dir = 'static/custom-flags/'.$b; if (!is_dir($dir)){ @@ -146,6 +148,12 @@ } if (isset($_FILES['file'])){ + if (!isset($_POST['description']) and $_POST['description']) + error(_('You must enter a flag description!')); + + if (strlen($_POST['description']) > 255) + error(_('Flag description too long!')); + $upload = $_FILES['file']['tmp_name']; $banners = array_diff(scandir($dir), array('..', '.')); @@ -167,27 +175,50 @@ error($config['error']['invalidimg']); } - if ($size[0] != 16 or $size[1] != 11){ + if ($size[0] > 20 or $size[0] < 11 or $size[1] != 11){ error(_('Image wrong size!')); } - if (sizeof($banners) >= 100) { + if (sizeof($banners) > 256) { error(_('Too many flags.')); } copy($upload, "$dir/$id.$extension"); + $config['user_flags'][$id] = utf8tohtml($_POST['description']); + + $flags = << $d){ - if (!preg_match('/[0-9+]\.(png|jpeg|jpg|gif)/', $d)){ + if (!preg_match('/[0-9+]/', $d)){ error('Nice try.'); } - unlink("$dir/$d"); + unlink("$dir/$d.png"); + $id = explode('.', $d)[0]; + unset($config['user_flags'][$id]); + file_write($b.'/flags.ser', serialize($config['user_flags'])); } } + if (isset($_POST['alphabetize'])) { + asort($config['user_flags'], SORT_NATURAL | SORT_FLAG_CASE); + file_write($b.'/flags.ser', serialize($config['user_flags'])); + } + $banners = array_diff(scandir($dir), array('..', '.')); - mod_page(_('Edit banners'), 'mod/banners.html', array('board'=>$board,'banners'=>$banners,'token'=>make_secure_link_token('banners/'.$board['uri']))); + mod_page(_('Edit flags'), 'mod/flags.html', array('board'=>$board,'banners'=>$banners,'token'=>make_secure_link_token('banners/'.$board['uri']))); }; $config['mod']['custom_pages']['/banners/(\%b)'] = function($b) { @@ -285,6 +316,8 @@ $allow_pdf = isset($_POST['allow_pdf']) ? '$config[\'allowed_ext_files\'][] = \'pdf\';' : ''; $code_tags = isset($_POST['code_tags']) ? '$config[\'additional_javascript\'][] = \'js/code_tags/run_prettify.js\';$config[\'markup\'][] = array("/\[code\](.+?)\[\/code\]/ms", "
\$1
");' : ''; $katex = isset($_POST['katex']) ? '$config[\'katex\'] = true;$config[\'additional_javascript\'][] = \'js/katex/katex.min.js\'; $config[\'markup\'][] = array("/\[tex\](.+?)\[\/tex\]/ms", "\$1"); $config[\'additional_javascript\'][] = \'js/katex-enable.js\';' : ''; + $user_flags = isset($_POST['user_flags']) ? "if (file_exists('$b/flags.php')) { include 'flags.php'; }\n" : ''; + $oekaki_js = << +
+
+ +

{% trans %}Upload flag{% endtrans %}

+

+ +

{% trans %}Flags must be a maximum of 48KB and 16 x 11 pixels.{% endtrans %}
{% trans %}A maximum of 256 custom flags per board is enforced.{% endtrans %}

+ +

{% trans %}Important: Flags must be accompanied by a description of the flag that will be shown to the users to your board. The description must not exceed 255 characters. To use flags, you also must have "Enable user flags" enabled on your board settings page as well as having flags uploaded on this page.{% endtrans %}

+ +

+
+
+ +

{% trans %}Flags already in use{% endtrans %}

+
+ + + +{% for flag, description in config.user_flags %} + + + +{% endfor %} + +
{{description}}
+

+
+
+ + +
+