-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathqr.php
144 lines (126 loc) · 2.65 KB
/
qr.php
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/*
*
* QR Image Generator Bundle for Laravel
*
* This class will allow for easy manipulation and creation of QR codes
* @author Tony Lea
* @version 1.0
*
*/
final class QR {
/**
* Google API URL
*/
const API_URL = "https://chart.googleapis.com/chart?";
/**
* Code data
*
* @var string $_data
*/
private $_data;
/**
* Bookmark code
*
* @param string $title
* @param string $url
*/
public function bookmark($title = null, $url = null) {
$this->_data = "MEBKM:TITLE:{$title};URL:{$url};;";
}
/**
* MECARD code
*
* @param string $name
* @param string $address
* @param string $phone
* @param string $email
*/
public function contact($name = null, $address = null, $phone = null, $email = null) {
$this->_data = "MECARD:N:{$name};ADR:{$address};TEL:{$phone};EMAIL:{$email};;";
}
/**
* Create code with GIF, JPG, etc.
*
* @param string $type
* @param string $size
* @param string $content
*/
public function content($type = null, $size = null, $content = null) {
$this->_data = "CNTS:TYPE:{$type};LNG:{$size};BODY:{$content};;";
}
/**
* Generate QR code image
*
* @param int $size
* @return image output
*/
public function draw($size = 150) {
$url = self::API_URL . "choe=UTF-8&chs={$size}x{$size}&cht=qr&chl=" . urlencode($this->_data);
echo '<img src="'.$url.'">';
}
/**
* Email address code
*
* @param string $email
* @param string $subject
* @param string $message
*/
public function email($email = null, $subject = null, $message = null) {
$this->_data = "MATMSG:TO:{$email};SUB:{$subject};BODY:{$message};;";
}
/**
* Geo location code
*
* @param string $lat
* @param string $lon
* @param string $height
*/
public function geo($lat = null, $lon = null, $height = null) {
$this->_data = "GEO:{$lat},{$lon},{$height}";
}
/**
* Telephone number code
*
* @param string $phone
*/
public function phone($phone = null) {
$this->_data = "TEL:{$phone}";
}
/**
* SMS code
*
* @param string $phone
* @param string $text
*/
public function sms($phone = null, $text = null) {
$this->_data = "SMSTO:{$phone}:{$text}";
}
/**
* Text code
*
* @param string $text
*/
public function text($text = null) {
$this->_data = $text;
}
/**
* URL code
*
* @param string $url
*/
public function url($url = null) {
$this->_data = preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : "http://{$url}";
}
/**
* Wifi code
*
* @param string $type
* @param string $ssid
* @param string $password
*/
public function wifi($type = null, $ssid = null, $password = null) {
$this->_data = "WIFI:T:{$type};S{$ssid};{$password};;";
}
}
?>