Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
4e95a064
Commit
4e95a064
authored
Dec 05, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(menu) minor performance changes
parent
902b9431
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
31 deletions
+28
-31
MenuItem.php
src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuItem.php
+28
-31
No files found.
src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuItem.php
View file @
4e95a064
...
...
@@ -280,6 +280,15 @@ class MenuItem
return
$this
->
visibility
;
}
/**
* is node visible
* @return bool
*/
public
function
isVisible
()
{
return
$this
->
visibility
!=
'delete'
;
}
/**
* check if this item is selected
* @return bool is this item selected
...
...
@@ -379,36 +388,21 @@ class MenuItem
public
function
toggleSelected
(
$url
)
{
$this
->
selected
=
false
;
foreach
(
$this
->
getFilteredChildren
()
as
$nodeId
=>
$node
)
{
$node
->
toggleSelected
(
$url
);
if
(
$node
->
getUrl
()
!=
""
)
{
// hash part isn't available on server end
$menuItemUrl
=
explode
(
"#"
,
$node
->
getUrl
())[
0
];
$match
=
str_replace
(
array
(
"."
,
"*"
,
"?"
),
array
(
"\."
,
".*"
,
"\?"
),
$menuItemUrl
);
if
(
preg_match
(
"@^
{
$match
}
$@"
,
"
{
$url
}
"
))
{
$node
->
select
();
foreach
(
$this
->
children
as
$nodeId
=>
&
$node
)
{
if
(
$node
->
isVisible
())
{
$node
->
toggleSelected
(
$url
);
if
(
$node
->
getUrl
()
!=
""
)
{
// hash part isn't available on server end
$menuItemUrl
=
explode
(
"#"
,
$node
->
getUrl
())[
0
];
$match
=
str_replace
(
array
(
"."
,
"*"
,
"?"
),
array
(
"\."
,
".*"
,
"\?"
),
$menuItemUrl
);
if
(
preg_match
(
"@^
{
$match
}
$@"
,
"
{
$url
}
"
))
{
$node
->
select
();
}
}
}
}
}
/**
* Menu items are pluggable and can override already existing sections.
* This function filters the available child items and only return the still existing ones.
* @return array filtered set of children
*/
private
function
getFilteredChildren
()
{
$result
=
array
();
foreach
(
$this
->
children
as
$key
=>
$node
)
{
if
(
$node
->
getVisibility
()
!=
'delete'
)
{
$result
[
$key
]
=
$node
;
}
}
ksort
(
$result
);
return
$result
;
}
/**
* Recursive method to retrieve a simple ordered structure of all menu items
* @return array named array containing menu items as simple objects to keep the api cleaner for our templates
...
...
@@ -417,12 +411,15 @@ class MenuItem
{
$result
=
array
();
// sort by order/id and map getters to array items
foreach
(
$this
->
getFilteredChildren
()
as
$key
=>
$node
)
{
$result
[
$node
->
id
]
=
new
\stdClass
();
foreach
(
self
::
$internalClassGetterNames
as
$methodName
=>
$propName
)
{
$result
[
$node
->
id
]
->
{
$propName
}
=
$node
->
$methodName
();
foreach
(
$this
->
children
as
$key
=>
&
$node
)
{
if
(
$node
->
isVisible
())
{
$result
[
$key
]
=
new
\stdClass
();
foreach
(
self
::
$internalClassGetterNames
as
$methodName
=>
$propName
)
{
$result
[
$key
]
->
{
$propName
}
=
$node
->
$methodName
();
}
}
}
ksort
(
$result
);
return
$result
;
}
...
...
@@ -434,8 +431,8 @@ class MenuItem
*/
public
function
findNodeById
(
$id
)
{
foreach
(
$this
->
getFilteredChildren
()
as
$key
=>
$node
)
{
if
(
strtolower
(
$node
->
getId
())
==
strtolower
(
$id
))
{
foreach
(
$this
->
children
as
$key
=>
&
$node
)
{
if
(
$node
->
isVisible
()
&&
strtolower
(
$node
->
getId
())
==
strtolower
(
$id
))
{
return
$node
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment