1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: use Xoops\Core\Service\AbstractContract;
13: use Xoops\Core\Service\Contract\QrcodeInterface;
14: use Xoops\Core\Service\Response;
15: use Xoops\Html\Img;
16:
17: /**
18: * Qrcode provider for service manager
19: *
20: * @category ServiceProvider
21: * @package QrcodeProvider
22: * @author Richard Griffith <richard@geekwright.com>
23: * @copyright 2013-2014 XOOPS Project (http://xoops.org)
24: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
25: * @link http://xoops.org
26: * @since 2.6.0
27: */
28: class QrcodeProvider extends AbstractContract implements QrcodeInterface
29: {
30: /** @var string $renderScript */
31: protected $renderScript = 'modules/qrcode/include/qrrender.php';
32:
33: /**
34: * getName - get a short name for this service provider. This should be unique within the
35: * scope of the named service, so using module dirname is suggested.
36: *
37: * @return string - a unique name for the service provider
38: */
39: public function getName()
40: {
41: return 'qrcode';
42: }
43:
44: /**
45: * getDescription - get human readable description of the service provider
46: *
47: * @return string
48: */
49: public function getDescription()
50: {
51: return 'QR Code generation using endroid/qrcode';
52: }
53:
54:
55: /**
56: * getQRUrl
57: *
58: * @param string $qrText text for QR code
59: *
60: * @return string URL to obtain QR Code image of $qrText
61: */
62: private function getQRUrl($qrText)
63: {
64: $xoops = \Xoops::getInstance();
65: $params = array(
66: 'text' => (string) $qrText,
67: );
68: $url = $xoops->buildUrl($xoops->url($this->renderScript), $params);
69: return $url;
70: }
71:
72: /**
73: * getImgUrl - get URL to QR Code image of supplied text
74: *
75: * @param Response $response \Xoops\Core\Service\Response object
76: * @param string $qrText text to encode in QR Code
77: *
78: * @return void - response->value set to URL string
79: */
80: public function getImgUrl(Response $response, $qrText)
81: {
82: $response->setValue($this->getQRUrl($qrText));
83: }
84:
85: /**
86: * getImgTag - get a full HTML img tag to display a QR Code image of supplied text
87: *
88: * @param Response $response \Xoops\Core\Service\Response object
89: * @param string $qrText text to encode in QR Code
90: * @param array $attributes array of attribute name => value pairs for img tag
91: *
92: * @return void - response->value set to image tag
93: */
94: public function getImgTag(Response $response, $qrText, $attributes = array())
95: {
96: $url = $this->getQRUrl($qrText);
97: if (!is_array($attributes)) {
98: $attributes = array();
99: }
100:
101: $imgTag = new Img(array('src' => $url,));
102: $imgTag->setMerge($attributes);
103: $response->setValue($imgTag->render());
104: }
105: }
106: