]> git.wh0rd.org - tt-rss.git/blame - lib/phpqrcode/index.php
first stage of headline element handling refactoring
[tt-rss.git] / lib / phpqrcode / index.php
CommitLineData
fb70f26e
AD
1<?php
2/*\r
3 * PHP QR Code encoder\r
4 *\r
5 * Exemplatory usage\r
6 *\r
7 * PHP QR Code is distributed under LGPL 3\r
8 * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>\r
9 *\r
10 * This library is free software; you can redistribute it and/or\r
11 * modify it under the terms of the GNU Lesser General Public\r
12 * License as published by the Free Software Foundation; either\r
13 * version 3 of the License, or any later version.\r
14 *\r
15 * This library is distributed in the hope that it will be useful,\r
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
18 * Lesser General Public License for more details.\r
19 *\r
20 * You should have received a copy of the GNU Lesser General Public\r
21 * License along with this library; if not, write to the Free Software\r
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r
23 */\r
24 \r
25 echo "<h1>PHP QR Code</h1><hr/>";
26 \r
27 //set it to writable location, a place for temp generated PNG files\r
28 $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;\r
29 \r
30 //html PNG location prefix\r
31 $PNG_WEB_DIR = 'temp/';\r
32\r
33 include "qrlib.php"; \r
34 \r
35 //ofcourse we need rights to create temp dir\r
36 if (!file_exists($PNG_TEMP_DIR))\r
37 mkdir($PNG_TEMP_DIR);
38 \r
39 \r
40 $filename = $PNG_TEMP_DIR.'test.png';\r
41 \r
42 //processing form input\r
43 //remember to sanitize user input in real-life solution !!!\r
44 $errorCorrectionLevel = 'L';\r
45 if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))\r
46 $errorCorrectionLevel = $_REQUEST['level']; \r
47\r
48 $matrixPointSize = 4;\r
49 if (isset($_REQUEST['size']))\r
50 $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10);\r
51\r
52
53 if (isset($_REQUEST['data'])) { \r
54 \r
55 //it's very important!\r
56 if (trim($_REQUEST['data']) == '')\r
57 die('data cannot be empty! <a href="?">back</a>');\r
58
59 // user data\r
60 $filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
61 QRcode::png($_REQUEST['data'], $filename, $errorCorrectionLevel, $matrixPointSize, 2); \r
62
63 } else { \r
64 \r
65 //default data
66 echo 'You can provide data in GET parameter: <a href="?data=like_that">like that</a><hr/>';
67 QRcode::png('PHP QR Code :)', $filename, $errorCorrectionLevel, $matrixPointSize, 2); \r
68
69 }
70 \r
71 //display generated file
72 echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" /><hr/>'; \r
73 \r
74 //config form\r
75 echo '<form action="index.php" method="post">\r
76 Data:&nbsp;<input name="data" value="'.(isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):'PHP QR Code :)').'" />&nbsp;\r
77 ECC:&nbsp;<select name="level">\r
78 <option value="L"'.(($errorCorrectionLevel=='L')?' selected':'').'>L - smallest</option>\r
79 <option value="M"'.(($errorCorrectionLevel=='M')?' selected':'').'>M</option>\r
80 <option value="Q"'.(($errorCorrectionLevel=='Q')?' selected':'').'>Q</option>\r
81 <option value="H"'.(($errorCorrectionLevel=='H')?' selected':'').'>H - best</option>\r
82 </select>&nbsp;\r
83 Size:&nbsp;<select name="size">';\r
84 \r
85 for($i=1;$i<=10;$i++)\r
86 echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>';\r
87 \r
88 echo '</select>&nbsp;\r
89 <input type="submit" value="GENERATE"></form><hr/>';\r
90 \r
91 // benchmark
92 QRtools::timeBenchmark();
93
94