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.

297 lines
13KB

  1. <?php require "inc.php"; ?>
  2. <!--
  3. _ _ _ ___ ____
  4. | | (_| |__ _ __ ___ / _ \| _ \
  5. | | | | '_ \| '__/ _ | | | | |_) |
  6. | |___| | |_) | | | __| |_| | _ <
  7. |_____|_|_.__/|_| \___|\__\_|_| \_\
  8. LibreQR version 1.2.0
  9. Créé par Miraty et diffusé sous AGPLv3+
  10. Code source : https://code.antopie.org/miraty/libreqr
  11. Ce fichier fait partie de LibreQR.
  12. LibreQR est un logiciel libre ; vous pouvez le redistribuer ou le modifier
  13. suivant les termes de la GNU Affero General Public License
  14. telle que publiée par la Free Software Foundation ; soit la version 3
  15. de la licence, soit (à votre gré) toute version ultérieure.
  16. LibreQR est distribué dans l'espoir qu'il sera utile,
  17. mais SANS AUCUNE GARANTIE ; sans même la garantie tacite de
  18. QUALITÉ MARCHANDE ou d'ADÉQUATION à UN BUT PARTICULIER.
  19. Consultez la GNU Affero General Public License pour plus de détails.
  20. Vous devez avoir reçu une copie de la GNU Affero General Public License
  21. en même temps que LibreQR ; si ce n'est pas le cas,
  22. consultez <https://www.gnu.org/licenses/>.
  23. -->
  24. <?php
  25. function badQuery() { // Check if browser must be redirected
  26. // Check if parameters are set
  27. if (!isset($_GET['txt']))
  28. return true;
  29. else if (!isset($_GET['size']))
  30. return true;
  31. else if (!isset($_GET['redondancy']))
  32. return true;
  33. else if (!isset($_GET['margin']))
  34. return true;
  35. else if (!isset($_GET['bgColor']))
  36. return true;
  37. else if (!isset($_GET['mainColor']))
  38. return true;
  39. // Check parameters's types
  40. else if (!is_numeric($_GET['size']))
  41. return true;
  42. else if (!is_string($_GET['redondancy']))
  43. return true;
  44. else if (!is_numeric($_GET['margin']))
  45. return true;
  46. else if (!is_string($_GET['bgColor']))
  47. return true;
  48. else if (!is_string($_GET['mainColor']))
  49. return true;
  50. // Check if redondancy value is correct
  51. else if ($_GET['redondancy'] != "L" AND $_GET['redondancy'] != "M" AND $_GET['redondancy'] != "Q" AND $_GET['redondancy'] != "H")
  52. return true;
  53. else
  54. return false;
  55. }
  56. if (badQuery()) {
  57. parse_str(parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY), $params);
  58. if (!isset($params['txt']))
  59. $params['txt'] = "";
  60. 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"))
  61. $params['redondancy'] = "H";
  62. if (!isset($params['margin']) OR !is_numeric($params['margin']))
  63. $params['margin'] = 2;
  64. if (!isset($params['size']) OR !is_numeric($params['size']))
  65. $params['size'] = 4;
  66. if (!isset($params['bgColor']) OR !is_string($params['bgColor']))
  67. $params['bgColor'] = "#FFFFFF";
  68. if (!isset($params['mainColor']) OR !is_string($params['mainColor']))
  69. $params['mainColor'] = "#000000";
  70. header('Location: ' . $instPath . "?" . http_build_query($params));
  71. exit;
  72. }
  73. ?>
  74. <!DOCTYPE html>
  75. <html lang="<?= $locale ?>">
  76. <head>
  77. <meta charset="UTF-8">
  78. <title>LibreQR · <?= $loc['subtitle'] ?></title>
  79. <meta name="description" content="<?= $loc['description'] ?>">
  80. <meta name="theme-color" content="<?php echo $variablesTheme['bg']; ?>">
  81. <meta name="viewport" content="width=device-width, initial-scale=1">
  82. <link rel="manifest" href="manifest.php">
  83. <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']) ?>">
  84. <?php
  85. // If style.min.css exists
  86. if (file_exists("style.min.css"))
  87. // And if it's older than theme.php or config.inc.php (so not up to date)
  88. if (filemtime("themes/" . $theme . "/theme.php") > filemtime("style.min.css") OR filemtime("config.inc.php") > filemtime("style.min.css"))
  89. // Then delete it
  90. unlink("style.min.css");
  91. require "lesserphp/lessc.inc.php";
  92. $less = new lessc;
  93. $less->setVariables($variablesTheme); // Make these colors available in style.less
  94. $less->setFormatter("compressed");
  95. $less->checkedCompile("style.less", "style.min.css"); // Compile, minimise and cache style.less into style.min.css
  96. ?>
  97. <link type="text/css" rel="stylesheet" href="style.min.css">
  98. <link type="text/css" rel="stylesheet" href="ubuntu/ubuntu.min.css">
  99. <?php
  100. foreach($themeDimensionsIcons as $dimFav) { // Set all icons dimensions
  101. echo ' <link rel="icon" type="image/png" href="themes/' . $theme . '/icons/' . $dimFav . '.png" sizes="' . $dimFav . 'x' . $dimFav . '">' . "\n";
  102. } ?>
  103. </head>
  104. <body>
  105. <main>
  106. <header>
  107. <a id="lienTitres" href="./">
  108. <img id="logo" src="themes/<?php echo $theme; ?>/icons/128.png">
  109. <div id="titres">
  110. <h1>LibreQR</h1>
  111. <h2><?= $loc['subtitle'] ?></h2>
  112. </div>
  113. </a>
  114. </header>
  115. <form method="get" action="./">
  116. <div id="firstWrapper">
  117. <div class="param">
  118. <label for="txt"><?= $loc['label_content'] ?></label>
  119. <span class="conteneurAide">
  120. <span class="boutonAide" tabindex="0"><img id="helpImg" src="help.svg.php?clr=<?= urlencode($variablesTheme["text"]) ?>" alt="Aide"></span>
  121. <span class="contenuAide">
  122. <?= $loc['help_content'] ?>
  123. </span>
  124. </span>
  125. <br>
  126. <textarea rows="8" required="" id="txt" placeholder="<?= $loc['placeholder'] ?>" name="txt"><?php
  127. if (isset($_GET['txt'])) {
  128. echo htmlspecialchars($_GET['txt']);
  129. }
  130. ?></textarea>
  131. </div>
  132. <div id="menusDeroulants">
  133. <div class="param">
  134. <label for="redondancy"><?= $loc['label_redondancy'] ?></label>
  135. <span class="conteneurAide">
  136. <span class="boutonAide" tabindex="0"><img id="helpImg" src="help.svg.php?clr=<?= urlencode($variablesTheme["text"]) ?>" alt="Aide"></span>
  137. <span class="contenuAide"><?= $loc['help_redondancy'] ?></span>
  138. </span>
  139. <br>
  140. <select id="redondancy" name="redondancy">
  141. <option <?php if (isset($_GET['redondancy']) AND ($_GET['redondancy'] == "L")) {echo 'selected="" ';} ?>value="L">L - 7%</option>
  142. <option <?php if (isset($_GET['redondancy']) AND ($_GET['redondancy'] == "M")) {echo 'selected="" ';} ?>value="M">M - 15%</option>
  143. <option <?php if (isset($_GET['redondancy']) AND ($_GET['redondancy'] == "Q")) {echo 'selected="" ';} ?>value="Q">Q - 25%</option>
  144. <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>
  145. </select>
  146. </div>
  147. <div class="param">
  148. <label for="margin"><?= $loc['label_margin'] ?></label>
  149. <span class="conteneurAide">
  150. <span class="boutonAide" tabindex="0"><img id="helpImg" src="help.svg.php?clr=<?= urlencode($variablesTheme["text"]) ?>" alt="Aide"></span>
  151. <span class="contenuAide"><?= $loc['help_margin'] ?></span>
  152. </span>
  153. <br>
  154. <select id="margin" name="margin">
  155. <option <?php if (isset($_GET['margin']) AND ($_GET['margin'] == "0")) {echo 'selected="" ';} ?>value="0">0</option>
  156. <option <?php if (isset($_GET['margin']) AND ($_GET['margin'] == "1")) {echo 'selected="" ';} ?>value="1">1</option>
  157. <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>
  158. <option <?php if (isset($_GET['margin']) AND ($_GET['margin'] == "3")) {echo 'selected="" ';} ?>value="3">3</option>
  159. <option <?php if (isset($_GET['margin']) AND ($_GET['margin'] == "4")) {echo 'selected="" ';} ?>value="4">4</option>
  160. <option <?php if (isset($_GET['margin']) AND ($_GET['margin'] == "5")) {echo 'selected="" ';} ?>value="5">5</option>
  161. <option <?php if (isset($_GET['margin']) AND ($_GET['margin'] == "8")) {echo 'selected="" ';} ?>value="8">8</option>
  162. <option <?php if (isset($_GET['margin']) AND ($_GET['margin'] == "10")) {echo 'selected="" ';} ?>value="10">10</option>
  163. </select>
  164. </div>
  165. <div class="param">
  166. <label for="size"><?= $loc['label_size'] ?></label>
  167. <span class="conteneurAide">
  168. <span class="boutonAide" tabindex="0"><img id="helpImg" src="help.svg.php?clr=<?= urlencode($variablesTheme["text"]) ?>" alt="Aide"></span>
  169. <span class="contenuAide"><?= $loc['help_size'] ?></span>
  170. </span>
  171. <br>
  172. <select id="size" name="size">
  173. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 1)) {echo 'selected="" ';} ?>value="1">1</option>
  174. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 2)) {echo 'selected="" ';} ?>value="2">2</option>
  175. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 3)) {echo 'selected="" ';} ?>value="3">3</option>
  176. <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>
  177. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 5)) {echo 'selected="" ';} ?>value="5">5</option>
  178. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 6)) {echo 'selected="" ';} ?>value="6">6</option>
  179. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 8)) {echo 'selected="" ';} ?>value="8">8</option>
  180. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 10)) {echo 'selected="" ';} ?>value="10">10</option>
  181. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 15)) {echo 'selected="" ';} ?>value="15">15</option>
  182. <option <?php if (isset($_GET['size']) AND ($_GET['size'] == 20)) {echo 'selected="" ';} ?>value="20">20</option>
  183. </select>
  184. </div>
  185. </div>
  186. </div>
  187. <div id="colors">
  188. <div class="param">
  189. <label for="bgColor"><?= $loc['label_bgColor'] ?></label>
  190. <div class="conteneurInputColor">
  191. <input type="color" name="bgColor" id="bgColor" value="<?php if (!empty($_GET['bgColor'])) {echo htmlspecialchars($_GET['bgColor']);} else {echo "#FFFFFF";} ?>">
  192. </div>
  193. </div>
  194. <div class="param">
  195. <label for="mainColor"><?= $loc['label_mainColor'] ?></label>
  196. <div class="conteneurInputColor">
  197. <input type="color" name="mainColor" id="mainColor" value="<?php if (!empty($_GET['mainColor'])) {echo htmlspecialchars($_GET['mainColor']);} else {echo "#000000";} ?>">
  198. </div>
  199. </div>
  200. </div>
  201. <div class="centered">
  202. <input class="bouton" type="submit" value="<?= $loc['button_create'] ?>" />
  203. </div>
  204. </form>
  205. <?php
  206. if (!empty($_GET['txt']) AND !empty($_GET['size']) AND !empty($_GET['redondancy']) AND !empty($_GET['margin']) AND !empty($_GET['bgColor']) AND !empty($_GET['mainColor'])) {
  207. if (isset($_GET['txt']) AND isset($_GET['size']) AND isset($_GET['redondancy']) AND isset($_GET['margin']) AND isset($_GET['bgColor']) AND isset($_GET['mainColor'])) {
  208. require "phpqrcode.php";
  209. $cheminImage = "temp/" . generateRandomString($fileNameLenght) . ".png";
  210. QRcode::png($_GET['txt'], $cheminImage, $_GET['redondancy'], $_GET['size'], $_GET['margin'], false, hexdec($_GET['bgColor']), hexdec($_GET['mainColor']));
  211. ?>
  212. <div class="centered">
  213. <a href="<?php echo $cheminImage; ?>" class="bouton" download="<?php echo htmlspecialchars($_GET['txt']); ?>.png"><?= $loc['button_download'] ?></a>
  214. </div>
  215. <div class="centered" id="showOnlyQR">
  216. <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>
  217. </div>
  218. <?php
  219. }
  220. }
  221. ?>
  222. </main>
  223. <div id="metaTexts">
  224. <section id="info" class="metaText">
  225. <?= $loc['metaText_qr'] ?>
  226. </section>
  227. <footer class="metaText">
  228. <p>
  229. <?= $loc['metaText_legal'] ?>
  230. </p>
  231. <?php if (isset($additionalText)) { ?>
  232. <br>
  233. <p>
  234. <?= $additionalText ?>
  235. </p>
  236. <?php } ?>
  237. </footer>
  238. </div>
  239. </body>
  240. </html>