1 <?php
2
3 4 5 6 7 8 9 10
11 class rex_var_linklist extends rex_var
12 {
13 protected function getOutput()
14 {
15 $id = $this->getArg('id', 0, true);
16 if (!in_array($this->getContext(), ['module', 'action']) || !is_numeric($id) || $id < 1 || $id > 10) {
17 return false;
18 }
19
20 $value = $this->getContextData()->getValue('linklist' . $id);
21
22 if ($this->hasArg('isset') && $this->getArg('isset')) {
23 return $value ? 'true' : 'false';
24 }
25
26 if ($this->hasArg('widget') && $this->getArg('widget')) {
27 if (!$this->environmentIs(self::ENV_INPUT)) {
28 return false;
29 }
30 $args = [];
31 foreach (['category'] as $key) {
32 if ($this->hasArg($key)) {
33 $args[$key] = $this->getArg($key);
34 }
35 }
36 $value = self::getWidget($id, 'REX_INPUT_LINKLIST[' . $id . ']', $value, $args);
37 }
38
39 return self::quote($value);
40 }
41
42 public static function getWidget($id, $name, $value, array $args = [])
43 {
44 $category = rex_category::getCurrent() ? rex_category::getCurrent()->getId() : 0;
45
46
47 if (isset($args['category'])) {
48 $category = (int) $args['category'];
49 }
50
51 $open_params = '&clang=' . rex_clang::getCurrentId() . '&category_id=' . $category;
52
53 $options = '';
54 $linklistarray = explode(',', $value);
55 if (is_array($linklistarray)) {
56 foreach ($linklistarray as $link) {
57 if ($link != '') {
58 if ($article = rex_article::get($link)) {
59 $options .= '<option value="' . $link . '">' . rex_escape(trim(sprintf('%s [%s]', $article->getName(), $article->getId()))) . '</option>';
60 }
61 }
62 }
63 }
64
65 $disabled = ' disabled';
66 $open_func = '';
67 $delete_func = '';
68 if (rex::getUser()->getComplexPerm('structure')->hasStructurePerm()) {
69 $disabled = '';
70 $open_func = 'openREXLinklist(' . $id . ', \'' . $open_params . '\');';
71 $delete_func = 'deleteREXLinklist(' . $id . ');';
72 }
73
74 $e = [];
75 $e['field'] = '
76 <select class="form-control" name="REX_LINKLIST_SELECT[' . $id . ']" id="REX_LINKLIST_SELECT_' . $id . '" size="10">
77 ' . $options . '
78 </select>
79 <input type="hidden" name="' . $name . '" id="REX_LINKLIST_' . $id . '" value="' . $value . '" />';
80 $e['moveButtons'] = '
81 <a href="#" class="btn btn-popup" onclick="moveREXLinklist(' . $id . ',\'top\');return false;" title="' . rex_i18n::msg('var_linklist_move_top') . '"><i class="rex-icon rex-icon-top"></i></a>
82 <a href="#" class="btn btn-popup" onclick="moveREXLinklist(' . $id . ',\'up\');return false;" title="' . rex_i18n::msg('var_linklist_move_up') . '"><i class="rex-icon rex-icon-up"></i></a>
83 <a href="#" class="btn btn-popup" onclick="moveREXLinklist(' . $id . ',\'down\');return false;" title="' . rex_i18n::msg('var_linklist_move_down') . '"><i class="rex-icon rex-icon-down"></i></a>
84 <a href="#" class="btn btn-popup" onclick="moveREXLinklist(' . $id . ',\'bottom\');return false;" title="' . rex_i18n::msg('var_linklist_move_bottom') . '"><i class="rex-icon rex-icon-bottom"></i></a>';
85 $e['functionButtons'] = '
86 <a href="#" class="btn btn-popup" onclick="' . $open_func . 'return false;" title="' . rex_i18n::msg('var_link_open') . '"' . $disabled . '><i class="rex-icon rex-icon-open-linkmap"></i></a>
87 <a href="#" class="btn btn-popup" onclick="' . $delete_func . 'return false;" title="' . rex_i18n::msg('var_link_delete') . '"' . $disabled . '><i class="rex-icon rex-icon-delete-link"></i></a>';
88
89 $fragment = new rex_fragment();
90 $fragment->setVar('elements', [$e], false);
91 $link = $fragment->parse('core/form/widget_list.php');
92
93 return $link;
94 }
95 }
96