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.
 
 
 
 
 
 

97 lines
2.6 KiB

  1. <?php
  2. define('IN_CB', true);
  3. include_once('include/function.php');
  4. function showError() {
  5. header('Content-Type: image/png');
  6. readfile('error.png');
  7. exit;
  8. }
  9. $requiredKeys = array('code', 'filetype', 'dpi', 'scale', 'rotation', 'font_family', 'font_size', 'text');
  10. // Check if everything is present in the request
  11. foreach ($requiredKeys as $key) {
  12. if (!isset($_GET[$key])) {
  13. showError();
  14. }
  15. }
  16. if (!preg_match('/^[A-Za-z0-9]+$/', $_GET['code'])) {
  17. showError();
  18. }
  19. $code = $_GET['code'];
  20. // Check if the code is valid
  21. if (!file_exists('config' . DIRECTORY_SEPARATOR . $code . '.php')) {
  22. showError();
  23. }
  24. include_once('config' . DIRECTORY_SEPARATOR . $code . '.php');
  25. $class_dir = '..' . DIRECTORY_SEPARATOR . 'class';
  26. require_once($class_dir . DIRECTORY_SEPARATOR . 'BCGColor.php');
  27. require_once($class_dir . DIRECTORY_SEPARATOR . 'BCGBarcode.php');
  28. require_once($class_dir . DIRECTORY_SEPARATOR . 'BCGDrawing.php');
  29. require_once($class_dir . DIRECTORY_SEPARATOR . 'BCGFontFile.php');
  30. if (!include_once($class_dir . DIRECTORY_SEPARATOR . $classFile)) {
  31. showError();
  32. }
  33. include_once('config' . DIRECTORY_SEPARATOR . $baseClassFile);
  34. $filetypes = array('PNG' => BCGDrawing::IMG_FORMAT_PNG, 'JPEG' => BCGDrawing::IMG_FORMAT_JPEG, 'GIF' => BCGDrawing::IMG_FORMAT_GIF);
  35. $drawException = null;
  36. try {
  37. $color_black = new BCGColor(0, 0, 0);
  38. $color_white = new BCGColor(255, 255, 255);
  39. $code_generated = new $className();
  40. if (function_exists('baseCustomSetup')) {
  41. baseCustomSetup($code_generated, $_GET);
  42. }
  43. if (function_exists('customSetup')) {
  44. customSetup($code_generated, $_GET);
  45. }
  46. $code_generated->setScale(max(1, min(4, $_GET['scale'])));
  47. $code_generated->setBackgroundColor($color_white);
  48. $code_generated->setForegroundColor($color_black);
  49. if ($_GET['text'] !== '') {
  50. $text = convertText($_GET['text']);
  51. $code_generated->parse($text);
  52. }
  53. } catch(Exception $exception) {
  54. $drawException = $exception;
  55. }
  56. $drawing = new BCGDrawing('', $color_white);
  57. if($drawException) {
  58. $drawing->drawException($drawException);
  59. } else {
  60. $drawing->setBarcode($code_generated);
  61. $drawing->setRotationAngle($_GET['rotation']);
  62. $drawing->setDPI($_GET['dpi'] === 'NULL' ? null : max(72, min(300, intval($_GET['dpi']))));
  63. $drawing->draw();
  64. }
  65. switch ($_GET['filetype']) {
  66. case 'PNG':
  67. header('Content-Type: image/png');
  68. break;
  69. case 'JPEG':
  70. header('Content-Type: image/jpeg');
  71. break;
  72. case 'GIF':
  73. header('Content-Type: image/gif');
  74. break;
  75. }
  76. $drawing->finish($filetypes[$_GET['filetype']]);
  77. ?>