mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-28 17:31:00 +01:00
Make it so you can change names/file of user flags
This commit is contained in:
parent
31d160d25b
commit
6da9f7ad93
@ -248,21 +248,29 @@
|
|||||||
mkdir($dir, 0777, true);
|
mkdir($dir, 0777, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_FILES['file'])){
|
function handle_file($id = false, $description, $b, $dir) {
|
||||||
if (!isset($_POST['description']) and $_POST['description'])
|
global $config;
|
||||||
|
|
||||||
|
if (!isset($description) and $description)
|
||||||
error(_('You must enter a flag description!'));
|
error(_('You must enter a flag description!'));
|
||||||
|
|
||||||
if (strlen($_POST['description']) > 255)
|
if (strlen($description) > 255)
|
||||||
error(_('Flag description too long!'));
|
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('..', '.'));
|
$banners = array_diff(scandir($dir), array('..', '.'));
|
||||||
|
|
||||||
if (!is_readable($upload))
|
if (!is_readable($upload))
|
||||||
error($config['error']['nomove']);
|
error($config['error']['nomove']);
|
||||||
|
|
||||||
$id = time() . substr(microtime(), 2, 3);
|
$extension = strtolower(mb_substr($_FILES[$f]['name'], mb_strrpos($_FILES[$f]['name'], '.') + 1));
|
||||||
$extension = strtolower(mb_substr($_FILES['file']['name'], mb_strrpos($_FILES['file']['name'], '.') + 1));
|
|
||||||
|
|
||||||
if ($extension != 'png') {
|
if ($extension != 'png') {
|
||||||
error(_('Flags must be in PNG format.'));
|
error(_('Flags must be in PNG format.'));
|
||||||
@ -284,8 +292,45 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
copy($upload, "$dir/$id.$extension");
|
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 = <<<FLAGS
|
$flags = <<<FLAGS
|
||||||
<?php
|
<?php
|
||||||
\$config['country_flags'] = false;
|
\$config['country_flags'] = false;
|
||||||
@ -297,10 +342,9 @@
|
|||||||
FLAGS;
|
FLAGS;
|
||||||
|
|
||||||
file_write($b.'/flags.php', $flags);
|
file_write($b.'/flags.php', $flags);
|
||||||
file_write($b.'/flags.ser', serialize($config['user_flags']));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (isset($_POST['delete'])){
|
if (isset($_POST['delete'])){
|
||||||
foreach ($_POST['delete'] as $i => $d){
|
foreach ($_POST['delete'] as $i => $d){
|
||||||
if (!preg_match('/[0-9+]/', $d)){
|
if (!preg_match('/[0-9+]/', $d)){
|
||||||
|
@ -504,6 +504,8 @@ function boardTitle($uri) {
|
|||||||
function purge($uri) {
|
function purge($uri) {
|
||||||
global $config, $debug;
|
global $config, $debug;
|
||||||
|
|
||||||
|
if (!isset($config['purge'])) return;
|
||||||
|
|
||||||
// Fix for Unicode
|
// Fix for Unicode
|
||||||
$uri = rawurlencode($uri);
|
$uri = rawurlencode($uri);
|
||||||
|
|
||||||
|
@ -14,18 +14,19 @@
|
|||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<h2>{% trans %}Flags already in use{% endtrans %}</h2>
|
<h2>{% trans %}Flags already in use{% endtrans %}</h2>
|
||||||
<form action="{{ action }}" method="post">
|
<form action="{{ action }}" method="post" enctype="multipart/form-data">
|
||||||
<input type="hidden" name="token" value="{{ token }}">
|
<input type="hidden" name="token" value="{{ token }}">
|
||||||
<table>
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<th>D</th><th>{% trans %}Flag image{% endtrans %}</th><th>{% trans %}Flag description{% endtrans %}</th>
|
||||||
{% for flag, description in config.user_flags %}
|
{% for flag, description in config.user_flags %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><input name="delete[]" type="checkbox" value="{{flag}}"></td><td><img src="static/custom-flags/{{board.uri}}/{{flag}}.png"></td><td>{{description}}</td>
|
<td><input name="delete[]" type="checkbox" value="{{flag}}"></td><td><img src="static/custom-flags/{{board.uri}}/{{flag}}.png"> <input type="file" name="flag-{{ flag }}"></td><td><input type="text" name="description-{{flag}}" value="{{ description|addslashes }}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<p><input type="submit" value="Delete selected"></p>
|
<p><input type="submit" value="{% trans 'Update flags' %}"></p>
|
||||||
</form>
|
</form>
|
||||||
<form action="{{ action }}" method="post">
|
<form action="{{ action }}" method="post">
|
||||||
<input type="hidden" name="token" value="{{ token }}">
|
<input type="hidden" name="token" value="{{ token }}">
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script type="text/javascript" src="js/jquery.min.js"></script>
|
<script type="text/javascript" src="js/jquery.min.js"></script>
|
||||||
|
<p style="text-align: center" class="unimportant">{% trans %}Tip: Some changes made on this page won't take effect until a new post is made on your board.{% endtrans %}</p>
|
||||||
<form action="{{ action }}" method="post">
|
<form action="{{ action }}" method="post">
|
||||||
<input type="hidden" name="token" value="{{ token }}">
|
<input type="hidden" name="token" value="{{ token }}">
|
||||||
<table>
|
<table>
|
||||||
|
Loading…
Reference in New Issue
Block a user