1 <?php
2
3 4 5 6 7 8 9 10 11 12
13 class rex_var_medialist extends rex_var
14 {
15 protected function getOutput()
16 {
17 $id = $this->getArg('id', 0, true);
18 if (!in_array($this->getContext(), ['module', 'action']) || !is_numeric($id) || $id < 1 || $id > 10) {
19 return false;
20 }
21
22 $value = $this->getContextData()->getValue('medialist' . $id);
23
24 if ($this->hasArg('isset') && $this->getArg('isset')) {
25 return $value ? 'true' : 'false';
26 }
27
28 if ($this->hasArg('widget') && $this->getArg('widget')) {
29 if (!$this->environmentIs(self::ENV_INPUT)) {
30 return false;
31 }
32 $args = [];
33 foreach (['category', 'preview', 'types'] as $key) {
34 if ($this->hasArg($key)) {
35 $args[$key] = $this->getArg($key);
36 }
37 }
38 $value = self::getWidget($id, 'REX_INPUT_MEDIALIST[' . $id . ']', $value, $args);
39 }
40
41 return self::quote($value);
42 }
43
44 public static function getWidget($id, $name, $value, array $args = [])
45 {
46 $open_params = '';
47 if (isset($args['category']) && ($category = (int) $args['category'])) {
48 $open_params .= '&rex_file_category=' . $category;
49 }
50
51 foreach ($args as $aname => $avalue) {
52 $open_params .= '&args[' . $aname . ']=' . urlencode($avalue);
53 }
54
55 $wdgtClass = ' rex-js-widget-medialist';
56 if (isset($args['preview']) && $args['preview']) {
57 $wdgtClass .= ' rex-js-widget-preview';
58 if (rex_addon::get('media_manager')->isAvailable()) {
59 $wdgtClass .= ' rex-js-widget-preview-media-manager';
60 }
61 }
62
63 $options = '';
64 $medialistarray = explode(',', $value);
65 if (is_array($medialistarray)) {
66 foreach ($medialistarray as $file) {
67 if ($file != '') {
68 $options .= '<option value="' . $file . '">' . $file . '</option>';
69 }
70 }
71 }
72
73 $disabled = ' disabled';
74 $open_func = '';
75 $add_func = '';
76 $delete_func = '';
77 $view_func = '';
78 if (rex::getUser()->getComplexPerm('media')->hasMediaPerm()) {
79 $disabled = '';
80 $open_func = 'openREXMedialist(' . $id . ',\'' . $open_params . '\');';
81 $add_func = 'addREXMedialist(' . $id . ',\'' . $open_params . '\');';
82 $delete_func = 'deleteREXMedialist(' . $id . ');';
83 $view_func = 'viewREXMedialist(' . $id . ',\'' . $open_params . '\');';
84 }
85
86 $e = [];
87 $e['before'] = '<div class="rex-js-widget' . $wdgtClass . '">';
88 $e['field'] = '<select class="form-control" name="REX_MEDIALIST_SELECT[' . $id . ']" id="REX_MEDIALIST_SELECT_' . $id . '" size="10">' . $options . '</select><input type="hidden" name="' . $name . '" id="REX_MEDIALIST_' . $id . '" value="' . $value . '" />';
89 $e['moveButtons'] = '
90 <a href="#" class="btn btn-popup" onclick="moveREXMedialist(' . $id . ',\'top\');return false;" title="' . rex_i18n::msg('var_medialist_move_top') . '"><i class="rex-icon rex-icon-top"></i></a>
91 <a href="#" class="btn btn-popup" onclick="moveREXMedialist(' . $id . ',\'up\');return false;" title="' . rex_i18n::msg('var_medialist_move_up') . '"><i class="rex-icon rex-icon-up"></i></a>
92 <a href="#" class="btn btn-popup" onclick="moveREXMedialist(' . $id . ',\'down\');return false;" title="' . rex_i18n::msg('var_medialist_move_down') . '"><i class="rex-icon rex-icon-down"></i></a>
93 <a href="#" class="btn btn-popup" onclick="moveREXMedialist(' . $id . ',\'bottom\');return false;" title="' . rex_i18n::msg('var_medialist_move_bottom') . '"><i class="rex-icon rex-icon-bottom"></i></a>';
94 $e['functionButtons'] = '
95 <a href="#" class="btn btn-popup" onclick="' . $open_func . 'return false;" title="' . rex_i18n::msg('var_media_open') . '"' . $disabled . '><i class="rex-icon rex-icon-open-mediapool"></i></a>
96 <a href="#" class="btn btn-popup" onclick="' . $add_func . 'return false;" title="' . rex_i18n::msg('var_media_new') . '"' . $disabled . '><i class="rex-icon rex-icon-add-media"></i></a>
97 <a href="#" class="btn btn-popup" onclick="' . $delete_func . 'return false;" title="' . rex_i18n::msg('var_media_remove') . '"' . $disabled . '><i class="rex-icon rex-icon-delete-media"></i></a>
98 <a href="#" class="btn btn-popup" onclick="' . $view_func . 'return false;" title="' . rex_i18n::msg('var_media_view') . '"' . $disabled . '><i class="rex-icon rex-icon-view-media"></i></a>';
99 $e['after'] = '<div class="rex-js-media-preview"></div></div>';
100
101 $fragment = new rex_fragment();
102 $fragment->setVar('elements', [$e], false);
103 $media = $fragment->parse('core/form/widget_list.php');
104
105 return $media;
106 }
107 }
108