1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Properties editor class.
|
6
|
*/
|
7
|
class sweaver_plugin_editor extends sweaver_plugin {
|
8
|
|
9
|
/**
|
10
|
* Menu registry.
|
11
|
*/
|
12
|
public function sweaver_menu(&$weight, $page_arguments, $base) {
|
13
|
$items = array();
|
14
|
|
15
|
$base = array(
|
16
|
'load arguments' => array('%map'),
|
17
|
'access arguments' => array('configure sweaver'),
|
18
|
'file' => 'plugins/sweaver_plugin_editor/sweaver_plugin_editor.admin.inc',
|
19
|
'type' => MENU_CALLBACK,
|
20
|
);
|
21
|
|
22
|
$items['admin/config/user-interface/sweaver'] = array(
|
23
|
'title' => 'Sweaver',
|
24
|
'description' => 'Visual interface for tweaking or building Drupal themes.',
|
25
|
'page callback' => 'drupal_get_form',
|
26
|
'page arguments' => array('sweaver_settings'),
|
27
|
'access arguments' => array('configure sweaver'),
|
28
|
'file' => 'plugins/sweaver_plugin_editor/sweaver_plugin_editor.admin.inc',
|
29
|
);
|
30
|
$items['admin/config/user-interface/sweaver/settings'] = array(
|
31
|
'title' => 'General',
|
32
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
33
|
'weight' => $weight++,
|
34
|
);
|
35
|
|
36
|
// Enable or disable plugins.
|
37
|
$items['admin/config/user-interface/sweaver/plugins'] = $base + array(
|
38
|
'title' => 'Plugins',
|
39
|
'page callback' => 'drupal_get_form',
|
40
|
'page arguments' => array('sweaver_plugin_editor_config_plugins'),
|
41
|
'weight' => $weight++,
|
42
|
);
|
43
|
$items['admin/config/user-interface/sweaver/plugins']['type'] = MENU_LOCAL_TASK;
|
44
|
|
45
|
|
46
|
// Editor form configuration.
|
47
|
$items['admin/config/user-interface/sweaver/editor'] = $base + array(
|
48
|
'title' => 'Editor',
|
49
|
'page callback' => 'drupal_get_form',
|
50
|
'page arguments' => array('sweaver_plugin_editor_config_editor'),
|
51
|
'weight' => $weight++,
|
52
|
);
|
53
|
$items['admin/config/user-interface/sweaver/editor']['type'] = MENU_LOCAL_TASK;
|
54
|
$items['admin/config/user-interface/sweaver/editor/form'] = $base + array(
|
55
|
'title' => 'Form',
|
56
|
'page callback' => 'drupal_get_form',
|
57
|
'page arguments' => array('sweaver_plugin_editor_config_editor'),
|
58
|
'weight' => $weight++,
|
59
|
);
|
60
|
$items['admin/config/user-interface/sweaver/editor/form']['type'] = MENU_DEFAULT_LOCAL_TASK;
|
61
|
|
62
|
$menu_items = array(
|
63
|
'selectors' => array(
|
64
|
'title' => 'Selectors',
|
65
|
'ctools_collection' => 'selectors',
|
66
|
'ctools_object' => 'selector',
|
67
|
'ctools_table' => 'sweaver_selector',
|
68
|
),
|
69
|
'properties' => array(
|
70
|
'title' => 'Properties',
|
71
|
'ctools_collection' => 'properties',
|
72
|
'ctools_object' => 'property',
|
73
|
'ctools_table' => 'sweaver_property',
|
74
|
),
|
75
|
'types' => array(
|
76
|
'title' => 'Types',
|
77
|
'ctools_collection' => 'types',
|
78
|
'ctools_object' => 'type',
|
79
|
'ctools_table' => 'sweaver_type',
|
80
|
),
|
81
|
);
|
82
|
|
83
|
foreach ($menu_items as $key => $item) {
|
84
|
|
85
|
$items['admin/config/user-interface/sweaver/editor/'. $item['ctools_collection']] = array(
|
86
|
'title' => $item['title'],
|
87
|
'page callback' => 'drupal_get_form',
|
88
|
'page arguments' => array('sweaver_plugin_editor_objects_list', $item['ctools_object']),
|
89
|
'access arguments' => array('configure sweaver'),
|
90
|
'file' => 'plugins/sweaver_plugin_editor/sweaver_plugin_editor.admin.inc',
|
91
|
'type' => MENU_LOCAL_TASK,
|
92
|
'weight' => $weight++,
|
93
|
);
|
94
|
$items['admin/config/user-interface/sweaver/editor/add/'. $item['ctools_object']] = $base + array(
|
95
|
'title' => 'Add new ' . $item['ctools_object'],
|
96
|
'page callback' => 'drupal_get_form',
|
97
|
'page arguments' => array('sweaver_object_form', $item['ctools_object']),
|
98
|
);
|
99
|
$items['admin/config/user-interface/sweaver/editor/edit/'. $item['ctools_object'] .'/%sweaver_object'] = $base + array(
|
100
|
'title' => 'Edit ' . $item['ctools_object'],
|
101
|
'page callback' => 'drupal_get_form',
|
102
|
'page arguments' => array('sweaver_object_form', $item['ctools_object'], 7),
|
103
|
);
|
104
|
$items['admin/config/user-interface/sweaver/editor/delete/'. $item['ctools_object'] .'/%sweaver_object'] = $base + array(
|
105
|
'title' => 'Delete ' . $item['ctools_object'],
|
106
|
'page callback' => 'drupal_get_form',
|
107
|
'page arguments' => array('sweaver_object_delete', $item['ctools_collection'], $item['ctools_object'], 7, 'delete', 'deleted'),
|
108
|
);
|
109
|
$items['admin/config/user-interface/sweaver/editor/revert/'. $item['ctools_object'] .'/%sweaver_object'] = $base + array(
|
110
|
'title' => 'Revert ' . $item['ctools_object'],
|
111
|
'page callback' => 'drupal_get_form',
|
112
|
'page arguments' => array('sweaver_object_delete', $item['ctools_collection'], $item['ctools_object'], 7, 'revert', 'reverted'),
|
113
|
);
|
114
|
$items['admin/config/user-interface/sweaver/editor/enable/'. $item['ctools_object'] .'/%sweaver_object'] = $base + array(
|
115
|
'title' => 'Enable ' . $item['ctools_object'],
|
116
|
'page callback' => 'sweaver_object_status',
|
117
|
'page arguments' => array($item['ctools_collection'], 7, FALSE),
|
118
|
);
|
119
|
$items['admin/config/user-interface/sweaver/editor/disable/'. $item['ctools_object'] .'/%sweaver_object'] = $base + array(
|
120
|
'title' => 'Disable ' . $item['ctools_object'],
|
121
|
'page callback' => 'sweaver_object_status',
|
122
|
'page arguments' => array($item['ctools_collection'], 7, TRUE),
|
123
|
);
|
124
|
$items['admin/config/user-interface/sweaver/editor/export/'. $item['ctools_object'] .'/%sweaver_object'] = $base + array(
|
125
|
'title' => 'Export ' . $item['ctools_object'],
|
126
|
'page callback' => 'sweaver_object_export',
|
127
|
'page arguments' => array($item['ctools_object'], 7),
|
128
|
);
|
129
|
}
|
130
|
|
131
|
return $items;
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* Theme registry.
|
136
|
*/
|
137
|
public function sweaver_theme() {
|
138
|
$theme_functions = array();
|
139
|
|
140
|
$editor_plugin_path = drupal_get_path('module', 'sweaver') .'/plugins/sweaver_plugin_editor';
|
141
|
$theme_functions = array(
|
142
|
'sweaver_plugin_editor_config_editor' => array(
|
143
|
'template' => 'sweaver-plugin-editor-config-editor',
|
144
|
'file' => 'sweaver_plugin_editor.theme.inc',
|
145
|
'path' => $editor_plugin_path,
|
146
|
'render element' => 'form',
|
147
|
),
|
148
|
'sweaver_plugin_editor_config_plugins' => array(
|
149
|
'template' => 'sweaver-plugin-editor-config-plugins',
|
150
|
'file' => 'sweaver_plugin_editor.theme.inc',
|
151
|
'path' => $editor_plugin_path,
|
152
|
'render element' => 'form',
|
153
|
),
|
154
|
'sweaver_plugin_editor_objects_list' => array(
|
155
|
'render element' => 'form',
|
156
|
),
|
157
|
);
|
158
|
|
159
|
return $theme_functions;
|
160
|
}
|
161
|
|
162
|
/**
|
163
|
* Frontend form.
|
164
|
*/
|
165
|
public function sweaver_form() {
|
166
|
$form = array();
|
167
|
$form['#editor_containers'] = array();
|
168
|
|
169
|
$current_style = Sweaver::get_instance()->get_current_style();
|
170
|
$form['sweaver-css'] = array(
|
171
|
'#type' => 'hidden',
|
172
|
'#default_value' => isset($current_style->css) ? $current_style->css : '',
|
173
|
);
|
174
|
$form['css-rendered'] = array(
|
175
|
'#type' => 'hidden',
|
176
|
'#default_value' => '',
|
177
|
);
|
178
|
|
179
|
$properties = sweaver_object_load(NULL, 'property');
|
180
|
$sweaver_editor_form_configuration = variable_get('sweaver_editor_form_configuration', array());
|
181
|
|
182
|
|
183
|
// Images.
|
184
|
$images = array('' => t('Theme default'), 'none' => t('No image'));
|
185
|
$image_handler_plugin = variable_get('sweaver_plugin_handle_images', '');
|
186
|
if (!empty($image_handler_plugin)) {
|
187
|
$image_handler = Sweaver::get_instance()->get_plugin($image_handler_plugin);
|
188
|
if (is_object($image_handler) && method_exists($image_handler, 'sweaver_images_handler')) {
|
189
|
$image_handler->sweaver_images_handler($images);
|
190
|
}
|
191
|
}
|
192
|
|
193
|
// Container and properties.
|
194
|
foreach ($sweaver_editor_form_configuration as $container => $settings) {
|
195
|
if (!empty($settings['properties'])) {
|
196
|
// Container title.
|
197
|
$form['#editor_containers'][$container]['title'] = check_plain($settings['title']);
|
198
|
foreach ($settings['properties'] as $weight => $property_key) {
|
199
|
$form['#editor_containers'][$container]['properties'][$property_key] = $property_key;
|
200
|
|
201
|
// Create property element, continue if it doesn't exist.
|
202
|
if (!isset($properties[$property_key])) {
|
203
|
continue;
|
204
|
}
|
205
|
$property = $properties[$property_key];
|
206
|
sweaver_export_check_serialized_keys($property);
|
207
|
$form[$property->name] = $this->sweaver_property_element($property, $images);
|
208
|
// Any children?
|
209
|
if ($property->property_type == 'parent') {
|
210
|
foreach ($properties as $key => $prop) {
|
211
|
if ($prop->property_parent == $property->name && !$prop->disabled)
|
212
|
$form[$property->name][$prop->name] = $this->sweaver_property_element($prop, $images);
|
213
|
}
|
214
|
}
|
215
|
}
|
216
|
}
|
217
|
}
|
218
|
|
219
|
return $form;
|
220
|
}
|
221
|
|
222
|
/**
|
223
|
* Frontend form render.
|
224
|
*/
|
225
|
public function sweaver_form_render(&$vars, &$form, $plugin) {
|
226
|
|
227
|
$name = $plugin['name'];
|
228
|
$vars['tabs'][$name]['#tab_name'] = $form[$name]['#tab_name'];
|
229
|
$vars['tabs_data'][$name]['#tab_description'] = $form[$name]['#tab_description'];
|
230
|
|
231
|
$output = '';
|
232
|
|
233
|
$output .= '<div id="sweaver-editor" class="clearfix">';
|
234
|
|
235
|
// Tab switcher.
|
236
|
$output .= drupal_render($form[$name]['form']['editor_switcher']);
|
237
|
|
238
|
// Containers.
|
239
|
$vertical_tabs = '';
|
240
|
$containers = '';
|
241
|
|
242
|
foreach ($form[$name]['form']['#editor_containers'] as $key => $container_value) {
|
243
|
// Set the first tab as active by default.
|
244
|
$tab_class = '';
|
245
|
if ($key == 'one') {
|
246
|
$tab_class = 'class="active"';
|
247
|
}
|
248
|
|
249
|
// Combine all vertical tabs.
|
250
|
$vertical_tabs .= '<div id="tab-'. $key .'" class="vertical-tab"><a href="#" '. $tab_class .'>'. $container_value['title'] .'</a></div>';
|
251
|
|
252
|
//TODO: All of the container count method has to be rethought
|
253
|
// Combine all properties in containers.
|
254
|
$i = 0;
|
255
|
$container_count = 1;
|
256
|
$container_total = 1;
|
257
|
foreach ($container_value['properties'] as $property) {
|
258
|
//var_dump($form[$name]['form'][$property]);
|
259
|
if (isset($form[$name]['form'][$property]['#theme'])){
|
260
|
if ($form[$name]['form'][$property]['#theme'] == 'table') {
|
261
|
$form[$name]['form'][$property]['#rows'] = $this->sweaver_recursive_table_element($form[$name]['form'][$property]['#rows'], $form[$name]['form'][$property]);
|
262
|
$i = 4; // The container is closed after the table
|
263
|
}
|
264
|
elseif($form[$name]['form'][$property]['#name'] == 'background-image'){
|
265
|
$i = 4; // The container is closed after the table
|
266
|
}
|
267
|
}
|
268
|
$i++;
|
269
|
if ($i == 5){
|
270
|
$container_total++;
|
271
|
$i = 0;
|
272
|
}
|
273
|
}
|
274
|
$i = 0;
|
275
|
|
276
|
$containers .= '<div id="container-'. $key .'" class="container-wrapper">';
|
277
|
|
278
|
foreach ($container_value['properties'] as $property) {
|
279
|
if ($i == 0) {
|
280
|
// Add first/last classes to the containers.
|
281
|
$container_class = '';
|
282
|
if ($container_count == 1) {
|
283
|
$container_class .= ' container-first';
|
284
|
}
|
285
|
if ($container_total == $container_count) {
|
286
|
$container_class .= ' container-last';
|
287
|
}
|
288
|
$containers .= '<div class="container '. $container_class .'"><div class="container-inner">';
|
289
|
}
|
290
|
|
291
|
if (isset($form[$name]['form'][$property]['#theme'])){
|
292
|
if ($form[$name]['form'][$property]['#theme'] == 'table') {
|
293
|
$form[$name]['form'][$property]['#rows'] = $this->sweaver_recursive_table_element($form[$name]['form'][$property]['#rows'], $form[$name]['form'][$property]);
|
294
|
$i = 4; // The container is closed after the table
|
295
|
}
|
296
|
elseif($form[$name]['form'][$property]['#name'] == 'background-image'){
|
297
|
$i = 4; // The container is closed after the table
|
298
|
}
|
299
|
}
|
300
|
|
301
|
$containers .= drupal_render($form[$name]['form'][$property]);
|
302
|
$i++;
|
303
|
if ($i == 5) {
|
304
|
$containers .= '</div></div>';
|
305
|
$container_count++;
|
306
|
$i = 0;
|
307
|
}
|
308
|
}
|
309
|
if ($i != 0) {
|
310
|
$containers .= '</div></div>';
|
311
|
}
|
312
|
$containers .= '</div>';
|
313
|
}
|
314
|
|
315
|
$output .= '<div class="vertical-tabs">' . $vertical_tabs . '</div>';
|
316
|
$output .= '<div class="vertical-content">' . $containers . '</div>';
|
317
|
|
318
|
$output .= '</div>';
|
319
|
|
320
|
$vars['tabs_data'][$name]['content'] = $output;
|
321
|
}
|
322
|
|
323
|
/**
|
324
|
* Frontend css and js.
|
325
|
*/
|
326
|
public function sweaver_form_css_js(&$inline_settings) {
|
327
|
|
328
|
drupal_add_js(drupal_get_path('module', 'sweaver') . '/plugins/sweaver_plugin_editor/sweaver_plugin_editor.js');
|
329
|
|
330
|
// Serializer for database storage
|
331
|
drupal_add_js(drupal_get_path('module', 'sweaver') . '/plugins/sweaver_plugin_editor/jquery.json-2.2.js');
|
332
|
|
333
|
// Slider
|
334
|
drupal_add_library('system', 'ui.slider');
|
335
|
drupal_add_css('misc/ui/jquery.ui.theme.css');
|
336
|
|
337
|
// colorpicker
|
338
|
drupal_add_css(drupal_get_path('module', 'sweaver') . '/plugins/sweaver_plugin_editor/colorpicker/css/colorpicker.css');
|
339
|
drupal_add_js(drupal_get_path('module', 'sweaver') . '/plugins/sweaver_plugin_editor/colorpicker/js/colorpicker.js');
|
340
|
|
341
|
// Selectors can either come from the database or from the theme info file.
|
342
|
// Depending on the setting we'll decide from which source/ we'll be adding
|
343
|
// the selectors into the inline javascript.
|
344
|
$selectors = array();
|
345
|
$default_source = TRUE;
|
346
|
$theme_key = Sweaver::get_instance()->get_theme_key();
|
347
|
|
348
|
if (variable_get('sweaver_selectors_source', FALSE)) {
|
349
|
$theme_info = sweaver_get_theme_info($theme_key);
|
350
|
if (isset($theme_info['sweaver']['selectors'])) {
|
351
|
foreach ($theme_info['sweaver']['selectors'] as $selector_selector => $selector_description) {
|
352
|
$selector = new stdClass;
|
353
|
if (!is_array($selector_description)) {
|
354
|
$name = str_replace(array('', '.', '-'), array(''), $selector_selector);
|
355
|
$selector->name = $name;
|
356
|
$selector->description = $selector_description;
|
357
|
$selector->selector_selector = $selector_selector;
|
358
|
$selector->selector_highlight = FALSE;
|
359
|
$selectors[$name] = $selector;
|
360
|
}
|
361
|
else {
|
362
|
if (isset($selector_description['type'])) {
|
363
|
if ($selector_description['type'] == 'replace') {
|
364
|
if (isset($selector_description['name'])) {
|
365
|
$name = $selector_description['name'];
|
366
|
}
|
367
|
else {
|
368
|
$name = str_replace(array(
|
369
|
'',
|
370
|
'.',
|
371
|
'-'), array(''), $selector_selector);
|
372
|
}
|
373
|
$selector->name = $name;
|
374
|
$selector->description = isset($selector_description['description']) ? $selector_description['description'] :
|
375
|
$selector->name;
|
376
|
$selector->selector_selector = $selector_selector;
|
377
|
|
378
|
if (isset($selector_description['selector_highlight'])) {
|
379
|
if ($selector_description['selector_highlight']) {
|
380
|
$selector->selector_highlight = true;
|
381
|
}
|
382
|
else {
|
383
|
$selector->selector_highlight = false;
|
384
|
}
|
385
|
}
|
386
|
else {
|
387
|
$selector->selector_highlight = false;
|
388
|
}
|
389
|
|
390
|
if (isset($selector_description['weight'])) {
|
391
|
$selector->weight = $selector_description['weight'];
|
392
|
}
|
393
|
|
394
|
$selectors[$selector->name] = $selector;
|
395
|
}
|
396
|
}
|
397
|
}
|
398
|
}
|
399
|
|
400
|
if (!empty($selectors)) {
|
401
|
$default_source = FALSE;
|
402
|
}
|
403
|
}
|
404
|
}
|
405
|
|
406
|
if ($default_source) {
|
407
|
$selectors = sweaver_object_load(NULL, 'selector');
|
408
|
$order = variable_get('sweaver_selector_order', array());
|
409
|
}
|
410
|
|
411
|
$new_weight = 20;
|
412
|
$js_selectors = array();
|
413
|
foreach ($selectors as $key => $selector) {
|
414
|
if (isset($order[$key])) {
|
415
|
$weight = $order[$key];
|
416
|
}
|
417
|
else {
|
418
|
if (isset($selector->weight)) {
|
419
|
$weight = $selector->weight;
|
420
|
}
|
421
|
else {
|
422
|
$weight = $new_weight++;
|
423
|
}
|
424
|
}
|
425
|
$options = array(
|
426
|
'weight' => $weight,
|
427
|
'name' => $selector->name,
|
428
|
'description' => check_plain($selector->description),
|
429
|
'selector' => check_plain($selector->selector_selector),
|
430
|
'highlight' => $selector->selector_highlight,
|
431
|
);
|
432
|
$js_selectors[$key] = $options;
|
433
|
}
|
434
|
asort($js_selectors);
|
435
|
|
436
|
// Types.
|
437
|
$js_types = array();
|
438
|
$types = sweaver_object_load(NULL, 'type');
|
439
|
foreach ($types as $key => $type) {
|
440
|
sweaver_export_check_serialized_keys($type);
|
441
|
$js_types[$key] = $type->type_options;
|
442
|
}
|
443
|
|
444
|
// Properties.
|
445
|
$js_properties = array();
|
446
|
$properties = sweaver_object_load(NULL, 'property');
|
447
|
foreach ($properties as $key => $property) {
|
448
|
sweaver_export_check_serialized_keys($property);
|
449
|
if ($property->property_type != 'parent') {
|
450
|
$options = array(
|
451
|
'name' => $property->name,
|
452
|
'property' => $property->property,
|
453
|
'parent' => $property->property_parent,
|
454
|
'type' => $property->property_type,
|
455
|
'options' => $property->property_options,
|
456
|
'prefix' => $property->property_prefix,
|
457
|
'suffix' => $property->property_suffix,
|
458
|
'slider_min' => $property->property_slider_min,
|
459
|
'slider_max' => $property->property_slider_max,
|
460
|
);
|
461
|
$js_properties[$key] = $options;
|
462
|
}
|
463
|
}
|
464
|
|
465
|
// Excluded selectors.
|
466
|
$js_excluded_selectors = array();
|
467
|
$exclude_selectors = variable_get('sweaver_selectors_exclude', SWEAVER_SELECTORS_EXCLUDE);
|
468
|
$exploded = explode("\n", $exclude_selectors);
|
469
|
foreach ($exploded as $key => $selector) {
|
470
|
$trimmed = trim($selector);
|
471
|
if (!empty($trimmed)) {
|
472
|
$js_excluded_selectors[] = $trimmed;
|
473
|
}
|
474
|
}
|
475
|
$js_excluded_selectors = implode(',', $js_excluded_selectors);
|
476
|
|
477
|
// Excluded classes.
|
478
|
$js_excluded_classes = array();
|
479
|
$exclude_classes = variable_get('sweaver_classes_exclude', SWEAVER_CLASSES_EXCLUDE);
|
480
|
$exploded = explode("\n", $exclude_classes);
|
481
|
foreach ($exploded as $key => $class) {
|
482
|
$trimmed = trim($class);
|
483
|
if (!empty($trimmed)) {
|
484
|
$js_excluded_classes[] = $trimmed;
|
485
|
}
|
486
|
}
|
487
|
|
488
|
$inline_settings['sweaver']['selectors'] = $js_selectors;
|
489
|
$inline_settings['sweaver']['types'] = $js_types;
|
490
|
$inline_settings['sweaver']['properties'] = $js_properties;
|
491
|
$inline_settings['sweaver']['exclude_selectors'] = $js_excluded_selectors;
|
492
|
$inline_settings['sweaver']['exclude_classes'] = $js_excluded_classes;
|
493
|
$inline_settings['sweaver']['preview_selector'] = variable_get('sweaver_preview_selection', TRUE);
|
494
|
$inline_settings['sweaver']['combined_selectors'] = variable_get('sweaver_combined_selectors', FALSE);
|
495
|
$inline_settings['sweaver']['translate_path'] = variable_get('sweaver_translate_path', TRUE);
|
496
|
global $base_root;
|
497
|
$inline_settings['sweaver']['base_root'] = $base_root;
|
498
|
}
|
499
|
|
500
|
/**
|
501
|
* Create a form element for a property.
|
502
|
*
|
503
|
* @param $property
|
504
|
* The property.
|
505
|
* @param $images
|
506
|
* A collection of images to use for the image type.
|
507
|
*/
|
508
|
private function sweaver_property_element($property, $images) {
|
509
|
switch ($property->property_type) {
|
510
|
|
511
|
case 'slider':
|
512
|
return array(
|
513
|
'#type' => 'textfield',
|
514
|
'#title' => $property->description,
|
515
|
'#attributes' => array(
|
516
|
'class' => array('slider-value'),
|
517
|
'title' => $property->description,
|
518
|
'autocomplete' => 'off',
|
519
|
),
|
520
|
'#prefix' => isset($property->css_prefix) ? $property->css_prefix : '',
|
521
|
'#suffix' => isset($property->css_suffix) ? $property->css_suffix : '',
|
522
|
);
|
523
|
break;
|
524
|
|
525
|
// New Type of Field implemented to improve the interface
|
526
|
case 'checkbox':
|
527
|
return array(
|
528
|
'#markup' => '<div id="button-checkbox-'.$property->name.'" class="editor_icons form-item-'.$property->name.'" title="'.$property->description.'"></div>',
|
529
|
);
|
530
|
break;
|
531
|
|
532
|
case 'color':
|
533
|
return array(
|
534
|
'#markup' => '<div id="edit-'. $property->name .'-wrapper" class="form-item clearfix">
|
535
|
<label class="color">' . $property->description .':</label>
|
536
|
<div id="'. $property->name .'" class="colorSelector-wrapper">
|
537
|
<div class="colorSelector"><div style="background-color: #ffffff"></div>
|
538
|
</div></div></div>'
|
539
|
);
|
540
|
break;
|
541
|
|
542
|
case 'image':
|
543
|
$sweaver = Sweaver::get_instance();
|
544
|
if ($sweaver->is_plugin_activated('sweaver_plugin_images')){
|
545
|
return array(
|
546
|
'#type' => 'select',
|
547
|
'#title' => $property->description,
|
548
|
'#options' => $images,
|
549
|
'#attributes' => array(
|
550
|
'class' => array('background-image'),
|
551
|
),
|
552
|
);
|
553
|
}
|
554
|
else {
|
555
|
return array(
|
556
|
'#type' => 'managed_file',
|
557
|
'#title' => $property->description,
|
558
|
'#size' => '40',
|
559
|
'#upload_location' => 'public://sweaver/',
|
560
|
'#upload_validators' => array(
|
561
|
'file_validate_is_image' => array(),
|
562
|
'file_validate_extensions' => array('png gif jpg jpeg'),
|
563
|
),
|
564
|
);
|
565
|
}
|
566
|
break;
|
567
|
|
568
|
case 'select':
|
569
|
return array(
|
570
|
'#type' => 'select',
|
571
|
'#title' => $property->description,
|
572
|
'#options' => $property->property_options,
|
573
|
'#prefix' => isset($property->css_prefix) ? $property->css_prefix : '',
|
574
|
'#suffix' => isset($property->css_suffix) ? $property->css_suffix : '',
|
575
|
);
|
576
|
break;
|
577
|
|
578
|
case 'parent':
|
579
|
if (empty($property->property_options)) {
|
580
|
return array(
|
581
|
'#type' => 'markup',
|
582
|
'#prefix' => '<div class="sweaver-group clearfix"><label>'. $property->description .':</label><div class="sweaver-group-content">',
|
583
|
'#suffix' => '</div></div>',
|
584
|
);
|
585
|
}
|
586
|
else {
|
587
|
return array(
|
588
|
'#theme' => 'table')
|
589
|
+ $property->property_options;
|
590
|
}
|
591
|
break;
|
592
|
|
593
|
// New Type of Field implemented to improve the interface
|
594
|
case 'radio':
|
595
|
$return_markup = '';
|
596
|
foreach ($property->property_options as $key => $value)
|
597
|
$return_markup .= '<div id="button-radio-'.$property->name.'-'.$key.'" name="'. $property->name.'" class="editor_icons form-item-'.$property->name.'" title="'.$property->description . ' : ' . $value.'"></div>';
|
598
|
return array(
|
599
|
'#markup' => $return_markup,
|
600
|
'#prefix' => '<div class="sweaver-group clearfix"><label>'. $property->description .':</label><div class="sweaver-group-content">',
|
601
|
'#suffix' => '</div></div>',
|
602
|
);
|
603
|
break;
|
604
|
|
605
|
}
|
606
|
}
|
607
|
|
608
|
private function sweaver_recursive_table_element ($property, $properties)
|
609
|
{
|
610
|
if (is_array($property))
|
611
|
{
|
612
|
foreach($property as $kee => $value)
|
613
|
{
|
614
|
if (is_array($value))
|
615
|
$property[$kee] = $this->sweaver_recursive_table_element($value, $properties);
|
616
|
|
617
|
elseif (preg_match('/^{([a-zA-Z_-]+)}$/', $value, $property_name)) {
|
618
|
// $property_name[0] contains the entire string and $property_name[1] the first variable
|
619
|
$property_name = $property_name[1];
|
620
|
if (isset($properties[$property_name]))
|
621
|
$property[$kee] = $properties[$property_name];
|
622
|
}
|
623
|
}
|
624
|
return $property;
|
625
|
}
|
626
|
}
|
627
|
}
|