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.

49 lines
1.6KB

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