forked from yucombinator/cappdme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQRCode.class.php
77 lines (68 loc) · 1.8 KB
/
QRCode.class.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
<?php
/**
* @title QR Code
* @desc Compatible to vCard 4.0 or higher.
*
* @author Pierre-Henry Soria <[email protected]>, modified by Yu Chen Hou<[email protected]>
* @copyright (c) 2012, Pierre-Henry Soria. All Rights Reserved.
* @license GNU General Public License.
* @version 1.2
*/
class QRCode
{
const API_URL = 'http://chart.apis.google.com/chart?chs=';
private $_sData;
/**
* Constructor.
*/
public function __construct()
{
$this->_sData = 'BEGIN:VCARD' . "\n";
$this->_sData .= 'VERSION:4.0' . "\n";
return $this;
}
/**
* URL address.
*
* @param string $sUrl
* @return object this
*/
public function url($sUrl)
{
$sUrl = (substr($sUrl, 0, 4) != 'http') ? 'http://' . $sUrl : $sUrl;
$this->_sData .= 'URL:' . $sUrl . "\n";
return $this;
}
/**
* Generate the QR code.
*
* @return object this
*/
public function finish()
{
$this->_sData .= 'END:VCARD';
return $this;
}
/**
* Get the URL of QR Code.
*
* @param integer $iSize Default 150
* @param string $sECLevel Default L
* @param integer $iMargin Default 1
* @return string The API URL configure.
*/
public function get($iSize = 150, $sECLevel = 'L', $iMargin = 1)
{
$this->_sData = urlencode($this->_sData);
return static::API_URL . $iSize . 'x' . $iSize . '&cht=qr&chld=' . $sECLevel . '|' . $iMargin . '&chl=' . $this->_sData;
}
/**
* The HTML code for displaying the QR Code.
*
* @return void
*/
public function display()
{
echo '<p class="center"><img src="' . $this->get() . '" alt="QR Code" /></p>';
}
}