From 863364ac0e9a4f705898b2b3a4f5b2eba9b3fabb Mon Sep 17 00:00:00 2001
From: Hugo A
Date: Mon, 15 Aug 2022 12:06:27 +0200
Subject: [PATCH] branche initiale
---
index.php | 334 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 334 insertions(+)
create mode 100755 index.php
diff --git a/index.php b/index.php
new file mode 100755
index 0000000..e199ba6
--- /dev/null
+++ b/index.php
@@ -0,0 +1,334 @@
+ $localeFile)
+ $availableLocales[$key] = basename($localeFile, ".php");
+ foreach ($clientLocales as $clientLocale) {
+ if (in_array($clientLocale, $availableLocales)) {
+ $locale = $clientLocale;
+ break;
+ }
+ }
+}
+require "locales/" . $locale . ".php";
+
+$params = array(
+ "txt" => "",
+ "redundancy" => DEFAULT_REDUNDANCY,
+ "margin" => DEFAULT_MARGIN,
+ "size" => DEFAULT_SIZE,
+ "bgColor" => DEFAULT_BGCOLOR,
+ "fgColor" => DEFAULT_FGCOLOR,
+);
+
+$qrCodeAvailable = NULL;
+
+if (
+ isset($_POST['txt'])
+ AND isset($_POST['redundancy'])
+ AND isset($_POST['margin'])
+ AND isset($_POST['size'])
+ AND isset($_POST['bgColor'])
+ AND isset($_POST['fgColor'])
+) {
+
+ $qrCodeAvailable = true;
+
+ if (strlen($_POST['txt']) >= 1 AND strlen($_POST['txt']) <= 4096) {
+ $params['txt'] = $_POST['txt'];
+ } else {
+ http_response_code(400);
+ exit("Wrong value for txt");
+ }
+
+ if ($_POST['redundancy'] === "low" OR $_POST['redundancy'] === "medium" OR $_POST['redundancy'] === "quartile" OR $_POST['redundancy'] === "high") {
+ $params['redundancy'] = $_POST['redundancy'];
+ } else {
+ http_response_code(400);
+ exit("Wrong value for redundancy");
+ }
+
+ if (is_numeric($_POST['margin']) AND $_POST['margin'] >= 0 AND $_POST['margin'] <= 1024) {
+ $params['margin'] = $_POST['margin'];
+ } else if (empty($_POST['margin'])) {
+ $params['margin'] = NULL;
+ } else {
+ http_response_code(400);
+ exit("Wrong value for margin");
+ }
+
+ if (is_numeric($_POST['size']) AND $_POST['size'] >= 25 AND $_POST['size'] <= 4096) {
+ $params['size'] = $_POST['size'];
+ } else if (empty($_POST['size'])) {
+ $params['size'] = NULL;
+ } else {
+ http_response_code(400);
+ exit("Wrong value for size");
+ }
+
+ if (preg_match("/^#[abcdefABCDEF0-9]{6}$/", $_POST['bgColor'])) {
+ $params['bgColor'] = substr($_POST['bgColor'], -6);
+ } else {
+ http_response_code(400);
+ exit("Wrong value for bgColor");
+ }
+
+ if (preg_match("/^#[abcdefABCDEF0-9]{6}$/", $_POST['fgColor'])) {
+ $params['fgColor'] = substr($_POST['fgColor'], -6);
+ } else {
+ http_response_code(400);
+ exit("Wrong value for fgColor");
+ }
+
+ $validFormSubmitted = true;
+
+ $rgbBgColor = array(
+ 'r' => hexdec(substr($params['bgColor'],0,2)),
+ 'g' => hexdec(substr($params['bgColor'],2,2)),
+ 'b' => hexdec(substr($params['bgColor'],4,2)),
+ );
+
+ $qrCode = Builder::create()
+ ->data($params['txt']);
+ if (!is_null($params['margin']))
+ $qrCode->margin($params['margin']);
+ if (!is_null($params['size']))
+ $qrCode->size($params['size']);
+
+ if ($params['redundancy'] === "high")
+ $qrCode->errorCorrectionLevel(new ErrorCorrectionLevelHigh());
+ else if ($params['redundancy'] === "quartile")
+ $qrCode->errorCorrectionLevel(new ErrorCorrectionLevelQuartile());
+ else if ($params['redundancy'] === "medium")
+ $qrCode->errorCorrectionLevel(new ErrorCorrectionLevelMedium());
+ else if ($params['redundancy'] === "low")
+ $qrCode->errorCorrectionLevel(new ErrorCorrectionLevelLow());
+
+ $qrCode
+ ->backgroundColor(new Color(
+ $rgbBgColor['r'],
+ $rgbBgColor['g'],
+ $rgbBgColor['b']
+ ))
+ ->foregroundColor(new Color(
+ hexdec(substr($params['fgColor'],0,2)),
+ hexdec(substr($params['fgColor'],2,2)),
+ hexdec(substr($params['fgColor'],4,2))
+ ));
+
+ try {
+ $result = $qrCode->build();
+ } catch (Exception $ex) {
+ http_response_code(500);
+ $qrCodeAvailable = false;
+ error_log("LibreQR encountered an error while generating a QR code: " . $ex);
+ }
+}
+
+?>
+
+
+
+
+ LibreQR · = $loc['subtitle'] ?>
+
+
+
+
+
+
+
+ 'css/', 'compress' => true);
+$cssFileName = Less_Cache::Get(array("style.less" => ""), $options, $colorScheme);
+?>
+
+' . "\n";
+?>
+
+
+
+
+
+
+
+
+getDataUri();
+
+ $qrSize = $params['size'] + 2 * $params['margin'];
+
+?>
+
+
+
+" . $loc['error_generation'] . "
";
+}
+?>
+
+
+
+