Merge branch 'master' of github.com:vichan-devel/Tinyboard

This commit is contained in:
czaks 2014-08-10 18:44:59 +02:00
commit 5cd435f176
4 changed files with 235 additions and 5 deletions

View File

@ -549,6 +549,10 @@
'eu' => 'Europe' 'eu' => 'Europe'
); );
*/ */
// Allow dice rolling: an email field of the form "dice XdY+/-Z" will result in X Y-sided dice rolled and summed,
// with the modifier Z added, with the result displayed at the top of the post body.
$config['allow_roll'] = false;
/* /*
* ==================== * ====================

View File

@ -243,6 +243,9 @@ function loadConfig() {
if (is_array($config['anonymous'])) if (is_array($config['anonymous']))
$config['anonymous'] = $config['anonymous'][array_rand($config['anonymous'])]; $config['anonymous'] = $config['anonymous'][array_rand($config['anonymous'])];
if ($config['allow_roll'])
event_handler('post', 'diceRoller');
event('load-config'); event('load-config');
if ($config['debug']) { if ($config['debug']) {
@ -2323,3 +2326,62 @@ function shell_exec_error($command, $suppress_stdout = false) {
return $return === 'TB_SUCCESS' ? false : $return; return $return === 'TB_SUCCESS' ? false : $return;
} }
/* Die rolling:
* If "dice XdY+/-Z" is in the email field (where X or +/-Z may be
* missing), X Y-sided dice are rolled and summed, with the modifier Z
* added on. The result is displayed at the top of the post.
*/
function diceRoller($post) {
global $config;
if(strpos(strtolower($post->email), 'dice%20') === 0) {
$dicestr = str_split(substr($post->email, strlen('dice%20')));
// Get params
$diceX = '';
$diceY = '';
$diceZ = '';
$curd = 'diceX';
for($i = 0; $i < count($dicestr); $i ++) {
if(is_numeric($dicestr[$i])) {
$$curd .= $dicestr[$i];
} else if($dicestr[$i] == 'd') {
$curd = 'diceY';
} else if($dicestr[$i] == '-' || $dicestr[$i] == '+') {
$curd = 'diceZ';
$$curd = $dicestr[$i];
}
}
// Default values for X and Z
if($diceX == '') {
$diceX = '1';
}
if($diceZ == '') {
$diceZ = '+0';
}
// Intify them
$diceX = intval($diceX);
$diceY = intval($diceY);
$diceZ = intval($diceZ);
// Continue only if we have valid values
if($diceX > 0 && $diceY > 0) {
$dicerolls = array();
$dicesum = $diceZ;
for($i = 0; $i < $diceX; $i++) {
$roll = rand(1, $diceY);
$dicerolls[] = $roll;
$dicesum += $roll;
}
// Prepend the result to the post body
$modifier = ($diceZ != 0) ? ((($diceZ < 0) ? ' - ' : ' + ') . abs($diceZ)) : '';
$dicesum = ($diceX > 1) ? ' = ' . $dicesum : '';
$post->body = '<table class="diceroll"><tr><td><img src="'.$config['dir']['static'].'d10.svg" alt="Dice roll" width="24"></td><td>Rolled ' . implode(', ', $dicerolls) . $modifier . $dicesum . '</td></tr></table><br/>' . $post->body;
}
}
}

View File

@ -1,12 +1,15 @@
<?php <?php
/* This file is dedicated to the public domain; you may do as you wish with it. */ /* This file is dedicated to the public domain; you may do as you wish with it. */
$params = '?v=' . urlencode($_GET['v']) . '&amp;t=' . urlencode($_GET['t']); $v = @(string)$_GET['v'];
$loop = ($_GET['loop'] != "0"); $t = @(string)$_GET['t'];
$loop = @(boolean)$_GET['loop'];
$params = '?v=' . urlencode($v) . '&amp;t=' . urlencode($t);
?><!DOCTYPE html> ?><!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title><?php echo htmlspecialchars($_GET['t']); ?></title> <title><?php echo htmlspecialchars($t); ?></title>
<link rel="stylesheet" href="stylesheets/webm/playerstyle.css"> <link rel="stylesheet" href="stylesheets/webm/playerstyle.css">
<script src="js/webm-settings.js"></script> <script src="js/webm-settings.js"></script>
<script src="js/webm/playersettings.js"></script> <script src="js/webm/playersettings.js"></script>
@ -17,8 +20,8 @@ $loop = ($_GET['loop'] != "0");
<a id="loop1" href="<?php echo $params; ?>&amp;loop=1"<?php if ($loop) echo ' style="font-weight: bold"'; ?>>[loop]</a> <a id="loop1" href="<?php echo $params; ?>&amp;loop=1"<?php if ($loop) echo ' style="font-weight: bold"'; ?>>[loop]</a>
</div> </div>
<div id="playercontent"> <div id="playercontent">
<video controls<?php if ($loop) echo ' loop'; ?> src="<?php echo htmlspecialchars($_GET['v']); ?>"> <video controls<?php if ($loop) echo ' loop'; ?> src="<?php echo htmlspecialchars($v); ?>">
Your browser does not support HTML5 video. <a href="<?php echo htmlspecialchars($_GET['v']); ?>">[Download]</a> Your browser does not support HTML5 video. <a href="<?php echo htmlspecialchars($v); ?>">[Download]</a>
</video> </video>
</div> </div>
</body> </body>

161
static/d10.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.4 KiB