-
Notifications
You must be signed in to change notification settings - Fork 2
/
lib.php
129 lines (112 loc) · 4.78 KB
/
lib.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
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage blocktype-qrcode
* @author Emanuel Garc�s
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2011 Emanuel Garc�s
*
*/
defined('INTERNAL') || die();
class PluginBlocktypeQRCode extends PluginBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.qrcode');
}
public static function get_description() {
return get_string('description', 'blocktype.qrcode');
}
public static function get_categories() {
return array('general');
}
public static function render_instance(BlockInstance $instance, $editing = false, $versioning = false) {
$configdata = $instance->get('configdata');
$size = (!empty($configdata['size']) ? hsc($configdata['size']) : 'medium');
$width = (!empty($configdata['width']) ? hsc($configdata['width']) : '200');
switch ($size) {
case 'small':
$width = '100';
break;
case 'medium':
$width = '200';
break;
case 'big':
$width = '300';
break;
}
$align = (!empty($configdata['align']) ? hsc($configdata['align']) : 'left');
// Point URL to the current view.
$qrcode = get_config('wwwroot') . 'view/view.php?id=' . param_integer('id');
// Render template.
$smarty = smarty_core();
$smarty->assign('align', $align);
$smarty->assign('blockid', $instance->get('id'));
$smarty->assign('kjuaconfobject', json_encode(array('text' => $qrcode, 'size' => $width, 'ecLevel' => 'M', 'rounded' => 50)));
return $smarty->fetch('blocktype:qrcode:qrcode.tpl');
}
public static function has_instance_config() {
return true;
}
public static function get_instance_config_javascript(BlockInstance $instance) {
return array('js/configform.js');
}
public static function get_instance_javascript(BlockInstance $instance) {
return array('js/kjua.min.js');
}
public static function instance_config_form($instance) {
$configdata = $instance->get('configdata');
return array(
'size' => array(
'type' => 'radio',
'title' => get_string('size', 'blocktype.qrcode'),
'defaultvalue' => (!empty($configdata['size']) ? hsc($configdata['size']) : 'medium'),
'options' => array(
'small' => get_string('size_small', 'blocktype.qrcode'),
'medium' => get_string('size_medium', 'blocktype.qrcode'),
'big' => get_string('size_big', 'blocktype.qrcode'),
'custom' => get_string('size_custom', 'blocktype.qrcode'),
),
'onclick' => 'toggle_custom_size();',
),
'width' => array(
'type' => 'text',
'title' => get_string('width', 'blocktype.qrcode'),
'size' => 1,
'defaultvalue' => (!empty($configdata['width']) ? hsc($configdata['width']) : '200'),
'class' => ((isset($configdata['size']) && hsc($configdata['size']) == 'custom') ? '' : 'hidden'),
),
'align' => array(
'type' => 'radio',
'title' => get_string('align', 'blocktype.qrcode'),
'defaultvalue' => (!empty($configdata['align'])) ? hsc($configdata['align']) : 'left',
'options' => array(
'left' => get_string('alignleft', 'blocktype.qrcode'),
'center' => get_string('aligncenter', 'blocktype.qrcode'),
'right' => get_string('alignright', 'blocktype.qrcode'),
),
),
);
}
public static function default_copy_type() {
return 'full';
}
public static function get_css_icon($blocktypename) {
return 'qrcode';
}
}