Link.php
2.47 KB
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
<?php
/**
* @package Better Preview
* @version 6.1.0
*
* @author Peter van Westen <info@regularlabs.com>
* @link http://www.regularlabs.com
* @copyright Copyright © 2018 Regular Labs All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
namespace RegularLabs\Plugin\System\BetterPreview\Component\Menus\Item;
defined('_JEXEC') or die;
use JFactory;
use JText;
use MenusHelper;
use MenusModelMenutypes;
use RegularLabs\Plugin\System\BetterPreview\Component\Link as Main_Link;
class Link extends Main_Link
{
var $types = [];
function getLinks()
{
if ( ! JFactory::getApplication()->input->get('id'))
{
return [];
}
$item = $this->getItem(
JFactory::getApplication()->input->get('id'),
'menu',
['name' => 'title', 'parent' => 'parent_id', 'url' => 'link', 'type' => 'type']
);
$parents = $this->getParents(
$item,
'menu',
['name' => 'title', 'parent' => 'parent_id', 'url' => 'link', 'type' => 'type'],
[],
1
);
$model = new MenusModelMenutypes;
$model->getTypeOptions();
$this->types = $model->getReverseLookup();
$this->setParams($item);
foreach ($parents as &$parent)
{
$this->setParams($parent);
}
return array_merge([$item], $parents);
}
private function setParams(&$item)
{
if ($item->type == 'alias')
{
$name = $item->name;
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('m.params')
->from('#__menu as m')
->where('m.id = ' . (int) $item->id);
$db->setQuery($query);
$params = json_decode($db->loadResult());
if (is_null($params))
{
$params = (object) [];
}
$item = $this->getItem(
$params->aliasoptions,
'menu',
['name' => 'title', 'parent' => 'parent_id', 'url' => 'link', 'type' => 'type', 'home' => false]
);
$this->setParams($item);
$item->name = $name . ' → ' . $item->name;
}
switch ($item->type)
{
case 'url':
$item->type = JText::_('COM_MENUS_TYPE_EXTERNAL_URL');
break;
case 'separator':
$item->type = JText::_('COM_MENUS_TYPE_SEPARATOR');
$item->url = '';
$item->published = 0;
break;
default:
$item->type = $this->getType($item);
$item->url .= '&Itemid=' . $item->id;
break;
}
}
private function getType($item)
{
$key = MenusHelper::getLinkKey($item->url);
if (isset($this->types[$key]))
{
$item->type = JText::_($this->types[$key]);
}
return $item->type;
}
}