Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 990 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
	}
1105 jpm 36
 
990 isa 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
	}
1105 jpm 45
 
990 isa 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();
1105 jpm 59
			// For Debugging
60
			//curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
61
			//curl_setopt($ch, CURLOPT_STDERR, $f = fopen("$cheminImg.txt", "w+"));
62
 
990 isa 63
			curl_setopt($ch, CURLOPT_URL, $this->API_CHART_URL);
64
			curl_setopt($ch, CURLOPT_POST, true);
65
			curl_setopt($ch, CURLOPT_POSTFIELDS, "chs={$this->taille}x{$this->taille}&cht=qr&chl=".urlencode($this->contenu));
66
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
67
			curl_setopt($ch, CURLOPT_HEADER, false);
68
			curl_setopt($ch, CURLOPT_TIMEOUT, 30);
69
			$img = curl_exec($ch);
70
			curl_close($ch);
1105 jpm 71
 
72
			// For Debugging
73
			//fclose($f);
74
 
990 isa 75
			file_put_contents($cheminImg, $img);
76
		}
77
		$urlQrCode = sprintf($this->urlQrCodeTpl, $idQrCode);
78
		return $urlQrCode;
79
	}
80
}
81
?>