-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
74 lines (59 loc) · 1.63 KB
/
index.php
File metadata and controls
74 lines (59 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
// vim: set et sw=4 ts=4 sts=4 ft=php fdm=marker ff=unix fenc=utf8 nobomb:
/**
* @author mingcheng<lucky#gracecode.com>
* @date 2013-03-21
*/
require_once __DIR__.'/libs/qrlib.php';
require_once __DIR__.'/common.inc.php';
$ERRORS = array(
"NOT_DXY_URL" => array(
"id" => -2, "message" => "Sorry, Its not DXY's url."
),
"NOT_WRITABLE" => array(
"id" => -3, "message" => "Sorry, Cache directory not writable."
)
);
// Thanks Sam :^)
function getUrl() {
$url = getRequestParam("url", null, "get");
if(empty($url) && isset($_SERVER['HTTP_REFERER'])) {
$url = $_SERVER['HTTP_REFERER'];
}
return strip_tags($url);
}
if (!isDXYUrl($url = getUrl())) {
raiseErros($ERRORS["NOT_DXY_URL"]["message"], $ERRORS["NOT_DXY_URL"]["id"]);
}
$format = getRequestParam("format", "png", "get");
$size = getRequestParam("size", "5", "get"); // 27px
$margin = getRequestParam("margin", "1", "get");
$level = getRequestParam("level", "l", "get");
switch(strtolower($level)) {
case 'l':
$level = QR_ECLEVEL_L;
break;
case 'm':
$level = QR_ECLEVEL_M;
break;
case 'q':
$level = QR_ECLEVEL_Q;
break;
case 'h':
$level = QR_ECLEVEL_H;
break;
default:
$level = QR_ECLEVEL_L;
}
switch($format) {
case 'text':
$data = QRcode::text($url, false, $level, $size, $margin);
header("Content-type:text/plain");
foreach($data as $d) {
echo $d."\n";
}
break;
default:
header("Content-type:image/png");
QRcode::png($url, false, $level, $size, $margin);
}