PHP Web interface for generating QR codes
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.

51 lines
1.7 KiB

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