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.

52 lines
1.7 KiB

  1. <?php // ----- This file is included everywhere -----
  2. require "config.inc.php";
  3. // Defines the locale used
  4. if ($forceLocale == false) {
  5. $clientLocales = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  6. $clientLocales = preg_replace("#[A-Z0-9]|q=|;|-|\.#", "", $clientLocales);
  7. $clientLocales = explode(',', $clientLocales);
  8. $availableLocales = array('fr', 'en', 'template');
  9. foreach ($clientLocales as $clientLocale) {
  10. if (in_array($clientLocale, $availableLocales)) {
  11. $locale = $clientLocale;
  12. break;
  13. }
  14. }
  15. }
  16. require "locales/" . $locale . ".php";
  17. // Defines the root URL
  18. if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')
  19. $protocol = "https";
  20. else
  21. $protocol = "http";
  22. $rootPath = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  23. $rootPath = preg_replace('#\?.*$#', '', $rootPath);
  24. $rootPath = preg_replace('#(manifest|opensearch|index).php$#i', '', $rootPath);
  25. require "themes/" . $theme . "/theme.php"; // Load theme
  26. // Used to generate the filename of the QR code
  27. function generateRandomString($length) {
  28. $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  29. $charactersLength = strlen($characters);
  30. $randomString = '';
  31. for ($i = 0; $i < $length; $i++) {
  32. $randomString .= $characters[rand(0, $charactersLength - 1)];
  33. }
  34. return $randomString;
  35. }
  36. // Deletes images in temp/ older than the specified time in seconds
  37. function deleteOldQR($deleteAfter) {
  38. $files = array_diff(scandir("temp"), array('..', '.', '.gitkeep'));
  39. foreach($files as $file) {
  40. // If this actual time (in Posix time) less last modification image date is greater than time asked
  41. if ((time() - filemtime("temp/" . $file)) > $deleteAfter) {
  42. unlink("temp/" . $file); // Deletes this image
  43. }
  44. }
  45. }