| 990 |
isa |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* BarcodeQR - Code QR Barcode Image Generator (PNG)
|
|
|
4 |
*
|
|
|
5 |
* @package BarcodeQR
|
|
|
6 |
* @category BarcodeQR
|
|
|
7 |
* @name BarcodeQR
|
|
|
8 |
* @version 1.0
|
|
|
9 |
* @author Shay Anderson 05.11
|
|
|
10 |
* @link http://www.shayanderson.com/php/php-qr-code-generator-class.htm
|
|
|
11 |
* @license http://www.gnu.org/licenses/gpl.html GPL License
|
|
|
12 |
* This is free software and is distributed WITHOUT ANY WARRANTY
|
|
|
13 |
*/
|
|
|
14 |
final class QrCode {
|
|
|
15 |
|
|
|
16 |
private $API_CHART_URL = '';
|
|
|
17 |
private $taille = '150';
|
|
|
18 |
private $contenu;
|
|
|
19 |
private $urlQrCodeTpl;
|
|
|
20 |
private $dossierQrCode;
|
|
|
21 |
|
|
|
22 |
public function __construct($conteneur) {
|
|
|
23 |
$this->API_CHART_URL = $conteneur->getParametre('urlApiChart');
|
|
|
24 |
$this->dossierQrCode = $conteneur->getParametre('dossierQrCode');
|
|
|
25 |
$this->urlQrCodeTpl = $conteneur->getParametre('urlQrCodeTpl');
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* URL code
|
|
|
30 |
*
|
|
|
31 |
* @param string $url
|
|
|
32 |
*/
|
|
|
33 |
public function setUrl($url = '') {
|
|
|
34 |
$this->contenu = $url;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Taille du QRcode en pixel. Cela sera forcément un carré.
|
|
|
39 |
*
|
|
|
40 |
* @param string $taille
|
|
|
41 |
*/
|
|
|
42 |
public function setTaille($taille) {
|
|
|
43 |
$this->taille = $taille;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* Generate QR code image
|
|
|
48 |
*
|
|
|
49 |
* @param string $filename
|
|
|
50 |
* @return bool
|
|
|
51 |
*/
|
|
|
52 |
public function dessiner($idQrCode = null) {
|
|
|
53 |
if (!preg_match('/\.png$/i', $idQrCode)) {
|
|
|
54 |
$idQrCode .= '.png';
|
|
|
55 |
}
|
|
|
56 |
$cheminImg = $this->dossierQrCode.$idQrCode;
|
|
|
57 |
if (file_exists($cheminImg) == false) {
|
|
|
58 |
$ch = curl_init();
|
|
|
59 |
curl_setopt($ch, CURLOPT_URL, $this->API_CHART_URL);
|
|
|
60 |
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
61 |
curl_setopt($ch, CURLOPT_POSTFIELDS, "chs={$this->taille}x{$this->taille}&cht=qr&chl=".urlencode($this->contenu));
|
|
|
62 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
63 |
curl_setopt($ch, CURLOPT_HEADER, false);
|
|
|
64 |
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
|
|
65 |
$img = curl_exec($ch);
|
|
|
66 |
curl_close($ch);
|
|
|
67 |
|
|
|
68 |
file_put_contents($cheminImg, $img);
|
|
|
69 |
}
|
|
|
70 |
$urlQrCode = sprintf($this->urlQrCodeTpl, $idQrCode);
|
|
|
71 |
return $urlQrCode;
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
?>
|