Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
fusiondirectory
fusiondirectory
Commits
f279d3b2
Unverified
Commit
f279d3b2
authored
4 years ago
by
Côme Chilliet
Browse files
Options
Download
Patches
Plain Diff
fix(xml) Fix PHPStan warning in xml due to extract use
issue
#6114
parent
cbb8461e
dev
6342-update-the-locales-for-1-5
6344-template-issue-when-creating-a-template-with-empty-password-error-message-should-not-be-seen
6365-core-locking-mechanism-is-not-changing-the-mail-ressource-it-does-lock-the-mail-account
6365-core-when-lock-mechanism-is-trigger-the-user-should-not-be-editable-if-not-unlock
6378-orcid-test-method-is-wrong-and-break-orcid-saving
core-php8
master
fusiondirectory-1.5
fusiondirectory-1.4
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/class_xml.inc
+71
-59
include/class_xml.inc
with
71 additions
and
59 deletions
+71
-59
include/class_xml.inc
+
71
−
59
View file @
f279d3b2
<?php
<?php
/*
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2011-20
16
FusionDirectory
Copyright (C) 2011-20
20
FusionDirectory
This program is free software; you can redistribute it and/or modify
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
...
@@ -62,107 +63,118 @@ class xml
...
@@ -62,107 +63,118 @@ class xml
return
;
return
;
}
}
//Initializations
//
Initializations
$xml_array
=
[];
$xml_array
=
[];
$current
=
&
$xml_array
;
//Refference
// Reference
$current
=
&
$xml_array
;
//Go through the tags.
// Go through the tags.
$repeated_tag_index
=
[];
//Multiple tags with same name will be turned into an array
// Multiple tags with same name will be turned into an array
$repeated_tag_index
=
[];
foreach
(
$xml_values
as
$data
)
{
foreach
(
$xml_values
as
$data
)
{
unset
(
$attributes
,
$value
);
//Remove existing values, or there will be trouble
//This command will extract these variables into the foreach scope
// tag(string), type(string), level(int), attributes(array).
extract
(
$data
);
//We could use the array by itself, but this cooler.
$result
=
[];
$result
=
[];
$attributes_data
=
[];
$attributes_data
=
[];
if
(
isset
(
$value
))
{
if
(
isset
(
$
data
[
'
value
'
]
))
{
if
(
$priority
==
'tag'
)
{
if
(
$priority
==
'tag'
)
{
$result
=
$value
;
$result
=
$
data
[
'
value
'
]
;
}
else
{
}
else
{
//Put the value in a assoc array if we are in the 'Attribute' mode
//
Put the value in a assoc array if we are in the 'Attribute' mode
$result
[
'value'
]
=
$value
;
$result
[
'value'
]
=
$
data
[
'
value
'
]
;
}
}
}
}
//Set the attributes too.
//Set the attributes too.
if
(
isset
(
$attributes
)
and
$get_attributes
)
{
if
(
isset
(
$
data
[
'
attributes
'
]
)
and
$get_attributes
)
{
foreach
(
$attributes
as
$attr
=>
$val
)
{
foreach
(
$
data
[
'
attributes
'
]
as
$attr
=>
$val
)
{
if
(
$priority
==
'tag'
)
{
if
(
$priority
==
'tag'
)
{
$attributes_data
[
$attr
]
=
$val
;
$attributes_data
[
$attr
]
=
$val
;
}
else
{
}
else
{
//Set all the attributes in a array called 'attr'
//
Set all the attributes in a array called 'attr'
$result
[
'attr'
][
$attr
]
=
$val
;
$result
[
'attr'
][
$attr
]
=
$val
;
}
}
}
}
}
}
//See tag status and do the needed.
// See tag status and do the needed.
if
(
$type
==
"open"
)
{
//The starting of the tag '<tag>'
if
(
$data
[
'type'
]
==
'open'
)
{
$parent
[
$level
-
1
]
=
&
$current
;
// The starting of the tag '<tag>'
if
(
!
is_array
(
$current
)
or
(
!
in_array
(
$tag
,
array_keys
(
$current
))))
{
//Insert New tag
$parent
[
$data
[
'level'
]
-
1
]
=
&
$current
;
$current
[
$tag
]
=
$result
;
if
(
!
is_array
(
$current
)
or
(
!
in_array
(
$data
[
'tag'
],
array_keys
(
$current
))))
{
// Insert New tag
$current
[
$data
[
'tag'
]]
=
$result
;
if
(
$attributes_data
)
{
if
(
$attributes_data
)
{
$current
[
$tag
.
'_attr'
]
=
$attributes_data
;
$current
[
$
data
[
'
tag
'
]
.
'_attr'
]
=
$attributes_data
;
}
}
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
$repeated_tag_index
[
$data
[
'tag'
]
.
'_'
.
$data
[
'level'
]]
=
1
;
$current
=
&
$current
[
$tag
];
}
else
{
//There was another element with the same tag name
if
(
isset
(
$current
[
$tag
][
0
]))
{
//If there is a 0th element it is already an array
$current
=
&
$current
[
$data
[
'tag'
]];
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]]
=
$result
;
}
else
{
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
// There was another element with the same tag name
}
else
{
//This section will make the value an array if multiple tags with the same name appear together
$current
[
$tag
]
=
[
$current
[
$tag
],
$result
];
//This will combine the existing item and the new item together to make an array
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
2
;
if
(
isset
(
$current
[
$tag
.
'_attr'
]))
{
//The attribute of the last(0th) tag must be moved as well
if
(
isset
(
$current
[
$data
[
'tag'
]][
0
]))
{
$current
[
$tag
][
'0_attr'
]
=
$current
[
$tag
.
'_attr'
];
// If there is a 0th element it is already an array
unset
(
$current
[
$tag
.
'_attr'
]);
$current
[
$data
[
'tag'
]][
$repeated_tag_index
[
$data
[
'tag'
]
.
'_'
.
$data
[
'level'
]]]
=
$result
;
$repeated_tag_index
[
$data
[
'tag'
]
.
'_'
.
$data
[
'level'
]]
++
;
}
else
{
// This section will make the value an array if multiple tags with the same name appear together
// This will combine the existing item and the new item together to make an array
$current
[
$data
[
'tag'
]]
=
[
$current
[
$data
[
'tag'
]],
$result
];
$repeated_tag_index
[
$data
[
'tag'
]
.
'_'
.
$data
[
'level'
]]
=
2
;
if
(
isset
(
$current
[
$data
[
'tag'
]
.
'_attr'
]))
{
// The attribute of the last(0th) tag must be moved as well
$current
[
$data
[
'tag'
]][
'0_attr'
]
=
$current
[
$data
[
'tag'
]
.
'_attr'
];
unset
(
$current
[
$data
[
'tag'
]
.
'_attr'
]);
}
}
}
}
$last_item_index
=
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
-
1
;
$last_item_index
=
$repeated_tag_index
[
$
data
[
'
tag
'
]
.
'_'
.
$
data
[
'
level
'
]
]
-
1
;
$current
=
&
$current
[
$tag
][
$last_item_index
];
$current
=
&
$current
[
$
data
[
'
tag
'
]
][
$last_item_index
];
}
}
}
elseif
(
$type
==
"complete"
)
{
//Tags that ends in 1 line '<tag />'
}
elseif
(
$data
[
'type'
]
==
"complete"
)
{
//See if the key is already taken.
// Tags that ends in 1 line '<tag />'
if
(
!
isset
(
$current
[
$tag
]))
{
//New Key
// See if the key is already taken.
$current
[
$tag
]
=
$result
;
if
(
!
isset
(
$current
[
$data
[
'tag'
]]))
{
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
// New Key
$current
[
$data
[
'tag'
]]
=
$result
;
$repeated_tag_index
[
$data
[
'tag'
]
.
'_'
.
$data
[
'level'
]]
=
1
;
if
(
$priority
==
'tag'
and
$attributes_data
)
{
if
(
$priority
==
'tag'
and
$attributes_data
)
{
$current
[
$tag
.
'_attr'
]
=
$attributes_data
;
$current
[
$
data
[
'
tag
'
]
.
'_attr'
]
=
$attributes_data
;
}
}
}
else
{
//If taken, put all things inside a list(array)
}
else
{
if
(
isset
(
$current
[
$tag
][
0
])
and
is_array
(
$current
[
$tag
]))
{
//If it is already an array...
// If taken, put all things inside a list(array)
if
(
isset
(
$current
[
$data
[
'tag'
]][
0
])
and
is_array
(
$current
[
$data
[
'tag'
]]))
{
// If it is already an array...
// ...push the new element into that array.
// ...push the new element into that array.
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]]
=
$result
;
$current
[
$
data
[
'
tag
'
]
][
$repeated_tag_index
[
$
data
[
'
tag
'
]
.
'_'
.
$
data
[
'
level
'
]
]]
=
$result
;
if
(
$priority
==
'tag'
and
$get_attributes
and
$attributes_data
)
{
if
(
$priority
==
'tag'
and
$get_attributes
and
$attributes_data
)
{
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
.
'_attr'
]
=
$attributes_data
;
$current
[
$
data
[
'
tag
'
]
][
$repeated_tag_index
[
$
data
[
'
tag
'
]
.
'_'
.
$
data
[
'
level
'
]
]
.
'_attr'
]
=
$attributes_data
;
}
}
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
$repeated_tag_index
[
$
data
[
'
tag
'
]
.
'_'
.
$
data
[
'
level
'
]
]
++
;
}
else
{
//If it is not an array...
}
else
{
//If it is not an array...
$current
[
$tag
]
=
[
$current
[
$tag
],
$result
];
//...Make it an array using using the existing value and the new value
//...Make it an array using using the existing value and the new value
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
$current
[
$data
[
'tag'
]]
=
[
$current
[
$data
[
'tag'
]],
$result
];
$repeated_tag_index
[
$data
[
'tag'
]
.
'_'
.
$data
[
'level'
]]
=
1
;
if
(
$priority
==
'tag'
and
$get_attributes
)
{
if
(
$priority
==
'tag'
and
$get_attributes
)
{
if
(
isset
(
$current
[
$tag
.
'_attr'
]))
{
//The attribute of the last(0th) tag must be moved as well
if
(
isset
(
$current
[
$data
[
'tag'
]
.
'_attr'
]))
{
$current
[
$tag
][
'0_attr'
]
=
$current
[
$tag
.
'_attr'
];
// The attribute of the last(0th) tag must be moved as well
unset
(
$current
[
$tag
.
'_attr'
]);
$current
[
$data
[
'tag'
]][
'0_attr'
]
=
$current
[
$data
[
'tag'
]
.
'_attr'
];
unset
(
$current
[
$data
[
'tag'
]
.
'_attr'
]);
}
}
if
(
$attributes_data
)
{
if
(
$attributes_data
)
{
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
.
'_attr'
]
=
$attributes_data
;
$current
[
$
data
[
'
tag
'
]
][
$repeated_tag_index
[
$
data
[
'
tag
'
]
.
'_'
.
$
data
[
'
level
'
]
]
.
'_attr'
]
=
$attributes_data
;
}
}
}
}
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
//0 and 1 index is already taken
// 0 and 1 index is already taken
$repeated_tag_index
[
$data
[
'tag'
]
.
'_'
.
$data
[
'level'
]]
++
;
}
}
}
}
}
elseif
(
$type
==
'close'
)
{
//End of tag '</tag>'
}
elseif
(
$data
[
'type'
]
==
'close'
)
{
$current
=
&
$parent
[
$level
-
1
];
// End of tag '</tag>'
$current
=
&
$parent
[
$data
[
'level'
]
-
1
];
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets