1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2025-01-31 12:23:48 +01:00
This commit is contained in:
8chan 2015-04-03 03:04:08 -07:00
commit f587bd0b69
15 changed files with 186 additions and 26 deletions

View File

@ -49,6 +49,7 @@
$config['mod']['unban'] = BOARDVOLUNTEER;
$config['mod']['deletebyip'] = BOARDVOLUNTEER;
$config['mod']['sticky'] = BOARDVOLUNTEER;
$config['mod']['cycle'] = BOARDVOLUNTEER;
$config['mod']['lock'] = BOARDVOLUNTEER;
$config['mod']['postinlocked'] = BOARDVOLUNTEER;
$config['mod']['bumplock'] = BOARDVOLUNTEER;
@ -246,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.'));
@ -283,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 = <<<FLAGS
<?php
\$config['country_flags'] = false;
@ -296,10 +342,9 @@
FLAGS;
file_write($b.'/flags.php', $flags);
file_write($b.'/flags.ser', serialize($config['user_flags']));
}
if (isset($_POST['delete'])){
foreach ($_POST['delete'] as $i => $d){
if (!preg_match('/[0-9+]/', $d)){

View File

@ -32,6 +32,7 @@ class Api {
'images' => 'images',
'sticky' => 'sticky',
'locked' => 'locked',
'cycle' => 'cyclical',
'bump' => 'last_modified',
'embed' => 'embed',
);

View File

@ -1272,6 +1272,8 @@
$config['mod']['link_bumpunlock'] = '[-Sage]';
$config['mod']['link_editpost'] = '[Edit]';
$config['mod']['link_move'] = '[Move]';
$config['mod']['link_cycle'] = '[Cycle]';
$config['mod']['link_uncycle'] = '[-Cycle]';
// Moderator capcodes.
$config['capcode'] = ' <span class="capcode">## %s</span>';
@ -1415,6 +1417,9 @@
$config['mod']['deletebyip_global'] = ADMIN;
// Sticky a thread
$config['mod']['sticky'] = MOD;
// Cycle a thread
$config['mod']['cycle'] = MOD;
$config['cycle_limit'] = &$config['reply_limit'];
// Lock a thread
$config['mod']['lock'] = MOD;
// Post in a locked thread

View File

@ -504,6 +504,8 @@ function boardTitle($uri) {
function purge($uri) {
global $config, $debug;
if (!isset($config['purge'])) return;
// Fix for Unicode
$uri = rawurlencode($uri);
@ -913,7 +915,7 @@ function insertFloodPost(array $post) {
function post(array $post) {
global $pdo, $board;
$query = prepare(sprintf("INSERT INTO ``posts_%s`` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :body_nomarkup, :time, :time, :files, :num_files, :filehash, :password, :ip, :sticky, :locked, 0, :embed, NULL)", $board['uri']));
$query = prepare(sprintf("INSERT INTO ``posts_%s`` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :body_nomarkup, :time, :time, :files, :num_files, :filehash, :password, :ip, :sticky, :locked, :cycle, 0, :embed, NULL)", $board['uri']));
// Basic stuff
if (!empty($post['subject'])) {
@ -953,6 +955,12 @@ function post(array $post) {
$query->bindValue(':locked', false, PDO::PARAM_INT);
}
if ($post['op'] && $post['mod'] && isset($post['cycle']) && $post['cycle']) {
$query->bindValue(':cycle', true, PDO::PARAM_INT);
} else {
$query->bindValue(':cycle', false, PDO::PARAM_INT);
}
if ($post['mod'] && isset($post['capcode']) && $post['capcode']) {
$query->bindValue(':capcode', $post['capcode'], PDO::PARAM_INT);
} else {

View File

@ -1160,6 +1160,28 @@ function mod_sticky($board, $unsticky, $post) {
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
}
function mod_cycle($board, $uncycle, $post) {
global $config;
if (!openBoard($board))
error($config['error']['noboard']);
if (!hasPermission($config['mod']['cycle'], $board))
error($config['error']['noaccess']);
$query = prepare(sprintf('UPDATE ``posts_%s`` SET `cycle` = :cycle WHERE `id` = :id AND `thread` IS NULL', $board));
$query->bindValue(':id', $post);
$query->bindValue(':cycle', $uncycle ? 0 : 1);
$query->execute() or error(db_error($query));
if ($query->rowCount()) {
modLog(($uncycle ? 'Made not cyclical' : 'Made cyclical') . " thread #{$post}");
buildThread($post);
buildIndex();
}
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
}
function mod_bumplock($board, $unbumplock, $post) {
global $config;
@ -1593,10 +1615,17 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
$_POST['body'] .= "<tinyboard $key>$value</tinyboard>";
}
// Handle embed edits...
foreach ($config['embedding'] as &$embed) {
if (preg_match($embed[0], $_POST['embed'])) {
$embed_link = $_POST['embed'];
}
}
if ($edit_raw_html)
$query = prepare(sprintf('UPDATE ``posts_%s`` SET `name` = :name,'. $trip .' `email` = :email, `subject` = :subject, `body` = :body, `body_nomarkup` = :body_nomarkup, `edited_at` = UNIX_TIMESTAMP(NOW()) WHERE `id` = :id', $board));
$query = prepare(sprintf('UPDATE ``posts_%s`` SET `name` = :name,'. $trip .' `email` = :email, `subject` = :subject, `body` = :body, `body_nomarkup` = :body_nomarkup, `embed` = :embed `edited_at` = UNIX_TIMESTAMP(NOW()) WHERE `id` = :id', $board));
else
$query = prepare(sprintf('UPDATE ``posts_%s`` SET `name` = :name,'. $trip .' `email` = :email, `subject` = :subject, `body_nomarkup` = :body, `edited_at` = UNIX_TIMESTAMP(NOW()) WHERE `id` = :id', $board));
$query = prepare(sprintf('UPDATE ``posts_%s`` SET `name` = :name,'. $trip .' `email` = :email, `subject` = :subject, `body_nomarkup` = :body, `embed` = :embed, `edited_at` = UNIX_TIMESTAMP(NOW()) WHERE `id` = :id', $board));
$query->bindValue(':id', $postID);
$query->bindValue(':name', $_POST['name'] ? $_POST['name'] : $config['anonymous']);
$query->bindValue(':email', $_POST['email']);
@ -1606,6 +1635,11 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
$body_nomarkup = $_POST['body'] . "\n<tinyboard raw html>1</tinyboard>";
$query->bindValue(':body_nomarkup', $body_nomarkup);
}
if (isset($embed_link)) {
$query->bindValue(':embed', $embed_link);
} else {
$query->bindValue(':embed', NULL, PDO::PARAM_NULL);
}
$query->execute() or error(db_error($query));
if( $config['clean']['edits_remove_local'] || $config['clean']['edits_remove_global'] ) {
@ -1664,7 +1698,10 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
$post['body'] = str_replace("\t", '&#09;', $post['body']);
}
mod_page(_('Edit post'), 'mod/edit_post_form.html', array('token' => $security_token, 'board' => $board, 'raw' => $edit_raw_html, 'post' => $post));
$preview = new Post($post);
$html = $preview->build(true);
mod_page(_('Edit post'), 'mod/edit_post_form.html', array('token' => $security_token, 'board' => $board, 'raw' => $edit_raw_html, 'post' => $post, 'preview' => $html));
}
}

View File

@ -94,6 +94,7 @@ $pages = array(
'/(\%b)/deletebyip/(\d+)(/global)?' => 'secure deletebyip', // delete all posts by IP address
'/(\%b)/(un)?lock/(\d+)' => 'secure lock', // lock thread
'/(\%b)/(un)?sticky/(\d+)' => 'secure sticky', // sticky thread
'/(\%b)/(un)?cycle/(\d+)' => 'secure cycle', // cycle thread
'/(\%b)/bump(un)?lock/(\d+)' => 'secure bumplock', // "bumplock" thread
'/themes' => 'themes_list', // manage themes

View File

@ -315,7 +315,7 @@ elseif (isset($_POST['post'])) {
//Check if thread exists
if (!$post['op']) {
$query = prepare(sprintf("SELECT `sticky`,`locked`,`sage` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri']));
$query = prepare(sprintf("SELECT `sticky`,`locked`,`cycle`,`sage` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri']));
$query->bindValue(':id', $post['thread'], PDO::PARAM_INT);
$query->execute() or error(db_error());
@ -905,6 +905,19 @@ elseif (isset($_POST['post'])) {
$post['id'] = $id = post($post);
insertFloodPost($post);
// Handle cyclical threads
if (!$post['op'] && isset($thread['cycle']) && $thread['cycle']) {
// Query is a bit weird due to "This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'" (MariaDB Ver 15.1 Distrib 10.0.17-MariaDB, for Linux (x86_64))
$query = prepare(sprintf('SELECT `id` FROM ``posts_%s`` WHERE `thread` = :thread AND `id` NOT IN (SELECT `id` FROM (SELECT `id` FROM ``posts_%s`` WHERE `thread` = :thread ORDER BY `id` DESC LIMIT :limit) i)', $board['uri'], $board['uri']));
$query->bindValue(':thread', $post['thread']);
$query->bindValue(':limit', $config['cycle_limit'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
while ($dpost = $query->fetch()) {
deletePost($dpost['id'], false, false);
}
}
if (isset($post['antispam_hash'])) {
incrementSpamHash($post['antispam_hash']);

View File

@ -1,3 +1,5 @@
<div style="text-align: center">
<style>.post {text-align:left}</style>
<form action="" method="post">
<input type="hidden" name="token" value="{{ token }}">
@ -15,7 +17,7 @@
{% trans %}Tripcode{% endtrans %}
</th>
<td>
Remove? <input type="checkbox" name="remove_trip" value="{{ post.trip }}">
{% trans %}Remove tripcode?{% endtrans %} <input type="checkbox" name="remove_trip" value="{{ post.trip }}">
</td>
</tr>
<tr>
@ -43,7 +45,28 @@
<textarea name="body" id="body" rows="8" cols="35">{% if raw %}{{ post.body }}{% else %}{{ post.body_nomarkup }}{% endif %}</textarea>
</td>
</tr>
{# <tr> <!-- The file handling code is quite complicated and I'm not about to start maintaining it in two places. It needs to be made into a set of reusable functions or something. If you want to do so uncomment this. Pull requests that copy the code from post.php to inc/mod/pages.php without creating functions to be used in both won't be accepted. -->
<th>
{% trans %}Files{% endtrans %}<br/>
<p class="unimportant">{% trans %}Note: Changing files<br/>deletes all previous ones.{% endtrans %}</p>
</th>
<td>
{% for i in range(0, config.max_images - 1) %}
<input type="file" name="file" id="upload_file"><br/>
{% endfor %}
</td>
</tr> #}
<tr id="upload_embed">
<th>
{% trans %}Embed{% endtrans %}
</th>
<td>
<input type="text" name="embed" value="{{ post.embed|e }}" size="30" maxlength="120" autocomplete="off">
</td>
</tr>
</table>
<h2>{% trans %}Existing post{% endtrans %}</h2>
{{ preview }}
<p style="text-align:center">
{% if mod|hasPermission(config.mod.rawhtml) %}
{% if raw %}
@ -55,3 +78,4 @@
{% endif %}
</p>
</form>
</div>

View File

@ -14,18 +14,19 @@
<hr>
<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 }}">
<table>
<tbody>
<th>D</th><th>{% trans %}Flag image{% endtrans %}</th><th>{% trans %}Flag description{% endtrans %}</th>
{% for flag, description in config.user_flags %}
<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>
{% endfor %}
</tbody>
</table>
<p><input type="submit" value="Delete selected"></p>
<p><input type="submit" value="{% trans 'Update flags' %}"></p>
</form>
<form action="{{ action }}" method="post">
<input type="hidden" name="token" value="{{ token }}">

View File

@ -1,5 +1,5 @@
<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">
<input type="hidden" name="token" value="{{ token }}">
<table>

View File

@ -44,7 +44,6 @@
{% endif %}
{% endif %}
{% if mod|hasPermission(config.mod.move, board.uri) %}
{% if not post.thread %}
<a title="{% trans %}Move thread to another board{% endtrans %}" href="?/{{ board.dir }}move/{{ post.id }}">{{ config.mod.link_move }}</a>&nbsp;
@ -52,6 +51,13 @@
<a title="{% trans %}Move reply to another board{% endtrans %}" href="?/{{ board.dir }}move_reply/{{ post.id }}">{{ config.mod.link_move }}</a>&nbsp;
{% endif %}
{% endif %}
{% if mod|hasPermission(config.mod.cycle, board.uri) %}
{% if post.cycle %}
<a title="{% trans %}Make thread not cycle{% endtrans %}" href="?/{{ secure_link(board.dir ~ 'uncycle/' ~ post.id) }}">{{ config.mod.link_uncycle }}</a>&nbsp;
{% else %}
<a title="{% trans %}Make thread cycle{% endtrans %}" href="?/{{ secure_link(board.dir ~ 'cycle/' ~ post.id) }}">{{ config.mod.link_cycle }}</a>&nbsp;
{% endif %}
{% endif %}
{% if mod|hasPermission(config.mod.editpost, board.uri) %}
<a title="{% trans %}Edit post{% endtrans %}" href="?/{{ board.dir }}edit{% if config.mod.raw_html_default %}_raw{% endif %}/{{ post.id }}">{{ config.mod.link_editpost }}</a>&nbsp;
{% endif %}

View File

@ -19,25 +19,32 @@
<a class="post_no" onclick="citeReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('q', config.file_page50) }}{% else %}{{ post.link('q') }}{% endif %}">{{ post.id }}</a>
{% if post.sticky %}
{% if config.font_awesome %}
<i class="fa fa-thumb-tack"></i>
<i class="fa fa-thumb-tack" title="Sticky"></i>
{% else %}
<img class="icon" title="Sticky" src="{{ config.image_sticky }}" alt="Sticky" />
{% endif %}
{% endif %}
{% if post.locked %}
{% if config.font_awesome %}
<i class="fa fa-lock"></i>
<i class="fa fa-lock" title="Locked"></i>
{% else %}
<img class="icon" title="Locked" src="{{ config.image_locked }}" alt="Locked" />
{% endif %}
{% endif %}
{% if post.bumplocked and (config.mod.view_bumplock < 0 or (post.mod and post.mod|hasPermission(config.mod.view_bumplock, board.uri))) %}
{% if config.font_awesome %}
<i class="fa fa-anchor"></i>
<i class="fa fa-anchor" title="Bumplocked"></i>
{% else %}
<img class="icon" title="Bumplocked" src="{{ config.image_bumplocked }}" alt="Bumplocked" />
{% endif %}
{% endif %}
{% if post.cycle %}
{% if config.font_awesome %}
<i class="fa fa-refresh" title="Cyclical"></i>
{% else %}
<img class="icon" title="Cyclical" src="{{ config.image_sticky }}" alt="Cyclical" />
{% endif %}
{% endif %}
{% if index %}
<a href="{{ post.root }}{{ board.dir }}{{ config.dir.res }}{{ config.file_page|sprintf(post.id) }}">[{% trans %}Reply{% endtrans %}]</a>
{% endif %}

View File

@ -17,6 +17,7 @@ CREATE TABLE IF NOT EXISTS ``posts_{{ board }}`` (
`ip` varchar(39) CHARACTER SET ascii NOT NULL,
`sticky` int(1) NOT NULL,
`locked` int(1) NOT NULL,
`cycle` int(1) NOT NULL,
`sage` int(1) NOT NULL,
`embed` text,
`edited_at` int(11) DEFAULT NULL,

View File

@ -39,10 +39,10 @@ foreach ($locales as $loc) {
if (file_exists($locdir."/LC_MESSAGES/tinyboard.po")) $join = "-j --omit-header";
else $join = "";
passthru("cd $locdir/LC_MESSAGES;
xgettext -d tinyboard -L php --from-code utf-8 $join -c $(find ../../../../ -name \*.php)");
xgettext -d tinyboard -L php --from-code utf-8 $join $(find ../../../../ -name \*.php)");
// Generate javascript.po
passthru("cd $locdir/LC_MESSAGES;".
"xgettext -d javascript -L Python --force-po --from-code utf-8 $join -c ".
"xgettext -d javascript -L Python --force-po --from-code utf-8 $join ".
"$(find ../../../../js/ ../../../../templates/ -not -path \*node_modules\* -name \*.js)");
}

11
tools/migrate_cycle.php Normal file
View File

@ -0,0 +1,11 @@
<?php
require dirname(__FILE__) . '/inc/cli.php';
# edited_at column was using DATETIME when time column uses INT(11). This script solves that.
$boards = listBoards(TRUE);
#$boards = array('test2');
foreach ($boards as $i => $b) {
query(sprintf('ALTER TABLE ``posts_%s`` ADD COLUMN cycle INT(1) NOT NULL AFTER locked', $b));
}