XOOPS  2.6.0
qrrender.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  */
11 
13 
21 // this is located in include, otherwise normal/anon users do not have authority to run
22 include dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
23 
24 $xoops = Xoops::getinstance();
25 $xoops->logger()->quiet();
26 
27 $text = Request::getString('text', 'error');
28 
29 $configs = $xoops->getModuleConfigs('qrcode');
30 
31 $qrCode = new Endroid\QrCode\QrCode($text);
32 
33 $ecChar = $configs['qrcode_ecl'];
34 switch (strtoupper($ecChar)) {
35  case 'H':
36  $ec = Endroid\QrCode\QrCode::LEVEL_HIGH;
37  break;
38  case 'Q':
39  $ec = Endroid\QrCode\QrCode::LEVEL_QUARTILE;
40  break;
41  case 'M':
42  $ec = Endroid\QrCode\QrCode::LEVEL_MEDIUM;
43  break;
44  case 'L':
45  default:
46  $ec = Endroid\QrCode\QrCode::LEVEL_LOW;
47  break;
48 }
49 $qrCode->setErrorCorrection($ec);
50 $qrCode->setModuleSize(intval($configs['qrcode_mps'])-1);
51 $qrCode->setPadding($configs['qrcode_margin']*$qrCode->getModuleSize());
52 $qrCode->setBackgroundColor(normalizeColor($configs['qrcode_bgcolor']));
53 $qrCode->setForegroundColor(normalizeColor($configs['qrcode_fgcolor']));
54 
55 //$qrCode->setText("Life is too short to be generating QR codes");
56 //$qrCode->setSize(300);
57 
58 try {
59  $qrData = $qrCode->get('png');
60 } catch (\Exception $e) {
61  $xoopsPreload->triggerEvent('core.exception', $e);
62  $qrData = '';
63 }
64 
65 $mimetype = \Xoops\Core\MimeTypes::findType('png');
66 $expires = 60*60*24*15; // seconds, minutes, hours, days
67 header("Cache-Control: public, max-age=" . $expires);
68 header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
69 //header('Last-Modified: ' . gmdate('D, d M Y H:i:s T', $mtime));
70 header('Content-type: ' . $mimetype);
71 echo $qrData;
72 exit;
73 
81 function normalizeColor($color)
82 {
83  $color = preg_replace('/[^a-fA-F0-9]+/', '', $color); // only hex digits
84  $color = substr('000000'.$color, -6); // only 6 digits, pad with leading zeros
85  $rgb = array(
86  'r' => hexdec(substr($color, 0, 2)),
87  'g' => hexdec(substr($color, 2, 2)),
88  'b' => hexdec(substr($color, 4, 2)),
89  );
90  return $rgb;
91 }
$ecChar
Definition: qrrender.php:33
$expires
Definition: qrrender.php:66
exit
Definition: qrrender.php:71
catch(\Exception $e) $mimetype
Definition: qrrender.php:65
$xoops
Definition: qrrender.php:24
$text
Definition: qrrender.php:27
$configs
Definition: qrrender.php:29
normalizeColor($color)
Definition: qrrender.php:81
$qrCode
Definition: qrrender.php:31