1 <?php
2
3 4 5 6 7 8 9 10
11 class rex_var_link 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('link' . $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_LINK[' . $id . ']', $value, $args);
37 } else {
38 if ($value && $this->hasArg('output') && $this->getArg('output') != 'id') {
39 $value = rex_getUrl($value);
40 }
41 }
42
43 return self::quote($value);
44 }
45
46 public static function getWidget($id, $name, $value, array $args = [])
47 {
48 $art_name = '';
49 $art = rex_article::get($value);
50 $category = rex_category::getCurrent() ? rex_category::getCurrent()->getId() : 0;
51
52
53 if ($art instanceof rex_article) {
54 $art_name = trim(sprintf('%s [%s]', $art->getName(), $art->getId()));
55 $category = $art->getCategoryId();
56 }
57
58
59 if (isset($args['category'])) {
60 $category = (int) $args['category'];
61 }
62
63 $open_params = '&clang=' . rex_clang::getCurrentId() . '&category_id=' . $category;
64
65 $class = ' rex-disabled';
66 $open_func = '';
67 $delete_func = '';
68 if (rex::getUser()->getComplexPerm('structure')->hasStructurePerm()) {
69 $class = '';
70 $open_func = 'openLinkMap(\'REX_LINK_' . $id . '\', \'' . $open_params . '\');';
71 $delete_func = 'deleteREXLink(' . $id . ');';
72 }
73
74 $e = [];
75 $e['field'] = '<input class="form-control" type="text" name="REX_LINK_NAME[' . $id . ']" value="' . rex_escape($art_name) . '" id="REX_LINK_' . $id . '_NAME" readonly="readonly" /><input type="hidden" name="' . $name . '" id="REX_LINK_' . $id . '" value="' . $value . '" />';
76 $e['functionButtons'] = '
77 <a href="#" class="btn btn-popup' . $class . '" onclick="' . $open_func . 'return false;" title="' . rex_i18n::msg('var_link_open') . '"><i class="rex-icon rex-icon-open-linkmap"></i></a>
78 <a href="#" class="btn btn-popup' . $class . '" onclick="' . $delete_func . 'return false;" title="' . rex_i18n::msg('var_link_delete') . '"><i class="rex-icon rex-icon-delete-link"></i></a>';
79
80 $fragment = new rex_fragment();
81 $fragment->setVar('elements', [$e], false);
82 $media = $fragment->parse('core/form/widget.php');
83
84 return $media;
85 }
86 }
87