/
Shortcode.php
219 lines (175 loc) · 4.01 KB
/
Shortcode.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
namespace WPKit\Integrations\Vc;
use WPKit\Shortcodes\Shortcode as BaseShortcode;
class Shortcode extends BaseShortcode {
/**
* The name of the shortcode
*
* @var string
*/
var $name = '';
/**
* The description of the shortcode
*
* @var string
*/
var $description = '';
/**
* The classname for the shortcode
*
* @var string
*/
var $class = '';
/**
* Should settings show on create
*
* @var boolean
*/
var $show_settings_on_create = false;
/**
* Is the shortcode a container
*
* @var boolean
*/
var $is_container = false;
/**
* What does the shortcode act as a parant to
*
* @var array
*/
var $as_parent = array();
/**
* What does the shortcode act as a child to
*
* @var array
*/
var $as_child = array();
/**
* The weight of the shortcode
*
* @var int
*/
var $weight = 1;
/**
* The category of the shortcode
*
* @var string
*/
var $category = '';
/**
* The group of the shortcode
*
* @var string
*/
var $group = '';
/**
* The admin js for the shortcode
*
* @var string
*/
var $admin_enqueue_js = '';
/**
* The admin css for the shortcode
*
* @var string
*/
var $admin_enqueue_css = '';
/**
* The frotend js for the shortcode
*
* @var string
*/
var $front_enqueue_js = '';
/**
* The frotend css for the shortcode
*
* @var string
*/
var $front_enqueue_css = '';
/**
* The icon for the shortode
*
* @var string
*/
var $icon = '';
/**
* The custom markup for the shortcode
*
* @var string
*/
var $custom_markup = '';
/**
* The js view for the shortcode
*
* @var string
*/
var $js_view = '';
/**
* The html template for the shortcode
*
* @var string
*/
var $html_template = '';
/**
* Is the shortcode a content elemenet
*
* @var boolean
*/
var $content_element = true;
/**
* The params of the shortcode
*
* @var array
*/
var $params = array();
/**
* Get base of shortcode
*
* @return string
*/
public function getBase() {
return $this->tag;
}
/**
* Get array data for shortcode
*
* @return array
*/
public function toArray() {
return array_merge(get_object_vars($this), array(
'base' => $this->getBase()
));
}
/**
* Filter the shortcode attributes
*
* @param array $atts
* @return array
*/
protected function filterAtts( $atts = array() ) {
foreach($atts as $key => &$att) {
$param = $this->params[$key];
switch( $param['type'] ) {
case 'vc_link' :
$att = vc_build_link($att);
break;
}
}
return $atts;
}
/**
* Get default attributes for the shortcode
*
* @return array
*/
protected function getDefaultAtts() {
return array_combine(
array_map(function($param) {
return $param['param_name'];
}, $this->params),
array_map(function($param) {
return ! empty( $param['default'] ) ? $param['default'] : '';
}, $this->params)
);
}
}