diff --git a/inc/8chan-mod-pages.php b/inc/8chan-mod-pages.php index e6315ed5..2b09d098 100644 --- a/inc/8chan-mod-pages.php +++ b/inc/8chan-mod-pages.php @@ -247,22 +247,30 @@ if (!is_dir($dir)){ mkdir($dir, 0777, true); } - - if (isset($_FILES['file'])){ - if (!isset($_POST['description']) and $_POST['description']) + + function handle_file($id = false, $description, $b, $dir) { + global $config; + + if (!isset($description) and $description) error(_('You must enter a flag description!')); - if (strlen($_POST['description']) > 255) + if (strlen($description) > 255) error(_('Flag description too long!')); - $upload = $_FILES['file']['tmp_name']; + if ($id) { + $f = 'flag-'.$id; + } else { + $f = 'file'; + $id = time() . substr(microtime(), 2, 3); + } + + $upload = $_FILES[$f]['tmp_name']; $banners = array_diff(scandir($dir), array('..', '.')); if (!is_readable($upload)) error($config['error']['nomove']); - $id = time() . substr(microtime(), 2, 3); - $extension = strtolower(mb_substr($_FILES['file']['name'], mb_strrpos($_FILES['file']['name'], '.') + 1)); + $extension = strtolower(mb_substr($_FILES[$f]['name'], mb_strrpos($_FILES[$f]['name'], '.') + 1)); if ($extension != 'png') { error(_('Flags must be in PNG format.')); @@ -284,8 +292,45 @@ } copy($upload, "$dir/$id.$extension"); - $config['user_flags'][$id] = utf8tohtml($_POST['description']); + purge("$dir/$id.$extension"); + $config['user_flags'][$id] = utf8tohtml($description); + file_write($b.'/flags.ser', serialize($config['user_flags'])); + } + + // Handle a new flag, if any. + if (isset($_FILES['file'])){ + handle_file(false, $_POST['description'], $b, $dir); + } + // Handle edits to existing flags. + foreach ($_FILES as $k => $a) { + if (empty($_FILES[$k]['tmp_name'])) continue; + + if (preg_match('/^flag-(\d+)$/', $k, $matches)) { + $id = (int)$matches[1]; + if (!isset($_POST['description-'.$id])) continue; + + if (isset($config['user_flags'][$id])) { + handle_file($id, $_POST['description-'.$id], $b, $dir); + } + } + } + + // Description just changed, flag not edited. + foreach ($_POST as $k => $v) { + if (!preg_match('/^description-(\d+)$/', $k, $matches)) continue; + $id = (int)$matches[1]; + if (!isset($_POST['description-'.$id])) continue; + + $description = $_POST['description-'.$id]; + + if (strlen($description) > 255) + error(_('Flag description too long!')); + $config['user_flags'][$id] = utf8tohtml($description); + file_write($b.'/flags.ser', serialize($config['user_flags'])); + } + + if ($_SERVER['REQUEST_METHOD'] === 'POST') { $flags = << $d){ if (!preg_match('/[0-9+]/', $d)){ diff --git a/inc/functions.php b/inc/functions.php index d7a11b26..8674ecd0 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -504,6 +504,8 @@ function boardTitle($uri) { function purge($uri) { global $config, $debug; + if (!isset($config['purge'])) return; + // Fix for Unicode $uri = rawurlencode($uri); diff --git a/templates/mod/flags.html b/templates/mod/flags.html index d78f8e21..b804e51b 100644 --- a/templates/mod/flags.html +++ b/templates/mod/flags.html @@ -14,18 +14,19 @@

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

-
+ + {% for flag, description in config.user_flags %} - + {% endfor %}
D{% trans %}Flag image{% endtrans %}{% trans %}Flag description{% endtrans %}
{{description}}
-

+

diff --git a/templates/mod/settings.html b/templates/mod/settings.html index f7be4866..660bb684 100644 --- a/templates/mod/settings.html +++ b/templates/mod/settings.html @@ -1,5 +1,5 @@ - +

{% trans %}Tip: Some changes made on this page won't take effect until a new post is made on your board.{% endtrans %}