AdminMenu.php
3.15 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* @package Regular Labs Library
* @version 18.2.10140
*
* @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\RegularLabs;
defined('_JEXEC') or die;
use JFactory;
use RegularLabs\Library\RegEx as RL_RegEx;
class AdminMenu
{
public static function combine()
{
$params = Params::get();
if ( ! $params->combine_admin_menu)
{
return;
}
$html = JFactory::getApplication()->getBody();
if ($html == '')
{
return;
}
if (strpos($html, '<ul id="menu"') === false
|| (strpos($html, '">Regular Labs ') === false
&& strpos($html, '" >Regular Labs ') === false)
)
{
return;
}
if ( ! RL_RegEx::matchAll(
'<li><a class="(?:no-dropdown )?menu-[^>]*>Regular Labs [^<]*</a></li>',
$html,
$matches,
null,
PREG_PATTERN_ORDER
)
)
{
return;
}
$menu_items = $matches[0];
if (count($menu_items) < 2)
{
return;
}
$manager = null;
foreach ($menu_items as $i => &$menu_item)
{
RL_RegEx::match('class="(?:no-dropdown )?menu-(.*?)"', $menu_item, $icon);
$icon = str_replace('icon-icon-', 'icon-', 'icon-' . $icon[1]);
$menu_item = str_replace(
['>Regular Labs - ', '>Regular Labs '],
'><span class="icon-reglab ' . $icon . '"></span> ',
$menu_item
);
if ($icon != 'icon-regularlabsmanager')
{
continue;
}
$manager = $menu_item;
unset($menu_items[$i]);
}
$main_link = "";
if ( ! is_null($manager))
{
array_unshift($menu_items, $manager);
$main_link = 'href="index.php?option=com_regularlabsmanager"';
}
$new_menu_item =
'<li class="dropdown-submenu">'
. '<a class="dropdown-toggle menu-regularlabs" data-toggle="dropdown" ' . $main_link . '>Regular Labs</a>'
. "\n" . '<ul id="menu-cregularlabs" class="dropdown-menu menu-scrollable menu-component">'
. "\n" . implode("\n", $menu_items)
. "\n" . '</ul>'
. '</li>';
$first = array_shift($matches[0]);
$html = str_replace($first, $new_menu_item, $html);
$html = str_replace($matches[0], '', $html);
JFactory::getApplication()->setBody($html);
}
public static function addHelpItem()
{
$params = Params::get();
if ( ! $params->show_help_menu)
{
return;
}
$html = JFactory::getApplication()->getBody();
if ($html == '')
{
return;
}
$pos_1 = strpos($html, '<!-- Top Navigation -->');
$pos_2 = strpos($html, '<!-- Header -->');
if ( ! $pos_1 || ! $pos_2)
{
return;
}
$nav = substr($html, $pos_1, $pos_2 - $pos_1);
$shop_item = '(\s*<li>\s*<a [^>]*class="[^"]*menu-help-)shop("\s[^>]*)href="[^"]+\.joomla\.org[^"]*"([^>]*>)[^<]*(</a>s*</li>)';
$nav = RL_RegEx::replace(
$shop_item,
'\0<li class="divider"><span></span></li>\1dev\2href="https://www.regularlabs.com"\3Regular Labs Extensions\4',
$nav
);
// Just in case something fails
if (empty($nav))
{
return;
}
$html = substr_replace($html, $nav, $pos_1, $pos_2 - $pos_1);
JFactory::getApplication()->setBody($html);
}
}