mirror of
https://github.com/joshp23/PEWS.git
synced 2024-12-22 10:30:19 +01:00
unset property array on delete if array is empty
This commit is contained in:
parent
5ff1b202b8
commit
92f5d6052d
1 changed files with 11 additions and 5 deletions
|
@ -2,7 +2,7 @@
|
||||||
/*
|
/*
|
||||||
*------------------------------------------------------------
|
*------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* PEWS (pew! pew!) - PHP Easy WebFinger Server 1.7.0
|
* PEWS (pew! pew!) - PHP Easy WebFinger Server 1.7.2
|
||||||
*
|
*
|
||||||
* This script enables webfinger support on a server that
|
* This script enables webfinger support on a server that
|
||||||
* handles one or more domains.
|
* handles one or more domains.
|
||||||
|
@ -454,14 +454,16 @@ function pews_manager( $auth, $password ) {
|
||||||
if (file_exists($acct_file)) {
|
if (file_exists($acct_file)) {
|
||||||
$data = json_decode(file_get_contents($acct_file), true);
|
$data = json_decode(file_get_contents($acct_file), true);
|
||||||
$aliases = isset($data['aliases']) ? $data['aliases'] : null;
|
$aliases = isset($data['aliases']) ? $data['aliases'] : null;
|
||||||
if($aliases !== null && in_array( $oldAlias, $aliases ) ) {
|
|
||||||
$oldAliasArray[] = $oldAlias;
|
if($aliases !== null && in_array( $oldAlias, $aliases ) ) {
|
||||||
$newAliasesArray = array_diff( $aliases , $oldAliasArray);
|
unset($aliases[$oldAlias]);
|
||||||
if(empty($newAliasesArray)) {
|
if(empty($newAliasesArray)) {
|
||||||
unset ($data['aliases']);
|
unset ($data['aliases']);
|
||||||
} else {
|
} else {
|
||||||
$data['aliases'] = $newAliasesArray;
|
$data['aliases'] = $newAliasesArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
||||||
$success = file_put_contents( $acct_file, $data );
|
$success = file_put_contents( $acct_file, $data );
|
||||||
if($success === false) {
|
if($success === false) {
|
||||||
|
@ -609,7 +611,11 @@ function pews_manager( $auth, $password ) {
|
||||||
$props = isset($data['properties']) ? $data['properties'] : array();
|
$props = isset($data['properties']) ? $data['properties'] : array();
|
||||||
if(array_key_exists($propKey, $props)){
|
if(array_key_exists($propKey, $props)){
|
||||||
unset($props[$propKey]);
|
unset($props[$propKey]);
|
||||||
$data['properties'] = $props;
|
if(empty($props)) {
|
||||||
|
unset ($data['properties']);
|
||||||
|
} else {
|
||||||
|
$data['properties'] = $props;
|
||||||
|
}
|
||||||
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
||||||
$success = file_put_contents( $acct_file, $data );
|
$success = file_put_contents( $acct_file, $data );
|
||||||
if($success === false) {
|
if($success === false) {
|
||||||
|
|
Loading…
Reference in a new issue