Un générateur de codes QR en PHP pour le Web. https://qr.antopie.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

285 lines
13 KiB

  1. <?php require "inc.php"; ?>
  2. <!--
  3. _ _ _ ___ ____
  4. | | (_| |__ _ __ ___ / _ \| _ \
  5. | | | | '_ \| '__/ _ | | | | |_) |
  6. | |___| | |_) | | | __| |_| | _ <
  7. |_____|_|_.__/|_| \___|\__\_|_| \_\
  8. A PHP Web interface for generating QR codes
  9. Source code : https://code.antopie.org/miraty/libreqr
  10. This file is part of LibreQR.
  11. LibreQR is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  12. LibreQR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
  13. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. -->
  15. <?php
  16. function badQuery() { // Check if browser must be redirected
  17. // Check if parameters are set
  18. if (!isset($_GET['txt']))
  19. return true;
  20. else if (!isset($_GET['size']))
  21. return true;
  22. else if (!isset($_GET['redondancy']))
  23. return true;
  24. else if (!isset($_GET['margin']))
  25. return true;
  26. else if (!isset($_GET['bgColor']))
  27. return true;
  28. else if (!isset($_GET['mainColor']))
  29. return true;
  30. // Check parameters's types
  31. else if (!is_numeric($_GET['size']))
  32. return true;
  33. else if (!is_string($_GET['redondancy']))
  34. return true;
  35. else if (!is_numeric($_GET['margin']))
  36. return true;
  37. else if (!is_string($_GET['bgColor']))
  38. return true;
  39. else if (!is_string($_GET['mainColor']))
  40. return true;
  41. // Check if redondancy value is correct
  42. else if ($_GET['redondancy'] != "L" AND $_GET['redondancy'] != "M" AND $_GET['redondancy'] != "Q" AND $_GET['redondancy'] != "H")
  43. return true;
  44. else
  45. return false;
  46. }
  47. if (badQuery()) {
  48. parse_str(parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY), $params);
  49. if (!isset($params['txt']))
  50. $params['txt'] = "";
  51. if (!isset($params['redondancy']) OR !is_string($params['redondancy']) OR ($params['redondancy'] != "L" AND $params['redondancy'] != "M" AND $params['redondancy'] != "Q" AND $params['redondancy'] != "H"))
  52. $params['redondancy'] = "H";
  53. if (!isset($params['margin']) OR !is_numeric($params['margin']))
  54. $params['margin'] = 2;
  55. if (!isset($params['size']) OR !is_numeric($params['size']))
  56. $params['size'] = 4;
  57. if (!isset($params['bgColor']) OR !is_string($params['bgColor']))
  58. $params['bgColor'] = "#FFFFFF";
  59. if (!isset($params['mainColor']) OR !is_string($params['mainColor']))
  60. $params['mainColor'] = "#000000";
  61. header('Location: ' . $instPath . "?" . http_build_query($params));
  62. exit;
  63. }
  64. ?>
  65. <!DOCTYPE html>
  66. <html lang="<?= $locale ?>">
  67. <head>
  68. <meta charset="UTF-8">
  69. <title>LibreQR · <?= $loc['subtitle'] ?></title>
  70. <meta name="description" content="<?= $loc['description'] ?>">
  71. <meta name="theme-color" content="<?php echo $variablesTheme['bg']; ?>">
  72. <meta name="viewport" content="width=device-width, initial-scale=1">
  73. <link rel="manifest" href="manifest.php">
  74. <link rel="search" type="application/opensearchdescription+xml" title="<?= $loc['opensearch_actionName'] ?>" href="opensearch.php&#63;redondancy=<?= $_GET['redondancy'] ?>&amp;margin=<?= $_GET['margin'] ?>&amp;size=<?= $_GET['size'] ?>&amp;bgColor=<?= urlencode($_GET['bgColor']) ?>&amp;mainColor=<?= urlencode($_GET['mainColor']) ?>">
  75. <?php
  76. // If style.min.css exists
  77. if (file_exists("style.min.css"))
  78. // And if it's older than theme.php or config.inc.php (so not up to date)
  79. if (filemtime("themes/" . $theme . "/theme.php") > filemtime("style.min.css") OR filemtime("config.inc.php") > filemtime("style.min.css"))
  80. // Then delete it
  81. unlink("style.min.css");
  82. require "lesserphp/lessc.inc.php";
  83. $less = new lessc;
  84. $less->setVariables($variablesTheme); // Make these colors available in style.less
  85. $less->setFormatter("compressed");
  86. $less->checkedCompile("style.less", "style.min.css"); // Compile, minimise and cache style.less into style.min.css
  87. ?>
  88. <link type="text/css" rel="stylesheet" href="style.min.css">
  89. <link type="text/css" rel="stylesheet" href="ubuntu/ubuntu.min.css">
  90. <?php
  91. foreach($themeDimensionsIcons as $dimFav) { // Set all icons dimensions
  92. echo ' <link rel="icon" type="image/png" href="themes/' . $theme . '/icons/' . $dimFav . '.png" sizes="' . $dimFav . 'x' . $dimFav . '">' . "\n";
  93. } ?>
  94. </head>
  95. <body>
  96. <main>
  97. <header>
  98. <a id="lienTitres" href="./">
  99. <img id="logo" src="themes/<?php echo $theme; ?>/icons/128.png">
  100. <div id="titres">
  101. <h1>LibreQR</h1>
  102. <h2><?= $loc['subtitle'] ?></h2>
  103. </div>
  104. </a>
  105. </header>
  106. <form method="get" action="./">
  107. <div id="firstWrapper">
  108. <div class="param">
  109. <label for="txt"><?= $loc['label_content'] ?></label>
  110. <span class="conteneurAide">
  111. <span class="boutonAide" tabindex="0"><img class="helpImg" src="help.svg.php?clr=<?= urlencode($variablesTheme["text"]) ?>" alt="Aide"></span>
  112. <span class="contenuAide">
  113. <?= $loc['help_content'] ?>
  114. </span>
  115. </span>
  116. <br>
  117. <textarea rows="8" required="" id="txt" placeholder="<?= $loc['placeholder'] ?>" name="txt"><?php
  118. if (isset($_GET['txt'])) {
  119. echo htmlspecialchars($_GET['txt']);
  120. }
  121. ?></textarea>
  122. </div>
  123. <div id="menusDeroulants">
  124. <div class="param">
  125. <label for="redondancy"><?= $loc['label_redondancy'] ?></label>
  126. <span class="conteneurAide">
  127. <span class="boutonAide" tabindex="0"><img class="helpImg" src="help.svg.php?clr=<?= urlencode($variablesTheme["text"]) ?>" alt="Aide"></span>
  128. <span class="contenuAide"><?= $loc['help_redondancy'] ?></span>
  129. </span>
  130. <br>
  131. <select id="redondancy" name="redondancy">
  132. <option <?php if (isset($_GET['redondancy']) AND ($_GET['redondancy'] == "L")) {echo 'selected="" ';} ?>value="L">L - 7%</option>
  133. <option <?php if (isset($_GET['redondancy']) AND ($_GET['redondancy'] == "M")) {echo 'selected="" ';} ?>value="M">M - 15%</option>
  134. <option <?php if (isset($_GET['redondancy']) AND ($_GET['redondancy'] == "Q")) {echo 'selected="" ';} ?>value="Q">Q - 25%</option>
  135. <option <?php if ((isset($_GET['redondancy']) AND ($_GET['redondancy'] == "H")) OR (!isset($_GET['redondancy']) OR empty($_GET['redondancy']))) {echo 'selected="" ';} ?>value="H">H - 30%</option>
  136. </select>
  137. </div>
  138. <div class="param">
  139. <label for="margin"><?= $loc['label_margin'] ?></label>
  140. <span class="conteneurAide">
  141. <span class="boutonAide" tabindex="0"><img class="helpImg" src="help.svg.php?clr=<?= urlencode($variablesTheme["text"]) ?>" alt="Aide"></span>
  142. <span class="contenuAide"><?= $loc['help_margin'] ?></span>
  143. </span>
  144. <br>
  145. <select id="margin" name="margin">
  146. <option <?php if (isset($_GET['margin']) AND ($_GET['margin'] == "0")) {echo 'selected="" ';} ?>value="0">0</option>
  147. <option <?php if (isset($_GET['margin']) AND ($_GET['margin'] == "1")) {echo 'selected="" ';} ?>value="1">1</option>
  148. <option <?php if ((isset($_GET['margin']) AND ($_GET['margin'] == "2")) OR (!isset($_GET['margin']) OR empty($_GET['margin']))) {echo 'selected="" ';} ?>value="2">2 - <?= $loc['value_default'] ?></option>
  149. <option <?php if (isset($_GET['margin']) AND ($_GET['margin'] == "3")) {echo 'selected="" ';} ?>value="3">3</option>
  150. <option <?php if (isset($_GET['margin']) AND ($_GET['margin'] == "4")) {echo 'selected="" ';} ?>value="4">4</option>
  151. <option <?php if (isset($_GET['margin']) AND ($_GET['margin'] == "5")) {echo 'selected="" ';} ?>value="5">5</option>
  152. <option <?php if (isset($_GET['margin']) AND ($_GET['margin'] == "8")) {echo 'selected="" ';} ?>value="8">8</option>
  153. <option <?php if (isset($_GET['margin']) AND ($_GET['margin'] == "10")) {echo 'selected="" ';} ?>value="10">10</option>
  154. </select>
  155. </div>
  156. <div class="param">
  157. <label for="size"><?= $loc['label_size'] ?></label>
  158. <span class="conteneurAide">
  159. <span class="boutonAide" tabindex="0"><img class="helpImg" src="help.svg.php?clr=<?= urlencode($variablesTheme["text"]) ?>" alt="Aide"></span>
  160. <span class="contenuAide"><?= $loc['help_size'] ?></span>
  161. </span>
  162. <br>
  163. <select id="size" name="size">
  164. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 1)) {echo 'selected="" ';} ?>value="1">1</option>
  165. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 2)) {echo 'selected="" ';} ?>value="2">2</option>
  166. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 3)) {echo 'selected="" ';} ?>value="3">3</option>
  167. <option <?php if ((isset($_GET['size']) AND ($_GET['size'] == 4)) OR (!isset($_GET['size']) OR empty($_GET['size']))) {echo 'selected="" ';} ?>value="4">4 - <?= $loc['value_default'] ?></option>
  168. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 5)) {echo 'selected="" ';} ?>value="5">5</option>
  169. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 6)) {echo 'selected="" ';} ?>value="6">6</option>
  170. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 8)) {echo 'selected="" ';} ?>value="8">8</option>
  171. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 10)) {echo 'selected="" ';} ?>value="10">10</option>
  172. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 15)) {echo 'selected="" ';} ?>value="15">15</option>
  173. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 20)) {echo 'selected="" ';} ?>value="20">20</option>
  174. </select>
  175. </div>
  176. </div>
  177. </div>
  178. <div id="colors">
  179. <div class="param">
  180. <label for="bgColor"><?= $loc['label_bgColor'] ?></label>
  181. <div class="conteneurInputColor">
  182. <input type="color" name="bgColor" id="bgColor" value="<?php if (!empty($_GET['bgColor'])) {echo htmlspecialchars($_GET['bgColor']);} else {echo "#FFFFFF";} ?>">
  183. </div>
  184. </div>
  185. <div class="param">
  186. <label for="mainColor"><?= $loc['label_mainColor'] ?></label>
  187. <div class="conteneurInputColor">
  188. <input type="color" name="mainColor" id="mainColor" value="<?php if (!empty($_GET['mainColor'])) {echo htmlspecialchars($_GET['mainColor']);} else {echo "#000000";} ?>">
  189. </div>
  190. </div>
  191. </div>
  192. <div class="centered">
  193. <input class="bouton" type="submit" value="<?= $loc['button_create'] ?>" />
  194. </div>
  195. </form>
  196. <?php
  197. if (!empty($_GET['txt']) AND !empty($_GET['size']) AND !empty($_GET['redondancy']) AND !empty($_GET['margin']) AND !empty($_GET['bgColor']) AND !empty($_GET['mainColor'])) {
  198. if (isset($_GET['txt']) AND isset($_GET['size']) AND isset($_GET['redondancy']) AND isset($_GET['margin']) AND isset($_GET['bgColor']) AND isset($_GET['mainColor'])) {
  199. require "phpqrcode.php";
  200. $cheminImage = "temp/" . generateRandomString($fileNameLenght) . ".png";
  201. QRcode::png($_GET['txt'], $cheminImage, $_GET['redondancy'], $_GET['size'], $_GET['margin'], false, hexdec($_GET['bgColor']), hexdec($_GET['mainColor']));
  202. ?>
  203. <div class="centered">
  204. <a href="<?php echo $cheminImage; ?>" class="bouton" download="<?php echo htmlspecialchars($_GET['txt']); ?>.png"><?= $loc['button_download'] ?></a>
  205. </div>
  206. <div class="centered" id="showOnlyQR">
  207. <a title="<?= $loc['title_showOnlyQR'] ?>" href="<?php echo $cheminImage; ?>"><img alt='Un code QR contenant "<?php echo htmlspecialchars($_GET['txt']); ?>"' id="qrCode" src="<?php echo $cheminImage; ?>"/></a>
  208. </div>
  209. <?php
  210. }
  211. }
  212. ?>
  213. <div id="metaTexts">
  214. <section id="info" class="metaText">
  215. <?= $loc['metaText_qr'] ?>
  216. </section>
  217. <footer class="metaText">
  218. <p>
  219. <?= $loc['metaText_legal'] ?>
  220. </p>
  221. <?php if (isset($customText)) { ?>
  222. <br>
  223. <p>
  224. <?= $customText ?>
  225. </p>
  226. <?php } ?>
  227. </footer>
  228. </div>
  229. </main>
  230. </body>
  231. </html>