qrcode.chapril.org-libreqr/index.php

252 lines
8.8 KiB
PHP
Raw Normal View History

<?php // This file is part of LibreQR, which is distributed under the GNU AGPLv3+ license
2021-11-03 19:35:20 +01:00
use CodeItNow\BarcodeBundle\Utils\QrCode;
require "inc.php";
2021-07-11 14:00:35 +02:00
$params = array(
"txt" => "",
"redondancy" => DEFAULT_REDONDANCY,
"margin" => DEFAULT_MARGIN,
"size" => DEFAULT_SIZE,
2021-11-01 18:08:42 +01:00
"bgColor" => DEFAULT_BGCOLOR,
"mainColor" => DEFAULT_MAINCOLOR,
2021-07-11 14:00:35 +02:00
);
if (
isset($_POST['txt'])
AND isset($_POST['redondancy'])
AND isset($_POST['margin'])
AND isset($_POST['size'])
AND isset($_POST['bgColor'])
AND isset($_POST['mainColor'])
) {
if (strlen($_POST['txt']) >= 1 AND strlen($_POST['txt']) <= 4096)
$params['txt'] = $_POST['txt'];
else
2021-07-11 14:00:35 +02:00
exit("Wrong value for txt");
2021-11-01 18:08:42 +01:00
if ($_POST['redondancy'] === "low" OR $_POST['redondancy'] === "medium" OR $_POST['redondancy'] === "quartile" OR $_POST['redondancy'] === "high")
2021-07-11 14:00:35 +02:00
$params['redondancy'] = $_POST['redondancy'];
else
exit("Wrong value for redondancy");
2021-11-01 18:08:42 +01:00
if (is_numeric($_POST['margin']) AND $_POST['margin'] >= 0 AND $_POST['margin'] <= 1024)
2021-07-11 14:00:35 +02:00
$params['margin'] = $_POST['margin'];
else if (empty($_POST['margin']))
$params['margin'] = NULL;
2021-07-11 14:00:35 +02:00
else
exit("Wrong value for margin");
if (is_numeric($_POST['size']) AND $_POST['size'] >= 1 AND $_POST['size'] <= 4096)
2021-07-11 14:00:35 +02:00
$params['size'] = $_POST['size'];
else if (empty($_POST['size']))
$params['size'] = NULL;
2021-07-11 14:00:35 +02:00
else
exit("Wrong value for size");
2021-07-11 14:00:35 +02:00
if (preg_match("/^#[abcdefABCDEF0-9]{6}$/", $_POST['bgColor']))
2021-11-01 18:08:42 +01:00
$params['bgColor'] = substr($_POST['bgColor'], -6);
2021-07-11 14:00:35 +02:00
else
exit("Wrong value for bgColor");
2021-07-11 14:00:35 +02:00
if (preg_match("/^#[abcdefABCDEF0-9]{6}$/", $_POST['mainColor']))
2021-11-01 18:08:42 +01:00
$params['mainColor'] = substr($_POST['mainColor'], -6);
2021-07-11 14:00:35 +02:00
else
exit("Wrong value for mainColor");
}
?>
<!DOCTYPE html>
<html lang="<?= $locale ?>">
2019-01-26 14:23:19 +01:00
<head>
2019-08-13 21:17:08 +02:00
<meta charset="UTF-8">
<title>LibreQR · <?= $loc['subtitle'] ?></title>
<meta name="description" content="<?= $loc['description'] ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
2019-03-28 22:44:06 +01:00
<link rel="manifest" href="manifest.php">
2021-07-11 14:00:35 +02:00
<link rel="search" type="application/opensearchdescription+xml" title="LibreQR" href="opensearch.php&#63;redondancy=<?= $params['redondancy'] ?>&amp;margin=<?= $params['margin'] ?>&amp;size=<?= $params['size'] ?>&amp;bgColor=<?= urlencode($params['bgColor']) ?>&amp;mainColor=<?= urlencode($params['mainColor']) ?>">
<?php
require_once "less.php/lib/Less/Autoloader.php";
Less_Autoloader::register();
$options = array('cache_dir' => 'css/', 'compress' => true);
2021-10-19 17:07:51 +02:00
$cssFileName = Less_Cache::Get(array("style.less" => ""), $options, $colorScheme);
?>
<link type="text/css" rel="stylesheet" href="css/<?= $cssFileName ?>">
<?php
foreach($themeDimensionsIcons as $dimFav) { // Set all icons dimensions
echo ' <link rel="icon" type="image/png" href="themes/' . $theme . '/icons/' . $dimFav . '.png" sizes="' . $dimFav . 'x' . $dimFav . '">' . "\n";
}
?>
2019-01-26 14:23:19 +01:00
</head>
<body>
<main>
2019-01-26 14:23:19 +01:00
<header>
<a id="linkTitles" href="./">
<img alt="" id="logo" src="themes/<?php echo $theme; ?>/icons/128.png">
<div id="titles">
<h1>LibreQR</h1>
<h2><?= $loc['subtitle'] ?></h2>
</div>
</a>
</header>
2019-08-13 21:17:08 +02:00
2021-07-11 14:00:35 +02:00
<form method="post" action="./">
2019-01-26 14:23:19 +01:00
<div id="firstWrapper">
2019-08-13 21:17:08 +02:00
2021-07-11 21:48:56 +02:00
<div class="param" id="txtParam">
<details>
<summary><label for="txt"><?= $loc['label_content'] ?></label></summary>
<div class="helpText">
<?= $loc['help_content'] ?>
</div>
</details>
<textarea rows="8" required="" id="txt" placeholder="<?= $loc['placeholder'] ?>" name="txt"><?= htmlspecialchars($params['txt']) ?></textarea>
</div>
<div id="sideParams">
<div class="param">
<details>
<summary><label for="redondancy"><?= $loc['label_redondancy'] ?></label></summary>
<p class="helpText">
<?= $loc['help_redondancy'] ?>
</p>
</details>
<select id="redondancy" name="redondancy">
2021-11-01 18:08:42 +01:00
<option <?php if ($params['redondancy'] === "low") echo 'selected="" '; ?>value="low">L - 7%</option>
<option <?php if ($params['redondancy'] === "medium") echo 'selected="" '; ?>value="medium">M - 15%</option>
<option <?php if ($params['redondancy'] === "quartile") echo 'selected="" '; ?>value="quartile">Q - 25%</option>
<option <?php if ($params['redondancy'] === "high") echo 'selected="" '; ?>value="high">H - 30%</option>
</select>
</div>
<div class="param">
<details>
<summary><label for="margin"><?= $loc['label_margin'] ?></label></summary>
<p class="helpText">
<?= $loc['help_margin'] ?>
</p>
</details>
<input type="number" list="margins" id="margin" placeholder="<?= $loc['placeholder_pixels'] ?>" name="margin" min="0" max="1024" value="<?= htmlspecialchars($params['margin']) ?>">
<datalist id="margins">
<option value="16">
<option value="32">
<option value="64">
<option value="128">
</datalist>
</div>
<div class="param">
<details>
<summary><label for="size"><?= $loc['label_size'] ?></label></summary>
<p class="helpText">
<?= $loc['help_size'] ?>
</p>
</details>
<input type="number" list="sizes" id="size" placeholder="<?= $loc['placeholder_pixels'] ?>" name="size" min="1" max="4096" value="<?= htmlspecialchars($params['size']) ?>">
<datalist id="sizes">
<option value="128">
<option value="256">
<option value="512">
<option value="1024">
</datalist>
</div>
</div>
</div>
<div id="colors">
<div class="param">
<label for="bgColor"><?= $loc['label_bgColor'] ?></label>
<div class="inputColorContainer">
2021-11-01 18:08:42 +01:00
<input type="color" name="bgColor" id="bgColor" value="#<?= htmlspecialchars($params['bgColor']) ?>">
</div>
</div>
2019-01-26 14:23:19 +01:00
<div class="param">
<label for="mainColor"><?= $loc['label_mainColor'] ?></label>
<div class="inputColorContainer">
2021-11-01 18:08:42 +01:00
<input type="color" name="mainColor" id="mainColor" value="#<?= htmlspecialchars($params['mainColor']) ?>">
</div>
</div>
</div>
2019-08-13 21:17:08 +02:00
<div class="centered">
<input class="button" type="submit" value="<?= $loc['button_create'] ?>" />
</div>
</form>
<?php
if (!empty($params['txt'])) {
require "barcode-generator/Utils/QrCode.php";
$qrCode = new QrCode();
if (!is_null($params['margin']))
$qrCode->setPadding($params['margin']);
$qrCode
->setText($params['txt'])
->setSize($params['size'])
->setErrorCorrection($params['redondancy'])
->setForegroundColor(array(
'r' => hexdec(substr($params['mainColor'],0,2)),
'g' => hexdec(substr($params['mainColor'],2,2)),
'b' => hexdec(substr($params['mainColor'],4,2)),
))
->setBackgroundColor(array(
'r' => hexdec(substr($params['bgColor'],0,2)),
'g' => hexdec(substr($params['bgColor'],2,2)),
'b' => hexdec(substr($params['bgColor'],4,2)),
))
->setImageType(QrCode::IMAGE_TYPE_PNG);
$dataUri = $qrCode->getDataUri();
$qrSize = $qrCode->getSize() + 2 * $qrCode->getPadding();
?>
<section id="output">
2021-07-11 21:48:56 +02:00
<div class="centered" id="downloadQR">
<a href="<?= $dataUri ?>" class="button" download="<?= htmlspecialchars($params['txt']); ?>.png"><?= $loc['button_download'] ?></a>
2021-07-11 21:48:56 +02:00
</div>
<div class="centered" id="showOnlyQR">
<a title="<?= $loc['title_showOnlyQR'] ?>" href="<?= $dataUri ?>"><img width="<?= $qrSize ?>" height="<?= $qrSize ?>" alt='<?= $loc['alt_QR_before'] ?><?= htmlspecialchars($params['txt']); ?><?= $loc['alt_QR_after'] ?>' id="qrCode" src="<?= $dataUri ?>"></a>
2021-07-11 21:48:56 +02:00
</div>
</section>
<?php } ?>
<footer>
2020-10-12 18:55:36 +02:00
<section id="info" class="metaText">
<?= $loc['metaText_qr'] ?>
</section>
2020-10-12 18:55:36 +02:00
<?php if ($customTextEnabled) { ?>
<section class="metaText">
<?= $customText ?>
</section>
2020-10-12 18:55:36 +02:00
<?php } ?>
<section class="metaText">
<?= $loc['metaText_legal'] ?>
</section>
2020-10-12 18:55:36 +02:00
</footer>
</main>
</body>
</html>