2021-11-25 22:36:21 +01:00
|
|
|
<?php // This file is part of LibreQR, which is distributed under the GNU AGPLv3+ license
|
2020-03-06 21:34:31 +01:00
|
|
|
|
2021-11-03 19:35:20 +01:00
|
|
|
use CodeItNow\BarcodeBundle\Utils\QrCode;
|
|
|
|
|
2022-02-18 17:15:43 +01:00
|
|
|
require "config.inc.php";
|
|
|
|
|
|
|
|
define("LIBREQR_VERSION", "2.0.0dev");
|
|
|
|
|
|
|
|
// Defines the locale to be used
|
|
|
|
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
|
|
|
$clientLocales = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
|
|
|
|
$clientLocales = preg_replace("#[A-Z0-9]|q=|;|-|\.#", "", $clientLocales);
|
|
|
|
$clientLocales = explode(',', $clientLocales);
|
|
|
|
$availableLocales = array('en', 'fr', 'oc', 'template');
|
|
|
|
foreach ($clientLocales as $clientLocale) {
|
|
|
|
if (in_array($clientLocale, $availableLocales)) {
|
|
|
|
$locale = $clientLocale;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$locale = DEFAULT_LOCALE;
|
|
|
|
}
|
|
|
|
require "locales/" . $locale . ".php";
|
|
|
|
|
2021-07-11 14:00:35 +02:00
|
|
|
$params = array(
|
|
|
|
"txt" => "",
|
2022-02-13 01:24:34 +01:00
|
|
|
"redundancy" => DEFAULT_REDUNDANCY,
|
2021-07-11 14:00:35 +02:00
|
|
|
"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
|
|
|
);
|
|
|
|
|
2021-12-06 20:56:56 +01:00
|
|
|
$validFormSubmitted = false;
|
|
|
|
|
2021-07-11 14:00:35 +02:00
|
|
|
if (
|
|
|
|
isset($_POST['txt'])
|
2022-02-13 01:24:34 +01:00
|
|
|
AND isset($_POST['redundancy'])
|
2021-07-11 14:00:35 +02:00
|
|
|
AND isset($_POST['margin'])
|
|
|
|
AND isset($_POST['size'])
|
|
|
|
AND isset($_POST['bgColor'])
|
|
|
|
AND isset($_POST['mainColor'])
|
|
|
|
) {
|
|
|
|
|
2022-02-18 22:51:32 +01:00
|
|
|
if (strlen($_POST['txt']) >= 1 AND strlen($_POST['txt']) <= 4096) {
|
2021-07-11 14:00:35 +02:00
|
|
|
$params['txt'] = $_POST['txt'];
|
2022-02-18 22:51:32 +01:00
|
|
|
} else {
|
|
|
|
http_response_code(400);
|
2021-07-11 14:00:35 +02:00
|
|
|
exit("Wrong value for txt");
|
2022-02-18 22:51:32 +01:00
|
|
|
}
|
2020-03-06 21:34:31 +01:00
|
|
|
|
2022-02-18 22:51:32 +01:00
|
|
|
if ($_POST['redundancy'] === "low" OR $_POST['redundancy'] === "medium" OR $_POST['redundancy'] === "quartile" OR $_POST['redundancy'] === "high") {
|
2022-02-13 01:24:34 +01:00
|
|
|
$params['redundancy'] = $_POST['redundancy'];
|
2022-02-18 22:51:32 +01:00
|
|
|
} else {
|
|
|
|
http_response_code(400);
|
2022-02-13 01:24:34 +01:00
|
|
|
exit("Wrong value for redundancy");
|
2022-02-18 22:51:32 +01:00
|
|
|
}
|
2020-03-06 21:34:31 +01:00
|
|
|
|
2022-02-18 22:51:32 +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'];
|
2022-02-18 22:51:32 +01:00
|
|
|
} else if (empty($_POST['margin'])) {
|
2021-11-06 00:33:15 +01:00
|
|
|
$params['margin'] = NULL;
|
2022-02-18 22:51:32 +01:00
|
|
|
} else {
|
|
|
|
http_response_code(400);
|
2021-07-11 14:00:35 +02:00
|
|
|
exit("Wrong value for margin");
|
2022-02-18 22:51:32 +01:00
|
|
|
}
|
2020-03-06 21:34:31 +01:00
|
|
|
|
2022-02-18 22:51:32 +01:00
|
|
|
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'];
|
2022-02-18 22:51:32 +01:00
|
|
|
} else if (empty($_POST['size'])) {
|
2021-11-06 00:33:15 +01:00
|
|
|
$params['size'] = NULL;
|
2022-02-18 22:51:32 +01:00
|
|
|
} else {
|
|
|
|
http_response_code(400);
|
2021-07-11 14:00:35 +02:00
|
|
|
exit("Wrong value for size");
|
2022-02-18 22:51:32 +01:00
|
|
|
}
|
2020-03-06 21:34:31 +01:00
|
|
|
|
2022-02-18 22:51:32 +01:00
|
|
|
if (preg_match("/^#[abcdefABCDEF0-9]{6}$/", $_POST['bgColor'])) {
|
2021-11-01 18:08:42 +01:00
|
|
|
$params['bgColor'] = substr($_POST['bgColor'], -6);
|
2022-02-18 22:51:32 +01:00
|
|
|
} else {
|
|
|
|
http_response_code(400);
|
2021-07-11 14:00:35 +02:00
|
|
|
exit("Wrong value for bgColor");
|
2022-02-18 22:51:32 +01:00
|
|
|
}
|
2020-03-06 21:34:31 +01:00
|
|
|
|
2022-02-18 22:51:32 +01:00
|
|
|
if (preg_match("/^#[abcdefABCDEF0-9]{6}$/", $_POST['mainColor'])) {
|
2021-11-01 18:08:42 +01:00
|
|
|
$params['mainColor'] = substr($_POST['mainColor'], -6);
|
2022-02-18 22:51:32 +01:00
|
|
|
} else {
|
|
|
|
http_response_code(400);
|
2021-07-11 14:00:35 +02:00
|
|
|
exit("Wrong value for mainColor");
|
2022-02-18 22:51:32 +01:00
|
|
|
}
|
2020-03-06 21:34:31 +01:00
|
|
|
|
2021-12-06 20:56:56 +01:00
|
|
|
$validFormSubmitted = true;
|
2020-03-06 21:34:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
2020-07-01 20:47:02 +02:00
|
|
|
<html lang="<?= $locale ?>">
|
2019-01-26 14:23:19 +01:00
|
|
|
<head>
|
2021-12-01 21:57:49 +01:00
|
|
|
<meta charset="utf-8">
|
2020-07-01 20:47:02 +02:00
|
|
|
<title>LibreQR · <?= $loc['subtitle'] ?></title>
|
|
|
|
<meta name="description" content="<?= $loc['description'] ?>">
|
2019-02-11 19:26:31 +01:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
2021-12-01 21:57:49 +01:00
|
|
|
<meta name="color-scheme" content="dark light">
|
|
|
|
<meta name="application-name" content="LibreQR">
|
|
|
|
<meta name="referrer" content="no-referrer">
|
2022-02-25 13:10:11 +01:00
|
|
|
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' data:; style-src 'self'; form-action 'self';">
|
2021-11-03 19:48:30 +01:00
|
|
|
<?php
|
2022-02-26 16:45:39 +01:00
|
|
|
require "themes/" . THEME . "/theme.php";
|
|
|
|
$colorScheme['theme'] = THEME;
|
|
|
|
|
2021-03-07 23:03:33 +01:00
|
|
|
require_once "less.php/lib/Less/Autoloader.php";
|
|
|
|
Less_Autoloader::register();
|
|
|
|
|
2021-11-03 19:48:30 +01:00
|
|
|
$options = array('cache_dir' => 'css/', 'compress' => true);
|
2021-10-19 17:07:51 +02:00
|
|
|
$cssFileName = Less_Cache::Get(array("style.less" => ""), $options, $colorScheme);
|
2020-03-06 21:34:31 +01:00
|
|
|
?>
|
2021-12-18 23:16:35 +01:00
|
|
|
<link rel="stylesheet" media="screen" href="css/<?= $cssFileName ?>">
|
2021-11-03 19:48:30 +01:00
|
|
|
<?php
|
2020-07-01 20:47:02 +02:00
|
|
|
foreach($themeDimensionsIcons as $dimFav) { // Set all icons dimensions
|
2022-02-18 17:15:43 +01:00
|
|
|
echo ' <link rel="icon" type="image/png" href="themes/' . THEME . '/icons/' . $dimFav . '.png" sizes="' . $dimFav . 'x' . $dimFav . '">' . "\n";
|
2021-11-03 19:48:30 +01:00
|
|
|
}
|
|
|
|
?>
|
2019-01-26 14:23:19 +01:00
|
|
|
</head>
|
|
|
|
|
2020-03-06 21:34:31 +01:00
|
|
|
<body>
|
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<header>
|
|
|
|
<a id="linkTitles" href="./">
|
|
|
|
<div id="titles">
|
|
|
|
<h1>LibreQR</h1>
|
|
|
|
<h2><?= $loc['subtitle'] ?></h2>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</header>
|
2019-01-26 14:23:19 +01:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<form method="post" action="./#output">
|
|
|
|
|
|
|
|
<div id="firstWrapper">
|
2019-08-13 21:17:08 +02:00
|
|
|
|
2022-03-03 18:26:21 +01: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>
|
2019-01-26 14:23:19 +01:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<div id="sideParams">
|
2019-08-13 21:17:08 +02:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<div class="param">
|
2021-11-06 00:33:15 +01:00
|
|
|
<details>
|
2022-03-03 18:26:21 +01:00
|
|
|
<summary><label for="redundancy"><?= $loc['label_redundancy'] ?></label></summary>
|
|
|
|
<p class="helpText">
|
|
|
|
<?= $loc['help_redundancy'] ?>
|
|
|
|
</p>
|
2021-11-06 00:33:15 +01:00
|
|
|
</details>
|
2022-03-03 18:26:21 +01:00
|
|
|
<select id="redundancy" name="redundancy">
|
|
|
|
<option <?php if ($params['redundancy'] === "low") echo 'selected="" '; ?>value="low">L - 7%</option>
|
|
|
|
<option <?php if ($params['redundancy'] === "medium") echo 'selected="" '; ?>value="medium">M - 15%</option>
|
|
|
|
<option <?php if ($params['redundancy'] === "quartile") echo 'selected="" '; ?>value="quartile">Q - 25%</option>
|
|
|
|
<option <?php if ($params['redundancy'] === "high") echo 'selected="" '; ?>value="high">H - 30%</option>
|
|
|
|
</select>
|
2019-03-17 16:03:43 +01:00
|
|
|
</div>
|
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<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>
|
2020-03-06 21:34:31 +01:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<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>
|
2019-03-17 16:03:43 +01:00
|
|
|
</div>
|
|
|
|
|
2020-03-06 21:34:31 +01:00
|
|
|
</div>
|
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
</div>
|
2020-03-06 21:34:31 +01:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<div id="colors">
|
2019-01-26 14:23:19 +01:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<div class="param">
|
|
|
|
<label for="bgColor"><?= $loc['label_bgColor'] ?></label>
|
|
|
|
<div class="inputColorContainer">
|
|
|
|
<input type="color" name="bgColor" id="bgColor" value="#<?= htmlspecialchars($params['bgColor']) ?>">
|
2020-03-06 21:34:31 +01:00
|
|
|
</div>
|
2019-03-17 16:03:43 +01:00
|
|
|
</div>
|
2019-08-13 21:17:08 +02:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<div class="param">
|
|
|
|
<label for="mainColor"><?= $loc['label_mainColor'] ?></label>
|
|
|
|
<div class="inputColorContainer">
|
|
|
|
<input type="color" name="mainColor" id="mainColor" value="#<?= htmlspecialchars($params['mainColor']) ?>">
|
|
|
|
</div>
|
2019-03-17 16:03:43 +01:00
|
|
|
</div>
|
2022-03-03 18:26:21 +01:00
|
|
|
</div>
|
2019-02-11 19:26:31 +01:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<div class="centered">
|
|
|
|
<input class="button" type="submit" value="<?= $loc['button_create'] ?>" />
|
|
|
|
</div>
|
2021-07-11 21:48:56 +02:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
</form>
|
2021-12-06 20:53:23 +01:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<?php
|
2021-12-06 20:53:23 +01:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
if ($validFormSubmitted) {
|
|
|
|
|
|
|
|
$rgbBgColor = array(
|
|
|
|
'r' => hexdec(substr($params['bgColor'],0,2)),
|
|
|
|
'g' => hexdec(substr($params['bgColor'],2,2)),
|
|
|
|
'b' => hexdec(substr($params['bgColor'],4,2)),
|
|
|
|
);
|
|
|
|
|
|
|
|
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['redundancy'])
|
|
|
|
->setForegroundColor(array(
|
|
|
|
'r' => hexdec(substr($params['mainColor'],0,2)),
|
|
|
|
'g' => hexdec(substr($params['mainColor'],2,2)),
|
|
|
|
'b' => hexdec(substr($params['mainColor'],4,2)),
|
|
|
|
))
|
|
|
|
->setBackgroundColor($rgbBgColor)
|
|
|
|
->setImageType(QrCode::IMAGE_TYPE_PNG);
|
|
|
|
$dataUri = $qrCode->getDataUri();
|
|
|
|
$qrSize = $qrCode->getSize() + 2 * $qrCode->getPadding();
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<section id="output">
|
|
|
|
<div class="centered" id="downloadQR">
|
|
|
|
<a href="<?= $dataUri ?>" class="button" download="<?= htmlspecialchars($params['txt']); ?>.png"><?= $loc['button_download'] ?></a>
|
|
|
|
</div>
|
2019-02-11 19:26:31 +01:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<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"<?php
|
2021-11-06 00:33:15 +01:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
// Compute the difference between the QR code and theme background colors
|
|
|
|
$diffLight = abs($rgbBgColor['r']-hexdec(substr($colorScheme['bg-light'],-6,2))) + abs($rgbBgColor['g']-hexdec(substr($colorScheme['bg-light'],-4,2))) + abs($rgbBgColor['b']-hexdec(substr($colorScheme['bg-light'],-2,2)));
|
|
|
|
$diffDark = abs($rgbBgColor['r']-hexdec(substr($colorScheme['bg-dark'],-6,2))) + abs($rgbBgColor['g']-hexdec(substr($colorScheme['bg-dark'],-4,2))) + abs($rgbBgColor['b']-hexdec(substr($colorScheme['bg-dark'],-2,2)));
|
2020-10-12 18:55:36 +02:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
// Determine whether a CSS corner is needed to let the user see the margin of the QR code
|
|
|
|
$contrastThreshold = 64;
|
|
|
|
if ($diffLight < $contrastThreshold)
|
|
|
|
echo " class='needLightContrast'";
|
|
|
|
if ($diffDark < $contrastThreshold)
|
|
|
|
echo " class='needDarkContrast'";
|
|
|
|
?> src="<?= $dataUri ?>"></a>
|
|
|
|
</div>
|
|
|
|
</section>
|
2020-10-12 18:55:36 +02:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<?php } ?>
|
2020-10-25 18:02:57 +01:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<footer>
|
|
|
|
|
|
|
|
<section id="info" class="metaText">
|
|
|
|
<?= $loc['metaText_qr'] ?>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<?php if (CUSTOM_TEXT_ENABLED) { ?>
|
2020-10-25 18:02:57 +01:00
|
|
|
<section class="metaText">
|
2022-03-03 18:26:21 +01:00
|
|
|
<?= CUSTOM_TEXT ?>
|
2020-10-25 18:02:57 +01:00
|
|
|
</section>
|
2022-03-03 18:26:21 +01:00
|
|
|
<?php } ?>
|
2020-10-25 18:02:57 +01:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
<section class="metaText">
|
|
|
|
<?= $loc['metaText_legal'] ?>
|
|
|
|
</section>
|
2020-10-12 18:55:36 +02:00
|
|
|
|
2022-03-03 18:26:21 +01:00
|
|
|
</footer>
|
2019-02-11 19:26:31 +01:00
|
|
|
|
2019-03-17 16:03:43 +01:00
|
|
|
</body>
|
|
|
|
</html>
|