Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to include QR Code when printing vote keys #37

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions license.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,39 @@ you don't have your priorities right"-file.)
1. Wuhu comes with no obligations from the side of its creators.
We won't add features unless they're a really good idea, even
if your party's success depends on it. (Because it doesn't.)

2. The creators of Wuhu take no responsibility over any damage
you cause with it. (Yes, you.)
In other words, if your party sucks, you might want to look
somewhere else for blame.

3. Wuhu is free, as in beer. We don't ask for free entrance to
parties that use Wuhu, nor any compensation, nothing.
It would be nice, however, if you could notify us about the
use of our stuff.

4. Please don't make mutated versions of it, and/or if you have
something you hacked in and it doesn't smell too bad of
WTF, contact us and we'll try to integrate it with credits included.

5. Wuhu remains our copyright. Just so you know.



OptimusPrinceps example font courtesy of Manfred Klein.
http://www.dafont.com/optimusprinceps.font

OpenSSL Toolkit libraries courtesy of The OpenSSL Project.
http://www.openssl.org/

Prototype JS library courtesy of Prototype Core Team
http://prototypejs.org/

Adminer courtesy of Jakub Vrana
http://www.adminer.org/

Reveal.js courtesy of Hakim El Hattab
http://lab.hakim.se/reveal-js/

QRCode for PHP5 courtesy of Kazuhiko Arase
http://www.d-project.com/
36 changes: 36 additions & 0 deletions www_admin/plugins/qrcodevotekeys/options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

defined('ADMIN_DIR') || exit();

if (isset($_POST['qrcodevotekeys_register_url'])) {
update_setting('qrcodevotekeys_register_url', $_POST['qrcodevotekeys_register_url']);
}

if (isset($_POST['qrcodevotekeys_pixelsize'])) {
update_setting('qrcodevotekeys_pixelsize', $_POST['qrcodevotekeys_pixelsize']);
}

$qrcodevotekeys_register_url = $settings['qrcodevotekeys_register_url'] ?? 'http://party.lan/index.php?page=Login&votekey={%VOTEKEY%}';
$qrcodevotekeys_pixelsize = ((int)($settings['qrcodevotekeys_pixelsize'] ?? 2)) ?? 2;
?>
<style>
#qrcodevotekeys_form input[type="text"] { width: 500px; }
</style>

<h2>Votekeys with QR code</h2>

<h3>Print Votekeys with QR code</h3>
<a href="<?php echo _html($_SERVER['REQUEST_URI']); ?>&print=1" target="_blank">Print Votekeys with QR code</a>

<form action="<?php echo _html($_SERVER['REQUEST_URI']); ?>" method="post" enctype="multipart/form-data" id="qrcodevotekeys_form">
<label>Register URL (Used for QRCode, <b>{%VOTEKEY%}</b> will be substituted):</label>
<input name="qrcodevotekeys_register_url" type="text" value="<?php echo _html($qrcodevotekeys_register_url); ?>">

<label>Size of QR Code pixel:</label>
<select name="qrcodevotekeys_pixelsize">
<?php for ($i = 1; $i <= 32; $i++): ?>
<option value="<?php echo $i; ?>"<?php echo ($qrcodevotekeys_pixelsize === $i ? ' selected' : ''); ?>><?php echo $i; ?> px</option>
<?php endfor; ?>
</select>
<input type="submit" value="Save"/>
</form>
119 changes: 119 additions & 0 deletions www_admin/plugins/qrcodevotekeys/plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php
/*
Plugin name: Print Votekeys with QR code
Description: Add ability to print votekeys with QR code
*/

defined('ADMIN_DIR') || exit();

function qrcodevotekeys_generate_html($url) {
require_once(__DIR__.'/qrcode.php');

$qr = QRCode::getMinimumQRCode($url, QR_ERROR_CORRECT_LEVEL_L);

$html = '<table>';
for ($r = 0; $r < $qr->getModuleCount(); $r++) {
$html .= '<tr>';
for ($c = 0; $c < $qr->getModuleCount(); $c++) {
$isdark = $qr->isDark($r, $c);
if ($isdark) {
$html .= '<td class="dark"></td>';
} else {
$html .= '<td></td>';
}
}
$html .= '</tr>';
}
$html .= '</table>';

return $html;
}

function qrcodevotekeys_print() {
tditlu marked this conversation as resolved.
Show resolved Hide resolved
global $settings;

$register_url = $settings['qrcodevotekeys_register_url'] ?? 'http://party.lan/index.php?page=Login&votekey={%VOTEKEY%}';
$pixelsize = ((int)($settings['qrcodevotekeys_pixelsize'] ?? 2)) ?? 2;

$format = $settings['votekeys_format'] ?: '{%VOTEKEY%}';
$stylesheet = $settings['votekeys_css'] ?? '';
$rows = SQLLib::selectRows('SELECT * FROM `votekeys`');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<style type="text/css">
body {
font-family: arial;
margin: 0;
padding: 0;
}
ul {
margin: 0;
padding: 0;
}
li {
list-style: none;
padding: 15px;
padding-top: 25px;
padding-bottom: 25px;
border: 1px dotted #ccc;
text-align:center;
font-size: 130%;
letter-spacing: 2px;
}
.votekeys li {
float: left;
width: 25%;
}
.qr {
display: block;
padding-bottom: 10px;
}
.qr table {
display: inline-block;
}
.qr table, .qr tr, .qr td {
border-style: none;
border-collapse: collapse;
margin: 0;
padding: 0;
}
.qr td {
width: <?php echo $pixelsize; ?>px;
height: <?php echo $pixelsize; ?>px;
}
.qr td.dark {
background-color: #000;
}

<?php echo $stylesheet; ?>
</style>
</head>
<body>
<ul class="votekeys">
<?php foreach($rows as $row): ?>
<li>
<span class="qr"><?php echo qrcodevotekeys_generate_html(str_replace('{%VOTEKEY%}', $row->votekey, $register_url)); ?></span>
<?php echo str_replace('{%VOTEKEY%}', $row->votekey, $format); ?>
</li>
<?php endforeach; ?>
</ul>
</body>
</html>
<?php
}

add_hook('admin_menu', function($data) {
$data['links']['pluginoptions.php?plugin=qrcodevotekeys'] = 'QR code Votekeys';

});

add_hook('admin_page_start', function() {
if (!empty($_GET['plugin']) && $_GET['plugin'] === 'qrcodevotekeys' && isset($_GET['print'])) {
qrcodevotekeys_print();
exit();
}
});
Loading